ImageButton

class vanilla.ImageButton(posSize, imagePath=None, imageNamed=None, imageObject=None, title=None, bordered=True, imagePosition='top', callback=None, sizeStyle='regular')

A button with an image.:

from vanilla import *

class ImageButtonDemo(object):

     def __init__(self):
         path = "/path/to/an/image"
         self.w = Window((50, 50))
         self.w.button = ImageButton((10, 10, 30, 30), imagePath=path,
                            callback=self.buttonCallback)
         self.w.open()

     def buttonCallback(self, sender):
         print "button hit!"

ImageButtonDemo()

posSize Tuple of form (left, top, width, height) representing the position and size of the button.

title The text to be displayed on the button. Pass None is no title is desired.

bordered Boolean representing if the button should be bordered.

imagePath A file path to an image.

imageNamed The name of an image already load as a NSImage by the application.

imageObject A NSImage object.

Only one of imagePath, imageNamed, imageObject should be set.

imagePosition The position of the image relative to the title. The options are:

“top”
“bottom”
“left”
“right”

callback The method to be called when the user presses the button.

sizeStyle A string representing the desired size style of the button. The options are:

“regular”
“small”
“mini”
setImage(imagePath=None, imageNamed=None, imageObject=None)

Set the image in the button.

imagePath A file path to an image.

imageNamed The name of an image already load as a NSImage by the application.

imageObject A NSImage object.

Only one of imagePath, imageNamed, imageObject should be set.

bind(key, modifiers)

Bind a key to the button.

key A single character or one of the following:

“help”
“home”
“end”
“pageup”
“pagedown”
“forwarddelete”
“leftarrow”
“rightarrow”
“uparrow”
“downarrow”

modifiers A list containing nothing or as many of the following as desired:

“command”
“control”
“option”
“shift”
“capslock”
enable(onOff)

Enable or disable the object. onOff should be a boolean.

getNSButton()

Return the NSButton that this object wraps.

getPosSize()

The position and size of the object as a tuple of form (left, top, width, height).

getTitle()

Get the control title.

isVisible()

Return a bool indicting if the object is visible or not.

move(x, y)

Move the object by x units and y units.

resize(width, height)

Change the size of the object to width and height.

setPosSize(posSize)

Set the postion and size of the object.

posSize A tuple of form (left, top, width, height).

setTitle(title)

Set the control title.

title A string representing the title.

show(onOff)

Show or hide the object.

onOff A boolean value representing if the object should be shown or not.