o YA'iƒã@s`dZddlmZmZmZddlmZmZddlm Z ddl m Z ddl m Z Gdd„deƒZd S) ze System Tray Icon for Python Scheduler Always visible in Windows taskbar with menu and notifications é)ÚQSystemTrayIconÚQMenuÚ QApplication)ÚQIconÚQAction)ÚQTimer)Úlogger)ÚSchedulerDatabasecspeZdZdZdef‡fdd„ Zdd„Zdd„Zd d „Zd d „Z d e de fdd„Z dd„Z dd„Z dd„Z‡ZS)ÚSchedulerSystemTrayzSystem tray icon with menuÚdbcs’tƒ |¡||_||_t ¡}|r | | ¡ | ¡j j ¡¡|  d¡|  ¡|j  |j¡tƒ|_|jj |j¡|j d¡t d¡dS)NzPython Scheduler - Runningi'zSystem tray icon initialized)ÚsuperÚ__init__Ú parent_windowr rÚinstanceZsetIconÚstyleZ standardIconZStandardPixmapZSP_ComputerIconÚ setToolTipÚ _create_menuZ activatedÚconnectÚ _on_activatedrÚ update_timerÚtimeoutÚ _update_menuÚstartrÚinfo)ÚselfÚparentr Úapp©Ú __class__©ú&c:\PYTHON\Scheduler\gui\system_tray.pyr s   zSchedulerSystemTray.__init__cCsŠtƒ}tdƒ|_|j d¡| |j¡tdƒ|_|jj |j¡| |j¡tdƒ|_ |j j |j ¡| |j ¡|  |¡|  ¡dS)zCreate context menuú Status: ReadyFzOpen DashboardzExit ApplicationN) rrÚ status_actionÚ setEnabledÚ addActionZ open_actionÚ triggeredrÚ_show_dashboardZ exit_actionÚ _exit_appZsetContextMenur)rÚmenurrr r*s         z SchedulerSystemTray._create_menuc Cszz!t|j ¡ƒ}|dkr|j d|›d¡WdS|j d¡WdSty<}zt d|›¡WYd}~dSd}~ww)zUpdate dynamic menu itemsrzStatus: z job(s) runningr!z!Error updating system tray menu: N)Úlenr Úget_active_executionsr"ÚsetTextÚ ExceptionrÚerror)rÚ active_countÚerrr rBs€ÿz SchedulerSystemTray._update_menuc CsÆ|j ¡zB|jjdd}|s!tdƒ}| d¡|j |¡Wd S|D]!}| |d¡}|›d|d›}t|ƒ}| d¡|j |¡q#Wd Styb}zt   d|›¡WYd }~d Sd }~ww) zUpdate recent jobs submenué)ÚlimitzNo recent executionsFÚstatusú Újob_namez!Error updating recent jobs menu: N) Z recent_menuÚclearr Úget_recent_executionsrr#r$Ú_get_status_iconr,rr-)rÚrecentZno_jobsÚ executionÚ status_iconÚjob_textÚactionr/rrr Ú_update_recent_jobsOs$   ú€ÿz'SchedulerSystemTray._update_recent_jobsc Cs°|j ¡z7|j ¡}|stdƒ}| d¡|j |¡WdS|D]}d|d›}t|ƒ}| d¡|j |¡q!WdStyW}zt  d|›¡WYd}~dSd}~ww)zUpdate active jobs submenuzNo jobs runningFuâ–¶ r4z!Error updating active jobs menu: N) Z active_menur5r r*rr#r$r,rr-)rÚactiveZ no_activer9r;r<r/rrr Ú_update_active_jobsfs"    û€ÿz'SchedulerSystemTray._update_active_jobsr2ÚreturncCsddddddœ}| |d¡S)zGet status iconu✓u✗uâ–¶uâ±uâ›”)Ú completedÚfailedÚrunningrÚ cancelledú?)Úget)rr2Úiconsrrr r7|sû z$SchedulerSystemTray._get_status_iconcCs|tjjkr | ¡dSdS)zHandle tray icon activationN)rZActivationReasonZ DoubleClickr&)rÚreasonrrr r‡s  ÿz!SchedulerSystemTray._on_activatedcCs|j ¡dS)zShow main windowN)rÚ show_window)rrrr r&Œsz#SchedulerSystemTray._show_dashboardcCs"ddlm}t d¡| ¡dS)zExit applicationr)rz$Exiting application from system trayN)ÚPyQt6.QtWidgetsrrrÚquit)rrrrr r's   zSchedulerSystemTray._exit_app)Ú__name__Ú __module__Ú __qualname__Ú__doc__r r rrr=r?Ústrr7rr&r'Ú __classcell__rrrr r s  r N)rOrJrrrÚ PyQt6.QtGuirrÚ PyQt6.QtCorerÚlogururÚ core.databaser r rrrr Ús