tadd proxy settings to kivy GUI - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 59b0b51f248feb0e25cac238f329c31c7b3eb4b0 DIR parent 2fcdd458b3af68b46fd9e7b2f42921c924b9ba9a HTML Author: ThomasV <thomasv@electrum.org> Date: Mon, 27 Mar 2017 18:59:48 +0200 add proxy settings to kivy GUI Diffstat: M gui/kivy/uix/dialogs/settings.py | 38 ++++++++++++++++++++++++++++++- A gui/kivy/uix/ui_screens/proxy.kv | 60 +++++++++++++++++++++++++++++++ M gui/qt/network_dialog.py | 8 -------- M lib/network.py | 9 ++++++++- 4 files changed, 105 insertions(+), 10 deletions(-) --- DIR diff --git a/gui/kivy/uix/dialogs/settings.py b/gui/kivy/uix/dialogs/settings.py t@@ -97,6 +97,12 @@ Builder.load_string(''' action: partial(root.network_dialog, self) CardSeparator SettingsItem: + status: root.proxy_status() + title: _('Proxy') + ': ' + self.status + description: _("Proxy configuration.") + action: partial(root.proxy_dialog, self) + CardSeparator + SettingsItem: status: 'ON' if bool(app.plugins.get('labels')) else 'OFF' title: _('Labels Sync') + ': ' + self.status description: _("Save and synchronize your labels.") t@@ -137,6 +143,7 @@ class SettingsDialog(Factory.Popup): self._fee_dialog = None self._rbf_dialog = None self._network_dialog = None + self._proxy_dialog = None self._language_dialog = None self._unit_dialog = None self._coinselect_dialog = None t@@ -195,10 +202,39 @@ class SettingsDialog(Factory.Popup): if value: self.app.network.blockchain.set_checkpoint(height, value) item.status = self.checkpoint_status() - self._checkpoint_dialog = CheckpointDialog(self.app.network, callback) self._checkpoint_dialog.open() + def proxy_status(self): + server, port, protocol, proxy, auto_connect = self.app.network.get_parameters() + return proxy.get('host') +':' + proxy.get('port') if proxy else _('None') + + def proxy_dialog(self, item, dt): + if self._proxy_dialog is None: + server, port, protocol, proxy, auto_connect = self.app.network.get_parameters() + def callback(popup): + if popup.ids.mode.text != 'None': + proxy = { + 'mode':popup.ids.mode.text, + 'host':popup.ids.host.text, + 'port':popup.ids.port.text, + 'user':popup.ids.user.text, + 'password':popup.ids.password.text + } + else: + proxy = None + self.app.network.set_parameters(server, port, protocol, proxy, auto_connect) + item.status = self.proxy_status() + popup = Builder.load_file('gui/kivy/uix/ui_screens/proxy.kv') + popup.ids.mode.text = proxy.get('mode') if proxy else 'None' + popup.ids.host.text = proxy.get('host') if proxy else '' + popup.ids.port.text = proxy.get('port') if proxy else '' + popup.ids.user.text = proxy.get('user') if proxy else '' + popup.ids.password.text = proxy.get('password') if proxy else '' + popup.on_dismiss = lambda: callback(popup) + self._proxy_dialog = popup + self._proxy_dialog.open() + def network_dialog(self, item, dt): if self._network_dialog is None: server, port, protocol, proxy, auto_connect = self.app.network.get_parameters() DIR diff --git a/gui/kivy/uix/ui_screens/proxy.kv b/gui/kivy/uix/ui_screens/proxy.kv t@@ -0,0 +1,60 @@ +Popup: + id: nd + title: _('Proxy') + BoxLayout: + orientation: 'vertical' + padding: '10dp' + spacing: '10dp' + GridLayout: + cols: 2 + Label: + text: _('Proxy mode') + Spinner: + id: mode + height: '48dp' + size_hint_y: None + text: '' + values: ['None', 'socks4', 'socks5', 'http'] + Label: + text: _('Host') + TextInput: + id: host + height: '48dp' + size_hint_y: None + text: '' + disabled: mode.text == 'None' + Label: + text: _('Port') + TextInput: + id: port + height: '48dp' + size_hint_y: None + text: '' + disabled: mode.text == 'None' + Label: + text: _('Username') + TextInput: + id: user + height: '48dp' + size_hint_y: None + text: '' + disabled: mode.text == 'None' + Label: + text: _('Password') + TextInput: + id: password + height: '48dp' + size_hint_y: None + text: '' + disabled: mode.text == 'None' + Widget: + size_hint: 1, 0.1 + BoxLayout: + Widget: + size_hint: 0.5, None + Button: + size_hint: 0.5, None + height: '48dp' + text: _('OK') + on_release: + nd.dismiss() DIR diff --git a/gui/qt/network_dialog.py b/gui/qt/network_dialog.py t@@ -318,12 +318,6 @@ class NetworkChoiceLayout(object): host = str(self.server_host.text()) port = str(self.server_port.text()) protocol = 's' if self.ssl_cb.isChecked() else 't' - # sanitize - try: - deserialize_server(serialize_server(host, port, protocol)) - except: - return - if self.proxy_mode.currentText() != 'NONE': proxy = { 'mode':str(self.proxy_mode.currentText()).lower(), 'host':str(self.proxy_host.text()), t@@ -332,9 +326,7 @@ class NetworkChoiceLayout(object): 'password':str(self.proxy_password.text())} else: proxy = None - auto_connect = self.autoconnect_cb.isChecked() - self.network.set_parameters(host, port, protocol, proxy, auto_connect) self.network.blockchain.set_checkpoint(self.checkpoint_height, self.checkpoint_value) DIR diff --git a/lib/network.py b/lib/network.py t@@ -461,13 +461,20 @@ class Network(util.DaemonThread): def set_parameters(self, host, port, protocol, proxy, auto_connect): proxy_str = serialize_proxy(proxy) server = serialize_server(host, port, protocol) + # sanitize parameters + try: + deserialize_server(serialize_server(host, port, protocol)) + if proxy: + proxy_modes.index(proxy["mode"]) + 1 + int(proxy['port']) + except: + return self.config.set_key('auto_connect', auto_connect, False) self.config.set_key("proxy", proxy_str, False) self.config.set_key("server", server, True) # abort if changes were not allowed by config if self.config.get('server') != server or self.config.get('proxy') != proxy_str: return - self.auto_connect = auto_connect if self.proxy != proxy or self.protocol != protocol: # Restart the network defaulting to the given server