# Path: lib/ui/ui_manager.py
# class DialogTextUi(GwDialog, FORM_CLASS):
#     pass


import inspect
import os
import operator
import sys
import subprocess
import traceback
import webbrowser
from functools import partial
from encodings.aliases import aliases
from qgis.PyQt.QtCore import QDate, QDateTime, QSortFilterProxyModel, QStringListModel, QTime, Qt, QRegExp, pyqtSignal,\
    QPersistentModelIndex, QCoreApplication, QTranslator
from qgis.PyQt.QtGui import QPixmap, QDoubleValidator, QTextCharFormat, QFont
from qgis.PyQt.QtSql import QSqlTableModel
from qgis.PyQt.QtWidgets import QAction, QLineEdit, QComboBox, QWidget, QDoubleSpinBox, QCheckBox, QLabel, QTextEdit, \
    QDateEdit, QAbstractItemView, QCompleter, QDateTimeEdit, QTableView, QSpinBox, QTimeEdit, QPushButton, \
    QPlainTextEdit, QRadioButton, QSizePolicy, QSpacerItem, QFileDialog, QGroupBox, QMessageBox, QTabWidget, QToolBox, \
    QToolButton
from qgis.core import QgsExpression, QgsProject, QgsLayerTreeLayer
from qgis.gui import QgsDateTimeEdit
from . import tools_log, tools_os, tools_qgis
from .. import global_vars
from .ui.ui_manager import DialogTextUi
    if widget != lazy_widget:
        return
    lazy_init_function(lazy_widget)


def filter_by_id(dialog, widget_table, widget_txt, table_object):

    field_object_id = "id"
    if table_object == "element":
        field_object_id = table_object + "_id"
    object_id = get_text(dialog, widget_txt)
    if object_id != 'null':
        expr = f"{field_object_id}::text ILIKE '%{object_id}%'"
        # Refresh model with selected filter
        widget_table.model().setFilter(expr)
        widget_table.model().select()
    else:
        fill_table(widget_table, global_vars.schema_name + "." + table_object)


def set_selection_behavior(dialog):

    # Get objects of type: QTableView
    widget_list = dialog.findChildren(QTableView)
    for widget in widget_list:
        widget.setSelectionBehavior(QAbstractItemView.SelectRows)
        widget.horizontalHeader().setSectionResizeMode(3)
        widget.horizontalHeader().setStretchLastSection(True)



# Path: lib/ui/ui_manager.py
# class DialogTextUi(GwDialog, FORM_CLASS):
#     pass


# Path: lib/tools_qt.py
import inspect
import os
import operator
import sys
import subprocess
import traceback
import webbrowser
from functools import partial
from encodings.aliases import aliases
from qgis.PyQt.QtCore import QDate, QDateTime, QSortFilterProxyModel, QStringListModel, QTime, Qt, QRegExp, pyqtSignal,\
    QPersistentModelIndex, QCoreApplication, QTranslator
from qgis.PyQt.QtGui import QPixmap, QDoubleValidator, QTextCharFormat, QFont
from qgis.PyQt.QtSql import QSqlTableModel
from qgis.PyQt.QtWidgets import QAction, QLineEdit, QComboBox, QWidget, QDoubleSpinBox, QCheckBox, QLabel, QTextEdit, \
    QDateEdit, QAbstractItemView, QCompleter, QDateTimeEdit, QTableView, QSpinBox, QTimeEdit, QPushButton, \
    QPlainTextEdit, QRadioButton, QSizePolicy, QSpacerItem, QFileDialog, QGroupBox, QMessageBox, QTabWidget, QToolBox, \
    QToolButton
from qgis.core import QgsExpression, QgsProject, QgsLayerTreeLayer
from qgis.gui import QgsDateTimeEdit
from . import tools_log, tools_os, tools_qgis
from .. import global_vars
from .ui.ui_manager import DialogTextUi

    if widget != lazy_widget:
        return
    lazy_init_function(lazy_widget)


def filter_by_id(dialog, widget_table, widget_txt, table_object):

    field_object_id = "id"
    if table_object == "element":
        field_object_id = table_object + "_id"
    object_id = get_text(dialog, widget_txt)
    if object_id != 'null':
        expr = f"{field_object_id}::text ILIKE '%{object_id}%'"
        # Refresh model with selected filter
        widget_table.model().setFilter(expr)
        widget_table.model().select()
    else:
        fill_table(widget_table, global_vars.schema_name + "." + table_object)


def set_selection_behavior(dialog):

    # Get objects of type: QTableView
    widget_list = dialog.findChildren(QTableView)
    for widget in widget_list:
        widget.setSelectionBehavior(QAbstractItemView.SelectRows)
        widget.horizontalHeader().setSectionResizeMode(3)
        widget.horizontalHeader().setStretchLastSection(True)



def get_folder_path(dialog, widget):