Skip to content

Commit

Permalink
Merge pull request #101 from opengisch/code_cleanup_colors
Browse files Browse the repository at this point in the history
Code cleanup concerning GUI-related stuff
  • Loading branch information
signedav authored Jun 20, 2024
2 parents b51f15f + 34936be commit 47444c6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 117 deletions.
15 changes: 0 additions & 15 deletions modelbaker/iliwrapper/ili2dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import zipfile

from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtGui import QColor

from ..utils.qt_utils import NetworkError, download_file
from .globals import DbIliMode
Expand Down Expand Up @@ -141,20 +140,6 @@ def get_all_modeldir_in_path(path, lambdafunction=None):
return ";".join(modeldirs)


def color_log_text(text, txt_edit):
textlines = text.splitlines()
for textline in textlines:
if textline.startswith("Warning:"):
txt_edit.setTextColor(QColor("#FFBF00"))
txt_edit.append(textline)
elif "error" in textline.lower() or "failed" in textline.lower():
txt_edit.setTextColor(QColor("#aa2222"))
txt_edit.append(textline)
else:
txt_edit.setTextColor(QColor("#2a2a2a"))
txt_edit.append(textline)


def get_java_path(base_configuration):
"""
Delivers the path to a Java 8 installation or raises a JavaNotFoundError
Expand Down
102 changes: 0 additions & 102 deletions modelbaker/utils/qt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
***************************************************************************/
"""

import fnmatch
import functools
import os.path
import re
import unicodedata
from abc import ABCMeta
Expand All @@ -33,7 +31,6 @@
QObject,
QUrl,
)
from qgis.PyQt.QtGui import QValidator
from qgis.PyQt.QtNetwork import QNetworkRequest
from qgis.PyQt.QtWidgets import QApplication, QFileDialog

Expand Down Expand Up @@ -211,105 +208,6 @@ def finished(filename, reply, on_error, on_success, on_finished):
return filename


class Validators(QObject):
def validate_line_edits(self, *args, **kwargs):
"""
Validate line edits and set their color to indicate validation state.
"""
senderObj = self.sender()
validator = senderObj.validator()
if validator is None:
color = "#fff" # White
else:
state = validator.validate(senderObj.text().strip(), 0)[0]
if state == QValidator.Acceptable:
color = "#fff" # White
elif state == QValidator.Intermediate:
color = "#ffd356" # Light orange
else:
color = "#f6989d" # Red
senderObj.setStyleSheet("QLineEdit {{ background-color: {} }}".format(color))


class FileValidator(QValidator):
def __init__(
self,
pattern="*",
is_executable=False,
parent=None,
allow_empty=False,
allow_non_existing=False,
):
"""
Validates if a string is a valid filename, based on the provided parameters.
:param pattern: A file glob pattern as recognized by ``fnmatch``, if a list if provided, the validator will try
to match every pattern in the list.
:param is_executable: Only match executable files
:param parent: The parent QObject
:param allow_empty: Empty strings are valid
:param allow_non_existing: Non existing files are valid
"""
QValidator.__init__(self, parent)
self.pattern = pattern
self.is_executable = is_executable
self.allow_empty = allow_empty
self.allow_non_existing = allow_non_existing
self.error = ""

"""
Validator for file line edits
"""

def validate(self, text, pos):
self.error = ""

if self.allow_empty and not text.strip():
return QValidator.Acceptable, text, pos

pattern_matches = False
if type(self.pattern) is str:
pattern_matches = fnmatch.fnmatch(text, self.pattern)
elif type(self.pattern) is list:
pattern_matches = True in (
fnmatch.fnmatch(text, pattern) for pattern in self.pattern
)
else:
raise TypeError(
"pattern must be str or list, not {}".format(type(self.pattern))
)

if not text:
self.error = self.tr("Text field value is empty.")
elif not self.allow_non_existing and not os.path.isfile(text):
self.error = self.tr("The chosen file does not exist.")
elif not pattern_matches:
self.error = self.tr(
"The chosen file has a wrong extension (has to be {}).".format(
self.pattern
if type(self.pattern) is str
else ",".join(self.pattern)
)
)
elif self.is_executable and not os.access(text, os.X_OK):
self.error = self.tr("The chosen file is not executable.")
if self.error:
return QValidator.Intermediate, text, pos
else:
return QValidator.Acceptable, text, pos


class NonEmptyStringValidator(QValidator):
def __init__(self, parent=None):
QValidator.__init__(self, parent)

def validate(self, text, pos):
if not text.strip():
return QValidator.Intermediate, text, pos

return QValidator.Acceptable, text, pos


class OverrideCursor:
def __init__(self, cursor):
self.cursor = cursor
Expand Down

0 comments on commit 47444c6

Please sign in to comment.