Skip to content

Commit c425114

Browse files
committed
universal resource path
1 parent 415de3b commit c425114

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

labelpush.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,13 @@
5858
# System
5959
from io import BytesIO
6060
from subprocess import Popen, PIPE
61+
from pathlib import Path
6162
import os
6263
import sys
6364
import shutil
6465

6566
name = 'labelpush'
66-
version = '2018.11.26'
67-
def_iconfiles = [
68-
os.path.join(sys.prefix, 'local/share/pixmaps/labelpush.png'),
69-
os.path.join(sys.prefix, 'share/pixmaps/labelpush.png'),
70-
'data/labelpush.png',
71-
'labelpush.png',
72-
]
67+
version = '2018.11.27'
7368
def_defaultcfg = {
7469
'lpname': 'default', # printer name
7570
'labw': 637, # labelwidth
@@ -319,6 +314,7 @@ def clock_thread(self):
319314
# Thread(target=self.clock_thread).start()
320315

321316
class LabelPushApp(App):
317+
resource_rootpath = ''
322318
def populate_printers(self):
323319
# check if lp/cups is found
324320
if shutil.which('lp') is None or shutil.which('lpstat') is None:
@@ -439,13 +435,15 @@ def on_start(self):
439435
def on_stop(self):
440436
GLO.stop.set() # stop thread so that the program can exit
441437
def build(self):
442-
for iconfile in def_iconfiles:
443-
if os.access(iconfile, os.R_OK):
444-
print(':: found app icon ' + iconfile)
445-
self.icon = iconfile
438+
app_path = Path(__file__).resolve()
439+
for tryroot in (str(app_path.parents[1]) + '/share', str(app_path.parents[0]) + '/data'):
440+
tryicon = tryroot + '/pixmaps/' + name + '.png'
441+
if os.access(tryicon, os.R_OK):
442+
self.icon = tryicon
443+
self.resource_rootpath = tryroot
446444
break
447-
if not self.icon:
448-
print('WARNING: Could not find application icon', file=sys.stderr)
445+
else:
446+
print('WARNING: Could not find application resource files', file=sys.stderr)
449447
return RootWidget()
450448

451449
#

setup.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
#!/usr/bin/env python3
2-
# requirements Mint/Ubuntu/Debian: sudo apt-get install python3-pip python3-dev libgl1-mesa-dev xsel
3-
# to build packages, invoke this script: ./setup.py bdist bdist_wheel
42
# to install directly, invoke via pip: sudo pip3 install .
53
# to generate a whl file: ./setup.py bdist_wheel
6-
#
74

85
import setuptools
9-
import re
10-
import sys
6+
import os, sys, re
7+
from pathlib import Path
118
mainscript = 'labelpush.py'
129

10+
resources = []
11+
for fil in (f for f in Path('data').rglob('*') if f.is_file()):
12+
resources.append((str('share' / fil.parent.relative_to('data')), [str(fil)]))
1313
with open('requirements.txt') as fh:
1414
required = fh.read().strip().splitlines()
15-
1615
with open('README.md', 'r') as fh:
1716
long_description = fh.read()
18-
1917
with open(mainscript) as fh:
2018
for line in fh:
2119
out = re.search(r'version = \u0027(.+?)\u0027$', line)
@@ -44,10 +42,7 @@
4442
'License :: OSI Approved :: MIT License',
4543
'Operating System :: OS Independent',
4644
],
47-
data_files = [
48-
('share/pixmaps', ['data/labelpush.png']),
49-
('share/applications', ['data/labelpush.desktop']),
50-
],
45+
data_files = resources,
5146
)
5247

5348
# End of file

0 commit comments

Comments
 (0)