[solved] Creating Plugin Help, combobox disabling line_edit based on current state
Hello,
I've created a plugin for opensesame called send_message that contains both a combobox and a line_edit item.
Here's my goal:
I am trying to get my line_edit to only be enabled when a specific option on the combobox is selected. This is because when the line_edit is disabled the opensesame GUI will gray out the line_edit box and not allow text to be typed. Current combobox options are 'Send Mark', 'Start Server', and 'Stop Server'. I'm trying to get the line_edit to only be enabled when 'Send Mark' is selected. If it's possible to get the line_edit to not display at all when 'Send Mark' isn't selected then that would be even better, but I'll be happy with either way.
What I've accomplished so far:
I included the line of code
self.combobox_widget.activated.connect(self.line_edit_widget.setDisabled)
inside of
class qtsend_message(send_message, qtautoplugin):
def __init__(self, name, experiment, script=None):
send_message.__init__(self, name, experiment, script)
qtautoplugin.__init__(self, __file__)
def init_edit_widget(self):
qtautoplugin.init_edit_widget(self)
self.combobox_widget.activated.connect(self.line_edit_widget.setDisabled)
this is inside of my send_message.py file. There are a couple of drawbacks to this approach.
I have to set the starting combobox option to 'Send Mark'. If I don't then the line_edit will be enabled on whatever the first option is. I would like to start my combobox option on 'Start Server' (which needs the line_edit disabled) because before sending a mark the server connection needs to be established.
After adding a send_message item into an opensesame experiment, setting the combobox option to either 'Start Server' or 'Stop Server' (At this point the line_edit is disabled which is good), saving, closing, and opening the experiment back up, the line_edit is now enabled for the send_message items for 'Start Server' and 'Stop Server'. I don't know how but the line_edit gets re-enabled when re-opening an experiment. Once the experiment is opened back up the line_edit will enable/disable appropriately if the combobox option is changed.
I feel like there is a fairly simple way to accomplish this, but I can't seem to figure one out.
Priorities
- Getting the line_edit to stay disabled for 'Start Server' and 'Stop Server' after re-opening an experiment has to get finished before I can be done with this project.
- Getting the line_edit enabling/disabling to work with 'Start Server' as the first combobox option isn't required but is something that I would like to accomplish.
- Getting the line_edit to only display on combobox option 'Send Mark' isn't necessary at all, but would be cool.
Any help at all on this would be greatly appreciated, thank you!
Comments
Hi Andrew,
Great to see that you're working on a plug-in. In your case, it may be convenient to implement a custom
edit_widget()
method. This method is called every time that a control is changed, and you can use it to implement all kinds of interactions. See below for an example:In general, the OpenSesame plug-in framework is set-up so that you don't need to bother with PyQt4 for simple controls. However, if you want to implement custom interactions, it quickly becomes convenient to know a bit about it.
Functions such as
QWidget.setEnabled()
(inherited byQLineEdit
) are documented in the PyQt4 reference list:This tutorial is also a very good way to get started with PyQt4:
Good luck and cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Adding in the edit widget method worked perfectly for enabling/disabling!
One comment is that
self.line_edit_widget.show(True)
andself.line_edit_widget.hide(True)
complained about too many arguements with passing in the True. I usedself.line_edit_widget.show()
andself.line_edit_widget.hide()
and that did the job.Thank you for the very fast response, info, and the great links you provided. Job well done! Keep up the good work!