bulk bmp import/export

This commit is contained in:
Klemek
2021-08-27 11:20:01 +02:00
parent 3c58b5c0c2
commit 9fdb029b06
2 changed files with 33 additions and 3 deletions
+26 -2
View File
@@ -69,12 +69,12 @@ class App(ttk.Frame):
"Bulk .bmp Import...",
"_bmp_import_all",
MenuEntryType.NEED_FILE,
), # TODO _bmp_import_all
),
(
"Export All To .bmp...",
"_bmp_export_all",
MenuEntryType.NEED_FILE,
), # TODO _bmp_export_all
),
("", "", MenuEntryType.SEPARATOR),
(
"Import .bmp Into Image...",
@@ -268,6 +268,30 @@ class App(ttk.Frame):
def _image_delete(self) -> None:
self.explorer.delete()
def _bmp_import_all(self) -> None:
paths = filedialog.askopenfilenames(
filetypes=Bitmap.FILE_TYPES,
defaultextension=Bitmap.FILE_TYPES,
)
if paths and len(paths) > 0:
for path in paths:
name = os.path.basename(path).rstrip(".bmp")
image = self.current_file.search(name)
if image is None:
image = Image(name, 20, 20, empty=True)
self.current_file.images += [image]
try:
image.import_bmp(path)
except BitmapError as e:
pass
self.update()
def _bmp_export_all(self) -> None:
dir_path = filedialog.askdirectory()
if dir_path:
for image in self.current_file.images:
image.export_bmp(os.path.join(dir_path, f"{image.name}.bmp"))
def _bmp_import_image(self) -> None:
path = filedialog.askopenfilename(
filetypes=Bitmap.FILE_TYPES,
+7 -1
View File
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional
import re
import os.path
@@ -25,6 +25,12 @@ class File:
def modified(self) -> bool:
return any(image.modified for image in self.images)
def search(self, name) -> Optional[Image]:
for image in self.images:
if image.name == name:
return image
return None
def __read_file(self) -> List[Image]:
images = []