[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8527 - in trunk/gnue-forms/src/uidrivers/wx26: . widgets
From: |
johannes |
Subject: |
[gnue] r8527 - in trunk/gnue-forms/src/uidrivers/wx26: . widgets |
Date: |
Thu, 6 Jul 2006 04:46:52 -0500 (CDT) |
Author: johannes
Date: 2006-07-06 04:46:51 -0500 (Thu, 06 Jul 2006)
New Revision: 8527
Modified:
trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Start of cleanup- and pep8-ifying session. Removed some unused methods
issue87 in-progress
Modified: trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py 2006-07-05 14:41:32 UTC
(rev 8526)
+++ trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py 2006-07-06 09:46:51 UTC
(rev 8527)
@@ -53,9 +53,6 @@
An implementation of the common GUI toolkit interface using wx 2.6+.
"""
- _WidgetToGFObj = {}
- _WidgetToUIObj = {}
-
_MBOX_KIND = {'info' : {'type' : wx.ICON_INFORMATION,
'buttons': wx.OK,
'title' : u_("Information")},
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-07-05
14:41:32 UTC (rev 8526)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-07-06
09:46:51 UTC (rev 8527)
@@ -20,6 +20,10 @@
# - Suite 330, Boston, MA 02111-1307, USA.
#
# $Id$
+"""
+Base classes for all UI widgets building the interface layer to the real wx
+widgets.
+"""
import wx
import os
@@ -54,6 +58,27 @@
class UIHelper (UIWidget):
"""
Implements the common behaviour of wx 2.6 widgets
+
+ @ivar label: if not None, this is the wx.StaticText instance representing
+ the label for this widget.
+ @ivar label: if not None, this is the instance of a wx.Window subclass
+ representing the control of this widget
+ @ivar growable: if True, the widget is growable in both directions (like a
+ multiline text entry). This means if the owning container gets more
+ available space this widget will consume as much as possible.
+
+ The following attributes are properly set for a positioned layout:
+
+ @ivar bouding_boxes: is a list of tuples with the bounding boxes of all the
+ widgets children. Such a tuple is made like (left, top, right, bottom,
+ gfObject of the corresponding child).
+ @ivar chr_x: zero-based x coordinate of the widget
+ @ivar chr_y: zero-based y coordinate of the widget
+ @ivar chr_w: width of the widgets in character-positions
+ @ivar chr_h: height of the widgets in character-positions
+ @ivar chr_pos: tuple of (chr_y, chr_x) defining the upper left corner
+ @ivar chr_span: tuple of (chr_h, chr_w) defining the number of rows and
+ columns the widget occupies
"""
# -------------------------------------------------------------------------
@@ -68,34 +93,37 @@
self.widget = None
self.growable = False
+ self.bounding_boxes = []
+ self.chr_w = None
+ self.chr_h = None
+ self.chr_x = None
+ self.chr_y = None
+ self.chr_pos = None
+ self.chr_span = None
+
# -------------------------------------------------------------------------
# Create a new wx widget
# -------------------------------------------------------------------------
- def createWidget (self, event, spacer):
+ def createWidget(self, event, spacer):
"""
- This function creates a new wx widget and adds it to the cross
reference
- table.
+ This function creates a new wx widget and adds it to the cross
+ reference table.
"""
self._eventHandler = event.eventHandler
- self.bounding_boxes = []
- self.prepare_for_layout(event, spacer)
+ self.__prepare_for_layout(spacer)
- newWidget = self._createWidget(event, spacer)
- if event.initialize:
- self._addToCrossRef(newWidget, self._gfObject, self)
+ return self._createWidget(event, spacer)
- return newWidget
-
# -------------------------------------------------------------------------
# Prepare a widget for the layout-manager
# -------------------------------------------------------------------------
- def prepare_for_layout(self, event, spacer):
+ def __prepare_for_layout(self, spacer):
if not self.managed:
if isinstance(self._gfObject, (GFBox, GFTabStop, GFLabel,
@@ -115,7 +143,7 @@
owner = self.getParent()
if isinstance(owner._gfObject, GFBox):
- (oleft, otop, oright, obottom) = owner.get_bounding_box()
+ (oright, obottom) = owner.get_bounding_box()[2:]
if right >= oright or bottom >= obottom or left < 0 \
or top < 0:
@@ -129,8 +157,8 @@
raise InvalidBoundingBoxError(self._gfObject, citem)
- bounds = (left, top, right, bottom, self._gfObject)
- owner.bounding_boxes.append(bounds)
+ owner.bounding_boxes.append((left, top, right, bottom,
+ self._gfObject))
# -------------------------------------------------------------------------
@@ -138,13 +166,19 @@
# -------------------------------------------------------------------------
def get_bounding_box(self):
+ """
+ Get the bounding box of the widget. For managed layouts this is always
+ None. For positioned layouts it is a tuple of character-positions
+ (left, top, right, bottom)
- if self._gfObject._form._layout.managed:
+ @returns: bounding-box as (left, top, right, bottom)
+ """
+
+ if self.managed:
return None
else:
- left, top = self.chr_x, self.chr_y
- right, bottom = self.chr_x+self.chr_w-1, self.chr_y+self.chr_h-1
- return (left, top, right, bottom)
+ return (self.chr_x, self.chr_y, self.chr_x + self.chr_w - 1,
+ self.chr_y + self.chr_h - 1)
# -------------------------------------------------------------------------
@@ -155,93 +189,26 @@
"""
Get the default size for a widget
- @returns: Size-tuple with the default size for the widget.
+ @returns: Size-tuple (width, height) representing the default size for
+ the widget
"""
return self._get_default_size_()
# -------------------------------------------------------------------------
- # Add a widget to the cross reference tables
- # -------------------------------------------------------------------------
-
- def _addToCrossRef (self, widget, gfobject, uiobject):
-
- self._uiDriver._WidgetToGFObj [widget] = gfobject
- self._uiDriver._WidgetToUIObj [widget] = uiobject
-
-
- # -------------------------------------------------------------------------
- # Remove a widget from the cross reference tables
- # -------------------------------------------------------------------------
-
- def _deleteFromCrossRef (self, widget, object):
-
- try:
- del self._uiDriver._WidgetToGFObj [widget]
- del self._uiDriver._WidgetToUIObj [widget]
-
- except:
- pass
-
-
- # -------------------------------------------------------------------------
- # Show all ui-widgets managed by this object
- # -------------------------------------------------------------------------
-
- def show (self):
- """
- Call Show () on all wx-widgets managed by this instance. This is needed
- if a row-count greater than 0 is given.
- """
-
- for widget in self.widgets:
- widget.Show ()
-
-
- # -------------------------------------------------------------------------
- # Hide all ui-widgets managed by this object
- # -------------------------------------------------------------------------
-
- def hide (self):
- """
- Call Hide () on all wx-widgets managed by this instance. This is needed
- if a row-count greater than 0 is given.
- """
-
- for widget in self.widgets:
- widget.Hide ()
-
-
- # -------------------------------------------------------------------------
- # Show widgets in a modal way
- # -------------------------------------------------------------------------
-
- def showModal (self):
-
- for widget in self.widgets:
- widget.ShowModal ()
-
- # -------------------------------------------------------------------------
- # Destroy all widgets associated with an instance
- # -------------------------------------------------------------------------
-
- def destroy (self):
-
- for widget in self.widgets:
- widget.Destroy ()
-
-
- # -------------------------------------------------------------------------
# Set the focus to a given widget
# -------------------------------------------------------------------------
def indexedFocus (self, index):
"""
- This function set's the focus to the widget specified by index.
+ Set the focus to the wx widget specified by index. For entries having
+ no rows the index will always be 0.
+
+ @param index: the index of the wx widget to set the focus to
"""
- widget = self.widgets [index]
+ widget = self.widgets[index]
if self.in_grid:
label = widget._gnue_label_
widget.Show()
@@ -250,16 +217,16 @@
if sizer:
sizer.Layout()
- current = widget.FindFocus ()
+ current = widget.FindFocus()
- if isinstance (widget, wx.ComboBox) and 'wxMac' in wx.PlatformInfo:
+ if isinstance(widget, wx.ComboBox) and 'wxMac' in wx.PlatformInfo:
item = widget._entry
else:
item = widget
# Only change the focus if necessary
if current != item:
- item.SetFocus ()
+ item.SetFocus()
# -------------------------------------------------------------------------
@@ -267,7 +234,14 @@
# -------------------------------------------------------------------------
def loseFocus (self, index):
+ """
+ Take away the focus of the wx widget with the given index. If this
+ object is used within a grid, losing the focus means hiding the entry
+ widget and displaying the label widget.
+ @param index: the index of the wx widget to kill the focus for
+ """
+
widget = self.widgets[index]
if self.in_grid:
widget.Hide()
@@ -279,7 +253,7 @@
# Set the value of a widget
# -------------------------------------------------------------------------
- def setValue (self, value, index = 0, enabled = True):
+ def setValue(self, value, index=0, enabled=True):
"""
This function sets the value of a widget and optionally enables or
disables the widget.
@@ -294,8 +268,9 @@
try:
if self._gfObject.style in ['dropdown', 'listbox']:
- if self._gfObject._field._allowedValues !=
widget._origAllowedValues:
- self._updateChoices (widget)
+ field = self._gfObject._field
+ if field._allowedValues != widget._orig_allowed_values:
+ self.update_choices (widget)
if isinstance (widget, wx.StaticText):
widget.SetLabel (value)
@@ -329,23 +304,23 @@
# ------------------------------------------------------------------------
def setCursorPosition (self, position, index = 0):
- """
- Set the cursor position to the given location inside a capable widget.
+ """
+ Set the cursor position to the given location inside a capable widget.
- @param position: new position of the insertion point
- @param index: index of the widget to be changed (if rows > 0)
- """
+ @param position: new position of the insertion point
+ @param index: index of the widget to be changed (if rows > 0)
+ """
- widget = self.widgets[index]
+ widget = self.widgets[index]
- if isinstance (widget, wx.ComboBox):
- if 'wxMac' in wx.PlatformInfo:
- widget._entry.SetInsertionPoint (position)
- else:
- widget.SetMark (position, position)
+ if isinstance (widget, wx.ComboBox):
+ if 'wxMac' in wx.PlatformInfo:
+ widget._entry.SetInsertionPoint (position)
+ else:
+ widget.SetMark (position, position)
- elif hasattr (widget, 'SetInsertionPoint'):
- widget.SetInsertionPoint (self._positionToWx (widget, position))
+ elif hasattr (widget, 'SetInsertionPoint'):
+ widget.SetInsertionPoint (self.__position_to_wx (widget, position))
# ------------------------------------------------------------------------
@@ -371,8 +346,8 @@
elif hasattr (widget, 'SetSelection'):
if isinstance (widget, wx.TextCtrl) and widget.IsMultiLine ():
- selection1 = self._positionToWx (widget, selection1)
- selection2 = self._positionToWx (widget, selection2)
+ selection1 = self.__position_to_wx (widget, selection1)
+ selection2 = self.__position_to_wx (widget, selection2)
widget.SetSelection (selection1, selection2)
@@ -390,39 +365,47 @@
sizer.AddSpacer((0, 0), 1)
return sizer
+
# -------------------------------------------------------------------------
# Update the choices of a ComboBox or a Listbox
# -------------------------------------------------------------------------
- def _updateChoices (self, widget):
+ def update_choices(self, widget):
+ """
+ Update the choices of a combo- or listbox widget with the allowed
+ values from the associated GFEntry. The values will be alphabetically
+ sorted before adding them to the wx control. A reference to the
+ original allowed values dictionary will be kept with the wx control.
+ """
- widget.Freeze ()
+ widget.Freeze()
try:
- choices = self._gfObject._field._allowedValuesReverse.keys ()
- choices.sort ()
+ choices = self._gfObject._field._allowedValuesReverse.keys()
+ choices.sort()
- widget.Clear ()
+ widget.Clear()
for dsc in choices:
- widget.Append (dsc,
self._gfObject._field._allowedValuesReverse [dsc])
+ widget.Append(dsc, \
+ self._gfObject._field._allowedValuesReverse[dsc])
- widget._origAllowedValues = self._gfObject._field._allowedValues
+ widget._orig_allowed_values = self._gfObject._field._allowedValues
finally:
- widget.Thaw ()
+ widget.Thaw()
# -------------------------------------------------------------------------
# Convert a GF-position to a wx position within a multiline edit
# -------------------------------------------------------------------------
- def _positionToWx (self, widget, position):
+ def __position_to_wx(self, widget, position):
- if len (os.linesep) < 2 or not position:
+ if len(os.linesep) < 2 or not position:
return position
- text = widget.GetValue () [:position]
- num = text.count ('\n')
+ text = widget.GetValue()[:position]
+ num = text.count('\n')
result = position + num
return result
@@ -432,17 +415,29 @@
# Convert a wx position to a GF position within a multiline edit
# -------------------------------------------------------------------------
- def _wxToPosition (self, widget, position):
+ def _wx_to_position(self, widget, position):
+ """
+ Convert a wx position within a multiline edit into a position suitable
+ for a GFEntry widget. This method treats different lineendings used by
+ the various OSes correct.
- if len (os.linesep) < 2 or not position:
+ @param widget: the wx control the convert the position for
+ @param position: the current position to be converted
+
+ @returns: the converted position usable for GFEntry intances (and their
+ displayhandler)
+ """
+
+ if len(os.linesep) < 2 or not position:
return position
- text = widget.GetValue ().replace ('\n', os.linesep) [:position]
- num = text.count (os.linesep)
- result = max (0, position - num)
+ text = widget.GetValue().replace('\n', os.linesep)[:position]
+ num = text.count(os.linesep)
+ result = max(0, position - num)
return result
+
# =========================================================================
# Virtual methods
# =========================================================================
@@ -462,4 +457,3 @@
return (-1, -1)
else:
return (self._uiDriver.cellWidth * self.chr_w, -1)
-
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-07-05
14:41:32 UTC (rev 8526)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-07-06
09:46:51 UTC (rev 8527)
@@ -142,7 +142,7 @@
csize = self.get_default_size()
result = wx.ComboBox(parent, -1, size=csize, style=wx.CB_DROPDOWN)
- self._updateChoices(result)
+ self.update_choices(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
@@ -181,7 +181,7 @@
self.growable = True
csize = self.get_default_size()
result = wx.ListBox(parent, -1, size=csize, style=wx.LB_SINGLE)
- self._updateChoices(result)
+ self.update_choices(result)
result.Bind(wx.EVT_LISTBOX, self.__on_item_selected)
result.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
@@ -425,8 +425,8 @@
(left, right) = widget.GetSelection()
if widget.IsMultiLine():
- left = self._wxToPosition(widget, left)
- right = self._wxToPosition(widget, right)
+ left = self._wx_to_position(widget, left)
+ right = self._wx_to_position(widget, right)
elif isinstance(widget, wx.ComboBox):
if 'wxMac' in wx.PlatformInfo:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8527 - in trunk/gnue-forms/src/uidrivers/wx26: . widgets,
johannes <=