Ungzip gziped data by python and PyQt4.
Source code:
##############################
#ungzip data by obaby
#2012.03.09
##############################
import sys
from PyQt4 import QtGui, QtCore
import sys
import gzip
import StringIO
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.resize(500, 350)
self.setWindowTitle('UnGzip Data(PyQt4) By obaby')
exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self)
exit.setShortcut('Ctrl+Q')
exit.setStatusTip('Exit application')
self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
open = QtGui.QAction(QtGui.QIcon('icons/open.png'), 'Open', self)
open.setShortcut('Ctrl+O')
open.setStatusTip('Open Gziped file to ungzip.')
open.triggered.connect(self.FileOpenDialog)
save = QtGui.QAction(QtGui.QIcon('icons/save.png'), 'Save', self)
save.setShortcut('Ctrl+S')
save.setStatusTip('Save Ungziped data to file.')
save.triggered.connect(self.FileSaveDialog)
help = QtGui.QAction(QtGui.QIcon('icons/help.png'), 'Help', self)
help.setShortcut('Ctrl+H')
help.triggered.connect(self.HelpDialog)
self.statusBar().showMessage('Status:ok')
menubar = self.menuBar()
file = menubar.addMenu('&File')
file.addAction(open)
file.addAction(save)
file.addAction(exit)
file = menubar.addMenu('&Help')
file.addAction(help)
def FileOpenDialog(self):
global file_content
textEdit = QtGui.QTextEdit()
self.setCentralWidget(textEdit)
fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '*.bin')
if fname <> '':
f = gzip.open(fname, 'rb')
try:
file_content = f.read()
textEdit.setText(file_content)
self.statusBar().showMessage("Status:"+fname+" Opened!")
except:
print('Wrong file Format!')
reply = QtGui.QMessageBox.question(self, 'Error', "Wrong file format,Plese select a gzip file!", QtGui.QMessageBox.Yes)
self.statusBar().showMessage("Status:"+fname+" is not a gziped file!")
def FileSaveDialog(self):
sname = QtGui.QFileDialog.getSaveFileName(self, 'Save file', '*.plist')
if sname <> '':
s = open(sname, 'w')
s.write(file_content)
s.close
def HelpDialog(self):
QtGui.QMessageBox.question(self, 'About', "Just use this app to ungzip gziped data!\n By obaby \n http://www.h4ck.ws", QtGui.QMessageBox.Yes)
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())