gui-utilities 1.3.4__tar.gz → 1.3.37__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.37
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,36 @@ 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
+ hover_background_color = "transparent",
390
+ disabled_background_color = "transparent",
391
+ parent = text_box
392
+ )
393
+ placeholder_label.setTextFormat(Qt.TextFormat.RichText)
394
+ placeholder_label.show()
395
+
396
+ def update_placeholder_visibility():
397
+ placeholder_label.setVisible(text_box.text() == "")
398
+
399
+ text_box.textChanged.connect(update_placeholder_visibility)
400
+ update_placeholder_visibility()
341
401
  if hide_text:
342
402
  show_text_icon = QIcon(show_text_icon_url)
343
403
  hide_text_icon = QIcon(hide_text_icon_url)
@@ -351,14 +411,13 @@ def create_text_box(
351
411
  toggle_text_visibility_button.setIconSize(QSize(25, 25))
352
412
  toggle_text_visibility_action = QWidgetAction(text_box)
353
413
  toggle_text_visibility_action.setDefaultWidget(toggle_text_visibility_button)
354
- style_sheet = f"""
355
- QToolButton {{
414
+ toggle_text_visibility_button.setStyleSheet("""
415
+ QToolButton {
356
416
  background-color: transparent;
357
417
  border: none;
358
418
  margin-right: 10px;
359
- }}
360
- """
361
- toggle_text_visibility_button.setStyleSheet(style_sheet)
419
+ }
420
+ """)
362
421
  text_box.addAction(toggle_text_visibility_action, QLineEdit.ActionPosition.TrailingPosition)
363
422
 
364
423
  def update_icon():
@@ -366,20 +425,21 @@ def create_text_box(
366
425
  if text_box.hasFocus(): icon = focused_hide_text_icon if is_password else focused_show_text_icon
367
426
  else: icon = hide_text_icon if is_password else show_text_icon
368
427
  toggle_text_visibility_button.setIcon(icon)
369
-
428
+
370
429
  def toggle_visibility():
371
430
  if text_box.echoMode() == QLineEdit.EchoMode.Password: text_box.setEchoMode(QLineEdit.EchoMode.Normal)
372
431
  else: text_box.setEchoMode(QLineEdit.EchoMode.Password)
373
432
  update_icon()
374
-
433
+
375
434
  toggle_text_visibility_button.clicked.connect(toggle_visibility)
376
435
 
377
436
  class FocusWatcher(QObject):
437
+
378
438
  def eventFilter(self, watched, event):
379
439
  if event.type() in (QEvent.Type.FocusIn, QEvent.Type.FocusOut): update_icon()
380
440
  return super().eventFilter(watched, event)
381
-
382
- focus_watcher = FocusWatcher(text_box)
441
+
442
+ focus_watcher = FocusWatcher(text_box, on_focus_change=update_icon)
383
443
  text_box.installEventFilter(focus_watcher)
384
444
  setattr(text_box, "focus_watcher", focus_watcher)
385
445
  update_icon()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gui_utilities
3
- Version: 1.3.4
3
+ Version: 1.3.37
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.37"
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