-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
36 lines (31 loc) · 1.05 KB
/
start.py
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
#testes iniciais com pyqt - Paulo Custodio
import sys
from PyQt4 import QtCore, QtGui
from edytor import Ui_notepad
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_notepad()
self.ui.setupUi(self)
# here we connect signals with our slots
QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"), self.file_dialog)
QtCore.QObject.connect(self.ui.save_button,QtCore.SIGNAL("clicked()"), self.file_save)
def file_dialog(self):
fd = QtGui.QFileDialog(self)
self.filename = fd.getOpenFileName()
from os.path import isfile
if isfile(self.filename):
import codecs
s = codecs.open(self.filename,'r','utf-8').read()
self.ui.editor_window.setPlainText(s)
def file_save(self):
from os.path import isfile
if isfile(self.filename):
file = open(self.filename, 'w')
file.write(self.ui.editor_window.toPlainText())
file.close()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())