From 45216994616b8b8556818e034e3efcfd8074d9af Mon Sep 17 00:00:00 2001 From: Jason Ramboz Date: Mon, 1 Jul 2024 11:01:42 -0400 Subject: [PATCH] #17 Move beep to last in reset --- app.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 223b6aa..6c5ea6f 100644 --- a/app.py +++ b/app.py @@ -440,6 +440,7 @@ def _upload_default_files(self): self.log.info('Uploading default sound font.') files = glob.glob(os.path.join(resourcedir, 'OpenCore_OEM', '*.RAW')) files.sort() + files = self.move_beep_to_last(files) self.uc = Upload_Controller(files, self.sc, set_effects=False, reload_config=False, autoclose=True, parent=self) self.uc.finished_action = self._send_reset_cmd try: @@ -576,6 +577,20 @@ def r(obj: object): pd.show() self.threadpool.start(worker) + @staticmethod + def move_beep_to_last(files: list[str]) -> list[str]: + '''If the list of files contains 'BEEP.RAW', move it to last. Otherwise return the list unchanged.''' + log = logging.getLogger() + beep_files = [file for file in files if "BEEP.RAW" in file] + # if a BEEP.RAW is specified, move it to the end of the list. + # NXTs seem to do better if BEEP.RAW is the last file uploaded + if beep_files: + for file in beep_files: + log.debug(f'Moving BEEP file {file} to end of upload list.') + files.remove(file) + files.append(file) + return files + uc: Upload_Controller = None def upload_button_handler(self): # Get a list of files to upload. Can be one file or multiple files @@ -583,16 +598,10 @@ def upload_button_handler(self): if(files): files.sort() if self.anima_is_NXT(): - beep_files = [file for file in files if "BEEP.RAW" in file] - # if a BEEP.RAW is specified, move it to the end of the list. - # NXTs seem to do better if BEEP.RAW is the last file uploaded - if beep_files: - for file in beep_files: - self.log.debug(f'Moving BEEP file {file} to end of upload list.') - files.remove(file) - files.append(file) - else: - if 'BEEP.RAW' not in self.files_dict.keys(): + # move any BEEP.RAW files to last + files = self.move_beep_to_last(files) + if not files[-1].endswith('BEEP.RAW'): # if a BEEP.RAW is not included in the list to upload + if 'BEEP.RAW' not in self.files_dict.keys(): # and there's not already a BEEP.RAW on the saber self.log.info('NXT saber detected and no BEEP.RAW provided. Adding default BEEP.RAW.') files.append(os.path.join(resourcedir, 'OpenCore_OEM', 'BEEP.RAW')) self.log.debug(f'List of files to upload: {files}')