From: Kevin A. <al...@se...> - 2004-09-09 04:24:00
|
Thanks Daryl, just as an FYI you don't have to use the Colour class, wxPython will accept a variety of formats and convert appropriately. You can use the same kind of representations you would in PythonCard. COLOURS = ['black', '#660000', 'red', (255, 0x99, 0), (255, 255, 0), 'green', 'blue', (0x99, 0xff, 0), '#cccccc', 'white'] is equivelant to COLOURS = [Colour(0, 0, 0), Colour(0x66, 0, 0), Colour(0xff, 0, 0), Colour(0xff, 0x99, 0), Colour(0xff, 0xff, 0), Colour(0, 0xff, 0), Colour(0, 0, 0xff), Colour(0x99, 0xff, 0), Colour(0xcc, 0xcc,0xcc), Colour(0xff, 0xff, 0xff)] All of the named colors that wxPython supports as well as their RGB values are defined in wx/lib/colourdb.py. The names are not case-sensitive. ka On Sep 8, 2004, at 8:25 PM, Daryl Fox wrote: > Okay, here's my solution to this. Please note, I'm sure that many > other > people have better ways, but this works for me. > > First, the List must become a MultiColumnList. As a bonus, I was able > to > remove my static text label and use the column label instead. Then > each > item is applied a wxCOLOR. Below is a simple example. > > Start up the resourceEditor. For this example, build a new 'Standard > Template with File->Exit menu'. Plop down a MultiColumnList and give > it the > name 'MultiColumnList'. Set it's size to be about 180 x 175. Save the > file. The .rsrc.py file should contain the following down near the > bottom: > {'type':'MultiColumnList', > 'name':'MultiColumnList', > 'position':(15, 10), > 'size':(182, 169), > 'backgroundColor':(255, 255, 255), > 'columnHeadings':[], > 'font':{'faceName': 'Tahoma', 'family': 'sansSerif', 'size': 8}, > 'items':[], > 'maxColumns':20, > 'rules':1, > }, > > Now open up the .py file. and change it to: > > from PythonCard import model > from wx import Colour > > COLOURS = [Colour(0, 0, 0), Colour(0x66, 0, 0), Colour(0xff, > 0, 0), > Colour(0xff, 0x99, 0), Colour(0xff, 0xff, 0), Colour(0, > 0xff, 0), > Colour(0, 0, 0xff), Colour(0x99, 0xff, 0), Colour(0xcc, > 0xcc, > 0xcc), > Colour(0xff, 0xff, 0xff)] > > class MyBackground(model.Background): > def on_initialize(self, event): > Items = "Bad Beer Rots Our Young Guts But Vodka Goes > Well".split(" ") > self.components.MultiColumnList.columnHeadings = "Color Code" > self.components.MultiColumnList.items = Items > > for Item in range(len(self.components.MultiColumnList.items)): > self.components.MultiColumnList.SetItemTextColour(Item, > COLOURS[Item]) > > if __name__ == '__main__': > app = model.Application(MyBackground) > app.MainLoop() > > Here we build a list of colours called COLOURS. Inside the > on_initialize > method, the column is given a label and then populated with items. > Finally, > the for loop goes over each item and sets it's color. Please note, > this is > just a funny little example. If you populate the list with more items > than > we have colors Bad Things will happen. I suppose you could do a max of > len(Items) and len(COLOURS) if you were worried about that... > > Hope this helps, > -Daryl > > > -----Original Message [With much snippage] ----- > From: Kevin Altis > Sent: Monday, September 06, 2004 8:51 PM > To: Daryl Fox > Cc: pyt...@li... > Subject: Re: [Pythoncard-users] Color in Lists > > On Sep 6, 2004, at 8:19 PM, Daryl Fox wrote: > > [SNIP] >> I do, however, have one issue. I would like to set the text colour of >> individual items in a list. > [SNIP] > > IIRC, I don't think it is supported in the underlying wx.ListBox > control used by the List component, but is supported by the wx.ListCtrl > which is underneath the MultiColumnList. You can check what the > wxWidgets docs say or find what you want to do in the wxPython demo and > then you'll have to call the appropriate wxPython methods to set the > colors. > > ka > > > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users > |