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.
Files changed (329) hide show
  1. codis-1.1.1.dist-info/METADATA +194 -0
  2. codis-1.1.1.dist-info/RECORD +329 -0
  3. codis-1.1.1.dist-info/WHEEL +5 -0
  4. codis-1.1.1.dist-info/entry_points.txt +5 -0
  5. codis-1.1.1.dist-info/licenses/LICENSE +21 -0
  6. codis-1.1.1.dist-info/top_level.txt +2 -0
  7. run.py +190 -0
  8. src/__init__.py +1 -0
  9. src/__main__.py +81 -0
  10. src/_app_build.py +1507 -0
  11. src/_app_editor.py +1274 -0
  12. src/_app_kui.py +825 -0
  13. src/_app_lsp.py +625 -0
  14. src/_app_recovery.py +189 -0
  15. src/_app_settings.py +1385 -0
  16. src/_app_tools.py +2471 -0
  17. src/_app_webpreview.py +126 -0
  18. src/_font_safety.py +127 -0
  19. src/_shells.py +172 -0
  20. src/app.py +1488 -0
  21. src/chat/__init__.py +1 -0
  22. src/chat/adapters/__init__.py +33 -0
  23. src/chat/adapters/base.py +209 -0
  24. src/chat/adapters/discord.py +190 -0
  25. src/chat/adapters/http.py +78 -0
  26. src/chat/adapters/irc.py +360 -0
  27. src/chat/adapters/matrix.py +219 -0
  28. src/chat/adapters/mattermost.py +178 -0
  29. src/chat/adapters/mqtt.py +165 -0
  30. src/chat/adapters/slack.py +204 -0
  31. src/chat/adapters/telegram.py +117 -0
  32. src/chat/adapters/ws.py +154 -0
  33. src/chat/adapters/xmpp.py +337 -0
  34. src/chat/history.py +76 -0
  35. src/chat/models.py +207 -0
  36. src/chat/probe.py +79 -0
  37. src/chat/session.py +446 -0
  38. src/chat/util.py +125 -0
  39. src/collab/__init__.py +1 -0
  40. src/collab/net.py +411 -0
  41. src/collab/ot.py +311 -0
  42. src/collab/session.py +141 -0
  43. src/collab/tk_adapter.py +134 -0
  44. src/config.py +335 -0
  45. src/constants.py +2552 -0
  46. src/dep_catalog.py +446 -0
  47. src/diff/__init__.py +1 -0
  48. src/diff/engine.py +247 -0
  49. src/dpi.py +30 -0
  50. src/editor/__init__.py +1 -0
  51. src/editor/_pane_lsp.py +2937 -0
  52. src/editor/_pane_utils.py +171 -0
  53. src/editor/autocomplete.py +607 -0
  54. src/editor/code_folding.py +836 -0
  55. src/editor/color_preview.py +382 -0
  56. src/editor/complexity_lens.py +281 -0
  57. src/editor/diff_pane.py +623 -0
  58. src/editor/file_watcher.py +144 -0
  59. src/editor/focus_block.py +236 -0
  60. src/editor/heatmap.py +141 -0
  61. src/editor/inlay_hints.py +366 -0
  62. src/editor/inline_blame.py +429 -0
  63. src/editor/kdocs.py +3376 -0
  64. src/editor/large_file.py +488 -0
  65. src/editor/ligatures.py +180 -0
  66. src/editor/line_numbers.py +598 -0
  67. src/editor/minimap.py +691 -0
  68. src/editor/multi_cursor.py +269 -0
  69. src/editor/pane.py +2082 -0
  70. src/editor/rhythm.py +206 -0
  71. src/editor/save_hooks.py +43 -0
  72. src/editor/smart_selection.py +425 -0
  73. src/editor/smart_tips.py +719 -0
  74. src/editor/snippets.py +411 -0
  75. src/editor/sticky_note_gutter.py +410 -0
  76. src/editor/sticky_scroll.py +385 -0
  77. src/editor/suggest.py +464 -0
  78. src/editor/text_transforms.py +310 -0
  79. src/editor/vim_mode.py +1074 -0
  80. src/events/__init__.py +84 -0
  81. src/events/bus.py +427 -0
  82. src/events/correlator.py +244 -0
  83. src/events/kinds.py +125 -0
  84. src/events/pipeline.py +264 -0
  85. src/events/stream.py +416 -0
  86. src/events/window.py +204 -0
  87. src/extcompat/__init__.py +19 -0
  88. src/extcompat/code/__init__.py +13 -0
  89. src/extcompat/code/consent.py +162 -0
  90. src/extcompat/code/host.py +353 -0
  91. src/extcompat/code/hosts/py_host.py +763 -0
  92. src/extcompat/code/locate.py +105 -0
  93. src/extcompat/code/manager.py +325 -0
  94. src/extcompat/code/permissions.py +154 -0
  95. src/extcompat/code/sandbox.py +60 -0
  96. src/extcompat/colors.py +131 -0
  97. src/extcompat/common.py +184 -0
  98. src/extcompat/cson.py +269 -0
  99. src/extcompat/formats/__init__.py +22 -0
  100. src/extcompat/formats/_tm.py +189 -0
  101. src/extcompat/formats/_util.py +31 -0
  102. src/extcompat/formats/base16.py +66 -0
  103. src/extcompat/formats/brackets.py +172 -0
  104. src/extcompat/formats/eclipse.py +193 -0
  105. src/extcompat/formats/emacs.py +361 -0
  106. src/extcompat/formats/geany.py +147 -0
  107. src/extcompat/formats/generic.py +184 -0
  108. src/extcompat/formats/gtksource.py +117 -0
  109. src/extcompat/formats/helix.py +91 -0
  110. src/extcompat/formats/jetbrains.py +343 -0
  111. src/extcompat/formats/kate.py +130 -0
  112. src/extcompat/formats/micro.py +131 -0
  113. src/extcompat/formats/nano.py +111 -0
  114. src/extcompat/formats/notepadpp.py +140 -0
  115. src/extcompat/formats/pulsar.py +165 -0
  116. src/extcompat/formats/pyides.py +163 -0
  117. src/extcompat/formats/sublime.py +340 -0
  118. src/extcompat/jsonc.py +65 -0
  119. src/extcompat/lessish.py +128 -0
  120. src/extcompat/manager.py +122 -0
  121. src/extcompat/market/__init__.py +63 -0
  122. src/extcompat/market/sources.py +211 -0
  123. src/extcompat/model.py +88 -0
  124. src/extcompat/net.py +228 -0
  125. src/extcompat/openvsx.py +63 -0
  126. src/extcompat/readers.py +362 -0
  127. src/extcompat/registry.py +73 -0
  128. src/extcompat/safexml.py +63 -0
  129. src/extcompat/sexp.py +187 -0
  130. src/extcompat/sources.py +105 -0
  131. src/extcompat/store.py +276 -0
  132. src/extcompat/textmate.py +214 -0
  133. src/extcompat/themes.py +487 -0
  134. src/extcompat/yamlite.py +294 -0
  135. src/fileio.py +94 -0
  136. src/fs_ops.py +106 -0
  137. src/i18n.py +233 -0
  138. src/ia/__init__.py +1 -0
  139. src/ia/actions.py +295 -0
  140. src/ia/approval_gate.py +672 -0
  141. src/ia/checkpoints.py +308 -0
  142. src/ia/context_builder.py +921 -0
  143. src/ia/dialdiff.py +408 -0
  144. src/ia/iaspace.py +2078 -0
  145. src/ia/pair.py +296 -0
  146. src/ia/providers.py +954 -0
  147. src/ia/session.py +335 -0
  148. src/ia/toolbox.py +2524 -0
  149. src/launcher_actions.py +204 -0
  150. src/lint/__init__.py +1 -0
  151. src/lint/manager.py +1058 -0
  152. src/locales/.translate_manifest.json +64170 -0
  153. src/locales/de.json +4936 -0
  154. src/locales/en.json +4936 -0
  155. src/locales/es.json +4936 -0
  156. src/locales/fr.json +4936 -0
  157. src/locales/it.json +4936 -0
  158. src/locales/ja.json +4936 -0
  159. src/locales/ko.json +4936 -0
  160. src/locales/nl.json +4936 -0
  161. src/locales/pl.json +4936 -0
  162. src/locales/pt-BR.json +4936 -0
  163. src/locales/ru.json +4936 -0
  164. src/locales/tr.json +4936 -0
  165. src/locales/uk.json +4936 -0
  166. src/locales/zh-CN.json +4936 -0
  167. src/lsp/__init__.py +26 -0
  168. src/lsp/client.py +2300 -0
  169. src/lsp/dap_client.py +480 -0
  170. src/lsp/edits.py +84 -0
  171. src/lsp/framing.py +73 -0
  172. src/lsp/protocol.py +931 -0
  173. src/main.py +260 -0
  174. src/memtrim.py +91 -0
  175. src/plugins/__init__.py +1 -0
  176. src/plugins/api.py +1761 -0
  177. src/plugins/loader.py +571 -0
  178. src/plugins/process_runner.py +519 -0
  179. src/plugins/registry.py +342 -0
  180. src/plugins/safety.py +367 -0
  181. src/plugins/startup.py +195 -0
  182. src/plugins/store.py +1178 -0
  183. src/proc_registry.py +278 -0
  184. src/pyexec.py +394 -0
  185. src/recovery.py +259 -0
  186. src/stall_trace.py +92 -0
  187. src/standalone.py +1070 -0
  188. src/startup_profile.py +35 -0
  189. src/syntax/__init__.py +1 -0
  190. src/syntax/highlighter.py +776 -0
  191. src/syntax/patterns.py +584 -0
  192. src/system_profile.py +430 -0
  193. src/terminal/backends.py +658 -0
  194. src/terminal/internal.py +346 -0
  195. src/terminal/keys.py +138 -0
  196. src/terminal/palette.py +67 -0
  197. src/terminal/session.py +283 -0
  198. src/terminal/shells.py +79 -0
  199. src/terminal/view.py +489 -0
  200. src/terminal/vt.py +870 -0
  201. src/textfmt.py +22 -0
  202. src/theme/__init__.py +1 -0
  203. src/theme/base.py +1281 -0
  204. src/theme/colors.py +49 -0
  205. src/theme/manager.py +602 -0
  206. src/theme/utils.py +312 -0
  207. src/toolbox.py +329 -0
  208. src/trash_core.py +531 -0
  209. src/ui/__init__.py +1 -0
  210. src/ui/_perf_utils.py +285 -0
  211. src/ui/_persistence_utils.py +93 -0
  212. src/ui/accessibility.py +843 -0
  213. src/ui/activity_bar.py +860 -0
  214. src/ui/app_embed.py +434 -0
  215. src/ui/archive_panel.py +608 -0
  216. src/ui/bookmarks.py +314 -0
  217. src/ui/breadcrumb.py +383 -0
  218. src/ui/calculator_panel.py +982 -0
  219. src/ui/calendar_panel.py +1218 -0
  220. src/ui/chat_panel.py +1271 -0
  221. src/ui/chat_profile_dialog.py +278 -0
  222. src/ui/chat_render.py +128 -0
  223. src/ui/clock_panel.py +810 -0
  224. src/ui/code_outline.py +364 -0
  225. src/ui/code_runner.py +729 -0
  226. src/ui/code_stats.py +546 -0
  227. src/ui/collab_panel.py +1009 -0
  228. src/ui/color_picker.py +547 -0
  229. src/ui/command_palette.py +452 -0
  230. src/ui/cursor_manager.py +750 -0
  231. src/ui/custom_keywords_panel.py +413 -0
  232. src/ui/debug_panel.py +1037 -0
  233. src/ui/dependency_graph.py +692 -0
  234. src/ui/diff_panel.py +381 -0
  235. src/ui/docs_panel.py +514 -0
  236. src/ui/doom_embed.py +349 -0
  237. src/ui/dropdown.py +321 -0
  238. src/ui/easter_eggs.py +979 -0
  239. src/ui/env_manager.py +666 -0
  240. src/ui/extcode_bridge.py +215 -0
  241. src/ui/extcode_dialogs.py +412 -0
  242. src/ui/extcompat_dialog.py +583 -0
  243. src/ui/file_timeline.py +319 -0
  244. src/ui/file_tree.py +1208 -0
  245. src/ui/find_in_files.py +1355 -0
  246. src/ui/flowchart_panel.py +727 -0
  247. src/ui/formatter_panel.py +490 -0
  248. src/ui/git_auth.py +763 -0
  249. src/ui/git_clone_dialog.py +487 -0
  250. src/ui/git_panel.py +1483 -0
  251. src/ui/grab_safe.py +84 -0
  252. src/ui/internal_python_dialog.py +98 -0
  253. src/ui/k_ui/__init__.py +1305 -0
  254. src/ui/k_ui/_bgrenderer.py +317 -0
  255. src/ui/k_ui/_colors.py +213 -0
  256. src/ui/k_ui/_dock.py +545 -0
  257. src/ui/k_ui/_easter.py +290 -0
  258. src/ui/k_ui/_engine.py +5448 -0
  259. src/ui/k_ui/_perf.py +333 -0
  260. src/ui/k_ui/_tkutil.py +7 -0
  261. src/ui/k_ui/_tooltip.py +365 -0
  262. src/ui/k_ui/_widgets.py +1204 -0
  263. src/ui/k_ui/_world.py +837 -0
  264. src/ui/key_remapper.py +856 -0
  265. src/ui/launcher.py +1252 -0
  266. src/ui/lazy_panel.py +73 -0
  267. src/ui/macro_recorder.py +610 -0
  268. src/ui/menu_bar.py +898 -0
  269. src/ui/output_panel.py +321 -0
  270. src/ui/paint_canvas.py +1000 -0
  271. src/ui/paint_engine.py +535 -0
  272. src/ui/paint_panel.py +888 -0
  273. src/ui/panel_detach.py +112 -0
  274. src/ui/performance_panel.py +861 -0
  275. src/ui/pip_manager.py +1758 -0
  276. src/ui/plugin_panel.py +1586 -0
  277. src/ui/pomodoro_panel.py +447 -0
  278. src/ui/problems.py +566 -0
  279. src/ui/process_manager.py +1657 -0
  280. src/ui/project_templates.py +775 -0
  281. src/ui/recovery_dialog.py +122 -0
  282. src/ui/regex_playground.py +304 -0
  283. src/ui/remote_adapters.py +1398 -0
  284. src/ui/remote_browser.py +1224 -0
  285. src/ui/remote_profile_dialog.py +342 -0
  286. src/ui/render_panel.py +1293 -0
  287. src/ui/rest_client.py +549 -0
  288. src/ui/scratchpad.py +548 -0
  289. src/ui/search_bar.py +1274 -0
  290. src/ui/settings_editor.py +3349 -0
  291. src/ui/settings_window.py +1554 -0
  292. src/ui/snippets_panel.py +597 -0
  293. src/ui/sql_studio.py +1815 -0
  294. src/ui/status_bar.py +438 -0
  295. src/ui/tab_bar.py +654 -0
  296. src/ui/task_manager.py +1773 -0
  297. src/ui/terminal.py +525 -0
  298. src/ui/theme_preview_panel.py +851 -0
  299. src/ui/thread_safe_tk.py +152 -0
  300. src/ui/time_tracker.py +574 -0
  301. src/ui/tkbind.py +43 -0
  302. src/ui/todo_panel.py +358 -0
  303. src/ui/toolbox_panels.py +658 -0
  304. src/ui/trash_manager.py +657 -0
  305. src/ui/ui_scale.py +294 -0
  306. src/ui/ux_enhancements.py +41 -0
  307. src/ui/web_preview.py +397 -0
  308. src/ui/webdev.py +630 -0
  309. src/ui/welcome.py +567 -0
  310. src/ui/window_embed.py +1500 -0
  311. src/ui/wizard.py +1550 -0
  312. src/ui/workspace_switcher.py +418 -0
  313. src/ui/workspace_trust.py +370 -0
  314. src/ui/zen_audio.py +354 -0
  315. src/ui/zen_media.py +2271 -0
  316. src/ui/zen_media_client.py +303 -0
  317. src/ui/zen_media_host.py +329 -0
  318. src/ui/zen_player.py +907 -0
  319. src/ui/zen_player_widgets.py +700 -0
  320. src/updater/__init__.py +11 -0
  321. src/updater/assets.py +145 -0
  322. src/updater/backup.py +101 -0
  323. src/updater/channel.py +221 -0
  324. src/updater/dialog.py +492 -0
  325. src/updater/integrity.py +111 -0
  326. src/updater/manager.py +727 -0
  327. src/updater/result.py +114 -0
  328. src/venv_runtime.py +531 -0
  329. src/workspace_state.py +25 -0
