diff --git a/demo/PropertyGrid.py b/demo/PropertyGrid.py index d35bd671..5e5fa2ca 100644 --- a/demo/PropertyGrid.py +++ b/demo/PropertyGrid.py @@ -77,8 +77,8 @@ class IntProperty2(wxpg.PGProperty): """ return "IntProperty2" - def GetEditor(self): - return "TextCtrl" + def DoGetEditorClass(self): + return wxpg.PropertyGridInterface.GetEditorByName("TextCtrl") def ValueToString(self, value, flags): return str(value) @@ -136,8 +136,8 @@ class SizeProperty(wxpg.PGProperty): def GetClassName(self): return self.__class__.__name__ - def GetEditor(self): - return "TextCtrl" + def DoGetEditorClass(self): + return wxpg.PropertyGridInterface.GetEditorByName("TextCtrl") def RefreshChildren(self): size = self.m_value @@ -174,29 +174,41 @@ class DirsProperty(wxpg.ArrayStringProperty): """ def __init__(self, label, name = wxpg.PG_LABEL, value=[]): wxpg.ArrayStringProperty.__init__(self, label, name, value) - + self.m_display = '' # Set default delimiter self.SetAttribute("Delimiter", ',') - def GetEditor(self): - return "TextCtrlAndButton" + + # NOTE: In the Classic version of the propgrid classes, all of the wrapped + # property classes override DoGetEditorClass so it calls GetEditor and + # looks up the class using that name, and hides DoGetEditorClass from the + # usable API. Jumping through those hoops is no longer needed in Phoenix + # as Phoenix allows overriding all necessary virtual methods without + # special support in the wrapper code, so we just need to override + # DoGetEditorClass here instead. + def DoGetEditorClass(self): + return wxpg.PropertyGridInterface.GetEditorByName("TextCtrlAndButton") + def ValueToString(self, value, flags): + # let's just use the cached display value return self.m_display + def OnSetValue(self): self.GenerateValueAsString() + def DoSetAttribute(self, name, value): retval = super(DirsProperty, self).DoSetAttribute(name, value) - # # Must re-generate cached string when delimiter changes if name == "Delimiter": self.GenerateValueAsString(delim=value) return retval + def GenerateValueAsString(self, delim=None): """ This function creates a cached version of displayed text (self.m_display). @@ -213,6 +225,7 @@ class DirsProperty(wxpg.ArrayStringProperty): text = ', '.join(ls) self.m_display = text + def StringToValue(self, text, argFlags): """ If failed, return False or (False, None). If success, return tuple (True, newValue). @@ -224,6 +237,7 @@ class DirsProperty(wxpg.ArrayStringProperty): v = [a.strip() for a in text.split(delim)] return (True, v) + def OnEvent(self, propgrid, primaryEditor, event): if event.GetEventType() == wx.wxEVT_COMMAND_BUTTON_CLICKED: dlg = wx.DirDialog(propgrid, @@ -249,6 +263,7 @@ class DirsProperty(wxpg.ArrayStringProperty): return False + class PyObjectPropertyValue: """\ Value type of our sample PyObjectProperty. We keep a simple dash-delimited @@ -380,9 +395,8 @@ class SingleChoiceProperty(wxpg.StringProperty): self.dialog_choices = dialog_choices - def GetEditor(self): - # Set editor to have button - return "TextCtrlAndButton" + def DoGetEditorClass(self): + return wxpg.PropertyGridInterface.GetEditorByName("TextCtrlAndButton") def GetEditorDialog(self): # Set what happens on button click diff --git a/docs/MigrationGuide.rst b/docs/MigrationGuide.rst index e3165587..49889f78 100644 --- a/docs/MigrationGuide.rst +++ b/docs/MigrationGuide.rst @@ -531,6 +531,26 @@ confident that you'll be much happier with this approach. +Property Grid +------------- + +In Classic, custom classes derived from ``wx.propgrid.PGProperty`` could +specify which editor to use by providing a ``GetEditor`` method that returned a +string. This method does not exist in C++, and was hacked in to the Python +wrapper classes in order to remove or simplify other wrapper related problems. + +Those problems are no longer present in Phoenix and so it is easiest to go +back to the way C++ handles selecting the cell editor and avoid needing to +awkwardly kludge things together in order to maintain full compatibility. If +you have a property class that implements the ``GetEditor`` method then adding +the following method to your property class will enable the propgrid to fetch +the editor instance properly:: + + def DoGetEditorClass(self): + return wx.propgrid.PropertyGridInterface.GetEditorByName(self.GetEditor()) + + + .. toctree:: :maxdepth: 2 :hidden: