Ejemplo n.º 1
0
class Main:
    def __init__(self):
        self.app = QGuiApplication(sys.argv)
        self.engine = QQmlApplicationEngine()
        self.context = self.engine.rootContext()

        self._setup_context()

        self.engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))

        if not self.engine.rootObjects():
            sys.exit(-1)
        sys.exit(self.app.exec_())

    def _setup_context(self):
        self.movie_list = MovieList()
        self.context.setContextProperty("MovieList", self.movie_list)

        self.movie_list_proxy = MovieListProxy()
        self.movie_list_proxy.setSourceModel(self.movie_list)
        self.context.setContextProperty("MovieListProxy",
                                        self.movie_list_proxy)

        self.resource_loader = ResourceLoader()
        self.context.setContextProperty("ResourceLoader", self.resource_loader)

        self.movie_details = MovieDetail()
        self.context.setContextProperty("MovieDetail", self.movie_details)
Ejemplo n.º 2
0
    def __init__(self):
        super(UISciHubEVA, self).__init__()

        self._engine = QQmlApplicationEngine()
        self._engine.rootContext().setContextProperty('APPLICATION_VERSION',
                                                      APPLICATION_VERSION)
        self._engine.rootContext().setContextProperty('PYTHON_VERSION',
                                                      PYTHON_VERSION)
        self._engine.rootContext().setContextProperty('QT_VERSION', QT_VERSION)
        self._engine.load('qrc:/ui/SciHubEVA.qml')
        self._window = self._engine.rootObjects()[0]

        self._logger = DEFAULT_LOGGER
        self._logger.addHandler(UISciHubEVALogHandler(self))

        self._connect()

        self._ui_preferences = UIPreferences(self)
        self._ui_captcha = UICaptcha(self, self._logger)
        self._captcha_query = None

        self._query_input = None
        self._query_list = None
        self._query_list_length = 0
        self._captcha_img_file_path = None

        self._save_to_dir = Preferences.get_or_default(
            FILE_SAVE_TO_DIR_KEY, FILE_SAVE_TO_DIR_DEFAULT)
        self.set_save_to_dir.emit(self._save_to_dir)
Ejemplo n.º 3
0
def main(verbosity, log_to_file):

    # Configure the LogConfigurator and instantiate logger for this module
    logConfig = LogConfigurator(verbosity="DEBUG",
                                output_to_logfile=log_to_file)

    # Create the QML Application and Engine
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()

    # Instantiate custom python classes and add them to QML engine
    nav_buttons = NavigationButton()
    search_panels = SearchPanel()
    qmlRegisterType(NavigationButton, "NavigationButton", 1, 0,
                    "NavigationButton")
    qmlRegisterType(SearchPanel, "Search", 1, 0, "SearchPanel")
    qmlRegisterType(NodeManager, "Node", 1, 0, "NodeManager")

    # Load the main QML file
    engine.load(QUrl("learn_ml/ui/app.qml"))

    if not engine.rootObjects():
        sys.exit(-1)

    # Begin execution
    sys.exit(app.exec_())
    def __init__(self, parent = None):
        # Initialization of the superclass
        super(MainWindow, self).__init__(parent)
        
        qInstallMessageHandler(qt_message_handler)
        
        self.backend = Backend()

        # Expose the Python "Backend" object to QML
        self.engine = QQmlApplicationEngine()  
        self.context = self.engine.rootContext()
        self.context.setContextProperty("backend", self.backend)
        
        # Load the GUI
        self.engine.load(os.path.join(os.path.dirname(__file__), "SpecPXA_QML.qml"))
        if not self.engine.rootObjects():
            sys.exit(-1)
        
        self.win = self.engine.rootObjects()[0]
        
        # Execute a function if "Start" button clicked
        startbutton = self.win.findChild(QObject, "startbutton")
        startbutton.startclicked.connect(self.startclicked)
        
        # Execute a function if "Stop" button clicked
        stopbutton = self.win.findChild(QObject, "stopbutton")
        stopbutton.stopclicked.connect(self.stopclicked)
