&7i(dZddlZddlmZddlmZmZmZmZm Z m Z m Z m Z ddl mZddlmZej"eZGddeZy) z_Recipe Editor Dialog for ChefSystem. Dialog for creating and editing recipe prompt templates. N)Optional)QDialog QVBoxLayout QFormLayout QLineEdit QTextEditQDialogButtonBox QMessageBoxQLabel)Qt) RecipeServiceceZdZdZd deeffd Zd dZd dZde e e ffdZ de fdZ d fd Zdeefd ZxZS) RecipeEditorzrDialog for creating and editing recipes. Provides form fields for all recipe attributes with validation. recipe_idcBt||||_t||_||_d|_|j|dnd|jddd|_ d|_ d|_ d|_ d|_ |j|jy)zInitialize the recipe editor dialog. Args: db_manager: DatabaseManager instance. recipe_id: ID of recipe to edit, or None for new recipe. parent: Parent widget. Nz New Recipez Edit RecipeiiX)super__init__ db_managerr recipe_servicerrecipesetWindowTitlesetMinimumSize name_input prompt_input tags_inputdescription_input notes_input _setup_ui _load_recipe)selfrrparent __class__s ;/mnt/ssd/data/python-lab/ChefSystem/src/ui/recipe_editor.pyrzRecipeEditor.__init__s  $+J7"  I,=L=Q C%0415/36:04  returnclt}td}|j|t}t |_|j j d|jd|j t |_|jj dtd}|jd|jd|j|jd|t|_ |jjd |jj d |jd |jt|_ |jjd |jj d td}|jd|jd|j|jd|t|_|jjd |jj d|jd|jtd}|jd|jd||j!||j#t%t$j&j(t$j&j*z}|j,j/|j0|j2j/|j4|j||j7|y)zSet up the form UI components.z

Recipe Details

z#Enter a unique name for this recipez Name*:z e.g., python,code-review,testingz.Comma-separated tags for categorizationzcolor: gray; font-size: 10px;z Tags:Pz*Brief description of what this recipe doeszDescription:z&Enter the prompt template text here...zEThe AI prompt template - can include placeholders like [TOPIC]zPrompt Text*:z0Optional notes about usage, best practices, etc.z Notes:z* Required fieldszcolor: red; font-size: 10px;N)rr addWidgetrrrsetPlaceholderTextaddRowr setStyleSheetrrsetMaximumHeightrsetMinimumHeightr addLayout addStretchr StandardButtonSaveCancelacceptedconnectacceptrejectedreject setLayout)r main_layout header_label form_layout tags_help prompt_help required_note button_boxs r#rzRecipeEditor._setup_ui4s!m 78 l+"m $+ **+PQ?DOO<$+ **+MNKL  ?@>4??;2y)"+ //3 112^_0$2H2HI&K **3/ ,,-UVde !!"AB143D3DE2{+%; ))"- ++,^_?D,<,<=9: ##$BC2}-k* &  + + 0 0  + + 2 2 3  ##DKK0##DKK0j) {#r$c|j |jj|j|_|jr`|jj |jj |jj|jj|jj |jjr|jjnd|jj|jjr|jjnd|jj|jjr|jjndt j#d|jj yt%j&|dd|jd|j)yy#t*$r[}t j-d|jd|d t%j&|dd ||j)Yd}~yd}~wwxYw) z,Load recipe data if editing existing recipe.Nr'zLoaded recipe for editing: Errorz Recipe ID z not found in database.zError loading recipe z: Texc_infozFailed to load recipe: )rr get_reciperrsetTextnamer setPlainText prompt_textrtagsr descriptionrnotesloggerinfor criticalr9 Exceptionerror)r es r#rzRecipeEditor._load_recipets >> %! "11<-> ))BKK"=dkk>N>N=O PQ (($T^^$44KL KKM3 &6  4T^^4DBqcJUY Z$$-aS1   sFG&5G I&AH<<Ic|jjj}|syt|dkDry|jj j}|sy|j $|jj|sdd|dfSy |jrH||jjk7r/|jj||j sdd|dfSy ) zhValidate form inputs. Returns: tuple[bool, str]: (is_valid, error_message) )FzRecipe name is required.r))Fz+Recipe name must be 200 characters or less.)FzPrompt text is required.FzA recipe named 'z1' already exists. Please choose a different name.) exclude_id)Tr') rtextstriplenr toPlainTextrrcheck_name_uniquerrH)r rHrJs r# validate_formzRecipeEditor.validate_forms##%++-4 t9s?G''335;;= 4 >> !&&88> 06ghhh {{tt{{'7'77**<t j#d|jtj&|dd |dy tj(|d dy#t,$r>} t j/d| d tj(|d d| Yd} ~ yd} ~ wwxYw)znSave the recipe to database. Returns: bool: True if successful, False otherwise. zValidation ErrorFN)rHrJrKrLrMzCreated new recipe: z (ID: )SuccesszRecipe 'z' created successfully!TrCz4Failed to create recipe. The name may already exist.zUpdated recipe ID z' updated successfully!z4Failed to update recipe. The name may already exist.zError saving recipe: rDz An error occurred while saving: )r[r warningrrVrWrrYrrrrr create_recipeidrrNrOrH informationrP update_reciperQrR) r is_valid error_messagerHrJrKrLrMrsuccessrSs r# save_recipezRecipeEditor.save_recipesU#'"4"4"6-   "  ##%++-''335 ##%++-,,88:@@B   ,,.446? ~~%,,:: + + ;%+YYDN"(DKKK"6v{{m6&))TU VW++!"6;;-/FG  ((N !--;;NN + + <KK"4T^^4D EF++!"4&(?@  ((N !  LL04tL D  21#6   s,)BH H A*H H I')4I""I'cD|jrt| yy)z'Handle dialog acceptance (Save button).N)rgrr7)r r"s r#r7zRecipeEditor.accepts     GN  r$c|jS)zpGet the ID of the saved recipe. Returns: int: Recipe ID, or None if not saved yet. )r)r s r# get_recipe_idzRecipeEditor.get_recipe_ids ~~r$)NN)r%N)__name__ __module__ __qualname____doc__rintrrrtupleboolstrr[rgr7rj __classcell__)r"s@r#rrs^ hsm6>$@$LuT3Y/BVTVp x}r$r)rnloggingtypingrPyQt6.QtWidgetsrrrrrr r r PyQt6.QtCorer src.services.recipe_servicer getLoggerrkrNrr$r#r{sI 5   8 $K7Kr$