Skip to content

Commit

Permalink
Add - copy on impact category copy (LCA-ActivityBrowser#1136)
Browse files Browse the repository at this point in the history
* Add - copy on impact category copy LCA-ActivityBrowser#1133

* Reorder impact category tree context menu
  • Loading branch information
mrvisscher authored and marc-vdm committed Dec 4, 2023
1 parent 504a6d8 commit 94b3295
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions activity_browser/controllers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ def copy_method(self, method: tuple, level: str = None) -> None:
else:
methods = [bw.Method(method)]
dialog = TupleNameDialog.get_combined_name(
self.window, "Impact category name", "Combined name:", method, "Copy"
self.window, "Impact category name", "Combined name:", method, " - Copy"
)
if dialog.exec_() == TupleNameDialog.Accepted:
new_name = dialog.result_tuple
for mthd in methods:
new_method = new_name + mthd.name[len(new_name)-1:]
new_method = new_name + mthd.name[len(new_name):]
if new_method in bw.methods:
warn = "Impact Category with name '{}' already exists!".format(new_method)
QtWidgets.QMessageBox.warning(self.window, "Copy failed", warn)
Expand Down
15 changes: 10 additions & 5 deletions activity_browser/ui/tables/impact_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,22 @@ def contextMenuEvent(self, event) -> None:
if self.indexAt(event.pos()).row() == -1:
return
menu = QtWidgets.QMenu(self)

if self.tree_level()[0] == 'leaf':
menu.addAction(qicons.edit, "Inspect Impact Category", self.method_selected)
else:
menu.addAction(qicons.forward, "Expand all sub levels", self.expand_branch)
menu.addAction(qicons.backward, "Collapse all sub levels", self.collapse_branch)

menu.addSeparator()

menu.addAction(qicons.copy, "Duplicate Impact Category",
lambda: self.copy_method()
)
menu.addAction(qicons.delete, "Delete Impact Category",
lambda: self.delete_method()
)
if self.tree_level()[0] == 'leaf':
menu.addAction(qicons.edit, "Inspect Impact Category", self.method_selected)
else:
menu.addAction(qicons.forward, "Expand all sub levels", self.expand_branch)
menu.addAction(qicons.backward, "Collapse all sub levels", self.collapse_branch)

menu.exec_(event.globalPos())

def selected_methods(self) -> Iterable:
Expand Down
16 changes: 13 additions & 3 deletions activity_browser/ui/widgets/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,22 @@ def add_input_field(self, text: str, placeholder: str = None) -> None:
@classmethod
def get_combined_name(cls, parent: QtWidgets.QWidget, title: str, label: str,
fields: tuple, extra: str = "Extra") -> 'TupleNameDialog':
"""
Set-up a TupleNameDialog pop-up with supplied title + label. Construct fields
for each field of the supplied tuple. Last field of the tuple is appended with
the extra string, to avoid duplicates.
"""
obj = cls(parent)
obj.setWindowTitle(title)
obj.name_label.setText(label)
for field in fields:
obj.add_input_field(str(field))
obj.add_input_field("", extra)

# set up a field for each tuple element
for i, field in enumerate(fields):
field_content = str(field)

# if it's the last element, add extra to the string
if i + 1 == len(fields): field_content += extra
obj.add_input_field(field_content)
obj.input_box.updateGeometry()
obj.changed()
return obj
Expand Down

0 comments on commit 94b3295

Please sign in to comment.