A good document about how to interface a GladeXML file from Perl



Heya,

I'm trying to find information how to control the widgets like
a Progressbar, GtkTextView etc in a GladeXML file from a Perl module.


I'm using Glade 2.9.0, GTK2 2.6.4, Perl 5.8.6.

I have some success in writing handler to buttons activated, but
right now I print to the console to check that the button click activate
my handler.  And it does! 
How can I display this console output in my GTK GUI? Can I use a
GtkTextView widget to do that or is it only for input? 
And how to update the progressbar widget from Perl?

Here is my relevant code:

from mtpfat.Glade:

<child> 
                    <widget class="GtkImageMenuItem" id="quit1">
                      <property name="visible">True</property>
                      <property name="label">gtk-quit</property>
                      <property name="use_stock">True</property>
                      <signal name="activate" handler="on_quit1_activate" last_modification_time="Thu, 06 Oct 
2005 23:23:25 GMT"/>
                    </widget>
                  </child>

..

<child> 
                <widget class="GtkProgressBar" id="progressbar1">
                  <property name="visible">True</property>
                  <property name="orientation">GTK_PROGRESS_LEFT_TO_RIGHT</property>
                  <property name="fraction">1</property>
                  <property name="pulse_step">0.10000000149</property>
                  <property name="text" translatable="yes"></property>
                  <property name="ellipsize">PANGO_ELLIPSIZE_START</property>
                  <signal name="progressSignal" handler="progressHandler" last_modification_time="Thu, 20 Oct 
2005 21:08:57 GMT"/>
                </widget>
                <packing>
                  <property name="padding">0</property>
                  <property name="expand">False</property>
                  <property name="fill">False</property>
                </packing>
              </child>


.. 
              <child>
                <widget class="GtkFrame" id="frame1">
                  <property name="visible">True</property>
                  <property name="label_xalign">0</property>
                  <property name="label_yalign">0.5</property>
                  <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
                  <signal name="testoutput" handler="gtk_widget_show" last_modification_time="Tue, 18 Oct 
2005 23:00:45 GMT"/>

                  <child>
                    <widget class="GtkScrolledWindow" id="scrolledwindow1">
                      <property name="visible">True</property>
                      <property name="can_focus">True</property>
                      <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
                      <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
                      <property name="shadow_type">GTK_SHADOW_NONE</property>
                      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

                      <child>
                        <widget class="GtkTextView" id="textview1">
                          <property name="border_width">4</property>
                          <property name="visible">True</property>
                          <property name="can_focus">True</property>
                          <property name="editable">True</property>
                          <property name="overwrite">False</property>
                          <property name="accepts_tab">True</property>
                          <property name="justification">GTK_JUSTIFY_LEFT</property>
                          <property name="wrap_mode">GTK_WRAP_WORD</property>
                          <property name="cursor_visible">True</property>
                          <property name="pixels_above_lines">0</property>
                          <property name="pixels_below_lines">0</property>
                          <property name="pixels_inside_wrap">0</property>
                          <property name="left_margin">0</property>
                          <property name="right_margin">0</property>
                          <property name="indent">0</property>
                          <property name="text" translatable="yes"></property>
                          <signal name="show" handler="on_textview1_show" last_modification_time="Thu, 27 Oct 
2005 17:24:18 GMT"/>
                        </widget>
                      </child>
                    </widget>
                  </child>


mtpfat file:

#!/usr/bin/perl -w 
use mtpfat1;

Gtk2->main;





From mtpfat1.pm:

#################################### 
### Main package ##
####################################

package mtpfat1;

use strict ;

require Exporter;
use vars qw(@EXPORT_OK);
@EXPORT_OK = qw ($gladexml);
use vars qw($gladexml);

use Gtk2 '-init';
use Gtk2::GladeXML;

$gladexml = Gtk2::GladeXML->new('mtpfat.glade');

# Initialize variables of the âcallbacksâ package.
callbacks::init ();

# Connect each callback function from the xml tree
# to their definitions written in the âcallbacksâ package.
$gladexml->signal_autoconnect_from_package('callbacks');
our $progresbar1 = $gladexml->get_widget('progressbar1');

1 ;

################################
### Callback functions ##
################################

package callbacks ;

use strict;
use vars qw($gladexml);
# $gladexml is the variable that deal with the main xml tree.

# Initalize the $gladexml value.
sub init {
$gladexml = $mtpfat1::gladexml ;
}

sub on_quit1_activate { 
my $quit1 = $gladexml->get_widget('quit1' );
print "on quit1 er activated \n";
Gtk2->main_quit;
}


sub on_textview1_show { 
??????????????

}


Hope that someone can guide me in the right direction, I have been
googled around without luck. 
Thanks in advanced!

Plung










-- 
Pih Lung Pang <plp southwestmicrowave com>




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