Skip to content

Commit 2dcc865

Browse files
committed
feat: executable version of AB
1 parent 1ecd682 commit 2dcc865

File tree

13 files changed

+212
-23
lines changed

13 files changed

+212
-23
lines changed

activity-browser.spec

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
import argparse
3+
import os
4+
import platform
5+
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument("--debug", action="store_true")
8+
parser.add_argument("--verbose", action="store_true")
9+
options = parser.parse_args()
10+
11+
python_options = [
12+
("W ignore", None, "OPTION"),
13+
]
14+
if options.verbose:
15+
python_options.append(("v", None, "OPTION"))
16+
17+
a = Analysis(
18+
["run-activity-browser.py"],
19+
pathex=[],
20+
binaries=[],
21+
datas=[],
22+
hiddenimports=["activity_browser"],
23+
hookspath=[],
24+
hooksconfig={},
25+
runtime_hooks=[],
26+
excludes=[],
27+
noarchive=False,
28+
optimize=0,
29+
)
30+
a.datas += Tree("activity_browser/static", prefix="activity_browser/static")
31+
pyz = PYZ(a.pure)
32+
33+
if options.debug:
34+
exe = EXE(
35+
pyz,
36+
a.scripts,
37+
python_options,
38+
exclude_binaries=True,
39+
name="activity-browser",
40+
debug=False,
41+
bootloader_ignore_signals=False,
42+
strip=False,
43+
upx=True,
44+
console=False,
45+
disable_windowed_traceback=False,
46+
argv_emulation=False,
47+
target_arch=None,
48+
codesign_identity=None,
49+
entitlements_file=None,
50+
)
51+
coll = COLLECT(
52+
exe,
53+
a.binaries,
54+
a.datas,
55+
strip=False,
56+
upx=True,
57+
upx_exclude=[],
58+
name="activity-browser",
59+
)
60+
target = coll
61+
else:
62+
exe = EXE(
63+
pyz,
64+
a.scripts,
65+
python_options,
66+
a.binaries,
67+
a.datas,
68+
name="activity-browser",
69+
console=False,
70+
)
71+
target = exe
72+
73+
if platform.system() == "Darwin":
74+
app = BUNDLE(
75+
target,
76+
name="Activity Browser.app",
77+
icon="activity_browser/static/icons/activity-browser.icns",
78+
bundle_identifier=None,
79+
version=os.environ.get("VERSION", "0.0.0"),
80+
info_plist={
81+
"NSPrincipalClass": "NSApplication",
82+
"NSAppleScriptEnabled": False,
83+
"CFBundleDocumentTypes": [
84+
{
85+
"CFBundleTypeName": "Icon",
86+
"CFBundleTypeIconFile": "activity_browser/static/icons/activity-browser.icns",
87+
"LSItemContentTypes": [
88+
"com.github.lca_activity_browser.activity_browser"
89+
],
90+
"LSHandlerRank": "Owner",
91+
}
92+
],
93+
},
94+
)

activity_browser/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .layouts.main import MainWindow
1212
from .plugin import Plugin
1313

14+
1415
def load_settings() -> None:
1516
if ab_settings.settings:
1617
bw2data.projects.switch_dir(ab_settings.current_bw_dir)
@@ -19,14 +20,16 @@ def load_settings() -> None:
1920
log.info(f"Brightway2 current project: {bw2data.projects.current}")
2021

2122

22-
def run_activity_browser():
23+
def run_activity_browser(splash=None):
2324
log.info(f"Activity Browser version: {version}")
2425
if log_file_location:
2526
log.info(f"The log file can be found at {log_file_location}")
2627

2728
application.main_window = MainWindow(application)
2829
load_settings()
2930
application.show()
31+
if splash:
32+
splash.finish(application.main_window)
3033

3134
sys.excepthook = exception_hook
3235

activity_browser/application.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import os
33

4+
from PySide2 import QtWidgets
45
from PySide2.QtCore import QCoreApplication, QObject, QSysInfo, Qt
56
from PySide2.QtWidgets import QApplication
67

@@ -51,6 +52,8 @@ def deleteLater(self):
5152
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--no-sandbox"
5253
log.info("Info: QtWebEngine sandbox disabled")
5354

