class ProducerConsumer(unittest.TestCase):
    '''Basic test case for producer-consumer QThread'''

    def setUp(self):
        #Create fixtures
        self.app = QCoreApplication([])

    def tearDown(self):
        #Destroy fixtures
        del self.app

    def finishCb(self):
        #Quits the application
        self.app.exit(0)

    def testProdCon(self):
        #QThread producer-consumer example
        bucket = Bucket()
        prod = Producer(bucket)
        cons = Consumer(bucket)

        prod.start()
        cons.start()

        QObject.connect(prod, SIGNAL('finished()'), self.finishCb)
        QObject.connect(cons, SIGNAL('finished()'), self.finishCb)

        self.app.exec_()

        prod.wait()
        cons.wait()

        self.assertEqual(prod.production_list, cons.consumption_list)
class ProducerConsumer(unittest.TestCase):
    '''Basic test case for producer-consumer QThread'''

    def setUp(self):
        #Create fixtures
        self.app = QCoreApplication([])

    def tearDown(self):
        #Destroy fixtures
        del self.app

    def finishCb(self):
        #Quits the application
        self.app.exit(0)

    def testProdCon(self):
        #QThread producer-consumer example
        bucket = Bucket()
        prod = Producer(bucket)
        cons = Consumer(bucket)

        prod.start()
        cons.start()

        QObject.connect(prod, SIGNAL('finished()'), self.finishCb)
        QObject.connect(cons, SIGNAL('finished()'), self.finishCb)

        self.app.exec_()

        prod.wait(50)
        cons.wait(50)

        self.assertEqual(prod.production_list, cons.consumption_list)
    def quit_app(self):
        self.node_set.lnd.process.terminate()
        self.node_set.lnd.process.waitForFinished(2000)
        self.node_set.bitcoin.process.terminate()
        self.node_set.bitcoin.process.waitForFinished(20000)
        self.node_set.bitcoin.process.kill()

        QCoreApplication.exit(0)
Beispiel #4
0
def pda(option):
    if SettingsManager.SETTINGS["System"]["OS"]["value"] != 0:
        return
    if option == 0:
        pass
    elif option == 1:
        print("exit")
        QCoreApplication.exit()
    elif option == 2:
        print("hibernate")
        os.system("shutdown /h")
    elif option == 3:
        print("shutdown")
        os.system("shutdown -s -t 1")
    def quit_app(self):
        log.debug('quit_app')
        self.system_tray.show_message(title='Stopping LND...')
        self.node_set.lnd_node.stop()
        self.node_set.lnd_node.process.waitForFinished(-1)

        self.node_set.bitcoind_node.stop()
        self.system_tray.show_message(title='Stopping bitcoind...')
        self.node_set.bitcoind_node.process.waitForFinished(-1)

        self.node_set.tor_node.process.kill()
        self.node_set.tor_node.process.waitForFinished(-1)

        self.system_tray.show_message(title='Exiting Node Launcher', timeout=1)

        QCoreApplication.exit(0)
Beispiel #6
0
    def test_controller_and_worker_better(self):
        app = QCoreApplication.instance() or QCoreApplication(sys.argv)
        controller = Controller()
        controller.worker.finished.connect(QCoreApplication.quit,
                                           type=Qt.QueuedConnection)

        timeout_timer = QTimer(parent=controller)
        timeout_timer.setInterval(3000)
        timeout_timer.setSingleShot(True)
        timeout_timer.timeout.connect(lambda: QCoreApplication.exit(-1))
        timeout_timer.start()

        with patch.object(controller, "on_worker_result") as on_result:
            controller.start()
            self.assertEqual(0, app.exec_())
            self.assertEqual(20, len(on_result.mock_calls))
Beispiel #7
0
    def testEmitOutsideThread(self):
        global thread_run

        app = QCoreApplication([])
        source = Source()
        thread = ThreadJustConnects(source)

        QObject.connect(thread, SIGNAL('finished()'), lambda: app.exit(0))
        thread.start()

        while not thread_run:
            pass

        source.emit_sig()

        app.exec_()
        thread.wait()

        self.assertTrue(thread.target.called)
    def testEmitOutsideThread(self):
        global thread_run

        app = QCoreApplication([])
        source = Source()
        thread = ThreadJustConnects(source)

        QObject.connect(thread, SIGNAL('finished()'), lambda: app.exit(0))
        thread.start()

        while not thread_run:
            pass

        source.emit_sig()

        app.exec_()
        thread.wait()

        self.assert_(thread.target.called)
