forked from Deusdies/pythonbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-eightTutorial-QFileDialog-class.py
More file actions
60 lines (41 loc) · 1.43 KB
/
08-eightTutorial-QFileDialog-class.py
File metadata and controls
60 lines (41 loc) · 1.43 KB
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
from PySide.QtGui import *
from PySide.QtCore import *
import sys
__appname__ = "Eight Video"
class Program(QDialog):
def __init__(self, parent=None):
super(Program, self).__init__(parent)
openButton = QPushButton("Open")
saveButton = QPushButton("Save")
dirButton = QPushButton("Other")
closeButton = QPushButton("Close...")
self.connect(openButton, SIGNAL("clicked()"), self.open)
self.connect(saveButton, SIGNAL("clicked()"), self.save)
layout = QVBoxLayout()
layout.addWidget(openButton)
layout.addWidget(saveButton)
layout.addWidget(dirButton)
layout.addWidget(closeButton)
self.setLayout(layout)
def open(self):
dir = "."
fileObj = QFileDialog.getOpenFileName(self, __appname__ + " Open File Dialog", dir=dir, filter="Text files (*.txt)")
print fileObj
print type(fileObj)
fileName = fileObj[0]
file = open(fileName, "r")
read = file.read()
file.close()
print read
def save(self):
dir = "."
fileObj = QFileDialog.getSaveFileName(self, __appname__, dir=dir, filter="Text Files (*.txt)")
print fileObj
print type(fileObj)
contents = "Hello from http://py.bo.vc"
fileName = fileObj[0]
open(fileName, mode="w").write(contents)
app = QApplication(sys.argv)
form = Program()
form.show()
app.exec_()