In general you'll be working with widget objects. Here are some general guidelines for using them.


So you start your Party Creation screen for your RPG?
Here are some guidelines how to approach the creation of the GUI.

First whip up some XML definitions. You'll anticipate which buttons you need,
where you place some text and maybe preview images. All the interactive stuff
gets descriptive names. Like class_description or whatever makes sense.

Second you'll load the xml files, which will give you a set of root widgets.
You are advised to mostly work with these top-level objects and make no
assumptions about the layout of the GUI inside these containers.

You can use these root widgets to map events to your callbacks, distribute
data changes to a whole bunch of labels, etc.pp.

    "current_label" : name,
    "description" : RACES[index].description,
    "allowed_classes" : ", ".join([c().name for c in RACES[index].allowed_classes]),

Third you'll eventually want to add dynamic behaviour, like adding buttons on the fly.
For this you're advised to set up named containers in the XML file.

You can grab them with findChild from your root widgets and add widgets,
remove them and whatever comes to mind.

With this approach you hopefully have separeted the logic from the design.

Attributes and methods

The ways to interact with the widget are separated in methods and attributes.
To understand what is handled by methods and attributes respectively it's useful to think of them
as verbs and nouns.

So if you want the widget to do something, e.g. display itself, map events to callbacks etc.pp.
you'll find a methods. Here are some examles:


On the other hand, if you want to change the state of a widget, it's likely to be an attribute.

label.text = "Hello world!"
label.position = 100,100

Of course this distinction gets blurry if you consider a "visible" state instead of showing the widget.
But since showing a widget always implies that the whole bunch (e.g. child widgets in a container)
change their state it's a method: It's an attribute if it changes a single widget only.

Additionally, more complex dynamic properties like the event callback will be handled by a method.

To wrap this up: Remember that you can set most attributes in your xml definitions.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License