|
| 1 | +import flet as ft |
1 | 2 | import subprocess
|
2 |
| -from tkinter import Tk, Canvas, Label, Entry, Button, filedialog, messagebox |
3 | 3 |
|
4 | 4 |
|
5 |
| -def set_dark_theme(): |
6 |
| - window.configure(bg="#333") |
7 |
| - canvas.configure(bg="#333") |
| 5 | +def main(page: ft.Page): |
| 6 | + page.title = "Unreal Plugin Migration Tool" |
| 7 | + page.window_resizable = True |
| 8 | + page.update() |
8 | 9 |
|
9 |
| - for widget in window.winfo_children(): |
10 |
| - if isinstance(widget, (Label, Entry, Button)): |
11 |
| - widget.configure(bg="#555", fg="white") |
12 |
| - |
13 |
| - engine_button.configure(bg="#333", fg="white") |
14 |
| - origin_button.configure(bg="#333", fg="white") |
15 |
| - output_button.configure(bg="#333", fg="white") |
16 |
| - print_button.configure(bg="#333", fg="white") |
17 |
| - |
18 |
| - |
19 |
| -def get_engine_path(): |
20 |
| - engine_path = filedialog.askdirectory() |
21 |
| - engine_path = engine_path.replace("/", "\\") |
22 |
| - engine_entry.delete(0, "end") |
23 |
| - engine_entry.insert(0, engine_path) |
24 |
| - |
25 |
| - |
26 |
| -def get_origin_path(): |
27 |
| - origin_path = filedialog.askopenfilename(filetypes=[("Plugin Files", "*.uplugin")]) |
28 |
| - origin_path = origin_path.replace("/", "\\") |
29 |
| - origin_entry.delete(0, "end") |
30 |
| - origin_entry.insert(0, origin_path) |
31 |
| - |
32 |
| - |
33 |
| -def get_output_path(): |
34 |
| - output_path = filedialog.askdirectory() |
35 |
| - output_path = output_path.replace("/", "\\") |
36 |
| - output_entry.delete(0, "end") |
37 |
| - output_entry.insert(0, output_path) |
38 |
| - |
39 |
| - |
40 |
| -def migrate_plugin(): |
41 |
| - origin = origin_entry.get() |
42 |
| - output = output_entry.get() |
43 |
| - engine = engine_entry.get() |
44 |
| - engine = '"' + engine + '"' |
45 |
| - origin = '"' + origin + '"' |
46 |
| - output = '"' + output + '"' |
47 |
| - |
48 |
| - command = rf"{engine}\Engine\Build\BatchFiles\RunUAT.bat BuildPlugin -plugin={origin} -package={output}\Migrated" |
49 |
| - |
50 |
| - try: |
51 |
| - subprocess.run(command, shell=True) |
52 |
| - messagebox.showinfo( |
53 |
| - title="Migration complete", message="Your plugin was successfully ported" |
| 10 | + # Theme selector |
| 11 | + def theme_changed(e): |
| 12 | + page.theme_mode = ( |
| 13 | + ft.ThemeMode.LIGHT |
| 14 | + if page.theme_mode == ft.ThemeMode.DARK |
| 15 | + else ft.ThemeMode.DARK |
54 | 16 | )
|
55 |
| - except Exception as e: |
56 |
| - messagebox.showerror(title="Error", message="Error during the migration") |
57 |
| - |
58 |
| - |
59 |
| -window = Tk() |
60 |
| -window.title("Unreal Engine Plugin Migration Tool") |
61 |
| -window.config(padx=50, pady=50) |
62 |
| -canvas = Canvas(window, width=800, height=600) |
63 |
| - |
64 |
| -engine_label = Label(window, text="Engine Path:") |
65 |
| -engine_label.grid(column=0, row=0) |
66 |
| - |
67 |
| -engine_entry = Entry(window, width=60) |
68 |
| -engine_entry.grid(column=1, row=0) |
69 |
| -engine_entry.insert(0, "Select the root of the engine folder") |
70 |
| - |
71 |
| -engine_button = Button(window, text="Select Engine Path", command=get_engine_path) |
72 |
| -engine_button.grid(column=2, row=0) |
73 |
| - |
74 |
| -origin_label = Label(window, text="Origin Path:") |
75 |
| -origin_label.grid(column=0, row=1) |
76 |
| - |
77 |
| -origin_entry = Entry(window, width=60) |
78 |
| -origin_entry.grid(column=1, row=1) |
79 |
| - |
80 |
| -origin_button = Button(window, text="Select Origin Plugin", command=get_origin_path) |
81 |
| -origin_button.grid(column=2, row=1) |
82 |
| - |
83 |
| -output_label = Label(window, text="Output Path:") |
84 |
| -output_label.grid(column=0, row=2) |
85 |
| - |
86 |
| -output_entry = Entry(window, width=60) |
87 |
| -output_entry.grid(column=1, row=2) |
| 17 | + color_switch.label = "🌙" if page.theme_mode == ft.ThemeMode.DARK else "☀️" |
| 18 | + page.update() |
| 19 | + |
| 20 | + page.theme_mode = ft.ThemeMode.DARK |
| 21 | + color_switch = ft.Switch(label="🌙", on_change=theme_changed) |
| 22 | + |
| 23 | + # File picker function |
| 24 | + def pick_files_result(e: ft.FilePickerResultEvent): |
| 25 | + selected_file.value = ( |
| 26 | + ", ".join(map(lambda f: f.path, e.files)) |
| 27 | + if e.files |
| 28 | + else "No *.uplugin file was selected!" |
| 29 | + ) |
| 30 | + selected_file.update() |
88 | 31 |
|
89 |
| -output_button = Button(window, text="Select Output Path", command=get_output_path) |
90 |
| -output_button.grid(column=2, row=2) |
| 32 | + pick_files_dialog = ft.FilePicker(on_result=pick_files_result) |
| 33 | + selected_file = ft.Text() |
91 | 34 |
|
92 |
| -print_button = Button(window, text="Begin Plugin Migration", command=migrate_plugin) |
93 |
| -print_button.grid(column=1, row=3) |
| 35 | + # Save directory function |
| 36 | + def save_directory_result(e: ft.FilePickerResultEvent): |
| 37 | + save_file_path.value = e.path if e.path else "No save directory was selected!" |
| 38 | + save_file_path.update() |
94 | 39 |
|
95 |
| -set_dark_theme() |
| 40 | + save_directory_dialog = ft.FilePicker(on_result=save_directory_result) |
| 41 | + save_file_path = ft.Text() |
96 | 42 |
|
97 |
| -window.mainloop() |
| 43 | + # Unreal engine directory function |
| 44 | + def ue_get_directory_result(e: ft.FilePickerResultEvent): |
| 45 | + directory_path.value = ( |
| 46 | + e.path |
| 47 | + if e.path |
| 48 | + else 'No UE root folder was selected! (Example "C:\\Program Files\\Epic Games\\UE_5.3)"' |
| 49 | + ) |
| 50 | + directory_path.update() |
| 51 | + |
| 52 | + get_directory_dialog = ft.FilePicker(on_result=ue_get_directory_result) |
| 53 | + directory_path = ft.Text() |
| 54 | + |
| 55 | + # Hide all dialogs in overlay |
| 56 | + page.overlay.extend( |
| 57 | + [pick_files_dialog, save_directory_dialog, get_directory_dialog] |
| 58 | + ) |
| 59 | + |
| 60 | + # Plugin migration function |
| 61 | + def plugin_migration(): |
| 62 | + engine = rf'"{directory_path.value}"' |
| 63 | + plugin = rf'"{selected_file.value}"' |
| 64 | + destination = rf'"{save_file_path.value}"' |
| 65 | + command = rf"{engine}\Engine\Build\BatchFiles\RunUAT.bat BuildPlugin -plugin={plugin} -package={destination}\Migrated" |
| 66 | + try: |
| 67 | + result = subprocess.run(command, shell=True) |
| 68 | + if result.returncode == 0: |
| 69 | + fine = ft.AlertDialog( |
| 70 | + title=ft.Text("Plugin migrated succesfully"), |
| 71 | + ) |
| 72 | + page.dialog = fine |
| 73 | + fine.open = True |
| 74 | + page.update() |
| 75 | + else: |
| 76 | + wrong = ft.AlertDialog( |
| 77 | + title=ft.Text("Something went wrong"), |
| 78 | + ) |
| 79 | + page.dialog = wrong |
| 80 | + wrong.open = True |
| 81 | + page.update() |
| 82 | + |
| 83 | + except Exception as e: |
| 84 | + fail = ft.AlertDialog( |
| 85 | + title=ft.Text("An error has ocurred"), |
| 86 | + content=ft.Text( |
| 87 | + "Please check the command promp to see what the error is" |
| 88 | + ), |
| 89 | + ) |
| 90 | + page.dialog = fail |
| 91 | + fail.open = True |
| 92 | + page.update() |
| 93 | + |
| 94 | + # App layout |
| 95 | + page.add( |
| 96 | + ft.Row( |
| 97 | + [ |
| 98 | + color_switch, |
| 99 | + ], |
| 100 | + alignment=ft.MainAxisAlignment.END, |
| 101 | + ), |
| 102 | + ft.Row( |
| 103 | + [ |
| 104 | + ft.ElevatedButton( |
| 105 | + "Select the .uplugin file", |
| 106 | + icon=ft.icons.UPLOAD_FILE, |
| 107 | + on_click=lambda _: pick_files_dialog.pick_files( |
| 108 | + allowed_extensions=["uplugin"] |
| 109 | + ), |
| 110 | + ), |
| 111 | + selected_file, |
| 112 | + ] |
| 113 | + ), |
| 114 | + ft.Row( |
| 115 | + [ |
| 116 | + ft.ElevatedButton( |
| 117 | + "Plugin destination folder", |
| 118 | + icon=ft.icons.SAVE, |
| 119 | + on_click=lambda _: save_directory_dialog.get_directory_path(), |
| 120 | + disabled=page.web, |
| 121 | + ), |
| 122 | + save_file_path, |
| 123 | + ] |
| 124 | + ), |
| 125 | + ft.Row( |
| 126 | + [ |
| 127 | + ft.ElevatedButton( |
| 128 | + "Select UE root folder", |
| 129 | + icon=ft.icons.FOLDER_OPEN, |
| 130 | + on_click=lambda _: get_directory_dialog.get_directory_path(), |
| 131 | + disabled=page.web, |
| 132 | + ), |
| 133 | + directory_path, |
| 134 | + ] |
| 135 | + ), |
| 136 | + ft.ElevatedButton( |
| 137 | + "Begin Migration", |
| 138 | + icon=ft.icons.DEW_POINT, |
| 139 | + on_click=lambda _: plugin_migration(), |
| 140 | + ), |
| 141 | + ) |
| 142 | + |
| 143 | + |
| 144 | +ft.app(target=main) |
0 commit comments