lightfall 0.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 (388) hide show
  1. lightfall/__init__.py +8 -0
  2. lightfall/__main__.py +10 -0
  3. lightfall/_version.py +24 -0
  4. lightfall/acquire/__init__.py +74 -0
  5. lightfall/acquire/buffer.py +363 -0
  6. lightfall/acquire/device_wrapper.py +416 -0
  7. lightfall/acquire/engine/__init__.py +155 -0
  8. lightfall/acquire/engine/base.py +587 -0
  9. lightfall/acquire/engine/bluesky.py +358 -0
  10. lightfall/acquire/engine/mock.py +165 -0
  11. lightfall/acquire/engine/plugins/__init__.py +9 -0
  12. lightfall/acquire/engine/plugins/bluesky_plugin.py +56 -0
  13. lightfall/acquire/engine/plugins/mock_plugin.py +55 -0
  14. lightfall/acquire/engine/protocol.py +145 -0
  15. lightfall/acquire/engine/registry.py +152 -0
  16. lightfall/acquire/engine/state.py +32 -0
  17. lightfall/acquire/engine/waiting_hook.py +225 -0
  18. lightfall/acquire/nats_bridge.py +62 -0
  19. lightfall/acquire/plan_ui.py +78 -0
  20. lightfall/acquire/plans/__init__.py +38 -0
  21. lightfall/acquire/plans/adaptive.py +288 -0
  22. lightfall/acquire/plans/example_plans.py +995 -0
  23. lightfall/acquire/plans/lightfall_plans.py +587 -0
  24. lightfall/acquire/plans/registry.py +543 -0
  25. lightfall/acquire/plans/standard_plans.py +186 -0
  26. lightfall/acquire/plans/user_plans.py +470 -0
  27. lightfall/acquire/runengine.py +36 -0
  28. lightfall/acquire/signals.py +452 -0
  29. lightfall/acquire/triggers/__init__.py +16 -0
  30. lightfall/acquire/triggers/base.py +25 -0
  31. lightfall/acquire/triggers/filter.py +37 -0
  32. lightfall/acquire/triggers/manager.py +73 -0
  33. lightfall/acquire/triggers/manual.py +36 -0
  34. lightfall/acquire/triggers/run_end.py +74 -0
  35. lightfall/acquire/triggers/run_start.py +52 -0
  36. lightfall/auth/__init__.py +38 -0
  37. lightfall/auth/policy.py +518 -0
  38. lightfall/auth/providers/__init__.py +30 -0
  39. lightfall/auth/providers/base.py +124 -0
  40. lightfall/auth/providers/keycloak.py +1017 -0
  41. lightfall/auth/providers/local.py +319 -0
  42. lightfall/auth/providers/pam.py +250 -0
  43. lightfall/auth/service_key.py +173 -0
  44. lightfall/auth/service_key_auth.py +79 -0
  45. lightfall/auth/session.py +656 -0
  46. lightfall/claude/__init__.py +52 -0
  47. lightfall/claude/_internal/__init__.py +1 -0
  48. lightfall/claude/_internal/serialization.py +195 -0
  49. lightfall/claude/_internal/threading.py +61 -0
  50. lightfall/claude/_internal/worker.py +757 -0
  51. lightfall/claude/_session_assembly.py +124 -0
  52. lightfall/claude/agent.py +596 -0
  53. lightfall/claude/lightfall_core_tools.py +410 -0
  54. lightfall/claude/markdown.py +103 -0
  55. lightfall/claude/permission_manager.py +588 -0
  56. lightfall/claude/tools/__init__.py +45 -0
  57. lightfall/claude/tools/controller.py +143 -0
  58. lightfall/claude/tools/interaction.py +177 -0
  59. lightfall/claude/tools/introspection.py +127 -0
  60. lightfall/claude/tools/logs.py +155 -0
  61. lightfall/claude/tools/screenshot.py +87 -0
  62. lightfall/claude/widget.py +851 -0
  63. lightfall/claude/widgets/__init__.py +5 -0
  64. lightfall/claude/widgets/permission_request.py +282 -0
  65. lightfall/claude/widgets/question_request.py +227 -0
  66. lightfall/claude/widgets/task_card.py +223 -0
  67. lightfall/config/__init__.py +23 -0
  68. lightfall/config/layers.py +317 -0
  69. lightfall/config/manager.py +244 -0
  70. lightfall/config/schema.py +154 -0
  71. lightfall/core/__init__.py +23 -0
  72. lightfall/core/application.py +727 -0
  73. lightfall/core/services.py +235 -0
  74. lightfall/devices/__init__.py +53 -0
  75. lightfall/devices/backends/__init__.py +17 -0
  76. lightfall/devices/backends/bcs.py +448 -0
  77. lightfall/devices/backends/happi.py +986 -0
  78. lightfall/devices/backends/mock.py +646 -0
  79. lightfall/devices/base.py +338 -0
  80. lightfall/devices/catalog.py +1039 -0
  81. lightfall/devices/connection_manager.py +676 -0
  82. lightfall/devices/model.py +290 -0
  83. lightfall/devices/monitoring.py +442 -0
  84. lightfall/devices/sim/__init__.py +26 -0
  85. lightfall/devices/sim/areadetector.py +436 -0
  86. lightfall/devices/sim/generators.py +223 -0
  87. lightfall/devices/sim/plugins.py +116 -0
  88. lightfall/epics/__init__.py +28 -0
  89. lightfall/epics/ca/__init__.py +10 -0
  90. lightfall/epics/ca/context.py +100 -0
  91. lightfall/epics/ca/pv.py +303 -0
  92. lightfall/epics/widgets/__init__.py +49 -0
  93. lightfall/epics/widgets/areadetector/__init__.py +16 -0
  94. lightfall/epics/widgets/areadetector/areadetector.py +281 -0
  95. lightfall/epics/widgets/areadetector/controls.py +478 -0
  96. lightfall/epics/widgets/areadetector/image_view.py +447 -0
  97. lightfall/epics/widgets/auto.py +319 -0
  98. lightfall/epics/widgets/base.py +404 -0
  99. lightfall/epics/widgets/checkbox.py +239 -0
  100. lightfall/epics/widgets/combobox.py +202 -0
  101. lightfall/epics/widgets/label.py +176 -0
  102. lightfall/epics/widgets/lineedit.py +253 -0
  103. lightfall/epics/widgets/motor.py +694 -0
  104. lightfall/epics/widgets/ophyd_base.py +469 -0
  105. lightfall/epics/widgets/ophyd_combobox.py +86 -0
  106. lightfall/epics/widgets/ophyd_label.py +54 -0
  107. lightfall/epics/widgets/ophyd_lineedit.py +170 -0
  108. lightfall/epics/widgets/ophyd_spinbox.py +79 -0
  109. lightfall/epics/widgets/slider.py +272 -0
  110. lightfall/epics/widgets/status_indicator.py +98 -0
  111. lightfall/epics/widgets/style.py +188 -0
  112. lightfall/exporter/__init__.py +1 -0
  113. lightfall/exporter/cli.py +67 -0
  114. lightfall/exporter/converters/__init__.py +26 -0
  115. lightfall/exporter/converters/base.py +39 -0
  116. lightfall/exporter/converters/noop.py +39 -0
  117. lightfall/exporter/converters/nxsas.py +73 -0
  118. lightfall/exporter/service.py +200 -0
  119. lightfall/exporter/tiled_utils.py +92 -0
  120. lightfall/ipc/__init__.py +6 -0
  121. lightfall/ipc/service.py +701 -0
  122. lightfall/ipc/trust.py +144 -0
  123. lightfall/logbook/__init__.py +46 -0
  124. lightfall/logbook/action_dialog.py +207 -0
  125. lightfall/logbook/action_logger.py +432 -0
  126. lightfall/logbook/block_mapper.py +562 -0
  127. lightfall/logbook/client.py +799 -0
  128. lightfall/logbook/converter.py +273 -0
  129. lightfall/logbook/editors/__init__.py +19 -0
  130. lightfall/logbook/editors/highlighter.py +305 -0
  131. lightfall/logbook/editors/markdown_editor.py +319 -0
  132. lightfall/logbook/editors/richtext_editor.py +1397 -0
  133. lightfall/logbook/entry_widget.py +1065 -0
  134. lightfall/logbook/event_listener.py +221 -0
  135. lightfall/logbook/fragment_widgets.py +925 -0
  136. lightfall/logbook/position_mapper.py +320 -0
  137. lightfall/logbook/protection.py +402 -0
  138. lightfall/logbook/style.py +394 -0
  139. lightfall/logbook/url.py +29 -0
  140. lightfall/logbook/visual_protection.py +330 -0
  141. lightfall/logbook/widget.py +680 -0
  142. lightfall/main.py +1091 -0
  143. lightfall/pipelines/__init__.py +4 -0
  144. lightfall/pipelines/client.py +148 -0
  145. lightfall/plugins/__init__.py +119 -0
  146. lightfall/plugins/agent_plugin.py +106 -0
  147. lightfall/plugins/agents/__init__.py +10 -0
  148. lightfall/plugins/agents/_mcp_helpers.py +52 -0
  149. lightfall/plugins/agents/alignment.py +94 -0
  150. lightfall/plugins/agents/autonomous_experiment/__init__.py +12 -0
  151. lightfall/plugins/agents/autonomous_experiment/nats_tools.py +210 -0
  152. lightfall/plugins/agents/autonomous_experiment/plugin.py +60 -0
  153. lightfall/plugins/agents/autonomous_experiment/prompts.py +164 -0
  154. lightfall/plugins/agents/current_esaf.py +435 -0
  155. lightfall/plugins/agents/device_tools.py +1043 -0
  156. lightfall/plugins/agents/engine_tools.py +720 -0
  157. lightfall/plugins/agents/ipython_tools.py +444 -0
  158. lightfall/plugins/agents/panel_builder.py +637 -0
  159. lightfall/plugins/agents/panel_design/references/cross_panel_patterns.md +95 -0
  160. lightfall/plugins/agents/panel_design/references/panel_design.md +680 -0
  161. lightfall/plugins/agents/panel_design.py +94 -0
  162. lightfall/plugins/agents/plan_design/references/plan_design.md +398 -0
  163. lightfall/plugins/agents/plan_design.py +90 -0
  164. lightfall/plugins/agents/plan_tools.py +878 -0
  165. lightfall/plugins/agents/scan_planning.py +101 -0
  166. lightfall/plugins/builtin_manifest.py +348 -0
  167. lightfall/plugins/controller_plugin.py +162 -0
  168. lightfall/plugins/engine_plugin.py +124 -0
  169. lightfall/plugins/errors.py +104 -0
  170. lightfall/plugins/info.py +112 -0
  171. lightfall/plugins/loader.py +878 -0
  172. lightfall/plugins/manifest.py +150 -0
  173. lightfall/plugins/panel_plugin.py +119 -0
  174. lightfall/plugins/plan_plugin.py +163 -0
  175. lightfall/plugins/registry.py +309 -0
  176. lightfall/plugins/settings_plugin.py +226 -0
  177. lightfall/plugins/statusbar_plugin.py +289 -0
  178. lightfall/plugins/theme_plugin.py +165 -0
  179. lightfall/plugins/types.py +136 -0
  180. lightfall/plugins/user_plugins.py +764 -0
  181. lightfall/project/__init__.py +37 -0
  182. lightfall/project/model.py +375 -0
  183. lightfall/project/service.py +427 -0
  184. lightfall/project/welcome.py +106 -0
  185. lightfall/resources/__init__.py +126 -0
  186. lightfall/resources/images/__init__.py +1 -0
  187. lightfall/resources/images/icon.ico +0 -0
  188. lightfall/resources/images/icon.png +0 -0
  189. lightfall/resources/images/logo.png +0 -0
  190. lightfall/services/__init__.py +33 -0
  191. lightfall/services/_alshub_client.py +73 -0
  192. lightfall/services/access_stamper.py +240 -0
  193. lightfall/services/als_beam_status.py +347 -0
  194. lightfall/services/ca_tunnel.py +325 -0
  195. lightfall/services/threaded_tiled_writer.py +174 -0
  196. lightfall/services/tiled_auth.py +21 -0
  197. lightfall/services/tiled_service.py +971 -0
  198. lightfall/services/tiled_writer_patch.py +301 -0
  199. lightfall/settings/__init__.py +1 -0
  200. lightfall/settings/image_helpers.py +30 -0
  201. lightfall/settings/user_settings_client.py +232 -0
  202. lightfall/ui/__init__.py +28 -0
  203. lightfall/ui/annotations.py +208 -0
  204. lightfall/ui/common/__init__.py +7 -0
  205. lightfall/ui/dialogs/__init__.py +26 -0
  206. lightfall/ui/dialogs/about_dialog.py +131 -0
  207. lightfall/ui/dialogs/add_trigger_dialog.py +152 -0
  208. lightfall/ui/dialogs/base.py +44 -0
  209. lightfall/ui/dialogs/bug_report_dialog.py +353 -0
  210. lightfall/ui/dialogs/create_plan_dialog.py +189 -0
  211. lightfall/ui/dialogs/device_edit_dialog.py +183 -0
  212. lightfall/ui/dialogs/export_dialog.py +565 -0
  213. lightfall/ui/dialogs/go_to_position_dialog.py +192 -0
  214. lightfall/ui/dialogs/login_dialog.py +756 -0
  215. lightfall/ui/dialogs/oauth_browser_dialog.py +305 -0
  216. lightfall/ui/dialogs/run_pipeline_dialog.py +131 -0
  217. lightfall/ui/dialogs/sample_metadata_dialog.py +316 -0
  218. lightfall/ui/docking/__init__.py +22 -0
  219. lightfall/ui/docking/icon_sidebar.py +806 -0
  220. lightfall/ui/docking/manager.py +682 -0
  221. lightfall/ui/docking/state.py +113 -0
  222. lightfall/ui/docking/theme.py +399 -0
  223. lightfall/ui/docking/widget.py +214 -0
  224. lightfall/ui/events.py +75 -0
  225. lightfall/ui/mainwindow.py +1006 -0
  226. lightfall/ui/models/__init__.py +49 -0
  227. lightfall/ui/models/device_selection.py +389 -0
  228. lightfall/ui/models/device_tree.py +1095 -0
  229. lightfall/ui/models/thread_model.py +667 -0
  230. lightfall/ui/models/tiled_model.py +384 -0
  231. lightfall/ui/panels/__init__.py +28 -0
  232. lightfall/ui/panels/base.py +525 -0
  233. lightfall/ui/panels/bluesky_panel.py +619 -0
  234. lightfall/ui/panels/claude/__init__.py +9 -0
  235. lightfall/ui/panels/claude/agent_registry.py +168 -0
  236. lightfall/ui/panels/claude_panel.py +887 -0
  237. lightfall/ui/panels/device_panel.py +370 -0
  238. lightfall/ui/panels/documents_panel.py +166 -0
  239. lightfall/ui/panels/ipython_panel.py +580 -0
  240. lightfall/ui/panels/logbook_entries_panel.py +84 -0
  241. lightfall/ui/panels/logbook_panel.py +627 -0
  242. lightfall/ui/panels/logging_panel.py +587 -0
  243. lightfall/ui/panels/pipeline_jobs_panel.py +160 -0
  244. lightfall/ui/panels/pipeline_triggers_panel.py +170 -0
  245. lightfall/ui/panels/plugins/__init__.py +34 -0
  246. lightfall/ui/panels/plugins/bluesky_plugin.py +27 -0
  247. lightfall/ui/panels/plugins/claude_plugin.py +29 -0
  248. lightfall/ui/panels/plugins/device_plugin.py +27 -0
  249. lightfall/ui/panels/plugins/documents_plugin.py +26 -0
  250. lightfall/ui/panels/plugins/ipython_plugin.py +27 -0
  251. lightfall/ui/panels/plugins/logbook_entries_plugin.py +23 -0
  252. lightfall/ui/panels/plugins/logbook_plugin.py +27 -0
  253. lightfall/ui/panels/plugins/logging_plugin.py +27 -0
  254. lightfall/ui/panels/plugins/pipeline_jobs_plugin.py +23 -0
  255. lightfall/ui/panels/plugins/pipeline_triggers_plugin.py +25 -0
  256. lightfall/ui/panels/plugins/queue_plugin.py +29 -0
  257. lightfall/ui/panels/plugins/synoptic_plugin.py +38 -0
  258. lightfall/ui/panels/plugins/threads_plugin.py +27 -0
  259. lightfall/ui/panels/plugins/tiled_browser_plugin.py +27 -0
  260. lightfall/ui/panels/plugins/visualization_plugin.py +27 -0
  261. lightfall/ui/panels/queue.py +754 -0
  262. lightfall/ui/panels/registry.py +483 -0
  263. lightfall/ui/panels/synoptic/__init__.py +27 -0
  264. lightfall/ui/panels/synoptic/editors.py +481 -0
  265. lightfall/ui/panels/synoptic/items.py +556 -0
  266. lightfall/ui/panels/synoptic/models.py +336 -0
  267. lightfall/ui/panels/synoptic/panel.py +889 -0
  268. lightfall/ui/panels/synoptic/serialization.py +300 -0
  269. lightfall/ui/panels/synoptic/view.py +504 -0
  270. lightfall/ui/panels/threads_panel.py +621 -0
  271. lightfall/ui/panels/tiled_browser_panel.py +854 -0
  272. lightfall/ui/panels/visualization_panel.py +508 -0
  273. lightfall/ui/preferences/__init__.py +24 -0
  274. lightfall/ui/preferences/backend.py +148 -0
  275. lightfall/ui/preferences/builtin.py +220 -0
  276. lightfall/ui/preferences/claude_settings.py +762 -0
  277. lightfall/ui/preferences/device_settings.py +461 -0
  278. lightfall/ui/preferences/dialog.py +234 -0
  279. lightfall/ui/preferences/editor_settings.py +227 -0
  280. lightfall/ui/preferences/ipc_settings.py +226 -0
  281. lightfall/ui/preferences/logbook_settings.py +232 -0
  282. lightfall/ui/preferences/login_settings.py +183 -0
  283. lightfall/ui/preferences/manager.py +562 -0
  284. lightfall/ui/preferences/plugin_settings.py +392 -0
  285. lightfall/ui/preferences/proxy_settings.py +561 -0
  286. lightfall/ui/preferences/skill_settings.py +28 -0
  287. lightfall/ui/preferences/tiled_settings.py +469 -0
  288. lightfall/ui/preferences/tool_settings.py +393 -0
  289. lightfall/ui/preferences/user_portable_backend.py +131 -0
  290. lightfall/ui/preferences/user_profile_settings.py +316 -0
  291. lightfall/ui/preferences/visualization_settings.py +159 -0
  292. lightfall/ui/resources/__init__.py +1 -0
  293. lightfall/ui/resources/logo.png +0 -0
  294. lightfall/ui/statusbar/__init__.py +11 -0
  295. lightfall/ui/statusbar/manager.py +379 -0
  296. lightfall/ui/statusbar/plugins/__init__.py +28 -0
  297. lightfall/ui/statusbar/plugins/als_beam_status.py +218 -0
  298. lightfall/ui/statusbar/plugins/auth_status.py +116 -0
  299. lightfall/ui/statusbar/plugins/connection_status.py +100 -0
  300. lightfall/ui/statusbar/plugins/thread_status.py +556 -0
  301. lightfall/ui/statusbar/plugins/tiled_status.py +179 -0
  302. lightfall/ui/statusbar/plugins/user_status.py +84 -0
  303. lightfall/ui/theater/__init__.py +28 -0
  304. lightfall/ui/theater/manager.py +124 -0
  305. lightfall/ui/theater/overlay.py +279 -0
  306. lightfall/ui/theater/proxy.py +111 -0
  307. lightfall/ui/theme/__init__.py +18 -0
  308. lightfall/ui/theme/builtin.py +1015 -0
  309. lightfall/ui/theme/manager.py +875 -0
  310. lightfall/ui/theme/registry.py +195 -0
  311. lightfall/ui/toast.py +221 -0
  312. lightfall/ui/tutorial.py +1100 -0
  313. lightfall/ui/widgets/__init__.py +110 -0
  314. lightfall/ui/widgets/base_control.py +259 -0
  315. lightfall/ui/widgets/camera/__init__.py +36 -0
  316. lightfall/ui/widgets/camera/base.py +815 -0
  317. lightfall/ui/widgets/camera/dark_frames.py +213 -0
  318. lightfall/ui/widgets/camera/image_view.py +649 -0
  319. lightfall/ui/widgets/camera/panels/__init__.py +14 -0
  320. lightfall/ui/widgets/camera/panels/cooler.py +320 -0
  321. lightfall/ui/widgets/camera/panels/temperature.py +192 -0
  322. lightfall/ui/widgets/camera/plan_based.py +202 -0
  323. lightfall/ui/widgets/compact_motor.py +522 -0
  324. lightfall/ui/widgets/controller_matcher.py +278 -0
  325. lightfall/ui/widgets/controller_registry.py +144 -0
  326. lightfall/ui/widgets/device_control.py +411 -0
  327. lightfall/ui/widgets/device_selector.py +438 -0
  328. lightfall/ui/widgets/device_tree_tab.py +461 -0
  329. lightfall/ui/widgets/document_stream.py +1028 -0
  330. lightfall/ui/widgets/favorites_tab.py +191 -0
  331. lightfall/ui/widgets/motor_control.py +1120 -0
  332. lightfall/ui/widgets/observers/__init__.py +8 -0
  333. lightfall/ui/widgets/observers/camera.py +48 -0
  334. lightfall/ui/widgets/observers/image_view.py +130 -0
  335. lightfall/ui/widgets/plan_config.py +954 -0
  336. lightfall/ui/widgets/plan_edit_dialog.py +294 -0
  337. lightfall/ui/widgets/plan_selector.py +452 -0
  338. lightfall/ui/widgets/profile_avatar.py +128 -0
  339. lightfall/ui/widgets/queue_view.py +647 -0
  340. lightfall/ui/widgets/runengine_control.py +549 -0
  341. lightfall/ui/widgets/signal_control.py +793 -0
  342. lightfall/ui/widgets/skill_trigger_button.py +183 -0
  343. lightfall/ui/widgets/tiled_filter_widget.py +314 -0
  344. lightfall/ui/widgets/tiled_status.py +149 -0
  345. lightfall/ui/widgets/warning_banner.py +185 -0
  346. lightfall/utils/__init__.py +53 -0
  347. lightfall/utils/crash_diagnostics.py +454 -0
  348. lightfall/utils/data_migration.py +22 -0
  349. lightfall/utils/editor_launcher.py +594 -0
  350. lightfall/utils/error_collector.py +245 -0
  351. lightfall/utils/git_tracker.py +197 -0
  352. lightfall/utils/log_buffer.py +233 -0
  353. lightfall/utils/logging.py +229 -0
  354. lightfall/utils/module_resolver.py +70 -0
  355. lightfall/utils/sentry.py +722 -0
  356. lightfall/utils/threads.py +991 -0
  357. lightfall/utils/tiled_helpers.py +96 -0
  358. lightfall/visualization/__init__.py +50 -0
  359. lightfall/visualization/base.py +5 -0
  360. lightfall/visualization/base_visualization.py +74 -0
  361. lightfall/visualization/fitting/__init__.py +24 -0
  362. lightfall/visualization/fitting/base.py +267 -0
  363. lightfall/visualization/fitting/fitters.py +325 -0
  364. lightfall/visualization/fitting/panel.py +265 -0
  365. lightfall/visualization/memory.py +392 -0
  366. lightfall/visualization/motor_mixin.py +524 -0
  367. lightfall/visualization/pg.py +156 -0
  368. lightfall/visualization/registry.py +144 -0
  369. lightfall/visualization/spec.py +79 -0
  370. lightfall/visualization/theme.py +266 -0
  371. lightfall/visualization/widgets/__init__.py +28 -0
  372. lightfall/visualization/widgets/adaptive/__init__.py +1 -0
  373. lightfall/visualization/widgets/adaptive/heatmap.py +655 -0
  374. lightfall/visualization/widgets/adaptive/plot.py +233 -0
  375. lightfall/visualization/widgets/heatmap.py +264 -0
  376. lightfall/visualization/widgets/image_stack.py +316 -0
  377. lightfall/visualization/widgets/image_view_toolbar.py +227 -0
  378. lightfall/visualization/widgets/lazy_image_view.py +590 -0
  379. lightfall/visualization/widgets/plot_1d.py +262 -0
  380. lightfall/visualization/widgets/scatter.py +247 -0
  381. lightfall/visualization/widgets/table.py +221 -0
  382. lightfall/visualization/widgets/time_axis.py +93 -0
  383. lightfall-0.1.1.dist-info/METADATA +223 -0
  384. lightfall-0.1.1.dist-info/RECORD +388 -0
  385. lightfall-0.1.1.dist-info/WHEEL +4 -0
  386. lightfall-0.1.1.dist-info/entry_points.txt +6 -0
  387. lightfall-0.1.1.dist-info/licenses/LEGAL.md +13 -0
  388. lightfall-0.1.1.dist-info/licenses/LICENSE.md +33 -0
