Ejemplo n.º 1
0
    def _update_available_project_menu(self):
        """
        Discover all projects and generate an action for each one.
        Then connect this action to _on_open_project_triggered
        """
        self.menu_available_projects.clear()
        self.action_available_project.clear()

        all_projects = {}  # dict parent dir -> list of Project objects
        for project in projects():
            all_projects.setdefault(project.projectdir, []).append(project)

        home = path(get_default_home_dir())
        for projectdir, _projects in all_projects.iteritems():
            relpath = home.relpathto(projectdir)
            label = unicode(relpath)
            menu = QtGui.QMenu(label, self.menu_available_projects)
            for project in sorted(_projects, key=lambda project: project.label):
                icon = obj_icon(project, default=DEFAULT_PROJECT_ICON, paths=[project.path])
                action = QtGui.QAction(icon, project.label, self.menu_available_projects)
                action.triggered.connect(self._on_open_project_triggered)
                menu.addAction(action)
                self.action_available_project[action] = project
            self.menu_available_projects.addMenu(menu)
        return self.menu_available_projects
Ejemplo n.º 2
0
    def _update_available_project_menu(self):
        """
        Discover all projects and generate an action for each one.
        Then connect this action to _on_open_project_triggered
        """
        self.menu_available_projects.clear()
        self.action_available_project.clear()

        all_projects = {}  # dict parent dir -> list of Project objects
        for project in projects():
            all_projects.setdefault(project.projectdir, []).append(project)

        home = path(get_default_home_dir())
        for projectdir, _projects in all_projects.iteritems():
            relpath = home.relpathto(projectdir)
            label = unicode(relpath)
            menu = QtGui.QMenu(label, self.menu_available_projects)
            for project in sorted(_projects,
                                  key=lambda project: project.label):
                icon = obj_icon(project,
                                default=DEFAULT_PROJECT_ICON,
                                paths=[project.path])
                action = QtGui.QAction(icon, project.label,
                                       self.menu_available_projects)
                action.triggered.connect(self._on_open_project_triggered)
                menu.addAction(action)
                self.action_available_project[action] = project
            self.menu_available_projects.addMenu(menu)
        return self.menu_available_projects
Ejemplo n.º 3
0
    def __init__(self):
        QtGui.QLineEdit.__init__(self, "I am a test applet")
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        icon = obj_icon(None)
        self.action_1 = QtGui.QAction(icon, 'A1 [widget.actions]', self)
        self.addAction(self.action_1)

        self.action_global_1 = QtGui.QAction(icon, 'Big 1 [widget.global_tb_actions]', self)
        self.action_global_2 = QtGui.QAction(icon, 'Small 1 [widget.global_tb_actions]', self)
        self.action_global_3 = QtGui.QAction(icon, 'Small 2 [widget.global_tb_actions]', self)

        self.action_context_1 = QtGui.QAction(icon, 'Big A [widget.tb_actions]', self)
        self.action_context_2 = QtGui.QAction(icon, 'Small A [widget.tb_actions]', self)
        self.action_context_3 = QtGui.QAction(icon, 'Small B [widget.tb_actions]', self)

        self.menu_tb = QtGui.QMenu("Toolbutton", self)
        self.menu_tb.addActions([self.action_context_1, self.action_context_2])

        self.action_search = QtGui.QAction(icon, 'search', self)

        self.menu_edit = QtGui.QMenu("Edit", self)
        self.menu_edit.addAction(self.action_search)

        self.action_menu_1 = QtGui.QAction(icon, 'A1 [widget.menu_actions]', self)

        self.toolbar_1 = QtGui.QToolBar("Toolbar 1")
        self.toolbar_1.addAction(self.action_context_1)
        self.toolbar_2 = QtGui.QToolBar("Toolbar 2")
        self.toolbar_2.addAction(self.action_context_2)
