How to use textFields method in pyatom

Best Python code snippet using pyatom_python

demo_3_tracker.py

Source:demo_3_tracker.py Github

copy

Full Screen

1from modtrack import tracker23import pygame4from textfield import Textfield56#for file dialogs7import tkinter as tk8import os9from tkinter import filedialog10from tkinter import messagebox11tkroot = tk.Tk()12tkroot.withdraw()13fd_opts = {}14fd_opts['initialdir'] = [os.path.dirname(os.path.abspath(__file__))]1516ret=tracker.load_amigamodule('ProTracker-win32/modules/oxygene.mod') #M.K. (make_pattern: 2.8s)17#ret = tracker.load_amigamodule('ProTracker-win32/modules/Tubbs and Valerie.mod') # M.K.18#ret = tracker.load_amigamodule('ProTracker-win32/modules/equinoxe.mod') # M.K.19#ret=tracker.load_amigamodule('ProTracker-win32/modules/POPCORN.MOD') # M.K.20#ret=tracker.load_amigamodule('ProTracker-win32/modules/equinoxe ii.mod') #M.K.21#ret=tracker.load_amigamodule('ProTracker-win32/modules.stk/STK.ghostbusters') # original 15 samples Soundtracker file222324#ret = tracker.load_amigamodule('TEST_0.MOD') # M.K.2526#################################################################27#INIT SCREEN AND TRACKER28#################################################################2930#determine resolution/window-size on nr of rows to display31nr_rows=1232resolution=(89*8,(nr_rows+5)*8)3334#init the tracker module and make pattern35screen=tracker.init(0x40,resolution)36dummy, raw_pattern_text, cumtimings = tracker.make_pattern(True)3738#load a font39pygame.font.init()40myfont = pygame.font.Font('C64_Pro_Mono-STYLE.ttf', 8)414243#################################################################44#PLAY AND DISPLAY TRACK45#################################################################4647#Construct screen from textfields48if tracker.songtitle=="" : tracker.songtitle=tracker.filename49textfields=[]50str_songtitle="{:_<20}".format(tracker.songtitle[:20].replace(" ", "_").upper())51str_samples="{:_<22}".format(tracker.samples[0]["name"][:22].replace(" ", "_").upper())52str_samples="1234567890123456789012"53tf_label_songtitle = Textfield((1,1),"NAME:",True)54tf_songtitle = Textfield((6,1),str_songtitle,[],20)55tf_load = Textfield((27,1),"L",True)56tf_save = Textfield((29,1),"S",True)57tf_new = Textfield((31,1),"N",True)58tf_load.border = (255,255,255)59tf_save.border = (255,255,255)60tf_new.border = (255,255,255)61tf_label_samples = Textfield((46,1)," | SAMPLE:",True)62tf_samplenr = Textfield((56,1),"01|",True)63tf_samples = Textfield((59,1),str_samples,[],22)64tf_prev = Textfield((81,1),"<",True)65tf_next = Textfield((82,1),">",True)66tf_prev.border = (255,255,255)67tf_next.border = (255,255,255)68tf_time = Textfield((74,nr_rows+4),"000:000 | 0000",True)69tf_time.color = (255,255,255)70tf_status = Textfield((1,nr_rows+4),"STATUS:PLAY",True)71tf_status.color = (255,255,255)72str_sequence = "--- --- 00 000 000"73all_hex = '0123456789abcdef'74allowed = ['abcdefg','#-','12345','',\75 'abcdefg','#-','12345','',\76 all_hex,all_hex,'',\77 all_hex,all_hex,all_hex,'',\78 all_hex,all_hex,all_hex]79uneditable_sequence = [3,7,10,14]80textfields.append(tf_label_songtitle)81textfields.append(tf_songtitle)82textfields.append(tf_load)83textfields.append(tf_save)84textfields.append(tf_new)85textfields.append(tf_label_samples)86textfields.append(tf_samplenr)87textfields.append(tf_samples)88textfields.append(tf_prev)89textfields.append(tf_next)90textfields.append(tf_time)91textfields.append(tf_status)92first_textfield=len(textfields)+1 #so we don't count first row-nr text-field93for row in range(0, nr_rows):94 pos = (1, row + 3)95 tf_row_id = Textfield(pos,"{:03d} |".format(row),True)96 textfields.append(tf_row_id)97 for col in range (0,4):98 pos=(7+col*21,row+3)99 div=((col+1)*21+5,row+3)100 tf_sequence=Textfield(pos,str_sequence,uneditable_sequence,None,allowed)101 textfields.append(tf_sequence)102 if col<3:103 tf_div=Textfield(div, "|",True)104 textfields.append(tf_div)105106# space will unpause and pause so state should be logged107#init cursor108play_offset = nr_rows // 3109# start player110activerow=0111active_textfield=textfields[first_textfield+(nr_rows-play_offset) *8]112cursor=active_textfield.startpos113edited=False114pause = False115samplenr=0116tf_samplenr.text = "{:02d}".format(samplenr)117tf_samples.text = tracker.samples[samplenr]["name"]118player = tracker.play_pattern()119while True:120 #clean screen121 pygame.draw.rect(screen, (0, 0, 0), pygame.Rect((0, 0), resolution))122 #draw cursor123 pygame.draw.rect(screen, (255, 255, 255), pygame.Rect((cursor[0]*8,cursor[1]*8), (8, 8)),0)124 #draw screen125 if pause:126 pos = "{:07.3f} | {:04}".format(tracker.get_play_pos(), activerow)127 tf_time.text = pos128 if textfields.index(active_textfield)>=first_textfield:129 offset=nr_rows-(cursor[1]-3)130 pass131 else:132 pos = "{:07.3f} | {:04}".format(tracker.get_play_pos(), tracker.get_play_row())133 tf_time.text = pos134 offset = play_offset135 activerow = tracker.get_play_row()136137 for i in range(0,nr_rows):138 pattern_rownr = activerow + i - nr_rows + offset139 textfield=textfields[first_textfield-1 + i * 8]140 if 0<=pattern_rownr<len(raw_pattern_text):141 textfield.text="{:03d} |".format(pattern_rownr)142 else:143 textfield.text = ""144 if i == nr_rows - offset:145 textfield.color = (255, 255, 255)146 else:147 textfield.color = (255, 0, 255)148 for channel in range(0,4):149 textfield=textfields[first_textfield + i * 8 + channel * 2]150 if 0 <= pattern_rownr < len(raw_pattern_text):151 textfield.text = raw_pattern_text[pattern_rownr][channel]152 else:153 textfield.text = ""154 if i==nr_rows-offset:155 textfield.color = (255,255,255)156 else:157 textfield.color = (255, 0, 255)158 pass159 if textfields.index(active_textfield)>=first_textfield:160 active_textfield.color = (255,255,0)161 for textfield in textfields:162 textfield.draw(myfont,screen)163 pygame.display.flip()164 pygame.time.Clock().tick(60)165166 #check for user events167 for event in pygame.event.get():168169 #Key event170 if event.type == pygame.KEYDOWN:171 #Close window172 if event.key==pygame.K_ESCAPE:173 tracker.abort_play()174 quit()175 #Play control176 if event.key==pygame.K_RALT:177 pause=False178 if edited:179 tracker.make_pattern(False, raw_pattern_text)180 edited = False181 # resume182 player = tracker.play_pattern()183 if event.key==pygame.K_SPACE:184 if pause:#not is_playing:185 #set cursor186 cursor=(7,3 + nr_rows - play_offset)187 idx=first_textfield+(nr_rows-play_offset)*8188 active_textfield=textfields[idx]189 #we could play from cursor, but from now we resume from pause190 #we should reparse edited raw_track_pattern191 tf_status.text = "STATUS:RESYNTH"192 if edited:193 tracker.make_pattern(False,raw_pattern_text)194 edited = False195 tracker.play_pattern(None, tracker.get_play_pos())196 #resume197 else:198 tracker.resume_play()199 pause=False200 tf_status.text="STATUS:PLAY"201 print ("RESUME playback")202 else:203 print("PAUSE playback")204 tf_status.text = "STATUS:PAUSE"205 pause=True206 tracker.pause_play()207 #set cursor and active_textfield208 cursor=(7,3 + nr_rows - offset )209 idx=first_textfield+(cursor[1]-3)*8210 active_textfield=textfields[idx]211 #Edit212 req_next_row = False213 req_next_char = False214 req_next_field= False215 req_prev_field= False216 if activerow == len(raw_pattern_text):217 raw_pattern_text.append(["--- --- 00 000 000"] * 4)218 active_textfield.text="--- --- 00 000 000"219 for textfield in textfields:220 idx=textfields.index(textfield)221 if textfield.edit(event.key,cursor):222 if idx<first_textfield: #we are editing song title or sample names223 req_next_char= True224 else: #we are in pattern data225 edited=True226 req_next_row = True227 channel=((idx-first_textfield)%8)//2228 print ("activerow, channel:",activerow, channel)229 raw_pattern_text[activerow][channel]=textfields[idx].text230231 #Navigate (only if not playing)232 if pause:233 if event.key == pygame.K_UP:234 idx=textfields.index(active_textfield)235 char_nr=active_textfield.char_nr(cursor)236 if idx>first_textfield+6:237 active_textfield=textfields[idx-8]238 cursor=(active_textfield.startpos[0]+char_nr,active_textfield.startpos[1])239 if idx>=first_textfield and activerow>0:240 activerow=activerow-1241 if event.key == pygame.K_DOWN or req_next_row:242 idx=textfields.index(active_textfield)243 char_nr=active_textfield.char_nr(cursor)244 if (first_textfield-1)<idx<len(textfields)-7:245 idx=idx+8246 active_textfield=textfields[idx]247 cursor = (active_textfield.startpos[0] + char_nr, active_textfield.startpos[1])248 if idx>=first_textfield and activerow<len(raw_pattern_text):249 activerow=activerow+1250 if event.key == pygame.K_RIGHT or req_next_char:251 ret = active_textfield.next_editable(cursor)252 if ret:253 ncursor=ret254 if textfields.index(active_textfield) > first_textfield:255 if ncursor[1] > cursor[1]: activerow = activerow + 1256 cursor=ncursor257 else: req_next_field=True258 pass259 if event.key == pygame.K_LEFT:260 ret = active_textfield.prev_editable(cursor)261 if ret:262 ncursor=ret263 ncursor=ret264 if textfields.index(active_textfield) > first_textfield:265 if ncursor[1] < cursor[1]: activerow = activerow - 1266 cursor=ncursor267 else: req_prev_field=True268 if event.key==pygame.K_TAB or req_next_field or req_prev_field:269 idx = textfields.index(active_textfield)270 if (pygame.key.get_mods() & pygame.KMOD_SHIFT) or req_prev_field:271 tf_range=range(idx - 1, 0,-1)272 else:273 tf_range = range(idx + 1, len(textfields))274 for idxn in tf_range :275 textfield=textfields[idxn]276 if not textfield.readonly:277 active_textfield=textfields[idxn]278 ncursor = active_textfield.startpos279 if textfields.index(active_textfield)>first_textfield:280 if ncursor[1] > cursor[1]: activerow = activerow + 1281 if ncursor[1] < cursor[1]: activerow = activerow - 1282 cursor=ncursor283 if req_prev_field: cursor = active_textfield.endpos284 break285286 #Mouse event287 else:288 # Window Close Button289 if event.type == pygame.QUIT:290 tracker.abort_play()291 quit()292293 # Click on window surface294 if event.type == pygame.MOUSEBUTTONDOWN and pause:295 x,y=pygame.mouse.get_pos()296 c = [x // 8,y // 8]297 for textfield in textfields:298 if textfield.is_editable(c):299 cursor=c300 active_textfield=textfield301302 if tf_load.is_selected(c):303 tkroot.lift()304 tkroot.focus_force()305 fd_opts['title'] = 'Open Music Track File'306 fd_opts['filetypes'] = [('Supported files', '*.mod;*.pyt'),('MOD files', '.mod'),('PYT files', '.pyt'), ('All files', '.*')]307 fd_opts['initialdir']308 file_path = filedialog.askopenfilename(**fd_opts)309 if file_path:310 tracker.load(file_path)311 pass312 if tf_save.is_selected(c):313 tkroot.lift()314 tkroot.focus_force()315 fd_opts['title'] = 'Save Music Track File'316 fd_opts['filetypes'] = [('PYT files', '.pyt')]317 file_path = filedialog.asksaveasfilename(**fd_opts)318 if file_path:319 tracker.songtitle=tf_songtitle.text320 tracker.save(file_path)321 messagebox.showinfo("Saved", "Track saved as "+file_path)322 if tf_new.is_selected(c):323 tkroot.lift()324 tkroot.focus_force()325 fd_opts['title'] = 'Create Music Track File'326 fd_opts['filetypes'] = [('PYT files', '.pyt')]327 file_path = filedialog.asksaveasfilename(**fd_opts)328 if file_path:329 tracker.clear(file_path)330331 if tf_samples.is_selected(c):332 tkroot.lift()333 tkroot.focus_force()334 fd_opts['title'] = 'Load Sample'335 fd_opts['filetypes'] = [('WAV files', '.wav')]336 file_path = filedialog.askopenfilename(**fd_opts)337 if file_path:338 tracker.samples[samplenr] = tracker.wav2sample(file_path)339 tf_samples.text = tracker.samples[samplenr]["name"]340 edited = True341342 if tf_prev.is_selected(c):343 samplenr=(samplenr-1) % 16344 tf_samplenr.text="{:02d}".format(samplenr)345 tf_samples.text = tracker.samples[samplenr]["name"]346 if tf_next.is_selected(c):347 samplenr=(samplenr+1) % 16348 tf_samplenr.text="{:02d}".format(samplenr)349 tf_samples.text = tracker.samples[samplenr]["name"]350351352 pass ...

