[d-feet] Add app menu



commit 24301908a3957f38706d7e41ff21887042f9bffb
Author: Thomas Bechtold <thomasbechtold jpberlin de>
Date:   Mon May 20 09:09:39 2013 +0200

    Add app menu

 data/ui/mainwindow.ui    |   86 ----------------------------------------------
 src/dfeet/application.py |   70 ++++++++++++++++++++++++++++++++++++-
 src/dfeet/window.py      |    8 ----
 3 files changed, 68 insertions(+), 96 deletions(-)
---
diff --git a/data/ui/mainwindow.ui b/data/ui/mainwindow.ui
index 83a390c..4a4a3a8 100644
--- a/data/ui/mainwindow.ui
+++ b/data/ui/mainwindow.ui
@@ -2,12 +2,6 @@
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkAccelGroup" id="accelgroup_connect"/>
-  <object class="GtkAccelGroup" id="accelgroup_help"/>
-  <object class="GtkAction" id="action_close">
-    <property name="label" translatable="yes">Close</property>
-    <property name="stock_id">gtk-close</property>
-    <signal name="activate" handler="action_close_activate_cb" swapped="no"/>
-  </object>
   <object class="GtkActionGroup" id="actiongroup_connect">
     <property name="accel_group">accelgroup_connect</property>
     <child>
@@ -38,49 +32,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkActionGroup" id="actiongroup_help">
-    <property name="accel_group">accelgroup_help</property>
-    <child>
-      <object class="GtkAction" id="action_about">
-        <property name="label" translatable="yes">About</property>
-        <property name="stock_id">gtk-about</property>
-        <signal name="activate" handler="action_about_activate_cb" swapped="no"/>
-      </object>
-    </child>
-  </object>
-  <object class="GtkAboutDialog" id="aboutdialog">
-    <property name="can_focus">False</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">About d-feet</property>
-    <property name="window_position">mouse</property>
-    <property name="type_hint">normal</property>
-    <property name="program_name">d-feet</property>
-    <property name="website">https://live.gnome.org/DFeet/</property>
-    <property name="logo_icon_name">d-feet</property>
-    <property name="license_type">gpl-2-0</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="aboutdialog-vbox1">
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="aboutdialog-action_area1">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-      </object>
-    </child>
-  </object>
   <object class="GtkVBox" id="vbox1">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -120,43 +71,6 @@
                     <property name="can_focus">False</property>
                   </object>
                 </child>
-                <child>
-                  <object class="GtkSeparatorMenuItem" id="menuitem1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkImageMenuItem" id="menuitem_close">
-                    <property name="related_action">action_close</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="use_stock">True</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkMenuItem" id="menuitem_help">
-            <property name="use_action_appearance">False</property>
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">Help</property>
-            <property name="use_underline">True</property>
-            <child type="submenu">
-              <object class="GtkMenu" id="menu2">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem_about">
-                    <property name="related_action">action_about</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                  </object>
-                </child>
               </object>
             </child>
           </object>
diff --git a/src/dfeet/application.py b/src/dfeet/application.py
index 53f775f..f2af13c 100644
--- a/src/dfeet/application.py
+++ b/src/dfeet/application.py
@@ -1,11 +1,35 @@
 # -*- coding: utf-8 -*-
 from __future__ import print_function
 
-from gi.repository import Gtk, Gio, GObject
+from gi.repository import Gtk, Gio, GObject, Gdk
 
 from dfeet.window import DFeetWindow
 
 
+APP_MENU = """
+<interface>
+  <menu id='app-menu'>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>About</attribute>
+        <attribute name='action'>app.about</attribute>
+      </item>
+      <item>
+        <attribute name='label' translatable='yes'>Help</attribute>
+        <attribute name='action'>app.help</attribute>
+        <attribute name="accel">F1</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+        <attribute name="accel">&lt;Primary&gt;q</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
+"""
+
+
 class DFeetApp(Gtk.Application):
 
     def __init__(self, package, version, data_dir):
@@ -15,7 +39,6 @@ class DFeetApp(Gtk.Application):
         Gtk.Application.__init__(self, application_id="org.gnome.d-feet",
                                  flags=Gio.ApplicationFlags.FLAGS_NONE)
 
-
     #Note that the function in C activate() becomes do_activate() in Python
     def do_activate(self):
         win = DFeetWindow(self, self.package, self.version, self.data_dir)
@@ -23,3 +46,46 @@ class DFeetApp(Gtk.Application):
     #Note that the function in C startup() becomes do_startup() in Python
     def do_startup(self):
         Gtk.Application.do_startup(self)
+        builder = Gtk.Builder()
+        builder.add_from_string(APP_MENU)
+
+        #create actions
+        action = Gio.SimpleAction.new("about", None)
+        action.connect("activate", self.action_about_cb)
+        self.add_action(action)
+
+        action = Gio.SimpleAction.new("help", None)
+        action.connect("activate", self.action_help_cb)
+        self.add_action(action)
+
+        action = Gio.SimpleAction.new("quit", None)
+        action.connect("activate", self.action_quit_cb)
+        self.add_action(action)
+
+        self.set_app_menu(builder.get_object("app-menu"))
+
+    def action_quit_cb(self, action, parameter):
+        self.quit()
+
+    def action_about_cb(self, action, parameter):
+        aboutdialog = DFeetAboutDialog(self.package, self.version)
+        aboutdialog.show()
+
+    def action_help_cb(self, action, parameter):
+        screen = Gdk.Screen.get_default()
+        link = "help:d-feet"
+        Gtk.show_uri(screen, link, Gtk.get_current_event_time())
+
+
+class DFeetAboutDialog(Gtk.AboutDialog):
+    def __init__(self, package, version):
+        Gtk.AboutDialog.__init__(self)
+        self.set_program_name(package)
+        self.set_version(version)
+        self.set_license_type(Gtk.License.GPL_2_0)
+        self.set_website("https://live.gnome.org/DFeet/";)
+        self.set_logo_icon_name(package)
+        self.connect("response", self.on_close_cb)
+
+    def on_close_cb(self, action, parameter):
+        action.destroy()
diff --git a/src/dfeet/window.py b/src/dfeet/window.py
index 1a7ae1c..ae00148 100644
--- a/src/dfeet/window.py
+++ b/src/dfeet/window.py
@@ -74,7 +74,6 @@ class DFeetWindow(Gtk.ApplicationWindow):
             '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,
-            'action_about_activate_cb': self.__action_about_activate_cb,
             }
 
         #get settings
@@ -90,7 +89,6 @@ class DFeetWindow(Gtk.ApplicationWindow):
         self.notebook = ui.get_widget('display_notebook')
         self.notebook.show_all()
         self.notebook_page_widget = ui.get_widget('box_notebook_page')
-        self.about_dialog = ui.get_widget('aboutdialog')
         #create bus history list and load entries from settings
         self.__bus_history = []
         for bus in settings.general['addbus_list']:
@@ -149,12 +147,6 @@ class DFeetWindow(Gtk.ApplicationWindow):
                     print("can not connect to '%s': %s" % (address, str(e)))
         dialog.destroy()
 
-    def __action_about_activate_cb(self, action):
-        """show the about dialog"""
-        self.about_dialog.set_visible(True)
-        self.about_dialog.run()
-        self.about_dialog.set_visible(False)
-
     def __notebook_append_page(self, widget, text):
         """add a page to the notebook"""
         ntl = NotebookTabLabel(text)


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