def showLayer_thread(self, menuitem, n): self.display.show_layer(self.device, n) # show layer in canvas self.layerListRowChanged(n) # Update the contourmap. if config.dimension() == 2: self.contourmap_newlayers() subthread.execute(self.show_contourmap_info)
def realizeCB(self, *args): if not self.realized: self.realized = 1 # Asynchronously zoom. if not self.zoomed: subthread.execute(self.zoomFillWindow) return False
def activate(self): if not self.active: self.active = True self.canvaslayer.set_opacity(self._opacity()) self.setVisibility(self._visibility()) self.canvaslayer.setModified() subthread.execute(self.gfxwindow.draw)
def meanwhile(self): ## This function should only be called if in text mode and on ## the main thread. It checks to see if the thread is ## finished and redraws the progress bars. It sleeps a bit ## after each check so that it doesn't eat up cpu. The sleep ## time is initially short, but grows (up to a point) on each ## iteration. naptime = 0.001 # initial length of sleep time maxnap = 0.3 # maximum length of sleep time napfactor = 2.0 # amount to increase on each iteration prgrsbars = {} # progressbar representations try: while not self.worker.finished(): subthread.execute(self._drawProgressBars, args=(prgrsbars,)) time.sleep(naptime) naptime *= napfactor if naptime > maxnap: naptime = maxnap # end while not worker.finished except KeyboardInterrupt: self.worker.threadstate.impedeProgress() # Wait for thread to finish before OOF-ing some more. Text # mode doesn't support concurrent operations. self.join()
def meanwhile(self): ## This function should only be called if in text mode and on ## the main thread. It checks to see if the thread is ## finished and redraws the progress bars. It sleeps a bit ## after each check so that it doesn't eat up cpu. The sleep ## time is initially short, but grows (up to a point) on each ## iteration. naptime = 0.001 # initial length of sleep time maxnap = 0.3 # maximum length of sleep time napfactor = 2.0 # amount to increase on each iteration prgrsbars = {} # progressbar representations try: while not self.worker.finished(): subthread.execute(self._drawProgressBars, args=(prgrsbars, )) time.sleep(naptime) naptime *= napfactor if naptime > maxnap: naptime = maxnap # end while not worker.finished except KeyboardInterrupt: self.worker.threadstate.impedeProgress() # Wait for thread to finish before OOF-ing some more. Text # mode doesn't support concurrent operations. self.join()
def up(self, x, y, buttons): debug.mainthreadTest() skelctxt = self.getSkeletonContext() if skelctxt: canvas = self.gfxwindow().oofcanvas view = canvas.get_view() pt = canvas.display2Physical(view, x, y) subthread.execute(self.up_subthread, (view, buttons, pt))
def deactivate(self): # gfxwindow may already be None if window is closing. if self.active and self.gfxwindow is not None: self.active = False self.canvaslayer.set_opacity(self._opacity()) self.setVisibility(self._visibility()) self.canvaslayer.setModified() subthread.execute(self.gfxwindow.draw)
def installed(self): # If redisplay_all is called by show() rather than by shown() # it can be called by gui start up code, which may be running # concurrently with other start up operations, including # gtklogging initialization. If that happens, the recording # of checkpoints reached by redisplay_all will depend on race # conditions. So redisplay_all must be called by shown(), # which is guaranteed (less likely?) to be called before gui # initialization is complete. subthread.execute(self.redisplay_all)
def moveCB(self, button): debug.mainthreadTest() x = utils.OOFeval(self.xtext.get_text()) y = utils.OOFeval(self.ytext.get_text()) if config.dimension() == 2: point = primitives.Point(x, y) elif config.dimension() == 3: z = utils.OOFeval(self.ztext.get_text()) point = primitives.Point(x, y, z) skelctxt = self.getSkeletonContext() subthread.execute(self.kbmove_subthread, (skelctxt, point))
def moveCB(self, button): debug.mainthreadTest() x = utils.OOFeval(self.xtext.get_text()) y = utils.OOFeval(self.ytext.get_text()) if config.dimension() == 2: point = primitives.Point(x,y) elif config.dimension() == 3: z = utils.OOFeval(self.ztext.get_text()) point = primitives.Point(x,y,z) skelctxt = self.getSkeletonContext() subthread.execute(self.kbmove_subthread, (skelctxt, point))
def up(self, x, y, buttons): # "Downed" must be cleared at the earliest opportunity, # otherwise spurious "move" events can be processed, # unilaterally changing the node position. self.downed = 0 if self.mode == "Keyboard": canvas = self.toolbox.gfxwindow().oofcanvas view = canvas.get_view() pt = canvas.display2Physical(view, x, y) self.toolbox.menu.SelectNode(position=pt, view=view) else: # self.mode == "Mouse" subthread.execute(self.up_subthread_mouse, (x, y, buttons))
def updateQuery(self): if not self.toolbox.querier: return # See if there's anything to update if self.toolbox.querier.object: # Change mode if needed. self.handleMode(self.toolbox.querier.targetname) self.showPosition(self.toolbox.querier.mouse_position, self.toolbox.querier.mesh_position) subthread.execute(self._updateQuerySubthread) else: self.modeobj.updateNothing() self.sensitize()
def updateTime(self, time): if not self.freezeTimeFlag and not self.tEditMode: if time != self.time: self.time = time subthread.execute(self.updateData) if time is None: self.tText.set_text("") else: # Strip blanks to the right of the number so that they # don't get in the way when the user edits the # position. self.tText.set_text(("%-13.6g" % self.time).rstrip()) gtklogger.checkpoint(self._name+" time updated")
def updateTime(self, time): if not self.freezeTimeFlag and not self.tEditMode: if time != self.time: self.time = time subthread.execute(self.updateData) if time is None: self.tText.set_text("") else: # Strip blanks to the right of the number so that they # don't get in the way when the user edits the # position. self.tText.set_text(("%-13.6g" % self.time).rstrip()) gtklogger.checkpoint(self._name + " time updated")
def installed(self): ## Obsolete comment that may still be relevant... The old ## "shown" routine is now called "installed". The default ## "show" method just calls self.gtk.show_all(). # If redisplay_all is called by show() rather than by shown() # it can be called by gui start up code, which may be running # concurrently with other start up operations, including # gtklogging initialization. If that happens, the recording # of checkpoints reached by redisplay_all will depend on race # conditions. So redisplay_all must be called by shown(), # which is guaranteed (more likely?) to be called after gui # initialization is complete. subthread.execute(self.redisplay_all)
def move(self, x, y, buttons): # The toolbox is updated when the mouse *moves*, even before a # click, because it's displaying node information which helps # the user decide which node to click on. debug.mainthreadTest() ## TODO OPT: During a move, the skeleton context and view can't ## change, so it's inefficient to retrieve them here. They ## should be cached whenever they change. A previous attempt ## to do that missed some changes, so the caching was removed. skelctxt = self.getSkeletonContext() view = self.toolbox.gfxwindow().oofcanvas.get_view() canvas = self.toolbox.gfxwindow().oofcanvas pt = canvas.display2Physical(view, x, y) subthread.execute(self.move3, (skelctxt, view, pt))
def changeModeCB(self, button, modename): # radio button callback if button.get_active(): if self.currentMode != modename: if self.clickIDs[modename] is not None: self.issueQueryCmd(self.modeobjdict[modename], self.clickIDs[modename]) else: # The new mode has no pre-clicked selection. No # menu command is issued, because there's no # selection being made, so we need to do some # extra housekeeping here. mode = self.modeobjdict[modename] subthread.execute(mode.update, (None, )) self.replaceInfoGUI(mode) self.toolbox.clearQuery() # Update the gfx layer switchboard.notify((self.gfxwindow(), "query " + self.toolbox.whoClassName)) # Redraw subthread.execute(self.gfxwindow().draw) self.sensitize()
def posChangedCB(self, gtkobj): # text edited in x & y gtk.Entries debug.mainthreadTest() try: if config.dimension() == 2: self.position = primitives.Point(_getval(self.xText), _getval(self.yText)) elif config.dimension() == 3: self.position = primitives.Point(_getval(self.xText), _getval(self.yText), _getval(self.zText)) except: # The user has typed something that can't be evaluated, # but maybe there's more typing to come. Ignore the error. if self.datawidget: self.datawidget.gtk.set_sensitive(0) else: subthread.execute(self.updateData) # Since the user has typed a new position, assume that # s/he really wants it, and don't overwrite it when the # mouse is clicked on the Mesh. self.freezeSpaceFlag = True self.freezeSpaceButton.set_active(True)
def updateMesh(self): debug.mainthreadTest() window = self.currentGfxWindow() newmesh = None if window: newmesh = window.topwho('Mesh') if newmesh: self.meshText.set_text(newmesh.path()) else: self.meshText.set_text('<No Mesh in window!>') else: self.meshText.set_text('---') if not self.freezeTimeFlag: self.updateTime(window.displayTime) if newmesh is not self.currentMesh: self.currentMesh = newmesh subthread.execute(self.updateData) if newmesh is not None: self.meshWidget.set_value(newmesh.path()) else: self.meshWidget.set_value(None) gtklogger.checkpoint(self._name+" mesh updated")
def updateMesh(self): debug.mainthreadTest() window = self.currentGfxWindow() newmesh = None if window: newmesh = window.topwho('Mesh') if newmesh: self.meshText.set_text(newmesh.path()) else: self.meshText.set_text('<No Mesh in window!>') else: self.meshText.set_text('---') if not self.freezeTimeFlag: self.updateTime(window.displayTime) if newmesh is not self.currentMesh: self.currentMesh = newmesh subthread.execute(self.updateData) if newmesh is not None: self.meshWidget.set_value(newmesh.path()) else: self.meshWidget.set_value(None) gtklogger.checkpoint(self._name + " mesh updated")
def updatePosition(self, position): # Switchboard callback for (gfxwindow, "meshinfo click"). # Also called when freezeSpaceFlag is unset, and during window # construction. debug.mainthreadTest() if not self.freezeSpaceFlag: if position != self.position: self.position = position subthread.execute(self.updateData) self.xsignal.block() self.ysignal.block() if config.dimension() == 3: self.zsignal.block() try: if position is not None: # Strip blanks to the right of the number so that they # don't get in the way when the user edits the # position. self.xText.set_text(("%-13.6g" % position.x).rstrip()) self.yText.set_text(("%-13.6g" % position.y).rstrip()) if config.dimension() == 3: self.zText.set_text(("%-13.6g" % position.z).rstrip()) else: # Probably not required -- position is initially None, # and having once been set, probably can't become # None. self.xText.set_text("") self.yText.set_text("") if config.dimension() == 3: self.zText.set_text("") finally: self.xsignal.unblock() self.ysignal.unblock() if config.dimension() == 3: self.zsignal.unblock() gtklogger.checkpoint(self._name+" position updated")
def tEditCB(self, button): if not self.tEditMode: # Switch to time editing mode self.tEditMode = True self.tEditButton.set_label("Done") self.tText.set_editable(True) else: # Switch out of time editing mode self.tEditMode = False self.tText.set_editable(False) self.tEditButton.set_label("Edit") try: t = utils.OOFeval(self.tText.get_text().lstrip()) except: pass else: self.time = t subthread.execute(self.updateData) # Since the user has entered a new time, don't # overwrite it when the graphics window's display time # changes. self.freezeTimeFlag = True self.freezeTimeButton.set_active(True) self.sensitize()
def updatePosition(self, position): # Switchboard callback for (gfxwindow, "meshinfo click"). # Also called when freezeSpaceFlag is unset, and during window # construction. debug.mainthreadTest() if not self.freezeSpaceFlag: if position != self.position: self.position = position subthread.execute(self.updateData) self.xsignal.block() self.ysignal.block() if config.dimension() == 3: self.zsignal.block() try: if position is not None: # Strip blanks to the right of the number so that they # don't get in the way when the user edits the # position. self.xText.set_text(("%-13.6g" % position.x).rstrip()) self.yText.set_text(("%-13.6g" % position.y).rstrip()) if config.dimension() == 3: self.zText.set_text(("%-13.6g" % position.z).rstrip()) else: # Probably not required -- position is initially None, # and having once been set, probably can't become # None. self.xText.set_text("") self.yText.set_text("") if config.dimension() == 3: self.zText.set_text("") finally: self.xsignal.unblock() self.ysignal.unblock() if config.dimension() == 3: self.zsignal.unblock() gtklogger.checkpoint(self._name + " position updated")
def updatePSInfo(self): debug.mainthreadTest() subthread.execute(self.updatePSInfo_subthread)
def meshDataChanged(self, meshctxt): # sb "mesh data changed" debug.mainthreadTest() if (meshctxt is self.currentMesh and (not self.freezeTimeFlag or self.time == self.currentMesh.getCurrentTime())): subthread.execute(self.updateData)
def freezeSpaceButtonCB(self, button): debug.mainthreadTest() self.freezeSpaceFlag = button.get_active() if not self.freezeSpaceFlag: self.updatePosition(self.position) subthread.execute(self.updateData)
def setInfo(self): debug.mainthreadTest() subthread.execute(self.setInfo_subthread)
def update(self, where): subthread.execute(self.update_thread, (where, ))
def sensitize(self): subthread.execute(self.sensitize_subthread)
def update(self, where): subthread.execute(self.update_thread, (where,))
def move(self, x, y, shift, ctrl): skeleton = self.getSkeleton() subthread.execute(self.move_thread, (skeleton, x, y, shift, ctrl))
def installed(self): # called by oofGUI when switching pages subthread.execute(self.installed_subth)
def msCB(self, *args): # whowidget callback subthread.execute(self.redisplay_all)
def down(self, x, y, shift, ctrl): subthread.execute(self.down_subthread, (x,y,shift,ctrl))
def sensitize(self): debug.mainthreadTest() subthread.execute(self.sensitize_subthread)
def up(self, x, y, shift, ctrl): # "Downed" must be cleared at the earliest opportunity, # otherwise spurious "move" events can be processed, # unilaterally changing the node position. self.downed = 0 subthread.execute(self.up_subthread, (x,y,shift,ctrl))
def installed(self): self.sensitize() self.sensitizeHistory() subthread.execute(self.displayImageInfo)
def update(self): skelctxt = self.getCurrentSkeleton() subthread.execute(self.update_subthread, (skelctxt,))
def iWidgetChanged(self, interactive): self.sensitize() subthread.execute(self.displayImageInfo)
def sensitize(self): current_selection = self.currentSelection() skelcontext = self.parent.getCurrentSkeleton() subthread.execute(self.sensitize_subthread, (skelcontext, current_selection) )
def skelmodCB(self, reg): subthread.execute(self.skelmodCB_subthread, (reg,))
def listItemChosen(self, name, interactive): # Chooser callback if self.built: subthread.execute(self.listItemChosen_thread, (name,))