o z£9i-ã@sdZddlmZmZmZmZmZmZmZm Z m Z m Z ddl m Z ddlmZddlmZddlmZddlmZddlmZGd d „d eƒZd S) z? History Widget for Python Scheduler Display execution history é) ÚQWidgetÚ QVBoxLayoutÚ QHBoxLayoutÚ QTableWidgetÚQTableWidgetItemÚ QPushButtonÚ QHeaderViewÚQLabelÚQSpinBoxÚ QMessageBox)ÚQt)ÚQColor)Úlogger)ÚSchedulerDatabase)ÚSchedulerConfig)ÚLogMonitorWindowcsJeZdZdZdedef‡fdd„ Zdd„Zdd „Zd d „Z d d „Z ‡Z S)Ú HistoryWidgetzExecution history widgetÚdbÚconfigcs0tƒ ¡||_||_d|_| ¡| ¡dS)Né2)ÚsuperÚ__init__rrÚlimitÚ _setup_uiÚrefresh)Úselfrr©Ú __class__©ú)c:\PYTHON\Scheduler\gui\history_widget.pyrs  zHistoryWidget.__init__cCspt|ƒ}tƒ}tdƒ}| d¡| |¡| ¡tdƒ}| |¡tƒ|_|j d¡|j  d¡|j  d¡|j  d¡|jj   |j¡| |j¡tdƒ|_|jj  |j¡|j d¡| |j¡td ƒ|_|jj  |j¡| |j¡| |¡tƒ|_|j d ¡|j gd ¢¡|j ¡ d tjj¡|j  tj!j"¡|j #d ¡|j $tj%j&¡| |j¡dS)zSetup UIzExecution Historyz#font-size: 14px; font-weight: bold;z Show last:é iôru📺 Monitor Logz'Open log monitor for selected executionu 🔄 Refreshé)ÚIDzJob NameZStatusz Start TimeZDurationz Exit Codez Triggered ByéTN)'rrr Ú setStyleSheetÚ addWidgetÚ addStretchr Z limit_spinÚ setMinimumÚ setMaximumÚsetValueZ setSingleStepZ valueChangedÚconnectÚ_on_limit_changedrZ monitor_btnÚclickedÚ _open_monitorÚ setToolTipÚ refresh_btnrÚ addLayoutrÚtableÚsetColumnCountÚsetHorizontalHeaderLabelsÚhorizontalHeaderÚsetSectionResizeModerÚ ResizeModeÚStretchÚsetSelectionBehaviorÚSelectionBehaviorÚ SelectRowsÚsetAlternatingRowColorsÚsetEditTriggersÚ EditTriggerÚNoEditTriggers)rÚlayoutÚ header_layoutÚ header_labelZ limit_labelrrrrs>                zHistoryWidget._setup_uicCs||_| ¡dS)zHandle limit changeN)rr)rÚvaluerrrr+Qs zHistoryWidget._on_limit_changedc Cs\z|jj|jd}|j t|ƒ¡t|ƒD]í\}}|j |dtt |dƒƒ¡t|dƒ}|j |d|¡|d}t|  ¡ƒ}|dkrQ|  t j j¡| d¡n2|d krb|  t j j¡| d ¡n!|d krs|  t j j¡| d ¡n|d krƒ|  t j j¡| d¡|j |d|¡|dr—|ddd…nd}|j |dt|ƒ¡|dr°|dd›d}nd}|j |dt|ƒ¡|ddurÈt |dƒnd} t| ƒ} |ddkrÜ|   t j j¡n|ddurï|ddkrï|   t j j¡|j |d| ¡|j |dt|dƒ¡qt dt|ƒ›d¡WdSty-} zt d| ›¡WYd} ~ dSd} ~ ww) zRefresh execution history)rrÚidÚjob_namer#ÚstatusÚ completedu ✓ COMPLETEDÚfailedu ✗ FAILEDÚrunningu â–¶ RUNNINGÚtimeoutu â± TIMEOUTéÚ start_timeNézN/AéÚduration_secondsz.1fÚséÚ exit_codeééÚ triggered_byzRefreshed history table: z executionszError refreshing history: )rÚget_recent_executionsrr1Ú setRowCountÚlenÚ enumerateÚsetItemrÚstrÚupperÚ setForegroundr Ú GlobalColorÚ darkGreenÚsetTextÚredÚblueÚ darkYellowrÚdebugÚ ExceptionÚerror) rÚ executionsÚrowÚ executionÚ name_itemrEZ status_itemrKÚ duration_strrQZ exit_itemÚerrrrVsR       €ÿzHistoryWidget.refreshc CsÊz?|j ¡}|st |dd¡WdS|d ¡}|j |d¡}|s$WdSt| ¡ƒ}t||j |ƒ}|  ¡t   d|›¡WdSt yd}zt  d|›¡t |dd|›¡WYd}~dSd}~ww) z.Open log monitor window for selected executionz No Selectionz%Please select an execution to monitorNrz!Opened log monitor for execution zError opening monitor: ÚErrorzFailed to open monitor: )r1ZselectedIndexesr ÚwarningrgÚitemÚintÚtextrrÚshowrÚinfordreÚcritical)rÚ selected_rowsrgZexecution_id_itemÚ execution_idZmonitor_windowrkrrrr-”s$   "€þzHistoryWidget._open_monitor) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrr+rr-Ú __classcell__rrrrrs 2>rN)ryÚPyQt6.QtWidgetsrrrrrrrr r r Ú PyQt6.QtCorer Ú PyQt6.QtGuir ÚlogururÚ core.databaserÚ core.configrZgui.log_monitor_windowrrrrrrÚs0