Introduction to Gtk2-Perl
[30 mn de lecture - paru le 10/7/2004 3:02:44 PM - Public : Confirmé]
|
   
|
Auteur
2. Standard elements
There are more complex elements.
2.1. Adjustements
The adjustment elements may be compared to buttons but they are more complex because their operation is not boolean and allows a choice of several values.
In fact GTK allows here to create several types of adjustments. The problem might be related to the signals. If each adjustment passes a different signal, it will be a nightmare for thr programmer. There is thus an adjustement object which makes it possible to store signals from adjustments and to use them to make the use of the adjustments flexible:
$ajust = Gtk2::Adjustment->new($value,$lower,$upper,$step_increment,$page_increment,$page_size);
Here is a beautiful adjustment object, invisible because it does nothing but manage the data resulting from the other (visible) objects.
Parameters are :
- $value actual value
- $lower is the lower limit
- $upper is the upper showed limit (it's not the highest value of $value)
- $step_increment is the incrementation step
- $page_size is the visible zone of the widget
To get these information that you want to use differently, with your own manager:
get_adjustment->nom ;
where 'nom' is one of the following:
value
lower
upper
step_increment
page_increment
page_size
To use the signals resulting from the adjustments:
$ajust->signal_connect("value_changed",\&function);
Here, it is enough to connect a visible object to the desired adjustment:
$echelle = Gtk2::HScale->new( $ajust ) ;
Some adjustement widgets: HScale, VScale, HScrollBar, VScrollBar...
The update of the value changed by the user using the adjustments can be made in three ways:
$echelle->set_update_policy($update) ;
where $update is one of the following:
- continuous thus real time(default)
- discontinuous thus once the mouse button has been released
- delayed thus after a certain time.
2.2. Menus
Menus are essential elements in any application. They are cut out in 3 distinct elements:
- the menubar which comprises menu elements
- the menu which appears while clicking on an element of the menu
- the element of the menu or of the menubar.
The order of creation of a menu is thus made in this way:
- 1. We create the menubar
- 2. We create elements in the menubar
- 3. For each element in the menubar we create a menu
- 4. In each menu we create elements
- For each element in aech menu we create actions or other menus
- etc....
Lets see the it step by step:
1. $menubarre = Gtk2::MenuBar->new ();
2. $element01 = Gtk2::MenuItem->new($label);
$menubarre->append($element01); #To add element at the begining
or
$menubarre->prepend($element01); #To addelement at the end
3. $menu1 = Gtk2::Menu->new ();
4. $element11 = Gtk2::MenuItem->new($label);
$menu1->append($element11);
ou
$menu1->prepend($element11);
etc...
Very simple :)
2.3. Status Bar
The status bars post text, in general current usefull information for users.
$statusbar = Gtk::Statusbar->new();
The creation of a status bar implies the generation af an unique identificator used to identify the user. To get this id:
$statusbar->get_context_id( $description );
With the id we can modify the posting of the status bar which functions like a stack. The events are stacked before being posted. Here possible operations on the stack:
$statusbar->push( $context_id, $text );
$statusbar->pop( $context_id );
$statusbar->remove( $context_id, $message_id );
2.4. Barre d'outils
A basic tool bar is quite as easy to create:
$toolbar = Gtk2::Toolbar->new();
And we add the tool bar button as follows:
$toolbar->append_item ($text, $tooltip_text, $tooltip_private_text,
$icon, $fonction, $user_data);
$toolbar->prepend_item ($text, $tooltip_text, $tooltip_private_text,
$icon, $fonction, $user_data);
$toolbar->insert_item ($text,$tooltip_text,$tooltip_private_text,
$icon, $fonction, $user_data, $position);
Parameters are easy to understand but tooltip_private_text which must stay undefined because it's obsolete. user_data is a complementary parameter to pass to the called function.
We can add other elements than standard buttons:
$toolbar->append_element ( $type, $widget, $text,
$tooltip_text, $tooltip_private_text, $icon, $fonction, $user_data);
$toolbar->prepend_element ( $type, $widget, $text,
$tooltip_text, $tooltip_private_text, $icon, $fonction, $user_data);
$toolbar->insert_element ( $type, $widget, $text,
$tooltip_text, $tooltip_private_text, $icon, $fonction, $user_data,$position);
where type is one of the following:
- 'space' to add a space
- 'button' to add a button
- 'togglebutton' to add a toggle button
- 'radiobutton' to add a radio button
- 'widget' to add any other widget
We just can add any other object (widget) to the tool bar:
$toolbar->append_widget ($objet, $tooltip_text, $tooltip_private_text);
Parameters and methods allow various spacings between the objects, but also the insertion of icones starting from an ASCII ART. The bar can be vertical or horizontal...
2.5. Baloon tips
The baloon tips are small helpful popup messages which show up when one leaves the mouse one moment on an object:
$bulle = Gtk2::Tooltips->new();
$bulle->set_tip ( $element01 , "our first element in the menu " , "" ) ;
We can enable or disable them or set up the delay:
$bulle->enable();
$bulle->disable();
$bulle->set_delay ( $delay );
|