From 2c0814f0d38aa97f84623267fba9860d79c453ed Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 24 Sep 2013 10:06:03 +0200 Subject: [PATCH] simplify gui names --- electrum | 4 +- gui/{gui_android.py => android.py} | 0 gui/{gui_gtk.py => gtk.py} | 0 gui/gui_classic/qt_console.py | 315 ------------- gui/gui_stdio.py | 252 ---------- gui/gui_text.py | 444 ------------------ gui/{gui_classic => qt}/__init__.py | 2 +- gui/{gui_classic => qt}/amountedit.py | 0 gui/{gui_classic => qt}/history_widget.py | 0 gui/{gui_classic => qt}/installwizard.py | 0 gui/{gui_classic => qt}/lite_window.py | 2 +- gui/{gui_classic => qt}/main_window.py | 4 +- gui/{gui_classic => qt}/network_dialog.py | 2 +- gui/{gui_classic => qt}/password_dialog.py | 0 gui/{gui_classic => qt}/qrcodewidget.py | 0 gui/{gui_classic => qt}/receiving_widget.py | 0 gui/{gui_classic => qt}/seed_dialog.py | 0 gui/{gui_classic => qt}/transaction_dialog.py | 0 gui/{gui_classic/qt_util.py => qt/util.py} | 0 gui/{gui_classic => qt}/version_getter.py | 0 plugins/exchange_rate.py | 2 +- plugins/labels.py | 2 +- plugins/pointofsale.py | 2 +- plugins/qrscanner.py | 2 +- setup.py | 39 +- 25 files changed, 31 insertions(+), 1041 deletions(-) rename gui/{gui_android.py => android.py} (100%) rename gui/{gui_gtk.py => gtk.py} (100%) delete mode 100644 gui/gui_classic/qt_console.py delete mode 100644 gui/gui_stdio.py delete mode 100644 gui/gui_text.py rename gui/{gui_classic => qt}/__init__.py (99%) rename gui/{gui_classic => qt}/amountedit.py (100%) rename gui/{gui_classic => qt}/history_widget.py (100%) rename gui/{gui_classic => qt}/installwizard.py (100%) rename gui/{gui_classic => qt}/lite_window.py (99%) rename gui/{gui_classic => qt}/main_window.py (99%) rename gui/{gui_classic => qt}/network_dialog.py (99%) rename gui/{gui_classic => qt}/password_dialog.py (100%) rename gui/{gui_classic => qt}/qrcodewidget.py (100%) rename gui/{gui_classic => qt}/receiving_widget.py (100%) rename gui/{gui_classic => qt}/seed_dialog.py (100%) rename gui/{gui_classic => qt}/transaction_dialog.py (100%) rename gui/{gui_classic/qt_util.py => qt/util.py} (100%) rename gui/{gui_classic => qt}/version_getter.py (100%) diff --git a/electrum b/electrum index f63bae83d..5125eebe8 100755 --- a/electrum +++ b/electrum @@ -149,9 +149,9 @@ if __name__ == '__main__': if cmd == 'gui': gui_name = config.get('gui','classic') - if gui_name in ['lite', 'qt']: gui_name = 'classic' + if gui_name in ['lite', 'classic']: gui_name = 'qt' try: - gui = __import__('electrum_gui.gui_' + gui_name, fromlist=['electrum_gui']) + gui = __import__('electrum_gui.' + gui_name, fromlist=['electrum_gui']) except ImportError: traceback.print_exc(file=sys.stdout) sys.exit() diff --git a/gui/gui_android.py b/gui/android.py similarity index 100% rename from gui/gui_android.py rename to gui/android.py diff --git a/gui/gui_gtk.py b/gui/gtk.py similarity index 100% rename from gui/gui_gtk.py rename to gui/gtk.py diff --git a/gui/gui_classic/qt_console.py b/gui/gui_classic/qt_console.py deleted file mode 100644 index 9ff94d226..000000000 --- a/gui/gui_classic/qt_console.py +++ /dev/null @@ -1,315 +0,0 @@ -# source: http://stackoverflow.com/questions/2758159/how-to-embed-a-python-interpreter-in-a-pyqt-widget - -import sys, os, re -import traceback, platform -from PyQt4 import QtCore -from PyQt4 import QtGui -from electrum import util - - -if platform.system() == 'Windows': - MONOSPACE_FONT = 'Lucida Console' -elif platform.system() == 'Darwin': - MONOSPACE_FONT = 'Monaco' -else: - MONOSPACE_FONT = 'monospace' - - -class Console(QtGui.QPlainTextEdit): - def __init__(self, prompt='>> ', startup_message='', parent=None): - QtGui.QPlainTextEdit.__init__(self, parent) - - self.prompt = prompt - self.history = [] - self.namespace = {} - self.construct = [] - - self.setGeometry(50, 75, 600, 400) - self.setWordWrapMode(QtGui.QTextOption.WrapAnywhere) - self.setUndoRedoEnabled(False) - self.document().setDefaultFont(QtGui.QFont(MONOSPACE_FONT, 10, QtGui.QFont.Normal)) - self.showMessage(startup_message) - - self.updateNamespace({'run':self.run_script}) - self.set_json(False) - - def set_json(self, b): - self.is_json = b - - def run_script(self, filename): - with open(filename) as f: - script = f.read() - result = eval(script, self.namespace, self.namespace) - - - - def updateNamespace(self, namespace): - self.namespace.update(namespace) - - def showMessage(self, message): - self.appendPlainText(message) - self.newPrompt() - - def clear(self): - self.setPlainText('') - self.newPrompt() - - def newPrompt(self): - if self.construct: - prompt = '.' * len(self.prompt) - else: - prompt = self.prompt - - self.completions_pos = self.textCursor().position() - self.completions_visible = False - - self.appendPlainText(prompt) - self.moveCursor(QtGui.QTextCursor.End) - - def getCommand(self): - doc = self.document() - curr_line = unicode(doc.findBlockByLineNumber(doc.lineCount() - 1).text()) - curr_line = curr_line.rstrip() - curr_line = curr_line[len(self.prompt):] - return curr_line - - def setCommand(self, command): - if self.getCommand() == command: - return - - doc = self.document() - curr_line = unicode(doc.findBlockByLineNumber(doc.lineCount() - 1).text()) - self.moveCursor(QtGui.QTextCursor.End) - for i in range(len(curr_line) - len(self.prompt)): - self.moveCursor(QtGui.QTextCursor.Left, QtGui.QTextCursor.KeepAnchor) - - self.textCursor().removeSelectedText() - self.textCursor().insertText(command) - self.moveCursor(QtGui.QTextCursor.End) - - - def show_completions(self, completions): - if self.completions_visible: - self.hide_completions() - - c = self.textCursor() - c.setPosition(self.completions_pos) - - completions = map(lambda x: x.split('.')[-1], completions) - t = '\n' + ' '.join(completions) - if len(t) > 500: - t = t[:500] + '...' - c.insertText(t) - self.completions_end = c.position() - - self.moveCursor(QtGui.QTextCursor.End) - self.completions_visible = True - - - def hide_completions(self): - if not self.completions_visible: - return - c = self.textCursor() - c.setPosition(self.completions_pos) - l = self.completions_end - self.completions_pos - for x in range(l): c.deleteChar() - - self.moveCursor(QtGui.QTextCursor.End) - self.completions_visible = False - - - def getConstruct(self, command): - if self.construct: - prev_command = self.construct[-1] - self.construct.append(command) - if not prev_command and not command: - ret_val = '\n'.join(self.construct) - self.construct = [] - return ret_val - else: - return '' - else: - if command and command[-1] == (':'): - self.construct.append(command) - return '' - else: - return command - - def getHistory(self): - return self.history - - def setHisory(self, history): - self.history = history - - def addToHistory(self, command): - if command.find("importprivkey") > -1: - return - - if command and (not self.history or self.history[-1] != command): - self.history.append(command) - self.history_index = len(self.history) - - def getPrevHistoryEntry(self): - if self.history: - self.history_index = max(0, self.history_index - 1) - return self.history[self.history_index] - return '' - - def getNextHistoryEntry(self): - if self.history: - hist_len = len(self.history) - self.history_index = min(hist_len, self.history_index + 1) - if self.history_index < hist_len: - return self.history[self.history_index] - return '' - - def getCursorPosition(self): - c = self.textCursor() - return c.position() - c.block().position() - len(self.prompt) - - def setCursorPosition(self, position): - self.moveCursor(QtGui.QTextCursor.StartOfLine) - for i in range(len(self.prompt) + position): - self.moveCursor(QtGui.QTextCursor.Right) - - def register_command(self, c, func): - methods = { c: func} - self.updateNamespace(methods) - - - 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("'%s' is a function. Type '%s()' to use it in the Python console."%(command, command)) - self.newPrompt() - return - - sys.stdout = stdoutProxy(self.appendPlainText) - try: - try: - result = eval(command, self.namespace, self.namespace) - if result != None: - if self.is_json: - util.print_json(result) - else: - self.appendPlainText(repr(result)) - except SyntaxError: - exec command in self.namespace - except SystemExit: - self.close() - except: - 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 keyPressEvent(self, event): - if event.key() == QtCore.Qt.Key_Tab: - self.completions() - return - - self.hide_completions() - - if event.key() in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return): - self.runCommand() - return - if event.key() == QtCore.Qt.Key_Home: - self.setCursorPosition(0) - return - if event.key() == QtCore.Qt.Key_PageUp: - return - elif event.key() in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Backspace): - if self.getCursorPosition() == 0: - return - elif event.key() == QtCore.Qt.Key_Up: - self.setCommand(self.getPrevHistoryEntry()) - return - elif event.key() == QtCore.Qt.Key_Down: - self.setCommand(self.getNextHistoryEntry()) - return - elif event.key() == QtCore.Qt.Key_L and event.modifiers() == QtCore.Qt.ControlModifier: - self.clear() - - super(Console, self).keyPressEvent(event) - - - - def completions(self): - cmd = self.getCommand() - lastword = re.split(' |\(|\)',cmd)[-1] - beginning = cmd[0:-len(lastword)] - - path = lastword.split('.') - ns = self.namespace.keys() - - if len(path) == 1: - ns = ns - prefix = '' - else: - obj = self.namespace.get(path[0]) - prefix = path[0] + '.' - ns = dir(obj) - - - completions = [] - for x in ns: - if x[0] == '_':continue - xx = prefix + x - if xx.startswith(lastword): - completions.append(xx) - completions.sort() - - if not completions: - self.hide_completions() - elif len(completions) == 1: - self.hide_completions() - self.setCommand(beginning + completions[0]) - else: - # find common prefix - p = os.path.commonprefix(completions) - if len(p)>len(lastword): - self.hide_completions() - self.setCommand(beginning + p) - else: - self.show_completions(completions) - - -welcome_message = ''' - --------------------------------------------------------------- - Welcome to a primitive Python interpreter. - --------------------------------------------------------------- -''' - -if __name__ == '__main__': - app = QtGui.QApplication(sys.argv) - console = Console(startup_message=welcome_message) - console.updateNamespace({'myVar1' : app, 'myVar2' : 1234}) - console.show(); - sys.exit(app.exec_()) diff --git a/gui/gui_stdio.py b/gui/gui_stdio.py deleted file mode 100644 index f252a8af5..000000000 --- a/gui/gui_stdio.py +++ /dev/null @@ -1,252 +0,0 @@ -from decimal import Decimal -_ = lambda x:x -#from i18n import _ -from electrum import mnemonic_encode, WalletStorage, Wallet -from electrum.util import format_satoshis, set_verbosity -from electrum.bitcoin import is_valid -from electrum.network import filter_protocol -import sys, getpass, datetime - -# minimal fdisk like gui for console usage -# written by rofl0r, with some bits stolen from the text gui (ncurses) - -class ElectrumGui: - - def __init__(self, config, network): - self.network = network - self.config = config - storage = WalletStorage(config) - if not storage.file_exists: - print "Wallet not found. try 'electrum create'" - exit() - - self.done = 0 - self.last_balance = "" - - set_verbosity(False) - - self.str_recipient = "" - self.str_description = "" - self.str_amount = "" - self.str_fee = "" - - self.wallet = Wallet(storage) - self.wallet.start_threads(network) - - self.wallet.network.register_callback('updated', self.updated) - self.wallet.network.register_callback('connected', self.connected) - self.wallet.network.register_callback('disconnected', self.disconnected) - self.wallet.network.register_callback('disconnecting', self.disconnecting) - self.wallet.network.register_callback('peers', self.peers) - self.wallet.network.register_callback('banner', self.print_banner) - self.commands = [_("[h] - displays this help text"), \ - _("[i] - display transaction history"), \ - _("[o] - enter payment order"), \ - _("[p] - print stored payment order"), \ - _("[s] - send stored payment order"), \ - _("[r] - show own receipt addresses"), \ - _("[c] - display contacts"), \ - _("[b] - print server banner"), \ - _("[q] - quit") ] - self.num_commands = len(self.commands) - - def main_command(self): - self.print_balance() - c = raw_input("enter command: ") - if c == "h" : self.print_commands() - elif c == "i" : self.print_history() - elif c == "o" : self.enter_order() - elif c == "p" : self.print_order() - elif c == "s" : self.send_order() - elif c == "r" : self.print_addresses() - elif c == "c" : self.print_contacts() - elif c == "b" : self.print_banner() - elif c == "n" : self.network_dialog() - elif c == "e" : self.settings_dialog() - elif c == "q" : self.done = 1 - else: self.print_commands() - - def peers(self): - print("got peers list:") - l = filter_protocol(self.wallet.network.get_servers(), 's') - for s in l: - print (s) - - def connected(self): - print ("connected") - - def disconnected(self): - print ("disconnected") - - def disconnecting(self): - print ("disconnecting") - - def updated(self): - s = self.get_balance() - if s != self.last_balance: - print(s) - self.last_balance = s - return True - - def print_commands(self): - self.print_list(self.commands, "Available commands") - - def print_history(self): - width = [20, 40, 14, 14] - delta = (80 - sum(width) - 4)/3 - format_str = "%"+"%d"%width[0]+"s"+"%"+"%d"%(width[1]+delta)+"s"+"%" \ - + "%d"%(width[2]+delta)+"s"+"%"+"%d"%(width[3]+delta)+"s" - b = 0 - messages = [] - - for item in self.wallet.get_tx_history(): - tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item - if confirmations: - try: - time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except: - time_str = "unknown" - else: - time_str = 'pending' - - label, is_default_label = self.wallet.get_label(tx_hash) - messages.append( format_str%( time_str, label, format_satoshis(value, whitespaces=True), format_satoshis(balance, whitespaces=True) ) ) - - self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance"))) - - - def print_balance(self): - print(self.get_balance()) - - def get_balance(self): - if self.wallet.network.interface and self.wallet.network.interface.is_connected: - if not self.wallet.up_to_date: - msg = _( "Synchronizing..." ) - else: - c, u = self.wallet.get_balance() - msg = _("Balance")+": %f "%(Decimal( c ) / 100000000) - if u: msg += " [%f unconfirmed]"%(Decimal( u ) / 100000000) - else: - msg = _( "Not connected" ) - - return(msg) - - - def print_contacts(self): - messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook) - self.print_list(messages, "%19s %25s "%("Address", "Label")) - - def print_addresses(self): - messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses()) - self.print_list(messages, "%19s %25s "%("Address", "Label")) - - def print_order(self): - print("send order to " + self.str_recipient + ", amount: " + self.str_amount \ - + "\nfee: " + self.str_fee + ", desc: " + self.str_description) - - def enter_order(self): - self.str_recipient = raw_input("Pay to: ") - self.str_description = raw_input("Description : ") - self.str_amount = raw_input("Amount: ") - self.str_fee = raw_input("Fee: ") - - def send_order(self): - self.do_send() - - def print_banner(self): - for i, x in enumerate( self.wallet.network.banner.split('\n') ): - print( x ) - - def print_list(self, list, firstline): - self.maxpos = len(list) - if not self.maxpos: return - print(firstline) - for i in range(self.maxpos): - msg = list[i] if i < len(list) else "" - print(msg) - - - def main(self,url): - while self.done == 0: self.main_command() - - def do_send(self): - if not is_valid(self.str_recipient): - print(_('Invalid Bitcoin address')) - return - try: - amount = int( Decimal( self.str_amount) * 100000000 ) - except: - print(_('Invalid Amount')) - return - try: - fee = int( Decimal( self.str_fee) * 100000000 ) - except: - print(_('Invalid Fee')) - return - - if self.wallet.use_encryption: - password = self.password_dialog() - if not password: - return - else: - password = None - - c = "" - while c != "y": - c = raw_input("ok to send (y/n)?") - if c == "n": return - - try: - tx = self.wallet.mktx( [(self.str_recipient, amount)], password, fee) - except BaseException, e: - print(str(e)) - return - - if self.str_description: - self.wallet.labels[tx.hash()] = self.str_description - - h = self.wallet.send_tx(tx) - print(_("Please wait...")) - self.wallet.tx_event.wait() - status, msg = self.wallet.receive_tx( h ) - - if status: - print(_('Payment sent.')) - #self.do_clear() - #self.update_contacts_tab() - else: - print(_('Error')) - - def network_dialog(self): - print("use 'electrum setconfig server/proxy' to change your network settings") - return True - - - def settings_dialog(self): - print("use 'electrum setconfig' to change your settings") - return True - - def password_dialog(self): - return getpass.getpass() - - -# XXX unused - - def run_receive_tab(self, c): - #if c == 10: - # out = self.run_popup('Address', ["Edit label", "Freeze", "Prioritize"]) - return - - def run_contacts_tab(self, c): - pass -# if c == 10 and self.wallet.addressbook: -# out = self.run_popup('Adress', ["Copy", "Pay to", "Edit label", "Delete"]).get('button') -# address = self.wallet.addressbook[self.pos%len(self.wallet.addressbook)] -# if out == "Pay to": -# self.tab = 1 -# self.str_recipient = address -# self.pos = 2 -# elif out == "Edit label": -# s = self.get_string(6 + self.pos, 18) -# if s: -# self.wallet.labels[address] = s diff --git a/gui/gui_text.py b/gui/gui_text.py deleted file mode 100644 index 72ba085b2..000000000 --- a/gui/gui_text.py +++ /dev/null @@ -1,444 +0,0 @@ -import curses, datetime -from decimal import Decimal -_ = lambda x:x -#from i18n import _ -from electrum.util import format_satoshis, set_verbosity -from electrum.bitcoin import is_valid - -from electrum import Wallet, WalletStorage - -import tty, sys - - -class ElectrumGui: - - def __init__(self, config, network): - - self.config = config - self.network = network - storage = WalletStorage(config) - if not storage.file_exists: - print "Wallet not found. try 'electrum create'" - exit() - - self.wallet = Wallet(storage) - self.wallet.start_threads(network) - - self.stdscr = curses.initscr() - curses.noecho() - curses.cbreak() - curses.start_color() - curses.use_default_colors() - curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) - curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN) - self.stdscr.keypad(1) - self.stdscr.border(0) - self.maxy, self.maxx = self.stdscr.getmaxyx() - self.set_cursor(0) - self.w = curses.newwin(10, 50, 5, 5) - - set_verbosity(False) - self.tab = 0 - self.pos = 0 - self.popup_pos = 0 - - self.str_recipient = "" - self.str_description = "" - self.str_amount = "" - self.str_fee = "" - - self.network.register_callback('updated', self.refresh) - self.network.register_callback('connected', self.refresh) - self.network.register_callback('disconnected', self.refresh) - self.network.register_callback('disconnecting', self.refresh) - self.tab_names = [_("History"), _("Send"), _("Receive"), _("Contacts"), _("Wall")] - self.num_tabs = len(self.tab_names) - - - def set_cursor(self, x): - try: - curses.curs_set(x) - except: - pass - - def restore_or_create(self): - pass - - def verify_seed(self): - pass - - def get_string(self, y, x): - self.set_cursor(1) - curses.echo() - self.stdscr.addstr( y, x, " "*20, curses.A_REVERSE) - s = self.stdscr.getstr(y,x) - curses.noecho() - self.set_cursor(0) - return s - - - def print_history(self): - width = [20, 40, 14, 14] - delta = (self.maxx - sum(width) - 4)/3 - format_str = "%"+"%d"%width[0]+"s"+"%"+"%d"%(width[1]+delta)+"s"+"%"+"%d"%(width[2]+delta)+"s"+"%"+"%d"%(width[3]+delta)+"s" - - b = 0 - messages = [] - - for item in self.wallet.get_tx_history(): - tx_hash, conf, is_mine, value, fee, balance, timestamp = item - if conf: - try: - time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except: - time_str = "------" - else: - time_str = 'pending' - - label, is_default_label = self.wallet.get_label(tx_hash) - messages.append( format_str%( time_str, label, format_satoshis(value, whitespaces=True), format_satoshis(balance, whitespaces=True) ) ) - - self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance"))) - - - def print_balance(self): - if self.network.interface and self.network.interface.is_connected: - if not self.wallet.up_to_date: - msg = _( "Synchronizing..." ) - else: - c, u = self.wallet.get_balance() - msg = _("Balance")+": %f "%(Decimal( c ) / 100000000) - if u: msg += " [%f unconfirmed]"%(Decimal( u ) / 100000000) - else: - msg = _( "Not connected" ) - - self.stdscr.addstr( self.maxy -1, 3, msg) - - for i in range(self.num_tabs): - self.stdscr.addstr( 0, 2 + 2*i + len(''.join(self.tab_names[0:i])), ' '+self.tab_names[i]+' ', curses.A_BOLD if self.tab == i else 0) - - self.stdscr.addstr( self.maxy -1, self.maxx-30, ' '.join([_("Settings"), _("Network"), _("Quit")])) - - - def print_contacts(self): - messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook) - self.print_list(messages, "%19s %25s "%("Address", "Label")) - - def print_receive(self): - messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses()) - self.print_list(messages, "%19s %25s "%("Address", "Label")) - - def print_edit_line(self, y, label, text, index, size): - text += " "*(size - len(text) ) - self.stdscr.addstr( y, 2, label) - self.stdscr.addstr( y, 15, text, curses.A_REVERSE if self.pos%6==index else curses.color_pair(1)) - - def print_send_tab(self): - self.stdscr.clear() - self.print_edit_line(3, _("Pay to"), self.str_recipient, 0, 40) - self.print_edit_line(5, _("Description"), self.str_description, 1, 40) - self.print_edit_line(7, _("Amount"), self.str_amount, 2, 15) - self.print_edit_line(9, _("Fee"), self.str_fee, 3, 15) - self.stdscr.addstr( 12, 15, _("[Send]"), curses.A_REVERSE if self.pos%6==4 else curses.color_pair(2)) - self.stdscr.addstr( 12, 25, _("[Clear]"), curses.A_REVERSE if self.pos%6==5 else curses.color_pair(2)) - - def print_banner(self): - for i, x in enumerate( self.network.banner.split('\n') ): - self.stdscr.addstr( 1+i, 1, x ) - - def print_list(self, list, firstline): - self.maxpos = len(list) - if not self.maxpos: return - firstline += " "*(self.maxx -2 - len(firstline)) - self.stdscr.addstr( 1, 1, firstline ) - for i in range(self.maxy-4): - msg = list[i] if i < len(list) else "" - msg += " "*(self.maxx - 2 - len(msg)) - self.stdscr.addstr( i+2, 1, msg[0:self.maxx - 2], curses.A_REVERSE if i == (self.pos % self.maxpos) else 0) - - def refresh(self): - if self.tab == -1: return - self.stdscr.border(0) - self.print_balance() - self.stdscr.refresh() - - def main_command(self): - c = self.stdscr.getch() - print c - if c == curses.KEY_RIGHT: self.tab = (self.tab + 1)%self.num_tabs - elif c == curses.KEY_LEFT: self.tab = (self.tab - 1)%self.num_tabs - elif c == curses.KEY_DOWN: self.pos +=1 - elif c == curses.KEY_UP: self.pos -= 1 - elif c == 9: self.pos +=1 # tab - elif curses.unctrl(c) in ['^W', '^C', '^X', '^Q']: self.tab = -1 - elif curses.unctrl(c) in ['^N']: self.network_dialog() - elif curses.unctrl(c) == '^S': self.settings_dialog() - else: return c - if self.pos<0: self.pos=0 - if self.pos>=self.maxpos: self.pos=self.maxpos - 1 - - def run_tab(self, i, print_func, exec_func): - while self.tab == i: - self.stdscr.clear() - print_func() - self.refresh() - c = self.main_command() - if c: exec_func(c) - - - def run_history_tab(self, c): - if c == 10: - out = self.run_popup('',["blah","foo"]) - - - def edit_str(self, target, c, is_num=False): - # detect backspace - if c in [8, 127, 263] and target: - target = target[:-1] - elif not is_num or curses.unctrl(c) in '0123456789.': - target += curses.unctrl(c) - return target - - - def run_send_tab(self, c): - if self.pos%6 == 0: - self.str_recipient = self.edit_str(self.str_recipient, c) - if self.pos%6 == 1: - self.str_description = self.edit_str(self.str_description, c) - if self.pos%6 == 2: - self.str_amount = self.edit_str(self.str_amount, c, True) - elif self.pos%6 == 3: - self.str_fee = self.edit_str(self.str_fee, c, True) - elif self.pos%6==4: - if c == 10: self.do_send() - elif self.pos%6==5: - if c == 10: self.do_clear() - - - def run_receive_tab(self, c): - if c == 10: - out = self.run_popup('Address', ["Edit label", "Freeze", "Prioritize"]) - - def run_contacts_tab(self, c): - if c == 10 and self.wallet.addressbook: - out = self.run_popup('Adress', ["Copy", "Pay to", "Edit label", "Delete"]).get('button') - address = self.wallet.addressbook[self.pos%len(self.wallet.addressbook)] - if out == "Pay to": - self.tab = 1 - self.str_recipient = address - self.pos = 2 - elif out == "Edit label": - s = self.get_string(6 + self.pos, 18) - if s: - self.wallet.labels[address] = s - - def run_banner_tab(self, c): - self.show_message(repr(c)) - pass - - def main(self,url): - - tty.setraw(sys.stdin) - while self.tab != -1: - self.run_tab(0, self.print_history, self.run_history_tab) - self.run_tab(1, self.print_send_tab, self.run_send_tab) - self.run_tab(2, self.print_receive, self.run_receive_tab) - self.run_tab(3, self.print_contacts, self.run_contacts_tab) - self.run_tab(4, self.print_banner, self.run_banner_tab) - - tty.setcbreak(sys.stdin) - curses.nocbreak() - self.stdscr.keypad(0) - curses.echo() - curses.endwin() - - - def do_clear(self): - self.str_amount = '' - self.str_recipient = '' - self.str_fee = '' - self.str_description = '' - - def do_send(self): - if not is_valid(self.str_recipient): - self.show_message(_('Invalid Bitcoin address')) - return - try: - amount = int( Decimal( self.str_amount) * 100000000 ) - except: - self.show_message(_('Invalid Amount')) - return - try: - fee = int( Decimal( self.str_fee) * 100000000 ) - except: - self.show_message(_('Invalid Fee')) - return - - if self.wallet.use_encryption: - password = self.password_dialog() - if not password: - return - else: - password = None - - try: - tx = self.wallet.mktx( [(self.str_recipient, amount)], password, fee) - except BaseException, e: - self.show_message(str(e)) - return - - if self.str_description: - self.wallet.labels[tx.hash()] = self.str_description - - h = self.wallet.send_tx(tx) - self.show_message(_("Please wait..."), getchar=False) - self.wallet.tx_event.wait() - status, msg = self.wallet.receive_tx( h ) - - if status: - self.show_message(_('Payment sent.')) - self.do_clear() - #self.update_contacts_tab() - else: - self.show_message(_('Error')) - - - def show_message(self, message, getchar = True): - w = self.w - w.clear() - w.border(0) - w.addstr(2,2,message) - w.refresh() - if getchar: c = self.stdscr.getch() - - - def run_popup(self, title, items): - return self.run_dialog(title, map(lambda x: {'type':'button','label':x}, items), interval=1, y_pos = self.pos+3) - - - def network_dialog(self): - out = self.run_dialog('Network', [ - {'label':'server', 'type':'str', 'value':self.network.interface.server}, - {'label':'proxy', 'type':'str', 'value':self.config.get('proxy', '')}, - ], buttons = 1) - if out: - if out.get('server'): - server = out.get('server') - if out.get('proxy'): - proxy = self.parse_proxy_options(out.get('proxy')) - else: - proxy = None - - self.wallet.config.set_key("proxy", proxy, True) - self.wallet.config.set_key("server", server, True) - self.network.interface.set_server(server, proxy) - - - - def settings_dialog(self): - out = self.run_dialog('Settings', [ - {'label':'Default GUI', 'type':'list', 'choices':['classic','lite','gtk','text'], 'value':self.config.get('gui')}, - {'label':'Default fee', 'type':'satoshis', 'value': format_satoshis(self.wallet.fee).strip() } - ], buttons = 1) - if out: - if out.get('Default GUI'): - self.config.set_key('gui', out['Default GUI'], True) - if out.get('Default fee'): - fee = int ( Decimal( out['Default fee']) *10000000 ) - self.config.set_key('fee_per_kb', fee, True) - - - def password_dialog(self): - out = self.run_dialog('Password', [ - {'label':'Password', 'type':'password', 'value':''} - ], buttons = 1) - return out.get('Password') - - - def run_dialog(self, title, items, interval=2, buttons=None, y_pos=3): - self.popup_pos = 0 - - self.w = curses.newwin( 5 + len(items)*interval + (2 if buttons else 0), 50, y_pos, 5) - w = self.w - out = {} - while True: - w.clear() - w.border(0) - w.addstr( 0, 2, title) - - num = len(items) - - numpos = num - if buttons: numpos += 2 - - for i in range(num): - item = items[i] - label = item.get('label') - if item.get('type') == 'list': - value = item.get('value','') - elif item.get('type') == 'satoshis': - value = item.get('value','') - elif item.get('type') == 'str': - value = item.get('value','') - elif item.get('type') == 'password': - value = '*'*len(item.get('value','')) - else: - value = '' - - if len(value)<20: value += ' '*(20-len(value)) - - if item.has_key('value'): - w.addstr( 2+interval*i, 2, label) - w.addstr( 2+interval*i, 15, value, curses.A_REVERSE if self.popup_pos%numpos==i else curses.color_pair(1) ) - else: - w.addstr( 2+interval*i, 2, label, curses.A_REVERSE if self.popup_pos%numpos==i else 0) - - if buttons: - w.addstr( 5+interval*i, 10, "[ ok ]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-2) else curses.color_pair(2)) - w.addstr( 5+interval*i, 25, "[cancel]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-1) else curses.color_pair(2)) - - w.refresh() - - c = self.stdscr.getch() - if c in [ord('q'), 27]: break - elif c in [curses.KEY_LEFT, curses.KEY_UP]: self.popup_pos -= 1 - elif c in [curses.KEY_RIGHT, curses.KEY_DOWN]: self.popup_pos +=1 - else: - i = self.popup_pos%numpos - if buttons and c==10: - if i == numpos-2: - return out - elif i == numpos -1: - return {} - - item = items[i] - _type = item.get('type') - - if _type == 'str': - item['value'] = self.edit_str(item['value'], c) - out[item.get('label')] = item.get('value') - - elif _type == 'password': - item['value'] = self.edit_str(item['value'], c) - out[item.get('label')] = item ['value'] - - elif _type == 'satoshis': - item['value'] = self.edit_str(item['value'], c, True) - out[item.get('label')] = item.get('value') - - elif _type == 'list': - choices = item.get('choices') - try: - j = choices.index(item.get('value')) - except: - j = 0 - new_choice = choices[(j + 1)% len(choices)] - item['value'] = new_choice - out[item.get('label')] = item.get('value') - - elif _type == 'button': - out['button'] = item.get('label') - break - - return out - diff --git a/gui/gui_classic/__init__.py b/gui/qt/__init__.py similarity index 99% rename from gui/gui_classic/__init__.py rename to gui/qt/__init__.py index 101535a58..486513546 100644 --- a/gui/gui_classic/__init__.py +++ b/gui/qt/__init__.py @@ -42,7 +42,7 @@ try: except: sys.exit("Error: Could not import icons_rc.py, please generate it with: 'pyrcc4 icons.qrc -o gui/gui_classic/icons_rc.py'") -from qt_util import * +from util import * from main_window import ElectrumWindow from electrum.plugins import init_plugins diff --git a/gui/gui_classic/amountedit.py b/gui/qt/amountedit.py similarity index 100% rename from gui/gui_classic/amountedit.py rename to gui/qt/amountedit.py diff --git a/gui/gui_classic/history_widget.py b/gui/qt/history_widget.py similarity index 100% rename from gui/gui_classic/history_widget.py rename to gui/qt/history_widget.py diff --git a/gui/gui_classic/installwizard.py b/gui/qt/installwizard.py similarity index 100% rename from gui/gui_classic/installwizard.py rename to gui/qt/installwizard.py diff --git a/gui/gui_classic/lite_window.py b/gui/qt/lite_window.py similarity index 99% rename from gui/gui_classic/lite_window.py rename to gui/qt/lite_window.py index e28596fa0..1e2d6665d 100644 --- a/gui/gui_classic/lite_window.py +++ b/gui/qt/lite_window.py @@ -36,7 +36,7 @@ from electrum.util import format_satoshis, age from main_window import ElectrumWindow import shutil -from qt_util import * +from util import * bitcoin = lambda v: v * 100000000 diff --git a/gui/gui_classic/main_window.py b/gui/qt/main_window.py similarity index 99% rename from gui/gui_classic/main_window.py rename to gui/qt/main_window.py index 39ca42d66..2b9d72e44 100644 --- a/gui/gui_classic/main_window.py +++ b/gui/qt/main_window.py @@ -72,7 +72,7 @@ else: from electrum import ELECTRUM_VERSION import re -from qt_util import * +from util import * @@ -1210,7 +1210,7 @@ class ElectrumWindow(QMainWindow): def create_console_tab(self): - from qt_console import Console + from console import Console self.console = console = Console() return console diff --git a/gui/gui_classic/network_dialog.py b/gui/qt/network_dialog.py similarity index 99% rename from gui/gui_classic/network_dialog.py rename to gui/qt/network_dialog.py index 47bab286e..16a0927e8 100644 --- a/gui/gui_classic/network_dialog.py +++ b/gui/qt/network_dialog.py @@ -25,7 +25,7 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * from electrum import DEFAULT_SERVERS, DEFAULT_PORTS -from qt_util import * +from util import * protocol_names = ['TCP', 'HTTP', 'SSL', 'HTTPS'] protocol_letters = 'thsg' diff --git a/gui/gui_classic/password_dialog.py b/gui/qt/password_dialog.py similarity index 100% rename from gui/gui_classic/password_dialog.py rename to gui/qt/password_dialog.py diff --git a/gui/gui_classic/qrcodewidget.py b/gui/qt/qrcodewidget.py similarity index 100% rename from gui/gui_classic/qrcodewidget.py rename to gui/qt/qrcodewidget.py diff --git a/gui/gui_classic/receiving_widget.py b/gui/qt/receiving_widget.py similarity index 100% rename from gui/gui_classic/receiving_widget.py rename to gui/qt/receiving_widget.py diff --git a/gui/gui_classic/seed_dialog.py b/gui/qt/seed_dialog.py similarity index 100% rename from gui/gui_classic/seed_dialog.py rename to gui/qt/seed_dialog.py diff --git a/gui/gui_classic/transaction_dialog.py b/gui/qt/transaction_dialog.py similarity index 100% rename from gui/gui_classic/transaction_dialog.py rename to gui/qt/transaction_dialog.py diff --git a/gui/gui_classic/qt_util.py b/gui/qt/util.py similarity index 100% rename from gui/gui_classic/qt_util.py rename to gui/qt/util.py diff --git a/gui/gui_classic/version_getter.py b/gui/qt/version_getter.py similarity index 100% rename from gui/gui_classic/version_getter.py rename to gui/qt/version_getter.py diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index fe91bcd31..9436180c8 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -9,7 +9,7 @@ import re from decimal import Decimal from electrum.plugins import BasePlugin from electrum.i18n import _ -from electrum_gui.gui_classic.qt_util import * +from electrum_gui.qt.util import * class Exchanger(threading.Thread): diff --git a/plugins/labels.py b/plugins/labels.py index 8234ce6d3..2bcdf7e46 100644 --- a/plugins/labels.py +++ b/plugins/labels.py @@ -20,7 +20,7 @@ from electrum import bmp, pyqrnative from electrum.plugins import BasePlugin from electrum.i18n import _ -from electrum_gui.gui_classic import HelpButton +from electrum_gui.qt import HelpButton class Plugin(BasePlugin): diff --git a/plugins/pointofsale.py b/plugins/pointofsale.py index 45c5d48a7..438e67208 100644 --- a/plugins/pointofsale.py +++ b/plugins/pointofsale.py @@ -7,7 +7,7 @@ from PyQt4.QtCore import * import PyQt4.QtCore as QtCore import PyQt4.QtGui as QtGui -from electrum_gui.gui_classic.qrcodewidget import QRCodeWidget +from electrum_gui.qt.qrcodewidget import QRCodeWidget from electrum import bmp, pyqrnative, BasePlugin from electrum.i18n import _ diff --git a/plugins/qrscanner.py b/plugins/qrscanner.py index d49096ea7..381405e44 100644 --- a/plugins/qrscanner.py +++ b/plugins/qrscanner.py @@ -7,7 +7,7 @@ from electrum.i18n import _ import re from electrum import Transaction from electrum.bitcoin import MIN_RELAY_TX_FEE, is_valid -from electrum_gui.gui_classic.qrcodewidget import QRCodeWidget +from electrum_gui.qt.qrcodewidget import QRCodeWidget from electrum import bmp import json diff --git a/setup.py b/setup.py index 7949f9768..8f8ffcafc 100644 --- a/setup.py +++ b/setup.py @@ -74,25 +74,26 @@ setup(name = "Electrum", 'electrum.i18n', 'electrum.pyqrnative', 'electrum.plugins', - 'electrum_gui.gui_gtk', - 'electrum_gui.gui_text', - 'electrum_gui.gui_classic', - 'electrum_gui.gui_classic.qt_console', - 'electrum_gui.gui_classic.lite_window', - 'electrum_gui.gui_classic.main_window', - 'electrum_gui.gui_classic.installwizard', - 'electrum_gui.gui_classic.icons_rc', - 'electrum_gui.gui_classic.qrcodewidget', - 'electrum_gui.gui_classic.history_widget', - 'electrum_gui.gui_classic.receiving_widget', - 'electrum_gui.gui_classic.qt_util', - 'electrum_gui.gui_classic.network_dialog', - 'electrum_gui.gui_classic.password_dialog', - 'electrum_gui.gui_classic.seed_dialog', - 'electrum_gui.gui_classic.transaction dialog', - 'electrum_gui.gui_classic.version_getter', - 'electrum_gui.gui_classic.amountedit', - #'electrum_plugins.aliases', + 'electrum_gui.gtk', + 'electrum_gui.text', + 'electrum_gui.qt', + 'electrum_gui.qt.amountedit', + 'electrum_gui.qt.console', + 'electrum_gui.qt.history_widget', + 'electrum_gui.qt.installwizard', + 'electrum_gui.qt.icons_rc', + 'electrum_gui.qt.lite_window', + 'electrum_gui.qt.main_window', + 'electrum_gui.qt.network_dialog', + 'electrum_gui.qt.password_dialog', + 'electrum_gui.qt.qrcodewidget', + 'electrum_gui.qt.receiving_widget', + 'electrum_gui.qt.seed_dialog', + 'electrum_gui.qt.transaction dialog', + 'electrum_gui.qt.util', + 'electrum_gui.qt.version_getter', + 'electrum_gui.stdio', + 'electrum_plugins.aliases', 'electrum_plugins.exchange_rate', 'electrum_plugins.labels', 'electrum_plugins.pointofsale',