Get all rows in Gtk2::ListStore
Hi All, I have defined the following ListStore: my $list_store = Gtk2::ListStore-new('Glib::Int', 'Glib::String', 'Glib::String'); What is the best way to get all of the rows in the store? At the moment I am trying something like below to try to get all of the second column's values: while ( $list_store-iter_next($iter) ) { push( @existing_classfns, $list_store-get($iter, 1) ); $iter = $list_store-iter_next($iter); } But @existing_classfns is always empty. Many thanks, Peter. ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Check Gtk2::ListStore empty or not
Hi All, Is it possible to check if a Gtk2::ListStore is empty? At the moment I have a combo box with a list of items. The user can select items from the combo box and add them to a list. But I don't want them to be able to add duplicate items to the list. So first I was going to check if the list was empty. If it was then it can add an item, but if it wasn't then get an array of the items already in the list store, loop through them checking that the combo selection isn't already there and then add the item. I'm not entirely sure how to check if the list is empty. At the moment I'm trying: if ($list_store-get_iter_first) #or if (defined $list_store-get_iter_first) # get what's there and check for duplicates else # add item to list but this doesn't work because when I try to get everything from my first column: my @col1 = $list_store-get($list_iter, 1); It says: variable not allowed to be undef where GtkTreeIter is wanted at line 331 which matches the 'my @col1' line above. Could someone please help me with the testing logic. I understand it needs to be defined, but it can only be defined if there's something in the row, but then I can't test if it's empty. Very confused. Many thanks, Peter. ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Check Gtk2::ListStore empty or not
2009/7/27 anguila angu...@gmail.com: integer = $tree_model-iter_n_children ($iter=undef) $iter (Gtk2::TreeIter or undef) Returns the number of children $iter has. If $iter is undef (or omitted) then returns the number of toplevel nodes. with $list_store-iter_n_children(undef) you will know if is empty or not and the rows that it has throug a integer value. The way of tadej showed is correct too. David. On Mon, Jul 27, 2009 at 1:49 PM, Tadej Borovšak tadeb...@gmail.com wrote: Hi. I would use construct like this one: --- CODE --- my $iter = $list_store-get_iter_first; if( $iter ) # Get contents of first line my @line = $list_store-get( $iter ); else # Add new line --- CODE --- This might not be the best way, but it should work. Tadej Thank you both for the suggestions. I will try them out and see how I go. ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Layout problems when getting widgets from glade file
2009/5/22 Kevin Ryde use...@zip.com.au: Peter E Dennis peter.edwin.den...@gmail.com writes: my $table = Gtk2::Table-new(2,9,FALSE); Do you have FALSE defined? If not then without use strict it's the string FALSE, making homogeneous true ... Yep, I'm brain dead. And that has sealed it. These weren't defined in my test program so no wonder I ran into trouble. Thank you Kevin! Is this: use Glib qw/TRUE FALSE/; the usual way it's done? Although I could be screwing even this up because the output of this: print Homogeneous is: . $table-get_homogeneous ? on\n: off\n; $table-set_homogeneous(FALSE); print Homogeneous is: . $table-get_homogeneous ? on\n: off\n; Is still: on on But the labels and separators now fit on the screen, with room to spare. Many thanks, Peter. ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Layout problems when getting widgets from glade file
2009/5/17 Cowley Harris warewo...@gmail.com: 2009/5/16 Peter E Dennis peter.edwin.den...@gmail.com: What I'm trying to do is to get the program using the glade file to look like the one that isn't. I would ideally like to be able to use glade than hand code the entire gui. Try setting the default window size for the main window with Gtk2::Window::set_default_size. Sorry I think I was unclear on this point and I appreciate this suggestion but the problem is I need to get the glade file one to shrink so that when I add more widgets to the Gtk2::Table in my ret_table() function, the window isn't too large for the screen upon executing the *.pl file that loads the gui. Upon further testing this actually works if the labels are all the same size - in with_glade.pl change ret_table to: sub ret_table { my $table = Gtk2::Table-new(2,9,FALSE); # Title Row my $lbl_num = Gtk2::Label-new(label 1); my $lbl_time = Gtk2::Label-new(label 2); my $lbl_objectives = Gtk2::Label-new(label 3); my $lbl_tasks = Gtk2::Label-new(label 4); my $lbl_resources = Gtk2::Label-new(label 5); my $tcol_sep1 = Gtk2::VSeparator-new; my $tcol_sep2 = Gtk2::VSeparator-new; my $tcol_sep3 = Gtk2::VSeparator-new; my $tcol_sep4 = Gtk2::VSeparator-new; # Layout title row $table-attach_defaults($lbl_num, 0,1,0,1); $table-attach_defaults($tcol_sep1, 1,2,0,1); $table-attach_defaults($lbl_time, 2,3,0,1); $table-attach_defaults($tcol_sep2, 3,4,0,1); $table-attach_defaults($lbl_objectives, 4,5,0,1); $table-attach_defaults($tcol_sep3, 5,6,0,1); $table-attach_defaults($lbl_tasks, 6,7,0,1); $table-attach_defaults($tcol_sep4, 7,8,0,1); $table-attach_defaults($lbl_resources, 8,9,0,1); return $table; } However, if the labels are different lengths the window becomes too large for the screen (diff_len_labels.png). The rest of the last two labels are off the right hand side of my screen. In with_glade.pl change ret_table to: sub ret_table { my $table = Gtk2::Table-new(2,9,FALSE); # Title Row my $lbl_num = Gtk2::Label-new(Num); my $lbl_time = Gtk2::Label-new(Time/Session); my $lbl_objectives = Gtk2::Label-new(Objectives/Learning Outcomes); my $lbl_tasks = Gtk2::Label-new(Activities/Tasks/Content); my $lbl_resources = Gtk2::Label-new(Resources); my $tcol_sep1 = Gtk2::VSeparator-new; my $tcol_sep2 = Gtk2::VSeparator-new; my $tcol_sep3 = Gtk2::VSeparator-new; my $tcol_sep4 = Gtk2::VSeparator-new; # Layout title row $table-attach_defaults($lbl_num, 0,1,0,1); $table-attach_defaults($tcol_sep1, 1,2,0,1); $table-attach_defaults($lbl_time, 2,3,0,1); $table-attach_defaults($tcol_sep2, 3,4,0,1); $table-attach_defaults($lbl_objectives, 4,5,0,1); $table-attach_defaults($tcol_sep3, 5,6,0,1); $table-attach_defaults($lbl_tasks, 6,7,0,1); $table-attach_defaults($tcol_sep4, 7,8,0,1); $table-attach_defaults($lbl_resources, 8,9,0,1); return $table; } How do I get my program to cope with different length labels so the window fits on the screen? attachment: diff_len_labels.png___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Layout problems when getting widgets from glade file
Hi All, I am trying to learn how to use VBox and Table layouts. At the moment I am getting different results when either coding the gui by hand or creating it in glade (with what I thought were similar options). Without glade: #!/usr/bin/perl use Gtk2 -init; use Gtk2::GladeXML; use Glib qw/TRUE FALSE/; # Create a new window $window = Gtk2::Window-new('toplevel'); # Main window vbox contains button and vbox2 # ($homogenous, $spacing) $vbox1 = Gtk2::VBox-new(FALSE, 5); # Button to add tables to vbox2 $btn_add = Gtk2::Button-new(Add); # Add button to main vbox # ($child, $expand, $fill, $padding) $vbox1-pack_start($btn_add, FALSE, TRUE, 0); # Create vbox where want to add table of widgets # ($homogenous, $spacing) $vbox2 = Gtk2::VBox-new(FALSE, 5); # Create a table of widgets # ($rows, $columns, $homogenous) $table = ret_table(); # Show the widgets # ($child, $expand, $fill, $padding) $vbox2-pack_start($table, TRUE, TRUE, 0); $vbox2-show_all; $vbox1-pack_start($vbox2, TRUE, TRUE, 0); $vbox1-show_all; # Add main vbox to window $window-add($vbox1); # Quit when user clicks on the close button/alt-f4 etc. $window-signal_connect (destroy = sub { Gtk2-main_quit; }); # Maximise the window #$window-maximize; # Show main window $window-show; # Run main loop. Gtk2-main; sub ret_table { my $table = Gtk2::Table-new(2,9,FALSE); my $label = Gtk2::Label-new(Blah); $label-set_alignment(0,0); $table-attach_defaults($label,0,1,0,1); return $table; } When I run it i get a window that looks like 'no_glade.png' However if I use glade for the vboxes and create the table in my code i get a picture similar to 'with_glade.png' With glade: #!/usr/bin/perl use Gtk2 -init; use Gtk2::GladeXML; # Read in glade file with gui $gladexml = Gtk2::GladeXML-new('with_glade.glade'); # Get main window vbox $vbox1 = $gladexml-get_widget('vbox1'); # Get vbox where want to add table of widgets $vbox2 = $gladexml-get_widget('vbox2'); # Create a table of widgets $table = ret_table(); # Show the widgets # $child, $expand, $fill, $padding $vbox2-pack_start($table, TRUE, TRUE, 0); $vbox2-show_all; # Get main window from widget tree. $main_window = $gladexml-get_widget('window1'); # Quit when user clicks on the close button/alt-f4 etc. $main_window-signal_connect (destroy = sub { Gtk2-main_quit; }); # Maximise window #$main_window-maximize; # Run main loop. Gtk2-main; sub ret_table { my $table = Gtk2::Table-new(2,9,FALSE); my $lbl_num = Gtk2::Label-new(Blah); $label-set_alignment(0,0); $table-attach_defaults($lbl_num, 0,1,0,1); return $table; } What I'm trying to do is to get the program using the glade file to look like the one that isn't. I would ideally like to be able to use glade than hand code the entire gui. Is anyone able to help me work out what I'm doing wrong? Peter. with_glade.glade Description: application/glade attachment: no_glade.pngattachment: with_glade.png___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Layout problems when getting widgets from glade file
Double-check all of the packing and sizing options in the glade file against the corresponding ones in your all-perl version; i noticed at least a few differences in a cursory glance. The boxes have spacing 5 in your code, 0 in glade; the button was expand=FALSE, fill=TRUE in code but expand=TRUE, fill=TRUE in glade, etc. In fact, the expand is a likely culprit. I thought I must have changed the glade file after attaching it to my original email but when i vi the original one - downloading it from my first email - (with_glade.glade), the packing for the button is: packing property name=padding0/property property name=expandFalse/property property name=fillFalse/property /packing Is this the setting you're talking about? ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Function to return Gtk2::Table
can you please provide your sscce.glade file? Sure it is attached to this email. Sorry wasn't sure if the list accepted attachments or not. sscce.glade Description: application/glade ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Display Japanese Characters in GtkComboBox
Hi, I am retrieving japanese characters from a MySQL database and trying to display them in a combo box. At the moment I am setting up my model using: my $liststore = Gtk2::ListStore-new('Glib::Int', 'Glib::String', 'Glib::String'); But the characters all appear mainly as small squares with numbers in each of the corners; in other words not the japanese characters that I can see when simply querying the table through mysql-client. Is there a different data type that I can use so that these characters are displayed? Or is this a font issue? My OS is Ubuntu 8.04. Thanks for any suggestions. Peter. ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Display Japanese Characters in GtkComboBox
Modify your program and add use warnings; and check if perl complains about wide characters in print. Did this but no warnings about 'wide characters in print'. Add the following to your loop: use Endode; print is kanji in UTF-8? , (is_utf8($ref-{'kanji'}, 1) ? 'YES' : 'NO'), \n; This was interesting. It says that all of the kanji: is kanji in UTF-8? NO Is there a way I can determine what encoding they are in? I'm afraid that this will only affect the low level communication between the mysql.so library and the server. What's important for your application is that the perl string are marked as being valid UTF-8 (perl strings have an internal flag for this purpose). Thanks for this info. Wasn't really sure if it would have any relevance but thought I should include it. Apart from finding out what the actual encoding is I have been able to display the kanji in the GtkComboBox by doing the following: while (my $ref = $sth-fetchrow_hashref) { my $string = decode(utf8, $ref-{'kanji'}); . } Although I'd much prefer to know what encoding it actually is in, as no doubt I'll hit similar problems when I start trying to insert data... Thanks for all your help so far. Peter. ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Newbie Question about Navigating API doco
Thanks for the tip ritz, I am using ubuntu and have installed it but can't see any of the gtk api stuff in it. Is there a way to add it? On 25/01/2008, ritz [EMAIL PROTECTED] wrote: Hello On Tue, 2008-01-22 at 09:08 +1100, Peter E Dennis wrote: Hi All, snip/ I can't find a reference to delete_event in the API. But possibly not looking in the right place. Can someone point me to it and others like it for other widgets? I would suggest devhelp to browse through documentation. rather helpful little tool with nifty search capability. Many thanks, Peter. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list -- Ritesh Khadgaray ॐ मणि पद्मे हूँ Desktop LinuX N Stuff Ph: +919970164885 Eat Right, Exercise, Die Anyway. Fedora is the best of what works today. Enterprise Linux is the best of what will work consistently for the next seven years. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
GtkComboBoxEntry Vs GtkComboBox
Hi All, I have the following code that I copied from the hello world part of the GTK+ tutorial. I used it to practice using GtkComboBoxEntry(s). #include gtk/gtk.h int main( int argc, char *argv[] ) { /* GtkWidget is the storage type for widgets */ GtkWidget *window; GtkWidget *cboVocSource; /* This is called in all GTK applications. Arguments are parsed * from the command line and are returned to the application. */ gtk_init (argc, argv); /* create a new window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* Sets the border width of the window. */ gtk_container_set_border_width (GTK_CONTAINER (window), 10); /* Creates a new combo box entry with the text Hello World */ cboVocSource = gtk_combo_box_entry_new_text (); gtk_widget_set_name (cboVocSource, cboVocSource); gtk_combo_box_append_text(cboVocSource, Hello World); /* This packs the button into the window (a gtk container). */ gtk_container_add (GTK_CONTAINER (window), cboVocSource); /* The final step is to display this newly created widget. */ gtk_widget_show (cboVocSource); /* and the window */ gtk_widget_show (window); /* All GTK applications must have a gtk_main(). Control ends here * and waits for an event to occur (like a key press or * mouse event). */ gtk_main (); return 0; } I compile it with the following command: $ gcc -Wall -g box.c -o box `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` And get this warning: box.c: In function 'main': box.c:23: warning: passing argument 1 of 'gtk_combo_box_append_text' from incompatible pointer type In the api it has the definition for gtk_combo_box_append_text as: void gtk_combo_box_append_text(GtkComboBox *combo_box, const gchar *text); So I wondered if I needed to cast my GtkComboBoxEntry to a GtkComboBox but wasn't sure how to do this so I tried: gtk_combo_box_append_text(GTK_COMBO(cboVocSource), Hello World); This however makes matters worse as I get the above warning still when I compile it, but now when I run it I get: $ ./box (box:11338): GLib-GObject-WARNING **: invalid cast from `GtkComboBoxEntry' to `GtkCombo' Can someone please tell me what I'm doing wrong? Many thanks, Peter. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkComboBoxEntry Vs GtkComboBox
Thanks Claudio. I'm just wondering why do I use the GTK_COMBO_BOX macro and not the GTK_COMBO_BOX_ENTRY macro? Many thanks, Peter. On 23/01/2008, Claudio Saavedra [EMAIL PROTECTED] wrote: El mar, 22-01-2008 a las 21:55 +1100, Peter E Dennis escribió: So I wondered if I needed to cast my GtkComboBoxEntry to a GtkComboBox but wasn't sure how to do this so I tried: gtk_combo_box_append_text(GTK_COMBO(cboVocSource), Hello World); This however makes matters worse as I get the above warning still when I compile it, but now when I run it I get: $ ./box (box:11338): GLib-GObject-WARNING **: invalid cast from `GtkComboBoxEntry' to `GtkCombo' Can someone please tell me what I'm doing wrong? You need to cast to a GtkComboBox, not to a GtkCombo. Use the GTK_COMBO_BOX macro. Claudio -- Claudio Saavedra [EMAIL PROTECTED] ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkComboBoxEntry Vs GtkComboBox
Thanks again Claudio for taking the time to explain that to me. Much appreciated. On 23/01/2008, Claudio Saavedra [EMAIL PROTECTED] wrote: El mié, 23-01-2008 a las 06:09 +1100, Peter E Dennis escribió: Thanks Claudio. I'm just wondering why do I use the GTK_COMBO_BOX macro and not the GTK_COMBO_BOX_ENTRY macro? Because gtk_combo_box_append_text () is a function that works on GtkComboBox objects, not GtkComboBoxEntry ones. As GtkComboBoxEntry inherites from GtkComboBox, you can use functions from the parent class in your GtkComboBoxEntry instance, but you need to cast it, given that C can't do it itself. A little pain of using GObject and C :-) Claudio Many thanks, Peter. On 23/01/2008, Claudio Saavedra [EMAIL PROTECTED] wrote: El mar, 22-01-2008 a las 21:55 +1100, Peter E Dennis escribió: So I wondered if I needed to cast my GtkComboBoxEntry to a GtkComboBox but wasn't sure how to do this so I tried: gtk_combo_box_append_text(GTK_COMBO(cboVocSource), Hello World); This however makes matters worse as I get the above warning still when I compile it, but now when I run it I get: $ ./box (box:11338): GLib-GObject-WARNING **: invalid cast from `GtkComboBoxEntry' to `GtkCombo' Can someone please tell me what I'm doing wrong? You need to cast to a GtkComboBox, not to a GtkCombo. Use the GTK_COMBO_BOX macro. Claudio -- Claudio Saavedra [EMAIL PROTECTED] ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Claudio Saavedra [EMAIL PROTECTED] ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Newbie Question about Navigating API doco
Hi Pablo, Thank you for the great overview of the documentation and pointing me towards the index. When I follow that link you provided to information about the delete_event it actually displays it as: The delete-event signal. Rather than: The delete_event signal I am sorry for being pedantic but this would make me believe when reading the documentation that I was to use delete-event in my program with a hyphen '-' not with an underscore '_' Is this standard notation in the documentation? Should I be reading any signals I see that contain a hyphen to substitute this with an underscore when it is written in code? Thanks again for your help. Peter. On 23/01/2008, Pablo Yanez Trujillo [EMAIL PROTECTED] wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Navigating the API doc is very easy once you've understood how it is organised. The API is divided in 5 main topics. I think the first three are the one that are most used. Topic 1, GTK+ Overview: gives you the overview of GTK+, i.e. what it is and how you can use it under different environments like Windows and Unix-like systems. Topic 2, GTK+ Core Reference: this is perhaps not the best part to start with because there are sometimes concepts that you understand later, when you have written some (little) GTK+ application. It conatains also main concepts that are widely used in the widgets. As a newbie I would read Main loop and Events, Signals and Types. Topic 3, GTK+ Widgets and Objects: here you have the documentation of the GTK+ Widgets you can use in your apps. This is far more a listing of constants, functions, macros, signals, properties, etc. that are declared within the widgets. Some widgets have explanations about how to use them but it cannot replace a good old tutorial :) At the top of each widget page you'll find a navigation bar with which you can navigate quickly through the page. Sometimes you see something and you don't have a clue where it belongs nor where to search for it. On the bottom of the start page you'll find a link to the index page. You'll find there a (more or less) complete list of the actual constants, functions, macros, signals, properties, etc. The point is, if say in the helloWorld program in the tutorial I change all instances of the string delete_event to monkey the program still compiles. Do you also have changed this line g_signal_connect (G_OBJECT (window), delete_event, G_CALLBACK (delete_event), NULL); to g_signal_connect (G_OBJECT (window), monkey, G_CALLBACK (monkey), NULL); ??? If so then you did a mistake. The second argument of the g_signal_connect function expects the name of a signal (internal name of the signal in GTK+, not the name of a function) and there isn't a monkey signal, hence you get the message that the signal `monkey' is invalid. I can't find a reference to delete_event in the API. But possibly not looking in the right place. I'm afraid so :) each widget has it own delete_event that is inherited from the GtkWidget class. Hence you will find the documentation of this particular signal under the GtkWidget page. If you would have searched it in the index page you would have found it :) http://library.gnome.org/devel/gtk/unstable/GtkWidget.html#id4180743 Regards Pablo Pablo Yanez Trujillo http://klingsor.informatik.uni-freiburg.de My public key: http://klingsor.informatik.uni-freiburg.de/gpg/supertux.asc Peter E Dennis wrote: Hi All, I am just starting out and going through the tutorial. I was wondering where I could find other signal strings like delete_event in the api? I noticed that it is defined in gtkwidget.c Do I need to know this kind of stuff? Sorry about the vague question, don't know enough to ask about it properly. The point is, if say in the helloWorld program in the tutorial I change all instances of the string delete_event to monkey the program still compiles. When I run it though I get: $ ./helloWorld (helloWorld:): GLib-GObject-WARNING **: /build/buildd/glib2.0-2.14.1/gobject/gsignal.c:1669: signal `monkey' is invalid for instance `0x8077000' I can't find a reference to delete_event in the API. But possibly not looking in the right place. Can someone point me to it and others like it for other widgets? Many thanks, Peter. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHlgnNDzf8xo+0xRURAkbXAKCojQ25bFtEZamRuqmAdUcZJe6wnQCeLHaS yISe7sWCaLM5GI6M1V49x8A= =Bp4C -END PGP SIGNATURE- ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list