bulk bmp import/export
This commit is contained in:
@@ -69,12 +69,12 @@ class App(ttk.Frame):
|
|||||||
"Bulk .bmp Import...",
|
"Bulk .bmp Import...",
|
||||||
"_bmp_import_all",
|
"_bmp_import_all",
|
||||||
MenuEntryType.NEED_FILE,
|
MenuEntryType.NEED_FILE,
|
||||||
), # TODO _bmp_import_all
|
),
|
||||||
(
|
(
|
||||||
"Export All To .bmp...",
|
"Export All To .bmp...",
|
||||||
"_bmp_export_all",
|
"_bmp_export_all",
|
||||||
MenuEntryType.NEED_FILE,
|
MenuEntryType.NEED_FILE,
|
||||||
), # TODO _bmp_export_all
|
),
|
||||||
("", "", MenuEntryType.SEPARATOR),
|
("", "", MenuEntryType.SEPARATOR),
|
||||||
(
|
(
|
||||||
"Import .bmp Into Image...",
|
"Import .bmp Into Image...",
|
||||||
@@ -268,6 +268,30 @@ class App(ttk.Frame):
|
|||||||
def _image_delete(self) -> None:
|
def _image_delete(self) -> None:
|
||||||
self.explorer.delete()
|
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:
|
def _bmp_import_image(self) -> None:
|
||||||
path = filedialog.askopenfilename(
|
path = filedialog.askopenfilename(
|
||||||
filetypes=Bitmap.FILE_TYPES,
|
filetypes=Bitmap.FILE_TYPES,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import List
|
from typing import List, Optional
|
||||||
import re
|
import re
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
@@ -25,6 +25,12 @@ class File:
|
|||||||
def modified(self) -> bool:
|
def modified(self) -> bool:
|
||||||
return any(image.modified for image in self.images)
|
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]:
|
def __read_file(self) -> List[Image]:
|
||||||
images = []
|
images = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user