Ejemplo n.º 5
0
class CaptchaDialog(QObject):
    showWindowCaptcha = Signal(str)

    def __init__(self, parent, log=None):
        super(CaptchaDialog, self).__init__()

        self._parent = parent
        self.log = log

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/Captcha.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()

    def _connect(self):
        # Connect QML signals to PyQt slots
        self._window.killCaptcha.connect(self.killCaptcha)

        # Connect PyQt signals to QML slots
        self.showWindowCaptcha.connect(self._window.showWindowCaptcha)

    @Slot(bool, str)
    def killCaptcha(self, kill, captcha):
        if kill:
            self._parent.rampage_with_typed_captcha(captcha)
        else:
            self.log(self.tr('Battle canceled, rampage again?'), logging.ERROR)
            self._parent.afterRampage.emit()
Ejemplo n.º 6
0
class AddSciHubURLDialog(QObject):
    showWindowAddSciHubURL = Signal()

    def __init__(self, parent, conf):
        super(AddSciHubURLDialog, self).__init__()

        self._parent = parent
        self._conf = conf

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/AddSciHubURL.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()

    def _connect(self):
        # Connect QML signals to PyQt slots
        self._window.addSciHubURL.connect(self.addSciHubURL)

        # Connect PyQt signals to QML slots
        self.showWindowAddSciHubURL.connect(
            self._window.showWindowAddSciHubURL)

    @Slot(str)
    def addSciHubURL(self, url):
        scihub_available_urls = json.loads(
            self._conf.get('network', 'scihub_available_urls'))

        if url not in scihub_available_urls:
            scihub_available_urls.append(url)

        self._conf.set('network', 'scihub_available_urls',
                       json.dumps(scihub_available_urls))
        self._parent.load_from_conf()
Ejemplo n.º 7
0
class MainWindow(QObject):
    def __init__(self):
        super().__init__()
        # Variável **DEVE** utilizar `self`!
        self.engine = QQmlApplicationEngine()
        self.engine.load('./MainWindow.qml')
        if not self.engine.rootObjects():
            sys.exit(-1)

        # Variável `window` **DEVE** utilizar `self`!
        # Variável window recebe a janela principal e os widgets.
        self.window = self.engine.rootObjects()[0]

        # Acessado/atribuindo os widgets.
        self.label = self.window.findChild(QObject, 'label')
        self.text_field = self.window.findChild(QObject, 'text_field')

        button = self.window.findChild(QObject, 'button')
        # Conectando o signal a um slot.
        button.clicked.connect(self.on_button_clicked)

    def on_button_clicked(self):
        if self.text_field.property('text'):
            self.label.setProperty('text', self.text_field.property('text'))
        else:
            self.label.setProperty('text', 'Digite algo no campo de texto :)')
Ejemplo n.º 8
0
    def __init__(self):
        super(SciHubEVA, self).__init__()

        self._conf = SciHubConf('SciHubEVA.conf')
        self._qt_quick_controls2_conf = SciHubConf(
            'qtquickcontrols2.conf', space_around_delimiters=False)

        self._engine = QQmlApplicationEngine()
        self._engine.rootContext().setContextProperty(
            'PYTHON_VERSION', '.'.join(str(v) for v in sys.version_info[:3]))
        self._engine.rootContext().setContextProperty(
            'QT_VERSION', PySide2.QtCore.qVersion())
        self._engine.load('qrc:/ui/SciHubEVA.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()

        self._scihub_preferences = SciHubPreferences(
            self._conf, self._qt_quick_controls2_conf)
        self._scihub_captcha = SciHubCaptcha(self, log=self.log)
        self._captcha_query = None

        save_to_dir = self._conf.get('common', 'save_to_dir')
        if not save_to_dir or save_to_dir.strip() == '':
            self._save_to_dir = None
        else:
            self._save_to_dir = save_to_dir
            self.loadSaveToDir.emit(save_to_dir)

        self._query_list = None
        self._query_list_length = 0

        self._captcha_img_file = None
Ejemplo n.º 9
0
class UICaptcha(QObject):
    show_ui_captcha = Signal(str)

    def __init__(self, parent, logger):
        super(UICaptcha, self).__init__()

        self._parent = parent
        self._logger = logger

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/Captcha.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()

    @property
    def window(self):
        return self._window

    def _connect(self):
        self._window.killCaptcha.connect(self.kill_captcha)

        self.show_ui_captcha.connect(self._window.showUICaptcha)

    @Slot(bool, str)
    def kill_captcha(self, kill, captcha):
        if kill:
            self._parent.rampage_with_typed_captcha(captcha)
        else:
            self._logger.error(self.tr('Battle canceled, rampage again?'))
            self._parent.after_rampage.emit()
Ejemplo n.º 10
0
    def __init__(self):
        self.app = QGuiApplication(sys.argv)
        self.engine = QQmlApplicationEngine()
        self.context = self.engine.rootContext()

        self.resource_loader = Resources()
        self.context.setContextProperty("Resources", self.resource_loader)

        self.movie_list = MovieList()
        self.context.setContextProperty("MovieList", self.movie_list)

        self.movie_list_proxy = MovieListProxy()
        self.movie_list_proxy.setSourceModel(self.movie_list)
        self.context.setContextProperty("MovieListProxy",
                                        self.movie_list_proxy)

        self.movie = Movie()
        self.context.setContextProperty("Movie", self.movie)

        self.engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))

        if not self.engine.rootObjects():
            sys.exit(-1)

        self.app.lastWindowClosed.connect(self._close_app)

        sys.exit(self.app.exec_())
