def show_data_at_index(self, index): itemData = self.__browseDataBut.itemData(index) if not itemData: return data, proj = itemData # NO_SPACE_CONTENT_TRACKING # content = proj.get_data_property(data, "spaceContent") content = self.__widgetMap.get(data) if not content: if not self.__restrictedToApplet: appFac = DataEditorSelector.mime_type_handler([data.mimetype]) content = appFac._create_space_content_0(data) else: content = self.__applet._create_space_content_0(data) self.__widgetMap[data]=content if content is None: print "Applet", self.name, "returned None content" widget = content.widget self.__projToWidgets.setdefault( proj, set() ).add(widget) self.__menubar.clear() for menu in content.menus: self.__menubar.addMenu(menu) if not self.__stack.indexOf(widget)>-1: self.__stack.addWidget(widget) self.__stack.setCurrentWidget(widget)
def on_type_selected(checked): data = dataFac._new_0() if restToApp: content = applet._create_space_content_0(data) else: appFac = DataEditorSelector.mime_type_handler([data.mimetype]) content = appFac._create_space_content_0(data) appletspace.show_data(data)
def __onLayoutChosen(self, index): """Called when a user chooses a layout. Fetches the corresponding layout from the registered applications and installs a new splitter in the central window.""" proj = self.__projMan.get_active_project() layoutName = str(self._layoutMode.itemText(index)) if layoutName is None or layoutName == "": return data = self._layoutMode.itemData(index)#.toPyObject() if data and isinstance(data, CustomSplittable): index = self.__centralStack.indexOf(data) if index == -1: self.__centralStack.addWidget(data) self.__centralStack.setCurrentWidget(data) else: # layoutNames encodes the application # name and the layout name: # they are seperated by a period. layout = LayoutManager().get(layoutName) if not layout: return # -- FILL THE LAYOUT WITH WIDGETS DESCRIBED BY THE APPLET MAP -- # create new splittable and retreive objects from previous newSplit, taken = self.__new_splittable(layout.skeleton) contentmap = layout.contentmap afm = AppletFactoryManager() gdm = GlobalDataManager() for paneId in newSplit.leaves(): contentDesc = contentmap.get(paneId) if not contentDesc: space = AppletSpace(proj=proj) else: resName, resType = contentDesc if resType == "g": dataName = resName data = gdm.get_data_by_name(dataName) appFac = DataEditorSelector.mime_type_handler([data.mimetype], applet=True) elif resType == "a": appletName = resName appFac = afm.get(appletName) if appFac is None: self.logger.error("__onLayoutChosen has None factory for "+ resName) continue try: space = appFac(proj) if resType == "g": space.show_data(data) except Exception, e: self.logger.error("__onLayoutChosen cannot display "+ \ resName+":"+\ e.message) traceback.print_exc() continue if space: self.__setSpaceAt(newSplit, paneId, space) self.__centralStack.addWidget(newSplit) self.__centralStack.setCurrentWidget(newSplit) self._layoutMode.setItemData(index, to_qvariant(newSplit))
def __on_splitter_pane_drop(self, splittable, paneId, event): mimeData = event.mimeData() if not self.__validate_mimedata(mimeData): return proj = self.__projMan.get_active_project() app = None data = None content = None space = None if mimeData.hasUrls(): formats = mimeData.formats() url = str(mimeData.urls()[0]) dt = DataEditorSelector.mime_type_handler(formats, applet=False) if not dt: return parsedUrl = urlparse.urlparse(url) data = dt._open_url_0(parsedUrl) if not data: return app = DataEditorSelector.mime_type_handler([data.mimetype], applet=True) if not app: return elif mimeData.hasFormat(ProjectManager.mimeformat): print "projectmanager drop" dataIdBytes = mimeData.data(ProjectManager.mimeformat) if dataIdBytes: dataId, ok = dataIdBytes.toInt() if ok and proj: data = proj.get_data(dataId) if data: app = DataEditorSelector.mime_type_handler([data.mimetype], applet=True) print "got applet", app.name # NO_SPACE_CONTENT_TRACKING # -- first try to retreive the content associated to this data -- # if proj and data: # content = proj.get_data_property(data, "spaceContent") # -- if content is still none, we can always try to create a new content -- # if content is None and data: # if app: # content = app._create_space_content_0(data) # -- find the space (applet) of the pane or create one if none: space = splittable.getContentAt(paneId) newSpace = False if not space: space = app(proj) newSpace = True elif not space.supports(data): newSpace = True space = app(proj) print "got to space", space, newSpace space.show_data(data) # NO_SPACE_CONTENT_TRACKING # space.add_content(data, content) if newSpace: self.__setSpaceAt(splittable, paneId, space)