Esempio n. 1
0
 def initTabWidget(self, tabWidget: ColorTabWidget, handle: ProjectReader):
     tabManager = TabManager(tabWidget, handle)
     # init qml main page list
     projectMainPage = QQuickWidget(tabWidget)
     projectMainPage.setResizeMode(QQuickWidget.SizeRootObjectToView)
     projectMainPage.setSource(
         QUrl.fromLocalFile('QML/ProjectMainPage.qml'))
     projectMainPage.setMinimumWidth(550)
     projectMainPage.setMinimumHeight(250)
     projectMainPage.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
     obj_projectMainPage = projectMainPage.rootObject()
     # send main page init dict
     obj_projectMainPage.onInitMainPageItems(
         self.getProjectDetail(tabManager))
     obj_projectMainPage.sendData.connect(self.getData_ProjectMainPage)
     tabManager.qmlHandle = obj_projectMainPage
     tabManager.qmlWidget = projectMainPage
     tabWidget.addTab(projectMainPage, 'MainPage:MainPage')
     return tabManager
Esempio n. 2
0
class StartPage(QWidget):
    openPreferences = pyqtSignal()
    newFile = pyqtSignal(str)
    openProject = pyqtSignal(str)
    openFiles = pyqtSignal(list)

    def __init__(self, parent=None):
        super(StartPage, self).__init__(parent)
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        self.view = QQuickWidget()
        self.view.setMinimumWidth(400)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("StartPage.qml"))
        self.root = self.view.rootObject()
        vbox.addWidget(self.view)

        self.load_items()

        self.root.openProject.connect(self._open_project)
        self.root.removeProject.connect(self._on_click_on_delete)
        self.root.markAsFavorite.connect(self._on_click_on_favorite)
        self.root.openPreferences.connect(self.openPreferences.emit)
        self.root.newFile.connect(lambda: self.newFile.emit(
            translations.TR_NEW_DOCUMENT))  #self.test)
        self.root.openFiles.connect(self.checkFiles)

        self.root.set_year(str(datetime.datetime.now().year))

    def test(self, c="-.-"):
        print(c)
        self.newFile.emit(c)

    def checkFiles(self, lst):
        f = QFileInfo()
        newLst = []
        for url in lst:
            _file = url.toLocalFile()
            print("FILE::", url, _file)
            f.setFile(_file)
            if f.suffix() not in ("tar", "exe", "mp3", "mp4", "flv", "zip",
                                  "rar", "iso"):
                newLst.append(_file)

        if newLst:
            self.openFiles.emit(newLst)

    def _open_project(self, path):
        projects_explorer = IDE.get_service('projects_explorer')
        if projects_explorer:
            projects_explorer.open_project_folder(path)

    def _on_click_on_delete(self, path):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        if path in recent_projects:
            del recent_projects[path]
            settings.setValue("recentProjects", recent_projects)

    def _on_click_on_favorite(self, path, value):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        properties = recent_projects[path]
        properties["isFavorite"] = value
        recent_projects[path] = properties
        settings.setValue("recentProjects", recent_projects)

    def load_items(self):
        settings = IDE.data_settings()
        listByFavorites = []
        listNoneFavorites = []
        recent_projects_dict = dict(settings.value('recentProjects', {}))
        #Filter for favorites
        for recent_project_path, content in list(recent_projects_dict.items()):
            if bool(dict(content)["isFavorite"]):
                listByFavorites.append(
                    (recent_project_path, content["lastopen"]))
            else:
                listNoneFavorites.append(
                    (recent_project_path, content["lastopen"]))
        if len(listByFavorites) > 1:
            # sort by date favorites
            listByFavorites = sorted(listByFavorites,
                                     key=lambda date: listByFavorites[1])

        if len(listNoneFavorites) > 1:
            #sort by date last used
            listNoneFavorites = sorted(listNoneFavorites,
                                       key=lambda date: listNoneFavorites[1])

        for recent_project_path in listByFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, True)

        for recent_project_path in listNoneFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, False)
        self.root.forceActiveFocus()
