Skip to content

Commit

Permalink
Merge pull request #1 from TejasIsCool/detached
Browse files Browse the repository at this point in the history
Update v1.3 Exe Compatiblity with PyInstaller
  • Loading branch information
TejasIsCool authored Feb 16, 2024
2 parents a2ce869 + cb5b958 commit 3432b5b
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .idea/mcIVASmaker.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
# PySimpleGui library: https://pypi.org/project/PySimpleGUI/
import os
import importlib.util

from src.logic import manage_events
from src.window import window as window_maker
import multiprocessing
import logging
from src.logger import configure_logging

if __name__ == "__main__":

configure_logging()
logging.info("This is the log console. Most events that take place will be shown here")

# Py Installer SPlash manager
if '_PYIBoot_SPLASH' in os.environ and importlib.util.find_spec("pyi_splash"):
import pyi_splash

pyi_splash.update_text('UI Loaded ...')
pyi_splash.close()
logging.info('Splash screen closed.')

# Enable Multiprocessing to work in executable form
multiprocessing.freeze_support()
logging.debug("Multiprocessing freeze_support enabled")

# Instantiate the window
window = window_maker.make_window()
logging.debug("Window instantiated")

# Manage all its events
manage_events.manage_events(window)
# Finish up by removing from the screen
window.close()
logging.warning("The Program has been closed!")

27 changes: 27 additions & 0 deletions src/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging
import time
import os


def configure_logging():
# Not using resource_path here, because I want it to be seen outside the executable
if not os.path.exists("./mcIVASMAKER_logs"):
os.makedirs("./mcIVASMAKER_logs")
logging.basicConfig(
filename=f"./mcIVASMAKER_logs/Log{time.strftime('%y_%m_%d-%H_%M_%S', time.localtime())}.log",
format="{asctime:s}::{name:s}_[{levelname:^8s}] - {message:s}",
datefmt='%Y/%m/%d %I:%M:%S%p',
style='{',
encoding='utf-8',
level=logging.DEBUG
)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
console.setFormatter(logging.Formatter(
"{asctime:s}::{name:s}_[{levelname:^8s}] - {message:s}",
style="{",
datefmt='%Y/%m/%d %I:%M:%S%p'
))
# add the handler to the root logger
logging.getLogger('').addHandler(console)

2 changes: 2 additions & 0 deletions src/logic/image_logic/image_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import List, Dict
import os
import mcschematic
import logging
logger = logging.getLogger(__name__)


# Convert an image, to what the user specified
Expand Down
5 changes: 3 additions & 2 deletions src/logic/image_logic/image_to_redstone_lamps.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from PIL import Image, ImageFile
import mcschematic
import numpy as np
from path_manager.pather import resource_path

ImageFile.LOAD_TRUNCATED_IMAGES = True

lit_lamp = Image.open("../assets/blocks/redstone_lamp_on.png")
lit_lamp = Image.open(resource_path("./assets/blocks/redstone_lamp_on.png"))
# noinspection PyTypeChecker
lit_lamp_np = np.array(lit_lamp.convert("RGB"))
unlit_lamp = Image.open("../assets/blocks/redstone_lamp.png")
unlit_lamp = Image.open(resource_path("./assets/blocks/redstone_lamp.png"))
# noinspection PyTypeChecker
unlit_lamp_np = np.array(unlit_lamp.convert("RGB"))

Expand Down
8 changes: 5 additions & 3 deletions src/logic/image_logic/img_to_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import numpy as np
from logic.image_logic.block_parser import block_parser
from PIL import Image, ImageFile
from path_manager.pather import resource_path
import os

ImageFile.LOAD_TRUNCATED_IMAGES = True

# Loading the pre-generated blocks color
path = "../assets/blocks/all_blocks_textures/"
with open("../assets/blocks/img_generator_code/out.json", "r") as f:
path = resource_path("./assets/blocks/all_blocks_textures/")
with open(resource_path("./assets/blocks/img_generator_code/out.json"), "r") as f:
blocks_data: List = list(json.load(f).items())

# Storing all the images in memory (as numpy arrays)
Expand All @@ -21,7 +23,7 @@
if block_side == "extra":
pass
else:
img = Image.open(path + block[1][block_side]['file']).convert("RGBA")
img = Image.open(os.path.join(path, block[1][block_side]['file'])).convert("RGBA")
# noinspection PyTypeChecker
blocks_img_np[block[0] + block_side] = np.array(img)

Expand Down
23 changes: 17 additions & 6 deletions src/logic/manage_image_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from logic.fileio.image_thumbnail import load_image_for_display, load_image_for_preview
from logic.image_logic.image_manager import manipulate_image
from io import BytesIO
from path_manager.pather import resource_path
import logging
logger = logging.getLogger(__name__)

img_info = {"path": "", "bytes": BytesIO(), "size": [0, 0], "img_size": [0, 0]}

Expand Down Expand Up @@ -193,22 +196,29 @@ def manage_img_tab(window, event, values):
details['side'] = values['-Img_Any_Side-'].lower()
# Setting the correct output path if unspecified
if values['-Output_Path-'] == "":
scriptDir = os.path.dirname(__file__)
if "Schematic" in img_type:
file_end = ".schem"
else:
file_end = ".png"
output = os.path.join(
scriptDir,
f"../../outputs/output{time.strftime('%y_%m_%d-%H_%M_%S', time.localtime())}{file_end}"
)
output = os.path.normpath(output)
if not os.path.exists("./mcIVASMAKER_output"):
os.makedirs("./mcIVASMAKER_output")
output = f"./mcIVASMAKER_output/output{time.strftime('%y_%m_%d-%H_%M_%S', time.localtime())}{file_end}"
else:
output = values['-Output_Path-']

