Commits

Yuya Nishihara committed d3e71fb

qscilib: extract helper functions to read/write file

It will also be used by RejectsDialog.

  • Participants
  • Parent commits ef63fe2
  • Branches stable

Comments (0)

Files changed (1)

tortoisehg/hgqt/qscilib.py

             return True
     return False # Use spaces for indents default
 
+def readFile(editor, filename):
+    f = QFile(filename)
+    f.open(QIODevice.ReadOnly)
+    editor.read(f)
+    editor.setModified(False)
+
+def writeFile(editor, filename):
+    f = QFile(filename)
+    f.open(QIODevice.WriteOnly)
+    editor.write(f)
+
 def fileEditor(filename, **opts):
     'Open a simple modal file editing dialog'
     dialog = QDialog()
 
     ret = QDialog.Rejected
     try:
-        f = QFile(filename)
-        f.open(QIODevice.ReadOnly)
-        editor.read(f)
-        editor.setModified(False)
-
+        readFile(editor, filename)
         ret = dialog.exec_()
         if ret == QDialog.Accepted:
-            f = QFile(filename)
-            f.open(QIODevice.WriteOnly)
-            editor.write(f)
+            writeFile(editor, filename)
         s.setValue(geomname, dialog.saveGeometry())
     except EnvironmentError, e:
         qtlib.WarningMsgBox(_('Unable to read/write config file'),