Ejemplo n.º 1
0
    def init_gui(self):
        self._cpu_checkbox = QtWidgets.QCheckBox()
        name = self._settings.cpu_color
        css = "QCheckBox:indicator:checked{{background-color:{}}}".format(name)
        self._cpu_checkbox.setStyleSheet(css)
        self._cpu_checkbox.setChecked(True)
        self._cpu_checkbox.stateChanged.connect(self.fake)

        self._ram_checkbox = QtWidgets.QCheckBox()
        name = self._settings.ram_color
        css = "QCheckBox:indicator:checked{{background-color:{}}}".format(name)
        self._ram_checkbox.setStyleSheet(css)
        self._ram_checkbox.setChecked(True)
        self._ram_checkbox.stateChanged.connect(self.fake)

        self._view = QtQuick.QQuickView(self.parent)
        self._view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)
        self._view.rootContext().setContextProperty("snail", self)

        color = QtGui.QColor(self._settings.background_color)
        self._view.setColor(color)

        dir_path = os.path.dirname(os.path.realpath(__file__))
        qml = os.path.join(dir_path, "qml", "lines.qml")
        self._view.setSource(QtCore.QUrl.fromLocalFile(qml))

        self._container = QtWidgets.QWidget.createWindowContainer(self._view)
        self._container.setMinimumHeight(80)
        layout = self._widget.mChartLayout
        if self._settings.display_chart:
            self._displayed = True
            layout.addWidget(self._container)

            self._widget.mGridLayout.addWidget(self._cpu_checkbox, 0, 0)
            self._widget.mGridLayout.addWidget(self._ram_checkbox, 2, 0)
Ejemplo n.º 2
0
def main():
    app = QtWidgets.QApplication(sys.argv)
    view = QtQuick.QQuickView()

    mw = MainWrapper(view)
    view.rootContext().setContextProperty("_mainWrapper", mw)
    view.setSource(QtCore.QUrl("source.qml"))
    view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)

    view.show()
    app.exec_()
Ejemplo n.º 3
0
    def __init__(self):
        super(Gauge, self).__init__()
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)

        self.chart = QtQuick.QQuickView()
        self.chart.setSource(QtCore.QUrl('icons/gauge.qml'))
        self.chart.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)

        container = QtWidgets.QWidget.createWindowContainer(self.chart, self);
        container.setMinimumHeight(150);
        
        layout.addWidget(container)
Ejemplo n.º 4
0
    def __init__(self, argv=None):
        """
        Ctor

        :param argv: Arguments passed to the underlying QGuiApplication
        """

        argv = argv or []

        # QGuiApplication usually takes sys.argv parameters as input so the first
        # argument is ignored
        self._app = QtGui.QGuiApplication([""] + argv)
        self._view = QtQuick.QQuickView()
        self._view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)
Ejemplo n.º 5
0
def main():
    app = QtWidgets.QApplication(sys.argv)
    view = QtQuick.QQuickView()
    view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)

    # Create a declarative view
    view.setSource(QtCore.QUrl("source.qml"))
    # Declare we are using instant coding tool on this view
    qic = QmlInstantCoding(view, verbose=True)
    # Add any source file (.qml and .js by default) in current working directory
    qic.addFilesFromDirectory(os.getcwd())

    view.show()
    app.exec_()
Ejemplo n.º 6
0
    def __init__(self, parent=None):
        super().__init__(parent)

        central_widget = QtWidgets.QWidget()
        self.setCentralWidget(central_widget)

        lay = QtWidgets.QHBoxLayout(central_widget)

        lay.addWidget(QtWidgets.QLabel("QLabel", alignment=QtCore.Qt.AlignCenter))

        file = os.path.join(DIR_PATH, "gallery.qml")
        self.view = QtQuick.QQuickView()
        self.view.statusChanged.connect(self.on_statusChanged)
        self.view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)
        engine = self.view.engine()
        context = engine.rootContext()
        context.setContextProperty("availableStyles", availableStyles())
        self.view.setSource(QtCore.QUrl.fromLocalFile(file))
        widget = QtWidgets.QWidget.createWindowContainer(self.view)
        lay.addWidget(widget)
Ejemplo n.º 7
0
def main():
    app = QtWidgets.QApplication(sys.argv)
    app.setFont(QtGui.QFont("Ubuntu Mono"))
    engine = QtQml.QQmlApplicationEngine()
    interfaces = Interfaces()
    engine.rootContext().setContextProperty('interfaces', interfaces)
    sniffer = Sniffer()
    engine.rootContext().setContextProperty('sniffer', sniffer)

    packetItemModel = sniffer.packetItemModel
    engine.rootContext().setContextProperty('packetItemModel', packetItemModel)
    engine.load(QUrl('main.qml'))

    topLevel = QtCore.QObject()
    topLevel = engine.rootObjects()[0]

    window = QtQuick.QQuickWindow()
    window = topLevel

    window.show()
    sys.exit(app.exec_())
Ejemplo n.º 8
0
def main():
    # This is required so that app.quit can be invoked when the quickview
    # is closed. If it is not present then the app does not exit. It is
    # possibly a bug in PyQt or Qt.
    global app

    app = QtWidgets.QApplication(sys.argv)
    quickview = QtQuick.QQuickView()
    if getattr(sys, 'frozen', None):
        basedir = sys._MEIPASS
    else:
        basedir = os.path.dirname(__file__)

    # The app dir is in the default import path but we can't put the QtQuick
    # import lib dirs there because of a name clash (on OSX) with the QtQuick
    # dll.
    print("Qt5 Qml import paths:", list(quickview.engine().importPathList()))
    quickview.setSource(QtCore.QUrl('qrc:/hello.qml'))
    quickview.engine().quit.connect(app.quit)
    quickview.show()

    app.exec_()
Ejemplo n.º 9
0
        return self.roles


class MessageHandler(logging.Handler):
    """Custom handler to intercept log records that feed our `model`"""
    def __init__(self, model, *args, **kwargs):
        super(MessageHandler, self).__init__(*args, **kwargs)
        self.model = model

    def emit(self, record):
        self.model.addItem(record)


app = QtGui.QGuiApplication(sys.argv)

view = QtQuick.QQuickView()

model = Model()
proxy = QtCore.QSortFilterProxyModel()
proxy.setSourceModel(model)
proxy.setFilterRole(model.roles.keys()[0])
proxy.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)

engine = view.engine()
context = engine.rootContext()
context.setContextProperty("qmodel", proxy)

view.setSource(QtCore.QUrl("tst_LogObject.qml"))
view.setResizeMode(view.SizeRootObjectToView)
view.show()