1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
class CPushButton
__init__(self, parent, text)
CCheckButton
__init__(self, parent, text)
CRadioButton
__init__(self, parent, text, group = None)
These classes represent buttons, a control the user can press with the
mouse. A push button is a plain button. A check button shows a check
mark to the left of its text, and can be checked or unchecked. A radio
button is like a check button, but exists in a group of other radio
buttons. Exactly one of the group of radio buttons is checked and all
others are unchecked. The first radio button constructed is the head
of the group.
All buttons have a text name to display on the button. They also have
a "handler" name, the name of a method which will be called when the button
is pressed. The handler name is equal to the alphanumeric characters in the
button text prepended with "OnButton" when the button is constructed, but the
handler name may be changed to any string. When the button is pressed a command
message is generated which is routed among the objects in the program (see messages)
until a method with the handler name is found. The form of a button message
handler is "OnButtonQuit(self, control)" where "Quit" is the button text, "self" is
the object defining the handler method, and "control" is the button object which
generated the message.
All buttons maintain their own check marks. You do not need to write code to check
or unckeck buttons in response to user actions. Instead you write the handler
methods to react to button presses, and you read the checked/unchecked state
of a button from the instance variables.
Instance Variables
wpyParent, wpyText, wpyChildList, wpySizeX/Y, wpyLocX/Y, wpyAnchor
wpyCheckValue, int zero or one, readonly after Create(), CCheckButton only
Used only by CCheckButton, this variable is zero or one to indicate
whether the button is checked. This can be assigned a value 0 or 1
when the button is constructed, but is a read-only variable after the
button is created. Check and radio buttons maintain their own checks
in response to user actions.
wpyRadioSelected, CRadioButton object, readonly, CRadioButton only
For each radio button, this is the selected radio button, the one with
the check.
wpyGroup, CRadioButton object, readonly, CRadioButton only
For each radio button, this is the button which is the head of the group.
The radio button constructed first has "group" None in its __init__ call,
and this makes it the head button. Subsequent radio buttons in the same
group have "group" equal to the head button.
wpyGroupList, list of CRadioButtons, readonly, CRadioButton group button only
For the radio button which is the head of the group, this is a list
of all the radio buttons in the group.
Methods
EnableWindow(bool), ShowWindow(bool), geometry
__init__(self, parent, text)
Return a button with self.wpySizeX/Y set according to the arguments given.
__init__(self, parent, text, group = None)
Return a radio button as a member of the specified group, and with
self.wpySizeX/Y set according to the arguments given.
parent, object
The view or dialog parent of the control.
text, string
The text to display in the button. Assigned to wpyText.
group, a CRadioButton object or None
For radio buttons, construct the button as a member of group "group". The
first radio button has "group" equal to None, subsequent buttons have "group"
equal to the first button.
Create(self)
Make the button visible by calling the underlying GUI.
SetCheck(self, check = 1)
Set or unset the checked state of a check button or radio button. For
a check button, "check" must be 0 or 1 to uncheck or check the button.
For a radio button, "check" must be 1 to select the given button
and unselect all other buttons (0 is not allowed).
WpyCommandRouter(self)
Simulate a button press message.
Examples
# Create a push button, a check button and three radio buttons.
p = CPushButton(parent, "Quit").Create()
c = CCheckButton(parent, "Status bar").Create()
r1 = CRadioButton(parent, "Times")
r2 = CRadioButton(parent, "Garamond", r1)
r3 = CRadioButton(parent, "Helvetica", r1)
# Create a handler for a button press as a method of another object.
class MyView(CScrollView):
def OnButtonQuit(self, control):
pass # self is the view object, control is the button object
|