Beispiel #1
0
    def delete_parameter(self, proxy) -> None:
        """ Override the base method to include additional logic.

        If there are multiple `ActivityParameters` for a single activity, only
        delete the selected instance, otherwise use `bw.parameters.remove_from_group`
        to clear out the `ParameterizedExchanges` as well.
        """
        key = self.get_key(proxy)
        query = (ActivityParameter.select().where(
            ActivityParameter.database == key[0],
            ActivityParameter.code == key[1]))

        if query.count() > 1:
            super().delete_parameter(proxy)
        else:
            act = bw.get_activity(key)
            group = self.get_current_group(proxy)
            bw.parameters.remove_from_group(group, act)
            # Also clear the group if there are no more parameters in it
            if ActivityParameter.get_or_none(group=group) is None:
                with bw.parameters.db.atomic():
                    Group.get(name=group).delete_instance()

        bw.parameters.recalculate()
        signals.parameters_changed.emit()
Beispiel #2
0
 def modify_parameter(self, param: ParameterBase, field: str,
                      value: Union[str, float, list]) -> None:
     with bw.parameters.db.atomic() as transaction:
         try:
             if hasattr(param, field):
                 setattr(param, field, value)
             elif field == "order":
                 # Store the given order in the Group used by the parameter
                 if param.group in value:
                     value.remove(param.group)
                 group = Group.get(name=param.group)
                 group.order = value
                 group.expire()
             else:
                 param.data[field] = value
             param.save()
             bw.parameters.recalculate()
         except Exception as e:
             # Anything wrong? Roll the transaction back and throw up a
             # warning message.
             transaction.rollback()
             QMessageBox.warning(
                 self.window, "Could not save changes", str(e),
                 QMessageBox.Ok, QMessageBox.Ok
             )
     signals.parameters_changed.emit()
Beispiel #3
0
 def store_group_order(self, proxy) -> None:
     """ Store the given order in the Group used by the parameter linked
     in the proxy.
     """
     param = self.get_parameter(proxy)
     order = proxy.data()
     if param.group in order:
         order.remove(param.group)
     group = Group.get(name=param.group)
     group.order = order
     group.expire()