mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 23:36:36 +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
3298e9925b
commit
f6afcd735a
@ -33,11 +33,14 @@ class RoarAssetsWindow(GuiMiniFrame):
|
|||||||
def _importFiles(self, f, wildcard):
|
def _importFiles(self, f, wildcard):
|
||||||
resultList = []
|
resultList = []
|
||||||
with wx.FileDialog(self, "Load...", os.getcwd(), "", wildcard, wx.FD_MULTIPLE | wx.FD_OPEN) as dialog:
|
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:
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||||
resultList += [[False, "(cancelled)", None, None, None, None]]
|
resultList += [[False, "(cancelled)", None, None, None, None]]
|
||||||
else:
|
else:
|
||||||
for pathName in dialog.GetPaths():
|
for pathName in dialog.GetPaths():
|
||||||
resultList += [self._import(f, pathName)]
|
resultList += [self._import(f, pathName)]
|
||||||
|
self.lastDir = os.path.dirname(pathName)
|
||||||
return resultList
|
return resultList
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _load_list(self, pathName)
|
# {{{ _load_list(self, pathName)
|
||||||
@ -242,9 +245,11 @@ class RoarAssetsWindow(GuiMiniFrame):
|
|||||||
def onLoadList(self, event):
|
def onLoadList(self, event):
|
||||||
rc = True
|
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:
|
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:
|
if dialog.ShowModal() != wx.ID_CANCEL:
|
||||||
pathName = dialog.GetPath()
|
pathName = dialog.GetPath(); self.lastDir = os.path.dirname(pathName);
|
||||||
self._load_list(pathName)
|
self._load_list(pathName)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onRemove(self, event)
|
# {{{ onRemove(self, event)
|
||||||
def onRemove(self, event):
|
def onRemove(self, event):
|
||||||
@ -271,8 +276,11 @@ class RoarAssetsWindow(GuiMiniFrame):
|
|||||||
rc = True
|
rc = True
|
||||||
if len(self.canvasList):
|
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:
|
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:
|
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()]:
|
for pathName in [self.canvasList[k][1] for k in self.canvasList.keys()]:
|
||||||
print(pathName, file=fileObject)
|
print(pathName, file=fileObject)
|
||||||
rc = True
|
rc = True
|
||||||
@ -289,7 +297,7 @@ class RoarAssetsWindow(GuiMiniFrame):
|
|||||||
if pos == None:
|
if pos == None:
|
||||||
parentRect = parent.GetScreenRect(); pos = (parentRect.x + parentRect.width, parentRect.y);
|
parentRect = parent.GetScreenRect(); pos = (parentRect.x + parentRect.width, parentRect.y);
|
||||||
super().__init__(parent, size, title, pos=pos)
|
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.cellSize, self.currentIndex, self.leftDown, self.parent, self.scrollFlag = cellSize, None, False, parent, False
|
||||||
self.Bind(wx.EVT_CHAR, self.onChar)
|
self.Bind(wx.EVT_CHAR, self.onChar)
|
||||||
|
|
||||||
|
@ -44,10 +44,13 @@ class RoarCanvasCommandsFile():
|
|||||||
# {{{ _importFile(self, f, newDirty, wildcard)
|
# {{{ _importFile(self, f, newDirty, wildcard)
|
||||||
def _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:
|
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:
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||||
return False
|
return False
|
||||||
elif self._promptSaveChanges():
|
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)
|
# {{{ _promptSaveChanges(self)
|
||||||
def _promptSaveChanges(self):
|
def _promptSaveChanges(self):
|
||||||
@ -77,10 +80,12 @@ class RoarCanvasCommandsFile():
|
|||||||
@GuiCommandDecorator("Export as ANSI...", "Export as ANSI...", None, None, None)
|
@GuiCommandDecorator("Export as ANSI...", "Export as ANSI...", None, None, None)
|
||||||
def canvasExportAsAnsi(self, event):
|
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:
|
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:
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
outPathName = dialog.GetPath()
|
outPathName = dialog.GetPath(); self.lastDir = os.path.dirname(outPathName);
|
||||||
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||||
with open(outPathName, "w", encoding="utf-8") as outFile:
|
with open(outPathName, "w", encoding="utf-8") as outFile:
|
||||||
self.parentCanvas.canvas.exportStore.exportAnsiFile(self.parentCanvas.canvas.map, self.parentCanvas.canvas.size, 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)
|
@GuiCommandDecorator("Export as PNG...", "Export as PN&G...", None, None, None)
|
||||||
def canvasExportAsPng(self, event):
|
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:
|
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:
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
outPathName = dialog.GetPath()
|
outPathName = dialog.GetPath(); self.lastDir = os.path.dirname(outPathName);
|
||||||
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
||||||
self.parentCanvas.canvas.exportStore.exportBitmapToPngFile(self.parentCanvas.backend.canvasBitmap, outPathName, wx.BITMAP_TYPE_PNG)
|
self.parentCanvas.canvas.exportStore.exportBitmapToPngFile(self.parentCanvas.backend.canvasBitmap, outPathName, wx.BITMAP_TYPE_PNG)
|
||||||
self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))
|
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)
|
@GuiCommandDecorator("Save As...", "Save &As...", ["", wx.ART_FILE_SAVE_AS], None, None)
|
||||||
def canvasSaveAs(self, event):
|
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:
|
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:
|
if dialog.ShowModal() == wx.ID_CANCEL:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.canvasPathName = dialog.GetPath()
|
self.canvasPathName = dialog.GetPath(); self.lastDir = os.path.dirname(self.canvasPathName);
|
||||||
return self.canvasSave(event, newDirty=True)
|
return self.canvasSave(event, newDirty=True)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
#
|
||||||
# __init__(self)
|
# __init__(self)
|
||||||
def __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 = (
|
self.menus = (
|
||||||
("&File",
|
("&File",
|
||||||
self.canvasNew, self.canvasOpen, self.canvasSave, self.canvasSaveAs, NID_MENU_SEP,
|
self.canvasNew, self.canvasOpen, self.canvasSave, self.canvasSaveAs, NID_MENU_SEP,
|
||||||
|
Loading…
Reference in New Issue
Block a user