Skip to content

Commit 918e8bc

Browse files
committed
Process types into calculation setups
1 parent 34182ab commit 918e8bc

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from qtpy import QtWidgets, QtCore
2+
from activity_browser import actions
3+
from activity_browser.ui import widgets
4+
5+
6+
class ImpactCategoryHeader(QtWidgets.QWidget):
7+
8+
def __init__(self, parent: QtWidgets.QWidget):
9+
"""
10+
Initializes the ActivityHeader widget.
11+
12+
Args:
13+
parent (QtWidgets.QWidget): The parent widget.
14+
"""
15+
super().__init__(parent)
16+
self.impact_category = parent.impact_category
17+
18+
layout = QtWidgets.QVBoxLayout()
19+
layout.setContentsMargins(0, 0, 0, 0)
20+
self.setLayout(layout)
21+
22+
def sync(self):
23+
"""
24+
Synchronizes the widget with the current state of the activity.
25+
"""
26+
self.clear_layout()
27+
self.layout().addLayout(self.build_grid())
28+
29+
def clear_layout(self, layout: QtWidgets.QLayout = None):
30+
layout = layout or self.layout()
31+
32+
if layout is None:
33+
return
34+
35+
while layout.count():
36+
item = layout.takeAt(0)
37+
widget = item.widget()
38+
if widget is not None:
39+
widget.deleteLater()
40+
elif item.layout() is not None:
41+
self.clear_layout(item.layout())
42+
43+
def build_grid(self) -> QtWidgets.QGridLayout:
44+
grid = QtWidgets.QGridLayout(self)
45+
grid.setContentsMargins(0, 5, 0, 5)
46+
grid.setSpacing(10)
47+
grid.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
48+
49+
setup = [
50+
("Name:", QtWidgets.QLabel(str(self.impact_category.name)),),
51+
("Unit:", QtWidgets.QLabel(str(self.impact_category.metadata.get("unit", "Undefined"))),),
52+
]
53+
54+
# Arrange widgets for display as a grid
55+
for i, (title, widget) in enumerate(setup):
56+
grid.addWidget(widgets.ABLabel.demiBold(title, self), i, 1)
57+
grid.addWidget(widget, i, 2, 1, 4)
58+
59+
return grid
60+
61+
62+
class ImpactCategoryName(QtWidgets.QLineEdit):
63+
"""
64+
A widget that displays and edits the name of the activity.
65+
"""
66+
67+
def __init__(self, parent: ImpactCategoryHeader):
68+
"""
69+
Initializes the ActivityName widget.
70+
71+
Args:
72+
parent (ActivityHeader): The parent widget.
73+
"""
74+
super().__init__(str(parent.impact_category.name), parent)
75+
self.editingFinished.connect(self.change_name)
76+
77+
def change_name(self):
78+
"""
79+
Changes the name of the activity if it has been modified.
80+
"""
81+
if self.text() == self.parent().impact_category.name:
82+
return
83+
# actions.ActivityModify.run(self.parent().activity, "name", self.text())

0 commit comments

Comments
 (0)