Widget
Widget([disabled, [active, [parent, [custom_styles]]]]) -> WidgetBase widget class.
Example of use
mywidget = Widget(x=30, y=100, width=100, height=30) mywidget.connect(EVENT, myfunc, [values]) # One of the cool things about GooeyPy is that you can change any style # widget specific options (like 'value' in the input and slider widgets) # and the widget will automatically update itself. mywidget.value = "GooeyPy is awesome!" # One thing to note is that while when initializing a widget you can # pass it arguments as custom styles (see below), you can't access those # styles directly (i.e. mywidget.width won't give you what you expect, # and it will raise an error if you try to assign to it). So if you want # to change or read a style option you would have to do something like # the following: mywidget.stylesets["default"]["width"] = 140 # You can also do it like this: mywidget.style["width"] = 140 # But be warned, widget.style returns the current styleset that's in # use! So if you are hovering over the widget when you change the width, # that width will only apply to that widget when you hover over it. # So if you want the width to apply to the widget at all times, you # can apply it to the "default" styleset (as shown above) in which # case it will apply to all stylesets that don't already have a width # style set. Or you can loop through mywidget.stylesets and set it for # each one, like so: for s in mywidget.stylesets.values(): s["width"] = 140
Arguments
- disabled
- If a widget is disabled, the "disabled" styling will apply and it will cease to interact with the user.
- active
- This widget will be ignored all together if it's not active.
- parent
- This is used internally when creating new widget types.
- custom_styles
- When you pass any extra arguments they get passed as a custom style; the key being the style option and the value passed as the tyle's option. Like in our example above, we pass 'x', 'y', 'width', and 'height'. Those will automatically get converted into styling options specific to that widget. Please refer to the documentation on styling for all available options and valid values.
Widget.link
Widget.link(attr) -> cellulose.DependencyCellThis is one of those very cool things in GooeyPy where you won't find anywhere else. You can have one widget share a value with one or more other widgets! In the below example, whenever the value of myslider changes, so will the fontsize for mylabel and vise-versa (and it automatically redraws the stuff too... of course).
Example of use
myslider = Slider(value=10, length=20) mylabel = Label(value="hi", font_size=myslider.link("value"))
Linking works with any attribute (that you would want to change) or styling option in any widget! Cool eh? Well, actually it's not quite all working perfectly, so expect a bug or two with linking certain attributes on certain widgets.
There is one pit-fall with this... if the thing you are trying to link isn't an attribute or a Cell (i.e. linkable), it will return None (and that could cause rather obscure errors).
Widget.connect
Widget.connect(code, func, [values]) -> NoneConnect an event to a callback function.
Example of use
def onclick(value): print 'clicked', value mybutton = Button("GooeyPy") mybutton.connect(CLICK, onclick, "button")
Arguments
- code
- The event code to trigger the callback.
- func
- The callback
- values
- Extra values you may want to send on to your callback when it is called.
Widget.pos
Widget.pos -> TupleGet the actual position
Widget.width
Widget.width -> intThis returns the actual width of this widget. It takes into account padding (for widgets that contain other widgets), min-width and max-width styles.
Widget.height
Widget.height -> intThis returns the actual height of this widget. It takes into account padding (for widgets that contain other widgets), min-height and max-height styles.
Widget.rect
Widget.rect -> pygame.RectGets the rect of the widget's current surface.
Widget.style
Widget.style -> StyleSetReturns the current styleset in use (from Widget.stylesets)
Widget.draw
Widget.draw() -> Nonedraws the widget if necessary.
Widget.draw_widget
When writing your own widgets, you can overwrite this function to have custom processes when drawing.
if getattr(self,'container',None) != None: if self.container.myfocus != self: self.container.focus(self) if getattr(self,'container',None) != None: self.container.blur(self)Widget.click
When writing your own widgets, you can overwrite this function which is called every time the widget is clicked.
Widget.send
Widget.send(code, [event]) -> NoneSends the event code 'code' and event 'event' (if suplied) to trigger any callbacks.