@@ -0,0 +1,1218 @@
1
+ """Codis - Calendário Integrado.
2
+
3
+ Funcionalidades:
4
+ - Calendário mensal navegável com visual polido
5
+ - Mini-mapa de eventos no grid
6
+ - Anotações e lembretes por data
7
+ - Lista de eventos com horário, cor e descrição
8
+ - Pesquisa de eventos
9
+ - Lembretes com notificação popup
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import contextlib
15
+ import json
16
+ import logging
17
+ import threading
18
+ import time
19
+ import tkinter as tk
20
+ from datetime import date, datetime, timedelta
21
+ from tkinter import messagebox, ttk
22
+ from typing import Any
23
+
24
+ from src.constants import CONFIG_DIR, FONT_UI
25
+ from src.i18n import I18n, _t
26
+ from src.ui._perf_utils import debounce_canvas
27
+ from src.ui.grab_safe import safe_grab_set
28
+
29
+ logger = logging.getLogger("Codis.Calendar")
30
+
31
+ _EVENTS_FILE = CONFIG_DIR / "calendar_events.json"
32
+
33
+ _MONTHS_BY_LOCALE: dict[str, list[str]] = {
34
+ "pt": [
35
+ "",
36
+ "Janeiro",
37
+ "Fevereiro",
38
+ "Março",
39
+ "Abril",
40
+ "Maio",
41
+ "Junho",
42
+ "Julho",
43
+ "Agosto",
44
+ "Setembro",
45
+ "Outubro",
46
+ "Novembro",
47
+ "Dezembro",
48
+ ],
49
+ "es": [
50
+ "",
51
+ "Enero",
52
+ "Febrero",
53
+ "Marzo",
54
+ "Abril",
55
+ "Mayo",
56
+ "Junio",
57
+ "Julio",
58
+ "Agosto",
59
+ "Septiembre",
60
+ "Octubre",
61
+ "Noviembre",
62
+ "Diciembre",
63
+ ],
64
+ "fr": [
65
+ "",
66
+ "Janvier",
67
+ "Février",
68
+ "Mars",
69
+ "Avril",
70
+ "Mai",
71
+ "Juin",
72
+ "Juillet",
73
+ "Août",
74
+ "Septembre",
75
+ "Octobre",
76
+ "Novembre",
77
+ "Décembre",
78
+ ],
79
+ "de": [
80
+ "",
81
+ "Januar",
82
+ "Februar",
83
+ "März",
84
+ "April",
85
+ "Mai",
86
+ "Juni",
87
+ "Juli",
88
+ "August",
89
+ "September",
90
+ "Oktober",
91
+ "November",
92
+ "Dezember",
93
+ ],
94
+ "it": [
95
+ "",
96
+ "Gennaio",
97
+ "Febbraio",
98
+ "Marzo",
99
+ "Aprile",
100
+ "Maggio",
101
+ "Giugno",
102
+ "Luglio",
103
+ "Agosto",
104
+ "Settembre",
105
+ "Ottobre",
106
+ "Novembre",
107
+ "Dicembre",
108
+ ],
109
+ "pl": [
110
+ "",
111
+ "Styczeń",
112
+ "Luty",
113
+ "Marzec",
114
+ "Kwiecień",
115
+ "Maj",
116
+ "Czerwiec",
117
+ "Lipiec",
118
+ "Sierpień",
119
+ "Wrzesień",
120
+ "Październik",
121
+ "Listopad",
122
+ "Grudzień",
123
+ ],
124
+ "en": [
125
+ "",
126
+ "January",
127
+ "February",
128
+ "March",
129
+ "April",
130
+ "May",
131
+ "June",
132
+ "July",
133
+ "August",
134
+ "September",
135
+ "October",
136
+ "November",
137
+ "December",
138
+ ],
139
+ }
140
+ _MONTHS_SHORT_BY_LOCALE: dict[str, list[str]] = {
141
+ "pt": [
142
+ "",
143
+ "Jan",
144
+ "Fev",
145
+ "Mar",
146
+ "Abr",
147
+ "Mai",
148
+ "Jun",
149
+ "Jul",
150
+ "Ago",
151
+ "Set",
152
+ "Out",
153
+ "Nov",
154
+ "Dez",
155
+ ],
156
+ "es": [
157
+ "",
158
+ "Ene",
159
+ "Feb",
160
+ "Mar",
161
+ "Abr",
162
+ "May",
163
+ "Jun",
164
+ "Jul",
165
+ "Ago",
166
+ "Sep",
167
+ "Oct",
168
+ "Nov",
169
+ "Dic",
170
+ ],
171
+ "fr": [
172
+ "",
173
+ "Jan",
174
+ "Fév",
175
+ "Mar",
176
+ "Avr",
177
+ "Mai",
178
+ "Jun",
179
+ "Jul",
180
+ "Aoû",
181
+ "Sep",
182
+ "Oct",
183
+ "Nov",
184
+ "Déc",
185
+ ],
186
+ "de": [
187
+ "",
188
+ "Jan",
189
+ "Feb",
190
+ "Mär",
191
+ "Apr",
192
+ "Mai",
193
+ "Jun",
194
+ "Jul",
195
+ "Aug",
196
+ "Sep",
197
+ "Okt",
198
+ "Nov",
199
+ "Dez",
200
+ ],
201
+ "en": [
202
+ "",
203
+ "Jan",
204
+ "Feb",
205
+ "Mar",
206
+ "Apr",
207
+ "May",
208
+ "Jun",
209
+ "Jul",
210
+ "Aug",
211
+ "Sep",
212
+ "Oct",
213
+ "Nov",
214
+ "Dec",
215
+ ],
216
+ }
217
+ _DAYS_SHORT_BY_LOCALE: dict[str, list[str]] = {
218
+ "pt": ["Seg", "Ter", "Qua", "Qui", "Sex", "Sáb", "Dom"],
219
+ "es": ["Lun", "Mar", "Mié", "Jue", "Vie", "Sáb", "Dom"],
220
+ "fr": ["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"],
221
+ "de": ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
222
+ "it": ["Lun", "Mar", "Mer", "Gio", "Ven", "Sab", "Dom"],
223
+ "en": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
224
+ }
225
+ _DAYS_FULL_BY_LOCALE: dict[str, list[str]] = {
226
+ "pt": ["Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado", "Domingo"],
227
+ "es": ["Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"],
228
+ "fr": ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
229
+ "de": [
230
+ "Montag",
231
+ "Dienstag",
232
+ "Mittwoch",
233
+ "Donnerstag",
234
+ "Freitag",
235
+ "Samstag",
236
+ "Sonntag",
237
+ ],
238
+ "en": [
239
+ "Monday",
240
+ "Tuesday",
241
+ "Wednesday",
242
+ "Thursday",
243
+ "Friday",
244
+ "Saturday",
245
+ "Sunday",
246
+ ],
247
+ }
248
+
249
+
250
+ def _locale_prefix(locale: str) -> str:
251
+ """Retorna prefixo de 2 letras do locale (pt-BR -> pt)."""
252
+ return locale[:2].lower()
253
+
254
+
255
+ def _months(locale: str) -> list[str]:
256
+ return _MONTHS_BY_LOCALE.get(_locale_prefix(locale), _MONTHS_BY_LOCALE["en"])
257
+
258
+
259
+ def _months_short(locale: str) -> list[str]:
260
+ return _MONTHS_SHORT_BY_LOCALE.get(
261
+ _locale_prefix(locale), _MONTHS_SHORT_BY_LOCALE["en"]
262
+ )
263
+
264
+
265
+ def _days_short(locale: str) -> list[str]:
266
+ return _DAYS_SHORT_BY_LOCALE.get(
267
+ _locale_prefix(locale), _DAYS_SHORT_BY_LOCALE["en"]
268
+ )
269
+
270
+
271
+ def _days_full(locale: str) -> list[str]:
272
+ return _DAYS_FULL_BY_LOCALE.get(_locale_prefix(locale), _DAYS_FULL_BY_LOCALE["en"])
273
+
274
+
275
+ _MONTHS_PT = _MONTHS_BY_LOCALE["pt"]
276
+ _MONTHS_SHORT = _MONTHS_SHORT_BY_LOCALE["pt"]
277
+ _DAYS_PT_SHORT = _DAYS_SHORT_BY_LOCALE["pt"]
278
+ _DAYS_PT_FULL = _DAYS_FULL_BY_LOCALE["pt"]
279
+
280
+ _EVENT_COLORS = [
281
+ "#89b4fa",
282
+ "#a6e3a1",
283
+ "#fab387",
284
+ "#f38ba8",
285
+ "#cba6f7",
286
+ "#f9e2af",
287
+ "#94e2d5",
288
+ "#eba0ac",
289
+ ]
290
+
291
+
292
+ def _load_events() -> dict[str, list[dict]]:
293
+ if not _EVENTS_FILE.exists():
294
+ return {}
295
+ try:
296
+ return json.loads(_EVENTS_FILE.read_text(encoding="utf-8"))
297
+ except Exception:
298
+ return {}
299
+
300
+
301
+ def _save_events(events: dict[str, list[dict]]) -> None:
302
+ _EVENTS_FILE.parent.mkdir(parents=True, exist_ok=True)
303
+ _EVENTS_FILE.write_text(
304
+ json.dumps(events, indent=2, ensure_ascii=False),
305
+ encoding="utf-8",
306
+ )
307
+
308
+
309
+ class CalendarPanel(tk.Frame):
310
+ """Calendário integrado ao Codis com anotações e lembretes."""
311
+
312
+ def __init__(self, parent: tk.Widget, tmgr: Any, cfg: Any) -> None:
313
+ t = tmgr.theme
314
+ super().__init__(parent, bg=t.panel_bg)
315
+ self._tmgr = tmgr
316
+ self._cfg = cfg
317
+ self._events = _load_events()
318
+ self._today = date.today()
319
+ self._cur_month = self._today.month
320
+ self._cur_year = self._today.year
321
+ self._selected = self._today
322
+ self._reminder_thread: threading.Thread | None = None
323
+ self._alive = True
324
+ self._build(t)
325
+ self._start_reminder_monitor()
326
+
327
+ def _build(self, t: Any) -> None:
328
+ hdr = tk.Frame(self, bg=t.activity_bg, height=48)
329
+ hdr.pack(fill="x")
330
+ hdr.pack_propagate(False)
331
+
332
+ tk.Label(
333
+ hdr, text="📅", bg=t.activity_bg, fg=t.accent, font=(FONT_UI, 16)
334
+ ).pack(side="left", padx=(14, 4), pady=8)
335
+ tk.Label(
336
+ hdr,
337
+ text=_t("calendar.title", "Calendário"),
338
+ bg=t.activity_bg,
339
+ fg=t.fg,
340
+ font=(FONT_UI, 13, "bold"),
341
+ ).pack(side="left", pady=8)
342
+
343
+ search_fr = tk.Frame(
344
+ hdr, bg=t.input_bg, highlightthickness=1, highlightbackground=t.border
345
+ )
346
+ search_fr.pack(side="right", padx=12, pady=10)
347
+ tk.Label(
348
+ search_fr, text="🔍", bg=t.input_bg, fg=t.fg_muted, font=(FONT_UI, 9)
349
+ ).pack(side="left", padx=(6, 2))
350
+ self._search_var = tk.StringVar()
351
+ search_ent = tk.Entry(
352
+ search_fr,
353
+ textvariable=self._search_var,
354
+ bg=t.input_bg,
355
+ fg=t.fg,
356
+ insertbackground=t.cursor,
357
+ relief="flat",
358
+ bd=0,
359
+ font=(FONT_UI, 9),
360
+ width=18,
361
+ )
362
+ search_ent.pack(side="left", padx=(0, 6), pady=4)
363
+ search_ent.bind("<Return>", lambda _: self._do_search())
364
+
365
+ tk.Frame(self, bg=t.border, height=1).pack(fill="x")
366
+
367
+ body = tk.Frame(self, bg=t.panel_bg)
368
+ body.pack(fill="both", expand=True)
369
+
370
+ left = tk.Frame(body, bg=t.panel_bg, width=310)
371
+ left.pack(side="left", fill="y")
372
+ left.pack_propagate(False)
373
+
374
+ tk.Frame(body, bg=t.border, width=1).pack(side="left", fill="y")
375
+
376
+ right = tk.Frame(body, bg=t.panel_bg)
377
+ right.pack(side="left", fill="both", expand=True)
378
+
379
+ self._build_nav(left, t)
380
+ self._build_weekday_header(left, t)
381
+ self._build_grid(left, t)
382
+ self._build_mini_agenda(left, t)
383
+ self._build_detail(right, t)
384
+ self._redraw_grid()
385
+ self._show_day_detail(self._selected)
386
+
387
+ def _build_nav(self, parent: tk.Widget, t: Any) -> None:
388
+ nav = tk.Frame(parent, bg=t.panel_bg)
389
+ nav.pack(fill="x", padx=10, pady=(10, 4))
390
+
391
+ prev_btn = tk.Label(
392
+ nav,
393
+ text="[",
394
+ bg=t.btn_bg,
395
+ fg=t.fg,
396
+ font=(FONT_UI, 18),
397
+ cursor="hand2",
398
+ padx=8,
399
+ pady=2,
400
+ )
401
+ prev_btn.pack(side="left")
402
+ prev_btn.bind("<Button-1>", lambda _: self._change_month(-1))
403
+ prev_btn.bind("<Enter>", lambda _: prev_btn.config(bg=t.btn_hover))
404
+ prev_btn.bind("<Leave>", lambda _: prev_btn.config(bg=t.btn_bg))
405
+
406
+ self._month_lbl = tk.Label(
407
+ nav,
408
+ text="",
409
+ bg=t.panel_bg,
410
+ fg=t.fg,
411
+ font=(FONT_UI, 13, "bold"),
412
+ cursor="hand2",
413
+ )
414
+ self._month_lbl.pack(side="left", fill="x", expand=True)
415
+ self._month_lbl.bind("<Button-1>", lambda _: self._go_today())
416
+
417
+ today_lbl = tk.Label(
418
+ nav,
419
+ text=_t("calendar.btn_today", "Hoje"),
420
+ bg=t.accent,
421
+ fg=t.btn_primary_fg,
422
+ font=(FONT_UI, 8),
423
+ cursor="hand2",
424
+ padx=8,
425
+ pady=3,
426
+ )
427
+ today_lbl.pack(side="right", padx=4)
428
+ today_lbl.bind("<Button-1>", lambda _: self._go_today())
429
+
430
+ next_btn = tk.Label(
431
+ nav,
432
+ text="]",
433
+ bg=t.btn_bg,
434
+ fg=t.fg,
435
+ font=(FONT_UI, 18),
436
+ cursor="hand2",
437
+ padx=8,
438
+ pady=2,
439
+ )
440
+ next_btn.pack(side="right", padx=2)
441
+ next_btn.bind("<Button-1>", lambda _: self._change_month(+1))
442
+ next_btn.bind("<Enter>", lambda _: next_btn.config(bg=t.btn_hover))
443
+ next_btn.bind("<Leave>", lambda _: next_btn.config(bg=t.btn_bg))
444
+
445
+ def _build_weekday_header(self, parent: tk.Widget, t: Any) -> None:
446
+ """Linha de cabeçalho dos dias da semana."""
447
+ wk = tk.Frame(parent, bg=t.activity_bg)
448
+ wk.pack(fill="x", padx=10, pady=(2, 0))
449
+ locale = (
450
+ I18n.get_instance().get_locale() if hasattr(_t, "__self__") else "pt-BR"
451
+ )
452
+ for i, day in enumerate(_days_short(locale)):
453
+ fg = t.t_func if i >= 5 else t.fg_muted
454
+ tk.Label(
455
+ wk,
456
+ text=day,
457
+ bg=t.activity_bg,
458
+ fg=fg,
459
+ font=(FONT_UI, 8, "bold"),
460
+ anchor="center",
461
+ width=4,
462
+ ).pack(side="left", expand=True)
463
+
464
+ def _build_grid(self, parent: tk.Widget, t: Any) -> None:
465
+ self._grid_frame = tk.Frame(parent, bg=t.panel_bg)
466
+ self._grid_frame.pack(fill="x", padx=10, pady=(1, 0))
467
+
468
+ def _build_mini_agenda(self, parent: tk.Widget, t: Any) -> None:
469
+ """Mini-agenda dos próximos eventos (abaixo do grid)."""
470
+ tk.Frame(parent, bg=t.border, height=1).pack(
471
+ fill="x", padx=10, pady=(8, 0))
472
+
473
+ hdr = tk.Frame(parent, bg=t.panel_bg)
474
+ hdr.pack(fill="x", padx=10, pady=(6, 2))
475
+ tk.Label(
476
+ hdr,
477
+ text=_t("calendar.upcoming", "Próximos eventos"),
478
+ bg=t.panel_bg,
479
+ fg=t.fg_muted,
480
+ font=(FONT_UI, 8, "bold"),
481
+ ).pack(side="left")
482
+
483
+ add_btn = tk.Label(
484
+ hdr,
485
+ text=_t("cal.btn_new", "+ Novo"),
486
+ bg=t.panel_bg,
487
+ fg=t.t_link,
488
+ font=(FONT_UI, 8),
489
+ cursor="hand2",
490
+ )
491
+ add_btn.pack(side="right")
492
+ add_btn.bind("<Button-1>", lambda _: self._add_event_dialog())
493
+
494
+ self._mini_agenda = tk.Frame(parent, bg=t.panel_bg)
495
+ self._mini_agenda.pack(fill="x", padx=10, pady=(0, 8))
496
+ self._refresh_mini_agenda()
497
+
498
+ def _refresh_mini_agenda(self) -> None:
499
+ t = self._tmgr.theme
500
+ for w in self._mini_agenda.winfo_children():
501
+ w.destroy()
502
+
503
+ today = date.today()
504
+ upcoming: list[tuple[date, dict]] = []
505
+ for delta in range(30):
506
+ d = today + timedelta(days=delta)
507
+ iso = d.isoformat()
508
+ for ev in self._events.get(iso, []):
509
+ upcoming.append((d, ev))
510
+ if len(upcoming) >= 4:
511
+ break
512
+
513
+ if not upcoming:
514
+ tk.Label(
515
+ self._mini_agenda,
516
+ text=_t("calendar.no_events",
517
+ "Nenhum evento nos próximos 30 dias"),
518
+ bg=t.panel_bg,
519
+ fg=t.fg_muted,
520
+ font=(FONT_UI, 8),
521
+ ).pack(anchor="w", pady=4)
522
+ return
523
+
524
+ for d, ev in upcoming[:4]:
525
+ row = tk.Frame(self._mini_agenda, bg=t.panel_bg)
526
+ row.pack(fill="x", pady=1)
527
+
528
+ color = ev.get("color", t.accent)
529
+ tk.Frame(row, bg=color, width=3).pack(
530
+ side="left", fill="y", padx=(0, 6))
531
+
532
+ is_today = d == today
533
+ locale = (
534
+ I18n.get_instance().get_locale() if hasattr(_t, "__self__") else "pt-BR"
535
+ )
536
+ if is_today:
537
+ date_str = _t("calendar.today_short", "Hoje")
538
+ elif d == today + timedelta(days=1):
539
+ date_str = _t("calendar.tomorrow", "Amanhã")
540
+ else:
541
+ date_str = f"{d.day} {_months_short(locale)[d.month]}"
542
+ tk.Label(
543
+ row,
544
+ text=date_str,
545
+ bg=t.panel_bg,
546
+ fg=t.accent if is_today else t.fg_muted,
547
+ font=(FONT_UI, 7),
548
+ width=6,
549
+ anchor="w",
550
+ ).pack(side="left")
551
+ tk.Label(
552
+ row,
553
+ text=ev.get("title", ""),
554
+ bg=t.panel_bg,
555
+ fg=t.fg,
556
+ font=(FONT_UI, 8),
557
+ anchor="w",
558
+ ).pack(side="left", fill="x", expand=True)
559
+ if ev.get("time"):
560
+ tk.Label(
561
+ row,
562
+ text=ev["time"],
563
+ bg=t.panel_bg,
564
+ fg=t.fg_muted,
565
+ font=(FONT_UI, 7),
566
+ ).pack(side="right")
567
+
568
+ def _build_detail(self, parent: tk.Widget, t: Any) -> None:
569
+ """Painel de detalhe do dia selecionado."""
570
+ detail_hdr = tk.Frame(parent, bg=t.activity_bg, height=42)
571
+ detail_hdr.pack(fill="x")
572
+ detail_hdr.pack_propagate(False)
573
+
574
+ self._detail_lbl = tk.Label(
575
+ detail_hdr,
576
+ text="",
577
+ bg=t.activity_bg,
578
+ fg=t.fg,
579
+ font=(FONT_UI, 11, "bold"),
580
+ anchor="w",
581
+ )
582
+ self._detail_lbl.pack(side="left", padx=14, pady=8)
583
+
584
+ add_btn = tk.Label(
585
+ detail_hdr,
586
+ text=_t("cal.btn_new_event", "+ Evento"),
587
+ bg=t.accent,
588
+ fg=t.btn_primary_fg,
589
+ font=(FONT_UI, 9),
590
+ cursor="hand2",
591
+ padx=10,
592
+ pady=4,
593
+ )
594
+ add_btn.pack(side="right", padx=10, pady=6)
595
+ add_btn.bind("<Button-1>", lambda _: self._add_event_dialog())
596
+
597
+ tk.Frame(parent, bg=t.border, height=1).pack(fill="x")
598
+
599
+ events_wrap = tk.Frame(parent, bg=t.panel_bg)
600
+ events_wrap.pack(fill="both", expand=True)
601
+
602
+ canvas = tk.Canvas(events_wrap, bg=t.panel_bg, highlightthickness=0)
603
+ vsb = ttk.Scrollbar(events_wrap, orient="vertical",
604
+ command=canvas.yview)
605
+ vsb.pack(side="right", fill="y")
606
+ canvas.config(yscrollcommand=vsb.set)
607
+ canvas.pack(fill="both", expand=True)
608
+
609
+ self._events_inner = tk.Frame(canvas, bg=t.panel_bg)
610
+ self._events_win = canvas.create_window(
611
+ (0, 0), window=self._events_inner, anchor="nw"
612
+ )
613
+
614
+ debounce_canvas(
615
+ canvas, self._events_win, ms=40, extra_widget=self._events_inner
616
+ )
617
+ for ev in ("<MouseWheel>", "<Button-4>", "<Button-5>"):
618
+ canvas.bind(
619
+ ev,
620
+ lambda e: canvas.yview_scroll(
621
+ -1 * (e.delta // 120) if e.delta else (-1 if e.num == 4 else 1),
622
+ "units",
623
+ ),
624
+ )
625
+
626
+ def _redraw_grid(self) -> None:
627
+ t = self._tmgr.theme
628
+ locale = (
629
+ I18n.get_instance().get_locale() if hasattr(_t, "__self__") else "pt-BR"
630
+ )
631
+ self._month_lbl.config(
632
+ text=f"{_months(locale)[self._cur_month]} {self._cur_year}"
633
+ )
634
+
635
+ for w in self._grid_frame.winfo_children():
636
+ w.destroy()
637
+
638
+ first = date(self._cur_year, self._cur_month, 1)
639
+ start_wd = first.weekday()
640
+
641
+ row = tk.Frame(self._grid_frame, bg=t.panel_bg)
642
+ row.pack(fill="x")
643
+
644
+ for _ in range(start_wd):
645
+ tk.Label(row, text="", bg=t.panel_bg, width=4, pady=5).pack(
646
+ side="left", expand=True
647
+ )
648
+
649
+ cur = first
650
+ col = start_wd
651
+ while cur.month == self._cur_month:
652
+ if col > 0 and col % 7 == 0:
653
+ row = tk.Frame(self._grid_frame, bg=t.panel_bg)
654
+ row.pack(fill="x")
655
+
656
+ iso = cur.isoformat()
657
+ has_events = bool(self._events.get(iso))
658
+ is_today = cur == self._today
659
+ is_sel = cur == self._selected
660
+ is_weekend = cur.weekday() >= 5
661
+
662
+ if is_sel:
663
+ cell_bg = t.accent
664
+ cell_fg = t.btn_primary_fg
665
+ font_w = "bold"
666
+ elif is_today:
667
+ cell_bg = t.sel_bg
668
+ cell_fg = t.fg
669
+ font_w = "bold"
670
+ else:
671
+ cell_bg = t.panel_bg
672
+ cell_fg = t.t_func if is_weekend else t.fg
673
+ font_w = "normal"
674
+
675
+ cell = tk.Frame(row, bg=cell_bg, cursor="hand2")
676
+ cell.pack(side="left", expand=True, padx=1, pady=1)
677
+
678
+ day_lbl = tk.Label(
679
+ cell,
680
+ text=str(cur.day),
681
+ bg=cell_bg,
682
+ fg=cell_fg,
683
+ font=(FONT_UI, 9, font_w),
684
+ padx=4,
685
+ pady=4,
686
+ cursor="hand2",
687
+ )
688
+ day_lbl.pack()
689
+
690
+ if has_events:
691
+ dot_color = (
692
+ t.btn_primary_fg if is_sel else t.accent if is_today else t.accent
693
+ )
694
+ dot = tk.Label(
695
+ cell, text="•", bg=cell_bg, fg=dot_color, font=(FONT_UI, 6)
696
+ )
697
+ dot.pack()
698
+ dot.bind("<Button-1>", lambda _, d=cur: self._on_day_click(d))
699
+
700
+ for w in (cell, day_lbl):
701
+ w.bind("<Button-1>", lambda _, d=cur: self._on_day_click(d))
702
+ w.bind(
703
+ "<Enter>",
704
+ lambda _, c=cell, bg=cell_bg: c.config(
705
+ bg=t.btn_hover if bg != t.accent else bg
706
+ ),
707
+ )
708
+ w.bind("<Leave>", lambda _, c=cell,
709
+ bg=cell_bg: c.config(bg=bg))
710
+
711
+ cur += timedelta(days=1)
712
+ col += 1
713
+
714
+ def _on_day_click(self, d: date) -> None:
715
+ self._selected = d
716
+ self._redraw_grid()
717
+ self._show_day_detail(d)
718
+
719
+ def _show_day_detail(self, d: date) -> None:
720
+ t = self._tmgr.theme
721
+ iso = d.isoformat()
722
+ locale = (
723
+ I18n.get_instance().get_locale() if hasattr(_t, "__self__") else "pt-BR"
724
+ )
725
+ weekday = _days_full(locale)[d.weekday()]
726
+ month_name = _months(locale)[d.month]
727
+ lp = _locale_prefix(locale)
728
+ if lp in ("pt", "es", "it"):
729
+ date_str = f"{weekday}, {d.day} de {month_name} de {d.year}"
730
+ elif lp == "fr":
731
+ date_str = f"{weekday}, {d.day} {month_name} {d.year}"
732
+ elif lp == "de":
733
+ date_str = f"{weekday}, {d.day}. {month_name} {d.year}"
734
+ else:
735
+ date_str = datetime(
736
+ d.year, d.month, d.day).strftime("%A, %B %d, %Y")
737
+ self._detail_lbl.config(text=date_str)
738
+
739
+ for w in self._events_inner.winfo_children():
740
+ w.destroy()
741
+
742
+ day_events = self._events.get(iso, [])
743
+ if not day_events:
744
+ empty = tk.Frame(self._events_inner, bg=t.panel_bg)
745
+ empty.pack(fill="both", expand=True, pady=40)
746
+ tk.Label(
747
+ empty, text="📭", bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 28)
748
+ ).pack()
749
+ tk.Label(
750
+ empty,
751
+ text=_t("calendar.no_events", "Nenhum evento neste dia"),
752
+ bg=t.panel_bg,
753
+ fg=t.fg_muted,
754
+ font=(FONT_UI, 10),
755
+ ).pack(pady=4)
756
+ tk.Label(
757
+ empty,
758
+ text=_t("calendar.add_hint",
759
+ "Clique em + Evento para adicionar"),
760
+ bg=t.panel_bg,
761
+ fg=t.fg_muted,
762
+ font=(FONT_UI, 8),
763
+ ).pack()
764
+ return
765
+
766
+ for idx, ev in enumerate(day_events):
767
+ color = ev.get("color", t.accent)
768
+
769
+ ev_frame = tk.Frame(self._events_inner, bg=t.panel_bg)
770
+ ev_frame.pack(fill="x", padx=12, pady=5)
771
+
772
+ color_bar = tk.Frame(ev_frame, bg=color, width=4)
773
+ color_bar.pack(side="left", fill="y")
774
+
775
+ content = tk.Frame(
776
+ ev_frame,
777
+ bg=t.btn_bg,
778
+ highlightthickness=1,
779
+ highlightbackground=t.border,
780
+ )
781
+ content.pack(side="left", fill="both", expand=True, padx=(0, 0))
782
+
783
+ title_row = tk.Frame(content, bg=t.btn_bg)
784
+ title_row.pack(fill="x", padx=8, pady=(7, 2))
785
+
786
+ tk.Label(
787
+ title_row,
788
+ text=ev.get("title", ""),
789
+ bg=t.btn_bg,
790
+ fg=t.fg,
791
+ font=(FONT_UI, 11, "bold"),
792
+ anchor="w",
793
+ ).pack(side="left", fill="x", expand=True)
794
+
795
+ for icon, cmd in [
796
+ ("✏", lambda i=idx, _d=d: self._edit_event_dialog(_d, i)),
797
+ ("🗑", lambda i=idx, _d=d: self._delete_event(_d, i)),
798
+ ]:
799
+ b = tk.Label(
800
+ title_row,
801
+ text=icon,
802
+ bg=t.btn_bg,
803
+ fg=t.fg_muted,
804
+ cursor="hand2",
805
+ font=(FONT_UI, 9),
806
+ )
807
+ b.pack(side="right", padx=2)
808
+ b.bind("<Button-1>", lambda _, c=cmd: c())
809
+
810
+ if ev.get("time") or ev.get("note") or ev.get("remind"):
811
+ meta_row = tk.Frame(content, bg=t.btn_bg)
812
+ meta_row.pack(fill="x", padx=8, pady=(0, 7))
813
+ if ev.get("time"):
814
+ tk.Label(
815
+ meta_row,
816
+ text=f"🕐 {ev['time']}",
817
+ bg=t.btn_bg,
818
+ fg=t.fg_muted,
819
+ font=(FONT_UI, 8),
820
+ ).pack(side="left", padx=(0, 8))
821
+ if ev.get("remind"):
822
+ tk.Label(
823
+ meta_row, text="🔔", bg=t.btn_bg, fg=t.accent, font=(FONT_UI, 8)
824
+ ).pack(side="left", padx=(0, 8))
825
+ if ev.get("note"):
826
+ tk.Label(
827
+ meta_row,
828
+ text=ev["note"],
829
+ bg=t.btn_bg,
830
+ fg=t.fg_muted,
831
+ font=(FONT_UI, 8),
832
+ anchor="w",
833
+ wraplength=280,
834
+ ).pack(side="left", fill="x", expand=True)
835
+ else:
836
+ tk.Frame(content, bg=t.btn_bg, height=4).pack()
837
+
838
+ def _add_event_dialog(
839
+ self, prefill: dict | None = None, edit_idx: int | None = None
840
+ ) -> None:
841
+ t = self._tmgr.theme
842
+ win = tk.Toplevel(self)
843
+ is_edit = edit_idx is not None
844
+ win.title(
845
+ _t("calendar.edit_event", "Editar Evento")
846
+ if is_edit
847
+ else _t("calendar.new_event", "Novo Evento")
848
+ )
849
+ win.config(bg=t.floating_bg)
850
+ safe_grab_set(win)
851
+ win.resizable(False, False)
852
+
853
+ hdr = tk.Frame(win, bg=t.activity_bg)
854
+ hdr.pack(fill="x")
855
+ tk.Label(
856
+ hdr,
857
+ text=(
858
+ _t("cal.edit_event", "✏ Editar Evento")
859
+ if is_edit
860
+ else _t("cal.new_event_title", "+ Novo Evento")
861
+ ),
862
+ bg=t.activity_bg,
863
+ fg=t.fg,
864
+ font=(FONT_UI, 11, "bold"),
865
+ ).pack(side="left", padx=12, pady=10)
866
+ tk.Label(
867
+ hdr,
868
+ text=f"📅 {self._selected.strftime('%d/%m/%Y')}",
869
+ bg=t.activity_bg,
870
+ fg=t.fg_muted,
871
+ font=(FONT_UI, 9),
872
+ ).pack(side="right", padx=12)
873
+
874
+ form = tk.Frame(win, bg=t.floating_bg)
875
+ form.pack(fill="x", padx=16, pady=12)
876
+
877
+ def field(
878
+ label: str, var: tk.StringVar, row_n: int, placeholder: str = ""
879
+ ) -> None:
880
+ tk.Label(
881
+ form,
882
+ text=label,
883
+ bg=t.floating_bg,
884
+ fg=t.fg_muted,
885
+ font=(FONT_UI, 8),
886
+ anchor="w",
887
+ ).grid(
888
+ row=row_n * 2, column=0, columnspan=2, padx=0, pady=(8, 2), sticky="w"
889
+ )
890
+ ent = tk.Entry(
891
+ form,
892
+ textvariable=var,
893
+ bg=t.input_bg,
894
+ fg=t.fg,
895
+ insertbackground=t.cursor,
896
+ relief="flat",
897
+ bd=0,
898
+ highlightthickness=1,
899
+ highlightbackground=t.border,
900
+ font=(FONT_UI, 10),
901
+ width=34,
902
+ )
903
+ ent.grid(
904
+ row=row_n * 2 + 1,
905
+ column=0,
906
+ columnspan=2,
907
+ padx=0,
908
+ pady=0,
909
+ sticky="ew",
910
+ ipady=5,
911
+ )
912
+
913
+ pf = prefill or {}
914
+ title_var = tk.StringVar(value=pf.get("title", ""))
915
+ time_var = tk.StringVar(value=pf.get("time", ""))
916
+ note_var = tk.StringVar(value=pf.get("note", ""))
917
+ remind_var = tk.BooleanVar(value=pf.get("remind", False))
918
+ color_var = tk.StringVar(value=pf.get("color", _EVENT_COLORS[0]))
919
+
920
+ field(_t("calendar.ev_title", "Título *"), title_var, 0)
921
+ field(_t("calendar.ev_time", "Horário (ex: 14:30)"), time_var, 1)
922
+ field(_t("calendar.ev_note", "Anotação"), note_var, 2)
923
+
924
+ tk.Label(
925
+ form,
926
+ text=_t("calendar.ev_color", "Cor"),
927
+ bg=t.floating_bg,
928
+ fg=t.fg_muted,
929
+ font=(FONT_UI, 8),
930
+ anchor="w",
931
+ ).grid(row=6, column=0, columnspan=2, pady=(8, 2), sticky="w")
932
+
933
+ color_fr = tk.Frame(form, bg=t.floating_bg)
934
+ color_fr.grid(row=7, column=0, columnspan=2, sticky="w")
935
+ self._color_dots: list[tk.Label] = []
936
+
937
+ def pick_color(c: str) -> None:
938
+ color_var.set(c)
939
+ for dot in self._color_dots:
940
+ dot.config(relief="flat")
941
+ idx = _EVENT_COLORS.index(c) if c in _EVENT_COLORS else -1
942
+ if idx >= 0:
943
+ self._color_dots[idx].config(relief="solid")
944
+
945
+ for _, c in enumerate(_EVENT_COLORS):
946
+ dot = tk.Label(
947
+ color_fr,
948
+ bg=c,
949
+ width=3,
950
+ pady=8,
951
+ cursor="hand2",
952
+ relief="flat",
953
+ highlightthickness=2,
954
+ highlightbackground=c,
955
+ )
956
+ dot.pack(side="left", padx=2)
957
+ dot.bind("<Button-1>", lambda _, col=c: pick_color(col))
958
+ self._color_dots.append(dot)
959
+ pick_color(color_var.get())
960
+
961
+ remind_fr = tk.Frame(form, bg=t.floating_bg)
962
+ remind_fr.grid(row=8, column=0, columnspan=2, pady=(10, 0), sticky="w")
963
+ tk.Checkbutton(
964
+ remind_fr,
965
+ text=_t("cal.enable_reminder",
966
+ "🔔 Ativar lembrete (1–2 min antes)"),
967
+ variable=remind_var,
968
+ bg=t.floating_bg,
969
+ fg=t.fg,
970
+ selectcolor=t.input_bg,
971
+ activebackground=t.floating_bg,
972
+ activeforeground=t.fg,
973
+ font=(FONT_UI, 9),
974
+ ).pack(side="left")
975
+
976
+ form.columnconfigure(0, weight=1)
977
+ form.columnconfigure(1, weight=1)
978
+
979
+ tk.Frame(win, bg=t.border, height=1).pack(fill="x")
980
+ btn_row = tk.Frame(win, bg=t.floating_bg)
981
+ btn_row.pack(fill="x", padx=16, pady=10)
982
+
983
+ def _save() -> None:
984
+ t_val = title_var.get().strip()
985
+ if not t_val:
986
+ messagebox.showwarning(
987
+ _t("calendar.missing_title", "Campo obrigatório"),
988
+ _t("calendar.title_required", "O título é obrigatório."),
989
+ parent=win,
990
+ )
991
+ return
992
+ ev = {
993
+ "title": t_val,
994
+ "time": time_var.get().strip(),
995
+ "note": note_var.get().strip(),
996
+ "remind": remind_var.get(),
997
+ "color": color_var.get() or _EVENT_COLORS[0],
998
+ }
999
+ iso = self._selected.isoformat()
1000
+ day_events = self._events.setdefault(iso, [])
1001
+ if is_edit and edit_idx is not None:
1002
+ day_events[edit_idx] = ev
1003
+ else:
1004
+ day_events.append(ev)
1005
+ _save_events(self._events)
1006
+ self._redraw_grid()
1007
+ self._show_day_detail(self._selected)
1008
+ self._refresh_mini_agenda()
1009
+ win.destroy()
1010
+
1011
+ cancel_b = tk.Label(
1012
+ btn_row,
1013
+ text=_t("calendar.cancel", "Cancelar"),
1014
+ bg=t.btn_bg,
1015
+ fg=t.fg,
1016
+ font=(FONT_UI, 10),
1017
+ cursor="hand2",
1018
+ padx=14,
1019
+ pady=6,
1020
+ )
1021
+ cancel_b.pack(side="left", padx=(0, 8))
1022
+ cancel_b.bind("<Button-1>", lambda _: win.destroy())
1023
+
1024
+ save_b = tk.Label(
1025
+ btn_row,
1026
+ text=_t("calendar.save", "Salvar evento"),
1027
+ bg=t.accent,
1028
+ fg=t.btn_primary_fg,
1029
+ font=(FONT_UI, 10, "bold"),
1030
+ cursor="hand2",
1031
+ padx=14,
1032
+ pady=6,
1033
+ )
1034
+ save_b.pack(side="right")
1035
+ save_b.bind("<Button-1>", lambda _: _save())
1036
+
1037
+ win.update_idletasks()
1038
+ sw, sh = win.winfo_screenwidth(), win.winfo_screenheight()
1039
+ ww, wh = win.winfo_reqwidth(), win.winfo_reqheight()
1040
+ win.geometry(f"{ww}x{wh}+{(sw - ww) // 2}+{(sh - wh) // 2}")
1041
+
1042
+ def _edit_event_dialog(self, d: date, idx: int) -> None:
1043
+ iso = d.isoformat()
1044
+ evs = self._events.get(iso, [])
1045
+ if idx < len(evs):
1046
+ self._selected = d
1047
+ self._add_event_dialog(prefill=evs[idx], edit_idx=idx)
1048
+
1049
+ def _delete_event(self, d: date, idx: int) -> None:
1050
+ iso = d.isoformat()
1051
+ evs = self._events.get(iso, [])
1052
+ if idx < len(evs):
1053
+ ev_title = evs[idx].get("title", "?")
1054
+ if messagebox.askyesno(
1055
+ "Remover Evento", f"Remover '{ev_title}'?", parent=self
1056
+ ):
1057
+ evs.pop(idx)
1058
+ if not evs:
1059
+ self._events.pop(iso, None)
1060
+ _save_events(self._events)
1061
+ self._redraw_grid()
1062
+ self._show_day_detail(d)
1063
+ self._refresh_mini_agenda()
1064
+
1065
+ def _change_month(self, delta: int) -> None:
1066
+ m = self._cur_month + delta
1067
+ y = self._cur_year
1068
+ while m > 12:
1069
+ m -= 12
1070
+ y += 1
1071
+ while m < 1:
1072
+ m += 12
1073
+ y -= 1
1074
+ self._cur_month = m
1075
+ self._cur_year = y
1076
+ self._redraw_grid()
1077
+
1078
+ def _go_today(self) -> None:
1079
+ self._today = date.today()
1080
+ self._cur_month = self._today.month
1081
+ self._cur_year = self._today.year
1082
+ self._selected = self._today
1083
+ self._redraw_grid()
1084
+ self._show_day_detail(self._selected)
1085
+
1086
+ def _do_search(self) -> None:
1087
+ q = self._search_var.get().strip().lower()
1088
+ if not q:
1089
+ return
1090
+ results: list[tuple[str, dict]] = []
1091
+ for iso, evs in self._events.items():
1092
+ for ev in evs:
1093
+ if q in ev.get("title", "").lower() or q in ev.get("note", "").lower():
1094
+ results.append((iso, ev))
1095
+
1096
+ t = self._tmgr.theme
1097
+ win = tk.Toplevel(self)
1098
+ win.title(f'Resultados: "{q}"')
1099
+ win.config(bg=t.floating_bg)
1100
+ win.geometry("480x380")
1101
+
1102
+ tk.Label(
1103
+ win,
1104
+ text=f'🔍 {len(results)} resultado(s) para "{q}"',
1105
+ bg=t.activity_bg,
1106
+ fg=t.fg,
1107
+ font=(FONT_UI, 10, "bold"),
1108
+ ).pack(fill="x", padx=0, pady=0, ipady=10)
1109
+ tk.Frame(win, bg=t.border, height=1).pack(fill="x")
1110
+
1111
+ if not results:
1112
+ tk.Label(
1113
+ win,
1114
+ text=_t("calendar.no_results", "Nenhum resultado encontrado."),
1115
+ bg=t.floating_bg,
1116
+ fg=t.fg_muted,
1117
+ font=(FONT_UI, 10),
1118
+ ).pack(pady=30)
1119
+ return
1120
+
1121
+ outer = tk.Frame(win, bg=t.floating_bg)
1122
+ outer.pack(fill="both", expand=True)
1123
+ canvas = tk.Canvas(outer, bg=t.floating_bg, highlightthickness=0)
1124
+ vsb = ttk.Scrollbar(outer, orient="vertical", command=canvas.yview)
1125
+ vsb.pack(side="right", fill="y")
1126
+ canvas.config(yscrollcommand=vsb.set)
1127
+ canvas.pack(fill="both", expand=True)
1128
+ inner = tk.Frame(canvas, bg=t.floating_bg)
1129
+ win_ = canvas.create_window((0, 0), window=inner, anchor="nw")
1130
+ debounce_canvas(canvas, win_, ms=40, extra_widget=inner)
1131
+
1132
+ for iso, ev in sorted(results):
1133
+ row = tk.Frame(inner, bg=t.floating_bg)
1134
+ row.pack(fill="x", padx=10, pady=4)
1135
+
1136
+ color = ev.get("color", t.accent)
1137
+ tk.Frame(row, bg=color, width=4).pack(side="left", fill="y")
1138
+
1139
+ info = tk.Frame(row, bg=t.btn_bg)
1140
+ info.pack(side="left", fill="both", expand=True, padx=1)
1141
+
1142
+ tk.Label(
1143
+ info,
1144
+ text=f"📅 {iso} {ev.get('time', '')}",
1145
+ bg=t.btn_bg,
1146
+ fg=t.fg_muted,
1147
+ font=(FONT_UI, 7),
1148
+ ).pack(anchor="w", padx=8, pady=(5, 0))
1149
+ lbl = tk.Label(
1150
+ info,
1151
+ text=ev.get("title", ""),
1152
+ bg=t.btn_bg,
1153
+ fg=t.fg,
1154
+ font=(FONT_UI, 10, "bold"),
1155
+ anchor="w",
1156
+ cursor="hand2",
1157
+ )
1158
+ lbl.pack(anchor="w", padx=8, pady=(0, 5))
1159
+ d_obj = date.fromisoformat(iso)
1160
+ lbl.bind(
1161
+ "<Button-1>",
1162
+ lambda _, _d=d_obj: (
1163
+ setattr(self, "_cur_month", _d.month),
1164
+ setattr(self, "_cur_year", _d.year),
1165
+ setattr(self, "_selected", _d),
1166
+ self._redraw_grid(),
1167
+ self._show_day_detail(_d),
1168
+ win.destroy(),
1169
+ ),
1170
+ )
1171
+
1172
+ def _start_reminder_monitor(self) -> None:
1173
+ def _monitor() -> None:
1174
+ while self._alive:
1175
+ try:
1176
+ self._check_reminders()
1177
+ except Exception as exc:
1178
+ logger.debug("Reminder check: %s", exc)
1179
+ time.sleep(60)
1180
+
1181
+ self._reminder_thread = threading.Thread(
1182
+ target=_monitor, daemon=True, name="Codis-CalReminder"
1183
+ )
1184
+ self._reminder_thread.start()
1185
+
1186
+ def _check_reminders(self) -> None:
1187
+ now = datetime.now()
1188
+ iso_today = now.date().isoformat()
1189
+ for ev in self._events.get(iso_today, []):
1190
+ if not ev.get("remind"):
1191
+ continue
1192
+ ev_time = ev.get("time", "").strip()
1193
+ if not ev_time:
1194
+ continue
1195
+ with contextlib.suppress(ValueError, AttributeError):
1196
+ hh, mm = map(int, ev_time.split(":")[:2])
1197
+ ev_dt = now.replace(hour=hh, minute=mm,
1198
+ second=0, microsecond=0)
1199
+ diff = (ev_dt - now).total_seconds()
1200
+ if 60 <= diff <= 120:
1201
+ title = ev.get("title", _t(
1202
+ "calendar.event_default", "Evento"))
1203
+ self.after(
1204
+ 0, lambda tt=title, et=ev_time: self._show_reminder(
1205
+ tt, et)
1206
+ )
1207
+
1208
+ def _show_reminder(self, title: str, ev_time: str) -> None:
1209
+ messagebox.showinfo(
1210
+ "🔔 Lembrete",
1211
+ f"Em breve: {title}\nHorário: {ev_time}",
1212
+ parent=self,
1213
+ )
1214
+
1215
+ def destroy(self) -> None:
1216
+ """Cancela timers pendentes e destrói o painel."""
1217
+ self._alive = False
1218
+ super().destroy()