commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9403 - in trunk/gnue-forms/src/uidrivers/win32: . widgets


From: btami
Subject: [gnue] r9403 - in trunk/gnue-forms/src/uidrivers/win32: . widgets
Date: Thu, 22 Feb 2007 16:44:31 -0600 (CST)

Author: btami
Date: 2007-02-22 16:44:30 -0600 (Thu, 22 Feb 2007)
New Revision: 9403

Added:
   trunk/gnue-forms/src/uidrivers/win32/widgets/menu.py
   trunk/gnue-forms/src/uidrivers/win32/widgets/menuitem.py
Modified:
   trunk/gnue-forms/src/uidrivers/win32/MenuBar.py
   trunk/gnue-forms/src/uidrivers/win32/ToolBar.py
Log:
user defined menu support

Modified: trunk/gnue-forms/src/uidrivers/win32/MenuBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/MenuBar.py     2007-02-22 15:49:51 UTC 
(rev 9402)
+++ trunk/gnue-forms/src/uidrivers/win32/MenuBar.py     2007-02-22 22:44:30 UTC 
(rev 9403)
@@ -38,22 +38,20 @@
 class MenuBar(_BaseMenuBar):
 
     # Create the menu
-    def init(self):
-        self.menu = win32gui.CreateMenu()
-        return self.menu
+    def init(self):
+        self.menu = win32gui.CreateMenu()
+        win32gui.SetMenu(self.container.GetHwnd(), self.menu )
+        return Menu(self.menu, self.container)
 
     # Add a (sub)menu
     def addMenu(self, name, parent):
         menu = win32gui.CreatePopupMenu()
-        win32gui.AppendMenu(parent, _menustyle | win32con.MF_POPUP, menu, 
textEncode(name))
-        # One would think this would go in init(),
-        # but, no... win32 has to be a jerkoff.
-        win32gui.SetMenu(self.container.GetHwnd(), self.menu )
-        return menu
+        win32gui.AppendMenu(parent.id, _menustyle | win32con.MF_POPUP, menu, 
textEncode(name))
+        return Menu(menu, parent)
 
     # Add a menu item (action)
     def addAction(self, name, parent, userAction):
-        label = name
+        label = name
         hotkey = userAction.getHotKeyText()
         iconloc = userAction.getIconLocation(size="16x16")
 
@@ -70,30 +68,35 @@
 
         id = getNextId()
         self.container.addDescription(id, textEncode(userAction.description) 
or '')
-        win32gui.AppendMenu(parent, _menustyle, id, textEncode(label))
+        win32gui.AppendMenu(parent.id, _menustyle, id, textEncode(label))
         self.container.Connect(id, lambda u=userAction: self._fire(u))
 
-        return (parent, id)
+        return Menu(id, parent)
 
 
     # Add a separator
     def addSeparator(self, parent):
-        win32gui.AppendMenu(parent, win32con.MF_SEPARATOR, 0, "")
+        win32gui.AppendMenu(parent.id, win32con.MF_SEPARATOR, 0, "")
 
     # Enable a menu item
     def enableItem(self, item):
-        parent, id = item
         try:
-            win32gui.EnableMenuItem(parent, id, 
win32con.MF_BYCOMMAND|win32con.MF_ENABLED)
+            win32gui.EnableMenuItem(item.parent.id, item.id, 
win32con.MF_BYCOMMAND|win32con.MF_ENABLED)
         except:
             pass
 
     # Disable a menu item
     def disableItem(self, item):
-        parent, id = item
         try:
-            win32gui.EnableMenuItem(parent, id, 
win32con.MF_BYCOMMAND|win32con.MF_GRAYED)
+            win32gui.EnableMenuItem(item.parent.id, item.id, 
win32con.MF_BYCOMMAND|win32con.MF_GRAYED)
         except:
             pass
+
+
+class Menu:
+    def __init__(self, id, parent):
+        self.id = id
+        self.parent = parent
+
 
 _cachedIcons = {}

