commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9433 - trunk/gnue-forms/src/uidrivers/win32/widgets


From: btami
Subject: [gnue] r9433 - trunk/gnue-forms/src/uidrivers/win32/widgets
Date: Sun, 11 Mar 2007 13:54:24 -0500 (CDT)

Author: btami
Date: 2007-03-11 13:54:23 -0500 (Sun, 11 Mar 2007)
New Revision: 9433

Added:
   trunk/gnue-forms/src/uidrivers/win32/widgets/toolbar.py
   trunk/gnue-forms/src/uidrivers/win32/widgets/toolbutton.py
Log:
started toolbar/toolbutton widget support

Added: trunk/gnue-forms/src/uidrivers/win32/widgets/toolbar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/toolbar.py     2007-03-07 
10:14:39 UTC (rev 9432)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/toolbar.py     2007-03-11 
18:54:23 UTC (rev 9433)
@@ -0,0 +1,107 @@
+# GNU Enterprise Forms - win32 UI Driver - Toolbar 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 os
+import sys
+import array
+import struct
+
+import win32api
+import win32con
+import win32gui
+import commctrl
+
+from gnue.forms.uidrivers.win32.widgets._base import UIHelper, Win32Window
+from gnue.forms.uidrivers.win32.common import getNextId, textEncode
+
+winver = sys.getwindowsversion()
+XP = winver[0]>5 or (winver[0]==5 and winver[1]>=1 and winver[3]==2)
+
+# =============================================================================
+# Wrap an UI layer around a wxMenu widget
+# =============================================================================
+
+class UIToolbar(UIHelper):
+    """
+    Implements a toolbar object.
+    """
+
+    # -------------------------------------------------------------------------
+    # Create a menu widget
+    # -------------------------------------------------------------------------
+
+    def _create_widget_(self, event, spacer):
+        """
+        Creates a new toolbar widget.
+        """
+
+        widget = None
+
+        if self._gfObject.name == '__main_toolbar__' \
+                and not self._form._features['GUI:TOOLBAR:SUPPRESS']:
+            print '__main_toolbar__'
+            # Make sure to disable the color-remapping in windows
+            #wx.SystemOptions.SetOption ('msw.remap', '0')
+
+            # Toolbar of the form
+            #~ if isinstance(self._uiForm.main_window, wx.Frame):
+                #~ widget = self._uiForm.main_window.CreateToolBar()
+                #~ widget.SetToolBitmapSize((24, 24))
+
+            hinst = win32api.GetModuleHandle(None)
+            style = win32con.WS_CHILD | commctrl.TBSTYLE_TOOLTIPS | 
commctrl.TBSTYLE_FLAT #|win32con.WS_BORDER
+            styleEx = 0
+            widget = self.toolbar = mainToolBar = 
Win32Window(self._uiForm.mainWindow._uiDriver, styleEx, 
commctrl.TOOLBARCLASSNAME, "GNUe toolbar",
+              style, 0, 0, 0, 0,
+              self._uiForm.mainWindow, getNextId(), hinst)
+
+            style = win32con.WS_CHILD | win32con.SS_SUNKEN
+            Win32Window(self._uiForm.mainWindow._uiDriver, 0, 'STATIC', '', 
style, 0, 30, 9999, 2, mainToolBar)
+        
+            self.himl = himl = win32gui.ImageList_Create(24, 24, 
commctrl.ILC_COLOR32, 0, 3)
+
+            tbab = struct.pack("ii", 0, himl)
+            win32gui.SendMessage(mainToolBar.GetHwnd(), 
commctrl.TB_SETIMAGELIST, 0, himl)
+
+            self._htt = win32gui.SendMessage(mainToolBar.GetHwnd(), 
commctrl.TB_GETTOOLTIPS, 0, 0)
+            win32gui.SendMessage(self._htt, commctrl.TTM_SETMAXTIPWIDTH , 0, 
250)
+
+            self._buttonCount = 0
+            win32gui.SendMessage(mainToolBar.GetHwnd(), commctrl.TB_AUTOSIZE, 
0, 0)
+            mainToolBar.Show()
+
+
+        self._container = self
+
+        return widget
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+  'baseClass': UIToolbar,
+  'provides' : 'GFToolbar',
+  'container': 1,
+}