@@ -0,0 +1,1065 @@
1
+ """
2
+ Entry-level widgets for the fragment-based logbook.
3
+
4
+ Provides:
5
+ * **EntryWidget** – displays a single logbook entry as a vertical list of
6
+ fragment widgets, with automatic grouping of consecutive readonly fragments.
7
+ * **EntryListWidget** – sidebar listing all entries with selection, sorting,
8
+ and creation controls.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import uuid
14
+ from dataclasses import dataclass, field
15
+ from datetime import datetime
16
+ from typing import Any
17
+
18
+ from loguru import logger
19
+ from PySide6.QtCore import (
20
+ QAbstractListModel,
21
+ QEvent,
22
+ QModelIndex,
23
+ QRect,
24
+ QSize,
25
+ QSortFilterProxyModel,
26
+ Qt,
27
+ Signal,
28
+ Slot,
29
+ )
30
+ from PySide6.QtGui import (
31
+ QBrush,
32
+ QColor,
33
+ QCursor,
34
+ QDragEnterEvent,
35
+ QDragMoveEvent,
36
+ QDropEvent,
37
+ QFont,
38
+ QFontMetrics,
39
+ QMouseEvent,
40
+ QPainter,
41
+ QPen,
42
+ )
43
+ from PySide6.QtWidgets import (
44
+ QComboBox,
45
+ QFrame,
46
+ QHBoxLayout,
47
+ QLabel,
48
+ QLineEdit,
49
+ QListView,
50
+ QPushButton,
51
+ QScrollArea,
52
+ QSizePolicy,
53
+ QStyledItemDelegate,
54
+ QStyleOptionViewItem,
55
+ QToolBar,
56
+ QToolButton,
57
+ QVBoxLayout,
58
+ QWidget,
59
+ )
60
+
61
+ from lightfall.logbook.fragment_widgets import (
62
+ CollapseMode,
63
+ CollapsibleGroup,
64
+ FragmentData,
65
+ FragmentType,
66
+ ImageFragmentWidget,
67
+ ReadonlyFragmentWidget,
68
+ TextFragmentWidget,
69
+ )
70
+ from lightfall.logbook.style import is_dark_theme
71
+
72
+ # ---------------------------------------------------------------------------
73
+ # Lightweight entry data container
74
+ # ---------------------------------------------------------------------------
75
+
76
+
77
+ @dataclass
78
+ class EntryData:
79
+ """Minimal logbook entry container (will be replaced by real model)."""
80
+
81
+ id: str = field(default_factory=lambda: str(uuid.uuid4())[:12])
82
+ title: str = ""
83
+ fragments: list[FragmentData] = field(default_factory=list)
84
+ tags: list[str] = field(default_factory=list)
85
+ created_at: datetime = field(default_factory=datetime.now)
86
+ updated_at: datetime = field(default_factory=datetime.now)
87
+
88
+
89
+ # ---------------------------------------------------------------------------
90
+ # Tag chip helper
91
+ # ---------------------------------------------------------------------------
92
+
93
+
94
+ class _TagChip(QFrame):
95
+ """Small coloured chip with optional remove button."""
96
+
97
+ removed = Signal(str) # tag text
98
+
99
+ def __init__(self, tag: str, *, removable: bool = True, parent: QWidget | None = None) -> None:
100
+ super().__init__(parent)
101
+ self._tag = tag
102
+ bg = "#3a3a5c" if is_dark_theme() else "#e0e0f0"
103
+ fg = "#c0c0e0" if is_dark_theme() else "#333366"
104
+ self.setStyleSheet(
105
+ f"_TagChip {{ background: {bg}; color: {fg}; border-radius: 6px; "
106
+ f"padding: 1px 4px; font-size: 8pt; }}"
107
+ )
108
+ self.setSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Fixed)
109
+
110
+ layout = QHBoxLayout(self)
111
+ layout.setContentsMargins(4, 0, 2, 0)
112
+ layout.setSpacing(2)
113
+
114
+ lbl = QLabel(tag)
115
+ lbl.setStyleSheet(f"color: {fg}; font-size: 8pt; background: transparent;")
116
+ layout.addWidget(lbl)
117
+
118
+ if removable:
119
+ close_btn = QToolButton()
120
+ close_btn.setText("✕")
121
+ close_btn.setStyleSheet(
122
+ f"QToolButton {{ border: none; color: {fg}; font-size: 7pt; padding: 0 2px; background: transparent; }} "
123
+ f"QToolButton:hover {{ color: #f44336; }}"
124
+ )
125
+ close_btn.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
126
+ close_btn.clicked.connect(lambda: self.removed.emit(self._tag))
127
+ layout.addWidget(close_btn)
128
+
129
+
130
+ # _tag_chip removed — delegate paints chips directly
131
+
132
+
133
+ # ---------------------------------------------------------------------------
134
+ # EntryWidget
135
+ # ---------------------------------------------------------------------------
136
+
137
+
138
+ class EntryWidget(QFrame):
139
+ """Displays one logbook entry as a vertical list of fragments.
140
+
141
+ Automatically groups consecutive readonly fragments into
142
+ :class:`CollapsibleGroup` widgets.
143
+
144
+ Signals:
145
+ fragment_added(entry_id, fragment_id): New text fragment created.
146
+ fragment_changed(entry_id, fragment_id, content): Fragment edited.
147
+ fragment_deleted(entry_id, fragment_id): Fragment removed.
148
+ """
149
+
150
+ fragment_added = Signal(str, str)
151
+ fragment_changed = Signal(str, str, str)
152
+ fragment_deleted = Signal(str, str)
153
+ fragment_reordered = Signal(str, list) # (entry_id, [fragment_ids])
154
+ title_changed = Signal(str, str) # (entry_id, new_title)
155
+ tags_changed = Signal(str, list) # (entry_id, new_tags)
156
+ claude_requested = Signal(str, str) # (entry_id, fragment_id)
157
+
158
+ def __init__(
159
+ self,
160
+ entry: EntryData,
161
+ collapse_mode: CollapseMode = CollapseMode.ALL_READONLY,
162
+ parent: QWidget | None = None,
163
+ ) -> None:
164
+ super().__init__(parent)
165
+ self._entry = entry
166
+ self._collapse_mode = collapse_mode
167
+
168
+ self.setFrameShape(QFrame.Shape.NoFrame)
169
+ self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
170
+
171
+ root = QVBoxLayout(self)
172
+ root.setContentsMargins(8, 8, 8, 8)
173
+ root.setSpacing(6)
174
+
175
+ # --- header ---
176
+ self._header = self._build_header()
177
+ root.addWidget(self._header)
178
+
179
+ # --- scrollable fragment area ---
180
+ scroll = QScrollArea()
181
+ scroll.setWidgetResizable(True)
182
+ scroll.setFrameShape(QFrame.Shape.NoFrame)
183
+
184
+ self._fragment_container = QWidget()
185
+ self._fragment_container.setAcceptDrops(True)
186
+ self._fragment_container.dragEnterEvent = self._frag_drag_enter
187
+ self._fragment_container.dragMoveEvent = self._frag_drag_move
188
+ self._fragment_container.dropEvent = self._frag_drop
189
+ self._fragment_layout = QVBoxLayout(self._fragment_container)
190
+ self._fragment_layout.setContentsMargins(0, 0, 0, 0)
191
+ self._fragment_layout.setSpacing(4)
192
+
193
+ # --- add-note button (inside fragment list, acts like a ghost fragment) ---
194
+ self._add_btn = QPushButton("+ Add note")
195
+ self._add_btn.setFlat(True)
196
+ self._add_btn.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
197
+ self._add_btn.setStyleSheet(
198
+ "color: #888; font-size: 9pt; padding: 8px 8px; text-align: left; "
199
+ "border: 1px dashed #555; border-radius: 4px;"
200
+ )
201
+ self._add_btn.clicked.connect(self._add_text_fragment)
202
+ self._fragment_layout.addWidget(self._add_btn)
203
+
204
+ self._fragment_layout.addStretch()
205
+
206
+ scroll.setWidget(self._fragment_container)
207
+ root.addWidget(scroll, 1)
208
+
209
+ # --- bottom toolbar ---
210
+ self._toolbar = self._build_toolbar()
211
+ root.addWidget(self._toolbar)
212
+
213
+ # Build fragment widgets
214
+ self._widget_items: list[QWidget] = []
215
+ self._rebuild_fragments()
216
+
217
+ # -- public --
218
+
219
+ @property
220
+ def entry(self) -> EntryData:
221
+ return self._entry
222
+
223
+ def set_entry(self, entry: EntryData) -> None:
224
+ """Replace the displayed entry."""
225
+ self._entry = entry
226
+ self._update_header()
227
+ self._rebuild_fragments()
228
+
229
+ def set_collapse_mode(self, mode: CollapseMode) -> None:
230
+ if mode != self._collapse_mode:
231
+ self._collapse_mode = mode
232
+ self._rebuild_fragments()
233
+
234
+ # -- header --
235
+
236
+ def _build_header(self) -> QWidget:
237
+ header = QWidget()
238
+ layout = QVBoxLayout(header)
239
+ layout.setContentsMargins(0, 0, 0, 4)
240
+ layout.setSpacing(2)
241
+
242
+ # Title / date row
243
+ top = QHBoxLayout()
244
+ self._title_edit = QLineEdit()
245
+ self._title_edit.setPlaceholderText("Untitled entry")
246
+ self._title_edit.setStyleSheet(
247
+ "font-size: 12pt; font-weight: bold; border: none; "
248
+ "background: transparent; padding: 2px 0;"
249
+ )
250
+ self._title_edit.editingFinished.connect(self._on_title_edited)
251
+ top.addWidget(self._title_edit, 1)
252
+
253
+ self._date_label = QLabel()
254
+ self._date_label.setStyleSheet("font-size: 8pt; color: #888;")
255
+ top.addWidget(self._date_label)
256
+ layout.addLayout(top)
257
+
258
+ # Tags row
259
+ self._tags_layout = QHBoxLayout()
260
+ self._tags_layout.setContentsMargins(0, 0, 0, 0)
261
+ self._tags_layout.setSpacing(4)
262
+ layout.addLayout(self._tags_layout)
263
+
264
+ self._update_header()
265
+ return header
266
+
267
+ def _update_header(self) -> None:
268
+ self._title_edit.setText(self._entry.title or "")
269
+ self._date_label.setText(self._entry.created_at.strftime("%Y-%m-%d %H:%M"))
270
+
271
+ # Clear old tag chips
272
+ while self._tags_layout.count():
273
+ item = self._tags_layout.takeAt(0)
274
+ if item.widget():
275
+ item.widget().deleteLater()
276
+ for tag in self._entry.tags:
277
+ chip = _TagChip(tag, removable=True)
278
+ chip.removed.connect(self._on_tag_removed)
279
+ self._tags_layout.addWidget(chip)
280
+
281
+ # Add-tag button
282
+ add_tag_btn = QToolButton()
283
+ add_tag_btn.setText("+ tag")
284
+ add_tag_btn.setStyleSheet(
285
+ "QToolButton { border: 1px dashed #666; border-radius: 6px; "
286
+ "padding: 1px 6px; font-size: 8pt; color: #888; } "
287
+ "QToolButton:hover { border-color: #aaa; color: #aaa; }"
288
+ )
289
+ add_tag_btn.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
290
+ add_tag_btn.clicked.connect(self._on_add_tag_clicked)
291
+ self._tags_layout.addWidget(add_tag_btn)
292
+ self._tags_layout.addStretch()
293
+
294
+ # -- fragment building --
295
+
296
+ # -- toolbar --
297
+
298
+ def _build_toolbar(self) -> QToolBar:
299
+ """Build the bottom toolbar with collapse controls."""
300
+ toolbar = QToolBar()
301
+ toolbar.setMovable(False)
302
+ toolbar.setFloatable(False)
303
+ toolbar.setStyleSheet(
304
+ "QToolBar { border-top: 1px solid #444; padding: 2px 4px; spacing: 2px; }"
305
+ )
306
+
307
+ spacer = QWidget()
308
+ spacer.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
309
+ toolbar.addWidget(spacer)
310
+
311
+ # Collapse mode buttons
312
+ self._expand_all_btn = QToolButton()
313
+ self._expand_all_btn.setText("Expand All")
314
+ self._expand_all_btn.setToolTip("Expand all collapsed groups")
315
+ self._expand_all_btn.clicked.connect(self._expand_all_groups)
316
+ toolbar.addWidget(self._expand_all_btn)
317
+
318
+ self._collapse_all_btn = QToolButton()
319
+ self._collapse_all_btn.setText("Collapse All")
320
+ self._collapse_all_btn.setToolTip("Group all consecutive readonly fragments")
321
+ self._collapse_all_btn.setCheckable(True)
322
+ self._collapse_all_btn.setChecked(self._collapse_mode == CollapseMode.ALL_READONLY)
323
+ self._collapse_all_btn.clicked.connect(
324
+ lambda: self._set_collapse_mode(CollapseMode.ALL_READONLY)
325
+ )
326
+ toolbar.addWidget(self._collapse_all_btn)
327
+
328
+ self._collapse_type_btn = QToolButton()
329
+ self._collapse_type_btn.setText("By Type")
330
+ self._collapse_type_btn.setToolTip("Group consecutive readonly fragments by subtype")
331
+ self._collapse_type_btn.setCheckable(True)
332
+ self._collapse_type_btn.setChecked(self._collapse_mode == CollapseMode.SAME_TYPE)
333
+ self._collapse_type_btn.clicked.connect(
334
+ lambda: self._set_collapse_mode(CollapseMode.SAME_TYPE)
335
+ )
336
+ toolbar.addWidget(self._collapse_type_btn)
337
+
338
+ return toolbar
339
+
340
+ def _expand_all_groups(self) -> None:
341
+ for w in self._widget_items:
342
+ if isinstance(w, CollapsibleGroup) and w.is_collapsed:
343
+ w._toggle_collapsed()
344
+
345
+ def _set_collapse_mode(self, mode: CollapseMode) -> None:
346
+ self._collapse_mode = mode
347
+ self._collapse_all_btn.setChecked(mode == CollapseMode.ALL_READONLY)
348
+ self._collapse_type_btn.setChecked(mode == CollapseMode.SAME_TYPE)
349
+ self._rebuild_fragments()
350
+
351
+ def _on_title_edited(self) -> None:
352
+ new_title = self._title_edit.text().strip()
353
+ if new_title != self._entry.title:
354
+ self._entry.title = new_title
355
+ self.title_changed.emit(self._entry.id, new_title)
356
+
357
+ def _on_tag_removed(self, tag: str) -> None:
358
+ if tag in self._entry.tags:
359
+ self._entry.tags.remove(tag)
360
+ self._update_header()
361
+ self.tags_changed.emit(self._entry.id, self._entry.tags)
362
+
363
+ def _on_add_tag_clicked(self) -> None:
364
+ """Replace the '+ tag' button with an inline QLineEdit."""
365
+ # Find and hide the add button
366
+ for i in range(self._tags_layout.count()):
367
+ w = self._tags_layout.itemAt(i).widget()
368
+ if isinstance(w, QToolButton) and w.text() == "+ tag":
369
+ w.setVisible(False)
370
+ break
371
+
372
+ tag_input = QLineEdit()
373
+ tag_input.setPlaceholderText("new tag")
374
+ tag_input.setFixedWidth(80)
375
+ tag_input.setStyleSheet(
376
+ "font-size: 8pt; border: 1px solid #666; border-radius: 6px; "
377
+ "padding: 1px 6px; background: transparent;"
378
+ )
379
+ # Insert before the stretch
380
+ self._tags_layout.insertWidget(self._tags_layout.count() - 1, tag_input)
381
+ tag_input.setFocus()
382
+
383
+ def commit() -> None:
384
+ text = tag_input.text().strip()
385
+ tag_input.deleteLater()
386
+ if text and text not in self._entry.tags:
387
+ self._entry.tags.append(text)
388
+ self.tags_changed.emit(self._entry.id, self._entry.tags)
389
+ self._update_header()
390
+
391
+ tag_input.returnPressed.connect(commit)
392
+ tag_input.editingFinished.connect(commit)
393
+
394
+ def _rebuild_fragments(self) -> None:
395
+ """Rebuild all fragment widgets, grouping readonly runs."""
396
+ # Remove old widgets (keep add button and trailing stretch)
397
+ for w in self._widget_items:
398
+ self._fragment_layout.removeWidget(w)
399
+ w.deleteLater()
400
+ self._widget_items.clear()
401
+
402
+ groups = _group_fragments(self._entry.fragments, self._collapse_mode)
403
+ insert_idx = 0
404
+ for group in groups:
405
+ widget: QWidget
406
+ if len(group) == 1 and group[0].fragment_type == FragmentType.TEXT:
407
+ widget = TextFragmentWidget(group[0])
408
+ widget.content_changed.connect(self._on_fragment_changed)
409
+ widget.delete_requested.connect(self._on_fragment_delete)
410
+ widget.claude_requested.connect(self._on_fragment_claude)
411
+ elif len(group) == 1 and group[0].fragment_type == FragmentType.IMAGE:
412
+ widget = ImageFragmentWidget(group[0])
413
+ widget.delete_requested.connect(self._on_fragment_delete)
414
+ widget.caption_changed.connect(self._on_fragment_changed)
415
+ widget.claude_requested.connect(self._on_fragment_claude)
416
+ elif all(f.fragment_type == FragmentType.READONLY for f in group) and len(group) > 1:
417
+ widget = CollapsibleGroup(group)
418
+ widget.collapse_mode = self._collapse_mode
419
+ elif len(group) == 1 and group[0].fragment_type == FragmentType.READONLY:
420
+ widget = ReadonlyFragmentWidget(group[0])
421
+ widget.delete_requested.connect(self._on_fragment_delete)
422
+ widget.claude_requested.connect(self._on_fragment_claude)
423
+ else:
424
+ # Mixed single item fallback
425
+ widget = ReadonlyFragmentWidget(group[0]) if group else QWidget()
426
+
427
+ self._fragment_layout.insertWidget(insert_idx, widget)
428
+ self._widget_items.append(widget)
429
+ insert_idx += 1
430
+
431
+ # -- slots --
432
+
433
+ @Slot(str, str)
434
+ def _on_fragment_changed(self, frag_id: str, content: str) -> None:
435
+ self._entry.updated_at = datetime.now()
436
+ self.fragment_changed.emit(self._entry.id, frag_id, content)
437
+
438
+ @Slot(str)
439
+ def _on_fragment_delete(self, frag_id: str) -> None:
440
+ """Remove a fragment from the entry."""
441
+ self._entry.fragments = [f for f in self._entry.fragments if f.id != frag_id]
442
+ self._entry.updated_at = datetime.now()
443
+ self._rebuild_fragments()
444
+ self.fragment_deleted.emit(self._entry.id, frag_id)
445
+ logger.debug("Deleted fragment {} from entry {}", frag_id, self._entry.id)
446
+
447
+ @Slot(str)
448
+ def _on_fragment_claude(self, frag_id: str) -> None:
449
+ """Forward Claude request to the panel."""
450
+ self.claude_requested.emit(self._entry.id, frag_id)
451
+
452
+ # -- drag & drop reorder --
453
+
454
+ def _frag_drag_enter(self, event: QDragEnterEvent) -> None:
455
+ if event.mimeData().hasFormat("application/x-logbook-fragment-id"):
456
+ event.acceptProposedAction()
457
+
458
+ def _frag_drag_move(self, event: QDragMoveEvent) -> None:
459
+ if event.mimeData().hasFormat("application/x-logbook-fragment-id"):
460
+ event.acceptProposedAction()
461
+
462
+ def _frag_drop(self, event: QDropEvent) -> None:
463
+ mime = event.mimeData()
464
+ if not mime.hasFormat("application/x-logbook-fragment-id"):
465
+ return
466
+ dragged_id = bytes(mime.data("application/x-logbook-fragment-id")).decode()
467
+
468
+ # Find the drop position by checking which widget we're over
469
+ drop_y = event.position().y()
470
+ target_idx = len(self._entry.fragments) # default: end
471
+
472
+ for i, w in enumerate(self._widget_items):
473
+ widget_y = w.y() + w.height() / 2
474
+ if drop_y < widget_y:
475
+ # Map widget back to fragment index
476
+ frag = (
477
+ getattr(w, "_fragment", None) if not isinstance(w, CollapsibleGroup) else None
478
+ )
479
+ if frag:
480
+ target_idx = next(
481
+ (j for j, f in enumerate(self._entry.fragments) if f.id == frag.id),
482
+ target_idx,
483
+ )
484
+ else:
485
+ target_idx = i
486
+ break
487
+
488
+ # Reorder
489
+ frags = self._entry.fragments
490
+ old_idx = next((j for j, f in enumerate(frags) if f.id == dragged_id), None)
491
+ if old_idx is None:
492
+ return
493
+
494
+ frag = frags.pop(old_idx)
495
+ if target_idx > old_idx:
496
+ target_idx -= 1
497
+ frags.insert(target_idx, frag)
498
+
499
+ self._rebuild_fragments()
500
+ self.fragment_reordered.emit(self._entry.id, [f.id for f in frags])
501
+ event.acceptProposedAction()
502
+
503
+ @Slot()
504
+ def _add_text_fragment(self) -> None:
505
+ frag = FragmentData(fragment_type=FragmentType.TEXT, content="")
506
+ self._entry.fragments.append(frag)
507
+ self._entry.updated_at = datetime.now()
508
+ self._rebuild_fragments()
509
+ self.fragment_added.emit(self._entry.id, frag.id)
510
+ logger.debug(f"Added text fragment {frag.id} to entry {self._entry.id}")
511
+
512
+ # Focus the newly created fragment's editor
513
+ for w in self._widget_items:
514
+ if isinstance(w, TextFragmentWidget) and w.fragment.id == frag.id:
515
+ w._enter_edit_mode()
516
+ break
517
+
518
+
519
+ # ---------------------------------------------------------------------------
520
+ # EntryListWidget
521
+ # ---------------------------------------------------------------------------
522
+
523
+
524
+ # ---------------------------------------------------------------------------
525
+ # Model / View components for EntryListWidget
526
+ # ---------------------------------------------------------------------------
527
+
528
+ # Custom data roles
529
+ _TitleRole = Qt.ItemDataRole.UserRole + 1
530
+ _DateRole = Qt.ItemDataRole.UserRole + 2
531
+ _TagsRole = Qt.ItemDataRole.UserRole + 3
532
+ _EntryIdRole = Qt.ItemDataRole.UserRole + 4
533
+ _UpdatedAtRole = Qt.ItemDataRole.UserRole + 5
534
+ _CreatedAtRole = Qt.ItemDataRole.UserRole + 6
535
+
536
+
537
+ class EntryListModel(QAbstractListModel):
538
+ """Stores ``EntryData`` objects for a ``QListView``."""
539
+
540
+ def __init__(self, parent: QWidget | None = None) -> None:
541
+ super().__init__(parent)
542
+ self._entries: list[EntryData] = []
543
+
544
+ # -- QAbstractListModel interface --
545
+
546
+ def rowCount(self, parent: QModelIndex | None = None) -> int: # noqa: N802
547
+ return len(self._entries)
548
+
549
+ def data(self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole) -> Any:
550
+ if not index.isValid() or not (0 <= index.row() < len(self._entries)):
551
+ return None
552
+ entry = self._entries[index.row()]
553
+ if role == Qt.ItemDataRole.DisplayRole or role == _TitleRole:
554
+ return entry.title or _first_line(entry)
555
+ if role == _DateRole:
556
+ return entry.created_at.strftime("%Y-%m-%d %H:%M")
557
+ if role == _TagsRole:
558
+ return entry.tags
559
+ if role == _EntryIdRole:
560
+ return entry.id
561
+ if role == _UpdatedAtRole:
562
+ return entry.updated_at
563
+ if role == _CreatedAtRole:
564
+ return entry.created_at
565
+ return None
566
+
567
+ # -- public helpers --
568
+
569
+ def set_entries(self, entries: list[EntryData]) -> None:
570
+ self.beginResetModel()
571
+ self._entries = list(entries)
572
+ self.endResetModel()
573
+
574
+ def add_entry(self, entry: EntryData) -> None:
575
+ row = len(self._entries)
576
+ self.beginInsertRows(QModelIndex(), row, row)
577
+ self._entries.append(entry)
578
+ self.endInsertRows()
579
+
580
+ def remove_entry(self, entry_id: str) -> None:
581
+ for row, e in enumerate(self._entries):
582
+ if e.id == entry_id:
583
+ self.beginRemoveRows(QModelIndex(), row, row)
584
+ self._entries.pop(row)
585
+ self.endRemoveRows()
586
+ return
587
+
588
+ def entry_at(self, index: QModelIndex) -> EntryData | None:
589
+ if index.isValid() and 0 <= index.row() < len(self._entries):
590
+ return self._entries[index.row()]
591
+ return None
592
+
593
+ def all_entries(self) -> list[EntryData]:
594
+ return list(self._entries)
595
+
596
+
597
+ class EntrySortFilterProxy(QSortFilterProxyModel):
598
+ """Sort by *created_at* or *updated_at* (descending) and filter by tag."""
599
+
600
+ def __init__(self, parent: QWidget | None = None) -> None:
601
+ super().__init__(parent)
602
+ self._sort_role_key: str = "created_at" # or "updated_at"
603
+ self._tag_filter: str | None = None
604
+ self.setSortRole(_CreatedAtRole)
605
+ self.setDynamicSortFilter(True)
606
+ self.sort(0, Qt.SortOrder.DescendingOrder)
607
+
608
+ # -- public --
609
+
610
+ def set_sort_key(self, key: str) -> None:
611
+ self._sort_role_key = key
612
+ role = _CreatedAtRole if key == "created_at" else _UpdatedAtRole
613
+ self.setSortRole(role)
614
+ self.invalidate()
615
+ self.sort(0, Qt.SortOrder.DescendingOrder)
616
+
617
+ def set_tag_filter(self, tag: str | None) -> None:
618
+ self._tag_filter = tag
619
+ self.invalidateFilter()
620
+
621
+ @property
622
+ def tag_filter(self) -> str | None:
623
+ return self._tag_filter
624
+
625
+ # -- overrides --
626
+
627
+ def lessThan(self, left: QModelIndex, right: QModelIndex) -> bool: # noqa: N802
628
+ lv = left.data(self.sortRole())
629
+ rv = right.data(self.sortRole())
630
+ if lv is None or rv is None:
631
+ return False
632
+ # Normalize to offset-naive for comparison
633
+ if hasattr(lv, "tzinfo") and lv.tzinfo is not None:
634
+ lv = lv.replace(tzinfo=None)
635
+ if hasattr(rv, "tzinfo") and rv.tzinfo is not None:
636
+ rv = rv.replace(tzinfo=None)
637
+ return lv < rv
638
+
639
+ def filterAcceptsRow( # noqa: N802
640
+ self, source_row: int, source_parent: QModelIndex
641
+ ) -> bool:
642
+ if self._tag_filter is None:
643
+ return True
644
+ idx = self.sourceModel().index(source_row, 0, source_parent)
645
+ tags = idx.data(_TagsRole) or []
646
+ return self._tag_filter in tags
647
+
648
+
649
+ class EntryDelegate(QStyledItemDelegate):
650
+ """Custom delegate that replicates the old ``_EntryRow`` look."""
651
+
652
+ delete_clicked = Signal(str) # entry_id
653
+
654
+ _ROW_PADDING = 6
655
+ _LINE_SPACING = 2
656
+ _CHIP_H_PAD = 6
657
+ _CHIP_V_PAD = 2
658
+ _CHIP_RADIUS = 6
659
+ _CHIP_SPACING = 4
660
+ _DELETE_SIZE = 18
661
+
662
+ def __init__(self, parent: QWidget | None = None) -> None:
663
+ super().__init__(parent)
664
+ self._hovered_index: QModelIndex = QModelIndex()
665
+
666
+ def set_hovered_index(self, index: QModelIndex) -> None:
667
+ self._hovered_index = index
668
+
669
+ # -- painting --
670
+
671
+ def paint(
672
+ self,
673
+ painter: QPainter,
674
+ option: QStyleOptionViewItem,
675
+ index: QModelIndex,
676
+ ) -> None:
677
+ painter.save()
678
+ painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
679
+
680
+ rect = option.rect
681
+ is_selected = bool(option.state & option.state.State_Selected)
682
+ is_hovered = self._hovered_index.isValid() and self._hovered_index.row() == index.row()
683
+ dark = is_dark_theme()
684
+
685
+ # Background — rounded rects for islands feel
686
+ _CARD_RADIUS = 6
687
+ card_rect = rect.adjusted(2, 1, -2, -1)
688
+ if is_selected:
689
+ bg = QColor("#3a3a5c") if dark else QColor("#d0d0f0")
690
+ painter.setBrush(QBrush(bg))
691
+ painter.setPen(Qt.PenStyle.NoPen)
692
+ painter.drawRoundedRect(card_rect, _CARD_RADIUS, _CARD_RADIUS)
693
+ elif is_hovered:
694
+ hover_bg = QColor("#2a2a4c") if dark else QColor("#e8e8f8")
695
+ painter.setBrush(QBrush(hover_bg))
696
+ painter.setPen(Qt.PenStyle.NoPen)
697
+ painter.drawRoundedRect(card_rect, _CARD_RADIUS, _CARD_RADIUS)
698
+
699
+ pad = self._ROW_PADDING
700
+ x0 = rect.left() + pad
701
+ y0 = rect.top() + pad
702
+ avail_w = rect.width() - 2 * pad
703
+
704
+ # Title (bold, 9pt)
705
+ title_font = QFont()
706
+ title_font.setPointSize(9)
707
+ title_font.setBold(True)
708
+ painter.setFont(title_font)
709
+ painter.setPen(QPen(QColor("#e0e0e0" if dark else "#222222")))
710
+ title_text = index.data(_TitleRole) or "Untitled entry"
711
+ fm_title = QFontMetrics(title_font)
712
+ elided = fm_title.elidedText(title_text, Qt.TextElideMode.ElideRight, avail_w)
713
+ painter.drawText(x0, y0 + fm_title.ascent(), elided)
714
+
715
+ # Second line: date + tag chips
716
+ y1 = y0 + fm_title.height() + self._LINE_SPACING
717
+
718
+ date_font = QFont()
719
+ date_font.setPointSize(8)
720
+ painter.setFont(date_font)
721
+ painter.setPen(QPen(QColor("#888888")))
722
+ date_text = index.data(_DateRole) or ""
723
+ fm_date = QFontMetrics(date_font)
724
+ painter.drawText(x0, y1 + fm_date.ascent(), date_text)
725
+
726
+ chip_x = x0 + fm_date.horizontalAdvance(date_text) + 8
727
+ tags = (index.data(_TagsRole) or [])[:3]
728
+ chip_bg = QColor("#3a3a5c" if dark else "#e0e0f0")
729
+ chip_fg = QColor("#c0c0e0" if dark else "#333366")
730
+ chip_font = QFont()
731
+ chip_font.setPointSize(8)
732
+ fm_chip = QFontMetrics(chip_font)
733
+
734
+ for tag in tags:
735
+ tw = fm_chip.horizontalAdvance(tag)
736
+ chip_w = tw + 2 * self._CHIP_H_PAD
737
+ chip_h = fm_chip.height() + 2 * self._CHIP_V_PAD
738
+ chip_rect = QRect(int(chip_x), int(y1), int(chip_w), int(chip_h))
739
+ painter.setBrush(QBrush(chip_bg))
740
+ painter.setPen(Qt.PenStyle.NoPen)
741
+ painter.drawRoundedRect(chip_rect, self._CHIP_RADIUS, self._CHIP_RADIUS)
742
+ painter.setPen(QPen(chip_fg))
743
+ painter.setFont(chip_font)
744
+ painter.drawText(chip_rect, Qt.AlignmentFlag.AlignCenter, tag)
745
+ chip_x += chip_w + self._CHIP_SPACING
746
+
747
+ # Delete button on hover
748
+ if is_hovered:
749
+ ds = self._DELETE_SIZE
750
+ dx = rect.right() - ds - pad
751
+ dy = rect.top() + pad
752
+ del_rect = QRect(dx, dy, ds, ds)
753
+
754
+ painter.setBrush(QBrush(QColor(244, 67, 54, 50)))
755
+ painter.setPen(Qt.PenStyle.NoPen)
756
+ painter.drawRoundedRect(del_rect, 3, 3)
757
+
758
+ del_font = QFont()
759
+ del_font.setPointSize(9)
760
+ del_font.setBold(True)
761
+ painter.setFont(del_font)
762
+ painter.setPen(QPen(QColor("#f44336")))
763
+ painter.drawText(del_rect, Qt.AlignmentFlag.AlignCenter, "✕")
764
+
765
+ painter.restore()
766
+
767
+ def sizeHint( # noqa: N802
768
+ self, option: QStyleOptionViewItem, index: QModelIndex
769
+ ) -> QSize:
770
+ title_font = QFont()
771
+ title_font.setPointSize(9)
772
+ title_font.setBold(True)
773
+ date_font = QFont()
774
+ date_font.setPointSize(8)
775
+ h = (
776
+ self._ROW_PADDING
777
+ + QFontMetrics(title_font).height()
778
+ + self._LINE_SPACING
779
+ + QFontMetrics(date_font).height()
780
+ + 2 * self._CHIP_V_PAD
781
+ + self._ROW_PADDING
782
+ )
783
+ return QSize(option.rect.width(), max(h, 44))
784
+
785
+ # -- delete click detection --
786
+
787
+ def editorEvent(self, event, model, option, index) -> bool: # noqa: N802
788
+ if (
789
+ isinstance(event, QMouseEvent)
790
+ and event.type() == event.Type.MouseButtonRelease
791
+ and event.button() == Qt.MouseButton.LeftButton
792
+ ):
793
+ rect = option.rect
794
+ pad = self._ROW_PADDING
795
+ ds = self._DELETE_SIZE
796
+ dx = rect.right() - ds - pad
797
+ dy = rect.top() + pad
798
+ del_rect = QRect(dx, dy, ds, ds)
799
+ if del_rect.contains(event.position().toPoint()):
800
+ entry_id = index.data(_EntryIdRole)
801
+ if entry_id:
802
+ self.delete_clicked.emit(entry_id)
803
+ return True
804
+ return super().editorEvent(event, model, option, index)
805
+
806
+
807
+ class EntryListWidget(QFrame):
808
+ """Sidebar listing all logbook entries.
809
+
810
+ Signals:
811
+ entry_selected(entry_id): User clicked an entry.
812
+ entry_delete_requested(entry_id): User requested deletion.
813
+ new_entry_requested(): User clicked 'New Entry'.
814
+ """
815
+
816
+ entry_selected = Signal(str)
817
+ entry_delete_requested = Signal(str) # entry_id
818
+ new_entry_requested = Signal()
819
+
820
+ def __init__(self, parent: QWidget | None = None) -> None:
821
+ super().__init__(parent)
822
+ self._selected_id: str | None = None
823
+ self.setObjectName("EntryListWidget")
824
+
825
+ self.setFrameShape(QFrame.Shape.NoFrame)
826
+ self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True)
827
+ self.setMinimumWidth(220)
828
+ self.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding)
829
+
830
+ root = QVBoxLayout(self)
831
+ root.setContentsMargins(6, 6, 6, 6)
832
+ root.setSpacing(6)
833
+
834
+ # --- toolbar row ---
835
+ toolbar = QHBoxLayout()
836
+ toolbar.setSpacing(4)
837
+ new_btn = QPushButton("+ New Entry")
838
+ new_btn.setStyleSheet(
839
+ "QPushButton { border: 1px solid #555; border-radius: 6px; "
840
+ "padding: 4px 10px; font-size: 9pt; } "
841
+ "QPushButton:hover { background: #3a3a5c; }"
842
+ )
843
+ new_btn.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
844
+ new_btn.clicked.connect(self.new_entry_requested)
845
+ toolbar.addWidget(new_btn)
846
+
847
+ self._sort_combo = QComboBox()
848
+ self._sort_combo.addItems(["Created", "Updated"])
849
+ self._sort_combo.setStyleSheet(
850
+ "QComboBox { border: 1px solid #555; border-radius: 6px; "
851
+ "padding: 3px 8px; font-size: 8pt; }"
852
+ )
853
+ self._sort_combo.currentIndexChanged.connect(self._on_sort_changed)
854
+ toolbar.addWidget(self._sort_combo)
855
+ root.addLayout(toolbar)
856
+
857
+ # --- tag filter row ---
858
+ self._tag_filter_container = QWidget()
859
+ self._tag_filter_layout = QHBoxLayout(self._tag_filter_container)
860
+ self._tag_filter_layout.setContentsMargins(0, 0, 0, 0)
861
+ self._tag_filter_layout.setSpacing(3)
862
+ self._tag_filter_container.setVisible(False)
863
+ root.addWidget(self._tag_filter_container)
864
+
865
+ # --- model / view ---
866
+ self._model = EntryListModel(self)
867
+ self._proxy = EntrySortFilterProxy(self)
868
+ self._proxy.setSourceModel(self._model)
869
+
870
+ self._delegate = EntryDelegate(self)
871
+ self._delegate.delete_clicked.connect(self._on_row_delete)
872
+
873
+ self._view = QListView()
874
+ self._view.setModel(self._proxy)
875
+ self._view.setItemDelegate(self._delegate)
876
+ self._view.setFrameShape(QFrame.Shape.NoFrame)
877
+ self._view.setSelectionMode(QListView.SelectionMode.SingleSelection)
878
+ self._view.setMouseTracking(True)
879
+ self._view.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
880
+ self._view.setVerticalScrollMode(QListView.ScrollMode.ScrollPerPixel)
881
+ self._view.viewport().installEventFilter(self)
882
+ self._view.selectionModel().currentChanged.connect(self._on_current_changed)
883
+ self._view.setStyleSheet(
884
+ "QListView { background: transparent; }"
885
+ "QListView::item { border: none; }"
886
+ "QListView::item:selected { background: transparent; }"
887
+ "QListView::item:hover { background: transparent; }"
888
+ )
889
+
890
+ root.addWidget(self._view, 1)
891
+
892
+ # -- public API --
893
+
894
+ def set_entries(self, entries: list[EntryData]) -> None:
895
+ """Replace the full entry list."""
896
+ self._model.set_entries(entries)
897
+ self._rebuild_tag_filter()
898
+ self._restore_selection()
899
+
900
+ def add_entry(self, entry: EntryData) -> None:
901
+ self._model.add_entry(entry)
902
+ self._rebuild_tag_filter()
903
+
904
+ def select_entry(self, entry_id: str) -> None:
905
+ self._selected_id = entry_id
906
+ self._restore_selection()
907
+
908
+ # -- internal --
909
+
910
+ def _restore_selection(self) -> None:
911
+ """Select the row matching ``_selected_id`` in the proxy view."""
912
+ if not self._selected_id:
913
+ return
914
+ for row in range(self._proxy.rowCount()):
915
+ idx = self._proxy.index(row, 0)
916
+ if idx.data(_EntryIdRole) == self._selected_id:
917
+ self._view.setCurrentIndex(idx)
918
+ return
919
+
920
+ def _rebuild_tag_filter(self) -> None:
921
+ """Rebuild the tag filter chips from all entries."""
922
+ while self._tag_filter_layout.count():
923
+ item = self._tag_filter_layout.takeAt(0)
924
+ if item.widget():
925
+ item.widget().deleteLater()
926
+
927
+ all_tags: set[str] = set()
928
+ for e in self._model.all_entries():
929
+ all_tags.update(e.tags)
930
+
931
+ if not all_tags:
932
+ self._tag_filter_container.setVisible(False)
933
+ return
934
+
935
+ self._tag_filter_container.setVisible(True)
936
+
937
+ # "All" button
938
+ all_btn = QToolButton()
939
+ all_btn.setText("All")
940
+ active = self._proxy.tag_filter is None
941
+ bg = "#4a4a6c" if active else "transparent"
942
+ all_btn.setStyleSheet(
943
+ f"QToolButton {{ border: 1px solid #555; border-radius: 6px; "
944
+ f"padding: 1px 6px; font-size: 8pt; background: {bg}; }} "
945
+ f"QToolButton:hover {{ background: #4a4a6c; }}"
946
+ )
947
+ all_btn.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
948
+ all_btn.clicked.connect(lambda: self._on_tag_filter(None))
949
+ self._tag_filter_layout.addWidget(all_btn)
950
+
951
+ for tag in sorted(all_tags):
952
+ btn = QToolButton()
953
+ btn.setText(tag)
954
+ active = self._proxy.tag_filter == tag
955
+ bg = "#4a4a6c" if active else "transparent"
956
+ btn.setStyleSheet(
957
+ f"QToolButton {{ border: 1px solid #555; border-radius: 6px; "
958
+ f"padding: 1px 6px; font-size: 8pt; background: {bg}; }} "
959
+ f"QToolButton:hover {{ background: #4a4a6c; }}"
960
+ )
961
+ btn.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
962
+ btn.clicked.connect(lambda checked=False, t=tag: self._on_tag_filter(t))
963
+ self._tag_filter_layout.addWidget(btn)
964
+
965
+ self._tag_filter_layout.addStretch()
966
+
967
+ def _on_tag_filter(self, tag: str | None) -> None:
968
+ self._proxy.set_tag_filter(tag)
969
+ self._rebuild_tag_filter()
970
+
971
+ def eventFilter(self, obj, event): # noqa: N802
972
+ if obj is self._view.viewport():
973
+ if event.type() == QEvent.Type.MouseMove:
974
+ idx = self._view.indexAt(event.position().toPoint())
975
+ self._delegate.set_hovered_index(idx)
976
+ self._view.viewport().update()
977
+ elif event.type() == QEvent.Type.Leave:
978
+ self._delegate.set_hovered_index(QModelIndex())
979
+ self._view.viewport().update()
980
+ return super().eventFilter(obj, event)
981
+
982
+ @Slot(QModelIndex, QModelIndex)
983
+ def _on_current_changed(self, current: QModelIndex, _previous: QModelIndex) -> None:
984
+ if not current.isValid():
985
+ return
986
+ entry_id = current.data(_EntryIdRole)
987
+ if entry_id and entry_id != self._selected_id:
988
+ self._selected_id = entry_id
989
+ self.entry_selected.emit(entry_id)
990
+
991
+ @Slot(str)
992
+ def _on_row_delete(self, entry_id: str) -> None:
993
+ self._model.remove_entry(entry_id)
994
+ entries = self._model.all_entries()
995
+ if self._selected_id == entry_id:
996
+ self._selected_id = entries[0].id if entries else None
997
+ self._rebuild_tag_filter()
998
+ self.entry_delete_requested.emit(entry_id)
999
+ if self._selected_id:
1000
+ self._restore_selection()
1001
+ self.entry_selected.emit(self._selected_id)
1002
+
1003
+ @Slot(int)
1004
+ def _on_sort_changed(self, index: int) -> None:
1005
+ key = "created_at" if index == 0 else "updated_at"
1006
+ self._proxy.set_sort_key(key)
1007
+
1008
+
1009
+ # ---------------------------------------------------------------------------
1010
+ # Private helpers
1011
+ # ---------------------------------------------------------------------------
1012
+
1013
+
1014
+ # _EntryRow removed — replaced by EntryDelegate + QListView
1015
+
1016
+
1017
+ def _first_line(entry: EntryData) -> str:
1018
+ """Extract a display title from the first text fragment."""
1019
+ for f in entry.fragments:
1020
+ if f.fragment_type == FragmentType.TEXT and f.content.strip():
1021
+ line = f.content.strip().split("\n")[0][:60]
1022
+ return line
1023
+ return "Untitled entry"
1024
+
1025
+
1026
+ def _group_fragments(
1027
+ fragments: list[FragmentData],
1028
+ mode: CollapseMode,
1029
+ ) -> list[list[FragmentData]]:
1030
+ """Group fragments for display.
1031
+
1032
+ Text fragments are always standalone. Consecutive readonly fragments
1033
+ are grouped according to *mode*.
1034
+
1035
+ Returns a list of groups, where each group is a list of fragments.
1036
+ """
1037
+ groups: list[list[FragmentData]] = []
1038
+ current_run: list[FragmentData] = []
1039
+
1040
+ def flush() -> None:
1041
+ nonlocal current_run
1042
+ if current_run:
1043
+ if mode == CollapseMode.ALL_READONLY:
1044
+ groups.append(current_run)
1045
+ else: # SAME_TYPE
1046
+ # Sub-split by subtype
1047
+ sub: list[FragmentData] = []
1048
+ for f in current_run:
1049
+ if sub and sub[-1].subtype != f.subtype:
1050
+ groups.append(sub)
1051
+ sub = []
1052
+ sub.append(f)
1053
+ if sub:
1054
+ groups.append(sub)
1055
+ current_run = []
1056
+
1057
+ for frag in fragments:
1058
+ if frag.fragment_type in (FragmentType.TEXT, FragmentType.IMAGE):
1059
+ flush()
1060
+ groups.append([frag])
1061
+ else:
1062
+ current_run.append(frag)
1063
+
1064
+ flush()
1065
+ return groups