Esempio n. 3
0
class StartPage(QWidget, itab_item.ITabItem):
    openPreferences = pyqtSignal()
    openProject = pyqtSignal(str)
    def __init__(self, parent=None):
        super(StartPage, self).__init__(parent)
        self._id = "Start Page"
        vbox = QVBoxLayout(self)
        self.view = QQuickWidget()
        self.view.setMinimumWidth(400)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        path_qml = QDir.fromNativeSeparators(
            os.path.join(resources.QML_FILES, "StartPage.qml"))
        path_qml = urlunparse(urlparse(path_qml)._replace(scheme='file'))
        self.view.setSource(QUrl(path_qml))
        #self.view.show()
        self.root = self.view.rootObject()
        self.view.setMinimumSize(630, 400)
        vbox.addWidget(self.view)

        self.load_items()

        # self.root.openProject[str].connect(self._open_project)
        # self.root.removeProject[str].connect(self._on_click_on_delete)
        # self.root.markAsFavorite[str, bool].connect(self._on_click_on_favorite)
        # self.root.openPreferences.connect(self.openPreferences.emit)

        self.root.openProject.connect(self._open_project)
        self.root.removeProject.connect(self._on_click_on_delete)
        self.root.markAsFavorite.connect(self._on_click_on_favorite)
        self.root.openPreferences.connect(self.openPreferences.emit)

    def _open_project(self, path):
        self.openProject.emit(path)

    def _on_click_on_delete(self, path):
        settings = QSettings(resources.SETTINGS_PATH, QSettings.IniFormat)
        recent_projects = settings.value("recentProjects")
        if path in recent_projects:
            del recent_projects[path]
            settings.setValue("recentProjects", recent_projects)

    def _on_click_on_favorite(self, path, value):
        settings = QSettings(resources.SETTINGS_PATH, QSettings.IniFormat)
        recent_projects = settings.value("recentProjects")
        properties = recent_projects[path]
        properties["isFavorite"] = value
        recent_projects[path] = properties
        settings.setValue("recentProjects", recent_projects)

    def load_items(self):
        settings = QSettings(resources.SETTINGS_PATH, QSettings.IniFormat)
        listByFavorites = []
        listNoneFavorites = []
        recent_projects_dict = dict(settings.value('recentProjects', {}))
        #Filter for favorites
        for recent_project_path, content in list(recent_projects_dict.items()):
            if bool(dict(content)["isFavorite"]):
                listByFavorites.append((recent_project_path,
                    content["lastopen"]))
            else:
                listNoneFavorites.append((recent_project_path,
                    content["lastopen"]))
        if len(listByFavorites) > 1:
            # sort by date favorites
            listByFavorites = sorted(listByFavorites,
                key=lambda date: listByFavorites[1])

        if len(listNoneFavorites) > 1:
            #sort by date last used
            listNoneFavorites = sorted(listNoneFavorites,
                key=lambda date: listNoneFavorites[1])

        for recent_project_path in listByFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, True)

        for recent_project_path in listNoneFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, False)
