Best Python code snippet using ATX
origamifill.py
Source:origamifill.py
...19 layerPaperWhite.fill(WHITE_FILL)20 21 layerPaperBase = gimp.Layer(image, "paper base", 1000, 1000, RGB_IMAGE, 85, NORMAL_MODE)22 image.add_layer(layerPaperBase)23 gimp.set_foreground(generate_color_noise(colorBase[2]))24 layerPaperBase.fill(FOREGROUND_FILL)25 layerBase = gimp.Layer(image, "base", 1000, 1000, RGB_IMAGE, 100, NORMAL_MODE)26 layerBase.add_alpha() 27 image.add_layer(layerBase)28 layerBase.fill(TRANSPARENT_FILL)29 30 if (text_value == "crane"):31 create_crane(image, layerBase, colorBase)32 elif (text_value == "butterfly"):33 create_butterfly(image, layerBase, colorBase)34 elif (text_value == "iris"):35 create_iris(image, layerBase, colorBase)36 else:37 create_crane(image, layerBase, colorBase)38 39 # Merge all layers down40 pdb.gimp_selection_none(image)41 layerBase = image.merge_down(layerBase, 0)42 layerBase = image.merge_down(layerBase, 0)43 layerBase.name = "Origami Fill"44 45 image.undo_group_end()46 return47"""Returns list of 3 color bases from the layer based on provided int seed."""48def generate_color_base(image, layerColorPick, int_value):49 colorBase = [(50,50,50), (100,100,100), (150,150,150)]50 51 if (int_value % 4 == 0):52 colorBase[0] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/4, layerColorPick.height*1/4, False, True, 10)53 colorBase[1] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/2, layerColorPick.height*1/2, False, True, 10)54 colorBase[2] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*3/4, layerColorPick.height*3/4, False, True, 10)55 elif (int_value % 4 == 1):56 colorBase[0] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*3/4, layerColorPick.height*3/4, False, True, 10)57 colorBase[1] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/2, layerColorPick.height*1/2, False, True, 10)58 colorBase[2] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/4, layerColorPick.height*1/4, False, True, 10) 59 elif (int_value % 4 == 2):60 colorBase[0] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/3, layerColorPick.height*1/3, False, True, 10)61 colorBase[1] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*2/3, layerColorPick.height*1/3, False, True, 10)62 colorBase[2] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/2, layerColorPick.height*2/3, False, True, 10)63 elif (int_value % 4 == 3):64 colorBase[0] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/3, layerColorPick.height*2/3, False, True, 10)65 colorBase[1] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*2/3, layerColorPick.height*2/3, False, True, 10)66 colorBase[2] = pdb.gimp_image_pick_color(image, layerColorPick, layerColorPick.width*1/2, layerColorPick.height*1/3, False, True, 10)67 68 return colorBase69 70 71"""Returns a color tuple with a random delta noise applied to the provided color tuple"""72def generate_color_noise(color):73 sign = random.randint(0,1)74 sign = -1 if (sign == 0) else 175 delta = random.randint(25,50)76 newR = max(min(255, color[0] + sign*delta), 0)77 newG = max(min(255, color[1] + sign*random.randint(delta-10, delta+10)), 0)78 newB = max(min(255, color[2] + sign*random.randint(delta-10, delta+10)), 0)79 return (newR, newG, newB)80"""Creates a crane on the base layer"""81def create_crane(image, layerBase, colorBase):82 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 10, [0,0 , 750,250 , 1000,1000 , 250,750 , 0,0])83 gimp.set_foreground(generate_color_noise(colorBase[0]))84 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL) 85 86 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 10, [0,0 , 325,225 , 300,300 , 225,325 , 0,0])87 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 10, [1000,1000 , 1000-325,1000-225 , 1000-300,1000-300 , 1000-225,1000-325 , 1000,1000])88 gimp.set_foreground(colorBase[0])89 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)90 91 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 6, [0,1000 , 200,500 , 500,800 , 0,1000])92 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 6, [1000,0 , 800,500 , 500,200 , 1000,0])93 gimp.set_foreground(colorBase[1])94 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL) 95 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 8, [1000,1000 , 800,1000 , 850,850 , 1000,800])96 gimp.set_foreground(colorBase[2])97 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL) 98"""Creates a crane on the base layer"""99def create_butterfly(image, layerBase, colorBase):100 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 8, [0,1000 , 300,1000 , 300,900 , 0,900])101 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 8, [1000,1000 , 1000-300,1000 , 1000-300,900 , 1000,900])102 gimp.set_foreground(generate_color_noise(colorBase[1]))103 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)104 105 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 10, [0,0 , 160,240, 160,410, 0,500, 0,0])106 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 10, [1000,0 , 1000,500, 840,410, 840,240, 1000,0])107 gimp.set_foreground(colorBase[0])108 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)109 110 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 6, [0,500 , 200,700 , 0,1000])111 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 6, [1000,500 , 800,700 , 1000,1000])112 gimp.set_foreground(colorBase[1])113 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)114 115 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 8, [1000,0 , 840,240, 650,0, 1000,0])116 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 8, [0,0 , 350,0, 160,240, 0,0])117 gimp.set_foreground(colorBase[2])118 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)119 120 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 8, [350,350 , 650,350 , 650,650 , 350,650])121 gimp.set_foreground(generate_color_noise(colorBase[0]))122 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)123 124 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 6, [160,240 , 160,410 , 500,500])125 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 6, [1000-160,240 , 1000-160,410 , 500,500])126 gimp.set_foreground(generate_color_noise(colorBase[2]))127 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)128 129 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 8, [350,650 , 650,650 , 650,850 , 350,850])130 gimp.set_foreground(generate_color_noise(colorBase[1]))131 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)132 133"""Creates an iris flower on the base layer"""134def create_iris(image, layerBase, colorBase):135 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 6, [0,0 , 500,500 , 500,0])136 gimp.set_foreground(generate_color_noise(colorBase[2]))137 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)138 139 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 6, [1000,0 , 500,500 , 500,0])140 gimp.set_foreground(generate_color_noise(colorBase[2]))141 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)142 143 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 6, [500,1000 , 500,500 , 0,1000])144 gimp.set_foreground(generate_color_noise(colorBase[2]))145 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)146 147 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 6, [500,1000 , 500,500 , 1000,1000])148 gimp.set_foreground(generate_color_noise(colorBase[2]))149 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)150 151 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 8, [0,500 , 500,0 , 1000,500 , 500,1000])152 gimp.set_foreground(colorBase[0])153 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)154 155 pdb.gimp_image_select_polygon(image, CHANNEL_OP_REPLACE, 8, [0,0 , 350,150 , 500,500 , 150,350])156 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 8, [1000,0 , 1000-350,150 , 500,500 , 1000-150,350])157 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 8, [0,1000 , 350,1000-150 , 500,500 , 150,1000-350])158 pdb.gimp_image_select_polygon(image, CHANNEL_OP_ADD, 8, [1000,1000 , 1000-350,1000-150 , 500,500 , 1000-150,1000-350])159 gimp.set_foreground(colorBase[1])160 pdb.gimp_edit_fill(layerBase, FOREGROUND_FILL)161 162# This is the plugin registration function163register(164 "origami_fill", 165 "Origami Fill", 166 "Low-Poly Origami Fill",167 "Arpit Sheth & Justin Selig", 168 "Computing in the Arts @ Cornell University", 169 "May 2014",170 "<Image>/MyScripts/Origami Fill", 171 "*", 172 [173 (PF_STRING, 'origami_obj', 'Origami Object', 'crane'),...
JudgmentEntryAuto.py
Source:JudgmentEntryAuto.py
...23 """find a window whose title matches the wildcard regex"""24 self._handle = None25 win32gui.EnumWindows(self._window_enum_callback, wildcard)2627 def set_foreground(self):28 """put the window in the foreground"""29 win32gui.SetForegroundWindow(self._handle)303132w = WindowMgr()3334print("Begin CLS insertion, DO NOT TOUCH KEYBOARD OR MOUSE")35time.sleep(10)3637filebase = "enterjudgment"38dt = datetime.datetime.now()39tdate =(dt.strftime("%m%d%Y"))40fileext = ".txt"41fileloc = "\\\\cs_webserver\\C\\Inetpub\\wwwroot\\Oracle1\\Judgments\\EnteredJudgments\\"42#fileloc = "N:\EDI1\JudgmentEntry\Judgments\EnteredJudgments\\";43filename = filebase+tdate+fileext44fullfile = fileloc+filename45fcheck = 046version = 0;47workingfile = fullfile48workingfilename = filename49currentfile = fullfile50while fcheck ==0:51 if os.path.exists(workingfile):52 print(fullfile + ' exists')53 currentfile = workingfile54 currentfilename = workingfilename55 workingfile = fileloc+filebase+tdate+"_version"+format(version)+fileext56 workingfilename = filebase+tdate+"_version"+format(version)+fileext57 version = version+158 else:59 print(currentfile + " is the file to be inserted.")60 fcheck = 161if os.stat(currentfile).st_size == 0:62 print("File is empty. No insert into CLS needed.\nDeleting on exit. Close Window to cancel Delete before exit.\nExiting in 20 seconds.")63 time.sleep(23)64 os.remove(fullfile)65 sys.exit(0)6667time.sleep(20)68shell = win32com.client.Dispatch('WScript.Shell')69shell.Run('S:\\ny\\CLSINC\\WBWIN\\BRClient.exe')70time.sleep(7)7172shell.SendKeys("{Enter}", 0)73time.sleep(5.1)74print("Work Through Menus")75w.find_window_wildcard(".*CM-.*")76w.set_foreground()7778shell.SendKeys("F", 0)79shell.SendKeys("4", 0)80time.sleep(5.1)8182pass1 = "PMAN2"83for x in range(5): 84 shell.SendKeys(pass1[x], 0)85shell.SendKeys("{Enter}", 0)86time.sleep(5.1)8788w.find_window_wildcard(".*CM-.*")89w.set_foreground()90shell.SendKeys("2", 0)91shell.SendKeys("1", 0)92pass2 = "PEDI"93for x in range(4): 94 shell.SendKeys(pass2[x], 0)95shell.SendKeys("{Enter}", 0)96shell.SendKeys("{Enter}", 0)97shell.SendKeys("{Up}", 0)98shell.SendKeys("{Up}", 0)99time.sleep(5.1)100w.find_window_wildcard(".*Select EDI Type.*")101w.set_foreground()102shell.SendKeys("{Enter}", 0)103shell.SendKeys("1", 0)104shell.SendKeys("{Right}", 0)105locstr = "\\\\cs_webserver\\C\\Inetpub\\wwwroot\\Oracle1\\Judgments\\EnteredJudgments\\"106loclen = len(locstr)107for x in range(loclen): 108 shell.SendKeys(locstr[x],0)109shell.SendKeys("{Enter}", 0)110time.sleep(3.1)111112shell.SendKeys("{Enter}", 0)113time.sleep(5.1)114print("Entering Filename")115w.find_window_wildcard(".*Open.*")116w.set_foreground()117#filename = "test" #FOR TESTING ONLY!!118119filenamelen = len(currentfilename)120for x in range(filenamelen): 121 shell.SendKeys(currentfilename[x],0)122""" filename = "enterjudgment"123filenamelen = len(filename)124print("Inserting Data")125for x in range(filenamelen): 126 shell.SendKeys(filename[x],0)127dt = datetime.datetime.now()128tdate =(dt.strftime("%m%d%Y"))129w.find_window_wildcard(".*Open.*")130w.set_foreground()131for x in range(8): 132 shell.SendKeys(tdate[x], 0)133fileext = ".txt"134w.find_window_wildcard(".*Open.*")135w.set_foreground()136for x in range(4): 137 shell.SendKeys(fileext[x], 0) """138time.sleep(5.1)139140print("Inserting Data")141shell.SendKeys("{Enter}", 0)142time.sleep(5.1)143shell.SendKeys("{Enter}", 0)144time.sleep(5.1)145146shell.SendKeys("{Enter}", 0)147time.sleep(200)148w.find_window_wildcard(".*CM-.*")149w.set_foreground()150shell.SendKeys("{Esc}", 0)151shell.SendKeys("{Esc}", 0)152153print("Complete")154sys.exit(0)
...
NEW_JERSEY_JudgmentEntryAuto.py
Source:NEW_JERSEY_JudgmentEntryAuto.py
...23 """find a window whose title matches the wildcard regex"""24 self._handle = None25 win32gui.EnumWindows(self._window_enum_callback, wildcard)2627 def set_foreground(self):28 """put the window in the foreground"""29 win32gui.SetForegroundWindow(self._handle)303132w = WindowMgr()3334print("Begin CLS insertion, DO NOT TOUCH KEYBOARD OR MOUSE")35time.sleep(10)3637filebase = "enterjudgment_NJ"383940dt = datetime.datetime.now()41tdate =(dt.strftime("%m%d%Y"))42fileext = ".txt"4344fileloc = "\\\\cs_webserver\\C\\Inetpub\\wwwroot\\Oracle1\\Judgments\\NJ_EnteredJudgments\\"454647filename = filebase+tdate+fileext48fullfile = fileloc+filename49fcheck = 050version = 0;51workingfile = fullfile52workingfilename = filename53currentfile = fullfile54while fcheck ==0:55 if os.path.exists(workingfile):56 print(fullfile + ' exists')57 currentfile = workingfile58 currentfilename = workingfilename59 workingfile = fileloc+filebase+tdate+"_version"+format(version)+fileext60 workingfilename = filebase+tdate+"_version"+format(version)+fileext61 version = version+162 else:63 print(currentfile + " is the file to be inserted.")64 fcheck = 165if os.stat(currentfile).st_size == 0:66 print("File is empty. No insert into CLS needed.\nDeleting on exit. Close Window to cancel Delete before exit.\nExiting in 20 seconds.")67 time.sleep(23)68 os.remove(fullfile)69 sys.exit(0)7071time.sleep(20)72737475shell = win32com.client.Dispatch('WScript.Shell')76shell.Run('S:\\ny\\CLSINC\\WBWIN\\BRClient.exe')77time.sleep(7)7879shell.SendKeys("{Enter}", 0)80time.sleep(5.1)81print("Work Through Menus")82w.find_window_wildcard(".*CM-.*")83w.set_foreground()8485shell.SendKeys("F", 0)86shell.SendKeys("4", 0)87time.sleep(5.1)8889pass1 = "PMAN2"90for x in range(5): 91 shell.SendKeys(pass1[x], 0)92shell.SendKeys("{Enter}", 0)93time.sleep(5.1)9495w.find_window_wildcard(".*CM-.*")96w.set_foreground()97shell.SendKeys("2", 0)98shell.SendKeys("1", 0)99pass2 = "PEDI"100for x in range(4): 101 shell.SendKeys(pass2[x], 0)102shell.SendKeys("{Enter}", 0)103shell.SendKeys("{Enter}", 0)104shell.SendKeys("{Up}", 0)105shell.SendKeys("{Up}", 0)106time.sleep(5.1)107w.find_window_wildcard(".*Select EDI Type.*")108w.set_foreground()109shell.SendKeys("{Enter}", 0)110shell.SendKeys("1", 0)111shell.SendKeys("{Right}", 0)112locstr = "\\\\cs_webserver\\C\\Inetpub\\wwwroot\\Oracle1\\Judgments\\NJ_EnteredJudgments\\"113loclen = len(locstr)114for x in range(loclen): 115 shell.SendKeys(locstr[x],0)116shell.SendKeys("{Enter}", 0)117time.sleep(3.1)118119shell.SendKeys("{Enter}", 0)120time.sleep(5.1)121print("Entering Filename")122w.find_window_wildcard(".*Open.*")123w.set_foreground()124#filename = "test" #FOR TESTING ONLY!!125126127128filenamelen = len(currentfilename)129print("Inserting Data")130for x in range(filenamelen): 131 shell.SendKeys(currentfilename[x],0)132133""" filename = "enterjudgment_NJ"134filenamelen = len(filename)135print("Inserting Data")136for x in range(filenamelen): 137 shell.SendKeys(filename[x],0)138dt = datetime.datetime.now()139tdate =(dt.strftime("%m%d%Y"))140w.find_window_wildcard(".*Open.*")141w.set_foreground()142for x in range(8): 143 shell.SendKeys(tdate[x], 0)144fileext = ".txt"145w.find_window_wildcard(".*Open.*")146w.set_foreground()147for x in range(4): 148 shell.SendKeys(fileext[x], 0) """149time.sleep(5.1)150151print("Inserting Data")152shell.SendKeys("{Enter}", 0)153time.sleep(5.1)154shell.SendKeys("{Enter}", 0)155time.sleep(5.1)156157158159shell.SendKeys("{Enter}", 0)160time.sleep(200)161w.find_window_wildcard(".*CM-.*")162w.set_foreground()163shell.SendKeys("{Esc}", 0)164shell.SendKeys("{Esc}", 0)165166print("Complete")167sys.exit(0)
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!