Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyperclip as pc # This enables getting string from clipboard
- import re
- num=0
- u_string="u "
- def find_num_of_colors(istr):
- n=1
- for c in istr:
- if c==",":
- n += 1
- return n
- def new_string(istr,line):
- global num
- global u_string
- if istr in ["int","float","choice","button","text","bool"]:
- num += 1
- part_string = str(num) + "."
- if istr=="button":
- u_string += "\"{0}\"\\" + "\n"
- else:
- u_string += "\"{$"+str(num)+"}\"\\"+"\n"
- new_string = line[:7] + part_string + line[7:]
- return new_string
- elif istr=="color":
- if find_num_of_colors(line)==4:
- u_string += "\"{$" + str(int(num+1)) +",$" + str(int(num+2)) + ",$" + str(int(num+3)) + ",$" + str(int(num+4)) + "}\"\\" + "\n"
- part_string=str(int(num+1)) + "." + str(int(num+2)) + "." +str(int(num+3)) + "." + str(int(num+4)) + "."
- num += 4
- new_string=line[:7]+part_string+line[7:]
- return new_string
- else:
- u_string += "\"{$" + str(int(num+1)) +",$" + str(int(num+2)) + ",$" + str(int(num+3)) + "}\"\\" + "\n"
- part_string=str(int(num+1))+"."+str(int(num+2))+"."+str(int(num+3)) + "."
- num += 3
- new_string=line[:7]+part_string+line[7:]
- return new_string
- elif istr=="point":
- u_string += "\"{$" + str(int(num + 1)) + ",$" + str(int(num + 2)) + "}\"\\" + "\n"
- part_string = str(int(num + 1)) + "." + str(int(num + 2)) + "."
- num += 2
- new_string=line[:7]+part_string+line[7:]
- return new_string
- else:
- return line
- def remove_number_and_period(line):
- pos=8
- iter=False
- while True:
- if line[pos].isdigit() or line[pos]=='.':
- iter=True
- pos += 1
- else:
- break
- if iter:
- return line[:7]+line[pos:]
- else:
- return line
- between_these_char="\=(.*?)\("
- gmic_str_paste=pc.paste()
- gmic_str=str(gmic_str_paste)
- lines=gmic_str.splitlines()
- while True:
- init_mode=input("""
- Type in the one of the two characters in the set of two character at the left to use one of those mode?
- 0F. Remove Number and Period.
- 1T. Add Numbers and Period
- Choice: """)
- if init_mode=="0" or init_mode=="F":
- mode=False
- break
- elif init_mode=="1" or init_mode=="T":
- mode=True
- break
- if mode:
- for line in lines:
- try:
- substring=re.search(between_these_char,line).group(1)
- except AttributeError:
- substring=re.search(between_these_char,line)
- if substring is None:
- print(line)
- continue
- else:
- print(new_string(str(substring),line))
- print(u_string)
- else:
- for line in lines:
- print(remove_number_and_period(line))
Advertisement
Add Comment
Please, Sign In to add comment