gui-utilities 1.3.27__py3-none-any.whl → 1.3.44__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.
@@ -9,8 +9,8 @@ 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 create_window(title, background_color = "#1e1e1e"):
13
- window = QWidget()
12
+ def create_window(title, background_color = "#1e1e1e", parent = None):
13
+ window = QWidget(parent)
14
14
  window.setObjectName("window")
15
15
  window.setWindowTitle(title)
16
16
  window.setStyleSheet(f"#window {{background-color: {background_color};}}")
@@ -33,7 +33,9 @@ def create_menu(
33
33
  title_padding_bottom = None,
34
34
  title_border_width = 0,
35
35
  title_border_color = "#ffffff",
36
- title_border_radius = 0
36
+ title_border_radius = 0,
37
+ math_expression = False,
38
+ title_alignment = Qt.AlignmentFlag.AlignCenter
37
39
  ):
38
40
  main_layout = QVBoxLayout()
39
41
  main_layout.setContentsMargins(25, 25, 25, 25)
@@ -50,7 +52,9 @@ def create_menu(
50
52
  padding_bottom = title_padding_bottom,
51
53
  border_width = title_border_width,
52
54
  border_color = title_border_color,
53
- border_radius = title_border_radius
55
+ border_radius = title_border_radius,
56
+ math_expression = math_expression,
57
+ alignment = title_alignment
54
58
  ))
55
59
  body_layout = QHBoxLayout()
56
60
  main_layout.addLayout(body_layout)
@@ -102,7 +106,9 @@ def create_header(
102
106
  title_padding_bottom = None,
103
107
  title_border_width = 0,
104
108
  title_border_color = "#ffffff",
105
- title_border_radius = 0
109
+ title_border_radius = 0,
110
+ math_expression = False,
111
+ title_alignment = Qt.AlignmentFlag.AlignCenter
106
112
  ):
107
113
  main_layout = QVBoxLayout()
108
114
  main_layout.setContentsMargins(margin_left, margin_top, margin_right, margin_bottom)
@@ -119,7 +125,9 @@ def create_header(
119
125
  padding_bottom = title_padding_bottom,
120
126
  border_width = title_border_width,
121
127
  border_color = title_border_color,
122
- border_radius = title_border_radius
128
+ border_radius = title_border_radius,
129
+ math_expression = math_expression,
130
+ alignment = title_alignment
123
131
  )
124
132
  main_layout.addLayout(title_layout)
125
133
  main_layout.addStretch()
@@ -138,11 +146,12 @@ def create_title(
138
146
  padding_bottom = None,
139
147
  border_width = 0,
140
148
  border_color = "#ffffff",
141
- border_radius = 0
149
+ border_radius = 0,
150
+ math_expression = False,
151
+ alignment = Qt.AlignmentFlag.AlignCenter
142
152
  ):
143
153
  title_layout = QHBoxLayout()
144
154
  title_layout.setContentsMargins(0, 0, 0, 25)
145
- title_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
146
155
  title_label = create_label(
147
156
  text = text,
148
157
  font_family = font_family,
@@ -157,7 +166,9 @@ def create_title(
157
166
  padding_bottom = padding_bottom,
158
167
  border_width = border_width,
159
168
  border_color = border_color,
160
- border_radius = border_radius
169
+ border_radius = border_radius,
170
+ math_expression = math_expression,
171
+ alignment = alignment
161
172
  )
162
173
  title_layout.addWidget(title_label)
163
174
  return title_layout
@@ -183,9 +194,30 @@ def create_label(
183
194
  disabled_font_color = "#888888",
184
195
  disabled_background_color = "transparent",
185
196
  disabled_border_width = 0,
186
- disabled_border_color = "#4a4a4a"
197
+ disabled_border_color = "#4a4a4a",
198
+ math_expression = False,
199
+ transparent_for_mouse = False,
200
+ alignment = None,
201
+ word_wrap = False,
202
+ parent = None
187
203
  ):
188
- label = QLabel(text)
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
+ if math_expression:
215
+ label = QLabel(latex_to_html(text), parent)
216
+ label.setTextFormat(Qt.TextFormat.RichText)
217
+ else: label = QLabel(text, parent)
218
+ if transparent_for_mouse: label.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents, True)
219
+ if alignment: label.setAlignment(alignment)
220
+ if word_wrap: label.setWordWrap(True)
189
221
  padding_left_value = padding_left if padding_left is not None else padding