class PluginsStore(QDialog):
    processCompleted = pyqtSignal('QObject*')
    def __init__(self, parent=None):
        super(PluginsStore, self).__init__(parent, Qt.Popup)#Qt.Tool
        self.setWindowTitle(translations.TR_MANAGE_PLUGINS)
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        #self.setWindowState(Qt.WindowActive)
        self.view = QQuickWidget()
        self.view.setMinimumWidth(800)
        self.view.setMinimumHeight(600)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("PluginsStore.qml"))
        self.root = self.view.rootObject()
        vbox.addWidget(self.view)
        self._plugins = {}
        self._plugins_inflate = []
        self._plugins_by_tag = collections.defaultdict(list)
        self._plugins_by_author = collections.defaultdict(list)
        self._base_color = QColor("white")
        self._counter = 0
        self._counter_callback = None
        self._inflating_plugins = []
        self._categoryTags = True
        self._search = []
        self.status = None

        # QApplication.instance().focusChanged["QWidget*", "QWidget*"].connect(\
        #     lambda w1, w2, this=self: this.hide() if w1 == this.view else None)

        self.root.loadPluginsGrid.connect(self._load_by_name)
        self.root.close.connect(lambda: print("self.close", self.close()))
        self.root.showPluginDetails[int].connect(self.show_plugin_details)
        self.root.loadTagsGrid.connect(self._load_tags_grid)
        self.root.loadAuthorGrid.connect(self._load_author_grid)
        self.root.search[str].connect(self._load_search_results)
        self.root.loadPluginsForCategory[str].connect(self._load_plugins_for_category)
        self.processCompleted.connect(self._process_complete)

        self.nenv = nenvironment.NenvEggSearcher()
        self.nenv.searchCompleted.connect(self.callback)
        self.status = self.nenv.do_search()

    def _load_by_name(self):
        if self._plugins:
            self.root.showGridPlugins()
            for plugin in list(self._plugins.values()):
                self.root.addPlugin(plugin.identifier, plugin.name,
                                    plugin.summary, plugin.version)

    def _load_plugins_for_category(self, name):
        self.root.showGridPlugins()
        if self._categoryTags:
            for plugin in self._plugins_by_tag[name]:
                self.root.addPlugin(plugin.identifier, plugin.name,
                                    plugin.summary, plugin.version)
        else:
            for plugin in self._plugins_by_author[name]:
                self.root.addPlugin(plugin.identifier, plugin.name,
                                    plugin.summary, plugin.version)

    def callback(self, values):
        self.root.showGridPlugins()
        for i, plugin in enumerate(values):
            plugin.identifier = i + 1
            self.root.addPlugin(plugin.identifier, plugin.name,
                                plugin.summary, plugin.version)
            self._plugins[plugin.identifier] = plugin

    def show_plugin_details(self, identifier):
        plugin = self._plugins[identifier]
        self._counter = 1
        self._counter_callback = self._show_details

        if plugin.shallow:
            plugin.pluginMetadataInflated.connect(self._update_content)
            self._plugins_inflate.append(plugin.inflate())
        else:
            self._update_content(plugin)

    def _load_tags_grid(self):
        self._categoryTags = True
        self._counter = len(self._plugins)
        self.root.updateCategoryCounter(self._counter)
        self._counter_callback = self._show_tags_grid
        self._inflating_plugins = list(self._plugins.values())
        self._loading_function()

    def _load_author_grid(self):
        self._categoryTags = False
        self._counter = len(self._plugins)
        self.root.updateCategoryCounter(self._counter)
        self._counter_callback = self._show_author_grid
        self._inflating_plugins = list(self._plugins.values())
        self._loading_function()

    def _load_search_results(self, search):
        self._search = search.lower().split()
        self._counter = len(self._plugins)
        self.root.updateCategoryCounter(self._counter)
        self._counter_callback = self._show_search_grid
        self._inflating_plugins = list(self._plugins.values())
        self._loading_function()

    def _loading_function(self):
        plugin = self._inflating_plugins.pop()
        if plugin.shallow:
            plugin.pluginMetadataInflated.connect(self._update_content)
            self._plugins_inflate.append(plugin.inflate())
        else:
            self._process_complete(plugin)

    def _process_complete(self, plugin=None):
        self._counter -= 1
        self.root.updateCategoryCounter(self._counter)
        if self._counter == 0:
            self._counter_callback(plugin)
        else:
            self._loading_function()

    def _show_search_grid(self, plugin=None):
        self.root.showGridPlugins()
        for plugin in list(self._plugins.values()):
            keywords = plugin.keywords.lower().split() + [plugin.name.lower()]
            for word in self._search:
                if word in keywords:
                    self.root.addPlugin(plugin.identifier, plugin.name,
                                        plugin.summary, plugin.version)

    def _show_details(self, plugin):
        self.root.displayDetails(plugin.identifier)

    def _show_tags_grid(self, plugin=None):
        tags = sorted(self._plugins_by_tag.keys())
        for tag in tags:
            color = self._get_random_color(self._base_color)
            self.root.addCategory(color.name(), tag)
        self.root.loadingComplete()

    def _show_author_grid(self, plugin=None):
        authors = sorted(self._plugins_by_author.keys())
        for author in authors:
            color = self._get_random_color(self._base_color)
            self.root.addCategory(color.name(), author)
        self.root.loadingComplete()

    def _update_content(self, plugin):
        self.root.updatePlugin(
            plugin.identifier, plugin.author, plugin.author_email,
            plugin.description, plugin.download_url, plugin.home_page,
            plugin.license)
        keywords = plugin.keywords.split()
        for key in keywords:
            plugins = self._plugins_by_tag[key]
            if plugin not in plugins:
                plugins.append(plugin)
                self._plugins_by_tag[key] = plugins
        plugins = self._plugins_by_author[plugin.author]
        if plugin not in plugins:
            plugins.append(plugin)
            self._plugins_by_author[plugin.author] = plugins
        self.processCompleted.emit(plugin)

    def _get_random_color(self, mix=None):
        red = random.randint(0, 256)
        green = random.randint(0, 256)
        blue = random.randint(0, 256)

        # mix the color
        if mix:
            red = (red + mix.red()) / 2
            green = (green + mix.green()) / 2
            blue = (blue + mix.blue()) / 2

        color = QColor(red, green, blue)
        return color
