commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8511 - in trunk/gnue-forms/src: . GFObjects uidrivers/_base/widg


From: johannes
Subject: [gnue] r8511 - in trunk/gnue-forms/src: . GFObjects uidrivers/_base/widgets uidrivers/wx26 uidrivers/wx26/widgets
Date: Tue, 27 Jun 2006 07:06:04 -0500 (CDT)

Author: johannes
Date: 2006-06-27 07:06:01 -0500 (Tue, 27 Jun 2006)
New Revision: 8511

Added:
   trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py
Modified:
   trunk/gnue-forms/src/GFObjects/GFEntry.py
   trunk/gnue-forms/src/GFObjects/GFVBox.py
   trunk/gnue-forms/src/GFParser.py
   trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/box.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/label.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/scrollbar.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py
Log:
More work on layout management
issue87 in-progress


Modified: trunk/gnue-forms/src/GFObjects/GFEntry.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFEntry.py   2006-06-22 19:14:39 UTC (rev 
8510)
+++ trunk/gnue-forms/src/GFObjects/GFEntry.py   2006-06-27 12:06:01 UTC (rev 
8511)
@@ -95,9 +95,14 @@
         self._field._entryList.append(self)
 
         # Have a look wether the entry will be navigable or not
-        if self.style == 'label':
+        style = self.style.lower()
+        if style == 'label':
             self.navigable = False
 
+        if not self._form._layout.managed:
+            if style == 'default' and self.Char__height > 1:
+                self.style = 'multiline'
+
         self._formatmask  = ""
         self._inputmask   = getattr(self, 'inputmask', '')
         self._displaymask = getattr(self, 'displaymask', '')

Modified: trunk/gnue-forms/src/GFObjects/GFVBox.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFVBox.py    2006-06-22 19:14:39 UTC (rev 
8510)
+++ trunk/gnue-forms/src/GFObjects/GFVBox.py    2006-06-27 12:06:01 UTC (rev 
8511)
@@ -40,11 +40,9 @@
 
     label = None
 
-
     # -------------------------------------------------------------------------
     # Constructor
     # -------------------------------------------------------------------------
 
     def __init__(self, parent=None):
         GFContainer.__init__(self, parent, "GFVBox")
-        print "BUILT a VBOX!"

Modified: trunk/gnue-forms/src/GFParser.py
===================================================================
--- trunk/gnue-forms/src/GFParser.py    2006-06-22 19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/GFParser.py    2006-06-27 12:06:01 UTC (rev 8511)
@@ -707,6 +707,7 @@
                   'dropdown': {'Label': _('Dropdown/Combo box')},
                   'listbox': {'Label': _('Listbox')},
                   'checkbox': {'Label': _('Checkbox')},
+                  'multiline': {'Label': _('Multiline-Edit')},
                   'label': {'Label': _('Label (non-editable)')} },
                'Default': 'default',
                'Description': 'The style of entry widget requested. '
@@ -769,7 +770,7 @@
                'Description': 'An optional text label that will be displayed '
                               'on the border.' },
             'block': {
-               'Required': True,
+               'Required': False,
                'Typecast': GTypecast.name,
                'References': 'block.name',
                'Description': 'The {block} to which this scrollbar scrolls.' },
@@ -791,7 +792,7 @@
                'Description': 'An optional text label that will be displayed '
                               'on the border.' },
             'block': {
-               'Required': True,
+               'Required': False,
                'Typecast': GTypecast.name,
                'References': 'block.name',
                'Description': 'The {block} to which this scrollbar scrolls.' },
@@ -872,6 +873,10 @@
                   'new': {'Label': _('New Records Only')} },
                'Typecast': GTypecast.text,
                'Default': 'Y' },