Ejemplo n.º 11
0
class UIAddSciHubURL(QObject):
    show = Signal()

    def __init__(self, parent):
        super(UIAddSciHubURL, self).__init__()

        self._parent = parent

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/AddSciHubURL.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()

    @property
    def window(self):
        return self._window

    def _connect(self):
        self._window.addSciHubURL.connect(self.add_scihub_url)

        self.show.connect(self._window.showUIAddSciHubURL)

    @Slot(str)
    def add_scihub_url(self, url):
        scihub_available_urls = Preferences.get_or_default(
            NETWORK_SCIHUB_URLS_KEY, NETWORK_SCIHUB_URLS_DEFAULT)

        if url not in scihub_available_urls:
            scihub_available_urls.append(url)

        Preferences.set(NETWORK_SCIHUB_URLS_KEY, scihub_available_urls)
        self._parent.load_preferences()
Ejemplo n.º 12
0
    def __init__(self, model):
        self.app = QGuiApplication(sys.argv)

        self.engine = QQmlApplicationEngine()
        manager = Manager()
        ctx = self.engine.rootContext()
        ctx.setContextProperty("Manager", manager)
        self.engine.load('style/interface.qml')
Ejemplo n.º 13
0
    def __init__(self):
        super().__init__()
        # Variável **DEVE** utilizar `self`!
        self.engine = QQmlApplicationEngine()
        self.engine.load('./MainWindow.qml')

        if not self.engine.rootObjects():
            sys.exit(-1)
Ejemplo n.º 14
0
def main():
    app = QApplication([])
    QtWebEngine.initialize()
    engine = QQmlApplicationEngine()
    qml_file_path = os.path.join(os.path.dirname(__file__), 'browser.qml')
    qml_url = QUrl.fromLocalFile(os.path.abspath(qml_file_path))
    engine.load(qml_url)
    app.exec_()
Ejemplo n.º 15
0
    def _initialize(self):
        # This may not be the most elegant way to enable
        # Material, but there does not seem any other way
        sys.argv += ['--style', 'material']
        self.app = QGuiApplication(sys.argv)
        self.engine = QQmlApplicationEngine()

        self.engine.load(QUrl('src/views/qml/RootView.qml'))
Ejemplo n.º 16
0
def main():
    app = QApplication([])
    QtWebEngine.initialize()
    engine = QQmlApplicationEngine()
    qml_file_path = os.path.join(os.path.dirname(__file__), 'browser.qml')
    qml_url = QUrl.fromLocalFile(os.path.abspath(qml_file_path))
    engine.load(qml_url)
    app.exec_()
Ejemplo n.º 17
0
    def __init__(self, parent):
        super(UIAddSciHubURL, self).__init__()

        self._parent = parent

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/AddSciHubURL.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()
Ejemplo n.º 18
0
def main():
    app = QApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load('qtpreview.qml')

    if not engine.rootObjects():
        return -1

    return app.exec_()
