def __init__(self, name, gfxmgr, clone=0): debug.subthreadTest() # self.name is also assigned by GhostGfxWindow, but it's # helpful for debugging for it to be assigned as soon as # possible in all execution paths. self.name = name self.gfxlock = lock.Lock() self.acquireGfxLock() # This whole initialization sequence is complicated. The # reason is that the order of operations is important -- the # ghostgfxwindow makes function calls which need to be # redefined in the GUI before they occur -- and there is a # requirement that the main thread never be locked. # Furthermore, the ghostgfxwindow has to create the menu # before the SubWindow init gets called. It could probably be # rationalized, but it's not urgent. # preinitialize and postinitialize are defined in gfxwindow.py # for 2D and gfxwindow3d.py for 3D. mainthread.runBlock(self.preinitialize, (name, gfxmgr, clone)) # GhostGfxWindow.__init__ creates the canvas, among other things. ghostgfxwindow.GhostGfxWindow.__init__(self, name, gfxmgr, clone=clone) mainthread.runBlock(self.postinitialize, (name, gfxmgr, clone)) self.releaseGfxLock() self.switchboardCallbacks.append( switchboard.requestCallback("shutdown", self.shutdownCB))
def move_thread(self, skeleton, x, y, shift, ctrl): debug.subthreadTest() self.mouselock.acquire() try: if self.movingnode is not None: self.moving = 1 homogeneity = 0.0 shapeenergy = 0.0 point = self.getPoint(x, y) # It's generally forbidden to call node.moveTo instead of # skeleton.moveNodeTo, but since we're going to move the # node back (see up(), below), it's ok. if point is not None: self.movingnode.moveTo(point) if self.movingnode.illegal(): homogtext = "---" shapetext = "---" labeltext = "Illegal node position!" else: for element in self.nbrelements: # Evaluating homogeneity and shape energy is # safe, because the Skeleton's read lock was # acquired when the mouse went down. homogeneity += element.homogeneity(skeleton.MS) shapeenergy += element.energyShape() homogtext = "%-11.4g" % (homogeneity - self.homogeneity0) shapetext = "%-11.4g" % (shapeenergy - self.shapeenergy0) labeltext = "" mainthread.runBlock(self.move_info, (point, homogtext, shapetext, labeltext)) gtklogger.checkpoint("Move Node toolbox move event") finally: self.mouselock.release()
def updateAAInfo(self): # must be called on subthread debug.subthreadTest() ms = self.getCurrentMS() if ms is not None: activearea = ms.getObject().activearea activearea.begin_reading() try: aasize = activearea.size() mssize = ms.getObject().sizeInPixels() if config.dimension()==2: mpxls = mssize[0] * mssize[1] pixstring="pixels" elif config.dimension()==3: mpxls = mssize[0] * mssize[1] * mssize[2] pixstring="voxels" apxls = mpxls - aasize if ms.getObject().activearea.getOverride(): msg = "OVERRIDE: all %d %s are active" % (mpxls, pixstring) else: msg = "%d of %d %s are active" % (apxls, mpxls, pixstring) finally: activearea.end_reading() else: msg = "No Microstructure selected" mainthread.runBlock(self.aainfo.set_text, (msg,)) gtklogger.checkpoint("active area status updated")
def updateSegmentList(self, chsr, objlist): # called only when Skeleton readlock has been obtained. namelist = ["Segment %d, nodes (%d, %d) (length: %s)" % (obj.index, obj.nodes()[0].index, obj.nodes()[1].index, obj.length()) for obj in objlist] mainthread.runBlock(chsr.update, (objlist, namelist))
def __init__(self, name, gfxmgr, clone=0): debug.subthreadTest() self.gfxlock = lock.Lock() mainthread.runBlock(self.preinitialize, (name, gfxmgr, clone)) self.newCanvas() ghostgfxwindow.GhostGfxWindow.__init__(self, name, gfxmgr, clone=clone) mainthread.runBlock(self.postinitialize, (name, gfxmgr, clone))
def initialize(self, gfxwindow, layerNumber=None): layereditor.LayerEditor.initialize(self, gfxwindow, layerNumber) gtklogger.checkpoint("layereditor layerset changed") self.setData("gfxwindow", gfxwindow) if gfxwindow is not None: mainthread.runBlock(self.destinationMenu.set_state, (gfxwindow.name, ))
def updateSomething(self, container): debug.subthreadTest() segment = container.object skeleton = container.skeleton container.context.begin_reading() try: sindex = `segment.getIndex()` self.updateNodeList(self.nodes, list(segment.get_nodes())) self.syncPeeker(self.nodes, "Node") self.updateElementList(self.elem, segment.getElements()) self.syncPeeker(self.elem, "Element") length = `segment.length()` homogval = segment.homogeneity(skeleton.MS) if 0.9999 < homogval < 1.0: homog = "1 - (%e)" % (1.0-homogval) else: homog = `homogval` self.updateGroup(segment) bdynames = ','.join( segment.boundaryNames(container.context.getObject())) # mat = segment.material(container.context) # if mat: # matname = mat.name() # else: # matname = "<No material>" finally: container.context.end_reading() mainthread.runBlock(self.updateSomething_thread, (sindex, length, homog, bdynames, #matname ))
def sensitize_subthread(self): def set_button_sensitivity(u, r, c): self.undobutton.set_sensitive(u) self.redobutton.set_sensitive(r) self.clearbutton.set_sensitive(c) def set_ok_sensitivity(selection): ok = selection is not None and \ self.selectionModFactory.isValid() self.okbutton.set_sensitive(ok) (ms, selection) = mainthread.runBlock(self.getSelectionContext) if selection is not None: selection.begin_reading() try: u = selection.undoable() r = selection.redoable() c = selection.clearable() finally: selection.end_reading() else: (u, r, c) = (0, 0, 0) mainthread.runBlock(set_button_sensitivity, (u, r, c)) mainthread.runBlock(set_ok_sensitivity, (selection, )) gtklogger.checkpoint("pixel page sensitized")
def setInfo_subthread(self): debug.subthreadTest() source = self.getSelectionSource() if source is not None: source.begin_reading() try: selection = source.getSelectionContext( **self.toolbox.extrakwargs) ## Selection can be None because an Image must be created ## before a Microstructure, but the selection source for ## an Image is its Microstructure. if selection is not None: selection.begin_reading() try: sizetextdata = ` selection.size() ` finally: selection.end_reading() else: sizetextdata = '0' finally: source.end_reading() else: sizetextdata = self.toolbox.emptyMessage() mainthread.runBlock(self._write_text, (sizetextdata, ))
def sensitize(self): debug.subthreadTest() ms_available = False grp_selected = False nonemptygrp = False pixelsselected = False ngrps = 0 msctxt = self.currentMScontext() if msctxt: # TODO: This is incorrect. Don't call begin_reading here. # The ms may be doing some long calculation, and the # buttons should be desensitized because of it. Calling # begin_reading will lock and prevent densensitization # until after the calculation is done! msctxt.begin_reading() try: ms = msctxt.getObject() if ms is not None: ms_available = True grp = self.currentGroup() grp_selected = (grp is not None) and ms_available nonemptygrp = grp_selected and len(grp) > 0 pixelsselected = ms.pixelselection.size() > 0 ngrps = ms.nGroups() finally: msctxt.end_reading() mainthread.runBlock( self.sensitize_thread, (ms_available, grp_selected, pixelsselected, nonemptygrp, ngrps))
def sensitize_subthread(self): def set_button_sensitivity(u, r, c): self.undobutton.set_sensitive(u) self.redobutton.set_sensitive(r) self.clearbutton.set_sensitive(c) def set_ok_sensitivity(selection): ok = (selection is not None and not selection.query_reservation() and self.selectionModFactory.isValid()) self.okbutton.set_sensitive(ok) (ms, selection) = mainthread.runBlock(self.getSelectionContext) if selection is not None: available = not selection.query_reservation() selection.begin_reading() try: u = available and selection.undoable() r = available and selection.redoable() c = available and selection.clearable() finally: selection.end_reading() else: (u,r,c) = (0,0,0) mainthread.runBlock(set_button_sensitivity, (u,r,c)) mainthread.runBlock(set_ok_sensitivity, (selection,) )
def sensitize_subthread(self): def set_button_sensitivity(u, r, c): self.undobutton.set_sensitive(u) self.redobutton.set_sensitive(r) self.clearbutton.set_sensitive(c) def set_ok_sensitivity(selection): ok = selection is not None and \ self.selectionModFactory.isValid() self.okbutton.set_sensitive(ok) (ms, selection) = mainthread.runBlock(self.getSelectionContext) if selection is not None: selection.begin_reading() try: u = selection.undoable() r = selection.redoable() c = selection.clearable() finally: selection.end_reading() else: (u,r,c) = (0,0,0) mainthread.runBlock(set_button_sensitivity, (u,r,c)) mainthread.runBlock(set_ok_sensitivity, (selection,) ) gtklogger.checkpoint("pixel page sensitized")
def displayMSInfo(self, *args): # *args is given because this is used as a switchboard # callback for ('rename who', 'Image') as well as being called # directly. This indicates either slovenliness or efficiency # on the part of the programmer. debug.subthreadTest() mscontext = self.currentMScontext() text = "" if mscontext is not None: mscontext.begin_reading() try: ms = mscontext.getObject() size = ms.sizeInPixels() if config.dimension() == 2: text += 'Pixel size: %dx%d\n' % (size.x, size.y) size = ms.size() text += 'Physical size: %gx%g\n' % (size.x, size.y) elif config.dimension() == 3: text += 'Voxel size: %dx%dx%d\n' % (size.x, size.y, size.z) size = ms.size() text += 'Physical size: %gx%gx%g\n' % (size.x, size.y, size.z) imagenames = ms.imageNames() if imagenames: text += 'Images:\n' for name in imagenames: text += ' ' + name + '\n' for infoplugin in self.infoplugins: plugintext = infoplugin(mscontext) if plugintext: text += plugintext + '\n' finally: mscontext.end_reading() mainthread.runBlock(self.infoarea.get_buffer().set_text, (text, ))
def updateNodeList(self, chsr, objlist, element=None): namelist = [ "Node %d at %s" % (obj.uiIdentifier(), genericinfoGUI.posString(obj.position())) for obj in objlist ] mainthread.runBlock(chsr.update, (objlist, namelist))
def update(self, indx): debug.subthreadTest() if indx is not None: meshctxt = self.gfxtoolbox.getMeshContext() meshctxt.begin_reading() try: element = meshctxt.getObject().getElement(indx) # element probably can't be None, but it doesn't hurt # to check. if element is not None: self.updateNodeList(element.nodes()) mat = element.material() if mat: matname = mat.name() else: matname = "<No material>" mainthread.runBlock(self.update_thread, (element.masterelement().name(), ` element.uiIdentifier() `, matname)) return finally: meshctxt.end_reading() # Nothing to display mainthread.runBlock(self.update_thread, ("", "", "")) self.updateNodeList([])
def rebuild_grouplist(self): debug.subthreadTest() mscontext = self.currentMScontext() msg = None if mscontext is not None: mscontext.begin_reading() ms = mscontext.getObject() try: if ms.nGroups() > 0: grpnames = ms.groupNames() dispnames = grpnames[:] for i in range(len(grpnames)): grpname = grpnames[i] grp = ms.findGroup(grpname) dispnames[i] += " (%d %s%s" % (len(grp), pixstring, "s" * (len(grp) != 1)) if grp.is_meshable(): dispnames[i] += ", meshable)" else: dispnames[i] += ")" else: msg = 'No %s groups defined!' % pixstring finally: mscontext.end_reading() else: # ms is None msg = 'No Microstructure defined!' if msg: mainthread.runBlock(self.set_group_message, (msg, )) else: mainthread.runBlock(self.set_group_list, (grpnames, dispnames)) self.setMeshableButton()
def updateNodeList(self, nodes): namelist = [ "%s %d at %s" % (node.classname(), node.uiIdentifier(), genericinfoGUI.posString(node.position())) for node in nodes ] mainthread.runBlock(self.nodes.update, (nodes, namelist))
def _clipPlanesChanged(self, viewobj, viewname=None): # The "true" arg tells set_view to set the clip planes. mainthread.runBlock(self.gfxwindow().oofcanvas.set_view, (viewobj, True)) self.gfxwindow().updateview() switchboard.notify("view changed", self.gfxwindow()) switchboard.notify("clip planes changed", self.gfxwindow())
def updateNodeListAngle(self, chsr, element): # called only when Skeleton readlock has been obtained. namelist = ["Node %d at (%s, %s) (angle: %s)" % \ (node.index, node.position().x, node.position().y, element.getRealAngle(element.nodes.index(node))) for node in element.nodes] mainthread.runBlock(chsr.update, (element.nodes, namelist))
def setInfo_subthread(self): debug.subthreadTest() source = self.getSource() if source is not None: source.begin_reading() try: selection = source.getSelectionContext( **self.toolbox.extrakwargs) ## Selection can be None because an Image must be created ## before a Microstructure, but the selection source for ## an Image is its Microstructure. if selection is not None: selection.begin_reading() try: sizetextdata = `selection.size()` finally: selection.end_reading() else: sizetextdata = '0' finally: source.end_reading() else: sizetextdata = self.toolbox.emptyMessage() mainthread.runBlock(self._write_text, (sizetextdata,)) gtklogger.checkpoint("selection info updated")
def rebuild_grouplist(self): debug.subthreadTest() mscontext = self.currentMScontext() msg = None if mscontext is not None: mscontext.begin_reading() ms = mscontext.getObject() try: if ms.nGroups() > 0: grpnames = ms.groupNames() dispnames = grpnames[:] for i in range(len(grpnames)): grpname = grpnames[i] grp = ms.findGroup(grpname) dispnames[i] += " (%d %s%s" % (len(grp), pixstring, "s"*(len(grp)!=1)) if grp.is_meshable(): dispnames[i] += ", meshable)" else: dispnames[i] += ")" else: msg = 'No %s groups defined!'%pixstring finally: mscontext.end_reading() else: # ms is None msg = 'No Microstructure defined!' if msg: mainthread.runBlock(self.set_group_message, (msg,)) else: mainthread.runBlock(self.set_group_list, (grpnames, dispnames)) self.setMeshableButton()
def move_thread(self, skeleton, x, y, shift, ctrl): debug.subthreadTest() self.mouselock.acquire() try: if self.movingnode is not None: self.moving = 1 homogeneity = 0.0 shapeenergy = 0.0 point = self.getPoint(x,y) # It's generally forbidden to call node.moveTo instead of # skeleton.moveNodeTo, but since we're going to move the # node back (see up(), below), it's ok. if point is not None: self.movingnode.moveTo(point) if self.movingnode.illegal(): homogtext = "---" shapetext = "---" labeltext = "Illegal node position!" else: for element in self.nbrelements: # Evaluating homogeneity and shape energy is # safe, because the Skeleton's read lock was # acquired when the mouse went down. homogeneity += element.homogeneity(skeleton.MS) shapeenergy += element.energyShape() homogtext = "%-11.4g" % (homogeneity-self.homogeneity0) shapetext = "%-11.4g" % (shapeenergy-self.shapeenergy0) labeltext = "" mainthread.runBlock(self.move_info, (point, homogtext, shapetext, labeltext)) gtklogger.checkpoint("Move Node toolbox move event") finally: self.mouselock.release()
def initialize(self, gfxwindow, layerNumber=None): layereditor.LayerEditor.initialize(self, gfxwindow, layerNumber) gtklogger.checkpoint("layereditor layerset changed") self.setData("gfxwindow", gfxwindow) if gfxwindow is not None: mainthread.runBlock(self.destinationMenu.set_state, (gfxwindow.name,))
def displayImageInfo(self): debug.subthreadTest() imagecontext = self.getCurrentImage() text = "" if imagecontext: imagecontext.begin_reading() try: if config.dimension() == 2: image = imagecontext.getObject() size = image.sizeInPixels() text += 'Pixel size: %dx%d\n' % (size.x, size.y) size = image.size() text += 'Physical size: %gx%g\n' % (size.x, size.y) if image.comment(): text += '\nComments:\n%s\n' % image.comment() elif config.dimension() == 3: image = imagecontext.getObject() size = image.sizeInPixels() text += 'Voxel size: %dx%dx%d\n' % (size.x, size.y, size.z) size = image.size() text += 'Physical size: %gx%gx%g\n' % (size.x, size.y, size.z) finally: imagecontext.end_reading() mainthread.runBlock(self.displayImageInfo_thread, (text, ))
def update(self, indx): debug.subthreadTest() if indx is not None: meshctxt = self.gfxtoolbox.getMeshContext() meshctxt.begin_reading() try: femesh = meshctxt.getObject() node = femesh.getNode(indx) # node probably can't be None, but it doesn't hurt to # check. if node is not None: # Find out which fields are defined at the node fieldnames = node.fieldNames() # compound field names nfieldrows = 0 listedfields = [] for fieldname in fieldnames: fld = field.getField(fieldname) nfieldrows += fld.ndof() listedfields.append(fld) if config.dimension() == 2: zfld = fld.out_of_plane() if node.hasField(zfld): listedfields.append(zfld) nfieldrows += zfld.ndof() tfld = fld.time_derivative() if node.hasField(tfld): listedfields.append(tfld) nfieldrows += tfld.ndof() # Rebuild the table of field values, but only if the # fields have changed. if self.fieldslisted != listedfields: mainthread.runBlock(self.rebuildFieldTable, ( nfieldrows, listedfields, )) # Get the field values for the table. fieldvals = [] # The structure of this loop must match the loop # in update_thread, below. for fld in self.fieldslisted: fcomp = fld.iterator(planarity.ALL_INDICES) while not fcomp.end(): fieldvals.append( fld.value(femesh, node, fcomp.integer())) fcomp.next() # end loop over field values mainthread.runBlock(self.update_thread, ( ` node.index() `, node.classname(), genericinfoGUI.posString( node.position()), fieldvals)) return # end if node is not None finally: meshctxt.end_reading() # end if indx is not None # No node mainthread.runBlock(self.update_thread, ("", "", "", []))
def nextCB(self, *args): # go to the next history item self.historyBuffer.next() self.inhibit = 1 self.setCB(self.historyBuffer.current(), **self.setCBkwargs) self.inhibit = 0 self.editingHistory = 1 if self.sensitizeCB: mainthread.runBlock(self.sensitizeCB)
def updateFaceList(self, chsr, objlist): namelist = [ "Face %d, nodes %s (area: %g)" % (obj.uiIdentifier(), tuple(o.uiIdentifier() for o in obj.getNodes()), obj.area()) for obj in objlist ] mainthread.runBlock(chsr.update, (objlist, namelist))
def updateSegmentList(self, chsr, objlist): # called only when Skeleton readlock has been obtained. namelist = [ "Segment %d, nodes (%d, %d) (length: %s)" % (obj.index, obj.nodes()[0].index, obj.nodes()[1].index, obj.length()) for obj in objlist ] mainthread.runBlock(chsr.update, (objlist, namelist))
def contourmapTextColor(self, menuitem, color): self.acquireGfxLock() try: ghostgfxwindow.GhostGfxWindow.contourmapTextColor(self, menuitem, color) mainthread.runBlock(self.oofcanvas.set_contourmap_textcolor, (color,)) self.oofcanvas.render() finally: self.releaseGfxLock()
def updateSegmentList(self, chsr, objlist): namelist = [ "Segment %d, nodes %s (length: %g)" % (obj.uiIdentifier(), tuple(o.uiIdentifier() for o in obj.getNodes()), obj.length()) for obj in objlist ] mainthread.runBlock(chsr.update, (objlist, namelist))
def destroy(self, destroy_canvaslayer=True): self.gfxwindow = None # TODO OPT: Is this necessary? if self.whoChangedSignal: switchboard.removeCallback(self.whoChangedSignal) switchboard.removeCallback(self.whoRenamedSignal) if destroy_canvaslayer and self.canvaslayer is not None: mainthread.runBlock(self.canvaslayer.destroy) self.canvaslayer = None
def bgColor(self, menuitem, color): self.acquireGfxLock() try: ghostgfxwindow.GhostGfxWindow.bgColor(self, menuitem, color) mainthread.runBlock(self.oofcanvas.set_bgColor, (color,)) self.oofcanvas.render() finally: self.releaseGfxLock()
def bgColor(self, menuitem, color): self.acquireGfxLock() try: ghostgfxwindow.GhostGfxWindow.bgColor(self, menuitem, color) mainthread.runBlock(self.oofcanvas.set_bgColor, (color, )) self.oofcanvas.render() finally: self.releaseGfxLock()
def update(self, indx): debug.subthreadTest() skelctxt = self.getContext() if not skelctxt: return skeleton = skelctxt.getObject() if indx is not None and 0 <= indx < skeleton.nelements(): skelctxt.begin_reading() try: microstructure = skeleton.getMicrostructure() # If the user typed the index, instead of clicking on # an element, it could be invalid. if indx < 0 or indx >= skeleton.nelements(): return element = skeleton.getElement(indx) assert element is not None if config.dimension() == 3: self.updateFaceList(self.faces, skeleton.getElementFaces(element)) self.updateSegmentList(self.segs, skeleton.getElementSegments(element)) self.updateNodeList(self.nodes, element.getNodes(), element) eid = ` indx ` etype = skeleton.getElementType(element.getIndex()) if config.dimension() == 3: earea = "%g" % element.volume() elif config.dimension() == 2: earea = "%g" % element.area() if not element.illegal(): domCat = element.dominantPixel(skeleton) hom = "%f" % element.homogeneity(skeleton) eshape = "%f" % element.energyShape() mat = element.material(skeleton) egrps = ", ".join(element.groupNames()) if mat: matname = mat.name() else: matname = "<No material>" else: # illegal element domCat = "Not Computed" egrps = "???" hom = "???" eshape = "???" matname = "???" mainthread.runBlock(self.update_thread, (etype, eid, earea, ` domCat `, egrps, hom, eshape, matname)) return finally: skelctxt.end_reading() # end if indx is not None # Nothing to display -- no element or no indx. mainthread.runBlock(self.update_thread, ("", "", "", "", "", "", "", "")) mainthread.runBlock(self.clearObjLists)
def updateSomething(self, container): debug.subthreadTest() node = container.object skeleton = container.skeleton container.context.begin_reading() try: nindex = `node.getIndex()` if config.dimension() == 2: npos = "(%s, %s)" % (node.position().x, node.position().y) elif config.dimension() == 3: npos = "(%s, %s, %s)" % (node.position().x, node.position().y, node.position().z) if config.dimension() == 2: if node.movable_x() and node.movable_y(): nmob = "free" elif node.movable_x() and not node.movable_y(): nmob = "x only" elif not node.movable_x() and node.movable_y(): nmob = "y only" elif node.pinned(): nmob = "pinned" else: nmob = "fixed" elif config.dimension() == 3: if node.movable_x() and node.movable_y() and node.movable_z(): nmob = "free" elif node.movable_x() and node.movable_y() and not node.movable_z(): nmob = "x and y only" elif node.movable_x() and not node.movable_y() and node.movable_z(): nmob = "x and z only" elif not node.movable_x() and node.movable_y() and node.movable_z(): nmob = "y and z only" elif node.movable_x() and not node.movable_y() and not node.movable_z(): nmob = "x only" elif not node.movable_x() and node.movable_y() and not node.movable_z(): nmob = "y only" elif not node.movable_x() and not node.movable_y() and node.movable_z(): nmob = "z only" elif node.pinned(): nmob = "pinned" else: nmob = "fixed" self.updateElementList(self.elem, node.neighborElements()) self.syncPeeker(self.elem, "Element") self.updateGroup(node) bdys = [] for key, bdy in skeleton.pointboundaries.items(): if node in bdy.nodes: bdys.append(key) bdynames = string.join(bdys, ", ") finally: container.context.end_reading() mainthread.runBlock(self.updateSomething_thread, (nindex, npos, nmob, bdynames))
def close(self, *args): # The subwindow menu-removal can't depend on the existence of # .gtk, and it's done in the non-GUI parent, so call it # if this is the first time through. if not self.closed: ghostgfxwindow.GhostGfxWindow.close(self, *args) self.closed = 1 if self.gtk: mainthread.runBlock(self.gtk.destroy) # calls destroyCB via gtk
def handleMode(self, targetname): for mode in modes: if mode.targetname == targetname: if self.modeclass is not mode: self.clearPosition() # Call changeModeCB on main thread mainthread.runBlock( self.modebuttondict[targetname].set_active, (1, )) break
def destroyCB(self, *args, **kwargs): if self.gtk is not None: # recursion suppression selfgtk = self.gtk self.gtk = None map(switchboard.removeCallback, self.sbcallbacks) if self.whowidgetsignal: switchboard.removeCallback(self.whowidgetsignal) mainthread.runBlock(selfgtk.destroy) layereditor.LayerEditor.destroy(self)
def handleMode(self, targetname): for mode in modes: if mode.targetname == targetname: if self.modeclass is not mode: self.clearPosition() # Call changeModeCB on main thread mainthread.runBlock( self.modebuttondict[targetname].set_active, (1,)) break
def prevCB(self, *args): # go to the previous history item if self.editingHistory: self.historyBuffer.prev() self.inhibit = 1 self.setCB(self.historyBuffer.current(), **self.setCBkwargs) self.inhibit = 0 self.editingHistory = 1 if self.sensitizeCB: mainthread.runBlock(self.sensitizeCB)
def _updateQuerySubthread(self): self.meshcontext.restoreCachedData(self.gfxwindow().displayTime) try: mainthread.runBlock(self.modeobj.updateSomething, (self.toolbox.querier,)) finally: self.meshcontext.releaseCachedData() gtklogger.checkpoint(self.gfxwindow().name + " " + self._name + " updated")
def newwhoMS(self, whoname): # switchboard ('new who', 'Microstructure') # whoname is a list of strings self.grouplock.acquire() try: mainthread.runBlock(self.mswidget.set_value, (whoname,)) self.rebuild_grouplist() self.displayMSInfo() self.sensitize() finally: self.grouplock.release()
def stateChangeCB(self, *args): # call this when the selector changes if self.inhibit: return self.editingHistory = 0 try: self.historyBuffer.last() except IndexError: pass if self.sensitizeCB: mainthread.runBlock(self.sensitizeCB)
def newCanvas(self): # Recreate the canvas object. # It's important to acquire and release the lock in the # subthread, before calling mainthread.runBlock, to avoid # deadlocks. debug.subthreadTest() self.acquireGfxLock() try: mainthread.runBlock(self.newCanvas_thread) finally: self.releaseGfxLock()
def updateSomething(self, container): debug.subthreadTest() element = container.object skeleton = container.skeleton container.context.begin_reading() try: etype = `element.type()`[1:-1] # strip quotes eindex = `element.getIndex()` if config.dimension() == 2: self.updateNodeListAngle(self.nodes, element) elif config.dimension() == 3: self.updateNodeList(self.nodes, element.nodes) # Clear the selection in the list of nodes if there's # nothing in the peeker. self.syncPeeker(self.nodes, "Node") esegs = element.getSegments(skeleton) self.updateSegmentList(self.segs, esegs) # Clear the selection in the list of segments if there's # nothing in the peeker. self.syncPeeker(self.segs, "Segment") if config.dimension() == 2: earea = "%s" % element.area() elif config.dimension() == 3: earea = "%s" % element.volume() if not element.illegal(): domCat = element.dominantPixel(skeleton.MS) repPix = skeleton.MS.getRepresentativePixel(domCat) pixGrp = pixelgroup.pixelGroupNames(skeleton.MS, repPix) pixgrps = string.join(pixGrp, ", ") ehom = "%f" % element.homogeneity(skeleton.MS) eshape = "%f" % element.energyShape() mat = element.material(container.context) if mat: matname = mat.name() else: matname = "<No material>" else: # illegal element pixgrps = "???" ehom = "???" eshape = "???" matname = "???" self.updateGroup(element) finally: container.context.end_reading() mainthread.runBlock(self.updateSomething_thread, (etype, eindex, earea, pixgrps, ehom, eshape, matname))
def update_subthread(self, skelcontext): # Get the selection from the skeleton context if skelcontext: n = self.selectionSize() # requires subthread status_text = " %d %s%s selected." % (n, self.activemode.name(), 's'*(n!=1)) else: status_text = "No Skeleton selected." mainthread.runBlock(self.status.set_text, (status_text,)) gtklogger.checkpoint("skeleton selection page updated")
def _CheckOOFMenuItem___call__(self, active): _old_CheckOOFMenuItem___call__(self, active) # Before calling set_active(), it's necessary to disable the gtk # callback mechanism for the button, so that set_active() won't # call the callback, which calls this function, which calls # set_active(), ad infinitum. try: gtkitem = self.gtkitem except AttributeError: pass else: mainthread.runBlock(_setactive, (gtkitem, self.handlerid, active))
def updateNodeList(self, chsr, objlist): # called only when Skeleton readlock has been obtained. if config.dimension() == 2: namelist = ["Node %d at (%s, %s)" % (obj.index, obj.position().x, obj.position().y) for obj in objlist] elif config.dimension() == 3: namelist = ["Node %d at (%s, %s, %s)" % (obj.index, obj.position().x, obj.position().y, obj.position().z) for obj in objlist] mainthread.runBlock(chsr.update, (objlist, namelist))
def setMeshableButton(self): debug.subthreadTest() mscontext = self.currentMScontext() if mscontext: mscontext.begin_reading() try: grp = self.currentGroup() meshable = grp is not None and grp.is_meshable() finally: mscontext.end_reading() else: meshable = False mainthread.runBlock(self.setMeshableButton_thread, (meshable,))
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) querier = self.toolbox.querier self.modeobj.updateSomething(querier) mainthread.runBlock(self.showPosition,(querier.position,)) else: mainthread.runBlock(self.modeobj.updateNothing) switchboard.notify("redraw") self.sensitize()
def zoomFillWindow(self, *args, **kwargs): # This has args because it's used as a menuitem callback. The # 'lock' argument is not a menu argument, though. It's only # used when zoomFillWindow is called explicitly from within # another drawing routine, to indicate that the gfxLock has # already been acquired. lock = kwargs.get('lock', True) # default is to acquire the lock if lock: self.acquireGfxLock() try: mainthread.runBlock(self.zoomFillWindow_thread) finally: if lock: self.releaseGfxLock()
def start(self): if self.menuitem.callback is not None: try: self.initialize() try: mainthread.runBlock(self.menuitem.precall) mainthread.runBlock(self.menuitem.callback, (self,)+self.args, self.kwargs) # remove_excepthook is called here only if no # exception occured. If an exception occured, # remove_excepthook can't be called until after # the exception is handled. excepthook.remove_excepthook(self.excepthook) except SystemExit: raise # TODO SWIG1.3: After conversion to SWIG 1.3, OOF # exceptions will probably be subclasses of Exception. except (Exception, ooferror.ErrErrorPtr), exception: mainthread.runBlock(self.menuitem.postcall, (False,)) if propagate_exceptions or not self.toplevel: excepthook.remove_excepthook(self.excepthook) raise else: reporter.error(exception) sys.excepthook(*sys.exc_info()) else: # no exception mainthread.runBlock(self.menuitem.postcall, (True,))