UnGzip Data(PyQt4) By obaby

 

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_())
☆版权☆

* 网站名称:obaby@mars
* 网址:https://lang.ma/
* 个性:https://oba.by/
* 本文标题: 《UnGzip Data(PyQt4) By obaby》
* 本文链接:https://baby.lc/2012/03/3838
* 短链接:https://oba.by/?p=3838
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


You may also like

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注