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. 5
      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 property string path
enter: null // disable transition wiz: Daemon.newWalletWizard
property QtObject wiz: Daemon.newWalletWizard
Component.onCompleted: { Component.onCompleted: {
var view = wiz.start_wizard() var view = wiz.start_wizard()

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

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

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

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

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

@ -11,7 +11,8 @@ Dialog {
height: parent.height height: parent.height
property var wizard_data property var wizard_data
property alias pages : pages property alias pages: pages
property QtObject wiz
function _setWizardData(wdata) { function _setWizardData(wdata) {
wizard_data = {} wizard_data = {}
@ -49,7 +50,6 @@ Dialog {
if (newview.view) { if (newview.view) {
console.log('next view: ' + newview.view) console.log('next view: ' + newview.view)
var newpage = _loadNextComponent(newview.view, newview.wizard_data) var newpage = _loadNextComponent(newview.view, newview.wizard_data)
newpage.last = wiz.isLast(newview.wizard_data)
} else { } else {
console.log('END') console.log('END')
} }
@ -57,7 +57,6 @@ Dialog {
page.prev.connect(function() { page.prev.connect(function() {
var wdata = wiz.prev() var wdata = wiz.prev()
console.log('prev view data: ' + JSON.stringify(wdata)) console.log('prev view data: ' + JSON.stringify(wdata))
page.last = wiz.isLast(wdata)
}) })
Object.assign(page.wizard_data, wdata) // deep copy Object.assign(page.wizard_data, wdata) // deep copy
page.ready = true // signal page it can access wizard_data 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 valid
property bool last: false property bool last: false
property bool ready: 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 .qelnpaymentdetails import QELnPaymentDetails
from .qechanneldetails import QEChannelDetails from .qechanneldetails import QEChannelDetails
from .qeswaphelper import QESwapHelper from .qeswaphelper import QESwapHelper
from .qewizard import QENewWalletWizard from .qewizard import QENewWalletWizard, QEServerConnectWizard
notification = None notification = None
@ -219,6 +219,7 @@ class ElectrumQmlApplication(QGuiApplication):
qmlRegisterUncreatableType(QEAmount, 'org.electrum', 1, 0, 'Amount', 'Amount can only be used as property') 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(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) 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 .qefx import QEFX
from .qewallet import QEWallet from .qewallet import QEWallet
from .qewalletdb import QEWalletDB from .qewalletdb import QEWalletDB
from .qewizard import QENewWalletWizard from .qewizard import QENewWalletWizard, QEServerConnectWizard
# wallet list model. supports both wallet basenames (wallet file basenames) # wallet list model. supports both wallet basenames (wallet file basenames)
# and whole Wallet instances (loaded wallets) # and whole Wallet instances (loaded wallets)
@ -123,6 +123,7 @@ class QEDaemon(AuthMixin, QObject):
_available_wallets = None _available_wallets = None
_current_wallet = None _current_wallet = None
_new_wallet_wizard = None _new_wallet_wizard = None
_server_connect_wizard = None
_path = None _path = None
_use_single_password = False _use_single_password = False
_password = None _password = None
@ -131,6 +132,7 @@ class QEDaemon(AuthMixin, QObject):
availableWalletsChanged = pyqtSignal() availableWalletsChanged = pyqtSignal()
fxChanged = pyqtSignal() fxChanged = pyqtSignal()
newWalletWizardChanged = pyqtSignal() newWalletWizardChanged = pyqtSignal()
serverConnectWizardChanged = pyqtSignal()
walletLoaded = pyqtSignal() walletLoaded = pyqtSignal()
walletRequiresPassword = pyqtSignal() walletRequiresPassword = pyqtSignal()
@ -296,3 +298,10 @@ class QEDaemon(AuthMixin, QObject):
self._new_wallet_wizard = QENewWalletWizard(self) self._new_wallet_wizard = QENewWalletWizard(self)
return self._new_wallet_wizard 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 PyQt5.QtQml import QQmlApplicationEngine
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.gui.wizard import NewWalletWizard from electrum.gui.wizard import NewWalletWizard, ServerConnectWizard
class QEAbstractWizard(QObject): class QEAbstractWizard(QObject):
_logger = get_logger(__name__) _logger = get_logger(__name__)
@ -99,3 +99,17 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard):
except Exception as e: except Exception as e:
self._logger.error(repr(e)) self._logger.error(repr(e))
self.createError.emit(str(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.load_plugins()
db.write(storage) 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