From 913836cac8f47508edbbb496f460f2f29ef9abbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauline=20Gom=C3=A9r?= Date: Sat, 29 Oct 2011 18:43:32 +0200 Subject: [PATCH] Add: Can open tarballs containing many files. --- core/reader.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/core/reader.py b/core/reader.py index 10d3fde..d0da0c7 100644 --- a/core/reader.py +++ b/core/reader.py @@ -365,12 +365,33 @@ class MainWindowReader(QtGui.QMainWindow, Ui_MainWindowReader): content = fp.read() fp.close() else: - content = unicode() - QtGui.QMessageBox.critical(self, 'Yomichan', 'Archives with more than one (1) file are not supported') + # Using index because of encoding difficulties + (index, ok) = self.selectItem([f.decode('utf-8') for f in files]) + if ok: + fp = tp.extractfile(files[index - 1]) + content = fp.read() + fp.close() + else: + content = unicode() else: with open(filename, 'rb') as fp: content = fp.read() return content + + def selectItem(self, list): + items = [self.formatQString(i, x) for i, x in enumerate(list)] + (item, ok) = QtGui.QInputDialog.getItem( + self, + 'Yomichan', + 'Select file to open:', + items, + current = 0, + editable=False) + (index, success) = item.split('.').first().toInt() + return (index, ok and success) + + def formatQString(self, index, item): + return QtCore.QString(str(index + 1) + '. ').append(QtCore.QString(item)) def closeFile(self): self.setWindowTitle('Yomichan')