Code

GNU/Linux!
[inkscape.git] / share / extensions / text_randomcase.py
1 import chardataeffect, inkex, string
3 import random
5 class C(chardataeffect.CharDataEffect):
7   def process_chardata(self,text, line, par):
8     r = ""
9     a = 1
10     for i in range(len(text)):
11       c = text[i]
12       # bias the randomness towards inversion of the previous case:
13       if a > 0:
14         a = random.choice([-2,-1,1])
15       else:
16         a = random.choice([-1,1,2])
17       if a > 0 and c.isalpha():
18         r = r + c.upper()
19       elif a < 0 and c.isalpha():
20         r = r + c.lower()
21       else:
22         r = r + c
24     return r
26 c = C()
27 c.affect()