首页 > 程序设计『Programing』 > UnGzip Data(PyQt4) By obaby

UnGzip Data(PyQt4) By obaby

 

Ungzip gziped data by python and PyQt4.

 
Source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
##############################
#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_())

原创文章,转载请注明: 转载自 火星信息安全研究院

本文标题: 《UnGzip Data(PyQt4) By obaby》

本文链接地址: http://h4ck.org.cn/2012/03/ungzip-datapyqt4-by-obaby/

  1. 还没有评论
评论提交中, 请稍候...

留言

可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks