trouble with checkbox popup

Asked by rob

hello,
i would like to make a popup that pauses the script and waits for the user to select some checkboxes and then continue the script once the user clicks the ok button. just like input() in sikuli only with some checkboxes instead of a textfield. i coded a popup with some checkboxes, but the script continues running instead of waiting for the user to click ok.
i know this is more of a jython/swing question. so, if it would be ok, can you explain to me to how to take a look at the input() function so i can emulate it?

here is the checkbox class that does not make the script wait for the user to click ok:

'''
   a window for selecting checkboxes
'''

from javax.swing import (JButton, JFrame, JPanel, JCheckBox, BoxLayout,
                        WindowConstants)
from java.awt import BorderLayout

class SelectBoxes(object):

    def tally(self, event):
        self.boxes= []
        if self.checkbox1.isSelected():
            self.boxes.append('1')
        if self.checkbox2.isSelected():
            self.boxes.append('2')
        if self.checkbox3.isSelected():
            self.boxes.append('3')
        if self.checkbox4.isSelected():
            self.boxes.append('4')
        if self.checkbox5.isSelected():
            self.boxes.append('5')
        if self.checkbox6.isSelected():
            self.boxes.append('6')
        if self.checkbox7.isSelected():
            self.boxes.append('7')
        print self.boxes
        self.frame.visible = False

    def __init__(self):
        self.frame = JFrame('Select boxes',
                            defaultCloseOperation = WindowConstants.HIDE_ON_CLOSE)
        self.selectionPanel = JPanel()
        self.selectionPanel.layout=BoxLayout(self.selectionPanel, BoxLayout.Y_AXIS)
        self.frame.add(self.selectionPanel)

        self.checkbox1 = JCheckBox('1', selected = True)
        self.selectionPanel.add(self.checkbox1)
        self.checkbox2 = JCheckBox('2', selected = True)
        self.selectionPanel.add(self.checkbox2)
        self.checkbox3 = JCheckBox('3', selected = False)
        self.selectionPanel.add(self.checkbox3)
        self.checkbox4 = JCheckBox('4', selected = False)
        self.selectionPanel.add(self.checkbox4)
        self.checkbox5 = JCheckBox('5', selected = False)
        self.selectionPanel.add(self.checkbox5)
        self.checkbox6 = JCheckBox('6', selected = False)
        self.selectionPanel.add(self.checkbox6)
        self.checkbox7 = JCheckBox('7', selected = False)
        self.selectionPanel.add(self.checkbox7)

        self.buttonPanel = JPanel()
        self.frame.add(self.buttonPanel, BorderLayout.SOUTH)
        self.button = JButton('ok', actionPerformed = self.tally)
        self.buttonPanel.add(self.button)

        self.frame.pack()
        self.show()

    def show(self):
        self.frame.visible = True

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

-1. you have to implement an event handler for the ok button, to get notified about the click
-2. you have to wait until the click event happens

The challenge: 1. and 2. are processed in different contexts, that do not know anything about each other (this is the reason, that your script just continues.

How to solve that in Sukuli scripts:
go through this to get on the road:
http://www.jython.org/jythonbook/en/1.0/GUIApplications.html

Revision history for this message
anuj (anuj-patel87) said :
#2

Hello RaiMan and Rob,

i am trying to implement similar user input function as rob mentioned (i.e. multicheckbox) and i am facing the same issue of script not waiting to listen any mouse events(i.e click of button). i tried using the button.addMouseListener(self) method on Jbutton but its not working. If possible can you help out solve this issue? Any help is greatly appreciated.

@Rob : Anyluck while trying to solve this issue? Please let me know if you found out the solution :).

Again Appreciate your help in advance.

Thanks,
AP

Can you help with this problem?

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

To post a message you must log in.