Skip to content

Commit e3bba80

Browse files
committed
move bundle_dir to globals
1 parent 13a11e2 commit e3bba80

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

components/globals.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import appdirs
2+
import sys
3+
import os
24

35
APP_NAME = "Reaper"
46
APP_AUTHOR = "UQ"
57

68
DATA_DIR = appdirs.user_data_dir(APP_NAME, APP_AUTHOR)
79
LOG_DIR = appdirs.user_log_dir(APP_NAME, APP_AUTHOR)
810
CACHE_DIR = appdirs.user_cache_dir(APP_NAME, APP_AUTHOR)
11+
12+
def _calc_path(path):
13+
head, tail = os.path.split(path)
14+
if tail == 'reaper':
15+
return path
16+
else:
17+
return _calc_path(head)
18+
19+
BUNDLE_DIR = sys._MEIPASS if getattr(sys, "frozen", False) else \
20+
_calc_path(os.path.dirname(os.path.abspath(__file__)))

components/sources.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from os import sep, path
44

55
from components.widgets.nodes import *
6+
from components.globals import BUNDLE_DIR
67

78

89
class NodeTree(QtWidgets.QTreeWidget):
@@ -424,7 +425,7 @@ def tree_click(item, column_no):
424425
item.sourceDescription.setCurrentIndex(item.pageIndex)
425426

426427
def read_sources(self):
427-
tree = ET.parse(f"{self.mainWindow.bundle_dir}{sep}{self.sourceFile}")
428+
tree = ET.parse(f"{BUNDLE_DIR}{sep}{self.sourceFile}")
428429
sources_root = tree.getroot()
429430
source_files = sources_root.findall("source")
430431

@@ -434,7 +435,7 @@ def read_sources(self):
434435
location = source_file.find("location").text
435436

436437
source_tree = ET.parse(
437-
f"{self.mainWindow.bundle_dir}{sep}sources/{location}"
438+
f"{BUNDLE_DIR}{sep}sources/{location}"
438439
)
439440
source_root = source_tree.getroot()
440441
sources.append(source_root)

components/widgets/nodes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from collections import OrderedDict
44
from os import getcwd, path, sep
55

6+
67
from PyQt5 import QtWidgets, QtCore, QtGui
8+
from components.globals import BUNDLE_DIR
79

810

911
class PrimaryInputWindow(QtWidgets.QMainWindow):
@@ -310,13 +312,13 @@ def __init__(self, primaryWindow, mainWindow, parent=None):
310312
self.data = []
311313

312314
self.readAction = self.addAction(
313-
QtGui.QIcon(f"{mainWindow.bundle_dir}{sep}ui/read.png"),
315+
QtGui.QIcon(f"{BUNDLE_DIR}{sep}ui/read.png"),
314316
self.TrailingPosition,
315317
)
316318
self.readAction.triggered.connect(self.add_file)
317319

318320
self.clearAction = self.addAction(
319-
QtGui.QIcon(f"{mainWindow.bundle_dir}{sep}ui/remove.png"),
321+
QtGui.QIcon(f"{BUNDLE_DIR}{sep}ui/remove.png"),
320322
self.TrailingPosition,
321323
)
322324
self.clearAction.triggered.connect(self.clear_file)

components/windows.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,31 @@ def __init__(self, text, details, parent=None):
7373

7474
class LicenseWindow(ScrollWindow):
7575

76-
def __init__(self, bundle_dir, parent=None):
76+
def __init__(self, parent=None):
7777
super().__init__("Software licenses", "Licenses", parent=parent)
7878
self.setFixedWidth(400)
7979

80-
self.bundle_dir = bundle_dir
81-
82-
with open(f"{self.bundle_dir}{sep}LICENSE.txt", "r") as f:
80+
with open(f"{BUNDLE_DIR}{sep}LICENSE.txt", "r") as f:
8381
reaper = LicenseWidget("Reaper GPL license", f.read(), self)
8482
self.contents.layout.addWidget(reaper)
8583

