Skip to content

Commit 9e45108

Browse files
committed
kivy: fix some resource path issues
When running kivy on Linux desktop, running from git clone, `./run_electrum -g kivy` worked, but `pip install -e .; electrum -g kivy` did not. This was due to the relative paths using cwd as base. see spesmilo#6835
1 parent 1851ec9 commit 9e45108

18 files changed

+90
-65
lines changed

electrum/gui/kivy/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import os
3030
from typing import TYPE_CHECKING
3131

32+
KIVY_GUI_PATH = os.path.abspath(os.path.dirname(__file__))
33+
os.environ['KIVY_DATA_DIR'] = os.path.join(KIVY_GUI_PATH, 'data')
34+
3235
try:
3336
sys.argv = ['']
3437
import kivy

electrum/gui/kivy/main.kv

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#:import Window kivy.core.window.Window
33
#:import Factory kivy.factory.Factory
44
#:import _ electrum.gui.kivy.i18n._
5+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
56

67

78
###########################
@@ -211,7 +212,7 @@
211212
Color:
212213
rgba: 0.192, .498, 0.745, 1
213214
BorderImage:
214-
source: 'atlas://electrum/gui/kivy/theming/light/card_bottom'
215+
source: f'atlas://{KIVY_GUI_PATH}/theming/light/card_bottom'
215216
size: self.size
216217
pos: self.pos
217218

@@ -225,7 +226,7 @@
225226
Color:
226227
rgba: 0.192, .498, 0.745, 1
227228
BorderImage:
228-
source: 'atlas://electrum/gui/kivy/theming/light/card_bottom'
229+
source: f'atlas://{KIVY_GUI_PATH}/theming/light/card_bottom'
229230
size: self.size
230231
pos: self.pos
231232

@@ -238,7 +239,7 @@
238239
Color:
239240
rgba: 0.192, .498, 0.745, 1
240241
BorderImage:
241-
source: 'atlas://electrum/gui/kivy/theming/light/card_bottom'
242+
source: f'atlas://{KIVY_GUI_PATH}/theming/light/card_bottom'
242243
size: self.size
243244
pos: self.pos
244245

@@ -326,8 +327,8 @@
326327
valign: 'middle'
327328
bold: True
328329
font_size: '12.5sp'
329-
background_normal: 'atlas://electrum/gui/kivy/theming/light/tab_btn'
330-
background_down: 'atlas://electrum/gui/kivy/theming/light/tab_btn_pressed'
330+
background_normal: f'atlas://{KIVY_GUI_PATH}/theming/light/tab_btn'
331+
background_down: f'atlas://{KIVY_GUI_PATH}/theming/light/tab_btn_pressed'
331332

332333

333334
<ColoredLabel@Label>:
@@ -417,7 +418,7 @@ BoxLayout:
417418
rgb: .6, .6, .6
418419
Rectangle:
419420
size: self.size
420-
source: 'electrum/gui/kivy/data/background.png'
421+
source: f'{KIVY_GUI_PATH}/data/background.png'
421422

422423
ActionBar:
423424

electrum/gui/kivy/main_window.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from electrum.interface import PREFERRED_NETWORK_PROTOCOL, ServerAddr
2424
from electrum.logging import Logger
2525
from .i18n import _
26+
from . import KIVY_GUI_PATH
2627

2728
from kivy.app import App
2829
from kivy.core.window import Window
@@ -68,11 +69,13 @@
6869
# Register fonts without this you won't be able to use bold/italic...
6970
# inside markup.
7071
from kivy.core.text import Label
71-
Label.register('Roboto',
72-
'electrum/gui/kivy/data/fonts/Roboto.ttf',
73-
'electrum/gui/kivy/data/fonts/Roboto.ttf',
74-
'electrum/gui/kivy/data/fonts/Roboto-Bold.ttf',
75-
'electrum/gui/kivy/data/fonts/Roboto-Bold.ttf')
72+
Label.register(
73+
'Roboto',
74+
KIVY_GUI_PATH + '/data/fonts/Roboto.ttf',
75+
KIVY_GUI_PATH + '/data/fonts/Roboto.ttf',
76+
KIVY_GUI_PATH + '/data/fonts/Roboto-Bold.ttf',
77+
KIVY_GUI_PATH + '/data/fonts/Roboto-Bold.ttf',
78+
)
7679

7780

