Skip to content

Commit

Permalink
Show/Hide comment field for exchanges in the Techno/Biosphere. Fixes …
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-vdm committed Feb 7, 2022
1 parent 6bb72e8 commit d36ffb3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions activity_browser/bwutils/commontasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def count_database_records(name: str) -> int:
"Formula": "formula",
"Categories": "categories",
"Type": "type",
"Comment": "comment",
}

bw_keys_to_AB_names = {v: k for k, v in AB_names_to_bw_keys.items()}
Expand Down
13 changes: 13 additions & 0 deletions activity_browser/layouts/tabs/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ def __init__(self, key: tuple, parent=None, read_only=True):
self.show_uncertainty.setChecked(False)
self.show_uncertainty.toggled.connect(self.show_exchange_uncertainty)

# Reveal/hide exchange comment columns
self.show_comment = QtWidgets.QCheckBox("Show Exchange comments")
self.show_comment.setToolTip("Show or hide the comment column in the Technosphere Inputs and Biosphere Flows tables")
self.show_comment.setChecked(False)
self.show_comment.toggled.connect(self.show_comments)

# Toolbar Layout
toolbar = QtWidgets.QToolBar()
toolbar.addWidget(self.checkbox_edit_act)
toolbar.addWidget(self.checkbox_activity_description)
toolbar.addWidget(self.show_uncertainty)
toolbar.addWidget(self.show_comment)
self.graph_action = toolbar.addAction(
qicons.graph_explorer, "Show graph", self.open_graph
)
Expand Down Expand Up @@ -187,6 +194,7 @@ def populate(self) -> None:
self.downstream.model.sync(self.activity.upstream())

self.show_exchange_uncertainty(self.show_uncertainty.isChecked())
self.show_comments(self.show_comment.isChecked())

def populate_description_box(self):
"""Populate the activity description."""
Expand All @@ -210,6 +218,11 @@ def show_exchange_uncertainty(self, toggled: bool) -> None:
self.technosphere.show_uncertainty(toggled)
self.biosphere.show_uncertainty(toggled)

@Slot(bool, name="toggleCommentColumn")
def show_comments(self, toggled: bool) -> None:
self.technosphere.show_comments(toggled)
self.biosphere.show_comments(toggled)

@Slot(bool, name="toggleReadOnly")
def act_read_only_changed(self, read_only: bool) -> None:
""" When read_only=False specific data fields in the tables below become user-editable
Expand Down
16 changes: 15 additions & 1 deletion activity_browser/ui/tables/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def __init__(self, parent=None):
self.setItemDelegateForColumn(0, FloatDelegate(self))
self.setItemDelegateForColumn(6, ViewOnlyUncertaintyDelegate(self))
self.setItemDelegateForColumn(13, FormulaDelegate(self))
self.setItemDelegateForColumn(14, StringDelegate(self))
self.setDragDropMode(QtWidgets.QTableView.DragDrop)
self.table_name = "technosphere"

Expand All @@ -167,6 +168,12 @@ def show_uncertainty(self, show: bool = False) -> None:
for c in self.model.UNCERTAINTY:
self.setColumnHidden(cols.index(c), not show)

def show_comments(self, show: bool = False) -> None:
"""Show or hide the comment column.
"""
cols = self.model.columns
self.setColumnHidden(cols.index("Comment"), not show)

def contextMenuEvent(self, event) -> None:
if self.indexAt(event.pos()).row() == -1:
return
Expand Down Expand Up @@ -204,8 +211,9 @@ def __init__(self, parent=None):
self.setItemDelegateForColumn(0, FloatDelegate(self))
self.setItemDelegateForColumn(5, ViewOnlyUncertaintyDelegate(self))
self.setItemDelegateForColumn(12, FormulaDelegate(self))
self.table_name = "biosphere"
self.setItemDelegateForColumn(13, StringDelegate(self))
self.setDragDropMode(QtWidgets.QTableView.DropOnly)
self.table_name = "biosphere"

@Slot(name="resizeView")
def custom_view_sizing(self) -> None:
Expand All @@ -221,6 +229,12 @@ def show_uncertainty(self, show: bool = False) -> None:
for c in self.model.UNCERTAINTY:
self.setColumnHidden(cols.index(c), not show)

def show_comments(self, show: bool = False) -> None:
"""Show or hide the comment column.
"""
cols = self.model.columns
self.setColumnHidden(cols.index("Comment"), not show)

def contextMenuEvent(self, event) -> None:
if self.indexAt(event.pos()).row() == -1:
return
Expand Down
8 changes: 5 additions & 3 deletions activity_browser/ui/tables/models/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BaseExchangeModel(EditablePandasModel):
# Fields accepted by brightway to be stored in exchange objects.
VALID_FIELDS = {
"amount", "formula", "uncertainty type", "loc", "scale", "shape",
"minimum", "maximum"
"minimum", "maximum", "comment"
}

def __init__(self, key=None, parent=None):
Expand Down Expand Up @@ -204,7 +204,7 @@ def create_row(self, exchange) -> dict:
class TechnosphereExchangeModel(BaseExchangeModel):
COLUMNS = [
"Amount", "Unit", "Product", "Activity", "Location", "Database",
"Uncertainty", "Formula"
"Uncertainty", "Formula", "Comment"
]
UNCERTAINTY = [
"loc", "scale", "shape", "minimum", "maximum"
Expand All @@ -228,6 +228,7 @@ def create_row(self, exchange: ExchangeProxyBase) -> dict:
"Database": act.get("database"),
"Uncertainty": exchange.get("uncertainty type", 0),
"Formula": exchange.get("formula"),
"Comment": exchange.get("comment"),
})
try:
matrix = PedigreeMatrix.from_dict(exchange.get("pedigree", {}))
Expand All @@ -246,7 +247,7 @@ def create_row(self, exchange: ExchangeProxyBase) -> dict:
class BiosphereExchangeModel(BaseExchangeModel):
COLUMNS = [
"Amount", "Unit", "Flow Name", "Compartments", "Database",
"Uncertainty", "Formula"
"Uncertainty", "Formula", "Comment"
]
UNCERTAINTY = [
"loc", "scale", "shape", "minimum", "maximum"
Expand All @@ -269,6 +270,7 @@ def create_row(self, exchange) -> dict:
"Database": act.get("database"),
"Uncertainty": exchange.get("uncertainty type", 0),
"Formula": exchange.get("formula"),
"Comment": exchange.get("comment"),
})
try:
matrix = PedigreeMatrix.from_dict(exchange.get("pedigree", {}))
Expand Down

0 comments on commit d36ffb3

Please sign in to comment.