Skip to content

Commit d4994be

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 69ec6bb + 0c75d6c commit d4994be

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

activity_browser/layouts/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
import importlib.util
3-
import shutil
4-
import sys
5-
import traceback
2+
from PySide2 import QtCore, QtWidgets
63

7-
from PySide2 import QtCore, QtGui, QtWidgets
4+
import activity_browser.mod.bw2data as bd
85

96
from ..signals import signals
107
from ..ui.icons import qicons
@@ -77,6 +74,11 @@ def connect_signals(self):
7774
# Keyboard shortcuts
7875
signals.restore_cursor.connect(self.restore_user_control)
7976

77+
bd.projects.current_changed.connect(self.set_titlebar)
78+
79+
def set_titlebar(self):
80+
self.setWindowTitle(f"Activity Browser - {bd.projects.current}")
81+
8082
def add_tab_to_panel(self, obj, label, side):
8183
panel = self.left_panel if side == "left" else self.right_panel
8284
panel.add_tab(obj, label)

activity_browser/ui/menu_bar.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from PySide2 import QtGui, QtWidgets
23
from PySide2.QtCore import QSize, QUrl, Slot
34

@@ -7,6 +8,8 @@
78
from ..info import __version__ as ab_version
89
from .icons import qicons
910

11+
AB_BW25 = True if os.environ.get("AB_BW25", False) else False
12+
1013

1114
class MenuBar(QtWidgets.QMenuBar):
1215
def __init__(self, window):
@@ -46,6 +49,7 @@ def connect_signals(self):
4649

4750
def setup_file_menu(self) -> None:
4851
"""Build the menu for specific importing/export/updating actions."""
52+
self.file_menu.addMenu(ProjectsMenu(self))
4953
self.file_menu.addAction(self.new_proj_action)
5054
self.file_menu.addAction(self.dup_proj_action)
5155
self.file_menu.addAction(self.delete_proj_action)
@@ -92,7 +96,7 @@ def setup_help_menu(self) -> None:
9296
"&About Qt", lambda: QtWidgets.QMessageBox.aboutQt(self.window)
9397
)
9498
self.help_menu.addAction(
95-
qicons.question, "&Get help on the wiki", self.open_wiki()
99+
qicons.question, "&Get help on the wiki", self.open_wiki
96100
)
97101
self.help_menu.addAction(
98102
qicons.issue, "&Report an idea/issue on GitHub", self.raise_issue_github
@@ -134,6 +138,47 @@ def biosphere_exists(self) -> None:
134138
self.import_db_action.setEnabled(exists)
135139

136140

141+
class ProjectsMenu(QtWidgets.QMenu):
142+
"""
143+
Menu that lists all the projects available through bw2data.projects
144+
"""
145+
def __init__(self, parent=None):
146+
super().__init__(parent)
147+
self.setTitle("Open project")
148+
self.populate()
149+
150+
self.aboutToShow.connect(self.populate)
151+
self.triggered.connect(lambda act: bd.projects.set_current(act.text()))
152+
153+
def populate(self):
154+
"""
155+
Populates the menu with the projects available in the database
156+
"""
157+
import bw2data as bd
158+
159+
# clear the menu of any already existing actions
160+
self.clear()
161+
162+
# sort projects alphabetically
163+
sorted_projects = sorted(list(bd.projects))
164+
165+
# iterate over the sorted projects and add them as actions to the menu
166+
for i, proj in enumerate(sorted_projects):
167+
# check whether the project is BW25
168+
bw_25 = (
169+
False if not isinstance(proj.data, dict) else proj.data.get("25", False)
170+
)
171+
172+
# add BW25 decorations if necessary
173+
name = proj.name if not bw_25 or AB_BW25 else "[BW25] " + proj.name
174+
175+
# create the action and disable it if it's BW25 and BW25 is not supported
176+
action = QtWidgets.QAction(name, self)
177+
action.setEnabled(not bw_25 or AB_BW25)
178+
179+
self.addAction(action)
180+
181+
137182
class MigrationsMenu(QtWidgets.QMenu):
138183
def __init__(self, parent=None) -> None:
139184
super().__init__(parent)
@@ -143,5 +188,3 @@ def __init__(self, parent=None) -> None:
143188

144189
self.addAction(self.install_migrations_action)
145190

146-
147-

activity_browser/ui/tables/impact_categories.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def connect_signals(self):
4646
self.model.updated.connect(self.update_proxy_model)
4747
methods.metadata_changed.connect(self.sync)
4848

49-
def selected_methods(self) -> Iterable:
50-
"""Returns a generator which yields the 'method' for each row."""
51-
return (self.model.get_method(p) for p in self.selectedIndexes())
49+
def selected_methods(self) -> list:
50+
"""Returns a list of all the currently selected methods."""
51+
return [self.model.get_method(p) for p in self.selectedIndexes()]
5252

5353
@Slot(name="syncTable")
5454
def sync(self, query=None) -> None:

0 commit comments

Comments
 (0)