Skip to content

Commit

Permalink
finetuning on project create and prototype of progress bar when loadi…
Browse files Browse the repository at this point in the history
…ng 'something' kind of a busy indicator
  • Loading branch information
signedav committed Dec 4, 2023
1 parent 8b6c968 commit 451eb17
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 29 deletions.
10 changes: 9 additions & 1 deletion QgisModelBaker/gui/panel/log_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import logging

from PyQt5.QtWidgets import QGridLayout
from PyQt5.QtWidgets import QGridLayout, QProgressBar
from qgis.core import Qgis
from qgis.gui import QgsMessageBar
from qgis.PyQt.QtCore import QSize, Qt
Expand All @@ -40,9 +40,17 @@ def __init__(self, parent=None):
self.txtStdout.setLayout(QGridLayout())
self.txtStdout.layout().setContentsMargins(0, 0, 0, 0)
self.txtStdout.layout().addWidget(self.bar, 0, 0, Qt.AlignTop)
self.scrollbar = self.txtStdout.verticalScrollBar()

self.busy_bar = QProgressBar()
self.busy_bar.setRange(0, 0)
self.busy_bar.setTextVisible(True)
self.busy_bar.setVisible(False)

layout = QGridLayout()
layout.addWidget(self.txtStdout)
layout.addWidget(self.busy_bar)

self.setLayout(layout)

def sizeHint(self):
Expand Down
7 changes: 7 additions & 0 deletions QgisModelBaker/gui/workflow_wizard/execution_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,10 @@ def _on_process_finished(self, exit_code, result):
message = self.tr("Finished with errors!")

self.workflow_wizard.log_panel.print_info(message, color)

def busy(self, busy, text=None):
self.setEnabled(not busy)
if busy:
self.workflow_wizard.start_busy_bar(text)
else:
self.workflow_wizard.stop_busy_bar()
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def _update_ilimetaconfigcache(self):
self.ilimetaconfigcache.model_refreshed.connect(
self._update_metaconfig_completer
)
self.busy(True, self.tr("Refresh repository data..."))
self._refresh_ili_metaconfig_cache()

def _update_ilireferencedatacache(self):
Expand Down Expand Up @@ -289,6 +290,7 @@ def _update_metaconfig_completer(self, rows):
completer.popup().setItemDelegate(self.metaconfig_delegate)
self.ili_metaconfig_line_edit.setCompleter(completer)
self.ili_metaconfig_line_edit.setEnabled(bool(rows))
self.busy(False)

def _on_metaconfig_completer_activated(self, text=None):
self._clean_metaconfig()
Expand All @@ -315,8 +317,9 @@ def _on_metaconfig_completer_activated(self, text=None):
self.ilimetaconfigcache.model.data(model_index, Qt.DisplayRole),
metaconfig_id,
self.ilimetaconfigcache.model.data(
model_index, int(IliDataItemModel.Roles.SHORT_DESCRIPTION) or ""
),
model_index, int(IliDataItemModel.Roles.SHORT_DESCRIPTION)
)
or "",
)
)
self.metaconfig_file_info_label.setStyleSheet("color: #341d5c")
Expand Down Expand Up @@ -433,6 +436,7 @@ def _load_crs_from_metaconfig(self, ili2db_metaconfig):
self._crs_changed()

def _load_metaconfig(self):
self.busy(True, "Load metaconfiguration...")
# load ili2db parameters to the GUI
if "ch.ehi.ili2db" in self.metaconfig.sections():
self.workflow_wizard.log_panel.print_info(
Expand Down Expand Up @@ -570,3 +574,12 @@ def _load_metaconfig(self):
LogColor.COLOR_TOPPING,
)
self.workflow_wizard.refresh_import_models()

self.busy(False)

def busy(self, busy, text=None):
self.setEnabled(not busy)
if busy:
self.workflow_wizard.start_busy_bar(text)
else:
self.workflow_wizard.stop_busy_bar()
52 changes: 40 additions & 12 deletions QgisModelBaker/gui/workflow_wizard/project_creation_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def setComplete(self, complete):
self.completeChanged.emit()

