Add: Can open tarballs containing many files.
This commit is contained in:
parent
dcbd8c661a
commit
913836cac8
@ -364,14 +364,35 @@ class MainWindowReader(QtGui.QMainWindow, Ui_MainWindowReader):
|
|||||||
fp = tp.extractfile(files[0])
|
fp = tp.extractfile(files[0])
|
||||||
content = fp.read()
|
content = fp.read()
|
||||||
fp.close()
|
fp.close()
|
||||||
|
else:
|
||||||
|
# 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:
|
else:
|
||||||
content = unicode()
|
content = unicode()
|
||||||
QtGui.QMessageBox.critical(self, 'Yomichan', 'Archives with more than one (1) file are not supported')
|
|
||||||
else:
|
else:
|
||||||
with open(filename, 'rb') as fp:
|
with open(filename, 'rb') as fp:
|
||||||
content = fp.read()
|
content = fp.read()
|
||||||
return content
|
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):
|
def closeFile(self):
|
||||||
self.setWindowTitle('Yomichan')
|
self.setWindowTitle('Yomichan')
|
||||||
self.textContent.setPlainText(unicode())
|
self.textContent.setPlainText(unicode())
|
||||||
|
Loading…
Reference in New Issue
Block a user