+            'label': {
+               'Required': False,
+               'Typecast': GTypecast.text,
+               'Description': 'Label displayed next or above to the image' },
             'focusorder': {
                'Typecast': GTypecast.whole,
                'Description': 'Defines what order the focus moves through '

Modified: trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py       2006-06-22 
19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py       2006-06-27 
12:06:01 UTC (rev 8511)
@@ -1,9 +1,12 @@
+# GNU Enterprise Forms - UI drivers - Base class for widgets implementation
 #
-# This file is part of GNU Enterprise.
+# Copyright 2001-2006 Free Software Foundation
 #
+# This file is part of GNU Enterprise
+#
 # GNU Enterprise is free software; you can redistribute it
 # and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Founda      tion; either
+# License as published by the Free Software Foundation; either
 # version 2, or (at your option) any later version.
 #
 # GNU Enterprise is distributed in the hope that it will be
@@ -16,150 +19,205 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2006 Free Software Foundation
-#
-# FILE:
-# UIWidget.py
-#
-# DESCRIPTION:
-# A generic class that handles most the internals of widget management in
-# gnue forms.  This should be subclassed by each of the specific driver's
-# widgets.
-#
-# NOTES:
-#
+# $Id$
 
+"""
+Base class for UIwidgets used by specific UI drivers to subclass their widgets
+from.
+"""
 
-#TODO: don't forget to cvs remove the old UIWidgets from base
-
-import string
 from gnue.common import events
-from gnue.common.apps import GDebug
 from gnue.common.definitions.GObjects import GObj
 from gnue.forms.input.GFKeyMapper import KeyMapper
 
+__all__ = ['UIWidget']
+
+# =============================================================================
+# Base class for ui widgets
+# =============================================================================
+
 class UIWidget(GObj):
-  def __init__(self, event):
-    GObj.__init__(self, parent=event.parent)
-    #
-    # set the default _type based upon the UIclass it is
-    #
-    self._type = string.split("%s" % self.__class__,'.')[-1]
+    """
+    Base class for user interface widgets.
 
-    self._inits=[self.primaryInit]
+    @ivar _gfObject: The GFObject for this UIWidget
+    @ivar widgets: Sequence of ui driver specific widgets created for this
+        UIWidget.
+    @ivar _containerToolkitWidget: If this widget can contain other widgets
+        then _containerToolkitWidget is the specific container children should
+        use (as parent)
+    @ivar managed: This boolean flag determines wether a widget is used in a
+        managed layout or in a positioned one
+    @ivar _uiDriver: the GFUserInterface instance of the current ui driver used
+        to render the form
+    @ivar _uiForm: the UIForm widget this widget is a child of
+    """
 
-    #TODO: Patented MemorySucka 2000 technology
-    self._creationEvent = event
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
 
-    self._containerToolkitWidget = None  # If this widget can contain other
-                                         # widgets then this the the toolkit
-                                         # specific container children should 
use
+    def __init__(self, event):
 
-    self._gfObject = event.object
+        GObj.__init__(self, parent=event.parent)
+        self._type = ("%s" % self.__class__).split('.')[-1]
+        self._inits = [self.__primary_init]
 
-    self.widgets = []
+        self._creationEvent = event
+        self._gfObject = event.object
+        self._containerToolkitWidget = None 
+        self._uiForm = None
+        self._uiDriver = None
 
-    #TODO: shouldn't the _gfObject checks be done in the gfObjects?
-    if not hasattr(self._gfObject,'_rows'):
-      self._gfObject._rows = 1
+        self.managed = self._gfObject._form._layout.managed
+        if self.managed:
+            self.stretch = int(getattr(self._gfObject, 'Sizer__stretch', 1))
 
-    if not hasattr(self._gfObject,'_gap'):
-      self._gfObject._gap = 0
+        self.widgets = []
 
-    if hasattr(self._gfObject,'Char__width'):
-      self.itemWidth = self._gfObject.Char__width*int(event.textWidth)
-    else:
-      self.itemWidth = -1
+        # TODO: The following assignments of itemWidth/Height as well as itemX
+        # should be either removed completely or moved to the ui drivers
+        # specific implementation.
+        if hasattr(self._gfObject, 'Char__width'):
+            self.itemWidth = self._gfObject.Char__width * int(event.textWidth)
+        else:
+            self.itemWidth = -1
 
-    if hasattr(self._gfObject,'Char__height'):
-      self.itemHeight = self._gfObject.Char__height*int(event.textHeight)
-    else:
-      self.itemHeight = -1
+        if hasattr(self._gfObject, 'Char__height'):
+            self.itemHeight = self._gfObject.Char__height*int(event.textHeight)
+        else:
+            self.itemHeight = -1
 
-    if hasattr(self._gfObject,'Char__x'):
-      self.itemX = self._gfObject.Char__x*int(event.widgetWidth)
-    else:
-      self.itemX = -1
+        if hasattr(self._gfObject, 'Char__x'):
+            self.itemX = self._gfObject.Char__x * int(event.widgetWidth)
+        else:
+            self.itemX = -1
 
-  #
-  # primaryInit
-  #
-  # The initial phased init run
-  #
-  def primaryInit(self):
-    self._uiDriver = self.findParentOfType('UIDriver')
-    self._uiForm = self.findParentOfType('UIForm')
 
-    try:
-      self._creationEvent.container = self.getParent ()._containerToolkitWidget
-    except AttributeError:
+    # -------------------------------------------------------------------------
+    # Phase 1 initialization
+    # -------------------------------------------------------------------------
 
+    def __primary_init(self):
 
-      if not hasattr(self._creationEvent, 'container'):
-        self._creationEvent.container = None
+        self._uiDriver = self.findParentOfType('UIDriver')
+        self._uiForm = self.findParentOfType('UIForm')
 
-    #print "The container will be ",self._creationEvent.container
-    if not hasattr (self._gfObject, 'hidden') or not self._gfObject.hidden:
-      for spacer in range(int(self._gfObject._rows)):
-        newWidget = self.createWidget(self._creationEvent, spacer)
-        self.widgets.append(newWidget)
+        try:
+            owner = self.getParent()
+            self._creationEvent.container = owner._containerToolkitWidget
 
-      assert gDebug (5, "WIDGETS.APPEND: %s, %s (%s)" % \
-            (self._gfObject.name, self, self.widgets))
+        except AttributeError:
+            if not hasattr(self._creationEvent, 'container'):
+                self._creationEvent.container = None
 
+        if not getattr(self._gfObject, 'hidden', False):
+            for spacer in range(int(self._gfObject._rows)):
+                widget = self.createWidget(self._creationEvent, spacer)
+                self.widgets.append(widget)
 
-  #
-  # Helper functions for descendants
-  #
-  # fire a requestXXX event
-  def _request (self, name, **params):
-    params ['_object'] = self._gfObject
-    params ['_form'] = self._gfObject._form
-    self._uiDriver.dispatchEvent (events.Event ("request%s" % name, **params))
 
-  # Handle a keyboard request for a character key
-  def _keypress (self, character):
-    if character in [chr (9), chr (10)]: # tab and enter shouldn't be ctrl keys
-      (evt, arg) = KeyMapper.getEvent (ord (character), False, False, False)
-      self._request (evt, triggerName = arg)
-    elif character < ' ':                # control key
-      (evt, arg) = KeyMapper.getEvent (ord (character) + 96, False, True, 
False)
-      self._request (evt, triggerName = arg)
-    else:
-      self._request ('KEYPRESS', text = character)
+    # -------------------------------------------------------------------------
+    # Helper functions for descendants
+    # -------------------------------------------------------------------------
 
-  # Handle a keyboard request for a function key
-  def _fkeypress (self, key, shift, ctrl, meta):
-    (evt, args) = KeyMapper.getEvent (key, shift, ctrl, meta)
-    self._request (evt, triggerName = args)
+    # -------------------------------------------------------------------------
+    # Fire a request* event
+    # -------------------------------------------------------------------------
 
+    def _request(self, name, **params):
+        """
+        Fire a request<name> event passing the GFObject and the GFObject's form
+        as additional event parameters.
 
-  #
-  # The following functions should be overridden by the widgets
-  # in the ui driver.
-  #
-  def createWidget(self, event, spacer):
-    assert gDebug(1,"UI doesn't support %s" % self.__class__)
+        @param name: name of the event, i.e. a name of 'FOO' would fire a
+            'requestFOO' event.
+        @param params: dictionary with parameters passed with the event. this
+            dictionary will always get the keys '_object' (with the GFObject of
+            this widget) and '_form' (with the GFForm of this widget) set.
+        """
 
-  def indexedFocus(self, index):
-    pass
+        params['_object'] = self._gfObject
+        params['_form'] = self._gfObject._form
 
-  def loseFocus(self):
-    pass
+        self._uiDriver.dispatchEvent(events.Event("request%s" % name, 
**params))
 
-  def showModal(self):
-    pass
 
-  def destroy(self):
-    pass
+    # -------------------------------------------------------------------------
+    # Handle a keyboard request for a character key
+    # -------------------------------------------------------------------------
 
-  def setValue(self, value, index=0, enabled=1):
-    pass
+    def _keypress(self, character):
+        """
+        Handle a keyboard request for a given character key. The Keymapper
+        get's queried for the given key. If the query returned a command it's
+        event will be fired, otherwise a requestKEYPRESS event get's fired.
 
-  def setCursorPosition(self, position, index=0):
-    pass
+        @param character: the charachter key to be handled
+        @type character: string
+        """
 
-  def setSelectedArea(self, selection1, selection2, index=0):
-    pass
+        ord_c = ord(character)
+        # Tab and Enter shouldn't be control keys
+        if character in [9, 10]:
+            (evt, arg) = KeyMapper.getEvent(ord_c, False, False, False)
+            self._request(evt, triggerName=arg)
 
+        # control key
+        elif ord_c < 32:
+            (evt, arg) = KeyMapper.getEvent(ord_c + 96, False, True, False)
+            self._request(evt, triggerName=arg)
 
+        else:
+            self._request('KEYPRESS', text=character)
+
+
+    # -------------------------------------------------------------------------
+    # Handle a keyboard request for a function key
+    # -------------------------------------------------------------------------
+
+    def _fkeypress(self, key, shift, ctrl, meta):
+        """
+        Handle a keyboard request for a given function key. The Keymapper is
+        asked for transforming the function key press into a command which will
+        be fired afterwards.
+
+        @param key: function key to be handled
+        @type key: integer
+        @param shift: state of the shift key (True is pressed, False released)
+        @param ctrl: state of the control key (True is pressed, False released)
+        @param meta: state of the meta key (True is pressed, False released)
+        """
+
+        (evt, args) = KeyMapper.getEvent(key, shift, ctrl, meta)
+        self._request(evt, triggerName = args)
+
+
+    # -------------------------------------------------------------------------
+    # Virtual methods // Descendants should override these functions
+    # -------------------------------------------------------------------------
+    # TODO: add docstrings to these methods and pep8-ify them
+
+    def createWidget(self, event, spacer):
+        assert gDebug(1,"UI doesn't support %s" % self.__class__)
+
+    def indexedFocus(self, index):
+        pass
+
+    def loseFocus(self):
+        pass
+
+    def showModal(self):
+        pass
+
+    def destroy(self):
+        pass
+
+    def setValue(self, value, index=0, enabled=1):
+        pass
+
+    def setCursorPosition(self, position, index=0):
+        pass
+
+    def setSelectedArea(self, selection1, selection2, index=0):
+        pass


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

Modified: trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py     2006-06-22 19:14:39 UTC 
(rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py     2006-06-27 12:06:01 UTC 
(rev 8511)
@@ -126,7 +126,7 @@
       # Get the height and width of a form-cell for which we use the tallest
       # control and the avarage character width of the application font
       cellHeight = max (result.values ()) + 1
-      cellWidth  = frame.GetCharWidth ()  + 1
+      cellWidth  = frame.GetCharWidth ()
 
     finally:
       frame.Destroy ()

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-06-22 
19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-06-27 
12:06:01 UTC (rev 8511)
@@ -56,6 +56,17 @@
     """
 
     # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
+
+    def __init__(self, event):
+        UIWidget.__init__(self, event)
+
+        self.label = None
+        self.widget = None
+        self.growable = False
+
+    # -------------------------------------------------------------------------
     # Create a new wx widget
     # -------------------------------------------------------------------------
 
@@ -78,12 +89,12 @@
 
 
     # -------------------------------------------------------------------------
-    # 
+    # Prepare a widget for the layout-manager
     # -------------------------------------------------------------------------
 
     def prepare_for_layout(self, event, spacer):
 
-        if not self._gfObject._form._layout.managed:
+        if not self.managed:
             if isinstance(self._gfObject, (GFBox, GFTabStop, GFLabel,
                 GFScrollBar)):
                 gap  = self._gfObject._gap + 1
@@ -133,7 +144,20 @@
             return (left, top, right, bottom)
 
 
+    # -------------------------------------------------------------------------
+    # Get the best size of a widget
+    # -------------------------------------------------------------------------
 
+    def get_default_size(self):
+        """
+        Get the default size for a widget
+
+        @returns: Size-tuple with the default size for the widget.
+        """
+
+        return self._get_default_size_()
+
+
     # -------------------------------------------------------------------------
     # Add a widget to the cross reference tables
     # -------------------------------------------------------------------------
@@ -329,7 +353,20 @@
 
             widget.SetSelection (selection1, selection2)
 
+    def add_to_vbox(self, widget, expand=True, flags=0):
+        return self.__add_to_sizer(wx.VERTICAL, widget, expand, flags)
 
+    def add_to_hbox(self, widget, expand=True, flags=0):
+        return self.__add_to_sizer(wx.HORIZONTAL, widget, expand, flags)
+
+    def __add_to_sizer(self, direction, widget, expand, flags = 0):
+        flags |= expand and wx.EXPAND or 0
+        sizer = wx.BoxSizer(direction)
+        sizer.AddSpacer((0, 0), 1)
+        sizer.Add(widget, 0, expand and wx.EXPAND or 0)
+        sizer.AddSpacer((0, 0), 1)
+        return sizer
+
     # -------------------------------------------------------------------------
     # Update the choices of a ComboBox or a Listbox
     # -------------------------------------------------------------------------
@@ -382,3 +419,24 @@
         result = max (0, position - num)
 
         return result
+
+    # =========================================================================
+    # Virtual methods
+    # =========================================================================
+
+    def _get_default_size_(self):
+        """
+        Get the default widget size.
+
+        For positioned layout the default width is the product of the
+        character-width and the avarage cellWidth. The default height is set to
+        -1, which means it will be set by the sizers.
+
+        @returns: tuple with default size
+        """
+
+        if self.managed:
+            return (-1, -1)
+        else:
+            return (self._uiDriver.cellWidth * self.chr_w, -1)
+

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/box.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/box.py  2006-06-22 19:14:39 UTC 
(rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/box.py  2006-06-27 12:06:01 UTC 
(rev 8511)
@@ -26,7 +26,9 @@
 from gnue.common.definitions import GParser
 from gnue.forms.uidrivers.wx26.widgets import _base
 
+__all__ = ['InvalidBoundingBoxError', 'UIBox']
 
+
 # =============================================================================
 # Exceptions
 # =============================================================================
@@ -48,47 +50,60 @@
 # Interface implementation for a box widget
 # =============================================================================
 
-class UIBox (_base.UIHelper):
+class UIBox(_base.UIHelper):
 
-  # ---------------------------------------------------------------------------
-  # Create a wx box widget
-  # ---------------------------------------------------------------------------
+    # -------------------------------------------------------------------------
+    # Create a wx box widget
+    # -------------------------------------------------------------------------
 
-  def _createWidget (self, event, spacer):
+    def _createWidget(self, event, spacer):
 
-    top, left = self.chr_pos
-    height, width = self.chr_span
+        top, left = self.chr_pos
+        height, width = self.chr_span
 
-    parent = event.container
+        parent = event.container
 
-    owner = self.getParent()
-    if isinstance(owner, UIBox):
-        if owner.chr_x + owner.chr_w <= left + width or \
-           owner.chr_y + owner.chr_h <= top + height:
-            raise InvalidBoundingBoxError(self, owner)
+        owner = self.getParent()
+        if isinstance(owner, UIBox):
+            if owner.chr_x + owner.chr_w <= left + width or \
+               owner.chr_y + owner.chr_h <= top + height:
+                raise InvalidBoundingBoxError(self, owner)
 
-    sizer = owner.container_sizer
-    outer = wx.BoxSizer(wx.VERTICAL)
+        sizer = owner.container_sizer
+        outer = wx.BoxSizer(wx.VERTICAL)
     
-    stb = wx.StaticBox (parent, -1, self._gfObject.label)
-    stb_sizer = wx.StaticBoxSizer(stb, wx.VERTICAL)
+        stb = wx.StaticBox (parent, -1, self._gfObject.label)
+        stb_sizer = wx.StaticBoxSizer(stb, wx.VERTICAL)
 
-    inner = wx.BoxSizer(wx.VERTICAL)
+        inner = wx.BoxSizer(wx.VERTICAL)
 
-    self.container_sizer = wx.GridBagSizer()
-    inner.Add(self.container_sizer, 1, wx.EXPAND | wx.ALL, 2)
+        self.container_sizer = wx.GridBagSizer(2, 0)
+        inner.Add(self.container_sizer, 1, wx.EXPAND | wx.ALL, 2)
 
-    stb_sizer.Add(inner, 1, wx.EXPAND)
-    outer.Add(stb_sizer, 1, wx.EXPAND | wx.ALL, 4)
+        stb_sizer.Add(inner, 1, wx.EXPAND)
+        outer.Add(stb_sizer, 1, wx.EXPAND | wx.ALL, 3)
 
-    sizer.Add(outer, self.chr_pos, self.chr_span, wx.EXPAND)
-    self._containerToolkitWidget = parent
+        sizer.Add(outer, self.chr_pos, self.chr_span, wx.EXPAND)
+        self._containerToolkitWidget = parent
 
-    return stb
+        return self.container_sizer
 
 
+    # -------------------------------------------------------------------------
+    # Add child widgets to the sizer
+    # -------------------------------------------------------------------------
 
+    def add_widgets(self, ui_widget):
 
+        if not ui_widget.growable:
+            add = self.add_to_vbox(ui_widget.widget)
+        else:
+            add = ui_widget.widget
+
+        self.container_sizer.Add(add, ui_widget.chr_pos,
+                ui_widget.chr_span, wx.EXPAND)
+
+
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py       2006-06-22 
19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py       2006-06-27 
12:06:01 UTC (rev 8511)
@@ -21,6 +21,10 @@
 #
 # $Id$
 
+"""
+Implementation of the <button> tag
+"""
+
 import wx
 
 from gnue.forms.input import GFKeyMapper
@@ -45,15 +49,14 @@
         Creates a new Button widget.
         """
 
-        newWidget = wx.Button(event.container, -1, self._gfObject.label)
-        newWidget.Bind(wx.EVT_BUTTON   , self.__on_button)
-        newWidget.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
-        newWidget.Bind(wx.EVT_CHAR     , self.__on_char)
+        self.widget = wx.Button(event.container, -1, self._gfObject.label)
+        self.widget.Bind(wx.EVT_BUTTON   , self.__on_button)
+        self.widget.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
+        self.widget.Bind(wx.EVT_CHAR     , self.__on_char)
 
-        sizer = self.getParent().container_sizer
-        sizer.Add(newWidget, self.chr_pos, self.chr_span, wx.EXPAND)
+        self.getParent().add_widgets(self)
 
-        return newWidget
+        return self.widget
 
 
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-06-22 
19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-06-27 
12:06:01 UTC (rev 8511)
@@ -21,383 +21,381 @@
 #
 # $Id$
 
+"""
+Implementation of the <entry> tag
+"""
+
 import wx
-import string
 
 from gnue.forms.uidrivers.wx26.widgets import _base
 from gnue.forms.input import GFKeyMapper
 from gnue.forms.input.GFKeyMapper import vk
-from gnue.common.apps import i18n
 
+__all__ = ['UIEntry']
 
 # =============================================================================
 # Interface class for entry widgets
 # =============================================================================
 
 class UIEntry (_base.UIHelper):
-  """
-  Interface implementation for entry widgets.
-  """
-
-  # ---------------------------------------------------------------------------
-  # Create the real wx widget
-  # ---------------------------------------------------------------------------
-
-  def _createWidget (self, event, spacer):
     """
-    Create the wx widget.
+    Interface implementation for entry widgets.
     """
 
-    self.__calculateSizes ()
-    func = getattr (self, "_build%s" % self._gfObject.style.title ())
-    
-    widget = func (event.container)
+    # -------------------------------------------------------------------------
+    # Create the real wx widget
+    # -------------------------------------------------------------------------
 
-    parent = event.container
-    sizer = self.getParent().container_sizer
+    def _createWidget (self, event, spacer):
+        """
+        Create the wx widget. The actual creation will be dispatched to a
+        method called '__build_<style>' depending on the object's style.
+        """
 
-    xFlag  = 0
-    border = 2
+        parent = event.container
 
-    if 'wxMac' in wx.PlatformInfo:
-        xFlag = wx.ALL
-    elif 'wxMSW' in wx.PlatformInfo:
-        xFlag = wx.TOP | wx.BOTTOM
-        border = 1
+        style = self._gfObject.style.lower()
+        func = getattr(self, "_UIEntry__build_%s" % style)
+        (self.label, self.widget) = func(parent)
 
-    ver = wx.BoxSizer (wx.VERTICAL)
-    ver.AddSpacer((0,0), 1)
-    ver.Add (widget, 0, wx.EXPAND | xFlag, border)
-    ver.AddSpacer((0,0), 1)
-    sizer.Add(ver, self.chr_pos, self.chr_span, wx.EXPAND)
+        self.getParent().add_widgets(self)
 
-    return widget
+        # We return the entry object here, since we will bind events to it
+        # later
+        return self.widget
 
 
-  # ---------------------------------------------------------------------------
-  # Calculate the position and size of a widget
-  # ---------------------------------------------------------------------------
+    # -------------------------------------------------------------------------
+    # Widget construction methods
+    # -------------------------------------------------------------------------
 
-  def __calculateSizes (self):
+    def __build_default(self, parent, password=False, multiline=False):
 
-      self.__lines = getattr (self._gfObject, 'Char__height', 1)
+        xFlags = wx.TE_PROCESS_TAB
 
+        if password:
+            xFlags |= wx.TE_PASSWORD
 
-  # ---------------------------------------------------------------------------
-  # Widget construction methods
-  # ---------------------------------------------------------------------------
+        if multiline:
+            self.growable = True
+            xFlags |= wx.TE_MULTILINE
 
-  def _buildDefault (self, parent, password = False):
-    """
-    """
+        csize = self.get_default_size()
 
-    xFlags = wx.TE_PROCESS_TAB
+        ctrl = wx.TextCtrl(parent, -1, size=csize, style=xFlags)
 
-    if password:
-      xFlags |= wx.TE_PASSWORD
+        ctrl.Bind(wx.EVT_CHAR, self.__on_keypress)
+        ctrl.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
 
-    if self.__lines > 1:
-      xFlags |= wx.TE_MULTILINE
+        # Currently wxMac does *not* recieve a button release event, so we
+        # don't bind it here. Instead we check the insertion point in the
+        # keypress event.
+        if not 'wxMac' in wx.PlatformInfo:
+            ctrl.Bind (wx.EVT_LEFT_UP, self.__on_left_mouseup)
 
-    if not self._gfObject._form._layout.managed:
-        size = (self._uiDriver.cellWidth * self.chr_w, -1)
-    else:
-        size = (-1, -1)
-    result = wx.TextCtrl (parent, -1, size = size, style = xFlags)
+        return [self.__add_entry_label(parent), ctrl]
 
-    result.Bind (wx.EVT_CHAR, self.__keypress)
-    result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
 
-    # Currently wxMac does *not* recieve a button release event, so we don't
-    # bind it here. Instead we check the insertion point in the keypress event
-    if not 'wxMac' in wx.PlatformInfo:
-      result.Bind (wx.EVT_LEFT_UP, self.__leftMouseUp)
+    # -------------------------------------------------------------------------
 
-    return result
+    def __build_password(self, parent):
 
+        return self.__build_default(parent, True)
 
-  # ---------------------------------------------------------------------------
+    # -------------------------------------------------------------------------
 
-  def _buildPassword (self, parent):
+    def __build_multiline(self, parent):
 
-    return self._buildDefault (parent, True)
+        return self.__build_default(parent, multiline=True)
 
+    # -------------------------------------------------------------------------
 
-  # ---------------------------------------------------------------------------
+    def __build_label(self, parent):
 
-  def _buildLabel (self, parent):
-    """
-    """
+        ctrl = wx.StaticText(parent, -1, "")
+        return [self.__add_entry_label(parent), ctrl]
 
-    return wx.StaticText (parent, -1, "")
 
+    # -------------------------------------------------------------------------
 
-  # ---------------------------------------------------------------------------
+    def __build_checkbox (self, parent):
 
-  def _buildCheckbox (self, parent):
-    """
-    """
+        result = wx.CheckBox (parent, -1, self._gfObject.label)
+        result.Bind (wx.EVT_CHECKBOX, self.__on_toggle_checkbox)
+        result.Bind (wx.EVT_CHAR, self.__on_keypress)
+        result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
 
-    result = wx.CheckBox (parent, -1, self._gfObject.label)
-    result.Bind (wx.EVT_CHECKBOX, self.__toggleCheckbox)
-    result.Bind (wx.EVT_CHAR, self.__keypress)
-    result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
+        return [None, result]
 
-    return result
 
+    # -------------------------------------------------------------------------
 
-  # ---------------------------------------------------------------------------
+    def __build_dropdown(self, parent):
 
-  def _buildDropdown (self, parent):
-    """
-    """
+        csize = self.get_default_size()
+        result = wx.ComboBox(parent, -1, size=csize, style=wx.CB_DROPDOWN)
 
-    csize = (-1, -1)
-    if not self._form._layout.managed:
-        csize = (self._uiDriver.cellWidth * self.chr_w, -1)
+        self._updateChoices(result)
 
-    result = wx.ComboBox (parent, -1, size=csize, style=wx.CB_DROPDOWN)
+        # On wxMac a Combobox is a container holding a TextCtrl and a Choice.
+        # So we have to bind Char- and Focus-Events to the textCtrl instead of
+        # the container widget.
+        if 'wxMac' in wx.PlatformInfo:
+            for child in result.GetChildren():
+                if isinstance(child, wx.TextCtrl):
+                    item = result._entry = child
+                    break
+        else:
+            item = result
 
-    self._updateChoices (result)
 
-    # On wxMac a Combobox is a container holding a TextCtrl and a Choice. So we
-    # have to bind Char- and Focus-Events to the textCtrl instead of the
-    # container widget.
-    if 'wxMac' in wx.PlatformInfo:
-      for child in result.GetChildren ():
-        if isinstance (child, wx.TextCtrl):
-          item = result._entry = child
-          break
-    else:
-      item = result
+        result.Bind(wx.EVT_COMBOBOX, self.__on_item_selected)
+        item.Bind(wx.EVT_CHAR, self.__on_keypress)
+        item.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
 
+        # On Mac we don't bind the button release event, as it does not get
+        # fired.
+        if not 'wxMac' in wx.PlatformInfo:
+            item.Bind(wx.EVT_LEFT_UP, self.__on_left_mouseup)
 
-    result.Bind (wx.EVT_COMBOBOX, self.__itemSelected)
-    item.Bind (wx.EVT_CHAR, self.__keypress)
-    item.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
+        # On MWS a ComboBox widget does not get an EVT_CHAR event for the left-
+        # and right-keys.  That's why we need to add a EVT_KEY_DOWN-handler
+        # here
+        if 'wxMSW' in wx.PlatformInfo:
+            result.Bind(wx.EVT_KEY_DOWN, self.__on_msw_keydown)
 
-    # On Mac we don't bind the button release event, as it does not get fired
-    if not 'wxMac' in wx.PlatformInfo:
-      item.Bind (wx.EVT_LEFT_UP, self.__leftMouseUp)
+        return [self.__add_entry_label(parent), result]
 
-    # On MWS a ComboBox widget does not get an EVT_CHAR event for the left- and
-    # right-keys. That's why we need to add a EVT_KEY_DOWN-handler here
-    if 'wxMSW' in wx.PlatformInfo:
-      result.Bind (wx.EVT_KEY_DOWN, self.__mswKeyDown)
 
-    return result
+    # -------------------------------------------------------------------------
 
+    def __build_listbox(self, parent):
 
-  # ---------------------------------------------------------------------------
+        self.growable = True
+        csize = self.get_default_size()
+        result = wx.ListBox(parent, -1, size=csize, style=wx.LB_SINGLE)
+        self._updateChoices(result)
 
-  def _buildListbox (self, parent):
-    """
-    """
+        result.Bind(wx.EVT_LISTBOX, self.__on_item_selected)
+        result.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
 
-    csize = (-1, -1)
-    if not self._gfObject._form._layout.managed:
-        csize = (self._uiDriver.cellWidth * self.chr_w, -1)
+        return [self.__add_entry_label(parent), result]
 
-    result = wx.ListBox (parent, -1, size=csize, style=wx.LB_SINGLE)
-    self._updateChoices (result)
 
-    result.Bind (wx.EVT_LISTBOX, self.__itemSelected)
-    result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
+    # -------------------------------------------------------------------------
 
-    return result
+    def __add_entry_label(self, parent):
 
+        if self._gfObject.label:
+            label = wx.StaticText(parent, -1, self._gfObject.label)
+        else:
+            label = None
 
-  # ---------------------------------------------------------------------------
+        return label
 
-  def __on_set_focus (self, event):
+    # -------------------------------------------------------------------------
 
-    doFocus = (self._form._currentEntry != self._gfObject)
+    def __add_to_vbox(self, widget):
 
-    # adjust the record number if necessary
-    lookup = event.GetEventObject ()
-    if 'wxMac' in wx.PlatformInfo and self._gfObject.style == 'dropdown':
-      lookup = lookup.GetParent ()
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        sizer.AddSpacer((0, 0), 1)
+        sizer.Add(widget, 0, wx.EXPAND)
+        sizer.AddSpacer((0, 0), 1)
+        return sizer
 
-    count  = self.widgets.index (lookup)
-    adjust = count - self._gfObject._visibleIndex
 
-    # Now follows a quite dirty trick. The current widget does not have an
-    # insertion point set yet, which happens after wx.EVT_SET_FOCUS is
-    # processed. Calling a requestFOCUS event sets the insertion point to the
-    # end of the display value (via beginEDIT). So the real insertion point (of
-    # a mouse click for example) always gets lost. To resolve that do all the
-    # dirty work of synchronizing the focus in GF *after* setting the initial
-    # wx-focus.
-    wx.CallAfter (self.__focusWorker, event.GetEventObject (), doFocus, adjust)
+    # -------------------------------------------------------------------------
+    # Event handler
+    # -------------------------------------------------------------------------
 
-    event.Skip ()
+    def __on_set_focus(self, event):
 
+        do_focus = (self._gfObject._form._currentEntry != self._gfObject)
 
+        # adjust the record number if necessary
+        lookup = event.GetEventObject()
+        if 'wxMac' in wx.PlatformInfo and self._gfObject.style == 'dropdown':
+            lookup = lookup.GetParent()
 
-  # ---------------------------------------------------------------------------
-  # Do the dirty work for moving the focus and adjusting the row
-  # ---------------------------------------------------------------------------
+        count  = self.widgets.index(lookup)
+        adjust = count - self._gfObject._visibleIndex
 
-  def __focusWorker (self, widget, doFocus = False, adjust = 0):
+        # Now follows a quite dirty trick.  The current widget does not have an
+        # insertion point set yet, which happens after wx.EVT_SET_FOCUS is
+        # processed.  Calling a requestFOCUS event sets the insertion point to
+        # the end of the display value (via beginEDIT).  So the real insertion
+        # point (of a mouse click for example) always gets lost.  To resolve
+        # that do all the dirty work of synchronizing the focus in GF *after*
+        # setting the initial wx-focus.
+        wx.CallAfter (self.__focus_worker, event.GetEventObject(), do_focus,
+                adjust)
 
-    # Before changing the focus in the GFForm, let's save the current insertion
-    # point for later restoring.
-    if isinstance (widget, wx.ComboBox):
-      args = widget.GetMark ()
-      restore = widget.SetMark
+        event.Skip()
 
-    elif hasattr (widget, 'GetInsertionPoint'):
-      args = (widget.GetInsertionPoint (),)
-      restore = widget.SetInsertionPoint
 
-    else:
-      restore = None
+    # -------------------------------------------------------------------------
+    # Release of the left mouse-button for textcontrols and combos
+    # -------------------------------------------------------------------------
 
-    if doFocus:
-      self._request ('FOCUS', data = self._gfObject)
+    def __on_left_mouseup(self, event):
 
-    if adjust:
-      self._request ('JUMPRECORD', data = adjust)
+        widget = event.GetEventObject()
+        event.Skip()
 
-    # Restore an insertion point (if the widget has something like that)
-    if restore is not None:
-      restore (*args)
+        wx.CallAfter(self.__update_insertion_point, widget)
 
 
-  # ---------------------------------------------------------------------------
-  # Release of the left mouse-button for textcontrols and combos
-  # ---------------------------------------------------------------------------
+    # -------------------------------------------------------------------------
+    # Toggle the state of a checkbox
+    # -------------------------------------------------------------------------
 
-  def __leftMouseUp (self, event):
+    def __on_toggle_checkbox(self, event):
 
-    widget = event.GetEventObject ()
-    event.Skip ()
+        self._request('TOGGLECHKBOX')
 
-    wx.CallAfter (self.__updateInsertionPoint, widget)
 
+    # -------------------------------------------------------------------------
+    # An item of a listbox has been selected
+    # -------------------------------------------------------------------------
 
-  # ---------------------------------------------------------------------------
-  # Make sure the insertion point or selection of a widget is in sync with GF*
-  # ---------------------------------------------------------------------------
+    def __on_item_selected(self, event):
 
-  def __updateInsertionPoint (self, widget):
+        widget = event.GetEventObject()
+        currVal = widget.GetClientData(event.GetSelection())
 
-    if isinstance (widget, wx.TextCtrl):
-      (left, right) = widget.GetSelection ()
+        if currVal != self._gfObject.getValue():
+            if self._gfObject._form._currentEntry != self._gfObject:
+                self._request('FOCUS', data=self._gfObject)
 
-      if widget.IsMultiLine ():
-        left   = self._wxToPosition (widget, left)
-        right  = self._wxToPosition (widget, right)
+            self._request('REPLACEVALUE', index=event.GetSelection(),
+                                          text=event.GetString())
 
-    elif isinstance (widget, wx.ComboBox):
-      if 'wxMac' in wx.PlatformInfo:
-        (left, right) = widget._entry.GetSelection ()
-      else:
-        (left, right) = widget.GetMark ()
-    else:
-      return
 
-    if left == right:
-      self._request ('CURSORMOVE', position = left)
+    # -------------------------------------------------------------------------
+    # Process a key-press in an entry
+    # -------------------------------------------------------------------------
 
-    else:
-      self._request ('SELECTWITHMOUSE', position1 = left, position2 = right)
+    def __on_keypress(self, event):
 
+        if 'wxMac' in wx.PlatformInfo or \
+            ('wxMSW' in wx.PlatformInfo and self._gfObject.style == 
'dropdown'):
+            self.__update_insertion_point(event.GetEventObject())
 
-  # ---------------------------------------------------------------------------
-  # Toggle the state of a checkbox
-  # ---------------------------------------------------------------------------
+        keycode = event.GetKeyCode()
+        unikey  = event.GetUnicodeKey()
 
-  def __toggleCheckbox (self, event):
+        gDebug(2, "__on_keypress: %s %s" % (keycode, unikey))
 
-    self._request ('TOGGLECHKBOX')
+        (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode,
+              event.ShiftDown(),
+              event.CmdDown(),
+              event.AltDown())
 
+        # This is a temporary workaround: since the KeyMapper encapsulates all
+        # unknown keys into a UserCommand we have no chance on Mac to enter
+        # symbols like @ or the euro-sign.
+        if 'wxMac' in wx.PlatformInfo and command == 'USERCOMMAND':
+            command = None
 
-  # ---------------------------------------------------------------------------
-  # An item of a listbox has been selected
-  # ---------------------------------------------------------------------------
+        if command:
+            gDebug(2, "--> COMMAND: %s" % command)
+            if command == 'NEWLINE':
+                self._request('KEYPRESS', text='\n')
+            else:
+                self._request(command, triggerName=args)
 
-  def __itemSelected (self, event):
+        elif unikey == keycode or unikey > 127:
+            gDebug(2, "--> _keyress: %s" % unikey)
+            self._keypress(unichr(unikey))
 
-    widget = event.GetEventObject ()
-    currVal = widget.GetClientData (event.GetSelection ())
+        else:
+            gDebug(2, "--> Skipping, running updateInsertionPoint on next 
loop")
+            event.Skip()
 
-    if currVal != self._gfObject.getValue ():
-      if self._form._currentEntry != self._gfObject:
-        self._request ('FOCUS', data = self._gfObject)
+            # If a keypress will be handled by the wx widget, make sure to keep
+            # in sync with the position and/or selection.
+            wx.CallAfter(self.__update_insertion_point, event.GetEventObject())
 
-      self._request ('REPLACEVALUE', index = event.GetSelection (),
-                                     text = event.GetString ())
 
+    # -------------------------------------------------------------------------
+    # Key-Down-Eventtrap for wx.MSW's ComboBox widgets
+    # -------------------------------------------------------------------------
 
-  # ---------------------------------------------------------------------------
-  # Process a key-press in an entry
-  # ---------------------------------------------------------------------------
+    def __on_msw_keydown(self, event):
 
-  def __keypress (self, event):
+        keycode = event.GetKeyCode()
+        command = None
 
-    if 'wxMac' in wx.PlatformInfo or \
-        ('wxMSW' in wx.PlatformInfo and self._gfObject.style == 'dropdown'):
-      self.__updateInsertionPoint (event.GetEventObject ())
+        if keycode in [wx.WXK_LEFT, wx.WXK_RIGHT]:
+            (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode,
+                    event.ShiftDown(),
+                    event.CmdDown(),
+                    event.AltDown())
 
-    keycode = event.GetKeyCode ()
-    unikey  = event.GetUnicodeKey ()
+        if command:
+            self._request(command, triggerName=args)
+        else:
+            event.Skip()
 
-    gDebug (2, "__keypress: %s %s" % (keycode, unikey))
 
-    (command, args) = GFKeyMapper.KeyMapper.getEvent (keycode,
-          event.ShiftDown (),
-          event.CmdDown (),
-          event.AltDown ())
+    # -------------------------------------------------------------------------
+    # Do the dirty work for moving the focus and adjusting the row
+    # -------------------------------------------------------------------------
 
-    # This is a temporary workaround: since the KeyMapper encapsulates all
-    # unknown keys into a UserCommand we have no chance on Mac to enter
-    # symbols like @ or the euro-sign.
-    if 'wxMac' in wx.PlatformInfo and command == 'USERCOMMAND':
-      command = None
+    def __focus_worker(self, widget, do_focus=False, adjust=0):
 
-    if command:
-      gDebug (2, "--> COMMAND: %s" % command)
-      if command == 'NEWLINE':
-        self._request ('KEYPRESS', text = '\n')
-      else:
-        self._request (command, triggerName = args)
+        # Before changing the focus in the GFForm, let's save the current
+        # insertion point for later restoring.
+        if isinstance(widget, wx.ComboBox):
+            args = widget.GetMark()
+            restore = widget.SetMark
 
-    elif unikey == keycode or unikey > 127:
-      gDebug (2, "--> _keyress: %s" % unikey)
-      self._keypress (unichr (unikey))
+        elif hasattr(widget, 'GetInsertionPoint'):
+            args = (widget.GetInsertionPoint(),)
+            restore = widget.SetInsertionPoint
 
-    else:
-      gDebug (2, "--> Skipping, running updateInsertionPoint on next loop")
-      event.Skip ()
+        else:
+            restore = None
 
-      # If a keypress will be handled by the wx widget, make sure to keep in
-      # sync with the position and/or selection
-      wx.CallAfter (self.__updateInsertionPoint, event.GetEventObject ())
+        if do_focus:
+            self._request('FOCUS', data=self._gfObject)
 
+        if adjust:
+            self._request('JUMPRECORD', data=adjust)
 
-  # ---------------------------------------------------------------------------
-  # Key-Down-Eventtrap for wx.MSW's ComboBox widgets
-  # ---------------------------------------------------------------------------
+        # Restore an insertion point (if the widget has something like that)
+        if restore is not None:
+            restore(*args)
 
-  def __mswKeyDown (self, event):
 
-    keycode = event.GetKeyCode ()
-    unikey  = event.GetUnicodeKey ()
-    command = None
+    # -------------------------------------------------------------------------
+    # Make sure the insertion point or selection of a widget is in sync with 
GF*
+    # -------------------------------------------------------------------------
 
-    if keycode in [wx.WXK_LEFT, wx.WXK_RIGHT]:
-      (command, args) = GFKeyMapper.KeyMapper.getEvent (keycode,
-          event.ShiftDown (),
-          event.CmdDown (),
-          event.AltDown ())
+    def __update_insertion_point(self, widget):
 
-    if command:
-      self._request (command, triggerName = args)
-    else:
-      event.Skip ()
+        if isinstance(widget, wx.TextCtrl):
+            (left, right) = widget.GetSelection()
 
+            if widget.IsMultiLine():
+                left  = self._wxToPosition(widget, left)
+                right = self._wxToPosition(widget, right)
 
+        elif isinstance(widget, wx.ComboBox):
+            if 'wxMac' in wx.PlatformInfo:
+                (left, right) = widget._entry.GetSelection()
+            else:
+                (left, right) = widget.GetMark()
+        else:
+            return
+
+        if left == right:
+            self._request('CURSORMOVE', position=left)
+
+        else:
+            self._request('SELECTWITHMOUSE', position1=left, position2=right)
+
+
 # =============================================================================
 # Configuration
 # =============================================================================
@@ -427,4 +425,4 @@
     vk.ENTER  : wx.WXK_RETURN,    vk.BACKSPACE : wx.WXK_BACK,
     vk.RETURN : wx.WXK_RETURN}
 
-GFKeyMapper.KeyMapper.setUIKeyMap (wxKeyTranslations)
+GFKeyMapper.KeyMapper.setUIKeyMap(wxKeyTranslations)

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py 2006-06-22 19:14:39 UTC 
(rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py 2006-06-27 12:06:01 UTC 
(rev 8511)
@@ -81,12 +81,6 @@
         else:
             self.main_window = wx.Dialog (None, -1)
 
-        # Do we have boxes
-        if self._form.findChildOfType ('GFVBox', True, True):
-            self.boxed = True
-        else:
-            self.boxed = False
-
         self.main_window.SetTitle (self._form.title)
         self.main_window.SetIcons (self.__loadIcons ())
         self.main_window.Bind (wx.EVT_CLOSE, self.__closeTrap, 
self.main_window)
@@ -301,7 +295,11 @@
       @param gfPage: GFPage instance to create a page widget for
       """
 
-      pg_sizer = wx.GridBagSizer()
+      if self._gfObject._layout.managed:
+          pg_sizer = wx.BoxSizer(wx.VERTICAL)
+      else:
+          pg_sizer = wx.GridBagSizer(2, 0)
+
       pg_panel = wx.Panel(self.page_container, -1)
       pg_panel.SetSizer(pg_sizer)
 

Added: trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py 2006-06-22 19:14:39 UTC 
(rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py 2006-06-27 12:06:01 UTC 
(rev 8511)
@@ -0,0 +1,115 @@
+# GNU Enterprise Forms - wx 2.6 UI Driver - Box widget
+#
+# Copyright 2001-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import wx
+
+from gnue.forms.uidrivers.wx26.widgets import _base, button
+
+
+# =============================================================================
+# Interface implementation for a box widget
+# =============================================================================
+
+class UIHBox (_base.UIHelper):
+
+    # -------------------------------------------------------------------------
+    # Create a wx box widget
+    # -------------------------------------------------------------------------
+
+    def _createWidget (self, event, spacer):
+
+        parent = event.container
+        owner  = self.getParent()
+        sizer  = owner.container_sizer
+
+        outer = wx.BoxSizer(wx.VERTICAL)
+
+        if self._gfObject.label:
+            stb = wx.StaticBox(parent, -1, self._gfObject.label)
+            stb_sizer = wx.StaticBoxSizer(stb, wx.VERTICAL)
+
+            outer.Add(stb_sizer, 1, wx.EXPAND | wx.ALL, 4)
+            next = stb_sizer
+        else:
+            next = outer
+      
+        self.container_sizer = wx.GridBagSizer (2, 2)
+        self.container_sizer.AddGrowableRow(1)
+        next.Add(self.container_sizer, 1, wx.EXPAND | wx.ALL, 2)
+
+        self._containerToolkitWidget = event.container
+        self.__current_col = 0
+
+        self.widget = outer
+        owner.add_widgets(self)
+
+        return self.container_sizer
+
+    # -------------------------------------------------------------------------
+    # Add new widgets for a givin UI* instance to the HBox container
+    # -------------------------------------------------------------------------
+
+    def add_widgets(self, ui_widget):
+
+        pos = (0, self.__current_col)
+        span = (1, 1)
+        add = 0
+        span_control = False
+
+        if ui_widget.label:
+            add = 1
+            self.container_sizer.Add(ui_widget.label, pos, span, wx.EXPAND)
+
+        if ui_widget.widget:
+            add = 1
+            if span_control and not ui_widget.label:
+                pos = (0, self.__current_col)
+                span = (2, 1)
+            else:
+                pos = (1, self.__current_col)
+                span = (1, 1)
+
+            item = ui_widget.widget
+            if isinstance(ui_widget, button.UIButton):
+                item = self.add_to_hbox(item)
+            elif not ui_widget.growable:
+                item = self.add_to_vbox(item)
+
+            self.container_sizer.Add(item, pos, span, wx.EXPAND)
+
+        if add:
+            self.container_sizer.AddGrowableCol(self.__current_col,
+                    ui_widget.stretch)
+
+        self.__current_col += add
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+  'baseClass': UIHBox,
+  'provides' : 'GFHBox',
+  'container': 0
+}


Property changes on: trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Id

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py        2006-06-22 
19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py        2006-06-27 
12:06:01 UTC (rev 8511)
@@ -29,97 +29,129 @@
 except:
   PILImage = None
 
+from gnue.common.definitions import GParser
 from gnue.forms.uidrivers.wx26.widgets import _base
 
 # =============================================================================
+# Exceptions
+# =============================================================================
+
+class MissingSizeError(GParser.MarkupError):
+    """ Image has no size given """
+    def __init__(self, image):
+        msg = u_("Image '%(name)s' is missing one of Sizer:width or "
+                 "Sizer:height") % {'name': image.name}
+        GParser.MarkupError.__init__(self, msg, image._url, image._lineNumber)
+
+
+# =============================================================================
 # Wrap an UI layer around a wx image
 # =============================================================================
 
 class UIImage (_base.UIHelper):
-  """
-  Creates a single instance of an image.
-  """
-
-  # --------------------------------------------------------------------------
-  # Create an image widget
-  # --------------------------------------------------------------------------
-
-  def _createWidget (self, event, spacer):
     """
-    Creates a new StaticBitmap widget.
+    Creates a single instance of an image.
     """
 
-    parent = event.container
-    sizer  = self.getParent().container_sizer
+    # ------------------------------------------------------------------------
+    # Create an image widget
+    # ------------------------------------------------------------------------
 
-    csize = (-1, -1)
-    if not self._gfObject._form._layout.managed:
-        csize = (self._uiDriver.cellWidth * self.chr_w, -1)
+    def _createWidget (self, event, spacer):
+        """
+        Creates a new StaticBitmap widget.
+        """
 
-    self.imagePanel = wx.ScrolledWindow (parent, -1, size=csize)
-    
-    newWidget = wx.StaticBitmap (self.imagePanel, -1, wx.NullBitmap)
-    sizer.Add(self.imagePanel, self.chr_pos, self.chr_span, wx.EXPAND)
+        parent = event.container
 
-    return newWidget
+        self.image_size = self.get_default_size()
+        self.widget = wx.ScrolledWindow(parent, -1, size=self.image_size)
 
+        sw_sizer = wx.BoxSizer(wx.VERTICAL)
+        self.widget.SetSizer(sw_sizer)
 
-  # --------------------------------------------------------------------------
-  # Set the widget's PIL
-  # --------------------------------------------------------------------------
+        if self.managed:
+            bmp = wx.StaticBitmap(self.widget, -1, wx.NullBitmap,
+                    size=self.image_size)
+        else:
+            bmp = wx.StaticBitmap(self.widget, -1, wx.NullBitmap)
 
-  def setValue (self, value, index = 0, enabled = True):
-    """
-    Loads an image.
-    """
+        sw_sizer.Add(bmp, 1, wx.EXPAND)
 
-    if PILImage is None:
-      return
+        self.getParent().add_widgets(self)
 
-    widget = self.widgets [index]
+        return bmp
 
-    scrx, scry = self.imagePanel.GetClientSizeTuple ()
-    imgx, imgy = value.size
 
-    self.imagePanel.SetVirtualSize ((imgx, imgy))
+    # -------------------------------------------------------------------------
+    # Get the default size for the image
+    # -------------------------------------------------------------------------
 
-    scalex = scaley = 1
+    def _get_default_size_(self):
 
-    fit = self._gfObject.fit
+        if self.managed:
+            width = int(getattr(self._gfObject, 'Sizer__width', -1))
+            height = int(getattr(self._gfObject, 'Sizer__height', -1))
+            if width == -1 or height == -1:
+                raise MissingSizeError(self._gfObject)
+        else:
+            width = self._uiDriver.cellWidth * self.chr_w
+            height = self._uiDriver.cellHeight * self.chr_h
 
-    if fit == "auto":
-      if float (scrx) / imgx < float (scry) / imgy:
-        fit = "width"
-      else:
-        fit = "height"
+        return (width, height)
 
-    if fit == "width":
-      scalex = scaley = float (scrx) / imgx
 
-    elif fit == "height":
-      scalex = scaley = float (scry) / imgy
+    # ------------------------------------------------------------------------
+    # Set the widget's PIL
+    # ------------------------------------------------------------------------
 
-    elif fit == "both":
-      scalex = float (scrx) / imgx
-      scaley = float (scry) / imgy
-    else:
-      self.imagePanel.SetScrollRate (10, 10)
+    def setValue (self, value, index = 0, enabled = True):
+        """
+        Loads an image.
+        """
 
-    if scalex != 1 or scaley != 1:
-      value = value.resize ((abs (int (imgx * scalex)),
-        abs (int (imgy * scaley))), PILImage.BICUBIC)
+        if PILImage is None:
+          return
 
-    # Convert the PIL Image to a wxBitmap
-    wxImg = wx.EmptyImage (value.size [0], value.size [1])
-    wxImg.SetData (value.convert ("RGB").tostring ())
-    image = wxImg.ConvertToBitmap ()
+        widget = self.widgets [index]
+        scrx, scry = self.image_size
+        imgx, imgy = value.size
 
-    widget.SetSize (wx.Size (image.GetWidth (), image.GetHeight ()))
-    widget.SetBitmap (image)
+        scalex = scaley = 1
 
-    widget.Refresh ()
+        fit = self._gfObject.fit
 
+        if fit == "auto":
+          if float (scrx) / imgx < float (scry) / imgy:
+            fit = "width"
+          else:
+            fit = "height"
 
+        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
+        else:
+          self.widget.SetScrollRate (10, 10)
+
+        if scalex != 1 or scaley != 1:
+          value = value.resize ((abs (int (imgx * scalex)),
+            abs (int (imgy * scaley))), PILImage.BICUBIC)
+
+        # Convert the PIL Image to a wxBitmap
+        wxImg = wx.EmptyImage(value.size[0], value.size[1])
+        wxImg.SetData(value.convert("RGB").tostring())
+        image = wxImg.ConvertToBitmap()
+
+        widget.SetBitmap(image)
+        widget.Refresh()
+
+
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/label.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/label.py        2006-06-22 
19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/label.py        2006-06-27 
12:06:01 UTC (rev 8511)
@@ -45,16 +45,13 @@
     flags = self._ALIGNMENT [self._gfObject.alignment] | wx.ST_NO_AUTORESIZE
 
     parent = event.container
-    sizer  = self.getParent().container_sizer
+    self.widget = wx.StaticText(parent, -1, self._gfObject.text, style=flags)
 
-    newWidget = wx.StaticText (parent, -1, self._gfObject.text, style=flags)
+    self.getParent().add_widgets(self)
 
-    sizer.Add(newWidget, self.chr_pos, self.chr_span,
-          self._ALIGNMENT[self._gfObject.alignment] | wx.ALIGN_CENTER_VERTICAL)
+    return self.widget
 
-    return newWidget
 
-
 # =============================================================================
 # Configuration
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py 2006-06-22 19:14:39 UTC 
(rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py 2006-06-27 12:06:01 UTC 
(rev 8511)
@@ -28,20 +28,39 @@
 # Interface implementation of a page
 # =============================================================================
 
-class UIPage (_base.UIHelper):
-  
-  # ---------------------------------------------------------------------------
-  # Create a new page widget
-  # ---------------------------------------------------------------------------
+class UIPage(_base.UIHelper):
 
-  def _createWidget (self, event, spacer):
+    # -------------------------------------------------------------------------
+    # Create a new page widget
+    # -------------------------------------------------------------------------
 
-    self._pageIndex = event.container.pageCount ()
-    self._containerToolkitWidget = event.container.createPage (self._gfObject)
-    self.container_sizer = self._containerToolkitWidget.GetSizer()
-    return self._containerToolkitWidget
+    def _createWidget(self, event, spacer):
 
+        self._pageIndex = event.container.pageCount()
+        self._containerToolkitWidget = \
+                event.container.createPage(self._gfObject)
+        self.container_sizer = self._containerToolkitWidget.GetSizer()
 
+        return self._containerToolkitWidget
+
+
+    # -------------------------------------------------------------------------
+    # Add widgets to the page
+    # -------------------------------------------------------------------------
+
+    def add_widgets(self, ui_widget):
+
+        if self.managed:
+            self.container_sizer.Add(ui_widget.widget, 1, wx.EXPAND)
+        else:
+            if ui_widget.growable:
+                add = self.add_to_vbox(ui_widget.widget)
+            else:
+                add = ui_widget.widget
+            self.container_sizer.Add(add, ui_widget.chr_pos,
+                    ui_widget.chr_span, wx.EXPAND)
+
+
 # =============================================================================
 # Configuration data
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/scrollbar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/scrollbar.py    2006-06-22 
19:14:39 UTC (rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/scrollbar.py    2006-06-27 
12:06:01 UTC (rev 8511)
@@ -38,33 +38,33 @@
   def _createWidget (self, event, spacer):
 
       parent = event.container
-      sizer = self.getParent().container_sizer
 
-      newWidget = self.widget = wx.ScrollBar (parent, -1, style=wx.SB_VERTICAL)
-      sizer.Add(newWidget, self.chr_pos, self.chr_span, wx.EXPAND)
+      self.widget = wx.ScrollBar(parent, -1, style=wx.SB_VERTICAL)
+      self.getParent().add_widgets(self)
 
       (crec, recs, self.pageSize) = self._gfObject.get_record_and_page_count()
-      wx.EVT_COMMAND_SCROLL (newWidget, newWidget.GetId (), self.__scrollEvent)
+      wx.EVT_COMMAND_SCROLL(self.widget, self.widget.GetId(),
+              self.__on_scroll)
       self.do_adjust_scrollbar (crec, recs)
 
-      return newWidget
+      return self.widget
 
 
   # ---------------------------------------------------------------------------
   # adjust the scrollbar to a new position
   # ---------------------------------------------------------------------------
 
-  def do_adjust_scrollbar (self, position, count):
+  def do_adjust_scrollbar(self, position, count):
 
-    self.widget.SetScrollbar (position, self.pageSize, count,
-        self.pageSize - 1, True)
+    self.widget.SetScrollbar(position, self.pageSize, count,
+        self.pageSize-1, True)
 
 
   # ---------------------------------------------------------------------------
   # Handle changes of the adjustment's value
   # ---------------------------------------------------------------------------
 
-  def __scrollEvent (self, event):
+  def __on_scroll(self, event):
 
     self._gfObject._event_scrollToRecord (event.GetPosition ())
     event.Skip ()

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py 2006-06-22 19:14:39 UTC 
(rev 8510)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py 2006-06-27 12:06:01 UTC 
(rev 8511)
@@ -23,7 +23,7 @@
 
 import wx
 
-from gnue.forms.uidrivers.wx26.widgets import _base
+from gnue.forms.uidrivers.wx26.widgets import _base, hbox, entry, button
 
 
 # =============================================================================
@@ -32,26 +32,85 @@
 
 class UIVBox (_base.UIHelper):
 
-  # ---------------------------------------------------------------------------
-  # Create a wx box widget
-  # ---------------------------------------------------------------------------
+    # -------------------------------------------------------------------------
+    # Create a wx box widget
+    # -------------------------------------------------------------------------
 
-  def _createWidget (self, event, spacer):
+    def _createWidget (self, event, spacer):
 
-      parent = self.getParent()
-      if parent._type == 'UIPage':
-          pSizer = parent.pageSizer
-      else:
-          pSizer = parent.sizer
+        parent = event.container
+        owner  = self.getParent()
+        sizer  = owner.container_sizer
+
+        outer = wx.BoxSizer(wx.VERTICAL)
+
+        if self._gfObject.label:
+            stb = wx.StaticBox(parent, -1, self._gfObject.label)
+            stb_sizer = wx.StaticBoxSizer(stb, wx.VERTICAL)
+
+            outer.Add(stb_sizer, 1, wx.EXPAND | wx.ALL, 4)
+            next = stb_sizer
+        else:
+            next = outer
       
-      self.sizer = wx.BoxSizer (wx.VERTICAL)
-      self._containerToolkitWidget = event.container
-      pSizer.Add(self.sizer, 1, wx.EXPAND)
+        self.container_sizer = wx.GridBagSizer (2, 2)
+        self.container_sizer.AddGrowableCol(1)
+        next.Add(self.container_sizer, 1, wx.EXPAND | wx.ALL, 2)
 
-      return self.sizer
+        self._containerToolkitWidget = event.container
+        self.__current_row = 0
 
+        self.widget = outer
+        owner.add_widgets(self)
 
+        return self.container_sizer
 
+
+    # -------------------------------------------------------------------------
+    # Add an UI widget to the VBox container
+    # -------------------------------------------------------------------------
+
+    def add_widgets(self, ui_widget):
+
+        pos = (self.__current_row, 0)
+        span = (1, 1)
+        add = 0
+
+        span_control = isinstance(ui_widget, (UIVBox, hbox.UIHBox)) or \
+                isinstance (ui_widget.widget, wx.CheckBox)
+
+        if ui_widget.label:
+            add = 1
+            if not ui_widget.growable:
+                item = self.add_to_vbox(ui_widget.label)
+            else:
+                item = ui_widget.label
+            self.container_sizer.Add(item, pos, span, wx.EXPAND)
+
+        if ui_widget.widget:
+            add = 1
+            if isinstance(ui_widget, button.UIButton):
+                item = self.add_to_hbox(ui_widget.widget)
+                item = ui_widget.widget
+            else:
+                item = ui_widget.widget
+
+            if span_control and not ui_widget.label:
+                pos = (self.__current_row, 0)
+                span = (1, 2)
+            else:
+                pos = (self.__current_row, 1)
+                span = (1, 1)
+
+            self.container_sizer.Add(item, pos, span, wx.EXPAND)
+
+        if add:
+            if ui_widget.growable:
+                self.container_sizer.AddGrowableRow(self.__current_row,
+                        ui_widget.stretch)
+
+        self.__current_row += add
+
 # =============================================================================
 # Configuration data
 # =============================================================================





reply via email to

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