brightway-basic-explorer 0.9.dev2__tar.gz → 0.9.dev3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/PKG-INFO +1 -1
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer/__init__.py +73 -13
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer.egg-info/PKG-INFO +1 -1
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/pyproject.toml +1 -1
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/COPYING +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/README.md +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer/icons/emission.png +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer/icons/natural_resource.png +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer/icons/process.png +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer/icons/unknown.png +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer.egg-info/SOURCES.txt +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer.egg-info/dependency_links.txt +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer.egg-info/requires.txt +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/brightway_basic_explorer.egg-info/top_level.txt +0 -0
- {brightway_basic_explorer-0.9.dev2 → brightway_basic_explorer-0.9.dev3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: brightway-basic-explorer
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.dev3
|
|
4
4
|
Summary: Implement basic GUI to explorer brightway ativities
|
|
5
5
|
Author-email: Benoît GSCHWIND <benoit.gschwind@minesparis.psl.eu>, OIE - Mines Paris PSL <benoit.gschwind@minesparis.psl.eu>
|
|
6
6
|
Maintainer-email: Benoît GSCHWIND <benoit.gschwind@minesparis.psl.eu>
|
|
@@ -18,6 +18,40 @@ def activity_to_json(act):
|
|
|
18
18
|
a["exchanges"] = exs
|
|
19
19
|
return a
|
|
20
20
|
|
|
21
|
+
def activity_to_json_with_params(act, params):
|
|
22
|
+
try:
|
|
23
|
+
from lca_algebraic.params import (
|
|
24
|
+
all_params,
|
|
25
|
+
_complete_and_expand_params,
|
|
26
|
+
_getAmountOrFormula,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from sympy import Basic, Symbol
|
|
30
|
+
except:
|
|
31
|
+
raise Exception("lca_algebraic not found, please install it before using show_activity_with_params")
|
|
32
|
+
|
|
33
|
+
a = dict(act)
|
|
34
|
+
exs = list()
|
|
35
|
+
for e in act.exchanges():
|
|
36
|
+
de = dict(bw2data.get_activity(e["input"]))
|
|
37
|
+
|
|
38
|
+
amount = _getAmountOrFormula(e)
|
|
39
|
+
|
|
40
|
+
# Params provided ? Evaluate formulas
|
|
41
|
+
if isinstance(amount, Basic):
|
|
42
|
+
print(amount)
|
|
43
|
+
new_params = [(name, value) for name, value in _complete_and_expand_params(params, list(all_params().keys())).items()]
|
|
44
|
+
print(new_params)
|
|
45
|
+
amount = amount.subs(new_params).evalf()
|
|
46
|
+
print(amount)
|
|
47
|
+
de["computed_amount"] = True
|
|
48
|
+
|
|
49
|
+
de["amount"] = amount
|
|
50
|
+
de["formula"] = e.get("formula", None)
|
|
51
|
+
exs.append(de)
|
|
52
|
+
a["exchanges"] = exs
|
|
53
|
+
return a
|
|
54
|
+
|
|
21
55
|
class QStandardItemRO(QtGui.QStandardItem):
|
|
22
56
|
def __init__(self, *args, data=None, **kwargs):
|
|
23
57
|
super().__init__(*args, **kwargs)
|
|
@@ -46,6 +80,9 @@ class TableModel(QtGui.QStandardItemModel):
|
|
|
46
80
|
for k in ["name", "unit", "categories", "location", "amount", "formula"]
|
|
47
81
|
]
|
|
48
82
|
|
|
83
|
+
if "computed_amount" in e:
|
|
84
|
+
row[-2].setForeground(QtGui.QBrush(QtCore.Qt.GlobalColor.red))
|
|
85
|
+
|
|
49
86
|
etype = e.get("type", "unknown")
|
|
50
87
|
if etype == "emission":
|
|
51
88
|
path = os.path.join(os.path.dirname(__file__), "icons", "emission.png")
|
|
@@ -89,11 +126,9 @@ class ActionMenu(QtGui.QMenu):
|
|
|
89
126
|
class ActivityWindow(QtGui.QMainWindow):
|
|
90
127
|
keep = dict()
|
|
91
128
|
|
|
92
|
-
def __init__(self,
|
|
129
|
+
def __init__(self, activity_json):
|
|
93
130
|
super().__init__()
|
|
94
|
-
self.
|
|
95
|
-
|
|
96
|
-
data = activity_to_json(act)
|
|
131
|
+
self.activity_key = (activity_json["database"], activity_json["code"])
|
|
97
132
|
|
|
98
133
|
self.setWindowTitle("Activity Viewer")
|
|
99
134
|
self.setGeometry(100, 100, 800, 600)
|
|
@@ -109,7 +144,7 @@ class ActivityWindow(QtGui.QMainWindow):
|
|
|
109
144
|
|
|
110
145
|
for i, k in enumerate(["database", "name", "location", "unit", "categories", "type"]):
|
|
111
146
|
grid.addWidget(QtGui.QLabel(f"{k}:"), i, 0)
|
|
112
|
-
x = QtGui.QLabel(f"{str(
|
|
147
|
+
x = QtGui.QLabel(f"{str(activity_json.get(k, '-'))}")
|
|
113
148
|
x.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.TextSelectableByMouse)
|
|
114
149
|
grid.addWidget(x, i, 1)
|
|
115
150
|
next_row = grid.rowCount()
|
|
@@ -134,7 +169,7 @@ class ActivityWindow(QtGui.QMainWindow):
|
|
|
134
169
|
self.tree_view.setAlternatingRowColors(True)
|
|
135
170
|
|
|
136
171
|
self.model = TableModel()
|
|
137
|
-
self.model.load(
|
|
172
|
+
self.model.load(activity_json["exchanges"])
|
|
138
173
|
self.tree_view.setModel(self.model)
|
|
139
174
|
self.tree_view.doubleClicked.connect(self.doubleCliked)
|
|
140
175
|
self.tree_view.setExpandsOnDoubleClick(False)
|
|
@@ -149,8 +184,8 @@ class ActivityWindow(QtGui.QMainWindow):
|
|
|
149
184
|
self.action_menu.exec(self.tree_view.viewport().mapToGlobal(point))
|
|
150
185
|
|
|
151
186
|
def closeEvent(self, ev):
|
|
152
|
-
if self.
|
|
153
|
-
del ActivityWindow.keep[self.
|
|
187
|
+
if self.activity_key in ActivityWindow.keep:
|
|
188
|
+
del ActivityWindow.keep[self.activity_key]
|
|
154
189
|
super().closeEvent(ev)
|
|
155
190
|
|
|
156
191
|
def update_filter(self, *args):
|
|
@@ -173,12 +208,29 @@ class ActivityWindow(QtGui.QMainWindow):
|
|
|
173
208
|
def explore(self, index):
|
|
174
209
|
r = index.row()
|
|
175
210
|
v = self.model.root.child(r, 0).data()
|
|
176
|
-
show_activity(bw2data.get_activity((v["database"], v["code"])))
|
|
211
|
+
show_activity(bw2data.get_activity((v["database"], v["code"])), self.params)
|
|
177
212
|
|
|
178
213
|
def show(self, *args, **kwargs):
|
|
179
214
|
super().show(*args, **kwargs)
|
|
180
215
|
self.tree_view.setColumnWidth(0, 400)
|
|
181
216
|
|
|
217
|
+
class ActivityWindowWithParams(ActivityWindow):
|
|
218
|
+
keep = dict()
|
|
219
|
+
|
|
220
|
+
def __init__(self, activity_json, params):
|
|
221
|
+
super().__init__(activity_json)
|
|
222
|
+
self.params = params
|
|
223
|
+
|
|
224
|
+
def closeEvent(self, ev):
|
|
225
|
+
if self.activity_key in ActivityWindow.keep:
|
|
226
|
+
del ActivityWindowWithParams.keep[self.activity_key]
|
|
227
|
+
super().closeEvent(ev)
|
|
228
|
+
|
|
229
|
+
def explore(self, index):
|
|
230
|
+
r = index.row()
|
|
231
|
+
v = self.model.root.child(r, 0).data()
|
|
232
|
+
show_activity_with_params(bw2data.get_activity((v["database"], v["code"])), self.params)
|
|
233
|
+
|
|
182
234
|
# Replace IPython version to one compatible with Qt6
|
|
183
235
|
def start_event_loop_qt4(app=None):
|
|
184
236
|
"""Start the qt event loop in a consistent manner."""
|
|
@@ -194,7 +246,7 @@ def start_event_loop_qt4(app=None):
|
|
|
194
246
|
else:
|
|
195
247
|
app._in_event_loop = True
|
|
196
248
|
|
|
197
|
-
def
|
|
249
|
+
def _show_activity(cls, activity_json, *args):
|
|
198
250
|
|
|
199
251
|
if 'matplotlib' in sys.modules:
|
|
200
252
|
import matplotlib
|
|
@@ -204,9 +256,9 @@ def show_activity(act):
|
|
|
204
256
|
|
|
205
257
|
app = get_app_qt4()
|
|
206
258
|
|
|
207
|
-
if (window :=
|
|
208
|
-
window =
|
|
209
|
-
|
|
259
|
+
if (window := cls.keep.get((activity_json["database"], activity_json["code"]), None)) is None:
|
|
260
|
+
window = cls(activity_json, *args)
|
|
261
|
+
cls.keep[(activity_json["database"], activity_json["code"])] = window
|
|
210
262
|
window.show()
|
|
211
263
|
|
|
212
264
|
if not is_event_loop_running_qt4(app):
|
|
@@ -214,6 +266,14 @@ def show_activity(act):
|
|
|
214
266
|
|
|
215
267
|
window.activateWindow()
|
|
216
268
|
|
|
269
|
+
def show_activity(act):
|
|
270
|
+
activity_json = activity_to_json(act)
|
|
271
|
+
_show_activity(ActivityWindow, activity_json)
|
|
272
|
+
|
|
273
|
+
def show_activity_with_params(act, params):
|
|
274
|
+
activity_json = activity_to_json_with_params(act, params)
|
|
275
|
+
_show_activity(ActivityWindowWithParams, activity_json, params)
|
|
276
|
+
|
|
217
277
|
def close_all():
|
|
218
278
|
for w in list(ActivityWindow.keep.values()):
|
|
219
279
|
w.close()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: brightway-basic-explorer
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.dev3
|
|
4
4
|
Summary: Implement basic GUI to explorer brightway ativities
|
|
5
5
|
Author-email: Benoît GSCHWIND <benoit.gschwind@minesparis.psl.eu>, OIE - Mines Paris PSL <benoit.gschwind@minesparis.psl.eu>
|
|
6
6
|
Maintainer-email: Benoît GSCHWIND <benoit.gschwind@minesparis.psl.eu>
|
|
@@ -12,7 +12,7 @@ name = "brightway-basic-explorer"
|
|
|
12
12
|
description = "Implement basic GUI to explorer brightway ativities"
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
license-files = ["COPYING"]
|
|
15
|
-
version = "0.9.
|
|
15
|
+
version = "0.9.dev3"
|
|
16
16
|
dependencies = [ "ipython" ]
|
|
17
17
|
requires-python = ">= 3.10"
|
|
18
18
|
keywords = ["lca", "ecoinvent", "brightway"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|