Zim::GUI::Component.3pm

Langue: en

Autres versions - même langue

Version: 2009-02-23 (debian - 07/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

Zim::GUI::Component - GUI base class

SYNOPSIS

FIXME example of a component init using actions etc.

DESCRIPTION

This class provides a base class for GUI components in zim. Modules can inherit a number of convenience methods from it.

Most GUI methods expect the "{app}" attribute to be set. This aplication object is expected to have attributes "{ui}" and "{window}".

METHODS

"new(%ATTRIBUTES)"
Simple constructor, calls "init()".
"init()"
Called by the constructor, to be overloaded.
"init_settings(NAME, \%DEFAULTS)"
Will initialise a hash $$self{settings} which is linked to section NAME in the config file. Intended for use by plugin modules.

When the whole section is missing it will be initialized with %DEFAULTS.

When called on the main application object it will not change $$app{settings} but only return the hash for the section requested.

"init_state(NAME, \%DEFAULTS)"
Like "init_settings()" but initializes $$self{state} and links to the file with state variables, not the config file.
"widget()"
Returns the ``top_widget'' attribute. This should be the toplevel widget for the GUI managed by this object.
"AUTOLOAD()"
Autoloader for object methods.

If you have a "{widget}" attribute in your object this will be the target for unknown methods.

UI Methods

"add_actions(ACTIONS, TYPE, FUNCTION)"
Add plain text action descriptions to the interface.

TYPE can be "undef", ``menu'', ``toggle'' or ``radio''.

FUNCTION is an optional function name. This is used to set a single callback for all actions. If NAME is not defined the callback function for each action will be of the same name as the action.

"get_action($NAME)"
"actions_set_sensitive($NAME => $VAL, ...)"
Set the sensitivity for one or more actions by name.
"actions_set_active($NAME => $VAL, ...)"
Set the one or more actions active by name.

Used to make the state of the actions match the settings. When it results in a change of state the handler is called, which in turn makes the state of the application match the settings.

"actions_show_active($NAME => $VAL, ..)"
Like "actions_set_active()" but prevents the action callback to be called. This method is used to make the appearance of the action match the state of the application.

The blocking works at the level of our AUTOLOAD function.

"add_ui($UI)"
Add a xml style ui description to the interface.
"popup($NAME, $BUTTON, $TIME, @ARGS)"
Popup the menu called NAME from the ui spec. BUTTON and TIME are passed to "Gtk2::Menu->popup()". Any ARGS are forwarded to the actions.

Actions

"ShowHelp(PAGE)"
"ShowHelp(NOTEBOOK, PAGE)"
Show a window showing the documentation. Both PAGE and NOTEBOOK are optional. NOTEBOOK defaults to '_doc_' (same as "--doc" on the commandline) but can be specified to be e.g. '_man_' (same as "--man").

In the one argument form the page must start with a ':'.

Process Methods

"call_daemon(@ARGS)"
Echo arguments to the daemon. See Zim::GUI::Daemon. Returns FALSE when no daemon listening.
"exec_new_window(@ARGS)"
Executes a new process for $0, this gives a detached window. Any arguments are passed on to the new process.

Helper Methods

"check_page_input()"
Checks whether an user input is indeed a page name and not e.g. an url. Returns a page name or undef. Page name didn't go through cleanup, so does not need to be valid.
"check_file_input(PATH)"
Resolves user input to an absolute path. When users specify a path it could be either be relative to document dir or document dir. This method tries to figure it out and return the right path. File does not need to exit. Returns a file object.
"decode_uri_list(TEXT)"
Method to decode data in the "text/uri-list" format. This format is used with drag-drop operations of files etc. Returns a list of uris.
"encode_uri_list(URI, ...)"
Method to encode data in the "text/uri-list" format. This format is used with drag-drop operations of files etc. Returns ascii text data.
"new_button(STOCK, TEXT)"
Creates a button with a stock image but different text.
"new_small_button(STOCK)"
Creates a small button without text.
"new_textview(TEXT)"
Returns a Gtk2::ScrolledWindow and a Gtk2::Textview. Sets scrolling, shadow and margins properly.
"set_treeview_single_click(TREEVIEW)"
Make TREEVIEW a single click navigation widget.
"list_text_targets(INFO)"
Returns a list of targets used to copy-paste or drag-drop text.

Common Dialogs

"new_prompt(TITLE, FIELDS, DATA, BUTTON_STOCK, BUTTON_TEXT, TEXT)"
Generates a dialog asking for one or more fields of input. Returns the dialog widget and a list with Gtk2::Entry objects.

TITLE is the dialog title.

FIELDS and DATA are used for the "new_form()" method.

TEXT, BUTTON_STOCK and BUTTON_TEXT are optional.

"new_form(FIELDS, DATA, DIALOG)"
FIELDS is an array ref giving the order of the input fields.

DATA is a hash ref containing definitions of the input fields. The key is the name used in FIELDS, the value an array ref with a label text, a data type and a value.

At the moment only the ``string'', ``int'', ``page'', ``file'' and ``dir'' data types are treated special, all other will be ignored silently.

The ``file'' and ``dir'' types can have a 4th item being the dir to open when the value is empty and the ``Browse'' button is clicked.

The ``int'' type has a range and a step size, so the 4th argument should be a array ref with 3 numbers: min, max and step.

DIALOG is optional and will be used to connect signals.

"set_page_completion(ENTRY)"
Attach page completions code to a Gtk2::Entry object.
"run_prompt(..)"
Wrapper around "new_prompt()" that runs the dialog and returns a list with input values. Returns undef on 'cancel'.
"prompt_question(TYPE, TEXT, BUTTONS ..., TIME)"
TYPE can either be 'error', 'warning', 'question', 'info' or "undef".

Runs a dialog displaying TEXT To comform with the Gnome HIG, the text should consist of a primary text in bold, possibly followed by an empty line and secondary text in normal style. Please make sure the text ends with a question if you expect a response.

BUTTONS is a list of array references, each containing a name, a stock item name and/or text. The id of the button that was pressed is returned.

TIME is an optional argument, it gives a timeout in seconds. This is used for popups that can popup while the user is typing to prevent accidental triggering of a accelerator.

"exit_error(ERROR)"
Like "error_dialog" but exits afterwards.
"error_dialog(ERROR)"
This method is used to display errors.
"filechooser_dialog(PATH, WANT_DIR, TITLE)"
Show the user a dialog to browse the file system and choose a file or directory. PATH is the suggested file or directory. WANT_DIR is a boolean that controls whether this dialog selects a file or a dir. TITLE is an optional title for the dialog.

If PATH is not defined, either the last directory used by a filechooser dialog from this GUI Component, the current document root or document dir will be opened. To control which directory opens, set the attribute $$self{filechooser_dir}. This attribute will be set to the lastest directory after the dialog is closed.

Returns an absolute path or undef.

"new_progress_bar(TITLE, LABEL)"
Returns a dialog with a progress bar.

AUTHOR

Jaap Karssenberg (Pardus) <pardus@cpan.org>

Copyright (c) 2006 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO