[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8542 - in trunk/gnue-forms/src: GFObjects uidrivers/_base/widget
From: |
johannes |
Subject: |
[gnue] r8542 - in trunk/gnue-forms/src: GFObjects uidrivers/_base/widgets uidrivers/wx26/widgets |
Date: |
Fri, 28 Jul 2006 12:29:50 -0500 (CDT) |
Author: johannes
Date: 2006-07-28 12:29:49 -0500 (Fri, 28 Jul 2006)
New Revision: 8542
Modified:
trunk/gnue-forms/src/GFObjects/GFBlock.py
trunk/gnue-forms/src/GFObjects/GFButton.py
trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.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/grid.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/gridline.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py
Log:
Fixed buttons in multi-row-blocks (issue6), improved usage of sizers.
Added support of checkboxes and buttons to the grid control
issue6 testing
issue89 in-progress
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-07-25 13:24:07 UTC (rev
8541)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-07-28 17:29:49 UTC (rev
8542)
@@ -715,6 +715,14 @@
self._form.updateUIEntry (field)
+ # Ok, don't forgett the buttons here. Since they might be used within a
+ # block as well but don't have a corresponding field we need a seperate
+ # iteration.
+ for entry in self._entryList:
+ if entry._type == 'GFButton':
+ entry.recalculate_visible (adjustment, self._currentRecord,
+ self._recordCount)
+
self._form.refreshUIEvents ()
# Adjusting scrollbars
Modified: trunk/gnue-forms/src/GFObjects/GFButton.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFButton.py 2006-07-25 13:24:07 UTC (rev
8541)
+++ trunk/gnue-forms/src/GFObjects/GFButton.py 2006-07-28 17:29:49 UTC (rev
8542)
@@ -68,9 +68,15 @@
self._block = self.get_block()
if self._block:
- self._rows = getattr(self._block, 'rows', self._rows)
- self._gap = getattr(self._block, 'rowSpacer', self._gap)
+ self._block._entryList.append(self)
+ grid = self.findParentOfType('GFGrid')
+ if grid:
+ self._rows = int(getattr(grid, 'rows', 1))
+ else:
+ self._rows = getattr(self._block, 'rows', self._rows)
+ self._gap = getattr(self._block, 'rowSpacer', self._gap)
+
self._rows = getattr(self, 'rows', self._rows)
self._gap = getattr(self, 'rowSpacer', self._gap)
Modified: trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py 2006-07-25
13:24:07 UTC (rev 8541)
+++ trunk/gnue-forms/src/uidrivers/_base/widgets/_base.py 2006-07-28
17:29:49 UTC (rev 8542)
@@ -73,6 +73,12 @@
self.managed = self._gfObject._form._layout.managed
if self.managed:
self.stretch = int(getattr(self._gfObject, 'Sizer__stretch', 1))
+ self.min_width = int(getattr(self._gfObject, 'Sizer__minwidth', 0))
+ self.min_height = int(getattr(self._gfObject, 'Sizer__minheight',
+ 0))
+ self.max_width = int(getattr(self._gfObject, 'Sizer__maxwidth', 0))
+ self.max_height = int(getattr(self._gfObject, 'Sizer__maxheight',
+ 0))
self.in_grid = self.findParentOfType('UIGrid') is not None
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-07-25
13:24:07 UTC (rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-07-28
17:29:49 UTC (rev 8542)
@@ -82,6 +82,8 @@
columns the widget occupies
"""
+ growable = False
+
# -------------------------------------------------------------------------
# Constructor
# -------------------------------------------------------------------------
@@ -92,7 +94,6 @@
self.label = None
self.widget = None
- self.growable = False
self.bounding_boxes = []
self.chr_w = None
@@ -193,7 +194,29 @@
return self._get_default_size_()
+ # -------------------------------------------------------------------------
+ # Get the size hints (minimum and maximum size) of a widget
+ # -------------------------------------------------------------------------
+ def get_size_hints(self):
+ """
+ Get the SizeHints - minimum and maximum size - for a widget.
+
+ @returns: tuple of wx.Size instances representing the minimum and
+ maximum size
+ """
+
+ if not self.managed:
+ return (wx.DefaultSize, wx.DefaultSize)
+ else:
+ cellw, cellh = self._uiDriver.cellWidth, self._uiDriver.cellHeight
+ mins = wx.Size((self.min_width * cellw) or -1,
+ (self.min_height * cellh) or -1)
+ maxs = wx.Size((self.max_width * cellw) or -1,
+ (self.max_height * cellh) or -1)
+ return (mins, maxs)
+
+
# -------------------------------------------------------------------------
# Set the focus to a given widget
# -------------------------------------------------------------------------
@@ -207,7 +230,7 @@
"""
widget = self.widgets[index]
- if self.in_grid:
+ if self.in_grid and widget._gnue_label_:
label = widget._gnue_label_
widget.Show()
label.Hide()
@@ -241,7 +264,7 @@
"""
widget = self.widgets[index]
- if self.in_grid:
+ if self.in_grid and widget._gnue_label_:
widget.Hide()
widget._gnue_label_.Show()
widget.GetContainingSizer().Layout()
@@ -290,8 +313,11 @@
widget.Enable (enabled)
finally:
- if self.in_grid:
- widget._gnue_label_.SetLabel(value)
+ if self.in_grid and widget._gnue_label_:
+ if isinstance(widget._gnue_label_, wx.StaticText):
+ widget._gnue_label_.SetLabel("%s" % value)
+ else:
+ widget._gnue_label_.SetValue(value)
widget.SetEvtHandlerEnabled (True)
widget.Refresh ()
@@ -562,6 +588,7 @@
_vertical_ = True
last_item = 0
_entry_pos = 0
+ growable = True
# -------------------------------------------------------------------------
# Create the box widget
@@ -586,6 +613,11 @@
panel = wx.Panel(parent, -1)
panel.SetSizer(wx.BoxSizer(wx.VERTICAL))
+ # If the has a block assigned we can bind the mouse wheel event to
+ # scroll through the block's records.
+ if self._gfObject.get_block() is not None:
+ panel.Bind(wx.EVT_MOUSEWHEEL, self.__on_mousewheel)
+
self._container = wx.Panel(panel, -1)
self._entry_pos = self.__use_second_one() and 2 or 1
@@ -630,3 +662,19 @@
break
return result
+
+ # -------------------------------------------------------------------------
+ # Event-Handler
+ # -------------------------------------------------------------------------
+
+ def __on_mousewheel(self, event):
+
+ forward = event.GetWheelRotation() < 0
+ block = self._gfObject.get_block()
+
+ if self._form._currentBlock != block:
+ # FIXME: this does not look like a good solution, does it?
+ self._request('FOCUS', data=block._entryList[0])
+ return
+
+ self._request(['PREVRECORD', 'NEXTRECORD'][forward])
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py 2006-07-25
13:24:07 UTC (rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py 2006-07-28
17:29:49 UTC (rev 8542)
@@ -50,13 +50,23 @@
Creates a new Button widget.
"""
- self.widget = wx.Button(event.container, -1, self._gfObject.label)
+ owner = self.getParent()
+
+ if self.in_grid:
+ parent = owner._get_cell(self, spacer)
+ else:
+ parent = event.container
+
+ self.widget = wx.Button(parent, -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)
- self.getParent().add_widgets(self, spacer)
+ if self.in_grid:
+ self.widget._gnue_label_ = None
+ owner.add_widgets(self, spacer)
+
return self.widget
@@ -93,9 +103,16 @@
def __on_set_focus (self, event):
+ lookup = event.GetEventObject()
+ count = self.widgets.index(lookup)
+ adjust = count - self._gfObject._visibleIndex
+
if self._form._currentEntry != self._gfObject:
self._request('FOCUS', data=self._gfObject)
+ if adjust:
+ self._request('JUMPRECORD', data=adjust)
+
event.Skip()
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-07-25
13:24:07 UTC (rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-07-28
17:29:49 UTC (rev 8542)
@@ -62,6 +62,13 @@
func = getattr(self, "_UIEntry__build_%s" % style)
(self.label, self.widget) = func(parent)
+ (mins, maxs) = self.get_size_hints()
+ if (mins != wx.DefaultSize):
+ self.widget.SetMinSize(mins)
+ if (maxs != wx.DefaultSize):
+ self.widget.SetMaxSize(maxs)
+
+
owner.add_widgets(self, spacer)
if self.in_grid:
@@ -88,9 +95,8 @@
xFlags |= wx.TE_MULTILINE
# TODO: should we use the container_sizer.GetEmptyCellSize() for
- # setting a minimal control size
+ # setting a minimal control size ?
csize = self.get_default_size()
-
ctrl = wx.TextCtrl(parent, -1, size=csize, style=xFlags)
ctrl.Bind(wx.EVT_CHAR, self.__on_keypress)
@@ -132,9 +138,11 @@
result.Bind (wx.EVT_CHAR, self.__on_keypress)
result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
- return [None, result]
+ label = None
+ return [label, result]
+
# -------------------------------------------------------------------------
def __build_dropdown(self, parent):
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/grid.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/grid.py 2006-07-25 13:24:07 UTC
(rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/grid.py 2006-07-28 17:29:49 UTC
(rev 8542)
@@ -20,38 +20,66 @@
# - Suite 330, Boston, MA 02111-1307, USA.
#
# $Id$
+"""
+Implementation of a <grid>. A grid is a grid control made of multiple
+<gridlines>.
+"""
import wx
from gnue.forms.uidrivers.wx26.widgets import _base, gridline
+__all__ = ["UIGrid"]
+
# =============================================================================
# Interface implementation for a box widget
# =============================================================================
class UIGrid (_base.UIHelper):
+ """
+ The visual container for the grid control.
+ """
# -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, event):
+
+ _base.UIHelper.__init__(self, event)
+ self._max = 0
+ self._current_records = 0
+ self._visible = 0
+
+
+ # -------------------------------------------------------------------------
# Create a wx box widget
# -------------------------------------------------------------------------
def _create_widget_ (self, event, spacer):
+ """
+ Create the wx.Panel for the grid control and add it to the owner.
+ The spacer is ignored for <grid> tags.
+ @param event: the creation-event instance carrying information like
+ container (parent-widget)
+ @param spacer: not used for grid tags
+
+ @returns: the wx.GridBagSizer instance used for adding the rows
+ """
+
self.growable = True
+
+ owner = self.getParent()
parent = event.container
- owner = self.getParent()
- sizer = owner.container_sizer
+ # The base panel for the grid control
self.widget = wx.Panel(parent, -1) # , style=wx.SUNKEN_BORDER)
self.widget.Bind(wx.EVT_SIZE, self.__on_size)
+ self.widget.Bind(wx.EVT_MOUSEWHEEL, self.__on_mousewheel)
- outer = wx.BoxSizer(wx.VERTICAL)
- self.widget.SetSizer(outer)
-
- self.container_sizer = wx.GridBagSizer()
- outer.Add(self.container_sizer, 1, wx.EXPAND | wx.ALL, 2)
-
+ self.widget.SetSizer(wx.GridBagSizer())
self._container = self.widget
self._max = self._gfObject.rows
@@ -62,9 +90,13 @@
owner.add_widgets(self, spacer)
- return self.container_sizer
+ return self._container.GetSizer()
+ # -------------------------------------------------------------------------
+ # Build the first row of the grid (the header)
+ # -------------------------------------------------------------------------
+
def __build_header(self):
cols = {}
@@ -80,8 +112,10 @@
colnum = cols.keys()
colnum.sort()
+ sizer = self._container.GetSizer()
+
for clx in colnum:
- self.container_sizer.AddGrowableCol(clx)
+ sizer.AddGrowableCol(clx)
pnl = wx.Panel(self.widget, -1, style=wx.RAISED_BORDER)
vbx = wx.BoxSizer(wx.VERTICAL)
pnl.SetSizer(vbx)
@@ -90,27 +124,28 @@
stc = wx.StaticText(pnl, -1, label)
vbx.Add(stc, 1, wx.EXPAND)
- self.container_sizer.Add(pnl, (0, clx), (1, 1), wx.EXPAND)
+ sizer.Add(pnl, (0, clx), (1, 1), wx.EXPAND)
-
# -------------------------------------------------------------------------
- # Add an UI widget to the Grid container
- # -------------------------------------------------------------------------
-
- def add_widgets(self, ui_widget, spacer):
- pass
-
-
- # -------------------------------------------------------------------------
# Get the row-number of a concrete gridline in the GridBagSizer
# -------------------------------------------------------------------------
def _get_row(self, line, record):
+ """
+ Get the row number of a concrete gridline in the GridBagSizer
+ @param line: the UIGridLine instance we're interested in
+ @param record: the spacer (rel. record-number) of the line in question
+ @returns: the row within the GridBagSizer
+ """
return len(self._children) * record + self._children.index(line) + 1
+ # -------------------------------------------------------------------------
+ # Event-Handler
+ # -------------------------------------------------------------------------
+
def __on_size(self, event):
if not self._uiForm.sizing_enabled:
@@ -121,19 +156,19 @@
self._uiForm.sizing_enabled = False
try:
- (width, height) = self.widget.GetContainingSizer().GetSize()
+ height = self.widget.GetContainingSizer().GetSize()[1]
rech = 0
for item in self._children:
- rech += max([panel.GetBestSize()[1] for panel in
item._columns[0]])
+ rech += max([panel.GetBestSize()[1] \
+ for panel in item._columns[0]])
- (hd_width, hd_height) = self.container_sizer.GetCellSize(0, 0)
+ hd_height = self._container.GetSizer().GetCellSize(0, 0)[1]
available = height - hd_height
num_recs = int(available / float(rech))
num_recs = (height - hd_height) / rech
# Get the diff
- refresh = False
if num_recs > self._visible:
self.__add_new_records(num_recs - self._visible)
self.walk(self.__child_rows_walker)
@@ -148,9 +183,24 @@
event.Skip()
+ # -------------------------------------------------------------------------
+ def __on_mousewheel(self, event):
+
+ forward = event.GetWheelRotation() < 0
+ block = self._gfObject.get_block()
+
+ if self._form._currentBlock != block:
+ # FIXME: this does not look like a good solution, does it?
+ self._request('FOCUS', data=block._entryList[0])
+ return
+
+ self._request(['PREVRECORD', 'NEXTRECORD'][forward])
+
+
+
# -------------------------------------------------------------------------
- #
+ # Add new records to the grid (after resizing it)
# -------------------------------------------------------------------------
def __add_new_records(self, num_recs):
@@ -169,6 +219,10 @@
self._uiForm.main_window.Layout()
+ # -------------------------------------------------------------------------
+ # Create all child-widgets
+ # -------------------------------------------------------------------------
+
def __child_add_walker(self, item, spacer):
if item == self:
@@ -179,12 +233,12 @@
# -------------------------------------------------------------------------
- #
+ # Show or hide grid lines
# -------------------------------------------------------------------------
def __change_visibility(self, record, state):
- grid = self.container_sizer
+ grid = self._container.GetSizer()
for item in self._children:
row = self._get_row(item, record)
@@ -195,7 +249,7 @@
# -------------------------------------------------------------------------
- #
+ # Hide a given number of records
# -------------------------------------------------------------------------
def __hide_records(self, num_recs):
@@ -214,6 +268,10 @@
self._uiForm.main_window.Layout()
+ # -------------------------------------------------------------------------
+ # Set the rows attribute for all child widgets
+ # -------------------------------------------------------------------------
+
def __child_rows_walker(self, item):
if item == self:
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/gridline.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/gridline.py 2006-07-25
13:24:07 UTC (rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/gridline.py 2006-07-28
17:29:49 UTC (rev 8542)
@@ -20,10 +20,14 @@
# - Suite 330, Boston, MA 02111-1307, USA.
#
# $Id$
+"""
+Implementation of a <gridline>. A gridline is a logical line within a <grid>
+and defines the controls building up the line.
+"""
import wx
-from gnue.forms.uidrivers.wx26.widgets import _base, hbox, entry, button
+from gnue.forms.uidrivers.wx26.widgets import _base
__all__ = ['UIGridLine']
@@ -32,39 +36,48 @@
# =============================================================================
class UIGridLine (_base.UIHelper):
+ """
+ Collection of controls building a given line in a grid.
+ @ivar _columns: a dictionary which holds a sequence of wx.Panel instances
+ per spacer. Each of these panels will get the parent widget for the
+ control located in that cell.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
def __init__(self, event):
+
_base.UIHelper.__init__(self, event)
self._columns = {}
+
# -------------------------------------------------------------------------
# Create a wx box widget
# -------------------------------------------------------------------------
def _create_widget_ (self, event, spacer):
+ """
+ Prepare the columns (cells) for the girdline and add it to the owner.
+ """
- owner = self.getParent()
-
parent = event.container
- sizer = owner.container_sizer
-
self.__prepare_columns(parent, spacer)
-
- self.container_sizer = sizer
self._container = parent
- owner.add_widgets(self, spacer)
-
return None
+
# -------------------------------------------------------------------------
- #
+ # Prepare the cells for this gridline
# -------------------------------------------------------------------------
def __prepare_columns(self, parent, spacer):
owner = self.getParent()
- sizer = owner.container_sizer
+ sizer = parent.GetSizer()
row = owner._get_row(self, spacer)
offset = 0
@@ -107,19 +120,38 @@
# -------------------------------------------------------------------------
def add_widgets(self, ui_widget, spacer):
+ """
+ Add a given UI widget to the gridline.
+ @param ui_widget: widget to add to the page
+ @param spacer: the row-index (relative record number) to add the
widget
+ """
+
panel = self._get_cell(ui_widget, spacer)
sizer = panel.GetSizer()
- sizer.Add(ui_widget.label, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, 5)
- sizer.Add(ui_widget.widget, 1, wx.EXPAND)
+ if ui_widget.label:
+ sizer.Add(ui_widget.label, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT,
+ 5)
+ sizer.Add(ui_widget.widget, 1, wx.ALIGN_CENTER)
best = ui_widget.widget.GetBestSize()
sizer.SetMinSize(best)
- ui_widget.widget.Hide()
+ if ui_widget.label:
+ ui_widget.widget.Hide()
+ # -------------------------------------------------------------------------
+ # Get the cell-parent for a given child-control
+ # -------------------------------------------------------------------------
+
def _get_cell(self, ui_widget, spacer):
+ """
+ Return the wx.Panel instance (acting as parent widget) for a given
+ UI-Widget.
+ @param ui_widget: the UIWidget to get the cell parent for
+ @param spacer: the spacer of the row to get the cell parent for
+ """
index = self._children.index(ui_widget)
return self._columns[spacer][index]
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py 2006-07-25 13:24:07 UTC
(rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/hbox.py 2006-07-28 17:29:49 UTC
(rev 8542)
@@ -73,14 +73,19 @@
flags = wx.ALIGN_TOP | wx.EXPAND
if isinstance(ui_widget, button.UIButton):
- item = self.add_to_hbox(item)
+ item = self.add_to_hbox(item, False)
elif not ui_widget.growable:
- item = self.add_to_vbox(item)
+ box = wx.BoxSizer(wx.VERTICAL)
+ box.Add(item, 0, wx.EXPAND)
+ box.Add((0,0))
+ item = box
sizer.Add(item, pos, span, flags)
- if add:
+ # Only columns having a stretch greater than zero require a growable
+ # column. Setting a stretch of 0 breaks the size calculation anyway.
+ if add and ui_widget.stretch:
sizer.AddGrowableCol(self.last_item, ui_widget.stretch)
self.last_item += add
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py 2006-07-25 13:24:07 UTC
(rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/page.py 2006-07-28 17:29:49 UTC
(rev 8542)
@@ -102,7 +102,7 @@
sizer = self._container.GetSizer()
if self.managed:
- sizer.Add(item, 1, wx.EXPAND | wx.ALL, 4)
+ sizer.Add(item, ui_widget.stretch, wx.EXPAND | wx.ALL, 4)
else:
flags = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND
border = 0
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py 2006-07-25 13:24:07 UTC
(rev 8541)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/vbox.py 2006-07-28 17:29:49 UTC
(rev 8542)
@@ -41,6 +41,8 @@
Implementation of the vbox tag
"""
+ growable = True
+
# -------------------------------------------------------------------------
# Add an UI widget to the VBox container
# -------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8542 - in trunk/gnue-forms/src: GFObjects uidrivers/_base/widgets uidrivers/wx26/widgets,
johannes <=