Skip to content

Commit 0755a4b

Browse files
committed
Merged 2 destination files buttons into one called "Rename selected", added building GUI executable action.
1 parent c57b61a commit 0755a4b

File tree

11 files changed

+88
-43
lines changed

11 files changed

+88
-43
lines changed

.github/workflows/build_executable.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ jobs:
2525
pyinstaller --onefile --name="flatc_deserializer" --console --icon=images\flatbuffers-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_deserializer.py
2626
pyinstaller --onefile --name="flatc_downloader" --console --icon=images\flatbuffers-downloader-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_downloader.py
2727
pyinstaller --onefile --name="flatc_deserializer_batch" --console --icon=images\flatbuffers-batch-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_deserializer_batch.py
28-
- name: Move Deserializer and Downloader Executables from dist to root directory and delete dist directory
28+
- name: Install additional GUI requirements
29+
run: |
30+
pip install -r requirements_frontend.txt
31+
pip install pywinstyles
32+
- name: Run PyInstaller for GUI
33+
run: |
34+
set PYTHONOPTIMIZE=2
35+
pyinstaller --onefile --noconsole --name="flatc_deserializer_frontend" --console --hiddenimport pywinstyles --icon=images\flatbuffers-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_deserializer_frontend.py
36+
- name: Move Executables from dist to root directory and delete dist directory
2937
run: |
3038
move dist\flatc_deserializer.exe .
3139
move dist\flatc_downloader.exe .
3240
move dist\flatc_deserializer_batch.exe .
41+
move dist\flatc_deserializer_frontend.exe .
3342
rd /s /q dist
3443
shell: cmd
3544
- name: Create Automatic Windows Release
@@ -42,4 +51,5 @@ jobs:
4251
files: |
4352
flatc_deserializer.exe
4453
flatc_downloader.exe
45-
flatc_deserializer_batch.exe
54+
flatc_deserializer_batch.exe
55+
flatc_deserializer_frontend.exe

.github/workflows/build_executable_nuitka.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,29 @@ jobs:
5252
localization=localization
5353
images=images
5454
windows-icon-from-ico: images/flatbuffers-batch-logo-clean.png
55+
- name: Install additional GUI requirements
56+
run: |
57+
pip install -r requirements_frontend.txt
58+
pip install pywinstyles
59+
- name: Run Nuitka for GUI
60+
uses: Nuitka/Nuitka-Action@main
61+
with:
62+
nuitka-version: main
63+
script-name: flatc_deserializer_frontend.py
64+
mode: app
65+
windows-console-mode: disable
66+
enable-plugins: tk-inter
67+
include-package: pywinstyles
68+
include-data-dir: |
69+
localization=localization
70+
images=images
71+
windows-icon-from-ico: images/flatbuffers-logo-clean.png
5572
- name: Move Executables from build to root directory
5673
run: |
5774
move build\flatc_deserializer.exe .
5875
move build\flatc_deserializer_batch.exe .
5976
move build\flatc_downloader.exe .
77+
move build\flatc_deserializer_frontend.exe .
6078
rd /s /q build
6179
shell: cmd
6280
- name: Create Automatic Windows Release
@@ -69,4 +87,5 @@ jobs:
6987
files: |
7088
flatc_deserializer.exe
7189
flatc_deserializer_batch.exe
72-
flatc_downloader.exe
90+
flatc_downloader.exe
91+
flatc_deserializer_frontend.exe

