Skip to content

Commit 8d33650

Browse files
authored
Added Open Impact Category to Calculation Setup screen (#1338)
1 parent 0456796 commit 8d33650

4 files changed

Lines changed: 45 additions & 3 deletions

File tree

activity_browser/actions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from .method.method_duplicate import MethodDuplicate
3232
from .method.method_delete import MethodDelete
33+
from .method.method_open import MethodOpen
3334

3435
from .method.cf_uncertainty_modify import CFUncertaintyModify
3536
from .method.cf_amount_modify import CFAmountModify
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List
2+
3+
from PySide2 import QtWidgets, QtCore
4+
5+
from activity_browser import signals
6+
from activity_browser.actions.base import ABAction, exception_dialogs
7+
from activity_browser.ui.icons import qicons
8+
9+
10+
class MethodOpen(ABAction):
11+
"""
12+
ABAction to open one or more supplied methods in a method tab by employing signals.
13+
14+
TODO: move away from using signals like this. Probably add a method to the MainWindow to add a panel instead.
15+
"""
16+
17+
icon = qicons.right
18+
text = "Open Impact Category"
19+
20+
@staticmethod
21+
@exception_dialogs
22+
def run(method_names: List[tuple]):
23+
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
24+
for method_name in method_names:
25+
signals.method_selected.emit(method_name)
26+
QtWidgets.QApplication.restoreOverrideCursor()

activity_browser/ui/tables/LCA_setup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from PySide2 import QtWidgets
22
from PySide2.QtCore import Qt, Slot
33

4-
from activity_browser import log, signals
4+
from activity_browser import log, signals, actions
55
from activity_browser.mod.bw2data import calculation_setups
66

77
from ..icons import qicons
@@ -174,6 +174,8 @@ def __init__(self, parent=None):
174174
"Hold CTRL and click to select multiple rows to open or delete them."
175175
)
176176

177+
self.open_method_action = actions.MethodOpen.get_QAction(self.selected_methods)
178+
177179
def to_python(self):
178180
return self.model.methods
179181

@@ -195,11 +197,14 @@ def contextMenuEvent(self, event) -> None:
195197
if self.indexAt(event.pos()).row() == -1:
196198
return
197199
menu = QtWidgets.QMenu()
200+
201+
menu.addAction(self.open_method_action)
198202
menu.addAction(
199203
qicons.delete,
200-
"Remove row",
204+
"Remove rows",
201205
lambda: self.model.delete_rows(self.selectedIndexes()),
202206
)
207+
203208
menu.exec_(event.globalPos())
204209

205210
def dragEnterEvent(self, event):
@@ -225,6 +230,9 @@ def dropEvent(self, event):
225230
):
226231
self.model.relocateRow(from_index, to_index)
227232

233+
def selected_methods(self):
234+
return [self.model.get_method(p) for p in self.selectedIndexes() if p.column() == 0]
235+
228236

229237
class ScenarioImportTable(ABDataFrameView):
230238
"""Self-contained widget that shows the scenario headers for a given

activity_browser/ui/tables/models/lca_setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterable
1+
from typing import Iterable, List, Union
22

33
import numpy as np
44
import pandas as pd
@@ -192,6 +192,13 @@ def methods(self) -> list:
192192
else self._dataframe.loc[:, "method"].to_list()
193193
)
194194

195+
def get_method(self, proxy: Union[QModelIndex, int]) -> tuple:
196+
"""
197+
Return the method coupled to a model index
198+
"""
199+
idx = self.proxy_to_source(proxy)
200+
return self._dataframe["method"][idx.row()]
201+
195202
def load(self, cs_name: str = None) -> None:
196203
"""
197204
Load a calculation setup defined by cs_name into the methods table.

0 commit comments

Comments
 (0)