From 6e5f3546c234549f0f9f4dfb5da6fb80e50f6d52 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 12:33:36 -0700 Subject: [PATCH 1/8] Add call to wxPGInitResourceModule so propgrid globals are initialized when the module is imported. --- etg/_propgrid.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etg/_propgrid.py b/etg/_propgrid.py index b8fc5e12..8dcbb8e0 100644 --- a/etg/_propgrid.py +++ b/etg/_propgrid.py @@ -66,6 +66,9 @@ def run(): module.addInclude(INCLUDES) + module.addInitializerCode("""\ + wxPGInitResourceModule(); + """) #----------------------------------------------------------------- tools.doCommonTweaks(module) From dc8f1a87ebcb09fdb60f8368b69f20f416f311ae Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 12:54:56 -0700 Subject: [PATCH 2/8] Add AddButton and AddBitmapButton to PGMultiButton --- etg/propgrideditors.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/etg/propgrideditors.py b/etg/propgrideditors.py index ef7dc83d..09be8c57 100644 --- a/etg/propgrideditors.py +++ b/etg/propgrideditors.py @@ -44,6 +44,13 @@ def run(): assert isinstance(c, etgtools.ClassDef) tools.fixWindowClass(c) + c.addPyMethod('AddButton', '(self, label, id=-2)', + doc='A simple wrapper around the PGMultiButton.Add method, for backwards compatibility.', + body="self.Add(label, id)") + + c.addPyMethod('AddBitmapButton', '(self, bitmap, id=-2)', + doc='A simple wrapper around the PGMultiButton.Add method, for backwards compatibility.', + body="self.Add(bitmap, id)") # Switch all wxVariant types to wxPGVariant, so the propgrid-specific # version of the MappedType will be used for converting to/from Python From 105642c6c504d8a4a35a8cab75ef18ef2116d92f Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 13:31:46 -0700 Subject: [PATCH 3/8] Also transfer ownership of the editor arg for RegisterEditorClass --- etg/propgrid.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/etg/propgrid.py b/etg/propgrid.py index 530aea03..df404358 100644 --- a/etg/propgrid.py +++ b/etg/propgrid.py @@ -44,8 +44,9 @@ def run(): tools.fixWindowClass(c) module.addGlobalStr('wxPropertyGridNameStr', c) - for m in c.find('RegisterEditorClass').all(): - m.find('editor').transfer = True + for name in ['RegisterEditorClass', 'DoRegisterEditorClass']: + for m in c.find(name).all(): + m.find('editor').transfer = True # TODO: provide a way to use a Python callable as a sort function From d3dc961f844c6946acc114a0c44cbecb81421c8d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 13:52:54 -0700 Subject: [PATCH 4/8] Add some missing constants --- etg/propgrid.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/etg/propgrid.py b/etg/propgrid.py index df404358..d1094cff 100644 --- a/etg/propgrid.py +++ b/etg/propgrid.py @@ -101,6 +101,13 @@ def run(): EVT_PG_COL_END_DRAG = wx.PyEventBinder( wxEVT_PG_COL_END_DRAG, 1 ) """) + module.addItem(etgtools.WigCode("""\ + enum { + wxPG_SUBID1, + wxPG_SUBID2, + wxPG_SUBID_TEMP1, + }; + """)) # Switch all wxVariant types to wxPGVariant, so the propgrid-specific # version of the MappedType will be used for converting to/from Python From 1b725ef4ca822084b3b9cc7c325d85d82943ab02 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 15:29:17 -0700 Subject: [PATCH 5/8] Tweak PGEditor.GetValueFromControl.variant to be an output parameter, and also modify the virtual handler code so it works the same way --- etg/propgrideditors.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/etg/propgrideditors.py b/etg/propgrideditors.py index 09be8c57..88263b77 100644 --- a/etg/propgrideditors.py +++ b/etg/propgrideditors.py @@ -40,6 +40,31 @@ def run(): # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. + + c = module.find('wxPGEditor') + assert isinstance(c, etgtools.ClassDef) + + # Change the method to return the value instead of passing it + # through a parameter for modification. + m = c.find('GetValueFromControl') + m.find('variant').out = True + + # Change the virtual method handler code to follow the same pattern as the + # tweaked public API, namely that the value is the return value instead of + # an out parameter. + m.cppSignature = 'bool (wxVariant& variant, wxPGProperty* property, wxWindow* ctrl)' + m.virtualCatcherCode = """\ + PyObject *sipResObj = sipCallMethod(0, sipMethod, "DDD", + property, sipType_wxPGProperty, NULL, + ctrl, sipType_wxWindow, NULL); + if (sipResObj == Py_None) { + sipRes = false; + } else { + sipParseResult(&sipIsErr, sipMethod, sipResObj, "bH5", &sipRes, sipType_wxPGVariant, &variant); + } + """ + + c = module.find('wxPGMultiButton') assert isinstance(c, etgtools.ClassDef) tools.fixWindowClass(c) From 9ceff621de570252d3fd489c196ed5bc87d0d065 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 15:29:51 -0700 Subject: [PATCH 6/8] Various propgrid demo fixes --- demo/PropertyGrid.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/demo/PropertyGrid.py b/demo/PropertyGrid.py index 6815e05a..e9946e4a 100644 --- a/demo/PropertyGrid.py +++ b/demo/PropertyGrid.py @@ -319,6 +319,7 @@ class SampleMultiButtonEditor(wxpg.PGTextCtrlEditor): property, pos, buttons.GetPrimarySize()) + wnd = wnd.m_primary # Finally, move buttons-subwindow to correct position and make sure # returned wxPGWindowList contains our custom button list. @@ -331,7 +332,7 @@ class SampleMultiButtonEditor(wxpg.PGTextCtrlEditor): # PGMultiButton instance. self.buttons = buttons - return (wnd, buttons) + return wxpg.PGWindowList(wnd, buttons) def OnEvent(self, propGrid, prop, ctrl, event): if event.GetEventType() == wx.wxEVT_COMMAND_BUTTON_CLICKED: @@ -429,7 +430,7 @@ class TrivialPropertyEditor(wxpg.PGEditor): btn = wx.Button(propgrid.GetPanel(), wxpg.PG_SUBID2, '...', (x+w, y), (bw, h), wx.WANTS_CHARS) - return (tc, btn) + return wxpg.PGWindowList(tc, btn) except: import traceback print(traceback.print_exc()) @@ -503,8 +504,7 @@ class LargeImagePickerCtrl(wx.Panel): Control created and used by LargeImageEditor. """ def __init__(self): - pre = wx.PrePanel() - self.PostCreate(pre) + wx.Panel.__init__(self) def Create(self, parent, id_, pos, size, style = 0): wx.Panel.Create(self, parent, id_, pos, size, @@ -586,18 +586,10 @@ class LargeImageEditor(wxpg.PGEditor): lipc.Hide() lipc.Create(propgrid.GetPanel(), wxpg.PG_SUBID1, (x,y), (w,h)) lipc.SetProperty(property) - # Hmmm.. how to have two-stage creation without subclassing? - #btn = wx.PreButton() - #pre = wx.PreWindow() - #self.PostCreate(pre) - #if sys.platform == 'win32': - # btn.Hide() - #btn.Create(propgrid, wxpg.PG_SUBID2, '...', (x2-bw,pos[1]), - # (bw,h), wx.WANTS_CHARS) btn = wx.Button(propgrid.GetPanel(), wxpg.PG_SUBID2, '...', (x+w, y), (bw, h), wx.WANTS_CHARS) - return (lipc, btn) + return wxpg.PGWindowList(lipc, btn) except: import traceback print(traceback.print_exc()) From a3af417f8ff4e77b84c87bcce7e08f0c9f25b3b1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 22:43:21 -0700 Subject: [PATCH 7/8] Fix the monkey-patch to use the new name of the real method --- wx/lib/mixins/listctrl.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/wx/lib/mixins/listctrl.py b/wx/lib/mixins/listctrl.py index 57b99413..d641ad15 100644 --- a/wx/lib/mixins/listctrl.py +++ b/wx/lib/mixins/listctrl.py @@ -698,7 +698,7 @@ HISTORY: 1.1 - Initial version """ -class CheckListCtrlMixin: +class CheckListCtrlMixin(object): """ This is a mixin for ListCtrl which add a checkbox in the first column of each row. It is inspired by limodou's CheckList.py(which @@ -738,8 +738,16 @@ class CheckListCtrlMixin: self.Bind(wx.EVT_LEFT_DOWN, self.__OnLeftDown_) - # override the default methods of ListCtrl/ListView - self.InsertStringItem = self.__InsertStringItem_ + # Monkey-patch in a new InsertItem so we can also set the image ID for the item + self._origInsertItem = self.InsertItem + self.InsertItem = self.__InsertItem_ + + + def __InsertItem_(self, *args, **kw): + index = self._origInsertItem(*args, **kw) + self.SetItemImage(index, self.uncheck_image) + return index + def __CreateBitmap(self, flag=0, size=(16, 16)): """Create a bitmap of the platforms native checkbox. The flag @@ -754,9 +762,6 @@ class CheckListCtrlMixin: dc.SelectObject(wx.NullBitmap) return bmp - def __InsertStringItem_(self, index, label): - index = self.InsertItem(index, label, 0) - return index def __OnLeftDown_(self, evt): (index, flags) = self.HitTest(evt.GetPosition()) From 8e1da1f2e0d155ea0004f7f99257a61502c046a0 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 22:46:35 -0700 Subject: [PATCH 8/8] Clear the bitmap with the white brush --- wx/lib/mixins/listctrl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wx/lib/mixins/listctrl.py b/wx/lib/mixins/listctrl.py index d641ad15..d52077f0 100644 --- a/wx/lib/mixins/listctrl.py +++ b/wx/lib/mixins/listctrl.py @@ -756,6 +756,7 @@ class CheckListCtrlMixin(object): """ bmp = wx.Bitmap(*size) dc = wx.MemoryDC(bmp) + dc.SetBackground(wx.WHITE_BRUSH) dc.Clear() wx.RendererNative.Get().DrawCheckBox(self, dc, (0, 0, size[0], size[1]), flag)