How to use add_event method in Slash

Best Python code snippet using slash

test_building.py

Source:test_building.py Github

copy

Full Screen

...187class EventHandler:188 def __init__(self):189 self.events = []190 self.elapsed = 0191 def add_event(self, time, func):192 self.events.append((time, func))193 self.events.sort(key=lambda x: x[0], reverse=True)194 def run(self):195 self.start_time = rospy.Time.now()196 r = rospy.Rate(15)197 while not rospy.is_shutdown() and len(self.events) > 0:198 if (rospy.Time.now() - self.start_time) >= self.events[-1][0]:199 self.events[-1][1]()200 print "calling function:",(self.start_time + self.events[-1][0]).to_sec()201 self.events.pop()202 r.sleep()203 print rospy.Time.now().to_sec()204if __name__=="__main__":205 rospy.init_node('test_building')206 r = rospkg.RosPack()207 f = open(r.get_path("test_building") + "/config/test_building.yaml")208 y = yaml.load(f)209 f.close()210 for door in y['doors']:211 door.setup()212 # for person in y['people']:213 # person.setup(y['doors'])214 e = EventHandler()215 # for i in range(len(y['doors'])):216 # e.add_event(rospy.Duration(0), lambda :y['doors'][i].close_door())217 # e.add_event(rospy.Duration(2), lambda :y['doors'][i].open_door())218 # e.add_event(rospy.Duration(10), lambda :y['doors'][i].close_door())219 e.add_event(rospy.Duration(0), lambda :y['doors'][0].open_door())220 e.add_event(rospy.Duration(0), lambda :y['doors'][1].open_door())221 e.add_event(rospy.Duration(0), lambda :y['doors'][2].open_door())222 e.add_event(rospy.Duration(0), lambda :y['doors'][3].open_door())223 e.add_event(rospy.Duration(0), lambda :y['doors'][4].open_door())224 e.add_event(rospy.Duration(0), lambda :y['doors'][5].open_door())225 e.add_event(rospy.Duration(0), lambda :y['doors'][6].open_door())226 e.add_event(rospy.Duration(0), lambda :y['doors'][7].open_door())227 e.add_event(rospy.Duration(0), lambda :y['doors'][8].open_door())228 e.add_event(rospy.Duration(0), lambda :y['doors'][9].open_door())229 e.add_event(rospy.Duration(0), lambda :y['doors'][10].open_door())230 e.add_event(rospy.Duration(0), lambda :y['doors'][11].open_door())231 # e.add_event(rospy.Duration(0), lambda :y['doors'][0].open_door())232 # e.add_event(rospy.Duration(20), lambda :y['doors'][0].close_door())233 # e.add_event(rospy.Duration(40), lambda :y['doors'][0].open_door())234 # e.add_event(rospy.Duration(60), lambda :y['doors'][0].close_door())235 # e.add_event(rospy.Duration(0), lambda :y['doors'][1].close_door())236 # e.add_event(rospy.Duration(20), lambda :y['doors'][1].open_door())237 # e.add_event(rospy.Duration(40), lambda :y['doors'][1].close_door())238 # e.add_event(rospy.Duration(60), lambda :y['doors'][1].close_door())239 # e.add_event(rospy.Duration(0), lambda :y['doors'][2].open_door())240 # e.add_event(rospy.Duration(20), lambda :y['doors'][2].open_door())241 # e.add_event(rospy.Duration(40), lambda :y['doors'][2].close_door())242 # e.add_event(rospy.Duration(60), lambda :y['doors'][2].close_door())243 # e.add_event(rospy.Duration(0), lambda :y['doors'][3].open_door())244 # e.add_event(rospy.Duration(20), lambda :y['doors'][3].close_door())245 # e.add_event(rospy.Duration(40), lambda :y['doors'][3].open_door())246 # e.add_event(rospy.Duration(60), lambda :y['doors'][3].close_door())247 # e.add_event(rospy.Duration(0), lambda :y['doors'][4].open_door())248 # e.add_event(rospy.Duration(20), lambda :y['doors'][4].open_door())249 # e.add_event(rospy.Duration(40), lambda :y['doors'][4].close_door())250 # e.add_event(rospy.Duration(60), lambda :y['doors'][4].open_door())251 # e.add_event(rospy.Duration(0), lambda :y['doors'][5].close_door())252 # e.add_event(rospy.Duration(20), lambda :y['doors'][5].close_door())253 # e.add_event(rospy.Duration(40), lambda :y['doors'][5].close_door())254 # e.add_event(rospy.Duration(60), lambda :y['doors'][5].close_door())255 # e.add_event(rospy.Duration(0), lambda :y['doors'][6].close_door())256 # e.add_event(rospy.Duration(20), lambda :y['doors'][6].close_door())257 # e.add_event(rospy.Duration(40), lambda :y['doors'][6].close_door())258 # e.add_event(rospy.Duration(60), lambda :y['doors'][6].close_door())259 # e.add_event(rospy.Duration(0), lambda :y['doors'][7].close_door())260 # e.add_event(rospy.Duration(20), lambda :y['doors'][7].open_door())261 # e.add_event(rospy.Duration(40), lambda :y['doors'][7].close_door())262 # e.add_event(rospy.Duration(60), lambda :y['doors'][7].open_door())263 # e.add_event(rospy.Duration(0), lambda :y['doors'][8].close_door())264 # e.add_event(rospy.Duration(20), lambda :y['doors'][8].close_door())265 # e.add_event(rospy.Duration(40), lambda :y['doors'][8].open_door())266 # e.add_event(rospy.Duration(60), lambda :y['doors'][8].close_door())267 # e.add_event(rospy.Duration(0), lambda :y['doors'][9].open_door())268 # e.add_event(rospy.Duration(20), lambda :y['doors'][9].close_door())269 # e.add_event(rospy.Duration(40), lambda :y['doors'][9].close_door())270 # e.add_event(rospy.Duration(60), lambda :y['doors'][9].close_door())271 # e.add_event(rospy.Duration(0), lambda :y['doors'][10].close_door())272 # e.add_event(rospy.Duration(20), lambda :y['doors'][10].close_door())273 # e.add_event(rospy.Duration(40), lambda :y['doors'][10].open_door())274 # e.add_event(rospy.Duration(60), lambda :y['doors'][10].open_door())275 # e.add_event(rospy.Duration(0), lambda :y['doors'][11].open_door())276 # e.add_event(rospy.Duration(20), lambda :y['doors'][11].open_door())277 # e.add_event(rospy.Duration(40), lambda :y['doors'][11].close_door())278 # e.add_event(rospy.Duration(60), lambda :y['doors'][11].close_door())279 # e.add_event(rospy.Duration(0), lambda :y['doors'][12].open_door())280 # e.add_event(rospy.Duration(20), lambda :y['doors'][12].open_door())281 # e.add_event(rospy.Duration(40), lambda :y['doors'][12].open_door())282 # e.add_event(rospy.Duration(60), lambda :y['doors'][12].close_door())283 # e.add_event(rospy.Duration(0), lambda :y['people'][0].move_to_end())284 # e.add_event(rospy.Duration(0), lambda :y['doors'][10].open_door())285 # e.add_event(rospy.Duration(2), lambda :y['people'][1].move_to_end())286 # e.add_event(rospy.Duration(2), lambda :y['people'][2].move_to_end())287 # e.add_event(rospy.Duration(2), lambda :y['people'][3].move_to_end())288 # e.add_event(rospy.Duration(5), lambda :y['people'][4].move_to_end())289 # e.add_event(rospy.Duration(5), lambda :y['people'][5].move_to_end())290 # e.add_event(rospy.Duration(5), lambda :y['people'][6].move_to_end())291 # e.add_event(rospy.Duration(9), lambda :y['people'][7].move_to_end())292 # e.add_event(rospy.Duration(9), lambda :y['people'][8].move_to_end())293 # e.add_event(rospy.Duration(9), lambda :y['people'][9].move_to_end())294 # e.add_event(rospy.Duration(13), lambda :y['doors'][10].close_door())295 m = MobileRobot("/robot_13")296 # rospy.sleep(5)297 e.run()298 # y['doors'][8].open_door()299 # for person in y['people']:300 # person.loop_outandback()301 # close all the doors302 # for door in y['doors']:303 # door.setup()304 # door.close_door()305 # for door in y['doors']:306 # while door.is_active() and not rospy.is_shutdown():307 # pass308 print "done\n"...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...35 self.ui = UI()36 self.calc = Calc()37 form = self.ui.Form38 self.answer = form.lbl_answer39 self.add_event(form.btn_0, 'clicked', lambda: self.oninput('0'))40 self.add_event(form.btn_1, 'clicked', lambda: self.oninput('1'))41 self.add_event(form.btn_2, 'clicked', lambda: self.oninput('2'))42 self.add_event(form.btn_3, 'clicked', lambda: self.oninput('3'))43 self.add_event(form.btn_4, 'clicked', lambda: self.oninput('4'))44 self.add_event(form.btn_5, 'clicked', lambda: self.oninput('5'))45 self.add_event(form.btn_6, 'clicked', lambda: self.oninput('6'))46 self.add_event(form.btn_7, 'clicked', lambda: self.oninput('7'))47 self.add_event(form.btn_8, 'clicked', lambda: self.oninput('8'))48 self.add_event(form.btn_9, 'clicked', lambda: self.oninput('9'))49 self.add_event(form.btn_plus, 'clicked', lambda: self.oninput('+'))50 self.add_event(form.btn_minus, 'clicked', lambda: self.oninput('-'))51 self.add_event(form.btn_mult, 'clicked', lambda: self.oninput('*'))52 self.add_event(form.btn_div, 'clicked', lambda: self.oninput('/'))53 self.add_event(form.btn_equals, 'clicked', lambda: self.onequals())54 self.add_event(form.btn_clear, 'clicked', lambda: self.onclear())55 self.add_event(form.btn_left_bracket, 'clicked', lambda: self.oninput('('))56 self.add_event(form.btn_right_bracket, 'clicked', lambda: self.oninput(')'))57 self.add_event(form.btn_square_root, 'clicked', lambda: self.oninput('sqrt('))58 self.add_event(form.btn_square_power, 'clicked', lambda: self.oninput('**2'))59 self.add_event(form.btn_dot, 'clicked', lambda: self.oninput('.'))60 self.add_event(form.btn_backspace, 'clicked', lambda: self.onbackspace())61 62 def refreshText(self, answer = None):63 if answer == None: self.answer.setText(self.calc.input)64 else: self.answer.setText(str(answer))65 def onbackspace(self):66 self.calc.backspace()67 self.refreshText()68 def oninput(self, sym):69 self.calc.add(sym)70 self.refreshText()71 72 def onequals(self):73 self.refreshText(self.calc.equals())74 75 def onclear(self):76 self.calc.clear() 77 self.refreshText()78 79 def start_app(self):80 self.ui.show_window()81 self.app.exec()82 def add_event(self, obj, name_event, handler):83 obj_event = getattr(obj, name_event)84 obj_event.connect(handler)85app = App()...

