Skip to content

Commit

Permalink
Merge branch 'master' into fix-issue605
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinD42 committed Nov 18, 2017
2 parents 9c253cf + 7feff93 commit b36669c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
4 changes: 1 addition & 3 deletions CHANGES.rst
Expand Up @@ -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)



Expand Down
68 changes: 50 additions & 18 deletions demo/DVC_CustomRenderer.py
Expand Up @@ -11,24 +11,30 @@ def __init__(self, log, *args, **kw):
dv.DataViewCustomRenderer.__init__(self, *args, **kw)
self.log = log
self.value = None
self.EnableEllipsize(wx.ELLIPSIZE_END)


def SetValue(self, value):
#self.log.write('SetValue: %s' % value)
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):
Expand All @@ -38,28 +44,37 @@ def Render(self, rect, dc, state):
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
)
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')
Expand Down Expand Up @@ -131,24 +146,41 @@ def __init__(self, parent, log, model=None, data=None):
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

# 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("Id", 0, width=40)
col.Alignment = wx.ALIGN_RIGHT
col.MinWidth = 40

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)


#----------------------------------------------------------------------

Expand Down
10 changes: 9 additions & 1 deletion etg/dataview.py
Expand Up @@ -251,9 +251,14 @@ def _fixupBoolGetters(method, sig):
_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')
Expand All @@ -275,6 +280,9 @@ def _fixupBoolGetters(method, sig):

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,
Expand Down
7 changes: 4 additions & 3 deletions etg/treelist.py
Expand Up @@ -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')
Expand Down

0 comments on commit b36669c

Please sign in to comment.