commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8761 - in trunk/gnue-forms/src/uidrivers/qt3: . widgets


From: johannes
Subject: [gnue] r8761 - in trunk/gnue-forms/src/uidrivers/qt3: . widgets
Date: Thu, 12 Oct 2006 03:08:20 -0500 (CDT)

Author: johannes
Date: 2006-10-12 03:08:19 -0500 (Thu, 12 Oct 2006)
New Revision: 8761

Modified:
   trunk/gnue-forms/src/uidrivers/qt3/ToolBar.py
   trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py
Log:
Added Toolbar


Modified: trunk/gnue-forms/src/uidrivers/qt3/ToolBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/ToolBar.py       2006-10-11 23:03:52 UTC 
(rev 8760)
+++ trunk/gnue-forms/src/uidrivers/qt3/ToolBar.py       2006-10-12 08:08:19 UTC 
(rev 8761)
@@ -1,6 +1,9 @@
+# GNU Enterprise Forms - QT3 UI driver - ToolBar
 #
-# This file is part of GNU Enterprise.
+# Copyright 2001-2006 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,152 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2006 Free Software Foundation
-#
-# FILE:
-# qt/ToolBar.py
-#
-# DESCRIPTION:
-# NOTES:
-#
+# $Id: $
 
-import string, sys
-from qt import *
-from gnue.forms.uidrivers._commonGuiToolkit.ToolBar import ToolBar as 
_BaseToolBar
+import qt
 
-class ToolBar(_BaseToolBar):
+from gnue.forms.uidrivers._commonGuiToolkit import ToolBar as _Base
 
-  # Create the menu
-  def init(self):
-    self.toolbar = QToolBar(_("Forms Navigation"), self.container)
-    self.toolbar.show()
-    return self.toolbar
+__all__ = ['ToolBar']
 
-  # Add a menu item (action)
-  def addAction(self, name, userAction):
-    iconloc = userAction.getIconLocation(size="24x24")
-    grayloc = userAction.getIconLocation(size="24x24-gray")
+_ICON_CACHE = {}
 
-    # Set the action icon if available
-    if iconloc:
-      try:
-        # Some caching logic for faster second/third forms
-        icon = _cachedIcons[iconloc]
-      except KeyError:
-        icon = QIconSet(QPixmap(iconloc))
-        _cachedIcons[iconloc] = icon
-        if grayloc:
-          icon.setPixmap(QPixmap(grayloc), QIconSet.Automatic, 
QIconSet.Normal, QIconSet.Off)
-        else:
-          print "** WARNING: No gray version of '%s' to toolbar; no icon" % 
userAction.event
+# =============================================================================
+# ToolBar widget
+# =============================================================================
 
-    else:
-      print "** WARNING: Cannot add '%s' to toolbar; no icon" % 
userAction.event
-      return
+class ToolBar(_Base.ToolBar):
+    """
+    Implementation of the QT3 tool bar
+    """
 
-    action = QAction(self.toolbar)
-    action.setIconSet(icon)
-    action.setText(name)
-    if userAction.canToggle:
-      action.setToggleAction(True)
+    # -------------------------------------------------------------------------
+    # Initialize the toolbar
+    # -------------------------------------------------------------------------
 
-    # Set popup tooltip
-    try:
-      action.setToolTip(userAction.help)
-    except AttributeError:
-      action.setToolTip(userAction.description)
+    def init(self):
+        """
+        Create a new tool bar
+        @returns: the QToolBar instance
+        """
 
+        self.toolbar = qt.QToolBar(u_("Forms Toolbar"), self.container)
+        self.toolbar.show()
+        return self.toolbar
 
-    # Set status tip   TODO: Doesn't seem to do anything
-    try:
-      action.setStatusTip(userAction.description)
-    except AttributeError:
-      pass
 
-    # Connect to the events
-    event = 'request%s' % userAction.event
-    function = '_%s_activate' % id(action)
-    if userAction.canToggle:
-      self.__dict__[function] = lambda state, l=self.driver, \
-              e=event, a=action, \
-              te='request%s' % userAction.canToggle, \
-              f=self.form: l.dispatchEvent(state and e or te,_form=f)
+    # -------------------------------------------------------------------------
+    # Add a menu item (action)
+    # -------------------------------------------------------------------------
 
-      QObject.connect(action, SIGNAL('toggled(bool)'),self.__dict__[function])
-    else:
-      self.__dict__[function] = lambda l=self.driver, e=event, f=self.form: 
l.dispatchEvent(e,_form=f)
-      QObject.connect(action, SIGNAL('activated()'), self.__dict__[function])
+    def addAction(self, name, userAction):
+        """
+        Add an action to the toolbar
 
-    # Add ourself to toolbar
-    action.addTo(self.toolbar)
+        @param name: name of the action
+        @param userAction: userAction instance representing the action to add
+        """
 
