Skip to content

Commit

Permalink
[ux] Improve color definition for log texts, taking into account the …
Browse files Browse the repository at this point in the history
…current theme (palette) and adjusting some colors to work well on both environments light and dark
  • Loading branch information
gacarrillor committed Jun 13, 2024
1 parent 0502aea commit b57b9df
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 143 deletions.
81 changes: 37 additions & 44 deletions QgisModelBaker/gui/ili2db_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
make_file_selector,
)
from QgisModelBaker.utils import gui_utils
from QgisModelBaker.utils.gui_utils import LogColor
from QgisModelBaker.utils.gui_utils import LogLevel, get_text_color

DIALOG_UI = gui_utils.get_ui_class("ili2db_options.ui")

Expand All @@ -36,6 +36,9 @@ class Ili2dbOptionsDialog(QDialog, DIALOG_UI):

ValidExtensions = ["toml", "TOML", "ini", "INI"]
SQLValidExtensions = ["sql", "SQL"]
COLOR_INFO = get_text_color(LogLevel.INFO)
COLOR_WARNING = get_text_color(LogLevel.WARNING)
COLOR_TOPPING = get_text_color(LogLevel.TOPPING)

def __init__(self, parent=None, remove_create_tid_group=True):
"""
Expand Down Expand Up @@ -292,59 +295,59 @@ def _restyle_concerning_metaconfig(self):
== self.smart1_radio_button.isChecked()
):
self.smart1_radio_button.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
else:
self.smart1_radio_button.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
if "smart2Inheritance" in self.current_metaconfig_ili2db:
if (
self.current_metaconfig_ili2db.getboolean("smart2Inheritance")
== self.smart2_radio_button.isChecked()
):
self.smart2_radio_button.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
else:
self.smart2_radio_button.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
if "createBasketCol" in self.current_metaconfig_ili2db:
if (
self.current_metaconfig_ili2db.getboolean("createBasketCol")
== self.create_basket_col_checkbox.isChecked()
):
self.create_basket_col_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
else:
self.create_basket_col_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
if "importTid" in self.current_metaconfig_ili2db:
if (
self.current_metaconfig_ili2db.getboolean("importTid")
== self.create_import_tid_checkbox.isChecked()
):
self.create_import_tid_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
else:
self.create_import_tid_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
if "strokeArcs" in self.current_metaconfig_ili2db:
if (
self.current_metaconfig_ili2db.getboolean("strokeArcs")
== self.stroke_arcs_checkbox.isChecked()
):
self.stroke_arcs_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
else:
self.stroke_arcs_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)

if self.current_metaconfig_toml_file_path:
Expand All @@ -353,77 +356,67 @@ def _restyle_concerning_metaconfig(self):
== self.toml_file_line_edit.text()
):
self.toml_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
)
self.toml_file_label.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
self.toml_file_label.setStyleSheet(f"color:{self.COLOR_TOPPING}")
else:
self.toml_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
)
self.toml_file_label.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
self.toml_file_label.setStyleSheet(f"color:{self.COLOR_WARNING}")

if self.current_metaconfig_post_script_path:
if (
self.current_metaconfig_post_script_path
== self.post_script_file_line_edit.text()
):
self.post_script_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
self.post_script_file_label.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
else:
self.post_script_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
self.post_script_file_label.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
if self.current_metaconfig_pre_script_path:
if (
self.current_metaconfig_pre_script_path
== self.pre_script_file_line_edit.text()
):
self.pre_script_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
self.pre_script_file_label.setStyleSheet(
f"color:{LogColor.COLOR_TOPPING}"
f"color:{self.COLOR_TOPPING}"
)
else:
self.pre_script_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)
self.pre_script_file_label.setStyleSheet(
f"color:{LogColor.COLOR_WARNING}"
f"color:{self.COLOR_WARNING}"
)

self.metaconfig_info_label.setVisible(True)
else:
# reset all
self.smart1_radio_button.setStyleSheet(f"color:{LogColor.COLOR_INFO}")
self.smart2_radio_button.setStyleSheet(f"color:{LogColor.COLOR_INFO}")
self.create_basket_col_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_INFO}"
)
self.create_import_tid_checkbox.setStyleSheet(
f"color:{LogColor.COLOR_INFO}"
)
self.stroke_arcs_checkbox.setStyleSheet(f"color:{LogColor.COLOR_INFO}")
self.toml_file_browse_button.setStyleSheet(f"color:{LogColor.COLOR_INFO}")
self.toml_file_label.setStyleSheet(f"color:{LogColor.COLOR_INFO}")
self.smart1_radio_button.setStyleSheet(f"color:{self.COLOR_INFO}")
self.smart2_radio_button.setStyleSheet(f"color:{self.COLOR_INFO}")
self.create_basket_col_checkbox.setStyleSheet(f"color:{self.COLOR_INFO}")
self.create_import_tid_checkbox.setStyleSheet(f"color:{self.COLOR_INFO}")
self.stroke_arcs_checkbox.setStyleSheet(f"color:{self.COLOR_INFO}")
self.toml_file_browse_button.setStyleSheet(f"color:{self.COLOR_INFO}")
self.toml_file_label.setStyleSheet(f"color:{self.COLOR_INFO}")
self.post_script_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_INFO}"
)
self.post_script_file_label.setStyleSheet(f"color:{LogColor.COLOR_INFO}")
self.pre_script_file_browse_button.setStyleSheet(
f"color:{LogColor.COLOR_INFO}"
f"color:{self.COLOR_INFO}"
)
self.pre_script_file_label.setStyleSheet(f"color:{LogColor.COLOR_INFO}")
self.post_script_file_label.setStyleSheet(f"color:{self.COLOR_INFO}")
self.pre_script_file_browse_button.setStyleSheet(f"color:{self.COLOR_INFO}")
self.pre_script_file_label.setStyleSheet(f"color:{self.COLOR_INFO}")

self.metaconfig_info_label.setVisible(False)
24 changes: 11 additions & 13 deletions QgisModelBaker/gui/panel/log_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
from qgis.core import Qgis
from qgis.gui import QgsMessageBar
from qgis.PyQt.QtCore import QSize, Qt
from qgis.PyQt.QtGui import QColor
from qgis.PyQt.QtWidgets import QGridLayout, QSizePolicy, QTextBrowser, QWidget

from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbutils import color_log_text
from QgisModelBaker.utils.gui_utils import LogColor
from QgisModelBaker.utils.gui_utils import (
LogLevel,
get_parsed_log_text_color,
get_text_color_object,
)


class LogPanel(QWidget):
Expand Down Expand Up @@ -58,23 +60,19 @@ def sizeHint(self):
self.fontMetrics().lineSpacing() * 48, self.fontMetrics().lineSpacing() * 10
)

def print_info(self, text, text_color=LogColor.COLOR_INFO):
self.txtStdout.setTextColor(QColor(text_color))
def print_info(self, text, level=LogLevel.INFO):
self.txtStdout.setTextColor(get_text_color_object(level))
self.txtStdout.append(text)

if text_color == LogColor.COLOR_INFO:
if level in (LogLevel.INFO, LogLevel.SUCCESS, LogLevel.TOPPING):
logging.info(text)
elif text_color == LogColor.COLOR_SUCCESS:
logging.info(text)
elif text_color == LogColor.COLOR_WARNING:
elif level == LogLevel.WARNING:
logging.warning(text)
elif text_color == LogColor.COLOR_FAIL:
elif level == LogLevel.FAIL:
logging.error(text)
elif text_color == LogColor.COLOR_TOPPING:
logging.info(text)

def on_stderr(self, text):
color_log_text(text, self.txtStdout)
get_parsed_log_text_color(text, self.txtStdout)

def show_message(self, level, message):
if level == Qgis.Warning:
Expand Down
24 changes: 11 additions & 13 deletions QgisModelBaker/gui/panel/session_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os

from qgis.PyQt.QtCore import Qt, pyqtSignal
from qgis.PyQt.QtWidgets import QAction, QMessageBox, QWidget
from qgis.PyQt.QtWidgets import QAction, QApplication, QMessageBox, QWidget

import QgisModelBaker.libs.modelbaker.utils.db_utils as db_utils
import QgisModelBaker.utils.gui_utils as gui_utils
Expand All @@ -35,14 +35,14 @@
from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
from QgisModelBaker.libs.modelbaker.utils.qt_utils import OverrideCursor
from QgisModelBaker.utils.globals import DEFAULT_DATASETNAME
from QgisModelBaker.utils.gui_utils import LogColor
from QgisModelBaker.utils.gui_utils import LogLevel

WIDGET_UI = gui_utils.get_ui_class("workflow_wizard/session_panel.ui")


class SessionPanel(QWidget, WIDGET_UI):

print_info = pyqtSignal(str, str)
print_info = pyqtSignal(str, int)
on_stderr = pyqtSignal(str)
on_process_started = pyqtSignal(str)
on_process_finished = pyqtSignal(int, int)
Expand Down Expand Up @@ -295,7 +295,7 @@ def _pre_generate_project(self):
if not res:
self.print_info.emit(
message,
LogColor.COLOR_FAIL,
LogLevel.FAIL,
)

def edit_command(self):
Expand All @@ -313,7 +313,7 @@ def edit_command(self):
def run(self, edited_command=None):
if self.is_running:
# means this is called by "cancel" option
self.print_info.emit(self.tr("Cancel session..."), LogColor.COLOR_INFO)
self.print_info.emit(self.tr("Cancel session..."), LogLevel.INFO)
self.set_button_to_last_create_state()
self.cancel_session.emit()
return
Expand All @@ -332,9 +332,7 @@ def run(self, edited_command=None):
self.progress_bar.setTextVisible(False)
self.progress_bar.setValue(10)

porter.stdout.connect(
lambda str: self.print_info.emit(str, LogColor.COLOR_INFO)
)
porter.stdout.connect(lambda str: self.print_info.emit(str, LogLevel.INFO))
porter.stderr.connect(self.on_stderr)
porter.process_started.connect(self.on_process_started)
porter.process_finished.connect(self.on_process_finished)
Expand All @@ -351,7 +349,7 @@ def run(self, edited_command=None):
self.is_running = False
return False
except JavaNotFoundError as e:
self.print_info.emit(e.error_string, LogColor.COLOR_FAIL)
self.print_info.emit(e.error_string, LogLevel.FAIL)
self.progress_bar.setValue(0)
if not self.db_action_type == DbActionType.GENERATE:
self.set_button_to_create_without_constraints()
Expand Down Expand Up @@ -379,14 +377,14 @@ def run(self, edited_command=None):

self.set_button_to_last_create_state()
self.is_running = False
self.print_info.emit(f'{self.tr("Done!")}\n', LogColor.COLOR_SUCCESS)
self.print_info.emit(f'{self.tr("Done!")}\n', LogLevel.SUCCESS)
self._done()
return True

def _create_default_dataset(self):
self.print_info.emit(
self.tr("Create the default dataset {}").format(DEFAULT_DATASETNAME),
LogColor.COLOR_INFO,
LogLevel.INFO,
)
db_connector = db_utils.get_db_connector(self.configuration)

Expand All @@ -400,7 +398,7 @@ def _create_default_dataset(self):
default_dataset_tid = default_datasets_info_tids[0]
else:
status, message = db_connector.create_dataset(DEFAULT_DATASETNAME)
self.print_info.emit(message, LogColor.COLOR_INFO)
self.print_info.emit(message, LogLevel.INFO)
if status:
default_datasets_info_tids = [
datasets_info["t_id"]
Expand All @@ -415,7 +413,7 @@ def _create_default_dataset(self):
self.tr(
"No default dataset created ({}) - do it manually in the dataset manager."
).format(message),
LogColor.COLOR_FAIL,
LogLevel.FAIL,
)

def _get_tid_handling(self):
Expand Down
2 changes: 1 addition & 1 deletion QgisModelBaker/gui/topping_wizard/generation_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ def generate(self):
self.progress_bar.setFormat(result_message)
self.progress_bar.setTextVisible(True)
self.topping_wizard.log_panel.print_info(
result_message, gui_utils.LogColor.COLOR_SUCCESS
result_message, gui_utils.LogLevel.SUCCESS
)
10 changes: 5 additions & 5 deletions QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def validatePage(self) -> bool:
schema=self.schema_combobox.currentText()
)
),
gui_utils.LogColor.COLOR_SUCCESS,
gui_utils.LogLevel.SUCCESS,
)
if self.topping_wizard.topping.metaconfig.ili2db_settings.prescript_path:
self.topping_wizard.log_panel.print_info(
Expand All @@ -223,7 +223,7 @@ def validatePage(self) -> bool:
path=self.topping_wizard.topping.metaconfig.ili2db_settings.prescript_path
)
),
gui_utils.LogColor.COLOR_SUCCESS,
gui_utils.LogLevel.SUCCESS,
)
if self.topping_wizard.topping.metaconfig.ili2db_settings.postscript_path:
self.topping_wizard.log_panel.print_info(
Expand All @@ -232,7 +232,7 @@ def validatePage(self) -> bool:
path=self.topping_wizard.topping.metaconfig.ili2db_settings.postscript_path
)
),
gui_utils.LogColor.COLOR_SUCCESS,
gui_utils.LogLevel.SUCCESS,
)
if self.topping_wizard.topping.metaconfig.ili2db_settings.metaattr_path:
self.topping_wizard.log_panel.print_info(
Expand All @@ -241,14 +241,14 @@ def validatePage(self) -> bool:
path=self.topping_wizard.topping.metaconfig.ili2db_settings.metaattr_path
)
),
gui_utils.LogColor.COLOR_SUCCESS,
gui_utils.LogLevel.SUCCESS,
)
if self.topping_wizard.topping.metaconfig.metaconfigparamsonly:
self.topping_wizard.log_panel.print_info(
self.tr(
"This metaconfiguration will be passed without any additional settings on import made by Model Baker (except models and on disable constraint run): qgis.modelbaker.metaConfigParamsOnly = true"
),
gui_utils.LogColor.COLOR_SUCCESS,
gui_utils.LogLevel.SUCCESS,
)
return super().validatePage()

Expand Down
2 changes: 1 addition & 1 deletion QgisModelBaker/gui/topping_wizard/layers_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,6 @@ def initializePage(self) -> None:
def validatePage(self) -> bool:
self.topping_wizard.log_panel.print_info(
self.tr("Set export settings for layers."),
gui_utils.LogColor.COLOR_SUCCESS,
gui_utils.LogLevel.SUCCESS,
)
return super().validatePage()
Loading

0 comments on commit b57b9df

Please sign in to comment.