[gnome-tweak-tool/appmenu] WHY WONT THIS WORK



commit 26b28317f96b8de05e9b85306be885bea9180878
Author: John Stowers <john stowers gmail com>
Date:   Tue Aug 7 19:58:38 2012 +0200

    WHY WONT THIS WORK

 data/shell.ui        |    8 ++++++++
 gnome-tweak-tool     |    5 +++--
 gtweak/mainwindow.py |   35 ++++++++++++++++++++++++++++++-----
 gtweak/tweakview.py  |   10 +++-------
 4 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/data/shell.ui b/data/shell.ui
index fa84718..d5f40fe 100644
--- a/data/shell.ui
+++ b/data/shell.ui
@@ -1,6 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <menu id='appmenu'>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_About</attribute>
+        <attribute name='action'>app.about</attribute>
+      </item>
+    </section>
+  </menu>
   <object class="GtkWindow" id="main_window">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Advanced Settings</property>
diff --git a/gnome-tweak-tool b/gnome-tweak-tool
index 6102e1a..77c5af9 100755
--- a/gnome-tweak-tool
+++ b/gnome-tweak-tool
@@ -18,6 +18,7 @@ import optparse
 import logging
 import locale
 import gettext
+import sys
 
 import gi
 gi.require_version("Gtk", "3.0")
@@ -72,6 +73,6 @@ if __name__ == '__main__':
     gettext.textdomain(gtweak.APP_NAME)
     gettext.install(gtweak.APP_NAME)
 
-    from gtweak.mainwindow import MainWindow
-    MainWindow()
+    from gtweak.mainwindow import GnomeTweakTool
+    GnomeTweakTool().run(sys.argv)
 
diff --git a/gtweak/mainwindow.py b/gtweak/mainwindow.py
index 9f23aa3..e078984 100644
--- a/gtweak/mainwindow.py
+++ b/gtweak/mainwindow.py
@@ -17,23 +17,32 @@
 
 import os.path
 
-from gi.repository import Gtk
+from gi.repository import Gtk, Gio
 
 import gtweak
 from gtweak.tweakmodel import TweakModel
 from gtweak.tweakview import TweakView
 
-class MainWindow:
+class GnomeTweakTool(Gtk.Application):
     def __init__(self):
-        builder = Gtk.Builder()
-
         assert(os.path.exists(gtweak.PKG_DATA_DIR))
+        Gtk.Application.__init__(self, application_id='org.gnome.TweakTool')
+        self.connect('activate', self._on_activate)
+        self.connect('startup', self._on_startup)
+
+        builder = Gtk.Builder()
 
         filename = os.path.join(gtweak.PKG_DATA_DIR, 'shell.ui')
         builder.add_from_file(filename)
         
         toolbar = builder.get_object('toolbar')
         toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
+
+        main_window = builder.get_object('main_window')
+        main_window.set_size_request(640, 480)
+        #call show_all before the view is constructed because the view is responsible
+        #for hiding tweaks when the appropriate group is un/selected
+        main_window.show_all()
         
         model = TweakModel()
         view = TweakView(
@@ -41,5 +50,21 @@ class MainWindow:
                     model)
         builder.get_object('overview_sw').add(view.treeview)
 
-        view.run()
+        self.appmenu = builder.get_object('appmenu')
+        self.main_window = main_window
+
+    def _on_activate(self, *args):
+        self.main_window.present()
+
+    def _on_startup(self, *args):
+        for name,handler in [('about', self._on_about)]:
+            action = Gio.SimpleAction(name=name)
+            action.connect('activate', handler)
+            self.add_action(action)
+        self.set_app_menu(self.appmenu)
+        self.add_window(self.main_window)
+
+    def _on_about(self, *args):
+        print "ABOUT"
+
 
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index 6991014..c5d108f 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -42,10 +42,6 @@ class TweakView:
     def __init__(self, builder, model):
         self._notebook = builder.get_object('notebook')
         self._detail_vbox = builder.get_object('detail_vbox')
-        self._main_window = builder.get_object('main_window')
-
-        self._main_window.set_size_request(640, 480)
-        self._main_window.connect('destroy', Gtk.main_quit)
 
         self._entry_manager = EntryManager(
             builder.get_object('search_entry'),
@@ -61,6 +57,7 @@ class TweakView:
                 Gtk.TreeViewColumn(
                         "Tweak", Gtk.CellRendererText(), text=TweakModel.COLUMN_NAME))
         self.treeview.get_selection().connect("changed", self._on_selection_changed)
+        self.treeview.show_all()
 
         #make sure the tweak background is the correct color
         ctx = builder.get_object('tweak_viewport').get_style_context ()
@@ -79,11 +76,10 @@ class TweakView:
         #dict of pending notifications, the key is the function to be called
         self._notification_functions = {}
 
-    def run(self):
-        self._main_window.show_all()
+        #select a tweak group by default
         self.treeview.get_selection().select_iter(
                 self._model.get_tweakgroup_iter(DEFAULT_TWEAKGROUP))
-        Gtk.main()
+
 
     def show_only_tweaks(self, tweaks):
         for t in self._model.tweaks:



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