Allow update_sprites to work on strict text only systems
This commit is contained in:
parent
3f20bdaaa2
commit
0558351a12
|
@ -102,14 +102,15 @@ def main():
|
||||||
parser.add_argument('--update_sprites', action='store_true', help='Update Sprite Database, then exit.')
|
parser.add_argument('--update_sprites', action='store_true', help='Update Sprite Database, then exit.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
args.music = not args.disablemusic
|
args.music = not args.disablemusic
|
||||||
if args.update_sprites:
|
|
||||||
run_sprite_update()
|
|
||||||
sys.exit()
|
|
||||||
# set up logger
|
# set up logger
|
||||||
loglevel = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}[
|
loglevel = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}[
|
||||||
args.loglevel]
|
args.loglevel]
|
||||||
logging.basicConfig(format='%(message)s', level=loglevel)
|
logging.basicConfig(format='%(message)s', level=loglevel)
|
||||||
|
|
||||||
|
if args.update_sprites:
|
||||||
|
run_sprite_update()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.isfile(args.rom):
|
if not os.path.isfile(args.rom):
|
||||||
adjustGUI()
|
adjustGUI()
|
||||||
else:
|
else:
|
||||||
|
@ -241,12 +242,16 @@ def adjustGUI():
|
||||||
def run_sprite_update():
|
def run_sprite_update():
|
||||||
import threading
|
import threading
|
||||||
done = threading.Event()
|
done = threading.Event()
|
||||||
|
try:
|
||||||
top = Tk()
|
top = Tk()
|
||||||
|
except:
|
||||||
|
task = BackgroundTaskProgressNullWindow(update_sprites, lambda successful, resultmessage: done.set())
|
||||||
|
else:
|
||||||
top.withdraw()
|
top.withdraw()
|
||||||
BackgroundTaskProgress(top, update_sprites, "Updating Sprites", lambda succesful, resultmessage: done.set())
|
task = BackgroundTaskProgress(top, update_sprites, "Updating Sprites", lambda succesful, resultmessage: done.set())
|
||||||
while not done.isSet():
|
while not done.isSet():
|
||||||
top.update()
|
task.do_events()
|
||||||
print("Done updating sprites")
|
logging.info("Done updating sprites")
|
||||||
|
|
||||||
|
|
||||||
def update_sprites(task, on_finish=None):
|
def update_sprites(task, on_finish=None):
|
||||||
|
@ -400,12 +405,39 @@ class BackgroundTaskProgress(BackgroundTask):
|
||||||
def update_status(self, text):
|
def update_status(self, text):
|
||||||
self.queue_event(lambda: self.label_var.set(text))
|
self.queue_event(lambda: self.label_var.set(text))
|
||||||
|
|
||||||
|
def do_events(self):
|
||||||
|
self.parent.update()
|
||||||
|
|
||||||
# only call this in an event callback
|
# only call this in an event callback
|
||||||
def close_window(self):
|
def close_window(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
|
||||||
|
|
||||||
|
class BackgroundTaskProgressNullWindow(BackgroundTask):
|
||||||
|
def __init__(self, code_to_run, *args):
|
||||||
|
super().__init__(None, code_to_run, *args)
|
||||||
|
|
||||||
|
def process_queue(self):
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
if not self.running:
|
||||||
|
return
|
||||||
|
event = self.queue.get_nowait()
|
||||||
|
event()
|
||||||
|
except queue.Empty:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def do_events(self):
|
||||||
|
self.process_queue()
|
||||||
|
|
||||||
|
def update_status(self, text):
|
||||||
|
self.queue_event(lambda: logging.info(text))
|
||||||
|
|
||||||
|
def close_window(self):
|
||||||
|
self.stop()
|
||||||
|
|
||||||
|
|
||||||
def get_rom_frame(parent=None):
|
def get_rom_frame(parent=None):
|
||||||
romFrame = Frame(parent)
|
romFrame = Frame(parent)
|
||||||
baseRomLabel = Label(romFrame, text='LttP Base Rom: ')
|
baseRomLabel = Label(romFrame, text='LttP Base Rom: ')
|
||||||
|
|
|
@ -10,6 +10,7 @@ def update_sprites_lttp():
|
||||||
from tkinter import Tk
|
from tkinter import Tk
|
||||||
from LttPAdjuster import get_image_for_sprite
|
from LttPAdjuster import get_image_for_sprite
|
||||||
from LttPAdjuster import BackgroundTaskProgress
|
from LttPAdjuster import BackgroundTaskProgress
|
||||||
|
from LttPAdjuster import BackgroundTaskProgressNullWindow
|
||||||
from LttPAdjuster import update_sprites
|
from LttPAdjuster import update_sprites
|
||||||
|
|
||||||
# Target directories
|
# Target directories
|
||||||
|
@ -19,11 +20,15 @@ def update_sprites_lttp():
|
||||||
os.makedirs(os.path.join(output_dir, "sprites"), exist_ok=True)
|
os.makedirs(os.path.join(output_dir, "sprites"), exist_ok=True)
|
||||||
# update sprites through gui.py's functions
|
# update sprites through gui.py's functions
|
||||||
done = threading.Event()
|
done = threading.Event()
|
||||||
|
try:
|
||||||
top = Tk()
|
top = Tk()
|
||||||
|
except:
|
||||||
|
task = BackgroundTaskProgressNullWindow(update_sprites, lambda successful, resultmessage: done.set())
|
||||||
|
else:
|
||||||
top.withdraw()
|
top.withdraw()
|
||||||
BackgroundTaskProgress(top, update_sprites, "Updating Sprites", lambda succesful, resultmessage: done.set())
|
task = BackgroundTaskProgress(top, update_sprites, "Updating Sprites", lambda succesful, resultmessage: done.set())
|
||||||
while not done.isSet():
|
while not done.isSet():
|
||||||
top.update()
|
task.do_events()
|
||||||
|
|
||||||
spriteData = []
|
spriteData = []
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue