def _getPixelRatio():
     if PyQtImpl in ["PyQt5", "PySide2"]:
         # Source: https://stackoverflow.com/a/40053864/3388962
         pos = QCursor.pos()
         for screen in QApplication.screens():
             rect = screen.geometry()
             if rect.contains(pos):
                 return screen.devicePixelRatio()
         # Should never happen, but try to find a good fallback.
         return QApplication.devicePixelRatio()
     else:
         # Qt4 seems not to provide any cross-platform means to get the
         # pixel ratio.
         return 1.
 def _getPixelRatio():
     if PyQtImpl == "PyQt5":
         # Source: https://stackoverflow.com/a/40053864/3388962
         pos = QCursor.pos()
         for screen in QApplication.screens():
             rect = screen.geometry()
             if rect.contains(pos):
                 return screen.devicePixelRatio()
         # Should never happen, but try to find a good fallback.
         return QApplication.devicePixelRatio()
     else:
         # Qt4 seems not to provide any cross-platform means to get the
         # pixel ratio.
         return 1.
Example #3
0
qmlRegisterType(DataBlock, 'WeatherCategory', 1, 0, 'DataBlock')
qmlRegisterType(Geocoder, 'WeatherCategory', 1, 0, 'Geocoder')

component = QQmlComponent(engine)
component.loadUrl(QUrl('WeatherDash.qml'))

# Create the QML user interface.  Auto creates its own engine
view = QQuickView()

engine2 = view.engine
# Does not run
#engine2.quit.connect(app.quit)

#view.setSource(QUrl('PyTest.qml'))
# To Satisfy cool-retro-term needs
view.rootContext().setContextProperty('devicePixelRatio', app.devicePixelRatio())

view.setSource(QUrl('WeatherDash.qml'))
#view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
view.setGeometry(100, 100, 750, 480)
# ala https://pythonspot.com/pyqt5-colors/
view.setColor(QColor(0, 30, 0))

view.show()

is_full_screen = False

# technique lifted from https://stackoverflow.com/questions/19131084/pyqt5-qml-signal-to-python-slot
# and augmented from https://stackoverflow.com/questions/30586983/how-to-close-pyqt5-program-from-qml
# could refine with https://stackoverflow.com/questions/24111717/how-to-bind-buttons-in-qt-quick-to-python-pyqt-5
# not 100% ideal, but adequate and interesting
Example #4
0
    def __init__(self, recording=None, exec=True, app=None, **kwargs):
        # Check if exist a default config file in the home (user) directory:
        mp.set_start_method("spawn", force=True)
        inum = kwargs.get("instance_number", -1)
        if inum >= 0:
            default_config_file = Path.home(
            ) / "stytra_setup_config_{}.json".format(inum)
        else:
            default_config_file = Path.home() / "stytra_setup_config.json"
        if default_config_file.is_file():
            config = json.load(open(str(default_config_file)))
        else:
            config = dict()

        # Get rest of configuration parameters from the protocol:
        try:
            extra_config = kwargs["protocol"].stytra_config
            recursive_update(config, extra_config)
        except AttributeError:
            pass

        recursive_update(config, kwargs)  # Use also keyword arguments

        if config.get("scope_triggering", None) == "zmq":
            # Automatically use zmqTrigger if zmq is specified
            from stytra.triggering import ZmqTrigger

            config["scope_triggering"] = ZmqTrigger(port="5555")

        if app is None:
            app = QApplication([])
            app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
            if app.devicePixelRatio() > 1:
                app.setAttribute(Qt.AA_UseHighDpiPixmaps)
        class_kwargs = dict(app=app)
        class_kwargs.update(config)

        base = VisualExperiment

        if "camera" in class_kwargs.keys():
            base = CameraVisualExperiment
            if "tracking" in class_kwargs.keys():
                base = TrackingExperiment
                if not class_kwargs["tracking"].get("embedded", True):
                    class_kwargs["calibrator"] = CircleCalibrator()

            if recording:
                base = VideoRecordingExperiment

        # Stytra logo
        app_icon = QIcon()
        for size in [32, 64, 128, 256]:
            app_icon.addFile(
                pkg_resources.resource_filename(__name__,
                                                "/icons/{}.png".format(size)),
                QSize(size, size),
            )
        app.setWindowIcon(app_icon)

        pg.setConfigOptions(imageAxisOrder="row-major")

        self.exp = base(**class_kwargs)

        self.exp.start_experiment()

        if exec:
            app.exec_()
