예제 #1
0
def init():
    import sys
    import traceback
    from app import helpers
    from app import models
    sys.excepthook = traceback.print_exception
    helpers.init_logging()
    helpers.init_data_dir()
    models.init_profile_db()
    models.init_data_db()
예제 #2
0
def generate_api_sample_responses():
    """Creates sample response json data in .scratch folder.

    Note: Calls rpc.RpcClient methods with their default args.
    Other args may yield different json structures!
    """
    init_profile_db()
    client = get_active_rpc_client()
    for method in scan:
        result = getattr(client, method)()
        fp = '.scratch/{}.json'.format(method)
        json.dump(result, open(fp, 'w'), indent=4, cls=DecimalEncoder)
예제 #3
0
    def on_application_start(self):
        init_profile_db()
        self.updater = Updater(self)
        self.node = Node(self)
        self.aboutToQuit.connect(self.cleanup)

        from app.models.db import profile_session_scope
        with profile_session_scope() as session:
            is_first_start = app.is_first_start(session)

        if is_first_start:
            wizard = SetupWizard()
            if wizard.exec() == SetupWizard.Rejected:
                QtWidgets.qApp.quit()
                return
        else:
            init_data_db()

        # Initialize main window
        self.ui = self.main_widget()

        # Init TrayIcon
        self.tray_icon = QtWidgets.QSystemTrayIcon(self)
        self.tray_icon.setIcon(QIcon(':images/resources/app_icon.png'))
        self.tray_icon.activated.connect(self.on_tray_activated)

        show_action = QtWidgets.QAction("Show", self)
        quit_action = QtWidgets.QAction("Exit", self)
        hide_action = QtWidgets.QAction("Hide", self)
        show_action.triggered.connect(self.ui.show)
        hide_action.triggered.connect(self.ui.hide)
        quit_action.triggered.connect(QtWidgets.qApp.quit)

        tray_menu = QtWidgets.QMenu()
        tray_menu.addAction(show_action)
        tray_menu.addAction(hide_action)
        tray_menu.addAction(quit_action)
        self.tray_icon.setContextMenu(tray_menu)
        self.tray_icon.show()

        # Shortcuts
        if hasattr(self.ui, 'node'):
            self.ui.debug_shortcut = QtWidgets.QShortcut(
                'Ctrl+K', self.ui, self.node.kill)
            self.ui.debug_shortcut = QtWidgets.QShortcut(
                'Ctrl+S', self.ui, self.node.stop)
            self.ui.debug_shortcut = QtWidgets.QShortcut(
                'Ctrl+R', self.ui, self.node.start)
예제 #4
0
def generate_classes():
    init_profile_db()
    client = get_active_rpc_client()

    class_blocks = []
    for method in generate:
        result = getattr(client, method)()
        classname = method.title()
        setters = []
        for field in result['result'].keys():
            setter = 'self.{} = kwargs["{}"]'.format(field, field)
            setters.append(setter)
        setters = '\n        '.join(setters)
        class_block = class_template.format(
            classname=classname, setters=setters
        )
        class_blocks.append(class_block)
    module_code = module_header + "\n".join(class_blocks)
    with open('app/responses.py', 'w') as outf:
        outf.write(module_code)
예제 #5
0
    def page7_sync_initialize_page(self):
        if self._mnemonic and not self._address:
            self._address = main_address_from_mnemonic(self._mnemonic)

        self.label_address.setText(self._address)
        img = ImageQt(qrcode.make(self._address, box_size=3))
        self.label_qr_code.setPixmap(QPixmap.fromImage(img))

        if not exists(app.DATA_DIR):
            self.log('Creating data dir at: %s' % app.DATA_DIR)
            init_data_dir()

        self.log('Initialize profile database at: %s' % app.PROFILE_DB_FILEPATH)

        if self._manage_node:
            init_profile_db(create_default_profile=True)
        elif self._connection_tested:
            init_profile_db(create_default_profile=False)
            p_obj, created = Profile.get_or_create(
                name=self.edit_rpc_host.text(),
                defaults=dict(
                    rpc_host=self.edit_rpc_host.text(),
                    rpc_port=self.edit_rpc_port.text(),
                    rpc_user=self.edit_rpc_user.text(),
                    rpc_password=self.edit_rpc_password.text(),
                    rpc_use_ssl=self.cbox_use_ssl.isChecked(),
                    manage_node=False,
                    exit_on_close=True,
                    active=True,
                )
            )

        self.log('Initialize node-sync database')
        init_data_db()

        if self._manage_node:
            self.node.start(initprivkey=main_wif_from_mnemonic(self._mnemonic))
        else:
            self._database_sync = True
            if not self.updater.isRunning():
                self.updater.start()
