Просмотр исходного кода

added kill button for stuck/unwanted processes

Jonathan Higgins 7 месяцев назад
Родитель
Сommit
4553d505f3
2 измененных файлов с 21 добавлено и 7 удалено
  1. 7 1
      scenes/main/control.gd
  2. 14 6
      scenes/main/control.tscn

+ 7 - 1
scenes/main/control.gd

@@ -1276,6 +1276,7 @@ func monitor_process(pid: int, stdout: FileAccess, stderr: FileAccess) -> String
 			console_output.scroll_to_line(console_output.get_line_count() - 1)
 			console_output.scroll_to_line(console_output.get_line_count() - 1)
 		while stderr.get_position() < stderr.get_length():
 		while stderr.get_position() < stderr.get_length():
 			var line = stderr.get_line()
 			var line = stderr.get_line()
+			output += line
 			console_output.append_text(line + "\n")
 			console_output.append_text(line + "\n")
 			console_output.scroll_to_line(console_output.get_line_count() - 1)
 			console_output.scroll_to_line(console_output.get_line_count() - 1)
 	
 	
@@ -1299,7 +1300,12 @@ func monitor_process(pid: int, stdout: FileAccess, stderr: FileAccess) -> String
 			
 			
 	return output
 	return output
 
 
-
+func _on_kill_process_button_down() -> void:
+	if process_running and process_info.has("pid"):
+		# Terminate the process by PID
+		OS.kill(process_info["pid"])
+		process_running = false
+		print("Process cancelled.")
 
 
 	
 	
 	#if is_windows:
 	#if is_windows:

+ 14 - 6
scenes/main/control.tscn

@@ -193,21 +193,28 @@ always_on_top = true
 offset_left = 10.0
 offset_left = 10.0
 offset_top = 8.0
 offset_top = 8.0
 offset_right = 590.0
 offset_right = 590.0
-offset_bottom = 352.0
+offset_bottom = 344.0
 
 
 [node name="ConsoleOutput" type="RichTextLabel" parent="Console"]
 [node name="ConsoleOutput" type="RichTextLabel" parent="Console"]
 offset_left = 12.0
 offset_left = 12.0
 offset_top = 8.0
 offset_top = 8.0
 offset_right = 588.0
 offset_right = 588.0
-offset_bottom = 352.0
+offset_bottom = 344.0
 
 
 [node name="ConsoleOpenFolder" type="Button" parent="Console"]
 [node name="ConsoleOpenFolder" type="Button" parent="Console"]
-offset_left = -4.0
-offset_top = 360.0
-offset_right = 604.0
-offset_bottom = 401.0
+offset_left = 308.0
+offset_top = 352.0
+offset_right = 588.0
+offset_bottom = 393.0
 text = "Open Output Folder"
 text = "Open Output Folder"
 
 
+[node name="KillProcess" type="Button" parent="Console"]
+offset_left = 12.0
+offset_top = 352.0
+offset_right = 292.0
+offset_bottom = 393.0
+text = "Stop Running Thread"
+
 [node name="ColorRect" type="ColorRect" parent="."]
 [node name="ColorRect" type="ColorRect" parent="."]
 layout_mode = 1
 layout_mode = 1
 anchors_preset = 10
 anchors_preset = 10
@@ -414,6 +421,7 @@ visible = false
 [connection signal="dir_selected" from="CdpLocationDialog" to="." method="_on_cdp_location_dialog_dir_selected"]
 [connection signal="dir_selected" from="CdpLocationDialog" to="." method="_on_cdp_location_dialog_dir_selected"]
 [connection signal="close_requested" from="Console" to="." method="_on_console_close_requested"]
 [connection signal="close_requested" from="Console" to="." method="_on_console_close_requested"]
 [connection signal="button_down" from="Console/ConsoleOpenFolder" to="." method="_on_console_open_folder_button_down"]
 [connection signal="button_down" from="Console/ConsoleOpenFolder" to="." method="_on_console_open_folder_button_down"]
+[connection signal="button_down" from="Console/KillProcess" to="." method="_on_kill_process_button_down"]
 [connection signal="index_pressed" from="MenuBar/FileButton" to="." method="_on_file_button_index_pressed"]
 [connection signal="index_pressed" from="MenuBar/FileButton" to="." method="_on_file_button_index_pressed"]
 [connection signal="index_pressed" from="MenuBar/SettingsButton" to="." method="_on_settings_button_index_pressed"]
 [connection signal="index_pressed" from="MenuBar/SettingsButton" to="." method="_on_settings_button_index_pressed"]
 [connection signal="index_pressed" from="MenuBar/HelpButton" to="." method="_on_help_button_index_pressed"]
 [connection signal="index_pressed" from="MenuBar/HelpButton" to="." method="_on_help_button_index_pressed"]