Example of implementing a GUI for Sikuli

Asked by Maurice Richard on 2017-02-15

Hello,

I was hoping someone could provide a basic example of implementing a GUI for a Sikuli script.
It can be very simple ... an interface with a single button that runs the Sikuli script.

This would be very helpful.

Thanks!
Moe

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Maurice Richard
Solved:
2017-02-24
Last query:
2017-02-24
Last reply:
Maurice Richard (flashfires) said : #1

I'm sure this could be cleaner, but this works ... in case it helps others:

#Global Variable used to avoid glitch when calling functions by button click
varButtonClicked = "No"

#Function to use global variable to handle glitch with calling function on button click
def ProcessClick(event):
    global varButtonClicked
    varButtonClicked = 'Yes'

#Function to do 'whatever'
def DoSomething(event):
    #Code here to do whatever you want

#genrrates interface for the user
frame = JFrame("Some Title")
frame.setSize(200, 100)
frame.setLayout(BorderLayout())
label = JLabel('Some label text. ')
frame.add(label, BorderLayout.NORTH)
button = JButton('Button Text Here',actionPerformed=ProcessClick)
frame.add(button, BorderLayout.SOUTH)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setVisible(True)

#listener to handle button clicks
while True:
  if (varButtonClicked=='Yes'):
    global varButtonClicked
    varButtonClicked = "No"
    DoSomething()
  wait(1)