Browse Source

qt,qml: add checkboxes for advanced network config on welcome page, remove separate proxy-ask and autoconnect pages

master
Sander van Grieken 2 years ago
parent
commit
ebcecdccce
No known key found for this signature in database
GPG Key ID: 9BCF8209EA402EBA
  1. 50
      electrum/gui/qml/components/wizard/WCAutoConnect.qml
  2. 44
      electrum/gui/qml/components/wizard/WCProxyAsk.qml
  3. 2
      electrum/gui/qml/components/wizard/WCServerConfig.qml
  4. 49
      electrum/gui/qml/components/wizard/WCWelcome.qml
  5. 2
      electrum/gui/qml/qewizard.py
  6. 110
      electrum/gui/qt/wizard/server_connect.py
  7. 8
      electrum/gui/qt/wizard/wizard.py
  8. 37
      electrum/wizard.py

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

@ -1,50 +0,0 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import "../controls"
WizardComponent {
valid: true
title: qsTr('Server')
function apply() {
wizard_data['autoconnect'] = serverconnectgroup.checkedButton.connecttype === 'auto'
}
ColumnLayout {
width: parent.width
Label {
Layout.fillWidth: true
text: qsTr('How do you want to connect to a server?')
wrapMode: Text.Wrap
}
InfoTextArea {
Layout.fillWidth: true
text: qsTr('Electrum communicates with remote servers to get information about your transactions and addresses. The servers all fulfill the same purpose only differing in hardware. In most cases you simply want to let Electrum pick one at random. However if you prefer feel free to select a server manually.')
}
ButtonGroup {
id: serverconnectgroup
onCheckedButtonChanged: checkIsLast()
}
ElRadioButton {
Layout.fillWidth: true
ButtonGroup.group: serverconnectgroup
property string connecttype: 'auto'
text: qsTr('Auto connect')
checked: true
}
ElRadioButton {
Layout.fillWidth: true
ButtonGroup.group: serverconnectgroup
property string connecttype: 'manual'
text: qsTr('Select servers manually')
}
}
}

44
electrum/gui/qml/components/wizard/WCProxyAsk.qml

@ -1,44 +0,0 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
import "../controls"
WizardComponent {
valid: true
title: qsTr('Proxy')
function apply() {
wizard_data['want_proxy'] = wantproxygroup.checkedButton.wantproxy
}
ColumnLayout {
width: parent.width
Label {
Layout.fillWidth: true
text: qsTr('Do you use a local proxy service such as TOR to reach the internet?')
wrapMode: Text.Wrap
}
ButtonGroup {
id: wantproxygroup
onCheckedButtonChanged: checkIsLast()
}
ElRadioButton {
ButtonGroup.group: wantproxygroup
property bool wantproxy: true
text: qsTr('Yes')
}
ElRadioButton {
ButtonGroup.group: wantproxygroup
property bool wantproxy: false
text: qsTr('No')
checked: true
}
}
}

2
electrum/gui/qml/components/wizard/WCServerConfig.qml

@ -10,7 +10,7 @@ WizardComponent {
title: qsTr('Server') title: qsTr('Server')
function apply() { function apply() {
wizard_data['autoconnect'] = sc.address == "" wizard_data['autoconnect'] = sc.address.trim() == ""
wizard_data['server'] = sc.address wizard_data['server'] = sc.address
} }

49
electrum/gui/qml/components/wizard/WCWelcome.qml

@ -2,22 +2,16 @@ import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Controls import QtQuick.Controls
// import org.electrum 1.0
import "../controls" import "../controls"
WizardComponent { WizardComponent {
valid: true valid: true
title: qsTr('Electrum Bitcoin Wallet') wizard_title: qsTr('Electrum Bitcoin Wallet')
function apply() { function apply() {
wizard_data['use_defaults'] = use_defaults.checked wizard_data['use_defaults'] = !config_advanced.checked
wizard_data['want_proxy'] = false wizard_data['want_proxy'] = config_advanced.checked && config_proxy.checked
if (use_defaults.checked) { wizard_data['autoconnect'] = !config_server.checked || !config_advanced.checked
wizard_data['autoconnect'] = true
} else {
wizard_data['autoconnect'] = undefined
}
} }
ColumnLayout { ColumnLayout {
@ -29,22 +23,37 @@ WizardComponent {
source: Qt.resolvedUrl('../../../icons/electrum_presplash.png') source: Qt.resolvedUrl('../../../icons/electrum_presplash.png')
// reduce spacing a bit // reduce spacing a bit
Layout.topMargin: -50 Layout.topMargin: -50
Layout.bottomMargin: -160 Layout.bottomMargin: -120
} }
Label { CheckBox {
id: config_advanced
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
text: qsTr('Welcome') text: qsTr('Advanced network settings')
font.pixelSize: constants.fontSizeXLarge checked: false
Layout.bottomMargin: constants.paddingXXLarge onCheckedChanged: checkIsLast()
} }
CheckBox { ColumnLayout {
id: use_defaults
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
text: qsTr('Use default network settings')
checked: true opacity: config_advanced.checked ? 1 : 0
onCheckedChanged: checkIsLast() Behavior on opacity {
NumberAnimation { duration: 300 }
}
CheckBox {
id: config_proxy
text: qsTr('Configure Proxy')
checked: false
onCheckedChanged: checkIsLast()
}
CheckBox {
id: config_server
text: qsTr('Select Server')
checked: false
onCheckedChanged: checkIsLast()
}
} }
} }
} }