def restore_configuration(self, configuration):
self.setEnabled(False)
self.busy(
True,
self.tr("Restoring configuration and check existing metaconfigfile..."),
)
self.configuration = configuration
self.db_connector = db_utils.get_db_connector(self.configuration)

Expand All @@ -126,7 +129,7 @@ def restore_configuration(self, configuration):
self.existing_topping_checkbox.setChecked(True)
else:
self._use_existing(False)
self.setEnabled(True)
self.busy(False)

def _use_existing(self, state):
# triggered by checked state...
Expand All @@ -139,14 +142,26 @@ def _use_existing(self, state):
self._set_topping_info(True)
else:
self._clean_topping()
models = ";".join(self._modelnames())
self.ilitoppingcache = IliDataCache(
self.configuration.base_configuration, "projecttopping", models
self.configuration.base_configuration,
type="projecttopping",
models=";".join(self._modelnames()),
datasources=["pg"]
if (
self.workflow_wizard.import_schema_configuration.tool & DbIliMode.pg
)
else ["gpkg"]
if (
self.workflow_wizard.import_schema_configuration.tool
& DbIliMode.gpkg
)
else None,
)
self.ilitoppingcache.new_message.connect(
self.workflow_wizard.log_panel.show_message
)
# wait before activating untill end of refreshment
# wait before activating until end of refreshment
self.busy(True, self.tr("Refresh repository data..."))
self.ilitoppingcache.model_refreshed.connect(
lambda: self._enable_topping_selection(True)
)
Expand Down Expand Up @@ -174,6 +189,7 @@ def _enable_topping_selection(self, state):
self.topping_line_edit.setEnabled(state)
self.topping_line_label.setEnabled(state)
self.topping_info.setEnabled(state)
self.busy(False)

def _enable_optimize_combo(self, state):
self.optimize_combo.setEnabled(state)
Expand Down Expand Up @@ -307,21 +323,26 @@ def _clean_topping(self):
def _set_topping_info(self, valid, index=None):
if self.projecttopping_id:
if index:
if self.existing_topping_checkbox.isChecked():
info = self.tr(
"Project topping received according to the id found in the database or selected previously"
)
else:
info = self.tr("Project topping received according selection")
self.topping_info.setText(
self.tr(
"<html><head/><body><p><b>Current project topping is: {} ({})</b><br><i>{}</i></p></body></html>"
).format(
self.ilitoppingcache.model.data(index, Qt.DisplayRole),
"<html><head/><body><p><b>{} ({})</b><br><i><b>{}</b></i></p></body></html>".format(
info,
self.projecttopping_id,
self.ilitoppingcache.model.data(
index, int(IliDataItemModel.Roles.SHORT_DESCRIPTION) or ""
),
index, int(IliDataItemModel.Roles.SHORT_DESCRIPTION)
)
or "",
)
)
else:
self.topping_info.setText(
self.tr(
"<html><head/><body><p><b>Current project topping is: {}</b></p></body></html>"
"<html><head/><body><p><b>Project topping from file {}</b></p></body></html>"
).format(self.projecttopping_id)
)

Expand Down Expand Up @@ -638,3 +659,10 @@ def ilidata_path_resolver(self, base_path, path):
data_file_path_list = self.workflow_wizard.get_topping_file_list([path])
return data_file_path_list[0] if data_file_path_list else None
return os.path.join(base_path, path)

def busy(self, busy, text=None):
self.setEnabled(not busy)
if busy:
self.workflow_wizard.start_busy_bar(text)
else:
self.workflow_wizard.stop_busy_bar()
27 changes: 26 additions & 1 deletion QgisModelBaker/gui/workflow_wizard/workflow_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
IliToppingFileCache,
)
from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
from QgisModelBaker.utils import gui_utils
from QgisModelBaker.utils.gui_utils import (
FileDropListView,
ImportDataModel,
Expand Down Expand Up @@ -271,6 +272,9 @@ def next_id(self):
"Checking for potential referenced data on the repositories (might take a while)..."
)
)
self.schema_configuration_page.busy(
True, self.tr("Checking for potential referenced data...")
)
self.schema_configuration_page.setComplete(False)
if (
self.import_data_file_model.rowCount()
Expand All @@ -283,6 +287,7 @@ def next_id(self):
self.tr("Potential referenced data found.")
)
self.schema_configuration_page.setComplete(True)
self.schema_configuration_page.busy(False)
return PageIds.ImportDataConfiguration
else:
self.log_panel.print_info(
Expand All @@ -291,6 +296,7 @@ def next_id(self):
)
)
self.schema_configuration_page.setComplete(True)
self.schema_configuration_page.busy(False)

