@@ -35,7 +35,7 @@ class ConvertRunnable(QRunnable):
3535 """Runnable class for conversion tasks"""
3636
3737 def __init__ (self , script_path , convert_mode , output_dir , exe_name , icon_path , file_version ,
38- copyright_info , extra_library , additional_options ):
38+ copyright_info , extra_library , additional_options , python_path ):
3939 super ().__init__ ()
4040 self .script_path = script_path
4141 self .convert_mode = convert_mode
@@ -46,6 +46,7 @@ def __init__(self, script_path, convert_mode, output_dir, exe_name, icon_path, f
4646 self .copyright_info = copyright_info
4747 self .extra_library = extra_library
4848 self .additional_options = additional_options
49+ self .python_path = python_path
4950 self .signals = WorkerSignals ()
5051 self ._is_running = True
5152
@@ -72,7 +73,7 @@ def run(self):
7273
7374 self .update_status ("Start converting..." )
7475 success = self .run_pyinstaller (options )
75-
76+ self . _is_running = False
7677 if success :
7778 exe_path = os .path .join (output_dir , exe_name + '.exe' )
7879 if os .path .exists (exe_path ):
@@ -93,6 +94,7 @@ def run(self):
9394 self .update_status (error_message )
9495 self .signals .conversion_failed .emit (error_message )
9596 finally :
97+ self ._is_running = False
9698 self .cleanup_files (version_file_path )
9799
98100 def stop (self ):
@@ -106,15 +108,18 @@ def update_status(self, message: str):
106108
107109 def ensure_pyinstaller (self ) -> bool :
108110 """Make sure PyInstaller is installed"""
111+ path = self .python_path
112+ if not path :
113+ path = sys .executable
109114 try :
110- subprocess .run ([sys . executable , '-m' , 'PyInstaller' , '--version' ],
115+ subprocess .run ([path , '-m' , 'PyInstaller' , '--version' ],
111116 check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
112117 self .update_status ("PyInstaller detected." )
113118 return True
114119 except subprocess .CalledProcessError :
115120 self .update_status ("PyInstaller not detected, trying to install..." )
116121 try :
117- subprocess .check_call ([sys . executable , "-m" , "pip" , "install" , "pyinstaller" ])
122+ subprocess .check_call ([path , "-m" , "pip" , "install" , "pyinstaller" ])
118123 self .update_status ("PyInstaller was installed successfully." )
119124 return True
120125 except subprocess .CalledProcessError as e :
@@ -221,7 +226,10 @@ def create_version_file(self, exe_name: str, script_dir: str) -> str:
221226
222227 def run_pyinstaller (self , options : list ) -> bool :
223228 """Run PyInstaller to convert"""
224- cmd = [sys .executable , '-m' , 'PyInstaller' ] + options + [self .script_path ]
229+ path = self .python_path
230+ if not path :
231+ path = sys .executable
232+ cmd = [path , '-m' , 'PyInstaller' ] + options + [self .script_path ]
225233 self .update_status (f"Execute Command: { ' ' .join (cmd )} " )
226234 try :
227235 process = subprocess .Popen (
@@ -614,7 +622,11 @@ def start_conversion(self):
614622 if not self .script_paths :
615623 QMessageBox .warning (self , "Warning" , "Please select at least one Python script first." )
616624 return
617-
625+ python_path = None
626+ if not ("__file__" in globals () and "PythonEXE_Maker.py" in sys .argv [0 ]):
627+ python_path , _ = QFileDialog .getOpenFileName (self , "Select Python File" , "" , "Executable (*.exe)" )
628+ if not python_path :
629+ return
618630 convert_mode = self .mode_combo .currentText ()
619631 output_dir = self .output_edit .text ().strip () or None
620632 exe_name = self .name_edit .text ().strip () or None
@@ -652,7 +664,7 @@ def start_conversion(self):
652664 output_dir = output_dir , exe_name = exe_name , icon_path = icon_path ,
653665 file_version = file_version ,
654666 copyright_info = copyright_info , extra_library = extra_library ,
655- additional_options = additional_options )
667+ additional_options = additional_options , python_path = python_path )
656668
657669 runnable .signals .status_updated .connect (lambda msg , sp = script_path : self .update_status (msg , sp ))
658670 runnable .signals .progress_updated .connect (lambda val , sp = script_path : self .update_progress (val , sp ))
@@ -682,7 +694,7 @@ def conversion_finished(self, exe_path: str, exe_size: int, script_path: str):
682694 task_widget ['status' ].setText (f"Conversion successful! File: { exe_path } ({ exe_size } MB)" )
683695 task_widget ['progress' ].setValue (100 )
684696 self .progress_bar .setValue (100 )
685- if all ([getattr (task , '_is_running' , False ) for task in self .tasks ]):
697+ if not all ([getattr (task , '_is_running' , False ) for task in self .tasks ]):
686698 self .conversion_complete ()
687699
688700 def conversion_failed (self , error_message : str , script_path : str ):
@@ -693,7 +705,7 @@ def conversion_failed(self, error_message: str, script_path: str):
693705 task_widget ['status' ].setText (f"<span style='color:red;'>{ error_message } </span>" )
694706 task_widget ['progress' ].setValue (0 )
695707 self .progress_bar .setValue (0 )
696- if all ([getattr (task , '_is_running' , False ) for task in self .tasks ]):
708+ if not all ([getattr (task , '_is_running' , False ) for task in self .tasks ]):
697709 self .conversion_complete ()
698710
699711 def conversion_complete (self ):
@@ -765,16 +777,6 @@ def create_task_widget(self, script_path: str) -> dict:
765777
766778 return {'widget' : widget , 'script_label' : script_label , 'progress' : progress , 'status' : status } # , 'log': log}
767779
768- def load_settings (self ):
769- """Load saved settings"""
770- # QSettings (This method has been removed as QSettings is no longer used)
771- pass
772-
773- def save_settings (self ):
774- """Save current settings"""
775- # QSettings (This method has been removed as QSettings is no longer used)
776- pass
777-
778780 def update_start_button_state (self ):
779781 """Update the enabled state of the start button"""
780782 self .start_button .setEnabled (bool (self .script_paths ))
0 commit comments