commit-gnue
[Top][All Lists]
Advanced

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

r6011 - trunk/gnue-forms/src/uidrivers/gtk2


From: johannes
Subject: r6011 - trunk/gnue-forms/src/uidrivers/gtk2
Date: Wed, 21 Jul 2004 10:16:05 -0500 (CDT)

Author: johannes
Date: 2004-07-21 10:16:04 -0500 (Wed, 21 Jul 2004)
New Revision: 6011

Modified:
   trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py
Log:
Updated the toolbar widget


Modified: trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py      2004-07-21 13:56:52 UTC 
(rev 6010)
+++ trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py      2004-07-21 15:16:04 UTC 
(rev 6011)
@@ -1,6 +1,9 @@
+# GNU Enterprise Forms - GTK UI Driver - Toolbar widget
 #
-# This file is part of GNU Enterprise.
+# Copyright 2001-2004 Free Software Foundation
 #
+# This file is part of GNU Enterprise
+#
 # GNU Enterprise is free software; you can redistribute it
 # and/or modify it under the terms of the GNU General Public
 # License as published by the Free Software Foundation; either
@@ -16,110 +19,142 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# gtk2/ToolBar.py
-#
-# DESCRIPTION:
-# A gtk2 based Toolbar
-#
-# NOTES:
-#
+# $Id$
 
-import string, sys
 import gtk
-from gnue.forms.uidrivers._commonGuiToolkit.ToolBar import ToolBar as 
_BaseToolBar
+
+from gnue.common.apps import GDebug, i18n
+from gnue.forms.uidrivers._commonGuiToolkit.ToolBar import ToolBar as Base
   
-class ToolBar(_BaseToolBar):
+# =============================================================================
+# This class implements the toolbar for GTK2
+# =============================================================================
 
-  # Create the menu
-  def init(self): 
-    self.toolbar = toolbar = gtk.Toolbar()
+class ToolBar (Base):
 
-    toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
+  # ---------------------------------------------------------------------------
+  # Create the toolbar
+  # ---------------------------------------------------------------------------
 
-    # TODO:
-    #   - add user preference for toolbar 
-    #      choices: (use global toolbar settings| just icon | just text | both)
-    #
-    # (for now use ICONS only)
-    toolbar.set_style(gtk.TOOLBAR_ICONS)   # gtk.TOOLBAR_BOTH | 
gtk.TOOLBAR_TEXT 
-    toolbar.set_tooltips(gtk.TRUE)
+  def init (self):
+    handlebox = gtk.HandleBox ()
+    self.toolbar = gtk.Toolbar ()
+
+    self.toolbar.set_orientation (gtk.ORIENTATION_HORIZONTAL)
+    self.toolbar.set_style (gtk.TOOLBAR_ICONS)
+    self.toolbar.set_tooltips (gtk.TRUE)
+    handlebox.add (self.toolbar)
     