Beispiel #9
0
    def __init__(self, node_set: NodeSet, system_tray):
        super().__init__()
        self.node_set = node_set
        self.system_tray = system_tray

        # Bitcoind
        self.bitcoind_status_action = self.addAction('bitcoind off')
        self.bitcoind_status_action.setEnabled(False)

        self.bitcoind_manager_tabs_dialog = BitcoindManagerTabsDialog(
            bitcoin=self.node_set.bitcoin, system_tray=self.system_tray)
        self.bitcoin_manage_action = self.addAction('Manage Bitcoind')
        self.bitcoin_manage_action.triggered.connect(
            self.bitcoind_manager_tabs_dialog.show)

        QTimer.singleShot(500, self.node_set.bitcoin.process.start)
        self.bitcoind_manager_tabs_dialog.output_tab.bitcoind_synced.connect(
            self.node_set.lnd.process.start)

        self.addSeparator()

        # LND
        self.lnd_status_action = self.addAction('lnd off')
        self.lnd_status_action.setEnabled(False)

        self.lnd_manager_tabs_dialog = LndManagerTabsDialog(
            lnd=self.node_set.lnd, system_tray=self.system_tray)
        self.lnd_manage_action = self.addAction('Manage LND')
        self.lnd_manage_action.triggered.connect(
            self.lnd_manager_tabs_dialog.show)

        self.addSeparator()

        # Joule
        self.joule_status_action = self.addAction('Joule Browser UI')
        self.joule_status_action.setEnabled(False)
        self.joule_url_action = self.addAction('Copy Node URL (REST)')
        self.joule_macaroons_action = self.addAction('Show Macaroons')
        self.joule_url_action.triggered.connect(
            lambda: QClipboard().setText(self.node_set.lnd.rest_url))
        self.joule_macaroons_action.triggered.connect(
            lambda: reveal(self.node_set.lnd.macaroon_path))

        self.addSeparator()

        # Zap
        self.zap_status_action = self.addAction('Zap Desktop UI')
        self.zap_status_action.setEnabled(False)
        self.zap_open_action = self.addAction('Open Zap Desktop')
        self.zap_open_action.triggered.connect(
            lambda: webbrowser.open(self.node_set.lnd.lndconnect_url))
        self.zap_qr_code_label = ZapQrcodeLabel(
            self.node_set.lnd.lndconnect_qrcode)
        self.show_zap_qrcode_action = self.addAction('Pair Zap Mobile')
        self.show_zap_qrcode_action.triggered.connect(
            self.zap_qr_code_label.show)

        self.addSeparator()

        # Quit
        self.quit_action = self.addAction('Quit')
        self.quit_action.triggered.connect(lambda _: QCoreApplication.exit(0))
Beispiel #10
0
    def __init__(self, node_set: NodeSet, system_tray):
        super().__init__()
        self.node_set = node_set
        self.system_tray = system_tray

        # Tor
        self.tor_status_action = self.addAction('Tor: off')
        self.tor_status_action.setEnabled(False)
        self.node_set.tor_node.status.connect(
            lambda line: self.tor_status_action.setText('Tor: ' + line.replace('_', ' '))
        )

        # Bitcoind
        self.bitcoind_status_action = self.addAction('Bitcoind: off')
        self.bitcoind_status_action.setEnabled(False)
        self.node_set.bitcoind_node.status.connect(
            lambda line: self.bitcoind_status_action.setText('Bitcoind: ' + line.replace('_', ' '))
        )

        # LND
        self.lnd_status_action = self.addAction('LND: off')
        self.lnd_status_action.setEnabled(False)
        self.node_set.lnd_node.status.connect(
            lambda line: self.lnd_status_action.setText('LND: ' + line.replace('_', ' '))
        )

        self.bitcoind_manager_tabs_dialog = NodeManagerTabsDialog(
            node_set=self.node_set,
            system_tray=self.system_tray
        )
        self.bitcoin_manage_action = self.addAction('Manage Nodes')
        self.bitcoin_manage_action.triggered.connect(
            self.bitcoind_manager_tabs_dialog.show
        )
        self.addSeparator()

        # Joule
        self.joule_status_action = self.addAction('Joule Browser UI')
        self.joule_status_action.setEnabled(False)
        self.joule_url_action = self.addAction('Copy Node URL (REST)')
        self.joule_macaroons_action = self.addAction('Show Macaroons')
        self.joule_url_action.triggered.connect(self.copy_rest_url)
        self.joule_macaroons_action.triggered.connect(self.reveal_macaroon_path)

        self.addSeparator()

        # Zap
        self.zap_status_action = self.addAction('Zap Desktop UI')
        self.zap_status_action.setEnabled(False)
        self.zap_open_action = self.addAction('Open Zap Desktop')
        self.zap_open_action.triggered.connect(
            lambda: webbrowser.open(self.node_set.lnd_node.configuration.lndconnect_url)
        )
        # Todo: reenable when Zap mobile supports Tor
        # self.zap_qr_code_label = ZapQrcodeLabel(
        #     configuration=self.node_set.lnd_node.configuration
        # )
        # self.show_zap_qrcode_action = self.addAction('Pair Zap Mobile')
        # self.show_zap_qrcode_action.triggered.connect(
        #     self.zap_qr_code_label.show
        # )

        self.addSeparator()

        # Quit
        self.quit_action = self.addAction('Quit')
        self.quit_action.triggered.connect(
            lambda _: QCoreApplication.exit(0)
        )
Beispiel #11
0
def exit(code):
    QCoreApplication.exit(code)
    sys.exit(code)
Beispiel #12
0
 def exit(self):
     QCoreApplication.exit()
Beispiel #13
0
 def handle_object_created(obj, objUrl):
     if not obj and url == objUrl:
         QCoreApplication.exit(-1)
Beispiel #14
0
    def __init__(self, node_set: NodeSet, system_tray):
        super().__init__()
        self.node_set = node_set
        self.system_tray = system_tray

        # Bitcoind
        self.bitcoind_status_action = self.addAction('bitcoind off')
        self.bitcoind_status_action.setEnabled(False)
        self.node_set.bitcoind_node.process.status.connect(
            lambda line: self.bitcoind_status_action.setText(line))

        self.bitcoind_manager_tabs_dialog = BitcoindManagerTabsDialog(
            bitcoind_node=self.node_set.bitcoind_node,
            system_tray=self.system_tray)
        self.bitcoin_manage_action = self.addAction('Manage Bitcoind')
        self.bitcoin_manage_action.triggered.connect(
            self.bitcoind_manager_tabs_dialog.show)
        self.addSeparator()

        # LND
        self.lnd_status_action = self.addAction('lnd off')
        self.lnd_status_action.setEnabled(False)
        self.node_set.lnd_node.process.status.connect(
            lambda line: self.lnd_status_action.setText(line))

        self.lnd_manager_tabs_dialog = LndManagerTabsDialog(
            lnd_node=self.node_set.lnd_node, system_tray=self.system_tray)
        self.lnd_manage_action = self.addAction('Manage LND')
        self.lnd_manage_action.triggered.connect(
            self.lnd_manager_tabs_dialog.show)

        self.addSeparator()

        # Joule
        self.joule_status_action = self.addAction('Joule Browser UI')
        self.joule_status_action.setEnabled(False)
        self.joule_url_action = self.addAction('Copy Node URL (REST)')
        self.joule_macaroons_action = self.addAction('Show Macaroons')
        self.joule_url_action.triggered.connect(self.copy_rest_url)
        self.joule_macaroons_action.triggered.connect(
            self.reveal_macaroon_path)

        self.addSeparator()

        # Zap
        self.zap_status_action = self.addAction('Zap Desktop UI')
        self.zap_status_action.setEnabled(False)
        self.zap_open_action = self.addAction('Open Zap Desktop')
        self.zap_open_action.triggered.connect(
            lambda: webbrowser.open(self.node_set.lnd_node.lndconnect_url))
        self.zap_qr_code_label = ZapQrcodeLabel(
            configuration=self.node_set.lnd_node.configuration)
        self.show_zap_qrcode_action = self.addAction('Pair Zap Mobile')
        self.show_zap_qrcode_action.triggered.connect(
            self.zap_qr_code_label.show)

        self.addSeparator()

        # Quit
        self.quit_action = self.addAction('Quit')
        self.quit_action.triggered.connect(lambda _: QCoreApplication.exit(0))