Added: trunk/gnue-forms/src/uidrivers/win32/widgets/toolbutton.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/toolbutton.py  2007-03-07 
10:14:39 UTC (rev 9432)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/toolbutton.py  2007-03-11 
18:54:23 UTC (rev 9433)
@@ -0,0 +1,178 @@
+# GNU Enterprise Forms - win32 UI Driver - ToolButton 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 os
+import sys
+import array
+import struct
+
+import win32api
+import win32con
+import win32gui
+import commctrl
+
+from gnue.forms.uidrivers.win32 import ToolBar
+from gnue.forms.uidrivers.win32.widgets._base import UIHelper
+from gnue.forms.uidrivers.win32.common import getNextId, textEncode
+
+
+# =============================================================================
+# UIToolButton
+# =============================================================================
+
+class UIToolButton(UIHelper):
+    """
+    Implements a toolbar button object.
+    """
+
+    # -------------------------------------------------------------------------
+    # Create a menu item widget
+    # -------------------------------------------------------------------------
+
+    def _create_widget_(self, event, spacer):
+        """
+        Creates a new toolbar button widget.
+        """
+        
+        # These are the relevant parameters
+        icon_file = self._gfObject._get_icon_file(size="24x24", format="bmp")
+        label = self._gfObject.label
+        description = self._gfObject.description
+        check = (self._gfObject.action_off is not None)
+
+        check = 0
+        style = commctrl.TBSTYLE_BUTTON
+        self.parent = parent = event.container
+
+        if label is not None:
+            self.id = id = getNextId()
+            #~ if check:
+                #~ kind = wx.ITEM_CHECK
+            #~ else:
+                #~ kind = wx.ITEM_NORMAL
+
+            # Set the action icon if available
+            if icon_file:
+                print icon_file
+                icon_flags = win32con.LR_LOADFROMFILE #| win32con.LR_SHARED
+                him = win32gui.LoadImage(0, icon_file, win32con.IMAGE_BITMAP, 
24, 24, icon_flags)
+                win32gui.ImageList_Add(event.container.himl, him, 0)
+            else:
+                print "** WARNING: Cannot a_commonGuiToolkitdd '%s' to 
toolbar; no icon" % userAction.event
+                return
+
+            #~ if icon_file:
+                #~ image = wx.Image(icon_file, wx.BITMAP_TYPE_PNG)
+            #~ else:
+                #~ image = None
+
+            #~ widget = event.container.AddLabelTool(wx.ID_ANY, label,
+                    #~ image.ConvertToBitmap(), kind=kind, shortHelp=label,
+                    #~ longHelp=(description or u""))
+
+            #~ wx.EVT_TOOL(event.container, widget.GetId(), self.__on_tool)
+
+#    TBBUTTON stru (iBitmap, idCommand, fsState, fsStyle, dwData, iString)
+            tbb=struct.pack("iibbli", parent._buttonCount, id, 
commctrl.TBSTATE_ENABLED, style, 0, 0)
+            win32gui.SendMessage(parent.toolbar.GetHwnd(), 
commctrl.TB_ADDBUTTONS, 1, tbb)
+            # i have to count myself 'coz TB_BUTTONCOUNT counts separators 
too...
+            parent._buttonCount += 1
+
+#    TOOLINFO stru (cbSize, uFlags, hwnd, uId, rect, hinst, lpszText, lParam)
+            buff = array.array('c', '%s \0x00' % (textEncode(description) or 
''))
+            addrText = buff.buffer_info()[0]
+            format = "IIiIllllili"
+            size = struct.calcsize(format)
+            ti = struct.pack(format, size, 0, parent.toolbar.GetHwnd(), id, 0, 
0, 0, 0, 0, addrText, 0)
+            win32gui.SendMessage(parent._htt, commctrl.TTM_UPDATETIPTEXT , 0, 
ti)
+
+            widget = ToolBar.ToolButton(parent, id, check)
+
+        else:
+            widget = None
+            #event.container.AddSeparator()
+            tbb=struct.pack("iibbli", 0, 0, commctrl.TBSTATE_ENABLED, 
commctrl.TBSTYLE_SEP, 0, 0)
+            win32gui.SendMessage(parent.toolbar.GetHwnd(), 
commctrl.TB_ADDBUTTONS, 1, tbb)
+            
+        self.__widget = widget
+
+        return widget
+
+
+    # -------------------------------------------------------------------------
+    # Events
+    # -------------------------------------------------------------------------
+
+    def __on_tool(self, event):
+        self._gfObject._event_fire()
+
+
+    # -------------------------------------------------------------------------
+    # Check/uncheck menu item
+    # -------------------------------------------------------------------------
+
+    def _ui_switch_on_(self):
+        if self.__widget is not None:
+            # FIXME: why doesn't the next line work?
+            # self.__widget.SetToggle(True)
+            #self.__widget.GetToolBar().ToggleTool(self.__widget.GetId(), True)
+            pass
+    # -------------------------------------------------------------------------
+
+    def _ui_switch_off_(self):
+        if self.__widget is not None:
+            # FIXME: why doesn't the next line work?
+            # self.__widget.SetToggle(False)
+            #self.__widget.GetToolBar().ToggleTool(self.__widget.GetId(), 
False)
+            pass
+
+    # -------------------------------------------------------------------------
+    # Enable/disable menu item
+    # -------------------------------------------------------------------------
+
+    def _ui_enable_(self):
+        if self.__widget is not None:
+            # FIXME: why doesn't the next line work?
+            # self.__widget.Enable(True)
+            #self.__widget.GetToolBar().EnableTool(self.__widget.GetId(), True)
+            win32gui.SendMessage(self.parent.toolbar.GetHwnd(), 
commctrl.TB_ENABLEBUTTON, self.id, 1)
+
+    # -------------------------------------------------------------------------
+
+    def _ui_disable_(self):
+        if self.__widget is not None:
+            # FIXME: why doesn't the next line work?
+            # self.__widget.Enable(False)
+            #self.__widget.GetToolBar().EnableTool(self.__widget.GetId(), 
False)
+            win32gui.SendMessage(self.parent.toolbar.GetHwnd(), 
commctrl.TB_ENABLEBUTTON, self.id, 0)
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+  'baseClass': UIToolButton,
+  'provides' : 'GFToolButton',
+  'container': False
+}





reply via email to

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