2
electrum/gui/qml/qewizard.py

@ -148,8 +148,6 @@ class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard):
# attach view names # attach view names
self.navmap_merge({ self.navmap_merge({
'welcome': {'gui': 'WCWelcome'}, 'welcome': {'gui': 'WCWelcome'},
'autoconnect': {'gui': 'WCAutoConnect'},
'proxy_ask': {'gui': 'WCProxyAsk'},
'proxy_config': {'gui': 'WCProxyConfig'}, 'proxy_config': {'gui': 'WCProxyConfig'},
'server_config': {'gui': 'WCServerConfig'}, 'server_config': {'gui': 'WCServerConfig'},
}) })

110
electrum/gui/qt/wizard/server_connect.py

@ -2,12 +2,12 @@ from typing import TYPE_CHECKING
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QCheckBox, QLabel, QHBoxLayout from PyQt5.QtWidgets import QCheckBox, QLabel, QHBoxLayout, QVBoxLayout, QWidget
from electrum.i18n import _ from electrum.i18n import _
from electrum.wizard import ServerConnectWizard from electrum.wizard import ServerConnectWizard
from electrum.gui.qt.network_dialog import ProxyWidget, ServerWidget from electrum.gui.qt.network_dialog import ProxyWidget, ServerWidget
from electrum.gui.qt.util import ChoiceWidget, icon_path from electrum.gui.qt.util import icon_path
from .wizard import QEAbstractWizard, WizardComponent from .wizard import QEAbstractWizard, WizardComponent
if TYPE_CHECKING: if TYPE_CHECKING:
@ -23,12 +23,11 @@ class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard):
ServerConnectWizard.__init__(self, daemon) ServerConnectWizard.__init__(self, daemon)
QEAbstractWizard.__init__(self, config, app) QEAbstractWizard.__init__(self, config, app)
self.window_title = _('Network and server configuration') self.window_title = _('Network and server configuration')
self.finish_label = _('Next')
# attach gui classes # attach gui classes
self.navmap_merge({ self.navmap_merge({
'welcome': {'gui': WCWelcome, 'params': {'icon': ''}}, 'welcome': {'gui': WCWelcome, 'params': {'icon': ''}},
'proxy_ask': {'gui': WCProxyAsk},
'autoconnect': {'gui': WCAutoConnect},
'proxy_config': {'gui': WCProxyConfig}, 'proxy_config': {'gui': WCProxyConfig},
'server_config': {'gui': WCServerConfig}, 'server_config': {'gui': WCServerConfig},
}) })
@ -38,82 +37,57 @@ class WCWelcome(WizardComponent):
def __init__(self, parent, wizard): def __init__(self, parent, wizard):
WizardComponent.__init__(self, parent, wizard, title='') WizardComponent.__init__(self, parent, wizard, title='')
self.wizard_title = _('Electrum Bitcoin Wallet') self.wizard_title = _('Electrum Bitcoin Wallet')
self.use_defaults_w = QCheckBox(_('Use default network settings')) self.use_advanced_w = QCheckBox(_('Advanced network settings'))
self.use_defaults_w.setChecked(True) self.use_advanced_w.setChecked(False)
self.use_defaults_w.stateChanged.connect(self.on_updated) self.use_advanced_w.stateChanged.connect(self.on_advanced_changed)
self.img_label = QLabel() self.img_label = QLabel()
pixmap = QPixmap(icon_path('electrum_darkblue_1.png')) pixmap = QPixmap(icon_path('electrum_darkblue_1.png'))
self.img_label.setPixmap(pixmap) self.img_label.setPixmap(pixmap)
self.img_label2 = QLabel() self.img_label2 = QLabel()
pixmap = QPixmap(icon_path('electrum_text.png')) pixmap = QPixmap(icon_path('electrum_text.png'))
self.img_label2.setPixmap(pixmap) self.img_label2.setPixmap(pixmap)
hbox = QHBoxLayout() hbox_img = QHBoxLayout()
hbox.addStretch(1) hbox_img.addStretch(1)
hbox.addWidget(self.img_label) hbox_img.addWidget(self.img_label)
hbox.addWidget(self.img_label2) hbox_img.addWidget(self.img_label2)
hbox.addStretch(1) hbox_img.addStretch(1)
self.layout().addLayout(hbox)
self.welcome_label = QLabel('Welcome') self.config_proxy_w = QCheckBox(_('Configure Proxy'))
font = self.welcome_label.font() self.config_proxy_w.setChecked(False)
font.setPointSize(font.pointSize() + 3) self.config_proxy_w.setVisible(False)
self.welcome_label.setFont(font) self.config_proxy_w.stateChanged.connect(self.on_updated)
self.layout().addStretch(1) self.config_server_w = QCheckBox(_('Select Server'))
self.layout().addWidget(self.welcome_label, False, Qt.AlignHCenter) self.config_server_w.setChecked(False)
self.layout().addStretch(1) self.config_server_w.setVisible(False)
self.layout().addWidget(self.use_defaults_w, False, Qt.AlignHCenter) self.config_server_w.stateChanged.connect(self.on_updated)
self.layout().addStretch(1) options_w = QWidget()
vbox = QVBoxLayout()
vbox.addWidget(self.config_proxy_w)
vbox.addWidget(self.config_server_w)
vbox.addStretch(1)
options_w.setLayout(vbox)
self.layout().addLayout(hbox_img)
self.layout().addSpacing(50)
self.layout().addWidget(self.use_advanced_w, False, Qt.AlignHCenter)
self.layout().addWidget(options_w, False, Qt.AlignHCenter)
self._valid = True self._valid = True
def apply(self): def on_advanced_changed(self):
self.wizard_data['use_defaults'] = self.use_defaults_w.isChecked() self.config_proxy_w.setVisible(self.use_advanced_w.isChecked())
self.wizard_data['want_proxy'] = False self.config_server_w.setVisible(self.use_advanced_w.isChecked())
if self.use_defaults_w.isChecked(): self.on_updated()
self.wizard_data['autoconnect'] = True
else:
self.wizard_data['autoconnect'] = None
class WCAutoConnect(WizardComponent):
def __init__(self, parent, wizard):
WizardComponent.__init__(self, parent, wizard, title=_("How do you want to connect to a server? "))
message = _("Electrum communicates with remote servers to get "
"information about your transactions and addresses. The "
"servers all fulfill the same purpose only differing in "
"hardware. In most cases you simply want to let Electrum "
"pick one at random. However if you prefer feel free to "
"select a server manually.")
choices = [('autoconnect', _("Auto connect")),
('select', _("Select server manually"))]
self.choice_w = ChoiceWidget(message=message, choices=choices, selected='autoconnect')
self.choice_w.itemSelected.connect(self.on_updated)
self.layout().addWidget(self.choice_w)
self.layout().addStretch(1)
self._valid = True
def apply(self):
self.wizard_data['autoconnect'] = (self.choice_w.selected_item[0] == 'autoconnect')
class WCProxyAsk(WizardComponent):
def __init__(self, parent, wizard):
WizardComponent.__init__(self, parent, wizard, title=_("Proxy"))
message = _("Do you use a local proxy service such as TOR to reach the internet?")
choices = [
('no', _("No")),
('yes', _("Yes")),
]
self.choice_w = ChoiceWidget(message=message, choices=choices, selected='no')
self.layout().addWidget(self.choice_w)
self.layout().addStretch(1)
self._valid = True
def apply(self): def apply(self):
self.wizard_data['want_proxy'] = (self.choice_w.selected_item[0] == 'yes') self.wizard_data['use_defaults'] = not self.use_advanced_w.isChecked()
self.wizard_data['want_proxy'] = self.use_advanced_w.isChecked() and self.config_proxy_w.isChecked()
self.wizard_data['autoconnect'] = not self.use_advanced_w.isChecked() or not self.config_server_w.isChecked()
class WCProxyConfig(WizardComponent): class WCProxyConfig(WizardComponent):
def __init__(self, parent, wizard): def __init__(self, parent, wizard):
WizardComponent.__init__(self, parent, wizard, title=_("Proxy")) WizardComponent.__init__(self, parent, wizard, title=_('Proxy'))
self.pw = ProxyWidget(self) self.pw = ProxyWidget(self)
self.pw.proxy_cb.setChecked(True) self.pw.proxy_cb.setChecked(True)
self.pw.proxy_host.setText('localhost') self.pw.proxy_host.setText('localhost')
@ -128,11 +102,11 @@ class WCProxyConfig(WizardComponent):
class WCServerConfig(WizardComponent): class WCServerConfig(WizardComponent):
def __init__(self, parent, wizard): def __init__(self, parent, wizard):
WizardComponent.__init__(self, parent, wizard, title=_("Server")) WizardComponent.__init__(self, parent, wizard, title=_('Server'))
self.sw = ServerWidget(wizard._daemon.network, self) self.sw = ServerWidget(wizard._daemon.network, self)
self.layout().addWidget(self.sw) self.layout().addWidget(self.sw)
self._valid = True self._valid = True
def apply(self): def apply(self):
self.wizard_data['autoconnect'] = self.sw.autoconnect_cb.isChecked() self.wizard_data['autoconnect'] = self.sw.server_e.text().strip() == ''
self.wizard_data['server'] = self.sw.server_e.text() self.wizard_data['server'] = self.sw.server_e.text()

