brightway-basic-explorer 0.9.dev0__tar.gz → 0.9.dev2__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.
Files changed (17) hide show
  1. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/PKG-INFO +31 -2
  2. brightway_basic_explorer-0.9.dev2/README.md +28 -0
  3. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/brightway_basic_explorer/__init__.py +61 -14
  4. brightway_basic_explorer-0.9.dev2/brightway_basic_explorer/icons/emission.png +0 -0
  5. brightway_basic_explorer-0.9.dev2/brightway_basic_explorer/icons/natural_resource.png +0 -0
  6. brightway_basic_explorer-0.9.dev2/brightway_basic_explorer/icons/process.png +0 -0
  7. brightway_basic_explorer-0.9.dev2/brightway_basic_explorer/icons/unknown.png +0 -0
  8. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/brightway_basic_explorer.egg-info/PKG-INFO +31 -2
  9. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/brightway_basic_explorer.egg-info/SOURCES.txt +5 -1
  10. brightway_basic_explorer-0.9.dev2/brightway_basic_explorer.egg-info/requires.txt +1 -0
  11. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/pyproject.toml +5 -3
  12. brightway_basic_explorer-0.9.dev0/README.md +0 -0
  13. brightway_basic_explorer-0.9.dev0/brightway_basic_explorer.egg-info/requires.txt +0 -1
  14. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/COPYING +0 -0
  15. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/brightway_basic_explorer.egg-info/dependency_links.txt +0 -0
  16. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/brightway_basic_explorer.egg-info/top_level.txt +0 -0
  17. {brightway_basic_explorer-0.9.dev0 → brightway_basic_explorer-0.9.dev2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: brightway-basic-explorer
3
- Version: 0.9.dev0
3
+ Version: 0.9.dev2
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>
@@ -16,5 +16,34 @@ Classifier: Programming Language :: Python :: 3.13
16
16
  Requires-Python: >=3.10
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: COPYING
19
- Requires-Dist: PyQt6
19
+ Requires-Dist: ipython
20
20
  Dynamic: license-file
21
+
22
+ # Brightway Basic Explorer
23
+
24
+ Implement a basic activity explorer mostly to use in interractive python such as notebooks, ipython and spyder.
25
+
26
+ # Install
27
+
28
+ ```
29
+ pip install brightway_basic_explorer
30
+ ```
31
+
32
+ # Sample and Documentation
33
+
34
+ ![Sample Window](https://github.com/gschwind/brightway-basic-explorer/raw/main/doc/sample-window.png)
35
+
36
+ ```python
37
+ import bw2data
38
+ from brightway_basic_explorer import show_activity, close_all
39
+
40
+ db = bw2data.Database("ecoinvent-3.11-cutoff")
41
+
42
+ act = db.search("570kWp")
43
+
44
+ # Show the first activity
45
+ show_activity(act[0])
46
+
47
+ # Close all activity windows
48
+ close_all()
49
+ ```
@@ -0,0 +1,28 @@
1
+ # Brightway Basic Explorer
2
+
3
+ Implement a basic activity explorer mostly to use in interractive python such as notebooks, ipython and spyder.
4
+
5
+ # Install
6
+
7
+ ```
8
+ pip install brightway_basic_explorer
9
+ ```
10
+
11
+ # Sample and Documentation
12
+
13
+ ![Sample Window](https://github.com/gschwind/brightway-basic-explorer/raw/main/doc/sample-window.png)
14
+
15
+ ```python
16
+ import bw2data
17
+ from brightway_basic_explorer import show_activity, close_all
18
+
19
+ db = bw2data.Database("ecoinvent-3.11-cutoff")
20
+
21
+ act = db.search("570kWp")
22
+
23
+ # Show the first activity
24
+ show_activity(act[0])
25
+
26
+ # Close all activity windows
27
+ close_all()
28
+ ```
@@ -3,7 +3,8 @@
3
3
  from IPython.external.qt_for_kernel import QtGui, QtCore
4
4
  from IPython.lib.guisupport import start_event_loop_qt4, get_app_qt4, is_event_loop_running_qt4
5
5
 
6
- import matplotlib
6
+ import os
7
+ import sys
7
8
  import bw2data
8
9
 
9
10
  def activity_to_json(act):
@@ -40,10 +41,23 @@ class TableModel(QtGui.QStandardItemModel):
40
41
  self.exchanges = [e for e in data]
41
42
  self.root = self.invisibleRootItem()
42
43
  for e in data:
43
- self.root.appendRow([
44
+ row = [
44
45
  QStandardItemRO(str(e.get(k, "-")), data=e)
45
46
  for k in ["name", "unit", "categories", "location", "amount", "formula"]
46
- ])
47
+ ]
48
+
49
+ etype = e.get("type", "unknown")
50
+ if etype == "emission":
51
+ path = os.path.join(os.path.dirname(__file__), "icons", "emission.png")
52
+ elif etype in {"process", "processwithreferenceproduct"}:
53
+ path = os.path.join(os.path.dirname(__file__), "icons", "process.png")
54
+ elif etype == "natural resource":
55
+ path = os.path.join(os.path.dirname(__file__), "icons", "natural_resource.png")
56
+ else:
57
+ path = os.path.join(os.path.dirname(__file__), "icons", "unknown.png")
58
+
59
+ row[0].setIcon(QtGui.QIcon(path))
60
+ self.root.appendRow(row)
47
61
 
48
62
  class ActionMenu(QtGui.QMenu):
49
63
  def __init__(self, parent, index):
@@ -53,12 +67,21 @@ class ActionMenu(QtGui.QMenu):
53
67
  self.action_copy = self.addAction("Copy")
54
68
  self.action_copy.triggered.connect(self.copy_triggered)
55
69
 
70
+ self.action_copy = self.addAction("Copy Full Reference")
71
+ self.action_copy.triggered.connect(self.copy_full_reference_triggered)
72
+
56
73
  self.action_explore = self.addAction("Explore")
57
74
  self.action_explore.triggered.connect(self.explore_triggered)
58
75
 
59
76
  def copy_triggered(self):
60
77
  QtGui.QGuiApplication.clipboard().setText(self.index.data())
61
78
 
79
+ def copy_full_reference_triggered(self):
80
+ parent = self.parentWidget()
81
+ v = parent.model.root.child(self.index.row(), 0).data()
82
+ text = (v["database"], v["name"], v.get("location", None), v.get("categories", tuple()), v.get("unit", None))
83
+ QtGui.QGuiApplication.clipboard().setText(str(text))
84
+
62
85
  def explore_triggered(self):
63
86
  self.parentWidget().explore(self.index)
64
87
 
@@ -84,15 +107,16 @@ class ActivityWindow(QtGui.QMainWindow):
84
107
  grid = QtGui.QGridLayout()
85
108
  layout.addLayout(grid)
86
109
 
87
- for i, k in enumerate(["database", "name", "location", "unit", "categories"]):
110
+ for i, k in enumerate(["database", "name", "location", "unit", "categories", "type"]):
88
111
  grid.addWidget(QtGui.QLabel(f"{k}:"), i, 0)
89
112
  x = QtGui.QLabel(f"{str(data.get(k, '-'))}")
90
113
  x.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.TextSelectableByMouse)
91
114
  grid.addWidget(x, i, 1)
92
- grid.addWidget(QtGui.QLabel("filter:"), 5, 0)
115
+ next_row = grid.rowCount()
116
+ grid.addWidget(QtGui.QLabel("filter:"), next_row, 0)
93
117
  self.filter_edit = QtGui.QLineEdit("")
94
118
  self.filter_edit.textChanged.connect(self.update_filter)
95
- grid.addWidget(self.filter_edit, 5, 1)
119
+ grid.addWidget(self.filter_edit, next_row, 1)
96
120
  grid.setColumnStretch(0, 0)
97
121
  grid.setColumnStretch(1, 1)
98
122
  self.ignore_case = QtGui.QCheckBox("Ignore Case")
@@ -101,7 +125,8 @@ class ActivityWindow(QtGui.QMainWindow):
101
125
  self.ignore_case.checkStateChanged.connect(self.update_filter)
102
126
  else:
103
127
  self.ignore_case.stateChanged.connect(self.update_filter)
104
- grid.addWidget(self.ignore_case, 6, 1)
128
+ next_row = grid.rowCount()
129
+ grid.addWidget(self.ignore_case, next_row, 1)
105
130
  # Create tree view
106
131
  self.tree_view = QtGui.QTreeView()
107
132
  layout.addWidget(self.tree_view)
@@ -115,7 +140,7 @@ class ActivityWindow(QtGui.QMainWindow):
115
140
  self.tree_view.setExpandsOnDoubleClick(False)
116
141
  self.tree_view.setSelectionBehavior(QtGui.QAbstractItemView.SelectionBehavior.SelectItems)
117
142
  #self.tree_view.rightClick.connect(self.rightClick)
118
- self.tree_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
143
+ self.tree_view.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
119
144
  self.tree_view.customContextMenuRequested.connect(self.context_menu)
120
145
 
121
146
  def context_menu(self, point):
@@ -124,7 +149,8 @@ class ActivityWindow(QtGui.QMainWindow):
124
149
  self.action_menu.exec(self.tree_view.viewport().mapToGlobal(point))
125
150
 
126
151
  def closeEvent(self, ev):
127
- #del ActivityWindow.keep[self.act]
152
+ if self.act.key in ActivityWindow.keep:
153
+ del ActivityWindow.keep[self.act.key]
128
154
  super().closeEvent(ev)
129
155
 
130
156
  def update_filter(self, *args):
@@ -153,11 +179,29 @@ class ActivityWindow(QtGui.QMainWindow):
153
179
  super().show(*args, **kwargs)
154
180
  self.tree_view.setColumnWidth(0, 400)
155
181
 
182
+ # Replace IPython version to one compatible with Qt6
183
+ def start_event_loop_qt4(app=None):
184
+ """Start the qt event loop in a consistent manner."""
185
+ if app is None:
186
+ app = get_app_qt4([""])
187
+ if not is_event_loop_running_qt4(app):
188
+ app._in_event_loop = True
189
+ if hasattr(app, "exec_"):
190
+ app.exec_()
191
+ else:
192
+ app.exec()
193
+ app._in_event_loop = False
194
+ else:
195
+ app._in_event_loop = True
196
+
156
197
  def show_activity(act):
157
- if 'module://matplotlib_inline.backend_inline' == matplotlib.backends.backend:
158
- print("WARNING: ActivityGUI will block, use `%matplotlib qt` to avoid blocking")
159
- if matplotlib.backends.backend != "qtagg":
160
- print(f"unexpected backend {matplotlib.backends.backend}")
198
+
199
+ if 'matplotlib' in sys.modules:
200
+ import matplotlib
201
+ if hasattr(matplotlib.backends, "backend"):
202
+ if 'qt' not in matplotlib.backends.backend:
203
+ print("WARNING: ActivityGUI will block, use `%matplotlib qt` to avoid blocking")
204
+
161
205
  app = get_app_qt4()
162
206
 
163
207
  if (window := ActivityWindow.keep.get(act.key, None)) is None:
@@ -168,5 +212,8 @@ def show_activity(act):
168
212
  if not is_event_loop_running_qt4(app):
169
213
  start_event_loop_qt4(app)
170
214
 
215
+ window.activateWindow()
171
216
 
172
-
217
+ def close_all():
218
+ for w in list(ActivityWindow.keep.values()):
219
+ w.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: brightway-basic-explorer
3
- Version: 0.9.dev0
3
+ Version: 0.9.dev2
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>
@@ -16,5 +16,34 @@ Classifier: Programming Language :: Python :: 3.13
16
16
  Requires-Python: >=3.10
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: COPYING
19
- Requires-Dist: PyQt6
19
+ Requires-Dist: ipython
20
20
  Dynamic: license-file
21
+
22
+ # Brightway Basic Explorer
23
+
24
+ Implement a basic activity explorer mostly to use in interractive python such as notebooks, ipython and spyder.
25
+
26
+ # Install
27
+
28
+ ```
29
+ pip install brightway_basic_explorer
30
+ ```
31
+
32
+ # Sample and Documentation
33
+
34
+ ![Sample Window](https://github.com/gschwind/brightway-basic-explorer/raw/main/doc/sample-window.png)
35
+
36
+ ```python
37
+ import bw2data
38
+ from brightway_basic_explorer import show_activity, close_all
39
+
40
+ db = bw2data.Database("ecoinvent-3.11-cutoff")
41
+
42
+ act = db.search("570kWp")
43
+
44
+ # Show the first activity
45
+ show_activity(act[0])
46
+
47
+ # Close all activity windows
48
+ close_all()
49
+ ```
@@ -6,4 +6,8 @@ brightway_basic_explorer.egg-info/PKG-INFO
6
6
  brightway_basic_explorer.egg-info/SOURCES.txt
7
7
  brightway_basic_explorer.egg-info/dependency_links.txt
8
8
  brightway_basic_explorer.egg-info/requires.txt
9
- brightway_basic_explorer.egg-info/top_level.txt
9
+ brightway_basic_explorer.egg-info/top_level.txt
10
+ brightway_basic_explorer/icons/emission.png
11
+ brightway_basic_explorer/icons/natural_resource.png
12
+ brightway_basic_explorer/icons/process.png
13
+ brightway_basic_explorer/icons/unknown.png
@@ -12,8 +12,8 @@ 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.dev0"
16
- dependencies = [ "PyQt6" ]
15
+ version = "0.9.dev2"
16
+ dependencies = [ "ipython" ]
17
17
  requires-python = ">= 3.10"
18
18
  keywords = ["lca", "ecoinvent", "brightway"]
19
19
  classifiers = [
@@ -28,4 +28,6 @@ Repository = "https://github.com/gschwind/brightway-basic-explorer"
28
28
  Documentation = "https://github.com/gschwind/brightway-basic-explorer"
29
29
  Issues = "https://github.com/gschwind/brightway-basic-explorer/issues"
30
30
  [tool.setuptools]
31
- packages = ["brightway_basic_explorer"]
31
+ packages = ["brightway_basic_explorer", "brightway_basic_explorer.icons"]
32
+ [tool.setuptools.package-data]
33
+ "brightway_basic_explorer.icons" = ["*.png"]
File without changes