Development Team/Almanac/sugar.graphics.toolbutton: Difference between revisions

 
(9 intermediate revisions by 6 users not shown)
Line 44: Line 44:


=== How do I add a keyboard shortcut to my tool button? ===
=== How do I add a keyboard shortcut to my tool button? ===
We typically use Alt characters for shortcuts within an activity, reserving Ctrl for system shortcuts. In the example below, we add the Alt-b short cut to our custom button.
In the example below, we add the Ctrl-b short cut to our custom button. (Activity authors are encouraged to use <ctrl> for most shortcuts.)


         #Add keyboard shortcut for customButton
         #Add keyboard shortcut for customButton
         customButton.props.accelerator = '<Alt>b'
         customButton.props.accelerator = '<ctrl>b'


If you want to enable translators to override the shortcut, use the gettext syntax so that an entry in the POT file is generated (See [[Development_Team/Almanac/Internationalization]] for details):
If you want to enable translators to override the shortcut, use the gettext syntax so that an entry in the POT file is generated (See [[Development_Team/Almanac/Internationalization]] for details):


         customButton.props.accelerator = _('<Alt>b')
         customButton.props.accelerator = _('<ctrl>b')
 
If you want to use symbols in you shortcuts, you'll need to refer to the X11 keysymdefs (/usr/include/X11/keysymdef.h), e.g., to use a "+" as a shortcut, you'd refer to <code>#define XK_plus 0x002b /* U+002B PLUS SIGN */</code> and use the string after the <code>XK_</code>:
 
        customButton.props.accelerator = _('<ctrl>plus')
 
=== How do I set the default toolbar menu? ===
 
Use the set_expanded() method of the ToolbarButton class.
 
        my_toolbar_button.set_expanded(True)
 
When using pre-0.86 toolbars, use the set_current_toolbar() method:
 
        self.toolbox.set_current_toolbar(1)
 
=== How do I set the icon search path for my toolbar button? ===
 
By default, the Sugar system icon folders and the icons subdirectory of your activity are searched. You can add additional directories to search as follows:
 
        icon_theme = gtk.icon_theme_get_default()
        icon_theme.append_search_path(your_icon_path)