Ejemplo n.º 19
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Create an Qt instance of the application
        self.app = QApplication(sys.argv)
        # Create a QML engine.
        self.qml_engine = QQmlApplicationEngine()
        self.qml_engine.rootContext().setContextProperty("pyappview", self)

        self.main_qml = None
Ejemplo n.º 20
0
def runLottie():
    app = QApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load('lottie.qml')

    if not engine.rootObjects():
        return -1

    return app.exec_()
Ejemplo n.º 21
0
class Main(QObject):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.engine = QQmlApplicationEngine(self)
        self.engine.rootContext().setContextProperty("backend", self)
        self.engine.load(QUrl.fromLocalFile('app.qml'))

    @Slot(str)
    def create(self, string):
        print(string)
Ejemplo n.º 22
0
    def __init__(self, parent, logger):
        super(UICaptcha, self).__init__()

        self._parent = parent
        self._logger = logger

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/Captcha.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()
Ejemplo n.º 23
0
    def __init__(self, parent, log=None):
        super(CaptchaDialog, self).__init__()

        self._parent = parent
        self.log = log

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/Captcha.qml')
        self._window = self._engine.rootObjects()[0]
        self._connect()
Ejemplo n.º 24
0
def main():
    # Initial installation check
    if (verify_installation_status()):
        from mygnuhealth.profile_settings import ProfileSettings
        from mygnuhealth.network_settings import NetworkSettings
        from mygnuhealth.ghlogin import GHLogin
        from mygnuhealth.bio import GHBio

        from mygnuhealth.bloodpressure import BloodPressure
        from mygnuhealth.glucose import Glucose
        from mygnuhealth.weight import Weight
        from mygnuhealth.osat import Osat

    app = QApplication(sys.argv)

    # Register ProfileSettings to use in QML
    qmlRegisterType(ProfileSettings, "ProfileSettings", 0, 1,
                    "ProfileSettings")

    # Register NetworkSettings to use in QML
    qmlRegisterType(NetworkSettings, "NetworkSettings", 0, 1,
                    "NetworkSettings")

    # Register BloodPressure to use in QML
    qmlRegisterType(BloodPressure, "BloodPressure", 0, 1, "BloodPressure")

    # Register Glucose to use in QML
    qmlRegisterType(Glucose, "Glucose", 0, 1, "Glucose")

    # Register Weight to use in QML
    qmlRegisterType(Weight, "Weight", 0, 1, "Weight")

    # Register Osat to use in QML
    qmlRegisterType(Osat, "Osat", 0, 1, "Osat")

    # Register GHLogin to use in QML
    qmlRegisterType(GHLogin, "GHLogin", 0, 1, "GHLogin")

    # Register GHBio to use in QML
    qmlRegisterType(GHBio, "GHBio", 0, 1, "GHBio")

    # Register GHPol to use in QML
    # qmlRegisterType(GHPol, "GHPol", 0, 1,
    #                "GHPol")

    engine = QQmlApplicationEngine()

    base_path = os.path.abspath(os.path.dirname(__file__))
    url = QUrl(f'file://{base_path}/qml/main.qml')
    engine.load(url)

    if not engine.rootObjects():
        sys.exit(-1)

    sys.exit(app.exec_())
Ejemplo n.º 25
0
    def run(self, path):
        # Create an instance of the application
        # QApplication MUST be declared in global scope to avoid segmentation
        # fault
        app = QApplication(self._argv)

        # Create QML engine
        engine = QQmlApplicationEngine()

        plugin_dir = path / 'plugins'
        imports_dir = path / 'imports'
        entry_path = path / 'src' / 'main.qml'
        
        sys.path.append(str(plugin_dir))
        if os.path.isdir(str(plugin_dir)):
            plugins = scan_plugins(str(plugin_dir))
            # install all
            for p in plugins:
                p.install()
                debug_print('Plugin %s loaded' % p.uri)
        else:
            debug_print('No plugin folder found!')

        engine.addImportPath(str(plugin_dir))
        engine.addImportPath(str(imports_dir))

        # Load the qml file into the engine
        debug_print('Start from entry %s' % str(entry_path))
        engine.load(str(entry_path))

        # Qml file error handling
        if not engine.rootObjects():
            sys.exit(-1)

        return app.exec_()
