-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add table-cell change callbacks #205
Comments
Thanks so much for working on this! - Looking forward to this change. |
@pranathivemuri, there is a workaround you can use in the meantime, by directly using the Qt api. Let's take the example at https://github.com/napari/magicgui/blob/master/examples/table.py ... If, before running def on_item_changed(item):
# item will be an instance of `QTableWidgetItem`
# https://doc.qt.io/Qt-5/qtablewidgetitem.html
print('row:', item.row())
print('col:', item.column())
print('new data:', item.data(table._widget._DATA_ROLE)) # _DATA_ROLE will likely just be the number 255
# whatever you want to do with the new value
table.native.itemChanged.connect(on_item_changed) that might let you get started on some stuff until there is a "magicgui" way of doing it |
awesome, I was just researching for this! in my case, it doesn't necessarily have to be a table it is just one text input from user that needs to be passed so there is probably multiple ways to work around it |
oh! If it doesn't have to be a table... like if you just want to know if a user has changed a text input, then it's already supported (again, tables are a specific, special case) see some docs here, but the basic idea is this: # if using the decorator:
@magicgui
def func(your_name='Bob'):
return f'hello {your_name}!'
# to connect to just the specific parameter changing
def _on_your_name_changed(event):
print(f'your_name was changed to {event.value}')
func.your_name.changed.connect(_on_your_name_changed)
# to connect to the whole function being called
def _on_func_called(event):
print(f"func called: {event.value}")
func.called.connect(_on_your_name_changed) |
nice, thanks! I will just have to figure out passing this to current_properties in napari shapes layer to change the label for that bounding box. So far so good, thanks for all the example code! :) |
feel free to point me to code if you need help |
Thanks, it worked out. I will open-source the code in a few days, but it is working as I wanted. Thanks to the workaround you pointed out with QT table! I appreciate your quick replies today! |
As pointed out by @pranathivemuri in https://github.com/napari/magicgui/pull/182#issuecomment-812670169 ... magicgui
Table
doesn't yet have a good way to bind a callback to a change event on a cell or a group of cells. (It was left for a later PR, and that time has come! 😄 )https://github.com/napari/magicgui/blob/a07b6d3885fb63a6d7947fbb03fc90a971759006/magicgui/backends/_qtpy/widgets.py#L828-L832
The text was updated successfully, but these errors were encountered: