Guest User

Code # 1

a guest
Mar 24th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. import pyperclip as pc # This enables getting string from clipboard
  2. import re
  3.  
  4. num=0
  5. u_string="u "
  6.  
  7. def find_num_of_colors(istr):
  8.     n=1
  9.     for c in istr:
  10.        if c==",":
  11.            n += 1
  12.     return n
  13.  
  14. def new_string(istr,line):
  15.     global num
  16.     global u_string
  17.     if istr in ["int","float","choice","button","text","bool"]:
  18.         num += 1
  19.         part_string = str(num) + "."
  20.         if istr=="button":
  21.             u_string += "\"{0}\"\\" + "\n"
  22.         else:
  23.             u_string += "\"{$"+str(num)+"}\"\\"+"\n"
  24.         new_string = line[:7] + part_string + line[7:]
  25.         return new_string
  26.     elif istr=="color":
  27.         if find_num_of_colors(line)==4:
  28.             u_string += "\"{$" + str(int(num+1)) +",$" + str(int(num+2)) + ",$" + str(int(num+3)) + ",$" + str(int(num+4)) + "}\"\\" + "\n"
  29.             part_string=str(int(num+1)) + "." + str(int(num+2)) + "." +str(int(num+3)) + "." + str(int(num+4)) + "."
  30.             num += 4
  31.             new_string=line[:7]+part_string+line[7:]
  32.             return new_string
  33.         else:
  34.             u_string += "\"{$" + str(int(num+1)) +",$" + str(int(num+2)) + ",$" + str(int(num+3))  + "}\"\\" + "\n"
  35.             part_string=str(int(num+1))+"."+str(int(num+2))+"."+str(int(num+3)) + "."
  36.             num += 3
  37.             new_string=line[:7]+part_string+line[7:]
  38.             return new_string
  39.     elif istr=="point":
  40.         u_string += "\"{$" + str(int(num + 1)) + ",$" + str(int(num + 2))  + "}\"\\" + "\n"
  41.         part_string = str(int(num + 1)) + "." + str(int(num + 2)) + "."
  42.         num += 2
  43.         new_string=line[:7]+part_string+line[7:]
  44.         return new_string
  45.     else:
  46.         return line
  47. def remove_number_and_period(line):
  48.     pos=8
  49.     iter=False
  50.     while True:
  51.         if line[pos].isdigit() or line[pos]=='.':
  52.             iter=True
  53.             pos += 1
  54.         else:
  55.             break
  56.     if iter:
  57.         return line[:7]+line[pos:]
  58.     else:
  59.         return line
  60.  
  61. between_these_char="\=(.*?)\("
  62.  
  63. gmic_str_paste=pc.paste()
  64. gmic_str=str(gmic_str_paste)
  65. lines=gmic_str.splitlines()
  66.  
  67. while True:
  68.     init_mode=input("""
  69.    Type in the one of the two characters in the set of two character at the left to use one of those mode?
  70.    0F. Remove Number and Period.
  71.    1T. Add Numbers and Period
  72.    Choice: """)
  73.     if init_mode=="0" or init_mode=="F":
  74.         mode=False
  75.         break
  76.     elif init_mode=="1" or init_mode=="T":
  77.         mode=True
  78.         break
  79.  
  80. if mode:
  81.     for line in lines:
  82.         try:
  83.             substring=re.search(between_these_char,line).group(1)
  84.         except AttributeError:
  85.             substring=re.search(between_these_char,line)
  86.         if substring is None:
  87.             print(line)
  88.             continue
  89.         else:
  90.             print(new_string(str(substring),line))
  91.  
  92.     print(u_string)
  93. else:
  94.     for line in lines:
  95.         print(remove_number_and_period(line))
Advertisement
Add Comment
Please, Sign In to add comment