How to use on_close method in ATX

Best Python code snippet using ATX

posteffect.py

Source:posteffect.py Github

copy

Full Screen

...273 274 if self.fade>=1.0 and not self.on_close is None: # sanity check275 print("End FadeInOverlay anim")276 277 self.on_close(self)278 self.on_close = None279 280 281class FadeOutOverlay(PostFXOverlay):282 """A special overlay to fade from the normal view to a specific color"""283 def __init__(self,fade_time=1.0,fade_end=defaults.fade_stop,on_close=None,draworder=900):284 """285 Construct a FadeOverlay.286 287 Parameters:288 fade_time -- Time to life289 fade_end -- Fade intensity to end at290 on_close -- Closure to be called when the end status of the291 animation has been reached. Pass None to let the 292 overlay automatically unregister itself.293 draworder -- Draw order ordinal294 295 """296 PostFXOverlay.__init__(self,PostFXCache.Get("fade.sfx",()),draworder)297 self.fade_time = fade_time298 self.fade_end = fade_end299 self.fade = 1.0300 self.on_close = (lambda x:Renderer.RemoveDrawable(x)) if on_close is None else on_close 301 302 def GetCurrentStrength(self):303 return self.fade304 305 def Draw(self):306 PostFXOverlay.Draw(self)307 308 if not hasattr(self,"clock"):309 print("Begin FadeOutOverlay anim")310 self.clock = sf.Clock()311 312 curtime = self.clock.GetElapsedTime()313 self.fade = max(self.fade_end, 1.0 - curtime/self.fade_time)314 self.postfx.SetParameter("fade",self.fade)315 316 if self.fade <= self.fade_end and not self.on_close is None: # sanity check317 print("End FadeOutOverlay anim")318 319 self.on_close(self)320 self.on_close = None321 322 323 324 325class BlurInOverlay(PostFXOverlay):326 """A special overlay to slowly decrease the amount of blur until the normal status is reached"""327 def __init__(self,blur_time=1.0,blur_start=defaults.blur_stop,on_close=None,draworder=910):328 """329 Construct a BlurOverlay.330 331 Parameters:332 blur_time -- Time to life333 blur_start -- Blur intensity to start with334 on_close -- Closure to be called when the end status of the335 animation has been reached. Pass None to let the 336 overlay automatically unregister itself.337 draworder -- Draw order ordinal338 339 """340 PostFXOverlay.__init__(self,PostFXCache.Get("blur_x.sfx",()),draworder)341 self.postfx2 = PostFXCache.Get("blur_y.sfx",())342 assert self.postfx2343 344 self.blur_time = blur_time345 self.blur = self.blur_start = blur_start346 self.on_close = (lambda x:Renderer.RemoveDrawable(x)) if on_close is None else on_close 347 348 def GetCurrentStrength(self):349 return self.blur350 351 def Draw(self):352 PostFXOverlay.Draw(self)353 self.postfx2.Draw()354 355 if not hasattr(self,"clock"):356 self.clock = sf.Clock()357 print("Begin BlurInOverlay anim")358 359 curtime = self.clock.GetElapsedTime()360 self.blur = min(1.0, self.blur_start + curtime/self.blur_time)361 self.postfx.SetParameter("blurSize",(1-self.blur)*defaults.blur_multiplier / defaults.resolution[0])362 self.postfx2.SetParameter("blurSize",(1-self.blur)*defaults.blur_multiplier / defaults.resolution[1])363 364 if self.blur>=1.0 and not self.on_close is None: # sanity check365 print("End BlurInOverlay anim")366 367 self.on_close(self)368 self.on_close = None369 370 371class BlurOutOverlay(PostFXOverlay):372 """A special overlay to vlur the normal view up to a certain intensity"""373 def __init__(self,blur_time=1.0,blur_end=defaults.blur_stop,on_close=None,draworder=910):374 """375 Construct a BlurOverlay.376 377 Parameters:378 blur_time -- Time to life379 blur_end -- Blur intensity to end at380 on_close -- Closure to be called when the end status of the381 animation has been reached. Pass None to let the 382 overlay automatically unregister itself.383 draworder -- Draw order ordinal384 385 """386 PostFXOverlay.__init__(self,PostFXCache.Get("blur_x.sfx",()),draworder)387 self.postfx2 = PostFXCache.Get("blur_y.sfx",())388 assert self.postfx2389 390 self.blur_time = blur_time391 self.blur_end = blur_end392 self.blur = 1.0393 self.on_close = (lambda x:Renderer.RemoveDrawable(x)) if on_close is None else on_close 394 395 def GetCurrentStrength(self):396 return self.blur397 398 def Draw(self):399 PostFXOverlay.Draw(self)400 self.postfx2.Draw()401 402 if not hasattr(self,"clock"):403 print("Begin BlurOutOverlay anim")404 self.clock = sf.Clock()405 406 curtime = self.clock.GetElapsedTime()407 self.blur = max(self.blur_end, 1.0 - curtime/self.blur_time)408 self.postfx.SetParameter("blurSize",(1-self.blur)*defaults.blur_multiplier / defaults.resolution[0])409 self.postfx2.SetParameter("blurSize",(1-self.blur)*defaults.blur_multiplier / defaults.resolution[1])410 411 if self.blur <= self.blur_end and not self.on_close is None: # sanity check412 print("End BlurOutOverlay anim")413 414 self.on_close(self)415 self.on_close = None416 417 418class FlashOverlay(PostFXOverlay):419 """A postprocessing overlay to apply a short color flash"""420 def __init__(self,flash_color=sf.Color.White,flash_intensity=None, flash_length=None,func=0,on_close=None,draworder=900):421 """422 Construct a FadeOverlay.423 424 Parameters:425 fade_time -- Time to life426 fade_start -- Fade intensity to start with427 on_close -- Closure to be called when the end status of the428 animation has been reached. Pass None to let the 429 overlay automatically unregister itself.430 draworder -- Draw order ordinal431 432 """433 PostFXOverlay.__init__(self,PostFXCache.Get("heat.sfx",()),draworder)434 self.flash_length = flash_length or defaults.postfx_flash_length435 self.flash_intensity = flash_intensity or defaults.postfx_flash_intensity436 self.flash_color = flash_color437 self.on_close = (lambda x:Renderer.RemoveDrawable(x)) if on_close is None else on_close 438 self.func = 0439 440 def EvalIntensity(self,t):441 if self.func == 0:442 # http://www.wolframalpha.com/input/?i=x^2*e^%28-x%29*100+for+x+%3D10443 t *= 10444 return ((t**2)*math.exp(-t)*100)/55445 elif self.func == 1:446 return t447 elif self.func == 2:448 return min(t*5,1) 449 if self.func == 3:450 # same as 0, except it's sharper451 t *= 10452 return (((t*10)**3)*math.exp(-t)*100)/55453 454 assert False455 456 457 def Draw(self):458 PostFXOverlay.Draw(self)459 460 if not hasattr(self,"clock"):461 self.clock = sf.Clock()462 print("Begin FlashOverlay anim")463 464 curtime = self.clock.GetElapsedTime()465 466 s = self.EvalIntensity(curtime/self.flash_length)*self.flash_intensity467 self.postfx.SetParameter("col_scale",s)468 self.postfx.SetParameter("col_target",self.flash_color.r*s,self.flash_color.g*s,self.flash_color.b*s)469 470 if curtime > self.flash_length and not self.on_close is None: # sanity check471 print("End FlashOverlay anim")472 473 self.on_close(self)474 self.on_close = None 475 476 477class QuickFocus(PostFXOverlay):478 """A postprocessing overlay to limit the view to a circle around the player, 479 which is gradually increased until normal size is reached again"""480 def __init__(self,player,flash_color=sf.Color.White,focus_length=None,on_close=None,draworder=700):481 482 PostFXOverlay.__init__(self,PostFXCache.Get("focusplayer.sfx",()),draworder)483 self.focus_length = focus_length or defaults.postfx_focus_length484 self.on_close = (lambda x:Renderer.RemoveDrawable(x)) if on_close is None else on_close 485 self.player = player486 487 self.postfx.SetUpdaterParam("player",player)488 489 490 def Draw(self):491 PostFXOverlay.Draw(self)492 493 if not hasattr(self,"clock"):494 self.clock = sf.Clock()495 print("Begin QuickFocus anim")496 497 curtime = self.clock.GetElapsedTime()498 self.postfx.SetParameter("amount",curtime/self.focus_length)499 self.postfx.SetParameter("aspect",defaults.resolution[0]/defaults.resolution[1])500 501 if curtime > self.focus_length and not self.on_close is None: # sanity check502 print("End QuickFocus anim")503 504 self.on_close(self)505 self.on_close = None 506 ...

