dabo Commit
Revision 2916
Date: 2007-03-15 11:33:59 -0700 (Thu, 15 Mar 2007)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/2916
Changed:
U trunk/dabo/ui/dPemMixinBase.py
U trunk/dabo/ui/uiwx/dFormMixin.py
U trunk/dabo/ui/uiwx/dGrid.py
U trunk/dabo/ui/uiwx/dPemMixin.py
U trunk/dabo/ui/uiwx/dTreeView.py
U trunk/dabo/ui/uiwx/uiApp.py
Log:
Added abstract Children property to dPemMixinBase, as an empty list. Added
Children property to dGrid, which is an alias to grid.Columns.
Added abstract refresh() method to dPemMixinBase, which does nothing.
Changed the getter in uiApp.ActiveForm to first check the value of _activeForm,
and if that is None to check wx.GetActiveWindow(). Previously, it wasn't
respecting the setting of ActiveForm on Windows.
dColumn's afterInit() wasn't being fired. Fixed.
Fixed dGrid's test to have the selection radio button painted with the same
background as the test form, so it looks better.
Refactored dPemMixin.iterateCall() into dPemMixinBase.iterateCall(), and
removed it from dColumn as it now works without overriding it.
Refactored the zooming of font sizes into the following public functions:
fontZoomIn()
fontZoomOut()
fontZoomNormal()
and made the restoration of the zoom happen at individual object instantiation
instead of form instantiation, as some objects may not get instantiated until
later on and were thus missed in the original implementation.
Normally, I would have split these into several smaller commits, but all the
changes were intertwined with the font zooming.
Diff:
Modified: trunk/dabo/ui/dPemMixinBase.py
===================================================================
--- trunk/dabo/ui/dPemMixinBase.py 2007-03-15 18:32:43 UTC (rev 2915)
+++ trunk/dabo/ui/dPemMixinBase.py 2007-03-15 18:33:59 UTC (rev 2916)
@@ -2,6 +2,7 @@
import dabo
import types
from dabo.dObject import dObject
+import dabo.dException as dException
from dabo.dLocalize import _
@@ -15,7 +16,6 @@
super(dPemMixinBase, self)._initEvents()
self.autoBindEvents()
-
def _initUI(self):
""" Abstract method: subclasses MUST override for
UI-specifics."""
pass
@@ -44,7 +44,11 @@
""" Abstract method: subclasses MUST override for
UI-specifics."""
pass
+ def refresh(self):
+ """ Abstract method."""
+ pass
+
def _initName(self, name=None, _explicitName=True):
if name is None:
name = self.Name
@@ -75,7 +79,73 @@
return name, _explicitName
+ def iterateCall(self, funcName, *args, **kwargs):
+ """Call the given function on this object and all of its
Children. If
+ any object does not have the given function, no error is
raised; it
+ is simply ignored.
+ """
+ func = getattr(self, funcName, None)
+ if func:
+ try:
+ func(*args, **kwargs)
+ except dException.StopIterationException:
+ # This is raised when the object does not want
to pass
+ # the iteration on through its Children.
+ func = None
+ if func:
+ for child in self.Children:
+ if hasattr(child, "iterateCall"):
+ child.iterateCall(funcName, *args,
**kwargs)
+
+
+ # These five functions are essentially a single unit that provides font
zooming.
+ def fontZoomIn(self, amt=1):
+ """Zoom in on the font, by setting a higher point size."""
+ self._setRelativeFontZoom(amt)
+
+ def fontZoomOut(self, amt=1):
+ """Zoom out on the font, by setting a lower point size."""
+ self._setRelativeFontZoom(-amt)
+
+ def fontZoomNormal(self):
+ """Reset the font zoom back to zero."""
+ self._setAbsoluteFontZoom(0)
+
+ def _setRelativeFontZoom(self, amt):
+ abs_zoom = getattr(self, "_currFontZoom", 0) + amt
+ self._setAbsoluteFontZoom(abs_zoom)
+
+ def _setAbsoluteFontZoom(self, newZoom):
+ if not hasattr(self, "FontSize"):
+ # Menus, for instance
+ return
+ origFontSize = self._origFontSize = getattr(self,
"_origFontSize", self.FontSize)
+ fontSize = origFontSize + newZoom
+ self._currFontZoom = newZoom
+ if fontSize > 1:
+ self.FontSize = fontSize
+ dabo.ui.callAfterInterval(200, self.refresh)
+
+ if isinstance(self, dabo.ui.dFormMixin):
+ frm = self
+ else:
+ frm = self.Form
+ if frm is not None:
+ dabo.ui.callAfterInterval(200, frm.layout)
+
+ def _restoreFontZoom(self):
+ """Called when object is instantiated: restore the zoom based
on the form."""
+ if not hasattr(self.Form, "_currFontZoom"):
+ self.Form._restoreFontZoom()
+ zoom = getattr(self.Form, "_currFontZoom", 0)
+ if zoom and not isinstance(self, (dabo.ui.dPanel,
dabo.ui.dScrollPanel)):
+ dabo.ui.callAfter(self._setAbsoluteFontZoom, zoom)
+
+
# Property get/set/delete methods follow.
+ def _getChildren(self):
+ return []
+
def _getForm(self):
try:
return self._cachedForm
@@ -115,6 +185,9 @@
_("""The position of the bottom side of the object.
This is a
convenience property, and is equivalent to setting the
Top property
to this value minus the Height of the control.
(int)"""))
+
+ Children = property(_getChildren, None, None,
+ _("""List of child objects."""))
Form = property(_getForm, None, None,
_("Object reference to the dForm containing the object.
Read-only. (dForm)."))
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py 2007-03-15 18:32:43 UTC (rev 2915)
+++ trunk/dabo/ui/uiwx/dFormMixin.py 2007-03-15 18:33:59 UTC (rev 2916)
@@ -373,8 +373,7 @@
""" Restore the saved window geometry for this form.
Ask dApp for the last saved setting of height, width, left, and
top,
- and set those properties on this form. Also, if there was a
font zoom
- defined for this form, restore it.
+ and set those properties on this form.
"""
if self.Application and self.SaveRestorePosition:
name = self.getAbsoluteName()
@@ -383,7 +382,6 @@
width = self.Application.getUserSetting("%s.width" %
name)
height = self.Application.getUserSetting("%s.height" %
name)
state =
self.Application.getUserSetting("%s.windowstate" % name)
- zoom = self.Application.getUserSetting("%s.zoomlevel" %
name)
if isinstance(left, int) and isinstance(top, int):
self.Position = (left,top)
@@ -395,8 +393,6 @@
state = "Normal"
self.WindowState = state
- if zoom:
- dabo.ui.callAfter(self.iterateCall,
"_changeFontSize", zoom)
self.restoredSP = True
@@ -479,6 +475,23 @@
tip=tip, help=help, *args, **kwargs)
+ def _setAbsoluteFontZoom(self, amt):
+ # Let the default behavior run, but then save the font zoom
level to
+ # the user preferences file. The loading of the saved pref happens in
+ # the individual control (dPemMixinBase) so that the restoration of the
+ # control's font zoom isn't dependent on the control being created at
+ # form load time.
+ self.super(amt)
+ if self.Application and self.SaveRestorePosition:
+ self.Application.setUserSetting("%s.fontzoom"
+ % self.getAbsoluteName(),
self._currFontZoom)
+
+ def _restoreFontZoom(self):
+ if self.Application:
+ self._currFontZoom =
self.Application.getUserSetting("%s.fontzoom"
+ % self.getAbsoluteName(), 0)
+
+
# property get/set/del functions follow:
def _getActiveControl(self):
# Can't use FindFocus: it returns whatever control has the
keyboard focus,
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2007-03-15 18:32:43 UTC (rev 2915)
+++ trunk/dabo/ui/uiwx/dGrid.py 2007-03-15 18:33:59 UTC (rev 2916)
@@ -415,7 +415,7 @@
they provide a way to interact with the underlying grid table in a more
straightforward manner.
"""
- _call_beforeInit, _call_afterInit, _call_initProperties = False, True,
True
+ _call_beforeInit, _call_afterInit, _call_initProperties = False, True,
False
def __init__(self, parent, properties=None, attProperties=None,
*args, **kwargs):
@@ -436,6 +436,7 @@
super(dColumn, self).__init__(properties, attProperties, *args,
**kwargs)
self._baseClass = dColumn
+ self._afterInit()
def _beforeInit(self):
@@ -483,7 +484,9 @@
def _afterInit(self):
self._isConstructed = True
super(dColumn, self)._afterInit()
-
+ if self.Form and self.Form.SaveRestorePosition:
+ self._restoreFontZoom()
+
def _getDefaultFont(self):
ret = dabo.ui.dFont(Size=10, Bold=False, Italic=False,
@@ -507,48 +510,18 @@
self.Parent.removeColumn(self)
except:
pass
-
-
- def iterateCall(self, funcName, *args, **kwargs):
- """Call the given function on this object and all of its
Children. If
- any object does not have the given function, no error is
raised; it
- is simply ignored. This is copied from dPemMixin, since dColumn
- doesn't inherit from dPemMixin, and it is needed for the
iterations
- to work across grids.
- """
- ok = True
- try:
- fnc = eval("self.%s" % funcName)
- except AttributeError:
- ok = False
- if ok:
- fnc(*args, **kwargs)
+ def _setAbsoluteFontZoom(self, newZoom):
+ origFontSize = self._origFontSize = getattr(self,
"_origFontSize", self.FontSize)
+ origHeaderFontSize = self._origHeaderFontSize = getattr(self,
"_origHeaderFontSize", self.HeaderFontSize)
+ fontSize = origFontSize + newZoom
+ headerFontSize = origHeaderFontSize + newZoom
+ self._currFontZoom = newZoom
+ if fontSize > 1:
+ self.FontSize = fontSize
+ if headerFontSize > 1:
+ self.HeaderFontSize = headerFontSize
- def increaseFontSize(self, val=None):
- """Increase the font size by the specified amount for both the
column
- and its header.
- """
- if val is None:
- val = 1
- self._changeFontSize(val)
- def decreaseFontSize(self, val=None):
- if val is None:
- val = -1
- else:
- val = -1 * val
- self._changeFontSize(val)
- def _changeFontSize(self, val):
- try:
- self.FontSize += val
- except PyAssertionError:
- # This catches invalid point sizes
- pass
- try:
- self.HeaderFontSize += val
- except PyAssertionError:
- # This catches invalid point sizes
- pass
if self.Form is not None:
dabo.ui.callAfterInterval(200, self.Form.layout)
@@ -4046,6 +4019,9 @@
CellHighlightWidth = property(_getCellHighlightWidth,
_setCellHighlightWidth, None,
_("Specifies the width of the cell highlight box."))
+ Children = property(_getColumns, None, None,
+ _("List of dColumns, same as self.Columns. (list)"))
+
Columns = property(_getColumns, None, None,
_("List of dColumns. (list)"))
@@ -4293,15 +4269,10 @@
def afterInit(self):
self.super()
- col = dColumn(self, Name="Geek", Order=10, DataField="coder",
- DataType="bool", Width=60, Caption="Geek?",
Sortable=False,
- Searchable=False, Editable=True)
- self.addColumn(col)
+ self.addColumn(Name="Geek", DataField="coder", Caption="Geek?",
+ Order=10, DataType="bool", Width=60,
Sortable=False,
+ Searchable=False, Editable=True,
HeaderFontBold=False)
-# col.CustomRenderers[1] = col.stringRendererClass
-# col.CustomEditors[1] = col.stringEditorClass
- col.HeaderFontBold = False
-
col = dColumn(self, Name="Person", Order=20, DataField="name",
DataType="string", Width=200,
Caption="Celebrity Name",
Sortable=True, Searchable=True, Editable=True,
Expand=False)
@@ -4358,8 +4329,8 @@
gsz.append(chk, row=2, col=0)
radSelect = dabo.ui.dRadioList(self, Choices=["Row",
"Col", "Cell"],
- ValueMode="string", Caption="Sel Mode",
- DataSource="sampleGrid",
DataField="SelectionMode")
+ ValueMode="string", Caption="Sel Mode",
BackColor=self.BackColor,
+ DataSource="sampleGrid",
DataField="SelectionMode", RegID="radSelect")
radSelect.refresh()
gsz.append(radSelect, row=0, col=1, rowSpan=3)
@@ -4368,9 +4339,9 @@
self.layout()
self.fitToSizer(20,20)
+
-
- app = dabo.dApp()
- app.MainFormClass = TestForm
+ app = dabo.dApp(MainFormClass=TestForm)
app.setup()
+ app.MainForm.radSelect.setFocus()
app.start()
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py 2007-03-15 18:32:43 UTC (rev 2915)
+++ trunk/dabo/ui/uiwx/dPemMixin.py 2007-03-15 18:33:59 UTC (rev 2916)
@@ -304,6 +304,9 @@
self.afterInit()
+ if self.Form and self.Form.SaveRestorePosition:
+ self._restoreFontZoom()
+
def _afterInitAll(self):
"""This is the framework-level hook. It calls the
developer-specific method."""
@@ -315,7 +318,6 @@
def _preInitUI(self, kwargs):
"""Subclass hook, for internal Dabo use.
-
Some wx objects (RadioBox) need certain props forced if they
hadn't been
set by the user either as a parm or in beforeInit().
"""
@@ -1030,55 +1032,6 @@
kid.setAll(prop, val, recurse=recurse,
filt=filt)
- def iterateCall(self, funcName, *args, **kwargs):
- """Call the given function on this object and all of its
Children. If
- any object does not have the given function, no error is
raised; it
- is simply ignored.
- """
- ok = True
- try:
- fnc = eval("self.%s" % funcName)
- except AttributeError:
- ok = False
- if ok:
- try:
- fnc(*args, **kwargs)
- except dException.StopIterationException:
- # This is raised when the object does not want
to pass
- # the iteration on through its Children.
- ok = False
- if ok:
- if isinstance(self, dabo.ui.dGrid):
- kids = self.Columns
- else:
- kids = self.Children
- for kid in kids:
- if hasattr(kid, "iterateCall"):
- kid.iterateCall(funcName, *args,
**kwargs)
-
-
- # These three functions are essentially a single unit that provides for
font size mods.
- def increaseFontSize(self, val=None):
- if val is None:
- val = 1
- self._changeFontSize(val)
- def decreaseFontSize(self, val=None):
- if val is None:
- val = -1
- else:
- val = -1 * val
- self._changeFontSize(val)
- def _changeFontSize(self, val):
- try:
- self.FontSize += val
- self.refresh()
- except PyAssertionError:
- # This catches invalid point sizes
- pass
- if self.Form is not None:
- dabo.ui.callAfterInterval(200, self.Form.layout)
-
-
def recreate(self, child=None):
"""Recreate the object.
@@ -1189,6 +1142,9 @@
# This can happen if an object is released when there
is a
# pending callAfter() refresh.
pass
+ except AttributeError:
+ # Menus don't have a Refresh() method.
+ pass
def show(self):
@@ -1823,7 +1779,7 @@
def _setFontSize(self, val):
if self._constructed():
- self.Font.Size = val
+ self.Font.Size = val
else:
self._properties["FontSize"] = val
Modified: trunk/dabo/ui/uiwx/dTreeView.py
===================================================================
--- trunk/dabo/ui/uiwx/dTreeView.py 2007-03-15 18:32:43 UTC (rev 2915)
+++ trunk/dabo/ui/uiwx/dTreeView.py 2007-03-15 18:33:59 UTC (rev 2916)
@@ -818,24 +818,14 @@
os.path.walk(dirPath, sortNode, None)
- def increaseFontSize(self, val=None):
- """Increase the font size by the specified amount for all
nodes."""
- if val is None:
- val = 1
- self._changeFontSize(val)
- def decreaseFontSize(self, val=None):
- if val is None:
- val = -1
- else:
- val = -1 * val
- self._changeFontSize(val)
- def _changeFontSize(self, val):
- for nd in self.nodes:
- try:
- nd.FontSize += val
- except PyAssertionError:
- # This catches invalid point sizes
- pass
+ def _setAbsoluteFontZoom(self, newZoom):
+ for node in self.nodes:
+ origFontSize = node._origFontSize = getattr(self,
"_origFontSize", node.FontSize)
+ fontSize = origFontSize + newZoom
+ node._currFontZoom = newZoom
+ if fontSize > 1:
+ node.FontSize = fontSize
+
if self.Form is not None:
dabo.ui.callAfterInterval(200, self.Form.layout)
Modified: trunk/dabo/ui/uiwx/uiApp.py
===================================================================
--- trunk/dabo/ui/uiwx/uiApp.py 2007-03-15 18:32:43 UTC (rev 2915)
+++ trunk/dabo/ui/uiwx/uiApp.py 2007-03-15 18:33:59 UTC (rev 2916)
@@ -165,9 +165,7 @@
def _onKeyPress(self, evt):
- if not self.ActiveForm:
- evt.Skip()
- return
+ ## Zoom In / Out / Normal:
alt = evt.AltDown()
ctl = evt.ControlDown()
kcd = evt.GetKeyCode()
@@ -175,7 +173,7 @@
uk = evt.GetUnicodeKey()
met = evt.MetaDown()
sh = evt.ShiftDown()
- if alt or not ctl:
+ if not self.ActiveForm or alt or not ctl:
evt.Skip()
return
try:
@@ -185,22 +183,14 @@
plus = (char == "=") or (char == "+") or (kcd ==
wx.WXK_NUMPAD_ADD)
minus = (char == "-") or (kcd == wx.WXK_NUMPAD_SUBTRACT)
slash = (char == "/") or (kcd == wx.WXK_NUMPAD_DIVIDE)
- if not (plus or minus or slash):
- evt.Skip()
- return
- settingName = "%s.zoomlevel" % self.ActiveForm.Name
- currZoom = self.dApp.getUserSetting(settingName, 0)
if plus:
- self.ActiveForm.iterateCall("increaseFontSize")
- currZoom += 1
+ self.ActiveForm.iterateCall("fontZoomIn")
elif minus:
- self.ActiveForm.iterateCall("decreaseFontSize")
- currZoom -= 1
+ self.ActiveForm.iterateCall("fontZoomOut")
+ elif slash:
+ self.ActiveForm.iterateCall("fontZoomNormal")
else:
- # Set back to zero zoom
- self.ActiveForm.iterateCall("decreaseFontSize",
currZoom)
- currZoom = 0
- self.dApp.setUserSetting(settingName, currZoom)
+ evt.Skip()
def setup(self):
@@ -798,14 +788,10 @@
def _getActiveForm(self):
- if self._platform == "Win":
- v = wx.GetActiveWindow()
- else:
- try:
- v = self._activeForm
- except AttributeError:
- v = self._activeForm = None
- return v
+ af = getattr(self, "_activeForm", None)
+ if af is None:
+ af = wx.GetActiveWindow()
+ return af
def _setActiveForm(self, frm):
self._activeForm = frm
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev