diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2020-03-26 23:08:00 +0100 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2020-03-26 23:08:02 +0100 |
commit | e93654fab836d63ef055e7ffd392481880256ac5 (patch) | |
tree | c8864c4362197ad2d4b262f8b2af31691562695d | |
parent | 5e292af036c845bc11b73ccb80ad7e17387b5331 (diff) | |
download | d-feet-e93654fab836d63ef055e7ffd392481880256ac5.tar.gz |
DFeetWindow: factor out connect_to(address)
Reused in the following patch. Also returns whether attempt was
successfull.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
-rw-r--r-- | src/dfeet/window.py | 30 |
1 files 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): |