190
222
  padding_top_value = padding_top if padding_top is not None else padding
191
223
  padding_right_value = padding_right if padding_right is not None else padding
@@ -242,10 +274,12 @@ def create_button(
242
274
  disabled_background_color = "#2d2d2d",
243
275
  disabled_border_width = 2,
244
276
  disabled_border_color = "#4a4a4a",
245
- maximum_width = 360
277
+ maximum_width = 360,
278
+ math_expression = False,
279
+ parent = None
246
280
  ):
247
- button = QPushButton()
248
- button.setMaximumWidth(maximum_width)
281
+ button = QPushButton(parent)
282
+ if maximum_width is not None: button.setMaximumWidth(maximum_width)
249
283
  main_layout = QVBoxLayout()
250
284
  button.setLayout(main_layout)
251
285
  main_layout.setContentsMargins(0, 0, 0, 0)
@@ -259,9 +293,11 @@ def create_button(
259
293
  padding_top = padding_top,
260
294
  padding_right = padding_right,
261
295
  padding_bottom = padding_bottom,
262
- disabled_border_width = disabled_border_width
296
+ disabled_border_width = disabled_border_width,
297
+ transparent_for_mouse = True,
298
+ alignment = Qt.AlignmentFlag.AlignCenter,
299
+ math_expression = math_expression
263
300
  )
264
- label.setAlignment(Qt.AlignmentFlag.AlignCenter)
265
301
  label.setWordWrap(True)
266
302
  main_layout.addWidget(label)
267
303
  button.setFixedHeight(main_layout.sizeHint().height() + 2 * border_width)
@@ -315,6 +351,7 @@ def create_text_box(
315
351
  border_width = 2,
316
352
  border_color = "#5c5c5c",
317
353
  border_radius = 0,
354
+ placeholder_font_color = "#888888",
318
355
  hover_background_color = "#333333",
319
356
  hover_border_width = 3,
320
357
  hover_border_color = "#777777",
@@ -330,9 +367,10 @@ def create_text_box(
330
367
  focused_show_text_icon_url = str(icons_dir / "focused_show_text_icon.png"),
331
368
  focused_hide_text_icon_url = str(icons_dir / "focused_hide_text_icon.png"),
332
369
  hide_text = False,
333
- math_expression = False
370
+ math_expression = False,
371
+ parent = None
334
372
  ):
335
- text_box = QLineEdit()
373
+ text_box = QLineEdit(parent)
336
374
  padding_left_value = padding_left if padding_left is not None else padding
337
375
  padding_top_value = padding_top if padding_top is not None else padding
338
376
  padding_right_value = padding_right if padding_right is not None else padding
@@ -366,30 +404,6 @@ def create_text_box(
366
404
  }}
