help with treeview property setting

Reply

Join Date: Nov 2006
Posts: 3
Reputation: pachjo is an unknown quantity at this point 
Solved Threads: 0
pachjo pachjo is offline Offline
Newbie Poster

help with treeview property setting

 
0
  #1
Nov 5th, 2006
I am trying to get to grips with treeviews in pygtk/gtk and am stuck on setting the alignment of the columns.

No matter what I try I cannot change the alignmenthttp://ubuntuforums.org/images/smilies/eusa_wall.gif

Here is the code I found on the web which I am using to change different lines to see the effect and thus learn how they work. However I added the line self.cell1.set_property('alignment', pango.ALIGN_CENTER) and it makes no difference. I have tried right align too with no joy!

Can anyone help me please?

  1. def __init__(self):
  2.  
  3. # Create a new window
  4.  
  5. self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  6.  
  7. self.window.set_title("TreeViewColumn Example")
  8.  
  9. self.window.set_size_request(400, 200)
  10.  
  11. self.window.connect("delete_event", self.delete_event)
  12.  
  13. # create a liststore with one string column to use as the model
  14.  
  15. self.liststore = gtk.ListStore(str, str, str, 'gboolean')
  16.  
  17. # create the TreeView using liststore
  18.  
  19. self.treeview = gtk.TreeView(self.liststore)
  20.  
  21. # create the TreeViewColumns to display the data
  22.  
  23. self.tvcolumn = gtk.TreeViewColumn('Pixbuf and Text')
  24.  
  25. self.tvcolumn1 = gtk.TreeViewColumn('Text Only')
  26.  
  27. # add a row with text and a stock item - color strings for
  28.  
  29. # the background
  30.  
  31. self.liststore.append(['Open', gtk.STOCK_OPEN, 'Open a File', True])
  32.  
  33. self.liststore.append(['New', gtk.STOCK_NEW, 'New File', True])
  34.  
  35. self.liststore.append(['Print', gtk.STOCK_PRINT, 'Print File', False])
  36.  
  37. # add columns to treeview
  38.  
  39. self.treeview.append_column(self.tvcolumn)
  40.  
  41. self.treeview.append_column(self.tvcolumn1)
  42.  
  43. # create a CellRenderers to render the data
  44.  
  45. self.cellpb = gtk.CellRendererPixbuf()
  46.  
  47. self.cell = gtk.CellRendererText()
  48.  
  49. self.cell1 = gtk.CellRendererText()
  50.  
  51. # set background color property
  52.  
  53. self.cellpb.set_property('cell-background', 'yellow')
  54.  
  55. self.cell.set_property('cell-background', 'cyan')
  56.  
  57. self.cell1.set_property('cell-background', 'pink')
  58.  
  59. self.cell1.set_property('alignment', pango.ALIGN_CENTER)
  60.  
  61. # add the cells to the columns - 2 in the first
  62.  
  63. self.tvcolumn.pack_start(self.cellpb, False)
  64.  
  65. self.tvcolumn.pack_start(self.cell, True)
  66.  
  67. self.tvcolumn1.pack_start(self.cell1, True)
  68.  
  69. # set the cell attributes to the appropriate liststore column
  70.  
  71. # GTK+ 2.0 doesn't support the "stock_id" property
  72.  
  73. if gtk.gtk_version[1] < 2:
  74.  
  75. self.tvcolumn.set_cell_data_func(self.cellpb, self.make_pb)
  76.  
  77. else:
  78.  
  79. self.tvcolumn.set_attributes(self.cellpb, stock_id=1)
  80.  
  81. self.tvcolumn.set_attributes(self.cell, text=0)
  82.  
  83. self.tvcolumn1.set_attributes(self.cell1, text=2,
  84.  
  85. cell_background_set=3)
  86.  
  87. # make treeview searchable
  88.  
  89. self.treeview.set_search_column(0)
  90.  
  91. # Allow sorting on the column
  92.  
  93. self.tvcolumn.set_sort_column_id(0)
  94.  
  95. # Allow drag and drop reordering of rows
  96.  
  97. self.treeview.set_reorderable(True)
  98.  
  99. self.window.add(self.treeview)
  100.  
  101. self.window.show_all()
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,276
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 175
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: help with treeview property setting

 
0
  #2
Nov 5th, 2006
What is pygtk/gtk and what is is it used for?
Also, what is a treeview?
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 3
Reputation: pachjo is an unknown quantity at this point 
Solved Threads: 0
pachjo pachjo is offline Offline
Newbie Poster

Re: help with treeview property setting

 
0
  #3
Nov 6th, 2006
Originally Posted by sneekula View Post
What is pygtk/gtk and what is is it used for?
Also, what is a treeview?
If you don't know then you wont be able to help me.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,276
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 175
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: help with treeview property setting

 
0
  #4
Nov 6th, 2006
Originally Posted by pachjo View Post
If you don't know then you wont be able to help me.
Thanks for your kind answer. I took the liberty to check
http://www.pygtk.org/pygtk2reference...ktreeview.html
all I can say is "ouch!", that is one complex thing! No wonder you are lost!
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 3
Reputation: pachjo is an unknown quantity at this point 
Solved Threads: 0
pachjo pachjo is offline Offline
Newbie Poster

Re: help with treeview property setting

 
0
  #5
Nov 6th, 2006
Originally Posted by sneekula View Post
Thanks for your kind answer. I took the liberty to check
http://www.pygtk.org/pygtk2reference...ktreeview.html
all I can say is "ouch!", that is one complex thing! No wonder you are lost!
hey, no offence intended.....

I just presumed that if you did not know what they were, you would know the answer.

And yep....it is making my head hurt!

Stupid thing is I could have had the application finished now in MS but as I only use Linux now at home want to do it in python. Needless to say I am less than impressed that it has taken me days now of searching and am still no nearer the answer. Also I dont seem to get any response from other forums either.

I can only guess this is something python/pygtk/gtk just cant do even though the sparse help suggests otherwise:eek:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC