Beispiel #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--nintendont", help="Connect to the given IP via the Nintendont protocol instead.")
    args = parser.parse_args()

    app = QCoreApplication(sys.argv)

    os.environ['QT_API'] = "PySide2"
    import qasync
    loop = qasync.QEventLoop(app)
    asyncio.set_event_loop(loop)

    logging.config.dictConfig({
        'version': 1,
        'formatters': {
            'default': {
                'format': '[%(asctime)s] [%(levelname)s] [%(name)s] %(funcName)s: %(message)s',
            }
        },
        'handlers': {
            'default': {
                'level': 'DEBUG',
                'formatter': 'default',
                'class': 'logging.StreamHandler',
                'stream': 'ext://sys.stdout',  # Default is stderr
            },
        },
        'loggers': {
        },
        'root': {
            'level': 'DEBUG',
            'handlers': ['default'],
        },
    })

    def catch_exceptions(t, val, tb):
        global should_quit
        should_quit = True
        old_hook(t, val, tb)

    def catch_exceptions_async(loop, context):
        if 'future' in context:
            future: asyncio.Future = context['future']
            logging.exception(context["message"], exc_info=future.exception())
        else:
            logging.critical(str(context))

    sys.excepthook = catch_exceptions
    loop.set_exception_handler(catch_exceptions_async)

    if args.nintendont is not None:
        backend = NintendontBackend(args.nintendont)
    else:
        backend = DolphinBackend()

    with loop:
        try:
            asyncio.get_event_loop().run_until_complete(worker(app, backend))
        finally:
            app.quit()
 def loaded(self, ok):
     self.assertTrue(ok)
     if not ok:
         QCoreApplication.quit()
     self._view.page().runJavaScript("document.title", 1,
                                     partial(self.javascript_callback))
     self._view.findText("fox", QWebEnginePage.FindFlags(),
                         partial(self.found_callback))
Beispiel #3
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setWindowTitle("AxiGUI")
        self._config_dialog = ConfigDialog()
        self._plot_control = PlotControlWidget()

        # setup toolbar
        self._toolbar = QToolBar()
        self._toolbar.setIconSize(QSize(64, 64))
        load_act = self._toolbar.addAction(QIcon("images/icons_open.png"),
                                           "Load")
        load_act.triggered.connect(lambda: self.load_svg())
        config_act = self._toolbar.addAction(
            QIcon("images/icons_settings.png"), "Config")
        config_act.triggered.connect(lambda: self._config_dialog.exec_())
        self._toolbar.addSeparator()
        self._plot_control.add_actions(self._toolbar)
        empty = QWidget()
        empty.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred))
        self._toolbar.addWidget(empty)
        quit_act = self._toolbar.addAction(QIcon("images/icons_exit.png"),
                                           "Quit")
        quit_act.triggered.connect(lambda: QCoreApplication.quit())

        # setup layout
        layout = QVBoxLayout()
        layout.setSpacing(0)
        layout.setMargin(0)
        layout.addWidget(self._toolbar)
        layout.addWidget(self._plot_control)
        self.setLayout(layout)
class DnsLookupTestCase(unittest.TestCase):
    '''Test case for QDnsLookup'''
    def setUp(self):
        self._app = QCoreApplication([])
        self._lookup = QDnsLookup(QDnsLookup.ANY, 'www.qt.io')
        self._lookup.finished.connect(self._finished)

    def tearDown(self):
        del self._lookup

    def _finished(self):
        if self._lookup.error() == QDnsLookup.NoError:
            nameRecords = self._lookup.canonicalNameRecords()
            if nameRecords:
                print(nameRecords[0].name())
        self._app.quit()

    def testLookup(self):
        self._lookup.lookup()
        self._app.exec_()