-    self.container.content_table.attach(toolbar,
+    self.container.content_table.attach (handlebox,
                                         # X direction           Y direction
                                         0, 1,                      1, 2,
                                         gtk.EXPAND | gtk.FILL,     0,
                                         0,                         0)
-    return toolbar
+    self.toolbar.show ()
+    handlebox.show ()
 
+    return handlebox
+
+
+  # ---------------------------------------------------------------------------
   # Add a menu item (action)
-  def addAction(self, name, userAction):
+  # ---------------------------------------------------------------------------
 
-    # TODO: try to use stock items for basic functions (load/save...)
-    
-    # TODO: remove decode step, when gettext translations are send
-    # in unicode instead of local encoding
-    label = unicode(name,gConfigForms('textEncoding'))
-    toolTip = unicode(userAction.description,gConfigForms('textEncoding'))
-    iconloc = userAction.getIconLocation(size="24x24")
+  def addAction (self, name, userAction):
 
+    GDebug.printMesg (1, "TOOL: add action %s, %s" % \
+        (repr (name), repr (userAction.description)))
+
+    label   = name.encode ('utf-8')
+    toolTip = unicode (userAction.description, i18n.encoding)
+    iconloc = userAction.getIconLocation (size = "24x24")
+
     # Set the action icon if available
-    if iconloc:
-      try:
-        # Some caching logic for faster second/third forms
-        icon = _cachedIcons[iconloc]
-      except KeyError:
-        icon = gtk.Image()
-        icon.set_from_file(iconloc)
-        _cachedIcons[iconloc] = icon
-    else:
+    if not iconloc:
       print "** WARNING: Cannot add '%s' to toolbar; no icon" % 
userAction.event
       return
 
+    if _cachedIcons.has_key (iconloc):
+      icon = _cachedIcons [iconloc]
+    else:
+      icon = gtk.Image ()
+      icon.set_from_file (iconloc)
+      _cachedIcons [iconloc] = icon
+
     event = 'request%s' % userAction.event
     
     if userAction.canToggle:
-      button = self.toolbar.append_element(gtk.TOOLBAR_CHILD_TOGGLEBUTTON,None,
-                                  label,toolTip,
-                                  None, icon, None, None)
-      button.connect("toggled", lambda widget, l=self.driver, \
-              e=event, te='request%s' % userAction.canToggle,
-              s=button,
-              f=self.form: 
-              l.dispatchEvent((widget.get_active() and e or te),_form=f))
+      button = self.toolbar.append_element (gtk.TOOLBAR_CHILD_TOGGLEBUTTON,
+          None, label, toolTip, None, icon, self._toggleEvent, userAction)
+    else:
+      button = self.toolbar.append_item (label, toolTip, None, icon,
+                                         self._buttonPress, userAction)
+    return button
 
+
+  # ---------------------------------------------------------------------------
+  # Event handler for toggle buttons
+  # ---------------------------------------------------------------------------
+
+  def _toggleEvent (self, button, userAction):
+    if button.get_active ():
+      event = 'request%s' % userAction.event
     else:
-      button = self.toolbar.append_item(label,toolTip,
-                                        None, icon, None, None)
-    
+      event = 'request%s' % userAction.canToggle
 
-      button.connect("clicked", lambda widget, l=self.driver, \
-                     e=event, f=self.form: l.dispatchEvent(e,_form=f))
-    return button  
+    self.driver.dispatchEvent (event, _form = self.form)
+
+
+  # ---------------------------------------------------------------------------
+  # Event handler for toolbar buttons
+  # ---------------------------------------------------------------------------
+
+  def _buttonPress (self, button, userAction):
+    event = 'request%s' % userAction.event
+    self.driver.dispatchEvent (event, _form = self.form)
+
         
+  # ---------------------------------------------------------------------------
   # Add a separator
-  def addSeparator(self):
-    self.toolbar.append_space()
+  # ---------------------------------------------------------------------------
+
+  def addSeparator (self):
+    self.toolbar.append_space ()
     
+
+  # ---------------------------------------------------------------------------
   # Enable a menu item
-  def enableItem(self, item):
-    if item != None:
-      item.set_sensitive(1)
+  # ---------------------------------------------------------------------------
+
+  def enableItem (self, item):
+    if item is not None:
+      item.set_sensitive (1)
   
+
+  # ---------------------------------------------------------------------------
   # Disable a menu item
-  def disableItem(self, item):
-    if item != None:
-      item.set_sensitive(0)
+  # ---------------------------------------------------------------------------
+
+  def disableItem (self, item):
+    if item is not None:
+      item.set_sensitive (0)
   
-  def startingItem(self, item):
-    if item!=None:
-      item.set_active(1)
 
-  def endingItem(self, item):
-    if item!=None:
-      item.set_active(0)
+  # ---------------------------------------------------------------------------
+  # Set an item active
+  # ---------------------------------------------------------------------------
+
+  def startingItem (self, item):
+    if item is not None:
+      item.set_active (1)
+
+  # ---------------------------------------------------------------------------
+  # Set an item inactive
+  # ---------------------------------------------------------------------------
+
+  def endingItem (self, item):
+    if item is not None:
+      item.set_active (0)
         
     
 _cachedIcons = {}


Property changes on: trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py
___________________________________________________________________
Name: svn:keywords
   + Id





reply via email to

[Prev in Thread] Current Thread [Next in Thread]