Re: [Glade & Gtk-Perl] Adding widgets dynamically to windows

Hi Bhaskar,

"Bhaskar S. Manda" wrote:

I want to add a CListModel to a scrolled window. Glade doesn't have a
CListModel in its widget palette, so I see a few options.

1) Use custom widget from palette
The debug output of glade2perl indicates that custom widgets are ignored.
That's OK though ...  you can add any widget to a contaner after the
generated form is constructed. For instance, in Window_Class->app_run()
add a line before you show the form eg.

  $window->FORM->{'scrolledwindow9'}->add_with_viewport(new CListModel);

However, you must have a Perl binding for the CListModel widget. I don't
know whether there is one or not.

2) Build GUI dynamically with libglade
Does libglade handle the CListModel widget?

I don't see a perl module giving access to libbglade, 
use Gtk::GladeXML();

so assuming that
glade2perl generates a libglade application, I try to modify the files
it generates. Of the generated files, if I edit the <projectname>, 
The generated file for a Libglade app is src/ so edit
that if you want a Libglade type app. Call it with something like:
    perl -e 'use src::ProjectLIBGLADE; window1->app_run'

I can make it do whatever I want since I can access the widgets right 
after they are created in the code. But if I add some widgets through 
the Glade UI and then generate the code again, my modifications are
obviously lost. So I need to make changes in the <projectname>.pm file.

One way around this is to split off individual dialogs into files that 
Glade will not touch again, but then you can't add any more widgets 
through the UI.

Perhaps the documentation is not clear but have a look at the perldoc or
man page for Glade::PerlGenerate. There are project options that you can
add to the project options file (Project.glade2perl.xml) that will make
Glade-Perl generate libglade type code or split each class to separate

snipped from the man page:
<style> - default AUTOLOAD
  AUTOLOAD - OO class implements missing signal handlers 
    with an AUTOLOAD sub

  Libglade - generate libglade code and signal handlers

  split - generates each class in its own .pm file.

So if you edit the file to include the lines below it will generate
Libglade type code to a file called eg. src/ that
uses Gtk::GladeXML to show the form and has skeleton subs that will
handle the signals.


Back to the <projectname>.pm file. With all_forms, I can (per 
get at any widget. Since I need to essentially do a
scrolledwindow->add(widget), I get the scrolled window by adding a signal:

      my ($class, $data, $object, $instance, $event) = @_;

      my $form = $__PACKAGE__::all_forms->{$instance};
      my $window = $form->{'scrolledwindow9'};
      my $clistmodel = &sub_that_makes_clistmodel;
This doesn't work:
   widget is not of type Gtk::Widget at line xx (the line with 
You don't call add() with a scrolledwindow you call eg.
    $scrolled_window->add_with_viewport( $child ); 

The easiest way to do this is in the app_run() sub as I explained above.

If I use the class that comes in, $class, which prints out as a
there is still the same error. So how can I do this?

HTH, Dermot

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]