As soon as Python is initialized inside the bot, it will load all *.py scripts inside the ‘Plugins’ directory. This is when you should initialize the GUI if you plan on having one.
Step 1: Initialize.
import QtBind
from phBot import *
gui = QtBind.init(__name__, 'GUI Example')
Step 2: Create your UI elements. This part can be done at any time.
button1 = QtBind.createButton(gui, 'button_clicked', 'Button', 10, 125)
checkbox1 = QtBind.createCheckBox(gui, 'checkbox_clicked', 'Check Box', 10, 150)
The return values are pointers to the QWidget objects. They must be passed to QtBind whenever you want to get a value or change something with the object.
Step 3: Handle events from the widgets.
def button_clicked():
log('Button clicked')
def checkbox_clicked(checked):
log('Check Box: %s' % checked)
All together:
import QtBind
from phBot import *
gui = QtBind.init(__name__, 'GUI Example')
button1 = QtBind.createButton(gui, 'button_clicked', 'Button', 10, 125)
checkbox1 = QtBind.createCheckBox(gui, 'checkbox_clicked', 'Check Box', 10, 150)
def button_clicked():
log('Button clicked')
def checkbox_clicked(checked):
log('Check Box: %s' % checked)