gui-utilities 1.3.4__tar.gz → 1.3.40__tar.gz

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
  Metadata-Version: 2.4
2
2
  Name: gui_utilities
3
- Version: 1.3.4
3
+ Version: 1.3.40
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,6 +1,6 @@
1
1
  from PyQt6.QtCore import Qt, QObject, QEvent, QSize
2
2
  from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QLineEdit, QComboBox, QDialog, QToolButton, QWidgetAction, QCheckBox, QTableWidget, QHeaderView
3
- from PyQt6.QtGui import QIcon, QFont, QFontMetrics
3
+ from PyQt6.QtGui import QIcon
4
4
  import re
5
5
  import requests
6
6
  import importlib.resources
@@ -18,7 +18,7 @@ def create_window(title, background_color = "#1e1e1e"):
18
18
  window.setLayout(main_layout)
19
19
  return window
20
20
 
21
- def create_form(
21
+ def create_menu(
22
22
  ui_instance,
23
23
  buttons,
24
24
  title,
@@ -130,7 +130,7 @@ def create_title(
130
130
  font_family = "Segoe UI",
131
131
  font_size = 36,
132
132
  font_color = "#ffffff",
133
- background_color = "#1e1e1e",
133
+ background_color = "transparent",
134
134
  padding = 15,
135
135
  padding_left = None,
136
136
  padding_top = None,
@@ -168,33 +168,52 @@ def create_label(
168
168
  font_size = 14,
169
169
  font_color = "#ffffff",
170
170
  font_weight = "normal",
171
- background_color = "#1e1e1e",
171
+ background_color = "transparent",
172
172
  padding = 15,
173
173
  padding_left = None,
174
174
  padding_top = None,
175
175
  padding_right = None,
176
176
  padding_bottom = None,
177
177
  border_width = 0,
178
- border_color = "#ffffff",
179
- border_radius = 0
178
+ border_color = "#5c5c5c",
179
+ border_radius = 0,
180
+ hover_background_color = "transparent",
181
+ hover_border_width = 0,
182
+ hover_border_color = "#777777",
183
+ disabled_font_color = "#888888",
184
+ disabled_background_color = "transparent",
185
+ disabled_border_width = 0,
186
+ disabled_border_color = "#4a4a4a",
187
+ parent = None
180
188
  ):
181
- label = QLabel(text)
189
+ label = QLabel(text, parent)
182
190
  padding_left_value = padding_left if padding_left is not None else padding
183
191
  padding_top_value = padding_top if padding_top is not None else padding
184
192
  padding_right_value = padding_right if padding_right is not None else padding
185
193
  padding_bottom_value = padding_bottom if padding_bottom is not None else padding
186
194
  style = f"""
187
- font-family: {font_family};
188
- font-size: {font_size}px;
189
- color: {font_color};
190
- font-weight: {font_weight};
191
- background-color: {background_color};
192
- padding-left: {padding_left_value}px;
193
- padding-top: {padding_top_value}px;
194
- padding-right: {padding_right_value}px;
195
- padding-bottom: {padding_bottom_value}px;
196
- border: {border_width}px solid {border_color};
197
- border-radius: {border_radius}px;
195
+ QLabel {{
196
+ font-family: {font_family};
197
+ font-size: {font_size}px;
198
+ color: {font_color};
199
+ font-weight: {font_weight};
200
+ background-color: {background_color};
201
+ padding-left: {padding_left_value}px;
202
+ padding-top: {padding_top_value}px;
203
+ padding-right: {padding_right_value}px;
204
+ padding-bottom: {padding_bottom_value}px;
205
+ border: {border_width}px solid {border_color};
206
+ border-radius: {border_radius}px;
207
+ }}
208
+ QLabel:hover{{
209
+ background-color: {hover_background_color};
210
+ border: {hover_border_width}px solid {hover_border_color};
211
+ }}
212
+ QLabel:disabled{{
213
+ color: {disabled_font_color};
214
+ background-color: {disabled_background_color};
215
+ border: {disabled_border_width}px solid {disabled_border_color};
216
+ }}
198
217
  """
199
218
  label.setStyleSheet(style)
200
219
  return label
@@ -223,24 +242,34 @@ def create_button(
223
242
  disabled_font_color = "#888888",
224
243
  disabled_background_color = "#2d2d2d",
225
244
  disabled_border_width = 2,
226
- disabled_border_color = "#4a4a4a"
245
+ disabled_border_color = "#4a4a4a",
246
+ maximum_width = 360
227
247
  ):
228
248
  button = QPushButton()
229
- button.setMaximumWidth(360)
249
+ button.setMaximumWidth(maximum_width)
250
+ main_layout = QVBoxLayout()
251
+ button.setLayout(main_layout)
252
+ main_layout.setContentsMargins(0, 0, 0, 0)
253
+ label = create_label(
254
+ text = text,
255
+ font_size = font_size,
256
+ font_color = font_color,
257
+ font_weight = "bold",
258
+ padding = padding,
259
+ padding_left = padding_left,
260
+ padding_top = padding_top,
261
+ padding_right = padding_right,
262
+ padding_bottom = padding_bottom,
263
+ disabled_border_width = disabled_border_width
264
+ )
265
+ label.setAlignment(Qt.AlignmentFlag.AlignCenter)
266
+ label.setWordWrap(True)
267
+ main_layout.addWidget(label)
268
+ button.setFixedHeight(main_layout.sizeHint().height() + 2 * border_width)
230
269
  padding_left_value = padding_left if padding_left is not None else padding
231
270
  padding_top_value = padding_top if padding_top is not None else padding
232
271
  padding_right_value = padding_right if padding_right is not None else padding
233
272
  padding_bottom_value = padding_bottom if padding_bottom is not None else padding
234
- max_text_width = 360 - padding_left_value - padding_right_value - 2 * border_width
235
- font = QFont(font_family, font_size)
236
- if font_weight == "bold": font.setWeight(QFont.Weight.Bold)
237
- else: font.setWeight(QFont.Weight.Normal)
238
- metrics = QFontMetrics(font)
239
- text_width = metrics.horizontalAdvance(text)
240
- if text_width > max_text_width:
241
- html_text = f"<html><div style = \"white-space: normal; text-align: center;\">{text}</div><html>"
242
- button.setText(html_text)
243
- else: button.setText(text)
244
273
  style_sheet = f"""
245
274
  QPushButton {{
246
275
  font-family: {font_family};
@@ -287,6 +316,7 @@ def create_text_box(
287
316
  border_width = 2,
288
317
  border_color = "#5c5c5c",
289
318
  border_radius = 0,
319
+ placeholder_font_color = "#888888",
290
320
  hover_background_color = "#333333",
291
321
  hover_border_width = 3,
292
322
  hover_border_color = "#777777",
@@ -301,10 +331,10 @@ def create_text_box(
301
331
  hide_text_icon_url = str(icons_dir / "hide_text_icon.png"),
302
332
  focused_show_text_icon_url = str(icons_dir / "focused_show_text_icon.png"),
303
333
  focused_hide_text_icon_url = str(icons_dir / "focused_hide_text_icon.png"),
304
- hide_text = False
334
+ hide_text = False,
335
+ math_expression = False
305
336
  ):
306
337
  text_box = QLineEdit()
307
- text_box.setPlaceholderText(placeholder_text)
308
338
  padding_left_value = padding_left if padding_left is not None else padding
309
339
  padding_top_value = padding_top if padding_top is not None else padding
310
340
  padding_right_value = padding_right if padding_right is not None else padding
@@ -338,6 +368,53 @@ def create_text_box(
338
368
  }}
339
369
  """
340
370
  text_box.setStyleSheet(style_sheet)
371
+
372
+ def latex_to_html(expression):
373
+ html_expression = expression
374
+ html_expression = re.sub(r"\\frac\{(.*?)\}\{(.*?)\}", r"<span style='font-size:90%;'>\1⁄\2</span>", html_expression)
375
+ html_expression = re.sub(r"([a-zA-Z])_(\d+)", r"\1<sub>\2</sub>", html_expression)
376
+ html_expression = re.sub(r"([a-zA-Z0-9])\^(\d+)", r"\1<sup>\2</sup>", html_expression)
377
+ html_expression = html_expression.replace(" ", "&nbsp;")
378
+ return html_expression
379
+
380
+ if not math_expression: text_box.setPlaceholderText(placeholder_text)
381
+ else:
382
+ html_placeholder = latex_to_html(placeholder_text)
383
+ placeholder_label = create_label(
384
+ text = html_placeholder,
385
+ font_color = placeholder_font_color,
386
+ font_family = font_family,
387
+ font_size = font_size,
388
+ background_color = "transparent",
389
+ disabled_background_color = "transparent",
390
+ parent = text_box
391
+ )
392
+ placeholder_label.setTextFormat(Qt.TextFormat.RichText)
393
+ placeholder_label.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents, True)
394
+ placeholder_label.move(0, -2)
395
+ placeholder_label.show()
396
+
397
+ class _PlaceholderFocusWatcher(QObject):
398
+
399
+ def __init__(self, watched, placeholder_label):
400
+ super().__init__(watched)
401
+ self._watched = watched
402
+ self._placeholder = placeholder_label
403
+
404
+ def eventFilter(self, watched, event):
405
+ if watched is self._watched and event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut):
406
+ self._placeholder.setVisible((self._watched.text() == "") and (not self._watched.hasFocus()))
407
+ return super().eventFilter(watched, event)
408
+
409
+ def _update_placeholder_visibility():
410
+ if placeholder_label is not None:
411
+ placeholder_label.setVisible(text_box.text() == "" and not text_box.hasFocus())
412
+
413
+ text_box.textChanged.connect(_update_placeholder_visibility)
414
+ focus_watcher_placeholder = _PlaceholderFocusWatcher(text_box, placeholder_label)
415
+ text_box.installEventFilter(focus_watcher_placeholder)
416
+ setattr(text_box, "_placeholder_focus_watcher", focus_watcher_placeholder)
417
+ _update_placeholder_visibility()
341
418
  if hide_text:
342
419
  show_text_icon = QIcon(show_text_icon_url)
343
420
  hide_text_icon = QIcon(hide_text_icon_url)
@@ -351,37 +428,43 @@ def create_text_box(
351
428
  toggle_text_visibility_button.setIconSize(QSize(25, 25))
352
429
  toggle_text_visibility_action = QWidgetAction(text_box)
353
430
  toggle_text_visibility_action.setDefaultWidget(toggle_text_visibility_button)
354
- style_sheet = f"""
355
- QToolButton {{
431
+ text_box.addAction(toggle_text_visibility_action, QLineEdit.ActionPosition.TrailingPosition)
432
+ toggle_text_visibility_button.setStyleSheet("""
433
+ QToolButton {
356
434
  background-color: transparent;
357
435
  border: none;
358
436
  margin-right: 10px;
359
- }}
360
- """
361
- toggle_text_visibility_button.setStyleSheet(style_sheet)
362
- text_box.addAction(toggle_text_visibility_action, QLineEdit.ActionPosition.TrailingPosition)
437
+ }
438
+ """)
363
439
 