details['brightness'] = values['-Image_Brightness-']
details['place_redstone_blocks'] = values['-Img_Lamps_Schem_Check-']

logger.info("Image Conversion")
logger.debug("Video Details:")
logger.debug("FilePath: " + img_info['path'])
logger.debug("Output Path: " + output)
logger.debug("Manupilations: " + img_type)
logger.debug(f"Crop: {all_crop}")
logger.debug(f"Scale: {scale}")
logger.debug(f"Details: {details}")


iteration = 0
progress_size = 0
# manipulate_image is a generator, so we can update the progress more easily
Expand All @@ -234,6 +244,7 @@ def manage_img_tab(window, event, values):
"Saving..", 1, 1, no_button=True, no_titlebar=True, orientation='horizontal',
)
sg.popup_auto_close("Done!", "Done!", auto_close_duration=4)
logger.info("Done Image!")
continue
iteration += 1
sg.one_line_progress_meter(
Expand Down
13 changes: 7 additions & 6 deletions src/logic/manage_video_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
from logic.fileio.file_verifier import check_file_exists
from logic.vid_logic.ffmpeg_manager import get_resolution, get_frame_count
from logic.vid_logic.vid_manager import vid_manager
from path_manager.pather import resource_path

# Loads up the progress animation
IMAGES = []
frame_count = 0
for i in range(60):
img = Image.open(f"../assets/gifs/vid_progress/{i}.png")
img = Image.open(resource_path(f"./assets/gifs/vid_progress/{i}.png"))
img = img.resize((50, 50))
with BytesIO() as out:
img.save(out, format="PNG")
Expand Down Expand Up @@ -166,11 +167,9 @@ def manage_vid_tab(window, event, values):
filepath = vid_info['path']
# Setting the correct output location
if values['-Vid_Output_Path-'] == "":
scriptDir = os.path.dirname(__file__)
output = os.path.join(scriptDir,
f"../../outputs/output{time.strftime('%y_%m_%d-%H_%M_%S', time.localtime())}.mp4"
)
output = os.path.normpath(output)
if not os.path.exists("./mcIVASMAKER_output"):
os.makedirs("./mcIVASMAKER_output")
output = f"./mcIVASMAKER_output/output{time.strftime('%y_%m_%d-%H_%M_%S', time.localtime())}.mp4"
else:
output = values['-Vid_Output_Path-']

Expand All @@ -195,6 +194,8 @@ def manage_vid_tab(window, event, values):
# Update the progress meter
if event[1] == '-Image_Count-':
img_count = values[event]
if event[1] == '-Reset_Images_Done-':
images_done = 0
if event[1] == "-Image_Done-":
images_done += 1
progress = images_done / img_count * 100
Expand Down
23 changes: 10 additions & 13 deletions src/logic/vid_logic/ffmpeg_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
import os
import subprocess
from typing import Tuple

from path_manager.pather import resource_path
import ffmpeg

scriptDir = os.path.dirname(__file__)
assets_path = os.path.join(scriptDir,
f"../../../assets/cache/"
)
assets_path = os.path.normpath(assets_path)
assets_path = resource_path(f"./assets/cache/")

# The cache folders
vid_cache_folder_jpg = assets_path + "\\img_cache_jpg\\"
vid_cache_folder_png = assets_path + "\\img_cache_png\\"
vid_cache_folder_mp3 = assets_path + "\\audio_cache\\"
vid_cache_folder_jpg = os.path.normpath(os.path.join(assets_path, "./img_cache_jpg/"))
vid_cache_folder_png = os.path.normpath(os.path.join(assets_path, "./img_cache_png/"))
vid_cache_folder_m4a = os.path.normpath(os.path.join(assets_path, "./audio_cache/"))

vid_processed_folder = assets_path + "\\img_process_cache\\"
vid_processed_folder = os.path.normpath(os.path.join(assets_path, "./img_process_cache./"))


# Runs ffmpeg in a subprocess
Expand Down Expand Up @@ -47,7 +43,7 @@ def vid_to_img(vid_path: str, frame_rate: int, cache_folder: str):
extension = "jpg"
else:
extension = "png"
return ffmpeg_runner(f'-i "{vid_path}" -r {frame_rate} "{cache_folder}file%01d.{extension}"')
return ffmpeg_runner(f'-i "{vid_path}" -r {frame_rate} "{os.path.join(cache_folder,"file%01d."+extension)}"')


# Vid to images: Unused
Expand All @@ -59,8 +55,9 @@ def vid_to_img_single(vid_path: str, frame_rate: int, cache_folder: str):
number_of_frames = get_frame_count(vid_path, frame_rate)
for frame_number in range(number_of_frames):
frame_time = frame_number * 1 / frame_rate
ffmpeg_runner(f'-ss {frame_time} -i "{vid_path}" -vframes 1 {cache_folder}file{frame_number}.{extension}')
ffmpeg_runner(f'-ss {frame_time} -i "{vid_path}" '
f'-vframes 1 {os.path.join(cache_folder,"file"+str(frame_number)+"."+extension)}')


def vid_to_audio(vid_path: str):
out = ffmpeg_runner(f'-i "{vid_path}" -q:a 0 -map a "{vid_cache_folder_mp3}audio.m4a"')
out = ffmpeg_runner(f'-i "{vid_path}" -q:a 0 -map a "{os.path.join(vid_cache_folder_m4a,"audio.m4a")}"')
Loading

0 comments on commit 3432b5b

Please sign in to comment.