Beispiel #15
0
 def handle_object_created(obj, obj_url):
     if obj is None and url == obj_url:
         QCoreApplication.exit(-1)
Beispiel #16
0
    def __init__(self, node_set: NodeSet, system_tray):
        super().__init__()
        self.node_set = node_set
        self.system_tray = system_tray

        self.bitcoind_status_action = self.addAction('bitcoind off')
        self.bitcoind_status_action.setEnabled(False)

        # bitcoin console
        self.bitcoin_cli_widget = ConsoleDialog(
            title='bitcoin-cli',
            program=self.node_set.bitcoin.software.bitcoin_cli,
            args=self.node_set.bitcoin.args,
            commands=BITCOIN_CLI_COMMANDS)
        self.bitcoin_console_action = self.addAction('Open Bitcoin Console')
        self.bitcoin_console_action.triggered.connect(
            self.bitcoin_cli_widget.show)

        # bitcoind output
        self.bitcoind_output_widget = BitcoindOutputWidget(
            node_set=self.node_set, system_tray=self.system_tray)
        self.bitcoind_output_action = self.addAction('See Bitcoin Output')
        self.bitcoind_output_action.triggered.connect(
            self.bitcoind_output_widget.show)

        self.addSeparator()

        self.lnd_status_action = self.addAction('lnd off')
        self.lnd_status_action.setEnabled(False)

        # lnd console

        self.lncli_widget = ConsoleDialog(
            title='lncli',
            program=self.node_set.lnd.software.lncli,
            args=self.node_set.lnd.lncli_arguments(),
            commands=LNCLI_COMMANDS)
        self.lnd_console_action = self.addAction('Open LND Console')
        self.lnd_console_action.triggered.connect(self.lncli_widget.show)

        # lnd output
        self.lnd_output_widget = LndOutputWidget(node_set=self.node_set,
                                                 system_tray=self.system_tray)
        self.lnd_output_action = self.addAction('See LND Output')
        self.lnd_output_action.triggered.connect(self.lnd_output_widget.show)

        self.addSeparator()

        # Joule

        self.joule_status_action = self.addAction('Joule Browser Extension')
        self.joule_status_action.setEnabled(False)
        self.joule_url_action = self.addAction('Copy Node URL (REST)')
        self.joule_macaroons_action = self.addAction('Show Macaroons')

        self.joule_url_action.triggered.connect(
            lambda: QClipboard().setText(self.node_set.lnd.rest_url))

        self.joule_macaroons_action.triggered.connect(
            lambda: reveal(self.node_set.lnd.macaroon_path))

        self.addSeparator()

        # settings

        self.settings_action = self.addAction('&Settings')
        self.settings_action.setShortcut(QKeySequence.Preferences)
        self.settings_tab = SettingsTabDialog(node_set=self.node_set)
        self.settings_action.triggered.connect(self.settings_tab.show)

        # advanced

        self.advanced_widget = AdvancedWidget(node_set=self.node_set)
        self.advanced_action = self.addAction('Advanced...')
        self.advanced_action.triggered.connect(self.advanced_widget.show)

        self.addSeparator()

        # quit
        self.quit_action = self.addAction('Quit')

        self.quit_action.triggered.connect(lambda _: QCoreApplication.exit(0))
Beispiel #17
0
 def _on_exit(self):
     logger.debug("Worker thread quit")
     if self._tracker_thread:
         self._tracker_thread.quit()
         self._tracker_thread.wait(2)
     QCoreApplication.exit(0)