+27i,dZddlZddlmZmZmZmZmZmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZddlmZej.eZGdd eZy) z]Output Manager Dialog for ChefSystem. Dialog for managing outputs associated with a recipe. N) QDialog QVBoxLayout QHBoxLayout QPushButton QListWidgetQListWidgetItem QTextEditQLabel QFileDialog QMessageBox QInputDialog QLineEdit)Qt)Recipe) OutputService)format_file_sizeceZdZdZddeffd ZddZddeddfdZdd Z d e ddfd Z dd Z dd Z ddZdeddfdZxZS) OutputManagerzDialog for managing recipe outputs. Displays list of outputs with Add/Open/Delete actions and execution notes editor. NrecipecTt||||_||_t ||_d|_|jd|j|jddd|_ d|_ d|_ d|_ d|_|j|j!y)zInitialize the output manager dialog. Args: db_manager: DatabaseManager instance. recipe: Recipe instance to manage outputs for. parent: Parent widget. NzManage Outputs: i iX)super__init__ db_managerrroutput_servicecurrent_outputsetWindowTitlenamesetMinimumSize outputs_list notes_edit add_button open_button delete_button _setup_ui _load_outputs)selfrrparent __class__s Outputs for: zzSearch Outputs:zSearch by filename or notes...zOutput Files:z Add Outputz Open FileFDeletezExecution Notes:dTz(Select an output to view execution notesCloseN)#rr rr addWidgetr search_boxsetPlaceholderText textChangedconnecton_search_changedrritemSelectionChangedon_output_selecteditemDoubleClickedon_output_double_clickedrrr!clicked on_add_outputr" setEnabledon_open_outputr#on_delete_output addStretch addLayoutr r setMaximumHeight setReadOnlyaccept setLayout)r& main_layoutheader search_label list_label button_layout notes_label close_buttons r)r$zOutputManager._setup_ui6s!m +DKK,<,<+=UCDf%67 l+#+ **+KL ##++D,B,BCdoo.23 j)'M ..66t7N7NO ++33D4Q4QRd//0$ %l3 ''(:(:;0&{3 ##E*   (()<)<= 0 01(2 %%e, ""**4+@+@A 2 23  "m,67 k*#+ ((- ##D) **+UVdoo.#7+ $$T[[1l+ {#r* search_querycD |jj|jj}|r|j rq|j j }|Dcgc]H}||j j vs(|jr||jj vr|J}}|jj|s|td}|jtjj|jj|t j#d|jjy|D]}|j$r|j$j'dnd}|j(rt+|j(nd}|j d|j,d|d |}t|}|j/tj0j2|j|jj|t j#d t5|d |jjycc}w#t6$r>} t j9d | d t;j<|dd| Yd} ~ yd} ~ wwxYw)zLoad outputs for the recipe from database. Args: search_query: Optional search query to filter outputs. zNo outputs yetzNo outputs found for recipe Nz%Y-%m-%d %H:%M-z0 Bz (z, z) - zLoaded z outputs for recipe zError loading outputs: Texc_infoErrorzFailed to load outputs: )rget_recipe_outputsridstriplowerfilenameexecution_notesrclearrsetFlagsrItemFlag NoItemFlagsaddItemloggerinfo generated_atstrftime file_sizer file_typesetData ItemDataRoleUserRolelen Exceptionerrorr critical) r&rLoutputs query_loweroutputitemdate_strsize_str item_textes r)r%zOutputManager._load_outputsus2 $ P))<>:JKL! 0MSM`M`6..778HIfiAGAQAQ+F,<,<=W\%/r&2B2B1C2hZtT\S]^ &y1 R__55vyyA!!))$/ 0 KK'#g,/CDKKNNCST U36 P LL21#6L F  w2J1#0N O O Ps3A#I%A I2BI DII J!4JJc|jj}|sXd|_|jj |j j d|jj dy|d}|jtjj}|y |jj|}|r||_|jj|jr |jnd|j j d|jj dt j#d|j$yy#t&$r'}t j)d|d|d Yd}~yd}~wwxYw) zHandle output selection change.NFrzNo notesTzSelected output: zError loading output z: rO)r selectedItemsrr rXr"r<r#datarrdrerget_output_by_id setPlainTextrWr]debugrVrgrh)r&selected_itemsrm output_idrlrqs r)r7z OutputManager.on_output_selectedsN**88:"&D  OO ! ! #    ' ' .    ) )% 0 a IIboo667    R((99)DF&,#,,vG]G]V-C-Ccmn  ++D1""--d3 00ABC  R LL0 2aSADL Q Q Rs'B/E F!FFrmc||jtjj}|r|j yy)zqHandle double-click on output item (opens file). Args: item: The clicked list item. N)rtrrdrer=)r&rmrys r)r9z&OutputManager.on_output_double_clickeds0 IIboo667     ! r*c tj|ddd\}}|stjdyt j |ddd\}}|stjdy|j j|jj||}|rXtjd |jtj|d d |jd |jytj|d dy#t$r>}tj!d|dtj|d d|Yd}~yd}~wwxYw)zHandle add output action.zSelect Output FilezAll Files (*.*)zAdd output cancelledNzExecution Notesz'Enter optional notes about this output:z#Add output cancelled at notes inputzAdded output: SuccesszOutput 'z' added successfully!rQz1Failed to add output. Check the logs for details.zError adding output: TrOzFailed to add output: )r getOpenFileNamer]r^r getMultiLineTextr save_outputrrSrVr informationr%rirgrh)r& file_path_notesokrlrqs r)r;zOutputManager.on_add_outputsN5 N&66$! LIq 23%55!9 IE2 AB((44 F  nV__,=>?''v//DE""$$$G  N LL04tL D  w2H0L M M Ns)2D 2D (B D 3D E4E  Ecv|jsy |jj|jj}|s0t j |dd|jj dyy#t$r>}tjd|dt j|dd|Yd}~yd}~wwxYw) zHandle open output action.NrQzFailed to open 'zR'. The file may not exist or no application is configured to open this file type.zError opening output: TrOzFailed to open output: ) rr open_outputrSr warningrVrgr]rhri)r&successrqs r)r=zOutputManager.on_open_outputs""  O))55d6I6I6L6LMG##&t':':'C'C&DEee O LL1!5L E  w2I!0M N N OsA A11 B8:4B33B8c.|jsytj|dd|jjdtjj tjj ztjj }|tjj k(r |jj|jj}|r[tjd|jjtj|ddd|_|jytj|dd yy#t$r>}tj!d |d tj"|dd |Yd}~yd}~wwxYw)zHandle delete output action.NzConfirm Deletez(Are you sure you want to delete output 'zE'? This will delete both the database record and the file from disk.zDeleted output: r}zOutput deleted successfullyrQz4Failed to delete output. Check the logs for details.zError deleting output: TrOzFailed to delete output: )rr questionrVStandardButtonYesNor delete_outputrSr]r^rr%rrgrhri)r&replyrrqs r)r>zOutputManager.on_delete_outputsk"" $$  6t7J7J7S7S6TUP P  & & * *[-G-G-J-J J  & & ) )   K..22 2 U--;;Dr5 __classcell__)r(s@r)rrsr 66=$~*P#*Pt*PXRB "_ " "7NrO('UR.c.d.r*r)rloggingPyQt6.QtWidgetsrrrrrrr r r r r r PyQt6.QtCorersrc.database.modelsrsrc.services.output_servicersrc.utils.file_utilsr getLoggerrr]rr*r)rsQ  &51   8 $t.Gt.r*