8
electrum/gui/qt/wizard/wizard.py

@ -6,7 +6,7 @@ from typing import TYPE_CHECKING
from PyQt5.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QSize from PyQt5.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QSize
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import (QDialog, QPushButton, QWidget, QLabel, QVBoxLayout, QScrollArea, from PyQt5.QtWidgets import (QDialog, QPushButton, QWidget, QLabel, QVBoxLayout, QScrollArea,
QHBoxLayout, QLayout, QStackedWidget) QHBoxLayout, QLayout)
from electrum.i18n import _ from electrum.i18n import _
from electrum.logging import get_logger from electrum.logging import get_logger
@ -40,6 +40,7 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
self.title = QLabel() self.title = QLabel()
self.window_title = '' self.window_title = ''
self.finish_label = _('Finish')
self.main_widget = ResizableStackedWidget(self) self.main_widget = ResizableStackedWidget(self)
@ -64,9 +65,6 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
error_layout = QVBoxLayout() error_layout = QVBoxLayout()
error_layout.addStretch(1) error_layout.addStretch(1)
# error_l = QLabel(_("Error!"))
# error_l.setAlignment(Qt.AlignCenter)
# error_layout.addWidget(error_l)
self.error_msg = WWLabel() self.error_msg = WWLabel()
self.error_msg.setAlignment(Qt.AlignCenter) self.error_msg.setAlignment(Qt.AlignCenter)
error_layout.addWidget(self.error_msg) error_layout.addWidget(self.error_msg)
@ -172,7 +170,7 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
self.title.setText(f'<b>{page.title}</b>' if page.title else '') self.title.setText(f'<b>{page.title}</b>' if page.title else '')
self.back_button.setText(_('Back') if self.can_go_back() else _('Cancel')) self.back_button.setText(_('Back') if self.can_go_back() else _('Cancel'))
self.back_button.setEnabled(not page.busy) self.back_button.setEnabled(not page.busy)
self.next_button.setText(_('Next') if not self.is_last(page.wizard_data) else _('Finish')) self.next_button.setText(_('Next') if not self.is_last(page.wizard_data) else self.finish_label)
self.next_button.setEnabled(not page.busy and page.valid) self.next_button.setEnabled(not page.busy and page.valid)
self.main_widget.setVisible(not page.busy and not bool(page.error)) self.main_widget.setVisible(not page.busy and not bool(page.error))
self.please_wait.setVisible(page.busy) self.please_wait.setVisible(page.busy)

