gnope php gtk gui gnope.org  

End packing and treeviewcolumn

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
kingrs



Joined: 15 Jan 2006
Posts: 30
Location: Stafford, UK

PostPosted: Wed Jan 18, 2006 3:57 pm    Post subject: End packing and treeviewcolumn Reply with quote

Sorry for all the questions.
I want to right justify the numbers in one column of a treeview.
This should be possible I would have thought using $treeView->pack_end ($cell,true);
But I cannot get it to work, or this is not the way to do it.

My test code is this:
Code:

<?

//the model
$store = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_DOUBLE);

//add some data to the data store
$store->append(array('PHP for idots' , '123.00', 123.00));
$store->append(array('C for biginners' , '8.95' , 8.95));
$store->append(array('C++ Guide', '19.95' , 19.95));
$store->append(array('Ruby for the novist', '1.50', 1.50));

//sort by price by default
$store->set_sort_column_id(2, Gtk::SORT_ASCENDING);

//We want to display our data in a GtkTreeView
$treeview = new GtkTreeView($store);

//the text renderer is used to display text
$cell_renderer = new GtkCellRendererText();

//Create the first column, make it resizable and sortable
$colLanguage = new GtkTreeViewColumn('Book', $cell_renderer, 'text', 0);
//make the column resizable in width
$colLanguage->set_resizable(true);
//make it sortable and let it sort after model column 1
$colLanguage->set_sort_column_id(0);
//add the column to the view
$treeview->append_column($colLanguage);

//second column, also sortable
$colPrice = new GtkTreeViewColumn('Price', $cell_renderer, 'text', 1);
$colPrice->set_sort_column_id(2);

$treeview->append_column($colPrice);

//we want to display a boolean value, so we can use a check box for display
$colPriced = new GtkTreeViewColumn('Price', $cell_renderer, 'text', 2);
$colPriced->set_sort_column_id(0);
$colPriced->Set_visible(false);

$treeview->append_column($colPriced);
$treeview->connect("row_activated","on_treeview_row_activate");

//A window where we can put our tree view
$wnd = new GtkWindow();
$wnd->set_title('Programming languages');
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
//$wnd->signal_connect("on_treeview_row_activate","on_treeview_row_activate");



//to make the view scrollable, we need a scrolled window
$scrwnd = new GtkScrolledWindow();
$scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
$scrwnd->add($treeview);

$wnd->add($scrwnd);
$wnd->set_default_size(250, 200);
$wnd->show_all();
Gtk::main();

function on_treeview_row_activate () {
   echo "hello\n";
}
?>
[/code]
Back to top
karlbowden



Joined: 18 Dec 2005
Posts: 21
Location: Taree, NSW, Australia

PostPosted: Thu Jan 19, 2006 3:41 am    Post subject: Reply with quote

Just going off memory, i think your looking for
$colPrice->set_alignment (1); // Right align column
$colPrice->set_alignment (0.5); // Center column

The pack_end just changes the order that the items are placed into the model.

(I could be quite wrong though. good luck)
Back to top
kingrs



Joined: 15 Jan 2006
Posts: 30
Location: Stafford, UK

PostPosted: Thu Jan 19, 2006 10:40 am    Post subject: Reply with quote

Quote:
Just going off memory, i think your looking for
$colPrice->set_alignment (1); // Right align column
$colPrice->set_alignment (0.5); // Center column


The manual says it sets the column title and I tried it and it does but not the cell contents, its a start.
http://www.pygtk.org/pygtk2reference/class-gtktreeviewcolumn.html#method-gtktreeviewcolumn--set-alignment

This is the best reference I have found so far for gtk2, although it is for python, its close enough:

http://www.pygtk.org/pygtk2reference

My next step will be to set the font of the cell to say courier and add spaces to the front of the text to get it to line up.
I'm not sure how to set the font of the rendered cell though.
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Jan 19, 2006 11:01 am    Post subject: Reply with quote

kingrs wrote:
I'm not sure how to set the font of the rendered cell though.

GtkCellRenderer has many, many properties which can be set. See the original Gtk manual for that.
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Sat May 20, 2006 2:51 pm    Post subject: Reply with quote

kingrs wrote:

I'm not sure how to set the font of the rendered cell though.


Hi,

I don't know if you're still searching for a way to do this, but here's what I came up with:

Code:

$font = array("Arial", 12, 575, "#095C63", "#d9fbfc");
$cell = new GtkCellRendererText();
$cell->set_property("font",  $font[0]);
$cell->set_property("size-points", $font[1]);
$cell->set_property("weight", $font[2]);
$cell->set_property("foreground",  $font[3]);
$cell->set_property("background", $font[4]);


You don't, of course, have to use the $font array() I've set up here, but it makes it handy if you want to pass the font properties to a method or function that creates your cell.

The items in the fonts array() are self-explanitory if you look at which property is being set, all except for the weight (bold-ness). Usable values for weight seem to range from 0 to about 575. Values above this don't seem to make any difference. Somewhere in the middle of the range is the "normal" weight; values toward the low end make the font lighter, toward the high end, more bold.

-Ron T.

-
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.