Sugar.graphics.toolbutton: Difference between revisions

From OLPC
Jump to navigation Jump to search
Line 9: Line 9:
# Use the code below to guide you on how to then create your button programmatically and add it to a tool bar (we add it to an EditToolbar object that was presumably created already in our code).
# Use the code below to guide you on how to then create your button programmatically and add it to a tool bar (we add it to an EditToolbar object that was presumably created already in our code).


#### CUSTOM TOOL BUTTON

from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.toolbutton import ToolButton
...
...

Revision as of 19:46, 29 May 2008

Class: ToolButton (gtk.ToolButton)

Sugar tool buttons can be added to toolbars and used to control various activity processes. Some common tool button tasks are outlined below.

How do I create my own custom tool button?

There are several steps you need to follow in order to create a tool button:

  1. Import the ToolButton class from the sugar.graphics.toolbutton package.
  2. If you intend to have an icon for your tool button, then create an "icons" directory in your activity directory and put the icon (which is a .svg file) in to that directory. For example, the code below uses an icon called "edit-custom" that accesses an edit-custom.svg file saved in the icons directory for the activity.
  3. Use the code below to guide you on how to then create your button programmatically and add it to a tool bar (we add it to an EditToolbar object that was presumably created already in our code).
       #### CUSTOM TOOL BUTTON
       from sugar.graphics.toolbutton import ToolButton
       ...
       #Create a custom tool button and add it to the edit toolbar
       customButton = ToolButton('edit-custom')
       customButton.set_tooltip(_('Custom'))
       self._edit_toolbar.insert(customButton, -1)
       customButton.show()

How do I connect my tool button to a callback?