Editing PyMaemo/UI tutorial/Controls
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
Warning: This page is 39 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
- | + | = Controls = | |
- | + | ||
Hildon provides a set of controls specially designed for touchscreens that allows to build simple and easy-to-use interfaces. This chapter explains how to use these widgets. | Hildon provides a set of controls specially designed for touchscreens that allows to build simple and easy-to-use interfaces. This chapter explains how to use these widgets. | ||
+ | |||
== Buttons == | == Buttons == | ||
- | + | A Hildon application can use several types of buttons. Hildon provides specialized buttons derived from GtkButton which provide additional commodities specific to the Hildon framework. Using GtkButtons and GtkToggleButtons is also recommended. | |
- | A Hildon application can use several types of buttons. Hildon provides specialized buttons derived from | + | |
===Hildon Button=== | ===Hildon Button=== | ||
+ | HildonButton is a GtkButton which usually contains two labels, title and value. It can also include an image. | ||
- | + | To create a HildonButton, use the following function: | |
- | |||
- | |||
button = hildon.Button(size, arrangement, title='', value='') | button = hildon.Button(size, arrangement, title='', value='') | ||
- | + | ||
- | Note that in the creation of a | + | |
+ | Note that in the creation of a HildonButton you must indicate the value for the properties "size" and "arrangement", choosing a Hildon size and a horizontal or vertical arrangement of the labels. | ||
You can set and retrieve both labels by using the following convenience functions: | You can set and retrieve both labels by using the following convenience functions: | ||
- | + | ||
hildon.Button.set_title(title) | hildon.Button.set_title(title) | ||
hildon.Button.set_value(value) | hildon.Button.set_value(value) | ||
title = hildon.Button.get_title() | title = hildon.Button.get_title() | ||
value = hildon.Button.get_value() | value = hildon.Button.get_value() | ||
- | + | ||
- | Alternatively, use the following function to set both labels of a | + | |
- | + | Alternatively, use the following function to set both labels of a HildonButton: | |
+ | |||
hildon.Button.set_text(title, value) | hildon.Button.set_text(title, value) | ||
- | + | ||
- | To add images to | + | To add images to HildonButtons, use the following functions to set and retrieve the current image: <code>hildon_button_set_image()</code> and <code>hildon_button_get_image()</code>. |
You can also set the position of the image. | You can also set the position of the image. | ||
- | + | ||
hildon.Button.set_image_position(position) | hildon.Button.set_image_position(position) | ||
- | |||
- | |||
- | |||
- | + | Currently supported positions are gtk.POS_LEFT or gtk.POS_RIGHT. | |
- | + | The visual style (color, fonts, etc) of a HildonButton can be changed by using the function <code>set_style()</code>. Use hildon.BUTTON_STYLE_NORMAL to make it look like a normal HildonButton, or hildon.BUTTON_STYLE_PICKER to make it look like a HildonPickerButton. | |
- | < | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | The next simple example shows how to create a HildonButton, set the label text and add an image. | |
- | + | ||
- | # Set | + | '''Example 7.1. Example of a Hildon button with a label and an image''' |
- | image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON) | + | |
- | + | def create_button(): | |
- | + | # Create a hildon button | |
+ | button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, | ||
+ | hildon.BUTTON_ARRANGEMENT_VERTICAL) | ||
+ | |||
+ | # Set labels value | ||
+ | button.set_text("Some title", "Some value") | ||
+ | |||
+ | # Set image | ||
+ | image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON) | ||
+ | button.set_image(image) | ||
+ | button.set_image_position(gtk.POS_RIGHT) | ||
+ | |||
+ | return button | ||
- | |||
- | |||
===Hildon Check Button=== | ===Hildon Check Button=== | ||
+ | HildonCheckButton is a button that contains a label and a check box. The check box toggles between checked or unchecked. | ||
+ | |||
+ | To create a HildonCheckButton: | ||
- | < | + | <tt> GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_check_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HildonSizeType size<span><font color="#990000">);</font></span> |
+ | </tt> | ||
- | |||
- | |||
- | |||
- | |||
Note that, again, you must specify the size of the button. | Note that, again, you must specify the size of the button. | ||
You can retrieve or set the current state of the button with the following functions, respectively: | You can retrieve or set the current state of the button with the following functions, respectively: | ||
- | < | + | |
- | + | <tt>gboolean <span>'''<span><font color="#000000">hildon_check_button_get_active</font></span>'''</span> <span><font color="#990000">(</font></span>HildonCheckButton <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000">);</font></span> | |
- | + | <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_check_button_set_active</font></span>'''</span> <span><font color="#990000">(</font></span>HildonCheckButton <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000">,</font></span> | |
- | </ | + | gboolean is_active<span><font color="#990000">);</font></span> |
+ | </tt> | ||
+ | |||
The signal "toggled" is emitted when the state of the button changes. A handler can be attached to this signal if a further action is required. | The signal "toggled" is emitted when the state of the button changes. A handler can be attached to this signal if a further action is required. | ||
Line 77: | Line 80: | ||
'''Example 7.2. Example of a Hildon check button''' | '''Example 7.2. Example of a Hildon check button''' | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | + | <tt><span><font color="#009900">void</font></span> | |
- | + | <span>'''<span><font color="#000000">button_toggled</font></span>'''</span> <span><font color="#990000">(</font></span>HildonCheckButton <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000">,</font></span> gpointer user_data<span><font color="#990000">)</font></span> | |
- | + | <span><font color="#FF0000">{</font></span> | |
- | + | gboolean active<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | active <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_check_button_get_active</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">);</font></span> | |
- | </ | + | <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>active<span><font color="#990000">)</font></span> |
- | = | + | <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Button is active"</font></span><span><font color="#990000">);</font></span> |
+ | <span>'''<span><font color="#0000FF">else</font></span>'''</span> | ||
+ | <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Button is not active"</font></span><span><font color="#990000">);</font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span> | ||
+ | <span>'''<span><font color="#000000">create_button</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_check_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_button_set_label</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Click me"</font></span><span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"toggled"</font></span><span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>button_toggled<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#0000FF">return</font></span>'''</span> button<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | </tt> | ||
- | As was said above, apart from Hildon specific buttons, use | + | |
+ | ==Using Gtk Buttons and Toggles== | ||
+ | As was said above, apart from Hildon specific buttons, use GtkButton and GtkToggleButton also in the Hildon framework. | ||
===GtkButton=== | ===GtkButton=== | ||
+ | If only a label is needed, you do not need to use HildonButtons and a GtkButton can be used instead. You can use it as you would do in a GTK application. The only change is the creation function that you must use: | ||
+ | |||
+ | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_gtk_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HildonSizeType size<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
- | |||
- | |||
- | |||
- | |||
This alternative constructor allows you to set a Hildon size for the newly create function. | This alternative constructor allows you to set a Hildon size for the newly create function. | ||
===GtkToggleButton=== | ===GtkToggleButton=== | ||
+ | To create a GtkToggleButton in a Hildon application you should use: | ||
+ | |||
+ | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_gtk_toggle_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HildonSizeType size<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
- | |||
- | |||
- | |||
- | |||
==GtkRadioButton== | ==GtkRadioButton== | ||
+ | To create a GtkRadioButton in a Hildon application, use: | ||
+ | |||
+ | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_gtk_radio_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HildonSizeType size<span><font color="#990000">,</font></span> | ||
+ | GSList <span><font color="#990000"><nowiki>*</nowiki></font></span>group<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
- | |||
- | |||
- | |||
- | |||
The most common use case of this type of buttons in a Hildon application is as filters in a application menu. For more information, see section Touch View Menu. | The most common use case of this type of buttons in a Hildon application is as filters in a application menu. For more information, see section Touch View Menu. | ||
==Text display and handling == | ==Text display and handling == | ||
- | + | Text entry fields are used for entering one or more lines of plain text. Use a HildonEntry for a single-line text input or HildonTextView if you need a multi-line text input. | |
- | Text entry fields are used for entering one or more lines of plain text. Use a | + | |
===Hildon Text Entry=== | ===Hildon Text Entry=== | ||
- | + | The HildonEntry is a GTK+ widget which represents a text entry. It is derived from the GtkEntry widget and provides additional commodities specific to the Hildon framework. | |
- | The | + | |
The main additional feature is a placeholder text to display if the entry is empty and not in focus. | The main additional feature is a placeholder text to display if the entry is empty and not in focus. | ||
- | Creating a new < | + | Creating a new HildonEntry: |
- | < | + | |
- | + | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_entry_new</font></span>'''</span> <span><font color="#990000">(</font></span>HildonSizeType size<span><font color="#990000">);</font></span> | |
- | </ | + | </tt> |
- | Note that the creation function needs to specify a size from | + | |
+ | Note that the creation function needs to specify a size from HildonSizeType. | ||
The placeholder is stored as a property. To set it, use the following convenience function: | The placeholder is stored as a property. To set it, use the following convenience function: | ||
- | |||
- | |||
- | |||
- | Here's a very simple example showing how to create a | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_entry_set_placeholder</font></span>'''</span> <span><font color="#990000">(</font></span>HildonEntry <span><font color="#990000"><nowiki>*</nowiki></font></span>entry<span><font color="#990000">,</font></span> |
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>text<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
+ | |||
+ | Here's a very simple example showing how to create a HindonEntry. | ||
'''Example 7.3. Example of a Hildon entry''' | '''Example 7.3. Example of a Hildon entry''' | ||
- | < | + | |
- | + | <tt>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span> | |
- | + | <span>'''<span><font color="#000000">create_entry</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">)</font></span> | |
- | + | <span><font color="#FF0000">{</font></span> | |
- | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>entry<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | </ | + | entry <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_entry_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">);</font></span> |
+ | <span>'''<span><font color="#000000">hildon_entry_set_placeholder</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_ENTRY</font></span>'''</span> <span><font color="#990000">(</font></span>entry<span><font color="#990000">),</font></span> | ||
+ | <span><font color="#FF0000">"First name"</font></span><span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#0000FF">return</font></span>'''</span> entry<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | </tt> | ||
+ | |||
===Hildon Text Area=== | ===Hildon Text Area=== | ||
- | The | + | The HildonTextView is a GTK+ widget which represents a text area in Hildon applications. It is derived from the GtkTextView widget and provides additional commodities specific to the Hildon framework. |
- | Create a | + | Create a HildonTextView: |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ''' | + | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_text_view_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span> |
- | < | + | </tt> |
- | + | ||
- | + | ||
- | + | Like for the HildonTextEntry presented above, you can store a placeholder as well using the function. | |
- | + | ||
- | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_text_view_set_placeholder</font></span>'''</span> <span><font color="#990000">(</font></span>HildonEntry <span><font color="#990000"><nowiki>*</nowiki></font></span>entry<span><font color="#990000">,</font></span> | |
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>text<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
- | + | The text that is being edited with a HildonTextView is represented by a object GtkTextBuffer. The following functions can be used to set and retrieve the buffer associated with a HildonTextView. | |
- | + | ||
- | + | ||
- | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_text_view_set_buffer</font></span>'''</span> <span><font color="#990000">(</font></span>HildonTextView <span><font color="#990000"><nowiki>*</nowiki></font></span>text_view<span><font color="#990000">,</font></span> | |
- | + | GtkTextBuffer <span><font color="#990000"><nowiki>*</nowiki></font></span>buffer<span><font color="#990000">);</font></span> | |
+ | GtkTextBuffer<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_text_view_get_buffer</font></span>'''</span> <span><font color="#990000">(</font></span>HildonTextView <span><font color="#990000"><nowiki>*</nowiki></font></span>text_view<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
- | + | Here is an example that shows how to create a HildonTextView and how to set its placeholder. Also, the buffer is retrieved and a function is set as a handler to the "changed" of the buffer. The handler simply gets the text from the HildonTextView's buffer and prints it. | |
- | + | ||
- | + | ||
- | + | '''Example 7.4. Example of a Hildon text view with a placeholder''' | |
- | == | + | <tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> |
+ | <span>'''<span><font color="#000000">text_changed</font></span>'''</span> <span><font color="#990000">(</font></span>GtkTextBuffer <span><font color="#990000"><nowiki>*</nowiki></font></span>buffer<span><font color="#990000">,</font></span> | ||
+ | gpointer <span><font color="#990000"><nowiki>*</nowiki></font></span>user_data<span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>text<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | GtkTextIter start<span><font color="#990000">,</font></span> end<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_text_buffer_get_start_iter</font></span>'''</span> <span><font color="#990000">(</font></span>buffer<span><font color="#990000">,</font></span> <span><font color="#990000">&</font></span>start<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_text_buffer_get_end_iter</font></span>'''</span> <span><font color="#990000">(</font></span>buffer<span><font color="#990000">,</font></span> <span><font color="#990000">&</font></span>end<span><font color="#990000">);</font></span> | ||
+ | text <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_text_buffer_get_text</font></span>'''</span> <span><font color="#990000">(</font></span>buffer<span><font color="#990000">,</font></span> <span><font color="#990000">&</font></span>start<span><font color="#990000">,</font></span> <span><font color="#990000">&</font></span>end<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span>text<span><font color="#990000">);</font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span> | ||
+ | <span>'''<span><font color="#000000">create_text_view</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>text_view<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | text_view <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_text_view_new</font></span>'''</span><span><font color="#990000">();</font></span> | ||
+ | <span>'''<span><font color="#000000">hildon_text_view_set_placeholder</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_TEXT_VIEW</font></span>'''</span> <span><font color="#990000">(</font></span>text_view<span><font color="#990000">),</font></span> | ||
+ | <span><font color="#FF0000">"Type some text here"</font></span><span><font color="#990000">);</font></span> | ||
+ | buffer <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_text_view_get_buffer</font></span>'''</span> <span><font color="#990000">(</font></span>textview<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span>buffer<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"changed"</font></span><span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>text_changed<span><font color="#990000">),</font></span> | ||
+ | NULL<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#0000FF">return</font></span>'''</span> text_view<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | </tt> | ||
- | + | ===Warning=== | |
- | + | Although HildonTextView is derived from GtkTextView, <code>gtk_text_view_get_buffer()</code> and<code> gtk_text_view_set_buffer()</code> must never be used to get/set the buffer in this widget, <code>hildon_text_view_get_buffer()</code> and <code>hildon_text_view_set_buffer()</code> must be used instead. | |
- | A | + | |
+ | ==Notification widgets == | ||
+ | To cover the main use cases regarding notification of users, Hildon provides banners and notes. Banner widgets display a text information during a certain period of time. Notes are specialized GtkDialogs that need a small amount of input from the user. | ||
+ | |||
+ | ===Banners=== | ||
+ | A HildonBanner is useful to display information which does not need any user response. This widget automatically disappears after a certain time period. | ||
To create and show a banner, use the following function: | To create and show a banner, use the following function: | ||
- | |||
- | |||
- | + | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_banner_show_information</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span> | |
- | </ | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>icon_name<span><font color="#990000">,</font></span> |
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>text<span><font color="#990000">);</font></span> | ||
+ | GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_banner_show_informationf</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>icon_name<span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>format<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#990000">...);</font></span> | ||
+ | GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> hildon_banner_show_information_with_markup | ||
+ | <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>icon_name<span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>markup<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
+ | |||
All functions above require a widget as an argument that must be a pointer to the owner widget of the banner. Usually, the owner is the window that represents the currently displayed view. | All functions above require a widget as an argument that must be a pointer to the owner widget of the banner. Usually, the owner is the window that represents the currently displayed view. | ||
- | Function <code> | + | Function <code>hildon_banner_show_information()</code> shows a banner with the given text. |
- | Function <code> | + | Function <code>hildon_banner_show_informationf()</code> shows a banner which displays the text given by the printf-like formated string applied to the parameters that the rest of the function's arguments represent. |
- | You can also apply a Pango markup and add some attributes to the displayed text. To do that, either use <code> | + | You can also apply a Pango markup and add some attributes to the displayed text. To do that, either use <code>hildon_banner_show_information_with_markup()</code> to create the banner or setup the markup by calling <code>hildon_banner_set_markup()</code> after the initialization. [@@COMMENT@@ LINK TO PANGO MARKUP] |
- | + | ||
- | + | ||
+ | ===Warning=== | ||
Currently, icons are not displayed in banners, so any value that you pass as the icon_name is ignored. | Currently, icons are not displayed in banners, so any value that you pass as the icon_name is ignored. | ||
The period of time after the banner automatically disappear is stored in the property "timeout" (in miliseconds). A convenience function to set this property is provided: | The period of time after the banner automatically disappear is stored in the property "timeout" (in miliseconds). A convenience function to set this property is provided: | ||
- | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_banner_set_timeout</font></span>'''</span> <span><font color="#990000">(</font></span>HildonBanner <span><font color="#990000"><nowiki>*</nowiki></font></span>self<span><font color="#990000">,</font></span> | |
- | + | guint timeout<span><font color="#990000">);</font></span> | |
- | ==== | + | </tt> |
Here is a simple example showing how to setup and show an informational banner. | Here is a simple example showing how to setup and show an informational banner. | ||
'''Example 7.5. Setting up an informational banner''' | '''Example 7.5. Setting up an informational banner''' | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
+ | <tt> GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> banner<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | <span>''<span><font color="#9A1900">/* Create a banner with a markup */</font></span>''</span> | ||
+ | banner <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_banner_show_information_with_markup</font></span>'''</span> <span><font color="#990000">(</font></span>widget<span><font color="#990000">,</font></span> | ||
+ | NULL<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"<b>Information banner</b>"</font></span><span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">hildon_banner_set_timeout</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_BANNER</font></span>'''</span> <span><font color="#990000">(</font></span>banner<span><font color="#990000">),</font></span> <span><font color="#993399">9000</font></span><span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
+ | |||
+ | ===Note=== | ||
Only one timed banner can exist for each window in your application. If you spawn a new banner before the previous one has timed out, the first one is replaced. | Only one timed banner can exist for each window in your application. If you spawn a new banner before the previous one has timed out, the first one is replaced. | ||
====Notes==== | ====Notes==== | ||
- | + | HildonNotes are GtkDialogs designed to request a small amount of input from users. Usually, notes show an information text and buttons to confirm and cancel, for example, according to their type. | |
- | + | ||
Unlike banners, notes always need a user action, that is, notes do not disappear automatically after a period of time. | Unlike banners, notes always need a user action, that is, notes do not disappear automatically after a period of time. | ||
- | The | + | The HildonNote widget provides functions to create and show different types of notes: information notes, confirmation notes and cancel notes. |
- | < | + | |
- | + | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_note_new_information</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">,</font></span> | |
- | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>description<span><font color="#990000">);</font></span> | |
- | + | GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_note_new_confirmation</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">,</font></span> | |
- | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>description<span><font color="#990000">);</font></span> | |
- | + | GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> hildon_note_new_confirmation_add_buttons | |
- | </ | + | <span><font color="#990000">(</font></span>GtkWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">,</font></span> |
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>description<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#990000">...);</font></span> | ||
+ | GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> hildon_note_new_cancel_with_progress_bar | ||
+ | <span><font color="#990000">(</font></span>GtkWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>description<span><font color="#990000">,</font></span> | ||
+ | GtkProgressBar <span><font color="#990000"><nowiki>*</nowiki></font></span>progressbar<span><font color="#990000">);</font></span> | ||
+ | </tt> | ||
+ | |||
Every function to create notes receives as a parameter the parent window of the newly created note. This is important in order to allow the window manager to handle the windows properly. | Every function to create notes receives as a parameter the parent window of the newly created note. This is important in order to allow the window manager to handle the windows properly. | ||
====Information Notes==== | ====Information Notes==== | ||
- | |||
Information notes are used to show an information to the users. This note disappears when user taps outside the note's area. Otherwise the note remains visible. | Information notes are used to show an information to the users. This note disappears when user taps outside the note's area. Otherwise the note remains visible. | ||
Line 255: | Line 305: | ||
'''Example 7.6. Example of a Hildon information note''' | '''Example 7.6. Example of a Hildon information note''' | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | + | <tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> | |
+ | <span>'''<span><font color="#000000">show_information_note</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000">,</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>note<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | gint response<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | note <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_note_new_information</font></span>'''</span> <span><font color="#990000">(</font></span>NULL<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"Lorem ipsum dolor sit amet, consectetur adipiscing elit."</font></span> | ||
+ | <span><font color="#FF0000">"Maecenas tristique dictum est. Aenean rhoncus aliquam mi."</font></span> | ||
+ | <span><font color="#FF0000">"In hac habitasse platea dictumst."</font></span><span><font color="#990000">);</font></span> | ||
+ | response <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_dialog_run</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_DIALOG</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>response <span><font color="#990000"><nowiki>==</nowiki></font></span> GTK_RESPONSE_DELETE_EVENT<span><font color="#990000">)</font></span> | ||
+ | <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"%s: GTK_RESPONSE_DELETE_EVENT"</font></span><span><font color="#990000">,</font></span> __FUNCTION__<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_object_destroy</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | </tt> | ||
- | |||
- | |||
- | |||
====Confirmation Notes==== | ====Confirmation Notes==== | ||
- | |||
Confirmation notes show an information text that is usually a question and two buttons labelled "Yes" and "No". | Confirmation notes show an information text that is usually a question and two buttons labelled "Yes" and "No". | ||
- | To create a confirmation note with the text you specify and two buttons labelled "Yes"/"No", use <code> | + | To create a confirmation note with the text you specify and two buttons labelled "Yes"/"No", use <code>hildon_note_new_confirmation()</code> as follows: |
'''Example 7.7. Example of a Hildon confirmation note''' | '''Example 7.7. Example of a Hildon confirmation note''' | ||
- | |||
- | |||
- | |||
- | + | <tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> | |
+ | <span>'''<span><font color="#000000">show_confirmation_note</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>note<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | gint response<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | note <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_note_new_confirmation</font></span>'''</span> <span><font color="#990000">(</font></span>parent<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"Do you want foo ?"</font></span><span><font color="#990000">);</font></span> | ||
+ | response <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_dialog_run</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_DIALOG</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>response <span><font color="#990000"><nowiki>==</nowiki></font></span> GTK_RESPONSE_DELETE_EVENT<span><font color="#990000">)</font></span> | ||
+ | <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"%s: GTK_RESPONSE_DELETE_EVENT"</font></span><span><font color="#990000">,</font></span> __FUNCTION__<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_object_destroy</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | </tt> | ||
- | + | Alternatively, you can use <code>hildon_note_new_confirmation_add_buttons()</code> to create a confirmation note with custom buttons. | |
- | + | ||
- | + | ||
- | Alternatively, you can use <code> | + | |
'''Example 7.8. Example of a Hildon copnfirmation note with custom buttons''' | '''Example 7.8. Example of a Hildon copnfirmation note with custom buttons''' | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | + | <tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> | |
+ | <span>'''<span><font color="#000000">show_confirmation_note</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>note<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | gint response<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | note <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_note_new_confirmation_add_buttons</font></span>'''</span><span><font color="#990000">(</font></span>parent<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"Do you want foo?"</font></span><span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"ACCEPT"</font></span><span><font color="#990000">,</font></span> GTK_RESPONSE_OK<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"CANCEL"</font></span><span><font color="#990000">,</font></span> GTK_RESPONSE_CANCEL<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"DELETE"</font></span><span><font color="#990000">,</font></span> GTK_RESPONSE_DELETE_EVENT<span><font color="#990000">);</font></span> | ||
+ | response <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_dialog_run</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_DIALOG</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>response <span><font color="#990000"><nowiki>==</nowiki></font></span> GTK_RESPONSE_DELETE_EVENT<span><font color="#990000">)</font></span> | ||
+ | <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"%s: GTK_RESPONSE_DELETE_EVENT"</font></span><span><font color="#990000">,</font></span> __FUNCTION__<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_object_destroy</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | </tt> | ||
+ | |||
+ | '''Cancel Notes''' | ||
+ | |||
+ | A cancel note displays a text, a Cancel button and a progress bar. They are useful to tell users that a long task is in progress. Also, cancel notes allow users to cancel the task in progress. | ||
+ | |||
+ | Next example shows how to create a cancel note with a progress bar. Note that to control the progress bar, additional code is needed. | ||
- | + | '''Example 7.9. Example of a Hildon cancel note with a progress bar''' | |
- | + | ||
- | + | ||
- | + | <tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> | |
+ | <span>'''<span><font color="#000000">show_information_note</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>parent<span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>note | ||
+ | GtkProgressBar <span><font color="#990000"><nowiki>*</nowiki></font></span>progressbar | ||
+ | gint response<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | progressbar <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_progress_bar_new</font><font color="#990000">()</font></span>''' | ||
+ | note <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_note_new_cancel_with_progress_bar</font></span>'''</span> <span><font color="#990000">(</font></span>parent<span><font color="#990000">,</font></span> | ||
+ | <span><font color="#FF0000">"A large task is happening"</font></span> | ||
+ | <span><font color="#990000">progressbar</font></span><span><font color="#990000">);</font></span> | ||
+ | response <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_dialog_run</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_DIALOG</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>response <span><font color="#990000"><nowiki>==</nowiki></font></span> GTK_RESPONSE_DELETE_EVENT<span><font color="#990000">)</font></span> | ||
+ | <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"%s: GTK_RESPONSE_DELETE_EVENT"</font></span><span><font color="#990000">,</font></span> __FUNCTION__<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_object_destroy</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>note<span><font color="#990000">));</font></span> | ||
+ | <span><font color="#FF0000">}</font></span> |
Learn more about Contributing to the wiki.