grail.widgets.gspinner module

Version: 16.2

Table of Contents

Description

Provides a standard incremental integer entry widget.

Example

The following example sets up a series of GSpinner widgets. Each widget uses handles the data in a different format. The purpose is to illustrate how you can handle the data format for your use of the GSpinner widget.

from grail.widgets import *
from grail import rtv
from grail import objsignal
from grail import const

def onrtv1change(var):
   
"""Event handler for first RTV variable."""
   
print "on top spinner's rtv change: rtv value= %d." % (var.get())

root = gwidgetinit()
root.title("Demo - GSpinner")

var = rtv.IntegerRTV(name="__gspinner_test", value=1)
objsignal.listen(var, const.sigON_CHANGE, None, onrtv1change)
var2 = rtv.IntegerRTV(name="__gspinner_rtv2", value=10)
texts = ("Range 0 to 10: ",
"Range 5 to 15: ",
"Range -10 to 10 (no rtv): ",)
labels = gtools.makewidgets(root, GLabel, len(texts), list_text=texts)

spin1 = GSpinner(parent=root, rtv=var, min=0, max=10)
spin2 = GSpinner(parent=root, rtv=var2, min=5, max=15)
spin3 = GSpinner(parent=root, min=-10, max=10, value=3)

gtools.stdwidgetcolumns(labels, (spin1, spin2, spin3,))
root.mainloop()

The above script will generate a window that appears as the figure below,

Example of GSpinner widget.

Example of the GSpinner widget.

GSpinner Widget

The GSpinner widget inherits from,

class GSpinner([parent, **keywords])

Arguments:
parent : Tkinter.Frame
Parent widget, widget we insert into.
keywords
Variable keyword list defined below.
Keywords:
min : integer
Minimum value for the spinner. Default is -sys.MAX_INT.
max : integer
Maximum value for the spinner. Default is sys.MAX_INT.
rtv : IntegerRTV
Variable to associate with the spinner.
Signal:
const.sigON_CHANGE
Emitted when the contents of the GSpinner object change. Attempts to guarantee that the text value of the entry component is convertable to an integer prior to signal emission.
Components:
entry
GTextEntry component where the user enters the integer.
uparrow
GArrow component representing the up arrow in the GSpinner object.
downarrow
GArrow component representing the down arrow in the GSpinner object.

Note

If there is a var on this widget, and the var changes its value to a value that lies outside of the range [min, max], the rtv will then get its value clamped.

clearerror()
Removes any flagging of an error state for the spinner. If the spinner was not in an error state, then nothing happens.
destroy()
Handles the Tkinter de-allocation.
disable()
Set the spinner to ignore user events.
enable()
Set the spinner to respond to user events.
flagerror()
Flags spinner as being in an error state. If the spinner is already in an error state, then nothing happens.
updatevars()
Synchronizes the Graphical User Interface (GUI) with the internal variable.