Added Export function

Removed useless input :(
This commit is contained in:
Arne van Iterson 2023-09-27 14:20:20 +02:00
parent 4331f3b090
commit dcd4411fbd
3 changed files with 25 additions and 5 deletions

View File

@ -1,4 +1,5 @@
{
"path": "",
"out": "",
"size": 750
}

View File

@ -192,7 +192,7 @@
</child>
<child>
<object class="ttk.Button" id="button3">
<property name="text" translatable="yes">Useless button</property>
<property name="text" translatable="yes">Export PNG</property>
<bind sequence="&lt;ButtonPress&gt;" handler="apply" add="" />
<layout manager="grid">
<property name="column">2</property>
@ -215,7 +215,7 @@
</child>
<child>
<object class="ttk.Label" id="label1">
<property name="text" translatable="yes">Useless imput</property>
<property name="text" translatable="yes">Export Image by ID</property>
<layout manager="grid">
<property name="column">1</property>
<property name="columnspan">2</property>
@ -228,8 +228,10 @@
<property name="height">15</property>
<property name="pady">0</property>
<property name="selectborderwidth">4</property>
<property name="setgrid">false</property>
<property name="state">disabled</property>
<property name="text" translatable="yes">Image metadata should appear here</property>
<property name="takefocus">true</property>
<property name="text" translatable="yes">Image IDs should appear here</property>
<property name="width">25</property>
<property name="wrap">word</property>
<layout manager="grid">

View File

@ -10,6 +10,8 @@ import time
import matplotlib.pyplot as plt
import json
from helpers.statistics import imgStats
import datetime
import os
## UI config load
PROJECT_PATH = pathlib.Path(__file__).parent
@ -97,11 +99,25 @@ class MainApp:
'''
Export current dataset
'''
# Get export settings
img_arr = self.tk_imgs
img_id = self.export_id.get()
path = config_json["out"]
if (img_id >= 0 and img_id < len(img_arr)):
print("export")
if (img_id >= 0 and img_id < len(img_arr)):
# Create file
now = datetime.datetime.now()
new_file_name = F"{now.strftime('%Y-%m-%dT%H.%M.%S')}-id{img_id}.png"
# Put data
file_path = pathlib.Path(path, new_file_name)
# print(file_path)
imgpil = ImageTk.getimage(self.tk_imgs[img_id])
imgpil.save(file_path, "PNG" )
imgpil.close()
print(f"Exported Image ID {img_id} to {os.path.join(path, new_file_name)}")
else:
print("Nothing to export!")
@ -206,6 +222,7 @@ class MainApp:
def update(self, event=None):
path = self.img_path.get()
# print(path)
if path != None and path != "":
# Get all images at current path