Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03b05ecc08 | ||
|
|
34db86fdac | ||
|
|
ed74e97693 | ||
|
|
9eb1d2cc88 | ||
|
|
9a64fecd3d | ||
|
|
904e8ba82b | ||
|
|
a80d28c616 | ||
|
|
aa5dadc302 | ||
|
|
7d67d4a74d | ||
|
|
d129c70c10 | ||
|
|
f962dd393e | ||
|
|
573c08a07c | ||
|
|
5270ef92c1 | ||
|
|
8c7b9fe521 | ||
|
|
599efb060e | ||
|
|
781283e628 | ||
|
|
214531fc8e |
11
README.md
11
README.md
@@ -1,3 +1,10 @@
|
||||
# overlaynote
|
||||
## overlaynote
|
||||
desktop note overlay
|
||||
v1.1
|
||||
|
||||
minimal note overlay
|
||||
---
|
||||
*v1.1* <br>
|
||||
<a href="https://git.backend-3.com/admin/overlaynote/releases/download/v1.0/overlaynote-v1.1.zip" download>download</a>
|
||||
---
|
||||
|
||||
<img width="790vw" src="https://git.backend-3.com/admin/i/raw/branch/main/1etagdzc.png" >
|
||||
|
||||
@@ -44,7 +44,7 @@ THEMES: Final[list[ThemePalette]] = [
|
||||
),
|
||||
ThemePalette(
|
||||
name="yellow",
|
||||
background="rgba(113,63,18,0.24)",
|
||||
background="rgba(113,93,38,0.24)",
|
||||
background_inactive="rgba(113,63,18,0.16)",
|
||||
border_active="rgba(250,204,21,0.36)",
|
||||
border_inactive="rgba(255,255,255,0.10)",
|
||||
|
||||
@@ -1,34 +1,62 @@
|
||||
# v3.1.1 settings.py
|
||||
# v4.0.0 settings.py
|
||||
import json
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
|
||||
def resolve_app_dir() -> Path:
|
||||
if getattr(sys, "frozen", False):
|
||||
return Path(
|
||||
sys.executable
|
||||
).resolve().parent
|
||||
|
||||
return (
|
||||
Path(__file__)
|
||||
.resolve()
|
||||
.parent
|
||||
.parent
|
||||
)
|
||||
|
||||
|
||||
APP_DIR: Final[Path] = (
|
||||
Path(__file__).resolve().parent.parent
|
||||
resolve_app_dir()
|
||||
)
|
||||
|
||||
APP_DIR.mkdir(
|
||||
parents=True,
|
||||
exist_ok=True,
|
||||
)
|
||||
|
||||
SETTINGS_FILE: Final[Path] = (
|
||||
APP_DIR / "settings.json"
|
||||
)
|
||||
|
||||
STATE_FILE: Final[Path] = (
|
||||
APP_DIR / "active.json"
|
||||
)
|
||||
|
||||
MARKDOWN_FILE: Final[Path] = (
|
||||
APP_DIR / "note.md"
|
||||
)
|
||||
|
||||
|
||||
DEFAULT_SETTINGS: Final[dict] = {
|
||||
"active_profile": "default",
|
||||
"profiles": {
|
||||
"default": {
|
||||
"theme": "macos_blue",
|
||||
"theme": "dark",
|
||||
"window": {
|
||||
"width": 260,
|
||||
"height": 300,
|
||||
"min_width": 220,
|
||||
"min_height": 140,
|
||||
"layout_margin": 4,
|
||||
"layout_spacing": 4,
|
||||
"drag_handle_height": 28,
|
||||
"width": 250,
|
||||
"height": 260,
|
||||
"min_width": 200,
|
||||
"min_height": 100,
|
||||
"layout_margin": 0,
|
||||
"layout_spacing": 0,
|
||||
"drag_handle_height": 0,
|
||||
"resize_grip_size": 16,
|
||||
"corner_radius": 16,
|
||||
"corner_radius": 8,
|
||||
"startup_stabilize_ms": 80,
|
||||
},
|
||||
"appearance": {
|
||||
@@ -36,10 +64,10 @@ DEFAULT_SETTINGS: Final[dict] = {
|
||||
"enable_acrylic": True,
|
||||
"enable_glass_blur": True,
|
||||
"enable_animations": True,
|
||||
"enable_shadow": True,
|
||||
"opacity_active": 1.0,
|
||||
"opacity_inactive": 0.96,
|
||||
"opacity_dragging": 0.92,
|
||||
"enable_shadow": False,
|
||||
"opacity_active": 0.97,
|
||||
"opacity_inactive": 0.95,
|
||||
"opacity_dragging": 0.89,
|
||||
"focus_animation_ms": 180,
|
||||
},
|
||||
"editor": {
|
||||
@@ -58,7 +86,7 @@ DEFAULT_SETTINGS: Final[dict] = {
|
||||
"enable_clickable_links": True,
|
||||
"enable_antialiasing": True,
|
||||
"enable_spellcheck": False,
|
||||
"padding": 8,
|
||||
"padding": 0,
|
||||
},
|
||||
"behavior": {
|
||||
"enable_tray": True,
|
||||
@@ -68,127 +96,49 @@ DEFAULT_SETTINGS: Final[dict] = {
|
||||
"high_contrast_inactive": False,
|
||||
},
|
||||
},
|
||||
"light": {
|
||||
"theme": "light",
|
||||
"window": {
|
||||
"width": 260,
|
||||
"height": 300,
|
||||
"min_width": 220,
|
||||
"min_height": 140,
|
||||
"layout_margin": 4,
|
||||
"layout_spacing": 4,
|
||||
"drag_handle_height": 28,
|
||||
"resize_grip_size": 16,
|
||||
"corner_radius": 16,
|
||||
"startup_stabilize_ms": 80,
|
||||
},
|
||||
"appearance": {
|
||||
"enable_mica": False,
|
||||
"enable_acrylic": False,
|
||||
"enable_glass_blur": False,
|
||||
"enable_animations": True,
|
||||
"enable_shadow": False,
|
||||
"opacity_active": 1.0,
|
||||
"opacity_inactive": 0.98,
|
||||
"opacity_dragging": 0.96,
|
||||
"focus_animation_ms": 120,
|
||||
},
|
||||
"editor": {
|
||||
"font_family": [
|
||||
"Inter",
|
||||
"Segoe UI",
|
||||
"Arial",
|
||||
"system-ui",
|
||||
],
|
||||
"font_size": 13,
|
||||
"preview_delay_ms": 500,
|
||||
"save_debounce_ms": 400,
|
||||
"max_note_size": 2_000_000,
|
||||
"enable_markdown_preview": True,
|
||||
"enable_clickable_links": True,
|
||||
"enable_antialiasing": True,
|
||||
"enable_spellcheck": False,
|
||||
"padding": 8,
|
||||
},
|
||||
"behavior": {
|
||||
"enable_tray": True,
|
||||
"enable_persistence": True,
|
||||
"enable_window_memory": True,
|
||||
"enable_auto_restore": True,
|
||||
"high_contrast_inactive": False,
|
||||
},
|
||||
},
|
||||
"accessibility": {
|
||||
"theme": "dark",
|
||||
"window": {
|
||||
"width": 320,
|
||||
"height": 380,
|
||||
"min_width": 260,
|
||||
"min_height": 180,
|
||||
"layout_margin": 6,
|
||||
"layout_spacing": 6,
|
||||
"drag_handle_height": 32,
|
||||
"resize_grip_size": 18,
|
||||
"corner_radius": 18,
|
||||
"startup_stabilize_ms": 80,
|
||||
},
|
||||
"appearance": {
|
||||
"enable_mica": False,
|
||||
"enable_acrylic": False,
|
||||
"enable_glass_blur": False,
|
||||
"enable_animations": False,
|
||||
"enable_shadow": False,
|
||||
"opacity_active": 1.0,
|
||||
"opacity_inactive": 1.0,
|
||||
"opacity_dragging": 1.0,
|
||||
"focus_animation_ms": 0,
|
||||
},
|
||||
"editor": {
|
||||
"font_family": [
|
||||
"Inter",
|
||||
"Segoe UI",
|
||||
"Arial",
|
||||
"system-ui",
|
||||
],
|
||||
"font_size": 15,
|
||||
"preview_delay_ms": 300,
|
||||
"save_debounce_ms": 300,
|
||||
"max_note_size": 2_000_000,
|
||||
"enable_markdown_preview": True,
|
||||
"enable_clickable_links": True,
|
||||
"enable_antialiasing": True,
|
||||
"enable_spellcheck": False,
|
||||
"padding": 10,
|
||||
},
|
||||
"behavior": {
|
||||
"enable_tray": True,
|
||||
"enable_persistence": True,
|
||||
"enable_window_memory": True,
|
||||
"enable_auto_restore": True,
|
||||
"high_contrast_inactive": True,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def atomic_write(
|
||||
path: Path,
|
||||
content: str,
|
||||
) -> None:
|
||||
path.parent.mkdir(
|
||||
parents=True,
|
||||
exist_ok=True,
|
||||
)
|
||||
|
||||
temp = path.with_suffix(
|
||||
f"{path.suffix}.tmp"
|
||||
)
|
||||
|
||||
temp.write_text(
|
||||
content,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
temp.replace(path)
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class SettingsManager:
|
||||
settings: dict
|
||||
|
||||
@classmethod
|
||||
def load(cls) -> "SettingsManager":
|
||||
SETTINGS_FILE.parent.mkdir(
|
||||
parents=True,
|
||||
exist_ok=True,
|
||||
)
|
||||
|
||||
if not SETTINGS_FILE.exists():
|
||||
SETTINGS_FILE.write_text(
|
||||
atomic_write(
|
||||
SETTINGS_FILE,
|
||||
json.dumps(
|
||||
DEFAULT_SETTINGS,
|
||||
indent=2,
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
return cls(
|
||||
DEFAULT_SETTINGS
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -203,9 +153,21 @@ class SettingsManager:
|
||||
data,
|
||||
)
|
||||
|
||||
return cls(merged)
|
||||
manager = cls(merged)
|
||||
|
||||
manager.save()
|
||||
|
||||
return manager
|
||||
|
||||
except Exception:
|
||||
atomic_write(
|
||||
SETTINGS_FILE,
|
||||
json.dumps(
|
||||
DEFAULT_SETTINGS,
|
||||
indent=2,
|
||||
),
|
||||
)
|
||||
|
||||
return cls(
|
||||
DEFAULT_SETTINGS
|
||||
)
|
||||
@@ -245,12 +207,12 @@ class SettingsManager:
|
||||
return result
|
||||
|
||||
def save(self) -> None:
|
||||
SETTINGS_FILE.write_text(
|
||||
atomic_write(
|
||||
SETTINGS_FILE,
|
||||
json.dumps(
|
||||
self.settings,
|
||||
indent=2,
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -284,22 +246,6 @@ class SettingsManager:
|
||||
|
||||
return profiles[active]
|
||||
|
||||
def set_active_profile(
|
||||
self,
|
||||
profile_name: str,
|
||||
) -> None:
|
||||
if (
|
||||
profile_name
|
||||
not in self.profiles
|
||||
):
|
||||
return
|
||||
|
||||
self.settings[
|
||||
"active_profile"
|
||||
] = profile_name
|
||||
|
||||
self.save()
|
||||
|
||||
def reload(self) -> None:
|
||||
loaded = (
|
||||
SettingsManager.load()
|
||||
@@ -315,43 +261,3 @@ class SettingsManager:
|
||||
)
|
||||
|
||||
self.save()
|
||||
|
||||
def create_profile(
|
||||
self,
|
||||
name: str,
|
||||
data: dict,
|
||||
) -> None:
|
||||
self.settings[
|
||||
"profiles"
|
||||
][name] = data
|
||||
|
||||
self.save()
|
||||
|
||||
def delete_profile(
|
||||
self,
|
||||
name: str,
|
||||
) -> None:
|
||||
if name == "default":
|
||||
return
|
||||
|
||||
if (
|
||||
name
|
||||
not in self.settings[
|
||||
"profiles"
|
||||
]
|
||||
):
|
||||
return
|
||||
|
||||
del self.settings[
|
||||
"profiles"
|
||||
][name]
|
||||
|
||||
if (
|
||||
self.active_profile_name
|
||||
== name
|
||||
):
|
||||
self.settings[
|
||||
"active_profile"
|
||||
] = "default"
|
||||
|
||||
self.save()
|
||||
684
core/app.py
684
core/app.py
@@ -1,15 +1,15 @@
|
||||
# v3.1.0 app.py
|
||||
import contextlib
|
||||
# v4.2.1 app.py
|
||||
import atexit
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import traceback
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum, auto
|
||||
from hashlib import sha256
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
from PyQt6.QtCore import (
|
||||
QEasingCurve,
|
||||
@@ -33,6 +33,7 @@ from PyQt6.QtGui import (
|
||||
)
|
||||
|
||||
from PyQt6.QtWidgets import (
|
||||
QApplication,
|
||||
QFrame,
|
||||
QMenu,
|
||||
QSizeGrip,
|
||||
@@ -45,10 +46,16 @@ from PyQt6.QtWidgets import (
|
||||
from qframelesswindow import AcrylicWindow
|
||||
|
||||
from config.profiles import THEMES
|
||||
|
||||
from config.settings import (
|
||||
APP_DIR,
|
||||
MARKDOWN_FILE,
|
||||
SETTINGS_FILE,
|
||||
STATE_FILE,
|
||||
SettingsManager,
|
||||
atomic_write,
|
||||
)
|
||||
|
||||
from ui.editor import LinkTextEdit
|
||||
from ui.styles import build_stylesheet
|
||||
|
||||
@@ -59,15 +66,6 @@ logging.basicConfig(
|
||||
)
|
||||
|
||||
|
||||
STATE_FILE: Final[Path] = (
|
||||
APP_DIR / "sticky_state.json"
|
||||
)
|
||||
|
||||
MARKDOWN_FILE: Final[Path] = (
|
||||
APP_DIR / "sticky.md"
|
||||
)
|
||||
|
||||
|
||||
class WindowState(Enum):
|
||||
IDLE = auto()
|
||||
DRAGGING = auto()
|
||||
@@ -83,9 +81,8 @@ class ActiveState(Enum):
|
||||
class PersistedState:
|
||||
x: int = 100
|
||||
y: int = 100
|
||||
width: int = 260
|
||||
height: int = 300
|
||||
theme_index: int = 0
|
||||
width: int = 250
|
||||
height: int = 260
|
||||
|
||||
|
||||
class DragHandle(QFrame):
|
||||
@@ -138,12 +135,15 @@ class StickyNoteApp(AcrylicWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self._closing = False
|
||||
self._is_quitting = False
|
||||
self._force_close = False
|
||||
|
||||
self.settings_manager = (
|
||||
SettingsManager.load()
|
||||
)
|
||||
|
||||
self.ensure_runtime_files()
|
||||
|
||||
self.profile = (
|
||||
self.settings_manager.profile
|
||||
)
|
||||
@@ -158,6 +158,10 @@ class StickyNoteApp(AcrylicWindow):
|
||||
|
||||
self.drag_offset = QPoint()
|
||||
|
||||
self.drag_origin = QPoint()
|
||||
|
||||
self.pending_drag = False
|
||||
|
||||
self.last_saved_hash = ""
|
||||
|
||||
self.last_preview_hash = ""
|
||||
@@ -166,25 +170,68 @@ class StickyNoteApp(AcrylicWindow):
|
||||
|
||||
self.configure_font()
|
||||
|
||||
self.build_ui()
|
||||
|
||||
self.setup_timers()
|
||||
|
||||
self.build_ui()
|
||||
|
||||
self.configure_window()
|
||||
|
||||
self.build_tray()
|
||||
|
||||
self.restore_state()
|
||||
|
||||
self.apply_style()
|
||||
QTimer.singleShot(
|
||||
80,
|
||||
self.restore_state,
|
||||
)
|
||||
|
||||
QTimer.singleShot(
|
||||
self.profile["window"][
|
||||
"startup_stabilize_ms"
|
||||
],
|
||||
120,
|
||||
self.initialize_effects,
|
||||
)
|
||||
|
||||
QTimer.singleShot(
|
||||
220,
|
||||
self.build_tray,
|
||||
)
|
||||
|
||||
QTimer.singleShot(
|
||||
260,
|
||||
self.apply_style,
|
||||
)
|
||||
|
||||
QTimer.singleShot(
|
||||
320,
|
||||
self.finalize_startup,
|
||||
)
|
||||
|
||||
self.register_shutdown_hooks()
|
||||
|
||||
def ensure_runtime_files(self) -> None:
|
||||
APP_DIR.mkdir(
|
||||
parents=True,
|
||||
exist_ok=True,
|
||||
)
|
||||
|
||||
if not SETTINGS_FILE.exists():
|
||||
self.settings_manager.save()
|
||||
|
||||
if not MARKDOWN_FILE.exists():
|
||||
atomic_write(
|
||||
MARKDOWN_FILE,
|
||||
"",
|
||||
)
|
||||
|
||||
if not STATE_FILE.exists():
|
||||
atomic_write(
|
||||
STATE_FILE,
|
||||
json.dumps(
|
||||
{
|
||||
"x": 100,
|
||||
"y": 100,
|
||||
"width": 250,
|
||||
"height": 260,
|
||||
},
|
||||
indent=2,
|
||||
),
|
||||
)
|
||||
|
||||
def configure_font(self) -> None:
|
||||
self.font_object = QFont()
|
||||
|
||||
@@ -232,6 +279,16 @@ class StickyNoteApp(AcrylicWindow):
|
||||
self.show_preview
|
||||
)
|
||||
|
||||
self.drag_timer = QTimer(self)
|
||||
|
||||
self.drag_timer.setSingleShot(
|
||||
True
|
||||
)
|
||||
|
||||
self.drag_timer.timeout.connect(
|
||||
self.activate_delayed_drag
|
||||
)
|
||||
|
||||
self.opacity_anim = (
|
||||
QPropertyAnimation(
|
||||
self,
|
||||
@@ -262,10 +319,14 @@ class StickyNoteApp(AcrylicWindow):
|
||||
window["min_height"],
|
||||
)
|
||||
|
||||
self.setWindowFlags(
|
||||
Qt.WindowType.Tool
|
||||
| Qt.WindowType.WindowStaysOnTopHint
|
||||
| Qt.WindowType.FramelessWindowHint
|
||||
self.setWindowFlag(
|
||||
Qt.WindowType.WindowStaysOnTopHint,
|
||||
True,
|
||||
)
|
||||
|
||||
self.setWindowFlag(
|
||||
Qt.WindowType.FramelessWindowHint,
|
||||
True,
|
||||
)
|
||||
|
||||
self.setAttribute(
|
||||
@@ -273,33 +334,14 @@ class StickyNoteApp(AcrylicWindow):
|
||||
True,
|
||||
)
|
||||
|
||||
self.setAutoFillBackground(False)
|
||||
|
||||
appearance = (
|
||||
self.profile["appearance"]
|
||||
self.setAttribute(
|
||||
Qt.WidgetAttribute.WA_NoSystemBackground,
|
||||
True,
|
||||
)
|
||||
|
||||
try:
|
||||
if appearance[
|
||||
"enable_mica"
|
||||
]:
|
||||
self.windowEffect.setMicaEffect(
|
||||
self.winId(),
|
||||
True,
|
||||
)
|
||||
|
||||
elif appearance[
|
||||
"enable_acrylic"
|
||||
]:
|
||||
self.windowEffect.setAcrylicEffect(
|
||||
self.winId(),
|
||||
"00000001",
|
||||
)
|
||||
|
||||
except Exception:
|
||||
logging.exception(
|
||||
"window_effect_failure"
|
||||
)
|
||||
self.setAutoFillBackground(
|
||||
False
|
||||
)
|
||||
|
||||
def build_ui(self) -> None:
|
||||
self.root = QWidget(self)
|
||||
@@ -308,48 +350,34 @@ class StickyNoteApp(AcrylicWindow):
|
||||
"container"
|
||||
)
|
||||
|
||||
self.root.setGeometry(
|
||||
self.rect()
|
||||
)
|
||||
|
||||
self.layout = QVBoxLayout(
|
||||
self.root
|
||||
)
|
||||
|
||||
window = self.profile["window"]
|
||||
|
||||
margin = window[
|
||||
"layout_margin"
|
||||
]
|
||||
|
||||
self.layout.setContentsMargins(
|
||||
margin,
|
||||
margin,
|
||||
margin,
|
||||
margin,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
)
|
||||
|
||||
self.layout.setSpacing(
|
||||
window["layout_spacing"]
|
||||
)
|
||||
self.layout.setSpacing(0)
|
||||
|
||||
self.titleBar.hide()
|
||||
|
||||
self.titleBar.setFixedHeight(0)
|
||||
|
||||
self.drag_handle = DragHandle(
|
||||
self.root
|
||||
)
|
||||
|
||||
self.drag_handle.setFixedHeight(
|
||||
window[
|
||||
"drag_handle_height"
|
||||
]
|
||||
)
|
||||
self.drag_handle.hide()
|
||||
|
||||
self.drag_handle.drag_started.connect(
|
||||
self.start_drag
|
||||
)
|
||||
|
||||
self.drag_handle.drag_moved.connect(
|
||||
self.perform_drag
|
||||
)
|
||||
|
||||
self.drag_handle.drag_finished.connect(
|
||||
self.finish_drag
|
||||
)
|
||||
self.drag_handle.setFixedHeight(0)
|
||||
|
||||
self.editor = LinkTextEdit(
|
||||
self.root
|
||||
@@ -367,6 +395,37 @@ class StickyNoteApp(AcrylicWindow):
|
||||
0
|
||||
)
|
||||
|
||||
self.editor.setViewportMargins(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
|
||||
self.editor.setAcceptRichText(
|
||||
False
|
||||
)
|
||||
|
||||
self.editor.setMouseTracking(
|
||||
True
|
||||
)
|
||||
|
||||
self.editor.setStyleSheet("""
|
||||
QTextEdit {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
QTextEdit > QWidget {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
}
|
||||
""")
|
||||
|
||||
self.editor.textChanged.connect(
|
||||
self.queue_save
|
||||
)
|
||||
@@ -396,13 +455,13 @@ class StickyNoteApp(AcrylicWindow):
|
||||
)
|
||||
|
||||
content_layout.setContentsMargins(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
)
|
||||
|
||||
content_layout.setSpacing(0)
|
||||
content_layout.setSpacing(1)
|
||||
|
||||
content_layout.addWidget(
|
||||
self.editor,
|
||||
@@ -418,10 +477,6 @@ class StickyNoteApp(AcrylicWindow):
|
||||
self.root
|
||||
)
|
||||
|
||||
self.layout.addWidget(
|
||||
self.drag_handle
|
||||
)
|
||||
|
||||
self.layout.addWidget(
|
||||
content,
|
||||
1,
|
||||
@@ -434,7 +489,12 @@ class StickyNoteApp(AcrylicWindow):
|
||||
| Qt.AlignmentFlag.AlignRight,
|
||||
)
|
||||
|
||||
self.editor.setFocus()
|
||||
|
||||
def build_tray(self) -> None:
|
||||
if not QSystemTrayIcon.isSystemTrayAvailable():
|
||||
return
|
||||
|
||||
if not self.profile[
|
||||
"behavior"
|
||||
]["enable_tray"]:
|
||||
@@ -474,7 +534,7 @@ class StickyNoteApp(AcrylicWindow):
|
||||
)
|
||||
|
||||
quit_action.triggered.connect(
|
||||
self.close
|
||||
self.safe_exit
|
||||
)
|
||||
|
||||
menu.addAction(open_settings)
|
||||
@@ -589,10 +649,46 @@ class StickyNoteApp(AcrylicWindow):
|
||||
)
|
||||
)
|
||||
|
||||
def start_drag(
|
||||
self,
|
||||
global_pos: QPoint,
|
||||
) -> None:
|
||||
def initialize_effects(self) -> None:
|
||||
appearance = (
|
||||
self.profile["appearance"]
|
||||
)
|
||||
|
||||
try:
|
||||
hwnd = int(self.winId())
|
||||
|
||||
if not hwnd:
|
||||
return
|
||||
|
||||
if appearance[
|
||||
"enable_mica"
|
||||
]:
|
||||
self.windowEffect.setMicaEffect(
|
||||
hwnd,
|
||||
True,
|
||||
)
|
||||
|
||||
elif appearance[
|
||||
"enable_acrylic"
|
||||
]:
|
||||
self.windowEffect.setAcrylicEffect(
|
||||
hwnd,
|
||||
"00000001",
|
||||
)
|
||||
|
||||
self.update()
|
||||
|
||||
self.repaint()
|
||||
|
||||
except Exception:
|
||||
logging.exception(
|
||||
"window_effect_failure"
|
||||
)
|
||||
|
||||
def activate_delayed_drag(self) -> None:
|
||||
if not self.pending_drag:
|
||||
return
|
||||
|
||||
self.window_state = (
|
||||
WindowState.DRAGGING
|
||||
)
|
||||
@@ -603,27 +699,84 @@ class StickyNoteApp(AcrylicWindow):
|
||||
|
||||
self.apply_style()
|
||||
|
||||
self.drag_offset = (
|
||||
global_pos
|
||||
- self.frameGeometry().topLeft()
|
||||
)
|
||||
|
||||
self.setWindowOpacity(
|
||||
self.profile["appearance"][
|
||||
"opacity_dragging"
|
||||
]
|
||||
)
|
||||
|
||||
def perform_drag(
|
||||
self,
|
||||
global_pos: QPoint,
|
||||
) -> None:
|
||||
target = (
|
||||
global_pos
|
||||
- self.drag_offset
|
||||
def mousePressEvent(self, event) -> None:
|
||||
if (
|
||||
event.button()
|
||||
== Qt.MouseButton.LeftButton
|
||||
):
|
||||
self.pending_drag = True
|
||||
|
||||
self.drag_origin = (
|
||||
event.globalPosition()
|
||||
.toPoint()
|
||||
)
|
||||
|
||||
self.drag_offset = (
|
||||
self.drag_origin
|
||||
- self.frameGeometry().topLeft()
|
||||
)
|
||||
|
||||
if hasattr(
|
||||
self,
|
||||
"drag_timer",
|
||||
):
|
||||
self.drag_timer.start(180)
|
||||
|
||||
super().mousePressEvent(event)
|
||||
|
||||
def mouseMoveEvent(self, event) -> None:
|
||||
if not (
|
||||
event.buttons()
|
||||
& Qt.MouseButton.LeftButton
|
||||
):
|
||||
return
|
||||
|
||||
global_pos = (
|
||||
event.globalPosition()
|
||||
.toPoint()
|
||||
)
|
||||
|
||||
self.move(target)
|
||||
if (
|
||||
self.pending_drag
|
||||
and (
|
||||
global_pos
|
||||
- self.drag_origin
|
||||
).manhattanLength()
|
||||
> 6
|
||||
):
|
||||
if (
|
||||
self.window_state
|
||||
== WindowState.DRAGGING
|
||||
):
|
||||
self.move(
|
||||
global_pos
|
||||
- self.drag_offset
|
||||
)
|
||||
|
||||
super().mouseMoveEvent(event)
|
||||
|
||||
def mouseReleaseEvent(self, event) -> None:
|
||||
if hasattr(
|
||||
self,
|
||||
"drag_timer",
|
||||
):
|
||||
self.drag_timer.stop()
|
||||
|
||||
self.pending_drag = False
|
||||
|
||||
if (
|
||||
self.window_state
|
||||
== WindowState.DRAGGING
|
||||
):
|
||||
self.finish_drag()
|
||||
|
||||
super().mouseReleaseEvent(event)
|
||||
|
||||
def finish_drag(self) -> None:
|
||||
self.window_state = (
|
||||
@@ -642,7 +795,15 @@ class StickyNoteApp(AcrylicWindow):
|
||||
]
|
||||
)
|
||||
|
||||
self.queue_save()
|
||||
|
||||
def queue_save(self) -> None:
|
||||
if not hasattr(
|
||||
self,
|
||||
"save_timer",
|
||||
):
|
||||
return
|
||||
|
||||
self.save_timer.start(
|
||||
self.profile["editor"][
|
||||
"save_debounce_ms"
|
||||
@@ -650,6 +811,12 @@ class StickyNoteApp(AcrylicWindow):
|
||||
)
|
||||
|
||||
def queue_preview(self) -> None:
|
||||
if not hasattr(
|
||||
self,
|
||||
"preview_timer",
|
||||
):
|
||||
return
|
||||
|
||||
if not self.profile[
|
||||
"editor"
|
||||
][
|
||||
@@ -668,9 +835,16 @@ class StickyNoteApp(AcrylicWindow):
|
||||
)
|
||||
|
||||
def show_preview(self) -> None:
|
||||
if self.editor.hasFocus():
|
||||
if (
|
||||
self.editor.hasFocus()
|
||||
or not self.isActiveWindow()
|
||||
):
|
||||
return
|
||||
|
||||
self.preview.setFocusPolicy(
|
||||
Qt.FocusPolicy.NoFocus
|
||||
)
|
||||
|
||||
markdown = (
|
||||
self.editor.toPlainText()
|
||||
)
|
||||
@@ -698,49 +872,65 @@ class StickyNoteApp(AcrylicWindow):
|
||||
self.preview.show()
|
||||
|
||||
def save_state(self) -> None:
|
||||
markdown = (
|
||||
self.editor.toPlainText()
|
||||
)
|
||||
|
||||
current_hash = sha256(
|
||||
markdown.encode("utf-8")
|
||||
).hexdigest()
|
||||
|
||||
if current_hash != self.last_saved_hash:
|
||||
MARKDOWN_FILE.write_text(
|
||||
markdown,
|
||||
encoding="utf-8",
|
||||
try:
|
||||
APP_DIR.mkdir(
|
||||
parents=True,
|
||||
exist_ok=True,
|
||||
)
|
||||
|
||||
self.last_saved_hash = (
|
||||
markdown = (
|
||||
self.editor.toPlainText()
|
||||
)
|
||||
|
||||
current_hash = sha256(
|
||||
markdown.encode("utf-8")
|
||||
).hexdigest()
|
||||
|
||||
if (
|
||||
current_hash
|
||||
!= self.last_saved_hash
|
||||
):
|
||||
atomic_write(
|
||||
MARKDOWN_FILE,
|
||||
markdown,
|
||||
)
|
||||
|
||||
self.last_saved_hash = (
|
||||
current_hash
|
||||
)
|
||||
|
||||
atomic_write(
|
||||
STATE_FILE,
|
||||
json.dumps(
|
||||
{
|
||||
"x": self.x(),
|
||||
"y": self.y(),
|
||||
"width": self.width(),
|
||||
"height": self.height(),
|
||||
},
|
||||
indent=2,
|
||||
),
|
||||
)
|
||||
|
||||
STATE_FILE.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"x": self.x(),
|
||||
"y": self.y(),
|
||||
"width": self.width(),
|
||||
"height": self.height(),
|
||||
},
|
||||
indent=2,
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
except Exception:
|
||||
logging.exception(
|
||||
"save_state_failure"
|
||||
)
|
||||
|
||||
def restore_state(self) -> None:
|
||||
if MARKDOWN_FILE.exists():
|
||||
self.editor.setPlainText(
|
||||
try:
|
||||
self.ensure_runtime_files()
|
||||
|
||||
markdown = (
|
||||
MARKDOWN_FILE.read_text(
|
||||
encoding="utf-8",
|
||||
)
|
||||
)
|
||||
|
||||
if not STATE_FILE.exists():
|
||||
return
|
||||
self.editor.setPlainText(
|
||||
markdown
|
||||
)
|
||||
|
||||
try:
|
||||
state = json.loads(
|
||||
STATE_FILE.read_text(
|
||||
encoding="utf-8",
|
||||
@@ -748,13 +938,25 @@ class StickyNoteApp(AcrylicWindow):
|
||||
)
|
||||
|
||||
self.resize(
|
||||
state["width"],
|
||||
state["height"],
|
||||
max(
|
||||
state.get(
|
||||
"width",
|
||||
250,
|
||||
),
|
||||
200,
|
||||
),
|
||||
max(
|
||||
state.get(
|
||||
"height",
|
||||
260,
|
||||
),
|
||||
100,
|
||||
),
|
||||
)
|
||||
|
||||
self.move(
|
||||
state["x"],
|
||||
state["y"],
|
||||
state.get("x", 100),
|
||||
state.get("y", 100),
|
||||
)
|
||||
|
||||
self.clamp_to_screen()
|
||||
@@ -814,29 +1016,38 @@ class StickyNoteApp(AcrylicWindow):
|
||||
self.apply_style()
|
||||
|
||||
def open_settings(self) -> None:
|
||||
path = (
|
||||
APP_DIR / "settings.json"
|
||||
SETTINGS_FILE.touch(
|
||||
exist_ok=True
|
||||
)
|
||||
|
||||
path.touch(exist_ok=True)
|
||||
|
||||
try:
|
||||
if os.name == "nt":
|
||||
os.startfile(str(path))
|
||||
os.startfile(
|
||||
str(SETTINGS_FILE)
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
if sys.platform.startswith(
|
||||
"linux"
|
||||
):
|
||||
subprocess.Popen(
|
||||
["xdg-open", str(path)]
|
||||
[
|
||||
"xdg-open",
|
||||
str(SETTINGS_FILE),
|
||||
]
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
if sys.platform == "darwin":
|
||||
subprocess.Popen(
|
||||
["open", str(path)]
|
||||
[
|
||||
"open",
|
||||
str(SETTINGS_FILE),
|
||||
]
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
except Exception:
|
||||
@@ -844,26 +1055,21 @@ class StickyNoteApp(AcrylicWindow):
|
||||
"open_settings_failure"
|
||||
)
|
||||
|
||||
def nativeEvent(
|
||||
self,
|
||||
eventType,
|
||||
message,
|
||||
):
|
||||
if getattr(
|
||||
self,
|
||||
"_closing",
|
||||
False,
|
||||
):
|
||||
return False, 0
|
||||
def moveEvent(self, event) -> None:
|
||||
super().moveEvent(event)
|
||||
|
||||
try:
|
||||
return super().nativeEvent(
|
||||
eventType,
|
||||
message,
|
||||
if (
|
||||
getattr(
|
||||
self,
|
||||
"startup_ready",
|
||||
False,
|
||||
)
|
||||
|
||||
except Exception:
|
||||
return False, 0
|
||||
and hasattr(
|
||||
self,
|
||||
"save_timer",
|
||||
)
|
||||
):
|
||||
self.queue_save()
|
||||
|
||||
def resizeEvent(self, event) -> None:
|
||||
super().resizeEvent(event)
|
||||
@@ -874,15 +1080,29 @@ class StickyNoteApp(AcrylicWindow):
|
||||
None,
|
||||
)
|
||||
|
||||
if root is None:
|
||||
return
|
||||
if root is not None:
|
||||
geometry = self.rect()
|
||||
|
||||
geometry = self.rect()
|
||||
if (
|
||||
root.geometry()
|
||||
!= geometry
|
||||
):
|
||||
root.setGeometry(
|
||||
geometry
|
||||
)
|
||||
|
||||
if root.geometry() != geometry:
|
||||
root.setGeometry(
|
||||
geometry
|
||||
if (
|
||||
getattr(
|
||||
self,
|
||||
"startup_ready",
|
||||
False,
|
||||
)
|
||||
and hasattr(
|
||||
self,
|
||||
"save_timer",
|
||||
)
|
||||
):
|
||||
self.queue_save()
|
||||
|
||||
def focusInEvent(self, event) -> None:
|
||||
super().focusInEvent(event)
|
||||
@@ -921,22 +1141,108 @@ class StickyNoteApp(AcrylicWindow):
|
||||
)
|
||||
|
||||
def closeEvent(self, event) -> None:
|
||||
self._closing = True
|
||||
if (
|
||||
self._is_quitting
|
||||
or self._force_close
|
||||
):
|
||||
try:
|
||||
self.save_state()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
event.accept()
|
||||
|
||||
return
|
||||
|
||||
event.ignore()
|
||||
|
||||
self.hide()
|
||||
|
||||
def register_shutdown_hooks(self) -> None:
|
||||
app = QApplication.instance()
|
||||
|
||||
def handle_shutdown(*_) -> None:
|
||||
self.safe_exit()
|
||||
|
||||
atexit.register(
|
||||
handle_shutdown
|
||||
)
|
||||
|
||||
for sig in (
|
||||
signal.SIGINT,
|
||||
signal.SIGTERM,
|
||||
):
|
||||
try:
|
||||
signal.signal(
|
||||
sig,
|
||||
handle_shutdown,
|
||||
)
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if app is not None:
|
||||
app.aboutToQuit.connect(
|
||||
lambda: setattr(
|
||||
self,
|
||||
"_is_quitting",
|
||||
True,
|
||||
)
|
||||
)
|
||||
|
||||
def safe_exit(self) -> None:
|
||||
if self._is_quitting:
|
||||
return
|
||||
|
||||
self._is_quitting = True
|
||||
|
||||
try:
|
||||
self.save_state()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
self.save_timer.stop()
|
||||
try:
|
||||
if hasattr(
|
||||
self,
|
||||
"save_timer",
|
||||
):
|
||||
self.save_timer.stop()
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
self.preview_timer.stop()
|
||||
if hasattr(
|
||||
self,
|
||||
"preview_timer",
|
||||
):
|
||||
self.preview_timer.stop()
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
self.opacity_anim.stop()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
if hasattr(self, "tray"):
|
||||
try:
|
||||
if hasattr(
|
||||
self,
|
||||
"tray",
|
||||
):
|
||||
self.tray.hide()
|
||||
|
||||
super().closeEvent(event)
|
||||
self.tray.deleteLater()
|
||||
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
try:
|
||||
self.hide()
|
||||
|
||||
self.deleteLater()
|
||||
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
app = QApplication.instance()
|
||||
|
||||
if app is not None:
|
||||
app.quit()
|
||||
|
||||
try:
|
||||
app.quit()
|
||||
except Exception:
|
||||
sys.exit(0)
|
||||
61
start.py
61
start.py
@@ -1,35 +1,64 @@
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "1"
|
||||
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QGuiApplication
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
|
||||
from config.settings import (
|
||||
APP_DIR,
|
||||
)
|
||||
from core.app import StickyNoteApp
|
||||
|
||||
|
||||
APP_DIR.mkdir(
|
||||
parents=True,
|
||||
exist_ok=True,
|
||||
)
|
||||
|
||||
QGuiApplication.setHighDpiScaleFactorRoundingPolicy(
|
||||
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
|
||||
signal.signal(
|
||||
signal.SIGINT,
|
||||
signal.SIG_DFL,
|
||||
)
|
||||
|
||||
QApplication.setQuitOnLastWindowClosed(False)
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
app = QApplication.instance()
|
||||
if app is None:
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
app.setQuitLockEnabled(False)
|
||||
|
||||
existing = getattr(app, "_sticky_note_instance", None)
|
||||
if existing is not None:
|
||||
existing.raise_()
|
||||
existing.activateWindow()
|
||||
return 0
|
||||
app.setQuitOnLastWindowClosed(
|
||||
False
|
||||
)
|
||||
|
||||
window = StickyNoteApp()
|
||||
|
||||
app._sticky_note_instance = window
|
||||
|
||||
window.show()
|
||||
|
||||
return app.exec()
|
||||
try:
|
||||
return app.exec()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
try:
|
||||
window.safe_exit()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
return 0
|
||||
|
||||
except SystemExit:
|
||||
return 0
|
||||
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
BIN
ui/app.ico
Normal file
BIN
ui/app.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.7 KiB |
37
ui/editor.py
37
ui/editor.py
@@ -1,10 +1,19 @@
|
||||
# v3.0.0 editor.py
|
||||
# v4.1.0 editor-link-click-fix-v1
|
||||
import re
|
||||
import webbrowser
|
||||
|
||||
from PyQt6.QtCore import Qt, QUrl
|
||||
from PyQt6.QtGui import QDesktopServices
|
||||
from PyQt6.QtWidgets import QTextEdit
|
||||
from PyQt6.QtCore import (
|
||||
Qt,
|
||||
QUrl,
|
||||
)
|
||||
|
||||
from PyQt6.QtGui import (
|
||||
QDesktopServices,
|
||||
)
|
||||
|
||||
from PyQt6.QtWidgets import (
|
||||
QTextEdit,
|
||||
)
|
||||
|
||||
|
||||
URL_PATTERN = re.compile(
|
||||
@@ -15,9 +24,14 @@ URL_PATTERN = re.compile(
|
||||
|
||||
class LinkTextEdit(QTextEdit):
|
||||
|
||||
def mouseReleaseEvent(self, event) -> None:
|
||||
def mouseReleaseEvent(
|
||||
self,
|
||||
event,
|
||||
) -> None:
|
||||
if (
|
||||
event.modifiers()
|
||||
event.button()
|
||||
== Qt.MouseButton.LeftButton
|
||||
and event.modifiers()
|
||||
& Qt.KeyboardModifier.ControlModifier
|
||||
):
|
||||
cursor = self.cursorForPosition(
|
||||
@@ -47,14 +61,19 @@ class LinkTextEdit(QTextEdit):
|
||||
)
|
||||
|
||||
try:
|
||||
webbrowser.open(target)
|
||||
webbrowser.open(
|
||||
target
|
||||
)
|
||||
|
||||
except Exception:
|
||||
QDesktopServices.openUrl(
|
||||
QUrl(target)
|
||||
)
|
||||
|
||||
event.accept()
|
||||
|
||||
return
|
||||
|
||||
super().mouseReleaseEvent(event)
|
||||
|
||||
super().mouseReleaseEvent(
|
||||
event
|
||||
)
|
||||
@@ -28,7 +28,7 @@ def build_stylesheet(
|
||||
QWidget#container {{
|
||||
background: {background};
|
||||
border: 1px solid {border};
|
||||
border-radius: 16px;
|
||||
border-radius: 7px;
|
||||
}}
|
||||
|
||||
QWidget#container:hover {{
|
||||
|
||||
Reference in New Issue
Block a user