import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui
-from electrum_gui.qrcodewidget import QRCodeWidget
-from electrum_gui import bmp, pyqrnative
+from electrum_gui.qt.qrcodewidget import QRCodeWidget
-from electrum_gui.i18n import _
+from electrum import bmp, pyqrnative, BasePlugin
+from electrum.i18n import _
if platform.system() == 'Windows':
self.qrw.set_addr( msg )
-
-config = {}
-def get_info():
- return 'Point of Sale', _('Show QR code window and amounts requested for each address. Add menu item to request amount.')
+class Plugin(BasePlugin):
+
+ def fullname(self):
+ return 'Point of Sale'
-def init(gui):
- global config
- config = gui.config
- gui.requested_amounts = config.get('requested_amounts',{})
- gui.merchant_name = config.get('merchant_name', 'Invoice')
- gui.qr_window = None
- do_enable(gui, is_enabled())
+ def description(self):
+ return _('Show QR code window and amounts requested for each address. Add menu item to request amount.')+_(' Note: This requires the exchange rate plugin to be installed.')
-def is_enabled():
- return config.get('pointofsale') is True
+ def init(self):
+ self.window = self.gui.main_window
+ self.wallet = self.window.wallet
-def is_available():
- return True
+ self.qr_window = None
+ self.merchant_name = self.config.get('merchant_name', 'Invoice')
+ self.window.expert_mode = True
+ self.window.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Request')])
+ self.requested_amounts = {}
+ self.toggle_QR_window(True)
-def toggle(gui):
- enabled = not is_enabled()
- config.set_key('pointofsale', enabled, True)
- do_enable(gui, enabled)
- update_gui(gui)
- return enabled
+ def enable(self):
+ if not self.config.get('use_exchange_rate'):
+ self.gui.main_window.show_message("Please enable exchange rates first!")
+ return False
+ return BasePlugin.enable(self)
-def do_enable(gui, enabled):
- if enabled:
- gui.expert_mode = True
- gui.set_hook('item_changed', item_changed)
- gui.set_hook('current_item_changed', recv_changed)
- gui.set_hook('receive_menu', receive_menu)
- gui.set_hook('update_receive_item', update_receive_item)
- gui.set_hook('timer_actions', timer_actions)
- gui.set_hook('close_main_window', close_main_window)
- gui.set_hook('init', update_gui)
- else:
- gui.unset_hook('item_changed', item_changed)
- gui.unset_hook('current_item_changed', recv_changed)
- gui.unset_hook('receive_menu', receive_menu)
- gui.unset_hook('update_receive_item', update_receive_item)
- gui.unset_hook('timer_actions', timer_actions)
- gui.unset_hook('close_main_window', close_main_window)
- gui.unset_hook('init', update_gui)
+ def load_wallet(self, wallet):
+ self.wallet = wallet
+ self.requested_amounts = self.wallet.storage.get('requested_amounts',{})
+ def close(self):
+ self.window.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')])
+ self.toggle_QR_window(False)
+
-def update_gui(gui):
- enabled = is_enabled()
- if enabled:
- gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Request')])
- else:
- gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')])
+ def close_main_window(self):
+ if self.qr_window:
+ self.qr_window.close()
+ self.qr_window = None
- toggle_QR_window(gui, enabled)
+ def timer_actions(self):
+ if self.qr_window:
+ self.qr_window.qrw.update_qr()
+
+
+ def toggle_QR_window(self, show):
+ if show and not self.qr_window:
+ self.qr_window = QR_Window(self.gui.exchanger)
+ self.qr_window.setVisible(True)
+ self.qr_window_geometry = self.qr_window.geometry()
+ item = self.window.receive_list.currentItem()
+ if item:
+ address = str(item.text(1))
+ label = self.wallet.labels.get(address)
+ amount, currency = self.requested_amounts.get(address, (None, None))
+ self.qr_window.set_content( address, label, amount, currency )
+ elif show and self.qr_window and not self.qr_window.isVisible():
+ self.qr_window.setVisible(True)
+ self.qr_window.setGeometry(self.qr_window_geometry)
-def toggle_QR_window(self, show):
- if show and not self.qr_window:
- self.qr_window = QR_Window(self.exchanger)
- self.qr_window.setVisible(True)
- self.qr_window_geometry = self.qr_window.geometry()
- item = self.receive_list.currentItem()
- if item:
- address = str(item.text(1))
- label = self.wallet.labels.get(address)
- amount, currency = self.requested_amounts.get(address, (None, None))
- self.qr_window.set_content( address, label, amount, currency )
+ elif not show and self.qr_window and self.qr_window.isVisible():
+ self.qr_window_geometry = self.qr_window.geometry()
+ self.qr_window.setVisible(False)
- elif show and self.qr_window and not self.qr_window.isVisible():
- self.qr_window.setVisible(True)
- self.qr_window.setGeometry(self.qr_window_geometry)
- elif not show and self.qr_window and self.qr_window.isVisible():
- self.qr_window_geometry = self.qr_window.geometry()
- self.qr_window.setVisible(False)
+
+ def update_receive_item(self, address, item):
+ try:
+ amount, currency = self.requested_amounts.get(address, (None, None))
+ except:
+ print "cannot get requested amount", address, self.requested_amounts.get(address)
+ amount, currency = None, None
+ self.requested_amounts.pop(address)
+
+ amount_str = amount + (' ' + currency if currency else '') if amount is not None else ''
+ item.setData(column_index,0,amount_str)
+
+ def current_item_changed(self, a):
+ if not self.wallet:
+ return
+ if a is not None and self.qr_window and self.qr_window.isVisible():
+ address = str(a.text(0))
+ label = self.wallet.labels.get(address)
+ try:
+ amount, currency = self.requested_amounts.get(address, (None, None))
+ except:
+ amount, currency = None, None
+ self.qr_window.set_content( address, label, amount, currency )
-def item_changed(self, item, column):
- if column == column_index:
+
+ def item_changed(self, item, column):
+ if column != column_index:
+ return
address = str( item.text(0) )
text = str( item.text(column) )
try:
seq = self.wallet.get_address_index(address)
- index = seq[-1]
+ index = seq[1][1]
except:
print "cannot get index"
return
text = text.strip().upper()
print text
- m = re.match('^(\d+(|\.\d*))\s*(|BTC|EUR|USD|GBP|CNY|JPY|RUB|BRL)$', text)
- if m:
+ m = re.match('^(\d*(|\.\d*))\s*(|BTC|EUR|USD|GBP|CNY|JPY|RUB|BRL)$', text)
+ if m and m.group(1) and m.group(1)!='.':
amount = m.group(1)
currency = m.group(3)
if not currency:
currency = currency.upper()
self.requested_amounts[address] = (amount, currency)
- self.wallet.config.set_key('requested_amounts', self.requested_amounts, True)
+ self.wallet.storage.put('requested_amounts', self.requested_amounts, True)
label = self.wallet.labels.get(address)
if label is None:
if address in self.requested_amounts:
self.requested_amounts.pop(address)
- self.update_receive_item(self.receive_list.currentItem())
-
-
-def recv_changed(self, a):
- if a is not None and self.qr_window and self.qr_window.isVisible():
- address = str(a.text(0))
- label = self.wallet.labels.get(address)
- try:
- amount, currency = self.requested_amounts.get(address, (None, None))
- except:
- amount, currency = None, None
- self.qr_window.set_content( address, label, amount, currency )
-
-
+ self.window.update_receive_item(self.window.receive_list.currentItem())
-def edit_amount(self):
- l = self.receive_list
- item = l.currentItem()
- item.setFlags(Qt.ItemIsEditable|Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled)
- l.editItem( item, column_index )
- item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled)
-def receive_menu(self, menu):
- menu.addAction(_("Request amount"), lambda: edit_amount(self))
-def update_receive_item(self, address, item):
- try:
- amount, currency = self.requested_amounts.get(address, (None, None))
- except:
- print "cannot get requested amount", address, self.requested_amounts.get(address)
- amount, currency = None, None
- self.requested_amounts.pop(address)
+ def edit_amount(self):
+ l = self.window.receive_list
+ item = l.currentItem()
+ item.setFlags(Qt.ItemIsEditable|Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled)
+ l.editItem( item, column_index )
+ item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled)
- amount_str = amount + (' ' + currency if currency else '') if amount is not None else ''
- item.setData(column_index,0,amount_str)
-
-
-def close_main_window(self):
- if self.qr_window:
- self.qr_window.close()
- self.qr_window = None
+
+ def receive_menu(self, menu):
+ menu.addAction(_("Request amount"), self.edit_amount)
-def timer_actions(self):
- if self.qr_window:
- self.qr_window.qrw.update_qr()