-    return action
+        action = Action(self, name, userAction)
+        return action
 
 
-  # Add a separator
-  def addSeparator(self):
-    self.toolbar.addSeparator()
+    # -------------------------------------------------------------------------
+    # Add a separator
+    # -------------------------------------------------------------------------
 
-  # Enable a menu item
-  def enableItem(self, item):
-    item.setEnabled(True)
+    def addSeparator(self):
+        self.toolbar.addSeparator()
 
-  # Disable a menu item
-  def disableItem(self, item):
-    item.setEnabled(False)
+    # -------------------------------------------------------------------------
+    # Enable a menu item
+    # -------------------------------------------------------------------------
 
-  def startingItem(self, item):
-    item.setOn(True)
+    def enableItem(self, item):
+        item.setEnabled(True)
 
-  def endingItem(self, item):
-    item.setOn(False)
+    # -------------------------------------------------------------------------
+    # Disable a menu item
+    # -------------------------------------------------------------------------
 
-  # A menu item was selected
-  def __itemSelected(self, itemid):
-    print "foobar"
-    self.driver.dispatchEvent(self.__idmap[itemid], _form=self.form)
+    def disableItem(self, item):
+        item.setEnabled(False)
 
+    # -------------------------------------------------------------------------
+    # Set a toggle action to 'on'
+    # -------------------------------------------------------------------------
 
-_cachedIcons = {}
+    def startingItem(self, item):
+        item.setOn(True)
+
+    # -------------------------------------------------------------------------
+    # Set a toggle action to 'off'
+    # -------------------------------------------------------------------------
+
+    def endingItem(self, item):
+        item.setOn(False)
+
+
+# =============================================================================
+# Action
+# =============================================================================
+
+class Action(qt.QAction):
+    """
+    Implementation of an action used within a toolbar
+    """
+
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
+
+    def __init__(self, parent, name, user_action):
+
+        qt.QAction.__init__(self, parent.toolbar)
+
+        self.parent = parent
+        self.user_action = user_action
+
+        iconloc = user_action.getIconLocation(size="24x24")
+
+        # Set the action icon if available
+        if iconloc:
+            icon = _ICON_CACHE.setdefault(iconloc,
+                                          qt.QIconSet(qt.QPixmap(iconloc)))
+            self.setIconSet(icon)
+        else:
+            print u_("** WARNING: Cannot add '%s' to toolbar; no icon") \
+                                %  user_action.event
+
+        self.setText(name)
+        if user_action.canToggle:
+            self.setToggleAction(True)
+
+        self.setToolTip(user_action.description or '')
+
+        if user_action.canToggle:
+            self.connect(self, qt.SIGNAL('toggled(bool)'), self.__toggled)
+        else:
+            self.connect(self, qt.SIGNAL('activated()'), self.__activated)
+
+        self.addTo(parent.toolbar)
+
+    # -------------------------------------------------------------------------
+    # String representation
+    # -------------------------------------------------------------------------
+
+    def __repr__(self):
+        return "<Action %s (%s)>" % (self.user_action.event,
+                self.user_action.canToggle)
+
+    # -------------------------------------------------------------------------
+    # Slot Implementations
+    # -------------------------------------------------------------------------
+
+    def __toggled(self, state):
+        self.parent._fire(self.user_action, state)
+
+    # -------------------------------------------------------------------------
+
+    def __activated(self):
+        self.parent._fire(self.user_action, False)

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py  2006-10-11 23:03:52 UTC 
(rev 8760)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py  2006-10-12 08:08:19 UTC 
(rev 8761)
@@ -27,6 +27,7 @@
 import qt
 
 from gnue.forms.uidrivers.qt3.MenuBar import MenuBar
+from gnue.forms.uidrivers.qt3.ToolBar import ToolBar
 from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
 
 # =============================================================================
@@ -97,6 +98,9 @@
             if not self._form._features['GUI:MENUBAR:SUPPRESS']:
                 MenuBar(self._uiDriver, self.main_window, self._form)
 
+            if not self._form._features['GUI:TOOLBAR:SUPPRESS']:
+                tlb = ToolBar(self._uiDriver, self.main_window, self._form)
+
         if self._form._layout.tabbed != 'none':
             self._container = qt.QTabWidget(self.main_widget)
             self._container.setTabPosition( \





reply via email to

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