GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Nov 26, 2014 9:24 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [solved] hide gui elements on startup
PostPosted: Sat Sep 22, 2012 9:58 am 
Offline
Familiar Face

Joined: Sat Sep 22, 2012 7:06 am
Posts: 6
Hi, I just started programming in python and using glade to build my Gui, for the time being in gtk2 as gtk3 gives me numerous errors which shouldn't occur (even I can judge that from my basic sckills). I wrote some command line python scripts some years ago so I'm not a complete beginner, but I am with regard to glade and gtk.

I create a gtk2 gui in glade with a number of elements. One of these elements is a gtkcombobox offering you the option to set the outputto jpg, tiff or png, where jpg is the default.
If jpeg is selected only a spinbutton with jpeg compression is displayed.
if tiff is selected only a combobox with tiff compression options is displayed
if png is selected there is no further selection.
This is handled in the following code:
Code:
def on_cb_imageformats_changed(self, combo ):
        # Which image format did we select
        value = combo.get_active_text()
        print "selected output format: " + value
        if value == "JPEG":
                self.lbl_tiffcompression.hide()
                self.cb_tiffcompression.hide()
                self.lbl_jpegcompression.show()
                self.spinbutton_jpegcompression.show()
        elif value == "TIFF":
                self.lbl_tiffcompression.show()
                self.lbl_jpegcompression.hide()
                self.cb_tiffcompression.show()
                self.spinbutton_jpegcompression.hide()
        else:  #PNG
                self.lbl_jpegcompression.hide()
                self.lbl_tiffcompression.hide()
                self.cb_tiffcompression.hide()
                self.spinbutton_jpegcompression.hide()

This works fine. However, as jpeg is the default I want to hide the tiff label and combobox on startup.
At the end of the "def __init__( self ):" routine I use the same code for my tiff label and combobox with a print statement to see whether it gets there and whether it gets executed
Code:
        print "And now we hide our tiff elements"
        self.lbl_tiffcompression.hide()
        self.cb_tiffcompression.hide()

It writes the print statement but doesn't execute the hide commands and gives no error either. What am I doing wrong?

Note: If I switch the sensitivity (enabled/disabled) in glade the element gets disabled but I can't enable it anymore from the code. If I set the visibility in glade (hide/show) it has no influence at all.
Again: Am I doing something wrong or is this maybe a bug?

Ubuntu 12.04 64bits
glade 3.8.0
python 2.7.3 (although 3.2 is also installed as a dependency for blender)
python-gtk2 2.24.0-3


Last edited by hvdwolf on Sun Sep 23, 2012 8:58 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: hide gui elements on startup
PostPosted: Sat Sep 22, 2012 1:50 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Ok I don't know python but I'm also aware that there aren't as many python programmers on the forum so I might jump in in case you don't get a reply otherwise. I don't know if python has it (it probably does) but a lot of what you can do is with the (in c) gtk_file_chooser_dialog functions. You can then set up various gtk_file_filters, add mime types to them, add them to the file chooser and then set the default with gtk_file_chooser_set_filter. It looks like similar functions exist in pyGTK (http://developer.gnome.org/pygtk/stable/class-gtkfilefilter.html, http://developer.gnome.org/pygtk/stable/class-gtkfilechooser.html#method-gtkfilechooser--add-filter, http://developer.gnome.org/pygtk/stable/class-gtkfilechooser.html#method-gtkfilechooser--set-filter).


Top
 Profile  
 
 Post subject: Re: hide gui elements on startup
PostPosted: Sat Sep 22, 2012 5:17 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums!

hvdwolf wrote:
At the end of the "def __init__( self ):" routine I use the same code for my tiff label and combobox with a print statement to see whether it gets there and whether it gets executed
Code:
        print "And now we hide our tiff elements"
        self.lbl_tiffcompression.hide()
        self.cb_tiffcompression.hide()

It writes the print statement but doesn't execute the hide commands and gives no error either. What am I doing wrong?


Are you sure these two commands are not executed? I would guess that some later call overrides the state of these two widgets (something like show_all()).

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: hide gui elements on startup
PostPosted: Sat Sep 22, 2012 10:09 pm 
Offline
Familiar Face

Joined: Sat Sep 22, 2012 7:06 am
Posts: 6
tadeboro wrote:
Are you sure these two commands are not executed? I would guess that some later call overrides the state of these two widgets (something like show_all()).

Thanks for your replies.
I think that makes sense. I have also been looking for "something" I could execute on startup, or better said: After the full gui has loaded.
Is there some event or signal I could use to check whether "everything" has loaded and I can execute "something else"? I can't find it.
Something like:
Code:
def on_Mainwindow_completely_loaded(self, *args):
      do this
      do that

I come from Apple (not Gtk) and that event does exist there: for the main window and for every widget in it: After it has fully loaded you can execute some initializing code.


Top
 Profile  
 
 Post subject: Re: hide gui elements on startup
PostPosted: Sat Sep 22, 2012 10:12 pm 
Offline
Familiar Face

Joined: Sat Sep 22, 2012 7:06 am
Posts: 6
Paul Childs wrote:
Ok I don't know python but I'm also aware that there aren't as many python programmers on the forum so I might jump in in case you don't get a reply otherwise. I don't know if python has it (it probably does) but a lot of what you can do is with the (in c) gtk_file_chooser_dialog functions. You can then set up various gtk_file_filters, add mime types to them, add them to the file chooser and then set the default with gtk_file_chooser_set_filter. It looks like similar functions exist in pyGTK (http://developer.gnome.org/pygtk/stable/class-gtkfilefilter.html, http://developer.gnome.org/pygtk/stable/class-gtkfilechooser.html#method-gtkfilechooser--add-filter, http://developer.gnome.org/pygtk/stable/class-gtkfilechooser.html#method-gtkfilechooser--set-filter).

It's not the file chooser. I can indeed set file filters, choose between read or save mode, etc.
It's really about hiding widgets on startup.


Top
 Profile  
 
 Post subject: Re: hide gui elements on startup
PostPosted: Sun Sep 23, 2012 7:54 am 
Offline
Never Seen the Sunlight

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

GTK+ objects are completely loaded after the call to _new() function returns (or, in other languages, when constructor returns), so there is no need for such a signal, since any state updates can be done right after that call.

Are you sure you're not calling show_all() method on any of the widget's parents? I've been thinking about this and this is probably the only function that could mess things up in the manner you describe.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: hide gui elements on startup
PostPosted: Sun Sep 23, 2012 8:57 am 
Offline
Familiar Face

Joined: Sat Sep 22, 2012 7:06 am
Posts: 6
tadeboro wrote:
Are you sure you're not calling show_all() method on any of the widget's parents? I've been thinking about this and this is probably the only function that could mess things up in the manner you describe.

Well, of course I have in my main script
Code:
if __name__ == "__main__":
    win = ImageFuser()
    win.window.show_all()
    gtk.main()

However, my Ubuntu is set to Dutch. The translation of the parameter "No show All:" and it's corresponding tooltip (whether the widget should react to "show all") in glade is the opposite of the english version. So I had set the button to "No" as it corresponded to the Dutch "react to show all".
Now I logged in in english and the tooltip is now the opposite. So I now set the "No show all:" button to yes and now it functions: the label and combobox are hidden on startup.

Sorry for waisting your time on which obviously was the result of some badly translated strings.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 2 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