Upload files to "ui"
This commit is contained in:
60
ui/editor.py
Normal file
60
ui/editor.py
Normal file
@@ -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)
|
||||
|
||||
77
ui/styles.py
Normal file
77
ui/styles.py
Normal file
@@ -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;
|
||||
}}
|
||||
"""
|
||||
Reference in New Issue
Block a user