From e93654fab836d63ef055e7ffd392481880256ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 26 Mar 2020 23:08:00 +0100 Subject: DFeetWindow: factor out connect_to(address) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reused in the following patch. Also returns whether attempt was successfull. Signed-off-by: Marc-André Lureau --- src/dfeet/window.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/dfeet/window.py b/src/dfeet/window.py index bfc08cc..2a91a23 100644 --- a/src/dfeet/window.py +++ b/src/dfeet/window.py @@ -147,6 +147,23 @@ class DFeetWindow(Gtk.ApplicationWindow): except Exception as e: print(e) + def connect_to(self, address): + """connect to given bus address""" + try: + bw = BusWatch(self.data_dir, address) + self.stack.add_titled(bw.box_bus, address, address) + # Fill history + if address in self.bus_history: + self.bus_history.remove(address) + self.bus_history.insert(0, address) + # Truncating history + if (len(self.bus_history) > self.HISTORY_MAX_SIZE): + self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE] + except Exception as e: + print("can not connect to '%s': %s" % (address, str(e))) + return False + return True + def __action_connect_other_bus_cb(self, action, parameter): """connect to other bus""" dialog = AddConnectionDialog(self.data_dir, self, self.bus_history) @@ -160,18 +177,7 @@ class DFeetWindow(Gtk.ApplicationWindow): self.activate_action('connect-system-bus', None) return else: - try: - bw = BusWatch(self.data_dir, address) - self.stack.add_titled(bw.box_bus, address, address) - # Fill history - if address in self.bus_history: - self.bus_history.remove(address) - self.bus_history.insert(0, address) - # Truncating history - if (len(self.bus_history) > self.HISTORY_MAX_SIZE): - self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE] - except Exception as e: - print("can not connect to '%s': %s" % (address, str(e))) + self.connect_to(address) dialog.destroy() def __action_close_bus_cb(self, action, parameter): -- cgit v1.2.1