Ejemplo n.º 4
0
    def __init__(self):
        QtGui.QLineEdit.__init__(self, "I am a test applet")
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        icon = obj_icon(None)
        self.action_1 = QtGui.QAction(icon, "A1 [widget.actions]", self)
        self.addAction(self.action_1)

        self.action_global_1 = QtGui.QAction(icon, "Big 1 [widget.global_tb_actions]", self)
        self.action_global_2 = QtGui.QAction(icon, "Small 1 [widget.global_tb_actions]", self)
        self.action_global_3 = QtGui.QAction(icon, "Small 2 [widget.global_tb_actions]", self)

        self.action_context_1 = QtGui.QAction(icon, "Big A [widget.tb_actions]", self)
        self.action_context_2 = QtGui.QAction(icon, "Small A [widget.tb_actions]", self)
        self.action_context_3 = QtGui.QAction(icon, "Small B [widget.tb_actions]", self)

        self.menu_tb = QtGui.QMenu("Toolbutton", self)
        self.menu_tb.addActions([self.action_context_1, self.action_context_2])

        self.action_search = QtGui.QAction(icon, "search", self)

        self.menu_edit = QtGui.QMenu("Edit", self)
        self.menu_edit.addAction(self.action_search)

        self.action_menu_1 = QtGui.QAction(icon, "A1 [widget.menu_actions]", self)

        self.toolbar_1 = QtGui.QToolBar("Toolbar 1")
        self.toolbar_1.addAction(self.action_context_1)
        self.toolbar_2 = QtGui.QToolBar("Toolbar 2")
        self.toolbar_2.addAction(self.action_context_2)
Ejemplo n.º 5
0
    def refresh(self):
        self.clear()
        project = self._project
        if project is None:
            return

        icons = dict(
            project=QtGui.QIcon(":/images/resources/openalea_icon2.png"),
            src=QtGui.QIcon(":/images/resources/filenew.png"),
            control=QtGui.QIcon(":/images/resources/node.png"),
            world=QtGui.QIcon(":/images/resources/plant.png"),
            startup=QtGui.QIcon(":/images/resources/editredo.png"),
            data=qicon("Crystal_Clear_filesystem_folder_grey_open.png"),
            doc=QtGui.QIcon(":/images/resources/book.png"),
            cache=QtGui.QIcon(":/images/resources/editcopy.png"),
            model=qicon("icons/Crystal_Clear_app_kservices.png"),
            lib=QtGui.QIcon(":/images/resources/codefile-red.png"),
        )

        name = project.name
        parentItem = self.invisibleRootItem()
        item = QtGui.QStandardItem(project.label)
        self._root_item = name

        item.setIcon(obj_icon(project, default=icons['project'], paths=[project.path]))
        parentItem.appendRow(item)

        for category in project.categories:
            item2 = QtGui.QStandardItem(category)
            item.appendRow(item2)

            if category in icons:
                item2.setIcon(icons[category])

            if not hasattr(project, category):
                continue

            data_dict = getattr(project, category)

            names = data_dict.keys()
            for name in sorted(names):
                data = data_dict[name]
                item3 = QtGui.QStandardItem(name)
                item3.setIcon(obj_icon(data, packages=[openalea.oalab]))
                item3.setData((category, data))
                item2.appendRow(item3)
Ejemplo n.º 6
0
    def __init__(self, manager, group='default', parent=None, style=None):
        """
        items: function returning items for a given group
        """
        self.manager = manager
        if style is None:
            style = WelcomePage.STYLE_MEDIUM
        WelcomePage.__init__(self, parent=parent, style=style)

        self._actions = {}
        items = sorted(self.manager.items(group), key=lambda item: item.label)
        self._sorted_actions = []
        for item in items:
            action = QtGui.QAction(obj_icon(item), item.label, self)
            action.triggered.connect(self._on_action_triggered)
            self._actions[action] = item
            self._sorted_actions.append(action)

        self.set_actions(self._sorted_actions)
Ejemplo n.º 7
0
    def _redraw_tab(self, idx):
        """
        """
        if idx not in self._name:
            return

        name = self._name[idx]
        pl = plugin(name, 'oalab.applet')
        applet = self._applets[idx][name]
        # self.setTabText(idx, _plugin_class.label)
        if self.tabPosition() == QtGui.QTabWidget.East:
            rotation = -90
        elif tabposition_int(self.tabPosition()) == 2:
            rotation = 90
        else:
            rotation = 0

        self.setTabIcon(idx, obj_icon([pl, applet], rotation=rotation))
        self.setTabToolTip(idx, pl.label)
        self.widget(idx).set_edit_mode(self._edit_mode)
Ejemplo n.º 8
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        self.setContentsMargins(0, 0, 0, 0)
        self._layout = QtGui.QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)

        self._cb_applets = QtGui.QComboBox()
        self._applet_label = []  # list of label sorted by name
        self._applet_plugins = {}  # label -> plugin class

        self._cb_applets.addItem('Select applet')
        for plugin in plugins('oalab.applet'):
            self._applet_label.append(plugin.label)
            self._applet_plugins[plugin.label] = plugin
        self._applet_label.sort()

        for label in self._applet_label:
            plugin_class = self._applet_plugins[label]
            self._cb_applets.addItem(obj_icon(plugin_class), label)

        self._layout.addWidget(self._cb_applets)

        self.setCurrentApplet('')
        self._cb_applets.currentIndexChanged.connect(self._on_current_applet_changed)
