wxpython listbox help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shuf
    New Member
    • Mar 2007
    • 8

    #1

    wxpython listbox help

    Hello,

    I am running python 2.4.4 with wxpython 2.6 on Fedora 6. I am trying to set the font color of individual elements in a listbox, but I am not able to with SetItemForegrou ndColour() (this method does not appear to do anything):

    Code:
    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    # generated by wxGlade 0.4.1 on Thu Mar 22 12:15:29 2007
    
    import wx
    
    class MyFrame(wx.Frame):
        def __init__(self, *args, **kwds):
            # begin wxGlade: MyFrame.__init__
            kwds["style"] = wx.DEFAULT_FRAME_STYLE
            wx.Frame.__init__(self, *args, **kwds)
            self.list_box_1 = wx.ListBox(self, -1, choices=["One", "Two"])
    
            self.__set_properties()
            self.__do_layout()
    
            self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list_box_1)
            # end wxGlade
    
        def __set_properties(self):
            # begin wxGlade: MyFrame.__set_properties
            self.SetTitle("frame_1")
            self.list_box_1.SetSelection(0)
            # end wxGlade
    
        def __do_layout(self):
            # begin wxGlade: MyFrame.__do_layout
            sizer_1 = wx.BoxSizer(wx.VERTICAL)
            sizer_1.Add(self.list_box_1, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
            self.SetAutoLayout(True)
            self.SetSizer(sizer_1)
            sizer_1.Fit(self)
            sizer_1.SetSizeHints(self)
            self.Layout()
            # end wxGlade
    
        def OnSelect(self, event): # wxGlade: MyFrame.<event_handler>
            self.list_box_1.SetItemForegroundColour(0,wx.RED)
            self.list_box_1.SetItemForegroundColour(1,wx.BLUE)
    
    # end of class MyFrame
    
    
    if __name__ == "__main__":
        app = wx.PySimpleApp(0)
        wx.InitAllImageHandlers()
        frame_1 = MyFrame(None, -1, "")
        app.SetTopWindow(frame_1)
        frame_1.Show()
        app.MainLoop()
    However, I am able to set the font color of all the elements with SetForegroundCo lour(). I want to be able to have each color represent the current state of an element. I know that I can do this with a listctrl, but I wanted to try to do it with a listbox. Any help is greatly appreciated.

    Thanks in advance,
    Stephen
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by shuf
    Hello,

    I am running python 2.4.4 with wxpython 2.6 on Fedora 6. I am trying to set the font color of individual elements in a listbox, but I am not able to with SetItemForegrou ndColour() (this method does not appear to do anything):

    Code:
    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    # generated by wxGlade 0.4.1 on Thu Mar 22 12:15:29 2007
    
    import wx
    
    class MyFrame(wx.Frame):
        def __init__(self, *args, **kwds):
            # begin wxGlade: MyFrame.__init__
            kwds["style"] = wx.DEFAULT_FRAME_STYLE
            wx.Frame.__init__(self, *args, **kwds)
            self.list_box_1 = wx.ListBox(self, -1, choices=["One", "Two"])
    
            self.__set_properties()
            self.__do_layout()
    
            self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list_box_1)
            # end wxGlade
    
        def __set_properties(self):
            # begin wxGlade: MyFrame.__set_properties
            self.SetTitle("frame_1")
            self.list_box_1.SetSelection(0)
            # end wxGlade
    
        def __do_layout(self):
            # begin wxGlade: MyFrame.__do_layout
            sizer_1 = wx.BoxSizer(wx.VERTICAL)
            sizer_1.Add(self.list_box_1, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
            self.SetAutoLayout(True)
            self.SetSizer(sizer_1)
            sizer_1.Fit(self)
            sizer_1.SetSizeHints(self)
            self.Layout()
            # end wxGlade
    
        def OnSelect(self, event): # wxGlade: MyFrame.<event_handler>
            self.list_box_1.SetItemForegroundColour(0,wx.RED)
            self.list_box_1.SetItemForegroundColour(1,wx.BLUE)
    
    # end of class MyFrame
    
    
    if __name__ == "__main__":
        app = wx.PySimpleApp(0)
        wx.InitAllImageHandlers()
        frame_1 = MyFrame(None, -1, "")
        app.SetTopWindow(frame_1)
        frame_1.Show()
        app.MainLoop()
    However, I am able to set the font color of all the elements with SetForegroundCo lour(). I want to be able to have each color represent the current state of an element. I know that I can do this with a listctrl, but I wanted to try to do it with a listbox. Any help is greatly appreciated.

    Thanks in advance,
    Stephen
    I can't find SetItemForegrou ndColour() anywhere in the docs.
    For the foreground, you want SetItemTextColo ur()
    Both SetItemTextColo ur() and SetItemBackgrou ndColour() is ListCtrl and TreeCtrl specific.

    Comment

    • shuf
      New Member
      • Mar 2007
      • 8

      #3
      Originally posted by bartonc
      I can't find SetItemForegrou ndColour() anywhere in the docs.
      For the foreground, you want SetItemTextColo ur()
      Both SetItemTextColo ur() and SetItemBackgrou ndColour() is ListCtrl and TreeCtrl specific.
      I found the method specified here. Is this the right place to be looking?

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by shuf
        I found the method specified here. Is this the right place to be looking?
        The site is good, but is layed out in a manner that is a little confusing. The docs that I use are for the C++ package, but have some wxPython notes where they are needed. These docs come from win32-docs-demos download here. These are the easiest to follow if you don't mind thinking in C++ just a little.

        Comment

        • shuf
          New Member
          • Mar 2007
          • 8

          #5
          Originally posted by bartonc
          ... if you don't mind thinking in C++ just a little.
          After working in C and C++ for a couple of years thinking in C++ is a nice break :). This is my first real project in Python, and I really enjoy it and all the help I have recieved!

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by shuf
            After working in C and C++ for a couple of years thinking in C++ is a nice break :). This is my first real project in Python, and I really enjoy it and all the help I have recieved!
            That's great to hear! Drop in any time for what ever python help you need. That's what TheScripts Python Forum is all about!

            Comment

            • bartonc
              Recognized Expert Expert
              • Sep 2006
              • 6478

              #7
              Originally posted by shuf
              Hello,

              I am running python 2.4.4 with wxpython 2.6 on Fedora 6. I am trying to set the font color of individual elements in a listbox, but I am not able to with SetItemForegrou ndColour() (this method does not appear to do anything):
              By the way, wxPython version 2.8 is out and stable. There are no issues that I've discovered (using Boa Constructor) in upgrading.

              Comment

              Working...