Upload files to "ui"

This commit is contained in:
admin
2026-05-23 20:23:12 +00:00
parent bc8061d708
commit 84af675514
2 changed files with 137 additions and 0 deletions

60
ui/editor.py Normal file
View 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)