Skip to content

Commit

Permalink
Various patches for database importing (#344)
Browse files Browse the repository at this point in the history
* Implement page enums for import wizard, pages now have explicit nextId page

* Ensure no db import can take place before biosphere (biosphere3) exists

* Speedup 7zip extract by not printing 'Extracted ...' lines.

* Force cleanup of DatabaseImportWizard on creation and project change

* Subclass BW2Package to allow check for required dependencies

* Move tempdir creation and handling together, feed correct paths to methods

* Rename 'import failed' signal for clarity

* Possible fix for #333
  • Loading branch information
dgdekoning authored Dec 13, 2019
1 parent 58b5530 commit 2dbc1b6
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 77 deletions.
28 changes: 16 additions & 12 deletions activity_browser/app/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Controller(object):
It is different from bwutils in that it also contains Qt elements such as dialogs.
- """
def __init__(self):
self.db_wizard = None
self.connect_signals()
signals.project_selected.emit()
self.load_settings()
self.db_wizard = None
print('Brightway2 data directory: {}'.format(bw.projects._base_data_dir))
print('Brightway2 active project: {}'.format(bw.projects.current))

Expand Down Expand Up @@ -77,18 +77,21 @@ def load_settings(self):
self.switch_brightway2_dir_path(dirpath=ab_settings.custom_bw_dir)
self.change_project(ab_settings.startup_project)

def clear_database_wizard(self):
""" Separate cleanup method, used to clear out existing import wizard
when switching projects.
"""
if self.db_wizard is None:
return
self.db_wizard.deleteLater()
self.db_wizard = None

def import_database_wizard(self):
try:
if self.db_wizard is None:
self.db_wizard = DatabaseImportWizard()
else:
self.db_wizard.show()
self.db_wizard.activateWindow()
except:
QtWidgets.QMessageBox.warning(None,
"Error during importing.",
"Oops. Something went wrong with the data import. "
"Please check the console for details.")
""" Create a database import wizard, if it already exists, set the
previous one to delete and recreate it.
"""
self.clear_database_wizard()
self.db_wizard = DatabaseImportWizard()

def switch_brightway2_dir_path(self, dirpath):
if dirpath == bw.projects._base_data_dir:
Expand Down Expand Up @@ -128,6 +131,7 @@ def change_project_dialog(self):

def change_project(self, name=None, reload=False):
# TODO: what should happen if a new project is opened? (all activities, etc. closed?)
self.clear_database_wizard()
if not name:
print("No project name given.")
return
Expand Down
11 changes: 6 additions & 5 deletions activity_browser/app/ui/menu_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def __init__(self, window):
"&Update biosphere...", None
)
self.biosphere_updater = None
self.import_db_action = QtWidgets.QAction(
qicons.import_db, '&Import database...', None
)

self.menubar = QtWidgets.QMenuBar()
self.menubar.addMenu(self.setup_file_menu())
Expand All @@ -35,15 +38,12 @@ def connect_signals(self):
signals.project_selected.connect(self.biosphere_exists)
signals.databases_changed.connect(self.biosphere_exists)
self.update_biosphere_action.triggered.connect(self.update_biosphere)
self.import_db_action.triggered.connect(signals.import_database.emit)

# FILE
def setup_file_menu(self):
menu = QtWidgets.QMenu('&File', self.window)
menu.addAction(
qicons.import_db,
'&Import database...',
signals.import_database.emit
)
menu.addAction(self.import_db_action)
menu.addAction(
self.window.style().standardIcon(QtWidgets.QStyle.SP_DriveHDIcon),
"&Export database...",
Expand Down Expand Up @@ -153,6 +153,7 @@ def biosphere_exists(self) -> None:
"""
exists = True if bw.config.biosphere in bw.databases else False
self.update_biosphere_action.setEnabled(exists)
self.import_db_action.setEnabled(exists)

def update_biosphere(self):
""" Open a popup with progression bar and run through the different
Expand Down
Loading

0 comments on commit 2dbc1b6

Please sign in to comment.