[POS-commit] r5380 - in stoq/trunk/stoq: .

Johan Dahlin jdahlin at async.com.br
Fri Nov 24 13:26:15 BRST 2006


Author: jdahlin
Date: Fri Nov 24 13:26:14 2006
New Revision: 5380

Modified:
   stoq/trunk/stoq/gui/application.py
   stoq/trunk/stoq/gui/login.py
   stoq/trunk/stoq/main.py

Log:
Send in options to applications. Add a debug menu to all applications which is only shown if --debug is used. Add an introspect slaves menu option

Modified: stoq/trunk/stoq/gui/application.py
==============================================================================
--- stoq/trunk/stoq/gui/application.py	(original)
+++ stoq/trunk/stoq/gui/application.py	Fri Nov 24 13:26:14 2006
@@ -44,10 +44,17 @@
 _ = gettext.gettext
 
 
+def _foreach_child(widget, cb, lvl=0):
+    cb(widget, lvl)
+    if isinstance(widget, gtk.Container):
+        for child in widget.get_children():
+            _foreach_child(child, cb, lvl+1)
+
 class App(BaseApp):
 
     def __init__(self, window_class, appconfig):
         self.config = appconfig
+        self.options = appconfig.options
         self.window_class = window_class
         BaseApp.__init__(self, window_class)
 
@@ -90,6 +97,8 @@
         self._klist = getattr(self, self.klist_name)
         self._klist.set_columns(self.get_columns())
         self._klist.set_selection_mode(self.klist_selection_mode)
+        if app.options.debug:
+            self._create_debug_menu()
         self._create_user_menu()
         self.setup_focus()
 
@@ -181,6 +190,25 @@
         self.menu_hbox.pack_start(menubar, expand=False)
         menubar.show_all()
 
+    def _create_debug_menu(self):
+        ui_string = """<ui>
+          <menubar name="menubar">
+            <menu action="DebugMenu">
+              <menuitem action="Introspect"/>
+            </menu>
+          </menubar>
+        </ui>"""
+        actions = [
+            ('DebugMenu', None, _('Debug')),
+            ('Introspect', None, _('Introspect slaves'),
+             None, None, self.on_Introspect_activate),
+            ]
+
+        ag = gtk.ActionGroup('DebugMenuActions')
+        ag.add_actions(actions)
+        self.uimanager.insert_action_group(ag, 0)
+        self.uimanager.add_ui_from_string(ui_string)
+
     def print_report(self, report_class, *args, **kwargs):
         print_report(report_class, *args, **kwargs)
 
@@ -216,6 +244,19 @@
         # Implement a change user dialog here
         raise NotImplementedError
 
+    def on_Introspect_activate(self, action):
+        def _printone(slave, lvl=0):
+            filename = slave.gladefile + '.glade'
+            print ' ' * lvl, slave.__class__.__name__, filename
+
+        def _parse(widget, lvl):
+            if isinstance(widget, gtk.EventBox):
+                slave = widget.get_data('kiwi::slave')
+                _printone(slave, lvl)
+
+        window = self.get_toplevel()
+
+        _foreach_child(window, _parse)
 
 class SearchableAppWindow(AppWindow):
     """ Base class for searchable applications.

Modified: stoq/trunk/stoq/gui/login.py
==============================================================================
--- stoq/trunk/stoq/gui/login.py	(original)
+++ stoq/trunk/stoq/gui/login.py	Fri Nov 24 13:26:14 2006
@@ -101,8 +101,9 @@
 
 class LoginHelper:
 
-    def __init__(self, appname):
+    def __init__(self, appname, options):
         self.appname = appname
+        self.options = options
 
         if not self.validate_user():
             raise LoginError('Could not authenticate in the system')

Modified: stoq/trunk/stoq/main.py
==============================================================================
--- stoq/trunk/stoq/main.py	(original)
+++ stoq/trunk/stoq/main.py	Fri Nov 24 13:26:14 2006
@@ -182,7 +182,7 @@
 
     return splash
 
-def _run_app(appname):
+def _run_app(options, appname):
     from stoqlib.gui.base.gtkadds import register_iconsets
     from stoq.gui.login import LoginHelper
 
@@ -190,7 +190,7 @@
     register_iconsets()
 
     log.debug('loading application')
-    appconf = LoginHelper(appname)
+    appconf = LoginHelper(appname, options)
     # Get the selected application if nothing was selected
     if not appname:
         appname = appconf.appname
@@ -245,4 +245,4 @@
     options, appname = _parse_command_line(args)
 
     _initialize(options)
-    _run_app(appname)
+    _run_app(options, appname)


More information about the POS-commit mailing list