Full Screen

Full Screen

dialog.py

Source:dialog.py Github

copy

Full Screen

...70 )71 def show(self, loop):72 self.loop = loop73 w = DialogOverlay(74 on_close=lambda: self.on_close(self.parent),75 on_enter=self.on_save,76 top_w=urwid.AttrMap(77 urwid.LineBox(78 self.advanced_body if self.show_advanced else self.body, self.header_text),79 "dialog"),80 bottom_w=loop.widget,81 align='center',82 width=64,83 valign='middle',84 height=11 if self.show_advanced else 885 )86 loop.widget = w87 def on_advanced(self, args, user_data):88 self.show_advanced = not self.show_advanced89 self.show(self.loop)90 def on_save(self, args=None):91 host_info = HostInfo(self.connection_name.edit_text)92 host_info.ip = self.ip.edit_text93 host_info.username = self.username.edit_text94 host_info.port = self.port.edit_text95 host_info.identity_file = self.id_file.edit_text96 host_info.dynamic_forward = self.dynamic_forward.edit_text97 host_info.local_forward = (self.local_forward_from.edit_text, self.local_forward_to.edit_text)98 host_info.remote_forward = (self.remote_forward_from.edit_text, self.remote_forward_to.edit_text)99 self.target.name = self.connection_name.edit_text100 self.target.hostinfo = host_info101 self.parent.add_child(self.target)102 self.on_close(self.target)103 def on_cancel(self, args):104 self.on_close(self.parent)105class RemoveHostDialog:106 def __init__(self, parent: Node, target: Node, on_close):107 self.parent = parent108 self.target = target109 self.on_close = on_close110 def show(self, loop):111 # Header112 header_text = urwid.Text('Remove Connection: ' + self.target.name, align='center')113 header = urwid.AttrMap(header_text, 'dialog')114 # Footer115 ok_btn = urwid.Button('Ok', self.on_ok)116 ok_btn = urwid.AttrWrap(ok_btn, 'dialog_button', 'dialog_button_focus')117 cancel_btn = urwid.Button('Cancel', self.on_cancel)118 cancel_btn = urwid.AttrWrap(cancel_btn, 'dialog_button', 'dialog_button_focus')119 footer = urwid.GridFlow([ok_btn, cancel_btn], 12, 1, 1, 'center')120 body = urwid.Filler(121 urwid.Pile([122 urwid.Text("Are you sure?"),123 urwid.Text(""),124 footer125 ])126 )127 # Layout128 layout = urwid.Frame(129 body,130 header=header131 )132 w = DialogOverlay(133 on_close=lambda: self.on_close(self.target),134 on_enter=lambda: self.on_ok(None),135 top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),136 bottom_w=loop.widget,137 align='center',138 width=40,139 valign='middle',140 height=10141 )142 loop.widget = w143 def on_ok(self, args):144 self.parent.remove_child(self.target)145 self.on_close(self.parent)146 def on_cancel(self, args):147 self.on_close(self.target)148class AddFolderDialog:149 def __init__(self, parent: Node, target: Node, on_close):150 self.parent = parent151 self.target = target152 self.on_close = on_close153 # Form Fields154 self.folder_name = urwid.Edit("Folder Name: ", target.name)155 def show(self, loop):156 # Header157 header_text = urwid.Text('Edit Folder' if self.target.name else "Add Folder", align='center')158 header = urwid.AttrMap(header_text, 'dialog')159 # Footer160 save_btn = urwid.Button('Save', self.on_save)161 save_btn = urwid.AttrWrap(save_btn, 'dialog_button', 'dialog_button_focus')162 cancel_btn = urwid.Button('Cancel', self.on_cancel)163 cancel_btn = urwid.AttrWrap(cancel_btn, 'dialog_button', 'dialog_button_focus')164 footer = urwid.GridFlow([save_btn, cancel_btn], 12, 1, 1, 'center')165 body = urwid.Filler(166 urwid.Pile([self.folder_name, footer])167 )168 # Layout169 layout = urwid.Frame(170 body,171 header=header)172 w = DialogOverlay(173 on_close=lambda: self.on_close(self.target),174 on_enter=self.on_save,175 top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),176 bottom_w=loop.widget,177 align='center',178 width=40,179 valign='middle',180 height=10181 )182 loop.widget = w183 def on_save(self, args=None):184 self.target.name = self.folder_name.edit_text185 self.parent.add_child(self.target)186 self.on_close(self.target)187 def on_cancel(self, args):188 self.on_close(self.parent)189class SSHListBox(urwid.ListBox):190 def __init__(self, on_enter, **kwargs):191 self.on_enter = on_enter192 super(SSHListBox, self).__init__(**kwargs)193 def keypress(self, size, key):194 if key == "enter":195 self.on_enter()196 else:197 return super(SSHListBox, self).keypress(size, key)198class CopySSHKeyDialog:199 def __init__(self, target: Node, on_close, change_log):200 self.target = target201 self.on_close = on_close202 self.change_log = change_log203 # Form Fields204 self.ssh_keys_walker = urwid.SimpleListWalker(205 self.prepare_ssh_list_elements()206 )207 def show(self, loop):208 # Header209 header_text = urwid.Text('Select Public SSH Key to Copy', align='center')210 header = urwid.AttrMap(header_text, 'dialog')211 cancel_btn = urwid.Button('Cancel', self.on_cancel)212 cancel_btn = urwid.AttrWrap(cancel_btn, 'dialog_button', 'dialog_button_focus')213 footer = urwid.GridFlow([cancel_btn], 12, 1, 1, 'center')214 list_box = urwid.BoxAdapter(SSHListBox(on_enter=self.on_copy, body=self.ssh_keys_walker), 5)215 body = urwid.Filler(216 urwid.Pile([list_box, footer])217 )218 # Layout219 layout = urwid.Frame(220 body=body,221 header=header)222 layout = urwid.AttrWrap(layout, 'dialog')223 w = DialogOverlay(224 on_close=lambda: self.on_close(),225 on_enter=self.on_copy,226 top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),227 bottom_w=loop.widget,228 align='center',229 width=40,230 valign='middle',231 height=10232 )233 loop.widget = w234 def on_copy(self, args=None):235 ssh_files_path = os.path.join(expanduser("~"), '.ssh/')236 selected_ssh_key = os.path.join(ssh_files_path, self.ssh_keys_walker.get_focus()[0].original_widget.text)237 command = self.target.hostinfo.get_ssh_copy_command(selected_ssh_key)238 self.on_close(command)239 def on_cancel(self, args):240 self.change_log(None)241 self.on_close()242 def prepare_ssh_list_elements(self):243 ssh_keys = []244 for key in get_public_ssh_keys():245 ssh_keys.append(urwid.AttrWrap(SelectableText(os.path.basename(key)), 'ssh_copy', 'ssh_copy_focus'))246 return ssh_keys247class MessageDialog:248 def __init__(self, title, message, on_close):249 self.title = title250 self.message = message251 self.on_close = on_close252 def show(self, loop):253 # Header254 header_text = urwid.Text(self.title, align='center')255 header = urwid.AttrMap(header_text, 'dialog')256 # Footer257 ok_btn = urwid.Button('Ok', self.on_ok)258 ok_btn = urwid.AttrWrap(ok_btn, 'dialog_button', 'dialog_button_focus')259 footer = urwid.GridFlow([ok_btn], 12, 1, 1, 'center')260 body = urwid.Filler(261 urwid.Pile([262 urwid.Text(self.message),263 urwid.Text(""),264 footer265 ])266 )267 # Layout268 layout = urwid.Frame(269 body,270 header=header271 )272 w = DialogOverlay(273 on_close=self.on_close,274 on_enter=self.on_ok,275 top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),276 bottom_w=loop.widget,277 align='center',278 width=40,279 valign='middle',280 height=10281 )282 loop.widget = w283 def on_ok(self, args=None):284 self.on_close()285class DialogOverlay(urwid.Overlay):286 def __init__(self, on_close, on_enter, **kwargs):287 self.on_close = on_close288 self.on_enter = on_enter289 super(DialogOverlay, self).__init__(**kwargs)290 def keypress(self, size, key):291 if key == 'shift tab':292 key = 'up'293 elif key == 'tab':294 key = 'down'295 elif key == 'esc':296 self.on_close()297 # TODO: implement, save with "enter"...

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