GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 22, 2014 4:16 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [pygtk] grid like in Ubuntu Update Manager
PostPosted: Wed Mar 11, 2009 1:38 pm 
Offline

Joined: Fri Jan 23, 2009 6:46 am
Posts: 3
hello, is there anyone knows how to make grid like in ubuntu update manager on pygtk? its a simple list but with headlines. i cant understand how can i add headlines like this:

------------------
HEADLINE 1
[x] | Item 1
[ ] | Item 2
[x] | Item 3
HEADLINE 2
[ ] | Item 1
[ ] | Item 2
[x] | Item 3
...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 2:09 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

This actually quite easy to achieve using pango markup language. And since sample code can explain what 1e3 words can't, I wrote a simple application to demonstrate the priciples. (My code is written in C, since my Python skills suck badly. Sorry.)

Code:
#include <gtk/gtk.h>

int
main( int    argc,
     char **argv )
{
   GtkWidget *window;
   GtkWidget *swindow;
   GtkWidget *tree;
   GtkListStore *store;
   GtkTreeViewColumn *col;
   GtkTreeIter iter;
   GtkCellRenderer *cell;

   gtk_init( &argc, &argv );

   window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   g_signal_connect( G_OBJECT( window ), "destroy",
                 G_CALLBACK( gtk_main_quit ), NULL );

   swindow = gtk_scrolled_window_new( NULL, NULL );
   gtk_container_add( GTK_CONTAINER( window ), swindow );

   store = gtk_list_store_new( 3, G_TYPE_BOOLEAN,
                           G_TYPE_BOOLEAN,
                           G_TYPE_STRING );
   gtk_list_store_append( store, &iter );
   gtk_list_store_set( store, &iter, 0, FALSE,
                             1, FALSE,
                             2, "<b><big>Important security "
                                "updates</big></b>",
                             -1 );
   gtk_list_store_append( store, &iter );
   gtk_list_store_set( store, &iter, 0, TRUE,
                             1, FALSE,
                             2, "<b>file</b>\n"
                                "Determines file type using "
                               "\"magic\" numbers\n"
                               "From version 4.19-1ubuntu2 to ...",
                             -1 );
   gtk_list_store_append( store, &iter );
   gtk_list_store_set( store, &iter, 0, TRUE,
                             1, TRUE,
                             2, "<b>firefox</b>\n"
                                "lightweight web browser based "
                               "on Mozilla"
                               "From vrsion 2.0.0.3+1-0ubuntu2 ...",
                             -1 );

   tree = gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) );
   gtk_container_add( GTK_CONTAINER( swindow ), tree );

   col = gtk_tree_view_column_new();
   cell = gtk_cell_renderer_toggle_new();
   gtk_tree_view_column_pack_start( col, cell, FALSE );
   gtk_tree_view_column_set_attributes( col, cell, "visible", 0,
                                       "active", 1,
                                       NULL );
   cell = gtk_cell_renderer_text_new();
   gtk_tree_view_column_pack_start( col, cell, TRUE );
   gtk_tree_view_column_set_attributes( col, cell, "markup", 2, NULL );

   gtk_tree_view_append_column( GTK_TREE_VIEW( tree ), col );

   gtk_widget_show_all( window );

   gtk_main();

   return( 0 );
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 12:28 pm 
Offline

Joined: Fri Jan 23, 2009 6:46 am
Posts: 3
tadeboro, thanks a lot for helping me! your example was very helpful!

i done it slightly differently, there is cut from my code

Code:
self.tv = self.widgetsTree.get_widget("treeview")
self.ls = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN, gobject.TYPE_STRING)
self.ls.append([False, False, u'<big><b>Caption</b></big>'])
self.ls.append([True, False, u'<b>test1</b>\n<small>test1</small>'])
self.ls.append([True, True, u'<b>test2</b>\n<small>test2</small>'])
self.check_cell = gtk.CellRendererToggle()
self.text_cell = gtk.CellRendererText()
self.cn0 = gtk.TreeViewColumn(None, self.check_cell, visible=0, active=1)
self.cn1 = gtk.TreeViewColumn(None, self.text_cell, markup=2)
self.tv.append_column(self.cn0)
self.tv.append_column(self.cn1)
self.tv.set_model(self.ls)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group