Esempio n. 5
0
class StartPage(QWidget):
    # Signals
    openPreferences = pyqtSignal()
    newFile = pyqtSignal()

    def __init__(self, parent=None):
        super(StartPage, self).__init__(parent)
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        self.view = QQuickWidget()
        self.view.rootContext().setContextProperty("theme",
                                                   resources.QML_COLORS)
        self.view.rootContext().setContextProperty("shortcuts",
                                                   self.get_shortcuts())
        self.view.setMinimumWidth(400)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("StartPage.qml"))
        self.root = self.view.rootObject()
        vbox.addWidget(self.view)

        # Connections
        self.root.onDrop.connect(self.__open_drop_files)
        self.root.openProject.connect(self._open_project)
        self.root.newFile.connect(lambda: self.newFile.emit())
        self.load_items()

    @pyqtSlot('QString')
    def _open_project(self, path):
        projects_explorer = IDE.get_service("projects_explorer")
        projects_explorer.open_project_folder(path)

    def get_shortcuts(self):
        shortcuts = {k: v.toString() for k, v in resources.SHORTCUTS.items()}
        return shortcuts

    def load_items(self):
        # dsettings = IDE.data_settings()
        # recent_projects_dict = dict(dsettings.value('recentProjects', {}))
        # for prj, values in recent_projects_dict.items():
        #    prj_name = values["name"]
        #    last_open = values["lastopen"]
        #    self.root.addProject(prj_name, prj, last_open)
        self.root.forceActiveFocus()
        """
        # Connections
        self.root.openProject['QString'].connect(self._open_project)
        self.root.removeProject['QString'].connect(self._on_click_on_delete)
        self.root.markAsFavorite['QString',
                                 bool].connect(self._on_click_on_favorite)
        self.root.openPreferences.connect(
            lambda: self.openPreferences.emit())
        self.root.newFile.connect(lambda: self.newFile.emit())

    def _open_project(self, path):
        projects_explorer = IDE.get_service('projects_explorer')
        if projects_explorer:
            projects_explorer.open_project_folder(path)

    def _on_click_on_delete(self, path):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        if path in recent_projects:
            del recent_projects[path]
            settings.setValue("recentProjects", recent_projects)

    def _on_click_on_favorite(self, path, value):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        properties = recent_projects[path]
        properties["isFavorite"] = value
        recent_projects[path] = properties
        settings.setValue("recentProjects", recent_projects)

    def load_items(self):
        settings = IDE.data_settings()
        listByFavorites = []
        listNoneFavorites = []
        recent_projects_dict = dict(settings.value('recentProjects', {}))
        # Filter for favorites
        for recent_project_path, content in list(recent_projects_dict.items()):
            if bool(dict(content)["isFavorite"]):
                listByFavorites.append((recent_project_path,
                                        content["lastopen"]))
            else:
                listNoneFavorites.append((recent_project_path,
                                          content["lastopen"]))
        if len(listByFavorites) > 1:
            # sort by date favorites
            listByFavorites = sorted(listByFavorites,
                                     key=lambda date: listByFavorites[1])

        if len(listNoneFavorites) > 1:
            # sort by date last used
            listNoneFavorites = sorted(listNoneFavorites,
                                       key=lambda date: listNoneFavorites[1])

        for recent_project_path in listByFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, True)

        for recent_project_path in listNoneFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, False)
        self.root.forceActiveFocus()
    """

    def __open_drop_files(self, files: str):
        """Open dragged files to Start Page"""
        files = files.split(',')  # FIXME: it's ok?
        main_container = IDE.get_service("main_container")
        for f in files:
            main_container.open_file(QUrl(f).toLocalFile())
