[d-feet/aleksander/ui: 2/6] window: use a GtkHeaderBar and a gear menu



commit af60036470472f3d6f4d0540422ffb5d14773474
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Sun Sep 29 15:35:06 2013 +0200

    window: use a GtkHeaderBar and a gear menu

 data/ui/mainwindow.ui |  119 +++++++++++++++---------------------------------
 src/dfeet/window.py   |   54 +++++++++++-----------
 2 files changed, 65 insertions(+), 108 deletions(-)
---
diff --git a/data/ui/mainwindow.ui b/data/ui/mainwindow.ui
index 4a4a3a8..f780c0f 100644
--- a/data/ui/mainwindow.ui
+++ b/data/ui/mainwindow.ui
@@ -1,101 +1,56 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkAccelGroup" id="accelgroup_connect"/>
-  <object class="GtkActionGroup" id="actiongroup_connect">
-    <property name="accel_group">accelgroup_connect</property>
-    <child>
-      <object class="GtkAction" id="action_systembus_connect">
-        <property name="label" translatable="yes">Connect to System Bus</property>
-        <property name="short_label" translatable="yes">Connect to System Bus</property>
-        <property name="tooltip" translatable="yes">Connect to System Bus</property>
-        <property name="stock_id">gtk-connect</property>
-        <signal name="activate" handler="action_systembus_connect_activate_cb" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="action_sessionbus_connect">
-        <property name="label" translatable="yes">Connect to Session Bus</property>
-        <property name="short_label" translatable="yes">Connect to Session Bus</property>
-        <property name="tooltip" translatable="yes">Connect to Session Bus</property>
-        <property name="stock_id">gtk-connect</property>
-        <signal name="activate" handler="action_sessionbus_connect_activate_cb" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkAction" id="action_otherbus_connect">
-        <property name="label" translatable="yes">Connect to other Bus</property>
-        <property name="short_label" translatable="yes">Connect to other Bus</property>
-        <property name="tooltip" translatable="yes">Connect to other Bus</property>
-        <property name="stock_id">gtk-connect</property>
-        <signal name="activate" handler="action_otherbus_connect_activate_cb" swapped="no"/>
-      </object>
-    </child>
-  </object>
-  <object class="GtkVBox" id="vbox1">
+  <!-- interface-requires gtk+ 3.10 -->
+  <menu id='gear_menu'>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>Connect to System Bus</attribute>
+        <attribute name='action'>win.connect-system</attribute>
+      </item>
+      <item>
+        <attribute name='label' translatable='yes'>Connect to Session Bus</attribute>
+        <attribute name='action'>win.connect-session</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Connect to other Bus</attribute>
+        <attribute name="action">win.connect-other</attribute>
+      </item>
+    </section>
+  </menu>
+  <object class="GtkHeaderBar" id="headerbar">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
+    <property name="show-close-button">True</property>
+    <property name="title">d-feet</property>
     <child>
-      <object class="GtkMenuBar" id="menubar1">
+      <object class="GtkMenuButton" id="gear_menu_button">
         <property name="visible">True</property>
+        <property name="valign">center</property>
         <property name="can_focus">False</property>
+        <property name="action_name">win.gear-menu</property>
+        <property name="menu_model">gear_menu</property>
+        <style>
+          <class name="image-button"/>
+        </style>
         <child>
-          <object class="GtkMenuItem" id="menuitem_file">
-            <property name="use_action_appearance">False</property>
+          <object class="GtkImage" id="gear_image">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">File</property>
-            <property name="use_underline">True</property>
-            <child type="submenu">
-              <object class="GtkMenu" id="menu1">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem_systembus">
-                    <property name="related_action">action_systembus_connect</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem_sessionbus">
-                    <property name="related_action">action_sessionbus_connect</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem_otherbus">
-                    <property name="related_action">action_otherbus_connect</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                  </object>
-                </child>
-              </object>
-            </child>
+            <property name="icon_size">1</property>
+            <property name="icon_name">emblem-system-symbolic</property>
           </object>
         </child>
       </object>
       <packing>
-        <property name="expand">False</property>
-        <property name="fill">True</property>
-        <property name="position">0</property>
+        <property name="pack_type">end</property>
       </packing>
     </child>
+  </object>
+  <object class="GtkNotebook" id="display_notebook">
+    <property name="visible">True</property>
+    <property name="can_focus">True</property>
+    <property name="scrollable">True</property>
     <child>
-      <object class="GtkNotebook" id="display_notebook">
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="scrollable">True</property>
-        <child>
-          <placeholder/>
-        </child>
-      </object>
-      <packing>
-        <property name="expand">True</property>
-        <property name="fill">True</property>
-        <property name="position">1</property>
-      </packing>
+      <placeholder/>
     </child>
   </object>
 </interface>
