def launch_viewer(request): project = loadProject(request) objectId = request.GET.get('objectId') # Fix this, now we should use newer notation: . instead of :: if '::' in objectId: idParts = objectId.split("::") if idParts[1] != 'None': # We use the logic in Pointer.get to handle the 'extended' # parts that can come as part of the id (eg: 2::outputAverages::1) protObj = project.getObject(int(idParts[0])) pointer = Pointer(value=protObj) pointer.setExtendedParts(idParts[1:]) obj = pointer.get() else: # obj = project.getObject(int(idParts[0])) else: obj = project.getObject(int(objectId)) if obj is not None: if obj.isPointer(): obj = obj.get() viewers = findViewers(obj.getClassName(), WEB_DJANGO) if len(viewers) == 0: views = [] if isinstance(obj, EMProtocol): for _, output in obj.iterOutputAttributes(EMObject): objViewers = findViewers(output.getClassName(), WEB_DJANGO) if objViewers: views += objViewers[0](project=project)._visualize(output) or [] if not views: views = [MessageView("No viewers found for object type: %s" % obj.getClassName())] urls = [viewToUrl(request, view) for view in views] else: viewerClass = viewers[0] viewer = viewerClass(project=project, protocol=obj) # Lets assume if there is a viewer for the protocol # it will be a ProtocolViewer with a Form if issubclass(viewerClass, ProtocolViewer): urls = [viewerForm(project, obj, viewer, request)] else: views = viewer._visualize(obj) urls = [viewToUrl(request, v) for v in views] else: views = [MessageView("Object not found to visualize")] urls = [viewToUrl(request, view) for view in views] jsonStr = json.dumps(urls, ensure_ascii=False) return HttpResponse(jsonStr, content_type='application/javascript')
def _onDoubleClick(self, e=None): if e.node.object: self._selectObject(e.node.object) # Graph the first viewer available for this type of object ViewerClass = findViewers(self._selected.getClassName(), DESKTOP_TKINTER)[0] # viewer = ViewerClass(project=self.project) viewer.visualize(self._selected)
def _viewObject(self, objId): """ Call appropriate viewer for objId. """ obj = self.project.getObject(int(objId)) viewerClasses = findViewers(obj.getClassName(), DESKTOP_TKINTER) if not viewerClasses: return # TODO: protest nicely viewer = viewerClasses[0](project=self.project, parent=self.windows) viewer.visualize(obj)
def _onDoubleClick(self, e=None): if e.node.pointer: self._selectObject(e.node.pointer) # Graph the first viewer available for this type of object ViewerClass = findViewers(self._selected.getClassName(), DESKTOP_TKINTER)[0] # viewer = ViewerClass(project=self.project) viewer.visualize(self._selected)
def launch_viewer(request): from views_util import loadProject from pyworkflow.em import findViewers, EMProtocol, EMObject projectName = request.session['projectName'] project = loadProject(request) objectId = request.GET.get('objectId') if '::' in objectId: idParts = objectId.split("::") if idParts[1] != 'None': setObj = project.getObject(int(idParts[0])) if idParts[1].startswith('__attribute__'): attrName = idParts[1].replace('__attribute__', '') if setObj.hasAttribute(attrName): obj = getattr(setObj, attrName) else: obj = None print "OBJ IS NONE!!" else: obj = setObj[int(idParts[1])] else: obj = project.getObject(int(idParts[0])) else: obj = project.getObject(int(objectId)) if obj != None: if obj.isPointer(): obj = obj.get() viewers = findViewers(obj.getClassName(), WEB_DJANGO) if len(viewers) == 0: views = [] if isinstance(obj, EMProtocol): for _, output in obj.iterOutputAttributes(EMObject): objViewers = findViewers(output.getClassName(), WEB_DJANGO) if objViewers: views += objViewers[0](project=project)._visualize(output) or [] if not views: views = [MessageView("No viewers found for object type: %s" % obj.getClassName())] urls = [viewToUrl(request, view) for view in views] else: viewerClass = viewers[0] # Lets assume if there is a viewer for the protocol # it will be a ProtocolViewer with a Form if issubclass(viewerClass, ProtocolViewer): viewer = viewerClass(project=project, protocol=obj) urls = [viewerForm(project, obj, viewer)] else: viewer = viewerClass(project=project) views = viewer._visualize(obj) urls = [viewToUrl(request, v) for v in views] else: views = [MessageView("Object not found to visualize")] urls = [viewToUrl(request, view) for view in views] jsonStr = json.dumps(urls, ensure_ascii=False) return HttpResponse(jsonStr, mimetype='application/javascript')