Esempio n. 6
0
class StartPage(QWidget):
    openPreferences = pyqtSignal()
    newFile = pyqtSignal(str)
    openProject = pyqtSignal(str)
    openFiles = pyqtSignal(list)
    def __init__(self, parent=None):
        super(StartPage, self).__init__(parent)
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        self.view = QQuickWidget()
        self.view.setMinimumWidth(400)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("StartPage.qml"))
        self.root = self.view.rootObject()
        vbox.addWidget(self.view)

        self.load_items()

        self.root.openProject.connect(self._open_project)
        self.root.removeProject.connect(self._on_click_on_delete)
        self.root.markAsFavorite.connect(self._on_click_on_favorite)
        self.root.openPreferences.connect(self.openPreferences.emit)
        self.root.newFile.connect(lambda: self.newFile.emit(translations.TR_NEW_DOCUMENT))#self.test)
        self.root.openFiles.connect(self.checkFiles)

        self.root.set_year(str(datetime.datetime.now().year))

    def test(self, c= "-.-"):
        print(c)
        self.newFile.emit(c)

    def checkFiles(self, lst):
        f = QFileInfo()
        newLst = []
        for url in lst:
            _file = url.toLocalFile()
            print("FILE::", url, _file)
            f.setFile(_file)
            if f.suffix() not in ("tar", "exe", "mp3", "mp4", "flv", "zip", "rar", "iso"):
                newLst.append(_file)

        if newLst:
            self.openFiles.emit(newLst)



    def _open_project(self, path):
        projects_explorer = IDE.get_service('projects_explorer')
        if projects_explorer:
            projects_explorer.open_project_folder(path)

    def _on_click_on_delete(self, path):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        if path in recent_projects:
            del recent_projects[path]
            settings.setValue("recentProjects", recent_projects)

    def _on_click_on_favorite(self, path, value):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        properties = recent_projects[path]
        properties["isFavorite"] = value
        recent_projects[path] = properties
        settings.setValue("recentProjects", recent_projects)

    def load_items(self):
        settings = IDE.data_settings()
        listByFavorites = []
        listNoneFavorites = []
        recent_projects_dict = dict(settings.value('recentProjects', {}))
        #Filter for favorites
        for recent_project_path, content in list(recent_projects_dict.items()):
            if bool(dict(content)["isFavorite"]):
                listByFavorites.append((recent_project_path,
                    content["lastopen"]))
            else:
                listNoneFavorites.append((recent_project_path,
                    content["lastopen"]))
        if len(listByFavorites) > 1:
            # sort by date favorites
            listByFavorites = sorted(listByFavorites,
                key=lambda date: listByFavorites[1])

        if len(listNoneFavorites) > 1:
            #sort by date last used
            listNoneFavorites = sorted(listNoneFavorites,
                key=lambda date: listNoneFavorites[1])

        for recent_project_path in listByFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, True)

        for recent_project_path in listNoneFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, False)
        self.root.forceActiveFocus()
