示例#1
0
    def gather_items(self):
        from openalea.secondnature.applets import AppletFactoryManager
        APM = AppletFactoryManager()
        appletFactories = APM.gather_items()

        self.items.clear()
        for appFac in appletFactories.itervalues():
            dataTypes = appFac.get_data_types()
            self.items.update( (dt.name, dt) for dt in dataTypes )
        self.item_list_changed.emit(self, self.items.copy())
    def init(cls):
        from openalea.secondnature.layouts    import LayoutManager
        from openalea.secondnature.applets    import AppletFactoryManager
        from openalea.secondnature.data       import DataFactoryManager

        lm = LayoutManager()
        am = AppletFactoryManager()
        dm = DataFactoryManager()

        lm.init_sources()
        am.init_sources()
        dm.init_sources()

        lm.gather_items(refresh=True)
        am.gather_items(refresh=True)
        dm.gather_items(refresh=True)
示例#3
0
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.setMinimumSize(500, 400)
        self.showMaximized()
        self.setWindowTitle("Second Nature")
        self.setWindowFlags(QtCore.Qt.Window)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.logger = sn_logger
        self.__applets = []

        self.__extInitialised = False

        # -- main menu bar --
        self._mainMenuBar = QtGui.QMenuBar(self)
        self._projectMenu = self._mainMenuBar.addMenu("&Project")
        self.setMenuBar(self._mainMenuBar)

        # -- project menu --
        qpm = QActiveProjectManager()
        self._projectMenu.addAction(qpm.get_action_new())
        self._projectMenu.addAction(qpm.get_action_open())
        self._projectMenu.addAction(qpm.get_action_save())
        self._projectMenu.addAction(qpm.get_action_close())

        # -- a default central widget--
        self.__centralStack = QtGui.QStackedWidget(self)

        # -- status bar --
        self._statusBar  = QtGui.QStatusBar(self)
        self._layoutMode = QtGui.QComboBox(self)
        self._statusBar.addPermanentWidget(self._layoutMode)
        self._layoutMode.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
        self.__currentLayout = None
        self._statusBar.setStyleSheet("QStatusBar{background-color: " +\
                                      "qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, "+\
                                      "stop:0 rgba(135,135,135,255), " +\
                                      "stop:0.1 rgba(175,175,175,255), " +\
                                      "stop:1 rgba(200, 200, 200, 255));}")


        # -- add all those guys to the main window (self) --
        self.setMenuBar(self._mainMenuBar)
        self.setStatusBar(self._statusBar)
        self.setCentralWidget(self.__centralStack)

        self.__projMan = ProjectManager()
        if not self.__projMan.has_active_project():
            self.__projMan.new_active_project("New Project")

        # -- connections --
        self.__projMan.active_project_changed.connect(self.__on_active_project_set)
        AppletFactoryManager().applet_created.connect(self.add_applet)
        LayoutManager().item_list_changed.connect(self.__onLayoutListChanged)
        self._layoutMode.activated[int].connect(self.__onLayoutChosen)
        self._layoutMode.currentIndexChanged[int].connect(self.__onLayoutChosen)
示例#4
0
    def __onPaneMenuRequest(self, splittable, paneId, pos):
        proj = self.__projMan.get_active_project()

        pos = splittable.mapToGlobal(pos)
        menu = QtGui.QMenu(splittable)
        menu.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        action = menu.addAction("Empty")
        menu.addSeparator()
        action.triggered.connect(self.__make_clear_pane_handler(splittable, paneId))

        applets    = list(AppletFactoryManager().gather_items().itervalues())
        applets.sort(cmp = lambda x,y:cmp(x.name, y.name))
        for app in applets:
            action = menu.addAction(app.icon, app.name)
            action.setIconVisibleInMenu(True)
            func = self.__make_new_applet_pane_handler(splittable, proj, paneId, app)
            action.triggered.connect(func)
        menu.popup(pos)
    def init(cls):
        from openalea.secondnature.layouts import LayoutManager
        from openalea.secondnature.applets import AppletFactoryManager
        from openalea.secondnature.data import DataFactoryManager

        lm = LayoutManager()
        am = AppletFactoryManager()
        dm = DataFactoryManager()

        lm.init_sources()
        am.init_sources()
        dm.init_sources()

        lm.gather_items(refresh=True)
        am.gather_items(refresh=True)
        dm.gather_items(refresh=True)
    def mime_type_handler(formats, applet=True):
        from openalea.secondnature.applets import AppletFactoryManager
        from openalea.secondnature.data    import DataFactoryManager

        formats = map(str, formats)
        if applet:
            handlers = AppletFactoryManager().get_handlers_for_mimedata(formats)
        else:
            handlers = DataFactoryManager().get_handlers_for_mimedata(formats)

        nbHandlers = len(handlers)
        if nbHandlers == 0:
            return
        elif nbHandlers == 1:
            fac = handlers[0]
        elif nbHandlers > 1:
            selector = DataEditorSelector( [h.name for h in handlers] )
            if selector.exec_() == QtGui.QDialog.Rejected:
                return
            else:
                facName = selector.get_selected()
                fac = filter(lambda x: x.name == facName, handlers)[0]
        return fac
示例#7
0
    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))