if self.current_id == PageIds.ImportSchemaExecution:
# if basket handling active, go to the create basket
Expand All @@ -307,6 +313,9 @@ def next_id(self):
"Checking for potential referenced data on the repositories (might take a while)..."
)
)
self.import_schema_execution_page.busy(
True, self.tr("Checking for potential referenced data...")
)
self.import_schema_execution_page.setComplete(False)
if self.update_referecedata_cache_model(
self._db_modelnames(self.import_data_configuration),
Expand All @@ -316,8 +325,10 @@ def next_id(self):
self.tr("Potential referenced data found.")
)
self.import_schema_execution_page.setComplete(True)
self.import_schema_execution_page.busy(False)
return PageIds.ImportDataConfiguration
self.import_schema_execution_page.setComplete(True)
self.import_schema_execution_page.busy(False)

# otherwise, go to project create
return PageIds.ProjectCreation
Expand All @@ -334,6 +345,9 @@ def next_id(self):
)
)
self.default_baskets_page.setComplete(False)
self.ddefault_baskets_page.busy(
True, self.tr("Checking for potential referenced data...")
)
if self.update_referecedata_cache_model(
self._db_modelnames(self.import_data_configuration),
"referenceData",
Expand All @@ -342,8 +356,10 @@ def next_id(self):
self.tr("Potential referenced data found.")
)
self.default_baskets_page.setComplete(True)
self.default_baskets_page.busy(False)
return PageIds.ImportDataConfiguration
self.default_baskets_page.setComplete(True)
self.default_baskets_page.busy(False)

# otherwise, go to project create
return PageIds.ProjectCreation
Expand Down Expand Up @@ -670,10 +686,19 @@ def append_dropped_files(self, dropped_files, dropped_ini_files):
dropped_ini_files[0]
)

def start_busy_bar(self, text="Loading..."):
self.log_panel.busy_bar.setFormat(text)
self.log_panel.busy_bar.setVisible(True)

def stop_busy_bar(self):
self.log_panel.busy_bar.setVisible(False)
self.log_panel.scrollbar.setValue(self.log_panel.scrollbar.maximum())


class WorkflowWizardDialog(QDialog):
def __init__(self, iface, base_config, parent):
QDialog.__init__(self, parent)
self.setStyleSheet(gui_utils.DEFAULT_STYLE)
self.iface = iface
self.base_config = base_config

Expand All @@ -683,8 +708,8 @@ def __init__(self, iface, base_config, parent):
self.workflow_wizard.setStartId(PageIds.Intro)
self.workflow_wizard.setWindowFlags(Qt.Widget)
self.workflow_wizard.show()

self.workflow_wizard.finished.connect(self.done)

layout = QVBoxLayout()
splitter = QSplitter(Qt.Vertical)
splitter.addWidget(self.workflow_wizard)
Expand Down
29 changes: 16 additions & 13 deletions QgisModelBaker/ui/workflow_wizard/project_creation.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="existing_topping_checkbox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;A project topping is already given by the previous metaconfiguration selection or via the metaconfiguration id stored in the database. Uncheck, when you want to choose another project topping file.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Use existing project topping</string>
</property>
Expand Down Expand Up @@ -114,6 +117,19 @@
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QProgressBar" name="progress_bar">
<property name="value">
Expand Down Expand Up @@ -181,19 +197,6 @@
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
Expand Down

0 comments on commit 451eb17

Please sign in to comment.