def prompt_auth(self, msg): import getpass print_msg(msg) response = getpass.getpass('') if len(response) == 0: return None return response
def runCommand(self): command = self.getCommand() self.addToHistory(command) command = self.getConstruct(command) if command: tmp_stdout = sys.stdout class stdoutProxy(): def __init__(self, write_func): self.write_func = write_func self.skip = False def flush(self): pass def write(self, text): if not self.skip: stripped_text = text.rstrip('\n') self.write_func(stripped_text) QtCore.QCoreApplication.processEvents() self.skip = not self.skip if type(self.namespace.get(command)) == type(lambda:None): self.appendPlainText("'{}' is a function. Type '{}()' to use it in the Python console." .format(command, command)) self.newPrompt() return sys.stdout = stdoutProxy(self.appendPlainText) try: try: # eval is generally considered bad practice. use it wisely! result = eval(command, self.namespace, self.namespace) if result != None: if self.is_json: util.print_msg(util.json_encode(result)) else: self.appendPlainText(repr(result)) except SyntaxError: # exec is generally considered bad practice. use it wisely! exec(command, self.namespace, self.namespace) except SystemExit: self.close() except BaseException: traceback_lines = traceback.format_exc().split('\n') # Remove traceback mentioning this file, and a linebreak for i in (3,2,1,-1): traceback_lines.pop(i) self.appendPlainText('\n'.join(traceback_lines)) sys.stdout = tmp_stdout self.newPrompt() self.set_json(False)
def _send(self, parent, blob): def sender_thread(): with self._audio_interface() as interface: src = BytesIO(blob) dst = interface.player() amodem.main.send(config=self.modem_config, src=src, dst=dst) print_msg('Sending:', repr(blob)) blob = zlib.compress(blob.encode('ascii')) kbps = self.modem_config.modem_bps / 1e3 msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps) WaitingDialog(parent, msg, sender_thread)
def update_proposals(self): url = "{}/VoteProposals/CheckAddresses".format(URL_HIVE_VOTING_PORTAL) data = list(self.avaliable_addresses.keys()) headers = { 'Content-type': 'application/json', 'User-Agent': 'Electrum' } response = requests.post(url, json=data, headers=headers) if response.ok: jData = response.json() self.proposals = jData.get("result") print_msg("[VOTE API] successfully loaded proposals") else: response.raise_for_status()
def get_pin(self, msg): t = { 'a': '7', 'b': '8', 'c': '9', 'd': '4', 'e': '5', 'f': '6', 'g': '1', 'h': '2', 'i': '3' } print_msg(msg) print_msg("a b c\nd e f\ng h i\n-----") o = raw_input() return ''.join(map(lambda x: t[x], o))
def on_load_proposal_successful(self, result): open_proposals = self.smartvote_manager.proposals self.open_proposals_qty = len(open_proposals) self.openProposalsLabel.setText(str(self.open_proposals_qty)) for proposal in open_proposals: SmartProposalWidget = QWidget() ui = Ui_SmartProposalWidget() ui.setupUi(SmartProposalWidget, proposal, self.selected_voting_option_map, self.smartvote_manager) ui.yesButton.clicked.connect(self.on_proposal_option_changed) ui.noButton.clicked.connect(self.on_proposal_option_changed) ui.abstainButton.clicked.connect(self.on_proposal_option_changed) ui.disabledButton.clicked.connect(self.on_proposal_option_changed) self.verticalLayout_6.addWidget(SmartProposalWidget) self.votedForLabel.setText(str(self.smartvote_manager.voted_proposals)) print_msg('Successfully loaded proposals')
def on_load_news_successful(self): news_json = self.get_json('electrum-news.smartcash.cc', '/smartnews.json') print_msg('Loading news: {}'.format(json.dumps(news_json))) if news_json: news_qtd = 0 for news in news_json['itens']: try: SmartnewsListWidget = QWidget() ui = Ui_SmartNewsWidget() ui.setupUi(SmartnewsListWidget) ui.update_proposal_details(news) self.verticalLayout_6.addWidget(SmartnewsListWidget) news_qtd += 1 if news_qtd == 5: break except Exception as e: print_msg("could not load news: {}".format(str(e))) return else: print_msg('Could not load news api')
def show_error(self, msg): print_msg(msg)
def show_message(self, msg, on_cancel=None): print_msg(msg)
def get_passphrase(self, msg, confirm): import getpass print_msg(msg) return getpass.getpass('')
def yes_no_question(self, msg): print_msg(msg) return raw_input() in 'yY'
def on_finished(blob): if blob: blob = zlib.decompress(blob).decode('ascii') print_msg('Received:', repr(blob)) parent.setText(blob)
def debug_msg(*args): if DEBUG: print_msg(*args)