JavaxSwing GUI: Do.popAsk not working --- stuff must be run from EventQueue

Asked by 123456789 on 2018-11-20

By using the following code <UPDATED>:

from javax.swing import JButton, JFrame

def test():
   global button
   button = Do.popAsk("test", "Error", 10)
   if button == False:
    exit(1)

def start(event):
   test()

def testUI():
  frame = JFrame('test', size = (200,200))
  startbutton = JButton('start', actionPerfomed = start)
  frame.add(startbutton)
  frame.setVisible(True)

testUI()

======
Issue : text popAsk dialog box is blank.
             When using Do.popAsk outside the Start(event) function, the text is displayed.

Any idea regarding this? I'm using 1.1.3

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-11-20
Last reply:
2018-11-21
RaiMan (raimund-hocke) said : #1

my test:

def Start(event):
  Main()

def Main():
  button = Do.popAsk("test", "Error", 10)
  if button == False:
    exit(1)

Start(None)

works as expected (using 1.1.4)

BTW: (Python/Jython rules)
- by convention function names should be written starting with lowercase (starting uppercase are names for classes)
- a function should not be named main (since it overwrites the internally used name main, which might lead to problems)

123456789 (testok) said : #2

Hi! sorry I updated the code above. Thank you

RaiMan (raimund-hocke) said : #3

Since the Do.pop.... features itself internally use JavaxSwing features, your implementation will not work this way.

A GUI implementation like this must be run from the Java EventQueue, but I cannot tell you how this can be managed from a Jython script.

Another option might be, to run the stuff behind actionPerfomed = start in a subprocess.

... and of course, you can completely switch to a plain Java implementation.

For possible approaches consult the net/google with the keywords:
Java GUI SikuliX

Can you help with this problem?

Provide an answer of your own, or ask 123456789 for more information if necessary.

To post a message you must log in.