[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/designer/src/base/tools PropertyEditor.py
From: |
Jason Cater |
Subject: |
gnue/designer/src/base/tools PropertyEditor.py |
Date: |
Fri, 06 Jun 2003 21:10:39 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Branch:
Changes by: Jason Cater <address@hidden> 03/06/06 21:10:39
Modified files:
designer/src/base/tools: PropertyEditor.py
Log message:
Implementation of a non-wxGrid property editor
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/base/tools/PropertyEditor.py.diff?tr1=1.42&tr2=1.43&r1=text&r2=text
Patches:
Index: gnue/designer/src/base/tools/PropertyEditor.py
diff -c gnue/designer/src/base/tools/PropertyEditor.py:1.42
gnue/designer/src/base/tools/PropertyEditor.py:1.43
*** gnue/designer/src/base/tools/PropertyEditor.py:1.42 Fri May 23 20:02:31 2003
--- gnue/designer/src/base/tools/PropertyEditor.py Fri Jun 6 21:10:39 2003
***************
*** 26,31 ****
--- 26,32 ----
# NOTES:
#
+ __all__ = ['PropertyEditor']
import sys, os, string
from wxPython.wx import *
***************
*** 33,39 ****
from gnue.common.apps import GDebug
from gnue.common.formatting import GTypecast
from gnue.designer.base.ToolBase import *
- from gnue.designer.base.uihelpers.GridCellEditors import *
class PropertyEditor (ToolBase):
--- 34,39 ----
***************
*** 56,62 ****
})
self.supplemental = []
! EVT_SIZE(self, self.onSize)
self.main = self.createMainPage()
self.notebook.AddPage(self.main,'Properties')
--- 56,62 ----
})
self.supplemental = []
! EVT_SIZE(self, self.__onSize)
self.main = self.createMainPage()
self.notebook.AddPage(self.main,'Properties')
***************
*** 115,121 ****
pass
! def onSize(self, event):
w,h = self.GetClientSizeTuple()
self.panel.SetSize((w-12,h-12))
self.notebook.SetSize(self.panel.GetClientSizeTuple())
--- 115,121 ----
pass
! def __onSize(self, event):
w,h = self.GetClientSizeTuple()
self.panel.SetSize((w-12,h-12))
self.notebook.SetSize(self.panel.GetClientSizeTuple())
***************
*** 124,147 ****
#
#
#
! class InspectorPanel(wxPanel):
NAMESPACE = ""
def __init__(self, editor, parent):
!
! wxPanel.__init__(self, parent, -1)
self.object = None
self.editor = editor
! # Set up our grid
! self.grid = wxGrid(self, -1, pos=wxPoint(0,0))
! self.grid.CreateGrid(1,1)
! self.grid.SetColLabelSize(0)
!
! EVT_GRID_CELL_CHANGE(self.grid, self.OnCellChange)
! EVT_GRID_CELL_LEFT_DCLICK(self.grid, self.OnLeftDClick)
! EVT_SIZE(self, self.onSize)
def getAttributes(self, object):
--- 124,146 ----
#
#
#
! class InspectorPanel(wxScrolledWindow):
NAMESPACE = ""
def __init__(self, editor, parent):
! wxScrolledWindow.__init__(self, parent, -1, style = wxHSCROLL)
! self.splitter = splitter = wxSplitterWindow(self, -1, style=wxSP_FULLSASH
| wxSP_NOBORDER)
self.object = None
self.editor = editor
+ self.fields = []
+ self.labels = []
! self.labelPanel = wxPanel(splitter, -1)
! self.fieldPanel = wxPanel(splitter, -1)
! splitter.SplitVertically(self.labelPanel, self.fieldPanel)
! EVT_SPLITTER_SASH_POS_CHANGED(self, self.splitter.GetId(),self.__onSize)
! EVT_SIZE(self, self.__onSize)
def getAttributes(self, object):
***************
*** 159,176 ****
self.object = object
self.attributes = self.getAttributes(object)
! # Speed up the process by not refreshing the grid yet
! self.grid.BeginBatch()
!
! # Delete any old rows from a previous object
! nr = self.grid.GetNumberRows()
! if nr:
! self.grid.DeleteRows(0,nr)
!
!
self.rowList = self.attributes.keys()
self.rowList.sort()
# Only show properties for nondeprecated values (unless set)
i = 0
while i < len(self.rowList):
--- 158,174 ----
self.object = object
self.attributes = self.getAttributes(object)
! # Define our rows
self.rowList = self.attributes.keys()
self.rowList.sort()
+ # Get rid of any old fields
+ for i in range(len(self.fields)):
+ field = self.fields.pop()
+ field.Destroy()
+ label = self.labels.pop()
+ label.Destroy()
+
# Only show properties for nondeprecated values (unless set)
i = 0
while i < len(self.rowList):
***************
*** 185,275 ****
else:
i = i + 1
-
- # Create the number of rows we'll need
- self.grid.InsertRows(0,len(self.rowList))
-
i = 0
for key in self.rowList:
xkey = key.replace(':','__')
! # This little tidbit does mixed case w/'_' as separators
! words = string.split(key.split(':',1)[-1],'_')
! for j in range(len(words)):
! words[j] = words[j].capitalize()
! self.grid.SetRowLabelValue(i,string.join(words,' '))
# Determine the type of Cell Editor we want
# (Integer, Boolean, Dropdown, Char)
if self.attributes[key].has_key('ValueSet'):
! self.grid.SetCellEditor(i, 0,
RestrictedCellEditor(self.grid,self.attributes[key]))
elif self.attributes[key]['Typecast'] == GTypecast.boolean:
! self.grid.SetCellEditor(i, 0,
BoolCellEditor(self.grid,self.attributes[key]))
elif self.attributes[key]['Typecast'] in (GTypecast.integer,
GTypecast.number, GTypecast.whole):
! self.grid.SetCellEditor(i, 0,
IntCellEditor(self.grid,self.attributes[key]))
else:
! self.grid.SetCellEditor(i, 0,
CharCellEditor(self.grid,self.attributes[key]))
# Set the initial value of the cells to the current property values
if hasattr(object, xkey):
! if self.attributes[key]['Typecast'] == GTypecast.boolean:
! if object.__dict__[xkey]:
! self.grid.SetCellValue(i,0,"TRUE")
! else:
! self.grid.SetCellValue(i,0,"FALSE")
! pass
! else:
! self.grid.SetCellValue(i,0, "%s" % object.__dict__[xkey])
! pass
! i = i + 1
! # Redraw the grid
! self.grid.EndBatch()
! try:
! self.grid.ForceRefresh() # Added in 2.3.1
! except AttributeError:
! pass
def getPageText(self):
return self.object._type[2:]
! def onSize(self, event):
! self.grid.SetSize(self.GetClientSize())
! w,h = self.grid.GetClientSizeTuple()
! self.grid.SetColSize(0, w - self.grid.GetRowLabelSize()-1)
! try:
! self.grid.ForceRefresh() # Added in 2.3.1
! except AttributeError:
! pass
!
!
! # Force a grid cell into Edit mode when Double-Clicked
! def OnLeftDClick(self,evt):
! if self.grid.CanEnableCellControl():
! self.grid.EnableCellEditControl()
!
! def OnCellChange(self, evt):
! attr = self.rowList[evt.GetRow()]
! value = self.grid.GetCellValue(evt.GetRow(), evt.GetCol())
xkey = attr.replace(':','__')
try:
try:
! oldVal = {attr: self.object.__dict__[xkey]}
except KeyError:
! oldVal = {attr: None}
! self.object.__dict__[xkey] = self.attributes[attr]['Typecast'](value)
! newVal = {attr: self.object.__dict__[xkey]}
! self.editor.dispatchEvent('ObjectModified',
object=self.object,
originator=__name__,
old=oldVal,
new=newVal)
! evt.Skip()
except ValueError:
wxBell()
--- 183,444 ----
else:
i = i + 1
i = 0
+ y = 2
+ maxLabel = 0
for key in self.rowList:
xkey = key.replace(':','__')
! # If an attribute has a "Label", use it;
! # otherwise create one from its name.
! try:
! text = self.attributes[key]['Label']
! except KeyError:
! # This little tidbit does mixed case w/'_' as separators
! words = string.split(key.split(':',1)[-1],'_')
! for j in range(len(words)):
! words[j] = words[j].capitalize()
! text = string.join(words)
!
! if self.attributes[key]['Typecast'] == GTypecast.boolean:
! text += _('?')
! else:
! text += ':'
+ label = wxStaticText(self.labelPanel, -1, text)
# Determine the type of Cell Editor we want
# (Integer, Boolean, Dropdown, Char)
if self.attributes[key].has_key('ValueSet'):
! field = LimitedSetEditor(self.fieldPanel,self.attributes[key])
elif self.attributes[key]['Typecast'] == GTypecast.boolean:
! field = BoolEditor(self.fieldPanel,self.attributes[key])
elif self.attributes[key]['Typecast'] in (GTypecast.integer,
GTypecast.number, GTypecast.whole):
! field = IntEditor(self.fieldPanel,self.attributes[key])
else:
! field = TextEditor(self.fieldPanel,self.attributes[key])
!
! EVT_KILL_FOCUS(field, self.__valueModified)
! EVT_KEY_UP(field, self.__enterPressed)
!
! # Align the centers of the field and label
! fx, fy = field.GetSizeTuple()
! lx, ly = label.GetSizeTuple()
! maxy = max(fy, ly)
! maxLabel = max(maxLabel, lx+4)
! field.SetPosition((2, int((maxy - fy)/2) + y))
! label.SetPosition((4, int((maxy - ly)/2) + y))
!
! # Next y...
! y += maxy
# Set the initial value of the cells to the current property values
if hasattr(object, xkey):
! field.SetValue(object.__dict__[xkey])
! self.fields.append(field)
! self.labels.append(label)
!
! self.splitter.SetSashPosition(maxLabel+2)
! self.maxy = y
! self.maxLabel = maxLabel
! self.__onSize(None)
def getPageText(self):
return self.object._type[2:]
! def __onSize(self, event):
! x, y = self.GetClientSizeTuple()
! my = max(y, self.maxy)
! self.splitter.SetSize((x, my ))
! self.splitter.SetSashPosition(self.maxLabel+2)
! self.SetVirtualSize((x, my))
! if my > y:
! self.SetScrollRate(0,10)
! fw = self.fieldPanel.GetSize().x - 4
! for field in self.fields:
! field.SetSize((fw, field.GetSize().y))
!
! def __enterPressed(self, event):
! if event.GetKeyCode() == WXK_RETURN:
! self.__valueModified(event)
! event.Skip()
!
! def __valueModified(self, event):
! field = event.GetEventObject()
! attr = self.rowList[self.fields.index(field)]
! value = field.GetValue()
xkey = attr.replace(':','__')
try:
try:
! ov = self.object.__dict__[xkey]
except KeyError:
! ov = None
!
! oldVal = {attr: ov}
!
! if ov != value:
! # If value is None, then user basically selected "No value"
! if value != None:
! # Typecast the value, then store in the object's dictionary
! value = self.attributes[attr]['Typecast'](value)
! else:
! # No value... try to set value as "default" value
! try:
! value = self.attributes[attr]['Default']
! except KeyError:
! # Otherwise leave as None
! pass
!
! self.object.__dict__[xkey] = value
! newVal = {attr: value}
!
! self.editor.dispatchEvent('ObjectModified',
object=self.object,
originator=__name__,
old=oldVal,
new=newVal)
!
except ValueError:
wxBell()
+
+ event.Skip()
+
+
+ #
+ # Property Editor derived from an attribute's ValueSet
+ #
+ class LimitedSetEditor(wxComboBox):
+ def __init__(self, parent, attributes):
+ wxComboBox.__init__(self, parent, -1,
+ style=wxTE_PROCESS_ENTER|wxCB_DROPDOWN|wxCB_READONLY)
+ self.attributes = attributes
+ self.selectionList = []
+
+ try:
+ default = self.attributes['Default']
+ except KeyError:
+ default = None
+
+
+ if not (attributes.has_key('Required') and attributes['Required'] ):
+ self.selectionList.append(None)
+ self.Append('')
+
+ # Sort the attribute names...
+ keys = attributes['ValueSet'].keys()
+ keys.sort()
+
+ # .. but make the default always come first
+ if default:
+ print default
+ print keys
+ keys.remove(default)
+ keys.insert(0, default)
+
+ # Add attributes to the combo box
+ for v in keys:
+ self.selectionList.append(v)
+ try:
+ text = attributes['ValueSet'][v]['Label']
+ except KeyError:
+ text = v
+ self.Append("%s%s" % (text, v == default and '*' or '' ))
+
+ def GetValue(self):
+ return self.selectionList[self.GetSelection()]
+
+ def SetValue(self, value):
+ self.SetSelection(self.selectionList.index(value))
+
+
+ #
+ # Property Editor whose selections are linked to lists of other objects
+ #
+ class LinkedTextEditor(wxComboBox):
+ def __init__(self, parent, attributes, objectList, forceToList=1):
+ wxComboBox.__init__(self, parent, -1,
+ style=wxTE_PROCESS_ENTER|wxCB_DROPDOWN|(forceToList and
wxCB_READONLY)|wxCB_SORT)
+ self.attributes = attributes
+ self.updateList()
+ try:
+ objectList.addListener(self.updateList)
+ except AttributeError:
+ pass
+
+ def Destroy(self):
+ try:
+ objectList.removeListener(self.updateList)
+ except:
+ pass
+ wxComboBox.Destroy(self)
+
+ def GetValue(self):
+ return wxComboBox.GetValue(self) or None
+
+ def updateList(self):
+ self.Clear()
+ if not (self.attributes.has_key('Required') and
self.attributes['Required'] ):
+ self.Append('')
+ for v in objectList:
+ self.Append("%s" % (self.attributes['ValueSet'][v] or v))
+
+ #
+ # Property editor for boolean types
+ #
+ class BoolEditor(wxComboBox):
+ def __init__(self, parent, attributes):
+ wxComboBox.__init__(self, parent, -1,
+ style=wxTE_PROCESS_ENTER|wxCB_DROPDOWN|wxCB_READONLY|wxCB_SORT)
+ self.attributes = attributes
+
+ if not (self.attributes.has_key('Required') and
self.attributes['Required'] ):
+ self.Append('')
+
+ try:
+ default = self.attributes['Default']
+ except KeyError:
+ default = None
+
+ self.true = _('Yes') + (default and '*' or '')
+ self.false = _('No') + (not default and '*' or '')
+
+ self.Append(self.true)
+ self.Append(self.false)
+
+
+ def GetValue(self):
+ v = wxComboBox.GetValue(self)
+ if v == '':
+ return None
+ else:
+ return v == self.true
+
+ def SetValue(self, value):
+ if value == None:
+ wxComboBox.SetValue(self,'')
+ elif value:
+ wxComboBox.SetValue(self,self.true)
+ else:
+ wxComboBox.SetValue(self,self.false)
+
+ #
+ #
+ #
+ class IntEditor(wxSpinCtrl):
+ def __init__(self, parent, attributes):
+ wxSpinCtrl.__init__(self, parent, -1, style=wxTE_PROCESS_ENTER)
+ self.attributes = attributes
+
+ #
+ #
+ #
+ class TextEditor(wxTextCtrl):
+ def __init__(self, parent, attributes):
+ wxTextCtrl.__init__(self, parent, -1, style=wxTE_PROCESS_ENTER)
+ self.attributes = attributes
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/designer/src/base/tools PropertyEditor.py,
Jason Cater <=