Ejemplo n.º 26
0
    def __init__(self):
        self.app = QGuiApplication(sys.argv)
        self.engine = QQmlApplicationEngine()
        self.context = self.engine.rootContext()

        self._setup_context()

        self.engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))

        if not self.engine.rootObjects():
            sys.exit(-1)
        sys.exit(self.app.exec_())
Ejemplo n.º 27
0
 def __init__(self, argv):
     self._docopt = docopt(__doc__)
     self.paths = Paths()
     self.paths.ROOT_PATH = self._docopt["--root"]
     self.tools = Tools(self.paths)
     self.config = self._get_config()
     self.qapp = self._get_app(argv)
     self._set_loop()
     self.aiohttp_session = aiohttp.ClientSession(loop=self.loop)
     self.qml_engine = QQmlApplicationEngine()
     self.qml_engine_ctx = self.qml_engine.rootContext()
     self.qml_engine_ctx.setContextProperty(
         "ROOT_PATH", QUrl.fromLocalFile(self.paths.ROOT_PATH))
Ejemplo n.º 28
0
    def __init__(self, parent):
        super(UIPreferences, self).__init__()

        self._parent = parent

        self._engine = QQmlApplicationEngine()
        self._engine.load('qrc:/ui/Preferences.qml')
        self._window = self._engine.rootObjects()[0]

        self._ui_add_scihub_url = UIAddSciHubURL(self)

        self._connect()
        self.load_preferences()
Ejemplo n.º 29
0
    def __init__(self):
        self.app = QGuiApplication(sys.argv)

        self.touchscreens = list(filter(lambda d: d.type() == QTouchDevice.TouchScreen, QTouchDevice.devices()))
        if self.touchscreens:
            logger.info("touchscreens detected, disabling mouse: %s" % self.touchscreens)
            # self.app.setOverrideCursor(QCursor(Qt.BlankCursor))
        else:
            logger.error("No touchscreen detected!")

        self.engine = QQmlApplicationEngine()
        self.loop = QEventLoop(self.app)
        asyncio.set_event_loop(self.loop)
Ejemplo n.º 30
0
def main():
    global dbus
    parser = ArgumentParser()
    parser.add_argument("-v",
                        "--verbose",
                        help="increase output verbosity",
                        action="store_true")
    args = parser.parse_args()
    QtQml.qmlRegisterType(QmlPage, "djpdf", 1, 0, "DjpdfPage")
    app = QApplication([])
    app.setWindowIcon(QIcon.fromTheme("com.github.unrud.djpdf"))
    engine = QQmlApplicationEngine()
    thumbnail_image_provider = ThumbnailImageProvider()
    engine.addImageProvider("thumbnails", thumbnail_image_provider)
    ctx = engine.rootContext()
    pages_model = QmlPagesModel(verbose=args.verbose)
    if os.environ.get("DJPDF_PLATFORM") == "flatpak":
        import dbus
        import dbus.mainloop.glib
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        bus = dbus.SessionBus()
        platform_integration = QmlFlatpakPlatformIntegration(bus)
    else:
        platform_integration = QmlPlatformIntegration()
    ctx.setContextProperty("pagesModel", pages_model)
    ctx.setContextProperty("platformIntegration", platform_integration)
    engine.load(QUrl.fromLocalFile(os.path.join(QML_DIR, "main.qml")))
    platform_integration.window = engine.rootObjects()[0]
    exit(app.exec_())
Ejemplo n.º 31
0
    def __setup(self):
        self.__current_language = QLocale.system().name()
        self.__de_translator = QTranslator()

        self.translation_directory = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "crimpy", "languages"))

        self.__engine = QQmlApplicationEngine()
        self.__root_context = RootContext()
        self.__engine.rootContext().setContextProperty("main",
                                                       self.__root_context)
        qmlRegisterType(TwitterConnector, 'Twitter', major, minor,
                        'TwitterModel')
        self.__engine.load(QUrl.fromLocalFile(qml_file))
