From 84af675514eee93528708728925dd8bee3261371 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 May 2026 20:23:12 +0000 Subject: [PATCH] Upload files to "ui" --- ui/editor.py | 60 ++++++++++++++++++++++++++++++++++++++++ ui/styles.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 ui/editor.py create mode 100644 ui/styles.py diff --git a/ui/editor.py b/ui/editor.py new file mode 100644 index 0000000..90cd252 --- /dev/null +++ b/ui/editor.py @@ -0,0 +1,60 @@ +# v3.0.0 editor.py +import re +import webbrowser + +from PyQt6.QtCore import Qt, QUrl +from PyQt6.QtGui import QDesktopServices +from PyQt6.QtWidgets import QTextEdit + + +URL_PATTERN = re.compile( + r"(https?://[^\s]+|(?:www\.)?[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(?:/[^\s]*)?)", + re.IGNORECASE, +) + + +class LinkTextEdit(QTextEdit): + + def mouseReleaseEvent(self, event) -> None: + if ( + event.modifiers() + & Qt.KeyboardModifier.ControlModifier + ): + cursor = self.cursorForPosition( + event.position().toPoint() + ) + + cursor.select( + cursor.SelectionType.WordUnderCursor + ) + + text = ( + cursor.selectedText() + .strip() + ) + + if URL_PATTERN.fullmatch(text): + target = text + + if not target.startswith( + ( + "http://", + "https://", + ) + ): + target = ( + f"https://{target}" + ) + + try: + webbrowser.open(target) + + except Exception: + QDesktopServices.openUrl( + QUrl(target) + ) + + return + + super().mouseReleaseEvent(event) + diff --git a/ui/styles.py b/ui/styles.py new file mode 100644 index 0000000..5f1bf4c --- /dev/null +++ b/ui/styles.py @@ -0,0 +1,77 @@ +# v3.1.0 styles.py +from config.profiles import ThemePalette + + +def build_stylesheet( + theme: ThemePalette, + border: str, + background: str, + font_size: int, + font_family: list[str], + layout_margin: int, +) -> str: + fonts = ",".join( + [f'"{item}"' for item in font_family] + ) + + padding = max( + 4, + layout_margin * 2, + ) + + radius = max( + 12, + layout_margin * 4, + ) + + return f""" + QWidget#container {{ + background: {background}; + border: 1px solid {border}; + border-radius: 16px; + }} + + QWidget#container:hover {{ + border: 1px solid {theme.border_active}; + }} + + QFrame {{ + background: transparent; + border: none; + }} + + QTextEdit#editor, + QTextBrowser#preview {{ + background: transparent; + color: {theme.foreground}; + border: none; + border-radius: {radius}px; + padding: {padding}px; + selection-background-color: + {theme.selection}; + font-size: {font_size}px; + font-family: {fonts}; + }} + + QTextEdit#editor {{ + outline: none; + }} + + QTextBrowser#preview code {{ + background: + {theme.code_background}; + border-radius: 6px; + padding: 2px 6px; + }} + + QSizeGrip {{ + background: transparent; + width: 16px; + height: 16px; + }} + + QScrollBar {{ + width: 0px; + height: 0px; + }} + """ \ No newline at end of file