Ejemplo n.º 9
0
    def refresh(self):

        self.clear()
        self._group = {}
        items = self._items
        if items is None:
            return

        # Manage groupby info
        gby_func = self._groupby.get('function', None)
        gby_criteria = self._groupby.get('criteria', None)
        gby_label = self._groupby.get('label', None)

        if gby_func:
            f_gby_key = gby_func
        elif gby_criteria:
            def f_gby_key(item):
                if hasattr(item, gby_criteria):
                    return getattr(item, gby_criteria)
                else:
                    return self.undefined_group_label
        else:
            f_gby_key = lambda item: self.undefined_group_label

        if gby_label:
            f_gby_label = gby_label
        else:
            f_gby_label = lambda criterion: str(criterion)

        _items = []

        for item in items:
            key = f_gby_key(item)
            if isinstance(key, (list, set, tuple)):
                if not key:
                    key = [self.undefined_group_label]
                for k in key:
                    if not k:
                        k = self.undefined_group_label
                    _items.append((k, item))
            else:
                if not key:
                    key = self.undefined_group_label
                _items.append((key, item))
        _items.sort()

        parent_item = self.invisibleRootItem()

        groups = groupby(_items, lambda item: item[0])

        for key, items in groups:
            try:
                label = f_gby_label(key)
            except:
                label = str(key)
            repository_item = QtGui.QStandardItem(label)
            repository_item.setIcon(qicon(self.default_group_icon))
            parent_item.appendRow(repository_item)
            self._group[repository_item] = []

            for _, item in sorted(items, key=lambda args: args[1].label):
                qitem = QtGui.QStandardItem(item.label)
                qitem.item = item
                if hasattr(item, 'path'):
                    paths = [item.path, item.path.parent]
                else:
                    paths = []
                qitem.setIcon(obj_icon(item, default=self.default_item_icon, paths=paths))
                repository_item.appendRow(qitem)
                self._group[repository_item].append(qitem)

        self.more_item = QtGui.QStandardItem("Add more items")
        self.more_item.setIcon(qicon("icons/Crystal_Clear_action_edit_add.png"))
        parent_item.appendRow(self.more_item)
Ejemplo n.º 10
0
    def refresh(self):

        self.clear()
        self._group = {}
        items = self._items
        if items is None:
            return

        # Manage groupby info
        gby_func = self._groupby.get('function', None)
        gby_criteria = self._groupby.get('criteria', None)
        gby_label = self._groupby.get('label', None)

        if gby_func:
            f_gby_key = gby_func
        elif gby_criteria:

            def f_gby_key(item):
                if hasattr(item, gby_criteria):
                    return getattr(item, gby_criteria)
                else:
                    return self.undefined_group_label
        else:
            f_gby_key = lambda item: self.undefined_group_label

        if gby_label:
            f_gby_label = gby_label
        else:
            f_gby_label = lambda criterion: str(criterion)

        _items = []

        for item in items:
            key = f_gby_key(item)
            if isinstance(key, (list, set, tuple)):
                if not key:
                    key = [self.undefined_group_label]
                for k in key:
                    if not k:
                        k = self.undefined_group_label
                    _items.append((k, item))
            else:
                if not key:
                    key = self.undefined_group_label
                _items.append((key, item))
        _items.sort()

        parent_item = self.invisibleRootItem()

        groups = groupby(_items, lambda item: item[0])

        for key, items in groups:
            try:
                label = f_gby_label(key)
            except:
                label = str(key)
            repository_item = QtGui.QStandardItem(label)
            repository_item.setIcon(qicon(self.default_group_icon))
            parent_item.appendRow(repository_item)
            self._group[repository_item] = []

            for _, item in sorted(items, key=lambda args: args[1].label):
                qitem = QtGui.QStandardItem(item.label)
                qitem.item = item
                if hasattr(item, 'path'):
                    paths = [item.path, item.path.parent]
                else:
                    paths = []
                qitem.setIcon(
                    obj_icon(item, default=self.default_item_icon,
                             paths=paths))
                repository_item.appendRow(qitem)
                self._group[repository_item].append(qitem)

        self.more_item = QtGui.QStandardItem("Add more items")
        self.more_item.setIcon(
            qicon("icons/Crystal_Clear_action_edit_add.png"))
        parent_item.appendRow(self.more_item)