Howdy, Stranger!

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

Supported by

Dynamic GUI elements

edited March 2015 in OpenSesame

I am developing a plugin (new style) with dynamically linked GUI elements.
It has a combobox with two (or more) language options and beneath it a couple of checkboxes which are made with a for loop. These checkboxes are dependent on the selected option in the combobox. I am trying to redraw/recreate those checkboxes when a different language is selected in the combobox. In the old plugin style I did establish to add the correct new checkboxes but it did not delete the old ones. In the new style both fail.

I tried to use some methods from the auto_example but that does not work on the combobox:

    self.checkbox_widget.stateChanged.connect( \
        self.line_edit_widget.setEnabled)

Most elegant would be to group the checkboxes inside a groupbox and connect the groupbox to the combobox. On stateChanged in the combobox, the groupbox with the checkboxes encapsulated would be recreated.

Any ideas on this?

Comments

  • edited 12:21PM

    Hi Bob,

    Good to see you on the forum again!

    I think the best way to handle this is not by changing or recreating controls, but to hide and show controls (i.e. widgets) based on which language is selected, using QWidget.setVisible().

    It's not usually a good idea to delete and create things in Qt on the fly. It's better to create all controls that you might need, and just hide the ones that aren't needed at a particular moment.

    I tried to use some methods from the auto_example but that does not work on the combobox:

    Every widget has its own signals and functions, which are described in the PyQt4 api:

    Is that helpful at all?

    Cheers,
    Sebastiaan

  • edited 12:21PM

    Hi Sebastiaan,

    Thanks!
    Good idea!
    This has only one problem.
    For example, I have 8 languages with 20 experiments/questionnaires.
    I have to make 8x20 checkboxes. I have to hide 7x20 checkboxes but the empty space is still shown and the positions are occupied. The position of the corresponding 1x20 checkboxes changes when a different language is selected.

    Because order is also a relevant feature, I am now trying to make a treeview widget.
    I was thinking of applying your hiding principle. Making one treeview widget, with all the languages as parents, the experiments as children. And then hiding the language/parents, and thereby hiding the children. In this case I only have one widget that I do not have to recreate, and I fix it internally within the widget.

    I just finished making a treeview widget but it does not show anywhere. Any idea how I can get this widget within the plugin controls.
    The code:

    class treewidgetmaker(food):
    
            """
            Constructs a treewidget.
            """
    
        def __init__(self):
            self.widget = QtGui.QTreeWidget()
    
        def fill_widget(self, value):
            #self.widget.clear()
            self.fill_item(self.widget.invisibleRootItem(), value)    
    
    
        def fill_item(self, item, value):
            item.setExpanded(True)
            if type(value) is dict:
                for key, val in sorted(value.iteritems()):
                    child = QtGui.QTreeWidgetItem()
                    child.setText(0, unicode(key))
                    item.addChild(child)
                    self.fill_item(child, val)
            elif type(value) is list:
                for val in value:
                    child = QtGui.QTreeWidgetItem()
                    item.addChild(child)
                    if type(val) is dict:      
                        child.setText(0, '[dict]')
                        self.fill_item(child, val)
                    elif type(val) is list:
                        child.setText(0, '[list]')
                        self.fill_item(child, val)
                    else:
                        child.setText(0, unicode(val))              
                        child.setExpanded(True)
            else:
                child = QtGui.QTreeWidgetItem()
                child.setText(0, unicode(value))
                item.addChild(child)
    
        def show_widget(self):
            self.widget.show()
    

    I call this class as a instance from within the class qtfood (plugin name = food) after:

        food.__init__(self, name, experiment, script)
        qtautoplugin.__init__(self, __file__)
    

    with the following code:

        widget1 = treewidgetmaker()
        widget1.fill_widget(experiment_dict)
        widget1.show_widget()
    

    Is it possible to add a self.add_treeview_control within the plugin classes?

    Cheers,
    Bob

  • edited March 2015

    Hi Bob,

    I have to hide 7x20 checkboxes but the empty space is still shown and the positions are occupied.

    If you hide a widget, it won't take up any space. If this appears to happen in your case, then you have probably grouped the widgets in a container widget, which takes some space of its own, even if all widgets in it are hidden. In that case, it would make sense to just hide the container widget.

    The position of the corresponding 1x20 checkboxes changes when a different language is selected.

    I'm not sure what you mean, but the order of widgets doesn't change, unless you explicitly change it.

    If I understand your goal correctly, I think the easiest solution is to:

    • Add all widgets that you want to group to a QFrame
    • Add all the QFrames to the GUI controls, using self.add_widget()
    • Hide/ show the QFrames based on user interactions

    Does that sound reasonable?

    I don't see why you would want to use a QTreeWidget. That's really for hierarchical lists that you want to expand and collapse, like the OpenSesame overview area. Is that the kind of layout you're looking for?

    Cheers,
    Sebastiaan

  • edited 12:21PM

    Hi Sebastiaan,

    I am gonna look into that. It is not that relevant at this time because I need the QTreeWidget.
    Order of items is relevant. I will elaborate some more.

    The basic setup is that the plugin makes a list of all language folders located in a folder. Each language folder consists of a number of questionnaires (opensesame experiment files).

    The combobox let's you select a language.
    The Qtreewidget shows the questionnaires corresponding to the selected language.
    Users need the ability to select the questionnaires they want (with checkboxes) and they need to put them in an order of their liking.
    Qtreeview can do all this.

    When the plugin/item is configured, there will be one item in the opensesame experiment which will execute the ordered list of questionnaires one by one through processes of opensesamerun.

    Cheers,
    Bob

  • edited 12:21PM

    Hi Bob,

    Right I see. In that case, using a QTreeWidget indeed makes sense. Adding it to the controls works the same though, you can simply use self.add_widget().

    You could also consider turning this into a standalone program that launches an OpenSesame experiment. That was what you initially had in mind, right? Is there a specific reason that made you decide to implement it as a plug-in? Not that there's anything wrong with that, I suppose it just comes down to what is most user friendly.

    Cheers,
    Sebastiaan

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