pMi1zdZddlZddlmZmZmZmZmZmZm Z m Z m Z ddl m Z mZddlmZddlmZGddeZy) z,Aggregator tab for combining markdown files.N) QWidget QVBoxLayout QHBoxLayoutQLabel QLineEdit QPushButton QProgressBar QFileDialog QMessageBox)QtQCoreApplication) Aggregator)ObsidianToolExceptioncFeZdZdZfdZdZdZdZdZde fdZ xZ S) AggregatorTabz,Tab for aggregating multiple markdown files.c`t|t|_|j y)zInitialize the aggregator tab.N)super__init__r aggregatorinit_ui)self __class__s ?/mnt/ssd/data/python-lab/ObsidianTool/src/gui/aggregator_tab.pyrzAggregatorTab.__init__s  $, c4t|}|jd|jdddd|jt dt }t |_|jjd|jjd|j|jtd|_ |jjd|jjj|j|j|j|j!||jt dt }t |_|j"jd|j"jd |j|j"td|_|j$jd|j$jj|j&|j|j$|j!||j)dtd |_|j*j-d |j*jj|j.|j|j*t1|_|j2j5d |j|j2t d |_|j6j9t:j<j>|j6jAd|j|j6|jCy)zInitialize the user interface.zSource Directory:Tz*Select a directory containing .md files...z Browse...dzOutput File:zSelect output file location...zAggregate Files(rReadyz color: #666; font-style: italic;N)"r setSpacingsetContentsMargins addWidgetrrr source_edit setReadOnlysetPlaceholderTextr source_btnsetMaximumWidthclickedconnect browse_source addLayout output_edit output_btn browse_output addSpacing aggregate_btnsetMinimumHeightaggregate_filesr progress_barsetValue status_label setAlignmentr AlignmentFlag AlignCenter setStyleSheet addStretch)rlayout source_layout output_layouts rrzAggregatorTab.init_uisT""!!"b"b1  :;<# $; $$T* ++,XY 0 01%k2 '', ''(:(:;0'  567# $; $$T* ++,LM 0 01%k2 '', ''(:(:;0' ")):; ++B/ ""**4+?+?@++,)N ""1%**+#7O &&r'7'7'C'CD ''(JK**+ rctj|dtjj d}|r7|j j ||jj dyy)z'Open dialog to select source directory.zSelect Source Directory~zSource directory selectedN)r getExistingDirectoryospath expanduserr$setTextr6)r directorys rr+zAggregatorTab.browse_sourceSs]44  % GG  s #     $ $Y /    % %&A B rctj|dtjj dd\}}|rM|j ds|dz }|j j||jjdyy)z"Open dialog to select output file.zSelect Output Filez~/aggregated.mdz$Markdown Files (*.md);;All Files (*)z.mdzOutput file selectedN) r getSaveFileNamerBrCrDendswithr-rEr6)r file_path_s rr/zAggregatorTab.browse_output_s}"22  GG  0 1 2  1 %%e,U"    $ $Y /    % %&< = rc &jj}jj}|stjddy|stjddyj dj jdjjd fd}jj|||}tjd d |d d |d jjdj dy#t$rc}tjddt|jjdj jdYd}~yd}~wt $rc}tjddt|jjdj jdYd}~d}~wwxYw#j dwxYw)z"Perform the aggregation operation.zInput Requiredz!Please select a source directory.NzPlease select an output file.FrzAggregating files...cjj|jj|t j y)N)r4r5r6rEr processEvents) percentagemessagers rupdate_progressz6AggregatorTab.aggregate_files..update_progresss7!!**:6!!))'2 ..0rSuccessz(Aggregation complete! Files processed: files_processedz Output file: output_filez"Aggregation completed successfullyErrorzAggregation failed: zAggregation failedzUnexpected ErrorzAn unexpected error occurred: T)r$textr-r warningset_ui_enabledr4r5r6rEr aggregate informationrcriticalstr Exception)r source_dirrTrQresultes` rr3zAggregatorTab.aggregate_filesos%%**, &&++-     3      /   E" ""1% !!"89- & 1 __..F  # #$$*+<$=#>? &} 568     % %&J K,    %)% *  )#a&2     % %&: ;    & &q ) ) *  "3CF8<     % %&: ;    & &q ) ) *    %s?2A D$$ G:-AF G= G:AG50G=5G::G==Henabledc|jj||jj||jj|y)z/Enable or disable UI elements during operation.N)r' setEnabledr.r1)rras rrXzAggregatorTab.set_ui_enableds: ""7+ ""7+ %%g.r) __name__ __module__ __qualname____doc__rrr+r/r3boolrX __classcell__)rs@rrr s/6 ;z C> H&T/d/rr)rgrBPyQt6.QtWidgetsrrrrrrr r r PyQt6.QtCorer r core.aggregatorrcore.exceptionsrrrrros32 .&1p/Gp/r