class PluginsStore(QDialog):
    processCompleted = pyqtSignal('QObject*')

    def __init__(self, parent=None):
        super(PluginsStore, self).__init__(parent, Qt.Popup)  #Qt.Tool
        self.setWindowTitle(translations.TR_MANAGE_PLUGINS)
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        #self.setWindowState(Qt.WindowActive)
        self.view = QQuickWidget()
        self.view.setMinimumWidth(800)
        self.view.setMinimumHeight(600)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("PluginsStore.qml"))
        self.root = self.view.rootObject()
        vbox.addWidget(self.view)
        self._plugins = {}
        self._plugins_inflate = []
        self._plugins_by_tag = collections.defaultdict(list)
        self._plugins_by_author = collections.defaultdict(list)
        self._base_color = QColor("white")
        self._counter = 0
        self._counter_callback = None
        self._inflating_plugins = []
        self._categoryTags = True
        self._search = []
        self.status = None

        # QApplication.instance().focusChanged["QWidget*", "QWidget*"].connect(\
        #     lambda w1, w2, this=self: this.hide() if w1 == this.view else None)

        self.root.loadPluginsGrid.connect(self._load_by_name)
        self.root.close.connect(lambda: print("self.close", self.close()))
        self.root.showPluginDetails[int].connect(self.show_plugin_details)
        self.root.loadTagsGrid.connect(self._load_tags_grid)
        self.root.loadAuthorGrid.connect(self._load_author_grid)
        self.root.search[str].connect(self._load_search_results)
        self.root.loadPluginsForCategory[str].connect(
            self._load_plugins_for_category)
        self.processCompleted.connect(self._process_complete)

        self.nenv = nenvironment.NenvEggSearcher()
        self.nenv.searchCompleted.connect(self.callback)
        self.status = self.nenv.do_search()

    def _load_by_name(self):
        if self._plugins:
            self.root.showGridPlugins()
            for plugin in list(self._plugins.values()):
                self.root.addPlugin(plugin.identifier, plugin.name,
                                    plugin.summary, plugin.version)

    def _load_plugins_for_category(self, name):
        self.root.showGridPlugins()
        if self._categoryTags:
            for plugin in self._plugins_by_tag[name]:
                self.root.addPlugin(plugin.identifier, plugin.name,
                                    plugin.summary, plugin.version)
        else:
            for plugin in self._plugins_by_author[name]:
                self.root.addPlugin(plugin.identifier, plugin.name,
                                    plugin.summary, plugin.version)

    def callback(self, values):
        self.root.showGridPlugins()
        for i, plugin in enumerate(values):
            plugin.identifier = i + 1
            self.root.addPlugin(plugin.identifier, plugin.name, plugin.summary,
                                plugin.version)
            self._plugins[plugin.identifier] = plugin

    def show_plugin_details(self, identifier):
        plugin = self._plugins[identifier]
        self._counter = 1
        self._counter_callback = self._show_details

        if plugin.shallow:
            plugin.pluginMetadataInflated.connect(self._update_content)
            self._plugins_inflate.append(plugin.inflate())
        else:
            self._update_content(plugin)

    def _load_tags_grid(self):
        self._categoryTags = True
        self._counter = len(self._plugins)
        self.root.updateCategoryCounter(self._counter)
        self._counter_callback = self._show_tags_grid
        self._inflating_plugins = list(self._plugins.values())
        self._loading_function()

    def _load_author_grid(self):
        self._categoryTags = False
        self._counter = len(self._plugins)
        self.root.updateCategoryCounter(self._counter)
        self._counter_callback = self._show_author_grid
        self._inflating_plugins = list(self._plugins.values())
        self._loading_function()

    def _load_search_results(self, search):
        self._search = search.lower().split()
        self._counter = len(self._plugins)
        self.root.updateCategoryCounter(self._counter)
        self._counter_callback = self._show_search_grid
        self._inflating_plugins = list(self._plugins.values())
        self._loading_function()

    def _loading_function(self):
        plugin = self._inflating_plugins.pop()
        if plugin.shallow:
            plugin.pluginMetadataInflated.connect(self._update_content)
            self._plugins_inflate.append(plugin.inflate())
        else:
            self._process_complete(plugin)

    def _process_complete(self, plugin=None):
        self._counter -= 1
        self.root.updateCategoryCounter(self._counter)
        if self._counter == 0:
            self._counter_callback(plugin)
        else:
            self._loading_function()

    def _show_search_grid(self, plugin=None):
        self.root.showGridPlugins()
        for plugin in list(self._plugins.values()):
            keywords = plugin.keywords.lower().split() + [plugin.name.lower()]
            for word in self._search:
                if word in keywords:
                    self.root.addPlugin(plugin.identifier, plugin.name,
                                        plugin.summary, plugin.version)

    def _show_details(self, plugin):
        self.root.displayDetails(plugin.identifier)

    def _show_tags_grid(self, plugin=None):
        tags = sorted(self._plugins_by_tag.keys())
        for tag in tags:
            color = self._get_random_color(self._base_color)
            self.root.addCategory(color.name(), tag)
        self.root.loadingComplete()

    def _show_author_grid(self, plugin=None):
        authors = sorted(self._plugins_by_author.keys())
        for author in authors:
            color = self._get_random_color(self._base_color)
            self.root.addCategory(color.name(), author)
        self.root.loadingComplete()

    def _update_content(self, plugin):
        self.root.updatePlugin(plugin.identifier, plugin.author,
                               plugin.author_email, plugin.description,
                               plugin.download_url, plugin.home_page,
                               plugin.license)
        keywords = plugin.keywords.split()
        for key in keywords:
            plugins = self._plugins_by_tag[key]
            if plugin not in plugins:
                plugins.append(plugin)
                self._plugins_by_tag[key] = plugins
        plugins = self._plugins_by_author[plugin.author]
        if plugin not in plugins:
            plugins.append(plugin)
            self._plugins_by_author[plugin.author] = plugins
        self.processCompleted.emit(plugin)

    def _get_random_color(self, mix=None):
        red = random.randint(0, 256)
        green = random.randint(0, 256)
        blue = random.randint(0, 256)

        # mix the color
        if mix:
            red = (red + mix.red()) / 2
            green = (green + mix.green()) / 2
            blue = (blue + mix.blue()) / 2

        color = QColor(red, green, blue)
        return color
