=================================== ``grail.widgets.gaddremove`` module =================================== .. include:: ../../version.h .. include:: ref.h .. contents:: Table of Contents :backlinks: top ----------- 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, .. Python:: 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, .. figure:: figure-gaddremove-example.gif :alt: Example of GAddRemove widget. Example of the :c:`GAddRemove` widget. ----------------- GAddRemove Widget ----------------- The :c:`GAddRemove` widget inherits from, * :c:`gwidget.GWidget` (grail.widgets.gwidget_) * :c:`objsignal.Emitter` (grail.objsignal_) class :dc:`GAddRemove([parent, count, prefix])` Basic widget to allow Add/Remove semantics. The widget inherits attributes from :c:`GWidget` defined in grail.widgets.gwidget_. Arguments: :a:`parent` : Tkinter.Frame Parent widget, widget we insert in. :a:`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. :a:`count` : integer The initial count you want on this widget. Keywords: None. Signals: :d:`const.sigON_ADD` Generated when the user clicks the ADD button. :d:`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). :df:`destroy()` Handles the Tkinter de-allocation. :df:`disable()` Disable the buttons on this widget. :df:`enable()` Enable the buttons on this widget. :df:`flashadd()` Forwards to the add button's flash() method. :df:`flashremove()` Forwards to the remove button's flash() method. :df:`invokeadd()` Forwards to the add button's invoke() method. :df:`invokeremove()` Forwards to the remove button's invoke() method. :df:`updatevars()` No RTVs on this widget; this always returns 1.