1
0

new kivy gui

This commit is contained in:
ThomasV
2018-03-06 14:58:00 +01:00
parent ba3ac1b648
commit c750ec153b
12 changed files with 600 additions and 454 deletions

View File

@@ -390,205 +390,10 @@ class ReceiveScreen(CScreen):
addr = self.get_new_address()
if not addr:
self.app.show_info(_('Please use the existing requests first.'))
else:
self.save_request()
self.app.show_info(_('New request added to your list.'))
invoice_text = {
PR_UNPAID:_('Pending'),
PR_UNKNOWN:_('Unknown'),
PR_PAID:_('Paid'),
PR_EXPIRED:_('Expired')
}
request_text = {
PR_UNPAID: _('Pending'),
PR_UNKNOWN: _('Unknown'),
PR_PAID: _('Received'),
PR_EXPIRED: _('Expired')
}
pr_icon = {
PR_UNPAID: 'atlas://gui/kivy/theming/light/important',
PR_UNKNOWN: 'atlas://gui/kivy/theming/light/important',
PR_PAID: 'atlas://gui/kivy/theming/light/confirmed',
PR_EXPIRED: 'atlas://gui/kivy/theming/light/close'
}
class InvoicesScreen(CScreen):
kvname = 'invoices'
cards = {}
def get_card(self, pr):
key = pr.get_id()
ci = self.cards.get(key)
if ci is None:
ci = Factory.InvoiceItem()
ci.key = key
ci.screen = self
self.cards[key] = ci
ci.requestor = pr.get_requestor()
ci.memo = pr.get_memo()
amount = pr.get_amount()
if amount:
ci.amount = self.app.format_amount_and_units(amount)
status = self.app.wallet.invoices.get_status(ci.key)
ci.status = invoice_text[status]
ci.icon = pr_icon[status]
else:
ci.amount = _('No Amount')
ci.status = ''
exp = pr.get_expiration_date()
ci.date = format_time(exp) if exp else _('Never')
return ci
def update(self):
self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view), ('Delete', self.do_delete)]
invoices_list = self.screen.ids.invoices_container
invoices_list.clear_widgets()
_list = self.app.wallet.invoices.sorted_list()
for pr in _list:
ci = self.get_card(pr)
invoices_list.add_widget(ci)
if not _list:
msg = _('This screen shows the list of payment requests that have been sent to you. You may also use it to store contact addresses.')
invoices_list.add_widget(EmptyLabel(text=msg))
def do_pay(self, obj):
pr = self.app.wallet.invoices.get(obj.key)
self.app.on_pr(pr)
def do_view(self, obj):
pr = self.app.wallet.invoices.get(obj.key)
pr.verify(self.app.wallet.contacts)
self.app.show_pr_details(pr.get_dict(), obj.status, True)
def do_delete(self, obj):
from .dialogs.question import Question
def cb(result):
if result:
self.app.wallet.invoices.remove(obj.key)
self.app.update_tab('invoices')
d = Question(_('Delete invoice?'), cb)
d.open()
address_icon = {
'Pending' : 'atlas://gui/kivy/theming/light/important',
'Paid' : 'atlas://gui/kivy/theming/light/confirmed'
}
class AddressScreen(CScreen):
kvname = 'address'
cards = {}
def get_card(self, addr, balance, is_used, label):
ci = self.cards.get(addr)
if ci is None:
ci = Factory.AddressItem()
ci.screen = self
ci.address = addr
self.cards[addr] = ci
ci.memo = label
ci.amount = self.app.format_amount_and_units(balance)
request = self.app.wallet.get_payment_request(addr, self.app.electrum_config)
if is_used:
ci.status = _('Used')
elif request:
status, conf = self.app.wallet.get_request_status(addr)
requested_amount = request.get('amount')
# make sure that requested amount is > 0
if status == PR_PAID:
s = _('Request paid')
elif status == PR_UNPAID:
s = _('Request pending')
elif status == PR_EXPIRED:
s = _('Request expired')
else:
s = ''
ci.status = s + ': ' + self.app.format_amount_and_units(requested_amount)
else:
ci.status = _('Funded') if balance>0 else _('Unused')
return ci
def update(self):
self.menu_actions = [('Receive', self.do_show), ('Details', self.do_view)]
wallet = self.app.wallet
if self.screen.show_change == 0:
_list = wallet.get_receiving_addresses()
elif self.screen.show_change == 1:
_list = wallet.get_change_addresses()
else:
_list = wallet.get_addresses()
search = self.screen.message
container = self.screen.ids.search_container
container.clear_widgets()
n = 0
for address in _list:
label = wallet.labels.get(address, '')
balance = sum(wallet.get_addr_balance(address))
is_used = wallet.is_used(address)
if self.screen.show_used == 1 and (balance or is_used):
continue
if self.screen.show_used == 2 and balance == 0:
continue
if self.screen.show_used == 3 and not is_used:
continue
card = self.get_card(address, balance, is_used, label)
if search and not self.ext_search(card, search):
continue
container.add_widget(card)
n += 1
if not n:
msg = _('No address matching your search')
container.add_widget(EmptyLabel(text=msg))
def do_show(self, obj):
self.app.show_request(obj.address)
def do_view(self, obj):
req = self.app.wallet.get_payment_request(obj.address, self.app.electrum_config)
if req:
c, u, x = self.app.wallet.get_addr_balance(obj.address)
balance = c + u + x
if balance > 0:
req['fund'] = balance
status = req.get('status')
amount = req.get('amount')
address = req['address']
if amount:
status = req.get('status')
status = request_text[status]
else:
received_amount = self.app.wallet.get_addr_received(address)
status = self.app.format_amount_and_units(received_amount)
self.app.show_pr_details(req, status, False)
else:
req = { 'address': obj.address, 'status' : obj.status }
status = obj.status
c, u, x = self.app.wallet.get_addr_balance(obj.address)
balance = c + u + x
if balance > 0:
req['fund'] = balance
self.app.show_addr_details(req, status)
def do_delete(self, obj):
from .dialogs.question import Question
def cb(result):
if result:
self.app.wallet.remove_payment_request(obj.address, self.app.electrum_config)
self.update()
d = Question(_('Delete request?'), cb)
d.open()
def ext_search(self, card, search):
return card.memo.find(search) >= 0 or card.amount.find(search) >= 0
def do_save(self):
self.save_request()
self.app.show_info(_('Request was saved.'))
class TabbedCarousel(Factory.TabbedPanel):