367
405
  """
368
406
  text_box.setStyleSheet(style_sheet)
369
-
370
- def latex_to_html(expression):
371
- html_expression = expression
372
- html_expression = re.sub(r"\\frac\{(.*?)\}\{(.*?)\}", r"<span style='font-size:90%;'>\1⁄\2</span>", html_expression)
373
- html_expression = re.sub(r"([a-zA-Z])_(\d+)", r"\1<sub>\2</sub>", html_expression)
374
- html_expression = re.sub(r"([a-zA-Z0-9])\^(\d+)", r"\1<sup>\2</sup>", html_expression)
375
- html_expression = html_expression.replace(" ", "&nbsp;")
376
- return html_expression
377
-
378
- if not math_expression: text_box.setPlaceholderText(placeholder_text)
379
- else:
380
- html_placeholder = latex_to_html(placeholder_text)
381
- placeholder_label = QLabel(text_box)
382
- placeholder_label.setTextFormat(Qt.TextFormat.RichText)
383
- placeholder_label.setText(f"<span style = \"color: {font_color}; font-family: {font_family}; font-size: {font_size}px;\">{html_placeholder}</span>")
384
- placeholder_label.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents)
385
- placeholder_label.move(padding_left_value + 2, padding_top_value + 2)
386
- placeholder_label.show()
387
-
388
- def update_placeholder_visibility():
389
- placeholder_label.setVisible(text_box.text() == "")
390
-
391
- text_box.textChanged.connect(update_placeholder_visibility)
392
- update_placeholder_visibility()
393
407
  if hide_text:
394
408
  show_text_icon = QIcon(show_text_icon_url)
395
409
  hide_text_icon = QIcon(hide_text_icon_url)
@@ -403,38 +417,83 @@ def create_text_box(
403
417
  toggle_text_visibility_button.setIconSize(QSize(25, 25))
404
418
  toggle_text_visibility_action = QWidgetAction(text_box)
405
419
  toggle_text_visibility_action.setDefaultWidget(toggle_text_visibility_button)
406
- style_sheet = f"""
407
- QToolButton {{
420
+ text_box.addAction(toggle_text_visibility_action, QLineEdit.ActionPosition.TrailingPosition)
421
+ toggle_text_visibility_button.setStyleSheet("""
422
+ QToolButton {
408
423
  background-color: transparent;
409
424
  border: none;
410
425
  margin-right: 10px;
411
- }}
412
- """
413
- toggle_text_visibility_button.setStyleSheet(style_sheet)
414
- text_box.addAction(toggle_text_visibility_action, QLineEdit.ActionPosition.TrailingPosition)
415
-
426
+ }
427
+ """)
428
+
416
429
  def update_icon():
417
430
  is_password = text_box.echoMode() == QLineEdit.EchoMode.Password
418
431
  if text_box.hasFocus(): icon = focused_hide_text_icon if is_password else focused_show_text_icon
419
432
  else: icon = hide_text_icon if is_password else show_text_icon
420
433
  toggle_text_visibility_button.setIcon(icon)
421
-
434
+
422
435
  def toggle_visibility():
423
436
  if text_box.echoMode() == QLineEdit.EchoMode.Password: text_box.setEchoMode(QLineEdit.EchoMode.Normal)
424
437
  else: text_box.setEchoMode(QLineEdit.EchoMode.Password)
425
438
  update_icon()
426
-
439
+
427
440
  toggle_text_visibility_button.clicked.connect(toggle_visibility)
428
441
 
429
- class FocusWatcher(QObject):
442
+ class _IconFocusWatcher(QObject):
443
+
444
+ def __init__(self, watched, on_focus_change):
445
+ super().__init__(watched)
446
+ self._watched = watched
447
+ self._on_focus_change = on_focus_change
448
+
430
449
  def eventFilter(self, watched, event):
431
- if event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut): update_icon()
450
+ if watched is self._watched and event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut):
451
+ if callable(self._on_focus_change): self._on_focus_change()
432
452
  return super().eventFilter(watched, event)
453
+
454
+ icon_focus_watcher = _IconFocusWatcher(text_box, update_icon)
455
+ text_box.installEventFilter(icon_focus_watcher)
456
+ setattr(text_box, "_icon_focus_watcher", icon_focus_watcher)
457
+
458
+ placeholder_label = create_label(
459
+ text = placeholder_text,
460
+ font_family = font_family,
461
+ font_size = font_size,
462
+ font_color = placeholder_font_color,
463
+ font_weight = font_weight,
464
+ padding = padding,
465
+ padding_left = padding_left,
466
+ padding_top = padding_top,
467
+ padding_right = padding_right,
468
+ padding_bottom = padding_bottom,
469
+ math_expression = math_expression,
470
+ transparent_for_mouse = True,
471
+ parent = text_box
472
+ )
473
+ placeholder_label.move(0, 2)
474
+
475
+ def update_placeholder_visibility():
476
+ has_text = bool(text_box.text().strip())
477
+ has_focus = text_box.hasFocus()
478
+ placeholder_label.setVisible(not has_text and not has_focus)
479
+ if hide_text: update_icon()
480
+
481
+ class _PlaceholderFocusWatcher(QObject):
433
482
 
434
- focus_watcher = FocusWatcher(text_box)
435
- text_box.installEventFilter(focus_watcher)
436
- setattr(text_box, "focus_watcher", focus_watcher)
437
- update_icon()
483
+ def __init__(self, watched, on_focus_change):
484
+ super().__init__(watched)
485
+ self._watched = watched
486
+ self._on_focus_change = on_focus_change
487
+
488
+ def eventFilter(self, watched, event):
489
+ if watched is self._watched and event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut):
490
+ if callable(self._on_focus_change): self._on_focus_change()
491
+ return super().eventFilter(watched, event)
492
+
493
+ placeholder_focus_watcher = _PlaceholderFocusWatcher(text_box, update_placeholder_visibility)
494
+ text_box.installEventFilter(placeholder_focus_watcher)
495
+ setattr(text_box, "_placeholder_focus_watcher", placeholder_focus_watcher)
496
+ update_placeholder_visibility()
438
497
  return text_box
439
498
 
440
499
  def create_combo_box(
@@ -464,9 +523,10 @@ def create_combo_box(
464
523
  dropdown_background_color = "#1e1e1e",
465
524
  dropdown_selection_background_color = "#0078d7",
466
525
  dropdown_border_width = 1,
467
- dropdown_border_color = "#5c5c5c"
526
+ dropdown_border_color = "#5c5c5c",
527
+ parent = None
468
528
  ):
469
- combo_box = QComboBox()
529
+ combo_box = QComboBox(parent)
470
530
  combo_box.setPlaceholderText(f"{placeholder_text}")
471
531
  combo_box.addItems(items)
472
532
  combo_box.setCurrentIndex(-1)
@@ -545,9 +605,10 @@ def create_checkbox(
545
605
  disabled_font_color = "#888888",
546
606
  disabled_background_color = "#2d2d2d",
547
607
  disabled_border_width = 1,
548
- disabled_border_color = "#4a4a4a"
608
+ disabled_border_color = "#4a4a4a",
609
+ parent = None
549
610
  ):
550
- check_box = QCheckBox(text)
611
+ check_box = QCheckBox(text, parent)
551
612
  padding_left_value = padding_left if padding_left is not None else padding
552
613
  padding_top_value = padding_top if padding_top is not None else padding
553
614
  padding_right_value = padding_right if padding_right is not None else padding
@@ -638,9 +699,10 @@ def create_information_message_box(
638
699
  button_disabled_font_color = "#888888",
639
700
  button_disabled_background_color = "#2d2d2d",
640
701
  button_disabled_border_width = 2,
641
- button_disabled_border_color = "#4a4a4a"
702
+ button_disabled_border_color = "#4a4a4a",
703
+ parent = None
642
704
  ):
643
- message_box = QDialog()
705
+ message_box = QDialog(parent)
644
706
  message_box.setObjectName("message_box")
645
707
  message_box.setWindowFlags(Qt.WindowType.FramelessWindowHint)
646
708
  message_box.setFixedWidth(360)
@@ -669,10 +731,10 @@ def create_information_message_box(
669
731
  padding_bottom = label_padding_bottom,
670
732
  border_width = label_border_width,
671
733
  border_color = label_border_color,
672
- border_radius = label_border_radius
734
+ border_radius = label_border_radius,
735
+ alignment = Qt.AlignmentFlag.AlignCenter
673
736
  )
674
737
  main_layout.addWidget(text_label)
675
- text_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
676
738
  text_label.setWordWrap(True)
677
739
  accept_button = create_button(
678
740
  text = button_text,
@@ -747,9 +809,10 @@ def create_confirmation_message_box(
747
809
  button_disabled_font_color = "#888888",
748
810
  button_disabled_background_color = "#2d2d2d",
749
811
  button_disabled_border_width = 2,
750
- button_disabled_border_color = "#4a4a4a"
812
+ button_disabled_border_color = "#4a4a4a",
813
+ parent = None
751
814
  ):
752
- confirm_message_box = QDialog()
815
+ confirm_message_box = QDialog(parent)
753
816
  confirm_message_box.setObjectName("confirm_message_box")
754
817
  confirm_message_box.setWindowFlags(Qt.WindowType.FramelessWindowHint)
755
818
  confirm_message_box.setFixedWidth(360)
@@ -778,10 +841,10 @@ def create_confirmation_message_box(
778
841
  padding_bottom = label_padding_bottom,
779
842
  border_width = label_border_width,
780
843
  border_color = label_border_color,
781
- border_radius = label_border_radius
844
+ border_radius = label_border_radius,
845
+ alignment = Qt.AlignmentFlag.AlignCenter
782
846
  )
783
847
  main_layout.addWidget(text_label)
784
- text_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
785
848
  text_label.setWordWrap(True)
786
849
  buttons_layout = QHBoxLayout()
787
850
  main_layout.addLayout(buttons_layout)
@@ -876,9 +939,10 @@ def create_list_table(
876
939
  hover_scrollbar_handle_border_color = "#777777",
877
940
  pressed_scrollbar_handle_background_color = "#4a4a4a",
878
941
  pressed_scrollbar_handle_border_width = 3,
879
- pressed_scrollbar_handle_border_color = "#0078d7"
942
+ pressed_scrollbar_handle_border_color = "#0078d7",
943
+ parent = None
880
944
  ):
881
- list_table = QTableWidget()
945
+ list_table = QTableWidget(parent)
882
946
  list_table.verticalHeader().setVisible(False)
883
947
  list_table.setColumnCount(len(column_headers))
884
948
  list_table.setHorizontalHeaderLabels(column_headers)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gui_utilities
3
- Version: 1.3.27
3
+ Version: 1.3.44
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
@@ -1,11 +1,11 @@
1
- gui_utilities/gui_utilities.py,sha256=dy0LllUZ5mC09HdhMfTzvj1kzNBeztyJPNNUsu_6H0c,46185
1
+ gui_utilities/gui_utilities.py,sha256=ijyqaux_QlVJdi80H2B9xLyRjs_mOH9Pcxea1ulEQKs,48674
2
2
  gui_utilities/icons/focused_hide_text_icon.png,sha256=0Ysx7vC-mEVfuSBWx1Zw-UhpqvrTCcIvnQ926wFmuK4,13084
3
3
  gui_utilities/icons/focused_show_text_icon.png,sha256=gmZU7RR4FN-9VSzpD00ZkQ8UGbihO2y808Kh3b_TaEg,6739
4
4
  gui_utilities/icons/hide_text_icon.png,sha256=f5jq6KaAygWNjzP_Ah6dw6eu8q5ml3m56JTeNSTSgEU,7207
5
5
  gui_utilities/icons/show_text_icon.png,sha256=8Vdp2XickPEM-eTb1-qBXf3qmHldSzllMZZfObir9p8,5376
6
6
  gui_utilities/tlds/tlds_list.txt,sha256=wIWmAQGVNsY0ZJy7qPW8kItDTCE4PTq8wcUhC2hpjkw,10916
7
- gui_utilities-1.3.27.dist-info/licenses/LICENSE,sha256=NNoMFs43kWl1J-aqq7_EsPlBjL5XTccWjZlwrlCR-Xc,1093
8
- gui_utilities-1.3.27.dist-info/METADATA,sha256=168zHVeB2toYacokpwO1kmBFZalHF3vxp5CQtGdmNIo,266
9
- gui_utilities-1.3.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- gui_utilities-1.3.27.dist-info/top_level.txt,sha256=c4C84nMT41keiX9b1AJJZDBU3kA38c7vOmP9kDie8Lk,14
11
- gui_utilities-1.3.27.dist-info/RECORD,,
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,,