Best Python code snippet using pyatom_python
match_recorder.py
Source:match_recorder.py
1from tkinter import *2import numpy as np3import os45import argparse6parser = argparse.ArgumentParser()7parser.add_argument("player", help="The Player whose game has to analysed")8parser.add_argument("opponent", help="Name of the Opponent whose game need to be analysed")9args = parser.parse_args()1011playername = args.player12opponentname = args.opponent131415class Window(Frame):16 17 18 def __init__(self, master=None):19 Frame.__init__(self, master) 20 self.master = master21 22 self.pos = ['a','b','c','d','e','f','g','h','i'] 23 self.pla = ['3','2','1','6','5','4','9','8','7']24 25 self.prev_highlight = None26 27 self.player = playername28 self.opponent = opponentname29 30 #Check if folder exists,if not create folder31 32 directory = "data/"+playername33 if not os.path.exists(directory):34 os.makedirs(directory)35 print("Folder created")36 37 #check if file exists if not create file38 file = directory+"/"+opponentname+".txt"39 try:40 self.file = open(file, 'ab+')41 print("File Opened")42 except IOError:43 print("File Does not exist")44 #file = open(file, 'w')45 #print("File created")46 47 48 self.previous_word = "hee haw"49 self.init_window()50 51 def init_window(self):52 self.pack(fill=BOTH, expand=1)53 w = 1554 h = 655 56 57 58 Button1 = Button(self, text="",height = h,width=w,bg="white")59 Button1.text = self.pos[6]60 Button1.bind('<Button-1>', self.click)61 Button1.bind('<Button-3>',self.rightClick)62 Button1.grid(row=0,column=1)63 64 Button2 = Button(self, text="",height = h,width=w,bg="white")65 Button2.text = self.pos[7]66 Button2.bind('<Button-1>', self.click)67 Button2.bind('<Button-3>',self.rightClick)68 Button2.grid(row=0,column=2)69 70 Button3 = Button(self, text="",height = h,width=w,bg="white")71 Button3.text = self.pos[8]72 Button3.bind('<Button-1>', self.click)73 Button3.bind('<Button-3>',self.rightClick)74 Button3.grid(row=0,column=3)75 76 Button4 = Button(self, text="",height = h,width=w,bg="white")77 Button4.text = self.pos[3]78 Button4.bind('<Button-1>', self.click)79 Button4.bind('<Button-3>',self.rightClick)80 Button4.grid(row=1,column=1)81 82 83 Button5 = Button(self, text=self.player,height = h,width=w,bg="white")84 Button5.text = self.pos[4]85 Button5.bind('<Button-1>', self.click)86 Button5.bind('<Button-3>',self.rightClick)87 Button5.grid(row=1,column=2)88 89 Button6 = Button(self, text="",height = h,width=w,bg="white")90 Button6.text = self.pos[5]91 Button6.bind('<Button-1>', self.click)92 Button6.grid(row=1,column=3)93 Button6.bind('<Button-3>',self.rightClick)94 95 Button7 = Button(self, text="",height = h,width=w,bg="white")96 Button7.text = self.pos[0]97 Button7.bind('<Button-1>', self.click)98 Button7.bind('<Button-3>',self.rightClick)99 Button7.grid(row=2,column=1)100 101 102 Button8 = Button(self, text="",height = h,width=w,bg="white")103 Button8.text = self.pos[1]104 Button8.bind('<Button-1>', self.click)105 Button8.bind('<Button-3>',self.rightClick)106 Button8.grid(row=2,column=2)107 108 Button9 = Button(self, text="",height = h,width=w,bg="white")109 Button9.text = self.pos[2]110 Button9.bind('<Button-1>', self.click)111 Button9.bind('<Button-3>',self.rightClick)112 Button9.grid(row=2,column=3)113 114 Button10 = Button(self, text="",height = h,width=w,bg="white")115 Button10.text = self.pla[2]116 Button10.bind('<Button-1>', self.click)117 Button10.bind('<Button-3>',self.rightClick)118 Button10.grid(row=3,column=1)119 120 121 Button11 = Button(self, text="",height = h,width=w,bg="white")122 Button11.text = self.pla[1]123 Button11.bind('<Button-1>', self.click)124 Button11.bind('<Button-3>',self.rightClick)125 Button11.grid(row=3,column=2)126 127 Button12 = Button(self, text="",height = h,width=w,bg="white")128 Button12.text = self.pla[0]129 Button12.bind('<Button-1>', self.click)130 Button12.bind('<Button-3>',self.rightClick)131 Button12.grid(row=3,column=3)132 133 Button13 = Button(self, text="",height = h,width=w,bg="white")134 Button13.text = self.pla[5]135 Button13.bind('<Button-1>', self.click)136 Button13.bind('<Button-3>',self.rightClick)137 Button13.grid(row=4,column=1)138 139 140 Button14 = Button(self, text=self.opponent,height = h,width=w,bg="white")141 Button14.text = self.pla[4]142 Button14.bind('<Button-1>', self.click)143 Button14.bind('<Button-3>',self.rightClick)144 Button14.grid(row=4,column=2)145 146 Button15 = Button(self, text="",height = h,width=w,bg="white")147 Button15.text = self.pla[3]148 Button15.bind('<Button-1>', self.click)149 Button15.bind('<Button-3>',self.rightClick)150 Button15.grid(row=4,column=3)151 152 Button16 = Button(self, text="",height = h,width=w,bg="white")153 Button16.text = self.pla[8]154 Button16.bind('<Button-1>', self.click)155 Button16.bind('<Button-3>',self.rightClick)156 Button16.grid(row=5,column=1)157 158 159 Button17 = Button(self, text="",height = h,width=w,bg="white")160 Button17.text = self.pla[7]161 Button17.bind('<Button-1>', self.click)162 Button17.bind('<Button-3>',self.rightClick)163 Button17.grid(row=5,column=2)164 165 Button18 = Button(self, text="",height = h,width=w,bg="white")166 Button18.text = self.pla[6]167 Button18.bind('<Button-1>', self.click)168 Button18.bind('<Button-3>',self.rightClick)169 Button18.grid(row=5,column=3)170 171 Button_switch = Button(self,text="SWITCH SIDES",height=h,width=w)172 Button_switch.bind('<Button-1>',self.switch)173 Button_switch.grid(row=0,column=4)174 175 176 Button_won = Button(self,text="WON",height=h,width=w)177 Button_won.bind('<Button-1>',self.click)178 Button_won.bind('<Button-3>',self.rightClick)179 Button_won.text = "won"180 Button_won.grid(row=2,column=4)181 182 Button_lost = Button(self,text="LOST",height=h,width=w)183 Button_lost.bind('<Button-1>',self.click)184 Button_lost.bind('<Button-3>',self.rightClick)185 Button_lost.text = "lost"186 Button_lost.grid(row=3,column=4)187 188 Button_save = Button(self,text="SAVE",height=h,width=w)189 Button_save.bind('<Button-1>',self.save)190 Button_save.grid(row=1,column=4)191 192 193 def click(self,event):194 195 self.write_to_file(event.widget.text)196 197 if self.prev_highlight:198 self.prev_highlight.configure(bg="white")199 event.widget.configure(bg="green")200 self.prev_highlight = event.widget201 202 def rightClick(self,event):203 self.write_to_file(event.widget.text,rightclick=True)204 205 if self.prev_highlight:206 self.prev_highlight.configure(bg="white")207 event.widget.configure(bg="green")208 self.prev_highlight = event.widget209 210 def switch(self,event):211 #switching button ids212 temp = self.pla213 self.pla = self.pos214 self.pos = temp215 #switching player names216 temp = self.player217 self.player = self.opponent218 self.opponent = temp219 220 print("switched")221 self.init_window()222 223 224 def save(self,event):225 self.file.close()226 227 def write_to_file(self,word,rightclick=False):228 pos = ['a','b','c','d','e','f','g','h','i'] 229 pla = ['3','2','1','6','5','4','9','8','7']230 if self.previous_word in pla:231 x = "pla"232 elif self.previous_word in pos:233 x = "pos"234 235 if not rightclick:236 if word in self.pos or word in self.pla:237 238 if self.previous_word==word:239 self.file.write(("_").encode('ascii'))240 else:241 self.file.write((" "+word).encode('ascii'))242243 else:244 self.file.write((" "+x+"fo"+word+"\n").encode('ascii'))#this is forced error245 else:246 if word in self.pos or word in self.pla:247 248 if self.previous_word==word:249 self.file.write(("_").encode('ascii'))250 else:251 self.file.write((" "+word+"b").encode('ascii'))252 253 254 else:255 self.file.write((" "+x+"ufo"+word+"\n").encode('ascii'))#this is unforced error256 257 self.previous_word = word 258259root = Tk()260261#size of the window262root.geometry("500x600")263264app = Window(root)265
...
item_actions.spec.js
Source:item_actions.spec.js
2context('Item actions', () => {3 it('includes an Edit button', () => {4 cy.createItem({ type: 'folder', name: 'Folder 1' })5 cy.visit('/')6 cy.item('Folder 1').rightclick()7 cy.contains('Edit').click()8 cy.url().should('match', new RegExp(`/items/\\d+$`))9 })10 it('includes a Delete button', () => {11 cy.createItem({ type: 'folder', name: 'Folder 1' })12 cy.visit('/')13 // test dialog rejection, should not delete14 cy.once('window:confirm', () => false)15 cy.item('Folder 1').rightclick()16 cy.contains('Delete').click()17 cy.item('Folder 1').should('exist')18 // second time, now for real19 cy.item('Folder 1').rightclick()20 cy.contains('Delete').click()21 cy.shouldNotHaveItem('Folder 1')22 })23 it('includes an Open URL button for URLs', () => {24 cy.createItem({ type: 'folder', name: 'Folder 1' })25 cy.createItem({ type: 'url', name: 'Bookmark 1', url: 'http://example.com' })26 cy.visit('/')27 cy.item('Folder 1').rightclick()28 cy.contains('Open URL').should('not.exist')29 cy.item('Bookmark 1').rightclick()30 cy.contains('Open URL').should('exist')31 })32 it('includes a Copy URL button for URLs', () => {33 cy.createItem({ type: 'folder', name: 'Folder 1' })34 cy.createItem({ type: 'url', name: 'Bookmark 1', url: 'http://example.com' })35 cy.visit('/')36 cy.item('Folder 1').rightclick()37 cy.contains('Copy URL').should('not.exist')38 cy.item('Bookmark 1').rightclick()39 cy.contains('Copy URL').should('exist')40 })41 it('includes Cut and Paste buttons', () => {42 cy.createItem({43 type: 'folder', name: 'Folder 1', children: [44 {45 type: 'folder', name: 'Folder 2', children: [46 { type: 'url', name: 'URL 1', url: 'http://url1.com' },47 { type: 'url', name: 'URL 2', url: 'http://url2.com' },48 ]49 },50 { type: 'url', name: 'URL 3', url: 'http://url3.com' },51 ]52 })53 cy.createItem({ type: 'folder', name: 'Folder 3' })54 cy.visit('/')55 cy.item('Folder 1').rightclick()56 cy.contains('Paste').should('be.disabled') // nothing cut yet => cant paste57 cy.get('body').click()58 cy.item('Folder 1').dblclick()59 // paste url into other folder60 cy.item('URL 3').rightclick()61 cy.contains('Cut').click()62 cy.item('URL 3').rightclick()63 cy.contains('Paste').should('not.exist') // can only paste into folder64 cy.get('body').click()65 cy.item('Folder 2').rightclick()66 cy.contains('Paste').click()67 cy.shouldNotHaveItem('URL 3')68 cy.item('Folder 2').dblclick()69 cy.shouldHaveItem('URL 3')70 // paste folder from tree view into other folder71 cy.item('Folder 1').click()72 cy.item('Folder 2').rightclick()73 cy.contains('Cut').click()74 cy.item('Folder 3').rightclick()75 cy.contains('Paste').click()76 cy.shouldNotHaveItem('Folder 2')77 cy.item('Folder 3').dblclick()78 cy.shouldHaveItem('Folder 2', { within: 'folder' })79 .dblclick()80 cy.shouldHaveItem('URL 1')81 cy.shouldHaveItem('URL 2')82 })83 it('includes a Dissolve button', () => {84 cy.createItem({85 type: 'folder', name: 'Folder 1', children: [86 { type: 'url', name: 'URL 1', url: 'http://url1.com' },87 { type: 'url', name: 'URL 2', url: 'http://url2.com' },88 ]89 })90 cy.visit('/')91 // test dialog rejection, should not dissolve92 cy.once('window:confirm', () => false)93 cy.item('Folder 1').rightclick()94 cy.contains('Dissolve').click()95 cy.item('Folder 1').should('exist')96 // second time, now for real97 cy.item('Folder 1').rightclick()98 cy.contains('Dissolve').click()99 cy.shouldNotHaveItem('Folder 1')100 cy.shouldHaveItem('URL 1')101 cy.shouldHaveItem('URL 2')102 })103 it('includes a Select / Deselect button', () => {104 cy.createItem({ type: 'url', name: 'URL 1', url: 'http://example.com' })105 cy.createItem({ type: 'url', name: 'URL 2', url: 'http://example.com' })106 cy.createItem({ type: 'url', name: 'URL 3', url: 'http://example.com' })107 cy.visit('/')108 cy.item('URL 1').rightclick()109 cy.contains('Deselect').should('not.exist')110 cy.contains('Select').click()111 cy.item('URL 2').rightclick()112 cy.contains('Select').click()113 cy.item('URL 3').rightclick()114 cy.contains('Select').click()115 cy.item('URL 1').rightclick()116 cy.contains('Select').should('not.exist')117 cy.contains('Deselect').click()118 cy.item('URL 1').should('not.have.class', 'selected')119 cy.item('URL 2').should('have.class', 'selected')120 cy.item('URL 3').should('have.class', 'selected')121 })122 it('includes a Delete selected button', () => {123 cy.createItem({ type: 'url', name: 'URL 1', url: 'http://example.com' })124 cy.createItem({ type: 'url', name: 'URL 2', url: 'http://example.com' })125 cy.createItem({ type: 'url', name: 'URL 3', url: 'http://example.com' })126 cy.visit('/')127 cy.item('URL 1').click()128 cy.item('URL 3').click()129 cy.item('URL 1').rightclick()130 cy.contains('Delete selected (2)').click()131 cy.shouldNotHaveItem('URL 1')132 cy.shouldHaveItem('URL 2')133 cy.shouldNotHaveItem('URL 3')134 })135 it('includes a Cut selected button', () => {136 cy.createItem({ type: 'folder', name: 'Folder 1' })137 cy.createItem({ type: 'url', name: 'URL 1', url: 'http://example.com' })138 cy.createItem({ type: 'url', name: 'URL 2', url: 'http://example.com' })139 cy.createItem({ type: 'url', name: 'URL 3', url: 'http://example.com' })140 cy.visit('/')141 cy.item('URL 1').click()142 cy.item('URL 2').click()143 cy.item('URL 1').rightclick()144 cy.contains('Cut selected (2)').click()145 cy.item('Folder 1').rightclick()146 cy.contains('Paste (2)').click()147 cy.shouldNotHaveItem('URL 1')148 cy.shouldNotHaveItem('URL 2')149 cy.shouldHaveItem('URL 3')150 cy.item('Folder 1').dblclick()151 cy.shouldHaveItem('URL 1')152 cy.shouldHaveItem('URL 2')153 })...
rightClick.js
Source:rightClick.js
1/**2 * 3 * Copyright 2007-20094 * 5 * Project website:6 * http://code.google.com/p/custom-context-menu/7 * 8 * --9 * RightClick for Flash Player. 10 * Version 0.6.311 * 12 */13var RightClick = {14 /**15 * Constructor16 */ 17 init: function () {18 if(window.location.hash) {19 window.location = window.location.href.replace( /#.*/, "");20 }21 this.FlashObjectID = "loghApplication";22 this.Cache = this.FlashObjectID;23 var ieContent=document.getElementById('flashcontent');24 if(window.addEventListener){25 this.FlashContainerID = document.getElementById("flashcontent");26 window.addEventListener("mousedown", this.onGeckoMouse(), true);27 } else {28 this.FlashContainerID = document.getElementById("iecontent");29 RightClick.FlashContainerID.onmouseup = function(){RightClick.FlashContainerID.releaseCapture(); }30 document.oncontextmenu = function(){ if(window.event.srcElement.id == RightClick.FlashObjectID) { return false; } else { RightClick.Cache = "nan"; }}31 RightClick.FlashContainerID.onmousedown = RightClick.onIEMouse;32 }33 },34 /**35 * Disable the Right-Click event trap and continue showing flash player menu36 */ 37 UnInit: function () { 38 //alert('Un init is called' ); 39 if(window.RemoveEventListener){40 alert('Un init is called for GECKO' ); 41 window.addEventListener("mousedown", null, true);42 window.RemoveEventListener("mousedown",this.onGeckoMouse(),true);43 //w//indow.releaseEvents("mousedown");44 } else {45 //alert('Un init is called for IE' ); 46 RightClick.FlashContainerID.onmouseup = "" ;47 document.oncontextmenu = "";48 RightClick.FlashContainerID.onmousedown = "";49 }50 },51 /**52 * GECKO / WEBKIT event overkill53 * @param {Object} eventObject54 */55 killEvents: function(eventObject) {56 if(eventObject) {57 if (eventObject.stopPropagation) eventObject.stopPropagation();58 if (eventObject.preventDefault) eventObject.preventDefault();59 if (eventObject.preventCapture) eventObject.preventCapture();60 if (eventObject.preventBubble) eventObject.preventBubble();61 }62 },63 /**64 * GECKO / WEBKIT call right click65 * @param {Object} ev66 */67 onGeckoMouse: function(ev) {68 return function(ev) {69 if (ev.button != 0) {70 RightClick.killEvents(ev);71 if(ev.target.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {72 RightClick.call();73 }74 RightClick.Cache = ev.target.id;75 }76 }77 },78 /**79 * IE call right click80 * @param {Object} ev81 */82 onIEMouse: function() {83 if (event.button > 1) {84 if(window.event.srcElement.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {85 RightClick.call(); 86 }87 RightClick.FlashContainerID.setCapture();88 if(window.event.srcElement.id)89 RightClick.Cache = window.event.srcElement.id;90 }91 },92 /**93 * Main call to Flash External Interface94 */95 call: function() {96 document.getElementById(this.FlashObjectID).rightClick();97 }...
junk_destroy.py
Source:junk_destroy.py
1# -*- coding: utf-8 -*-2"""3Created on Thu Jul 1 21:50:52 202145@author: rosebud6"""78import time9import pydirectinput101112pydirectinput.keyDown('alt')13pydirectinput.press('tab')14pydirectinput.keyUp('alt')15time.sleep(1)1617# pydirectinput.press('i')18time.sleep(.5)1920# window 121# 6,4,5,322pydirectinput.rightClick(500, 680) # right click at x, y coordinates23pydirectinput.press('6')24time.sleep(.2)25pydirectinput.rightClick(500, 680) # right click at x, y coordinates26pydirectinput.press('4')27time.sleep(.2)28pydirectinput.rightClick(500, 680) # right click at x, y coordinates29pydirectinput.press('5')30time.sleep(.2)31pydirectinput.rightClick(500, 680) # right click at x, y coordinates32pydirectinput.press('3')33time.sleep(.2)3435# window 236# 6,4,5,337pydirectinput.rightClick(1525, 680) # right click at x, y coordinates38pydirectinput.press('6')39time.sleep(.2)40pydirectinput.rightClick(1525, 680) # right click at x, y coordinates41pydirectinput.press('4')42time.sleep(.2)43pydirectinput.rightClick(1525, 680) # right click at x, y coordinates44pydirectinput.press('5')45time.sleep(.2)46pydirectinput.rightClick(1525, 680) # right click at x, y coordinates47pydirectinput.press('3')48time.sleep(.2)4950# window 351# 6,4,5,352pydirectinput.rightClick(2550, 680) # right click at x, y coordinates53pydirectinput.press('6')54time.sleep(.2)55pydirectinput.rightClick(2550, 680) # right click at x, y coordinates56pydirectinput.press('4')57time.sleep(.2)58pydirectinput.rightClick(2550, 680) # right click at x, y coordinates59pydirectinput.press('5')60time.sleep(.2)61pydirectinput.rightClick(2550, 680) # right click at x, y coordinates62pydirectinput.press('3')63time.sleep(.2)646566time.sleep(.5)67pydirectinput.keyDown('alt')68pydirectinput.press('esc')
...
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!!