Full Screen

Full Screen

novel_alerts_controller.py

Source:novel_alerts_controller.py Github

copy

Full Screen

1# Filename: novel_alerts_controller.py2"""Controller that connects data flow from the view(GUI) to the model."""3class NovelAlertsController:4 """5 A class that represents the controller for the Model-View-Controller(MVC) design pattern. 6 7 Controller receives events/requests and input from the view that puts the model to work.8 9 :param model: Object of the NovelAlertsModel class (Model)10 :type model: NovelAlertsModel11 :param view: Object of the NovelAlertsView class (View)12 :type view: NovelAlertsView13 """14 TYPES = ["Email", "Password", "URL"]15 16 def __init__(self, model_Obj: object, view_Obj: object) -> None:17 """Controller Initializer"""18 self.view = view_Obj19 self.model = model_Obj20 self._connect_signals()21 # Check if email is already loaded and if so, clear email msg22 if self.model.getEmail():23 self.view.messages[0].setText("")24 def _check_Enter(self) -> None:25 """Checks text field input and enters data into NovelAlertsModel object."""26 # Checks if the textFields have input and gets rid of QLabel messages once email and password are entered27 if self.view.textFields[self.TYPES[0]].text():28 self.model.setEmail(self.view.textFields[self.TYPES[0]].text())29 self.view.messages[0].setText("")30 self.view.clearLineEdit(self.view.textFields[self.TYPES[0]])31 if self.view.textFields[self.TYPES[1]].text():32 self.model.setPassword(self.view.textFields[self.TYPES[1]].text())33 self.view.messages[1].setText("")34 self.view.clearLineEdit(self.view.textFields[self.TYPES[1]])35 if self.view.textFields[self.TYPES[2]].text():36 self.model.addURLData(self.view.textFields[self.TYPES[2]].text())37 self.view.clearLineEdit(self.view.textFields[self.TYPES[2]])38 def _check_Delete(self) -> None:39 """Checks input from textFields and only deletes URL data, otherwise an error message is displayed."""40 # Checks if textFields have input and clears text fields if there is input41 if self.view.textFields[self.TYPES[0]].text():42 self.view.msgBox("ERROR: Cannot delete email, only enter in new one!")43 self.view.clearLineEdit(self.view.textFields[self.TYPES[0]])44 if self.view.textFields[self.TYPES[1]].text():45 self.view.msgBox("ERROR: Cannot delete password, only enter in new one!")46 self.view.clearLineEdit(self.view.textFields[self.TYPES[1]])47 if self.view.textFields[self.TYPES[2]].text():48 self.model.deleteURLData(self.view.textFields[self.TYPES[2]].text())49 self.view.clearLineEdit(self.view.textFields[self.TYPES[2]])50 def _connect_signals(self) -> None:51 """Connects the button signals to the _checkEnter and _checkDelete slots/methods."""52 self.view.buttons[0].clicked.connect(lambda: self._check_Enter())...

