From 5123a016e85c68fdcf8e765d57e892c87454ee8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sat, 14 Sep 2019 10:52:05 +0200 Subject: [PATCH] libroar/RoarAssetsWindow.py:{_load_list,onLoadList}(): split from onLoadList(). roar.py: optionally load assets list from argv[2]. --- libroar/RoarAssetsWindow.py | 82 +++++++++++++++++++------------------ roar.py | 4 +- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/libroar/RoarAssetsWindow.py b/libroar/RoarAssetsWindow.py index d5f15b3..1c12bc0 100644 --- a/libroar/RoarAssetsWindow.py +++ b/libroar/RoarAssetsWindow.py @@ -40,6 +40,48 @@ class RoarAssetsWindow(GuiMiniFrame): resultList += [self._import(f, pathName)] return resultList # }}} + # {{{ _load_list(self, pathName) + def _load_list(self, pathName): + try: + with open(pathName, "r") as fileObject: + try: + for line in fileObject.readlines(): + line = line.rstrip("\r\n") + if not os.path.isabs(line): + line = os.path.join(os.path.dirname(pathName), line) + def importmIRC(canvas, pathName): + rc, error = canvas.importStore.importTextFile(pathName) + return (rc, error, canvas.importStore.outMap, pathName, canvas.importStore.inSize) + rc, error, canvas, newMap, newPathName, newSize = self._import(importmIRC, line) + if rc: + self.currentIndex = self.listView.GetItemCount() + self.canvasList[self.currentIndex] = [canvas, newPathName] + self.listView.InsertItem(self.currentIndex, "") + idx = -1 + while True: + idx = self.listView.GetNextSelected(idx) + if idx != -1: + self.listView.Select(idx, on=0) + else: + break + self.listView.Select(self.currentIndex, on=1) + self.listView.SetFocus() + [self.listView.SetItem(self.currentIndex, col, label) for col, label in zip((0, 1), (os.path.basename(newPathName), "{}x{}".format(*newSize)))] + [self.listView.SetColumnWidth(col, wx.LIST_AUTOSIZE) for col in (0, 1)] + else: + with wx.MessageDialog(self, "Error: {}".format(error), "", wx.CANCEL | wx.OK | wx.OK_DEFAULT) as dialog: + dialogChoice = dialog.ShowModal() + if dialogChoice == wx.ID_CANCEL: + self.SetCursor(wx.Cursor(wx.NullCursor)); break; + except: + self.SetCursor(wx.Cursor(wx.NullCursor)) + with wx.MessageDialog(self, "Error: {}".format(str(sys.exc_info()[1])), "", wx.OK | wx.OK_DEFAULT) as dialog: + dialogChoice = dialog.ShowModal() + except FileNotFoundError as e: + self.SetCursor(wx.Cursor(wx.NullCursor)) + with wx.MessageDialog(self, "Error: {}".format(str(e)), "", wx.OK | wx.OK_DEFAULT) as dialog: + dialogChoice = dialog.ShowModal() + # }}} # {{{ _updateScrollBars(self) def _updateScrollBars(self): clientSize = self.panelCanvas.GetClientSize() @@ -201,46 +243,8 @@ class RoarAssetsWindow(GuiMiniFrame): 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 dialog.ShowModal() != wx.ID_CANCEL: - try: pathName = dialog.GetPath() - with open(pathName, "r") as fileObject: - try: - for line in fileObject.readlines(): - line = line.rstrip("\r\n") - if not os.path.isabs(line): - line = os.path.join(os.path.dirname(pathName), line) - def importmIRC(canvas, pathName): - rc, error = canvas.importStore.importTextFile(pathName) - return (rc, error, canvas.importStore.outMap, pathName, canvas.importStore.inSize) - rc, error, canvas, newMap, newPathName, newSize = self._import(importmIRC, line) - if rc: - self.currentIndex = self.listView.GetItemCount() - self.canvasList[self.currentIndex] = [canvas, newPathName] - self.listView.InsertItem(self.currentIndex, "") - idx = -1 - while True: - idx = self.listView.GetNextSelected(idx) - if idx != -1: - self.listView.Select(idx, on=0) - else: - break - self.listView.Select(self.currentIndex, on=1) - self.listView.SetFocus() - [self.listView.SetItem(self.currentIndex, col, label) for col, label in zip((0, 1), (os.path.basename(newPathName), "{}x{}".format(*newSize)))] - [self.listView.SetColumnWidth(col, wx.LIST_AUTOSIZE) for col in (0, 1)] - else: - with wx.MessageDialog(self, "Error: {}".format(error), "", wx.CANCEL | wx.OK | wx.OK_DEFAULT) as dialog: - dialogChoice = dialog.ShowModal() - if dialogChoice == wx.ID_CANCEL: - self.SetCursor(wx.Cursor(wx.NullCursor)); break; - except: - self.SetCursor(wx.Cursor(wx.NullCursor)) - with wx.MessageDialog(self, "Error: {}".format(str(sys.exc_info()[1])), "", wx.OK | wx.OK_DEFAULT) as dialog: - dialogChoice = dialog.ShowModal() - except FileNotFoundError as e: - self.SetCursor(wx.Cursor(wx.NullCursor)) - with wx.MessageDialog(self, "Error: {}".format(str(e)), "", wx.OK | wx.OK_DEFAULT) as dialog: - dialogChoice = dialog.ShowModal() + self._load_list(pathName) # }}} # {{{ onRemove(self, event) def onRemove(self, event): diff --git a/roar.py b/roar.py index aa9d3a3..f66cb1d 100755 --- a/roar.py +++ b/roar.py @@ -15,7 +15,9 @@ import wx # Entry point def main(*argv): wxApp, roarClient = wx.App(False), RoarClient(None) - if (len(argv) > 1) and (len(argv[1]) > 0): + if len(argv) >= 1: + if argv[2].endswith(".lst"): + roarClient.assetsWindow._load_list(argv[2]) roarClient.canvasPanel.commands.canvasPathName = argv[1] rc, error = roarClient.canvasPanel.canvas.importStore.importTextFile(argv[1]) if rc: