Skip to content

Commit aeaef00

Browse files
committed
Process types into Calculation Setups
1 parent b64540f commit aeaef00

1 file changed

Lines changed: 4 additions & 54 deletions

File tree

activity_browser/layouts/pages/calculation_setup/functional_unit_section.py

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from qtpy import QtWidgets
2-
from qtpy.QtCore import Qt
32

43
import bw2data as bd
54
import pandas as pd
65

76
from activity_browser import actions
8-
from activity_browser.ui import widgets, icons, delegates
7+
from activity_browser.ui import widgets, icons
98
from activity_browser.bwutils import AB_metadata
109

1110

@@ -47,7 +46,6 @@ def build_df(self):
4746
act_df = AB_metadata.get_metadata(keys, cols)
4847
act_df["amount"] = amounts
4948
act_df["_activity_key"] = keys
50-
act_df["_cs_name"] = self.calculation_setup_name
5149

5250
act_df["_processor_key"] = act_df["processor"]
5351
act_df["_processor_key"] = act_df["_processor_key"].fillna(act_df["_activity_key"])
@@ -75,15 +73,12 @@ def build_df(self):
7573
act_df.update(act_df["product"].rename("name"))
7674
act_df["product"] = act_df["name"]
7775

78-
cols = ["amount", "unit", "product", "process", "database", "location", "_processor_key", "_activity_key", "_cs_name"]
76+
cols = ["amount", "unit", "product", "process", "database", "location", "_processor_key", "_activity_key"]
7977

8078
return act_df[cols].reset_index(drop=True)
8179

8280

8381
class FunctionalUnitView(widgets.ABTreeView):
84-
defaultColumnDelegates = {
85-
"amount": delegates.AmountDelegate
86-
}
8782

8883
class ContextMenu(widgets.ABMenu):
8984
menuSetup = [
@@ -124,16 +119,10 @@ def mouseDoubleClickEvent(self, event) -> None:
124119
Args:
125120
event: The mouse double click event.
126121
"""
127-
index = self.indexAt(event.pos())
128-
if index.column() == 0:
129-
return super().mouseDoubleClickEvent(event)
130-
131122
if self.selectedIndexes():
132123
activities = [index.internalPointer()["_processor_key"] for index in self.selectedIndexes()]
133124
actions.ActivityOpen.run(list(set(activities)))
134125

135-
return None
136-
137126
def dragMoveEvent(self, event) -> None:
138127
pass
139128

@@ -142,7 +131,7 @@ def dragEnterEvent(self, event):
142131
keys: list = event.mimeData().retrievePickleData("application/bw-nodekeylist")
143132
for key in keys:
144133
act = bd.get_node(key=key)
145-
if act["type"] not in bd.labels.product_node_types + ["processwithreferenceproduct"]:
134+
if act["type"] not in bd.labels.product_node_types + ["processwithreferenceproduct", "process"]:
146135
keys.remove(key)
147136

148137
if not keys:
@@ -157,7 +146,7 @@ def dropEvent(self, event) -> None:
157146
keys: list = event.mimeData().retrievePickleData("application/bw-nodekeylist")
158147
for key in keys:
159148
act = bd.get_node(key=key)
160-
if act["type"] not in bd.labels.product_node_types + ["processwithreferenceproduct"]:
149+
if act["type"] not in bd.labels.product_node_types + ["processwithreferenceproduct", "process"]:
161150
keys.remove(key)
162151

163152
actions.CSAddFunctionalUnit.run(cs_name, keys)
@@ -169,45 +158,6 @@ def decorationData(self, col: int, key: str):
169158
return icons.qicons.product
170159
if key == "process":
171160
return icons.qicons.process
172-
return super().decorationData(col, key)
173-
174-
def flags(self, col: int, key: str):
175-
"""
176-
Returns the item flags for the given column and key.
177-
178-
Args:
179-
col (int): The column index.
180-
key (str): The key for which to return the flags.
181-
182-
Returns:
183-
QtCore.Qt.ItemFlags: The item flags.
184-
"""
185-
flags = super().flags(col, key)
186-
if key in ["amount"]:
187-
return flags | Qt.ItemFlag.ItemIsEditable
188-
return flags
189-
190-
def setData(self, col: int, key: str, value) -> bool:
191-
"""
192-
Sets the data for the given column and key.
193-
194-
Args:
195-
col (int): The column index.
196-
key (str): The key for which to set the data.
197-
value: The value to set.
198-
199-
Returns:
200-
bool: True if the data was set successfully, False otherwise.
201-
"""
202-
if key not in ["amount"]:
203-
return False
204-
205-
cs_name = self["_cs_name"]
206-
index = self.key()
207-
208-
actions.CSChangeFunctionalUnit.run(cs_name, index, value)
209-
210-
211161

212162

213163
class FunctionalUnitModel(widgets.ABItemModel):

0 commit comments

Comments
 (0)