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,756 @@
1
+ """Login dialog for Lightfall authentication.
2
+
3
+ Provides a modal dialog for users to authenticate via Keycloak
4
+ or a local development account.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import asyncio
10
+ import sys
11
+ from datetime import UTC
12
+ from enum import Enum, auto
13
+ from typing import TYPE_CHECKING
14
+
15
+ from PySide6.QtCore import Qt, Signal, Slot
16
+ from PySide6.QtWidgets import (
17
+ QFormLayout,
18
+ QHBoxLayout,
19
+ QLabel,
20
+ QLineEdit,
21
+ QProgressBar,
22
+ QPushButton,
23
+ QVBoxLayout,
24
+ QWidget,
25
+ )
26
+
27
+ from lightfall.auth.session import AuthState, SessionManager
28
+ from lightfall.ui.dialogs.base import LFDialog
29
+ from lightfall.utils.logging import logger
30
+ from lightfall.utils.threads import QThreadFuture
31
+
32
+ if TYPE_CHECKING:
33
+ from lightfall.auth.providers.base import AuthProvider
34
+
35
+
36
+ class LoginResult(Enum):
37
+ """Result of the login dialog."""
38
+
39
+ AUTHENTICATED = auto() # User logged in successfully
40
+ GUEST = auto() # User chose to continue as guest
41
+ CANCELLED = auto() # User cancelled/closed the dialog
42
+
43
+
44
+ class LoginDialog(LFDialog):
45
+ """Modal dialog for user authentication.
46
+
47
+ Presents options to login via Keycloak (opens browser) or
48
+ use a local development account.
49
+
50
+ Signals:
51
+ login_started: Emitted when login process begins.
52
+ login_completed: Emitted with LoginResult when finished.
53
+
54
+ Example:
55
+ >>> dialog = LoginDialog(parent_window)
56
+ >>> result = dialog.exec()
57
+ >>> if result == QDialog.Accepted:
58
+ ... print(f"Login result: {dialog.result}")
59
+ """
60
+
61
+ login_started = Signal()
62
+ login_completed = Signal(LoginResult)
63
+
64
+ def __init__(
65
+ self,
66
+ parent: QWidget | None = None,
67
+ title: str = "Login Required",
68
+ message: str | None = None,
69
+ allow_guest: bool = True,
70
+ show_on_expiry: bool = False,
71
+ ) -> None:
72
+ """Initialize the login dialog.
73
+
74
+ Args:
75
+ parent: Parent widget.
76
+ title: Dialog title.
77
+ message: Custom message to display.
78
+ allow_guest: Whether to show "Continue as Guest" option.
79
+ show_on_expiry: Whether this is shown due to session expiry.
80
+ """
81
+ super().__init__(parent)
82
+ self._allow_guest = allow_guest
83
+ self._show_on_expiry = show_on_expiry
84
+ self._login_result = LoginResult.CANCELLED
85
+ self._session_manager = SessionManager.get_instance()
86
+ self._login_thread: QThreadFuture | None = None
87
+ self._current_provider: AuthProvider | None = None
88
+ self._login_cancelled = False # Track if user manually cancelled
89
+
90
+ self.setWindowTitle(title)
91
+ self.setModal(True)
92
+ self.setMinimumWidth(400)
93
+
94
+ # Remove close button if guest not allowed
95
+ if not allow_guest:
96
+ self.setWindowFlags(
97
+ self.windowFlags() & ~Qt.WindowType.WindowCloseButtonHint
98
+ )
99
+
100
+ # Build UI
101
+ self._setup_ui(message)
102
+
103
+ # Connect to session manager
104
+ self._session_manager.state_changed.connect(self._on_auth_state_changed)
105
+
106
+ def _setup_ui(self, message: str | None) -> None:
107
+ """Setup the dialog UI.
108
+
109
+ Args:
110
+ message: Custom message to display.
111
+ """
112
+ # Outer layout with minimal margins for logo
113
+ outer_layout = QVBoxLayout(self)
114
+ outer_layout.setSpacing(0)
115
+ outer_layout.setContentsMargins(0, 0, 0, 0)
116
+
117
+ # Logo (full width, minimal margins)
118
+ try:
119
+ from lightfall.resources import get_logo_pixmap
120
+
121
+ logo_pixmap = get_logo_pixmap() # Load at full resolution
122
+ if not logo_pixmap.isNull():
123
+ logo_label = QLabel()
124
+ logo_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
125
+ logo_label.setPixmap(
126
+ logo_pixmap.scaledToWidth(
127
+ 500,
128
+ Qt.TransformationMode.SmoothTransformation,
129
+ )
130
+ )
131
+ outer_layout.addWidget(logo_label)
132
+ logger.debug("Login dialog logo loaded successfully")
133
+ else:
134
+ logger.warning("Login dialog logo pixmap is null")
135
+ except Exception as e:
136
+ logger.warning("Failed to load login dialog logo: {}", e)
137
+
138
+ # Content area with standard margins
139
+ content_widget = QWidget()
140
+ layout = QVBoxLayout(content_widget)
141
+ layout.setSpacing(12)
142
+ layout.setContentsMargins(24, 12, 24, 24)
143
+ outer_layout.addWidget(content_widget)
144
+
145
+ # Title/header
146
+ if self._show_on_expiry:
147
+ header_text = "Session Expired"
148
+ default_message = (
149
+ "Your session has expired. Please log in again to continue "
150
+ "or continue as a guest with limited access."
151
+ )
152
+ else:
153
+ header_text = "Welcome to Lightfall"
154
+ default_message = (
155
+ "Please log in to access all features, or continue as a guest "
156
+ "with limited access."
157
+ )
158
+
159
+ header = QLabel(header_text)
160
+ header.setStyleSheet("font-size: 18px; font-weight: bold;")
161
+ header.setAlignment(Qt.AlignmentFlag.AlignCenter)
162
+ layout.addWidget(header)
163
+
164
+ # Message
165
+ self._message_label = QLabel(message or default_message)
166
+ self._message_label.setWordWrap(True)
167
+ self._message_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
168
+ layout.addWidget(self._message_label)
169
+
170
+ layout.addSpacing(8)
171
+
172
+ # Keycloak login button
173
+ self._keycloak_btn = QPushButton("Login with Keycloak")
174
+ self._keycloak_btn.setMinimumHeight(44)
175
+ self._keycloak_btn.setStyleSheet(
176
+ """
177
+ QPushButton {
178
+ background-color: #0066cc;
179
+ color: white;
180
+ border: none;
181
+ border-radius: 4px;
182
+ font-size: 14px;
183
+ font-weight: bold;
184
+ }
185
+ QPushButton:hover {
186
+ background-color: #0055aa;
187
+ }
188
+ QPushButton:pressed {
189
+ background-color: #004488;
190
+ }
191
+ QPushButton:disabled {
192
+ background-color: #cccccc;
193
+ }
194
+ """
195
+ )
196
+ self._keycloak_btn.clicked.connect(self._on_keycloak_login)
197
+ layout.addWidget(self._keycloak_btn)
198
+
199
+ # Local login form (hidden by default)
200
+ self._local_form = self._create_local_form()
201
+ self._local_form.setVisible(False)
202
+ layout.addWidget(self._local_form)
203
+
204
+ # Progress indicator (hidden by default)
205
+ self._progress_widget = QWidget()
206
+ progress_layout = QVBoxLayout(self._progress_widget)
207
+ progress_layout.setContentsMargins(0, 0, 0, 0)
208
+ progress_layout.setSpacing(8)
209
+
210
+ # Progress bar and label row
211
+ progress_row = QHBoxLayout()
212
+ progress_row.setContentsMargins(0, 0, 0, 0)
213
+
214
+ self._progress_bar = QProgressBar()
215
+ self._progress_bar.setRange(0, 0) # Indeterminate
216
+ self._progress_bar.setTextVisible(False)
217
+ progress_row.addWidget(self._progress_bar)
218
+
219
+ self._progress_label = QLabel("Logging in...")
220
+ progress_row.addWidget(self._progress_label)
221
+
222
+ progress_layout.addLayout(progress_row)
223
+
224
+ # Cancel button for aborting login
225
+ self._cancel_btn = QPushButton("Cancel")
226
+ self._cancel_btn.setMinimumHeight(32)
227
+ self._cancel_btn.clicked.connect(self._on_cancel_login)
228
+ progress_layout.addWidget(self._cancel_btn)
229
+
230
+ self._progress_widget.setVisible(False)
231
+ layout.addWidget(self._progress_widget)
232
+
233
+ # Error label (hidden by default)
234
+ self._error_label = QLabel()
235
+ self._error_label.setStyleSheet("color: #cc0000; font-size: 12px;")
236
+ self._error_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
237
+ self._error_label.setVisible(False)
238
+ layout.addWidget(self._error_label)
239
+
240
+ # Linux User Login button (PAM auth)
241
+ self._pam_btn = QPushButton("Linux User Login")
242
+ self._pam_btn.setMinimumHeight(40)
243
+ self._pam_btn.setStyleSheet(
244
+ """
245
+ QPushButton {
246
+ background-color: #2e7d32;
247
+ color: white;
248
+ border: none;
249
+ border-radius: 4px;
250
+ font-size: 13px;
251
+ font-weight: bold;
252
+ }
253
+ QPushButton:hover {
254
+ background-color: #256428;
255
+ }
256
+ QPushButton:pressed {
257
+ background-color: #1b5e20;
258
+ }
259
+ QPushButton:disabled {
260
+ background-color: #cccccc;
261
+ }
262
+ """
263
+ )
264
+ self._pam_btn.clicked.connect(self._on_pam_login)
265
+ if sys.platform == "win32":
266
+ self._pam_btn.setVisible(False)
267
+ layout.addWidget(self._pam_btn)
268
+
269
+ # Guest button
270
+ if self._allow_guest:
271
+ self._guest_btn = QPushButton("Continue as Guest")
272
+ self._guest_btn.setMinimumHeight(36)
273
+ self._guest_btn.clicked.connect(self._on_guest_clicked)
274
+ layout.addWidget(self._guest_btn)
275
+ else:
276
+ self._guest_btn = None
277
+
278
+ # Link to switch to local login (in main layout, below guest button)
279
+ self._local_link = QPushButton("Use local account instead")
280
+ self._local_link.setFlat(True)
281
+ self._local_link.setCursor(Qt.CursorShape.PointingHandCursor)
282
+ self._local_link.setStyleSheet(
283
+ """
284
+ QPushButton {
285
+ color: #0066cc;
286
+ text-decoration: underline;
287
+ border: none;
288
+ background: transparent;
289
+ font-size: 11px;
290
+ padding: 4px;
291
+ }
292
+ QPushButton:hover {
293
+ color: #004488;
294
+ }
295
+ """
296
+ )
297
+ self._local_link.clicked.connect(self._show_local_page)
298
+ layout.addWidget(self._local_link, alignment=Qt.AlignmentFlag.AlignCenter)
299
+
300
+ # Info text
301
+ self._info_label = QLabel(
302
+ "Guest access provides read-only permissions."
303
+ )
304
+ self._info_label.setStyleSheet("color: gray; font-size: 10px;")
305
+ self._info_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
306
+ layout.addWidget(self._info_label)
307
+
308
+ def _create_local_form(self) -> QWidget:
309
+ """Create the local login form with username/password fields."""
310
+ form = QWidget()
311
+ layout = QVBoxLayout(form)
312
+ layout.setContentsMargins(0, 0, 0, 0)
313
+ layout.setSpacing(8)
314
+
315
+ # Username/password form
316
+ form_layout = QFormLayout()
317
+ form_layout.setSpacing(8)
318
+
319
+ self._username_edit = QLineEdit()
320
+ self._username_edit.setPlaceholderText("Enter username")
321
+ self._username_edit.setMinimumHeight(32)
322
+ form_layout.addRow("Username:", self._username_edit)
323
+
324
+ self._password_edit = QLineEdit()
325
+ self._password_edit.setPlaceholderText("Enter password")
326
+ self._password_edit.setEchoMode(QLineEdit.EchoMode.Password)
327
+ self._password_edit.setMinimumHeight(32)
328
+ self._password_edit.returnPressed.connect(self._on_local_login)
329
+ form_layout.addRow("Password:", self._password_edit)
330
+
331
+ layout.addLayout(form_layout)
332
+
333
+ # Local login button
334
+ self._local_login_btn = QPushButton("Login")
335
+ self._local_login_btn.setMinimumHeight(40)
336
+ self._local_login_btn.setStyleSheet(
337
+ """
338
+ QPushButton {
339
+ background-color: #0066cc;
340
+ color: white;
341
+ border: none;
342
+ border-radius: 4px;
343
+ font-size: 14px;
344
+ font-weight: bold;
345
+ }
346
+ QPushButton:hover {
347
+ background-color: #0055aa;
348
+ }
349
+ QPushButton:pressed {
350
+ background-color: #004488;
351
+ }
352
+ QPushButton:disabled {
353
+ background-color: #cccccc;
354
+ }
355
+ """
356
+ )
357
+ self._local_login_btn.clicked.connect(self._on_local_login)
358
+ layout.addWidget(self._local_login_btn)
359
+
360
+ # Link to go back to Keycloak
361
+ self._keycloak_link = QPushButton("Back to Keycloak login")
362
+ self._keycloak_link.setFlat(True)
363
+ self._keycloak_link.setCursor(Qt.CursorShape.PointingHandCursor)
364
+ self._keycloak_link.setStyleSheet(
365
+ """
366
+ QPushButton {
367
+ color: #0066cc;
368
+ text-decoration: underline;
369
+ border: none;
370
+ background: transparent;
371
+ font-size: 11px;
372
+ }
373
+ QPushButton:hover {
374
+ color: #004488;
375
+ }
376
+ """
377
+ )
378
+ self._keycloak_link.clicked.connect(self._show_keycloak_page)
379
+ layout.addWidget(self._keycloak_link, alignment=Qt.AlignmentFlag.AlignCenter)
380
+
381
+ # Dev hint
382
+ hint = QLabel("Dev accounts: admin/admin, user/user, operator/operator")
383
+ hint.setStyleSheet("color: gray; font-size: 10px;")
384
+ hint.setAlignment(Qt.AlignmentFlag.AlignCenter)
385
+ layout.addWidget(hint)
386
+
387
+ return form
388
+
389
+ def _show_keycloak_page(self) -> None:
390
+ """Switch to Keycloak login view."""
391
+ self._keycloak_btn.setVisible(True)
392
+ self._pam_btn.setVisible(True)
393
+ self._local_form.setVisible(False)
394
+ self._local_link.setVisible(True)
395
+ self._error_label.setVisible(False)
396
+
397
+ def _show_local_page(self) -> None:
398
+ """Switch to local login view."""
399
+ self._keycloak_btn.setVisible(False)
400
+ self._pam_btn.setVisible(False)
401
+ self._local_form.setVisible(True)
402
+ self._local_link.setVisible(False)
403
+ self._error_label.setVisible(False)
404
+ self._username_edit.setFocus()
405
+
406
+ @property
407
+ def login_result(self) -> LoginResult:
408
+ """Get the login result after dialog closes."""
409
+ return self._login_result
410
+
411
+ def _on_keycloak_login(self) -> None:
412
+ """Handle Keycloak login button click."""
413
+ self._login_cancelled = False # Reset cancel flag
414
+ self._keycloak_btn.setEnabled(False)
415
+ self._local_link.setVisible(False)
416
+ if self._guest_btn:
417
+ self._guest_btn.setEnabled(False)
418
+ self._progress_label.setText("Waiting for browser login...")
419
+ self._progress_widget.setVisible(True)
420
+ self._error_label.setVisible(False)
421
+
422
+ self.login_started.emit()
423
+ logger.info("Starting Keycloak login flow")
424
+
425
+ # Run Keycloak login in background thread
426
+ self._login_thread = QThreadFuture(
427
+ self._do_keycloak_login,
428
+ callback_slot=self._on_login_complete,
429
+ except_slot=self._on_login_error,
430
+ name="keycloak_login",
431
+ )
432
+ self._login_thread.start()
433
+
434
+ def _on_cancel_login(self) -> None:
435
+ """Handle cancel button click during login."""
436
+ logger.info("User cancelled login")
437
+ self._login_cancelled = True
438
+
439
+ # Cancel the background thread if running
440
+ if self._login_thread and self._login_thread.isRunning():
441
+ self._login_thread.cancel(timeout_ms=1000)
442
+
443
+ # Reset UI immediately
444
+ self._reset_ui()
445
+
446
+ def _do_keycloak_login(self) -> bool:
447
+ """Perform Keycloak login (runs in background thread)."""
448
+ from datetime import datetime
449
+
450
+ from lightfall.auth.providers.keycloak import KeycloakAuthProvider, KeycloakConfig
451
+ from lightfall.config import ConfigManager
452
+ from lightfall.core import LFApplication
453
+ from lightfall.ui.preferences.login_settings import LoginSettingsProvider
454
+
455
+ # Get Keycloak config
456
+ app = LFApplication.get_instance()
457
+ config: ConfigManager = app.services.get(ConfigManager)
458
+ auth_config = config.model.auth.provider
459
+
460
+ kc_config = KeycloakConfig(
461
+ server_url=auth_config.server_url,
462
+ realm=auth_config.realm,
463
+ client_id=auth_config.client_id,
464
+ client_secret=auth_config.client_secret or None,
465
+ redirect_uri=auth_config.redirect_uri,
466
+ )
467
+
468
+ provider = KeycloakAuthProvider(kc_config)
469
+ self._current_provider = provider
470
+
471
+ # Run async authenticate
472
+ session = asyncio.run(provider.authenticate())
473
+
474
+ if session:
475
+ # Apply app session duration (starts now, not when token was issued)
476
+ duration = LoginSettingsProvider.get_session_duration()
477
+ session.user.expires_at = datetime.now(UTC) + duration
478
+
479
+ # Hand the session to SessionManager. attach_session caches it,
480
+ # mints per-service API keys (auth-v2), transitions to
481
+ # AUTHENTICATED, and emits user_changed.
482
+ self._session_manager.set_provider(provider)
483
+ self._session_manager.attach_session(session)
484
+ return True
485
+
486
+ return False
487
+
488
+ def _on_local_login(self) -> None:
489
+ """Handle local login button click."""
490
+ username = self._username_edit.text().strip()
491
+ password = self._password_edit.text()
492
+
493
+ if not username or not password:
494
+ self._show_error("Please enter username and password")
495
+ return
496
+
497
+ self._login_cancelled = False # Reset cancel flag
498
+ self._local_login_btn.setEnabled(False)
499
+ self._username_edit.setEnabled(False)
500
+ self._password_edit.setEnabled(False)
501
+ self._keycloak_link.setEnabled(False)
502
+ if self._guest_btn:
503
+ self._guest_btn.setEnabled(False)
504
+ self._progress_label.setText("Logging in...")
505
+ self._progress_widget.setVisible(True)
506
+ self._error_label.setVisible(False)
507
+
508
+ self.login_started.emit()
509
+ logger.info("Starting local login flow")
510
+
511
+ self._login_thread = QThreadFuture(
512
+ self._do_local_login,
513
+ username,
514
+ password,
515
+ callback_slot=self._on_login_complete,
516
+ except_slot=self._on_login_error,
517
+ name="local_login",
518
+ )
519
+ self._login_thread.start()
520
+
521
+ def _do_local_login(self, username: str, password: str) -> bool:
522
+ """Perform local login (runs in background thread)."""
523
+ from datetime import datetime
524
+
525
+ from lightfall.auth.providers.local import LocalAuthProvider
526
+ from lightfall.ui.preferences.login_settings import LoginSettingsProvider
527
+
528
+ duration = LoginSettingsProvider.get_session_duration()
529
+ provider = LocalAuthProvider(session_duration=duration)
530
+ self._current_provider = provider
531
+
532
+ # Run async authenticate
533
+ session = asyncio.run(provider.authenticate(username=username, password=password))
534
+
535
+ if session:
536
+ # Apply app session duration (ensure it starts now)
537
+ session.user.expires_at = datetime.now(UTC) + duration
538
+
539
+ # Hand the session to SessionManager. attach_session caches it,
540
+ # mints per-service API keys (auth-v2), transitions to
541
+ # AUTHENTICATED, and emits user_changed.
542
+ self._session_manager.set_provider(provider)
543
+ self._session_manager.attach_session(session)
544
+ return True
545
+
546
+ return False
547
+
548
+ def _on_pam_login(self) -> None:
549
+ """Handle Linux User Login button click.
550
+
551
+ Authenticates immediately using the current OS username
552
+ and group membership — no password prompt needed.
553
+ """
554
+ self._login_cancelled = False
555
+ self._pam_btn.setEnabled(False)
556
+ self._keycloak_btn.setEnabled(False)
557
+ self._local_link.setVisible(False)
558
+ if self._guest_btn:
559
+ self._guest_btn.setEnabled(False)
560
+ self._progress_label.setText("Logging in as system user...")
561
+ self._progress_widget.setVisible(True)
562
+ self._error_label.setVisible(False)
563
+
564
+ self.login_started.emit()
565
+ logger.info("Starting Linux system user login")
566
+
567
+ self._login_thread = QThreadFuture(
568
+ self._do_pam_login,
569
+ callback_slot=self._on_login_complete,
570
+ except_slot=self._on_login_error,
571
+ name="pam_login",
572
+ )
573
+ self._login_thread.start()
574
+
575
+ def _do_pam_login(self) -> bool:
576
+ """Create session from current OS identity (runs in background thread)."""
577
+ from datetime import datetime
578
+
579
+ from lightfall.auth.providers.pam import PamAuthProvider, PamConfig
580
+ from lightfall.config import ConfigManager
581
+ from lightfall.core import LFApplication
582
+ from lightfall.ui.preferences.login_settings import LoginSettingsProvider
583
+
584
+ duration = LoginSettingsProvider.get_session_duration()
585
+
586
+ # Build config from app settings if available
587
+ try:
588
+ app = LFApplication.get_instance()
589
+ config: ConfigManager = app.services.get(ConfigManager)
590
+ auth_config = config.model.auth.provider
591
+
592
+ from lightfall.auth.policy import Role as _Role
593
+
594
+ group_role_map = {}
595
+ for group_name, role_str in auth_config.pam_group_role_map.items():
596
+ try:
597
+ group_role_map[group_name] = _Role(role_str)
598
+ except ValueError:
599
+ pass
600
+
601
+ pam_config = PamConfig(session_duration=duration)
602
+ if group_role_map:
603
+ pam_config.group_role_map = group_role_map
604
+ except Exception:
605
+ pam_config = PamConfig(session_duration=duration)
606
+
607
+ provider = PamAuthProvider(pam_config)
608
+ self._current_provider = provider
609
+
610
+ # authenticate() ignores username/password — uses OS identity
611
+ session = asyncio.run(provider.authenticate())
612
+
613
+ if session:
614
+ session.user.expires_at = datetime.now(UTC) + duration
615
+
616
+ self._session_manager.set_provider(provider)
617
+ self._session_manager.attach_session(session)
618
+ return True
619
+
620
+ return False
621
+
622
+ def _on_login_complete(self, success: bool) -> None:
623
+ """Handle login completion (called in main thread).
624
+
625
+ Args:
626
+ success: Whether login succeeded.
627
+ """
628
+ # Ignore callback if user already cancelled
629
+ if self._login_cancelled:
630
+ return
631
+
632
+ if success:
633
+ self._login_result = LoginResult.AUTHENTICATED
634
+ self.accept()
635
+ else:
636
+ self._reset_ui()
637
+ if self._local_form.isVisible():
638
+ self._show_error("Invalid username or password")
639
+ else:
640
+ self._show_error("Login failed or was cancelled")
641
+
642
+ def _on_login_error(self, error: Exception) -> None:
643
+ """Handle login error (called in main thread).
644
+
645
+ Args:
646
+ error: The exception that occurred.
647
+ """
648
+ # Ignore callback if user already cancelled
649
+ if self._login_cancelled:
650
+ return
651
+
652
+ logger.error("Login failed: {}", error)
653
+ self._reset_ui()
654
+ self._show_error(f"Login failed: {error}")
655
+
656
+ def _reset_ui(self) -> None:
657
+ """Reset UI after failed login attempt."""
658
+ # Keycloak
659
+ self._keycloak_btn.setEnabled(True)
660
+
661
+ # PAM
662
+ self._pam_btn.setEnabled(True)
663
+
664
+ # Local form
665
+ self._local_login_btn.setEnabled(True)
666
+ self._username_edit.setEnabled(True)
667
+ self._password_edit.setEnabled(True)
668
+ self._password_edit.clear()
669
+ self._keycloak_link.setEnabled(True)
670
+
671
+ # Common
672
+ if self._guest_btn:
673
+ self._guest_btn.setEnabled(True)
674
+ self._local_link.setVisible(self._keycloak_btn.isVisible())
675
+ self._progress_widget.setVisible(False)
676
+
677
+ # Focus appropriate field
678
+ if self._local_form.isVisible():
679
+ self._password_edit.setFocus()
680
+
681
+ def _show_error(self, message: str) -> None:
682
+ """Show an error message in the dialog.
683
+
684
+ Args:
685
+ message: Error message to display.
686
+ """
687
+ self._error_label.setText(message)
688
+ self._error_label.setVisible(True)
689
+
690
+ def _on_guest_clicked(self) -> None:
691
+ """Handle guest button click."""
692
+ self._login_result = LoginResult.GUEST
693
+ logger.info("User chose guest access")
694
+ self.accept()
695
+
696
+ @Slot(AuthState, AuthState)
697
+ def _on_auth_state_changed(self, new_state: AuthState, old_state: AuthState) -> None:
698
+ """Handle authentication state changes.
699
+
700
+ Args:
701
+ new_state: New auth state.
702
+ old_state: Previous auth state.
703
+ """
704
+ if new_state == AuthState.AUTHENTICATED:
705
+ self._login_result = LoginResult.AUTHENTICATED
706
+ self.login_completed.emit(LoginResult.AUTHENTICATED)
707
+ self.accept()
708
+ elif new_state == AuthState.ERROR:
709
+ self._reset_ui()
710
+ self._show_error("Login failed. Please try again.")
711
+
712
+ def closeEvent(self, event) -> None:
713
+ """Handle dialog close."""
714
+ if not self._allow_guest:
715
+ # Don't allow closing without action
716
+ event.ignore()
717
+ return
718
+
719
+ self._login_result = LoginResult.CANCELLED
720
+ self.login_completed.emit(LoginResult.CANCELLED)
721
+ super().closeEvent(event)
722
+
723
+ def reject(self) -> None:
724
+ """Handle dialog rejection (Escape key)."""
725
+ if not self._allow_guest:
726
+ return # Don't allow rejection
727
+
728
+ self._login_result = LoginResult.CANCELLED
729
+ self.login_completed.emit(LoginResult.CANCELLED)
730
+ super().reject()
731
+
732
+
733
+ def show_login_dialog(
734
+ parent: QWidget | None = None,
735
+ force: bool = False,
736
+ on_expiry: bool = False,
737
+ ) -> LoginResult:
738
+ """Show the login dialog and return the result.
739
+
740
+ Convenience function to display the login dialog.
741
+
742
+ Args:
743
+ parent: Parent widget.
744
+ force: If True, don't allow guest access.
745
+ on_expiry: If True, show expiry-specific messaging.
746
+
747
+ Returns:
748
+ The login result.
749
+ """
750
+ dialog = LoginDialog(
751
+ parent=parent,
752
+ allow_guest=not force,
753
+ show_on_expiry=on_expiry,
754
+ )
755
+ dialog.exec()
756
+ return dialog.login_result