예제 #6
0
        self.edit_alias.setText(self.profile.alias)
        self.lbl_wallet_alias.show()
        self.btn_wallet_alias_edit_start.show()
        self.btn_wallet_alias_edit_save.hide()
        self.btn_wallet_alias_edit_cancel.hide()
        self.edit_alias.hide()

    def save_alias(self):
        try:
            self.profile.update_alias(self.edit_alias.text())
            self.stop_edit_alias()
            QMessageBox().information(self, "New alias", "New alias registration in progress")
        except Exception as e:
            QMessageBox().critical(self, 'Alias update error', str(e))

if __name__ == '__main__':
    import sys
    from PyQt5 import QtWidgets
    from app import helpers
    from app import models
    helpers.init_logging()
    helpers.init_data_dir()
    models.init_profile_db()
    models.init_data_db()

    app = QtWidgets.QApplication(sys.argv)
    app.setStyle('fusion')
    wgt = MyAccount()
    wgt.show()
    sys.exit(app.exec())
예제 #7
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        # Instantiate workers
        self.updater = QApplication.instance().updater
        self.node = QApplication.instance().node

        self.data_dir = helpers.init_data_dir()
        self.profile_db = models.init_profile_db()
        self.node_data_dir = helpers.init_node_data_dir()
        self.data_db = models.init_data_db()
        self.profile = Profile.get_active()

        # Setup Widgets
        self.setupUi(self)

        self.on_profile_changed(self.profile)
        signals.profile_changed.connect(self.on_profile_changed)

        # Init Navigation
        self.btn_grp_nav.setId(self.btn_nav_wallet, 0)
        self.btn_grp_nav.setId(self.btn_nav_timestamp, 1)
        self.btn_grp_nav.setId(self.btn_nav_community, 2)
        self.btn_grp_nav.setId(self.btn_nav_settings, 3)
        self.btn_nav_wallet.setChecked(True)
        self.wgt_content.setCurrentIndex(0)

        # Patch custom widgets
        self.tab_widget_cummunity.setStyleSheet(
            'QPushButton {padding: 5 12 5 12; font: 10pt "Roboto Light"}')

        self.gbox_wallet_transactions.setParent(None)
        self.gbox_wallet_send.setParent(None)

        wallet_send = WalletSend(self)
        self.lout_page_wallet_v.addWidget(wallet_send)

        wallet_history = WalletHistory(self)
        self.lout_page_wallet_v.addWidget(wallet_history)

        widget_timestamp = WidgetTimestamping(self)
        self.lout_page_timestamp_v.addWidget(widget_timestamp)

        self.table_validators.setParent(None)
        table_validators = CommunityTableView(self, perm_type=Permission.MINE)
        self.tab_validators.layout().insertWidget(0, table_validators)

        self.table_guardians.setParent(None)
        table_guardians = CommunityTableView(self, perm_type=Permission.ADMIN)
        self.tab_guardians.layout().insertWidget(0, table_guardians)

        self.table_candidates.setParent(None)
        table_candidates = CandidateTableView(self)
        self.tab_candidates.layout().insertWidget(0, table_candidates)

        # Dialog Button hookups
        invite_dialog = InviteDialog(self)
        self.button_invite_canditate.clicked.connect(invite_dialog.exec)
        apply_dialog = ApplyDialog(self)
        self.button_apply_guardian.clicked.connect(apply_dialog.exec)
        self.button_apply_validator.clicked.connect(apply_dialog.exec)

        # Settings
        self.check_box_exit_on_close.setChecked(self.profile.exit_on_close)
        self.check_box_exit_on_close.stateChanged['int'].connect(
            self.setting_changed_exit_on_close)
        self.check_manage_node.setChecked(self.profile.manage_node)
        self.check_manage_node.stateChanged['int'].connect(
            self.setting_changed_manage_node)

        # Connections
        signals.getblockchaininfo.connect(self.getblockchaininfo)
        signals.listpermissions.connect(self.listpermissions)
        signals.node_started.connect(self.node_started)

        if self.profile.manage_node:
            # Todo check for existing node process
            self.node.start()
        else:
            # No managed node to wait for... start updater
            self.updater.start()

        self.show()
        self.setSortingEnabled(False)
        self.setCornerButtonEnabled(True)
        self.create_table_buttons()

    def create_table_buttons(self):
        self.setItemDelegateForColumn(5, ButtonDelegate(self))
        for row in range(0, self.table_model.rowCount()):
            self.openPersistentEditor(self.table_model.index(row, 5))
        # TODO find a better way to fix button sizes collapsing on update
        w, h = self.size().width(), self.size().height()
        self.resize(w + 1, h)
        self.resize(w, h)

    @pyqtSlot(bool)
    def is_admin_changed(self, is_admin):
        self.setColumnHidden(5, not is_admin)


if __name__ == '__main__':
    from app.models import init_profile_db, init_data_db
    from app.helpers import init_logging

    init_logging()
    # from app.tools.runner import run_widget
    init_profile_db()
    init_data_db()
    app = QtWidgets.QApplication(sys.argv)
    win = CommunityTableView(perm_type=Permission.MINE)
    win.show()
    sys.exit(app.exec_())