gui-utilities 1.3.44__py3-none-any.whl → 1.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  from PyQt6.QtCore import Qt, QObject, QEvent, QSize
2
- from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QLineEdit, QComboBox, QDialog, QToolButton, QWidgetAction, QCheckBox, QTableWidget, QHeaderView
3
- from PyQt6.QtGui import QIcon
2
+ from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QLineEdit, QComboBox, QDialog, QToolButton, QWidgetAction, QCheckBox, QTableWidget, QHeaderView, QApplication, QStyle, QStyledItemDelegate
3
+ from PyQt6.QtGui import QIcon, QTextDocument
4
4
  import re
5
5
  import requests
6
6
  import importlib.resources
@@ -9,6 +9,16 @@ main_dir = importlib.resources.files("gui_utilities")
9
9
  icons_dir = main_dir / "icons"
10
10
  tlds_path = main_dir / "tlds"
11
11
 
12
+ def latex_to_html(expression):
13
+ html_expression = expression
14
+ html_expression = re.sub(r"\\frac\{(.*?)\}\{(.*?)\}", r"<span style='font-size:90%;'>\1⁄\2</span>", html_expression)
15
+ html_expression = re.sub(r"_\{([^}]+)\}", r"<sub>\1</sub>", html_expression)
16
+ html_expression = re.sub(r"\^\{([^}]+)\}", r"<sup>\1</sup>", html_expression)
17
+ html_expression = re.sub(r"_([a-zA-Z0-9]+)", r"<sub>\1</sub>", html_expression)
18
+ html_expression = re.sub(r"\^([a-zA-Z0-9]+)", r"<sup>\1</sup>", html_expression)
19
+ html_expression = html_expression.replace(" ", "&nbsp;")
20
+ return html_expression
21
+
12
22
  def create_window(title, background_color = "#1e1e1e", parent = None):
13
23
  window = QWidget(parent)
14
24
  window.setObjectName("window")
@@ -201,16 +211,6 @@ def create_label(
201
211
  word_wrap = False,
202
212
  parent = None
203
213
  ):
204
- def latex_to_html(expression):
205
- html_expression = expression
206
- html_expression = re.sub(r"\\frac\{(.*?)\}\{(.*?)\}", r"<span style='font-size:90%;'>\1⁄\2</span>", html_expression)
207
- html_expression = re.sub(r"_\{([^}]+)\}", r"<sub>\1</sub>", html_expression)
208
- html_expression = re.sub(r"\^\{([^}]+)\}", r"<sup>\1</sup>", html_expression)
209
- html_expression = re.sub(r"_([a-zA-Z0-9]+)", r"<sub>\1</sub>", html_expression)
210
- html_expression = re.sub(r"\^([a-zA-Z0-9]+)", r"<sup>\1</sup>", html_expression)
211
- html_expression = html_expression.replace(" ", "&nbsp;")
212
- return html_expression
213
-
214
214
  if math_expression:
215
215
  label = QLabel(latex_to_html(text), parent)
216
216
  label.setTextFormat(Qt.TextFormat.RichText)
@@ -524,21 +524,107 @@ def create_combo_box(
524
524
  dropdown_selection_background_color = "#0078d7",
525
525
  dropdown_border_width = 1,
526
526
  dropdown_border_color = "#5c5c5c",
527
+ math_expression = False,
527
528
  parent = None
528
529
  ):
529
530
  combo_box = QComboBox(parent)
530
- combo_box.setPlaceholderText(f"{placeholder_text}")
531
- combo_box.addItems(items)
532
- combo_box.setCurrentIndex(-1)
533
-
531
+ combo_box.setAccessibleName("combo_box")
534
532
  padding_left_value = padding_left if padding_left is not None else padding
535
533
  padding_top_value = padding_top if padding_top is not None else padding
536
534
  padding_right_value = padding_right if padding_right is not None else padding
537
535
  padding_bottom_value = padding_bottom if padding_bottom is not None else padding
536
+ if math_expression:
537
+ placeholder_label = create_label(
538
+ text = placeholder_text,
539
+ font_family = font_family,
540
+ font_size = font_size,
541
+ font_color = placeholder_font_color,
542
+ padding = padding,
543
+ padding_left = padding_left,
544
+ padding_top = padding_top,
545
+ padding_right = padding_right,
546
+ padding_bottom = padding_bottom,
547
+ math_expression = True,
548
+ transparent_for_mouse = True,
549
+ parent = combo_box
550
+ )
551
+ placeholder_label.move(0, 2)
552
+
553
+ def update_placeholder_visibility():
554
+ has_selection = combo_box.currentIndex() != -1
555
+ placeholder_label.setVisible(not has_selection)
556
+
557
+ combo_box.currentIndexChanged.connect(update_placeholder_visibility)
558
+ update_placeholder_visibility()
559
+
560
+ class RichTextDelegate(QStyledItemDelegate):
561
+ def __init__(
562
+ self,
563
+ parent = None,
564
+ font_color = "#ffffff",
565
+ selection_font_color = "#ffffff"
566
+ ):
567
+ super().__init__(parent)
568
+ self.font_color = font_color
569
+ self.selection_font_color = selection_font_color
538
570
 
