[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9046 - in trunk/gnue-forms/src/uidrivers/win32: . widgets widget
From: |
btami |
Subject: |
[gnue] r9046 - in trunk/gnue-forms/src/uidrivers/win32: . widgets widgets/form |
Date: |
Fri, 17 Nov 2006 03:32:02 -0600 (CST) |
Author: btami
Date: 2006-11-17 03:32:00 -0600 (Fri, 17 Nov 2006)
New Revision: 9046
Modified:
trunk/gnue-forms/src/uidrivers/win32/GFwin32App.py
trunk/gnue-forms/src/uidrivers/win32/MenuBar.py
trunk/gnue-forms/src/uidrivers/win32/ToolBar.py
trunk/gnue-forms/src/uidrivers/win32/UILoginHandler.py
trunk/gnue-forms/src/uidrivers/win32/UIdriver.py
trunk/gnue-forms/src/uidrivers/win32/common.py
trunk/gnue-forms/src/uidrivers/win32/dialog.py
trunk/gnue-forms/src/uidrivers/win32/dialogs.py
trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
trunk/gnue-forms/src/uidrivers/win32/widgets/box.py
trunk/gnue-forms/src/uidrivers/win32/widgets/button.py
trunk/gnue-forms/src/uidrivers/win32/widgets/entry.py
trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py
trunk/gnue-forms/src/uidrivers/win32/widgets/form/wrappers.py
trunk/gnue-forms/src/uidrivers/win32/widgets/image.py
trunk/gnue-forms/src/uidrivers/win32/widgets/label.py
trunk/gnue-forms/src/uidrivers/win32/widgets/page.py
trunk/gnue-forms/src/uidrivers/win32/widgets/scrollbar.py
Log:
started of pep8ification, applied reindent.py
Modified: trunk/gnue-forms/src/uidrivers/win32/GFwin32App.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/GFwin32App.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/GFwin32App.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -37,12 +37,12 @@
class GFwin32App:
- _mainLoop= None
+ _mainLoop= None
- _HwndToTkObj = {}
- _MainWindowList = []
-
- def MainLoop (self):
+ _HwndToTkObj = {}
+ _MainWindowList = []
+
+ def MainLoop (self):
# just to launch one win32's mainloop
# otherwise, the app does not finishes cleanly when several windows
are open
# 'cause the first mainloop gets all the events
@@ -50,4 +50,3 @@
if self._mainLoop==None:
self._mainLoop= 1
win32gui.PumpMessages()
-
Modified: trunk/gnue-forms/src/uidrivers/win32/MenuBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/MenuBar.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/MenuBar.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -37,64 +37,63 @@
class MenuBar(_BaseMenuBar):
- # Create the menu
- def init(self):
- self.menu = win32gui.CreateMenu()
- return self.menu
+ # Create the menu
+ def init(self):
+ self.menu = win32gui.CreateMenu()
+ return self.menu
- # 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
+ # 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
- # Add a menu item (action)
- def addAction(self, name, parent, userAction):
- label = name
- hotkey = userAction.getHotKeyText()
- iconloc = userAction.getIconLocation(size="16x16")
+ # Add a menu item (action)
+ def addAction(self, name, parent, userAction):
+ label = name
+ hotkey = userAction.getHotKeyText()
+ iconloc = userAction.getIconLocation(size="16x16")
- if hotkey:
- label += '\t%s' % hotkey
+ if hotkey:
+ label += '\t%s' % hotkey
- # Set the action icon if available
- if iconloc:
- try:
- # Some caching logic for faster second/third forms
- icon = _cachedIcons[iconloc]
- except KeyError:
- pass
+ # Set the action icon if available
+ if iconloc:
+ try:
+ # Some caching logic for faster second/third forms
+ icon = _cachedIcons[iconloc]
+ except KeyError:
+ pass
- id = getNextId()
- self.container.addDescription(id, textEncode(userAction.description) or '')
- win32gui.AppendMenu(parent, _menustyle, id, textEncode(label))
- self.container.Connect(id, lambda u=userAction: self._fire(u))
+ id = getNextId()
+ self.container.addDescription(id, textEncode(userAction.description)
or '')
+ win32gui.AppendMenu(parent, _menustyle, id, textEncode(label))
+ self.container.Connect(id, lambda u=userAction: self._fire(u))
- return (parent, id)
+ return (parent, id)
- # Add a separator
- def addSeparator(self, parent):
- win32gui.AppendMenu(parent, win32con.MF_SEPARATOR, 0, "")
+ # Add a separator
+ def addSeparator(self, parent):
+ win32gui.AppendMenu(parent, 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)
- except:
- pass
+ # Enable a menu item
+ def enableItem(self, item):
+ parent, id = item
+ try:
+ win32gui.EnableMenuItem(parent, 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)
- except:
- pass
+ # Disable a menu item
+ def disableItem(self, item):
+ parent, id = item
+ try:
+ win32gui.EnableMenuItem(parent, id,
win32con.MF_BYCOMMAND|win32con.MF_GRAYED)
+ except:
+ pass
_cachedIcons = {}
-
Modified: trunk/gnue-forms/src/uidrivers/win32/ToolBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/ToolBar.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/ToolBar.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -47,120 +47,120 @@
class ToolBar(_BaseToolBar):
- # Create the menu
- def init(self):
- hinst = win32api.GetModuleHandle(None)
- style = win32con.WS_CHILD | commctrl.TBSTYLE_TOOLTIPS |
commctrl.TBSTYLE_FLAT #|win32con.WS_BORDER
- styleEx = 0
- self.toolbar = mainToolBar = Win32Window(self.driver, styleEx,
commctrl.TOOLBARCLASSNAME, "GNUe toolbar",
- style, 0, 0, 0, 0,
- self.container, getNextId(), hinst)
+ # Create the menu
+ def init(self):
+ hinst = win32api.GetModuleHandle(None)
+ style = win32con.WS_CHILD | commctrl.TBSTYLE_TOOLTIPS |
commctrl.TBSTYLE_FLAT #|win32con.WS_BORDER
+ styleEx = 0
+ self.toolbar = mainToolBar = Win32Window(self.driver, styleEx,
commctrl.TOOLBARCLASSNAME, "GNUe toolbar",
+ style, 0, 0, 0, 0,
+ self.container, getNextId(), hinst)
- style = win32con.WS_CHILD | win32con.SS_SUNKEN
- Win32Window(self.driver, 0, 'STATIC', '', style, 0, 30, 9999, 2,
self.toolbar)
-
- if XP:
- self.himl = himl = win32gui.ImageList_Create(24, 24,
commctrl.ILC_COLOR32, 0, 3)
- else:
- iconpath = GConfig.getInstalledBase('form_images', 'common_images')
- iconloc = os.path.join(iconpath, 'forms/default', 'toolbar-24x24.bmp')
- if not os.path.isfile(iconloc):
- print "*** WARNING: Cannot add 'toolbar-24x24.bmp' to toolbar"
- return
- else:
- himl = win32gui.ImageList_LoadImage(0, iconloc, 24, 0,
win32api.RGB(192,192,192), win32con.IMAGE_BITMAP,
- win32con.LR_LOADFROMFILE | win32con.LR_SHARED |
win32con.LR_CREATEDIBSECTION)
-
- tbab = struct.pack("ii", 0, himl)
- win32gui.SendMessage(mainToolBar.GetHwnd(), commctrl.TB_SETIMAGELIST, 0,
himl)
+ style = win32con.WS_CHILD | win32con.SS_SUNKEN
+ Win32Window(self.driver, 0, 'STATIC', '', style, 0, 30, 9999, 2,
self.toolbar)
+
+ if XP:
+ self.himl = himl = win32gui.ImageList_Create(24, 24,
commctrl.ILC_COLOR32, 0, 3)
+ else:
+ iconpath = GConfig.getInstalledBase('form_images', 'common_images')
+ iconloc = os.path.join(iconpath, 'forms/default',
'toolbar-24x24.bmp')
+ if not os.path.isfile(iconloc):
+ print "*** WARNING: Cannot add 'toolbar-24x24.bmp' to toolbar"
+ return
+ else:
+ himl = win32gui.ImageList_LoadImage(0, iconloc, 24, 0,
win32api.RGB(192,192,192), win32con.IMAGE_BITMAP,
+ win32con.LR_LOADFROMFILE | win32con.LR_SHARED |
win32con.LR_CREATEDIBSECTION)
- 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)
- self.toolbar.Show()
+ tbab = struct.pack("ii", 0, himl)
+ win32gui.SendMessage(mainToolBar.GetHwnd(), commctrl.TB_SETIMAGELIST,
0, himl)
- return self.toolbar
+ self._htt = win32gui.SendMessage(mainToolBar.GetHwnd(),
commctrl.TB_GETTOOLTIPS, 0, 0)
+ win32gui.SendMessage(self._htt, commctrl.TTM_SETMAXTIPWIDTH , 0, 250)
- # Add a menu item (action)
- def addAction(self, name, userAction):
- parent = self.toolbar
- label = name
+ self._buttonCount = 0
+ win32gui.SendMessage(mainToolBar.GetHwnd(), commctrl.TB_AUTOSIZE, 0, 0)
+ self.toolbar.Show()
- # Create an event binding in windows
- id = getNextId()
- event = 'request' + userAction.event
-
- if XP:
- iconloc = userAction.getIconLocation(format="bmp", size="24x24")
-
- # Set the action icon if available
- if iconloc:
- icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_SHARED
- him = win32gui.LoadImage(0, iconloc, win32con.IMAGE_BITMAP, 24, 24,
icon_flags)
- win32gui.ImageList_Add(self.himl, him, 0)
- else:
- print "** WARNING: Cannot add '%s' to toolbar; no icon" %
userAction.event
- return
-
- if userAction.canToggle:
- self.container.Connect(id,
- lambda u=userAction,
- tb=parent.GetHwnd(): self._fire(u,
- not win32gui.SendMessage(tb, commctrl.TB_ISBUTTONCHECKED, id,
- 0)))
- check = 1
- style = commctrl.TBSTYLE_CHECK
-
- else:
- self.container.Connect(id,
- lambda u=userAction: self._fire(u, False))
- check = 0
- style = commctrl.TBSTYLE_BUTTON
+ return self.toolbar
+ # Add a menu item (action)
+ def addAction(self, name, userAction):
+ parent = self.toolbar
+ label = name
+
+ # Create an event binding in windows
+ id = getNextId()
+ event = 'request' + userAction.event
+
+ if XP:
+ iconloc = userAction.getIconLocation(format="bmp", size="24x24")
+
+ # Set the action icon if available
+ if iconloc:
+ icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_SHARED
+ him = win32gui.LoadImage(0, iconloc, win32con.IMAGE_BITMAP,
24, 24, icon_flags)
+ win32gui.ImageList_Add(self.himl, him, 0)
+ else:
+ print "** WARNING: Cannot add '%s' to toolbar; no icon" %
userAction.event
+ return
+
+ if userAction.canToggle:
+ self.container.Connect(id,
+ lambda u=userAction,
+ tb=parent.GetHwnd(): self._fire(u,
+ not win32gui.SendMessage(tb,
commctrl.TB_ISBUTTONCHECKED, id,
+ 0)))
+ check = 1
+ style = commctrl.TBSTYLE_CHECK
+
+ else:
+ self.container.Connect(id,
+ lambda u=userAction: self._fire(u, False))
+ check = 0
+ style = commctrl.TBSTYLE_BUTTON
+
# TBBUTTON stru (iBitmap, idCommand, fsState, fsStyle, dwData, iString)
- tbb=struct.pack("iibbli", self._buttonCount, id, commctrl.TBSTATE_ENABLED,
style, 0, 0)
- win32gui.SendMessage(parent.GetHwnd(), commctrl.TB_ADDBUTTONS, 1, tbb)
- # i have to count myself 'coz TB_BUTTONCOUNT counts separators too...
- self._buttonCount += 1
+ tbb=struct.pack("iibbli", self._buttonCount, id,
commctrl.TBSTATE_ENABLED, style, 0, 0)
+ win32gui.SendMessage(parent.GetHwnd(), commctrl.TB_ADDBUTTONS, 1, tbb)
+ # i have to count myself 'coz TB_BUTTONCOUNT counts separators too...
+ self._buttonCount += 1
# TOOLINFO stru (cbSize, uFlags, hwnd, uId, rect, hinst, lpszText, lParam)
- buff = array.array('c', '%s \0x00' % (textEncode(userAction.description)
or ''))
- addrText = buff.buffer_info()[0]
- format = "IIiIllllili"
- size = struct.calcsize(format)
- 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)
+ buff = array.array('c', '%s \0x00' %
(textEncode(userAction.description) or ''))
+ addrText = buff.buffer_info()[0]
+ format = "IIiIllllili"
+ size = struct.calcsize(format)
+ 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)
- # Add a separator
- def addSeparator(self):
- tbb=struct.pack("iibbli", 0, 0, commctrl.TBSTATE_ENABLED,
commctrl.TBSTYLE_SEP, 0, 0)
- win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ADDBUTTONS, 1,
tbb)
+ # Add a separator
+ def addSeparator(self):
+ tbb=struct.pack("iibbli", 0, 0, commctrl.TBSTATE_ENABLED,
commctrl.TBSTYLE_SEP, 0, 0)
+ win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ADDBUTTONS,
1, tbb)
- # Enable a menu item
- def enableItem(self, item):
- parent, id, check = item
- win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ENABLEBUTTON, id,
1)
+ # Enable a menu item
+ def enableItem(self, item):
+ parent, id, check = item
+ win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ENABLEBUTTON,
id, 1)
- # Disable a menu item
- def disableItem(self, item):
- parent, id, check = item
- win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ENABLEBUTTON, id,
0)
+ # Disable a menu item
+ def disableItem(self, item):
+ parent, id, check = item
+ win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_ENABLEBUTTON,
id, 0)
- def startingItem(self, item):
- parent, id, check = item
- if check:
- win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_CHECKBUTTON,
id, 1)
- else:
- win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_PRESSBUTTON,
id, 1)
+ def startingItem(self, item):
+ parent, id, check = item
+ 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
- if check:
- win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_CHECKBUTTON,
id, 0)
- else:
- win32gui.SendMessage(self.toolbar.GetHwnd(), commctrl.TB_PRESSBUTTON,
id, 0)
+ def endingItem(self, item):
+ parent, id, check = item
+ if check:
+ win32gui.SendMessage(self.toolbar.GetHwnd(),
commctrl.TB_CHECKBUTTON, id, 0)
+ else:
+ win32gui.SendMessage(self.toolbar.GetHwnd(),
commctrl.TB_PRESSBUTTON, id, 0)
Modified: trunk/gnue-forms/src/uidrivers/win32/UILoginHandler.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/UILoginHandler.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/UILoginHandler.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -34,25 +34,25 @@
class UILoginHandler(GLoginHandler.LoginHandler):
- # ---------------------------------------------------------------------------
- # Create an instance of an InputDialog and return it's result
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Create an instance of an InputDialog and return it's result
+ #
---------------------------------------------------------------------------
- def _askLogin_ (self, title, fields):
+ def _askLogin_ (self, title, fields):
- lfields = fields [:]
- if lfields [0][2] != 'image':
- imageFile = gConfigForms('loginBMP')
- if not os.path.exists (imageFile):
- imageFile = os.path.join (os.path.normpath ( \
- GConfig.getInstalledBase ('forms_images', 'common_images')),
- gConfigForms ('loginBMP'))
+ lfields = fields [:]
+ if lfields [0][2] != 'image':
+ imageFile = gConfigForms('loginBMP')
+ if not os.path.exists (imageFile):
+ imageFile = os.path.join (os.path.normpath ( \
+ GConfig.getInstalledBase ('forms_images',
'common_images')),
+ gConfigForms ('loginBMP'))
- if os.path.exists (imageFile):
- lfields.insert (0, ('', imageFile, 'image', None, None, []))
+ if os.path.exists (imageFile):
+ lfields.insert (0, ('', imageFile, 'image', None, None, []))
- dlg = dialogs.InputDialog (0, title, lfields)
+ dlg = dialogs.InputDialog (0, title, lfields)
- dlg.DoModal ()
- result = dlg.inputData
- return result
+ dlg.DoModal ()
+ result = dlg.inputData
+ return result
Modified: trunk/gnue-forms/src/uidrivers/win32/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/UIdriver.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/UIdriver.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -34,9 +34,9 @@
from gnue.forms.uidrivers._base import Exceptions
try:
- import win32gui, win32con, afxres, commctrl, win32clipboard, win32ui
+ import win32gui, win32con, afxres, commctrl, win32clipboard, win32ui
except ImportError:
- raise Exceptions.DriverNotSupported, _("The GNUe-Forms Win32 driver requires
PyWin32.")
+ raise Exceptions.DriverNotSupported, _("The GNUe-Forms Win32 driver
requires PyWin32.")
from pywin.mfc import window
from gnue.common import events
@@ -56,28 +56,28 @@
def OnWMVScroll(hwnd, msg, wParam, lParam, widget):
- return widget.OnWMVScroll(hwnd, msg, wParam, lParam)
+ return widget.OnWMVScroll(hwnd, msg, wParam, lParam)
def OnWMMenuselect(hwnd, msg, wParam, lParam, widget):
- return widget.OnWMMenuselect(hwnd, msg, wParam, lParam)
+ return widget.OnWMMenuselect(hwnd, msg, wParam, lParam)
def OnWMNotify(hwnd, msg, wParam, lParam, widget):
- return widget.OnWMNotify(hwnd, msg, wParam, lParam)
+ return widget.OnWMNotify(hwnd, msg, wParam, lParam)
def OnWMDestroy(hwnd, msg, wParam, lParam, widget):
- win32gui.DestroyWindow(hwnd)
+ win32gui.DestroyWindow(hwnd)
def OnWMClose(hwnd, msg, wParam, lParam, widget):
- return widget.OnWMClose(hwnd, msg, wParam, lParam)
+ return widget.OnWMClose(hwnd, msg, wParam, lParam)
def OnWMSize(hwnd, msg, wParam, lParam, widget):
- return widget.OnWMSize(hwnd, msg, wParam, lParam)
+ return widget.OnWMSize(hwnd, msg, wParam, lParam)
def OnWMCommand(hwnd, msg, wParam, lParam, widget):
- return widget.OnWMCommand(hwnd, msg, wParam, lParam)
+ return widget.OnWMCommand(hwnd, msg, wParam, lParam)
def OnWMDefault(hwnd, msg, wParam, lParam, widget):
- return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
+ return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
#
# GFUserInterface
@@ -87,174 +87,174 @@
#
class GFUserInterface(commonToolkit.GFUserInterface):
- _message_map = { win32con.WM_VSCROLL : OnWMVScroll,
- win32con.WM_MENUSELECT : OnWMMenuselect,
- win32con.WM_NOTIFY : OnWMNotify,
- win32con.WM_DESTROY : OnWMDestroy,
- win32con.WM_CLOSE : OnWMClose,
- win32con.WM_SIZE : OnWMSize,
- win32con.WM_COMMAND : OnWMCommand }
+ _message_map = { win32con.WM_VSCROLL : OnWMVScroll,
+ win32con.WM_MENUSELECT : OnWMMenuselect,
+ win32con.WM_NOTIFY : OnWMNotify,
+ win32con.WM_DESTROY : OnWMDestroy,
+ win32con.WM_CLOSE : OnWMClose,
+ win32con.WM_SIZE : OnWMSize,
+ win32con.WM_COMMAND : OnWMCommand }
- _wndclass = None
-
- # ---------------------------------------------------------------------------
- # Constructor
- # ---------------------------------------------------------------------------
-
- def __init__(self, eventHandler, name="Undefined", disableSplash=None,
- parentContainer=None, moduleName=None):
-
- commonToolkit.GFUserInterface.__init__(self, eventHandler, name,
- disableSplash, parentContainer, moduleName)
- self.__splash = None
-
+ _wndclass = None
+
+ #
---------------------------------------------------------------------------
+ # Constructor
+ #
---------------------------------------------------------------------------
+
+ def __init__(self, eventHandler, name="Undefined", disableSplash=None,
+ parentContainer=None, moduleName=None):
+
+ commonToolkit.GFUserInterface.__init__(self, eventHandler, name,
+ disableSplash, parentContainer, moduleName)
+ self.__splash = None
+
- def _wndproc(self, hwnd, msg, wParam, lParam):
- try:
- widget = self._win32app._HwndToTkObj[hwnd]
- except:
- return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
-
- OnWM = self._message_map.get(msg, OnWMDefault)
- return OnWM(hwnd, msg, wParam, lParam, widget)
+ def _wndproc(self, hwnd, msg, wParam, lParam):
+ try:
+ widget = self._win32app._HwndToTkObj[hwnd]
+ except:
+ return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
+
+ OnWM = self._message_map.get(msg, OnWMDefault)
+ return OnWM(hwnd, msg, wParam, lParam, widget)
- # ---------------------------------------------------------------------------
- # Initialize the user interface
- # ---------------------------------------------------------------------------
-
- def _initialize(self):
+ #
---------------------------------------------------------------------------
+ # Initialize the user interface
+ #
---------------------------------------------------------------------------
+
+ def _initialize(self):
- self._disabledColour = afxres.AFX_IDC_COLOR_LIGHTGRAY
- self._win32app = getWin32App()
- win32gui.InitCommonControls()
-
- try:
- icon = win32gui.LoadImage(0, sys.prefix+'\py.ico', win32con.IMAGE_ICON,
- 0, 0, win32con.LR_LOADFROMFILE |
win32con.LR_DEFAULTSIZE)
- except:
- icon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
+ self._disabledColour = afxres.AFX_IDC_COLOR_LIGHTGRAY
+ self._win32app = getWin32App()
+ win32gui.InitCommonControls()
- if not self._wndclass:
- # Register the "GNUeWindow" class.
- wc = win32gui.WNDCLASS()
- wc.lpszClassName = "GNUeWindow"
- wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
- wc.hIcon = icon
- wc.hbrBackground = win32con.COLOR_BTNSHADOW #win32con.COLOR_WINDOW
- wc.lpfnWndProc = self._wndproc
- self.__class__._wndclass = win32gui.RegisterClass(wc)
+ try:
+ icon = win32gui.LoadImage(0, sys.prefix+'\py.ico',
win32con.IMAGE_ICON,
+ 0, 0, win32con.LR_LOADFROMFILE
| win32con.LR_DEFAULTSIZE)
+ except:
+ icon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
- #
- # SplashScreen
- #
+ if not self._wndclass:
+ # Register the "GNUeWindow" class.
+ wc = win32gui.WNDCLASS()
+ wc.lpszClassName = "GNUeWindow"
+ wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
+ wc.hIcon = icon
+ wc.hbrBackground = win32con.COLOR_BTNSHADOW #win32con.COLOR_WINDOW
+ wc.lpfnWndProc = self._wndproc
+ self.__class__._wndclass = win32gui.RegisterClass(wc)
+
+ #
+ # SplashScreen
+ #
# if not self._disableSplash:
# self.splash = UIWXSplashScreen()
- font_name = gConfigForms('faceName')
- if not font_name:
- # explicite boolean check forces generated report parameter dialog
- # to use ANSI_VAR_FONT (GConfig typecast initialization problem...)
- if gConfigForms ('fixedWidthFont') == True:
- fnt = win32con.ANSI_FIXED_FONT
- else:
- fnt = win32con.ANSI_VAR_FONT
+ font_name = gConfigForms('faceName')
+ if not font_name:
+ # explicite boolean check forces generated report parameter dialog
+ # to use ANSI_VAR_FONT (GConfig typecast initialization problem...)
+ if gConfigForms ('fixedWidthFont') == True:
+ fnt = win32con.ANSI_FIXED_FONT
+ else:
+ fnt = win32con.ANSI_VAR_FONT
- lf = win32gui.GetObject(win32gui.GetStockObject(fnt))
- font_name = lf.lfFaceName
-
- font_spec = {'name':font_name, 'height':int(gConfigForms('pointSize'))}
- self._font = win32ui.CreateFont(font_spec)
+ lf = win32gui.GetObject(win32gui.GetStockObject(fnt))
+ font_name = lf.lfFaceName
+
+ font_spec = {'name':font_name, 'height':int(gConfigForms('pointSize'))}
+ self._font = win32ui.CreateFont(font_spec)
- # Create a dummy window used to compute sizes
- dummyWindow = window.Wnd(win32ui.CreateWnd())
- dc = dummyWindow.GetWindowDC()
+ # Create a dummy window used to compute sizes
+ dummyWindow = window.Wnd(win32ui.CreateWnd())
+ dc = dummyWindow.GetWindowDC()
- dc.SelectObject(self._font)
- metrics = dc.GetTextMetrics()
- maxWidth = metrics["tmAveCharWidth"]
- maxHeight = metrics["tmHeight"]
- maxDescent = metrics["tmDescent"]
- maxLeading = metrics["tmExternalLeading"]
-
- self.textWidth = int(maxWidth+maxLeading) # The pixel width of text
inside a widget
- self.textWidth = int(self.textWidth)
- self.textHeight = int(maxHeight+maxDescent) # The pixel height of text
inside a widget
- self.widgetWidth = self.textWidth # The pixel width of a 1
char widget (for things like buttons)
- self.widgetHeight = self.textHeight + 4 # The pixel height of a 1
char widget (for things like buttons)
-
- font_spec = {'name':font_name, 'height':int(gConfigForms('pointSize')) or
-1}
- self._font = win32ui.CreateFont(font_spec)
-
- dummyWindow.ReleaseDC(dc)
+ dc.SelectObject(self._font)
+ metrics = dc.GetTextMetrics()
+ maxWidth = metrics["tmAveCharWidth"]
+ maxHeight = metrics["tmHeight"]
+ maxDescent = metrics["tmDescent"]
+ maxLeading = metrics["tmExternalLeading"]
+
+ self.textWidth = int(maxWidth+maxLeading) # The pixel width of
text inside a widget
+ self.textWidth = int(self.textWidth)
+ self.textHeight = int(maxHeight+maxDescent) # The pixel height of
text inside a widget
+ self.widgetWidth = self.textWidth # The pixel width of a
1 char widget (for things like buttons)
+ self.widgetHeight = self.textHeight + 4 # The pixel height of a
1 char widget (for things like buttons)
+
+ font_spec = {'name':font_name, 'height':int(gConfigForms('pointSize'))
or -1}
+ self._font = win32ui.CreateFont(font_spec)
+
+ dummyWindow.ReleaseDC(dc)
- # mainLoop
- #
- # The primary loop of the user interface. Called once the UI is
- # fully activated
- #
- def mainLoop(self):
- self._win32app.MainLoop()
+ # mainLoop
+ #
+ # The primary loop of the user interface. Called once the UI is
+ # fully activated
+ #
+ def mainLoop(self):
+ self._win32app.MainLoop()
- # ---------------------------------------------------------------------------
- # Start an input dialog and return the data record or None if cancelled
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Start an input dialog and return the data record or None if cancelled
+ #
---------------------------------------------------------------------------
- def _getInput (self, title, fields, cancel = True):
-
- try:
- parent = self._win32app._MainWindowList[0].GetHwnd()
- except:
- parent = 0
- dialog = dialogs.InputDialog (parent, title, fields, cancel)
- dialog.DoModal ()
- return dialog.inputData
-
+ def _getInput (self, title, fields, cancel = True):
+
+ try:
+ parent = self._win32app._MainWindowList[0].GetHwnd()
+ except:
+ parent = 0
+ dialog = dialogs.InputDialog (parent, title, fields, cancel)
+ dialog.DoModal ()
+ return dialog.inputData
+
- # ---------------------------------------------------------------------------
- # Show a simple error message
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Show a simple error message
+ #
---------------------------------------------------------------------------
- def _ui_show_error_(self, message):
+ def _ui_show_error_(self, message):
- win32gui.MessageBox(0, message, "GNU Enterprise",
- win32con.MB_TASKMODAL | win32con.MB_ICONERROR | win32con.MB_OK)
+ win32gui.MessageBox(0, message, "GNU Enterprise",
+ win32con.MB_TASKMODAL | win32con.MB_ICONERROR | win32con.MB_OK)
- # ---------------------------------------------------------------------------
- # Show an exception
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Show an exception
+ #
---------------------------------------------------------------------------
- def _ui_show_exception_(self, group, name, message, detail):
-
- try:
- parent = self._win32app._MainWindowList[0].GetHwnd()
- except:
- parent = 0
- dialog = dialogs.ExceptionDialog (parent, group, name, message, detail)
- dialog.DoModal ()
-
+ def _ui_show_exception_(self, group, name, message, detail):
+
+ try:
+ parent = self._win32app._MainWindowList[0].GetHwnd()
+ except:
+ parent = 0
+ dialog = dialogs.ExceptionDialog (parent, group, name, message, detail)
+ dialog.DoModal ()
- # ---------------------------------------------------------------------------
- # Exit the application
- # ---------------------------------------------------------------------------
- def _ui_exit_(self):
- """
- Exit the application.
- """
+ #
---------------------------------------------------------------------------
+ # Exit the application
+ #
---------------------------------------------------------------------------
- for child in self._children:
- self._win32app._MainWindowList.remove(child.mainWindow)
- child.mainWindow.Destroy()
+ def _ui_exit_(self):
+ """
+ Exit the application.
+ """
- if len(self._win32app._MainWindowList) == 0:
- win32gui.PostQuitMessage(0) # Terminate the app.
+ for child in self._children:
+ self._win32app._MainWindowList.remove(child.mainWindow)
+ child.mainWindow.Destroy()
- #~ for window in self._win32app._MainWindowList:
- #~ if isinstance(window, Win32Window):
- #~ window.Enable(1)
- #~ win32gui.SetActiveWindow(window.GetHwnd())
+ if len(self._win32app._MainWindowList) == 0:
+ win32gui.PostQuitMessage(0) # Terminate the app.
+
+ #~ for window in self._win32app._MainWindowList:
+ #~ if isinstance(window, Win32Window):
+ #~ window.Enable(1)
+ #~ win32gui.SetActiveWindow(window.GetHwnd())
Modified: trunk/gnue-forms/src/uidrivers/win32/common.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/common.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/common.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -36,27 +36,27 @@
_idPos = 1000
def getNextId():
- global _idPos
- _idPos += 1
- return _idPos
+ global _idPos
+ _idPos += 1
+ return _idPos
def centerWindow(hwnd):
- desktop = win32gui.GetDesktopWindow()
- l,t,r,b = win32gui.GetWindowRect(hwnd)
- dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
- center_x, center_y = (dt_r-dt_l)/2, (dt_b-dt_t)/2
- win32gui.MoveWindow(hwnd, center_x-((r-l)/2), center_y-((b-t)/2), r-l, b-t,
1)
-
-
-def textEncode(u_string):
+ desktop = win32gui.GetDesktopWindow()
+ l,t,r,b = win32gui.GetWindowRect(hwnd)
+ dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
+ center_x, center_y = (dt_r-dt_l)/2, (dt_b-dt_t)/2
+ win32gui.MoveWindow(hwnd, center_x-((r-l)/2), center_y-((b-t)/2), r-l,
b-t, 1)
+
+
+def textEncode(u_string):
if type(u_string)==UnicodeType:
return u_string.encode(gConfig('textEncoding'),'replace')
else:
return u_string
-def textDecode(string):
+def textDecode(string):
if type(string)==StringType:
return unicode(string, gConfig('textEncoding'))
else:
Modified: trunk/gnue-forms/src/uidrivers/win32/dialog.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/dialog.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/dialog.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -39,91 +39,91 @@
class BaseDialog:
- def __init__ (self, parent, title, cancel = False, ok = True):
- win32gui.InitCommonControls()
- self.hinst = win32api.GetModuleHandle(None)
- self.parent = parent
-
- self.message_map = {
- win32con.WM_COMMAND: self.OnCommand,
- win32con.WM_INITDIALOG: self.OnInitDialog,
- win32con.WM_CLOSE: self.OnClose,
- }
+ def __init__ (self, parent, title, cancel = False, ok = True):
+ win32gui.InitCommonControls()
+ self.hinst = win32api.GetModuleHandle(None)
+ self.parent = parent
+
+ self.message_map = {
+ win32con.WM_COMMAND: self.OnCommand,
+ win32con.WM_INITDIALOG: self.OnInitDialog,
+ win32con.WM_CLOSE: self.OnClose,
+ }
- dlgClassName = self._RegisterWndClass()
-
- style = win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | \
- win32con.DS_SETFONT | win32con.WS_SYSMENU | win32con.DS_MODALFRAME
-
- self.template = [ [textEncode(title), (0, 0, 120, 20), style, None, \
- (8, "MS Sans Serif"), None, dlgClassName], ]
-
- if ok:
- self.template.append ([BUTTON, _("Ok"), win32con.IDOK, (0, 0, 56, 15),
- win32con.WS_CHILD | win32con.WS_VISIBLE | \
- win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON])
- if cancel:
- self.template.append ([BUTTON, _("Cancel"), win32con.IDCANCEL, (60, 0,
56, 15),
- win32con.WS_CHILD | win32con.WS_VISIBLE | \
- win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
-
-
- def DoModal(self):
- self.oldfocus = win32gui.GetFocus()
- return win32gui.DialogBoxIndirect(self.hinst, self.template, self.parent,
self.message_map)
-
-
- def OnInitDialog(self, hwnd, msg, wparam, lparam):
- self.hwnd = hwnd
-
- def OnClose(self, hwnd, msg, wparam, lparam):
- win32gui.EndDialog(hwnd, 1)
- win32gui.SetFocus(self.oldfocus)
-
+ dlgClassName = self._RegisterWndClass()
+
+ style = win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION
| \
+ win32con.DS_SETFONT | win32con.WS_SYSMENU |
win32con.DS_MODALFRAME
+
+ self.template = [ [textEncode(title), (0, 0, 120, 20), style, None, \
+ (8, "MS Sans Serif"), None, dlgClassName], ]
+
+ if ok:
+ self.template.append ([BUTTON, _("Ok"), win32con.IDOK, (0, 0, 56,
15),
+ win32con.WS_CHILD | win32con.WS_VISIBLE | \
+ win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON])
+ if cancel:
+ self.template.append ([BUTTON, _("Cancel"), win32con.IDCANCEL,
(60, 0, 56, 15),
+ win32con.WS_CHILD | win32con.WS_VISIBLE | \
+ win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
+
+
+ def DoModal(self):
+ self.oldfocus = win32gui.GetFocus()
+ return win32gui.DialogBoxIndirect(self.hinst, self.template,
self.parent, self.message_map)
+
+
+ def OnInitDialog(self, hwnd, msg, wparam, lparam):
+ self.hwnd = hwnd
+
+ def OnClose(self, hwnd, msg, wparam, lparam):
+ win32gui.EndDialog(hwnd, 1)
+ win32gui.SetFocus(self.oldfocus)
+
- def Destroy(self):
- pass
-
+ def Destroy(self):
+ pass
+
- def OnCommand(self, hwnd, msg, wparam, lparam):
- id = win32api.LOWORD(wparam)
- if id == win32con.IDOK:
- win32gui.EndDialog(hwnd, 1)
- win32gui.SetFocus(self.oldfocus)
-
- elif id == win32con.IDCANCEL:
- win32gui.EndDialog(hwnd, 0)
- win32gui.SetFocus(self.oldfocus)
+ def OnCommand(self, hwnd, msg, wparam, lparam):
+ id = win32api.LOWORD(wparam)
+ if id == win32con.IDOK:
+ win32gui.EndDialog(hwnd, 1)
+ win32gui.SetFocus(self.oldfocus)
+
+ elif id == win32con.IDCANCEL:
+ win32gui.EndDialog(hwnd, 0)
+ win32gui.SetFocus(self.oldfocus)
+
+ def _RegisterWndClass(self):
+ className = "GNUe dialog"
+ global g_registeredClass
- def _RegisterWndClass(self):
- className = "GNUe dialog"
- global g_registeredClass
-
- try:
- icon = win32gui.LoadImage(0, sys.prefix+'\py.ico', win32con.IMAGE_ICON,
- 0, 0, win32con.LR_LOADFROMFILE |
win32con.LR_DEFAULTSIZE)
- except:
- icon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
+ try:
+ icon = win32gui.LoadImage(0, sys.prefix+'\py.ico',
win32con.IMAGE_ICON,
+ 0, 0, win32con.LR_LOADFROMFILE |
win32con.LR_DEFAULTSIZE)
+ except:
+ icon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
- if not g_registeredClass:
- message_map = {}
- wc = win32gui.WNDCLASS()
- wc.SetDialogProc() # Make it a dialog class.
- self.hinst = wc.hInstance = win32api.GetModuleHandle(None)
- wc.lpszClassName = className
- wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
- wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
+ if not g_registeredClass:
+ message_map = {}
+ wc = win32gui.WNDCLASS()
+ wc.SetDialogProc() # Make it a dialog class.
+ self.hinst = wc.hInstance = win32api.GetModuleHandle(None)
+ wc.lpszClassName = className
+ wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
+ wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
# wc.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
- wc.hIcon = icon
- wc.hbrBackground = win32con.COLOR_WINDOW
- wc.lpfnWndProc = message_map # could also specify a wndproc.
- wc.cbWndExtra = win32con.DLGWINDOWEXTRA + struct.calcsize("Pi")
- classAtom = win32gui.RegisterClass(wc)
- g_registeredClass = 1
- return className
-
-
+ wc.hIcon = icon
+ wc.hbrBackground = win32con.COLOR_WINDOW
+ wc.lpfnWndProc = message_map # could also specify a wndproc.
+ wc.cbWndExtra = win32con.DLGWINDOWEXTRA + struct.calcsize("Pi")
+ classAtom = win32gui.RegisterClass(wc)
+ g_registeredClass = 1
+ return className
+
+
if __name__ == '__main__':
- dialog = BaseDialog('MyDialog', cancel=True)
- dialog.DoModal()
\ No newline at end of file
+ dialog = BaseDialog('MyDialog', cancel=True)
+ dialog.DoModal()
Modified: trunk/gnue-forms/src/uidrivers/win32/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/dialogs.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/dialogs.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -46,667 +46,667 @@
# =============================================================================
class InvalidFieldTypeError (errors.ApplicationError):
- def __init__ (self, fieldtype):
- msg = u_("%s is not a valid type for an input field") % fieldtype
- errors.ApplicationError.__init__ (self, msg)
-
-
+ def __init__ (self, fieldtype):
+ msg = u_("%s is not a valid type for an input field") % fieldtype
+ errors.ApplicationError.__init__ (self, msg)
+
+
class InputDialog(BaseDialog):
- """
- Dialog class prompting the user for a given number of fields. These field
- definitions are specified as follows:
+ """
+ Dialog class prompting the user for a given number of fields. These field
+ definitions are specified as follows:
- A field definition is a tuple having these elements:
- - fieldlabel: This text will be used as label in the left column
- - fieldname: This is the key in the result-dictionary to contain the value
- entered by the user
- - fieldtype: Currently these types are supported:
- - label: The contents of 'fieldlabel' as static text
- - warning: The contents of 'fieldlabel' as static text, formatted as
- warning
- - string: A text entry control
- - password: A text entry control with obscured characters
- - dropdown: Foreach element given in 'elements' a separate ComboBox
- control will be created, where each one has it's own dictionary of
- allowed values. If a value is selected in one control, all others are
- synchronized to represent the same key-value.
- - default: Default value to use
- - masterfield: Used for 'dropdowns'. This item specifies another field
- definition acting as master field. If this master field is changed, the
- allowedValues of this dropdown will be changed accordingly. If a
- masterfield is specified the 'allowedValues' dictionaries are built like
- {master1: {key: value, key: value, ...}, master2: {key: value, ...}}
- - elements: sequence of input element tuples (label, allowedValues). This is
- used for dropdowns only. 'label' will be used as ToolTip for the control
- and 'allowedValues' gives a dictionary with all valid keys to be selected
- in the dropdown.
+ A field definition is a tuple having these elements:
+ - fieldlabel: This text will be used as label in the left column
+ - fieldname: This is the key in the result-dictionary to contain the value
+ entered by the user
+ - fieldtype: Currently these types are supported:
+ - label: The contents of 'fieldlabel' as static text
+ - warning: The contents of 'fieldlabel' as static text, formatted as
+ warning
+ - string: A text entry control
+ - password: A text entry control with obscured characters
+ - dropdown: Foreach element given in 'elements' a separate ComboBox
+ control will be created, where each one has it's own dictionary of
+ allowed values. If a value is selected in one control, all others
are
+ synchronized to represent the same key-value.
+ - default: Default value to use
+ - masterfield: Used for 'dropdowns'. This item specifies another field
+ definition acting as master field. If this master field is changed, the
+ allowedValues of this dropdown will be changed accordingly. If a
+ masterfield is specified the 'allowedValues' dictionaries are built
like
+ {master1: {key: value, key: value, ...}, master2: {key: value, ...}}
+ - elements: sequence of input element tuples (label, allowedValues). This
is
+ used for dropdowns only. 'label' will be used as ToolTip for the
control
+ and 'allowedValues' gives a dictionary with all valid keys to be
selected
+ in the dropdown.
- @return: If closed by 'Ok' the result is a dictionary with all values entered
- by the user, where the "fieldname"s will be used as keys. If the user has
- not selected a value from a dropdown (i.e. it has no values to select)
- there will be no such key in the result dictionary. If the dialog is
- canceled ('Cancel'-Button) the result will be None.
- """
- _FIELDTYPES = ['label', 'warning', 'string', 'password', 'dropdown', 'image']
- _NO_LABELS = ['label', 'warning', 'image']
-
- def __init__ (self, parent, title, fields, cancel = True):
+ @return: If closed by 'Ok' the result is a dictionary with all values
entered
+ by the user, where the "fieldname"s will be used as keys. If the user has
+ not selected a value from a dropdown (i.e. it has no values to select)
+ there will be no such key in the result dictionary. If the dialog is
+ canceled ('Cancel'-Button) the result will be None.
"""
- Create a new input dialog
+ _FIELDTYPES = ['label', 'warning', 'string', 'password', 'dropdown',
'image']
+ _NO_LABELS = ['label', 'warning', 'image']
- @param title: Dialog title
- @param fields: sequence of field definition tuples
- @param cancel: If True add a Cancel button to the dialog
- """
- BaseDialog.__init__(self, parent, title, cancel)
- self.message_map [win32con.WM_CTLCOLORSTATIC] = self.OnCtlColorStatic
- self.message_map [win32con.WM_CLOSE] = self.OnClose
+ def __init__ (self, parent, title, fields, cancel = True):
+ """
+ Create a new input dialog
+
+ @param title: Dialog title
+ @param fields: sequence of field definition tuples
+ @param cancel: If True add a Cancel button to the dialog
+ """
+ BaseDialog.__init__(self, parent, title, cancel)
+ self.message_map [win32con.WM_CTLCOLORSTATIC] = self.OnCtlColorStatic
+ self.message_map [win32con.WM_CLOSE] = self.OnClose
+
+ self.fields = fields
+ self.inputData = {}
+ self.controlsName = {}
+ self.__controls = []
+ self.__labels = []
+ self.__texts = []
+ self.__inputs = []
+ self.__warnings = []
+ self.__images = {}
+ self.__dropdowns = {}
- self.fields = fields
- self.inputData = {}
- self.controlsName = {}
- self.__controls = []
- self.__labels = []
- self.__texts = []
- self.__inputs = []
- self.__warnings = []
- self.__images = {}
- self.__dropdowns = {}
-
- # Now build and add all controls
- for field in fields:
- fieldtype = field[2]
- if not fieldtype in self._FIELDTYPES:
- raise InvalidFieldTypeError, fieldtype
- else:
- self.AddControl(field)
-
-
- def AddControl(self, field):
- label, name, ftype, default, master, elements = field
- cs = win32con.WS_CHILD | win32con.WS_VISIBLE
- es = win32con.WS_EX_CLIENTEDGE
-
- position = (0, 0, 0, 0)
- if ftype == 'label' or ftype == 'warning':
- ID = getNextId()
- s = cs | win32con.SS_CENTER #| win32con.WS_BORDER
- self.template.append([STATIC, textEncode(label), ID, position, s])
- self.__texts.append (ID)
- if ftype == 'warning':
- self.__warnings.append (ID)
+ # Now build and add all controls
+ for field in fields:
+ fieldtype = field[2]
+ if not fieldtype in self._FIELDTYPES:
+ raise InvalidFieldTypeError, fieldtype
+ else:
+ self.AddControl(field)
+
+
+ def AddControl(self, field):
+ label, name, ftype, default, master, elements = field
+ cs = win32con.WS_CHILD | win32con.WS_VISIBLE
+ es = win32con.WS_EX_CLIENTEDGE
- elif ftype == 'string' or ftype == 'password':
- ID = getNextId()
- s = cs | win32con.SS_LEFT #| win32con.WS_BORDER
- self.template.append([STATIC, textEncode(label), ID, position, s])
- self.__labels.append (ID)
- self.__controls.append (ID)
- self.controlsName [ID] = name
-
- ID = getNextId()
- s = cs | win32con.WS_TABSTOP #| win32con.WS_BORDER
- if ftype == 'password':
- s = s | win32con.ES_PASSWORD
- self.template.append([EDIT, default, ID, position, s,es])
- self.__inputs.append (ID)
+ position = (0, 0, 0, 0)
+ if ftype == 'label' or ftype == 'warning':
+ ID = getNextId()
+ s = cs | win32con.SS_CENTER #| win32con.WS_BORDER
+ self.template.append([STATIC, textEncode(label), ID, position, s])
+ self.__texts.append (ID)
+ if ftype == 'warning':
+ self.__warnings.append (ID)
- elif ftype == 'image':
- ID = getNextId()
- s = cs | win32con.SS_BITMAP
- self.template.append([STATIC, None, ID, position, s])
- imageFile = name
- bmp = win32gui.LoadImage(0, imageFile, win32con.IMAGE_BITMAP, \
- 0, 0, win32con.LR_LOADFROMFILE |
win32con.LR_DEFAULTSIZE)
- self.__images[ID] = bmp
+ elif ftype == 'string' or ftype == 'password':
+ ID = getNextId()
+ s = cs | win32con.SS_LEFT #| win32con.WS_BORDER
+ self.template.append([STATIC, textEncode(label), ID, position, s])
+ self.__labels.append (ID)
+ self.__controls.append (ID)
+ self.controlsName [ID] = name
- elif ftype == 'button':
- ID = getNextId()
- s = cs | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON
- self.template.append([BUTTON, textEncode(label), ID, position, s])
+ ID = getNextId()
+ s = cs | win32con.WS_TABSTOP #| win32con.WS_BORDER
+ if ftype == 'password':
+ s = s | win32con.ES_PASSWORD
+ self.template.append([EDIT, default, ID, position, s,es])
+ self.__inputs.append (ID)
- elif ftype == 'dropdown':
- ID = getNextId()
- s = cs | win32con.SS_LEFT #| win32con.WS_BORDER
- self.template.append([STATIC, textEncode(label), ID, position, s])
- self.__labels.append (ID)
- self.__controls.append (ID)
- self.controlsName [ID] = name
-
- ID = getNextId()
- s = cs | win32con.WS_TABSTOP | win32con.CBS_DROPDOWNLIST
- self.template.append([DROPDOWN, default, ID, position, s])
- self.__inputs.append (ID)
- self.__dropdowns[ID] = [default, master, elements, {}]
-
- self.__controls.append (ID)
- self.controlsName [ID] = name
-
-
- def OnInitDialog(self, hwnd, msg, wparam, lparam):
- BaseDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
-
- for ID in self.__images.keys():
- bmCtrl = win32gui.GetDlgItem(hwnd, ID)
- win32gui.SendMessage(bmCtrl, win32con.STM_SETIMAGE,
win32con.IMAGE_BITMAP, \
- self.__images[ID])
+ elif ftype == 'image':
+ ID = getNextId()
+ s = cs | win32con.SS_BITMAP
+ self.template.append([STATIC, None, ID, position, s])
+ imageFile = name
+ bmp = win32gui.LoadImage(0, imageFile, win32con.IMAGE_BITMAP, \
+ 0, 0, win32con.LR_LOADFROMFILE |
win32con.LR_DEFAULTSIZE)
+ self.__images[ID] = bmp
- self.__maxLabelWidth = 0
- for label in self.__labels:
- self.__maxLabelWidth = max(self.__maxLabelWidth, self.Width(label))
+ elif ftype == 'button':
+ ID = getNextId()
+ s = cs | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON
+ self.template.append([BUTTON, textEncode(label), ID, position, s])
- self.dlgWidth = 0
- for control in self.__controls:
- if control in self.__inputs:
- self.dlgWidth = max(self.dlgWidth, self.__maxLabelWidth +
self.Width(control))
- else:
- if control not in self.__warnings:
- self.dlgWidth = max(self.dlgWidth, self.Width(control))
+ elif ftype == 'dropdown':
+ ID = getNextId()
+ s = cs | win32con.SS_LEFT #| win32con.WS_BORDER
+ self.template.append([STATIC, textEncode(label), ID, position, s])
+ self.__labels.append (ID)
+ self.__controls.append (ID)
+ self.controlsName [ID] = name
+
+ ID = getNextId()
+ s = cs | win32con.WS_TABSTOP | win32con.CBS_DROPDOWNLIST
+ self.template.append([DROPDOWN, default, ID, position, s])
+ self.__inputs.append (ID)
+ self.__dropdowns[ID] = [default, master, elements, {}]
+
+ self.__controls.append (ID)
+ self.controlsName [ID] = name
- border = 10
- ypos = border
- for control in self.__controls:
- if (control in self.__images.keys()) or (control in self.__texts):
- if control in self.__warnings:
- dlgItem = win32gui.GetDlgItem(hwnd, control)
- text = win32gui.GetWindowText(dlgItem)
- #~ newText = self.wrapText(text, self.dlgWidth)
- #~ win32gui.SetDlgItemText(hwnd, control, newText)
- win32gui.SetDlgItemText(hwnd, control, text)
-
- self.SetPosition(control, (self.dlgWidth-self.Width(control))/2 +
border + 8 , ypos)
- ypos += self.Height(control) + 5
- elif control in self.__labels:
- self.SetPosition(control, border, ypos)
- else:
- self.SetPosition(control, border + self.__maxLabelWidth + 10, ypos)
- ypos += self.Height(control) + 3
-
- if control in self.__dropdowns.keys():
- bm = win32gui.GetDlgItem(hwnd, control)
- default, master, elements, rmap = self.__dropdowns[control]
-
- (label, allowed) = elements [0]
- if master is None:
- data = [allowed]
- else:
- data = allowed.values ()
+
+ def OnInitDialog(self, hwnd, msg, wparam, lparam):
+ BaseDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
- for vdict in data:
- for key,value in vdict.items():
- value = textEncode("%s" % value)
- self.__dropdowns[control][3][value] = key
- win32gui.SendMessage(bm, win32con.CB_ADDSTRING, 0, value)
+ for ID in self.__images.keys():
+ bmCtrl = win32gui.GetDlgItem(hwnd, ID)
+ win32gui.SendMessage(bmCtrl, win32con.STM_SETIMAGE,
win32con.IMAGE_BITMAP, \
+ self.__images[ID])
- win32gui.SendMessage(bm, win32con.CB_SELECTSTRING, -1, default)
-
- self.SetPosition(win32con.IDCANCEL, self.dlgWidth + 2*border\
- - self.Width(win32con.IDCANCEL), ypos + 15)
- self.SetPosition(win32con.IDOK, self.dlgWidth + 2*border \
- - self.Width(win32con.IDCANCEL) \
- - self.Width(win32con.IDOK) -4, ypos + 15)
- ypos += self.Height(win32con.IDOK) + border
+ self.__maxLabelWidth = 0
+ for label in self.__labels:
+ self.__maxLabelWidth = max(self.__maxLabelWidth, self.Width(label))
+
+ self.dlgWidth = 0
+ for control in self.__controls:
+ if control in self.__inputs:
+ self.dlgWidth = max(self.dlgWidth, self.__maxLabelWidth +
self.Width(control))
+ else:
+ if control not in self.__warnings:
+ self.dlgWidth = max(self.dlgWidth, self.Width(control))
+
+ border = 10
+ ypos = border
+ for control in self.__controls:
+ if (control in self.__images.keys()) or (control in self.__texts):
+ if control in self.__warnings:
+ dlgItem = win32gui.GetDlgItem(hwnd, control)
+ text = win32gui.GetWindowText(dlgItem)
+ #~ newText = self.wrapText(text, self.dlgWidth)
+ #~ win32gui.SetDlgItemText(hwnd, control, newText)
+ win32gui.SetDlgItemText(hwnd, control, text)
+
+ self.SetPosition(control,
(self.dlgWidth-self.Width(control))/2 + border + 8 , ypos)
+ ypos += self.Height(control) + 5
+ elif control in self.__labels:
+ self.SetPosition(control, border, ypos)
+ else:
+ self.SetPosition(control, border + self.__maxLabelWidth + 10,
ypos)
+ ypos += self.Height(control) + 3
+
+ if control in self.__dropdowns.keys():
+ bm = win32gui.GetDlgItem(hwnd, control)
+ default, master, elements, rmap = self.__dropdowns[control]
+
+ (label, allowed) = elements [0]
+ if master is None:
+ data = [allowed]
+ else:
+ data = allowed.values ()
+
+ for vdict in data:
+ for key,value in vdict.items():
+ value = textEncode("%s" % value)
+ self.__dropdowns[control][3][value] = key
+ win32gui.SendMessage(bm, win32con.CB_ADDSTRING, 0,
value)
+
+ win32gui.SendMessage(bm, win32con.CB_SELECTSTRING, -1, default)
+
+ self.SetPosition(win32con.IDCANCEL, self.dlgWidth + 2*border\
+ - self.Width(win32con.IDCANCEL), ypos + 15)
+ self.SetPosition(win32con.IDOK, self.dlgWidth + 2*border \
+ - self.Width(win32con.IDCANCEL) \
+ - self.Width(win32con.IDOK) -4, ypos + 15)
+ ypos += self.Height(win32con.IDOK) + border
+
+ # resize the dialog
+ win32gui.SetWindowPos(hwnd, 0,
+ 0, 0,
+ self.dlgWidth + 2*border + 16, ypos + 45,
+ win32con.SWP_NOACTIVATE |
win32con.SWP_NOZORDER)
+ # center the dialog
+ centerWindow(hwnd)
- # resize the dialog
- win32gui.SetWindowPos(hwnd, 0,
- 0, 0,
- self.dlgWidth + 2*border + 16, ypos + 45,
- win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER)
- # center the dialog
- centerWindow(hwnd)
-
- # set focus to first input item
- first = win32gui.GetDlgItem(hwnd, self.__inputs[0])
- win32gui.SetFocus(first)
-
- def OnClose(self, hwnd, msg, wparam, lparam):
- self.inputData = None
- win32gui.EndDialog(hwnd, 0)
- win32gui.SetFocus(self.oldfocus)
+ # set focus to first input item
+ first = win32gui.GetDlgItem(hwnd, self.__inputs[0])
+ win32gui.SetFocus(first)
+
+ def OnClose(self, hwnd, msg, wparam, lparam):
+ self.inputData = None
+ win32gui.EndDialog(hwnd, 0)
+ win32gui.SetFocus(self.oldfocus)
- def OnCommand(self, hwnd, msg, wparam, lparam):
- id = win32api.LOWORD(wparam)
- if id == win32con.IDOK:
- for control in self.__inputs:
- dlgItem = win32gui.GetDlgItem(self.hwnd, control)
- text = win32gui.GetWindowText(dlgItem)
- if control in self.__dropdowns.keys():
- key = self.__dropdowns[control][3].get(text)
- if key:
- self.inputData [self.controlsName [control]] = key
- else:
- self.inputData [self.controlsName [control]] = text
- win32gui.EndDialog(hwnd, 1)
- win32gui.SetFocus(self.oldfocus)
+ def OnCommand(self, hwnd, msg, wparam, lparam):
+ id = win32api.LOWORD(wparam)
+ if id == win32con.IDOK:
+ for control in self.__inputs:
+ dlgItem = win32gui.GetDlgItem(self.hwnd, control)
+ text = win32gui.GetWindowText(dlgItem)
+ if control in self.__dropdowns.keys():
+ key = self.__dropdowns[control][3].get(text)
+ if key:
+ self.inputData [self.controlsName [control]] = key
+ else:
+ self.inputData [self.controlsName [control]] = text
+ win32gui.EndDialog(hwnd, 1)
+ win32gui.SetFocus(self.oldfocus)
- elif id == win32con.IDCANCEL:
- self.inputData = None
- win32gui.EndDialog(hwnd, 0)
- win32gui.SetFocus(self.oldfocus)
-
- def OnCtlColorStatic(self, hwnd, msg, wparam, lparam):
- if win32gui.GetDlgCtrlID(lparam) in self.__warnings:
- win32gui.SetBkMode(wparam, win32con.TRANSPARENT) #OPAQUE
- win32gui.SetTextColor(wparam, win32api.RGB(0XFF, 0, 0))
- return 1
-
- def Width(self, id):
- item = win32gui.GetDlgItem(self.hwnd, id)
- dc = win32gui.GetDC(item)
- if (id in self.__labels) or (id in self.__texts):
- text = win32gui.GetWindowText(item)
- if '\n' in text:
- w = max ([win32gui.GetTextExtentPoint32(dc, t) [0] for t in text.split
('\n')])
- else:
- w, h = win32gui.GetTextExtentPoint32(dc, text)
- return w
- elif id in self.__inputs:
- w, h = win32gui.GetTextExtentPoint32(dc, 'W'*8)
- return w
- else:
- l,t,r,b = win32gui.GetWindowRect(item)
- return r-l
+ elif id == win32con.IDCANCEL:
+ self.inputData = None
+ win32gui.EndDialog(hwnd, 0)
+ win32gui.SetFocus(self.oldfocus)
+
+ def OnCtlColorStatic(self, hwnd, msg, wparam, lparam):
+ if win32gui.GetDlgCtrlID(lparam) in self.__warnings:
+ win32gui.SetBkMode(wparam, win32con.TRANSPARENT) #OPAQUE
+ win32gui.SetTextColor(wparam, win32api.RGB(0XFF, 0, 0))
+ return 1
+
+ def Width(self, id):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ dc = win32gui.GetDC(item)
+ if (id in self.__labels) or (id in self.__texts):
+ text = win32gui.GetWindowText(item)
+ if '\n' in text:
+ w = max ([win32gui.GetTextExtentPoint32(dc, t) [0] for t in
text.split ('\n')])
+ else:
+ w, h = win32gui.GetTextExtentPoint32(dc, text)
+ return w
+ elif id in self.__inputs:
+ w, h = win32gui.GetTextExtentPoint32(dc, 'W'*8)
+ return w
+ else:
+ l,t,r,b = win32gui.GetWindowRect(item)
+ return r-l
- def Height(self, id):
- item = win32gui.GetDlgItem(self.hwnd, id)
- dc = win32gui.GetDC(item)
- if (id in self.__labels) or (id in self.__texts):
- text = win32gui.GetWindowText(item)
- if '\n' in text:
- h = sum ([win32gui.GetTextExtentPoint32(dc, t) [1] for t in text.split
('\n')])
- else:
- w, h = win32gui.GetTextExtentPoint32(dc, text)
- return h
- elif id in self.__inputs:
- w, h = win32gui.GetTextExtentPoint32(dc, 'W')
- return h + 6
- else:
- l,t,r,b = win32gui.GetWindowRect(item)
- return b-t
+ def Height(self, id):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ dc = win32gui.GetDC(item)
+ if (id in self.__labels) or (id in self.__texts):
+ text = win32gui.GetWindowText(item)
+ if '\n' in text:
+ h = sum ([win32gui.GetTextExtentPoint32(dc, t) [1] for t in
text.split ('\n')])
+ else:
+ w, h = win32gui.GetTextExtentPoint32(dc, text)
+ return h
+ elif id in self.__inputs:
+ w, h = win32gui.GetTextExtentPoint32(dc, 'W')
+ return h + 6
+ else:
+ l,t,r,b = win32gui.GetWindowRect(item)
+ return b-t
- def SetPosition(self, id, x, y):
- item = win32gui.GetDlgItem(self.hwnd, id)
- flags = win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER
- w = self.Width(id)
- h = self.Height(id)
-
- win32gui.SetWindowPos(item, self.hwnd, x, y, w, h, flags)
-
- #~ def wrapText(self, text, width):
- #~ textSoFar = ""
- #~ thisLine = ""
- #~ for part in text.split('\n'):
- #~ for word in part.split():
- #~ if win32gui.GetTextExtentPoint32(dc, thisLine + word)[0] > width:
- #~ textSoFar += thisLine + " \n"
- #~ thisLine = word + " "
- #~ else:
- #~ thisLine += word + " "
+ def SetPosition(self, id, x, y):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ flags = win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER
+ w = self.Width(id)
+ h = self.Height(id)
+
+ win32gui.SetWindowPos(item, self.hwnd, x, y, w, h, flags)
+
+ #~ def wrapText(self, text, width):
+ #~ textSoFar = ""
+ #~ thisLine = ""
+ #~ for part in text.split('\n'):
+ #~ for word in part.split():
+ #~ if win32gui.GetTextExtentPoint32(dc, thisLine + word)[0] >
width:
+ #~ textSoFar += thisLine + " \n"
+ #~ thisLine = word + " "
+ #~ else:
+ #~ thisLine += word + " "
- #~ textSoFar += thisLine + " \n"
- #~ thisLine = ""
-
- #~ return textSoFar
-
+ #~ textSoFar += thisLine + " \n"
+ #~ thisLine = ""
+
+ #~ return textSoFar
+
# =============================================================================
# About Box
# =============================================================================
class AboutBox (BaseDialog):
- def __init__ (self, parent, name, version, author, description):
- """
- """
- title = textEncode(u_("About %s") % name)
- BaseDialog.__init__(self, parent, title, cancel= False)
+ def __init__ (self, parent, name, version, author, description):
+ """
+ """
+ title = textEncode(u_("About %s") % name)
+ BaseDialog.__init__(self, parent, title, cancel= False)
- self.__boxes = []
- self.__labels = []
- self.__contents = []
+ self.__boxes = []
+ self.__labels = []
+ self.__contents = []
- # Upper box with info about GNUe Forms
- self.template.append (self.__addBox (textEncode(u_('GNUe Forms')), 8, 44))
- self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Version:')), 20))
- self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Driver:')), 34))
+ # Upper box with info about GNUe Forms
+ self.template.append (self.__addBox (textEncode(u_('GNUe Forms')), 8,
44))
+ self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Version:')), 20))
+ self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Driver:')), 34))
- self.template.append (self.__addLabel (self.__contents,
textEncode(VERSION), 20))
- self.template.append (self.__addLabel (self.__contents, 'win32', 34))
+ self.template.append (self.__addLabel (self.__contents,
textEncode(VERSION), 20))
+ self.template.append (self.__addLabel (self.__contents, 'win32', 34))
- # Lower box with info about the form currently displayed
- self.template.append (self.__addBox (textEncode(u_('Form Information')),
56, 74))
- self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Name:')), 74))
- self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Version:')), 88))
- self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Author:')), 102))
- self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Description:')), 116))
+ # Lower box with info about the form currently displayed
+ self.template.append (self.__addBox (textEncode(u_('Form
Information')), 56, 74))
+ self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Name:')), 74))
+ self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Version:')), 88))
+ self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Author:')), 102))
+ self.template.append (self.__addLabel (self.__labels,
textEncode(u_('Description:')), 116))
- self.template.append (self.__addLabel (self.__contents, textEncode(name),
74))
- self.template.append (self.__addLabel (self.__contents,
textEncode(version), 88))
- self.template.append (self.__addLabel (self.__contents,
textEncode(author), 102))
- descr = '\n'.join (textwrap.wrap (description))
- self.template.append (self.__addLabel (self.__contents, textEncode(descr),
116))
-
-
- # ---------------------------------------------------------------------------
- # Finalize the dialog's initialization
- # ---------------------------------------------------------------------------
- def OnInitDialog(self, hwnd, msg, wparam, lparam):
- BaseDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
- """
- Recalculate sizes of all labels and boxes.
- """
- # Stretch all labels in the left column and calculate the widest label
- maxW = 0
- flags = win32con.SWP_NOMOVE | win32con.SWP_NOOWNERZORDER | \
- win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
+ self.template.append (self.__addLabel (self.__contents,
textEncode(name), 74))
+ self.template.append (self.__addLabel (self.__contents,
textEncode(version), 88))
+ self.template.append (self.__addLabel (self.__contents,
textEncode(author), 102))
+ descr = '\n'.join (textwrap.wrap (description))
+ self.template.append (self.__addLabel (self.__contents,
textEncode(descr), 116))
+
+
+ #
---------------------------------------------------------------------------
+ # Finalize the dialog's initialization
+ #
---------------------------------------------------------------------------
+ def OnInitDialog(self, hwnd, msg, wparam, lparam):
+ BaseDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
+ """
+ Recalculate sizes of all labels and boxes.
+ """
+ # Stretch all labels in the left column and calculate the widest label
+ maxW = 0
+ flags = win32con.SWP_NOMOVE | win32con.SWP_NOOWNERZORDER | \
+ win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
- for (ix, itemId) in enumerate (self.__labels):
- item = win32gui.GetDlgItem(hwnd, itemId)
- dc = win32gui.GetDC(item)
- text = win32gui.GetWindowText(item)
- (width, height) = win32gui.GetTextExtentPoint32(dc, text)
- maxW = max (maxW, width)
+ for (ix, itemId) in enumerate (self.__labels):
+ item = win32gui.GetDlgItem(hwnd, itemId)
+ dc = win32gui.GetDC(item)
+ text = win32gui.GetWindowText(item)
+ (width, height) = win32gui.GetTextExtentPoint32(dc, text)
+ maxW = max (maxW, width)
- win32gui.SetWindowPos(item, 0, 0, 0, width, height, flags)
+ win32gui.SetWindowPos(item, 0, 0, 0, width, height, flags)
- # Reposition and stretch all labels in the second column
- maxBottom = 0
- right = 0
- flags = win32con.SWP_NOOWNERZORDER | \
- win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
+ # Reposition and stretch all labels in the second column
+ maxBottom = 0
+ right = 0
+ flags = win32con.SWP_NOOWNERZORDER | \
+ win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
- for (ix, itemId) in enumerate (self.__contents):
- item = win32gui.GetDlgItem(hwnd, itemId)
- dc = win32gui.GetDC(item)
- text = win32gui.GetWindowText(item)
- if '\n' in text:
- width = max ([win32gui.GetTextExtentPoint32(dc, p) [0] for p in
text.split ('\n')])
- height = sum ([win32gui.GetTextExtentPoint32(dc, p) [1] for p in
text.split ('\n')])
- else:
- (width, height) = win32gui.GetTextExtentPoint32(dc, text)
+ for (ix, itemId) in enumerate (self.__contents):
+ item = win32gui.GetDlgItem(hwnd, itemId)
+ dc = win32gui.GetDC(item)
+ text = win32gui.GetWindowText(item)
+ if '\n' in text:
+ width = max ([win32gui.GetTextExtentPoint32(dc, p) [0] for p
in text.split ('\n')])
+ height = sum ([win32gui.GetTextExtentPoint32(dc, p) [1] for p
in text.split ('\n')])
+ else:
+ (width, height) = win32gui.GetTextExtentPoint32(dc, text)
- (left, top, w, h) = win32gui.GetWindowRect(item)
- left, top = win32gui.ScreenToClient(self.hwnd, (left, top))
- left = maxW + 40
+ (left, top, w, h) = win32gui.GetWindowRect(item)
+ left, top = win32gui.ScreenToClient(self.hwnd, (left, top))
+ left = maxW + 40
- win32gui.SetWindowPos (item, 0, left, top, width, height, flags)
- right = max ((left + width), right)
- maxBottom = max (top + height, maxBottom,)
+ win32gui.SetWindowPos (item, 0, left, top, width, height, flags)
+ right = max ((left + width), right)
+ maxBottom = max (top + height, maxBottom,)
- # Now stretch all boxes to fit the newly calculated width
- right += 8
- flags = win32con.SWP_NOMOVE | win32con.SWP_NOOWNERZORDER | \
- win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
- for itemId in self.__boxes:
- item = win32gui.GetDlgItem(hwnd, itemId)
- (left, top, r, bottom) = win32gui.GetWindowRect(item)
- left, top = win32gui.ScreenToClient(self.hwnd, (left, top))
- r, bottom = win32gui.ScreenToClient(self.hwnd, (r,bottom))
- win32gui.SetWindowPos (item, 0, 0, 0, right, bottom - top, flags)
+ # Now stretch all boxes to fit the newly calculated width
+ right += 8
+ flags = win32con.SWP_NOMOVE | win32con.SWP_NOOWNERZORDER | \
+ win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
+ for itemId in self.__boxes:
+ item = win32gui.GetDlgItem(hwnd, itemId)
+ (left, top, r, bottom) = win32gui.GetWindowRect(item)
+ left, top = win32gui.ScreenToClient(self.hwnd, (left, top))
+ r, bottom = win32gui.ScreenToClient(self.hwnd, (r,bottom))
+ win32gui.SetWindowPos (item, 0, 0, 0, right, bottom - top, flags)
- # Resize the dialog itself to the new width
- right += 24
- flags = win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER
- win32gui.SetWindowPos (self.hwnd, 0, 0, 0, right, maxBottom + 100, flags)
+ # Resize the dialog itself to the new width
+ right += 24
+ flags = win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER
+ win32gui.SetWindowPos (self.hwnd, 0, 0, 0, right, maxBottom + 100,
flags)
- # Re-Center the Ok button
- flags = win32con.SWP_NOOWNERZORDER | win32con.SWP_NOZORDER | \
- win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE
- item = win32gui.GetDlgItem(hwnd, win32con.IDOK)
- (l, t, r, b) = win32gui.GetWindowRect(item)
- l, t = win32gui.ScreenToClient(self.hwnd, (l, t))
- r, b = win32gui.ScreenToClient(self.hwnd, (r, b))
- left = right / 2 - (r - l) / 2
- win32gui.SetWindowPos (item, 0, left, maxBottom + 25, 0, 0, flags)
-
- centerWindow(hwnd)
-
+ # Re-Center the Ok button
+ flags = win32con.SWP_NOOWNERZORDER | win32con.SWP_NOZORDER | \
+ win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE
+ item = win32gui.GetDlgItem(hwnd, win32con.IDOK)
+ (l, t, r, b) = win32gui.GetWindowRect(item)
+ l, t = win32gui.ScreenToClient(self.hwnd, (l, t))
+ r, b = win32gui.ScreenToClient(self.hwnd, (r, b))
+ left = right / 2 - (r - l) / 2
+ win32gui.SetWindowPos (item, 0, left, maxBottom + 25, 0, 0, flags)
+
+ centerWindow(hwnd)
+
- # ---------------------------------------------------------------------------
- # Create a resource definition for a label
- # ---------------------------------------------------------------------------
- def __addLabel (self, collection, label, row):
+ #
---------------------------------------------------------------------------
+ # Create a resource definition for a label
+ #
---------------------------------------------------------------------------
+ def __addLabel (self, collection, label, row):
- s = win32con.WS_CHILD | win32con.WS_VISIBLE
- ID = getNextId()
- collection.append (ID)
- return ['Static', label, ID, (16, row, 5, 14), s]
+ s = win32con.WS_CHILD | win32con.WS_VISIBLE
+ ID = getNextId()
+ collection.append (ID)
+ return ['Static', label, ID, (16, row, 5, 14), s]
- # ---------------------------------------------------------------------------
- # Create a resource sequence for a labeled box
- # ---------------------------------------------------------------------------
- def __addBox (self, label, top, height):
+ #
---------------------------------------------------------------------------
+ # Create a resource sequence for a labeled box
+ #
---------------------------------------------------------------------------
+ def __addBox (self, label, top, height):
- self.__boxes.append (getNextId())
- style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_TABSTOP | \
- win32con.BS_GROUPBOX
- return ['button', label, self.__boxes [-1], (6, top, 282, height), style]
+ self.__boxes.append (getNextId())
+ style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_TABSTOP
| \
+ win32con.BS_GROUPBOX
+ return ['button', label, self.__boxes [-1], (6, top, 282, height),
style]
-
+
# =============================================================================
# This class implements a dialog for displaying exceptions
# =============================================================================
class ExceptionDialog (BaseDialog):
- _TITLE = {'system' : _("GNUe Internal System Error"),
- 'admin' : _("GNUe Unexpected Error"),
- 'application': _("GNUe Application Error")}
-
- _FORMAT = {
- 'system': u_("An unexpected internal error has occured:\r\n%s.\r\n"
- "This means you have found a bug in GNU Enterprise. "
- "Please report it to address@hidden"),
- 'admin': u_("An unexpected error has occured:\r\n%s.\r\n"
- "Please contact your system administrator."),
- 'application': u_("An unexpected error has occured:\r\n%s.\r\n"
- "Please contact your system administrator.")}
-
- # ---------------------------------------------------------------------------
- # Constructor
- # ---------------------------------------------------------------------------
-
- def __init__ (self, parent, group, name, message, detail):
-
- BaseDialog.__init__(self, parent, self._TITLE.get (group, _('Error')),
cancel = False, ok = False)
- self.message_map [win32con.WM_CTLCOLORSTATIC] = self.OnCtlColorStatic
-
- self.detail = detail.replace('\n','\r\n')
+ _TITLE = {'system' : _("GNUe Internal System Error"),
+ 'admin' : _("GNUe Unexpected Error"),
+ 'application': _("GNUe Application Error")}
+
+ _FORMAT = {
+ 'system': u_("An unexpected internal error has occured:\r\n%s.\r\n"
+ "This means you have found a bug in GNU Enterprise. "
+ "Please report it to address@hidden"),
+ 'admin': u_("An unexpected error has occured:\r\n%s.\r\n"
+ "Please contact your system administrator."),
+ 'application': u_("An unexpected error has occured:\r\n%s.\r\n"
+ "Please contact your system administrator.")}
+
+ #
---------------------------------------------------------------------------
+ # Constructor
+ #
---------------------------------------------------------------------------
+
+ def __init__ (self, parent, group, name, message, detail):
+
+ BaseDialog.__init__(self, parent, self._TITLE.get (group, _('Error')),
cancel = False, ok = False)
+ self.message_map [win32con.WM_CTLCOLORSTATIC] = self.OnCtlColorStatic
- cs = win32con.WS_CHILD | win32con.WS_VISIBLE
- position = (0, 0, 0, 0)
-
- self.iconID = ID = getNextId()
- s = cs | win32con.SS_ICON #| win32con.WS_BORDER
- self.template.append([STATIC, 'icon', ID, (5,8,32,32), s])
-
- self.messageID = ID = getNextId()
- s = cs | win32con.SS_LEFT
- self.template.append([STATIC, textEncode(self._FORMAT.get (group, "%s") %
message), \
- ID, position, s])
-
- s = cs | win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON
- self.template.append([BUTTON, textEncode(u_('Close')), win32con.IDCLOSE,
(0, 0, 56, 15), s])
-
- self.detailsID = ID = getNextId()
- s = cs | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON
- self.template.append([BUTTON, textEncode(u_('>> Details')), ID, (0, 0, 56,
15), s])
-
- self.detailID = ID = getNextId()
- s = cs | win32con.ES_MULTILINE | win32con.ES_READONLY |
win32con.WS_TABSTOP #\
+ self.detail = detail.replace('\n','\r\n')
+
+ cs = win32con.WS_CHILD | win32con.WS_VISIBLE
+ position = (0, 0, 0, 0)
+
+ self.iconID = ID = getNextId()
+ s = cs | win32con.SS_ICON #| win32con.WS_BORDER
+ self.template.append([STATIC, 'icon', ID, (5,8,32,32), s])
+
+ self.messageID = ID = getNextId()
+ s = cs | win32con.SS_LEFT
+ self.template.append([STATIC, textEncode(self._FORMAT.get (group,
"%s") % message), \
+ ID, position, s])
+
+ s = cs | win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON
+ self.template.append([BUTTON, textEncode(u_('Close')),
win32con.IDCLOSE, (0, 0, 56, 15), s])
+
+ self.detailsID = ID = getNextId()
+ s = cs | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON
+ self.template.append([BUTTON, textEncode(u_('>> Details')), ID, (0, 0,
56, 15), s])
+
+ self.detailID = ID = getNextId()
+ s = cs | win32con.ES_MULTILINE | win32con.ES_READONLY |
win32con.WS_TABSTOP #\
# | win32con.ES_AUTOVSCROLL | win32con.WS_VSCROLL
- es = win32con.WS_EX_STATICEDGE
- self.template.append([EDIT, textEncode(self.detail), ID, position, s, es])
-
- self._showsDetail = False
-
-
- def OnInitDialog(self, hwnd, msg, wparam, lparam):
- BaseDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
-
- item = win32gui.GetDlgItem(self.hwnd, self.detailID)
- win32gui.EnableWindow(item, 0)
-
- ico = win32gui.LoadIcon(0, win32con.IDI_ERROR)
- bmCtrl = win32gui.GetDlgItem(self.hwnd, self.iconID)
- win32gui.SendMessage(bmCtrl, win32con.STM_SETICON, ico, 0)
-
- self.Recalculate()
-
-
- def OnCommand(self, hwnd, msg, wparam, lparam):
- id = win32api.LOWORD(wparam)
- if id == win32con.IDCLOSE:
- win32gui.EndDialog(hwnd, 1)
- win32gui.SetFocus(self.oldfocus)
-
- elif id == self.detailsID:
- self._showsDetail = not self._showsDetail
- if self._showsDetail:
+ es = win32con.WS_EX_STATICEDGE
+ self.template.append([EDIT, textEncode(self.detail), ID, position, s,
es])
+
+ self._showsDetail = False
+
+
+ def OnInitDialog(self, hwnd, msg, wparam, lparam):
+ BaseDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
+
item = win32gui.GetDlgItem(self.hwnd, self.detailID)
- win32gui.EnableWindow(item, 1)
- win32gui.SetDlgItemText(hwnd, id, u_("<< Details"))
- self.Recalculate()
- else:
- item = win32gui.GetDlgItem(self.hwnd, self.detailID)
win32gui.EnableWindow(item, 0)
- win32gui.SetDlgItemText(hwnd, id, u_(">> Details"))
+
+ ico = win32gui.LoadIcon(0, win32con.IDI_ERROR)
+ bmCtrl = win32gui.GetDlgItem(self.hwnd, self.iconID)
+ win32gui.SendMessage(bmCtrl, win32con.STM_SETICON, ico, 0)
+
self.Recalculate()
-
- def OnCtlColorStatic(self, hwnd, msg, wparam, lparam):
- if win32gui.GetDlgCtrlID(lparam) == self.detailID:
- win32gui.SetBkMode(wparam, win32con.OPAQUE) #TRANSPARENT) #
- win32gui.SetTextColor(wparam, win32api.RGB(0, 0, 0))
- return 1
-
- def Recalculate(self):
- border = 10
- dlgWidth = self.Width(self.detailsID) + self.Width(win32con.IDCLOSE) + 20
- dlgWidth = max(dlgWidth, self.Width(self.messageID))
- if self._showsDetail:
- dlgWidth = max(dlgWidth, self.Width(self.detailID))
-
- ypos = border
-
- self.SetPosition(self.messageID, border+40, ypos)
- ypos += self.Height(self.messageID) + 10
- if self._showsDetail:
- self.SetPosition(self.detailID, border, ypos)
- ypos += self.Height(self.detailID) + 10
- else:
- dlgItem = win32gui.GetDlgItem(self.hwnd, self.detailID)
- win32gui.SetWindowPos(dlgItem, 0, 0, 0, 0, 0, 0)
-
- self.SetPosition(self.detailsID, dlgWidth + 2*border \
- - self.Width(self.detailsID) - 8, ypos + 10)
-
- self.SetPosition(win32con.IDCLOSE, dlgWidth + 2*border \
- - self.Width(self.detailsID) \
- - self.Width(win32con.IDCLOSE) -15, ypos + 10)
-
- ypos += self.Height(win32con.IDCLOSE) + border
+ def OnCommand(self, hwnd, msg, wparam, lparam):
+ id = win32api.LOWORD(wparam)
+ if id == win32con.IDCLOSE:
+ win32gui.EndDialog(hwnd, 1)
+ win32gui.SetFocus(self.oldfocus)
+
+ elif id == self.detailsID:
+ self._showsDetail = not self._showsDetail
+ if self._showsDetail:
+ item = win32gui.GetDlgItem(self.hwnd, self.detailID)
+ win32gui.EnableWindow(item, 1)
+ win32gui.SetDlgItemText(hwnd, id, u_("<< Details"))
+ self.Recalculate()
+ else:
+ item = win32gui.GetDlgItem(self.hwnd, self.detailID)
+ win32gui.EnableWindow(item, 0)
+ win32gui.SetDlgItemText(hwnd, id, u_(">> Details"))
+ self.Recalculate()
+
+ def OnCtlColorStatic(self, hwnd, msg, wparam, lparam):
+ if win32gui.GetDlgCtrlID(lparam) == self.detailID:
+ win32gui.SetBkMode(wparam, win32con.OPAQUE) #TRANSPARENT) #
+ win32gui.SetTextColor(wparam, win32api.RGB(0, 0, 0))
+ return 1
+
+ def Recalculate(self):
+ border = 10
+
+ dlgWidth = self.Width(self.detailsID) + self.Width(win32con.IDCLOSE) +
20
+ dlgWidth = max(dlgWidth, self.Width(self.messageID))
+ if self._showsDetail:
+ dlgWidth = max(dlgWidth, self.Width(self.detailID))
+
+ ypos = border
- # resize the dialog
- win32gui.SetWindowPos(self.hwnd, 0,
- 0, 0,
- dlgWidth + 2*border + 10, ypos + 45,
- win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER \
- | win32con.SWP_NOMOVE)
-
- # center the dialog
- centerWindow(self.hwnd)
-
-
- def Width(self, id):
- item = win32gui.GetDlgItem(self.hwnd, id)
- dc = win32gui.GetDC(item)
- if id == self.messageID or id == self.detailID:
- text = win32gui.GetWindowText(item)
- # GetWindowText has only 512 byte buffer, sigh...
- if id == self.detailID:
- text = self.detail
- if '\n' in text:
- w = max ([win32gui.GetTextExtentPoint32(dc, t) [0] for t in text.split
('\n')])
- else:
- w, h = win32gui.GetTextExtentPoint32(dc, text)
- return w
- else:
- l,t,r,b = win32gui.GetWindowRect(item)
- return r-l
-
-
- def Height(self, id):
- item = win32gui.GetDlgItem(self.hwnd, id)
- dc = win32gui.GetDC(item)
- if id == self.messageID or id == self.detailID:
- text = win32gui.GetWindowText(item)
- if id == self.detailID:
- text = self.detail
- if '\n' in text:
- h = sum ([win32gui.GetTextExtentPoint32(dc, t) [1] -2 for t in
text.split ('\n')])
- else:
- w, h = win32gui.GetTextExtentPoint32(dc, text)
- #~ if id == self.detailID:
- #~ h += -8 # extra for WS_EX_STATICEDGE
- return h
- else:
- l,t,r,b = win32gui.GetWindowRect(item)
- return b-t
-
-
- def SetPosition(self, id, x, y):
- item = win32gui.GetDlgItem(self.hwnd, id)
- win32gui.SetWindowPos(item, 0,
- x, y,
- self.Width(id), self.Height(id),
- win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER)
+ self.SetPosition(self.messageID, border+40, ypos)
+ ypos += self.Height(self.messageID) + 10
+
+ if self._showsDetail:
+ self.SetPosition(self.detailID, border, ypos)
+ ypos += self.Height(self.detailID) + 10
+ else:
+ dlgItem = win32gui.GetDlgItem(self.hwnd, self.detailID)
+ win32gui.SetWindowPos(dlgItem, 0, 0, 0, 0, 0, 0)
+
+ self.SetPosition(self.detailsID, dlgWidth + 2*border \
+ - self.Width(self.detailsID) - 8, ypos + 10)
+
+ self.SetPosition(win32con.IDCLOSE, dlgWidth + 2*border \
+ - self.Width(self.detailsID) \
+ - self.Width(win32con.IDCLOSE) -15, ypos + 10)
+
+ ypos += self.Height(win32con.IDCLOSE) + border
+
+ # resize the dialog
+ win32gui.SetWindowPos(self.hwnd, 0,
+ 0, 0,
+ dlgWidth + 2*border + 10, ypos + 45,
+ win32con.SWP_NOACTIVATE |
win32con.SWP_NOZORDER \
+ | win32con.SWP_NOMOVE)
+
+ # center the dialog
+ centerWindow(self.hwnd)
+
+
+ def Width(self, id):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ dc = win32gui.GetDC(item)
+ if id == self.messageID or id == self.detailID:
+ text = win32gui.GetWindowText(item)
+ # GetWindowText has only 512 byte buffer, sigh...
+ if id == self.detailID:
+ text = self.detail
+ if '\n' in text:
+ w = max ([win32gui.GetTextExtentPoint32(dc, t) [0] for t in
text.split ('\n')])
+ else:
+ w, h = win32gui.GetTextExtentPoint32(dc, text)
+ return w
+ else:
+ l,t,r,b = win32gui.GetWindowRect(item)
+ return r-l
+
+
+ def Height(self, id):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ dc = win32gui.GetDC(item)
+ if id == self.messageID or id == self.detailID:
+ text = win32gui.GetWindowText(item)
+ if id == self.detailID:
+ text = self.detail
+ if '\n' in text:
+ h = sum ([win32gui.GetTextExtentPoint32(dc, t) [1] -2 for t in
text.split ('\n')])
+ else:
+ w, h = win32gui.GetTextExtentPoint32(dc, text)
+ #~ if id == self.detailID:
+ #~ h += -8 # extra for WS_EX_STATICEDGE
+ return h
+ else:
+ l,t,r,b = win32gui.GetWindowRect(item)
+ return b-t
+
+
+ def SetPosition(self, id, x, y):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ win32gui.SetWindowPos(item, 0,
+ x, y,
+ self.Width(id), self.Height(id),
+ win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER)
if __name__ == '__main__':
- dialog = ExceptionDialog('system', 'name', 'message', 'detail')
- dialog.DoModal ()
-
- desc = "This is a quite long description of the application.\n" \
- "It also contains newlines as well as a lot of text. This text " \
- "get's continued in the third line too.\n" \
- "And here comes the rest. Here we go."
- #desc = "Hey boyz, that thingy is quite complicated"
- dialog = AboutBox ('Foobar', '1.0', 'Frodo', desc)
- dialog.DoModal ()
-
- #
---------------------------------------------------------------------------
+ dialog = ExceptionDialog('system', 'name', 'message', 'detail')
+ dialog.DoModal ()
- cname = {'c1': 'demoa', 'c2': 'demob'}
- ckey = {'c1': 'ck-A', 'c2': 'ck-B'}
+ desc = "This is a quite long description of the application.\n" \
+ "It also contains newlines as well as a lot of text. This text " \
+ "get's continued in the third line too.\n" \
+ "And here comes the rest. Here we go."
+ #desc = "Hey boyz, that thingy is quite complicated"
+ dialog = AboutBox ('Foobar', '1.0', 'Frodo', desc)
+ dialog.DoModal ()
+
+ #
---------------------------------------------------------------------------
- wija = {'c1': {'04': '2004', '05': '2005'},
- 'c2': {'24': '2024', '25': '2025', '26': '2026'}}
+ cname = {'c1': 'demoa', 'c2': 'demob'}
+ ckey = {'c1': 'ck-A', 'c2': 'ck-B'}
- codes = {'24': {'241': 'c-24-1', '242': 'c-24-2'},
- '25': {'251': 'c-25-1'}}
+ wija = {'c1': {'04': '2004', '05': '2005'},
+ 'c2': {'24': '2024', '25': '2025', '26': '2026'}}
- fields = [('Foo!', 'c:/gnue.bmp', 'image',
- None, None, []),
- ('Username', '_username', 'string', 'frodo', None, \
- [('Name of the user', None)]),
- ('Password', '_password', 'password', 'foo', None, [('yeah',1)]),
- ('Foobar', '_foobar', 'dropdown', 'frob', None, \
- [('single', {'trash': 'Da Trash', 'frob': 'Frob'})]),
- ('Multi', '_multi', 'dropdown', '100', None, \
- [('name', {'50': 'A 50', '100': 'B 100', '9': 'C 9'}),
- ('sepp', {'50': 'se 50', '100': 'se 100', '9': 'se 9'})]),
- ('Noe', '_depp', 'label', 'furz', None, []),
- ('Das ist jetzt ein Fehler', None, 'warning', None, None, []),
- ('Firma', 'company', 'dropdown', 'c1', None,
- [('Name', cname), ('Code', ckey)]),
- ('Wirtschaftsjahr', 'wija', 'dropdown', '05', 'company',
- [('Jahr', wija)]),
- ('Codes', 'codes', 'dropdown', None, 'wija',
- [('Code', codes)])]
-
- dialog = InputDialog('Foobar', fields)
- dialog.DoModal()
- print dialog.inputData
+ codes = {'24': {'241': 'c-24-1', '242': 'c-24-2'},
+ '25': {'251': 'c-25-1'}}
+
+ fields = [('Foo!', 'c:/gnue.bmp', 'image',
+ None, None, []),
+ ('Username', '_username', 'string', 'frodo', None, \
+ [('Name of the user', None)]),
+ ('Password', '_password', 'password', 'foo', None, [('yeah',1)]),
+ ('Foobar', '_foobar', 'dropdown', 'frob', None, \
+ [('single', {'trash': 'Da Trash', 'frob': 'Frob'})]),
+ ('Multi', '_multi', 'dropdown', '100', None, \
+ [('name', {'50': 'A 50', '100': 'B 100', '9': 'C 9'}),
+ ('sepp', {'50': 'se 50', '100': 'se 100', '9': 'se 9'})]),
+ ('Noe', '_depp', 'label', 'furz', None, []),
+ ('Das ist jetzt ein Fehler', None, 'warning', None, None, []),
+ ('Firma', 'company', 'dropdown', 'c1', None,
+ [('Name', cname), ('Code', ckey)]),
+ ('Wirtschaftsjahr', 'wija', 'dropdown', '05', 'company',
+ [('Jahr', wija)]),
+ ('Codes', 'codes', 'dropdown', None, 'wija',
+ [('Code', codes)])]
+
+ dialog = InputDialog('Foobar', fields)
+ dialog.DoModal()
+ print dialog.inputData
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -41,10 +41,10 @@
from gnue.forms.uidrivers.win32.common import *
try:
- from PIL import Image as PILImage
- from PIL import ImageWin
+ from PIL import Image as PILImage
+ from PIL import ImageWin
except:
- PILImage = None
+ PILImage = None
#TCN_SELCHANGE = (commctrl.TCN_FIRST - 1)
#TCN_SELCHANGING = (commctrl.TCN_FIRST - 2)
@@ -58,650 +58,650 @@
class Win32Base:
- _connectTable = {}
+ _connectTable = {}
- def __init__(self, uidriver, styleEx, className, windowTitle, style, x,y,
width,height, parent,menu=0,instance=0):
- if parent == 0:
- hparent = 0
- else:
- hparent = parent.GetHwnd()
+ def __init__(self, uidriver, styleEx, className, windowTitle, style, x,y,
width,height, parent,menu=0,instance=0):
+ if parent == 0:
+ hparent = 0
+ else:
+ hparent = parent.GetHwnd()
- self._id = menu
- self._className = className
- self._parent = parent
- self._children = []
- if parent:
- parent._children.append(self)
+ self._id = menu
+ self._className = className
+ self._parent = parent
+ self._children = []
+ if parent:
+ parent._children.append(self)
- self._hwnd = win32gui.CreateWindowEx(styleEx, className, windowTitle,
style, x,y, width,height, hparent, menu, instance, None)
-
- # this is only for SetFont
- self._PyCWnd = win32ui.CreateWindowFromHandle(self._hwnd)
+ self._hwnd = win32gui.CreateWindowEx(styleEx, className, windowTitle,
style, x,y, width,height, hparent, menu, instance, None)
- self._uiDriver = uidriver
- self._uiDriver._win32app._HwndToTkObj[self._hwnd] = self
+ # this is only for SetFont
+ self._PyCWnd = win32ui.CreateWindowFromHandle(self._hwnd)
- if className in ['STATIC', 'BUTTON', 'COMBOBOX', 'LISTBOX', 'EDIT']:
- # subclassing edit control part of the combo box eventhandler
- # to produce incremental search/autocomplete
- if className == 'COMBOBOX':
- self._AutoComplete = True
- windows = []
- try:
- win32gui.EnumChildWindows(self._hwnd, _MyCallback, windows)
- self._editHwnd = windows[0]
- self._oldWndProc1 = win32gui.SetWindowLong(self._editHwnd,
win32con.GWL_WNDPROC, self._wndproc1)
- except:
- pass
+ self._uiDriver = uidriver
+ self._uiDriver._win32app._HwndToTkObj[self._hwnd] = self
- self.Show()
- self._oldWndProc = win32gui.SetWindowLong(self._hwnd,
win32con.GWL_WNDPROC, self._wndproc)
+ if className in ['STATIC', 'BUTTON', 'COMBOBOX', 'LISTBOX', 'EDIT']:
+ # subclassing edit control part of the combo box eventhandler
+ # to produce incremental search/autocomplete
+ if className == 'COMBOBOX':
+ self._AutoComplete = True
+ windows = []
+ try:
+ win32gui.EnumChildWindows(self._hwnd, _MyCallback, windows)
+ self._editHwnd = windows[0]
+ self._oldWndProc1 = win32gui.SetWindowLong(self._editHwnd,
win32con.GWL_WNDPROC, self._wndproc1)
+ except:
+ pass
- # edit control part of the combo box eventhandler
- def _wndproc1(self, hwnd, msg, wParam, lParam):
- if msg == win32con.WM_LBUTTONDOWN:
- # TODO: only needed if this widget doesn't have the focus yet
- gfObject = self._uiDriver._IdToGFObj[self._id]
- uiObject = self._uiDriver._IdToUIObj[self._id]
- gfObject._event_set_focus(uiObject.widgets.index(self))
+ self.Show()
+ self._oldWndProc = win32gui.SetWindowLong(self._hwnd,
win32con.GWL_WNDPROC, self._wndproc)
- elif msg == win32con.WM_KEYDOWN:
- keycode = wParam
- self._AutoComplete = True
-
- # let the delete/back keys do their job
- if keycode in (win32con.VK_DELETE, win32con.VK_BACK):
- self._AutoComplete = False
-
- elif keycode == win32con.VK_TAB:
- # we have to deal with tab and enter
- ShiftDown = (win32api.GetKeyState(win32con.VK_SHIFT) & 0x8000) and 1
or 0
- if ShiftDown:
- win32gui.SendMessage(self._hwnd, WM_TAB, 0, 1)
- else:
- win32gui.SendMessage(self._hwnd, WM_TAB, 0, 0)
- return 0
-
- elif keycode == win32con.VK_RETURN:
- win32gui.SendMessage(self._hwnd, WM_RETURN, 0, 0)
- return 0
-
- elif keycode in F_KEYS:
- win32gui.SendMessage(self._hwnd, msg, wParam, lParam)
- return 0
+ # edit control part of the combo box eventhandler
+ def _wndproc1(self, hwnd, msg, wParam, lParam):
+ if msg == win32con.WM_LBUTTONDOWN:
+ # TODO: only needed if this widget doesn't have the focus yet
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ uiObject = self._uiDriver._IdToUIObj[self._id]
+ gfObject._event_set_focus(uiObject.widgets.index(self))
- elif msg == win32con.WM_CHAR:
- keycode = wParam
- if keycode in (win32con.VK_TAB, win32con.VK_RETURN):
- return 0
-
- return win32gui.CallWindowProc(self._oldWndProc1, hwnd, msg, wParam,
lParam)
+ elif msg == win32con.WM_KEYDOWN:
+ keycode = wParam
+ self._AutoComplete = True
- # main eventhandler
- def _wndproc(self, hwnd, msg, wParam, lParam):
- if msg == win32con.WM_LBUTTONDOWN:
- gfObject = self._uiDriver._IdToGFObj[self._id]
- uiObject = self._uiDriver._IdToUIObj[self._id]
+ # let the delete/back keys do their job
+ if keycode in (win32con.VK_DELETE, win32con.VK_BACK):
+ self._AutoComplete = False
- gfObject._event_set_focus(uiObject.widgets.index(self))
+ elif keycode == win32con.VK_TAB:
+ # we have to deal with tab and enter
+ ShiftDown = (win32api.GetKeyState(win32con.VK_SHIFT) & 0x8000)
and 1 or 0
+ if ShiftDown:
+ win32gui.SendMessage(self._hwnd, WM_TAB, 0, 1)
+ else:
+ win32gui.SendMessage(self._hwnd, WM_TAB, 0, 0)
+ return 0
- if gfObject._type == 'GFButton':
- self.SetFocus()
- self._connectTable[self._id](self._id)
- elif gfObject.style == 'checkbox':
- uiObject._request('TOGGLECHKBOX')
- else:
- if gfObject._type != 'GFEntry':
- cursorPosition = self.getSelectedArea()[1]
- uiObject._request ('CURSORMOVE', position = cursorPosition)
+ elif keycode == win32con.VK_RETURN:
+ win32gui.SendMessage(self._hwnd, WM_RETURN, 0, 0)
+ return 0
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ elif keycode in F_KEYS:
+ win32gui.SendMessage(self._hwnd, msg, wParam, lParam)
+ return 0
- elif msg == win32con.WM_LBUTTONUP:
- gfObject = self._uiDriver._IdToGFObj[self._id]
- uiObject = self._uiDriver._IdToUIObj[self._id]
+ elif msg == win32con.WM_CHAR:
+ keycode = wParam
+ if keycode in (win32con.VK_TAB, win32con.VK_RETURN):
+ return 0
- if gfObject._type == 'GFEntry' and gfObject.style == 'default':
- left, right = self.getSelectedArea ()
- if left == right:
- uiObject._request ('CURSORMOVE', position = left)
- else:
- uiObject._request ('SELECTWITHMOUSE', position1 = left,
- position2 = right)
-
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ return win32gui.CallWindowProc(self._oldWndProc1, hwnd, msg, wParam,
lParam)
- elif msg == win32con.WM_KEYDOWN:
- keycode = wParam
- gfObject = self._uiDriver._IdToGFObj[self._id]
- if (keycode in NOT_WM_CHAR_KEYS):
+ # main eventhandler
+ def _wndproc(self, hwnd, msg, wParam, lParam):
+ if msg == win32con.WM_LBUTTONDOWN:
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ uiObject = self._uiDriver._IdToUIObj[self._id]
- if gfObject._type == 'GFEntry' and \
- gfObject.style in ('dropdown', 'listbox') and \
- keycode not in F_KEYS:
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ gfObject._event_set_focus(uiObject.widgets.index(self))
- else:
- action = None
+ if gfObject._type == 'GFButton':
+ self.SetFocus()
+ self._connectTable[self._id](self._id)
+ elif gfObject.style == 'checkbox':
+ uiObject._request('TOGGLECHKBOX')
+ else:
+ if gfObject._type != 'GFEntry':
+ cursorPosition = self.getSelectedArea()[1]
+ uiObject._request ('CURSORMOVE', position = cursorPosition)
- ShiftDown = (win32api.GetKeyState(win32con.VK_SHIFT) & 0x8000) and 1
or 0
- ControlDown = (win32api.GetKeyState(win32con.VK_CONTROL) & 0x8000)
and 1 or 0
- AltDown = (win32api.GetKeyState(win32con.VK_MENU) & 0x8000) and 1 or 0
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg,
wParam, lParam)
- command, args = GFKeyMapper.KeyMapper.getEvent(
- keycode,
- ShiftDown,
- ControlDown,
- AltDown)
-
- if command:
+ elif msg == win32con.WM_LBUTTONUP:
+ gfObject = self._uiDriver._IdToGFObj[self._id]
uiObject = self._uiDriver._IdToUIObj[self._id]
- # handle up and down arrows in multiline edit
- if gfObject._type == 'GFEntry' and \
- hasattr(gfObject,'Char__height') and gfObject.Char__height > 1
and \
- keycode in (win32con.VK_UP, win32con.VK_DOWN):
- lines = win32gui.SendMessage(hwnd, win32con.EM_GETLINECOUNT, 0,
0)
- line = win32gui.SendMessage(hwnd, win32con.EM_LINEFROMCHAR, -1,
0)
+ if gfObject._type == 'GFEntry' and gfObject.style == 'default':
+ left, right = self.getSelectedArea ()
+ if left == right:
+ uiObject._request ('CURSORMOVE', position = left)
+ else:
+ uiObject._request ('SELECTWITHMOUSE', position1 = left,
+ position2 = right)
- if line == 0 and keycode == win32con.VK_UP:
- uiObject._request ('PREVENTRY')
- elif line == lines-1 and keycode == win32con.VK_DOWN:
- uiObject._request ('NEXTENTRY')
- else:
- win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
- pos = self.getSelectedArea ()[0]
- uiObject._request ('CURSORMOVE', position = pos)
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg,
wParam, lParam)
+ elif msg == win32con.WM_KEYDOWN:
+ keycode = wParam
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ if (keycode in NOT_WM_CHAR_KEYS):
+
+ if gfObject._type == 'GFEntry' and \
+ gfObject.style in ('dropdown', 'listbox') and \
+ keycode not in F_KEYS:
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd,
msg, wParam, lParam)
+
+ else:
+ action = None
+
+ ShiftDown = (win32api.GetKeyState(win32con.VK_SHIFT) &
0x8000) and 1 or 0
+ ControlDown = (win32api.GetKeyState(win32con.VK_CONTROL) &
0x8000) and 1 or 0
+ AltDown = (win32api.GetKeyState(win32con.VK_MENU) &
0x8000) and 1 or 0
+
+ command, args = GFKeyMapper.KeyMapper.getEvent(
+ keycode,
+ ShiftDown,
+ ControlDown,
+ AltDown)
+
+ if command:
+ uiObject = self._uiDriver._IdToUIObj[self._id]
+ # handle up and down arrows in multiline edit
+ if gfObject._type == 'GFEntry' and \
+ hasattr(gfObject,'Char__height') and
gfObject.Char__height > 1 and \
+ keycode in (win32con.VK_UP, win32con.VK_DOWN):
+
+ lines = win32gui.SendMessage(hwnd,
win32con.EM_GETLINECOUNT, 0, 0)
+ line = win32gui.SendMessage(hwnd,
win32con.EM_LINEFROMCHAR, -1, 0)
+
+ if line == 0 and keycode == win32con.VK_UP:
+ uiObject._request ('PREVENTRY')
+ elif line == lines-1 and keycode ==
win32con.VK_DOWN:
+ uiObject._request ('NEXTENTRY')
+ else:
+ win32gui.CallWindowProc(self._oldWndProc,
hwnd, msg, wParam, lParam)
+ pos = self.getSelectedArea ()[0]
+ uiObject._request ('CURSORMOVE', position =
pos)
+
+ else:
+ action = events.Event('request%s' % command,
arguments=args)
+
+ # Add the object's _form to the outgoing event
+ # rather than every event in the function
+ action.__dict__.update({'_form':gfObject._form})
+ uiObject._eventHandler(action)
+
+ win32gui.SendMessage(hwnd, win32con.EM_SCROLLCARET, 0, 0)
+
+
+ elif msg == win32con.WM_CHAR:
+
+ # The TranslateMessage function generates a WM_CHAR message
+ # when the user presses any of the following keys:
+ # Any character key
+ # backspace
+ # enter (carriage return)
+ # esc
+ # shift+enter (linefeed)
+ # tab
+
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ action = None
+
+ keycode = wParam
+
+ ShiftDown = (win32api.GetKeyState(win32con.VK_SHIFT) & 0x8000) and
1 or 0
+ ControlDown = (win32api.GetKeyState(win32con.VK_CONTROL) & 0x8000)
and 1 or 0
+ AltDown = (win32api.GetKeyState(win32con.VK_MENU) & 0x8000) and 1
or 0
+
+ #
+ # Sigh... a hack for using <enter> in multiline entries
+ #
+ if keycode == 13 and \
+ not ShiftDown and \
+ not ControlDown and \
+ not AltDown and \
+ gConfigForms('enterIsNewLine') and \
+ (hasattr(gfObject,'Char__height') and gfObject.Char__height) >
1:
+
+ command = 'NEWLINE'
+
else:
- action = events.Event('request%s' % command, arguments=args)
-
- # Add the object's _form to the outgoing event
- # rather than every event in the function
- action.__dict__.update({'_form':gfObject._form})
- uiObject._eventHandler(action)
- win32gui.SendMessage(hwnd, win32con.EM_SCROLLCARET, 0, 0)
+ #
+ # Get the event to process from the KeyMapper
+ #
+ (command, args) = GFKeyMapper.KeyMapper.getEvent(
+ keycode,
+ ShiftDown,
+ ControlDown,
+ AltDown)
+ if command == 'NEWLINE':
+ action = events.Event('requestKEYPRESS', '\r\n',
+ text='\r\n',
+ code=10)
- elif msg == win32con.WM_CHAR:
-
- # The TranslateMessage function generates a WM_CHAR message
- # when the user presses any of the following keys:
- # Any character key
- # backspace
- # enter (carriage return)
- # esc
- # shift+enter (linefeed)
- # tab
+ elif command and not keycode in NOT_WM_CHAR_KEYS:
+ action = events.Event('request%s' % command)
- gfObject = self._uiDriver._IdToGFObj[self._id]
- action = None
-
- keycode = wParam
-
- ShiftDown = (win32api.GetKeyState(win32con.VK_SHIFT) & 0x8000) and 1 or 0
- ControlDown = (win32api.GetKeyState(win32con.VK_CONTROL) & 0x8000) and 1
or 0
- AltDown = (win32api.GetKeyState(win32con.VK_MENU) & 0x8000) and 1 or 0
+ else:
+ try:
+ char = chr(keycode)
+ import string
+ if char in string.printable or char == "\n" or \
+ 128 <= keycode <= 255:
+ action = events.Event('requestKEYPRESS',
textDecode(char),
+ text=textDecode(char),
+ code=keycode)
+ except ValueError:
+ pass
- #
- # Sigh... a hack for using <enter> in multiline entries
- #
- if keycode == 13 and \
- not ShiftDown and \
- not ControlDown and \
- not AltDown and \
- gConfigForms('enterIsNewLine') and \
- (hasattr(gfObject,'Char__height') and gfObject.Char__height) > 1:
+ if action:
+ if gfObject._type == 'GFButton' and keycode == 13:
+ self.SetFocus()
+ self._connectTable[self._id](self._id)
+ # Add the object's _form to the outgoing event
+ # rather than every event in the function
+ action.__dict__.update({'_form':gfObject._form})
+ uiObject = self._uiDriver._IdToUIObj[self._id]
+ uiObject._eventHandler(action)
+
+ win32gui.SendMessage(hwnd, win32con.EM_SCROLLCARET, 0, 0)
- command = 'NEWLINE'
+ if gfObject._type == 'GFEntry':
+ if gfObject.style == 'dropdown' or gfObject.style == 'listbox':
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd,
msg, wParam, lParam)
- else:
+ elif msg == win32con.WM_COMMAND:
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ uiObject = self._uiDriver._IdToUIObj[self._id]
- #
- # Get the event to process from the KeyMapper
- #
- (command, args) = GFKeyMapper.KeyMapper.getEvent(
- keycode,
- ShiftDown,
- ControlDown,
- AltDown)
-
- if command == 'NEWLINE':
- action = events.Event('requestKEYPRESS', '\r\n',
- text='\r\n',
- code=10)
+ if gfObject.style == 'dropdown':
+ # Autocompletition goes here:
+ # First find if there any element in the dropdown wth prefix
matching, then
+ # select it with CB_SELECTSTRING, then
+ # highlight(select) the not typed yet part of the string
+ if win32api.HIWORD(wParam) == win32con.EN_UPDATE and
self._AutoComplete:
- elif command and not keycode in NOT_WM_CHAR_KEYS:
- action = events.Event('request%s' % command)
+ text = win32gui.GetWindowText(hwnd)
+ length = len(text)
+ gs = win32gui.SendMessage(self._editHwnd,
win32con.EM_GETSEL, 0, 0)
+ (start, end) = (win32api.LOWORD(gs), win32api.HIWORD(gs))
- else:
- try:
- char = chr(keycode)
- import string
- if char in string.printable or char == "\n" or \
- 128 <= keycode <= 255:
- action = events.Event('requestKEYPRESS', textDecode(char),
- text=textDecode(char),
- code=keycode)
- except ValueError:
- pass
+ if win32gui.SendMessage(hwnd, win32con.CB_SELECTSTRING,
-1, text) == win32con.CB_ERR:
+ win32gui.SetWindowText(self._editHwnd, text)
- if action:
- if gfObject._type == 'GFButton' and keycode == 13:
- self.SetFocus()
- self._connectTable[self._id](self._id)
- # Add the object's _form to the outgoing event
- # rather than every event in the function
- action.__dict__.update({'_form':gfObject._form})
- uiObject = self._uiDriver._IdToUIObj[self._id]
- uiObject._eventHandler(action)
-
- win32gui.SendMessage(hwnd, win32con.EM_SCROLLCARET, 0, 0)
+ selection = self.GetValue()
+ if selection >= 0:
+ string = gfObject._field.allowedValues()[1][selection]
+ uiObject._request('REPLACEVALUE',
+ index=selection, text=string)
- if gfObject._type == 'GFEntry':
- if gfObject.style == 'dropdown' or gfObject.style == 'listbox':
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
-
- elif msg == win32con.WM_COMMAND:
- gfObject = self._uiDriver._IdToGFObj[self._id]
- uiObject = self._uiDriver._IdToUIObj[self._id]
-
- if gfObject.style == 'dropdown':
- # Autocompletition goes here:
- # First find if there any element in the dropdown wth prefix matching,
then
- # select it with CB_SELECTSTRING, then
- # highlight(select) the not typed yet part of the string
- if win32api.HIWORD(wParam) == win32con.EN_UPDATE and
self._AutoComplete:
-
- text = win32gui.GetWindowText(hwnd)
- length = len(text)
- gs = win32gui.SendMessage(self._editHwnd, win32con.EM_GETSEL, 0, 0)
- (start, end) = (win32api.LOWORD(gs), win32api.HIWORD(gs))
-
- if win32gui.SendMessage(hwnd, win32con.CB_SELECTSTRING, -1, text) ==
win32con.CB_ERR:
- win32gui.SetWindowText(self._editHwnd, text)
+ if end < length:
+ win32gui.SendMessage(self._editHwnd,
win32con.EM_SETSEL, start, end)
+ else:
+ win32gui.SendMessage(self._editHwnd,
win32con.EM_SETSEL, length, -1)
- selection = self.GetValue()
- if selection >= 0:
- string = gfObject._field.allowedValues()[1][selection]
- uiObject._request('REPLACEVALUE',
- index=selection, text=string)
+ # selection from listbox part of dropdown with mouse or arrows
+ elif win32api.HIWORD(wParam) == win32con.CBN_SELCHANGE:
+ selection = self.GetValue()
+ if selection >= 0:
+ string = gfObject._field.allowedValues()[1][selection]
+ uiObject._request('REPLACEVALUE',
+ index=selection, text=string)
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd,
msg, wParam, lParam)
+ else:
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd,
msg, wParam, lParam)
+ else:
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg,
wParam, lParam)
- if end < length:
- win32gui.SendMessage(self._editHwnd, win32con.EM_SETSEL, start,
end)
- else:
- win32gui.SendMessage(self._editHwnd, win32con.EM_SETSEL, length,
-1)
- # selection from listbox part of dropdown with mouse or arrows
- elif win32api.HIWORD(wParam) == win32con.CBN_SELCHANGE:
- selection = self.GetValue()
- if selection >= 0:
- string = gfObject._field.allowedValues()[1][selection]
- uiObject._request('REPLACEVALUE',
- index=selection, text=string)
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
- else:
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
- else:
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ elif msg == win32con.WM_PAINT:
+ try:
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ except:
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg,
wParam, lParam)
+ if PILImage and gfObject._type == 'GFImage':
+ win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ hdc = win32gui.GetDC(self._hwnd)
+ self.dib.expose(hdc)
+ win32gui.ReleaseDC(self._hwnd,hdc)
+ else:
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg,
wParam, lParam)
- elif msg == win32con.WM_PAINT:
- try:
- gfObject = self._uiDriver._IdToGFObj[self._id]
- except:
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ # user defined events for edit part of dropdown
+ elif msg == WM_TAB or msg == WM_RETURN:
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ uiObject = self._uiDriver._IdToUIObj[self._id]
- if PILImage and gfObject._type == 'GFImage':
- win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam, lParam)
- hdc = win32gui.GetDC(self._hwnd)
- self.dib.expose(hdc)
- win32gui.ReleaseDC(self._hwnd,hdc)
- else:
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ text = win32gui.GetWindowText(hwnd)
+ win32gui.SendMessage(hwnd, win32con.CB_SELECTSTRING, -1, text)
- # user defined events for edit part of dropdown
- elif msg == WM_TAB or msg == WM_RETURN:
- gfObject = self._uiDriver._IdToGFObj[self._id]
- uiObject = self._uiDriver._IdToUIObj[self._id]
+ selection = self.GetValue()
+ if selection == -1:
+ selection = 0
- text = win32gui.GetWindowText(hwnd)
- win32gui.SendMessage(hwnd, win32con.CB_SELECTSTRING, -1, text)
-
- selection = self.GetValue()
- if selection == -1:
- selection = 0
-
- string = gfObject._field.allowedValues()[1][selection]
- uiObject._request('REPLACEVALUE',
- index=selection, text=string)
- if lParam == 1:
- action = events.Event('requestPREVENTRY')
- else:
- action = events.Event('requestNEXTENTRY')
- action.__dict__.update({'_form':gfObject._form})
- uiObject._eventHandler(action)
-
- elif msg == win32con.WM_CUT:
- uiObject = self._uiDriver._IdToUIObj[self._id]
-
- (start_pos, end_pos) = Win32Entry.getSelectedArea(self)
- text = win32gui.GetWindowText(hwnd)
- uiObject._request('DELETERANGE',
- start_pos=start_pos, end_pos=end_pos,
- position=start_pos)
-
- if win32clipboard.OpenClipboard() == None:
- try:
- win32clipboard.EmptyClipboard()
- win32clipboard.SetClipboardText(text[start_pos : end_pos])
- finally:
- win32clipboard.CloseClipboard()
-
- elif msg == win32con.WM_PASTE:
- uiObject = self._uiDriver._IdToUIObj[self._id]
-
- if win32clipboard.OpenClipboard() == None:
- try:
- data = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
- if data:
- uiObject._request('KEYPRESS', text=data)
- finally:
- win32clipboard.CloseClipboard()
+ string = gfObject._field.allowedValues()[1][selection]
+ uiObject._request('REPLACEVALUE',
+ index=selection, text=string)
+ if lParam == 1:
+ action = events.Event('requestPREVENTRY')
+ else:
+ action = events.Event('requestNEXTENTRY')
+ action.__dict__.update({'_form':gfObject._form})
+ uiObject._eventHandler(action)
+
+ elif msg == win32con.WM_CUT:
+ uiObject = self._uiDriver._IdToUIObj[self._id]
+
+ (start_pos, end_pos) = Win32Entry.getSelectedArea(self)
+ text = win32gui.GetWindowText(hwnd)
+ uiObject._request('DELETERANGE',
+ start_pos=start_pos, end_pos=end_pos,
+ position=start_pos)
+
+ if win32clipboard.OpenClipboard() == None:
+ try:
+ win32clipboard.EmptyClipboard()
+ win32clipboard.SetClipboardText(text[start_pos : end_pos])
+ finally:
+ win32clipboard.CloseClipboard()
+
+ elif msg == win32con.WM_PASTE:
+ uiObject = self._uiDriver._IdToUIObj[self._id]
+
+ if win32clipboard.OpenClipboard() == None:
+ try:
+ data =
win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
+ if data:
+ uiObject._request('KEYPRESS', text=data)
+ finally:
+ win32clipboard.CloseClipboard()
- else:
- return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam,
lParam)
+ else:
+ return win32gui.CallWindowProc(self._oldWndProc, hwnd, msg,
wParam, lParam)
- def SetFont(self, font):
- self._PyCWnd.SetFont(font,1)
+ def SetFont(self, font):
+ self._PyCWnd.SetFont(font,1)
- def GetId(self):
- return self._id
+ def GetId(self):
+ return self._id
- def GetHwnd(self):
- return self._hwnd
+ def GetHwnd(self):
+ return self._hwnd
- def Show(self):
- win32gui.ShowWindow(self._hwnd, win32con.SW_SHOWNORMAL)
+ def Show(self):
+ win32gui.ShowWindow(self._hwnd, win32con.SW_SHOWNORMAL)
- def Hide(self):
- try:
- win32gui.ShowWindow(self._hwnd, win32con.SW_HIDE)
- except:
- pass
+ def Hide(self):
+ try:
+ win32gui.ShowWindow(self._hwnd, win32con.SW_HIDE)
+ except:
+ pass
- def GetParent(self):
- return self._parent
+ def GetParent(self):
+ return self._parent
- def GetChildren(self):
- return self._children
+ def GetChildren(self):
+ return self._children
- def SetFocus(self):
- try:
- win32gui.SetFocus(self._hwnd)
- except:
- pass
+ def SetFocus(self):
+ try:
+ win32gui.SetFocus(self._hwnd)
+ except:
+ pass
- def Enable(self, enabled):
- if enabled:
- win32gui.EnableWindow(self._hwnd, 1)
- else:
- win32gui.EnableWindow(self._hwnd, 0)
+ def Enable(self, enabled):
+ if enabled:
+ win32gui.EnableWindow(self._hwnd, 1)
+ else:
+ win32gui.EnableWindow(self._hwnd, 0)
- def Destroy(self):
- win32gui.DestroyWindow(self._hwnd)
+ def Destroy(self):
+ win32gui.DestroyWindow(self._hwnd)
- def Connect(self, id, func):
- self._connectTable[id] = func
+ def Connect(self, id, func):
+ self._connectTable[id] = func
-
+
class Win32Window(Win32Base):
- _descriptionTable = {}
- _statusBar = None
+ _descriptionTable = {}
+ _statusBar = None
- def addDescription(self, id, description):
- self._descriptionTable[id] = description
+ def addDescription(self, id, description):
+ self._descriptionTable[id] = description
- def OnWMMenuselect(self, hwnd, msg, wParam, lParam):
- id = win32api.LOWORD(wParam)
- if self._descriptionTable.has_key(id):
- msg = self._descriptionTable[id]
- else:
- msg = ''
- win32gui.SendMessage(self._statusBar.GetHwnd(), commctrl.SB_SETTEXT, 0,
msg)
+ def OnWMMenuselect(self, hwnd, msg, wParam, lParam):
+ id = win32api.LOWORD(wParam)
+ if self._descriptionTable.has_key(id):
+ msg = self._descriptionTable[id]
+ else:
+ msg = ''
+ win32gui.SendMessage(self._statusBar.GetHwnd(), commctrl.SB_SETTEXT,
0, msg)
- def OnWMClose(self, hwnd, msg, wParam, lParam):
- self._uiDriver._form.close()
+ def OnWMClose(self, hwnd, msg, wParam, lParam):
+ self._uiDriver._form.close()
- def OnWMSize(self, hwnd, msg, wParam, lParam):
- for child in self._children:
- # resizing statusbar as needed
- if child._className == commctrl.STATUSCLASSNAME:
- (left, top, right, bottom) = win32gui.GetClientRect(hwnd)
- x = right - left
- statwidths =
struct.pack("iiiii",x-75-75-50-50,x-75-75-50,x-75-75,x-75,x)
- win32gui.SendMessage(child.GetHwnd(), commctrl.SB_SETPARTS, 5,
statwidths)
- win32gui.SendMessage(child.GetHwnd(), win32con.WM_SIZE, 0, 0)
- # and toolbar too
- elif child._className == commctrl.TOOLBARCLASSNAME:
- win32gui.SendMessage(child.GetHwnd(), commctrl.TB_AUTOSIZE, 0, 0)
-
- def OnWMCommand(self, hwnd, msg, wParam, lParam):
- # menu/toolbar selection happend'
- self._connectTable[wParam]()
+ def OnWMSize(self, hwnd, msg, wParam, lParam):
+ for child in self._children:
+ # resizing statusbar as needed
+ if child._className == commctrl.STATUSCLASSNAME:
+ (left, top, right, bottom) = win32gui.GetClientRect(hwnd)
+ x = right - left
+ statwidths =
struct.pack("iiiii",x-75-75-50-50,x-75-75-50,x-75-75,x-75,x)
+ win32gui.SendMessage(child.GetHwnd(), commctrl.SB_SETPARTS, 5,
statwidths)
+ win32gui.SendMessage(child.GetHwnd(), win32con.WM_SIZE, 0, 0)
+ # and toolbar too
+ elif child._className == commctrl.TOOLBARCLASSNAME:
+ win32gui.SendMessage(child.GetHwnd(), commctrl.TB_AUTOSIZE, 0,
0)
- def OnWMNotify(self, hwnd, msg, wParam, lParam):
- # handling tabbed pages
- format = "iiiiiiiiiii"
- buf = win32gui.PyMakeBuffer(struct.calcsize(format), lParam)
- hwndFrom, idFrom, code, iItem, iSubItem, uNewState, uOldState, uChanged,
actionx, actiony, lparam \
- = struct.unpack(format, buf)
- if code == -552: #commctrl.TCN_SELCHANGING
- window = self._uiDriver._win32app._HwndToTkObj[hwndFrom]
- pageId = win32gui.SendMessage(window.GetHwnd(), commctrl.TCM_GETCURSEL,
0, 0)
- window._children[pageId].Hide()
- elif code == -551: #commctrl.TCN_SELCHANGE
- window = self._uiDriver._win32app._HwndToTkObj[hwndFrom]
- pageId = win32gui.SendMessage(window.GetHwnd(), commctrl.TCM_GETCURSEL,
0, 0)
- window._children[pageId].Show()
+ def OnWMCommand(self, hwnd, msg, wParam, lParam):
+ # menu/toolbar selection happend'
+ self._connectTable[wParam]()
- id = window._children[pageId].GetId()
- gfObject = self._uiDriver._IdToGFObj[id]
- gfObject._form._event_page_changed(pageId)
- gfObject._form.findAndChangeFocus(gfObject)
+ def OnWMNotify(self, hwnd, msg, wParam, lParam):
+ # handling tabbed pages
+ format = "iiiiiiiiiii"
+ buf = win32gui.PyMakeBuffer(struct.calcsize(format), lParam)
+ hwndFrom, idFrom, code, iItem, iSubItem, uNewState, uOldState,
uChanged, actionx, actiony, lparam \
+ = struct.unpack(format, buf)
+ if code == -552: #commctrl.TCN_SELCHANGING
+ window = self._uiDriver._win32app._HwndToTkObj[hwndFrom]
+ pageId = win32gui.SendMessage(window.GetHwnd(),
commctrl.TCM_GETCURSEL, 0, 0)
+ window._children[pageId].Hide()
+ elif code == -551: #commctrl.TCN_SELCHANGE
+ window = self._uiDriver._win32app._HwndToTkObj[hwndFrom]
+ pageId = win32gui.SendMessage(window.GetHwnd(),
commctrl.TCM_GETCURSEL, 0, 0)
+ window._children[pageId].Show()
+ id = window._children[pageId].GetId()
+ gfObject = self._uiDriver._IdToGFObj[id]
+ gfObject._form._event_page_changed(pageId)
+ gfObject._form.findAndChangeFocus(gfObject)
+
class Win32Entry(Win32Base):
- def OnWMCommand(self, hwnd, msg, wParam, lParam):
- pass
+ def OnWMCommand(self, hwnd, msg, wParam, lParam):
+ pass
# print 'Win32Entry.OnWMCommand', hwnd, msg, wParam, lParam
- def SetValue(self, value):
- try:
- gfObject = self._uiDriver._IdToGFObj[self._id]
- if gfObject.style == 'checkbox':
- if value:
- val = win32con.BST_CHECKED
+ def SetValue(self, value):
+ try:
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ if gfObject.style == 'checkbox':
+ if value:
+ val = win32con.BST_CHECKED
+ else:
+ val = win32con.BST_UNCHECKED
+ win32gui.SendMessage(self._hwnd, win32con.BM_SETCHECK, val, 0)
+ elif gfObject.style == 'dropdown':
+ if value:
+ win32gui.SendMessage(self._hwnd, win32con.CB_SELECTSTRING,
-1, value)
+ else:
+ win32gui.SendMessage(self._hwnd, win32con.CB_SETCURSEL, 0,
0)
+ elif gfObject.style == 'listbox':
+ if value:
+ win32gui.SendMessage(self._hwnd, win32con.LB_SELECTSTRING,
-1, value)
+ else:
+ win32gui.SendMessage(self._hwnd, win32con.LB_SETCURSEL, 0,
0)
+ else:
+ if hasattr(gfObject,'Char__height') and gfObject.Char__height
> 1:
+ corrvalue = '\r\n'.join (value.splitlines ())
+ if len(value) and value[-1] == '\n':
+ corrvalue += '\r\n'
+ win32gui.SetWindowText(self._hwnd, corrvalue)
+ else:
+ win32gui.SetWindowText(self._hwnd, str(value))
+ except:
+ pass
+
+ def GetValue(self):
+ gfObject = self._uiDriver._IdToGFObj[self._id]
+ if gfObject.style == 'checkbox':
+ val = win32gui.SendMessage(self._hwnd, win32con.BM_GETCHECK, 0, 0)
& win32con.BST_CHECKED
+ if val:
+ return 1
+ else:
+ return 0
+ elif gfObject.style == 'dropdown':
+ return win32gui.SendMessage(self._hwnd, win32con.CB_GETCURSEL, 0,
0)
+ elif gfObject.style == 'listbox':
+ return win32gui.SendMessage(self._hwnd, win32con.LB_GETCURSEL, 0,
0)
else:
- val = win32con.BST_UNCHECKED
- win32gui.SendMessage(self._hwnd, win32con.BM_SETCHECK, val, 0)
- elif gfObject.style == 'dropdown':
- if value:
- win32gui.SendMessage(self._hwnd, win32con.CB_SELECTSTRING, -1, value)
- else:
- win32gui.SendMessage(self._hwnd, win32con.CB_SETCURSEL, 0, 0)
- elif gfObject.style == 'listbox':
- if value:
- win32gui.SendMessage(self._hwnd, win32con.LB_SELECTSTRING, -1, value)
- else:
- win32gui.SendMessage(self._hwnd, win32con.LB_SETCURSEL, 0, 0)
- else:
- if hasattr(gfObject,'Char__height') and gfObject.Char__height > 1:
- corrvalue = '\r\n'.join (value.splitlines ())
- if len(value) and value[-1] == '\n':
- corrvalue += '\r\n'
- win32gui.SetWindowText(self._hwnd, corrvalue)
- else:
- win32gui.SetWindowText(self._hwnd, str(value))
- except:
- pass
+ return win32gui.GetWindowText(self._hwnd)
- def GetValue(self):
- gfObject = self._uiDriver._IdToGFObj[self._id]
- if gfObject.style == 'checkbox':
- val = win32gui.SendMessage(self._hwnd, win32con.BM_GETCHECK, 0, 0) &
win32con.BST_CHECKED
- if val:
- return 1
- else:
- return 0
- elif gfObject.style == 'dropdown':
- return win32gui.SendMessage(self._hwnd, win32con.CB_GETCURSEL, 0, 0)
- elif gfObject.style == 'listbox':
- return win32gui.SendMessage(self._hwnd, win32con.LB_GETCURSEL, 0, 0)
- else:
- return win32gui.GetWindowText(self._hwnd)
+ def set_cursor_position(self, position):
+ win32gui.SendMessage(self._hwnd, win32con.EM_SETSEL, position,
position)
- def set_cursor_position(self, position):
- win32gui.SendMessage(self._hwnd, win32con.EM_SETSEL, position, position)
+ def set_selected_area(self, selection1, selection2):
+ win32gui.SendMessage(self._hwnd, win32con.EM_SETSEL, selection1,
selection2)
- def set_selected_area(self, selection1, selection2):
- win32gui.SendMessage(self._hwnd, win32con.EM_SETSEL, selection1,
selection2)
+ def getSelectedArea(self):
+ gs = win32gui.SendMessage(self._hwnd, win32con.EM_GETSEL, 0, 0)
+ return (win32api.LOWORD(gs), win32api.HIWORD(gs))
- def getSelectedArea(self):
- gs = win32gui.SendMessage(self._hwnd, win32con.EM_GETSEL, 0, 0)
- return (win32api.LOWORD(gs), win32api.HIWORD(gs))
+ def Cut(self):
+ win32gui.SendMessage(self._hwnd, win32con.WM_CUT, 0, 0)
+
+ def Copy(self):
+ win32gui.SendMessage(self._hwnd, win32con.WM_COPY, 0, 0)
+
+ def Paste(self):
+ win32gui.SendMessage(self._hwnd, win32con.WM_PASTE, 0, 0)
+
+ def SelectAll(self):
+ self.set_selected_area(0,-1)
+ (start_pos, end_pos) = self.getSelectedArea()
+
+ uiObject = self._uiDriver._IdToUIObj[self._id]
+ uiObject._request('SELECTWITHMOUSE',
+ position1=start_pos, position2=end_pos,
+ cursor=end_pos)
+
- def Cut(self):
- win32gui.SendMessage(self._hwnd, win32con.WM_CUT, 0, 0)
-
- def Copy(self):
- win32gui.SendMessage(self._hwnd, win32con.WM_COPY, 0, 0)
-
- def Paste(self):
- win32gui.SendMessage(self._hwnd, win32con.WM_PASTE, 0, 0)
-
- def SelectAll(self):
- self.set_selected_area(0,-1)
- (start_pos, end_pos) = self.getSelectedArea()
-
- uiObject = self._uiDriver._IdToUIObj[self._id]
- uiObject._request('SELECTWITHMOUSE',
- position1=start_pos, position2=end_pos,
- cursor=end_pos)
-
-
class Win32Button(Win32Base):
- def OnWMCommand(self, hwnd, msg, wParam, lParam):
- pass
+ def OnWMCommand(self, hwnd, msg, wParam, lParam):
+ pass
# print 'Win32Button.OnWMCommand', hwnd, msg, wParam, lParam
class Win32Page(Win32Base):
- def OnWMNotify(self, hwnd, msg, wParam, lParam):
- pass
+ def OnWMNotify(self, hwnd, msg, wParam, lParam):
+ pass
# print 'Win32Page.OnWMNotify', hwnd, msg, wParam, lParam
- def OnWMCommand(self, hwnd, msg, wParam, lParam):
- if win32api.HIWORD(wParam) == win32con.LBN_SELCHANGE:
- lbWindow = self._uiDriver._win32app._HwndToTkObj[lParam]
- id = lbWindow.GetId()
- gfObject = self._uiDriver._IdToGFObj[id]
- uiObject = self._uiDriver._IdToUIObj[id]
- if gfObject.style == 'listbox':
- selection = lbWindow.GetValue()
- string = gfObject._field.allowedValues()[1][selection]
- uiObject._request('REPLACEVALUE',
- index=selection, text=string)
+ def OnWMCommand(self, hwnd, msg, wParam, lParam):
+ if win32api.HIWORD(wParam) == win32con.LBN_SELCHANGE:
+ lbWindow = self._uiDriver._win32app._HwndToTkObj[lParam]
+ id = lbWindow.GetId()
+ gfObject = self._uiDriver._IdToGFObj[id]
+ uiObject = self._uiDriver._IdToUIObj[id]
+ if gfObject.style == 'listbox':
+ selection = lbWindow.GetValue()
+ string = gfObject._field.allowedValues()[1][selection]
+ uiObject._request('REPLACEVALUE',
+ index=selection, text=string)
- else:
- window = self._uiDriver._win32app._HwndToTkObj[lParam]
- window.OnWMCommand(hwnd, msg, wParam, lParam)
+ else:
+ window = self._uiDriver._win32app._HwndToTkObj[lParam]
+ window.OnWMCommand(hwnd, msg, wParam, lParam)
- def OnWMVScroll(self, hwnd, msg, wParam, lParam):
- sbWindow = self._uiDriver._win32app._HwndToTkObj[lParam]
- id = sbWindow.GetId()
- gfObject = self._uiDriver._IdToGFObj[id]
- uiObject = self._uiDriver._IdToUIObj[id]
- scrollCode = win32api.LOWORD(wParam)
+ def OnWMVScroll(self, hwnd, msg, wParam, lParam):
+ sbWindow = self._uiDriver._win32app._HwndToTkObj[lParam]
+ id = sbWindow.GetId()
+ gfObject = self._uiDriver._IdToGFObj[id]
+ uiObject = self._uiDriver._IdToUIObj[id]
+ scrollCode = win32api.LOWORD(wParam)
- if scrollCode == win32con.SB_THUMBTRACK:
- format = "IIiiIii"
- size = struct.calcsize (format)
- scrollinfo = struct.pack (format, size, win32con.SIF_ALL, 0, 0, 0, 0, 0)
- win32gui.SendMessage(lParam, win32con.SBM_GETSCROLLINFO, 0, scrollinfo)
- size, mask, min, max, page, pos, trackpos = struct.unpack (format,
- scrollinfo)
- gfObject._event_scrollToRecord (int (trackpos))
+ if scrollCode == win32con.SB_THUMBTRACK:
+ format = "IIiiIii"
+ size = struct.calcsize (format)
+ scrollinfo = struct.pack (format, size, win32con.SIF_ALL, 0, 0, 0,
0, 0)
+ win32gui.SendMessage(lParam, win32con.SBM_GETSCROLLINFO, 0,
scrollinfo)
+ size, mask, min, max, page, pos, trackpos = struct.unpack (format,
+ scrollinfo)
+ gfObject._event_scrollToRecord (int (trackpos))
- elif scrollCode == win32con.SB_PAGEUP:
- gfObject._event_scrollDelta (- uiObject.pageSize)
+ elif scrollCode == win32con.SB_PAGEUP:
+ gfObject._event_scrollDelta (- uiObject.pageSize)
- elif scrollCode == win32con.SB_PAGEDOWN:
- gfObject._event_scrollDelta (uiObject.pageSize)
+ elif scrollCode == win32con.SB_PAGEDOWN:
+ gfObject._event_scrollDelta (uiObject.pageSize)
- elif scrollCode == win32con.SB_LINEDOWN:
- gfObject._event_scrollDelta (1)
+ elif scrollCode == win32con.SB_LINEDOWN:
+ gfObject._event_scrollDelta (1)
- elif scrollCode == win32con.SB_LINEUP:
- gfObject._event_scrollDelta (-1)
+ elif scrollCode == win32con.SB_LINEUP:
+ gfObject._event_scrollDelta (-1)
- elif scrollCode == win32con.SB_BOTTOM:
- gfObject._event_scrollToRecord (uiObject.lastRecord)
+ elif scrollCode == win32con.SB_BOTTOM:
+ gfObject._event_scrollToRecord (uiObject.lastRecord)
- elif scrollCode == win32con.SB_TOP:
- gfObject._event_scrollToRecord (0)
+ elif scrollCode == win32con.SB_TOP:
+ gfObject._event_scrollToRecord (0)
class Win32Image(Win32Base):
-
- def SetValue(self, value):
- if PILImage is None:
- return
- l,t,r,b = win32gui.GetWindowRect(self._hwnd)
- scrx,scry = (r-l, b-t)
- imgx, imgy = value.size
-
- gfObject = self._uiDriver._IdToGFObj[self._id]
+ def SetValue(self, value):
+ if PILImage is None:
+ return
- scalex = scaley = 1
+ l,t,r,b = win32gui.GetWindowRect(self._hwnd)
+ scrx,scry = (r-l, b-t)
+ imgx, imgy = value.size
- fit = gfObject.fit
- if fit == "auto":
- if float(scrx) / imgx < float(scry) / imgy:
- fit = "width"
- else:
- fit = "height"
+ gfObject = self._uiDriver._IdToGFObj[self._id]
- if fit == "width":
- scalex = scaley = float(scrx) / imgx
- elif fit == "height":
- scalex = scaley = float(scry) / imgy
- elif fit == "both":
- scalex = float(scrx) / imgx
- scaley = float(scry) / imgy
+ scalex = scaley = 1
- if scalex != 1 or scaley != 1:
- value = value.resize((abs(int(imgx * (scalex))), abs(int(imgy *
(scaley)))), PILImage.BICUBIC)
+ fit = gfObject.fit
+ if fit == "auto":
+ if float(scrx) / imgx < float(scry) / imgy:
+ fit = "width"
+ else:
+ fit = "height"
- # clear the previous image
- win32gui.SetWindowPos(self._hwnd, 0, 0, 0, 0, 0, win32con.SWP_NOMOVE |
win32con.SWP_NOZORDER)
-
- # resize the bitmap holder to match the image size again
- win32gui.SetWindowPos(self._hwnd, 0, 0, 0, scrx, scry, win32con.SWP_NOMOVE
| win32con.SWP_NOZORDER)
-
- # convert a PIL image to Dib
- self.dib = ImageWin.Dib(value)
-
- # paint it
- win32gui.SendMessage(self._hwnd, win32con.WM_PAINT, 0, 0)
+ if fit == "width":
+ scalex = scaley = float(scrx) / imgx
+ elif fit == "height":
+ scalex = scaley = float(scry) / imgy
+ elif fit == "both":
+ scalex = float(scrx) / imgx
+ scaley = float(scry) / imgy
+ if scalex != 1 or scaley != 1:
+ value = value.resize((abs(int(imgx * (scalex))), abs(int(imgy *
(scaley)))), PILImage.BICUBIC)
+ # clear the previous image
+ win32gui.SetWindowPos(self._hwnd, 0, 0, 0, 0, 0, win32con.SWP_NOMOVE |
win32con.SWP_NOZORDER)
+
+ # resize the bitmap holder to match the image size again
+ win32gui.SetWindowPos(self._hwnd, 0, 0, 0, scrx, scry,
win32con.SWP_NOMOVE | win32con.SWP_NOZORDER)
+
+ # convert a PIL image to Dib
+ self.dib = ImageWin.Dib(value)
+
+ # paint it
+ win32gui.SendMessage(self._hwnd, win32con.WM_PAINT, 0, 0)
+
+
#
# UIHelper
#
@@ -709,110 +709,110 @@
# require in each UIclass listed below.
#
class UIHelper(UIWidget):
- def _addToCrossRef(self, widget, gfobject, uiobject):
- id = widget.GetId()
- self._uiDriver._IdToGFObj[id]=gfobject
- self._uiDriver._IdToUIObj[id]=uiobject
+ def _addToCrossRef(self, widget, gfobject, uiobject):
+ id = widget.GetId()
+ self._uiDriver._IdToGFObj[id]=gfobject
+ self._uiDriver._IdToUIObj[id]=uiobject
- def _deleteFromCrossRef(self, widget, object):
- id = widget.GetId()
- try:
- del self._uiDriver._IdToGFObj[id]
- del self._uiDriver._IdToUIObj[id]
- except:
- pass
+ def _deleteFromCrossRef(self, widget, object):
+ id = widget.GetId()
+ try:
+ del self._uiDriver._IdToGFObj[id]
+ del self._uiDriver._IdToUIObj[id]
+ except:
+ pass
- #
- # Override the base UIWidget functions
- #
- def show(self):
- for widget in self.widgets:
- widget.Show()
+ #
+ # Override the base UIWidget functions
+ #
+ def show(self):
+ for widget in self.widgets:
+ widget.Show()
- def hide(self):
- for widget in self.widgets:
- widget.Hide()
+ def hide(self):
+ for widget in self.widgets:
+ widget.Hide()
-
- def show_modal(self):
- for widget in self.widgets:
- widget.Show()
- def destroy(self):
- for widget in self.widgets:
- self.Destroy()
+ def show_modal(self):
+ for widget in self.widgets:
+ widget.Show()
+ def destroy(self):
+ for widget in self.widgets:
+ self.Destroy()
- def _ui_set_focus_(self, index):
- self.widgets[index].SetFocus()
- def _ui_focus_in_(self, index):
- # If we are in a grid, exchange label with entry widget
- pass
+ def _ui_set_focus_(self, index):
+ self.widgets[index].SetFocus()
- def _ui_focus_out_(self, index):
- # If we are in a grid, exchange entry widget with the label
- pass
+ def _ui_focus_in_(self, index):
+ # If we are in a grid, exchange label with entry widget
+ pass
- def _ui_set_value_(self, index, value):
- widget = self.widgets[index]
- # Check if foreign key changed
- gfObject = self._uiDriver._IdToGFObj[widget.GetId()]
- try:
- if (gfObject.style == "dropdown" or gfObject.style == "listbox") and \
- not gfObject._field._allowedValues == widget._origAllowedValues:
- widget._origAllowedValues = gfObject._field._allowedValues
- if gfObject.style == "dropdown":
- RESETCONTENT = win32con.CB_RESETCONTENT
- ADDSTRING = win32con.CB_ADDSTRING
- else:
- RESETCONTENT = win32con.LB_RESETCONTENT
- ADDSTRING = win32con.LB_ADDSTRING
+ def _ui_focus_out_(self, index):
+ # If we are in a grid, exchange entry widget with the label
+ pass
- win32gui.SendMessage(widget.GetHwnd(), RESETCONTENT, 0, 0)
- for value in gfObject._field.allowedValues()[1]:
- win32gui.SendMessage(widget.GetHwnd(), ADDSTRING, 0,
textEncode(value))
- widget.SetValue("")
- except AttributeError:
- pass
+ def _ui_set_value_(self, index, value):
+ widget = self.widgets[index]
+ # Check if foreign key changed
+ gfObject = self._uiDriver._IdToGFObj[widget.GetId()]
+ try:
+ if (gfObject.style == "dropdown" or gfObject.style == "listbox")
and \
+ not gfObject._field._allowedValues ==
widget._origAllowedValues:
+ widget._origAllowedValues = gfObject._field._allowedValues
+ if gfObject.style == "dropdown":
+ RESETCONTENT = win32con.CB_RESETCONTENT
+ ADDSTRING = win32con.CB_ADDSTRING
+ else:
+ RESETCONTENT = win32con.LB_RESETCONTENT
+ ADDSTRING = win32con.LB_ADDSTRING
- # display unicode chars properly
- value=textEncode(value) #.encode('mbcs') ?
-
- widget.SetValue(value)
+ win32gui.SendMessage(widget.GetHwnd(), RESETCONTENT, 0, 0)
+ for value in gfObject._field.allowedValues()[1]:
+ win32gui.SendMessage(widget.GetHwnd(), ADDSTRING, 0,
textEncode(value))
+ widget.SetValue("")
+ except AttributeError:
+ pass
+ # display unicode chars properly
+ value=textEncode(value) #.encode('mbcs') ?
- def _ui_set_cursor_position_(self, index, position):
- self.widgets[index].set_cursor_position(position)
+ widget.SetValue(value)
- def _ui_set_selected_area_(self, index, selection1, selection2):
- self.widgets[index].set_selected_area(selection1, selection2)
- def _create_widget_(self, event, spacer):
- gfObject = event.object
+ def _ui_set_cursor_position_(self, index, position):
+ self.widgets[index].set_cursor_position(position)
- if hasattr (gfObject, 'Char__y'):
- posY = gfObject.Char__y
- gap = gfObject._gap + 1
- self.itemY = (posY + spacer * gap) * event.widgetHeight
+ def _ui_set_selected_area_(self, index, selection1, selection2):
+ self.widgets[index].set_selected_area(selection1, selection2)
- newWidget = self._create_widget(event, spacer)
- newWidget.SetFont(self._uiDriver._font)
- if event.initialize:
- self._eventHandler = event.eventHandler
- self._addToCrossRef(newWidget,gfObject,self)
+ def _create_widget_(self, event, spacer):
+ gfObject = event.object
- return newWidget
+ if hasattr (gfObject, 'Char__y'):
+ posY = gfObject.Char__y
+ gap = gfObject._gap + 1
+ self.itemY = (posY + spacer * gap) * event.widgetHeight
- def cleanup(self, object):
- for widget in self.widgets[:]:
- id = widget.GetId()
- del self._uiDriver._IdToGFObj[id]
- del self._uiDriver._IdToUIObj[id]
- self.widgets.pop(0)
- self._deleteFromCrossRef(widget, object)
+ newWidget = self._create_widget(event, spacer)
+ newWidget.SetFont(self._uiDriver._font)
+ if event.initialize:
+ self._eventHandler = event.eventHandler
+ self._addToCrossRef(newWidget,gfObject,self)
+ return newWidget
+ def cleanup(self, object):
+ for widget in self.widgets[:]:
+ id = widget.GetId()
+ del self._uiDriver._IdToGFObj[id]
+ del self._uiDriver._IdToUIObj[id]
+ self.widgets.pop(0)
+ self._deleteFromCrossRef(widget, object)
+
+
#####################################################################
##
## Keymapper Support
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/box.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/box.py 2006-11-16 15:06:12 UTC
(rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/box.py 2006-11-17 09:32:00 UTC
(rev 9046)
@@ -35,32 +35,31 @@
# Widget set specific function that creates a single instance of a border box
#
class UIBox(UIHelper):
-
- def _create_widget(self, event, spacer):
- w = int (event.widgetWidth / 2)
- h = int (event.widgetHeight / 8)
+ def _create_widget(self, event, spacer):
- object = event.object
- itemHeight = object.Char__height * event.widgetHeight - int(
event.widgetHeight /2)
-
- style = win32con.WS_CHILD | win32con.BS_GROUPBOX | win32con.WS_GROUP
- styleEx = 0
- newWidget = Win32Window(self._uiDriver, styleEx, 'BUTTON',
textEncode(object.label), style,
- self.itemX + w,
- self.itemY + h,
- self.itemWidth - 2*w,
- itemHeight ,
- event.container)
- return newWidget
+ w = int (event.widgetWidth / 2)
+ h = int (event.widgetHeight / 8)
+ object = event.object
+ itemHeight = object.Char__height * event.widgetHeight - int(
event.widgetHeight /2)
+ style = win32con.WS_CHILD | win32con.BS_GROUPBOX | win32con.WS_GROUP
+ styleEx = 0
+ newWidget = Win32Window(self._uiDriver, styleEx, 'BUTTON',
textEncode(object.label), style,
+ self.itemX + w,
+ self.itemY + h,
+ self.itemWidth - 2*w,
+ itemHeight ,
+ event.container)
+ return newWidget
+
+
#
-# Configuration data
+# Configuration data
#
configuration = {
'baseClass' : UIBox,
'provides' : 'GFBox',
'container' : 0,
}
-
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/button.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/button.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -37,41 +37,41 @@
# Widget set specific function that creates a single instance of a button
#
class UIButton(UIHelper):
- def _create_widget(self, event, spacer):
- if self.itemHeight == -1:
- height = event.widgetHeight
- else:
- height = self.itemHeight+4
-
- object = event.object
- style = win32con.BS_PUSHBUTTON | win32con.WS_CHILD
- styleEx = 0
- newWidget = Win32Button(self._uiDriver, styleEx, 'BUTTON',
textEncode(object.label), style,
- self.itemX,
- self.itemY,
- self.itemWidth,
- height,
- event.container, getNextId())
- if event.initialize:
- event.container.Connect(newWidget.GetId(), self.buttonHandler)
+ def _create_widget(self, event, spacer):
+ if self.itemHeight == -1:
+ height = event.widgetHeight
+ else:
+ height = self.itemHeight+4
+
+ object = event.object
+ style = win32con.BS_PUSHBUTTON | win32con.WS_CHILD
+ styleEx = 0
+ newWidget = Win32Button(self._uiDriver, styleEx, 'BUTTON',
textEncode(object.label), style,
+ self.itemX,
+ self.itemY,
+ self.itemWidth,
+ height,
+ event.container, getNextId())
+ if event.initialize:
+ event.container.Connect(newWidget.GetId(), self.buttonHandler)
- return newWidget
+ return newWidget
- def buttonHandler(self, id):
- gfObject = self._uiDriver._IdToGFObj[id]
- gfObject._event_fire ()
+ def buttonHandler(self, id):
+ gfObject = self._uiDriver._IdToGFObj[id]
+ gfObject._event_fire ()
- # ---------------------------------------------------------------------------
- # Enable/disable this button
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Enable/disable this button
+ #
---------------------------------------------------------------------------
- def _ui_enable_(self, index):
- self.widgets[index].Enable(True)
+ def _ui_enable_(self, index):
+ self.widgets[index].Enable(True)
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
- def _ui_disable_(self, index):
- self.widgets[index].Enable(False)
+ def _ui_disable_(self, index):
+ self.widgets[index].Enable(False)
configuration = {
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/entry.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/entry.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -37,127 +37,127 @@
# Widget set specific function that creates a single instance of a data entry
widget
#
class UIEntry(UIHelper):
- def _create_widget(self, event, spacer):
- object = event.object
+ def _create_widget(self, event, spacer):
+ object = event.object
- ostyle = object.style
- height = self.itemHeight
- width = self.itemWidth
- title = ""
-
- if ostyle == 'dropdown':
- #~ style = win32con.WS_CHILD | win32con.WS_VSCROLL | win32con.LBS_NOTIFY
| \
- #~ win32con.CBS_DROPDOWNLIST | win32con.CBS_NOINTEGRALHEIGHT
- style = win32con.WS_CHILD | win32con.WS_VSCROLL | \
- win32con.CBS_DROPDOWN | win32con.CBS_NOINTEGRALHEIGHT
- styleEx = 0
- className = "COMBOBOX"
- height = self.itemHeight +100 # TODO
-
- elif ostyle == 'listbox':
- style = win32con.WS_CHILD | win32con.WS_VSCROLL | win32con.LBS_NOTIFY
- styleEx = win32con.WS_EX_CLIENTEDGE
- className = "LISTBOX"
+ ostyle = object.style
+ height = self.itemHeight
+ width = self.itemWidth
+ title = ""
- elif ostyle == 'label':
- style = win32con.WS_CHILD
- styleEx = 0
- className = "STATIC"
+ if ostyle == 'dropdown':
+ #~ style = win32con.WS_CHILD | win32con.WS_VSCROLL |
win32con.LBS_NOTIFY | \
+ #~ win32con.CBS_DROPDOWNLIST |
win32con.CBS_NOINTEGRALHEIGHT
+ style = win32con.WS_CHILD | win32con.WS_VSCROLL | \
+ win32con.CBS_DROPDOWN | win32con.CBS_NOINTEGRALHEIGHT
+ styleEx = 0
+ className = "COMBOBOX"
+ height = self.itemHeight +100 # TODO
+
+ elif ostyle == 'listbox':
+ style = win32con.WS_CHILD | win32con.WS_VSCROLL |
win32con.LBS_NOTIFY
+ styleEx = win32con.WS_EX_CLIENTEDGE
+ className = "LISTBOX"
- elif ostyle == 'checkbox':
- style = win32con.WS_CHILD | win32con.BS_AUTOCHECKBOX
- styleEx = 0
- className = "BUTTON"
- title = object.label
-
- else: # Normal text box
- height = self.itemHeight + 2
- width = self.itemWidth
- style = win32con.WS_CHILD #| win32con.WS_BORDER
+ elif ostyle == 'label':
+ style = win32con.WS_CHILD
+ styleEx = 0
+ className = "STATIC"
- if hasattr(object,'Char__height') and object.Char__height > 1:
- style = style | win32con.ES_MULTILINE | win32con.ES_AUTOVSCROLL | \
- win32con.WS_VSCROLL #| win32con.ES_WANTRETURN
- width = self.itemWidth
- else:
- style = style | win32con.ES_AUTOHSCROLL
+ elif ostyle == 'checkbox':
+ style = win32con.WS_CHILD | win32con.BS_AUTOCHECKBOX
+ styleEx = 0
+ className = "BUTTON"
+ title = object.label
- styleEx = win32con.WS_EX_CLIENTEDGE
- className = "EDIT"
+ else: # Normal text box
+ height = self.itemHeight + 2
+ width = self.itemWidth
+ style = win32con.WS_CHILD #| win32con.WS_BORDER
- newWidget = Win32Entry(self._uiDriver, styleEx, className, title, style,
- self.itemX,
- self.itemY,
- width,
- height,
- event.container, getNextId())
+ if hasattr(object,'Char__height') and object.Char__height > 1:
+ style = style | win32con.ES_MULTILINE |
win32con.ES_AUTOVSCROLL | \
+ win32con.WS_VSCROLL #| win32con.ES_WANTRETURN
+ width = self.itemWidth
+ else:
+ style = style | win32con.ES_AUTOHSCROLL
- if ostyle == 'dropdown' or ostyle == 'listbox':
- if event.initialize:
- choices = object._field.allowedValues()[1]
- else:
- choices = [""]
-
- if ostyle == 'dropdown':
- ADDSTRING = win32con.CB_ADDSTRING
- else:
- ADDSTRING = win32con.LB_ADDSTRING
-
- for item in choices:
- win32gui.SendMessage(newWidget.GetHwnd(), ADDSTRING, 0,
textEncode(item))
- if event.initialize:
- newWidget._origAllowedValues = object._field._allowedValues
- newWidget.SetValue("")
+ styleEx = win32con.WS_EX_CLIENTEDGE
+ className = "EDIT"
- return newWidget
+ newWidget = Win32Entry(self._uiDriver, styleEx, className, title,
style,
+ self.itemX,
+ self.itemY,
+ width,
+ height,
+ event.container, getNextId())
+ if ostyle == 'dropdown' or ostyle == 'listbox':
+ if event.initialize:
+ choices = object._field.allowedValues()[1]
+ else:
+ choices = [""]
+
+ if ostyle == 'dropdown':
+ ADDSTRING = win32con.CB_ADDSTRING
+ else:
+ ADDSTRING = win32con.LB_ADDSTRING
+
+ for item in choices:
+ win32gui.SendMessage(newWidget.GetHwnd(), ADDSTRING, 0,
textEncode(item))
+ if event.initialize:
+ newWidget._origAllowedValues = object._field._allowedValues
+ newWidget.SetValue("")
- # ---------------------------------------------------------------------------
- # Enable/disable this entry
- # ---------------------------------------------------------------------------
+ return newWidget
- def _ui_enable_(self, index):
- self.widgets[index].Enable(True)
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Enable/disable this entry
+ #
---------------------------------------------------------------------------
- def _ui_disable_(self, index):
- self.widgets[index].Enable(False)
+ def _ui_enable_(self, index):
+ self.widgets[index].Enable(True)
+ #
---------------------------------------------------------------------------
- # ---------------------------------------------------------------------------
- # Clipboard and selection
- # ---------------------------------------------------------------------------
+ def _ui_disable_(self, index):
+ self.widgets[index].Enable(False)
- def _ui_cut_(self, index):
-
+
+ #
---------------------------------------------------------------------------
+ # Clipboard and selection
+ #
---------------------------------------------------------------------------
+
+ def _ui_cut_(self, index):
+
widget = self.widgets[index]
if hasattr(widget, 'Cut'):
widget.Cut()
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
- def _ui_copy_(self, index):
-
- widget = self.widgets[index]
-
- if hasattr(widget, 'Copy'):
- widget.Copy()
+ def _ui_copy_(self, index):
+
+ widget = self.widgets[index]
+
+ if hasattr(widget, 'Copy'):
+ widget.Copy()
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
- def _ui_paste_(self, index):
-
+ def _ui_paste_(self, index):
+
widget = self.widgets[index]
if hasattr(widget, 'Paste'):
widget.Paste()
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
- def _ui_select_all_(self, index):
-
+ def _ui_select_all_(self, index):
+
widget = self.widgets[index]
if hasattr(widget, 'SelectAll'):
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/form/widget.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -74,278 +74,278 @@
class UIForm(UIHelper):
- def __init__(self, event):
- self._uiPageList=[]
- UIHelper.__init__(self, event)
+ def __init__(self, event):
+ self._uiPageList=[]
+ UIHelper.__init__(self, event)
- def _create_widget(self, event, spacer):
- object = event.object
- #
- # Size based upon the form definition
- #
+ def _create_widget(self, event, spacer):
+ object = event.object
+ #
+ # Size based upon the form definition
+ #
- formWidth = int(self._form._layout.Char__width)
- formHeight = int(self._form._layout.Char__height)
- self._visibleSize = (formWidth*self._uiDriver.widgetWidth,
- formHeight*self._uiDriver.widgetHeight)
+ formWidth = int(self._form._layout.Char__width)
+ formHeight = int(self._form._layout.Char__height)
+ self._visibleSize = (formWidth*self._uiDriver.widgetWidth,
+ formHeight*self._uiDriver.widgetHeight)
- self._formSize = formSize = (formWidth*self._uiDriver.widgetWidth,
- formHeight*self._uiDriver.widgetHeight)
+ self._formSize = formSize = (formWidth*self._uiDriver.widgetWidth,
+ formHeight*self._uiDriver.widgetHeight)
- # Create the main window.
- if self._form._features['GUI:TOOLBAR:SUPPRESS'] or \
- self._form.style == 'dialog':
- self.buttonbarWidth = 0
- self.buttonbarHeight = 0
- else:
- # TODO: calculate
- self.buttonbarWidth = 13*(24+8) + 5*7 #buttons and separators
- self.buttonbarHeight = 24+8
+ # Create the main window.
+ if self._form._features['GUI:TOOLBAR:SUPPRESS'] or \
+ self._form.style == 'dialog':
+ self.buttonbarWidth = 0
+ self.buttonbarHeight = 0
+ else:
+ # TODO: calculate
+ self.buttonbarWidth = 13*(24+8) + 5*7 #buttons and separators
+ self.buttonbarHeight = 24+8
- if object._layout.tabbed != 'none':
- self.tabHeight = self._uiDriver.widgetHeight + 6
- else:
- self.tabHeight = 0
+ if object._layout.tabbed != 'none':
+ self.tabHeight = self._uiDriver.widgetHeight + 6
+ else:
+ self.tabHeight = 0
- if self._form.style == 'dialog':
- style = win32con.WS_POPUP | win32con.WS_CAPTION |
win32con.WS_CLIPCHILDREN | win32con.WS_SYSMENU #| win32con.WS_OVERLAPPED
- else:
- style = win32con.WS_OVERLAPPEDWINDOW | win32con.WS_CLIPCHILDREN
- styleEx = 0
- self.mainWindow = Win32Window(self._uiDriver, styleEx,
self._uiDriver._wndclass, textEncode(self._form.title),
- style, win32con.CW_USEDEFAULT, 0,
- max(formWidth*self._uiDriver.widgetWidth+20, self.buttonbarWidth),
-
formHeight*self._uiDriver.widgetHeight+self.buttonbarHeight+self.tabHeight+83,
- 0)
+ if self._form.style == 'dialog':
+ style = win32con.WS_POPUP | win32con.WS_CAPTION |
win32con.WS_CLIPCHILDREN | win32con.WS_SYSMENU #| win32con.WS_OVERLAPPED
+ else:
+ style = win32con.WS_OVERLAPPEDWINDOW | win32con.WS_CLIPCHILDREN
+ styleEx = 0
+ self.mainWindow = Win32Window(self._uiDriver, styleEx,
self._uiDriver._wndclass, textEncode(self._form.title),
+ style, win32con.CW_USEDEFAULT, 0,
+ max(formWidth*self._uiDriver.widgetWidth+20, self.buttonbarWidth),
+
formHeight*self._uiDriver.widgetHeight+self.buttonbarHeight+self.tabHeight+83,
+ 0)
- self._uiDriver._win32app._MainWindowList.append(self.mainWindow)
-
- if self._form.style == 'dialog':
- centerWindow(self.mainWindow.GetHwnd())
+ self._uiDriver._win32app._MainWindowList.append(self.mainWindow)
+
+ if self._form.style == 'dialog':
+ centerWindow(self.mainWindow.GetHwnd())
- # The window in which pages will be rendered
- if object._layout.tabbed != 'none':
- self._wrapper = wrappers.TabbedWrapper(self)
- else:
- self._wrapper = wrappers.PlainWrapper(self)
+ # The window in which pages will be rendered
+ if object._layout.tabbed != 'none':
+ self._wrapper = wrappers.TabbedWrapper(self)
+ else:
+ self._wrapper = wrappers.PlainWrapper(self)
- newWidget = self._wrapper.pane
- self._container = newWidget
+ newWidget = self._wrapper.pane
+ self._container = newWidget
- # Add Statusbar, Toolbar and Menubar as requested and/or allowed
- if self._form.style != 'dialog':
- if not self._form._features['GUI:MENUBAR:SUPPRESS']:
- MenuBar(self._uiDriver, self.mainWindow, self._form)
+ # Add Statusbar, Toolbar and Menubar as requested and/or allowed
+ if self._form.style != 'dialog':
+ if not self._form._features['GUI:MENUBAR:SUPPRESS']:
+ MenuBar(self._uiDriver, self.mainWindow, self._form)
- if not self._form._features['GUI:TOOLBAR:SUPPRESS']:
- ToolBar(self._uiDriver, self.mainWindow, self._form)
+ if not self._form._features['GUI:TOOLBAR:SUPPRESS']:
+ ToolBar(self._uiDriver, self.mainWindow, self._form)
- if not self._form._features['GUI:STATUSBAR:SUPPRESS']:
- hinst = win32api.GetModuleHandle(None)
- style = win32con.WS_CHILD | win32con.WS_VISIBLE |
commctrl.SBARS_SIZEGRIP
- styleEx = 0
- self.statusBar = Win32Window(self._uiDriver, styleEx,
commctrl.STATUSCLASSNAME, "",
- style, 0, 0, 0, 0,
- self.mainWindow, getNextId(), hinst)
- x=formWidth*self._uiDriver.widgetWidth
- statwidths =
struct.pack("iiiii",x-75-75-50-50,x-75-75-50,x-75-75,x-75,x)
- win32gui.SendMessage(self.statusBar.GetHwnd(), commctrl.SB_SETPARTS,
5, statwidths)
- win32gui.SendMessage(self.statusBar.GetHwnd(), win32con.WM_SIZE, 0, 0)
- self.mainWindow._statusBar = self.statusBar
-
- self._eventHandler = event.eventHandler
+ if not self._form._features['GUI:STATUSBAR:SUPPRESS']:
+ hinst = win32api.GetModuleHandle(None)
+ style = win32con.WS_CHILD | win32con.WS_VISIBLE |
commctrl.SBARS_SIZEGRIP
+ styleEx = 0
+ self.statusBar = Win32Window(self._uiDriver, styleEx,
commctrl.STATUSCLASSNAME, "",
+ style, 0, 0, 0, 0,
+ self.mainWindow, getNextId(), hinst)
+ x=formWidth*self._uiDriver.widgetWidth
+ statwidths =
struct.pack("iiiii",x-75-75-50-50,x-75-75-50,x-75-75,x-75,x)
+ win32gui.SendMessage(self.statusBar.GetHwnd(),
commctrl.SB_SETPARTS, 5, statwidths)
+ win32gui.SendMessage(self.statusBar.GetHwnd(),
win32con.WM_SIZE, 0, 0)
+ self.mainWindow._statusBar = self.statusBar
- self._wrapper.finalize()
+ self._eventHandler = event.eventHandler
- return newWidget
+ self._wrapper.finalize()
- #
- # _ui_goto_page_
- #
- # Makes the requested page visible while hiding the others
- #
- def _ui_goto_page_(self,page):
- self._wrapper.setPage(page.widgets[0])
+ return newWidget
- def show(self):
- self.mainWindow.Show()
- if self._form.style == 'dialog':
- win32gui.PumpMessages()
-
+ #
+ # _ui_goto_page_
+ #
+ # Makes the requested page visible while hiding the others
+ #
+ def _ui_goto_page_(self,page):
+ self._wrapper.setPage(page.widgets[0])
- def show_modal(self):
- self.mainWindow.Show()
-
- #~ for key in self._uiDriver._formNameToUIForm.keys():
- #~ if self._form.name == key:
- #~ self._uiDriver._formNameToUIForm[key].mainWindow.Enable(1)
- #~ else:
- #~ self._uiDriver._formNameToUIForm[key].mainWindow.Enable(0)
- if self._form.style == 'dialog':
- win32gui.PumpMessages()
+ def show(self):
+ self.mainWindow.Show()
+ if self._form.style == 'dialog':
+ win32gui.PumpMessages()
+
+ def show_modal(self):
+ self.mainWindow.Show()
+
+ #~ for key in self._uiDriver._formNameToUIForm.keys():
+ #~ if self._form.name == key:
+ #~ self._uiDriver._formNameToUIForm[key].mainWindow.Enable(1)
+ #~ else:
+ #~ self._uiDriver._formNameToUIForm[key].mainWindow.Enable(0)
+ if self._form.style == 'dialog':
+ win32gui.PumpMessages()
- def _ui_set_title_(self, title):
- win32gui.SetWindowText(self.mainWindow.GetHwnd(), event.title)
- # ---------------------------------------------------------------------------
- # User feedback functions
- # ---------------------------------------------------------------------------
+ def _ui_set_title_(self, title):
+ win32gui.SetWindowText(self.mainWindow.GetHwnd(), event.title)
- def _ui_begin_wait_(self):
- win32ui.DoWaitCursor(1)
+ #
---------------------------------------------------------------------------
+ # User feedback functions
+ #
---------------------------------------------------------------------------
- # ---------------------------------------------------------------------------
+ def _ui_begin_wait_(self):
+ win32ui.DoWaitCursor(1)
- def _ui_end_wait_(self):
- win32ui.DoWaitCursor(0)
+ #
---------------------------------------------------------------------------
- # ---------------------------------------------------------------------------
+ def _ui_end_wait_(self):
+ win32ui.DoWaitCursor(0)
- def _ui_beep_(self):
- win32gui.MessageBeep(0)
+ #
---------------------------------------------------------------------------
- # ---------------------------------------------------------------------------
-
- def _ui_update_status_(self, tip, record_status, insert_status,
- record_number, record_count, page_number, page_count):
+ def _ui_beep_(self):
+ win32gui.MessageBeep(0)
- if not hasattr (self, 'statusBar'):
- return
+ #
---------------------------------------------------------------------------
- if tip is not None:
- win32gui.SendMessage(self.statusBar.GetHwnd(), commctrl.SB_SETTEXT, 0,
- textEncode(tip))
+ def _ui_update_status_(self, tip, record_status, insert_status,
+ record_number, record_count, page_number, page_count):
- if record_status:
- win32gui.SendMessage(self.statusBar.GetHwnd(), commctrl.SB_SETTEXT, 1,
- textEncode(record_status))
+ if not hasattr (self, 'statusBar'):
+ return
- if insert_status:
- win32gui.SendMessage(self.statusBar.GetHwnd(), commctrl.SB_SETTEXT, 2,
- textEncode(insert_status))
+ if tip is not None:
+ win32gui.SendMessage(self.statusBar.GetHwnd(),
commctrl.SB_SETTEXT, 0,
+ textEncode(tip))
- if record_number and record_count:
- win32gui.SendMessage(self.statusBar.GetHwnd(), commctrl.SB_SETTEXT, 3,
- ("%s/%s" % (record_number, record_count)).strip())
+ if record_status:
+ win32gui.SendMessage(self.statusBar.GetHwnd(),
commctrl.SB_SETTEXT, 1,
+ textEncode(record_status))
- if page_number and page_count:
- win32gui.SendMessage(self.statusBar.GetHwnd(), commctrl.SB_SETTEXT, 4,
- ("%s/%s" % (page_number, page_count)).strip())
+ if insert_status:
+ win32gui.SendMessage(self.statusBar.GetHwnd(),
commctrl.SB_SETTEXT, 2,
+ textEncode(insert_status))
- return
+ if record_number and record_count:
+ win32gui.SendMessage(self.statusBar.GetHwnd(),
commctrl.SB_SETTEXT, 3,
+ ("%s/%s" % (record_number, record_count)).strip())
+ if page_number and page_count:
+ win32gui.SendMessage(self.statusBar.GetHwnd(),
commctrl.SB_SETTEXT, 4,
+ ("%s/%s" % (page_number, page_count)).strip())
- # ---------------------------------------------------------------------------
- # create a modal message box
- # ---------------------------------------------------------------------------
+ return
- def _ui_show_message_(self, message, kind, title, cancel):
- """
- This function creates a message box of a given kind and returns True, False
- or None depending on the button pressed.
- @param message: the text of the messagebox
- @param kind: type of the message box. Valid types are 'Info', 'Warning',
- 'Question', 'Error'
- @param title: title of the message box
- @param cancel: If True a cancel button will be added to the dialog
- @return: True if the Ok-, Close-, or Yes-button was pressed, False if the
- No-button was pressed or None if the Cancel-button was pressed.
- """
- mbRec = _MBOX_KIND.get (kind)
- flags = win32con.MB_TASKMODAL | mbRec['icon']
- if title is not None and len (title):
- if isinstance (title, types.StringType):
- title = unicode (title, i18n.encoding)
- else:
- title = mbRec['type']
+ #
---------------------------------------------------------------------------
+ # create a modal message box
+ #
---------------------------------------------------------------------------
- if cancel:
- if mbRec ['buttons'] == win32con.MB_OK:
- flags = flags | win32con.MB_OKCANCEL
- elif mbRec ['buttons'] == win32con.MB_YESNO:
- flags = flags | win32con.MB_YESNOCANCEL
- else:
- flags = flags | mbRec['buttons']
+ def _ui_show_message_(self, message, kind, title, cancel):
+ """
+ This function creates a message box of a given kind and returns True,
False
+ or None depending on the button pressed.
+ @param message: the text of the messagebox
+ @param kind: type of the message box. Valid types are 'Info',
'Warning',
+ 'Question', 'Error'
+ @param title: title of the message box
+ @param cancel: If True a cancel button will be added to the dialog
+ @return: True if the Ok-, Close-, or Yes-button was pressed, False if
the
+ No-button was pressed or None if the Cancel-button was pressed.
+ """
+ mbRec = _MBOX_KIND.get (kind)
+ flags = win32con.MB_TASKMODAL | mbRec['icon']
- res = win32gui.MessageBox(0, message, title, flags)
- return _RESPONSE [res]
-
-
- # ---------------------------------------------------------------------------
- # Display an about box
- # ---------------------------------------------------------------------------
+ if title is not None and len (title):
+ if isinstance (title, types.StringType):
+ title = unicode (title, i18n.encoding)
+ else:
+ title = mbRec['type']
- def _ui_show_about_(self, name, version, author, description):
+ if cancel:
+ if mbRec ['buttons'] == win32con.MB_OK:
+ flags = flags | win32con.MB_OKCANCEL
+ elif mbRec ['buttons'] == win32con.MB_YESNO:
+ flags = flags | win32con.MB_YESNOCANCEL
+ else:
+ flags = flags | mbRec['buttons']
- d = dialogs.AboutBox (self.mainWindow.GetHwnd(), name, version, author,
description)
- d.DoModal ()
+ res = win32gui.MessageBox(0, message, title, flags)
+ return _RESPONSE [res]
+
+
+ #
---------------------------------------------------------------------------
+ # Display an about box
+ #
---------------------------------------------------------------------------
+ def _ui_show_about_(self, name, version, author, description):
- # ---------------------------------------------------------------------------
- # Print form screenshot
- # ---------------------------------------------------------------------------
+ d = dialogs.AboutBox (self.mainWindow.GetHwnd(), name, version,
author, description)
+ d.DoModal ()
- def _ui_printout_(self, title, subtitle, user):
- print 'PrintForm start...'
-
- window = self.mainWindow
- l,t,r,b = win32gui.GetWindowRect(window.GetHwnd())
- image = ImageGrab.grab((l+2, t+2, r-2, b-2))
- image.save("tmp.bmp")
-
- # Open the bitmap
- bmp = Image.open ("tmp.bmp")
- print "original bitmap size =", bmp.size
-
-
- printer = win32print.GetDefaultPrinter()
- print printer
- phandle = win32print.OpenPrinter(printer)
-
- # Find the printer resolution to scale to
- hDC = win32ui.CreateDC ()
- hDC.CreatePrinterDC () # can optionally put a printer name in here
- printer_resolution = hDC.GetDeviceCaps (HORZRES), hDC.GetDeviceCaps
(VERTRES)
- print "printer resolution =", printer_resolution
-
- # Resize the image to fit the page but not to overflow
- ratios = [printer_resolution[0] / bmp.size[0], printer_resolution[1] /
bmp.size[1]]
- print "ratios =", ratios
- scale = min (ratios)
- print "scale =", scale
-
- # Create the printer document and send the page
- hDC.StartDoc ("GNUe PrintForm")
- hDC.StartPage ()
-
- dib = ImageWin.Dib (bmp)
- scaled_size = [scale * i for i in bmp.size]
- print "scaled bitmap size =", scaled_size
- dib.draw (hDC.GetHandleOutput (), [0, 0] + scaled_size)
-
- hDC.EndPage ()
- hDC.EndDoc ()
-
- win32print.ClosePrinter(phandle)
- del hDC
- del bmp
- os.remove("tmp.bmp")
-
- print 'PrintForm end.'
+ #
---------------------------------------------------------------------------
+ # Print form screenshot
+ #
---------------------------------------------------------------------------
+ def _ui_printout_(self, title, subtitle, user):
- # ---------------------------------------------------------------------------
- # Close the window (actually only hide it)
- # ---------------------------------------------------------------------------
+ print 'PrintForm start...'
+
+ window = self.mainWindow
+ l,t,r,b = win32gui.GetWindowRect(window.GetHwnd())
+ image = ImageGrab.grab((l+2, t+2, r-2, b-2))
+ image.save("tmp.bmp")
+
+ # Open the bitmap
+ bmp = Image.open ("tmp.bmp")
+ print "original bitmap size =", bmp.size
+
+
+ printer = win32print.GetDefaultPrinter()
+ print printer
+ phandle = win32print.OpenPrinter(printer)
+
+ # Find the printer resolution to scale to
+ hDC = win32ui.CreateDC ()
+ hDC.CreatePrinterDC () # can optionally put a printer name in here
+ printer_resolution = hDC.GetDeviceCaps (HORZRES), hDC.GetDeviceCaps
(VERTRES)
+ print "printer resolution =", printer_resolution
+
+ # Resize the image to fit the page but not to overflow
+ ratios = [printer_resolution[0] / bmp.size[0], printer_resolution[1] /
bmp.size[1]]
+ print "ratios =", ratios
+ scale = min (ratios)
+ print "scale =", scale
+
+ # Create the printer document and send the page
+ hDC.StartDoc ("GNUe PrintForm")
+ hDC.StartPage ()
+
+ dib = ImageWin.Dib (bmp)
+ scaled_size = [scale * i for i in bmp.size]
+ print "scaled bitmap size =", scaled_size
+ dib.draw (hDC.GetHandleOutput (), [0, 0] + scaled_size)
+
+ hDC.EndPage ()
+ hDC.EndDoc ()
+
+ win32print.ClosePrinter(phandle)
+ del hDC
+ del bmp
+ os.remove("tmp.bmp")
+
+ print 'PrintForm end.'
- def _ui_close_(self):
- self.mainWindow.Hide()
+ #
---------------------------------------------------------------------------
+ # Close the window (actually only hide it)
+ #
---------------------------------------------------------------------------
- if self._form.style == 'dialog':
- win32gui.PostQuitMessage(0) # Terminate the dialog
+ def _ui_close_(self):
+
+ self.mainWindow.Hide()
+
+ if self._form.style == 'dialog':
+ win32gui.PostQuitMessage(0) # Terminate the dialog
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/form/wrappers.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/form/wrappers.py
2006-11-16 15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/form/wrappers.py
2006-11-17 09:32:00 UTC (rev 9046)
@@ -37,185 +37,185 @@
from gnue.forms.uidrivers.win32.common import *
-class ScrollableWrapper(Win32Window):
- def __init__(self, uiform):
- self.uiform = uiform
- self.frame = frame = uiform.mainWindow
- self.form = form = uiform._form
+class ScrollableWrapper(Win32Window):
+ def __init__(self, uiform):
+ self.uiform = uiform
+ self.frame = frame = uiform.mainWindow
+ self.form = form = uiform._form
- formWidth = int(form._layout.Char__width)
- formHeight = int(form._layout.Char__height)
+ formWidth = int(form._layout.Char__width)
+ formHeight = int(form._layout.Char__height)
- style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #| win32con.WS_BORDER
- #win32con.WS_VSCROLL | win32con.WS_HSCROLL
- styleEx = 0
- self.sw=Win32Window(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "ScrollableWrapper", style,
- 2,
- self.uiform.buttonbarHeight+4,
- max(formWidth*uiform._uiDriver.widgetWidth,
self.uiform.buttonbarWidth)+8,
- #formWidth*uiform._uiDriver.widgetWidth+8,
- formHeight*uiform._uiDriver.widgetHeight+self.uiform.tabHeight,
- frame)
+ style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #|
win32con.WS_BORDER
+ #win32con.WS_VSCROLL | win32con.WS_HSCROLL
+ styleEx = 0
+ self.sw=Win32Window(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "ScrollableWrapper", style,
+ 2,
+ self.uiform.buttonbarHeight+4,
+ max(formWidth*uiform._uiDriver.widgetWidth,
self.uiform.buttonbarWidth)+8,
+ #formWidth*uiform._uiDriver.widgetWidth+8,
+ formHeight*uiform._uiDriver.widgetHeight+self.uiform.tabHeight,
+ frame)
- self._fitted = 0
- self._pageList = []
+ self._fitted = 0
+ self._pageList = []
- def finalize(self):
- # This is the initial panel window setup during init
- # not a wxPanel set per page right after this
- self.sw.Show()
-
-
- def OnFrameSize(self, event):
- pass
-
- def fixScrollbars(self):
- pass
-
-
+ def finalize(self):
+ # This is the initial panel window setup during init
+ # not a wxPanel set per page right after this
+ self.sw.Show()
+
+
+ def OnFrameSize(self, event):
+ pass
+
+ def fixScrollbars(self):
+ pass
+
+
#
# Notebook pages
#
-class TabbedWrapper(ScrollableWrapper):
- tabHeight = 0
-
- def __init__(self, *args, **parms):
- ScrollableWrapper.__init__(self, *args, **parms)
- formWidth = int(self.form._layout.Char__width)
- formHeight = int(self.form._layout.Char__height)
- hinst = win32api.GetModuleHandle(None)
- tabstyle = _tabStyles[self.form._layout.tabbed]
- style = win32con.WS_CHILD | commctrl.TCS_TABS | tabstyle #|
win32con.WS_BORDER
- styleEx = 0
- self.pane = Win32Window(self.uiform._uiDriver, styleEx,
commctrl.WC_TABCONTROL, "tabcontrol", style,
- 2,
- 2,
- max(formWidth*self.uiform._uiDriver.widgetWidth+6,
self.uiform.buttonbarWidth-16),
- formHeight*self.uiform._uiDriver.widgetHeight+self.uiform.tabHeight-6,
- self.sw, getNextId(), hinst)
+class TabbedWrapper(ScrollableWrapper):
+ tabHeight = 0
- self.pane.Show()
+ def __init__(self, *args, **parms):
+ ScrollableWrapper.__init__(self, *args, **parms)
+ formWidth = int(self.form._layout.Char__width)
+ formHeight = int(self.form._layout.Char__height)
+ hinst = win32api.GetModuleHandle(None)
+ tabstyle = _tabStyles[self.form._layout.tabbed]
+ style = win32con.WS_CHILD | commctrl.TCS_TABS | tabstyle #|
win32con.WS_BORDER
+ styleEx = 0
+ self.pane = Win32Window(self.uiform._uiDriver, styleEx,
commctrl.WC_TABCONTROL, "tabcontrol", style,
+ 2,
+ 2,
+ max(formWidth*self.uiform._uiDriver.widgetWidth+6,
self.uiform.buttonbarWidth-16),
+
formHeight*self.uiform._uiDriver.widgetHeight+self.uiform.tabHeight-6,
+ self.sw, getNextId(), hinst)
- def createPage(self, object):
- pszText = "%s" % (object.caption or object.name)
- buff = array.array('c', textEncode(pszText) + "\0")
- addrText = buff.buffer_info()[0]
- tab=struct.pack("iilliii", commctrl.TCIF_TEXT | commctrl.TCIF_STATE, 0, 0,
addrText, 0, 0, -1)
- icount = win32gui.SendMessage(self.pane.GetHwnd(),
commctrl.TCM_GETITEMCOUNT, 0, 0)
- win32gui.SendMessage(self.pane.GetHwnd(), commctrl.TCM_INSERTITEM, icount,
tab)
+ self.pane.Show()
- l,t,r,b = win32gui.GetWindowRect(self.pane.GetHwnd())
-
- buff = array.array('i', [0,0,0,0])
- addrBuff = buff.buffer_info()[0]
- win32gui.SendMessage(self.pane.GetHwnd(), commctrl.TCM_GETITEMRECT, 1,
addrBuff)
- self.tabWidth = buff[2]-buff[0]
- self.tabHeight = buff[3]-buff[1]
+ def createPage(self, object):
+ pszText = "%s" % (object.caption or object.name)
+ buff = array.array('c', textEncode(pszText) + "\0")
+ addrText = buff.buffer_info()[0]
+ tab=struct.pack("iilliii", commctrl.TCIF_TEXT | commctrl.TCIF_STATE,
0, 0, addrText, 0, 0, -1)
+ icount = win32gui.SendMessage(self.pane.GetHwnd(),
commctrl.TCM_GETITEMCOUNT, 0, 0)
+ win32gui.SendMessage(self.pane.GetHwnd(), commctrl.TCM_INSERTITEM,
icount, tab)
- if self.form._layout.tabbed == 'top':
- x, y, w, h = 2, self.tabHeight+3, r-l-5, b-t-self.tabHeight-6
+ l,t,r,b = win32gui.GetWindowRect(self.pane.GetHwnd())
- elif self.form._layout.tabbed == 'bottom':
- x, y, w, h = 2, 2, r-l-5, b-t-self.tabHeight-6
+ buff = array.array('i', [0,0,0,0])
+ addrBuff = buff.buffer_info()[0]
+ win32gui.SendMessage(self.pane.GetHwnd(), commctrl.TCM_GETITEMRECT, 1,
addrBuff)
+ self.tabWidth = buff[2]-buff[0]
+ self.tabHeight = buff[3]-buff[1]
- elif self.form._layout.tabbed == 'left':
- x, y, w, h = self.tabWidth+3, 3, r-l-30, b-t-6
+ if self.form._layout.tabbed == 'top':
+ x, y, w, h = 2, self.tabHeight+3, r-l-5, b-t-self.tabHeight-6
- elif self.form._layout.tabbed == 'right':
- x, y, w, h = 2, 2, r-l-30, b-t-6
+ elif self.form._layout.tabbed == 'bottom':
+ x, y, w, h = 2, 2, r-l-5, b-t-self.tabHeight-6
+ elif self.form._layout.tabbed == 'left':
+ x, y, w, h = self.tabWidth+3, 3, r-l-30, b-t-6
- style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #| win32con.WS_BORDER
- styleEx = 0
- newWidget = Win32Page(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "tabbedPage", style,
- x,
- y,
- w,
- h,
- self.pane, getNextId())
+ elif self.form._layout.tabbed == 'right':
+ x, y, w, h = 2, 2, r-l-30, b-t-6
- # Only show first page
- if not self._fitted:
- newWidget.Show()
- else:
- newWidget.Hide()
- self._pageList.append(newWidget)
- self.fit()
- return newWidget
+ style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #|
win32con.WS_BORDER
+ styleEx = 0
+ newWidget = Win32Page(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "tabbedPage", style,
+ x,
+ y,
+ w,
+ h,
+ self.pane, getNextId())
- def fit(self):
- if self._fitted: return
- self._fitted = 1
-
- def setPage(self, page):
- pageId = self._pageList.index(page)
- win32gui.SendMessage(self.pane.GetHwnd(), commctrl.TCM_SETCURSEL, pageId,
0)
+ # Only show first page
+ if not self._fitted:
+ newWidget.Show()
+ else:
+ newWidget.Hide()
- for p in self._pageList:
- if p != page:
- p.Hide()
- else:
- p.Show()
+ self._pageList.append(newWidget)
+ self.fit()
+ return newWidget
+ def fit(self):
+ if self._fitted: return
+ self._fitted = 1
+ def setPage(self, page):
+ pageId = self._pageList.index(page)
+ win32gui.SendMessage(self.pane.GetHwnd(), commctrl.TCM_SETCURSEL,
pageId, 0)
+
+ for p in self._pageList:
+ if p != page:
+ p.Hide()
+ else:
+ p.Show()
+
+
#
-# Single pages win32con.CW_USEDEFAULT,
+# Single pages win32con.CW_USEDEFAULT,
#
-class PlainWrapper(ScrollableWrapper):
- def __init__(self, *args, **parms):
+class PlainWrapper(ScrollableWrapper):
+ def __init__(self, *args, **parms):
- ScrollableWrapper.__init__(self, *args, **parms)
- formWidth = int(self.form._layout.Char__width)
- formHeight = int(self.form._layout.Char__height)
-
- style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #| win32con.WS_BORDER
- styleEx = 0
- self.pane = Win32Window(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "PlainWrapper", style,
- 0,
- 0,
- max(formWidth*self.uiform._uiDriver.widgetWidth,
self.uiform.buttonbarWidth)+8,
- formHeight*self.uiform._uiDriver.widgetHeight,
- self.sw, getNextId())
+ ScrollableWrapper.__init__(self, *args, **parms)
+ formWidth = int(self.form._layout.Char__width)
+ formHeight = int(self.form._layout.Char__height)
+
+ style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #|
win32con.WS_BORDER
+ styleEx = 0
+ self.pane = Win32Window(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "PlainWrapper", style,
+ 0,
+ 0,
+ max(formWidth*self.uiform._uiDriver.widgetWidth,
self.uiform.buttonbarWidth)+8,
+ formHeight*self.uiform._uiDriver.widgetHeight,
+ self.sw, getNextId())
- self.pane.Show()
+ self.pane.Show()
- def createPage(self, object):
+ def createPage(self, object):
- formWidth = int(self.form._layout.Char__width)
- formHeight = int(self.form._layout.Char__height)
- style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #| win32con.WS_BORDER
- styleEx = 0
- newWidget = Win32Page(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "plainPage", style,
- 0,
- 0,
- max(formWidth*self.uiform._uiDriver.widgetWidth,
self.uiform.buttonbarWidth)+8,
- formHeight*self.uiform._uiDriver.widgetHeight,
- self.pane, getNextId())
+ formWidth = int(self.form._layout.Char__width)
+ formHeight = int(self.form._layout.Char__height)
+ style = win32con.WS_OVERLAPPED | win32con.WS_CHILD #|
win32con.WS_BORDER
+ styleEx = 0
+ newWidget = Win32Page(self.uiform._uiDriver, styleEx,
self.uiform._uiDriver._wndclass, "plainPage", style,
+ 0,
+ 0,
+ max(formWidth*self.uiform._uiDriver.widgetWidth,
self.uiform.buttonbarWidth)+8,
+ formHeight*self.uiform._uiDriver.widgetHeight,
+ self.pane, getNextId())
- # Only show first page
- if not self._fitted:
- newWidget.Show()
- else:
- newWidget.Hide()
-
- self._pageList.append(newWidget)
- self.fit()
- return newWidget
+ # Only show first page
+ if not self._fitted:
+ newWidget.Show()
+ else:
+ newWidget.Hide()
+ self._pageList.append(newWidget)
+ self.fit()
+ return newWidget
- def fit(self):
- if self._fitted: return
- self._fitted = 1
- def setPage(self, page):
- for p in self._pageList:
- if p != page:
- p.Hide()
- else:
- p.Show()
+ def fit(self):
+ if self._fitted: return
+ self._fitted = 1
+ def setPage(self, page):
+ for p in self._pageList:
+ if p != page:
+ p.Hide()
+ else:
+ p.Show()
+
_tabStyles = {'left':commctrl.TCS_MULTILINE | commctrl.TCS_VERTICAL,
'right':commctrl.TCS_MULTILINE | commctrl.TCS_VERTICAL |
commctrl.TCS_RIGHT,
'bottom':commctrl.TCS_BOTTOM,
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/image.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/image.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -37,17 +37,17 @@
#
class UIImage(UIHelper):
- def _create_widget(self, event, spacer):
- object = event.object
- style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.SS_BITMAP
- styleEx = 0
- newWidget = Win32Image(self._uiDriver, styleEx, 'STATIC', '', style,
- self.itemX,
- self.itemY,
- self.itemWidth,
- self.itemHeight,
- event.container, getNextId())
- return newWidget
+ def _create_widget(self, event, spacer):
+ object = event.object
+ style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.SS_BITMAP
+ styleEx = 0
+ newWidget = Win32Image(self._uiDriver, styleEx, 'STATIC', '', style,
+ self.itemX,
+ self.itemY,
+ self.itemWidth,
+ self.itemHeight,
+ event.container, getNextId())
+ return newWidget
configuration = {
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/label.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/label.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/label.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -36,29 +36,29 @@
# Widget set specific function that creates a single instance of a label
#
class UILabel(UIHelper):
- alignmentStyle = {'left' : win32con.SS_LEFT,
- 'center': win32con.SS_CENTER,
- 'right' : win32con.SS_RIGHT}
+ alignmentStyle = {'left' : win32con.SS_LEFT,
+ 'center': win32con.SS_CENTER,
+ 'right' : win32con.SS_RIGHT}
- def _create_widget(self, event, spacer):
- object = event.object
- if self.itemWidth == -1:
- self.itemWidth = len(str(textEncode(object.text)))*event.widgetWidth
- if self.itemHeight == -1:
- self.itemHeight = event.widgetHeight
-
- style = self.alignmentStyle[object.alignment] | win32con.WS_CHILD #|
win32con.WS_BORDER
- styleEx = 0
- newWidget = Win32Window(self._uiDriver, styleEx, 'STATIC',
textEncode(object.text), style,
- self.itemX,
- # Make sure the baseline of labels and widgets are the same
- self.itemY + 3,
- self.itemWidth,
- self.itemHeight,
- event.container)
- return newWidget
+ def _create_widget(self, event, spacer):
+ object = event.object
+ if self.itemWidth == -1:
+ self.itemWidth =
len(str(textEncode(object.text)))*event.widgetWidth
+ if self.itemHeight == -1:
+ self.itemHeight = event.widgetHeight
+ style = self.alignmentStyle[object.alignment] | win32con.WS_CHILD #|
win32con.WS_BORDER
+ styleEx = 0
+ newWidget = Win32Window(self._uiDriver, styleEx, 'STATIC',
textEncode(object.text), style,
+ self.itemX,
+ # Make sure the baseline of labels and widgets are the same
+ self.itemY + 3,
+ self.itemWidth,
+ self.itemHeight,
+ event.container)
+ return newWidget
+
configuration = {
'baseClass' : UILabel,
'provides' : 'GFLabel',
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/page.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/page.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/page.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -35,13 +35,13 @@
# Note: The event trap for changing notebook pages is attached to the UIForm
#
class UIPage(UIHelper):
- def _create_widget(self, event, spacer):
+ def _create_widget(self, event, spacer):
- object = event.object
+ object = event.object
- newWidget = self._uiForm._wrapper.createPage(object)
- self._container = newWidget
- return newWidget
+ newWidget = self._uiForm._wrapper.createPage(object)
+ self._container = newWidget
+ return newWidget
configuration = {
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/scrollbar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/scrollbar.py 2006-11-16
15:06:12 UTC (rev 9045)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/scrollbar.py 2006-11-17
09:32:00 UTC (rev 9046)
@@ -39,43 +39,43 @@
class UIScrollBar (UIHelper):
- # ---------------------------------------------------------------------------
- # Create a new scrollbar widget
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Create a new scrollbar widget
+ #
---------------------------------------------------------------------------
- def _create_widget (self, event, spacer):
+ def _create_widget (self, event, spacer):
- object = event.object
+ object = event.object
- style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.SBS_VERT | \
- win32con.SBS_LEFTALIGN
- styleEx = 0
+ style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.SBS_VERT | \
+ win32con.SBS_LEFTALIGN
+ styleEx = 0
- newWidget = self._widget = Win32Window (self._uiDriver, styleEx,
- "Scrollbar", "", style,
- self.itemX, self.itemY,
- -1, #object.Char__width*event.widgetWidth,
- object.Char__height*event.widgetHeight,
- event.container, getNextId ())
+ newWidget = self._widget = Win32Window (self._uiDriver, styleEx,
+ "Scrollbar", "", style,
+ self.itemX, self.itemY,
+ -1, #object.Char__width*event.widgetWidth,
+ object.Char__height*event.widgetHeight,
+ event.container, getNextId ())
- self._hwnd = newWidget.GetHwnd ()
+ self._hwnd = newWidget.GetHwnd ()
- return newWidget
+ return newWidget
- # ---------------------------------------------------------------------------
- # Adjust the scrollbar to reflect changed record or record-cound
- # ---------------------------------------------------------------------------
+ #
---------------------------------------------------------------------------
+ # Adjust the scrollbar to reflect changed record or record-cound
+ #
---------------------------------------------------------------------------
- def _ui_adjust_scrollbar_(self, current, size, count):
+ def _ui_adjust_scrollbar_(self, current, size, count):
- self.pageSize = size
- format = "IIiiIii"
- csize = struct.calcsize (format)
- mask = win32con.SIF_RANGE | win32con.SIF_PAGE | win32con.SIF_POS
- scrollinfo = struct.pack (format, csize, mask, 0, count - 1, size, current,
- 0)
- win32gui.SendMessage (self._hwnd, win32con.SBM_SETSCROLLINFO, 1,
scrollinfo)
+ self.pageSize = size
+ format = "IIiiIii"
+ csize = struct.calcsize (format)
+ mask = win32con.SIF_RANGE | win32con.SIF_PAGE | win32con.SIF_POS
+ scrollinfo = struct.pack (format, csize, mask, 0, count - 1, size,
current,
+ 0)
+ win32gui.SendMessage (self._hwnd, win32con.SBM_SETSCROLLINFO, 1,
scrollinfo)
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9046 - in trunk/gnue-forms/src/uidrivers/win32: . widgets widgets/form,
btami <=