[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/designer/src LayoutEditor.py PropertyEdito...
From: |
Jason Cater |
Subject: |
gnue/designer/src LayoutEditor.py PropertyEdito... |
Date: |
Wed, 27 Jun 2001 22:04:19 -0700 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 01/06/27 22:04:18
Modified files:
designer/src : LayoutEditor.py PropertyEditor.py
Log message:
PropertyEditor now restricts attribute input based on type of
attribute; uses combo boxes where appropriate
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/src/LayoutEditor.py.diff?cvsroot=OldCVS&tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/src/PropertyEditor.py.diff?cvsroot=OldCVS&tr1=1.7&tr2=1.8&r1=text&r2=text
Patches:
Index: gnue/designer/src/LayoutEditor.py
diff -u gnue/designer/src/LayoutEditor.py:1.13
gnue/designer/src/LayoutEditor.py:1.14
--- gnue/designer/src/LayoutEditor.py:1.13 Wed Jun 27 20:21:39 2001
+++ gnue/designer/src/LayoutEditor.py Wed Jun 27 22:04:18 2001
@@ -587,7 +587,7 @@
def __init__(self, parent):
wxPanel.__init__(self, parent, -1, style=wxRAISED_BORDER|wxCLIP_CHILDREN)
self.parent = parent
-
+ self.object = None
self.nameLabel = wxStaticText(self, -1, "Name:", pos=wxPoint(4,8))
self.nameEditor = wxTextCtrl(self, -1,
pos=calcRelPos(self.nameLabel, dx=6, absy=4))
Index: gnue/designer/src/PropertyEditor.py
diff -u gnue/designer/src/PropertyEditor.py:1.7
gnue/designer/src/PropertyEditor.py:1.8
--- gnue/designer/src/PropertyEditor.py:1.7 Tue Jun 26 21:28:00 2001
+++ gnue/designer/src/PropertyEditor.py Wed Jun 27 22:04:18 2001
@@ -27,10 +27,10 @@
#
-import sys, os, time
+import sys, os, time, string
from wxPython.wx import *
from wxPython.grid import *
-from gnue.common import GDebug, GConfig
+from gnue.common import GDebug, GConfig, GParser
from gnue.forms import GFForm, GFInstance, GFParser, GFObjects, GFTrigger,
GFLibrary, UIwxpython
from GFDesigner import *
from Incubator import elements
@@ -75,8 +75,22 @@
i = 0
for key in self.rowList:
self.grid.SetRowLabelValue(i, string.upper(key[0]) +
string.lower(key[1:]))
+
+ if self.attributes[key].has_key('ValueSet'):
+ self.grid.SetCellEditor(i, 0,
RestrictedCellEditor(self.attributes[key]))
+ elif self.attributes[key]['Typecast'] == GParser.bool:
+ self.grid.SetCellEditor(i, 0, BoolCellEditor(self.attributes[key]))
+ elif self.attributes[key]['Typecast'] == int:
+ self.grid.SetCellEditor(i, 0, IntCellEditor(self.attributes[key]))
+ else:
+ self.grid.SetCellEditor(i, 0, CharCellEditor(self.attributes[key]))
+
if hasattr(object, key):
- self.grid.SetCellValue(i,0,"%s" % object.__dict__[key])
+ if self.attributes[key]['Typecast'] == GParser.bool:
+ if object.__dict__[key]:
+ self.grid.SetCellValue(i,0,"TRUE")
+ else:
+ self.grid.SetCellValue(i,0,"FALSE")
i = i + 1
self.onSize(None)
EVT_GRID_CELL_CHANGE(self.grid, self.OnCellChange)
@@ -110,12 +124,197 @@
value = self.grid.GetCellValue(evt.GetRow(), evt.GetCol())
try:
- self.object.__dict__[attr] = self.attributes[attr][2](value)
+ self.object.__dict__[attr] = self.attributes[attr]['Typecast'](value)
self.instance.onModifyObject(self.object, __name__, ((attr,
self.object.__dict__[attr]),))
evt.Skip()
except ValueError:
wxBell()
+
+#
+#
+#
+class CharCellEditor (wxPyGridCellEditor):
+ def __init__(self, attributes):
+ wxPyGridCellEditor.__init__(self)
+ self.attributes = attributes
+
+ def Create(self, parent, id, evtHandler):
+ self._tc = wxTextCtrl(parent, id, "")
+ self._tc.SetInsertionPoint(0)
+ self.SetControl(self._tc)
+ if evtHandler:
+ self._tc.PushEventHandler(evtHandler)
+
+ def SetSize(self, rect):
+ self._tc.SetDimensions(rect.x, rect.y, rect.width+2, rect.height+2)
+
+ def Show(self, show, attr):
+ self.base_Show(show, attr)
+
+ def PaintBackground(self, rect, attr):
+ pass
+
+ def BeginEdit(self, row, col, grid):
+ self.startValue = grid.GetTable().GetValue(row, col)
+ self._tc.SetValue(self.startValue)
+ self._tc.SetInsertionPointEnd()
+ self._tc.SetFocus()
+
+ # For this example, select the text
+ self._tc.SetSelection(0, self._tc.GetLastPosition())
+
+
+ def EndEdit(self, row, col, grid):
+ changed = false
+
+ val = self._tc.GetValue()
+ if val != self.startValue:
+ changed = true
+ grid.GetTable().SetValue(row, col, val) # update the table
+
+ self.startValue = ''
+ self._tc.SetValue('')
+ return changed
+
+
+ def Reset(self):
+ self._tc.SetValue(self.startValue)
+ self._tc.SetInsertionPointEnd()
+
+
+ def IsAcceptedKey(self, evt):
+ return (not (evt.ControlDown() or evt.AltDown()) and
+ evt.GetKeyCode() != WXK_SHIFT)
+
+
+ def StartingKey(self, evt):
+ key = evt.GetKeyCode()
+ ch = None
+ if key in [WXK_NUMPAD0, WXK_NUMPAD1, WXK_NUMPAD2, WXK_NUMPAD3, WXK_NUMPAD4,
+ WXK_NUMPAD5, WXK_NUMPAD6, WXK_NUMPAD7, WXK_NUMPAD8,
WXK_NUMPAD9]:
+ ch = ch = chr(ord('0') + key - WXK_NUMPAD0)
+
+ elif key < 256 and key >= 0 and chr(key):
+ ch = chr(key)
+ if not evt.ShiftDown():
+ ch = string.lower(ch)
+
+ if ch is not None:
+ # For this example, replace the text. Normally we would append it.
+ #self._tc.AppendText(ch)
+ self._tc.SetValue(ch)
+ self._tc.SetInsertionPointEnd()
+ else:
+ evt.Skip()
+
+
+ def StartingClick(self):
+ pass
+
+ def Destroy(self):
+ self.base_Destroy()
+
+
+class IntCellEditor (CharCellEditor):
+ def __init__(self, attributes):
+ CharCellEditor.__init__(self, attributes)
+
+ def Create(self, parent, id, evtHandler):
+ CharCellEditor.Create(self, parent, id, evtHandler)
+ EVT_CHAR(self._tc, self.OnKeyPressed)
+
+ def OnKeyPressed(self, evt):
+ if (ord('0') <= evt.KeyCode() <= ord('9') or \
+ evt.KeyCode() in (ord('-'), ord('+')) or \
+ evt.KeyCode() < 32 or evt.KeyCode() > 126):
+ evt.Skip()
+
+
+class RestrictedCellEditor (CharCellEditor):
+ def __init__(self, attributes):
+ CharCellEditor.__init__(self, attributes)
+ self.valueList = attributes['ValueSet'].keys()
+ self.valueList.sort()
+ self.selectionList = []
+ self.valueMap = {}
+
+ i = 0
+ if not (attributes.has_key('Required') and attributes['Required'] ):
+ self.valueMap[''] = 0
+ self.selectionList.append(' <Not Set> ')
+ i = 1
+
+ for v in self.valueList:
+ self.valueMap[v] = i
+ self.selectionList.append("%s" % (attributes['ValueSet'][v] or v))
+ i = i + 1
+
+ self.valueList.insert(0, '')
+
+ def Create(self, parent, id, evtHandler):
+ self._tc = wxComboBox(parent, id, "", style=wxCB_READONLY,
+ choices=self.selectionList)
+ self.SetControl(self._tc)
+ if evtHandler:
+ self._tc.PushEventHandler(evtHandler)
+
+ def BeginEdit(self, row, col, grid):
+ self.startValue = grid.GetTable().GetValue(row, col)
+ self._tc.SetSelection(self.valueMap[self.startValue])
+ self._tc.SetFocus()
+
+ def EndEdit(self, row, col, grid):
+ changed = false
+
+ val = self.valueList[self._tc.GetSelection()]
+ if val != self.startValue:
+ changed = true
+ grid.GetTable().SetValue(row, col, "%s" % val) # update the table
+
+ self.startValue = ''
+ self._tc.SetSelection(0)
+ return changed
+
+
+ def Reset(self):
+ self._tc.SetSelection(self.valueMap[self.startValue])
+ #self._tc.SetInsertionPointEnd()
+
+
+ def StartingKey(self, evt):
+ key = evt.GetKeyCode()
+ ch = None
+ if key in [WXK_NUMPAD0, WXK_NUMPAD1, WXK_NUMPAD2, WXK_NUMPAD3, WXK_NUMPAD4,
+ WXK_NUMPAD5, WXK_NUMPAD6, WXK_NUMPAD7, WXK_NUMPAD8,
WXK_NUMPAD9]:
+ ch = ch = chr(ord('0') + key - WXK_NUMPAD0)
+
+ elif key < 256 and key >= 0 and chr(key):
+ ch = chr(key)
+ if not evt.ShiftDown():
+ ch = string.lower(ch)
+
+ if ch is not None:
+ # For this example, replace the text. Normally we would append it.
+ #self._tc.AppendText(ch)
+ pass
+# self._tc.SetValue(ch)
+# self._tc.SetInsertionPointEnd()
+ else:
+ evt.Skip()
+
+
+class BoolCellEditor (RestrictedCellEditor):
+ def __init__(self, attributes):
+ if attributes.has_key('Default'):
+ default = attributes['Default']
+ else:
+ default = 0
+ RestrictedCellEditor.__init__(self, {'ValueSet': {'TRUE':{}, 'FALSE':{}},
+ 'Required': 1,
+ 'Default': default} )
+
+
#
#
#
@@ -255,8 +454,6 @@
self.objectMap[nameMap[key]] = i
self.objectCombo.Append(nameMap[key].name)
i = i + 1
-
-
def inventoryObject(self, object):
if hasattr(object, 'name'):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/designer/src LayoutEditor.py PropertyEdito...,
Jason Cater <=