Skip to content

Instantly share code, notes, and snippets.

@sofroniewn
Created April 20, 2019 03:18
Show Gist options
  • Save sofroniewn/30b8893ca9c5183fd98d40cbb355dc33 to your computer and use it in GitHub Desktop.
Save sofroniewn/30b8893ca9c5183fd98d40cbb355dc33 to your computer and use it in GitHub Desktop.
Tests for qtdims model
# This is in interactive test
from time import sleep
import threading
from napari.components import Dims
from napari.components._dims._constants import DimsMode
from napari.components._dims.view import QtDims
from napari.util import app_context
with app_context():
# Instanciates a dimensions model:
dims = Dims(3)
# dims.set_mode(0, DimsMode.Point)
# dims.set_point(1,50)
# dims.set_point(2,50)
# defines a axis change listener:
def listener_axis(event):
axis = event.axis
slicespec, projectspec = dims.slice_and_project
print("axis: %d changed, slice: %s, project: %s" % (axis, slicespec[axis], projectspec[axis]))
print("dims: %s" % event.source)
# connects listener to model:
dims.events.axis.connect(listener_axis)
# defines a axis change listener:
def listener_ndim(event):
print("dims changed from: "+str(event.source))
# connects listener to model:
dims.events.ndims.connect(listener_ndim)
# creates a widget to view (and control) the model:
widget = QtDims(dims)
# makes the view visible on the desktop:
widget.show()
# a loop to simulate changes to the model happening outside of the QT event loop:
def myloop():
for i in range(0, 1000):
dims.set_point(0, i % 100)
#print(widget.sliders[0])
#print(widget.layout().itemAt(0))
sleep(0.1)
if i % 50 == 0:
dims.ndims = 3 + int(i // 50)
if i>100 and i % 150 == 0:
dims.ndims = dims.ndims - 1
if not widget.isVisible():
return
# starts the thread for the loop:
#threading.Thread(target=myloop).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment