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

Controller refactor #1280

Merged
merged 79 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
32d8084
Fixed the conversion from parameters to flow scenarios for production…
mrvisscher Feb 19, 2024
e24b3ec
Fixed scenario excel import for numbered scenarios. (#1236)
mrvisscher Feb 19, 2024
7710770
Install correct version of biosphere when choosing most recent (#1234)
marc-vdm Feb 19, 2024
ffa5ad8
Fixed EF & Process contribution tables not switching scenarios (#1237)
mrvisscher Feb 19, 2024
12377c2
Reworked logging to catch all logs and prints and be prettier
mrvisscher Mar 7, 2024
ea14963
Created a basic_setup for the logger to use during e.g. tests
mrvisscher Mar 8, 2024
2e0a60d
Fix badge white text
mrvisscher Mar 8, 2024
f06e93d
Removed custom_view_sizing
mrvisscher Mar 8, 2024
d153597
Fixed splitter-table combo's in activities & parameter tabs
mrvisscher Mar 8, 2024
124c3ed
Fixed database tables
mrvisscher Mar 8, 2024
44cf2a0
Some header tweaks
mrvisscher Mar 8, 2024
27a2b02
Fixed parameter tables
mrvisscher Mar 8, 2024
3c796cc
Fixed result tables
mrvisscher Mar 8, 2024
5cc342e
Row selection in activity tables
mrvisscher Mar 11, 2024
6ca5fed
Reenable column sorting
mrvisscher Mar 12, 2024
375a621
Hiding data columns in LCA, parameter and IC tables
mrvisscher Mar 18, 2024
baf82f0
Column resizing
mrvisscher Mar 18, 2024
9ec9ff8
Overhauled ProjectController and implemented changes
mrvisscher Apr 11, 2024
29d8ca2
Overhauled DatabaseController and implemented changes
mrvisscher Apr 11, 2024
d79f7b6
Overhauled ActivityController and implemented changes
mrvisscher Apr 11, 2024
aa322e9
Overhauled ExchangeController and implemented changes
mrvisscher Apr 11, 2024
7725af1
Overhauled CSController and implemented changes
mrvisscher Apr 12, 2024
76af343
Overhauled ICController and implemented changes
mrvisscher Apr 12, 2024
db52a32
Removed ProjectController in favor of patching bw2data
mrvisscher Apr 16, 2024
5c96964
Removed Database, Activity and Exchange Controllers in favor of patch…
mrvisscher Apr 18, 2024
8eab96d
Removed CSController in favor of patching bw2data
mrvisscher Apr 18, 2024
e337921
Removed ICController in favor of patching bw2data
mrvisscher Apr 18, 2024
366ddb8
Removed ParameterController in favor of patching bw2data
mrvisscher Apr 19, 2024
08d60fd
BW25 ready
mrvisscher Apr 22, 2024
334f5bd
BW25 ready
mrvisscher Apr 22, 2024
af6687b
Commenting and fixing
mrvisscher Apr 24, 2024
5ec945f
Commenting and fixing
mrvisscher Apr 24, 2024
e790b92
Test patches
mrvisscher Apr 26, 2024
e7e308a
Test patches
mrvisscher Apr 26, 2024
af0c3d5
Test patches
mrvisscher Apr 26, 2024
261c877
Test patches
mrvisscher Apr 26, 2024
f955010
Moved activity actions to new ABActions format
mrvisscher May 13, 2024
b42a1a7
Moved cs actions to new ABActions format
mrvisscher May 13, 2024
a6c5727
Moved database actions to new ABActions format
mrvisscher May 13, 2024
2e2cdec
Moved exchange actions to new ABActions format
mrvisscher May 13, 2024
8c7938b
Moved method actions to new ABActions format
mrvisscher May 14, 2024
3fc2140
Moved parameter actions to new ABActions format
mrvisscher May 15, 2024
f027a80
Moved project actions to new ABActions format
mrvisscher May 15, 2024
7360b62
Moved various actions to new ABActions format
mrvisscher May 15, 2024
3da7608
Added exception dialogs decorator
mrvisscher May 15, 2024
154f1ca
Retired signals.project_selected
mrvisscher May 15, 2024
5980e18
Fixed plot errors
mrvisscher May 15, 2024
22dd016
Moved IC context menu around
mrvisscher May 16, 2024
d938dfb
Added automatic opens
mrvisscher May 16, 2024
a2d1194
Fixed Pandas `SettingWithCopyWarning`
mrvisscher May 16, 2024
aec8735
Fixed `This database is empty` UserWarning
mrvisscher May 16, 2024
423ebc1
Automatically delete upstream exchanges on activity delete
mrvisscher May 16, 2024
1eb45ad
Automatically delete all upstream exchanges
mrvisscher May 16, 2024
b0a0de5
Changed method delete dialog
mrvisscher May 17, 2024
1b9949f
Changed log level for the MetaDataStore
mrvisscher May 17, 2024
b732c09
Merge branch 'logging-fixes' into controller-overhaul
mrvisscher May 17, 2024
721b84a
Removed utilities controller
mrvisscher May 17, 2024
68bfb7a
BW25 ready project combobox
mrvisscher May 17, 2024
8cc2c14
Small fixes
mrvisscher May 21, 2024
320ca2e
Activity updates to upstream
mrvisscher May 22, 2024
a9c48d2
Merge branch 'table-fixes' into controller-overhaul
mrvisscher May 22, 2024
9857be3
Disabled resize activities biosphere table
mrvisscher May 22, 2024
0c84a87
Fixed quintuple drags from activity rows
mrvisscher May 22, 2024
65cbdc6
Fixed database/activity layouting
mrvisscher May 22, 2024
413a25c
Fixed columnwidth for methodstable
mrvisscher May 22, 2024
2699a9a
resolve scenario indexing bug
marc-vdm May 22, 2024
ff68d37
Fixed context menu for activities-biosphere table
mrvisscher May 27, 2024
f61b15f
Merge pull request #1 from marc-vdm/scenario_indexing
mrvisscher May 27, 2024
bbb6a40
Renamed `brightway` directory to `mod` for modified modules
mrvisscher Jun 4, 2024
2fd8df6
Merge remote-tracking branch 'origin/controller-overhaul' into contro…
mrvisscher Jun 4, 2024
9b0f66b
Fix for legacy dummy parameters and existing param groups
mrvisscher Jun 4, 2024
9b0b8db
Exchange columns are hidden again
mrvisscher Jun 4, 2024
52d65a5
Activity tab splitter state is saved between sessions, selection disa…
mrvisscher Jun 4, 2024
8043363
Fixed automatic parameter tests
mrvisscher Jun 4, 2024
b6402ee
Logger now catches ABThread exceptions
mrvisscher Jun 4, 2024
5a92be7
Removed stdout/stderr stuff from logger
mrvisscher Jun 6, 2024
18579ba
Dynamic project list based on Brightway version
mrvisscher Jun 6, 2024
132b0b7
Test import fixes
mrvisscher Jun 6, 2024
a6f35b6
Fixed project list sorting
mrvisscher Jun 6, 2024
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
1 change: 1 addition & 0 deletions .github/conda-envs/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dependencies:
- pytest
- pytest-qt
- pytest-mock
- pytest-env
20 changes: 13 additions & 7 deletions activity_browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import sys
import traceback

from .logger import log
from .logger import log, exception_hook, log_file_location
from activity_browser.mod import bw2data
from .application import application
from .signals import signals
from .settings import ab_settings, project_settings
Expand All @@ -12,17 +12,23 @@
from .plugin import Plugin


def load_settings() -> None:
if ab_settings.settings:
bw2data.projects.switch_dir(ab_settings.current_bw_dir)
bw2data.projects.set_current(ab_settings.startup_project)
log.info(f'Brightway2 data directory: {bw2data.projects.base_dir}')
log.info(f'Brightway2 current project: {bw2data.projects.current}')


def run_activity_browser():
log.info(f'The Activity Browser log file can be found at {log.log_file_path()}')
log.info(f'Activity Browser version: {version}')
if log_file_location:
log.info(f'The log file can be found at {log_file_location}')

application.main_window = MainWindow(application)
project_controller.load_settings()
load_settings()
application.show()

def exception_hook(*args):
log.warning(''.join(traceback.format_exception(*args)))

sys.excepthook = exception_hook

sys.exit(application.exec_())
7 changes: 7 additions & 0 deletions activity_browser/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .activity.activity_duplicate_to_loc import ActivityDuplicateToLoc
from .activity.activity_delete import ActivityDelete
from .activity.activity_duplicate_to_db import ActivityDuplicateToDB
from .activity.activity_modify import ActivityModify

from .calculation_setup.cs_new import CSNew
from .calculation_setup.cs_delete import CSDelete
Expand Down Expand Up @@ -39,10 +40,16 @@
from .parameter.parameter_new import ParameterNew
from .parameter.parameter_new_automatic import ParameterNewAutomatic
from .parameter.parameter_rename import ParameterRename
from .parameter.parameter_delete import ParameterDelete
from .parameter.parameter_modify import ParameterModify
from .parameter.parameter_uncertainty_remove import ParameterUncertaintyRemove
from .parameter.parameter_uncertainty_modify import ParameterUncertaintyModify
from .parameter.parameter_clear_broken import ParameterClearBroken

from .project.project_new import ProjectNew
from .project.project_duplicate import ProjectDuplicate
from .project.project_delete import ProjectDelete
from .project.project_switch import ProjectSwitch

from .default_install import DefaultInstall
from .biosphere_update import BiosphereUpdate
Expand Down
44 changes: 32 additions & 12 deletions activity_browser/actions/activity/activity_delete.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Union, Callable, List
from typing import List

from PySide2 import QtWidgets, QtCore
from PySide2 import QtWidgets

from activity_browser import application, activity_controller
from activity_browser import application
from activity_browser.mod import bw2data as bd
from activity_browser.mod.bw2data.parameters import ActivityParameter, Group, GroupDependency, parameters
from activity_browser.ui.icons import qicons
from activity_browser.actions.base import ABAction
from activity_browser.actions.base import ABAction, exception_dialogs


class ActivityDelete(ABAction):
Expand All @@ -14,15 +16,13 @@ class ActivityDelete(ABAction):
will be removed
"""
icon = qicons.delete
title = 'Delete ***'
activity_keys: List[tuple]
text = 'Delete ***'

def __init__(self, activity_keys: Union[List[tuple], Callable], parent: QtCore.QObject):
super().__init__(parent, activity_keys=activity_keys)

def onTrigger(self, toggled):
@staticmethod
@exception_dialogs
def run(activity_keys: List[tuple]):
# retrieve activity objects from the controller using the provided keys
activities = activity_controller.get_activities(self.activity_keys)
activities = [bd.get_activity(key) for key in activity_keys]

# check for downstream processes
if any(len(act.upstream()) > 0 for act in activities):
Expand All @@ -42,4 +42,24 @@ def onTrigger(self, toggled):
if choice == QtWidgets.QMessageBox.No: return

# use the activity controller to delete multiple activities
activity_controller.delete_activities(self.activity_keys)
for act in activities:
db, code = act.key

try:
group_name = ActivityParameter.get(
(ActivityParameter.database == db) & (ActivityParameter.code == code)).group

# remove activity parameters from its group
parameters.remove_from_group(group_name, act)

# Also clear the group if there are no more parameters in it
if not ActivityParameter.select().where(ActivityParameter.group == group_name).exists():
Group.delete().where(Group.name == group_name).execute()
GroupDependency.delete().where(GroupDependency.group == group_name).execute()
except ActivityParameter.DoesNotExist:
# no parameters found for this activity
pass

act.upstream().delete()

act.delete()
21 changes: 11 additions & 10 deletions activity_browser/actions/activity/activity_duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

from PySide2 import QtCore

from activity_browser import activity_controller
from activity_browser.mod.bw2data import get_activity
from activity_browser.bwutils import commontasks
from activity_browser.ui.icons import qicons
from activity_browser.actions.base import ABAction
from activity_browser.actions.base import ABAction, exception_dialogs


class ActivityDuplicate(ABAction):
"""
Duplicate one or multiple activities using their keys. Proxy action to call the controller.
"""
icon = qicons.copy
title = 'Duplicate ***'
activity_keys: List[tuple]

def __init__(self, activity_keys: Union[List[tuple], Callable], parent: QtCore.QObject):
super().__init__(parent, activity_keys=activity_keys)

def onTrigger(self, toggled):
activity_controller.duplicate_activities(self.activity_keys)
text = 'Duplicate ***'

@staticmethod
@exception_dialogs
def run(activity_keys: List[tuple]):
activities = [get_activity(key) for key in activity_keys]

for activity in activities:
new_code = commontasks.generate_copy_code(activity.key)
activity.copy(new_code)
56 changes: 41 additions & 15 deletions activity_browser/actions/activity/activity_duplicate_to_db.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Union, Callable, List
from typing import List

from PySide2 import QtWidgets, QtCore
from PySide2 import QtWidgets

from activity_browser import application, project_settings, activity_controller
from activity_browser import application, project_settings
from activity_browser.mod import bw2data as bd
from activity_browser.ui.icons import qicons
from activity_browser.actions.base import ABAction
from activity_browser.actions.base import ABAction, exception_dialogs
from activity_browser.bwutils import commontasks

from .activity_open import ActivityOpen


class ActivityDuplicateToDB(ABAction):
Expand All @@ -14,16 +18,32 @@ class ActivityDuplicateToDB(ABAction):
duplicate the activities to the chosen database.
"""
icon = qicons.duplicate_to_other_database
title = 'Duplicate to other database'
activity_keys: List[tuple]

def __init__(self, activity_keys: Union[List[tuple], Callable], parent: QtCore.QObject):
super().__init__(parent, activity_keys=activity_keys)
text = 'Duplicate to other database'

def onTrigger(self, toggled):
@classmethod
@exception_dialogs
def run(cls, activity_keys: List[tuple], to_db: str = None):
# get bw activity objects from keys
activities = activity_controller.get_activities(self.activity_keys)
activities = [bd.get_activity(key) for key in activity_keys]

if to_db and not cls.confirm_db(to_db): return

target_db = to_db or cls.request_db(activities)

if not target_db: return

new_activity_keys = []

# otherwise move all supplied activities to the db using the controller
for activity in activities:
new_code = commontasks.generate_copy_code((target_db, activity["code"]))
new_activity = activity.copy(code=new_code, database=target_db)
new_activity_keys.append(new_activity.key)

ActivityOpen.run(new_activity_keys)

@staticmethod
def request_db(activities):
# get valid databases (not the original database, or locked databases)
origin_db = next(iter(activities)).get("database")
target_dbs = [db for db in project_settings.get_editable_databases() if db != origin_db]
Expand All @@ -48,9 +68,15 @@ def onTrigger(self, toggled):
)

# return if the user didn't choose, or canceled
if not target_db or not ok: return
if not ok: return

# otherwise move all supplied activities to the db using the controller
for activity in activities:
activity_controller.duplicate_activity_to_db(target_db, activity)
return target_db

@staticmethod
def confirm_db(to_db: str):
user_choice = QtWidgets.QMessageBox.question(
application.main_window,
"Duplicate to new database",
f"Copy to {to_db} and open as new tab?",
)
return user_choice == user_choice.Yes
Loading
Loading