571
+ def paint(self, painter, option, index):
572
+ if option.state & QStyle.StateFlag.State_Selected: text_color = self.selection_font_color
573
+ else: text_color = self.font_color
574
+ document = QTextDocument()
575
+ html = f"<span style = \"color:{text_color};\">{index.data(Qt.ItemDataRole.DisplayRole)}</span>"
576
+ document.setHtml(html)
577
+ option.text = ""
578
+ QApplication.style().drawControl(QStyle.ControlElement.CE_ItemViewItem, option, painter)
579
+ painter.save()
580
+ painter.translate(option.rect.left(), option.rect.top() + (option.rect.height() - document.size().height()) / 2)
581
+ document.drawContents(painter)
582
+ painter.restore()
583
+
584
+ delegate = RichTextDelegate(
585
+ parent = combo_box,
586
+ font_color = dropdown_font_color,
587
+ selection_font_color = font_color
588
+ )
589
+ combo_box.setItemDelegate(delegate)
590
+ combo_box.clear()
591
+ for item in items: combo_box.addItem(latex_to_html(item))
592
+ combo_box.view().setTextElideMode(Qt.TextElideMode.ElideNone)
593
+ else:
594
+ combo_box.setPlaceholderText(placeholder_text)
595
+ combo_box.addItems(items)
596
+ combo_box.setCurrentIndex(-1)
597
+ if math_expression:
598
+ selected_item_label = create_label(
599
+ text = "",
600
+ font_family = font_family,
601
+ font_size = font_size,
602
+ font_color = font_color,
603
+ padding = padding,
604
+ padding_left = padding_left,
605
+ padding_top = padding_top,
606
+ padding_right = padding_right,
607
+ padding_bottom = padding_bottom,
608
+ math_expression = True,
609
+ transparent_for_mouse = True,
610
+ alignment = Qt.AlignmentFlag.AlignCenter,
611
+ parent = combo_box
612
+ )
613
+ selected_item_label.setVisible(False)
614
+
615
+ def update_selected_item_display(index):
616
+ if index != -1:
617
+ html_text = combo_box.itemText(index)
618
+ selected_item_label.setText(html_text)
619
+ selected_item_label.setVisible(True)
620
+ else:
621
+ selected_item_label.setVisible(False)
622
+
623
+ combo_box.currentIndexChanged.connect(update_selected_item_display)
624
+
539
625
  def get_stylesheet(font_color):
540
626
  return f"""
541
- QComboBox {{
627
+ QComboBox[accessibleName="combo_box"] {{
542
628
  font-family: {font_family};
543
629
  font-size: {font_size}px;
544
630
  color: {font_color};
@@ -550,12 +636,12 @@ def create_combo_box(
550
636
  border: {border_width}px solid {border_color};
551
637
  border-radius: {border_radius}px;
552
638
  }}
553
- QComboBox:hover {{
639
+ QComboBox[accessibleName="combo_box"]:hover {{
554
640
  background-color: {hover_background_color};
555
641
  border: {hover_border_width}px solid {hover_border_color};
556
642
  }}
557
- QComboBox:on {{
558
- color: {on_font_color};
643
+ QComboBox[accessibleName="combo_box"]:on {{
644
+ color: {"transparent" if math_expression else on_font_color};
559
645
  background-color: {on_background_color};
560
646
  border: {on_border_width}px solid {on_border_color};
561
647
  }}
@@ -571,8 +657,12 @@ def create_combo_box(
571
657
  """
572
658
 
573
659
  def change_color(index):
574
- if index == -1: combo_box.setStyleSheet(get_stylesheet(placeholder_font_color))
575
- else: combo_box.setStyleSheet(get_stylesheet(font_color))
660
+ if index == -1:
661
+ text_color = "transparent" if math_expression else placeholder_font_color
662
+ combo_box.setStyleSheet(get_stylesheet(text_color))
663
+ else:
664
+ text_color = "transparent" if math_expression else font_color
665
+ combo_box.setStyleSheet(get_stylesheet(text_color))
576
666
 
577
667
  combo_box.currentIndexChanged.connect(change_color)
578
668
  change_color(-1)
@@ -1152,6 +1242,12 @@ def validate_integer(integer, suffix = "El", field = "campo"):
1152
1242
  if pattern.match(unformatted_integer): return None
