3
3
"""
4
4
# pylint: disable=import-error, too-many-instance-attributes, too-many-statements
5
5
import os
6
+ import tkinter .filedialog
6
7
from collections .abc import Callable
7
8
from importlib import import_module
8
9
from tkinter import ttk
@@ -60,10 +61,27 @@ def __init__(self):
60
61
self .src_binaries_table .heading ("file" , text = t ("frontend.source_file_loc" ))
61
62
self .src_binaries_table .heading ("file_size" , text = t ("frontend.file_size" ))
62
63
self .src_binaries_frame .grid_rowconfigure (0 , weight = 1 )
64
+ self .src_binaries_frame .grid_rowconfigure (1 , weight = 1 )
63
65
self .src_binaries_frame .grid_columnconfigure (0 , weight = 1 )
66
+ self .src_binaries_frame .grid_columnconfigure (1 , weight = 1 )
67
+ self .src_binaries_frame .grid_columnconfigure (2 , weight = 1 )
64
68
self .src_binaries_frame .grid_propagate (False )
65
- self .src_binaries_table .grid (row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = CTk .NSEW )
69
+ self .src_binaries_table .grid (row = 0 , column = 0 , columnspan = 3 , padx = 10 , pady = 10 ,
70
+ sticky = CTk .NSEW )
66
71
self .attempt_apply_dnd (self .src_binaries_table .winfo_id (), self .on_binary_dropped )
72
+ self .src_binaries_add_btn = CTk .CTkButton (self .src_binaries_frame ,
73
+ text = t ("frontend.button_add" ))
74
+ self .src_binaries_add_btn .configure (command = self .on_binary_add_click )
75
+ self .src_binaries_add_btn .grid (row = 1 , column = 0 , padx = 10 , pady = 10 , sticky = CTk .EW )
76
+ self .src_binaries_remove_selected_btn = CTk .CTkButton (self .src_binaries_frame , text = t (
77
+ "frontend.button_remove_selected" ))
78
+ self .src_binaries_remove_selected_btn .grid (row = 1 , column = 1 , padx = 10 , pady = 10 , sticky = CTk .EW )
79
+ self .src_binaries_remove_selected_btn .configure (
80
+ command = self .on_binary_remove_selected_click )
81
+ self .src_binaries_remove_all = CTk .CTkButton (self .src_binaries_frame ,
82
+ text = t ("frontend.button_remove_all" ))
83
+ self .src_binaries_remove_all .grid (row = 1 , column = 2 , padx = 10 , pady = 10 , sticky = CTk .EW )
84
+ self .src_binaries_remove_all .configure (command = self .on_binary_remove_all_click )
67
85
self .src_schemas_frame = ttk .LabelFrame (self .src_files_frame ,
68
86
text = t ("frontend.source_schemas" ))
69
87
self .src_schemas_frame .grid (row = 1 , column = 0 , padx = 10 , pady = 10 , sticky = CTk .NSEW )
@@ -84,14 +102,25 @@ def __init__(self):
84
102
self .dest_binaries_frame .grid (row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = CTk .NSEW )
85
103
self .dest_binaries_table = ttk .Treeview (self .dest_binaries_frame ,
86
104
columns = ("file" , "result" , "file_size" ),
87
- show = "headings" )
105
+ show = "headings" , selectmode = "browse" )
88
106
self .dest_binaries_table .heading ("file" , text = t ("frontend.destination_file_loc" ))
89
107
self .dest_binaries_table .heading ("result" , text = t ("frontend.result" ))
90
108
self .dest_binaries_table .heading ("file_size" , text = t ("frontend.file_size" ))
91
109
self .dest_binaries_frame .grid_rowconfigure (0 , weight = 1 )
110
+ self .dest_binaries_frame .grid_rowconfigure (1 , weight = 1 )
92
111
self .dest_binaries_frame .grid_columnconfigure (0 , weight = 1 )
112
+ self .dest_binaries_frame .grid_columnconfigure (1 , weight = 1 )
93
113
self .dest_binaries_frame .grid_propagate (False )
94
- self .dest_binaries_table .grid (row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = CTk .NSEW )
114
+ self .dest_binaries_table .grid (row = 0 , column = 0 , columnspan = 2 , padx = 10 , pady = 10 ,
115
+ sticky = CTk .NSEW )
116
+ self .attempt_apply_dnd (self .dest_binaries_table .winfo_id (), self .on_binary_dropped )
117
+ self .dest_binaries_change_dest_btn = CTk .CTkButton (self .dest_binaries_frame ,
118
+ text = t ("frontend.button_change_dest" ))
119
+ self .dest_binaries_change_dest_btn .grid (row = 1 , column = 0 , padx = 10 , pady = 10 , sticky = CTk .EW )
120
+ self .dest_binaries_change_dest_btn .configure (command = self .on_change_dest_click )
121
+ self .dest_binaries_rename_btn = CTk .CTkButton (self .dest_binaries_frame ,
122
+ text = t ("frontend.button_rename_file" ))
123
+ self .dest_binaries_rename_btn .grid (row = 1 , column = 1 , padx = 10 , pady = 10 , sticky = CTk .EW )
95
124
self .dest_options_frame = ttk .LabelFrame (self .dest_files_frame ,
96
125
text = t ("frontend.destination_options" ))
97
126
self .dest_options_frame .grid_propagate (False )
@@ -127,6 +156,60 @@ def flatc_button_pressed():
127
156
"""
128
157
execute_download (os .getcwd ())
129
158
159
+ def on_binary_add_click (self ):
160
+ """
161
+ Triggered when "Add..." button is clicked.
162
+ """
163
+ binary_paths = tkinter .filedialog .askopenfilenames (title = t ("main.tkinter_binaries_select" ))
164
+ if binary_paths is not None :
165
+ self .on_binary_dropped (binary_paths )
166
+
167
+ def on_binary_remove_selected_click (self ):
168
+ """
169
+ Triggered when "Remove selected" button is clicked.
170
+ """
171
+ selected_items = self .src_binaries_table .selection ()
172
+ for selected_item in selected_items :
173
+ self .src_binaries_table .delete (selected_item )
174
+ self .src_binaries_table .update ()
175
+ self .dest_binaries_table .delete (selected_item )
176
+ self .dest_binaries_table .update ()
177
+
178
+ def on_binary_remove_all_click (self ):
179
+ """
180
+ Triggered when "Remove all" button is clicked.
181
+ :return:
182
+ """
183
+ for item in self .dest_binaries_table .get_children ():
184
+ self .src_binaries_table .delete (item )
185
+ self .src_binaries_table .update ()
186
+ self .dest_binaries_table .delete (item )
187
+ self .dest_binaries_table .update ()
188
+
189
+ def on_change_dest_click (self ):
190
+ """
191
+ Triggered when "Change destination directory..." button is clicked.
192
+ :return:
193
+ """
194
+ selected_items = self .dest_binaries_table .selection ()
195
+ for selected_item in selected_items :
196
+ file_path = self .dest_binaries_table .set (selected_item , 0 )
197
+ file_dir , file_name = os .path .split (file_path )
198
+ dest_dir = tkinter .filedialog .askdirectory (title = t ("main.tkinter_output_select" ),
199
+ initialdir = file_dir )
200
+ if os .path .isdir (dest_dir ):
201
+ new_file_path = os .path .abspath (os .path .join (dest_dir , file_name ))
202
+ self .dest_binaries_table .set (selected_item , 0 , new_file_path )
203
+ if os .path .isfile (new_file_path ):
204
+ self .dest_binaries_table .set (selected_item , 1 ,
205
+ t ("frontend.file_already_exists" ))
206
+ self .dest_binaries_table .set (selected_item , 2 ,
207
+ t ("frontend.size_kb" ) % (
208
+ os .path .getsize (new_file_path ) / 1024 ))
209
+ else :
210
+ self .dest_binaries_table .set (selected_item , 1 , "" )
211
+ self .dest_binaries_table .update ()
212
+
130
213
def on_binary_dropped (self , paths : list [str ]):
131
214
"""
132
215
Triggered when binary files or directories are added to table.
@@ -233,6 +316,9 @@ def deserialize_and_update_table(self, flatc_path: str, schema_path: str, binary
233
316
self .dest_binaries_table .set (i , 1 , t ("frontend.result_done" ))
234
317
self .dest_binaries_table .set (i , 2 , t ("frontend.size_kb" ) % (
235
318
os .path .getsize (json_path ) / 1024 ))
319
+ elif not os .path .isfile (binary_path ):
320
+ self .dest_binaries_table .set (i , 1 , t ("frontend.binary_not_found" ))
321
+ self .dest_binaries_table .set (i , 2 , "" )
236
322
elif not os .path .isfile (schema_path ):
237
323
self .dest_binaries_table .set (i , 1 , t ("frontend.schema_not_found" ))
238
324
self .dest_binaries_table .set (i , 2 , "" )
0 commit comments