1
0

qt: show terms of use as first window on setup

This commit is contained in:
f321x
2025-05-07 09:50:42 +02:00
parent cec2089917
commit 802c316edb
6 changed files with 145 additions and 30 deletions

View File

@@ -500,6 +500,19 @@ class ElectrumGui(BaseElectrumGui, Logger):
window.close()
self._create_window_for_wallet(wallet)
def ask_terms_of_use(self):
"""Ask the user to accept the terms of use.
This is only shown if the user has not accepted them yet.
"""
if self.config.TERMS_OF_USE_ACCEPTED:
return
from electrum.gui.qt.wizard.terms_of_use import QETermsOfUseWizard
dialog = QETermsOfUseWizard(self.config, self.app)
result = dialog.exec()
if result == QDialog.DialogCode.Rejected:
self.logger.info('terms of use not accepted by user')
raise UserCancelled()
def init_network(self):
"""Start the network, including showing a first-start network dialog if config does not exist."""
if self.daemon.network:
@@ -524,6 +537,7 @@ class ElectrumGui(BaseElectrumGui, Logger):
Exception_Hook.maybe_setup(config=self.config)
# start network, and maybe show first-start network-setup
try:
self.ask_terms_of_use()
self.init_network()
except UserCancelled:
return

View File

@@ -27,7 +27,7 @@ class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard):
# attach gui classes
self.navmap_merge({
'welcome': {'gui': WCWelcome, 'params': {'icon': ''}},
'welcome': {'gui': WCWelcome},
'proxy_config': {'gui': WCProxyConfig},
'server_config': {'gui': WCServerConfig},
})
@@ -35,31 +35,22 @@ class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard):
class WCWelcome(WizardComponent):
def __init__(self, parent, wizard):
WizardComponent.__init__(self, parent, wizard, title='')
WizardComponent.__init__(self, parent, wizard, title='Network Configuration')
self.wizard_title = _('Electrum Bitcoin Wallet')
self.use_advanced_w = QCheckBox(_('Advanced network settings'))
self.use_advanced_w.setChecked(False)
self.use_advanced_w.stateChanged.connect(self.on_advanced_changed)
self.img_label = QLabel()
pixmap = QPixmap(icon_path('electrum_darkblue_1.png'))
self.img_label.setPixmap(pixmap)
self.img_label2 = QLabel()
pixmap = QPixmap(icon_path('electrum_text.png'))
self.img_label2.setPixmap(pixmap)
hbox_img = QHBoxLayout()
hbox_img.addStretch(1)
hbox_img.addWidget(self.img_label)
hbox_img.addWidget(self.img_label2)
hbox_img.addStretch(1)
self.help_label = QLabel()
self.help_label.setText("\n".join([
_("Optional settings to customize your network connection."),
_("If you are unsure what this is, leave them unchecked and Electrum will automatically "
"select servers."),
]))
self.help_label.setWordWrap(True)
self.config_proxy_w = QCheckBox(_('Configure Proxy'))
self.config_proxy_w.setChecked(False)
self.config_proxy_w.setVisible(False)
self.config_proxy_w.stateChanged.connect(self.on_updated)
self.config_server_w = QCheckBox(_('Select Server'))
self.config_server_w.setChecked(False)
self.config_server_w.setVisible(False)
self.config_server_w.stateChanged.connect(self.on_updated)
options_w = QWidget()
vbox = QVBoxLayout()
@@ -68,21 +59,15 @@ class WCWelcome(WizardComponent):
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.AlignmentFlag.AlignHCenter)
self.layout().addWidget(options_w, False, Qt.AlignmentFlag.AlignHCenter)
self.layout().addWidget(self.help_label)
self.layout().addSpacing(30)
self.layout().addWidget(options_w, False, Qt.AlignmentFlag.AlignLeft)
self._valid = True
def on_advanced_changed(self):
self.config_proxy_w.setVisible(self.use_advanced_w.isChecked())
self.config_server_w.setVisible(self.use_advanced_w.isChecked())
self.on_updated()
def apply(self):
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()
self.wizard_data['use_defaults'] = not (self.config_server_w.isChecked() or self.config_proxy_w.isChecked())
self.wizard_data['want_proxy'] = self.config_proxy_w.isChecked()
self.wizard_data['autoconnect'] = not self.config_server_w.isChecked()
class WCProxyConfig(WizardComponent):

View File

@@ -0,0 +1,76 @@
from typing import TYPE_CHECKING
from PyQt6.QtCore import QTimer
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QLabel, QHBoxLayout, QScrollArea
from electrum.i18n import _
from electrum.wizard import TermsOfUseWizard
from electrum.gui.qt.util import icon_path
from electrum.gui import messages
from .wizard import QEAbstractWizard, WizardComponent
if TYPE_CHECKING:
from electrum.simple_config import SimpleConfig
from electrum.gui.qt import QElectrumApplication
class QETermsOfUseWizard(TermsOfUseWizard, QEAbstractWizard):
def __init__(self, config: 'SimpleConfig', app: 'QElectrumApplication'):
TermsOfUseWizard.__init__(self, config)
QEAbstractWizard.__init__(self, config, app)
self.window_title = _('Terms of Use')
self.finish_label = _('I Accept')
self.title.setVisible(False)
# self.window().setMinimumHeight(565) # Enough to show the whole text without scrolling
self.next_button.setToolTip("You accept the Terms of Use by clicking this button.")
# attach gui classes
self.navmap_merge({
'terms_of_use': {'gui': WCTermsOfUseScreen, 'params': {'icon': ''}},
})
class WCTermsOfUseScreen(WizardComponent):
def __init__(self, parent, wizard):
WizardComponent.__init__(self, parent, wizard, title='')
self.wizard_title = _('Electrum Terms of Use')
self.img_label = QLabel()
pixmap = QPixmap(icon_path('electrum_darkblue_1.png'))
self.img_label.setPixmap(pixmap)
self.img_label2 = QLabel()
pixmap = QPixmap(icon_path('electrum_text.png'))
self.img_label2.setPixmap(pixmap)
hbox_img = QHBoxLayout()
hbox_img.addStretch(1)
hbox_img.addWidget(self.img_label)
hbox_img.addWidget(self.img_label2)
hbox_img.addStretch(1)
self.layout().addLayout(hbox_img)
self.tos_label = QLabel()
self.tos_label.setText(messages.MSG_TERMS_OF_USE)
self.tos_label.setWordWrap(True)
self.layout().addWidget(self.tos_label)
self._valid = False
# Find the scroll area and connect to its scrollbar
QTimer.singleShot(0, self.check_scroll_position)
def check_scroll_position(self):
# Find the scroll area
scroll_area = self.window().findChild(QScrollArea)
if scroll_area and scroll_area.verticalScrollBar():
scrollbar = scroll_area.verticalScrollBar()
def on_scroll_change(value):
if value >= scrollbar.maximum() - 5: # Allow 5 pixel margin
self._valid = True
self.on_updated()
scrollbar.valueChanged.connect(on_scroll_change)
else:
# Fallback if the scroll area is not detected
self._valid = True
self.on_updated()
def apply(self):
pass