def __init__(self, parent=None, *args, **kwds): self._img = None self._imgReq = None self._sizeHint = (640,480) ## no clue why this is needed, but it seems to be the default sizeHint for GraphicsView. ## without it, the widget will not compete for space against another GraphicsView. QtGui.QWidget.__init__(self) self._proc = mp.QtProcess(debug=False) self.pg = self._proc._import('pyqtgraph') self.pg.setConfigOptions(**self.pg.CONFIG_OPTIONS) rpgRemote = self._proc._import('pyqtgraph.widgets.RemoteGraphicsView') self._view = rpgRemote.Renderer(*args, **kwds) self._view._setProxyOptions(deferGetattr=True) self.setFocusPolicy(QtCore.Qt.StrongFocus) self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.setMouseTracking(True) self.shm = None shmFileName = self._view.shmFileName() if sys.platform.startswith('win'): self.shmtag = shmFileName else: self.shmFile = open(shmFileName, 'r') self._view.sceneRendered.connect(mp.proxy(self.remoteSceneChanged)) #, callSync='off')) ## Note: we need synchronous signals ## even though there is no return value-- ## this informs the renderer that it is ## safe to begin rendering again. for method in ['scene', 'setCentralItem']: setattr(self, method, getattr(self._view, method))
def listDataItems(self): """ Create a picklable list of data items. """ data_items = super().listDataItems() data_items = [mp.proxy(item) for item in data_items] return data_items
def getWindows(cls): windows = [mp.proxy(item) for item in cls._windows] return windows
def getLayoutItems(self): layout = self.ci items = list(layout.items.keys()) items = [mp.proxy(item) for item in items] return items
view.addItem(scatter2) proc2 = mp.QtProcess(processRequests=False) rpg2 = proc2._import('pyqtgraph') plotwindow2 = rpg2.plot() plot2 = plotwindow2.plot(pen=None, symbol='o') plotwindow2.setRange(xRange=[-10, 10], yRange=[0, 25]) a = 0 def mouseCallback(event): a += 1 proxy = mp.proxy(mouseCallback, callSync='off', autoProxy=True) plot2.scene().sigMouseClicked.connect(proxy) textitems = [rpg2.TextItem(text="test") for i in range(max_targets)] for x in textitems: plotwindow2.addItem(x) #END OF GRAPHING #Open a file to store data #f = h5py.File(sys.argv[1]+datetime.now().strftime("%Y%m%d%H%M%S") + ".hdf5", 'w') # try: # samples = f['/'+datasetName+'/samples'] # labels = f['/'+datasetName+'/labels'] # timestamps = f['/'+datasetName+'/timestamps'] # except KeyError as e:
def __init__(self): # set up simulation in remote process self.dt = 25*us self.proc = mp.QtProcess(debug=False) ndemo = self.proc._import('neurodemo') self.sim = ndemo.Sim(temp=6.3, dt=self.dt) self.sim._setProxyOptions(deferGetattr=True) self.neuron = ndemo.Section(name='soma') self.sim.add(self.neuron) self.hhna = self.neuron.add(ndemo.HHNa()) self.leak = self.neuron.add(ndemo.Leak()) self.hhk = self.neuron.add(ndemo.HHK()) self.dexh = self.neuron.add(ndemo.IH()) self.dexh.enabled = False self.clamp = self.neuron.add(ndemo.PatchClamp(mode='ic')) #cmd = np.zeros(int(1/self.dt)) #cmd[int(0.4/self.dt):int(0.8/self.dt)] = 200e-12 #self.clamp.set_command(cmd, dt=self.dt) mechanisms = [self.clamp, self.hhna, self.leak, self.hhk, self.dexh] # loop to run the simulation indefinitely self.runner = ndemo.SimRunner(self.sim) #self.runner.add_request('soma.Vm') self.runner.add_request('t') self.runner.new_result.connect(mp.proxy(self.new_result, autoProxy=False, callSync='off')) # set up GUI QtGui.QWidget.__init__(self) self.fullscreen_widget = None self.resize(1024, 768) self.layout = QtGui.QGridLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.layout) self.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal) self.layout.addWidget(self.splitter, 0, 0) self.ptree = pt.ParameterTree(showHeader=False) self.splitter.addWidget(self.ptree) self.plot_splitter = QtGui.QSplitter(QtCore.Qt.Vertical) self.splitter.addWidget(self.plot_splitter) self.neuronview = NeuronView(self.neuron, mechanisms) self.plot_splitter.addWidget(self.neuronview) #self.vm_plot = ScrollingPlot(dt=self.dt, npts=int(1.0/self.dt), #parent=self, labels={'left': ('Membrane Potential', 'V'), #'bottom': ('Time', 's')}) #self.vm_plot.setYRange(-90*mV, 50*mV) #self.vm_plot.setXRange(-1000*ms, 0*ms) #self.vm_plot.addLine(y=self.neuron.ek) #self.vm_plot.addLine(y=self.neuron.ena) #self.plot_splitter.addWidget(self.vm_plot) self.channel_plots = {} self.channel_params = [ ChannelParameter(self.leak), ChannelParameter(self.hhna), ChannelParameter(self.hhk), ChannelParameter(self.dexh), ] for ch in self.channel_params: ch.plots_changed.connect(self.plots_changed) self.clamp_param = ClampParameter(self.clamp, self) self.clamp_param.plots_changed.connect(self.plots_changed) self.vm_plot = self.add_plot('soma.V', 'Membrane Potential', 'V') self.splitter.setSizes([350, 650]) self.show() self.params = pt.Parameter.create(name='params', type='group', children=[ dict(name='Preset', type='list', values=['', 'Passive Membrane', 'Action Potential']), dict(name='Run', type='bool', value=True), dict(name='Speed', type='float', value=0.3, limits=[0, 10], step=1, dec=True), dict(name='Temp', type='float', value=self.sim.temp, suffix='C', step=1.0), dict(name='Capacitance', type='float', value=self.neuron.cap, suffix='F', siPrefix=True, dec=True), dict(name='Cell Schematic', type='bool', value=True, children=[ dict(name='Show Circuit', type='bool', value=False), ]), self.clamp_param, dict(name='Ion Channels', type='group', children=self.channel_params), ]) self.ptree.setParameters(self.params) self.params.sigTreeStateChanged.connect(self.params_changed) self.start() self.clamp_param['Plot Current'] = True self.plot_splitter.setSizes([300, 500, 200]) self.pause_shortcut = QtGui.QShortcut(QtGui.QKeySequence('Space'), self) self.pause_shortcut.activated.connect(self.pause) self.slow_shortcut = QtGui.QShortcut(QtGui.QKeySequence('-'), self) self.slow_shortcut.activated.connect(self.slower) self.fast_shortcut = QtGui.QShortcut(QtGui.QKeySequence('='), self) self.fast_shortcut.activated.connect(self.faster) self.fullscreen_shortcut = QtGui.QShortcut(QtGui.QKeySequence('F11'), self) self.fullscreen_shortcut.activated.connect(self.fullscreen) self.fullscreen_shortcut.setContext(QtCore.Qt.ApplicationShortcut)