diff --git a/CHANGES.rst b/CHANGES.rst index 21e14cb9..8352c8c8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -57,9 +57,7 @@ Changes in this release include the following: * Fixes in TextEditMixin to ensure that the new value is passed in the event. (#605) - - - +* Fix comparing DataViewItem and TreeListItem objects with None. (#595) diff --git a/demo/DVC_CustomRenderer.py b/demo/DVC_CustomRenderer.py index d8e84ca4..d1f5307d 100644 --- a/demo/DVC_CustomRenderer.py +++ b/demo/DVC_CustomRenderer.py @@ -11,6 +11,7 @@ class MyCustomRenderer(dv.DataViewCustomRenderer): dv.DataViewCustomRenderer.__init__(self, *args, **kw) self.log = log self.value = None + self.EnableEllipsize(wx.ELLIPSIZE_END) def SetValue(self, value): @@ -18,17 +19,22 @@ class MyCustomRenderer(dv.DataViewCustomRenderer): self.value = value return True + def GetValue(self): - self.log.write('GetValue') + self.log.write('GetValue: {}'.format(value)) return self.value + def GetSize(self): # Return the size needed to display the value. The renderer # has a helper function we can use for measuring text that is # aware of any custom attributes that may have been set for # this item. value = self.value if self.value else "" - return self.GetTextExtent(value) + size = self.GetTextExtent(value) + size += (2,2) + #self.log.write('GetSize("{}"): {}'.format(value, size)) + return size def Render(self, rect, dc, state): @@ -38,17 +44,17 @@ class MyCustomRenderer(dv.DataViewCustomRenderer): if not state & dv.DATAVIEW_CELL_SELECTED: # we'll draw a shaded background to see if the rect correctly # fills the cell - dc.SetBrush(wx.Brush('light grey')) + dc.SetBrush(wx.Brush('#ffd0d0')) dc.SetPen(wx.TRANSPARENT_PEN) rect.Deflate(1, 1) dc.DrawRoundedRectangle(rect, 2) # And then finish up with this helper function that draws the # text for us, dealing with alignment, font and color - # attributes, etc + # attributes, etc. value = self.value if self.value else "" self.RenderText(value, - 4, # x-offset, to compensate for the rounded rectangles + 0, # x-offset rect, dc, state # wxDataViewCellRenderState flags @@ -56,10 +62,19 @@ class MyCustomRenderer(dv.DataViewCustomRenderer): return True + def ActivateCell(self, rect, model, item, col, mouseEvent): + self.log.write("ActivateCell") + return False + + # The HasEditorCtrl, CreateEditorCtrl and GetValueFromEditorCtrl # methods need to be implemented if this renderer is going to # support in-place editing of the cell value, otherwise they can # be omitted. + # + # NOTE: This is well supported only in the DVC implementation on Windows, + # so this sample will not turn on the editable mode for the custom + # rendered column, see below. def HasEditorCtrl(self): self.log.write('HasEditorCtrl') @@ -131,24 +146,41 @@ class TestPanel(wx.Panel): self.dvc.AssociateModel(self.model) # Now we create some columns. - c0 = self.dvc.AppendTextColumn("Id", 0, width=40) - c0.Alignment = wx.ALIGN_RIGHT - c0.MinWidth = 40 + col = self.dvc.AppendTextColumn("Id", 0, width=40) + col.Alignment = wx.ALIGN_RIGHT + col.MinWidth = 40 - # We'll use our custom renderer for these columns - for title, col, width in [ ('Artist', 1, 170), - ('Title', 2, 260), - ('Genre', 3, 80)]: - renderer = MyCustomRenderer(self.log, mode=dv.DATAVIEW_CELL_EDITABLE) - #renderer.SetMode(dv.DATAVIEW_CELL_EDITABLE) - column = dv.DataViewColumn(title, renderer, col, width=width) - column.Alignment = wx.ALIGN_LEFT - self.dvc.AppendColumn(column) + col = self.dvc.AppendTextColumn("Artist", 1, width=170, mode=dv.DATAVIEW_CELL_EDITABLE) + col.Alignment = wx.ALIGN_LEFT + + # Use a custom renderer for the Title column. + # NOTE: Using an editor with the custom renderer is only well + # supported on the Windows version of the DVC, so we won't turn on + # editing in that case, and will inform the user about it. + if 'wxMSW' in wx.PlatformInfo: + custMode = dv.DATAVIEW_CELL_EDITABLE + else: + custMode = dv.DATAVIEW_CELL_INERT + wx.CallAfter(self.ShowMessage) + renderer = MyCustomRenderer(self.log, mode=custMode) + col = dv.DataViewColumn("Title", renderer, 2, width=260) + col.Alignment = wx.ALIGN_LEFT + self.dvc.AppendColumn(col) + + + col = self.dvc.AppendTextColumn("Genre", 3, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) + col.Alignment = wx.ALIGN_LEFT self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) + def ShowMessage(self): + msg = "This platform does not have good support for editing cells " \ + "which have a custom renderer, so the Title column's mode " \ + "will be set to DATAVIEW_CELL_INERT instead." + wx.MessageBox(msg, "Custom Renderer Info", style=wx.OK|wx.ICON_INFORMATION) + #---------------------------------------------------------------------- diff --git a/etg/dataview.py b/etg/dataview.py index 0c1e98e2..c0be8351 100644 --- a/etg/dataview.py +++ b/etg/dataview.py @@ -251,9 +251,14 @@ def run(): _fixupBoolGetters(c.find(name), sig) m = c.find('SetValue') - m.find('value').type = 'wxDVCVariant&' + m.find('value').type = 'const wxDVCVariant&' m.cppSignature = 'bool (const wxVariant& value)' + m = c.find('CreateEditorCtrl') + m.cppSignature = 'wxWindow* (wxWindow * parent, wxRect labelRect, const wxVariant& value)' + + c.find('GetView').ignore(False) + c = module.find('wxDataViewCustomRenderer') @@ -275,6 +280,9 @@ def run(): c.find('GetTextExtent').ignore(False) + m = c.find('CreateEditorCtrl') + m.cppSignature = 'wxWindow* (wxWindow * parent, wxRect labelRect, const wxVariant& value)' + module.addPyCode("""\ PyDataViewCustomRenderer = wx.deprecated(DataViewCustomRenderer, diff --git a/etg/treelist.py b/etg/treelist.py index 7fb30971..ea6cc859 100644 --- a/etg/treelist.py +++ b/etg/treelist.py @@ -51,9 +51,10 @@ def run(): return (long)self->GetID(); """) - c.addCppMethod('bool', '__eq__', '(wxTreeListItem* other)', "return (self->GetID() == other->GetID());") - c.addCppMethod('bool', '__ne__', '(wxTreeListItem* other)', "return (self->GetID() != other->GetID());") - + c.addCppMethod('bool', '__eq__', '(wxTreeListItem* other)', + "return other ? (self->GetID() == other->GetID()) : false;") + c.addCppMethod('bool', '__ne__', '(wxTreeListItem* other)', + "return other ? (self->GetID() != other->GetID()) : true;") #----------------------------------------------------------------- c = module.find('wxTreeListItemComparator')