Re: [pygtk] TreeView - Making whole row colored, Again

2008-12-15 Thread Kevin
Thanks for replying.  

sandro wrote:
> if you have alternated rows, #fff is not the default,
> I'm almost sure you
> can set None and that will pick the default color, besides
> the fact that
> people may have different default tha #fff.

I hadn't thought of that - alternated rows doesn't seem to work under Windows.  
I'll try that.

> but you want to set True the cell renderer. Isn't it
> possible to set it
> explicetly:  
> 
>   leftjust.set_property("cell-background-set",
> True)

You're completely right, of course; I figured that out a little while ago. :)

One other question: there are still white gridlines between the rows and 
columns with this method.  There's no easy way to get rid of those and make 
each row a solid color all the way through, is there?

Cheers, K.


  __
Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! 
Canada Messenger at http://ca.beta.messenger.yahoo.com/
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] TreeView - Making whole row colored, Again

2008-12-10 Thread John Finlay
Kevin wrote:
> Greetings,
>
> I came across an old message in the archives at 
> http://www.mail-archive.com/pygtk@daa.com.au/msg15480.html , which sounds a 
> lot like I want to do (though I want to work with background colors rather 
> than foreground colors).  But I was thinking: couldn't I just add a column to 
> my model containing the color values I want for each row, and use values of 
> #ff for all the rows I wanted to leave white?
>
> The problem is that without a column of booleans, I can't seem to set the 
> background-set property of the columns.  Specifically, I'm using:
>
> leftjust = gtk.CellRendererText()
> column = gtk.TreeViewColumn('Filename', leftjust, text=COLUMN_FILENAME)
> column.set_sort_column_id(COLUMN_FILENAME)
> treeview.append_column(column)
>
> column.add_attribute(leftjust, 'background-set', True)
>   
remove the above line.
> column.add_attribute(leftjust, 'background', COLUMN_FLAG)
>
> but when I run the program, I keep getting 
> Warning: unable to set property `background-set' of type `gboolean' from 
> value of type `gchararray'
>
> Is there really no way of doing this without creating another column of 
> booleans?
>
>   
You don't have to set "background-set" - it's set automatically when 
"background" is set.

John
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] TreeView - Making whole row colored, Again

2008-12-10 Thread Kevin
Greetings,

I came across an old message in the archives at 
http://www.mail-archive.com/pygtk@daa.com.au/msg15480.html , which sounds a lot 
like I want to do (though I want to work with background colors rather than 
foreground colors).  But I was thinking: couldn't I just add a column to my 
model containing the color values I want for each row, and use values of 
#ff for all the rows I wanted to leave white?

The problem is that without a column of booleans, I can't seem to set the 
background-set property of the columns.  Specifically, I'm using:

leftjust = gtk.CellRendererText()
column = gtk.TreeViewColumn('Filename', leftjust, text=COLUMN_FILENAME)
column.set_sort_column_id(COLUMN_FILENAME)
treeview.append_column(column)

column.add_attribute(leftjust, 'background-set', True)
column.add_attribute(leftjust, 'background', COLUMN_FLAG)

but when I run the program, I keep getting 
Warning: unable to set property `background-set' of type `gboolean' from value 
of type `gchararray'

Is there really no way of doing this without creating another column of 
booleans?

Thanks, K.



  __
Ask a question on any topic and get answers from real people. Go to Yahoo! 
Answers and share what you know at http://ca.answers.yahoo.com

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] TreeView - Making whole row colored

2008-07-09 Thread Neil Dugan

Stephen George wrote:

Hi,

I am trying to get a treeview (with liststore model) to display rows in 
different colors based on content in the list.


 From what I've read in GTK+ 2.0 Tree View Tutorial - Tim-Philipp Muller 
( c code based)


"The most suitable approach for most cases is that you add two columns 
to your model, one for
the property itself (e.g. a column COL_ROW_COLOR of type G_TYPE_STRING), 
and one for the boolean flag of
the property (e.g. a column COL_ROW_COLOR_SET of type G_TYPE_BOOLEAN). 
You would then connect these
columns with the "foreground" and "foreground-set" properties of each 
renderer. Now, whenever you set
a row’s COL_ROW_COLOR field to a colour, and set that row’s 
COL_ROW_COLOR_SET field to TRUE, then
this column will be rendered in the colour of your choice. If you only 
want either the default text colour or one
special other colour, you could even achieve the same thing with just 
one extra model column: in this case you
could just set all renderer’s "foreground" property to whatever special 
color you want, and only connect the
COL_ROW_COLOR_SET column to all renderer’s "foreground-set" property 
using attributes."


Which I've implemented as attached.

The setting of foreground seems to be working (half list blue, half red)
However my implementation seems to be ignoring the foreground-set flag.

I am expecting to ONLY see my 'special' foreground color when the 
modified flag is also set to true, and grey/black writing when the 
foreground-set flag is False.


I can get grey writing by setting the foreground to None, but I don't 
belive this was the intent of the above description.


Am I mis-understanding how this functionality should work, .. or made 
some errors in my code?


Thanks for any suggestions.
Steve



Hi Steve,

I can't see the pattern in why the colors are how they are.  I think 
some of the trouble has to be with some 'foreground-color' set as None.


It would probably be better to not use the 'Modified' column to affect 
the color, and just put the color you want the row in the 
'foreground-color' column (i.e. red,black or blue) and change the 
set-up to.


column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
mycell.set_property('foreground-set', True)




If you must stay with this set-up, this function seems to do what you want

def _cell_data_func(self, column, cell, model, iter):
		(modified,foreground) = 
model.get(iter,COLUMN_MODIFIED,COLUMN_FOREGROUND)

if foreground == None : foreground = 'black'
if modified :
cell.set_property('foreground',foreground)
else :
cell.set_property('foreground','black')
cell.set_property('foreground-set',True)
return False

And use "column.set_cell_data_func(mycell, self._cell_data_func)" to 
set it up.


Regards Neil.


77a78,84
> def _cell_data_func(self, column, cell, model, iter):
>   #print "totalcelldatamethod()"
>   (modified,foreground) = 
> model.get(iter,COLUMN_MODIFIED,COLUMN_FOREGROUND)
>   cell.set_property('foreground',foreground)
>   cell.set_property('foreground-set',modified)
>   return False
> 
92,93c99,101
< column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
< column.add_attribute(mycell, 'foreground-set', COLUMN_MODIFIED)
---
> #column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
> #column.add_attribute(mycell, 'foreground-set', COLUMN_MODIFIED)
> column.set_cell_data_func(mycell, self._cell_data_func)
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] TreeView - Making whole row colored

2008-01-30 Thread Stephen George


Neil Dugan wrote:

Stephen George wrote:

Hi,

I am trying to get a treeview (with liststore model) to display rows 
in different colors based on content in the list.


"The most suitable approach for most cases is that you add two 
columns to your model, one for
the property itself (e.g. a column COL_ROW_COLOR of type 
G_TYPE_STRING), and one for the boolean flag of
the property (e.g. a column COL_ROW_COLOR_SET of type 
G_TYPE_BOOLEAN). You would then connect these
columns with the "foreground" and "foreground-set" properties of each 
renderer. Now, whenever you set
a row’s COL_ROW_COLOR field to a colour, and set that row’s 
COL_ROW_COLOR_SET field to TRUE, then

this column will be rendered in the colour of your choice.




Hi Steve,

I can't see the pattern in why the colors are how they are.  I think 
some of the trouble has to be with some 'foreground-color' set as None.


It would probably be better to not use the 'Modified' column to affect 
the color, and just put the color you want the row in the 
'foreground-color' column (i.e. red,black or blue) and change the 
set-up to.


column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
mycell.set_property('foreground-set', True)




Regards Neil.

Hi Neil,

Thanks for the reply.

I'm not sure whats happening, but it's not to do with 'foreground-color' 
set as None. ... I did a lot of testing before I started to introduce 
None for the color.

(According to pygtk reference None is the default value of that property)

I do have a system thats working for me now, .. but I suspect it only 
working because of some bug somewhere.


I totally ignore the foreground-set property, I never set it now, .. it 
seems to do nothing - set or not set


If I want to change the cells color, I put it in 'foreground-color' 
property, else I leave 'foreground-color' at None.


Thats it, .. it all works nicely like that. Ya, .. I know relying on 
undocumented behavior is bad, .. but I needed something that works now.


Cheers
Steve

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] TreeView - Making whole row colored

2008-01-29 Thread Stephen George

Hi,

I am trying to get a treeview (with liststore model) to display rows in 
different colors based on content in the list.


From what I've read in GTK+ 2.0 Tree View Tutorial - Tim-Philipp Muller 
( c code based)


"The most suitable approach for most cases is that you add two columns 
to your model, one for
the property itself (e.g. a column COL_ROW_COLOR of type G_TYPE_STRING), 
and one for the boolean flag of
the property (e.g. a column COL_ROW_COLOR_SET of type G_TYPE_BOOLEAN). 
You would then connect these
columns with the "foreground" and "foreground-set" properties of each 
renderer. Now, whenever you set
a row’s COL_ROW_COLOR field to a colour, and set that row’s 
COL_ROW_COLOR_SET field to TRUE, then
this column will be rendered in the colour of your choice. If you only 
want either the default text colour or one
special other colour, you could even achieve the same thing with just 
one extra model column: in this case you
could just set all renderer’s "foreground" property to whatever special 
color you want, and only connect the
COL_ROW_COLOR_SET column to all renderer’s "foreground-set" property 
using attributes."


Which I've implemented as attached.

The setting of foreground seems to be working (half list blue, half red)
However my implementation seems to be ignoring the foreground-set flag.

I am expecting to ONLY see my 'special' foreground color when the 
modified flag is also set to true, and grey/black writing when the 
foreground-set flag is False.


I can get grey writing by setting the foreground to None, but I don't 
belive this was the intent of the above description.


Am I mis-understanding how this functionality should work, .. or made 
some errors in my code?


Thanks for any suggestions.
Steve
import pygtk
pygtk.require('2.0')
import gtk
import pango
import gobject

COLUMN_ERRORCODE=0 #Storage location of the Error Code
COLUMN_SYMBOLIC =1 #Storage location of the Symbolic Name
COLUMN_MODIFIED =2 #Storage location of the modified flag
COLUMN_FOREGROUND   =3 #Storage location if a color for unmodified lines

list1 = [
# ECODE,  SYMBOLIC,  useForground,   foreground-color 
('1234', 'SYMBOLIC_NAME',   True,   'red' ),
('1342', 'RUN_FOREVER', True,   'red' ),
('1345', 'NEVER_WAIT',  False,  'red' ),
('1342', 'DRIVE_CAR',   False,  'red' ),
('1453', 'GROW_UP', True,   'red' ),
('1534', 'WONDER_FOREVER',  True,   None ),
('1238', 'CHECK_THIS_OUT',  False,  'red' ),
('1344', 'LAST_ONE',False,  'red' ),
('9412', 'ddSYMBOLIC_NAME', True,   'blue' ),
('9223', 'ddRUN_FOREVER',   True,   'blue' ),
('9563', 'ddNEVER_WAIT',False,  None ),
('9223', 'ddDRIVE_CAR', False,  'blue' ),
('9334', 'ddGROW_UP',   True,   'blue' ),
('9445', 'ddWONDER_FOREVER',True,   'blue' ),
('9892', 'ddCHECK_THIS_OUT',False,  'blue' ),
('9423', 'ddLAST_ONE',  False,  'blue' ),
]

class ListColorExample(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)

self.set_title('Test Row Color')

#create a top level vertical box
self.emevbox = gtk.VBox()
self.add(self.emevbox)

self.changes = []
self.connect('destroy', lambda w: gtk.main_quit())

self.set_size_request(640, 520)

self.lsw = gtk.ScrolledWindow()
self.lsw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
self.lsw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.emevbox.pack_start(self.lsw)

# create data treestore_model
fmodel = self.__create_liststore()

# create treeview
self.ltreeview = gtk.TreeView(fmodel)
self.__add_columns(self.ltreeview)
self.lsw.add(self.ltreeview)

# expand all rows after the treeview widget has been realized
self.ltreeview.connect('realize', lambda tv: tv.expand_all())
self.show_all()


def __create_liststore(self):
# create tree storeECODE,  SYMBOLIC, DoColor,  color_string 
liststore_model = gtk.ListStore(str, str, gobject.TYPE_BOOLEAN, str) 
for item in list1:
iter = liststore_model.append()
liststore_model.set(iter,
COLUMN_ERRORCODE,   item[COLUMN_ERRORCODE],
COLUMN_SYMBOLIC,item[COLUMN_SYMBOLIC],
COLUMN_MODIFIED,item[COLUMN_MODIFIED], 
COLUMN_FOREGROUND,  item[COLUMN_FOREGROUND],
)
return liststore_model

def __add_columns(self, treeview):
model = treeview.get_model()

# column for the Error Cod