1153
1243
  return f"No ha ingresado {"un" if suffix == "El" else "una"} {field} {"válido" if suffix == "El" else "válida"}."
1154
1244
 
1245
+ def validate_float(decimal, suffix = "El", field = "campo"):
1246
+ if not decimal or not decimal.strip(): return f"{suffix} {field} no puede dejarse {"vacío" if suffix == "El" else "vacía"}."
1247
+ pattern = re.compile(r"^\d+(\.\d+)?$")
1248
+ if pattern.match(decimal): return None
1249
+ return f"No ha ingresado {"un" if suffix == "El" else "una"} {field} {"válido" if suffix == "El" else "válida"}."
1250
+
1155
1251
  def validate_id(id_str):
1156
1252
  if not id_str or not id_str.strip(): return "El D.N.I. no puede dejarse vacio."
1157
1253
  pattern = re.compile(r"^(?:\d{8}|(?:\d{1,2}\.\d{3}\.\d{3}))$")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gui_utilities
3
- Version: 1.3.44
3
+ Version: 1.4.1
4
4
  Summary: Librería de utilidades gráficas en PyQt6
5
5
  Author-email: Guido Iván Gross <grossguidoivan@gmail.com>
6
6
  Requires-Python: >=3.8
@@ -0,0 +1,11 @@
1
+ gui_utilities/gui_utilities.py,sha256=81Uak7qUrGbZf9zwiOHTSA-w7MrTdRoaz00aetUKI8o,52903
2
+ gui_utilities/icons/focused_hide_text_icon.png,sha256=0Ysx7vC-mEVfuSBWx1Zw-UhpqvrTCcIvnQ926wFmuK4,13084
3
+ gui_utilities/icons/focused_show_text_icon.png,sha256=gmZU7RR4FN-9VSzpD00ZkQ8UGbihO2y808Kh3b_TaEg,6739
4
+ gui_utilities/icons/hide_text_icon.png,sha256=f5jq6KaAygWNjzP_Ah6dw6eu8q5ml3m56JTeNSTSgEU,7207
5
+ gui_utilities/icons/show_text_icon.png,sha256=8Vdp2XickPEM-eTb1-qBXf3qmHldSzllMZZfObir9p8,5376
6
+ gui_utilities/tlds/tlds_list.txt,sha256=wIWmAQGVNsY0ZJy7qPW8kItDTCE4PTq8wcUhC2hpjkw,10916
7
+ gui_utilities-1.4.1.dist-info/licenses/LICENSE,sha256=NNoMFs43kWl1J-aqq7_EsPlBjL5XTccWjZlwrlCR-Xc,1093
8
+ gui_utilities-1.4.1.dist-info/METADATA,sha256=fIFVoTnI36Kc_pIweUPksAtZonBHBAslt_4jFQy1Qow,265
9
+ gui_utilities-1.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ gui_utilities-1.4.1.dist-info/top_level.txt,sha256=c4C84nMT41keiX9b1AJJZDBU3kA38c7vOmP9kDie8Lk,14
11
+ gui_utilities-1.4.1.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- gui_utilities/gui_utilities.py,sha256=ijyqaux_QlVJdi80H2B9xLyRjs_mOH9Pcxea1ulEQKs,48674
2
- gui_utilities/icons/focused_hide_text_icon.png,sha256=0Ysx7vC-mEVfuSBWx1Zw-UhpqvrTCcIvnQ926wFmuK4,13084
3
- gui_utilities/icons/focused_show_text_icon.png,sha256=gmZU7RR4FN-9VSzpD00ZkQ8UGbihO2y808Kh3b_TaEg,6739
4
- gui_utilities/icons/hide_text_icon.png,sha256=f5jq6KaAygWNjzP_Ah6dw6eu8q5ml3m56JTeNSTSgEU,7207
5
- gui_utilities/icons/show_text_icon.png,sha256=8Vdp2XickPEM-eTb1-qBXf3qmHldSzllMZZfObir9p8,5376
6
- gui_utilities/tlds/tlds_list.txt,sha256=wIWmAQGVNsY0ZJy7qPW8kItDTCE4PTq8wcUhC2hpjkw,10916
7
- gui_utilities-1.3.44.dist-info/licenses/LICENSE,sha256=NNoMFs43kWl1J-aqq7_EsPlBjL5XTccWjZlwrlCR-Xc,1093
8
- gui_utilities-1.3.44.dist-info/METADATA,sha256=SbDw7yIbotPVveUWeugigOLO5Rbj-703ZDaEUGSVox0,266
9
- gui_utilities-1.3.44.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- gui_utilities-1.3.44.dist-info/top_level.txt,sha256=c4C84nMT41keiX9b1AJJZDBU3kA38c7vOmP9kDie8Lk,14
11
- gui_utilities-1.3.44.dist-info/RECORD,,