Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/tautils.py
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt/tautils.py')
-rw-r--r--TurtleArt/tautils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py
index 676c4ca..c54c65f 100644
--- a/TurtleArt/tautils.py
+++ b/TurtleArt/tautils.py
@@ -24,6 +24,7 @@ import cairo
import pickle
import subprocess
import os
+import string
from gettext import gettext as _
try:
@@ -109,6 +110,23 @@ def strtype(x):
return False
+def increment_name(name):
+ ''' If name is of the form foo_2, change it to foo_3. Otherwise,
+ return name_2'''
+ if '_' in name:
+ parts = name.split('_')
+ try:
+ i = int(parts[-1])
+ i += 1
+ parts[-1] = str(i)
+ newname = string.join(parts, '_')
+ except ValueError:
+ newname = '%s_2' % (name)
+ else:
+ newname = '%s_2' % (name)
+ return newname
+
+
def magnitude(pos):
''' Calculate the magnitude of the distance between to blocks. '''
x, y = pos