Dialogs.py

Modal dialog components, intended for use with QUB.Dialog() and Buttons.AddTaskButton().

In general, a component's name is what you will use to look up its value, while the caption is what is displayed to the user.

DialogField

the base class for the various types of fields

DialogLabel( caption )

displays some text

DialogHidden( name, value )

invisible way to store a value

DialogCheckBox( name, caption, value=False )

DialogRadioGroup( name, caption, choices, value )

choices is a list of strings
values is one of those strings

DialogText( name, caption, value="", acceptor=acceptString, format=str )

A labeled text-input-box.

The value need not be a string. It is converted to a string using the format function, and when the user exits a textbox, the text is passed to acceptor:

newvalue = acceptor(text)

and the return value (of whatever type) becomes the DialogText's new value. The user can't close the dialog if acceptor raises an exception.

There are several predefined acceptor functions listed below. For example:
DialogText("anInt", "Must be an integer:", "0", acceptInt)
DialogText("boundedInt", "Int between 1 and 5:", "0", acceptIntBetween(1, 5))

FieldAcceptException( badStr, msg )

Preferred class of exceptions raised by an acceptor.
badStr: the string that was not accepted
msg: a phrase to chastise the user

acceptString

take the text as-is, with no conversions

acceptInt

convert the text into an int

acceptIntLessThan( ub )

convert the text into an int. Raise an exception if not x < ub

acceptIntGreaterThan( lb )

convert the text into an int. Raise an exception if not x > lb

acceptIntBetween( lb, ub )

convert the text into an int. Raise an exception if not lb <= x <= ub

acceptFloat

convert the text into a float.

acceptFloatLessThan( lb )

convert the text into a float. Raise an exception if not x < lb

acceptFloatGreaterThan( lb )

convert the text into a float. Raise an exception if not x > lb

acceptFloatBetween( lb, ub )

convert the text into a float. Raise an exception if not lb <= x <= ub

acceptFloatAbsBetween( lb, ub )

convert the text into a float. Raise an exception if not (lb <= x <= ub) or (-lb >= x >= -ub)

acceptList( acceptor, dashrange, description )

convert the text into a list. The text is split by spaces, commas, and dashes (minus signs). Each token is converted by acceptor, and expressions of the form '%s1-%s2' are converted by dashrange( acceptor(%s1), acceptor(%s2) ). dashrange can also just raise a FieldAcceptException, to disallow ranges. description, e.g. "integers", is used for error messages.

acceptIntList( acceptor=acceptInt, description='integers' )

convert the text into a list of integers

acceptFloatList( acceptor=acceptFloat, description='numbers' )

convert the text into a list of floating point numbers. Allow no ranges.

acceptDimList( acceptList, dim, msg )

convert the text into a list of a specific length (dimension). Specify your own error message.
Meant to be chained with a typed list acceptor above, as in
acceptDimList( acceptIntList(acceptIntGreaterThan(-1)), dim=2, msg='2 states please (from and to)' )