364
440
  def update_icon():
365
441
  is_password = text_box.echoMode() == QLineEdit.EchoMode.Password
366
442
  if text_box.hasFocus(): icon = focused_hide_text_icon if is_password else focused_show_text_icon
367
443
  else: icon = hide_text_icon if is_password else show_text_icon
368
444
  toggle_text_visibility_button.setIcon(icon)
369
-
445
+
370
446
  def toggle_visibility():
371
447
  if text_box.echoMode() == QLineEdit.EchoMode.Password: text_box.setEchoMode(QLineEdit.EchoMode.Normal)
372
448
  else: text_box.setEchoMode(QLineEdit.EchoMode.Password)
373
449
  update_icon()
374
-
450
+
375
451
  toggle_text_visibility_button.clicked.connect(toggle_visibility)
376
452
 
377
- class FocusWatcher(QObject):
453
+ class _IconFocusWatcher(QObject):
454
+
455
+ def __init__(self, watched, on_focus_change):
456
+ super().__init__(watched)
457
+ self._watched = watched
458
+ self._on_focus_change = on_focus_change
459
+
378
460
  def eventFilter(self, watched, event):
379
- if event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut): update_icon()
461
+ if watched is self._watched and event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut):
462
+ if callable(self._on_focus_change): self._on_focus_change()
380
463
  return super().eventFilter(watched, event)
381
-
382
- focus_watcher = FocusWatcher(text_box)
383
- text_box.installEventFilter(focus_watcher)
384
- setattr(text_box, "focus_watcher", focus_watcher)
464
+
465
+ icon_focus_watcher = _IconFocusWatcher(text_box, update_icon)
466
+ text_box.installEventFilter(icon_focus_watcher)
467
+ setattr(text_box, "_icon_focus_watcher", icon_focus_watcher)
385
468
  update_icon()
386
469
  return text_box
387
470
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gui_utilities
3
- Version: 1.3.4
3
+ Version: 1.3.40
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,6 +1,6 @@
1
1
  [project]
2
2
  name = "gui_utilities"
3
- version = "1.3.4"
3
+ version = "1.3.40"
4
4
  description = "Librería de utilidades gráficas en PyQt6"
5
5
  authors = [{name = "Guido Iván Gross", email = "grossguidoivan@gmail.com"}]
6
6
  requires-python = ">=3.8"
File without changes
File without changes
File without changes