Added rough dialog for the PluginBrowser

CURA-3856
This commit is contained in:
Jaime van Kessel 2017-06-22 17:55:45 +02:00
parent d1e1265215
commit 503aa00137
2 changed files with 63 additions and 2 deletions

View File

@ -5,18 +5,21 @@ from UM.i18n import i18nCatalog
from UM.Logger import Logger
from UM.Qt.ListModel import ListModel
from UM.PluginRegistry import PluginRegistry
from UM.Application import Application
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
from PyQt5.QtCore import QUrl, QObject, Qt, pyqtProperty, pyqtSignal
from PyQt5.QtQml import QQmlComponent, QQmlContext
import json
import os
i18n_catalog = i18nCatalog("cura")
class PluginBrowser(QObject, Extension):
def __init__(self, parent = None):
super().__init__()
super().__init__(parent)
self.addMenuItem(i18n_catalog.i18n("Browse plugins"), self.browsePlugins)
self._api_version = 1
self._api_url = "http://software.ultimaker.com/cura/v%s/" % self._api_version
@ -27,18 +30,40 @@ class PluginBrowser(QObject, Extension):
self._plugins_metadata = []
self._plugins_model = None
self._qml_component = None
self._qml_context = None
self._dialog = None
pluginsMetadataChanged = pyqtSignal()
def browsePlugins(self):
self._createNetworkManager()
self.requestPluginList()
#TODO: Show popup with populated plugin data.
if not self._dialog:
self._createDialog()
self._dialog.show()
def requestPluginList(self):
url = QUrl(self._api_url + "plugins")
self._plugin_list_request = QNetworkRequest(url)
self._network_manager.get(self._plugin_list_request)
def _createDialog(self):
Logger.log("d", "PluginBrowser")
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "PluginBrowser.qml"))
self._qml_component = QQmlComponent(Application.getInstance()._engine, path)
# We need access to engine (although technically we can't)
self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._qml_context.setContextProperty("manager", self)
self._dialog = self._qml_component.create(self._qml_context)
if self._dialog is None:
Logger.log("e", "QQmlComponent status %s", self._qml_component.status())
Logger.log("e", "QQmlComponent errorString %s", self._qml_component.errorString())
@pyqtProperty(QObject, notify=pluginsMetadataChanged)
def pluginsModel(self):
if self._plugins_model is None:

View File

@ -0,0 +1,36 @@
import UM 1.1 as UM
import QtQuick 2.2
import QtQuick.Dialogs 1.1
import QtQuick.Window 2.2
import QtQuick.Controls 1.1
UM.Dialog
{
id: base
title: "YAY"
width: 450
height: 150
ListView
{
model: manager.pluginsModel
anchors.fill: parent
delegate: Row
{
width: parent.width
Button
{
text: model.name
}
Button
{
text: model.author
}
Label
{
text: model.short_description
}
}
}
}