瀏覽代碼

pythonlib: implement percent() as wrapper for `g.message -p`

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42148 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 年之前
父節點
當前提交
9e2d915738
共有 1 個文件被更改,包括 19 次插入0 次删除
  1. 19 0
      lib/python/core.py

+ 19 - 0
lib/python/core.py

@@ -311,6 +311,25 @@ def info(msg):
     """
     message(msg, flag = 'i')
 
+def percent(i, n, s):
+    """!Display a progress info message using g.message -p
+    
+    @code
+    message(_("Percent complete..."))
+    n = 100
+    for i in range(n):
+        percent(i, n, 1)
+    percent(1, 1, 1)
+    @endcode
+    
+    @param i current item
+    @param n total number of items
+    @param s increment size
+    
+    @return g.message's exit code
+    """
+    message("%d %d %d" % (i, n, s), flag = 'p')
+
 def warning(msg):
     """!Display a warning message using g.message -w