[Glade-users] How to create a popup window

Tristan Van Berkom tvb at gnome.org
Wed Feb 1 09:51:52 UTC 2012


On Wed, Feb 1, 2012 at 5:46 PM, Manuel Ferrero <mferrero at reer.it> wrote:
> I draw a simple application in Glade with a main window and a button.
> With the builder I show the GUI and all works fine.
>
> Now I need to show a popup window when I press a button on the main window
> and it seems to me I have two way to get it.
> The first one is to create and show a new window in the button_pressed
> callback and destroy it in the delete-event callback of the new popup
> window. In this case I don't use Glade to create the popup window and I have
> to manage all the properties and signals via code. The window is created
> from scratch and destroyed when its works is done.
> The second one is to draw the popup window and set all its properties and
> signals in Glade, use the builder to create both the main and the popup
> windows, show just the main window and in the button_pressed callback show
> the popup window and hide it its delete-event callback. The popup window
> will always exist even if it could be never used.
>
> A few questions:
> is my analysis right?

You missed one option, usually one would split up the interface into
the fragments which are needed on demand.

So essentially you can have a glade file that is used only to describe
the popup menu.

> Is one way better than the other?
> Is the second one more resource demanding?

Usually parsing the builder file is not a real bottleneck unless
it involves loading lots of images from the disk (i.e. if you custom
widgets are configured to load lots of pretty graphics).

You might want to convert your Glade file to a C header
file, i.e. const gchar *my_menu_or_dialog_content = "<strinified glade
file content>"
and then use gtk_builder_load_from_data() instead of scratching the
hard-disk every time you need to show a dialog or menu.

If the parse, creation time taken to create the widget from GtkBuilder
xml is an issue (usually if it's theme is complex or needs lots
of graphics), then you might consider building it at app startup
time and only showing/hiding it when you need it.

Basically, your question's answer depends on the constraints
of your application, if memory consumption is an issue, then
you want to create your UI components on demand, if load
time speed is an issue and not memory consumption, then your
obviously better off caching invisible UI components.

Cheers,
           -Tristan

>
> Thanks.
> --
> Regards,
> Manuel Ferrero
> R&D department
>
> Reer SpA
> Tel.  +39 011 2482215
> Fax. +39 011 859867
>
> L'utilizzo non autorizzato del presente messaggio e' vietato e potrebbe
> costituire reato.
> Se il presente messaggio non e' a Lei indirizzato, il suo contenuto non deve
> essere considerato
> come trasmesso o autorizzato dalla Reer SpA; in tale caso Le saremmo grati
> se, via e-mail,
> ce ne comunicasse l'errata ricezione.
>
> The unauthorized use of this e-mail is prohibited and could constitute an
> offence.
> If you are not the intended recipient of this message its contents shall be
> understood as neither
> given nor endorsed by Reer SpA. Please notify Reer SpA by e-mail immediately
> in that case.
>
> _______________________________________________
> Glade-users maillist  -  Glade-users at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/glade-users


More information about the Glade-users mailing list