Source

python-hack-a-thon-1 / notepad / notepad.py

Full commit
from PyQt4 import QtCore, QtGui, uic

(form, base) = uic.loadUiType("mainwindow.ui")

class NotePad(form, base):
    encoding = 'utf-8'
    def __init__(self):
        super(NotePad, self).__init__()
        self.setupUi(self)
        self.filename = None

    @QtCore.pyqtSlot()
    def on_actionClose_triggered(self):
        self.close()

    @QtCore.pyqtSlot()
    def on_actionOpen_triggered(self):
        filename = QtGui.QFileDialog.getOpenFileName(self)
        if filename.isNull() or filename.isEmpty():
            return
        f = open(filename)
        self.textEdit.setPlainText(unicode(f.read(), self.encoding))
        f.close()
        self.filename = filename

import sys
def main():
    app = QtGui.QApplication(sys.argv)
    win = NotePad()
    win.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()