Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add - copy on impact category copy #1136

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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