Editing PyMaemo/UI tutorial/Data selection
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
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 114: | Line 114: | ||
[[Image:example-single-column-selector.png|400px]] | [[Image:example-single-column-selector.png|400px]] | ||
<source lang="python"> | <source lang="python"> | ||
- | # Based on C code from: | + | # Based on C code from: |
- | # "Hildon Tutorial" version 2009-04-28 | + | # "Hildon Tutorial" version 2009-04-28 |
- | # Example 6.2 "Example of a selector with a custom column" | + | # Example 6.2 "Example of a selector with a custom column" |
- | + | ||
- | import gtk | + | import gtk |
- | import hildon | + | import hildon |
- | import gobject | + | import gobject |
- | + | ||
- | def selection_changed(selector, user_data): | + | def selection_changed(selector, user_data): |
- | + | current_selection = selector.get_current_text() | |
- | + | print "Current selection : %s" % (current_selection) | |
- | + | ||
- | def create_customized_selector(): | + | def create_customized_selector(): |
- | + | # Create a touch selector | |
- | + | selector = hildon.TouchSelector() | |
- | + | ||
- | # Stock icons will be used for the example | + | # Stock icons will be used for the example |
- | + | icon_list = gtk.stock_list_ids() | |
- | + | ||
- | # Create model to store selector's items | + | # Create model to store selector's items |
- | + | store_icons = gtk.ListStore(gobject.TYPE_STRING) | |
- | + | ||
- | # Populate model | + | # Populate model |
- | + | for item in icon_list: | |
- | + | new_iter = store_icons.append() | |
- | + | store_icons.set(new_iter, 0, item) | |
- | + | ||
- | # Create and set up a pixbuf renderer to use in the selector | + | # Create and set up a pixbuf renderer to use in the selector |
- | + | renderer = gtk.CellRendererPixbuf() | |
- | + | renderer.set_fixed_size(-1, 100) | |
- | + | ||
- | + | ||
- | # Add the column to the selector | + | # Add the column to the selector |
- | + | column = selector.append_column(store_icons, renderer, stock_id = 0) | |
- | + | ||
- | # Set the selection mode | + | # Set the selection mode |
- | + | selector.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE) | |
- | + | ||
- | # Set the property "text-column" that indicates the column | + | # Set the property "text-column" that indicates the column |
- | + | # of the model to get the string from | |
- | + | column.set_property("text-column", 0) | |
- | + | ||
- | return selector | + | return selector |
- | + | ||
- | def app_quit(widget, data=None): | + | def app_quit(widget, data=None): |
- | + | gtk.main_quit() | |
- | + | ||
- | def main(): | + | def main(): |
- | + | program = hildon.Program.get_instance() | |
- | + | gtk.set_application_name("hildon-touch-selector example program") | |
- | + | ||
- | window = hildon.StackableWindow() | + | window = hildon.StackableWindow() |
- | + | program.add_window(window) | |
- | + | ||
- | # Create touch selector | + | # Create touch selector |
- | + | selector = create_customized_selector() | |
- | + | window.add(selector) | |
- | + | ||
- | window.connect("destroy", app_quit) | + | window.connect("destroy", app_quit) |
- | + | ||
- | window.show_all() | + | window.show_all() |
- | + | ||
- | gtk.main() | + | gtk.main() |
- | + | ||
- | if __name__ == "__main__": | + | if __name__ == "__main__": |
- | + | main() | |
</source> | </source> | ||
Line 223: | Line 223: | ||
'''Example 6.3. Example of a Hildon picker button''' | '''Example 6.3. Example of a Hildon picker button''' | ||
<source lang="python"> | <source lang="python"> | ||
- | # Based on C code from: | + | # Based on C code from: |
- | # "Hildon Tutorial" version 2009-04-28 | + | # "Hildon Tutorial" version 2009-04-28 |
- | # Example 6.3, "Example of a Hildon picker button" | + | # Example 6.3, "Example of a Hildon picker button" |
- | + | ||
- | import gtk | + | import gtk |
- | import hildon | + | import hildon |
- | import gobject | + | import gobject |
- | + | ||
- | def on_picker_value_changed(button, user_data=None): | + | def on_picker_value_changed(button, user_data=None): |
- | + | print "Newly selected value: %s\n" % button.get_value() | |
- | + | ||
- | def app_quit(widget, data=None): | + | def app_quit(widget, data=None): |
- | + | gtk.main_quit() | |
- | + | ||
- | def create_customized_selector(): | + | def create_customized_selector(): |
- | + | # Create a touch selector | |
- | + | selector = hildon.TouchSelector() | |
- | + | ||
- | # Stock icons will be used for the example | + | # Stock icons will be used for the example |
- | + | icon_list = gtk.stock_list_ids() | |
+ | |||
+ | print icon_list | ||
+ | |||
+ | # Create model to store selector's items | ||
+ | store_icons = gtk.ListStore(gobject.TYPE_STRING) | ||
+ | |||
+ | # Populate model | ||
+ | for item in icon_list: | ||
+ | new_iter = store_icons.append() | ||
+ | store_icons.set_value(new_iter, 0, item) | ||
+ | |||
+ | # Create and set up a text renderer to use in the selector | ||
+ | renderer = gtk.CellRendererPixbuf() | ||
+ | renderer.set_fixed_size(-1, 100) | ||
+ | |||
+ | # Add the column to the selector | ||
+ | column = selector.append_column(store_icons, renderer, stock_id=0) | ||
- | + | # Set the selection mode | |
- | + | selector.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE) | |
- | + | ||
- | + | # Set the property "text-column" that indicates the column | |
- | + | # of the model to get the string from | |
- | + | column.set_property("text-column", 0) | |
- | + | ||
- | + | return selector | |
- | + | ||
- | + | def main (): | |
- | + | program = hildon.Program.get_instance() | |
- | + | gtk.set_application_name("hildon-touch-selector example program") | |
- | + | ||
- | + | window = hildon.StackableWindow() | |
- | + | program.add_window(window) | |
- | + | ||
- | + | # Create touch selector | |
- | + | selector = create_customized_selector() | |
- | + | ||
- | + | # Create a picker button | |
- | + | picker_button = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, | |
- | + | hildon.BUTTON_ARRANGEMENT_VERTICAL) | |
- | + | ||
- | + | # Set a title to the button | |
- | return selector | + | picker_button.set_title("Select an item") |
- | + | ||
- | def main (): | + | # Attach the touch selector to the picker button |
- | + | picker_button.set_selector(selector) | |
- | + | ||
- | + | # Attach callback to the "value-changed" signal | |
- | window = hildon.StackableWindow() | + | picker_button.connect("value-changed", on_picker_value_changed) |
- | + | ||
- | + | # Add button to main window | |
- | # Create touch selector | + | window.add(picker_button) |
- | + | ||
- | + | window.connect("destroy", app_quit) | |
- | # Create a picker button | + | window.show_all() |
- | + | gtk.main() | |
- | + | ||
- | + | if __name__ == "__main__": | |
- | # Set a title to the button | + | main() |
- | + | ||
- | + | ||
- | # Attach the touch selector to the picker button | + | |
- | + | ||
- | + | ||
- | # Attach callback to the "value-changed" signal | + | |
- | + | ||
- | + | ||
- | # Add button to main window | + | |
- | + | ||
- | + | ||
- | window.connect("destroy", app_quit) | + | |
- | + | ||
- | + | ||
- | + | ||
- | if __name__ == "__main__": | + | |
- | + | ||
</source> | </source> | ||
In the above example a picker button is created. The reference to the attached selector is stored in the property "touch-selector" of the picker button. To retrieve the attached selector, use function <code>hildon.PickerButton()</code>. To attach the selector, use the function <code>picker_button.set_selector()</code>. | In the above example a picker button is created. The reference to the attached selector is stored in the property "touch-selector" of the picker button. To retrieve the attached selector, use function <code>hildon.PickerButton()</code>. To attach the selector, use the function <code>picker_button.set_selector()</code>. | ||
Line 327: | Line 327: | ||
'''Example 6.4. Example of a Hildon picker button with a selector entry''' | '''Example 6.4. Example of a Hildon picker button with a selector entry''' | ||
<source lang="python"> | <source lang="python"> | ||
- | # Based on C code from: | + | # Based on C code from: |
- | # "Hildon Tutorial" version 2009-04-28 | + | # "Hildon Tutorial" version 2009-04-28 |
- | # Example 6.4, "Hildon picker button with a selector entry" | + | # Example 6.4, "Hildon picker button with a selector entry" |
- | + | ||
- | import gtk | + | import gtk |
- | import hildon | + | import hildon |
- | + | ||
- | def app_quit(widget, data=None): | + | def app_quit(widget, data=None): |
- | + | gtk.main_quit() | |
- | + | ||
- | def main (): | + | def main (): |
- | + | artists = [ | |
- | + | "AC/DC", | |
- | + | "Aerosmith", | |
- | + | "Alice in Chains", | |
- | + | "Black Sabbath", | |
- | + | "Carcass", | |
- | + | "Danzig", | |
- | + | "Deep Purple", | |
- | + | "Dream Theater", | |
- | + | "Eric Clapton", | |
- | + | ] | |
- | + | ||
- | program = hildon.Program.get_instance() | + | program = hildon.Program.get_instance() |
- | + | gtk.set_application_name("hildon-touch-selector example program") | |
- | + | ||
- | window = hildon.StackableWindow() | + | window = hildon.StackableWindow() |
- | + | program.add_window(window) | |
- | + | ||
- | # Create a picker button | + | # Create a picker button |
- | + | picker_button = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, | |
- | + | hildon.BUTTON_ARRANGEMENT_VERTICAL) | |
- | + | ||
- | # Set a title to the button | + | # Set a title to the button |
- | + | picker_button.set_title("Pick a band!") | |
- | + | ||
- | # Create a touch selector entry | + | # Create a touch selector entry |
- | + | selector = hildon.TouchSelectorEntry(text=True) | |
- | + | ||
- | + | # Populate the selector | |
- | + | for artist in artists: | |
- | + | selector.append_text(artist) | |
- | + | ||
- | # Attach the touch selector to the picker button | + | # Attach the touch selector to the picker button |
- | + | picker_button.set_selector(selector) | |
- | + | ||
- | # Add button to main window | + | # Add button to main window |
- | + | window.add(picker_button) | |
- | + | ||
- | window.connect("destroy", app_quit) | + | window.connect("destroy", app_quit) |
- | + | window.show_all() | |
- | + | gtk.main() | |
- | + | ||
- | if __name__ == "__main__": | + | if __name__ == "__main__": |
- | + | main() | |
</source> | </source> | ||
As you can see in the example above, the use of this widget is similar to using a normal touchable selector. | As you can see in the example above, the use of this widget is similar to using a normal touchable selector. | ||
Line 397: | Line 397: | ||
'''Example 6.5. Example of a Hildon date button''' | '''Example 6.5. Example of a Hildon date button''' | ||
<source lang="python"> | <source lang="python"> | ||
- | # Based on C code from: | + | # Based on C code from: |
- | # "Hildon Tutorial" version 2009-04-28 | + | # "Hildon Tutorial" version 2009-04-28 |
- | # Example 6.5, "Example of a Hildon date button" | + | # Example 6.5, "Example of a Hildon date button" |
- | + | ||
- | import gtk | + | import gtk |
- | import hildon | + | import hildon |
- | + | ||
- | def app_quit(widget, data=None): | + | def app_quit(widget, data=None): |
- | + | gtk.main_quit() | |
- | + | ||
- | def main (): | + | def main (): |
- | + | program = hildon.Program.get_instance() | |
- | + | gtk.set_application_name("hildon-touch-selector example program") | |
- | + | ||
- | window = hildon.StackableWindow() | + | window = hildon.StackableWindow() |
- | + | program.add_window(window) | |
- | + | ||
- | # Create a date picker | + | # Create a date picker |
- | + | date_button = hildon.DateButton(gtk.HILDON_SIZE_AUTO, | |
- | + | hildon.BUTTON_ARRANGEMENT_VERTICAL) | |
- | + | ||
- | # Set a title to the button | + | # Set a title to the button |
- | + | date_button.set_title("Select an item") | |
- | + | ||
- | # Add button to main window | + | # Add button to main window |
- | + | window.add(date_button) | |
- | + | ||
- | + | ||
- | + | window.connect("destroy", app_quit) | |
- | + | window.show_all() | |
- | + | gtk.main() | |
- | + | ||
- | if __name__ == "__main__": | + | if __name__ == "__main__": |
- | + | main() | |
</source> | </source> | ||
[[Category:Python]] | [[Category:Python]] |
Learn more about Contributing to the wiki.