How to use sendGlobalKey method in pyatom

Best Python code snippet using pyatom_python

logic.py

Source:logic.py Github

copy

Full Screen

...42 print("Project opened")43def __toggle_open__(key, should_open):44 num_children = len(logic.windows()[0].AXChildren)45 logic.activate()46 logic.sendGlobalKey(key)47 # If we're supposed to open and the number of panes decreased, reopen it48 new_num_children = len(logic.windows()[0].AXChildren)49 if (should_open and new_num_children < num_children) or (50 not should_open and new_num_children > num_children51 ):52 logic.sendGlobalKey(key)53def closeMixer():54 print("Closing mixer...")55 __toggle_open__("x", False)56 print("Mixer closed")57def closeLibrary():58 print("Closing library...")59 __toggle_open__("x", False)60 print("Library closed")61def selectAllRegions():62 closeMixer()63 # Note that while selecting, we close the mixer (if open)64 print("Selecting all regions...")65 logic.sendGlobalKeyWithModifiers("a", ["command"])66 print("Regions selected")67def transpose(interval):68 print("Opening the inspector...")69 logic.activate()70 inspectors = [71 x72 for x in logic.windows()[0].AXChildren73 if "AXDescription" in x.getAttributes()74 and x.findFirstR(AXValue="Transpose:") != None75 ]76 if len(inspectors) == 0:77 logic.sendGlobalKey("i")78 inspectors = [79 x80 for x in logic.windows()[0].AXChildren81 if "AXDescription" in x.getAttributes()82 and x.findFirstR(AXValue="Transpose:") != None83 ]84 print("Transposing the regions...")85 inspectors[0].findFirstR(AXValue="Transpose:").AXParent.findFirst(86 AXRole="AXSlider"87 ).AXValue = interval88 print("Regions transposed")89def bounce(filepath, bounce_format="MP3"):90 # Adapted from https://gist.github.com/psobot/81635e6cbc933b7e886291 print("Opening bounce window...")92 logic.activate()93 time.sleep(0.1) # To make sure the command works94 logic.sendGlobalKeyWithModifiers("b", ["command"])95 windows = []96 while len(windows) == 0:97 time.sleep(0.1)98 windows = [99 window100 for window in logic.windows()101 if ("Output 1-2" in window.AXTitle) or ("Bounce" in window.AXTitle)102 ]103 bounce_window = windows[0]104 print("Selecting output formats...")105 quality_table = bounce_window.findFirst(AXRole="AXScrollArea").findFirst(106 AXRole="AXTable"107 )108 for row in quality_table.findAll(AXRole="AXRow"):109 row_name = row.findFirst(AXRole="AXTextField").AXValue110 checkbox = row.findFirst(AXRole="AXCheckBox")111 if row_name == bounce_format:112 if checkbox.AXValue == 0:113 print(f"Selecting {bounce_format} output format...")114 checkbox.Press()115 else:116 print(f"{bounce_format} format already selected.")117 elif checkbox.AXValue == 1:118 print(f"Deselecting {row_name} format...")119 print("Pressing bounce...")120 bounce_window.findFirst(AXRole="AXButton", AXTitle="OK").Press()121 print("Waiting for save window...")122 windows = []123 while len(windows) == 0:124 time.sleep(0.1)125 windows = [126 window127 for window in logic.windows()128 if ("Output 1-2" in window.AXTitle) or ("Bounce" in window.AXTitle)129 ]130 save_window = windows[0]131 print("Entering file path...")132 logic.activate()133 logic.sendGlobalKeyWithModifiers("g", ["command", "shift"])134 logic.sendKeys(f"{filepath}\n")135 print("Waiting for file path window to close...")136 logic.activate()137 windows = []138 while len(windows) != 1:139 time.sleep(0.1)140 windows = [141 window142 for window in logic.windows()143 if ("Output 1-2" in window.AXTitle) or ("Bounce" in window.AXTitle)144 ]145 save_window = windows[0]146 print("Pressing bounce on save window...")147 try:148 save_window.buttons("Bounce")[0].Press()149 except atomacos.errors.AXErrorAttributeUnsupported as e:150 print(f"Error when clicking bounce: {str(e)}")151 time.sleep(0.1)152 # Deal with case where file already exists153 for dialog in [154 window for window in logic.windows() if window.AXRoleDescription == "dialog"155 ]:156 print("Overwriting previous file...")157 btns = dialog.AXChildren[-1].buttons("Replace")158 for btn in btns:159 btn.Press()160 time.sleep(0.1)161 # Deal with extra messages that could pop up162 dialogs = [163 window164 for window in logic.windows()165 if window.AXRoleDescription == "dialog"166 ]167 while len(dialogs) > 0:168 replace_btn = dialogs[0].buttons("Replace")169 if len(replace_btn) == 0:170 break171 replace_btn[0].Press()172 time.sleep(0.1)173 dialogs = [174 window175 for window in logic.windows()176 if window.AXRoleDescription == "dialog"177 ]178 print("Bouncing...")179 # time.sleep(2)180 logic.activate() # Required for some reason181 still_going = True182 while still_going:183 try:184 still_going = len(logic.windows()) > 1185 except atomacos.errors.AXErrorInvalidUIElement:186 still_going = True187 time.sleep(0.1)188 print("File saved")189def close():190 print("Closing project...")191 logic.sendGlobalKeyWithModifiers("w", ["command"])192 print("Waiting for the save changes window...")193 windows = []194 for _ in range(20):195 time.sleep(0.1)196 windows = [197 window198 for window in logic.windows()199 if "AXDescription" in window.getAttributes()200 and window.AXDescription == "alert"201 ]202 if len(windows) > 0:203 break204 if len(windows) > 0:205 windows[0].buttons("Don’t Save")[0].Press()206 while len(logic.windows()) > 0:207 time.sleep(0.1)208 print("Project closed")209def importMidi(midiFile):210 print(midiFile)211 selectLastTrack()212 print("Opening up midi selection window...")213 logic.menuItem("File", "Import", "MIDI File…").Press()214 windows = []215 while len(windows) == 0:216 time.sleep(0.1)217 windows = [218 window219 for window in logic.windows()220 if "AXTitle" in window.getAttributes() and window.AXTitle == "Import"221 ]222 import_window = windows[0]223 print("Navigating to folder...")224 logic.activate()225 logic.sendGlobalKeyWithModifiers("g", ["command", "shift"])226 logic.sendKeys(midiFile)227 logic.sendKeys("\n")228 print("Pressing import...")229 time.sleep(0.1)230 import_window.buttons("Import")[0].Press()231 print("Waiting for tempo import message...")232 windows = []233 while len(windows) == 0:234 time.sleep(0.1)235 windows = [236 window237 for window in logic.windows()238 if "AXDescription" in window.getAttributes()239 and window.AXDescription == "alert"240 ]241 alert = windows[0]242 print("Importing tempo...")243 alert.buttons("Import Tempo")[0].Press()244 print("Midi file imported")245"""246old_instrument is the old instrument's name (like 'Sampler')247new_instrument_arr is an array like ['AU Instruments', 'Native Instruments', 'Kontakt', 'Stereo']248(it has the hierarchy of items to find in the menu).249"""250def selectInstrument(new_instrument_arr):251 print("Opening the appropriate window...")252 window = [253 window254 for window in logic.windows()255 if "AXTitle" in window.getAttributes() and "Tracks" in window.AXTitle256 ][0]257 print("Finding the instrument to change...")258 # It's at window.AXChildren[-2].AXChildren[0].AXChildren[-1].AXChildren[0].AXChildren[0]...259 # The one below could be used if we know the name of the instrument260 # strip = window.findFirstR(AXRoleDescription='channel strip group').findFirstR(AXDescription=old_instrument).AXChildren[-1]261 strip = (262 window.findFirstR(AXRoleDescription="channel strip group")263 .findAllR(AXDescription="open")[-1]264 .AXParent.AXChildren[-1]265 )266 # Manually click because Press() throws errors267 time.sleep(0.1)268 atomacos.mouse.click(x=strip.AXPosition.x + 1, y=strip.AXPosition.y + 1)269 print("Walking through the menu items...")270 menuitem = window271 for item in new_instrument_arr:272 if menuitem.AXChildren[0].AXRole == "AXMenu":273 menuitem = menuitem.AXChildren[0]274 menuitem = menuitem.findFirstR(AXRole="AXMenu*Item", AXTitle=item)275 while menuitem.AXPosition.x == 0:276 time.sleep(0.1)277 atomacos.mouse.moveTo(x=menuitem.AXPosition.x + 1, y=menuitem.AXPosition.y + 1)278 print("Clicking the instrument name...")279 atomacos.mouse.click(x=menuitem.AXPosition.x + 1, y=menuitem.AXPosition.y + 1)280 print("Waiting for the instrument screen...")281 windows = []282 i = 0283 while len(windows) < 1 and i < 20:284 time.sleep(0.1)285 i += 1286 windows = [287 window288 for window in logic.windows()289 if "AXTitle" not in window.getAttributes() or "Tracks" not in window.AXTitle290 ]291 if i >= 20:292 print("Failed to open instrument screen")293 raise Exception("Failed to open instrument screen")294 print("Closing the instrument screen...")295 for window in windows:296 window.AXChildren[0].Press()297 print("Done selecting instrument")298def selectPresetSound(sound):299 print("Opening the appropriate window...")300 window = [301 window302 for window in logic.windows()303 if "AXTitle" in window.getAttributes() and "Tracks" in window.AXTitle304 ][0]305 closeLibrary()306 strip = (307 window.findFirstR(AXRoleDescription="channel strip group")308 .findAllR(AXDescription="open")[-1]309 .AXParent.AXChildren[0]310 )311 print("Opening the presets for the instrument")312 atomacos.mouse.click(x=strip.AXPosition.x - 20, y=strip.AXPosition.y + 1)313 print("Waiting for search text field to appear...")314 fields = []315 while len(fields) == 0:316 time.sleep(0.1)317 try:318 fields = window.findAllR(319 AXRole="AXTextField", AXRoleDescription="search text field"320 )321 except Exception:322 print("Error finding search library field")323 fields = []324 search_field = fields[0]325 row = window.findFirstR(AXValue=sound)326 print("Double clicking the sound")327 logic.activate()328 atomacos.mouse.click(329 x=row.AXPosition.x + 30, y=row.AXPosition.y + 10, clicks=1, interval=0.1330 )331 time.sleep(0.05)332 atomacos.mouse.click(333 x=row.AXPosition.x + 30, y=row.AXPosition.y + 10, clicks=2, interval=0.01334 )335def selectLastTrack():336 closeMixer()337 print("Moving selection down by 5")338 logic.activate()339 for i in range(5):340 logic.sendGlobalKey("down")341def deleteLastTrack():342 selectLastTrack()343 print("Entering delete keyboard shortcut...")344 logic.sendGlobalKeyWithModifiers("del", ["command"])345 print("Confirming deletion...")346 windows = []347 while len(windows) == 0:348 time.sleep(0.1)349 windows = [x for x in logic.windows() if x.AXRoleDescription == "dialog"]350 delete_popup = windows[0]...

Full Screen

Full Screen

keypress_actions.py

Source:keypress_actions.py Github

copy

Full Screen

...153 if key_val.modifiers:154 self._dummy_window.sendGlobalKeyWithModifiers(key_val.value,155 key_val.modVal)156 else:157 self._dummy_window.sendGlobalKey(key_val.value)158 time.sleep(0.01)159class KeyPressAction:160 def __init__(self, window, data):161 self._data=data162 self._window=window163 _keyOp=KeyboardOp()164 self._keyvalId=_keyOp.get_keyval_id(data)165 if not self._keyvalId:166 raise LdtpServerException("Unsupported keys passed")167 self._doPress()168 def _doPress(self):169 for key_val in self._keyvalId:170 if key_val.modifiers:171 self._window.pressModifiers(key_val.modVal)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful