ejeschke / ginga

The Ginga astronomical FITS file viewer
BSD 3-Clause "New" or "Revised" License
120 stars 77 forks source link

Make an editable ComboBox with build_info? #1104

Closed mkelley closed 1 month ago

mkelley commented 1 month ago

I'm using the Widgets.build_info tool in a reference viewer local plugin and would like to add an editable ComboBox, but it doesn't seem to be easily done. make_widget cannot pass initialization options to ComboBox (or anything else), and replacing or re-initializing the widgets in the build_info return objects does not update the widget drawn in the reference viewer.

        design = (
            (
                "",
                "label",
                "",
                "label",
                "Autofill target",
                "checkbox",
                "target keyword list",
                "combobox",
            ),
        )
        widget, bunch = Widgets.build_info(design, orientation=orientation)

        # bunch.target_keyword_list = Widgets.ComboBox(editable=True)
        bunch["target_keyword_list"].__init__(editable=True)

        self.w.update(bunch)

Perhaps make_widget could be updated with a new wtype "editablecombobox"? Or is there another solution? In the meantime, I can make a separate textentry and add items to the combobox.

ejeschke commented 1 month ago

Hi @mkelley, you are correct: the easiest thing is to add a new type to make_widget. I've pushed a commit to main to add the type "comboboxedit". Can you verify that this gives you the capability that you want?

(sorry for late reply)

ejeschke commented 1 month ago

Note that when you get the callback for setting a custom value in the editable combobox, the index you receive will not correspond to any of the known items in the list. The value can be extracted with w.get_text() (where w is the first of two parameters in the widget callback (widget, index)).

mkelley commented 1 month ago

Thanks! I've implemented it and tested with GTK and QT5 and it works as advertised.