Commits

Atsushi Odagiri committed b598727

open file.

Comments (0)

Files changed (1)

notepad/notepad.py

 (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():