codis 1.1.1__py3-none-any.whl
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.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/ui/clock_panel.py
ADDED
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
"""Codis - Relógio, Alarme e Cronômetro.
|
|
2
|
+
|
|
3
|
+
Funcionalidades:
|
|
4
|
+
- Relógio analógico desenhado em Canvas com agulhas suaves
|
|
5
|
+
- Relógio digital com timezone configurável
|
|
6
|
+
- Alarmes múltiplos com rótulo e som opcional
|
|
7
|
+
- Cronômetro com voltas (laps) e exportação
|
|
8
|
+
- 3 abas: Relógio - Alarmes - Cronômetro
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
import math
|
|
15
|
+
import time
|
|
16
|
+
import tkinter as tk
|
|
17
|
+
from collections.abc import Callable
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
from tkinter import messagebox, ttk
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
from src.constants import CONFIG_DIR, FONT_MONO, FONT_UI
|
|
24
|
+
from src.i18n import _t
|
|
25
|
+
from src.ui._persistence_utils import load_dataclass_list, save_dataclass_list
|
|
26
|
+
from src.ui.grab_safe import safe_grab_set
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger("Codis.Clock")
|
|
29
|
+
|
|
30
|
+
_ALARMS_FILE = CONFIG_DIR / "clock_alarms.json"
|
|
31
|
+
_TAB_PAD = {"padx": 0, "pady": 0}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class Alarm:
|
|
36
|
+
"""Entrada de alarme persistida."""
|
|
37
|
+
|
|
38
|
+
label: str
|
|
39
|
+
hour: int
|
|
40
|
+
minute: int
|
|
41
|
+
enabled: bool = True
|
|
42
|
+
repeat: bool = False
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _load_alarms() -> list[Alarm]:
|
|
46
|
+
return load_dataclass_list(_ALARMS_FILE, Alarm, logger=logger)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _save_alarms(alarms: list[Alarm]) -> None:
|
|
50
|
+
save_dataclass_list(_ALARMS_FILE, alarms)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class ClockPanel(tk.Frame):
|
|
54
|
+
"""Relógio analógico/digital, alarmes e cronômetro integrado ao Codis."""
|
|
55
|
+
|
|
56
|
+
def __init__(self, parent: tk.Widget, tmgr: Any, cfg: Any) -> None:
|
|
57
|
+
t = tmgr.theme
|
|
58
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
59
|
+
self._tmgr = tmgr
|
|
60
|
+
self._cfg = cfg
|
|
61
|
+
self._alive = True
|
|
62
|
+
self._alarms: list[Alarm] = _load_alarms()
|
|
63
|
+
|
|
64
|
+
self._sw_running = False
|
|
65
|
+
self._sw_start_ts = 0.0
|
|
66
|
+
self._sw_elapsed = 0.0
|
|
67
|
+
self._sw_laps: list[float] = []
|
|
68
|
+
|
|
69
|
+
self._alarm_fired_this_minute: set[int] = set()
|
|
70
|
+
|
|
71
|
+
self._build(t)
|
|
72
|
+
self._tick()
|
|
73
|
+
|
|
74
|
+
def _build(self, t: Any) -> None:
|
|
75
|
+
"""Constrói a estrutura de abas."""
|
|
76
|
+
hdr = tk.Frame(self, bg=t.activity_bg, height=48)
|
|
77
|
+
hdr.pack(fill="x")
|
|
78
|
+
hdr.pack_propagate(False)
|
|
79
|
+
tk.Label(
|
|
80
|
+
hdr, text="🕐", bg=t.activity_bg, fg=t.accent, font=(FONT_UI, 16)
|
|
81
|
+
).pack(side="left", padx=(14, 4), pady=8)
|
|
82
|
+
tk.Label(
|
|
83
|
+
hdr,
|
|
84
|
+
text=_t("clock.title", "Relógio"),
|
|
85
|
+
bg=t.activity_bg,
|
|
86
|
+
fg=t.fg,
|
|
87
|
+
font=(FONT_UI, 13, "bold"),
|
|
88
|
+
).pack(side="left", pady=8)
|
|
89
|
+
|
|
90
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x")
|
|
91
|
+
|
|
92
|
+
nb = ttk.Notebook(self)
|
|
93
|
+
nb.pack(fill="both", expand=True, padx=0, pady=0)
|
|
94
|
+
|
|
95
|
+
self._tab_clock = tk.Frame(nb, bg=t.panel_bg)
|
|
96
|
+
self._tab_alarms = tk.Frame(nb, bg=t.panel_bg)
|
|
97
|
+
self._tab_stopwatch = tk.Frame(nb, bg=t.panel_bg)
|
|
98
|
+
|
|
99
|
+
nb.add(self._tab_clock, text=_t("clock.tab_clock", " Relógio "))
|
|
100
|
+
nb.add(self._tab_alarms, text=_t("clock.tab_alarms", " Alarmes "))
|
|
101
|
+
nb.add(self._tab_stopwatch, text=_t(
|
|
102
|
+
"clock.tab_stopwatch", "Cronômetro "))
|
|
103
|
+
|
|
104
|
+
self._build_clock_tab(t)
|
|
105
|
+
self._build_alarms_tab(t)
|
|
106
|
+
self._build_stopwatch_tab(t)
|
|
107
|
+
|
|
108
|
+
def _build_clock_tab(self, t: Any) -> None:
|
|
109
|
+
tab = self._tab_clock
|
|
110
|
+
|
|
111
|
+
self._canvas_size = 220
|
|
112
|
+
self._canvas = tk.Canvas(
|
|
113
|
+
tab,
|
|
114
|
+
width=self._canvas_size,
|
|
115
|
+
height=self._canvas_size,
|
|
116
|
+
bg=t.panel_bg,
|
|
117
|
+
highlightthickness=0,
|
|
118
|
+
)
|
|
119
|
+
self._canvas.pack(pady=(16, 0))
|
|
120
|
+
|
|
121
|
+
self._digital_var = tk.StringVar(value="00:00:00")
|
|
122
|
+
tk.Label(
|
|
123
|
+
tab,
|
|
124
|
+
textvariable=self._digital_var,
|
|
125
|
+
bg=t.panel_bg,
|
|
126
|
+
fg=t.accent,
|
|
127
|
+
font=(FONT_MONO, 28, "bold"),
|
|
128
|
+
).pack(pady=(6, 0))
|
|
129
|
+
|
|
130
|
+
self._date_var = tk.StringVar(value="")
|
|
131
|
+
tk.Label(
|
|
132
|
+
tab,
|
|
133
|
+
textvariable=self._date_var,
|
|
134
|
+
bg=t.panel_bg,
|
|
135
|
+
fg=t.fg_muted,
|
|
136
|
+
font=(FONT_UI, 9),
|
|
137
|
+
).pack(pady=(2, 8))
|
|
138
|
+
|
|
139
|
+
def _draw_clock(self, now: datetime) -> None:
|
|
140
|
+
"""Redesenha o relógio analógico."""
|
|
141
|
+
cv = self._canvas
|
|
142
|
+
t = self._tmgr.theme
|
|
143
|
+
cv.delete("all")
|
|
144
|
+
|
|
145
|
+
cx = cy = r = self._canvas_size // 2
|
|
146
|
+
r -= 10
|
|
147
|
+
|
|
148
|
+
cv.create_oval(
|
|
149
|
+
cx - r, cy - r, cx + r, cy + r, fill=t.editor_bg, outline=t.border, width=2
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
for h in range(12):
|
|
153
|
+
angle = math.radians(h * 30 - 90)
|
|
154
|
+
r_outer = r - 6
|
|
155
|
+
r_inner = r - (18 if h % 3 == 0 else 12)
|
|
156
|
+
x1 = cx + r_outer * math.cos(angle)
|
|
157
|
+
y1 = cy + r_outer * math.sin(angle)
|
|
158
|
+
x2 = cx + r_inner * math.cos(angle)
|
|
159
|
+
y2 = cy + r_inner * math.sin(angle)
|
|
160
|
+
w = 3 if h % 3 == 0 else 1
|
|
161
|
+
cv.create_line(
|
|
162
|
+
x1,
|
|
163
|
+
y1,
|
|
164
|
+
x2,
|
|
165
|
+
y2,
|
|
166
|
+
fill=t.fg_muted if h % 3 != 0 else t.fg,
|
|
167
|
+
width=w,
|
|
168
|
+
capstyle="round",
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
sec = now.second + now.microsecond / 1e6
|
|
172
|
+
minu = now.minute + sec / 60
|
|
173
|
+
hour = now.hour % 12 + minu / 60
|
|
174
|
+
|
|
175
|
+
def _hand(deg: float, length: float, width: int, color: str) -> None:
|
|
176
|
+
angle = math.radians(deg - 90)
|
|
177
|
+
x = cx + length * math.cos(angle)
|
|
178
|
+
y = cy + length * math.sin(angle)
|
|
179
|
+
cv.create_line(cx, cy, x, y, fill=color,
|
|
180
|
+
width=width, capstyle="round")
|
|
181
|
+
|
|
182
|
+
_hand(hour * 30, r * 0.52, 5, t.fg)
|
|
183
|
+
_hand(minu * 6, r * 0.72, 3, t.fg)
|
|
184
|
+
_hand(sec * 6, r * 0.85, 1, t.accent)
|
|
185
|
+
|
|
186
|
+
cv.create_oval(cx - 5, cy - 5, cx + 5, cy +
|
|
187
|
+
5, fill=t.accent, outline="")
|
|
188
|
+
cv.create_oval(cx - 2, cy - 2, cx + 2, cy +
|
|
189
|
+
2, fill=t.panel_bg, outline="")
|
|
190
|
+
|
|
191
|
+
def _build_alarms_tab(self, t: Any) -> None:
|
|
192
|
+
tab = self._tab_alarms
|
|
193
|
+
|
|
194
|
+
progress_bar = tk.Frame(tab, bg=t.panel_bg)
|
|
195
|
+
progress_bar.pack(fill="x", padx=8, pady=(8, 4))
|
|
196
|
+
tk.Label(
|
|
197
|
+
progress_bar,
|
|
198
|
+
text=_t("clock.alarms_title", "Meus alarmes"),
|
|
199
|
+
bg=t.panel_bg,
|
|
200
|
+
fg=t.fg,
|
|
201
|
+
font=(FONT_UI, 10, "bold"),
|
|
202
|
+
).pack(side="left")
|
|
203
|
+
tk.Button(
|
|
204
|
+
progress_bar,
|
|
205
|
+
text=_t("clock.alarm_add", "+ Adicionar"),
|
|
206
|
+
bg=t.accent,
|
|
207
|
+
fg="#FFF",
|
|
208
|
+
relief="flat",
|
|
209
|
+
font=(FONT_UI, 9),
|
|
210
|
+
command=self._add_alarm,
|
|
211
|
+
).pack(side="right")
|
|
212
|
+
|
|
213
|
+
list_frame = tk.Frame(tab, bg=t.panel_bg)
|
|
214
|
+
list_frame.pack(fill="both", expand=True, padx=8)
|
|
215
|
+
self._alarm_list_frame = list_frame
|
|
216
|
+
self._refresh_alarm_list(t)
|
|
217
|
+
|
|
218
|
+
def _refresh_alarm_list(self, t: Any | None = None) -> None:
|
|
219
|
+
if t is None:
|
|
220
|
+
t = self._tmgr.theme
|
|
221
|
+
for w in self._alarm_list_frame.winfo_children():
|
|
222
|
+
w.destroy()
|
|
223
|
+
if not self._alarms:
|
|
224
|
+
tk.Label(
|
|
225
|
+
self._alarm_list_frame,
|
|
226
|
+
text=_t("clock.no_alarms", "Nenhum alarme cadastrado."),
|
|
227
|
+
bg=t.panel_bg,
|
|
228
|
+
fg=t.fg_muted,
|
|
229
|
+
font=(FONT_UI, 9),
|
|
230
|
+
).pack(pady=20)
|
|
231
|
+
return
|
|
232
|
+
for idx, alarm in enumerate(self._alarms):
|
|
233
|
+
self._build_alarm_row(t, idx, alarm)
|
|
234
|
+
|
|
235
|
+
def _build_alarm_row(self, t: Any, idx: int, alarm: Alarm) -> None:
|
|
236
|
+
row = tk.Frame(
|
|
237
|
+
self._alarm_list_frame,
|
|
238
|
+
bg=t.sidebar_bg,
|
|
239
|
+
highlightthickness=1,
|
|
240
|
+
highlightbackground=t.border,
|
|
241
|
+
)
|
|
242
|
+
row.pack(fill="x", pady=3)
|
|
243
|
+
|
|
244
|
+
color_fg = t.accent if alarm.enabled else t.fg_muted
|
|
245
|
+
time_str = f"{alarm.hour:02d}:{alarm.minute:02d}"
|
|
246
|
+
tk.Label(
|
|
247
|
+
row,
|
|
248
|
+
text=time_str,
|
|
249
|
+
bg=t.sidebar_bg,
|
|
250
|
+
fg=color_fg,
|
|
251
|
+
font=(FONT_MONO, 20, "bold"),
|
|
252
|
+
).pack(side="left", padx=(12, 8), pady=8)
|
|
253
|
+
|
|
254
|
+
info = tk.Frame(row, bg=t.sidebar_bg)
|
|
255
|
+
info.pack(side="left", fill="x", expand=True, pady=8)
|
|
256
|
+
|
|
257
|
+
lbl_text = alarm.label or _t("clock.alarm_label_default", "Alarme")
|
|
258
|
+
tk.Label(info, text=lbl_text, bg=t.sidebar_bg, fg=t.fg, font=(FONT_UI, 9)).pack(
|
|
259
|
+
anchor="w"
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
repeat_txt = (
|
|
263
|
+
_t("clock.alarm_daily", "Diário")
|
|
264
|
+
if alarm.repeat
|
|
265
|
+
else _t("clock.alarm_once", "Uma vez")
|
|
266
|
+
)
|
|
267
|
+
tk.Label(
|
|
268
|
+
info, text=repeat_txt, bg=t.sidebar_bg, fg=t.fg_muted, font=(
|
|
269
|
+
FONT_UI, 7)
|
|
270
|
+
).pack(anchor="w")
|
|
271
|
+
|
|
272
|
+
ctrl = tk.Frame(row, bg=t.sidebar_bg)
|
|
273
|
+
ctrl.pack(side="right", padx=8, pady=8)
|
|
274
|
+
|
|
275
|
+
toggle_text = "●" if alarm.enabled else "○"
|
|
276
|
+
toggle_color = t.accent if alarm.enabled else t.fg_muted
|
|
277
|
+
tgl = tk.Label(
|
|
278
|
+
ctrl,
|
|
279
|
+
text=toggle_text,
|
|
280
|
+
bg=t.sidebar_bg,
|
|
281
|
+
fg=toggle_color,
|
|
282
|
+
font=(FONT_UI, 14),
|
|
283
|
+
cursor="hand2",
|
|
284
|
+
)
|
|
285
|
+
tgl.pack(side="left", padx=4)
|
|
286
|
+
tgl.bind("<Button-1>", lambda _, i=idx: self._toggle_alarm(i))
|
|
287
|
+
|
|
288
|
+
del_lbl = tk.Label(
|
|
289
|
+
ctrl,
|
|
290
|
+
text="✕",
|
|
291
|
+
bg=t.sidebar_bg,
|
|
292
|
+
fg=t.fg_muted,
|
|
293
|
+
font=(FONT_UI, 11),
|
|
294
|
+
cursor="hand2",
|
|
295
|
+
)
|
|
296
|
+
del_lbl.pack(side="left", padx=4)
|
|
297
|
+
del_lbl.bind("<Button-1>", lambda _, i=idx: self._delete_alarm(i))
|
|
298
|
+
|
|
299
|
+
def _add_alarm(self) -> None:
|
|
300
|
+
_AlarmDialog(self, self._tmgr, on_save=self._on_alarm_saved)
|
|
301
|
+
|
|
302
|
+
def _on_alarm_saved(self, alarm: Alarm) -> None:
|
|
303
|
+
self._alarms.append(alarm)
|
|
304
|
+
_save_alarms(self._alarms)
|
|
305
|
+
self._refresh_alarm_list()
|
|
306
|
+
|
|
307
|
+
def _toggle_alarm(self, idx: int) -> None:
|
|
308
|
+
if 0 <= idx < len(self._alarms):
|
|
309
|
+
self._alarms[idx].enabled = not self._alarms[idx].enabled
|
|
310
|
+
_save_alarms(self._alarms)
|
|
311
|
+
self._refresh_alarm_list()
|
|
312
|
+
|
|
313
|
+
def _delete_alarm(self, idx: int) -> None:
|
|
314
|
+
if 0 <= idx < len(self._alarms):
|
|
315
|
+
self._alarms.pop(idx)
|
|
316
|
+
_save_alarms(self._alarms)
|
|
317
|
+
self._refresh_alarm_list()
|
|
318
|
+
|
|
319
|
+
def _build_stopwatch_tab(self, t: Any) -> None:
|
|
320
|
+
tab = self._tab_stopwatch
|
|
321
|
+
|
|
322
|
+
disp = tk.Frame(tab, bg=t.panel_bg)
|
|
323
|
+
disp.pack(fill="x", pady=(20, 8))
|
|
324
|
+
|
|
325
|
+
self._sw_var = tk.StringVar(value="00:00.000")
|
|
326
|
+
tk.Label(
|
|
327
|
+
disp,
|
|
328
|
+
textvariable=self._sw_var,
|
|
329
|
+
bg=t.panel_bg,
|
|
330
|
+
fg=t.accent,
|
|
331
|
+
font=(FONT_MONO, 36, "bold"),
|
|
332
|
+
).pack()
|
|
333
|
+
|
|
334
|
+
self._sw_status_var = tk.StringVar(
|
|
335
|
+
value=_t("clock.sw_stopped", "Parado"))
|
|
336
|
+
tk.Label(
|
|
337
|
+
disp,
|
|
338
|
+
textvariable=self._sw_status_var,
|
|
339
|
+
bg=t.panel_bg,
|
|
340
|
+
fg=t.fg_muted,
|
|
341
|
+
font=(FONT_UI, 8),
|
|
342
|
+
).pack()
|
|
343
|
+
|
|
344
|
+
btn_row = tk.Frame(tab, bg=t.panel_bg)
|
|
345
|
+
btn_row.pack(pady=(4, 12))
|
|
346
|
+
|
|
347
|
+
def _btn(text: str, cmd: Callable, bg: str, fg: str) -> tk.Label:
|
|
348
|
+
lbl = tk.Label(
|
|
349
|
+
btn_row,
|
|
350
|
+
text=text,
|
|
351
|
+
bg=bg,
|
|
352
|
+
fg=fg,
|
|
353
|
+
font=(FONT_UI, 10, "bold"),
|
|
354
|
+
padx=14,
|
|
355
|
+
pady=6,
|
|
356
|
+
cursor="hand2",
|
|
357
|
+
relief="flat",
|
|
358
|
+
)
|
|
359
|
+
lbl.pack(side="left", padx=4)
|
|
360
|
+
lbl.bind("<Button-1>", lambda _: cmd())
|
|
361
|
+
lbl.bind("<Enter>", lambda _: lbl.config(bg=t.accent, fg="#FFF"))
|
|
362
|
+
lbl.bind("<Leave>", lambda _: lbl.config(bg=bg, fg=fg))
|
|
363
|
+
return lbl
|
|
364
|
+
|
|
365
|
+
self._sw_start_btn = _btn(
|
|
366
|
+
_t("clock.sw_start", "▶ Iniciar"),
|
|
367
|
+
self._sw_start,
|
|
368
|
+
t.accent,
|
|
369
|
+
"#FFF",
|
|
370
|
+
)
|
|
371
|
+
self._sw_lap_btn = _btn(
|
|
372
|
+
_t("clock.sw_lap", "⊕ Volta"),
|
|
373
|
+
self._sw_lap,
|
|
374
|
+
t.sidebar_bg,
|
|
375
|
+
t.fg,
|
|
376
|
+
)
|
|
377
|
+
self._sw_reset_btn = _btn(
|
|
378
|
+
_t("clock.sw_reset", "⟳ Zerar"),
|
|
379
|
+
self._sw_reset,
|
|
380
|
+
t.sidebar_bg,
|
|
381
|
+
t.fg,
|
|
382
|
+
)
|
|
383
|
+
self._sw_lap_btn.config(state="disabled")
|
|
384
|
+
self._sw_reset_btn.config(state="disabled")
|
|
385
|
+
|
|
386
|
+
sep = tk.Frame(tab, bg=t.border, height=1)
|
|
387
|
+
sep.pack(fill="x", padx=8)
|
|
388
|
+
|
|
389
|
+
laps_hdr = tk.Frame(tab, bg=t.panel_bg)
|
|
390
|
+
laps_hdr.pack(fill="x", padx=12, pady=(6, 2))
|
|
391
|
+
tk.Label(
|
|
392
|
+
laps_hdr,
|
|
393
|
+
text=_t("clock.sw_laps", "Voltas"),
|
|
394
|
+
bg=t.panel_bg,
|
|
395
|
+
fg=t.fg_muted,
|
|
396
|
+
font=(FONT_UI, 8, "bold"),
|
|
397
|
+
).pack(side="left")
|
|
398
|
+
clear_lbl = tk.Label(
|
|
399
|
+
laps_hdr,
|
|
400
|
+
text=_t("clock.sw_clear_laps", "Limpar"),
|
|
401
|
+
bg=t.panel_bg,
|
|
402
|
+
fg=t.fg_muted,
|
|
403
|
+
font=(FONT_UI, 8),
|
|
404
|
+
cursor="hand2",
|
|
405
|
+
)
|
|
406
|
+
clear_lbl.pack(side="right")
|
|
407
|
+
clear_lbl.bind("<Button-1>", lambda _: self._sw_clear_laps())
|
|
408
|
+
|
|
409
|
+
laps_outer = tk.Frame(tab, bg=t.panel_bg)
|
|
410
|
+
laps_outer.pack(fill="both", expand=True, padx=8, pady=(0, 8))
|
|
411
|
+
|
|
412
|
+
scrollbar = ttk.Scrollbar(laps_outer, orient="vertical")
|
|
413
|
+
self._laps_lb = tk.Listbox(
|
|
414
|
+
laps_outer,
|
|
415
|
+
bg=t.editor_bg,
|
|
416
|
+
fg=t.fg,
|
|
417
|
+
font=(FONT_MONO, 10),
|
|
418
|
+
relief="flat",
|
|
419
|
+
bd=0,
|
|
420
|
+
activestyle="none",
|
|
421
|
+
selectbackground=t.accent,
|
|
422
|
+
yscrollcommand=scrollbar.set,
|
|
423
|
+
)
|
|
424
|
+
scrollbar.config(command=self._laps_lb.yview)
|
|
425
|
+
self._laps_lb.pack(side="left", fill="both", expand=True)
|
|
426
|
+
scrollbar.pack(side="right", fill="y")
|
|
427
|
+
|
|
428
|
+
def _sw_fmt(self, elapsed: float) -> str:
|
|
429
|
+
"""Formata elapsed (segundos float) como MM:SS.mmm."""
|
|
430
|
+
total_ms = int(elapsed * 1000)
|
|
431
|
+
ms = total_ms % 1000
|
|
432
|
+
total_s = total_ms // 1000
|
|
433
|
+
sec = total_s % 60
|
|
434
|
+
minu = total_s // 60
|
|
435
|
+
return f"{minu:02d}:{sec:02d}.{ms:03d}"
|
|
436
|
+
|
|
437
|
+
def _sw_start(self) -> None:
|
|
438
|
+
if self._sw_running:
|
|
439
|
+
self._sw_elapsed += time.monotonic() - self._sw_start_ts
|
|
440
|
+
self._sw_running = False
|
|
441
|
+
self._sw_start_btn.config(
|
|
442
|
+
text=_t("clock.sw_resume", "▶ Continuar"))
|
|
443
|
+
self._sw_status_var.set(_t("clock.sw_paused", "Pausado"))
|
|
444
|
+
else:
|
|
445
|
+
self._sw_start_ts = time.monotonic()
|
|
446
|
+
self._sw_running = True
|
|
447
|
+
self._sw_start_btn.config(text=_t("clock.sw_pause", "⏸ Pausar"))
|
|
448
|
+
self._sw_status_var.set(_t("clock.sw_running", "Rodando"))
|
|
449
|
+
self._sw_lap_btn.config(state="normal")
|
|
450
|
+
self._sw_reset_btn.config(state="normal")
|
|
451
|
+
|
|
452
|
+
def _sw_lap(self) -> None:
|
|
453
|
+
if not self._sw_running:
|
|
454
|
+
return
|
|
455
|
+
elapsed = self._sw_elapsed + (time.monotonic() - self._sw_start_ts)
|
|
456
|
+
self._sw_laps.append(elapsed)
|
|
457
|
+
n = len(self._sw_laps)
|
|
458
|
+
prev = self._sw_laps[-2] if n > 1 else 0.0
|
|
459
|
+
lap_time = elapsed - prev
|
|
460
|
+
self._laps_lb.insert(
|
|
461
|
+
"end",
|
|
462
|
+
f" #{n:02d} {self._sw_fmt(lap_time)} ({self._sw_fmt(elapsed)})",
|
|
463
|
+
)
|
|
464
|
+
self._laps_lb.see("end")
|
|
465
|
+
|
|
466
|
+
def _sw_reset(self) -> None:
|
|
467
|
+
self._sw_running = False
|
|
468
|
+
self._sw_elapsed = 0.0
|
|
469
|
+
self._sw_laps.clear()
|
|
470
|
+
self._sw_var.set("00:00.000")
|
|
471
|
+
self._sw_status_var.set(_t("clock.sw_stopped", "Parado"))
|
|
472
|
+
self._sw_start_btn.config(text=_t("clock.sw_start", "▶ Iniciar"))
|
|
473
|
+
self._sw_lap_btn.config(state="disabled")
|
|
474
|
+
self._sw_reset_btn.config(state="disabled")
|
|
475
|
+
|
|
476
|
+
def _sw_clear_laps(self) -> None:
|
|
477
|
+
self._sw_laps.clear()
|
|
478
|
+
self._laps_lb.delete(0, "end")
|
|
479
|
+
|
|
480
|
+
def _tick(self) -> None:
|
|
481
|
+
"""Loop principal a ~10fps para relógio e cronômetro."""
|
|
482
|
+
if not self._alive:
|
|
483
|
+
return
|
|
484
|
+
now = datetime.now()
|
|
485
|
+
|
|
486
|
+
self._draw_clock(now)
|
|
487
|
+
self._digital_var.set(now.strftime("%H:%M:%S"))
|
|
488
|
+
locale = (
|
|
489
|
+
self._tmgr.i18n.get_locale() if hasattr(self._tmgr, "i18n") else "pt-BR"
|
|
490
|
+
)
|
|
491
|
+
self._date_var.set(_format_date(now, locale))
|
|
492
|
+
|
|
493
|
+
if self._sw_running:
|
|
494
|
+
elapsed = self._sw_elapsed + (time.monotonic() - self._sw_start_ts)
|
|
495
|
+
self._sw_var.set(self._sw_fmt(elapsed))
|
|
496
|
+
|
|
497
|
+
self._check_alarms(now)
|
|
498
|
+
|
|
499
|
+
self.after(100, self._tick)
|
|
500
|
+
|
|
501
|
+
def _check_alarms(self, now: datetime) -> None:
|
|
502
|
+
key = now.hour * 60 + now.minute
|
|
503
|
+
if now.second >= 5:
|
|
504
|
+
self._alarm_fired_this_minute.discard(key)
|
|
505
|
+
return
|
|
506
|
+
for alarm in self._alarms:
|
|
507
|
+
if (
|
|
508
|
+
alarm.enabled
|
|
509
|
+
and alarm.hour == now.hour
|
|
510
|
+
and alarm.minute == now.minute
|
|
511
|
+
and key not in self._alarm_fired_this_minute
|
|
512
|
+
):
|
|
513
|
+
self._alarm_fired_this_minute.add(key)
|
|
514
|
+
self._fire_alarm(alarm)
|
|
515
|
+
if not alarm.repeat:
|
|
516
|
+
alarm.enabled = False
|
|
517
|
+
_save_alarms(self._alarms)
|
|
518
|
+
self.after(100, self._refresh_alarm_list)
|
|
519
|
+
|
|
520
|
+
def _fire_alarm(self, alarm: Alarm) -> None:
|
|
521
|
+
label = alarm.label or _t("clock.alarm_label_default", "Alarme")
|
|
522
|
+
time_str = f"{alarm.hour:02d}:{alarm.minute:02d}"
|
|
523
|
+
messagebox.showinfo(
|
|
524
|
+
_t("clock.alarm_fired_title", "⏰ Alarme"),
|
|
525
|
+
_t("clock.alarm_fired_msg", f"{label} - {time_str}"),
|
|
526
|
+
parent=self,
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
def destroy(self) -> None:
|
|
530
|
+
"""Cancela timers pendentes e destrói o painel."""
|
|
531
|
+
self._alive = False
|
|
532
|
+
super().destroy()
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
def _format_date(dt: datetime, locale: str) -> str:
|
|
536
|
+
"""Formata data com base no locale ativo."""
|
|
537
|
+
week_days_pt = [
|
|
538
|
+
"Segunda",
|
|
539
|
+
"Terça",
|
|
540
|
+
"Quarta",
|
|
541
|
+
"Quinta",
|
|
542
|
+
"Sexta",
|
|
543
|
+
"Sábado",
|
|
544
|
+
"Domingo",
|
|
545
|
+
]
|
|
546
|
+
months_pt = [
|
|
547
|
+
"",
|
|
548
|
+
"Janeiro",
|
|
549
|
+
"Fevereiro",
|
|
550
|
+
"Março",
|
|
551
|
+
"Abril",
|
|
552
|
+
"Maio",
|
|
553
|
+
"Junho",
|
|
554
|
+
"Julho",
|
|
555
|
+
"Agosto",
|
|
556
|
+
"Setembro",
|
|
557
|
+
"Outubro",
|
|
558
|
+
"Novembro",
|
|
559
|
+
"Dezembro",
|
|
560
|
+
]
|
|
561
|
+
|
|
562
|
+
if locale.startswith("pt"):
|
|
563
|
+
wd = week_days_pt[dt.weekday()]
|
|
564
|
+
return f"{wd}, {dt.day} de {months_pt[dt.month]} de {dt.year}"
|
|
565
|
+
if locale.startswith("es"):
|
|
566
|
+
dias = [
|
|
567
|
+
"Lunes",
|
|
568
|
+
"Martes",
|
|
569
|
+
"Miércoles",
|
|
570
|
+
"Jueves",
|
|
571
|
+
"Viernes",
|
|
572
|
+
"Sábado",
|
|
573
|
+
"Domingo",
|
|
574
|
+
]
|
|
575
|
+
meses = [
|
|
576
|
+
"",
|
|
577
|
+
"enero",
|
|
578
|
+
"febrero",
|
|
579
|
+
"marzo",
|
|
580
|
+
"abril",
|
|
581
|
+
"mayo",
|
|
582
|
+
"junio",
|
|
583
|
+
"julio",
|
|
584
|
+
"agosto",
|
|
585
|
+
"septiembre",
|
|
586
|
+
"octubre",
|
|
587
|
+
"noviembre",
|
|
588
|
+
"diciembre",
|
|
589
|
+
]
|
|
590
|
+
return f"{dias[dt.weekday()]}, {dt.day} de {meses[dt.month]} de {dt.year}"
|
|
591
|
+
if locale.startswith("fr"):
|
|
592
|
+
jours = [
|
|
593
|
+
"Lundi",
|
|
594
|
+
"Mardi",
|
|
595
|
+
"Mercredi",
|
|
596
|
+
"Jeudi",
|
|
597
|
+
"Vendredi",
|
|
598
|
+
"Samedi",
|
|
599
|
+
"Dimanche",
|
|
600
|
+
]
|
|
601
|
+
mois = [
|
|
602
|
+
"",
|
|
603
|
+
"janvier",
|
|
604
|
+
"février",
|
|
605
|
+
"mars",
|
|
606
|
+
"avril",
|
|
607
|
+
"mai",
|
|
608
|
+
"juin",
|
|
609
|
+
"juillet",
|
|
610
|
+
"août",
|
|
611
|
+
"septembre",
|
|
612
|
+
"octobre",
|
|
613
|
+
"novembre",
|
|
614
|
+
"décembre",
|
|
615
|
+
]
|
|
616
|
+
return f"{jours[dt.weekday()]}, {dt.day} {mois[dt.month]} {dt.year}"
|
|
617
|
+
if locale.startswith("de"):
|
|
618
|
+
wochentage = [
|
|
619
|
+
"Montag",
|
|
620
|
+
"Dienstag",
|
|
621
|
+
"Mittwoch",
|
|
622
|
+
"Donnerstag",
|
|
623
|
+
"Freitag",
|
|
624
|
+
"Samstag",
|
|
625
|
+
"Sonntag",
|
|
626
|
+
]
|
|
627
|
+
monate = [
|
|
628
|
+
"",
|
|
629
|
+
"Januar",
|
|
630
|
+
"Februar",
|
|
631
|
+
"März",
|
|
632
|
+
"April",
|
|
633
|
+
"Mai",
|
|
634
|
+
"Juni",
|
|
635
|
+
"Juli",
|
|
636
|
+
"August",
|
|
637
|
+
"September",
|
|
638
|
+
"Oktober",
|
|
639
|
+
"November",
|
|
640
|
+
"Dezember",
|
|
641
|
+
]
|
|
642
|
+
return f"{wochentage[dt.weekday()]}, {dt.day}. {monate[dt.month]} {dt.year}"
|
|
643
|
+
return dt.strftime("%A, %B %d, %Y")
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
class _AlarmDialog(tk.Toplevel):
|
|
647
|
+
"""Diálogo para criar um novo alarme."""
|
|
648
|
+
|
|
649
|
+
def __init__(
|
|
650
|
+
self, parent: tk.Widget, tmgr: Any, on_save: Callable[[Alarm], None]
|
|
651
|
+
) -> None:
|
|
652
|
+
super().__init__(parent)
|
|
653
|
+
self._tmgr = tmgr
|
|
654
|
+
self._on_save = on_save
|
|
655
|
+
t = tmgr.theme
|
|
656
|
+
|
|
657
|
+
self.title(_t("clock.alarm_dialog_title", "Novo Alarme"))
|
|
658
|
+
self.resizable(False, False)
|
|
659
|
+
self.config(bg=t.panel_bg)
|
|
660
|
+
safe_grab_set(self)
|
|
661
|
+
|
|
662
|
+
self._build(t)
|
|
663
|
+
self.update_idletasks()
|
|
664
|
+
_center_window(self)
|
|
665
|
+
|
|
666
|
+
def _build(self, t: Any) -> None:
|
|
667
|
+
pad = {"padx": 16, "pady": 6}
|
|
668
|
+
|
|
669
|
+
hr_row = tk.Frame(self, bg=t.panel_bg)
|
|
670
|
+
hr_row.pack(fill="x", **pad)
|
|
671
|
+
tk.Label(
|
|
672
|
+
hr_row,
|
|
673
|
+
text=_t("clock.alarm_hour", "Hora (0-23)"),
|
|
674
|
+
bg=t.panel_bg,
|
|
675
|
+
fg=t.fg_muted,
|
|
676
|
+
font=(FONT_UI, 9),
|
|
677
|
+
width=18,
|
|
678
|
+
anchor="w",
|
|
679
|
+
).pack(side="left")
|
|
680
|
+
self._hour_var = tk.StringVar(value="08")
|
|
681
|
+
tk.Entry(
|
|
682
|
+
hr_row,
|
|
683
|
+
textvariable=self._hour_var,
|
|
684
|
+
bg=t.editor_bg,
|
|
685
|
+
fg=t.fg,
|
|
686
|
+
insertbackground=t.cursor,
|
|
687
|
+
relief="flat",
|
|
688
|
+
font=(FONT_MONO, 11),
|
|
689
|
+
width=5,
|
|
690
|
+
).pack(side="left", padx=4)
|
|
691
|
+
|
|
692
|
+
mn_row = tk.Frame(self, bg=t.panel_bg)
|
|
693
|
+
mn_row.pack(fill="x", **pad)
|
|
694
|
+
tk.Label(
|
|
695
|
+
mn_row,
|
|
696
|
+
text=_t("clock.alarm_minute", "Minuto (0-59)"),
|
|
697
|
+
bg=t.panel_bg,
|
|
698
|
+
fg=t.fg_muted,
|
|
699
|
+
font=(FONT_UI, 9),
|
|
700
|
+
width=18,
|
|
701
|
+
anchor="w",
|
|
702
|
+
).pack(side="left")
|
|
703
|
+
self._minute_var = tk.StringVar(value="00")
|
|
704
|
+
tk.Entry(
|
|
705
|
+
mn_row,
|
|
706
|
+
textvariable=self._minute_var,
|
|
707
|
+
bg=t.editor_bg,
|
|
708
|
+
fg=t.fg,
|
|
709
|
+
insertbackground=t.cursor,
|
|
710
|
+
relief="flat",
|
|
711
|
+
font=(FONT_MONO, 11),
|
|
712
|
+
width=5,
|
|
713
|
+
).pack(side="left", padx=4)
|
|
714
|
+
|
|
715
|
+
lbl_row = tk.Frame(self, bg=t.panel_bg)
|
|
716
|
+
lbl_row.pack(fill="x", **pad)
|
|
717
|
+
tk.Label(
|
|
718
|
+
lbl_row,
|
|
719
|
+
text=_t("clock.alarm_label", "Rótulo"),
|
|
720
|
+
bg=t.panel_bg,
|
|
721
|
+
fg=t.fg_muted,
|
|
722
|
+
font=(FONT_UI, 9),
|
|
723
|
+
width=18,
|
|
724
|
+
anchor="w",
|
|
725
|
+
).pack(side="left")
|
|
726
|
+
self._label_var = tk.StringVar(value="")
|
|
727
|
+
tk.Entry(
|
|
728
|
+
lbl_row,
|
|
729
|
+
textvariable=self._label_var,
|
|
730
|
+
bg=t.editor_bg,
|
|
731
|
+
fg=t.fg,
|
|
732
|
+
insertbackground=t.cursor,
|
|
733
|
+
relief="flat",
|
|
734
|
+
font=(FONT_UI, 10),
|
|
735
|
+
width=20,
|
|
736
|
+
).pack(side="left", padx=4)
|
|
737
|
+
|
|
738
|
+
rep_row = tk.Frame(self, bg=t.panel_bg)
|
|
739
|
+
rep_row.pack(fill="x", **pad)
|
|
740
|
+
self._repeat_var = tk.BooleanVar(value=False)
|
|
741
|
+
tk.Checkbutton(
|
|
742
|
+
rep_row,
|
|
743
|
+
text=_t("clock.alarm_repeat", "Repetir todos os dias"),
|
|
744
|
+
variable=self._repeat_var,
|
|
745
|
+
bg=t.panel_bg,
|
|
746
|
+
fg=t.fg,
|
|
747
|
+
selectcolor=t.editor_bg,
|
|
748
|
+
activebackground=t.panel_bg,
|
|
749
|
+
font=(FONT_UI, 9),
|
|
750
|
+
).pack(anchor="w")
|
|
751
|
+
|
|
752
|
+
btn_row = tk.Frame(self, bg=t.panel_bg)
|
|
753
|
+
btn_row.pack(fill="x", padx=16, pady=(4, 12))
|
|
754
|
+
|
|
755
|
+
tk.Button(
|
|
756
|
+
btn_row,
|
|
757
|
+
text=_t("clock.alarm_save", "Salvar"),
|
|
758
|
+
command=self._save,
|
|
759
|
+
bg=t.accent,
|
|
760
|
+
fg="#FFF",
|
|
761
|
+
relief="flat",
|
|
762
|
+
font=(FONT_UI, 10),
|
|
763
|
+
).pack(side="right", padx=4)
|
|
764
|
+
tk.Button(
|
|
765
|
+
btn_row,
|
|
766
|
+
text=_t("clock.alarm_cancel", "Cancelar"),
|
|
767
|
+
command=self.destroy,
|
|
768
|
+
bg=t.sidebar_bg,
|
|
769
|
+
fg=t.fg,
|
|
770
|
+
relief="flat",
|
|
771
|
+
font=(FONT_UI, 10),
|
|
772
|
+
).pack(side="right")
|
|
773
|
+
|
|
774
|
+
def _save(self) -> None:
|
|
775
|
+
try:
|
|
776
|
+
hour = int(self._hour_var.get())
|
|
777
|
+
minute = int(self._minute_var.get())
|
|
778
|
+
except ValueError:
|
|
779
|
+
messagebox.showwarning(
|
|
780
|
+
_t("clock.alarm_invalid_title", "Valor inválido"),
|
|
781
|
+
_t(
|
|
782
|
+
"clock.alarm_invalid_msg",
|
|
783
|
+
"Use números inteiros para hora e minuto.",
|
|
784
|
+
),
|
|
785
|
+
parent=self,
|
|
786
|
+
)
|
|
787
|
+
return
|
|
788
|
+
if not (0 <= hour <= 23 and 0 <= minute <= 59):
|
|
789
|
+
messagebox.showwarning(
|
|
790
|
+
_t("clock.alarm_invalid_title", "Valor inválido"),
|
|
791
|
+
_t("clock.alarm_range_msg", "Hora: 0–23 | Minuto: 0–59."),
|
|
792
|
+
parent=self,
|
|
793
|
+
)
|
|
794
|
+
return
|
|
795
|
+
alarm = Alarm(
|
|
796
|
+
label=self._label_var.get().strip(),
|
|
797
|
+
hour=hour,
|
|
798
|
+
minute=minute,
|
|
799
|
+
repeat=self._repeat_var.get(),
|
|
800
|
+
)
|
|
801
|
+
self._on_save(alarm)
|
|
802
|
+
self.destroy()
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
def _center_window(win: tk.Toplevel) -> None:
|
|
806
|
+
w = win.winfo_reqwidth()
|
|
807
|
+
h = win.winfo_reqheight()
|
|
808
|
+
x = (win.winfo_screenwidth() - w) // 2
|
|
809
|
+
y = (win.winfo_screenheight() - h) // 2
|
|
810
|
+
win.geometry(f"{w}x{h}+{x}+{y}")
|