Modified: trunk/gnue-forms/src/uidrivers/win32/ToolBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/ToolBar.py     2007-02-22 15:49:51 UTC 
(rev 9402)
+++ trunk/gnue-forms/src/uidrivers/win32/ToolBar.py     2007-02-22 22:44:30 UTC 
(rev 9403)
@@ -133,7 +133,8 @@
         ti = struct.pack(format, size, 0, self.toolbar.GetHwnd(), id, 0, 0, 0, 
0, 0, addrText, 0)
         win32gui.SendMessage(self._htt, commctrl.TTM_UPDATETIPTEXT , 0, ti)
 
-        return (parent, id, check)
+#        return (parent, id, check)
+        return ToolButton(parent, id, check)
 
 
     # Add a separator
@@ -143,24 +144,29 @@
 
     # Enable a menu item
     def enableItem(self, item):
-        parent, id, check = item
+        parent, id, check = item.data
         win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ENABLEBUTTON, 
id, 1)
 
     # Disable a menu item
     def disableItem(self, item):
-        parent, id, check = item
+        parent, id, check = item.data
         win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ENABLEBUTTON, 
id, 0)
 
     def startingItem(self, item):
-        parent, id, check = item
+        parent, id, check = item.data
         if check:
             win32gui.SendMessage(self.toolbar.GetHwnd(), 
commctrl.TB_CHECKBUTTON, id, 1)
         else:
             win32gui.SendMessage(self.toolbar.GetHwnd(), 
commctrl.TB_PRESSBUTTON, id, 1)
 
     def endingItem(self, item):
-        parent, id, check = item
+        parent, id, check = item.data
         if check:
             win32gui.SendMessage(self.toolbar.GetHwnd(), 
commctrl.TB_CHECKBUTTON, id, 0)
         else:
             win32gui.SendMessage(self.toolbar.GetHwnd(), 
commctrl.TB_PRESSBUTTON, id, 0)
+
+
+class ToolButton:
+    def __init__(self, parent, id, check):
+        self.data = (parent, id, check)

Added: trunk/gnue-forms/src/uidrivers/win32/widgets/menu.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/menu.py        2007-02-22 
15:49:51 UTC (rev 9402)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/menu.py        2007-02-22 
22:44:30 UTC (rev 9403)
@@ -0,0 +1,77 @@
+# GNU Enterprise Forms - win32 UI Driver - Menu widget
+#
+# Copyright 2001-2007 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
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id:$
+
+import win32gui
+import win32con
+
+from gnue.forms.uidrivers.win32.widgets._base import UIHelper, Win32Window
+from gnue.forms.uidrivers.win32.common import getNextId, textEncode
+from gnue.forms.uidrivers.win32 import MenuBar
+
+_menustyle = win32con.MF_STRING
+
+
+# =============================================================================
+# Wrap an UI layer around a Menu widget
+# =============================================================================
+
+class UIMenu(UIHelper):
+    """
+    Implements a menu object.
+    """
+
+    # -------------------------------------------------------------------------
+    # Create a menu widget
+    # -------------------------------------------------------------------------
+
+    def _create_widget_(self, event, spacer):
+        """
+        Creates a new Menu widget.
+        """
+        if self._gfObject.name == '__main_menu__' \
+                and not self._form._features['GUI:MENUBAR:SUPPRESS']:
+            # Menu bar of the form
+            widget = win32gui.CreateMenu()
+            self._container = MenuBar.Menu(widget, self._uiForm.mainWindow)
+            win32gui.SetMenu(self._uiForm.mainWindow.GetHwnd(), widget )
+
+        else:
+            # Submenu or popup menu
+            widget = win32gui.CreatePopupMenu()
+            if isinstance(event.container, MenuBar.Menu):
+                label = textEncode(self._gfObject.label) or ''
+                win32gui.AppendMenu(event.container.id, _menustyle | 
win32con.MF_POPUP, widget, label)
+            self._container = MenuBar.Menu(widget, event.container)
+            
+        return self._container
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+  'baseClass': UIMenu,
+  'provides' : 'GFMenu',
+  'container': 1,
+}

