Introduction to Gtk2-Perl
[30 mn de lecture - paru le 10/7/2004 3:02:44 PM - Public : Confirmé]
|
   
|
Auteur
3. Advanced Elements
The text fields seem simple. But they can react to multiple signals.
$entree = Gtk::Entry->new();
The object above is a text field where we can type only one line. The content can be accessed with:
$entree->set_text( $text );
$entree->append_text( $text );
$entree->prepend_text( $text );
We can set the text invisible::
$entree->set_visibility($visible ); #valeur booléenne.
We can create large text fields with:
$editable->select_region( $start, $end );
And modify the content with :
$editable->insert_text( $new_text, $position );
$editable->delete_text( $start, $pos );
$editable->get_chars( $start, $end );
$editable->cut_clipboard();
$editable->copy_clipboard();
$editable->paste_clipboard();
$editable->delete_selection();
These methods are quite simple to understand, there is no need to explain them.
Any action on the text field generates signals which may be 'changed', 'insert-text', 'delete-text'.... The list of generated signals is too large to describe.
Dialog boxes alow interaction between the user and the software.:
$dialog = Gtk2::Dialog->new($titre,$parent,$flags...);
dialog boxes contain in general text (a label) and buttons. To achieve that, these elements are stacked in a VBOX.
The actions on dialog boxes may be:
- 'none'
- 'reject'
- 'accept'
- 'delete-event'
- 'ok'
- 'cancel'
- 'close'
- 'yes'
- 'no'
- 'apply'
- 'help'
It is not necessary to create of any part one dialog box. One can always use one of the preset ones:
$dialog = Gtk2::MessageDialog->new ($fenetre_parente,
$flags,$type,$bouton,..
$message);
types may be :
- 'info'
- 'question'
- 'error'
- 'warrning'
Notebooks is a way to handle multiple pages in a same window.
$onglets = Gtk2::Notebook->new();
To add a page to the notebook :
$onglets->append_page( $child, $tab_label );
The line above describes how to append a page, but there still is a way to prepend or insert à page between two other pages.
The operations on pages may be various:
$onglets->remove_page( $page_num );
$onglets->get_current_page();
$onglets->page_num( $child );
$onglets->next_page();
$onglets->prev_page();
...
The progress bars allow the visualization of the advance of a task.
$progress = Gtk2::ProgressBar->new();
We can modify the advance by updating the percentage of advance:
$progress->set_fraction($percentage );
Of course the bar can advance from left to right, from right to left, upwards and from top to bottom:
$progress->set_orientation( $orientation );
orientations are :
-
'left_to_right'
- 'right_to_left'
-
'bottom_to_top'
-
'top_to_bottom'
If a task cannot be sized it is often useful to show the activity of it rather than a false estimation:
$progress->pulse();
progress->set_pulse_step($fraction);
We can add a text to the bar :
$progress->set_text( $text );
|