Beispiel #5
0
class HttpSignalsCase(unittest.TestCase):
    '''Test case for bug #124 - readDatagram signature

    QUdpSocket.readDatagram must return a tuple with the datagram, host and
    port, while receiving only the max payload size.'''
    def setUp(self):
        #Acquire resources
        self.called = False
        self.app = QCoreApplication([])

        self.socket = QUdpSocket()

        self.server = QUdpSocket()
        self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)

    def tearDown(self):
        #Release resources
        del self.socket
        del self.server
        del self.app

    def sendPackage(self):
        addr = QHostAddress(QHostAddress.LocalHost)
        self.socket.writeDatagram('datagram', addr, 45454)

    def callback(self):
        while self.server.hasPendingDatagrams():
            datagram, host, port = self.server.readDatagram(
                self.server.pendingDatagramSize())
            self.called = True
            self.app.quit()

    def testDefaultArgs(self):
        #QUdpSocket.readDatagram pythonic return
        # @bug 124
        QObject.connect(self.server, SIGNAL('readyRead()'), self.callback)
        self.sendPackage()
        self.app.exec_()

        self.assertTrue(self.called)
Beispiel #6
0
class HttpSignalsCase(unittest.TestCase):
    '''Test case for bug #124 - readDatagram signature

    QUdpSocket.readDatagram must return a tuple with the datagram, host and
    port, while receiving only the max payload size.'''

    def setUp(self):
        #Acquire resources
        self.called = False
        self.app = QCoreApplication([])

        self.socket = QUdpSocket()

        self.server = QUdpSocket()
        self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)

    def tearDown(self):
        #Release resources
        del self.socket
        del self.server
        del self.app

    def sendPackage(self):
        addr = QHostAddress(QHostAddress.LocalHost)
        self.socket.writeDatagram('datagram', addr, 45454)

    def callback(self):
        while self.server.hasPendingDatagrams():
            datagram, host, port = self.server.readDatagram(self.server.pendingDatagramSize())
            self.called = True
            self.app.quit()

    def testDefaultArgs(self):
        #QUdpSocket.readDatagram pythonic return
        # @bug 124
        QObject.connect(self.server, SIGNAL('readyRead()'), self.callback)
        self.sendPackage()
        self.app.exec_()

        self.assert_(self.called)
Beispiel #7
0
def main():
    parser = argparse.ArgumentParser()
    parser.parse_args()

    app = QCoreApplication(sys.argv)

    os.environ['QT_API'] = "PySide2"
    import asyncqt
    loop = asyncqt.QEventLoop(app)
    asyncio.set_event_loop(loop)

    def catch_exceptions(t, val, tb):
        global should_quit
        should_quit = True
        old_hook(t, val, tb)

    sys.excepthook = catch_exceptions

    with loop:
        try:
            asyncio.get_event_loop().run_until_complete(worker(app))
        finally:
            app.quit()
Beispiel #8
0
def quit_app():
    print("timer timeout - exiting")
    QCoreApplication.quit()
 def javascript_callback(self, result):
     self.assertEqual(result, "Title")
     self._callback_count += 1
     if self._callback_count == 2:
         QCoreApplication.quit()
 def found_callback(self, found):
     self.assertTrue(found)
     self._callback_count += 1
     if self._callback_count == 2:
         QCoreApplication.quit()
Beispiel #11
0
 def event_quit_callback(self, **kwargs):
     QCoreApplication.quit()
Beispiel #12
0
def _quit():
    QCoreApplication.quit()
Beispiel #13
0
import os
from PySide2 import QtCore, QtWidgets, QtGui
from PySide2.QtCore import QCoreApplication
from PySide2.QtWidgets import QAction

os.environ["QT_SCREEN_SCALE_FACTORS"] = "2"

app = QtWidgets.QApplication(["tray_icon_test"])
app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
app.setQuitOnLastWindowClosed(False)

icon_file = ("example.svg")
print(icon_file)
icon = QtGui.QIcon.fromTheme(icon_file)
tray_icon = QtWidgets.QSystemTrayIcon(icon)

quitAction = QAction("&Quit", tray_icon)
# connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);

quitAction.triggered.connect(QCoreApplication.quit())
tray_icon.show()
app.exec_()