grail.widgets.gaddremove module

Version: 16.2

Table of Contents

Description

Often you want a simple widget to provide the user with the ability to add and remove other widgets dynamically. For example, you want to allow the user the ability to enter a near infinite set of angles.

This widget helps you do this by providing a means of counting the number of requests, generating signals indicating an ADD or REMOVE state.

Example

The following is an example of how to use this widget,

def _onadd(event=None):
    
print "adding"

def _onremove(event=None):
    
print "removing"

def run_example():
    
"""Runs an example of this widget"""
    
global _addremove
    
root = Tkinter.Tk()
    
_addremove = GAddRemove(root, prefix="Count is: ")
    
objsignal.listen(_addremove, const.sigON_ADD,
                     
None, _onadd)
    
objsignal.listen(_addremove, const.sigON_REMOVE,
                     
None, _onremove)

    
_addremove.pack()

    
root.title("Demo - GAddRemove")
    
root.mainloop()

# start execution
run_example()

This generates the widget show in the figure below,

Example of GAddRemove widget.

Example of the GAddRemove widget.

GAddRemove Widget

The GAddRemove widget inherits from,
class GAddRemove([parent, count, prefix])

Basic widget to allow Add/Remove semantics.

The widget inherits attributes from GWidget defined in grail.widgets.gwidget.

Arguments:
parent : Tkinter.Frame
Parent widget, widget we insert in.
prefix : string
The 'prefix' to the label for this widget. for example, you could have "Number of processes: " and this widget will add the 'count' to end of the string.
count : integer
The initial count you want on this widget.
Keywords:
None.
Signals:
const.sigON_ADD
Generated when the user clicks the ADD button.
const.sigON_REMOVE
Generated when the user clicks the REMOVE button.
Components:
removebutton
The button responsible for remove actions.
addbutton
The button responsible for the add actions.
label
Contains the 'count' and the prefix (configuration option).
destroy()
Handles the Tkinter de-allocation.
disable()
Disable the buttons on this widget.
enable()
Enable the buttons on this widget.
flashadd()
Forwards to the add button's flash() method.
flashremove()
Forwards to the remove button's flash() method.
invokeadd()
Forwards to the add button's invoke() method.
invokeremove()
Forwards to the remove button's invoke() method.
updatevars()
No RTVs on this widget; this always returns 1.