Browse Source

rewrite server connect wizard to new wizard style

'last' property on WizardComponents is now queried from UI, not from the wizard.
This allows the content of the WizardComponent itself to be taken into account.
patch-4
Sander van Grieken 2 years ago
parent
commit
15e2ed4f58
  1. 4
      electrum/gui/qml/components/NewWalletWizard.qml
  2. 28
      electrum/gui/qml/components/ServerConnectWizard.qml
  3. 7
      electrum/gui/qml/components/wizard/WCAutoConnect.qml
  4. 3
      electrum/gui/qml/components/wizard/Wizard.qml
  5. 15
      electrum/gui/qml/components/wizard/WizardComponent.qml
  6. 3
      electrum/gui/qml/qeapp.py
  7. 11
      electrum/gui/qml/qedaemon.py
  8. 16
      electrum/gui/qml/qewizard.py
  9. 24
      electrum/gui/wizard.py

4
electrum/gui/qml/components/NewWalletWizard.qml

@ -15,9 +15,7 @@ Wizard {
property string path
enter: null // disable transition
property QtObject wiz: Daemon.newWalletWizard
wiz: Daemon.newWalletWizard
Component.onCompleted: {
var view = wiz.start_wizard()

28
electrum/gui/qml/components/ServerConnectWizard.qml

@ -11,6 +11,8 @@ Wizard {
enter: null // disable transition
wiz: Daemon.serverConnectWizard
onAccepted: {
var proxy = wizard_data['proxy']
if (proxy && proxy['enabled'] == true) {
@ -25,29 +27,7 @@ Wizard {
}
Component.onCompleted: {
var start = _loadNextComponent(autoconnect)
start.next.connect(function() {autoconnectDone()})
}
function autoconnectDone() {
var page = _loadNextComponent(proxyconfig, wizard_data)
page.next.connect(function() {proxyconfigDone()})
}
function proxyconfigDone() {
var page = _loadNextComponent(serverconfig, wizard_data)
}
property Component autoconnect: Component {
WCAutoConnect {}
}
property Component proxyconfig: Component {
WCProxyConfig {}
var view = wiz.start_wizard()
_loadNextComponent(view)
}
property Component serverconfig: Component {
WCServerConfig {}
}
}

7
electrum/gui/qml/components/wizard/WCAutoConnect.qml

@ -1,14 +1,12 @@
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.1
import ".."
import "../controls"
WizardComponent {
valid: true
last: serverconnectgroup.checkedButton.connecttype === 'auto'
onAccept: {
function apply() {
wizard_data['autoconnect'] = serverconnectgroup.checkedButton.connecttype === 'auto'
}
@ -22,17 +20,18 @@ WizardComponent {
ButtonGroup {
id: serverconnectgroup
onCheckedButtonChanged: checkIsLast()
}
RadioButton {
ButtonGroup.group: serverconnectgroup
property string connecttype: 'auto'
text: qsTr('Auto connect')
checked: true
}
RadioButton {
ButtonGroup.group: serverconnectgroup
property string connecttype: 'manual'
checked: true
text: qsTr('Select servers manually')
}

3
electrum/gui/qml/components/wizard/Wizard.qml

@ -12,6 +12,7 @@ Dialog {
property var wizard_data
property alias pages: pages
property QtObject wiz
function _setWizardData(wdata) {
wizard_data = {}
@ -49,7 +50,6 @@ Dialog {
if (newview.view) {
console.log('next view: ' + newview.view)
var newpage = _loadNextComponent(newview.view, newview.wizard_data)
newpage.last = wiz.isLast(newview.wizard_data)
} else {
console.log('END')
}
@ -57,7 +57,6 @@ Dialog {
page.prev.connect(function() {
var wdata = wiz.prev()
console.log('prev view data: ' + JSON.stringify(wdata))
page.last = wiz.isLast(wdata)
})
Object.assign(page.wizard_data, wdata) // deep copy
page.ready = true // signal page it can access wizard_data

15
electrum/gui/qml/components/wizard/WizardComponent.qml

@ -8,4 +8,19 @@ Item {
property bool valid
property bool last: false
property bool ready: false
onAccept: {
apply()
}
function apply() { }
function checkIsLast() {
apply()
last = wizard.wiz.isLast(wizard_data)
}
Component.onCompleted: {
checkIsLast()
}
}

3
electrum/gui/qml/qeapp.py

@ -29,7 +29,7 @@ from .qechannelopener import QEChannelOpener
from .qelnpaymentdetails import QELnPaymentDetails
from .qechanneldetails import QEChannelDetails
from .qeswaphelper import QESwapHelper
from .qewizard import QENewWalletWizard
from .qewizard import QENewWalletWizard, QEServerConnectWizard
notification = None
@ -219,6 +219,7 @@ class ElectrumQmlApplication(QGuiApplication):
qmlRegisterUncreatableType(QEAmount, 'org.electrum', 1, 0, 'Amount', 'Amount can only be used as property')
qmlRegisterUncreatableType(QENewWalletWizard, 'org.electrum', 1, 0, 'NewWalletWizard', 'NewWalletWizard can only be used as property')
qmlRegisterUncreatableType(QEServerConnectWizard, 'org.electrum', 1, 0, 'ServerConnectWizard', 'ServerConnectWizard can only be used as property')
self.engine = QQmlApplicationEngine(parent=self)

11
electrum/gui/qml/qedaemon.py

@ -14,7 +14,7 @@ from .auth import AuthMixin, auth_protect
from .qefx import QEFX
from .qewallet import QEWallet
from .qewalletdb import QEWalletDB
from .qewizard import QENewWalletWizard
from .qewizard import QENewWalletWizard, QEServerConnectWizard
# wallet list model. supports both wallet basenames (wallet file basenames)
# and whole Wallet instances (loaded wallets)
@ -123,6 +123,7 @@ class QEDaemon(AuthMixin, QObject):
_available_wallets = None
_current_wallet = None
_new_wallet_wizard = None
_server_connect_wizard = None
_path = None
_use_single_password = False
_password = None
@ -131,6 +132,7 @@ class QEDaemon(AuthMixin, QObject):
availableWalletsChanged = pyqtSignal()
fxChanged = pyqtSignal()
newWalletWizardChanged = pyqtSignal()
serverConnectWizardChanged = pyqtSignal()
walletLoaded = pyqtSignal()
walletRequiresPassword = pyqtSignal()
@ -296,3 +298,10 @@ class QEDaemon(AuthMixin, QObject):
self._new_wallet_wizard = QENewWalletWizard(self)
return self._new_wallet_wizard
@pyqtProperty(QEServerConnectWizard, notify=serverConnectWizardChanged)
def serverConnectWizard(self):
if not self._server_connect_wizard:
self._server_connect_wizard = QEServerConnectWizard(self)
return self._server_connect_wizard

16
electrum/gui/qml/qewizard.py

@ -4,7 +4,7 @@ from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from PyQt5.QtQml import QQmlApplicationEngine
from electrum.logging import get_logger
from electrum.gui.wizard import NewWalletWizard
from electrum.gui.wizard import NewWalletWizard, ServerConnectWizard
class QEAbstractWizard(QObject):
_logger = get_logger(__name__)
@ -99,3 +99,17 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard):
except Exception as e:
self._logger.error(repr(e))
self.createError.emit(str(e))
class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard):
def __init__(self, daemon, parent = None):
ServerConnectWizard.__init__(self, daemon)
QEAbstractWizard.__init__(self, parent)
self._daemon = daemon
# attach view names
self.navmap_merge({
'autoconnect': { 'gui': 'WCAutoConnect' },
'proxy_config': { 'gui': 'WCProxyConfig' },
'server_config': { 'gui': 'WCServerConfig' },
})

24
electrum/gui/wizard.py

@ -287,3 +287,27 @@ class NewWalletWizard(AbstractWizard):
db.load_plugins()
db.write(storage)
class ServerConnectWizard(AbstractWizard):
_logger = get_logger(__name__)
def __init__(self, daemon):
self.navmap = {
'autoconnect': {
'next': 'proxy_config',
'last': lambda v,d: d['autoconnect']
},
'proxy_config': {
'next': 'server_config'
},
'server_config': {
'last': True
}
}
self._daemon = daemon
def start(self, initial_data = {}):
self.reset()
self._current = WizardViewState('autoconnect', initial_data, {})
return self._current

Loading…
Cancel
Save