Skip to content

Commit c7b4be6

Browse files
author
Jan Klenner
committed
update activity relink to only show relevant
databases and avoid unsafe activity opening in relink dialogue. Avoid error of undefined failed variable in relink Resolves #1167
1 parent 0bbfa0d commit c7b4be6

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

activity_browser/actions/activity/activity_relink.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from activity_browser.ui.widgets import (ActivityLinkingDialog,
1111
ActivityLinkingResultsDialog)
1212

13-
1413
class ActivityRelink(ABAction):
1514
"""
1615
ABAction to relink the exchanges of an activity to exchanges from another database.
1716
18-
This action only uses the first key from activity_keys
17+
This action only uses the first key from activity_keys.
18+
Only shows databases relevant to activity.
1919
"""
2020

2121
icon = qicons.edit
@@ -31,8 +31,10 @@ def run(activity_keys: List[tuple]):
3131
db = bd.Database(key[0])
3232
activity = bd.get_activity(key)
3333

34-
# find the dependents for the database and construct the alternatives in tuple format
35-
depends = db.find_dependents()
34+
# find the dependents for the activity using bw2data method and construct the alternatives in tuple format
35+
data = {}
36+
data[activity.key] = db.load()[activity.key]
37+
depends = db.find_dependents(data = data, ignore= [db.name])
3638
options = [(depend, list(bd.databases)) for depend in depends]
3739

3840
# present the alternatives to the user in a linking dialog
@@ -49,16 +51,15 @@ def run(activity_keys: List[tuple]):
4951

5052
# use the relink_activity_exchanges strategy to relink the exchanges of the activity
5153
relinking_results = {}
54+
failed = 0
5255
for old, new in dialog.relink.items():
5356
other = bd.Database(new)
5457
failed, succeeded, examples = relink_activity_exchanges(
5558
activity, old, other
5659
)
5760
relinking_results[f"{old} --> {other.name}"] = (failed, succeeded)
58-
5961
# restore normal cursor
6062
QtWidgets.QApplication.restoreOverrideCursor()
61-
6263
# if any relinks failed present them to the user
6364
if failed > 0:
6465
relinking_dialog = ActivityLinkingResultsDialog.present_relinking_results(

activity_browser/ui/widgets/dialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def construct_results_dialog(
422422
for act, key in unlinked_exchanges.items():
423423
button = QtWidgets.QPushButton(act.as_dict()["name"])
424424
button.clicked.connect(
425-
lambda: signals.unsafe_open_activity_tab.emit(act.key)
425+
lambda: signals.safe_open_activity_tab.emit(act.key)
426426
)
427427
obj.exchangesUnlinked.addWidget(button)
428428
obj.updateGeometry()
@@ -574,7 +574,7 @@ def construct_results_dialog(
574574
for act, key in unlinked_exchanges.items():
575575
button = QtWidgets.QPushButton(act.as_dict()["name"])
576576
button.clicked.connect(
577-
lambda: signals.unsafe_open_activity_tab.emit(act.key)
577+
lambda: signals.safe_open_activity_tab.emit(act.key)
578578
)
579579
obj.exchangesUnlinked.addWidget(button)
580580
obj.updateGeometry()

0 commit comments

Comments
 (0)