mirror of
https://github.com/lalbornoz/roar.git
synced 2024-12-22 20:36:37 +00:00
libroar/RoarAssetsWindow.py:{_importFiles, on{Load,Save}List,__init__}(): {pass,receive} lastDir {before,after} wx.FileDialog()s.
libroar/RoarCanvasCommandsFile.py:{_importFile,canvasExportAs{Ansi,Png},SaveAs,__init__}(): {pass,receive} lastDir {before,after} wx.FileDialog()s.
This commit is contained in:
parent
67f2d11240
commit
c049181ceb
@ -33,11 +33,14 @@ class RoarAssetsWindow(GuiMiniFrame):
|
||||
def _importFiles(self, f, wildcard):
|
||||
resultList = []
|
||||
with wx.FileDialog(self, "Load...", os.getcwd(), "", wildcard, wx.FD_MULTIPLE | wx.FD_OPEN) as dialog:
|
||||
if self.lastDir != None:
|
||||
dialog.SetDirectory(self.lastDir)
|
||||
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||
resultList += [[False, "(cancelled)", None, None, None, None]]
|
||||
else:
|
||||
for pathName in dialog.GetPaths():
|
||||
resultList += [self._import(f, pathName)]
|
||||
self.lastDir = os.path.dirname(pathName)
|
||||
return resultList
|
||||
# }}}
|
||||
# {{{ _load_list(self, pathName)
|
||||
@ -242,9 +245,11 @@ class RoarAssetsWindow(GuiMiniFrame):
|
||||
def onLoadList(self, event):
|
||||
rc = True
|
||||
with wx.FileDialog(self, "Load from list...", os.getcwd(), "", "List files (*.lst)|*.lst|Text files (*.txt)|*.txt|All Files (*.*)|*.*", wx.FD_OPEN) as dialog:
|
||||
if self.lastDir != None:
|
||||
dialog.SetDirectory(self.lastDir)
|
||||
if dialog.ShowModal() != wx.ID_CANCEL:
|
||||
pathName = dialog.GetPath()
|
||||
self._load_list(pathName)
|
||||
pathName = dialog.GetPath(); self.lastDir = os.path.dirname(pathName);
|
||||
self._load_list(pathName)
|
||||
# }}}
|
||||
# {{{ onRemove(self, event)
|
||||
def onRemove(self, event):
|
||||
@ -271,8 +276,11 @@ class RoarAssetsWindow(GuiMiniFrame):
|
||||
rc = True
|
||||
if len(self.canvasList):
|
||||
with wx.FileDialog(self, "Save as list...", os.getcwd(), "", "List files (*.lst)|*.lst|Text files (*.txt)|*.txt|All Files (*.*)|*.*", wx.FD_SAVE) as dialog:
|
||||
if self.lastDir != None:
|
||||
dialog.SetDirectory(self.lastDir)
|
||||
if dialog.ShowModal() != wx.ID_CANCEL:
|
||||
with open(dialog.GetPath(), "w") as fileObject:
|
||||
pathName = dialog.GetPath(); self.lastDir = os.path.dirname(pathName);
|
||||
with open(pathName, "w") as fileObject:
|
||||
for pathName in [self.canvasList[k][1] for k in self.canvasList.keys()]:
|
||||
print(pathName, file=fileObject)
|
||||
rc = True
|
||||
@ -289,7 +297,7 @@ class RoarAssetsWindow(GuiMiniFrame):
|
||||
if pos == None:
|
||||
parentRect = parent.GetScreenRect(); pos = (parentRect.x + parentRect.width, parentRect.y);
|
||||
super().__init__(parent, size, title, pos=pos)
|
||||
self.backend, self.canvasList = backend((0, 0), cellSize), {}
|
||||
self.backend, self.canvasList, self.lastDir = backend((0, 0), cellSize), {}, None
|
||||
self.cellSize, self.currentIndex, self.leftDown, self.parent, self.scrollFlag = cellSize, None, False, parent, False
|
||||
self.Bind(wx.EVT_CHAR, self.onChar)
|
||||
|
||||
|
@ -44,10 +44,13 @@ class RoarCanvasCommandsFile():
|
||||
# {{{ _importFile(self, f, newDirty, wildcard)
|
||||
def _importFile(self, f, newDirty, wildcard):
|
||||
with wx.FileDialog(self.parentCanvas, "Open", os.getcwd(), "", wildcard, wx.FD_OPEN) as dialog:
|
||||
if self.lastDir != None:
|
||||
dialog.SetDirectory(self.lastDir)
|
||||
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||
return False
|
||||
elif self._promptSaveChanges():
|
||||
return self._import(f, newDirty, dialog.GetPath())
|
||||
pathName = dialog.GetPath(); self.lastDir = os.path.dirname(pathName);
|
||||
return self._import(f, newDirty, pathName)
|
||||
# }}}
|
||||
# {{{ _promptSaveChanges(self)
|
||||
def _promptSaveChanges(self):
|
||||
@ -77,10 +80,12 @@ class RoarCanvasCommandsFile():
|
||||
@GuiCommandDecorator("Export as ANSI...", "Export as ANSI...", None, None, None)
|
||||
def canvasExportAsAnsi(self, event):
|
||||
with wx.FileDialog(self.parentFrame, "Save As...", os.getcwd(), "", "ANSI files (*.ans;*.txt)|*.ans;*.txt|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
|
||||
if self.lastDir != None:
|
||||
dialog.SetDirectory(self.lastDir)
|
||||
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||
return False
|
||||
else:
|
||||
outPathName = dialog.GetPath()
|
||||
outPathName = dialog.GetPath(); self.lastDir = os.path.dirname(outPathName);
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||
with open(outPathName, "w", encoding="utf-8") as outFile:
|
||||
self.parentCanvas.canvas.exportStore.exportAnsiFile(self.parentCanvas.canvas.map, self.parentCanvas.canvas.size, outFile)
|
||||
@ -91,10 +96,12 @@ class RoarCanvasCommandsFile():
|
||||
@GuiCommandDecorator("Export as PNG...", "Export as PN&G...", None, None, None)
|
||||
def canvasExportAsPng(self, event):
|
||||
with wx.FileDialog(self.parentFrame, "Save As...", os.getcwd(), "", "PNG (*.png)|*.png|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
|
||||
if self.lastDir != None:
|
||||
dialog.SetDirectory(self.lastDir)
|
||||
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||
return False
|
||||
else:
|
||||
outPathName = dialog.GetPath()
|
||||
outPathName = dialog.GetPath(); self.lastDir = os.path.dirname(outPathName);
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||
self.parentCanvas.canvas.exportStore.exportBitmapToPngFile(self.parentCanvas.backend.canvasBitmap, outPathName, wx.BITMAP_TYPE_PNG)
|
||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
||||
@ -214,17 +221,19 @@ class RoarCanvasCommandsFile():
|
||||
@GuiCommandDecorator("Save As...", "Save &As...", ["", wx.ART_FILE_SAVE_AS], None, None)
|
||||
def canvasSaveAs(self, event):
|
||||
with wx.FileDialog(self.parentCanvas, "Save As", os.getcwd(), "", "mIRC art files (*.txt)|*.txt|All Files (*.*)|*.*", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) as dialog:
|
||||
if self.lastDir != None:
|
||||
dialog.SetDirectory(self.lastDir)
|
||||
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||
return False
|
||||
else:
|
||||
self.canvasPathName = dialog.GetPath()
|
||||
self.canvasPathName = dialog.GetPath(); self.lastDir = os.path.dirname(self.canvasPathName);
|
||||
return self.canvasSave(event, newDirty=True)
|
||||
# }}}
|
||||
|
||||
#
|
||||
# __init__(self)
|
||||
def __init__(self):
|
||||
self.imgurApiKey = ImgurApiKey.imgurApiKey if haveImgurApiKey else None
|
||||
self.imgurApiKey, self.lastDir = ImgurApiKey.imgurApiKey if haveImgurApiKey else None, None
|
||||
self.menus = (
|
||||
("&File",
|
||||
self.canvasNew, self.canvasOpen, self.canvasSave, self.canvasSaveAs, NID_MENU_SEP,
|
||||
|
Loading…
Reference in New Issue
Block a user