浏览代码

pyedit: doc and replace print by Debug

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68410 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 9 年之前
父节点
当前提交
579e4ec21a
共有 1 个文件被更改,包括 21 次插入5 次删除
  1. 21 5
      gui/wxpython/gui_core/pyedit.py

+ 21 - 5
gui/wxpython/gui_core/pyedit.py

@@ -35,6 +35,7 @@ from core.menutree import MenuTreeModelBuilder
 from gui_core.menu import Menu
 from gui_core.menu import Menu
 from gui_core.toolbars import BaseToolbar, BaseIcons
 from gui_core.toolbars import BaseToolbar, BaseIcons
 from icons.icon import MetaIcon
 from icons.icon import MetaIcon
+from core.debug import Debug
 
 
 # TODO: add validation: call/import pep8 (error message if not available)
 # TODO: add validation: call/import pep8 (error message if not available)
 # TODO: run with parameters (alternatively, just use console or GUI)
 # TODO: run with parameters (alternatively, just use console or GUI)
@@ -390,6 +391,7 @@ class PyEditController(object):
         self.tempfile = False
         self.tempfile = False
 
 
     def OnOpen(self, event):
     def OnOpen(self, event):
+        """Handle open event but ask about replacing content first"""
         if self.CanReplaceContent('file'):
         if self.CanReplaceContent('file'):
             self.Open()
             self.Open()
 
 
@@ -398,8 +400,13 @@ class PyEditController(object):
         return len(self.body.GetText()) == 0
         return len(self.body.GetText()) == 0
 
 
     def IsContentValuable(self):
     def IsContentValuable(self):
-        print "empty:", self.IsEmpty(), "modified:", self.IsModified()
-        print "valuable?", not self.IsEmpty() and self.IsModified()
+        """Check if content of the editor is valuable to user
+
+        Used for example to check if content should be saved before closing.
+        The content is not valuable for example if it already saved in a file.
+        """
+        Debug.msg(2, "pyedit IsContentValuable? empty={}, modified={}",
+                  self.IsEmpty(), self.IsModified())
         return not self.IsEmpty() and self.IsModified()
         return not self.IsEmpty() and self.IsModified()
 
 
     def SetScriptTemplate(self, event):
     def SetScriptTemplate(self, event):
@@ -423,6 +430,16 @@ class PyEditController(object):
             self.body.SetText(module_error_handling_example())
             self.body.SetText(module_error_handling_example())
 
 
     def CanReplaceContent(self, by_message):
     def CanReplaceContent(self, by_message):
+        """Check with user if we can replace content by something else
+
+        Asks user if replacement is OK depending on the state of the editor.
+        Use before replacing all editor content by some other text.
+        
+        :param by_message: message used to ask user if it is OK to replace
+            the content with something else; special values are 'template',
+            'example' and 'file' which will use predefined messages, otherwise
+            a translatable, user visible string should be used.
+        """
         if by_message == 'template':
         if by_message == 'template':
             message = _("Replace the content by the template?")
             message = _("Replace the content by the template?")
         elif by_message == 'example':
         elif by_message == 'example':
@@ -431,8 +448,6 @@ class PyEditController(object):
             message = _("Replace the current content by the file content?")
             message = _("Replace the current content by the file content?")
         else:
         else:
             message = by_message
             message = by_message
-        print "CanReplaceContent:", self.IsEmpty(), self.IsModified()
-        print "CanNotReplaceContent?", not self.IsEmpty() and self.IsModified()
         if self.IsContentValuable():
         if self.IsContentValuable():
             dlg = wx.MessageDialog(
             dlg = wx.MessageDialog(
                 parent=self.guiparent, message=message,
                 parent=self.guiparent, message=message,
@@ -634,7 +649,8 @@ class PyEditFrame(wx.Frame):
     def _set_overwrite(self, overwrite):
     def _set_overwrite(self, overwrite):
         self.controller.overwrite = overwrite
         self.controller.overwrite = overwrite
 
 
-    overwrite = property(_get_overwrite, _set_overwrite)
+    overwrite = property(_get_overwrite, _set_overwrite,
+                         doc="Tells if overwrite should be used")
 
 
 
 
 def main():
 def main():