diff --git a/src/dfeet/window.py b/src/dfeet/window.py
index f043c1a..36963c8 100644
--- a/src/dfeet/window.py
+++ b/src/dfeet/window.py
@@ -66,39 +66,45 @@ class DFeetWindow(Gtk.ApplicationWindow):
         self.data_dir = data_dir
         #setup the window
         self.set_default_size(600, 480)
-        self.set_title(self.package)
         self.set_icon_name(package)
 
-        signal_dict = {
-            'action_systembus_connect_activate_cb': self.__systembus_connect_cb,
-            'action_sessionbus_connect_activate_cb': self.__sessionbus_connect_cb,
-            'action_otherbus_connect_activate_cb': self.__otherbus_connect_cb,
-            'action_close_activate_cb': self.__close_cb,
-            }
+        #create actions
+        action = Gio.SimpleAction.new("connect-system", None)
+        action.connect("activate", self.__action_connect_system_cb)
+        self.add_action(action)
+
+        action = Gio.SimpleAction.new("connect-session", None)
+        action.connect("activate", self.__action_connect_session_cb)
+        self.add_action(action)
+
+        action = Gio.SimpleAction.new("connect-other", None)
+        action.connect("activate", self.__action_connect_other_cb)
+        self.add_action(action)
 
         #get settings
         settings = Settings.get_instance()
-
-        ui = UILoader(self.data_dir, UILoader.UI_MAINWINDOW)
-        vbox1 = ui.get_widget('vbox1')
-        self.add(vbox1)
-        self.connect('delete-event', self.__quit_dfeet)
+        self.connect('delete-event', self.__delete_cb)
         self.set_default_size(int(settings.general['windowwidth']),
                               int(settings.general['windowheight']))
 
+        #setup ui
+        ui = UILoader(self.data_dir, UILoader.UI_MAINWINDOW)
+        header = ui.get_widget('headerbar')
+        self.set_titlebar(header)
         self.notebook = ui.get_widget('display_notebook')
+        self.add(self.notebook)
         self.notebook.show_all()
         self.notebook_page_widget = ui.get_widget('box_notebook_page')
+
         #create bus history list and load entries from settings
         self.__bus_history = []
         for bus in settings.general['addbus_list']:
             if bus != '':
                 self.__bus_history.append(bus)
 
-        ui.connect_signals(signal_dict)
         #add a System- and Session Bus tab
-        self.__systembus_connect_cb(None)
-        self.__sessionbus_connect_cb(None)
+        self.activate_action("connect-system", None)
+        self.activate_action("connect-session", None)
 
         self.show_all()
 
@@ -110,7 +116,7 @@ class DFeetWindow(Gtk.ApplicationWindow):
     def bus_history(self, history_new):
         self.__bus_history = history_new
 
-    def __systembus_connect_cb(self, action):
+    def __action_connect_system_cb(self, action, parameter):
         """connect to system bus"""
         try:
             bw = BusWatch(self.data_dir, Gio.BusType.SYSTEM)
@@ -118,7 +124,7 @@ class DFeetWindow(Gtk.ApplicationWindow):
         except Exception as e:
             print(e)
 
-    def __sessionbus_connect_cb(self, action):
+    def __action_connect_session_cb(self, action, parameter):
         """connect to session bus"""
         try:
             bw = BusWatch(self.data_dir, Gio.BusType.SESSION)
@@ -126,17 +132,17 @@ class DFeetWindow(Gtk.ApplicationWindow):
         except Exception as e:
             print(e)
 
-    def __otherbus_connect_cb(self, action):
+    def __action_connect_other_cb(self, action, parameter):
         """connect to other bus"""
         dialog = AddConnectionDialog(self.data_dir, self, self.bus_history)
         result = dialog.run()
         if result == Gtk.ResponseType.OK:
             address = dialog.address
             if address == 'Session Bus':
-                self.__sessionbus_connect_cb(None)
+                self.activate_action("connect-session", None)
                 return
             elif address == 'System Bus':
-                self.__systembus_connect_cb(None)
+                self.activate_action("connect-system", None)
                 return
             else:
                 try:
@@ -164,12 +170,8 @@ class DFeetWindow(Gtk.ApplicationWindow):
         nbr = self.notebook.page_num(widget)
         self.notebook.remove_page(nbr)
 
-    def __close_cb(self, action):
-        """quit program"""
-        self.__quit_dfeet(self, None)
-
-    def __quit_dfeet(self, main_window, event):
-        """quit d-feet application and store some settings"""
+    def __delete_cb(self, main_window, event):
+        """store some settings"""
         settings = Settings.get_instance()
         size = main_window.get_size()
         pos = main_window.get_position()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]