Ejemplo n.º 32
0
def main():
    global dbus
    parser = ArgumentParser()
    parser.add_argument("-v", "--verbose", help="increase output verbosity",
                        action="store_true")
    args = parser.parse_args()
    QtQml.qmlRegisterType(QmlPage, "djpdf", 1, 0, "DjpdfPage")
    app = QApplication([])
    engine = QQmlApplicationEngine()
    thumbnail_image_provider = ThumbnailImageProvider()
    engine.addImageProvider("thumbnails", thumbnail_image_provider)
    ctx = engine.rootContext()
    pages_model = QmlPagesModel(verbose=args.verbose)
    if os.environ.get("DJPDF_PLATFORM_INTEGRATION", "") == "flatpak":
        import dbus
        import dbus.mainloop.glib
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        bus = dbus.SessionBus()
        platform_integration = QmlFlatpakPlatformIntegration(bus)
    else:
        platform_integration = QmlPlatformIntegration()
    ctx.setContextProperty("pagesModel", pages_model)
    ctx.setContextProperty("platformIntegration", platform_integration)
    engine.load(QUrl.fromLocalFile(
        os.path.join(QML_DIR, "main.qml")))
    if os.environ.get("DJPDF_PLATFORM_INTEGRATION", "") == "flatpak":
        platform_integration.win_id = engine.rootObjects()[0].winId()
    exit(app.exec_())
Ejemplo n.º 33
0
    
    numberChanged = Signal(int)
    
    def __set_number(self, val):
        if self.__number != val:
            self.__number = val;
            self.numberChanged.emit(self.__number)
    
    def get_number(self):
        return self.__number
    
    number = Property(int, get_number, notify=numberChanged)


if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    
    number_generator = NumberGenerator()
    engine.rootContext().setContextProperty("numberGenerator", number_generator)
    
    engine.load(QUrl("main.qml"))
    
    if not engine.rootObjects():
        sys.exit(-1)    
    
    sys.exit(app.exec_())

    # ...
    
Ejemplo n.º 34
0
            return True
        else:
            return False

    @Slot(str, result=bool)
    def getUnderline(self, s):
        if s.lower() == "underline":
            return True
        else:
            return False


if __name__ == '__main__':
    sys.argv += ['--style', 'material']
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()

    # Instance of the Python object
    bridge = Bridge()

    # Expose the Python object to QML
    context = engine.rootContext()
    context.setContextProperty("con", bridge)

    # Get the path of the current directory, and then add the name
    # of the QML file, to load it.
    qmlFile = join(dirname(__file__), 'view.qml')
    engine.load(abspath(qmlFile))

    if not engine.rootObjects():
        sys.exit(-1)
Ejemplo n.º 35
0
        psutil.cpu_percent(percpu=True)
            
    def __update(self):
        self.__cpu_load = psutil.cpu_percent(percpu=True)
        self.dataChanged.emit(self.index(0,0), self.index(self.__cpu_count-1, 0))
        
    def rowCount(self, parent):
        return self.__cpu_count
    
    def data(self, index, role):
        if (role == Qt.DisplayRole and
            index.row() >= 0 and
            index.row() < len(self.__cpu_load) and
            index.column() == 0):
            return self.__cpu_load[index.row()]
        else:
            return None

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    
    qmlRegisterType(CpuLoadModel, 'PsUtils', 1, 0, 'CpuLoadModel')
    
    engine.load(QUrl("main.qml"))
    
    if not engine.rootObjects():
        sys.exit(-1)    
    
    sys.exit(app.exec_())
Ejemplo n.º 36
0
import sys
import os

from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine

from view_model import ViewModel

if __name__ == '__main__':
    myApp = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    context = engine.rootContext()

    # import the path for the Qt Application Manager
    engine.addImportPath("/home/bob/Qt/5.11.2/Automotive/sources/qtapplicationmanager/dummyimports/")

    # create a view model
    view_model = ViewModel()

    # bind the view model to the context
    context.setContextProperty('view_model', view_model)

    # load the main QML window
    engine.load('mainwindow.qml')
    if not engine.rootObjects():
        sys.exit(-1)

    sys.exit(myApp.exec_())