@@ -46,6 +46,7 @@ def init_variables(self):
4646        self .max_size  =  1024 
4747        self .converting  =  False 
4848        self .current_view  =  "main" 
49+         self .output_format  =  "icns"  # Default output format 
4950
5051    def  setup_ui (self ):
5152        """Setup initial UI""" 
@@ -175,6 +176,17 @@ def create_widgets(self):
175176        #options_panel.SetBackgroundColour(wx.Colour(245, 245, 245)) 
176177        options_sizer  =  wx .BoxSizer (wx .VERTICAL )
177178
179+         # Output Format Selection 
180+         format_sizer  =  wx .BoxSizer (wx .HORIZONTAL )
181+         format_label  =  wx .StaticText (options_panel , label = "Output Format:" )
182+         self .format_combo  =  wx .ComboBox (options_panel , choices = convert .SUPPORTED_FORMATS , 
183+                                         style = wx .CB_READONLY , value = "icns" )
184+         self .format_combo .Bind (wx .EVT_COMBOBOX , self .on_format_change )
185+         format_sizer .Add (format_label , 0 , wx .ALIGN_CENTER_VERTICAL  |  wx .ALL , 10 )
186+         format_sizer .AddStretchSpacer ()
187+         format_sizer .Add (self .format_combo , 0 , wx .ALL , 10 )
188+         options_sizer .Add (format_sizer , 0 , wx .EXPAND )
189+         
178190        # Min size 
179191        min_sizer  =  wx .BoxSizer (wx .HORIZONTAL )
180192        min_label  =  wx .StaticText (options_panel , label = "Minimum Size:" )
@@ -198,9 +210,9 @@ def create_widgets(self):
198210        options_sizer .Add (max_sizer , 0 , wx .EXPAND )
199211
200212        # Auto-detect button 
201-         auto_button  =  wx .Button (options_panel , label = "Auto-detect Max Size" )
202-         auto_button .Bind (wx .EVT_BUTTON , self .on_auto_detect )
203-         options_sizer .Add (auto_button , 0 , wx .ALL  |  wx .CENTER , 15 )
213+         self . auto_button  =  wx .Button (options_panel , label = "Auto-detect Max Size" )
214+         self . auto_button .Bind (wx .EVT_BUTTON , self .on_auto_detect )
215+         options_sizer .Add (self . auto_button , 0 , wx .ALL  |  wx .CENTER , 15 )
204216
205217        options_panel .SetSizer (options_sizer )
206218        size_box_sizer .Add (options_panel , 1 , wx .EXPAND  |  wx .ALL , 10 )
@@ -277,19 +289,41 @@ def on_browse_input(self, event):
277289            self .update_image_info ()
278290
279291    def  on_browse_output (self , event ):
280-         with  wx .FileDialog (self , "Save ICNS file" , wildcard = "ICNS files (*.icns)|*.icns|All files (*.*)|*.*" ,
292+         wildcard_map  =  {
293+             "icns" : "ICNS files (*.icns)|*.icns" ,
294+             "png" : "PNG files (*.png)|*.png" ,
295+             "jpg" : "JPEG files (*.jpg)|*.jpg" ,
296+             "webp" : "WebP files (*.webp)|*.webp" ,
297+         }
298+         default_wildcard  =  wildcard_map .get (self .output_format , "All files (*.*)|*.*" )
299+         
300+         with  wx .FileDialog (self , f"Save { self .output_format .upper ()}  , wildcard = default_wildcard  +  "|All files (*.*)|*.*" ,
281301                          style = wx .FD_SAVE  |  wx .FD_OVERWRITE_PROMPT ) as  fileDialog :
282302            if  fileDialog .ShowModal () ==  wx .ID_CANCEL :
283303                return 
284304
285305            self .output_path  =  fileDialog .GetPath ()
286-             if  not  self .output_path .endswith ('.icns' ):
287-                 self .output_path  +=  '.icns' 
306+             # Ensure the output path has the correct extension based on selected format 
307+             expected_extension  =  '.'  +  self .output_format 
308+             if  not  self .output_path .lower ().endswith (expected_extension ):
309+                 self .output_path  +=  expected_extension 
288310            self .output_text .SetValue (self .output_path )
289311
312+     def  on_format_change (self , event ):
313+         self .output_format  =  self .format_combo .GetValue ().lower ()
314+         # Update output path with new extension if an input file is selected 
315+         self .auto_set_output ()
316+         self .convert_button .SetLabel (f"Convert to { self .output_format .upper ()}  )
317+         # Disable size options if not converting to ICNS 
318+         enable_size_options  =  (self .output_format  ==  "icns" )
319+         self .min_spin .Enable (enable_size_options )
320+         self .max_spin .Enable (enable_size_options )
321+         self .auto_button .Enable (enable_size_options ) # Corrected: Reference auto_button 
322+         
290323    def  auto_set_output (self ):
291-         if  self .input_path  and  self .input_path .lower ().endswith ('.png' ):
292-             output_file  =  os .path .splitext (self .input_path )[0 ] +  '.icns' 
324+         if  self .input_path :
325+             base_name  =  os .path .splitext (os .path .basename (self .input_path ))[0 ]
326+             output_file  =  f"{ os .path .dirname (self .input_path )} { os .sep } { base_name } { self .output_format }  
293327            self .output_path  =  output_file 
294328            self .output_text .SetValue (output_file )
295329
@@ -354,16 +388,15 @@ def on_start_conversion(self, event):
354388            return 
355389
356390        if  not  self .output_path :
357-             wx .MessageBox ("Please specify an output ICNS  file." , "Error" , wx .OK  |  wx .ICON_ERROR )
391+             wx .MessageBox (f "Please specify an output { self . output_format . upper () } "Error" , wx .OK  |  wx .ICON_ERROR )
358392            return 
359393
360394        if  not  os .path .exists (self .input_path ):
361395            wx .MessageBox ("Input file does not exist." , "Error" , wx .OK  |  wx .ICON_ERROR )
362396            return 
363397
364-         if  not  self .input_path .lower ().endswith ('.png' ):
365-             wx .MessageBox ("Input file must be a PNG image." , "Error" , wx .OK  |  wx .ICON_ERROR )
366-             return 
398+         # The input can be any image format now that Pillow handles it 
399+         # No longer need to check for .png extension here 
367400
368401        # Start conversion in a separate thread 
369402        self .converting  =  True 
@@ -378,13 +411,22 @@ def convert(self):
378411        """执行转换过程""" 
379412        try :
380413            # 执行转换 
381-             convert .create_icns (
382-                 self .input_path , 
383-                 self .output_path , 
384-                 self .min_size , 
385-                 self .max_size ,
386-                 progress_callback = self .update_progress 
387-             )
414+             if  self .output_format  ==  "icns" :
415+                 convert .convert_image (
416+                     self .input_path , 
417+                     self .output_path , 
418+                     self .output_format ,
419+                     self .min_size , 
420+                     self .max_size ,
421+                     progress_callback = self .update_progress 
422+                 )
423+             else :
424+                 convert .convert_image (
425+                     self .input_path ,
426+                     self .output_path ,
427+                     self .output_format ,
428+                     progress_callback = self .update_progress 
429+                 )
388430
389431            # 在主线程中显示成功界面 
390432            wx .CallAfter (self .show_success_view )
@@ -433,7 +475,7 @@ def show_success_view(self):
433475        center_sizer .Add (checkmark , 0 , wx .CENTER  |  wx .ALL , 20 )
434476
435477        # 添加成功信息 
436-         msg  =  wx .StaticText (center_panel , label = "Your ICNS  file has been created successfully!" )
478+         msg  =  wx .StaticText (center_panel , label = f "Your { self . output_format . upper () } 
437479        center_sizer .Add (msg , 0 , wx .CENTER  |  wx .BOTTOM , 20 )
438480
439481        # 添加返回按钮 
@@ -467,6 +509,7 @@ def show_success_view(self):
467509
468510        # 重置状态 
469511        self .converting  =  False 
512+         self .current_view  =  "success"  # Set current view to success 
470513
471514    def  on_conversion_error (self , error_message ):
472515        """转换失败后的处理""" 
@@ -480,28 +523,45 @@ def show_main_view(self, event=None):
480523        current_size  =  self .GetSize ()
481524        current_pos  =  self .GetPosition ()
482525
483-         # 重置所有变量  
526+         # Reset all variables  
484527        self .init_variables ()
485528
486-         # 清除所有控件  
529+         # Clear all controls (except status bar) to ensure a clean slate  
487530        for  child  in  self .GetChildren ():
488-             if  child  !=  self .status_bar : 
531+             if  child  !=  self .status_bar   and   child . GetName ()  !=   "FrameStatusBar" :  # Exclude status bar 
489532                child .Destroy ()
490533
491-         # 重置背景颜色 
492-         #self.SetBackgroundColour(wx.Colour(245, 245, 245)) 
493-         
494-         # 重新创建UI 
534+         # Re-setup UI (this will create new widgets and set self.main_panel) 
495535        self .setup_ui ()
536+         self .current_view  =  "main"  # Ensure we are in the main view 
496537
497-         # 恢复窗口尺寸和位置 
538+         # Update widgets to reflect initial state (these are new widgets from setup_ui) 
539+         self .input_text .SetValue ("" )
540+         self .output_text .SetValue ("" )
541+         self .info_text .SetValue ("No image selected" )
542+         self .preview_bitmap .SetBitmap (wx .NullBitmap )
543+         self .min_spin .SetValue (16 )
544+         self .max_spin .SetValue (1024 )
545+         self .format_combo .SetValue ("icns" )
546+         self .convert_button .SetLabel ("Convert to ICNS" )
547+         self .min_spin .Enable (True )
548+         self .max_spin .Enable (True )
549+         self .auto_button .Enable (True )
550+         self .progress .SetValue (0 )
551+         self .progress_label .SetLabel ("Ready" )
552+         self .convert_button .Enable (True )
553+         
554+         # Re-layout the main panel 
555+         self .main_panel .Layout ()
556+         
557+         # Restore window size and position 
498558        self .SetSize (current_size )
499559        self .SetPosition (current_pos )
500560
501-         # 刷新显示  
561+         # Refresh display  
502562        self .Layout ()
503563        self .Refresh ()
504-          
564+ 
505565    def  on_resize (self , event ):
506566        """处理窗口大小改变事件""" 
507567        self .Layout ()
@@ -516,7 +576,7 @@ def update_progress(self, message, percentage):
516576
517577class  ICNSConverterApp (wx .App ):
518578    def  OnInit (self ):
519-         frame  =  ICNSConverterGUI (None , "PNG to ICNS  Converter" )
579+         frame  =  ICNSConverterGUI (None , "Image  Converter" )
520580        return  True 
521581
522582
0 commit comments