Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Creating Plugin Help, combobox disabling line_edit based on current state

edited June 2013 in OpenSesame

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.

  1. 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.

  2. 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

  1. 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.
  2. 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.
  3. 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

  • edited 12:56AM

    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:


    class qtsend_message(send_message, qtautoplugin): # (...) def edit_widget(self): """ This function is called everytime that a change is made to the controls. You can use it to implement complex interactions between widgets. In this case, we check whether the currentText() of the combobox_widget is 'Send Mark', and if so, we enable the line_edit_widget. Otherwise, the line_edit_widget is disabled. All the controls are part of an underlying widget, which is called _edit_widget. This must be returned by the function. Returns: A QWidget """ qtautoplugin.edit_widget(self) if self.combobox_widget.currentText() == u'Send Mark': self.line_edit_widget.setEnabled(True) # self.line_edit_widget.show(True) else: self.line_edit_widget.setEnabled(False) # self.line_edit_widget.hide(True) return self._edit_widget

    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 by QLineEdit) 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

  • edited 12:56AM

    Adding in the edit widget method worked perfectly for enabling/disabling!

    One comment is that self.line_edit_widget.show(True) and self.line_edit_widget.hide(True) complained about too many arguements with passing in the True. I used self.line_edit_widget.show() and self.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!

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games