Full Screen

Full Screen

appium_test1.py

Source:appium_test1.py Github

copy

Full Screen

1import os2import unittest3from appium import webdriver4from time import sleep5PATH = lambda p: os.path.abspath(6 os.path.join(os.path.dirname(__file__),p)7)8class Test1Appium(unittest.TestCase):9 def setUp(self):10 desired_caps = {}11 desired_caps['platformName'] = 'Android'12 desired_caps['deviceName'] = 'Genymotion Cloud'13 desired_caps['app'] = PATH('ContactManager.apk')14 desired_caps['udid'] = 'localhost:10000'15 desired_caps['appPackage'] = 'com.example.android.contactmanager'16 desired_caps['appActivity'] = 'com.example.android.contactmanager.ContactManager'17 self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)18 self.driver.implicitly_wait(2)19 def tearDown(self):20 self.driver.quit()21 def testForm(self):22 self.driver.is_app_installed('com.example.android.contactmanager')23 self.driver.find_element_by_class_name('android.widget.Button').click()24 textfields = self.driver.find_elements_by_class_name('android.widget.EditText')25 textfields[0].send_keys('Jacek z Przypadkowa')26 textfields[1].send_keys('333222111')27 textfields[2].send_keys('jacek1@cdv.pl')28 sleep(1)29 print(textfields[0])30 print(textfields[0].text)31 self.assertEqual(textfields[0].text, "Jacek z Przypadkowa")32 self.assertEqual(textfields[1].text, "333222111")33 self.assertEqual(textfields[2].text, "jacek1@cdv.pl")34 sleep(1)35 self.assertEqual(textfields[0].text, "Jacek z Przypadkowa")36 self.assertEqual(textfields[1].text, "333222111")37 self.assertEqual(textfields[2].text, "jacek1@cdv.pl")38 self.driver.find_element_by_id('com.example.android.contactmanager:id/contactSaveButton').click()39 errorText = self.driver.find_element_by_id('android:id/alertTitle').text40 self.assertTrue('Contact Manager has stopped' in errorText)41 sleep(3)42if __name__ == 'main':43 suite = unittest.TestLoader().loadTestsFromTestCase(Test1Appium)...

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