Browse Source

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.
patch-4
Siddhant Chawla 3 years ago
committed by GitHub
parent
commit
3a583885d9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 53
      electrum/gui/kivy/main.kv
  2. 12
      electrum/gui/kivy/main_window.py
  3. 49
      electrum/gui/kivy/uix/ui_screens/first_screen.kv
  4. 20
      electrum/gui/kivy/uix/ui_screens/initial_network_setup.kv
  5. 53
      electrum/gui/kivy/uix/ui_screens/network.kv

53
electrum/gui/kivy/main.kv

@ -430,6 +430,59 @@
Clock.schedule_once(lambda dt: app.popup_dialog(self.name), 0.05)
self.state = 'normal'
<NetworkDialog@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
BoxLayout:
orientation: 'vertical'

12
electrum/gui/kivy/main_window.py

@ -124,14 +124,21 @@ class ElectrumWindow(App, Logger):
auto_connect = BooleanProperty(False)
def on_auto_connect(self, instance, x):
net_params = self.network.get_parameters()
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()
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):
@ -639,6 +646,11 @@ 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'])
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

49
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()

20
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()

53
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

Loading…
Cancel
Save