86-
with open(f"{self.bundle_dir}{sep}licenses/socialreaper.txt", "r") as f:
84+
with open(f"{BUNDLE_DIR}{sep}licenses/socialreaper.txt", "r") as f:
8785
reaper = LicenseWidget("Social Reaper MIT license", f.read(), self)
8886
self.contents.layout.addWidget(reaper)
8987

90-
with open(f"{self.bundle_dir}{sep}LICENSE.txt", "r") as f:
88+
with open(f"{BUNDLE_DIR}{sep}LICENSE.txt", "r") as f:
9189
reaper = LicenseWidget("PyQt GPL license", f.read(), self)
9290
self.contents.layout.addWidget(reaper)
9391

94-
with open(f"{self.bundle_dir}{sep}licenses/requests.txt", "r") as f:
92+
with open(f"{BUNDLE_DIR}{sep}licenses/requests.txt", "r") as f:
9593
reaper = LicenseWidget("Requests Apache license", f.read(), self)
9694
self.contents.layout.addWidget(reaper)
9795

98-
with open(f"{self.bundle_dir}{sep}licenses/requests-oauthlib.txt", "r") as f:
96+
with open(f"{BUNDLE_DIR}{sep}licenses/requests-oauthlib.txt", "r") as f:
9997
reaper = LicenseWidget("Requests-OAuthLib ISC license", f.read(), self)
10098
self.contents.layout.addWidget(reaper)
10199

102-
with open(f"{self.bundle_dir}{sep}licenses/oauthlib.txt", "r") as f:
100+
with open(f"{BUNDLE_DIR}{sep}licenses/oauthlib.txt", "r") as f:
103101
reaper = LicenseWidget("OAuthLib BSD license", f.read(), self)
104102
self.contents.layout.addWidget(reaper)
105103

reaper.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ def __init__(self, window, app, splash, show=True):
6060
self.dark_mode = False
6161

6262
self.splash_msg("Identifying app type")
63-
if getattr(sys, "frozen", False):
64-
self.bundle_dir = sys._MEIPASS
65-
else:
66-
self.bundle_dir = os.path.dirname(os.path.abspath(__file__))
6763

6864
# Add windows and actions
6965
self.splash_msg("Connecting widgets")
@@ -77,7 +73,7 @@ def __init__(self, window, app, splash, show=True):
7773
self.queue.job_error_log.connect(self.error_window.log_error)
7874
self.error_window.cancelButton.clicked.connect(self.queue.stop_retrying)
7975

80-
self.splash_msg("Adding iconds")
76+
self.splash_msg("Adding icons")
8177
self.set_icons()
8278

8379
# Create queue table
@@ -135,7 +131,7 @@ def add_actions(self):
135131
self.actionAPI_Keys.triggered.connect(self.export_keys)
136132

137133
def add_windows(self):
138-
self.license_window = LicenseWindow(self.bundle_dir, self.window)
134+
self.license_window = LicenseWindow(self.window)
139135
self.actionLicenses.triggered.connect(self.license_window.pop)
140136

141137
self.error_window = ErrorWindow(self.window)
@@ -144,10 +140,10 @@ def add_windows(self):
144140
self.actionSettings.triggered.connect(self.settings_window.show)
145141

146142
def set_icons(self):
147-
self.queueUp.setIcon(QIcon(f"{self.bundle_dir}{sep}ui/up.png"))
148-
self.queueDown.setIcon(QIcon(f"{self.bundle_dir}{sep}ui/down.png"))
149-
self.queueRemove.setIcon(QIcon(f"{self.bundle_dir}{sep}ui/remove.png"))
150-
self.window.setWindowIcon(QIcon(f"{self.bundle_dir}{sep}ui/icon.ico"))
143+
self.queueUp.setIcon(QIcon(f"{BUNDLE_DIR}{sep}ui/up.png"))
144+
self.queueDown.setIcon(QIcon(f"{BUNDLE_DIR}{sep}ui/down.png"))
145+
self.queueRemove.setIcon(QIcon(f"{BUNDLE_DIR}{sep}ui/remove.png"))
146+
self.window.setWindowIcon(QIcon(f"{BUNDLE_DIR}{sep}ui/icon.ico"))
151147

152148
def show_error_manager(self, _):
153149
self.error_window.show()

0 commit comments

Comments
 (0)