From 3a583885d9cb5f416aaa144f453d0b8c69f3f903 Mon Sep 17 00:00:00 2001 From: Siddhant Chawla Date: Thu, 9 Sep 2021 20:48:19 +0530 Subject: [PATCH] Add network setup option when Kivy GUI starts for the First time. (#7464) Offer a first-start network setup screen when using the kivy GUI, similar to what is already done in Qt. --- electrum/gui/kivy/main.kv | 53 +++++++++++++++++++ electrum/gui/kivy/main_window.py | 24 ++++++--- .../gui/kivy/uix/ui_screens/first_screen.kv | 49 +++++++++++++++++ .../uix/ui_screens/initial_network_setup.kv | 20 +++++++ electrum/gui/kivy/uix/ui_screens/network.kv | 53 +------------------ 5 files changed, 141 insertions(+), 58 deletions(-) create mode 100644 electrum/gui/kivy/uix/ui_screens/first_screen.kv create mode 100644 electrum/gui/kivy/uix/ui_screens/initial_network_setup.kv diff --git a/electrum/gui/kivy/main.kv b/electrum/gui/kivy/main.kv index d1ba7ad56..2a2470949 100644 --- a/electrum/gui/kivy/main.kv +++ b/electrum/gui/kivy/main.kv @@ -430,6 +430,59 @@ Clock.schedule_once(lambda dt: app.popup_dialog(self.name), 0.05) self.state = 'normal' + + orientation: 'vertical' + ScrollView: + GridLayout: + id: scrollviewlayout + cols:1 + size_hint: 1, None + height: self.minimum_height + padding: '10dp' + SettingsItem: + value: _("{} connections.").format(app.num_nodes) if app.num_nodes else _("Not connected") + title: _("Status") + ': ' + self.value + description: _("Connections with Electrum servers") + + CardSeparator + SettingsItem: + title: _("Server") + ': ' + app.server_host + description: _("Server used to query your history.") + action: lambda x: app.popup_dialog('server') + + CardSeparator + SettingsItem: + title: _("Proxy") + ': ' + app.proxy_str + description: _('Proxy configuration') + action: lambda x: app.popup_dialog('proxy') + + CardSeparator + SettingsItem: + title: _("Auto-connect") + ': ' + ('ON' if app.auto_connect else 'OFF') + description: _("Select your server automatically") + action: app.toggle_auto_connect + + CardSeparator + SettingsItem: + title: _("One-server mode") + ': ' + ('ON' if app.oneserver else 'OFF') + description: _("Only connect to a single server") + action: app.toggle_oneserver + disabled: app.auto_connect and not app.oneserver + + CardSeparator + SettingsItem: + value: "%d blocks" % app.num_blocks + title: _("Blockchain") + ': ' + self.value + description: _('Verified block headers') + + CardSeparator + SettingsItem: + title: _('Fork detected at block {}').format(app.blockchain_forkpoint) if app.num_chains>1 else _('No fork detected') + fork_description: (_('You are following branch') if app.auto_connect else _("Your server is on branch")) + ' ' + app.blockchain_name + description: self.fork_description if app.num_chains>1 else _('Connected nodes are on the same chain') + action: app.choose_blockchain_dialog + disabled: app.num_chains == 1 + BoxLayout: orientation: 'vertical' diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py index a0da69901..ce7f89256 100644 --- a/electrum/gui/kivy/main_window.py +++ b/electrum/gui/kivy/main_window.py @@ -124,16 +124,23 @@ class ElectrumWindow(App, Logger): auto_connect = BooleanProperty(False) def on_auto_connect(self, instance, x): net_params = self.network.get_parameters() - net_params = net_params._replace(auto_connect=self.auto_connect) - self.network.run_from_another_thread(self.network.set_parameters(net_params)) + if net_params.auto_connect != self.auto_connect: + net_params = net_params._replace(auto_connect=self.auto_connect) + self.network.run_from_another_thread(self.network.set_parameters(net_params)) + + def set_auto_connect(self, x: bool): + self.electrum_config.set_key('auto_connect',x) + self.auto_connect = x + def toggle_auto_connect(self, x): self.auto_connect = not self.auto_connect oneserver = BooleanProperty(False) def on_oneserver(self, instance, x): net_params = self.network.get_parameters() - net_params = net_params._replace(oneserver=self.oneserver) - self.network.run_from_another_thread(self.network.set_parameters(net_params)) + if net_params.oneserver != self.oneserver: + net_params = net_params._replace(oneserver=self.oneserver) + self.network.run_from_another_thread(self.network.set_parameters(net_params)) def toggle_oneserver(self, x): self.oneserver = not self.oneserver @@ -639,8 +646,13 @@ class ElectrumWindow(App, Logger): util.register_callback(self.on_channel_db, ['channel_db']) util.register_callback(self.set_num_peers, ['gossip_peers']) util.register_callback(self.set_unknown_channels, ['unknown_channels']) - # load wallet - self.load_wallet_by_name(self.electrum_config.get_wallet_path(use_gui_last_wallet=True)) + + if self.electrum_config.get('auto_connect') is None: + # load_wallet will be called in this code-path too at a later stage, after initial network setup is completed. + self.popup_dialog("first_screen") + else: + # load wallet + self.load_wallet_by_name(self.electrum_config.get_wallet_path(use_gui_last_wallet=True)) # URI passed in config uri = self.electrum_config.get('url') if uri: diff --git a/electrum/gui/kivy/uix/ui_screens/first_screen.kv b/electrum/gui/kivy/uix/ui_screens/first_screen.kv new file mode 100644 index 000000000..f2c84e482 --- /dev/null +++ b/electrum/gui/kivy/uix/ui_screens/first_screen.kv @@ -0,0 +1,49 @@ +Popup: + id: nd + title: _('Network Setup') + was_cancelled: True + auto_connect: True + on_dismiss: app.stop() if nd.was_cancelled else None + BoxLayout: + orientation: 'vertical' + padding: '10dp' + spacing: '10dp' + TopLabel: + text: _("How do you want to connect to a server?") + font_size: '18sp' + bold: True + TopLabel: + text: _("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.") + font_size: '16sp' + spacing: '10dp' + GridLayout: + cols: 2 + size_hint: 1, 0.1 + height: self.minimum_height + padding: '10dp' + spacing: '10dp' + Label: + text: _("Auto Connect") + CheckBox: + group: "NetworkConfig" + active: True + on_active: nd.auto_connect = True + Label: + text: _("Select server manually") + CheckBox: + group: "NetworkConfig" + on_active: nd.auto_connect = False + BoxLayout: + orientation:'horizontal' + size_hint: 1, 0.2 + Widget: + size_hint: 0.5, None + Button: + size_hint: 0.5, None + height: '48dp' + text: _('Next') + on_release: + app.set_auto_connect(nd.auto_connect) if nd.auto_connect else None + app.load_wallet_by_name(app.electrum_config.get_wallet_path(use_gui_last_wallet=True)) if nd.auto_connect else app.popup_dialog("initial_network_setup") + nd.was_cancelled = False + nd.dismiss() \ No newline at end of file diff --git a/electrum/gui/kivy/uix/ui_screens/initial_network_setup.kv b/electrum/gui/kivy/uix/ui_screens/initial_network_setup.kv new file mode 100644 index 000000000..d3291fcb2 --- /dev/null +++ b/electrum/gui/kivy/uix/ui_screens/initial_network_setup.kv @@ -0,0 +1,20 @@ +Popup: + id: nd + title: _('Network Setup') + was_cancelled: True + on_dismiss: app.stop() if nd.was_cancelled else None + NetworkDialog + BoxLayout: + orientation:'horizontal' + size_hint: 1, 0.2 + Widget: + size_hint: 0.5, None + Button: + size_hint: 0.5, None + height: '48dp' + text: _('Next') + on_release: + app.set_auto_connect(app.auto_connect) + app.load_wallet_by_name(app.electrum_config.get_wallet_path(use_gui_last_wallet=True)) + nd.was_cancelled = False + nd.dismiss() diff --git a/electrum/gui/kivy/uix/ui_screens/network.kv b/electrum/gui/kivy/uix/ui_screens/network.kv index 44b2c9e59..979a0453a 100644 --- a/electrum/gui/kivy/uix/ui_screens/network.kv +++ b/electrum/gui/kivy/uix/ui_screens/network.kv @@ -1,55 +1,4 @@ Popup: id: nd title: _('Network') - BoxLayout: - orientation: 'vertical' - ScrollView: - GridLayout: - id: scrollviewlayout - cols:1 - size_hint: 1, None - height: self.minimum_height - padding: '10dp' - SettingsItem: - value: _("{} connections.").format(app.num_nodes) if app.num_nodes else _("Not connected") - title: _("Status") + ': ' + self.value - description: _("Connections with Electrum servers") - - CardSeparator - SettingsItem: - title: _("Server") + ': ' + app.server_host - description: _("Server used to query your history.") - action: lambda x: app.popup_dialog('server') - - CardSeparator - SettingsItem: - title: _("Proxy") + ': ' + app.proxy_str - description: _('Proxy configuration') - action: lambda x: app.popup_dialog('proxy') - - CardSeparator - SettingsItem: - title: _("Auto-connect") + ': ' + ('ON' if app.auto_connect else 'OFF') - description: _("Select your server automatically") - action: app.toggle_auto_connect - - CardSeparator - SettingsItem: - title: _("One-server mode") + ': ' + ('ON' if app.oneserver else 'OFF') - description: _("Only connect to a single server") - action: app.toggle_oneserver - disabled: app.auto_connect and not app.oneserver - - CardSeparator - SettingsItem: - value: "%d blocks" % app.num_blocks - title: _("Blockchain") + ': ' + self.value - description: _('Verified block headers') - - CardSeparator - SettingsItem: - title: _('Fork detected at block {}').format(app.blockchain_forkpoint) if app.num_chains>1 else _('No fork detected') - fork_description: (_('You are following branch') if app.auto_connect else _("Your server is on branch")) + ' ' + app.blockchain_name - description: self.fork_description if app.num_chains>1 else _('Connected nodes are on the same chain') - action: app.choose_blockchain_dialog - disabled: app.num_chains == 1 + NetworkDialog