From 5c17aabf3a3db11e5f78439214f523d795faea51 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 31 Dec 2018 12:35:50 -0800 Subject: [PATCH 1/3] Added missing methods in wx.ListBox, SetItemForegroundColour, SetItemBackgroundColour and SetItemFont. --- CHANGES.rst | 3 +++ etg/listbox.py | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index eb01e7c4..b7ba4f17 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -151,6 +151,9 @@ Changes in this release include the following: anymore plastered right in the middle of the screen and can't be worked with easily and ESC now cancels the popup with a proper returnId. (#1096) +* Added missing methods in wx.ListBox, SetItemForegroundColour, + SetItemBackgroundColour and SetItemFont. (#1095) + diff --git a/etg/listbox.py b/etg/listbox.py index 56427506..7c2e0706 100644 --- a/etg/listbox.py +++ b/etg/listbox.py @@ -33,6 +33,8 @@ def run(): # customizing the generated code and docstrings. c = module.find('wxListBox') + assert isinstance(c, etgtools.ClassDef) + c.find('wxListBox').findOverload('wxString choices').ignore() c.find('wxListBox').findOverload('wxArrayString').find('choices').default = 'wxArrayString()' @@ -55,8 +57,41 @@ def run(): c.find('InsertItems').findOverload('wxString *items').ignore() - tools.fixWindowClass(c) + c.addCppMethod('void', 'SetItemForegroundColour', '(int item, const wxColour& c)', + doc="""\ + Set the foreground colour of an item in the ListBox. + Only valid on MSW and if the ``wx.LB_OWNERDRAW`` flag is set.""", + body="""\ + #ifdef __WXMSW__ + if (self->GetWindowStyle() & wxLB_OWNERDRAW) + self->GetItem(item)->SetTextColour(c); + #endif + """) + c.addCppMethod('void', 'SetItemBackgroundColour', '(int item, const wxColour& c)', + doc="""\ + Set the background colour of an item in the ListBox. + Only valid on MSW and if the ``wx.LB_OWNERDRAW`` flag is set.""", + body="""\ + #ifdef __WXMSW__ + if (self->GetWindowStyle() & wxLB_OWNERDRAW) + self->GetItem(item)->SetBackgroundColour(c); + #endif + """) + + c.addCppMethod('void', 'SetItemFont', '(int item, const wxColour& c)', + doc="""\ + Set the font of an item in the ListBox. + Only valid on MSW and if the ``wx.LB_OWNERDRAW`` flag is set.""", + body="""\ + #ifdef __WXMSW__ + if (self->GetWindowStyle() & wxLB_OWNERDRAW) + self->GetItem(item)->SetFont(f); + #endif + """) + + + tools.fixWindowClass(c) module.addGlobalStr('wxListBoxNameStr', c) #----------------------------------------------------------------- From 1783ea6fd1008d5e2816a3af8b073509279fa236 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 31 Dec 2018 14:09:58 -0800 Subject: [PATCH 2/3] Use pointers for the parameter types --- etg/listbox.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/etg/listbox.py b/etg/listbox.py index 7c2e0706..826b3dc7 100644 --- a/etg/listbox.py +++ b/etg/listbox.py @@ -57,36 +57,36 @@ def run(): c.find('InsertItems').findOverload('wxString *items').ignore() - c.addCppMethod('void', 'SetItemForegroundColour', '(int item, const wxColour& c)', + c.addCppMethod('void', 'SetItemForegroundColour', '(int item, const wxColour* c)', doc="""\ Set the foreground colour of an item in the ListBox. Only valid on MSW and if the ``wx.LB_OWNERDRAW`` flag is set.""", body="""\ #ifdef __WXMSW__ if (self->GetWindowStyle() & wxLB_OWNERDRAW) - self->GetItem(item)->SetTextColour(c); + self->GetItem(item)->SetTextColour(*c); #endif """) - c.addCppMethod('void', 'SetItemBackgroundColour', '(int item, const wxColour& c)', + c.addCppMethod('void', 'SetItemBackgroundColour', '(int item, const wxColour* c)', doc="""\ Set the background colour of an item in the ListBox. Only valid on MSW and if the ``wx.LB_OWNERDRAW`` flag is set.""", body="""\ #ifdef __WXMSW__ if (self->GetWindowStyle() & wxLB_OWNERDRAW) - self->GetItem(item)->SetBackgroundColour(c); + self->GetItem(item)->SetBackgroundColour(*c); #endif """) - c.addCppMethod('void', 'SetItemFont', '(int item, const wxColour& c)', + c.addCppMethod('void', 'SetItemFont', '(int item, const wxFont* f)', doc="""\ Set the font of an item in the ListBox. Only valid on MSW and if the ``wx.LB_OWNERDRAW`` flag is set.""", body="""\ #ifdef __WXMSW__ if (self->GetWindowStyle() & wxLB_OWNERDRAW) - self->GetItem(item)->SetFont(f); + self->GetItem(item)->SetFont(*f); #endif """) From 5dd7b81e7e5666113701ea237801ac5baeb2350d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 31 Dec 2018 14:16:24 -0800 Subject: [PATCH 3/3] Add example of setting item colours to the demo sample --- demo/ListBox.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/demo/ListBox.py b/demo/ListBox.py index 00538741..dec1eba1 100644 --- a/demo/ListBox.py +++ b/demo/ListBox.py @@ -77,7 +77,7 @@ class TestListBox(wx.Panel): wx.StaticText(self, -1, "This example uses the wx.ListBox control.", (45, 10)) wx.StaticText(self, -1, "Select one:", (15, 50)) - self.lb1 = wx.ListBox(self, 60, (100, 50), (90, 120), sampleList, wx.LB_SINGLE) + self.lb1 = wx.ListBox(self, 60, (100, 50), (90, 120), sampleList, wx.LB_SINGLE|wx.LB_OWNERDRAW) self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.lb1) self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.lb1) self.lb1.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton) @@ -85,6 +85,9 @@ class TestListBox(wx.Panel): self.lb1.Append("with data", "This one has data"); self.lb1.SetClientData(2, "This one has data"); + # These only work on Windows + self.lb1.SetItemBackgroundColour(1, "green") + self.lb1.SetItemForegroundColour(2, "red") wx.StaticText(self, -1, "Select many:", (220, 50)) self.lb2 = wx.ListBox(self, 70, (320, 50), (90, 120), sampleList, wx.LB_EXTENDED)