Capability needed: list-control functionality with the ability to ...

19 views
Skip to first unread message

Bob Klahn

unread,
Mar 21, 2017, 9:52:08 PM3/21/17
to wxPython users
... use color within individual list entries.  E.g., one entry might be INCREDIBLE, and another in the same list might be MONDEGREEN .

Any ideas, any suggestions?

Andrea Gavana

unread,
Mar 22, 2017, 1:01:44 AM3/22/17
to wxpytho...@googlegroups.com
Hi Bob,

On Wed, 22 Mar 2017 at 02:52, Bob Klahn <bobk...@comcast.net> wrote:
... use color within individual list entries.  E.g., one entry might be INCREDIBLE, and another in the same list might be MONDEGREEN .

Any ideas, any suggestions?



UltimateListCtrl with a custom renderer should probably do the trick. I believe the demo has something similar.

Andrea.




--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bob Klahn

unread,
Mar 22, 2017, 10:14:22 AM3/22/17
to wxpytho...@googlegroups.com
Hi Andrea,

I've looked at the UltimateListCtrl demo, and have Googled it a bit, but I see no examples in which a =single= item can have multiple colors, as in my black-and-red and black-and-green examples below.

I need to be able to present, in a list control, vocabulary items which contain specific character strings, with those character strings highlighted.

You've created a lot of very useful controls.  If what I need does not yet exist, might you be able to create what's needed?  Presumably as a mod to UltimateListControl, or a mix-in, rather than a new control.

Bob


On 3/22/2017 1:01 AM, Andrea Gavana wrote:

Andrea Gavana

unread,
Mar 22, 2017, 10:43:10 AM3/22/17
to wxPython-users
Hi,

On 22 March 2017 at 15:14, Bob Klahn <bobk...@comcast.net> wrote:
Hi Andrea,

I've looked at the UltimateListCtrl demo, and have Googled it a bit, but I see no examples in which a =single= item can have multiple colors, as in my black-and-red and black-and-green examples below.

I need to be able to present, in a list control, vocabulary items which contain specific character strings, with those character strings highlighted.

You've created a lot of very useful controls.  If what I need does not yet exist, might you be able to create what's needed?  Presumably as a mod to UltimateListControl, or a mix-in, rather than a new control.


There is, in the demo. If you look at the UltimateReportDemo.py, there are a few lines of code like:

            randomRenderer = random.randint(0, 2)
            if randomRenderer == 2:
                # set some custom renderers...
                klass = UltimateRenderer_1(self)
                renderers[index] = klass
                self.list.SetItemCustomRenderer(index, 3, klass)
            elif randomRenderer == 1:
                klass = UltimateRenderer_2(self)
                self.list.SetItemCustomRenderer(index, 3, klass)
            else:
                klass = UltimateRenderer_3()
                self.list.SetItemCustomRenderer(index, 3, klass)

UltimateRenderer_2 is the class you want. Looking at how that class implements its DrawSubItem method:

    def DrawSubItem(self, dc, rect, line, highlighted, enabled):
        
        dc.SetBackgroundMode(wx.SOLID)
        dc.SetBrush(wx.Brush(wx.BLACK, wx.SOLID))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangleRect(rect)

        dc.SetBackgroundMode(wx.TRANSPARENT)        
        dc.SetFont(self.randomFont)

        colours = [wx.RED, wx.WHITE, wx.GREEN, wx.NamedColour("SKY BLUE")]
        w, h = dc.GetTextExtent("Hg")
        x = rect.x + 1
        y = rect.y + rect.height/2 - h/2

        for ch in self.text:
            dc.SetTextForeground(random.choice(colours))
            dc.DrawText(ch, x, y)
            w, h = dc.GetTextExtent(ch)
            x = x + w
            if x > rect.right - 5:
                break

You can easily see that, for each character in the string "self.text" it chooses a random color and draws that letter. I believe it would be quite easy to modify that class to do what you want.

Andrea.

 


Bob


On 3/22/2017 1:01 AM, Andrea Gavana wrote:
Hi Bob,

On Wed, 22 Mar 2017 at 02:52, Bob Klahn <bobk...@comcast.net> wrote:
... use color within individual list entries.  E.g., one entry might be INCREDIBLE, and another in the same list might be MONDEGREEN .

Any ideas, any suggestions?


UltimateListCtrl with a custom renderer should probably do the trick. I believe the demo has something similar.

Andrea.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

Chris Barker - NOAA Federal

unread,
Mar 22, 2017, 11:10:03 AM3/22/17
to wxpytho...@googlegroups.com
Awesome use of the time machine, Andrea!

-CHB
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

Bob Klahn

unread,
Mar 22, 2017, 11:17:42 AM3/22/17
to wxpytho...@googlegroups.com
Thank you very much, Andrea!  The copy of the UltimateListCtrl demo I have is quite old, and the super-helpful code you've just cited is not part of it.  I'd like to install the current demo package on my new 64-bit machine, but I haven't yet figure out how to do so.  Rightly or wrongly, I'm afraid to try running the 32-bit installer, wxPython3.0-win32-docs-demos.exe, the only installer listed at https://wxpython.org/download.php .  Is my "fear" unfounded? 

Bob
Hi,

On 3/22/2017 1:01 AM, Andrea Gavana wrote:

Andrea Gavana

unread,
Mar 22, 2017, 11:20:43 AM3/22/17
to wxPython-users
On 22 March 2017 at 16:17, Bob Klahn <bobk...@comcast.net> wrote:
Thank you very much, Andrea!  The copy of the UltimateListCtrl demo I have is quite old, and the super-helpful code you've just cited is not part of it.  I'd like to install the current demo package on my new 64-bit machine, but I haven't yet figure out how to do so.  Rightly or wrongly, I'm afraid to try running the 32-bit installer, wxPython3.0-win32-docs-demos.exe, the only installer listed at https://wxpython.org/download.php .  Is my "fear" unfounded? 

It is. The 32-bit installer for the demo works without issues on any Windows architecture. As Mike (and quite a few others) said, the installer simply creates a few folders in the path you choose and copies there the demo files (which are Python files). No risk whatsoever.

Andrea.

 
Reply all
Reply to author
Forward
0 new messages