Code Monkey home page Code Monkey logo

Comments (5)

tlambert03 avatar tlambert03 commented on August 16, 2024 1

i agree!

from magicgui.

tlambert03 avatar tlambert03 commented on August 16, 2024

actually, that sounds to me like a bug in our Qt backend... Qt itself has no problem with this:

from qtpy.QtWidgets import QComboBox, QApplication

app = QApplication([])
combo = QComboBox()
combo.addItems(['a', 'b', 'c', 'c'])
combo.show()
app.exec_()
Screenshot 2024-03-18 at 1 58 17 PM

specifically, i would expect this to work fine:

from magicgui.widgets import ComboBox

# two different data values for c
box = ComboBox(choices=[("a", 0), ("b", 1), ("c", 2), ("c", 3)])

box.show(run=True)

but it doesn't because the ComboBox._mgui_set_choices implementation only looks at the name. Haven't dug too deeply there yet, but i'm not sure we should impose the restriction if both Qt and ipynb don't

from magicgui.

qin-yu avatar qin-yu commented on August 16, 2024

Yeah neither backend limit such use. Let's lift this restriction. The implementation now is to have unique choice names

# if it's not in the list, add a new item
if item_index == -1:
self._qwidget.addItem(choice_name, data)
# otherwise update its data
else:
self._qwidget.setItemData(item_index, data)

from magicgui.

qin-yu avatar qin-yu commented on August 16, 2024

It appears that modifying the current implementation of the Qt ComboBox resulted in 3 failures among the original tests:

=========================== short test summary info ============================
FAILED tests/test_container.py::test_reset_choice_recursion - assert (0, 0, 1... <- original
FAILED tests/test_widgets.py::test_separator[ipynb] - assert (1, 2, 4, 6, 7, ... <- new test
FAILED tests/test_widgets.py::test_separator[qt] - AssertionError: assert 21 ... <- new test
FAILED tests/test_widgets.py::test_unhashable_choice_data - AssertionError: a... <- original
FAILED tests/test_widgets.py::test_categorical_change_choices[ComboBox] - ass... <- original
============= 5 failed, 357 passed, 22 skipped, 1 xfailed in 7.36s =============

I guess these changes would lead to a minor release? Let's consider another PR later this week if necessary. For #638, let's retain the original implementation. What do you think? 🤔

from magicgui.

qin-yu avatar qin-yu commented on August 16, 2024

If we allow multiple items with the same name, how would this impact the ability for users to select options by name?

from magicgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.