Esempio n. 8
0
class StartPage(QWidget):
    # Signals
    openPreferences = pyqtSignal()
    newFile = pyqtSignal()

    def __init__(self, parent=None):
        super(StartPage, self).__init__(parent)
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        self.view = QQuickWidget()
        self.view.rootContext().setContextProperty(
            "theme", resources.QML_COLORS)
        self.view.rootContext().setContextProperty(
            "shortcuts", self.get_shortcuts())
        self.view.setMinimumWidth(400)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("StartPage.qml"))
        self.root = self.view.rootObject()
        vbox.addWidget(self.view)

        # Connections
        self.root.onDrop.connect(self.__open_drop_files)
        self.root.openProject.connect(self._open_project)
        self.root.newFile.connect(lambda: self.newFile.emit())
        self.load_items()

    @pyqtSlot('QString')
    def _open_project(self, path):
        projects_explorer = IDE.get_service("projects_explorer")
        projects_explorer.open_project_folder(path)

    def get_shortcuts(self):
        shortcuts = {k: v.toString() for k, v in resources.SHORTCUTS.items()}
        return shortcuts

    def load_items(self):
        # dsettings = IDE.data_settings()
        # recent_projects_dict = dict(dsettings.value('recentProjects', {}))
        # for prj, values in recent_projects_dict.items():
        #    prj_name = values["name"]
        #    last_open = values["lastopen"]
        #    self.root.addProject(prj_name, prj, last_open)
        self.root.forceActiveFocus()
        """
        # Connections
        self.root.openProject['QString'].connect(self._open_project)
        self.root.removeProject['QString'].connect(self._on_click_on_delete)
        self.root.markAsFavorite['QString',
                                 bool].connect(self._on_click_on_favorite)
        self.root.openPreferences.connect(
            lambda: self.openPreferences.emit())
        self.root.newFile.connect(lambda: self.newFile.emit())

    def _open_project(self, path):
        projects_explorer = IDE.get_service('projects_explorer')
        if projects_explorer:
            projects_explorer.open_project_folder(path)

    def _on_click_on_delete(self, path):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        if path in recent_projects:
            del recent_projects[path]
            settings.setValue("recentProjects", recent_projects)

    def _on_click_on_favorite(self, path, value):
        settings = IDE.data_settings()
        recent_projects = settings.value("recentProjects")
        properties = recent_projects[path]
        properties["isFavorite"] = value
        recent_projects[path] = properties
        settings.setValue("recentProjects", recent_projects)

    def load_items(self):
        settings = IDE.data_settings()
        listByFavorites = []
        listNoneFavorites = []
        recent_projects_dict = dict(settings.value('recentProjects', {}))
        # Filter for favorites
        for recent_project_path, content in list(recent_projects_dict.items()):
            if bool(dict(content)["isFavorite"]):
                listByFavorites.append((recent_project_path,
                                        content["lastopen"]))
            else:
                listNoneFavorites.append((recent_project_path,
                                          content["lastopen"]))
        if len(listByFavorites) > 1:
            # sort by date favorites
            listByFavorites = sorted(listByFavorites,
                                     key=lambda date: listByFavorites[1])

        if len(listNoneFavorites) > 1:
            # sort by date last used
            listNoneFavorites = sorted(listNoneFavorites,
                                       key=lambda date: listNoneFavorites[1])

        for recent_project_path in listByFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, True)

        for recent_project_path in listNoneFavorites:
            path = recent_project_path[0]
            name = recent_projects_dict[path]['name']
            self.root.add_project(name, path, False)
        self.root.forceActiveFocus()
    """

    def __open_drop_files(self, files: str):

        """Open dragged files to Start Page"""
        files = files.split(',')  # FIXME: it's ok?
        main_container = IDE.get_service("main_container")
        for f in files:
            main_container.open_file(QUrl(f).toLocalFile())