Skip to content

Commit

Permalink
impl: The export dialog will ask for file path of unnamed files
Browse files Browse the repository at this point in the history
  • Loading branch information
IoeCmcomc committed Feb 24, 2023
1 parent 32ca348 commit 4fa4b97
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,10 @@ def currentMax(self, value: int) -> None:

@property
def totalMax(self) -> int:
return self.builder.get_object('totalProgressBar')['maximum']
try:
return self.builder.get_object('totalProgressBar')['maximum']
except Exception:
return -1

@totalMax.setter
def totalMax(self, value: int) -> None:
Expand Down Expand Up @@ -1108,10 +1111,20 @@ async def work(dialog: ProgressDialog):
dialog.totalText.set(f"Exporting {i+1} / {len(indexes)} files")
dialog.currentProgress.set(0)
origPath = filePaths[i]
if not origPath:
origPath = asksaveasfilename(
filetypes=((self.fileExt+' files', self.fileExt),),
initialfile=path.basename(songsData[i].header.import_name).rsplit('.', 1)[0],
defaultextension=self.fileExt)
if not origPath:
if self.d.toplevel:
self.d.toplevel.after(1, self.d.destroy) # type: ignore
return
baseName = path.basename(origPath)
if baseName.endswith('.nbs'):
baseName = baseName[:-4]
baseName += self.fileExt
if not baseName.endswith(self.fileExt):
baseName += self.fileExt

filePath = ''
if not self.isFolderMode:
Expand All @@ -1121,8 +1134,9 @@ async def work(dialog: ProgressDialog):
try:
dialog.currentText.set(f"Current file: {filePath}")
# Prevent data from unintended changes
songData = deepcopy(songsData[i])
songData: NbsSong = deepcopy(songsData[i])
compactNotes(songData, True)
songData.correctData()
dialog.currentProgress.set(10) # 10%
await func(songData, filePath, dialog)
except CancelledError:
Expand Down

0 comments on commit 4fa4b97

Please sign in to comment.