import sys
from PyQt4 import QtGui, QtCore
class Editor(QtGui.QWidget):
def __init__(self):
super(Editor, self).__init__()
self.initUI()
def initUI(self):
self.setGeometry(200, 100, 400, 300)
self.setWindowTitle('Editor App')
self.setWindowIcon(QtGui.QIcon('e.png'))
self.editor = QtGui.QTextEdit(self)
self.editor.setGeometry(10, 10, 380, 250)
self.openFile = QtGui.QPushButton('Open', self)
self.saveFile = QtGui.QPushButton('Save As Plain Text', self)
self.saveHTML = QtGui.QPushButton('Save As HTML', self)
self.pbExit = QtGui.QPushButton('Exit', self)
self.openFile.setGeometry(10, 270, 70, 20)
self.saveFile.setGeometry(85, 270, 120, 20)
self.saveHTML.setGeometry(210, 270, 100, 20)
self.pbExit.setGeometry(315, 270, 70, 20)
self.connect( self.openFile, QtCore.SIGNAL('clicked()'), self.openPlease )
self.connect( self.saveFile, QtCore.SIGNAL('clicked()'), self.savePlease )
self.connect( self.saveHTML, QtCore.SIGNAL('clicked()'), self.saveHtmlPlease )
self.connect( self.pbExit, QtCore.SIGNAL('clicked()'), QtGui.qApp, QtCore.SLOT('quit()'))
def openPlease(self):
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
fname = open(filename)
data = fname.read()
fname.close()
self.editor.setText(data)
def savePlease(self):
filename = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '.')
fname = open(filename, 'w')
fname.write(self.editor.toPlainText())
fname.close()
def saveHtmlPlease(self):
filename = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '.')
fname = open(filename, 'w')
fname.write(self.editor.toHtml())
fname.close()
app = QtGui.QApplication(sys.argv)
file = Editor()
file.show()
sys.exit(app.exec_())
from PyQt4 import QtGui, QtCore
class Editor(QtGui.QWidget):
def __init__(self):
super(Editor, self).__init__()
self.initUI()
def initUI(self):
self.setGeometry(200, 100, 400, 300)
self.setWindowTitle('Editor App')
self.setWindowIcon(QtGui.QIcon('e.png'))
self.editor = QtGui.QTextEdit(self)
self.editor.setGeometry(10, 10, 380, 250)
self.openFile = QtGui.QPushButton('Open', self)
self.saveFile = QtGui.QPushButton('Save As Plain Text', self)
self.saveHTML = QtGui.QPushButton('Save As HTML', self)
self.pbExit = QtGui.QPushButton('Exit', self)
self.openFile.setGeometry(10, 270, 70, 20)
self.saveFile.setGeometry(85, 270, 120, 20)
self.saveHTML.setGeometry(210, 270, 100, 20)
self.pbExit.setGeometry(315, 270, 70, 20)
self.connect( self.openFile, QtCore.SIGNAL('clicked()'), self.openPlease )
self.connect( self.saveFile, QtCore.SIGNAL('clicked()'), self.savePlease )
self.connect( self.saveHTML, QtCore.SIGNAL('clicked()'), self.saveHtmlPlease )
self.connect( self.pbExit, QtCore.SIGNAL('clicked()'), QtGui.qApp, QtCore.SLOT('quit()'))
def openPlease(self):
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
fname = open(filename)
data = fname.read()
fname.close()
self.editor.setText(data)
def savePlease(self):
filename = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '.')
fname = open(filename, 'w')
fname.write(self.editor.toPlainText())
fname.close()
def saveHtmlPlease(self):
filename = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '.')
fname = open(filename, 'w')
fname.write(self.editor.toHtml())
fname.close()
app = QtGui.QApplication(sys.argv)
file = Editor()
file.show()
sys.exit(app.exec_())
No comments:
Post a Comment