37
electrum/wizard.py

@ -655,21 +655,14 @@ class ServerConnectWizard(AbstractWizard):
AbstractWizard.__init__(self) AbstractWizard.__init__(self)
self.navmap = { self.navmap = {
'welcome': { 'welcome': {
'next': 'proxy_ask', 'next': lambda d: 'proxy_config' if d['want_proxy'] else 'server_config',
'accept': self.do_configure_autoconnect, 'accept': self.do_configure_autoconnect,
'last': lambda d: d['use_defaults'] 'last': lambda d: bool(d['autoconnect'] and not d['want_proxy'])
},
'proxy_ask': {
'next': lambda d: 'proxy_config' if d['want_proxy'] else 'autoconnect'
},
'autoconnect': {
'next': 'server_config',
'accept': self.do_configure_autoconnect,
'last': lambda d: d['autoconnect']
}, },
'proxy_config': { 'proxy_config': {
'next': 'autoconnect', 'next': 'server_config',
'accept': self.do_configure_proxy 'accept': self.do_configure_proxy,
'last': lambda d: bool(d['autoconnect'])
}, },
'server_config': { 'server_config': {
'accept': self.do_configure_server, 'accept': self.do_configure_server,
@ -687,26 +680,28 @@ class ServerConnectWizard(AbstractWizard):
net_params = self._daemon.network.get_parameters() net_params = self._daemon.network.get_parameters()
if not proxy_settings['enabled']: if not proxy_settings['enabled']:
proxy_settings = None proxy_settings = None
net_params = net_params._replace(proxy=proxy_settings) net_params = net_params._replace(proxy=proxy_settings, auto_connect=bool(wizard_data['autoconnect']))
self._daemon.network.run_from_another_thread(self._daemon.network.set_parameters(net_params)) self._daemon.network.run_from_another_thread(self._daemon.network.set_parameters(net_params))
def do_configure_server(self, wizard_data: dict): def do_configure_server(self, wizard_data: dict):
self._logger.debug(f'configuring server: {wizard_data!r}') self._logger.debug(f'configuring server: {wizard_data!r}')
net_params = self._daemon.network.get_parameters() net_params = self._daemon.network.get_parameters()
try: server = ''
server = ServerAddr.from_str_with_inference(wizard_data['server']) if not wizard_data['autoconnect']:
if not server: try:
raise Exception('failed to parse server %s' % wizard_data['server']) server = ServerAddr.from_str_with_inference(wizard_data['server'])
except Exception: if not server:
return raise Exception('failed to parse server %s' % wizard_data['server'])
except Exception:
return
net_params = net_params._replace(server=server, auto_connect=wizard_data['autoconnect']) net_params = net_params._replace(server=server, auto_connect=wizard_data['autoconnect'])
self._daemon.network.run_from_another_thread(self._daemon.network.set_parameters(net_params)) self._daemon.network.run_from_another_thread(self._daemon.network.set_parameters(net_params))
def do_configure_autoconnect(self, wizard_data: dict): def do_configure_autoconnect(self, wizard_data: dict):
self._logger.debug(f'configuring autoconnect: {wizard_data!r}') self._logger.debug(f'configuring autoconnect: {wizard_data!r}')
if self._daemon.config.cv.NETWORK_AUTO_CONNECT.is_modifiable(): if self._daemon.config.cv.NETWORK_AUTO_CONNECT.is_modifiable():
if autoconnect := wizard_data.get('autoconnect') is not None: if wizard_data.get('autoconnect') is not None:
self._daemon.config.NETWORK_AUTO_CONNECT = autoconnect self._daemon.config.NETWORK_AUTO_CONNECT = wizard_data.get('autoconnect')
def start(self, initial_data: dict = None) -> WizardViewState: def start(self, initial_data: dict = None) -> WizardViewState:
if initial_data is None: if initial_data is None:

Loading…
Cancel
Save