Skip to content

Commit c18de52

Browse files
committed
Split Help Menu
1 parent 8055760 commit c18de52

1 file changed

Lines changed: 54 additions & 49 deletions

File tree

activity_browser/ui/menu_bar.py

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
2+
from importlib.metadata import version
3+
24
from PySide2 import QtGui, QtWidgets
35
from PySide2.QtCore import QSize, QUrl, Slot
46

5-
from activity_browser import actions, signals
7+
from activity_browser import actions, signals, application, info
68
from activity_browser.mod import bw2data as bd
79

8-
from ..info import __version__ as ab_version
910
from .icons import qicons
1011

1112
AB_BW25 = True if os.environ.get("AB_BW25", False) else False
@@ -14,57 +15,11 @@
1415
class MenuBar(QtWidgets.QMenuBar):
1516
def __init__(self, window):
1617
super().__init__(parent=window)
17-
self.help_menu = QtWidgets.QMenu("&Help", self)
1818

1919
self.addMenu(ProjectMenu(self))
2020
self.addMenu(ViewMenu(self))
2121
self.addMenu(ToolsMenu(self))
22-
self.addMenu(self.help_menu)
23-
24-
self.setup_help_menu()
25-
26-
def setup_help_menu(self) -> None:
27-
"""Build the help menu for the menubar."""
28-
self.help_menu.addAction(
29-
self.window().icon, "&About Activity Browser", self.about
30-
)
31-
self.help_menu.addAction(
32-
"&About Qt", lambda: QtWidgets.QMessageBox.aboutQt(self.parent())
33-
)
34-
self.help_menu.addAction(
35-
qicons.question, "&Get help on the wiki", self.open_wiki
36-
)
37-
self.help_menu.addAction(
38-
qicons.issue, "&Report an idea/issue on GitHub", self.raise_issue_github
39-
)
40-
41-
def about(self):
42-
text = """
43-
Activity Browser - a graphical interface for Brightway2.<br><br>
44-
Application version: <b>{}</b><br><br>
45-
All development happens on <a href="https://github.com/LCA-ActivityBrowser/activity-browser">github</a>.<br><br>
46-
For copyright information please see the copyright on <a href="https://github.com/LCA-ActivityBrowser/activity-browser/tree/main#copyright">this page</a>.<br><br>
47-
For license information please see the copyright on <a href="https://github.com/LCA-ActivityBrowser/activity-browser/blob/main/LICENSE.txt">this page</a>.<br><br>
48-
"""
49-
msgBox = QtWidgets.QMessageBox(parent=self.parent())
50-
msgBox.setWindowTitle("About the Activity Browser")
51-
pixmap = self.parent().icon.pixmap(QSize(150, 150))
52-
msgBox.setIconPixmap(pixmap)
53-
msgBox.setWindowIcon(self.parent().icon)
54-
msgBox.setText(text.format(ab_version))
55-
msgBox.exec_()
56-
57-
def open_wiki(self):
58-
url = QUrl(
59-
"https://github.com/LCA-ActivityBrowser/activity-browser/wiki"
60-
)
61-
QtGui.QDesktopServices.openUrl(url)
62-
63-
def raise_issue_github(self):
64-
url = QUrl(
65-
"https://github.com/LCA-ActivityBrowser/activity-browser/issues/new/choose"
66-
)
67-
QtGui.QDesktopServices.openUrl(url)
22+
self.addMenu(HelpMenu(self))
6823

6924

7025
class ProjectMenu(QtWidgets.QMenu):
@@ -145,6 +100,56 @@ def __init__(self, parent=None) -> None:
145100
self.addAction(self.manage_plugins_action)
146101

147102

103+
class HelpMenu(QtWidgets.QMenu):
104+
def __init__(self, parent=None) -> None:
105+
super().__init__(parent)
106+
self.setTitle("&Help")
107+
108+
self.addAction(
109+
qicons.ab, "&About Activity Browser", self.about
110+
)
111+
self.addAction(
112+
"&About Qt", lambda: QtWidgets.QMessageBox.aboutQt(application.main_window)
113+
)
114+
self.addAction(
115+
qicons.question, "&Get help on the wiki", self.open_wiki
116+
)
117+
self.addAction(
118+
qicons.issue, "&Report an idea/issue on GitHub", self.raise_issue_github
119+
)
120+
121+
def about(self):
122+
text = f"""
123+
Activity Browser - a graphical interface for Brightway2.<br><br>
124+
Application version: <b>{version("activity_browser")}</b><br>
125+
bw2data version: <b>{version("bw2data")}</b><br>
126+
bw2io version: <b>{version("bw2calc")}</b><br>
127+
bw2calc version: <b>{version("bw2io")}</b><br><br>
128+
All development happens on <a href="https://github.com/LCA-ActivityBrowser/activity-browser">github</a>.<br><br>
129+
For copyright information please see the copyright on <a href="https://github.com/LCA-ActivityBrowser/activity-browser/tree/main#copyright">this page</a>.<br><br>
130+
For license information please see the copyright on <a href="https://github.com/LCA-ActivityBrowser/activity-browser/blob/main/LICENSE.txt">this page</a>.<br><br>
131+
"""
132+
133+
about_window = QtWidgets.QMessageBox(parent=application.main_window)
134+
about_window.setWindowTitle("About the Activity Browser")
135+
about_window.setIconPixmap(qicons.ab.pixmap(QSize(150, 150)))
136+
about_window.setText(text)
137+
138+
about_window.exec_()
139+
140+
def open_wiki(self):
141+
url = QUrl(
142+
"https://github.com/LCA-ActivityBrowser/activity-browser/wiki"
143+
)
144+
QtGui.QDesktopServices.openUrl(url)
145+
146+
def raise_issue_github(self):
147+
url = QUrl(
148+
"https://github.com/LCA-ActivityBrowser/activity-browser/issues/new/choose"
149+
)
150+
QtGui.QDesktopServices.openUrl(url)
151+
152+
148153
class ProjectSelectionMenu(QtWidgets.QMenu):
149154
"""
150155
Menu that lists all the projects available through bw2data.projects

0 commit comments

Comments
 (0)