Example #5
0
class KeyboardIcon(XKBMixin):
    def __init__(self):
        self.app = QApplication(sys.argv)
        self.app.setQuitOnLastWindowClosed(False)
        # start class name with underscore so i3bar puts the icon first
        self.app.setApplicationName('_ input sources')
        self._init_menu()
        self._init_xcb_xkb()
        #self._init_xkb_groups()
        self._init_xkb_groups_simple()
        #self._draw_langs_icon_theme()
        self._draw_langs_renderer()
        self.icon = QSystemTrayIcon()
        self.icon.activated.connect(self.activate_icon)
        self.icon.setContextMenu(self.menu)
        self._init_xkb_handler()
        self.update_icon()

    def _init_menu(self):
        self.menu = QMenu()
        self.menu.addAction(EXIT_LABEL, self._exit)

    def _draw_text(self, text):
        dpr = self.app.devicePixelRatio()
        pixmap = QPixmap(int(ICON_SIZE * dpr), int(ICON_SIZE * dpr))
        pixmap.fill(Qt.transparent)
        painter = QPainter(pixmap)
        color = QColor()
        color.setRgbF(*FONT_COLOR)
        painter.setPen(color)
        font = painter.font()
        font.setFamily(FONT_FACE)
        font.setPixelSize(int(FONT_SIZE * dpr))
        font.setBold(True)
        painter.setFont(font)
        rect = pixmap.rect()
        rect.moveTop(-4)
        painter.drawText(rect, Qt.AlignCenter, text)
        painter.end()
        return QIcon(pixmap)

    def _get_theme_icon(self, icon_name):
        return QIcon.fromTheme(icon_name)

    def activate_icon(self, reason):
        if reason != QSystemTrayIcon.Trigger:
            return
        self.set_next_group()
        self.update_icon()

    def update_icon(self):
        group = self.get_xkb_group()
        self.icon.setIcon(self.langs[group])

    def async_listener(self):
        while True:
            e = self.xcb.xcb_wait_for_event(self.conn)
            if e:
                self.xcb.free(e)
                self.update_icon()

    def run(self):
        self.icon.show()
        sys.exit(self.app.exec_())

    def _exit(self, *args):
        self.xcb.xcb_disconnect(self.conn)
        os._exit(0)
Example #6
0
from PyQt5.QtCore import *

import CellModeller.GUI.Renderers
from CellModeller import Simulator
from CellModeller.GUI.PyGLCMViewer import PyGLCMViewer, RenderInfo
from pkg_resources import resource_stream

import os
import sys

# The Qt application
qapp = QApplication([])

# The UI
uifile = resource_stream('CellModeller.GUI', 'PyGLGUI.ui')
ui = uic.loadUi(uifile)
ui.show()
ui.raise_()
cmv = ui.PyGLCMViewer
pix_ratio = qapp.devicePixelRatio()
cmv.setPixelRatio(pix_ratio)
label = ui.label
label.setTextFormat(Qt.RichText)
label.setAlignment(Qt.AlignJustify)

# Load a model if specified
if len(sys.argv) > 1: cmv.loadModelFile(sys.argv[1])

# Launch app main loop
sys.exit(qapp.exec_())
Example #7
0
        inspect.setPage(view.page())
        view.setContextMenuPolicy(Qt.DefaultContextMenu)
        inspect.show()

    listenerEndpoint = SSL4ServerEndpoint(reactor, aetherListeningPort,
                                          globals.AetherContextFactory())
    listenerEndpoint.listen(aetherProtocol.AetherProtocolFactory())

    splash.finish(view)
    if not globals.appStartedAtBoot:
        view.show()
        toggleVisibilityMenuItem.setText('Hide Aether')
    reactor.run()


if __name__ == "__main__":

    if app.devicePixelRatio() == 2:
        splashPicture = QtGui.QPixmap(basedir + 'Assets/[email protected]')
        sp2 = splashPicture.copy(QtCore.QRect(
            0, 0, 450, 450))  # This is a workaround for a bug in Qt 5.1.1

    else:
        sp2 = QtGui.QPixmap(basedir + 'Assets/splash.png')

    splash = QSplashScreen(sp2, Qt.WindowStaysOnTopHint)

    if not globals.appStartedAtBoot:
        splash.show()
    main()
Example #8
0
        inspect.move(0,0)
        inspect.setPage(view.page())
        view.setContextMenuPolicy(Qt.DefaultContextMenu)
        inspect.show()

    listenerEndpoint = SSL4ServerEndpoint(reactor, aetherListeningPort, globals.AetherContextFactory())
    listenerEndpoint.listen(aetherProtocol.AetherProtocolFactory())

    splash.finish(view)
    if not globals.appStartedAtBoot:
        view.show()
        toggleVisibilityMenuItem.setText('Hide Aether')
    reactor.run()


if __name__ == "__main__":

    if app.devicePixelRatio() == 2:
        splashPicture = QtGui.QPixmap(basedir+'Assets/[email protected]')
        sp2 = splashPicture.copy(QtCore.QRect(0,0, 450,450)) # This is a workaround for a bug in Qt 5.1.1

    else:
        sp2 = QtGui.QPixmap(basedir+'Assets/splash.png')

    splash = QSplashScreen(sp2, Qt.WindowStaysOnTopHint)

    if not globals.appStartedAtBoot:
        splash.show()
    main()