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

Fix CF values not updated #1035

8 changes: 0 additions & 8 deletions activity_browser/controllers/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def connect_signals(self):
signals.manage_plugins.connect(self.manage_plugins_wizard)
signals.project_selected.connect(self.reload_plugins)
signals.plugin_selected.connect(self.add_plugin)
signals.plugin_deselected.connect(self.remove_plugin)

@Slot(name="openManagerWizard")
def manage_plugins_wizard(self) -> None:
Expand Down Expand Up @@ -60,13 +59,6 @@ def load_plugin(self, name):
except Exception as e:
log.error("Error: Import of plugin {} failed".format(name), error=e)

def remove_plugin(self, name):
log.info("Removing plugin {}".format(name))
# Apply plugin remove() function
self.plugins[name].remove()
# Close plugin tabs
self.close_plugin_tabs(self.plugins[name])

def add_plugin(self, name, select: bool = True):
""" add or reload tabs of the given plugin
"""
Expand Down
11 changes: 1 addition & 10 deletions activity_browser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ def connect_signals(self):
"""
signals.project_selected.connect(self.reset_for_project_selection)
signals.plugin_selected.connect(self.add_plugin)
signals.plugin_deselected.connect(self.remove_plugin)

@classmethod
def get_default_settings(cls) -> dict:
Expand Down Expand Up @@ -282,7 +281,7 @@ def get_editable_databases(self):
return (name for name, ro in iterator if not ro and name != "biosphere3")

def add_plugin(self, name: str, select: bool = True):
""" Add a plugin to settings
""" Add a plugin to settings or remove it
"""
if select:
self.settings["plugins_list"].append(name)
Expand All @@ -292,14 +291,6 @@ def add_plugin(self, name: str, select: bool = True):
self.settings["plugins_list"].remove(name)
self.write_settings()


def remove_plugin(self, name: str) -> None:
""" When a plugin is deselected from a project, remove it from settings
"""
if name in self.settings["plugins_list"]:
self.settings["plugins_list"].remove(name)
self.write_settings()

def get_plugins_list(self):
""" Return a list of plugins names
"""
Expand Down
201 changes: 97 additions & 104 deletions activity_browser/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,139 +4,132 @@

class Signals(QObject):
""" Signals used for the Activity Browser should be defined here.
While arguments can be passed to signals, it is good practice not to do this if possible. """
While arguments can be passed to signals, it is good practice not to do this if possible.
Every signal should have a comment (no matter how descriptive the name of the signal) that describes what a
signal is used for and after a pipe (|), what variables are sent, if any.
"""

# General Settings
log = Signal(str)
log = Signal(str) # Write log message to debug window | log message

# bw2 directory
switch_bw2_dir_path = Signal(str)
edit_settings = Signal()
switch_bw2_dir_path = Signal(str) # Change the path to the BW2 settings | path
edit_settings = Signal() # Change AB settings

# Project
change_project = Signal(str)
new_project = Signal()
copy_project = Signal()
delete_project = Signal()
project_selected = Signal()
projects_changed = Signal()
change_project = Signal(str) # Change the project | project name
new_project = Signal() # Start a new project
copy_project = Signal() # Copy a project
delete_project = Signal() # Delete a project
project_selected = Signal() # A project was selected (opened)
projects_changed = Signal() # The list of projects changed

# Database
add_database = Signal()
delete_database = Signal(str)
delete_database_confirmed = Signal(str)
copy_database = Signal(str)
install_default_data = Signal()
import_database = Signal()
export_database = Signal()
relink_database = Signal(str)
update_biosphere = Signal()
database_selected = Signal(str)
databases_changed = Signal()
database_changed = Signal(str)
database_read_only_changed = Signal(str, bool)
database_tab_open = Signal(str)

# Activity (key, field, new value)
new_activity = Signal(str)
add_activity_to_history = Signal(tuple)
duplicate_activity = Signal(tuple)
duplicate_activities = Signal(list)
duplicate_activity_to_db = Signal(str, object)
duplicate_to_db_interface = Signal(tuple, str)
duplicate_to_db_interface_multiple = Signal(list, str)
safe_open_activity_tab = Signal(tuple)
unsafe_open_activity_tab = Signal(tuple)
open_activity_tab = Signal(tuple)
close_activity_tab = Signal(tuple)
open_activity_graph_tab = Signal(tuple)
delete_activity = Signal(tuple)
delete_activities = Signal(list)
add_database = Signal() # Trigger dialog to start a new database
delete_database = Signal(str) # Delete this database | name of database
delete_database_confirmed = Signal(str) # This database has been deleted | name of database
copy_database = Signal(str) # Copy this database | name of the database to be copied
install_default_data = Signal() # Trigger dialog for user to install default data
import_database = Signal() # Trigger dialog to import a database
export_database = Signal() # Trigger dialog to export a database
relink_database = Signal(str) # Relink this database | name of database
update_biosphere = Signal() # Trigger dialog to update the biosphere
database_selected = Signal(str) # This database was selected (opened) | name of database
databases_changed = Signal() # The list of databases in this project has changed e.g. a database was added
database_changed = Signal(str) # This database has changed e.g. an activity was added to it | name of database
database_read_only_changed = Signal(str, bool) # The read_only state of database changed | name of database, read-only state
database_tab_open = Signal(str) # This database tab is being viewed by user | name of database

# Activity
new_activity = Signal(str) # Trigger dialog to create a new activity in this database | name of database
add_activity_to_history = Signal(tuple) # Add this activity to history | key of activity
duplicate_activity = Signal(tuple) # Duplicate this activity | key of activity
duplicate_activities = Signal(list) # Duplicate these activities | list of activity keys
duplicate_activity_to_db = Signal(str, object) # Duplicate this activity to another database | name of target database, BW2 actiivty object
#TODO write below 2 signals to work without the str, source database is already stored in activity keys
duplicate_to_db_interface = Signal(tuple, str) # Trigger dialog to duplicate actiivty to another database | key of activity, name of source database
duplicate_to_db_interface_multiple = Signal(list, str) # Trigger dialog to duplicate actiivty to another database | list of activity keys, name of source database
safe_open_activity_tab = Signal(tuple) # Open activity details tab in read-only mode | key of activity
unsafe_open_activity_tab = Signal(tuple) # Open activity details tab in editable mode | key of activity
close_activity_tab = Signal(tuple) # Close this activity details tab | key of activity
open_activity_graph_tab = Signal(tuple) # Open the graph-view tab | key of activity
delete_activity = Signal(tuple) # Delete this activity | key of activity
delete_activities = Signal(list) # Delete these activities | list of activity keys

# Activity editing
edit_activity = Signal(str) # db_name
activity_modified = Signal(tuple, str, object)
relink_activity = Signal(tuple)

edit_activity = Signal(str) # An activity in this database may now be edited | name of database
activity_modified = Signal(tuple, str, object) # This was changed about this activity | key of activity, name of the changed field, new content of the field
relink_activity = Signal(tuple) # Trigger dialog to relink this activity | key of activity

# Exchanges
exchanges_deleted = Signal(list)
exchanges_add = Signal(list, tuple)
exchange_modified = Signal(object, str, object)
exchanges_deleted = Signal(list) # These exchanges should be deleted | list of exchange keys
exchanges_add = Signal(list, tuple) # Add these exchanges to this activity | list of exchange keys to be added, key of target activity
exchange_modified = Signal(object, str, object) # This was changed about this exchange | exchange object, name of the changed field, new content of the field
# Exchange object and uncertainty dictionary
exchange_uncertainty_wizard = Signal(object)
exchange_uncertainty_modified = Signal(object, object)
exchange_pedigree_modified = Signal(object, object)
exchange_uncertainty_wizard = Signal(object) # Trigger uncertainty dialog for this exchange | exchange object
exchange_uncertainty_modified = Signal(object, dict) # The uncertainty data for this exchange was modified | exchange object, uncertainty data
exchange_pedigree_modified = Signal(object, object) # The pedigree uncertainty data for this exchange was modified | exchange object, pedigree data

# Parameters
add_parameter = Signal(tuple)
add_activity_parameter = Signal(tuple)
add_activity_parameters = Signal(list)
added_parameter = Signal(str, str, str)
parameters_changed = Signal()
rename_parameter = Signal(object, str)
parameter_renamed = Signal(str, str, str) # old, group, new
# Pass the key of the activity holding the exchange
exchange_formula_changed = Signal(tuple)
# Parameter, field, value for field
parameter_modified = Signal(object, str, object)
# Parameter object and uncertainty dictionary
parameter_uncertainty_modified = Signal(object, object)
parameter_pedigree_modified = Signal(object, object)
delete_parameter = Signal(object)
parameter_scenario_sync = Signal(int, object, bool)
parameter_superstructure_built = Signal(int, object)
clear_activity_parameter = Signal(str, str, str)
add_parameter = Signal(tuple) # Trigger dialog to add parameter to this exchange | key of exchange
add_activity_parameter = Signal(tuple) # Add a parameter to this exchange | key of exchange
add_activity_parameters = Signal(list) # Add parameter to these exchanges | list of exchange keys
added_parameter = Signal(str, str, str) # This parameter has been added | name of the parameter, amount, type (project, database or activity)
parameters_changed = Signal() # The parameters have changed
rename_parameter = Signal(object, str) # Trigger dialog to rename parameter | parameter object, type (project, database or activity)
parameter_renamed = Signal(str, str, str) # This parameter was renamed | old name, type (project, database or activity), new name
exchange_formula_changed = Signal(tuple) # The formula for an exchange in this activity was changed | key of activity
parameter_modified = Signal(object, str, object) # This parameter was modified | parameter object, name of the changed field, new content of the field
parameter_uncertainty_modified = Signal(object, dict) # The uncertainty data for this parameter was modified | parameter object, uncertainty data
parameter_pedigree_modified = Signal(object, object) # The pedigree uncertainty data for this parameter was modified | parameter object, pedigree data
delete_parameter = Signal(object) # Delete this parameter | proxy index of the table view of the parameter
parameter_scenario_sync = Signal(int, object, bool) # Synchronize this data for table | index of the table, dataframe with scenario data, include default scenario
parameter_superstructure_built = Signal(int, object) # Superstructure built from scenarios | index of the table, dataframe with scenario data
clear_activity_parameter = Signal(str, str, str) # Clear this parameter | name of database, name of code, name of group

# Calculation Setups
new_calculation_setup = Signal()
copy_calculation_setup = Signal(str)
delete_calculation_setup = Signal(str)
rename_calculation_setup = Signal(str)
set_default_calculation_setup = Signal()
new_calculation_setup = Signal() # Trigger dialog for a new calculation setup
copy_calculation_setup = Signal(str) # Trigger dialog for copying this calculation setup | name of calculation setup
delete_calculation_setup = Signal(str) # Delete this calculation setup | name of calculation setup
rename_calculation_setup = Signal(str) # Trigger dialog to rename this calculation setup | name of calculation setup
set_default_calculation_setup = Signal() # Show the default (first) calculation setup

calculation_setup_changed = Signal()
calculation_setup_selected = Signal(str)
calculation_setup_changed = Signal() # Calculation setup was changed
calculation_setup_selected = Signal(str) # This calculation setup was selected (opened) | name of calculation setup

# LCA Results
lca_calculation = Signal(dict)
lca_results_tabs_changed = Signal()
lca_calculation = Signal(dict) # Generate a calculation setup | dictionary with name, type (simple/scenario) and potentially scenario data

# Impact Categories & Characterization Factors
new_method = Signal()
method_deleted = Signal()
copy_method = Signal(tuple, str)
delete_method = Signal(tuple, str)
edit_method_cf = Signal(tuple, tuple)
remove_cf_uncertainties = Signal(list, tuple)
method_modified = Signal(tuple)
method_selected = Signal(tuple)
method_tabs_changed = Signal()
set_uncertainty = Signal(tuple)
add_cf_method = Signal(tuple, tuple)
delete_cf_method = Signal(tuple, tuple)
cf_changed = Signal()
new_method = Signal() # A new method was added
method_deleted = Signal() # A method was deleted
copy_method = Signal(tuple, str) # Copy this method | tuple of impact category, level of tree OR the proxy
delete_method = Signal(tuple, str) # Delete this method | tuple of impact category, level of tree OR the proxy
edit_method_cf = Signal(tuple, tuple) # Edit this CF for this method | tuple of characterization factor, tuple of method
remove_cf_uncertainties = Signal(list, tuple) # Remove uncertainty data for these CFs | list of CFs to remove info from, tuple of method
method_modified = Signal(tuple) # This method was modified | tuple of method
method_selected = Signal(tuple) # This method was selected (opened) | tuple of method
set_uncertainty = Signal(tuple) # Set uncertainty of CF | proxy index of the table view of the CF
add_cf_method = Signal(tuple, tuple) # Add uncertainty to CF | tuple of CF, tuple impact category
delete_cf_method = Signal(tuple, tuple) # Delete this CF from impact category | tuple of CF, tuple of impact category
cf_changed = Signal() # A characterization factor was changed

# Monte Carlo LCA
monte_carlo_finished = Signal()
monte_carlo_finished = Signal() # The monte carlo calculations are finished

# Qt Windows
update_windows = Signal()
new_statusbar_message = Signal(str)
restore_cursor = Signal()
update_windows = Signal() # Update the windows
new_statusbar_message = Signal(str) # Update the statusbar this message | message
restore_cursor = Signal() # Restore the cursor to normal

# Tabs
toggle_show_or_hide_tab = Signal(str)
show_tab = Signal(str)
hide_tab = Signal(str)
hide_when_empty = Signal()

# Metadata
metadata_changed = Signal(tuple) # key
toggle_show_or_hide_tab = Signal(str) # Show/Hide the tab with this name | name of tab
show_tab = Signal(str) # Show this tab | name of tab
hide_tab = Signal(str) # Hide this tab | name of tab
hide_when_empty = Signal() # Show/Hide tab when it has/does not have sub-tabs

# Plugins
plugin_selected = Signal(str, bool)
plugin_deselected = Signal(str)
manage_plugins = Signal()
plugin_selected = Signal(str, bool) # This plugin was/was not selected | name of plugin, selected state
manage_plugins = Signal() # Trigger the plugins dialog

signals = Signals()
4 changes: 3 additions & 1 deletion activity_browser/ui/tables/impact_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ def __init__(self, parent=None):

def cell_edited(self) -> None:
"""Store the edit made to the table in the underlying data."""
if len(self.selectedIndexes()) == 0:
return
col = self.model.proxy_to_source(self.selectedIndexes()[0]).column()
if col in [2]:
# if the column changed is 2 (Amount)
# if the column changed is 2 (Amount) --> This is a list in case of future editable columns
self.model.modify_cf(self.selectedIndexes()[0])

@Slot(name="resizeView")
Expand Down
12 changes: 10 additions & 2 deletions activity_browser/ui/tables/models/impact_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,17 @@ def build_row(cls, method_cf: tuple) -> dict:
return row

def get_cf(self, proxy: QModelIndex) -> tuple:
"""Get the characterization factor data of the selected row."""
idx = self.proxy_to_source(proxy)
return self._dataframe.iat[idx.row(), self.cf_column]

def get_value(self, proxy: QModelIndex) -> tuple:
def get_value(self, proxy: QModelIndex) -> float:
"""Get the value of the selected cell."""
idx = self.proxy_to_source(proxy)
return self._dataframe.iat[idx.row(), idx.column()]

def get_col_from_index(self, proxy: QModelIndex) -> tuple:
def get_col_from_index(self, proxy: QModelIndex) -> str:
"""Get the name of the column of the selected cell."""
idx = self.proxy_to_source(proxy)
return self.COLUMNS[idx.column()]

Expand Down Expand Up @@ -412,6 +415,11 @@ def modify_cf_uncertainty(self, cf: tuple, uncertainty: dict) -> None:
def modify_cf(self, proxy: QModelIndex) -> None:
"""Update the CF with new data, possibly converting
the second item in the tuple to a dictionary without losing information.

Parameters
----------
proxy : QModelIndex
The Qt object of the selected cell in the table.
"""
cf = self.get_cf(proxy)
col_name = self.get_col_from_index(proxy)
Expand Down