README.MD

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Flatbuffers Deserializer
2-
Set of console tools for batch deserialization of Flatbuffers binary files using pre-defined schemas and downloading latest version of Flatbuffers schema compiler written in Python.
2+
Set of console tools and single combined GUI for the following:
3+
1. Downloading latest version of Flatbuffers schema compiler.
4+
2. Batch deserializing binary Flatbuffers files using imported schemas.
5+
36
## Requirements:
47
- [Python 3.11+](https://www.python.org/)
58
- [Pillow](https://pypi.org/project/pillow/)
69
- [tqdm](https://pypi.org/project/tqdm/)
710
- [i18nice[YAML]](https://pypi.org/project/i18nice/)
11+
### GUI only:
12+
- [customtkinter](https://pypi.org/project/customtkinter/)
13+
- [CTkMenuBar](https://pypi.org/project/CTkMenuBar/)
14+
- [CTkMessagebox](https://pypi.org/project/CTkMessagebox/)
815
## Latest Windows releases:
916
- [PyInstaller](https://github.com/Shararamosh/flatc_deserializer/releases/tag/latest)
1017
- [Nuitka](https://github.com/Shararamosh/flatc_deserializer/releases/tag/latest-nuitka)

flatc_deserializer_frontend.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def _create_src_binaries_frame(self, src_files_frame: ttk.LabelFrame) -> ttk.Lab
127127
src_binaries_frame.grid(row=0, column=0, padx=10, pady=10, sticky=NSEW)
128128
self.src_binaries_table = ttk.Treeview(src_binaries_frame, columns=("file", "file_size"),
129129
show="headings")
130-
self.src_binaries_table.heading("file", text=t("frontend.source_file_loc"))
130+
self.src_binaries_table.heading("file", text=t("frontend.file_loc"))
131131
self.src_binaries_table.heading("file_size", text=t("frontend.file_size"))
132132
src_binaries_frame.grid_rowconfigure(0, weight=1)
133133
src_binaries_frame.grid_rowconfigure(1, weight=1)
@@ -206,24 +206,20 @@ def _create_dest_binaries_frame(self, dest_files_frame: ttk.LabelFrame) -> ttk.L
206206
self.dest_binaries_table = ttk.Treeview(dest_binaries_frame,
207207
columns=("file", "result", "file_size"),
208208
show="headings", selectmode="browse")
209-
self.dest_binaries_table.heading("file", text=t("frontend.destination_file_loc"))
209+
self.dest_binaries_table.heading("file", text=t("frontend.file_loc"))
210210
self.dest_binaries_table.heading("result", text=t("frontend.result"))
211211
self.dest_binaries_table.heading("file_size", text=t("frontend.file_size"))
212212
dest_binaries_frame.grid_rowconfigure(0, weight=1)
213213
dest_binaries_frame.grid_rowconfigure(1, weight=1)
214214
dest_binaries_frame.grid_columnconfigure(0, weight=1)
215-
dest_binaries_frame.grid_columnconfigure(1, weight=1)
216215
dest_binaries_frame.grid_propagate(False)
217216
self.dest_binaries_table.grid(row=0, column=0, columnspan=2, padx=10, pady=10,
218217
sticky=NSEW)
219218
attempt_apply_dnd(self.dest_binaries_table.winfo_id(), self.on_binary_dropped)
220-
dest_binaries_change_dest_btn = CTkButton(dest_binaries_frame,
221-
text=t("frontend.button_change_dest"))
222-
dest_binaries_change_dest_btn.grid(row=1, column=0, padx=10, pady=10, sticky=EW)
223-
dest_binaries_change_dest_btn.configure(command=self.on_change_dest_click)
224-
dest_binaries_rename_btn = CTkButton(dest_binaries_frame,
225-
text=t("frontend.button_rename_file"))
226-
dest_binaries_rename_btn.grid(row=1, column=1, padx=10, pady=10, sticky=EW)
219+
dest_binaries_change_btn = CTkButton(dest_binaries_frame,
220+
text=t("frontend.button_change_dest"))
221+
dest_binaries_change_btn.grid(row=1, column=0, padx=10, pady=10, sticky=EW)
222+
dest_binaries_change_btn.configure(command=self.on_change_dest_click)
227223
return dest_binaries_frame
228224

229225
@staticmethod
@@ -323,10 +319,13 @@ def on_change_dest_click(self):
323319
for selected_item in selected_items:
324320
file_path = self.dest_binaries_table.set(selected_item, 0)
325321
file_dir, file_name = os.path.split(file_path)
326-
dest_dir = tkinter.filedialog.askdirectory(title=t("main.tkinter_output_select"),
327-
initialdir=file_dir)
328-
if os.path.isdir(dest_dir):
329-
new_file_path = os.path.abspath(os.path.join(dest_dir, file_name))
322+
new_file_path = tkinter.filedialog.asksaveasfilename(
323+
title=t("main.tkinter_output_select"),
324+
defaultextension=".json",
325+
initialdir=file_dir, initialfile=file_name,
326+
filetypes=[(t("main.json_filetype"), "*.json")])
327+
if new_file_path != "":
328+
new_file_path = os.path.abspath(os.path.splitext(new_file_path)[0] + ".json")
330329
self.dest_binaries_table.set(selected_item, 0, new_file_path)
331330
if os.path.isfile(new_file_path):
332331
self.dest_binaries_table.set(selected_item, 1,
@@ -336,6 +335,7 @@ def on_change_dest_click(self):
336335
os.path.getsize(new_file_path) / 1024))
337336
else:
338337
self.dest_binaries_table.set(selected_item, 1, "")
338+
self.dest_binaries_table.set(selected_item, 2, "")
339339
self.dest_binaries_table.update()
340340

341341
def on_binary_dropped(self, paths: list[str]):

flatc_funcs.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
22
Модуль, включающий в себя функции для работы с Flatbuffers (flatc.exe).
33
"""
4+
# pylint: disable=too-many-branches
45
import os
6+
import shutil
57
from json import loads
68
from logging import info
79
from subprocess import run, CalledProcessError
@@ -16,7 +18,7 @@ def deserialize(flatc_path: str, schema_path: str, binary_path: str, output_path
1618
:param flatc_path: Путь к компилятору схемы.
1719
:param schema_path: Путь к файлу схемы.
1820
:param binary_path: Путь к бинарному файлу.
19-
:param output_path: Путь к директории вывода.
21+
:param output_path: Путь к директории или файлу вывода.
2022
:param return_dict: Если True, возвращать словарь из прочитанного файла. Иначе - путь к файлу.
2123
:return: Десериализованный бинарный файл в виде словаря.
2224
"""
@@ -28,22 +30,28 @@ def deserialize(flatc_path: str, schema_path: str, binary_path: str, output_path
2830
binary_path = os.path.abspath(binary_path)
2931
binary_name = os.path.splitext(os.path.basename(binary_path))[0]
3032
output_path = os.path.abspath(output_path)
31-
json_path = os.path.abspath(os.path.join(output_path, binary_name + ".json"))
32-
previous_json_contents = None
33-
try:
34-
with open(json_path, "rb") as json_file:
35-
previous_json_contents = json_file.read()
36-
except OSError:
37-
pass
38-
args = [flatc_path]
3933
if output_path == "":
4034
output_path = os.path.dirname(binary_path)
35+
json_path = os.path.join(output_path, binary_name + ".json")
36+
elif os.path.splitext(output_path)[1].lower() == ".json":
37+
output_path = os.path.dirname(output_path)
38+
json_path = output_path
39+
elif os.path.isfile(output_path):
40+
return {} if return_dict else ""
41+
else:
42+
json_path = os.path.join(output_path, binary_name + ".json")
4143
output_path += os.sep
44+
args = [flatc_path]
4245
args += ["--raw-binary"]
4346
args += ["-o", output_path]
4447
args += ["--strict-json"]
4548
args += ["-t", schema_path]
4649
args += ["--", binary_path]
50+
output_json_path = os.path.join(output_path, binary_name + ".json")
51+
previous_json_contents = None
52+
if os.path.isfile(output_json_path):
53+
with open(output_json_path, "rb") as file:
54+
previous_json_contents = file.read()
4755
try:
4856
proc = run(args, shell=False, capture_output=True, text=True, check=True)
4957
except CalledProcessError as cpe:
@@ -54,9 +62,13 @@ def deserialize(flatc_path: str, schema_path: str, binary_path: str, output_path
5462
if proc.stdout is not None and proc.stdout != "":
5563
info(t("flatc_funcs.run_ok"), " ".join(args))
5664
info(proc.stdout)
57-
if not os.path.isfile(json_path):
65+
if not os.path.isfile(output_json_path):
5866
info(t("flatc_funcs.json_error"), binary_path)
5967
return {} if return_dict else ""
68+
if previous_json_contents is not None and not os.path.samefile(output_json_path, json_path):
69+
shutil.copy(output_json_path, json_path)
70+
with open(output_json_path, "wb") as file:
71+
file.write(previous_json_contents)
6072
try:
6173
with open(json_path, "rb") as json_file:
6274
current_json_contents = json_file.read()

localization/en_US/frontend.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ source_files: Source files
33
source_binaries: Source binary files
44
source_schemas: Source schemas
55
destination_files: Destination files
6-
destination_binaries: Destination binary files
6+
destination_binaries: Destination JSON files
77
deserialize: Deserialize
88
destination_options: Destination file options
99
button_add: Add...
1010
button_remove_selected: Remove selected
1111
button_remove_all: Remove all
1212
file_size: File size
13-
source_file_loc: Source file location
14-
destination_file_loc: Destination file location
13+
file_loc: File location
1514
result: Result
1615
size_kb: "%0.2f KBs"
1716
file_already_exists: File already exists
@@ -21,5 +20,4 @@ result_done: Done
2120
result_error: Error
2221
result_binary_not_found: Source file not found
2322
schema_not_found: Schema not found
24-
button_change_dest: Change destination directory
25-
button_rename_file: Rename selected file
23+
button_change_dest: Rename selected

localization/en_US/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ tkinter_flatc_select: Select schema compiler
22
exe_filetype: Windows Executable
33
tkinter_fbs_select: Select schema file
44
tkinter_fbs_multiple_select: Select schema files
5+
json_filetype: JSON
56
fbs_filetype: Flatbuffers schema
67
tkinter_binaries_select: Select binary files
78
flatc_binary_filetype: Binary Flatbuffers file

localization/ru_RU/frontend.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ source_files: Исходные файлы
33
source_binaries: Исходные бинарные файлы
44
source_schemas: Исходные схемы
55
destination_files: Файлы назначения
6-
destination_binaries: Бинарные файлы назначения
6+
destination_binaries: JSON-файлы назначения
77
deserialize: Десериализовать
88
destination_options: Опции файлов назначения
99
button_add: Добавить...
1010
button_remove_selected: Удалить выбранные
1111
button_remove_all: Удалить все
1212
file_size: Размер файла
13-
source_file_loc: Расположение исходного файла
14-
destination_file_loc: Расположение файла назначения
13+
file_loc: Расположение файла
1514
result: Результат
1615
size_kb: "%0.2f КБ"
1716
file_already_exists: Файл уже существует
@@ -21,5 +20,4 @@ result_done: Завершено
2120
result_error: Ошибка
2221
result_binary_not_found: Исходный файл не найден
2322
schema_not_found: Схема не найдена
24-
button_change_dest: Изменить директорию назначения
25-
button_rename_file: Переименовать выбранный файл
23+
button_change_dest: Переименовать выбранный

localization/ru_RU/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ tkinter_flatc_select: Выбор компилятора схемы
22
exe_filetype: Приложение Windows
33
tkinter_fbs_select: Выбор файла схемы
44
tkinter_fbs_multiple_select: Выбор файлов схем
5+
json_filetype: JSON
56
fbs_filetype: Схема Flatbuffers
67
tkinter_binaries_select: Выбор бинарных файлов
78
flatc_binary_filetype: Бинарный файл Flatbuffers

requirements.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@ pillow
22
tqdm
33
i18nice[YAML]
44
future
5-
argparse
6-
customtkinter
7-
CTkMenuBar
8-
pywinstyles
9-
CTkMessagebox
5+
argparse

requirements_frontend.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
customtkinter
2+
CTkMenuBar
3+
CTkMessagebox

0 commit comments

Comments
 (0)