Full Screen

Full Screen

cronograma.py

Source:cronograma.py Github

copy

Full Screen

2from schedule import *3from datetime import *4start = date(2017, 3, 6)5schedule = Schedule(start, 2, [0, 2])6schedule.add_event(Event(description = 'Apresentação do curso'))7schedule.add_event(Event(description = 'Ferramentas'))8schedule.add_event(Event(description = 'Introdução ao Python'))9schedule.add_event(Event(description = 'Introdução ao Python científico'))10schedule.add_event(Event(description = 'Zeros de Funções'))11schedule.add_event(Event(description = 'Zeros de Funções'))12schedule.add_event(Event(description = 'Mínimo de funções'))13schedule.add_event(Event(description = 'Mínimo de funções de várias variáveis'))14schedule.add_event(Event(description = 'Interpolação'))15schedule.add_event(Event(description = 'Splines'))16schedule.add_event(Event(description = 'Ajuste de curvas: retas e mínimos quadrados'))17schedule.add_event(Event(description = 'Mínimos quadrados em modelos arbitrários'))18schedule.add_event(Event(description = 'Revisão'))19schedule.add_event(Event(description = 'Prova 01', emphasis=True, code=-1))20schedule.add_event(Event(description = 'Resolução da Prova 01'))21schedule.add_event(Event(description = 'Resolução de sistemas lineares'))22schedule.add_event(Event(description = 'Feriado', emphasis=True, code=-1))23schedule.add_event(Event(description = 'Formas matriciais especiais'))24schedule.add_event(Event(description = 'Métodos iterativos de fatoração'))25schedule.add_event(Event(description = 'Comparação de desempenho'))26schedule.add_event(Event(description = 'Integração numérica'))27schedule.add_event(Event(description = 'Regras avançadas de integração numérica'))28schedule.add_event(Event(description = 'Erro de regras de quadratura'))29schedule.add_event(Event(description = 'Soluções numéricas de EDO'))30schedule.add_event(Event(description = 'Métodos Runge-Kutta'))31schedule.add_event(Event(description = 'Sistemas de EDO'))32schedule.add_event(Event(description = 'Aplicações a sistemas físicos'))33schedule.add_event(Event(description = 'Método das diferenças finitas'))34schedule.add_event(Event(description = 'Fontes de erros'))35schedule.add_event(Event(description = 'Revisão'))36schedule.add_event(Event(description = 'Prova 02', emphasis=True, code=-1))37schedule.add_event(Event(description = 'Resolução da Prova 02'))38schedule.add_event(Event(description = 'Revisão de Provas', code=-1))39schedule.add_event(Event(description = 'Prova Substitutiva', emphasis=True, code=-1))40schedule.add_event(Event(description =41 'Menções Finais. Revisão de notas', code=-1))42schedule.add_event(Event(description =43 'Submissão das menções finais no sistema acadêmico', code=-1))...

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 Slash 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