7881
from electrum.util import (NoDynamicFeeEstimates, NotEnoughFunds,
@@ -530,7 +533,7 @@ def do_share(self, data, title):
530533
currentActivity.startActivity(it)
531534

532535
def build(self):
533-
return Builder.load_file('electrum/gui/kivy/main.kv')
536+
return Builder.load_file(KIVY_GUI_PATH + '/main.kv')
534537

535538
def _pause(self):
536539
if platform == 'android':
@@ -724,7 +727,7 @@ def popup_dialog(self, name):
724727
elif name == 'wallets':
725728
self.wallets_dialog()
726729
elif name == 'status':
727-
popup = Builder.load_file('electrum/gui/kivy/uix/ui_screens/'+name+'.kv')
730+
popup = Builder.load_file(KIVY_GUI_PATH + f'/uix/ui_screens/{name}.kv')
728731
master_public_keys_layout = popup.ids.master_public_keys
729732
for xpub in self.wallet.get_master_public_keys()[1:]:
730733
master_public_keys_layout.add_widget(TopLabel(text=_('Master Public Key')))
@@ -736,7 +739,7 @@ def popup_dialog(self, name):
736739
elif name.endswith("_dialog"):
737740
getattr(self, name)()
738741
else:
739-
popup = Builder.load_file('electrum/gui/kivy/uix/ui_screens/'+name+'.kv')
742+
popup = Builder.load_file(KIVY_GUI_PATH + f'/uix/ui_screens/{name}.kv')
740743
popup.open()
741744

742745
@profiler
@@ -766,7 +769,7 @@ def init_ui(self):
766769
self.history_screen = None
767770
self.send_screen = None
768771
self.receive_screen = None
769-
self.icon = "electrum/gui/icons/electrum.png"
772+
self.icon = os.path.dirname(KIVY_GUI_PATH) + "/icons/electrum.png"
770773
self.tabs = self.root.ids['tabs']
771774

772775
def update_interfaces(self, dt):
@@ -968,7 +971,7 @@ def on_ref_label(self, label):
968971
self.qr_dialog(label.name, label.data, True)
969972

970973
def show_error(self, error, width='200dp', pos=None, arrow_pos=None,
971-
exit=False, icon='atlas://electrum/gui/kivy/theming/light/error', duration=0,
974+
exit=False, icon=f'atlas://{KIVY_GUI_PATH}/theming/light/error', duration=0,
972975
modal=False):
973976
''' Show an error Message Bubble.
974977
'''
@@ -980,7 +983,7 @@ def show_info(self, error, width='200dp', pos=None, arrow_pos=None,
980983
exit=False, duration=0, modal=False):
981984
''' Show an Info Message Bubble.
982985
'''
983-
self.show_error(error, icon='atlas://electrum/gui/kivy/theming/light/important',
986+
self.show_error(error, icon=f'atlas://{KIVY_GUI_PATH}/theming/light/important',
984987
duration=duration, modal=modal, exit=exit, pos=pos,
985988
arrow_pos=arrow_pos)
986989

@@ -1021,7 +1024,7 @@ def show_info_bubble(self, text=_('Hello World'), pos=None, duration=0,
10211024
info_bubble.show_arrow = False
10221025
img.allow_stretch = True
10231026
info_bubble.dim_background = True
1024-
info_bubble.background_image = 'atlas://electrum/gui/kivy/theming/light/card'
1027+
info_bubble.background_image = f'atlas://{KIVY_GUI_PATH}/theming/light/card'
10251028
else:
10261029
info_bubble.fs = False
10271030
info_bubble.icon = icon

electrum/gui/kivy/uix/dialogs/installwizard.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Builder.load_string('''
3535
#:import Window kivy.core.window.Window
3636
#:import _ electrum.gui.kivy.i18n._
37+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
3738
3839
3940
<WizardTextInput@TextInput>
@@ -43,8 +44,8 @@
4344
background_color: (1, 1, 1, 1) if self.focus else (0.454, 0.698, 0.909, 1)
4445
foreground_color: (0.31, 0.31, 0.31, 1) if self.focus else (0.835, 0.909, 0.972, 1)
4546
hint_text_color: self.foreground_color
46-
background_active: 'atlas://electrum/gui/kivy/theming/light/create_act_text_active'
47-
background_normal: 'atlas://electrum/gui/kivy/theming/light/create_act_text_active'
47+
background_active: f'atlas://{KIVY_GUI_PATH}/theming/light/create_act_text_active'
48+
background_normal: f'atlas://{KIVY_GUI_PATH}/theming/light/create_act_text_active'
4849
size_hint_y: None
4950
height: '48sp'
5051
@@ -93,7 +94,7 @@
9394
size_hint: 1, None
9495
height: self.texture_size[1] if self.opacity else 0
9596
font_size: '33sp'
96-
font_name: 'electrum/gui/kivy/data/fonts/tron/Tr2n.ttf'
97+
font_name: f'{KIVY_GUI_PATH}/data/fonts/tron/Tr2n.ttf'
9798
GridLayout:
9899
cols: 1
99100
id: crcontent
@@ -314,7 +315,7 @@
314315
font_size: '18dp'
315316
text_size: self.width - dp(24), self.height - dp(12)
316317
color: .1, .1, .1, 1
317-
background_normal: 'atlas://electrum/gui/kivy/theming/light/white_bg_round_top'
318+
background_normal: f'atlas://{KIVY_GUI_PATH}/theming/light/white_bg_round_top'
318319
background_down: self.background_normal
319320
size_hint_y: None
320321
@@ -343,7 +344,7 @@
343344
height: '30dp'
344345
width: '30dp'
345346
size_hint: 1, None
346-
icon: 'atlas://electrum/gui/kivy/theming/light/gear'
347+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/gear'
347348
on_release:
348349
root.options_dialog() if root.options_dialog else None
349350
@@ -479,7 +480,7 @@
479480
id: scan
480481
height: '48sp'
481482
on_release: root.scan_xpub()
482-
icon: 'atlas://electrum/gui/kivy/theming/light/camera'
483+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/camera'
483484
size_hint: 1, None
484485
WizardButton:
485486
text: _('Paste')

electrum/gui/kivy/uix/dialogs/invoice_dialog.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616

1717
Builder.load_string('''
18+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
19+
1820
<InvoiceDialog@Popup>
1921
id: popup
2022
amount_str: ''
@@ -66,12 +68,12 @@
6668
text: _('Delete')
6769
on_release: root.delete_dialog()
6870
IconButton:
69-
icon: 'atlas://electrum/gui/kivy/theming/light/copy'
71+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/copy'
7072
size_hint: 0.5, None
7173
height: '48dp'
7274
on_release: root.copy_to_clipboard()
7375
IconButton:
74-
icon: 'atlas://electrum/gui/kivy/theming/light/share'
76+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/share'
7577
size_hint: 0.5, None
7678
height: '48dp'
7779
on_release: root.do_share()

electrum/gui/kivy/uix/dialogs/label_dialog.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from kivy.lang import Builder
55

66
Builder.load_string('''
7+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
8+
79
<LabelDialog@Popup>
810
id: popup
911
title: ''
@@ -21,8 +23,8 @@
2123
pos_hint: {'center_y':.5}
2224
text:''
2325
multiline: False
24-
background_normal: 'atlas://electrum/gui/kivy/theming/light/tab_btn'
25-
background_active: 'atlas://electrum/gui/kivy/theming/light/textinput_active'
26+
background_normal: f'atlas://{KIVY_GUI_PATH}/theming/light/tab_btn'
27+
background_active: f'atlas://{KIVY_GUI_PATH}/theming/light/textinput_active'
2628
hint_text_color: self.foreground_color
2729
foreground_color: 1, 1, 1, 1
2830
font_size: '16dp'

electrum/gui/kivy/uix/dialogs/lightning_open_channel.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919

2020
Builder.load_string('''
21+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
22+
2123
<LightningOpenChannelDialog@Popup>
2224
id: s
2325
name: 'lightning_open_channel'
@@ -38,7 +40,7 @@
3840
size_hint: 1, None
3941
height: blue_bottom.item_height
4042
Image:
41-
source: 'atlas://electrum/gui/kivy/theming/light/globe'
43+
source: f'atlas://{KIVY_GUI_PATH}/theming/light/globe'
4244
size_hint: None, None
4345
size: '22dp', '22dp'
4446
pos_hint: {'center_y': .5}
@@ -51,7 +53,7 @@
5153
size_hint: 1, None
5254
height: blue_bottom.item_height
5355
Image:
54-
source: 'atlas://electrum/gui/kivy/theming/light/calculator'
56+
source: f'atlas://{KIVY_GUI_PATH}/theming/light/calculator'
5557
size_hint: None, None
5658
size: '22dp', '22dp'
5759
pos_hint: {'center_y': .5}
@@ -64,12 +66,12 @@
6466
size_hint: 1, None
6567
height: '48dp'
6668
IconButton:
67-
icon: 'atlas://electrum/gui/kivy/theming/light/copy'
69+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/copy'
6870
size_hint: 0.5, None
6971
height: '48dp'
7072
on_release: s.do_paste()
7173
IconButton:
72-
icon: 'atlas://electrum/gui/kivy/theming/light/camera'
74+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/camera'
7375
size_hint: 0.5, None
7476
height: '48dp'
7577
on_release: app.scan_qr(on_complete=s.on_qr)

electrum/gui/kivy/uix/dialogs/password_dialog.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from electrum.storage import WalletStorage
2222

2323
Builder.load_string('''
24+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
2425
2526
<PasswordDialog@Popup>
2627
id: popup
@@ -47,7 +48,7 @@
4748
IconButton:
4849
size_hint: 0.15, None
4950
height: '40dp'
50-
icon: 'atlas://electrum/gui/kivy/theming/light/btn_create_account'
51+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/btn_create_account'
5152
on_release: root.select_file()
5253
disabled: root.is_change
5354
opacity: 0 if root.is_change else 1
@@ -81,7 +82,7 @@
8182
IconButton:
8283
height: '40dp'
8384
size_hint: 0.15, None
84-
icon: 'atlas://electrum/gui/kivy/theming/light/eye1'
85+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/eye1'
8586
icon_size: '40dp'
8687
on_release:
8788
textinput_generic_password.password = False if textinput_generic_password.password else True

electrum/gui/kivy/uix/dialogs/qr_dialog.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414

1515
Builder.load_string('''
16+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
17+
1618
<QRDialog@Popup>
1719
id: popup
1820
title: ''
@@ -47,7 +49,7 @@
4749
on_release:
4850
root.copy_to_clipboard()
4951
IconButton:
50-
icon: 'atlas://electrum/gui/kivy/theming/light/share'
52+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/share'
5153
size_hint: 0.6, None
5254
height: '48dp'
5355
on_release: root.do_share()

electrum/gui/kivy/uix/dialogs/qr_scanner.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def on_complete(self, x):
2121

2222

2323
Builder.load_string('''
24+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
25+
2426
<QrScannerDialog>
2527
title:
2628
_(\
@@ -33,7 +35,7 @@ def on_complete(self, x):
3335
#separator_color: .89, .89, .89, 1
3436
#separator_height: '1.2dp'
3537
#title_color: .437, .437, .437, 1
36-
#background: 'atlas://electrum/gui/kivy/theming/light/dialog'
38+
#background: f'atlas://{KIVY_GUI_PATH}/theming/light/dialog'
3739
on_activate:
3840
qrscr.start()
3941
qrscr.size = self.size

electrum/gui/kivy/uix/dialogs/request_dialog.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616

1717
Builder.load_string('''
18+
#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
19+
1820
<RequestDialog@Popup>
1921
id: popup
2022
amount_str: ''
@@ -66,12 +68,12 @@
6668
text: _('Delete')
6769
on_release: root.delete_dialog()
6870
IconButton:
69-
icon: 'atlas://electrum/gui/kivy/theming/light/copy'
71+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/copy'
7072
size_hint: 0.5, None
7173
height: '48dp'
7274
on_release: root.copy_to_clipboard()
7375
IconButton:
74-
icon: 'atlas://electrum/gui/kivy/theming/light/share'
76+
icon: f'atlas://{KIVY_GUI_PATH}/theming/light/share'
7577
size_hint: 0.5, None
7678
height: '48dp'
7779
on_release: root.do_share()

electrum/gui/kivy/uix/dialogs/settings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from electrum.plugin import run_hook
1010
from electrum import coinchooser
1111

12+
from electrum.gui.kivy import KIVY_GUI_PATH
13+
1214
from .choice_dialog import ChoiceDialog
1315

1416
Builder.load_string('''
@@ -193,7 +195,7 @@ def callback(popup):
193195
net_params = net_params._replace(proxy=proxy)
194196
network.run_from_another_thread(network.set_parameters(net_params))
195197
item.status = self.proxy_status()
196-
popup = Builder.load_file('electrum/gui/kivy/uix/ui_screens/proxy.kv')
198+
popup = Builder.load_file(KIVY_GUI_PATH + '/uix/ui_screens/proxy.kv')
197199
popup.ids.mode.text = proxy.get('mode') if proxy else 'None'
198200
popup.ids.host.text = proxy.get('host') if proxy else ''
199201
popup.ids.port.text = proxy.get('port') if proxy else ''

0 commit comments

Comments
 (0)