# Path: src/gui/line_edit_color_validator.py
# class LineEditColorValidator(object):
# 
#     def __init__(self, line_edit, re_mask, error_color='#f6989d', error_tooltip=''):
#         self.error_color = error_color
#         self.error_msg = error_tooltip
#         self.line_edit = line_edit
#         self.line_edit.textChanged.connect(self.on_changed)
#         self.re_mask = re_mask
#         self.re_comp = re.compile(self.re_mask)
#         self.on_changed()  # init
# 
#     def is_valid(self):
#         text = self.line_edit.text()
#         return self.re_comp.match(text)
# 
#     def on_changed(self, text=''):
#         if self.is_valid():
#             self.set_normal_style()
#         else:
#             self.set_error_style()
# 
#     def set_normal_style(self):
#         self.line_edit.setStyleSheet('')
#         self.line_edit.setToolTip('')
# 
#     def set_error_style(self):
#         self.line_edit.setStyleSheet('QLineEdit { background-color: %s }' % self.error_color)
#         self.line_edit.setToolTip(self.error_msg)


import os
from qgis.PyQt import uic
from qgis.PyQt.QtGui import QIntValidator
from qgis.PyQt.QtWidgets import QWidget, QMessageBox, QApplication
from .line_edit_color_validator import LineEditColorValidator



FORM_CLASS, _ = uic.loadUiType(os.path.join(
    os.path.dirname(__file__), 'editor_widget_tms.ui'))


class EditorWidgetTms(QWidget, FORM_CLASS):

    def __init__(self, parent=None):
        super(EditorWidgetTms, self).__init__(parent)
        self.setupUi(self)
        self.tms_validator = LineEditColorValidator(self.txtUrl, 'http[s]?://.+', error_tooltip='http{s}://any_text/{z}/{x}/{y}/')
        self.txtCrsId.setValidator(QIntValidator())

# Path: src/gui/line_edit_color_validator.py
# class LineEditColorValidator(object):
# 
#     def __init__(self, line_edit, re_mask, error_color='#f6989d', error_tooltip=''):
#         self.error_color = error_color
#         self.error_msg = error_tooltip
#         self.line_edit = line_edit
#         self.line_edit.textChanged.connect(self.on_changed)
#         self.re_mask = re_mask
#         self.re_comp = re.compile(self.re_mask)
#         self.on_changed()  # init
# 
#     def is_valid(self):
#         text = self.line_edit.text()
#         return self.re_comp.match(text)
# 
#     def on_changed(self, text=''):
#         if self.is_valid():
#             self.set_normal_style()
#         else:
#             self.set_error_style()
# 
#     def set_normal_style(self):
#         self.line_edit.setStyleSheet('')
#         self.line_edit.setToolTip('')
# 
#     def set_error_style(self):
#         self.line_edit.setStyleSheet('QLineEdit { background-color: %s }' % self.error_color)
#         self.line_edit.setToolTip(self.error_msg)


# Path: src/gui/editor_widget_tms.py
import os
from qgis.PyQt import uic
from qgis.PyQt.QtGui import QIntValidator
from qgis.PyQt.QtWidgets import QWidget, QMessageBox, QApplication
from .line_edit_color_validator import LineEditColorValidator




FORM_CLASS, _ = uic.loadUiType(os.path.join(
    os.path.dirname(__file__), 'editor_widget_tms.ui'))


class EditorWidgetTms(QWidget, FORM_CLASS):

    def __init__(self, parent=None):
        super(EditorWidgetTms, self).__init__(parent)
        self.setupUi(self)
        self.tms_validator = LineEditColorValidator(self.txtUrl, 'http[s]?://.+', error_tooltip='http{s}://any_text/{z}/{x}/{y}/')
        self.txtCrsId.setValidator(QIntValidator())

        self.txtPostgisCrsId.setValidator(QIntValidator())