Update Pushbutton label synchronizing with napari
See original GitHub issueI am working to integrate magicgui into napari. I create a dock widget inside napari. I have a pushbutton inside. Now, I want to change the label display and also value of pushbutton every time the button is pushed. Like, when button pushed, the display label on button will be changed between ‘connect’ and ‘disconnect’. Here is my code. However, even though the event.value changed, the pushbutton’s value and dislabel never update in napari and also in its own value. Could someone help me figure it out? Thanks.
import napari
from skimage import data
from magicgui import widgets
def tryme(event):
print("Before event is {}".format(event.value))
print("Before Button {}".format(event._sources[0].value))
if event.value == False:
event._sources[0].value = 1
event._sources[0]._qwidget.setText("Connect")
print(event._sources[0].text)
event.value = True
else:
event._sources[0].value = 0
event._sources[0]._qwidget.setText("Disconnect")
print(event._sources[0].text)
event.value = False
print("After event is {}".format(event.value))
print("After Button {}".format(event._sources[0].value))
return event._sources[0]
if __name__ == "__main__":
viewer = napari.Viewer()
wSetPowerLevel = widgets.FloatSlider(name="setPowerLevel",value=10,max=100,label="Power level(%)",min=0,step=0.1)
wSetLowerBandwidth = widgets.FloatSlider(name="setLowerBandwidth",value=400,max=700,label="Lower BW(nm)",min=400,step=0.1)
wSetUpperBandwidth = widgets.FloatSlider(name="setUpperBandwidth",value=1200,max=2000,label="Upper BW(nm)",min=1200,step=0.1)
wTimeOut = widgets.Label(name="Timeout (s)",value="0.5",label="Timeout(s)")
wStatus = widgets.Label(name="Status",value="Not connected",label="Status")
wVariaStatus = widgets.Label(name="VariaStatus",value="Not connected",label="VariaStatus")
wConnect = widgets.PushButton(name="Connect",tooltip="connect or disconnect from laser",value=0,text="Connect")
wEmission = widgets.PushButton(name="Emission",tooltip="set laser emission",value=0,text="Emission Off")
wResetInterlock = widgets.PushButton(name="ResetInterlock",tooltip="reset laser interlock",value=0,text="Reset Interlock")
wConnect.changed.connect(tryme)
container = widgets.Container(widgets=[wSetPowerLevel,wSetLowerBandwidth,wSetUpperBandwidth,wTimeOut,wStatus,wVariaStatus,wConnect,wEmission,wResetInterlock],name="Laser Control",label="Laser Control")
viewer.window.add_dock_widget(container,name="Laser Control",add_vertical_stretch=True)
napari.run()
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Using the labels layer - Napari
Changing the seed can be done by clicking on the shuffle colors button in the layers control panel. Shuffling colors can be useful...
Read more >Updating napari viewer from two scripts - Image.sc Forum
Hi, I am interested to know how I can connect to the same napari session ... using from magicgui.widgets import Label, LineEdit, PushButton, ......
Read more >Are some operations impossible via the Viewer.update ...
This code works how I expect: the screen updates with random "snow". import numpy as np import napari import time with napari.gui_qt(): viewer...
Read more >OpenPilot - OSCHINA - 中文开源技术交流社区
... change log from your tags, issues, labels and pull requests on GitHub. ... 5518 4-Port Hub 551a PC Sync Keypad 551b PC...
Read more >Proceedings of the 20th Python in Science Conference
PDFString is then used to update the annotation as shown ... filling is not supported and the push button is a widget which...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks very much! I got it.
you’re welcome 😃