54-
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts, True)
55-
56-
application = ABApplication()
55+
if not QtWidgets.QApplication.instance():
56+
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts, True)
57+
application = ABApplication()
58+
else:
59+
application: ABApplication = QtWidgets.QApplication.instance()

activity_browser/layouts/panels/right.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from activity_browser import log, signals
66
from activity_browser.mod import bw2data as bd
7+
from activity_browser.utils import STATIC_DIR
78

89
from ...bwutils.commontasks import get_activity_name
910
from ...ui.web import GraphNavigatorWidget, RestrictedWebViewWidget
@@ -22,8 +23,7 @@ class RightPanel(ABTab):
2223

2324
def __init__(self, *args):
2425
super(RightPanel, self).__init__(*args)
25-
package_dir = Path(__file__).resolve().parents[2]
26-
html_file = str(package_dir.joinpath("static", "startscreen", "welcome.html"))
26+
html_file = str(STATIC_DIR.joinpath("startscreen", "welcome.html"))
2727
self.tabs = {
2828
"Welcome": RestrictedWebViewWidget(html_file=html_file),
2929
"Characterization Factors": CharacterizationFactorsTab(self),
360 KB
Binary file not shown.
161 KB
Binary file not shown.

activity_browser/ui/icons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
from PySide2.QtGui import QIcon
55

6-
PACKAGE_DIR = Path(__file__).resolve().parents[1]
6+
from activity_browser.utils import STATIC_DIR
77

88

99
def create_path(folder: str, filename: str) -> str:
1010
"""Builds a path to the image file."""
11-
return str(PACKAGE_DIR.joinpath("static", "icons", folder, filename))
11+
return str(STATIC_DIR.joinpath("icons", folder, filename))
1212

1313

1414
# CURRENTLY UNUSED ICONS

activity_browser/ui/web/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, parent=None, css_file: str = "", *args, **kwargs):
3838
self.view.loadFinished.connect(self.load_finished_handler)
3939
self.view.setContextMenuPolicy(Qt.PreventContextMenu)
4040
self.view.page().setWebChannel(self.channel)
41-
self.url = QUrl.fromLocalFile(self.HTML_FILE)
41+
self.url = QUrl.fromLocalFile(str(self.HTML_FILE))
4242
self.css_file = css_file
4343

4444
# Various Qt objects

activity_browser/ui/web/navigator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from activity_browser import log, signals
1212
from activity_browser.mod.bw2data import Database, get_activity
13+
from activity_browser.utils import STATIC_DIR
1314

1415
from ...bwutils.commontasks import identify_activity_type
1516
from .base import BaseGraph, BaseNavigatorWidget
@@ -50,9 +51,7 @@ class GraphNavigatorWidget(BaseNavigatorWidget):
5051
NAVIGATION MODE:
5152
Click on activities to jump to specific activities (instead of expanding the graph).
5253
"""
53-
HTML_FILE = os.path.join(
54-
os.path.abspath(os.path.dirname(__file__)), "../../static/navigator.html"
55-
)
54+
HTML_FILE = STATIC_DIR.joinpath("navigator.html")
5655

5756
def __init__(self, parent=None, key=None):
5857
super().__init__(parent, css_file="navigator.css")

activity_browser/ui/web/sankey_navigator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from activity_browser import log, signals
1818
from activity_browser.mod import bw2data as bd
1919
from activity_browser.mod.bw2data.backends import ActivityDataset
20+
from activity_browser.utils import STATIC_DIR
2021

2122
from ...bwutils.commontasks import identify_activity_type
2223
from ...bwutils.superstructure.graph_traversal_with_scenario import (
@@ -45,9 +46,7 @@ class SankeyNavigatorWidget(BaseNavigatorWidget):
4546
Green flows: Avoided impacts
4647
4748
"""
48-
HTML_FILE = os.path.join(
49-
os.path.abspath(os.path.dirname(__file__)), "../../static/sankey_navigator.html"
50-
)
49+
HTML_FILE = STATIC_DIR.joinpath("sankey_navigator.html")
5150

5251
def __init__(self, cs_name, parent=None):
5352
super().__init__(parent, css_file="sankey_navigator.css")

0 commit comments

Comments
 (0)