Added: trunk/gnue-forms/src/uidrivers/win32/widgets/menuitem.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/menuitem.py    2007-02-22 
15:49:51 UTC (rev 9402)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/menuitem.py    2007-02-22 
22:44:30 UTC (rev 9403)
@@ -0,0 +1,127 @@
+# GNU Enterprise Forms - win32 UI Driver - MenuItem widget
+#
+# Copyright 2001-2007 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
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id:$
+
+import win32gui
+import win32con
+
+from gnue.forms.uidrivers.win32 import MenuBar
+from gnue.forms.uidrivers.win32.widgets._base import UIHelper
+from gnue.forms.uidrivers.win32.common import getNextId, textEncode
+
+_menustyle = win32con.MF_STRING
+
+
+# =============================================================================
+# Wrap an UI layer around a Menu widget
+# =============================================================================
+
+class UIMenuItem(UIHelper):
+    """
+    Implements a menu item object.
+    """
+
+    # -------------------------------------------------------------------------
+    # Create a menu item widget
+    # -------------------------------------------------------------------------
+
+    def _create_widget_(self, event, spacer):
+        """
+        Creates a new MenuItem widget.
+        """
+        # These are the relevant parameters
+        icon_file = self._gfObject._get_icon_file(size="16x16", format="png")
+        label = self._gfObject.label
+        description = self._gfObject.description
+        hotkey = self._gfObject.hotkey
+        check = (self._gfObject.action_off is not None)
+
+        self.__id = getNextId()
+        if label is not None:
+            if hotkey is not None:
+                label += u"\t" + hotkey
+
+            event.container.parent.parent.addDescription(self.__id, 
textEncode(description) or '')
+            widget = win32gui.AppendMenu(event.container.id, _menustyle, 
self.__id, textEncode(label))
+            event.container.parent.parent.Connect(self.__id, self.__on_menu)
+                
+        else:
+            widget = None
+            win32gui.AppendMenu(event.container.id, win32con.MF_SEPARATOR, 0, 
"")
+
+        self.__widget = MenuBar.Menu(self.__id, event.container)
+
+        return self.__widget
+
+
+    # -------------------------------------------------------------------------
+    # Events
+    # -------------------------------------------------------------------------
+
+    def __on_menu(self, *args):
+        print '_event_fire'
+        self._gfObject._event_fire()
+
+
+    # -------------------------------------------------------------------------
+    # Check/uncheck menu item
+    # -------------------------------------------------------------------------
+
+    def _ui_switch_on_(self):
+        if self.__widget is not None:
+            win32gui.CheckMenuItem(self.__widget.parent.id, self.__widget.id,
+                            win32con.MF_BYCOMMAND|win32con.MF_CHECKED)
+
+    # -------------------------------------------------------------------------
+
+    def _ui_switch_off_(self):
+        if self.__widget is not None:
+            win32gui.CheckMenuItem(self.__widget.parent.id, self.__widget.id,
+                            win32con.MF_BYCOMMAND|win32con.MF_UNCHECKED)
+
+
+    # -------------------------------------------------------------------------
+    # Enable/disable menu item
+    # -------------------------------------------------------------------------
+
+    def _ui_enable_(self):
+        if self.__widget is not None:
+            win32gui.EnableMenuItem(self.__widget.parent.id, self.__widget.id,
+                            win32con.MF_BYCOMMAND|win32con.MF_ENABLED)
+
+    # -------------------------------------------------------------------------
+
+    def _ui_disable_(self):
+        if self.__widget is not None:
+            win32gui.EnableMenuItem(self.__widget.parent.id, self.__widget.id,
+                            win32con.MF_BYCOMMAND|win32con.MF_GRAYED)
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+  'baseClass': UIMenuItem,
+  'provides' : 'GFMenuItem',
+  'container': False
+}





reply via email to

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