def call(self, query, return_dict=False): if isinstance(query, QJSValue): query = query.toVariant() # TODO: hack, find a real solution # logger.debug(query) try: for key in query['params']: if key in ['quantity']: query['params'][key] = int(query['params'][key]) except: pass try: result = clientapi.call(query['method'], query['params'], pubkey_resolver=pubkeyResolver) except LockedWalletError as e: passphrase = InputDialog.input( message=tr('Enter your wallet passhrase:'), is_password=True) try: clientapi.call('unlock', {'passphrase': passphrase}) return self.call(query) except Exception as e: raise ZuuldRPCError(str(e)) except Exception as e: raise ZuuldRPCError(str(e)) # TODO: hack, find a real solution result = json.dumps(result, cls=DecimalEncoder) result = json.loads(result) # logger.debug(result) if return_dict: return result return QVariant(result)
def main(): app = QApplication(sys.argv) if platform.system() == "Windows": import ctypes appid = 'zuul.zuul-gui' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(appid) # load global translation translator = QtCore.QTranslator() fileName = 'zuulgui_'.format(QtCore.QLocale.system().name()) #fileName = 'zuulgui_fr' translator.load(fileName, 'i18n') app.installTranslator(translator) splash_pix = QtGui.QPixmap('assets/splash.png') splash = QtWidgets.QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) splash.show() splash.showMessage(tr("Loading wallet..."), Qt.AlignBottom | Qt.AlignHCenter) setattr(zuulgui, 'splash', splash) app.processEvents() config = Config(splash=splash) screen = GUI(config, app, splash) def quitApp(): sys.exit() app.aboutToQuit.connect(quitApp) splash.finish(screen) app.exec()
def __init__(self, configfile, newconfig=False, parent=None): super().__init__( parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint) logger.debug(tr('Loading configuration file: `{}`').format(configfile)) knownConfig = configparser.ConfigParser() with codecs.open(configfile, 'r', encoding='utf8') as fp: knownConfig.readfp(fp) if 'Default' in knownConfig: knownConfig = dict(knownConfig['Default']) else: knownConfig = {} self.setMinimumWidth(400) self.setModal(True) self.setWindowTitle(tr('Configuration')) tabs = QtWidgets.QTabWidget() serverConfigWidget = ServerConfigPage(knownConfig, newconfig) walletConfigWidget = WalletConfigPage(knownConfig) advancedConfigWidget = AdvancedConfigPage(knownConfig) tabs.addTab(serverConfigWidget, tr("Zuul Server")) tabs.addTab(walletConfigWidget, tr("Wallet")) tabs.addTab(advancedConfigWidget, tr("Advanced")) tabLayout = QtWidgets.QVBoxLayout() tabLayout.addWidget(tabs) def onServersSelected(): config = {} config.update(serverConfigWidget.getServerConfig()) config.update(walletConfigWidget.getWalletConfig()) config.update(advancedConfigWidget.getAdvancedConfig()) knownConfig.update(config) generate_config_file(configfile, client.CONFIG_ARGS, known_config=knownConfig, overwrite=True) self.accept() def onCancel(): self.reject() btnLayout = QtWidgets.QHBoxLayout() cancelBtn = QtWidgets.QPushButton(tr("Cancel")) cancelBtn.clicked.connect(onCancel) btnLayout.addWidget(cancelBtn) selectionCompletedBtn = QtWidgets.QPushButton(tr("Ok")) selectionCompletedBtn.clicked.connect(onServersSelected) btnLayout.addWidget(selectionCompletedBtn) tabLayout.addLayout(btnLayout) self.setLayout(tabLayout)
def __init__(self, config, app, splash): super().__init__() self.config = config self.app = app self.splash = splash log.set_up(logger, verbose=config.VERBOSE, logfile=config.LOG_FILE) self.resize(1024, 680) self.setWindowTitle(tr("Zuul GUI")) icon = QtGui.QIcon('assets/zuul.icns') self.setWindowIcon(icon) self.app.setWindowIcon(icon) def openPreference(): if self.config.initialize(openDialog=True): self.loadPlugins() # Add Preferences menu mainMenuBar = QMenuBar() newAct = QAction(tr("Preferences..."), self) newAct.triggered.connect(openPreference) fileMenu = mainMenuBar.addMenu(tr("Zuul GUI")) fileMenu.addAction(newAct) self.setMenuBar(mainMenuBar) self.currentBlock = None if self.refreshStatus(): self.loadPlugins() timer = QtCore.QTimer(self) timer.timeout.connect(self.refreshStatus) timer.start(self.config.POLL_INTERVAL) self.show()
def __init__(self, message, is_password=False, parent=None): super().__init__(parent) self.message = message self.setModal(True) self.layout = QVBoxLayout() self.setLayout(self.layout) label = QLabel(message) self.layout.addWidget(label) self.input = QLineEdit() if is_password: self.input.setEchoMode(QLineEdit.Password) self.layout.addWidget(self.input) def onOkPushed(): self.close() okBtn = QPushButton(tr("Ok")) okBtn.clicked.connect(onOkPushed) self.layout.addWidget(okBtn) self.exec()
def pubkeyResolver(address): message = tr( 'Public keys (hexadecimal) or Private key (Wallet Import Format) for `{}`: ' ).format(address) return InputDialog.input(message=message)
def __init__(self, knownConfig, parent=None): super().__init__(parent) mainLayout = QtWidgets.QVBoxLayout() mainLayout.setAlignment(QtCore.Qt.AlignTop) self.setLayout(mainLayout) self.useTestnet = QtWidgets.QCheckBox(tr('Use testnet network')) self.useTestnet.setChecked(bool(int(knownConfig.get('testnet', '0')))) mainLayout.addWidget(self.useTestnet) self.allowUnconfirmed = QtWidgets.QCheckBox( tr('Allow the spending of unconfirmed transaction outputs')) self.allowUnconfirmed.setChecked( bool(int(knownConfig.get('unconfirmed', '0')))) mainLayout.addWidget(self.allowUnconfirmed) encodingLabel = QtWidgets.QLabel(tr('Data encoding method')) mainLayout.addWidget(encodingLabel) self.encoding = QtWidgets.QComboBox() self.encoding.addItems(['auto', 'multisig', 'opreturn', 'pubkeyhash']) mainLayout.addWidget(self.encoding) feePerKbLabel = QtWidgets.QLabel(tr('Fee per kilobyte, in GZR')) mainLayout.addWidget(feePerKbLabel) self.feePerKbField = QtWidgets.QDoubleSpinBox() self.feePerKbField.setDecimals(8) self.feePerKbField.setMinimum(0.00000001) self.feePerKbField.setSingleStep(0.00000001) try: self.feePerKbField.setValue( float( knownConfig.get('fee-per-kb', config.DEFAULT_FEE_PER_KB / config.UNIT))) except ValueError: self.feePerKbField.setValue(config.DEFAULT_FEE_PER_KB / config.UNIT) mainLayout.addWidget(self.feePerKbField) regularDustSizeLabel = QtWidgets.QLabel( tr('Value for dust Pay-to-Pubkey-Hash outputs, in GZR')) mainLayout.addWidget(regularDustSizeLabel) self.regularDustSize = QtWidgets.QDoubleSpinBox() self.regularDustSize.setDecimals(8) self.regularDustSize.setMinimum(0.00000001) self.regularDustSize.setSingleStep(0.00000001) try: self.regularDustSize.setValue( float( knownConfig.get( 'regular-dust-size', config.DEFAULT_REGULAR_DUST_SIZE / config.UNIT))) except ValueError: self.regularDustSize.setValue(config.DEFAULT_REGULAR_DUST_SIZE / config.UNIT) mainLayout.addWidget(self.regularDustSize) multisigDustSizeLabel = QtWidgets.QLabel( tr('Value for dust OP_CHECKMULTISIG outputs, in GZR')) mainLayout.addWidget(multisigDustSizeLabel) self.multisigDustSize = QtWidgets.QDoubleSpinBox() self.multisigDustSize.setDecimals(8) self.multisigDustSize.setMinimum(0.00000001) self.multisigDustSize.setSingleStep(0.00000001) try: self.multisigDustSize.setValue( float( knownConfig.get( 'multisig-dust-size', config.DEFAULT_MULTISIG_DUST_SIZE / config.UNIT))) except ValueError: self.multisigDustSize.setValue(config.DEFAULT_MULTISIG_DUST_SIZE / config.UNIT) mainLayout.addWidget(self.multisigDustSize) opReturnValueLabel = QtWidgets.QLabel( tr('Value for OP_RETURN outputs, in GZR')) mainLayout.addWidget(opReturnValueLabel) self.opReturnValue = QtWidgets.QDoubleSpinBox() self.opReturnValue.setDecimals(8) self.opReturnValue.setMinimum(0) self.opReturnValue.setSingleStep(0.00000001) try: self.opReturnValue.setValue( float( knownConfig.get( 'op-return-value', config.DEFAULT_OP_RETURN_VALUE / config.UNIT))) except ValueError: self.opReturnValue.setValue(config.DEFAULT_OP_RETURN_VALUE / config.UNIT) mainLayout.addWidget(self.opReturnValue)
def initialize(self, openDialog=False): configdir = appdirs.user_config_dir(appauthor=config.ZUL_NAME, appname=config.APP_NAME, roaming=True) configfile = os.path.join(configdir, 'client.conf') config_exists = os.path.exists(configfile) if not config_exists: generate_config_file(configfile, client.CONFIG_ARGS) # Parse command-line arguments. parser = argparse.ArgumentParser( prog=APP_NAME, description=tr('Zuul CLI for zuul-server'), add_help=False, conflict_handler='resolve') parser.add_argument('-h', '--help', dest='help', action='store_true', help=tr('show this help message and exit')) parser.add_argument('-V', '--version', action='version', version="{} v{}".format(APP_NAME, APP_VERSION)) parser.add_argument( '--config-file', help=tr('the location of the zuul-client configuration file')) self.args = parser.parse_known_args()[0] if not config_exists or openDialog: is_splash_visible = False if self.splash: is_splash_visible = self.splash.isVisible() if is_splash_visible: self.splash.hide() configfile = getattr(self.args, 'config_file', None) or configfile configUI = ConfigDialog(configfile, newconfig=not config_exists) result = configUI.exec() if is_splash_visible: self.splash.show() if openDialog and result == 0: return False parser = add_config_arguments(parser, CONFIG_ARGS, 'client.conf', config_file_arg_name='config_file') self.args = parser.parse_args() dargs = vars(self.args) for argName in dargs: print('{}: {}'.format(argName.upper(), dargs[argName])) setattr(self, argName.upper(), dargs[argName]) # Help message if self.args.help: parser.print_help() sys.exit() # Logging logdir = appdirs.user_log_dir(appauthor=config.ZUL_NAME, appname=config.APP_NAME) if not os.path.exists(logdir): os.makedirs(logdir, mode=0o755) self.LOG_FILE = os.path.join(logdir, 'zuulgui.log') log.set_up(logger, verbose=self.args.verbose, logfile=self.LOG_FILE) return True
def __init__(self, knownConfig, parent=None): super().__init__(parent) self.wallets = [(tr('Gozer Core'), 'gozercore'), (tr('gzrwallet'), 'gzrwallet')] mainLayout = QtWidgets.QVBoxLayout() mainLayout.setAlignment(QtCore.Qt.AlignTop) self.setLayout(mainLayout) self.radioButtonGroup = QtWidgets.QButtonGroup(self) for wallet in self.wallets: radioButton = QtWidgets.QRadioButton(wallet[0]) radioButton.setProperty('name', wallet[1]) if wallet[1] == knownConfig.get('wallet-name', 'gozercore'): radioButton.setChecked(True) self.radioButtonGroup.addButton(radioButton) mainLayout.addWidget(radioButton) groupBox = QtWidgets.QGroupBox(self) groupBoxLayout = QtWidgets.QVBoxLayout() groupBoxLayout.setAlignment(QtCore.Qt.AlignTop) serverLabel = QtWidgets.QLabel(tr('Host')) groupBoxLayout.addWidget(serverLabel) self.serverTextField = QtWidgets.QLineEdit() self.serverTextField.setToolTip( tr('the hostname or IP of the wallet server')) self.serverTextField.setText( knownConfig.get('wallet-connect', 'localhost')) groupBoxLayout.addWidget(self.serverTextField) portLabel = QtWidgets.QLabel(tr('Port')) groupBoxLayout.addWidget(portLabel) self.portTextField = QtWidgets.QSpinBox() self.portTextField.setRange(1, 65535) self.portTextField.setToolTip(tr('the wallet port to connect to')) try: self.portTextField.setValue( int(knownConfig.get('wallet-port', '28369'))) except ValueError: self.portTextField.setValue(28369) groupBoxLayout.addWidget(self.portTextField) userLabel = QtWidgets.QLabel(tr('User')) groupBoxLayout.addWidget(userLabel) self.userTextField = QtWidgets.QLineEdit() self.userTextField.setToolTip( tr('the username used to communicate with the wallet')) self.userTextField.setText(knownConfig.get('wallet-user', 'gozerrpc')) groupBoxLayout.addWidget(self.userTextField) passwordLabel = QtWidgets.QLabel(tr('Password')) groupBoxLayout.addWidget(passwordLabel) self.passwordTextField = QtWidgets.QLineEdit() self.passwordTextField.setToolTip( tr('the password used to communicate with the wallet')) self.passwordTextField.setEchoMode(QtWidgets.QLineEdit.Password) self.passwordTextField.setText(knownConfig.get('wallet-password', 'p')) groupBoxLayout.addWidget(self.passwordTextField) self.useSSLCheckbox = QtWidgets.QCheckBox( tr('Use SSL to connect to wallet')) self.useSSLCheckbox.setChecked( bool(int(knownConfig.get('wallet-ssl', '0')))) groupBoxLayout.addWidget(self.useSSLCheckbox) self.verifySSLCheckbox = QtWidgets.QCheckBox( tr('Verify SSL certificate of wallet (disallow use of self-signed certificates)' )) self.verifySSLCheckbox.setChecked( bool(int(knownConfig.get('wallet-ssl-verify', '0')))) groupBoxLayout.addWidget(self.verifySSLCheckbox) groupBox.setLayout(groupBoxLayout) mainLayout.addWidget(groupBox)
def __init__(self, knownConfig, newconfig=False, parent=None): super().__init__(parent) mainLayout = QtWidgets.QVBoxLayout() mainLayout.setAlignment(QtCore.Qt.AlignTop) self.setLayout(mainLayout) with open('servers.json') as f: self.public_servers = json.load(f) self.radioButtonGroup = QtWidgets.QButtonGroup(self) for server in self.public_servers: radioButton = QtWidgets.QRadioButton(server['connect']) radioButton.setProperty( 'ssl', server['ssl'] if 'ssl' in server else False) radioButton.setProperty('user', server['user'] if 'user' in server else '') radioButton.setProperty( 'password', server['password'] if 'password' in server else 'p') radioButton.setProperty('public', True) if newconfig and server['connect'] == self.public_servers[0][ 'connect']: radioButton.setChecked(True) elif server['connect'] == knownConfig.get('zuul-rpc-connect'): radioButton.setChecked(True) self.radioButtonGroup.addButton(radioButton) mainLayout.addWidget(radioButton) radioButton = QtWidgets.QRadioButton(tr('Private server:')) radioButton.setProperty('public', False) privateServerGroupBoxDisabled = True if not self.radioButtonGroup.checkedButton(): radioButton.setChecked(True) privateServerGroupBoxDisabled = False self.radioButtonGroup.addButton(radioButton) mainLayout.addWidget(radioButton) def onChangeSelectedServer(button): if not button.property('public'): groupBox.setDisabled(False) else: groupBox.setDisabled(True) self.radioButtonGroup.buttonReleased.connect(onChangeSelectedServer) groupBox = QtWidgets.QGroupBox(self) groupBoxLayout = QtWidgets.QVBoxLayout() groupBoxLayout.setAlignment(QtCore.Qt.AlignTop) serverLabel = QtWidgets.QLabel(tr('Host')) groupBoxLayout.addWidget(serverLabel) self.serverTextField = QtWidgets.QLineEdit() self.serverTextField.setToolTip( tr('the hostname or IP of the zuul JSON-RPC server')) self.serverTextField.setText( knownConfig.get('zuul-rpc-connect', 'localhost')) groupBoxLayout.addWidget(self.serverTextField) portLabel = QtWidgets.QLabel(tr('Port')) groupBoxLayout.addWidget(portLabel) self.portTextField = QtWidgets.QSpinBox() self.portTextField.setRange(1, 65535) self.portTextField.setToolTip( tr('the zuul JSON-RPC port to connect to')) try: self.portTextField.setValue( int(knownConfig.get('zuul-rpc-port', '12345'))) except ValueError: self.portTextField.setValue(12345) groupBoxLayout.addWidget(self.portTextField) userLabel = QtWidgets.QLabel(tr('User')) groupBoxLayout.addWidget(userLabel) self.userTextField = QtWidgets.QLineEdit() self.userTextField.setToolTip( tr('the username used to communicate with zuul over JSON-RPC')) self.userTextField.setText(knownConfig.get('zuul-rpc-user', 'rpc')) groupBoxLayout.addWidget(self.userTextField) passwordLabel = QtWidgets.QLabel(tr('Password')) groupBoxLayout.addWidget(passwordLabel) self.passwordTextField = QtWidgets.QLineEdit() self.passwordTextField.setToolTip( tr('the password used to communicate with zuul over JSON-RPC')) self.passwordTextField.setEchoMode(QtWidgets.QLineEdit.Password) self.passwordTextField.setText( knownConfig.get('zuul-rpc-password', 'p')) groupBoxLayout.addWidget(self.passwordTextField) self.useSSLCheckbox = QtWidgets.QCheckBox( tr('Use SSL to connect to zuul')) self.useSSLCheckbox.setChecked( bool(int(knownConfig.get('zuul-rpc-ssl', '0')))) groupBoxLayout.addWidget(self.useSSLCheckbox) self.verifySSLCheckbox = QtWidgets.QCheckBox( tr('Verify SSL certificate of zuul (disallow use of self-signed certificates)' )) self.verifySSLCheckbox.setChecked( bool(int(knownConfig.get('zuul-rpc-ssl-verify', '0')))) groupBoxLayout.addWidget(self.verifySSLCheckbox) groupBox.setLayout(groupBoxLayout) groupBox.setDisabled(privateServerGroupBoxDisabled) mainLayout.addWidget(groupBox)