[d-feet/aleksander/ui: 8/10] window: allow closing currently visible bus
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [d-feet/aleksander/ui: 8/10] window: allow closing currently visible bus
- Date: Tue, 1 Oct 2013 18:24:10 +0000 (UTC)
commit b8998deece9b7ec0de340f2e10c5461d5bcf7071
Author: Aleksander Morgado <aleksander lanedo com>
Date: Tue Oct 1 19:20:33 2013 +0200
window: allow closing currently visible bus
data/ui/mainwindow.ui | 6 ++++++
src/dfeet/window.py | 26 ++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/mainwindow.ui b/data/ui/mainwindow.ui
index c871f40..45cca51 100644
--- a/data/ui/mainwindow.ui
+++ b/data/ui/mainwindow.ui
@@ -16,6 +16,12 @@
<attribute name="action">win.connect-other-bus</attribute>
</item>
</section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Close Bus</attribute>
+ <attribute name="action">win.close-bus</attribute>
+ </item>
+ </section>
</menu>
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
diff --git a/src/dfeet/window.py b/src/dfeet/window.py
index d43cdcc..da0aae0 100644
--- a/src/dfeet/window.py
+++ b/src/dfeet/window.py
@@ -67,6 +67,9 @@ class DFeetWindow(Gtk.ApplicationWindow):
self.set_titlebar(header)
self.stack = ui.get_widget('buses_stack')
self.add(self.stack)
+ self.__stack_child_added_id = self.stack.connect('add', self.__stack_child_added_cb)
+ self.__stack_child_removed_id = self.stack.connect('remove', self.__stack_child_removed_cb)
+ self.connect('destroy', self.__on_destroy)
#create bus history list and load entries from settings
self.__bus_history = []
@@ -88,6 +91,22 @@ class DFeetWindow(Gtk.ApplicationWindow):
def bus_history(self, history_new):
self.__bus_history = history_new
+ def __stack_child_added_cb(self, stack, child):
+ existing = self.lookup_action('close-bus')
+ if existing is None:
+ action = Gio.SimpleAction.new('close-bus', None)
+ action.connect('activate', self.__action_close_bus_cb)
+ self.add_action(action)
+
+ def __stack_child_removed_cb(self, stack, child):
+ current = self.stack.get_visible_child()
+ if current is None:
+ self.remove_action('close-bus')
+
+ def __on_destroy(self, data=None):
+ self.stack.disconnect(self.__stack_child_added_id)
+ self.stack.disconnect(self.__stack_child_removed_id)
+
def __action_connect_system_bus_cb(self, action, parameter):
"""connect to system bus"""
try:
@@ -131,6 +150,13 @@ class DFeetWindow(Gtk.ApplicationWindow):
print("can not connect to '%s': %s" % (address, str(e)))
dialog.destroy()
+ def __action_close_bus_cb(self, action, parameter):
+ """close current bus"""
+ try:
+ current = self.stack.get_visible_child()
+ self.stack.remove (current)
+ except Exception as e:
+ print(e)
def __delete_cb(self, main_window, event):
"""store some settings"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]