Merge pull request #5913 from roth-a/master

Kivy: Adding address coloring to AddressPopup (Address Details)
This commit is contained in:
ThomasV 2020-02-01 19:38:22 +01:00 committed by GitHub
commit e876cb0d93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 24 deletions

View file

@ -151,6 +151,7 @@
text: self.data if self.data else _('Tap to show') text: self.data if self.data else _('Tap to show')
touched: False touched: False
padding: '10dp', '10dp' padding: '10dp', '10dp'
background_color: .3, .3, .3, 1
on_touch_down: on_touch_down:
touch = args[1] touch = args[1]
touched = bool(self.collide_point(*touch.pos)) touched = bool(self.collide_point(*touch.pos))
@ -158,7 +159,7 @@
if touched: self.touched = True if touched: self.touched = True
canvas.before: canvas.before:
Color: Color:
rgb: .3, .3, .3 rgba: root.background_color
Rectangle: Rectangle:
size: self.size size: self.size
pos: self.pos pos: self.pos

View file

@ -8,6 +8,7 @@ from decimal import Decimal
from kivy.uix.popup import Popup from kivy.uix.popup import Popup
from electrum.gui.kivy.i18n import _ from electrum.gui.kivy.i18n import _
from ...util import address_colors
if TYPE_CHECKING: if TYPE_CHECKING:
from ...main_window import ElectrumWindow from ...main_window import ElectrumWindow
@ -111,6 +112,8 @@ Builder.load_string('''
status: '' status: ''
script_type: '' script_type: ''
pk: '' pk: ''
address_color: 1, 1, 1, 1
address_background_color: 0.3, 0.3, 0.3, 1
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
ScrollView: ScrollView:
@ -123,6 +126,8 @@ Builder.load_string('''
TopLabel: TopLabel:
text: _('Address') text: _('Address')
RefLabel: RefLabel:
color: root.address_color
background_color: root.address_background_color
data: root.address data: root.address
name: _('Address') name: _('Address')
GridLayout: GridLayout:
@ -175,6 +180,7 @@ class AddressPopup(Popup):
self.status = status self.status = status
self.script_type = self.app.wallet.get_txin_type(self.address) self.script_type = self.app.wallet.get_txin_type(self.address)
self.balance = self.app.format_amount_and_units(balance) self.balance = self.app.format_amount_and_units(balance)
self.address_color, self.address_background_color = address_colors(self.app.wallet, address)
def receive_at(self): def receive_at(self):
self.dismiss() self.dismiss()

View file

@ -10,7 +10,6 @@ from kivy.clock import Clock
from kivy.uix.label import Label from kivy.uix.label import Label
from kivy.uix.dropdown import DropDown from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button from kivy.uix.button import Button
from kivy.utils import get_color_from_hex
from .question import Question from .question import Question
from electrum.gui.kivy.i18n import _ from electrum.gui.kivy.i18n import _
@ -19,6 +18,7 @@ from electrum.util import InvalidPassword
from electrum.address_synchronizer import TX_HEIGHT_LOCAL from electrum.address_synchronizer import TX_HEIGHT_LOCAL
from electrum.wallet import CannotBumpFee from electrum.wallet import CannotBumpFee
from electrum.transaction import Transaction, PartialTransaction from electrum.transaction import Transaction, PartialTransaction
from ...util import address_colors
if TYPE_CHECKING: if TYPE_CHECKING:
from ...main_window import ElectrumWindow from ...main_window import ElectrumWindow
@ -183,29 +183,8 @@ class TxDialog(Factory.Popup):
self.feerate_str = _('unknown') self.feerate_str = _('unknown')
self.ids.output_list.update(self.tx.outputs()) self.ids.output_list.update(self.tx.outputs())
def text_format(addr):
"""
Chooses the appropriate text color and background color to
mark receiving, change and billing addresses.
Returns: color, background_color
"""
# modified colors (textcolor, background_color) from electrum/gui/qt/util.py
GREEN = ("#000000", "#8af296")
YELLOW = ("#000000", "#ffff00")
BLUE = ("#000000", "#8cb3f2")
DEFAULT = ('#ffffff', '#4c4c4c')
colors = DEFAULT
if self.wallet.is_mine(addr):
colors = YELLOW if self.wallet.is_change(addr) else GREEN
elif self.wallet.is_billing_address(addr):
colors = BLUE
return (get_color_from_hex(color) for color in colors)
for dict_entry in self.ids.output_list.data: for dict_entry in self.ids.output_list.data:
dict_entry['color'], dict_entry['background_color'] = text_format(dict_entry['address']) dict_entry['color'], dict_entry['background_color'] = address_colors(self.wallet, dict_entry['address'])
self.is_local_tx = tx_mined_status.height == TX_HEIGHT_LOCAL self.is_local_tx = tx_mined_status.height == TX_HEIGHT_LOCAL
self.update_action_button() self.update_action_button()

23
electrum/gui/kivy/util.py Normal file
View file

@ -0,0 +1,23 @@
from kivy.utils import get_color_from_hex
def address_colors(wallet, addr):
"""
Chooses the appropriate text color and background color to
mark receiving, change and billing addresses.
Returns: color, background_color
"""
# modified colors (textcolor, background_color) from electrum/gui/qt/util.py
GREEN = ("#000000", "#8af296")
YELLOW = ("#000000", "#ffff00")
BLUE = ("#000000", "#8cb3f2")
DEFAULT = ('#ffffff', '#4c4c4c')
colors = DEFAULT
if wallet.is_mine(addr):
colors = YELLOW if wallet.is_change(addr) else GREEN
elif wallet.is_billing_address(addr):
colors = BLUE
return (get_color_from_hex(color) for color in colors)