Best Python code snippet using ATX
screenmanager.py
Source:screenmanager.py
...276 self.manager = manager277 self._anim = Animation(d=self.duration, s=0)278 self._anim.bind(on_progress=self._on_progress,279 on_complete=self._on_complete)280 self.add_screen(self.screen_in)281 self.screen_in.transition_progress = 0.282 self.screen_in.transition_state = 'in'283 self.screen_out.transition_progress = 0.284 self.screen_out.transition_state = 'out'285 self.screen_in.dispatch('on_pre_enter')286 self.screen_out.dispatch('on_pre_leave')287 self.is_active = True288 self._anim.start(self)289 self.dispatch('on_progress', 0)290 def stop(self):291 '''(internal) Stops the transition. This is automatically called by the292 :class:`ScreenManager`.293 '''294 if self._anim:295 self._anim.cancel(self)296 self.dispatch('on_complete')297 self._anim = None298 self.is_active = False299 def add_screen(self, screen):300 '''(internal) Used to add a screen to the :class:`ScreenManager`.301 '''302 self.manager.real_add_widget(screen)303 def remove_screen(self, screen):304 '''(internal) Used to remove a screen from the :class:`ScreenManager`.305 '''306 self.manager.real_remove_widget(screen)307 def on_complete(self):308 self.remove_screen(self.screen_out)309 def on_progress(self, progression):310 pass311 def _on_progress(self, *l):312 progress = l[-1]313 self.screen_in.transition_progress = progress314 self.screen_out.transition_progress = 1. - progress315 self.dispatch('on_progress', progress)316 def _on_complete(self, *l):317 self.is_active = False318 self.dispatch('on_complete')319 self.screen_in.dispatch('on_enter')320 self.screen_out.dispatch('on_leave')321 self._anim = None322class ShaderTransition(TransitionBase):323 '''Transition class that uses a Shader for animating the transition between324 2 screens. By default, this class doesn't assign any fragment/vertex325 shader. If you want to create your own fragment shader for the transition,326 you need to declare the header yourself and include the "t", "tex_in" and327 "tex_out" uniform::328 # Create your own transition. This shader implements a "fading"329 # transition.330 fs = """$HEADER331 uniform float t;332 uniform sampler2D tex_in;333 uniform sampler2D tex_out;334 void main(void) {335 vec4 cin = texture2D(tex_in, tex_coord0);336 vec4 cout = texture2D(tex_out, tex_coord0);337 gl_FragColor = mix(cout, cin, t);338 }339 """340 # And create your transition341 tr = ShaderTransition(fs=fs)342 sm = ScreenManager(transition=tr)343 '''344 fs = StringProperty(None)345 '''Fragment shader to use.346 :attr:`fs` is a :class:`~kivy.properties.StringProperty` and defaults to347 None.'''348 vs = StringProperty(None)349 '''Vertex shader to use.350 :attr:`vs` is a :class:`~kivy.properties.StringProperty` and defaults to351 None.'''352 clearcolor = ColorProperty([0, 0, 0, 1])353 '''Sets the color of Fbo ClearColor.354 .. versionadded:: 1.9.0355 :attr:`clearcolor` is a :class:`~kivy.properties.ColorProperty`356 and defaults to [0, 0, 0, 1].357 .. versionchanged:: 2.0.0358 Changed from :class:`~kivy.properties.ListProperty` to359 :class:`~kivy.properties.ColorProperty`.360 '''361 def make_screen_fbo(self, screen):362 fbo = Fbo(size=screen.size, with_stencilbuffer=True)363 with fbo:364 ClearColor(*self.clearcolor)365 ClearBuffers()366 fbo.add(screen.canvas)367 with fbo.before:368 PushMatrix()369 Translate(-screen.x, -screen.y, 0)370 with fbo.after:371 PopMatrix()372 return fbo373 def on_progress(self, progress):374 self.render_ctx['t'] = progress375 def on_complete(self):376 self.render_ctx['t'] = 1.377 super(ShaderTransition, self).on_complete()378 def _remove_out_canvas(self, *args):379 if (self.screen_out and380 self.screen_out.canvas in self.manager.canvas.children and381 self.screen_out not in self.manager.children):382 self.manager.canvas.remove(self.screen_out.canvas)383 def add_screen(self, screen):384 self.screen_in.pos = self.screen_out.pos385 self.screen_in.size = self.screen_out.size386 self.manager.real_remove_widget(self.screen_out)387 self.manager.canvas.add(self.screen_out.canvas)388 def remove_screen_out(instr):389 Clock.schedule_once(self._remove_out_canvas, -1)390 self.render_ctx.remove(instr)391 self.fbo_in = self.make_screen_fbo(self.screen_in)392 self.fbo_out = self.make_screen_fbo(self.screen_out)393 self.manager.canvas.add(self.fbo_in)394 self.manager.canvas.add(self.fbo_out)395 self.render_ctx = RenderContext(fs=self.fs, vs=self.vs,396 use_parent_modelview=True,397 use_parent_projection=True)398 with self.render_ctx:399 BindTexture(texture=self.fbo_out.texture, index=1)400 BindTexture(texture=self.fbo_in.texture, index=2)401 x, y = self.screen_in.pos402 w, h = self.fbo_in.texture.size403 Rectangle(size=(w, h), pos=(x, y),404 tex_coords=self.fbo_in.texture.tex_coords)405 Callback(remove_screen_out)406 self.render_ctx['tex_out'] = 1407 self.render_ctx['tex_in'] = 2408 self.manager.canvas.add(self.render_ctx)409 def remove_screen(self, screen):410 self.manager.canvas.remove(self.fbo_in)411 self.manager.canvas.remove(self.fbo_out)412 self.manager.canvas.remove(self.render_ctx)413 self._remove_out_canvas()414 self.manager.real_add_widget(self.screen_in)415 def stop(self):416 self._remove_out_canvas()417 super(ShaderTransition, self).stop()418class NoTransition(TransitionBase):419 '''No transition, instantly switches to the next screen with no delay or420 animation.421 .. versionadded:: 1.8.0422 '''423 duration = NumericProperty(0.0)424 def on_complete(self):425 self.screen_in.pos = self.manager.pos426 self.screen_out.pos = self.manager.pos427 super(NoTransition, self).on_complete()428class SlideTransition(TransitionBase):429 '''Slide Transition, can be used to show a new screen from any direction:430 left, right, up or down.431 '''432 direction = OptionProperty('left', options=('left', 'right', 'up', 'down'))433 '''Direction of the transition.434 :attr:`direction` is an :class:`~kivy.properties.OptionProperty` and435 defaults to 'left'. Can be one of 'left', 'right', 'up' or 'down'.436 '''437 def on_progress(self, progression):438 a = self.screen_in439 b = self.screen_out440 manager = self.manager441 x, y = manager.pos442 width, height = manager.size443 direction = self.direction444 al = AnimationTransition.out_quad445 progression = al(progression)446 if direction == 'left':447 a.y = b.y = y448 a.x = x + width * (1 - progression)449 b.x = x - width * progression450 elif direction == 'right':451 a.y = b.y = y452 b.x = x + width * progression453 a.x = x - width * (1 - progression)454 elif direction == 'down':455 a.x = b.x = x456 a.y = y + height * (1 - progression)457 b.y = y - height * progression458 elif direction == 'up':459 a.x = b.x = x460 b.y = y + height * progression461 a.y = y - height * (1 - progression)462 def on_complete(self):463 self.screen_in.pos = self.manager.pos464 self.screen_out.pos = self.manager.pos465 super(SlideTransition, self).on_complete()466class CardTransition(SlideTransition):467 '''Card transition that looks similar to Android 4.x application drawer468 interface animation.469 It supports 4 directions like SlideTransition: left, right, up and down,470 and two modes, pop and push. If push mode is activated, the previous471 screen does not move, and the new one slides in from the given direction.472 If the pop mode is activated, the previous screen slides out, when the new473 screen is already on the position of the ScreenManager.474 .. versionadded:: 1.10475 '''476 mode = OptionProperty('push', options=['pop', 'push'])477 '''Indicates if the transition should push or pop478 the screen on/off the ScreenManager.479 - 'push' means the screen slides in in the given direction480 - 'pop' means the screen slides out in the given direction481 :attr:`mode` is an :class:`~kivy.properties.OptionProperty` and482 defaults to 'push'.483 '''484 def start(self, manager):485 '''(internal) Starts the transition. This is automatically486 called by the :class:`ScreenManager`.487 '''488 super(CardTransition, self).start(manager)489 mode = self.mode490 a = self.screen_in491 b = self.screen_out492 # ensure that the correct widget is "on top"493 if mode == 'push':494 manager.canvas.remove(a.canvas)495 manager.canvas.add(a.canvas)496 elif mode == 'pop':497 manager.canvas.remove(b.canvas)498 manager.canvas.add(b.canvas)499 def on_progress(self, progression):500 a = self.screen_in501 b = self.screen_out502 manager = self.manager503 x, y = manager.pos504 width, height = manager.size505 direction = self.direction506 mode = self.mode507 al = AnimationTransition.out_quad508 progression = al(progression)509 if mode == 'push':510 b.pos = x, y511 if direction == 'left':512 a.pos = x + width * (1 - progression), y513 elif direction == 'right':514 a.pos = x - width * (1 - progression), y515 elif direction == 'down':516 a.pos = x, y + height * (1 - progression)517 elif direction == 'up':518 a.pos = x, y - height * (1 - progression)519 elif mode == 'pop':520 a.pos = x, y521 if direction == 'left':522 b.pos = x - width * progression, y523 elif direction == 'right':524 b.pos = x + width * progression, y525 elif direction == 'down':526 b.pos = x, y - height * progression527 elif direction == 'up':528 b.pos = x, y + height * progression529class SwapTransition(TransitionBase):530 '''Swap transition that looks like iOS transition when a new window531 appears on the screen.532 '''533 def __init__(self, **kwargs):534 super(SwapTransition, self).__init__(**kwargs)535 self.scales = {}536 def start(self, manager):537 for screen in self.screen_in, self.screen_out:538 with screen.canvas.before:539 PushMatrix(group='swaptransition_scale')540 scale = Scale(group='swaptransition_scale')541 with screen.canvas.after:542 PopMatrix(group='swaptransition_scale')543 screen.bind(center=self.update_scale)544 self.scales[screen] = scale545 super(SwapTransition, self).start(manager)546 def update_scale(self, screen, center):547 self.scales[screen].origin = center548 def add_screen(self, screen):549 self.manager.real_add_widget(screen, 1)550 def on_complete(self):551 self.screen_in.pos = self.manager.pos552 self.screen_out.pos = self.manager.pos553 for screen in self.screen_in, self.screen_out:554 for canvas in screen.canvas.before, screen.canvas.after:555 canvas.remove_group('swaptransition_scale')556 super(SwapTransition, self).on_complete()557 def on_progress(self, progression):558 a = self.screen_in559 b = self.screen_out560 manager = self.manager561 self.scales[b].xyz = [1. - progression * 0.7 for xyz in 'xyz']562 self.scales[a].xyz = [0.5 + progression * 0.5 for xyz in 'xyz']563 a.center_y = b.center_y = manager.center_y564 al = AnimationTransition.in_out_sine565 if progression < 0.5:566 p2 = al(progression * 2)567 width = manager.width * 0.7568 widthb = manager.width * 0.2569 a.x = manager.center_x + p2 * width / 2.570 b.center_x = manager.center_x - p2 * widthb / 2.571 else:572 if self.screen_in is self.manager.children[-1]:573 self.manager.real_remove_widget(self.screen_in)574 self.manager.real_add_widget(self.screen_in)575 p2 = al((progression - 0.5) * 2)576 width = manager.width * 0.85577 widthb = manager.width * 0.2578 a.x = manager.x + width * (1 - p2)579 b.center_x = manager.center_x - (1 - p2) * widthb / 2.580class WipeTransition(ShaderTransition):581 '''Wipe transition, based on a fragment Shader.582 '''583 WIPE_TRANSITION_FS = '''$HEADER$584 uniform float t;585 uniform sampler2D tex_in;586 uniform sampler2D tex_out;587 void main(void) {588 vec4 cin = texture2D(tex_in, tex_coord0);589 vec4 cout = texture2D(tex_out, tex_coord0);590 gl_FragColor = mix(cout, cin, clamp((-1.5 + 1.5*tex_coord0.x + 2.5*t),591 0.0, 1.0));592 }593 '''594 fs = StringProperty(WIPE_TRANSITION_FS)595class FadeTransition(ShaderTransition):596 '''Fade transition, based on a fragment Shader.597 '''598 FADE_TRANSITION_FS = '''$HEADER$599 uniform float t;600 uniform sampler2D tex_in;601 uniform sampler2D tex_out;602 void main(void) {603 vec4 cin = vec4(texture2D(tex_in, tex_coord0.st));604 vec4 cout = vec4(texture2D(tex_out, tex_coord0.st));605 vec4 frag_col = vec4(t * cin) + vec4((1.0 - t) * cout);606 gl_FragColor = frag_col;607 }608 '''609 fs = StringProperty(FADE_TRANSITION_FS)610class FallOutTransition(ShaderTransition):611 '''Transition where the new screen 'falls' from the screen centre,612 becoming smaller and more transparent until it disappears, and613 revealing the new screen behind it. Mimics the popular/standard614 Android transition.615 .. versionadded:: 1.8.0616 '''617 duration = NumericProperty(0.15)618 '''Duration in seconds of the transition, replacing the default of619 :class:`TransitionBase`.620 :class:`duration` is a :class:`~kivy.properties.NumericProperty` and621 defaults to .15 (= 150ms).622 '''623 FALLOUT_TRANSITION_FS = '''$HEADER$624 uniform float t;625 uniform sampler2D tex_in;626 uniform sampler2D tex_out;627 void main(void) {628 /* quantities for position and opacity calculation */629 float tr = 0.5*sin(t); /* 'real' time */630 vec2 diff = (tex_coord0.st - 0.5) * (1.0/(1.0-tr));631 vec2 dist = diff + 0.5;632 float max_dist = 1.0 - tr;633 /* in and out colors */634 vec4 cin = vec4(texture2D(tex_in, tex_coord0.st));635 vec4 cout = vec4(texture2D(tex_out, dist));636 /* opacities for in and out textures */637 float oin = clamp(1.0-cos(t), 0.0, 1.0);638 float oout = clamp(cos(t), 0.0, 1.0);639 bvec2 outside_bounds = bvec2(abs(tex_coord0.s - 0.5) > 0.5*max_dist,640 abs(tex_coord0.t - 0.5) > 0.5*max_dist);641 vec4 frag_col;642 if (any(outside_bounds) ){643 frag_col = vec4(cin.x, cin.y, cin.z, 1.0);644 }645 else {646 frag_col = vec4(oout*cout.x + oin*cin.x, oout*cout.y + oin*cin.y,647 oout*cout.z + oin*cin.z, 1.0);648 }649 gl_FragColor = frag_col;650 }651 '''652 fs = StringProperty(FALLOUT_TRANSITION_FS)653class RiseInTransition(ShaderTransition):654 '''Transition where the new screen rises from the screen centre,655 becoming larger and changing from transparent to opaque until it656 fills the screen. Mimics the popular/standard Android transition.657 .. versionadded:: 1.8.0658 '''659 duration = NumericProperty(0.2)660 '''Duration in seconds of the transition, replacing the default of661 :class:`TransitionBase`.662 :class:`duration` is a :class:`~kivy.properties.NumericProperty` and663 defaults to .2 (= 200ms).664 '''665 RISEIN_TRANSITION_FS = '''$HEADER$666 uniform float t;667 uniform sampler2D tex_in;668 uniform sampler2D tex_out;669 void main(void) {670 /* quantities for position and opacity calculation */671 float tr = 0.5 - 0.5*sqrt(sin(t)); /* 'real' time */672 vec2 diff = (tex_coord0.st - 0.5) * (1.0/(1.0-tr));673 vec2 dist = diff + 0.5;674 float max_dist = 1.0 - tr;675 /* in and out colors */676 vec4 cin = vec4(texture2D(tex_in, dist));677 vec4 cout = vec4(texture2D(tex_out, tex_coord0.st));678 /* opacities for in and out textures */679 float oin = clamp(sin(2.0*t), 0.0, 1.0);680 float oout = clamp(1.0 - sin(2.0*t), 0.0, 1.0);681 bvec2 outside_bounds = bvec2(abs(tex_coord0.s - 0.5) > 0.5*max_dist,682 abs(tex_coord0.t - 0.5) > 0.5*max_dist);683 vec4 frag_col;684 if (any(outside_bounds) ){685 frag_col = vec4(cout.x, cout.y, cout.z, 1.0);686 }687 else {688 frag_col = vec4(oout*cout.x + oin*cin.x, oout*cout.y + oin*cin.y,689 oout*cout.z + oin*cin.z, 1.0);690 }691 gl_FragColor = frag_col;692 }693 '''694 fs = StringProperty(RISEIN_TRANSITION_FS)695class ScreenManager(FloatLayout):696 '''Screen manager. This is the main class that will control your697 :class:`Screen` stack and memory.698 By default, the manager will show only one screen at a time.699 '''700 current = StringProperty(None, allownone=True)701 '''702 Name of the screen currently shown, or the screen to show.703 ::704 from kivy.uix.screenmanager import ScreenManager, Screen705 sm = ScreenManager()706 sm.add_widget(Screen(name='first'))707 sm.add_widget(Screen(name='second'))708 # By default, the first added screen will be shown. If you want to709 # show another one, just set the 'current' property.710 sm.current = 'second'711 :attr:`current` is a :class:`~kivy.properties.StringProperty` and defaults712 to None.713 '''714 transition = ObjectProperty(baseclass=TransitionBase)715 '''Transition object to use for animating the transition from the current716 screen to the next one being shown.717 For example, if you want to use a :class:`WipeTransition` between718 slides::719 from kivy.uix.screenmanager import ScreenManager, Screen,720 WipeTransition721 sm = ScreenManager(transition=WipeTransition())722 sm.add_widget(Screen(name='first'))723 sm.add_widget(Screen(name='second'))724 # by default, the first added screen will be shown. If you want to725 # show another one, just set the 'current' property.726 sm.current = 'second'727 :attr:`transition` is an :class:`~kivy.properties.ObjectProperty` and728 defaults to a :class:`SlideTransition`.729 .. versionchanged:: 1.8.0730 Default transition has been changed from :class:`SwapTransition` to731 :class:`SlideTransition`.732 '''733 screens = ListProperty()734 '''List of all the :class:`Screen` widgets added. You should not change735 this list manually. Use the736 :meth:`add_widget <kivy.uix.widget.Widget.add_widget>` method instead.737 :attr:`screens` is a :class:`~kivy.properties.ListProperty` and defaults to738 [], read-only.739 '''740 current_screen = ObjectProperty(None, allownone=True)741 '''Contains the currently displayed screen. You must not change this742 property manually, use :attr:`current` instead.743 :attr:`current_screen` is an :class:`~kivy.properties.ObjectProperty` and744 defaults to None, read-only.745 '''746 def _get_screen_names(self):747 return [s.name for s in self.screens]748 screen_names = AliasProperty(_get_screen_names, bind=('screens',))749 '''List of the names of all the :class:`Screen` widgets added. The list750 is read only.751 :attr:`screens_names` is an :class:`~kivy.properties.AliasProperty` and752 is read-only. It is updated if the screen list changes or the name753 of a screen changes.754 '''755 def __init__(self, **kwargs):756 if 'transition' not in kwargs:757 self.transition = SlideTransition()758 super(ScreenManager, self).__init__(**kwargs)759 self.fbind('pos', self._update_pos)760 def _screen_name_changed(self, screen, name):761 self.property('screen_names').dispatch(self)762 if screen == self.current_screen:763 self.current = name764 def add_widget(self, screen):765 if not isinstance(screen, Screen):766 raise ScreenManagerException(767 'ScreenManager accepts only Screen widget.')768 if screen.manager:769 if screen.manager is self:770 raise ScreenManagerException(771 'Screen already managed by this ScreenManager (are you '772 'calling `switch_to` when you should be setting '773 '`current`?)')774 raise ScreenManagerException(775 'Screen already managed by another ScreenManager.')776 screen.manager = self777 screen.bind(name=self._screen_name_changed)778 self.screens.append(screen)779 if self.current is None:780 self.current = screen.name781 def remove_widget(self, *l):782 screen = l[0]783 if not isinstance(screen, Screen):784 raise ScreenManagerException(785 'ScreenManager uses remove_widget only for removing Screens.')786 if screen not in self.screens:787 return788 if self.current_screen == screen:789 other = next(self)790 if screen.name == other:791 self.current = None792 screen.parent.real_remove_widget(screen)793 else:794 self.current = other795 screen.manager = None796 screen.unbind(name=self._screen_name_changed)797 self.screens.remove(screen)798 def clear_widgets(self, screens=None):799 if screens is None:800 screens = self.screens801 # iterate over a copy of screens, as self.remove_widget802 # modifies self.screens in place803 for screen in screens[:]:804 self.remove_widget(screen)805 def real_add_widget(self, screen, *args):806 # ensure screen is removed from its previous parent807 parent = screen.parent808 if parent:809 parent.real_remove_widget(screen)810 super(ScreenManager, self).add_widget(screen)811 def real_remove_widget(self, screen, *args):812 super(ScreenManager, self).remove_widget(screen)813 def on_current(self, instance, value):814 if value is None:815 self.transition.stop()816 self.current_screen = None817 return818 screen = self.get_screen(value)819 if screen == self.current_screen:820 return821 self.transition.stop()822 previous_screen = self.current_screen823 self.current_screen = screen824 if previous_screen:825 self.transition.screen_in = screen826 self.transition.screen_out = previous_screen827 self.transition.start(self)828 else:829 self.real_add_widget(screen)830 screen.pos = self.pos831 self.do_layout()832 screen.dispatch('on_pre_enter')833 screen.dispatch('on_enter')834 def get_screen(self, name):835 '''Return the screen widget associated with the name or raise a836 :class:`ScreenManagerException` if not found.837 '''838 matches = [s for s in self.screens if s.name == name]839 num_matches = len(matches)840 if num_matches == 0:841 raise ScreenManagerException('No Screen with name "%s".' % name)842 if num_matches > 1:843 Logger.warn('Multiple screens named "%s": %s' % (name, matches))844 return matches[0]845 def has_screen(self, name):846 '''Return True if a screen with the `name` has been found.847 .. versionadded:: 1.6.0848 '''849 return bool([s for s in self.screens if s.name == name])850 def __next__(self):851 '''Py2K backwards compatibility without six or other lib.852 '''853 screens = self.screens854 if not screens:855 return856 try:857 index = screens.index(self.current_screen)858 index = (index + 1) % len(screens)859 return screens[index].name860 except ValueError:861 return862 def next(self):863 '''Return the name of the next screen from the screen list.'''864 return self.__next__()865 def previous(self):866 '''Return the name of the previous screen from the screen list.867 '''868 screens = self.screens869 if not screens:870 return871 try:872 index = screens.index(self.current_screen)873 index = (index - 1) % len(screens)874 return screens[index].name875 except ValueError:876 return877 def switch_to(self, screen, **options):878 '''Add a new or existing screen to the ScreenManager and switch to it.879 The previous screen will be "switched away" from. `options` are the880 :attr:`transition` options that will be changed before the animation881 happens.882 If no previous screens are available, the screen will be used as the883 main one::884 sm = ScreenManager()885 sm.switch_to(screen1)886 # later887 sm.switch_to(screen2, direction='left')888 # later889 sm.switch_to(screen3, direction='right', duration=1.)890 If any animation is in progress, it will be stopped and replaced by891 this one: you should avoid this because the animation will just look892 weird. Use either :meth:`switch_to` or :attr:`current` but not both.893 The `screen` name will be changed if there is any conflict with the894 current screen.895 .. versionadded: 1.8.0896 '''897 assert(screen is not None)898 if not isinstance(screen, Screen):899 raise ScreenManagerException(900 'ScreenManager accepts only Screen widget.')901 # stop any transition that might be happening already902 self.transition.stop()903 # ensure the screen name will be unique904 if screen not in self.screens:905 if self.has_screen(screen.name):906 screen.name = self._generate_screen_name()907 # change the transition if given explicitly908 old_transition = self.transition909 specified_transition = options.pop("transition", None)910 if specified_transition:911 self.transition = specified_transition912 # change the transition options913 for key, value in iteritems(options):914 setattr(self.transition, key, value)915 # add and leave if we are set as the current screen916 if screen.manager is not self:917 self.add_widget(screen)918 if self.current_screen is screen:919 return920 old_current = self.current_screen921 def remove_old_screen(transition):922 if old_current in self.children:923 self.remove_widget(old_current)924 self.transition = old_transition925 transition.unbind(on_complete=remove_old_screen)926 self.transition.bind(on_complete=remove_old_screen)927 self.current = screen.name928 def _generate_screen_name(self):929 i = 0930 while True:931 name = '_screen{}'.format(i)932 if not self.has_screen(name):933 return name934 i += 1935 def _update_pos(self, instance, value):936 for child in self.children:937 if self.transition.is_active and \938 (child == self.transition.screen_in or939 child == self.transition.screen_out):940 continue941 child.pos = value942 def on_touch_down(self, touch):943 if self.transition.is_active:944 return False945 return super(ScreenManager, self).on_touch_down(touch)946 def on_touch_move(self, touch):947 if self.transition.is_active:948 return False949 return super(ScreenManager, self).on_touch_move(touch)950 def on_touch_up(self, touch):951 if self.transition.is_active:952 return False953 return super(ScreenManager, self).on_touch_up(touch)954if __name__ == '__main__':955 from kivy.app import App956 from kivy.uix.button import Button957 Builder.load_string('''958<Screen>:959 canvas:960 Color:961 rgb: .2, .2, .2962 Rectangle:963 size: self.size964 GridLayout:965 cols: 2966 Button:967 text: 'Hello world'968 Button:969 text: 'Hello world'970 Button:971 text: 'Hello world'972 Button:973 text: 'Hello world'974''')975 class TestApp(App):976 def change_view(self, *l):977 # d = ('left', 'up', 'down', 'right')978 # di = d.index(self.sm.transition.direction)979 # self.sm.transition.direction = d[(di + 1) % len(d)]980 self.sm.current = next(self.sm)981 def remove_screen(self, *l):982 self.sm.remove_widget(self.sm.get_screen('test1'))983 def build(self):984 root = FloatLayout()985 self.sm = sm = ScreenManager(transition=SwapTransition())986 sm.add_widget(Screen(name='test1'))987 sm.add_widget(Screen(name='test2'))988 btn = Button(size_hint=(None, None))989 btn.bind(on_release=self.change_view)990 btn2 = Button(size_hint=(None, None), x=100)991 btn2.bind(on_release=self.remove_screen)992 root.add_widget(sm)993 root.add_widget(btn)994 root.add_widget(btn2)995 return root996 TestApp().run()
cua_so.py
Source:cua_so.py
1import pygame2from geopy.geocoders import Nominatim3from geopy.distance import geodesic4import math56geolocator = Nominatim(user_agent="MyApp")7pygame.init()89# Create Screen10x_screen = 100011y_screen = 80012screen = pygame.display.set_mode((x_screen, y_screen))1314location_color = (255, 51, 153)15background_color = (255, 255, 255)16true_color = (0, 204, 0)17false_color = (255, 0, 0)18# Title of screen19pygame.display.set_caption("Wero - Wordle")2021# Text title22text_size_1 = 3023text_size_2 = 1524font_1 = pygame.font.SysFont("Times New Roman", text_size_1, bold=True)25font_2 = pygame.font.SysFont("Times New Roman", text_size_2, bold=True)26x_namegame = (x_screen // 2)27y_namegame = 02829wordle = font_1.render('Wordle', True, (0, 0, 0))30vietnam = font_1.render('VietNam', True, (255, 51, 153))31# running game3233game_location = 'Can Tho'34# guess_location = 'Lang Son'3536fps = 6037timer = pygame.time.Clock()383940def draw_checking_distance():41 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 10, 100, 40), 2, 5)42 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 240, y_screen // 16 + 10, 100, 40), 2, 5)43 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 30), 20, 5)44 # pygame.draw.line(screen, location_color, (x_screen// 2 + 405, y_screen//16 + 100), (x_screen// 2 + 420, y_screen//16 + 100), 4)4546 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 80, 100, 40), 2, 5)47 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 240, y_screen // 16 + 80, 100, 40), 2, 5)48 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 100), 20, 5)4950 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 150, 100, 40), 2, 5)51 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 240, y_screen // 16 + 150, 100, 40), 2, 5)52 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 170), 20, 5)5354 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 220, 100, 40), 2, 5)55 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 240, y_screen // 16 + 220, 100, 40), 2, 5)56 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 240), 20, 5)5758 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 290, 100, 40), 2, 5)59 pygame.draw.rect(screen, location_color, pygame.Rect(x_screen // 2 + 240, y_screen // 16 + 290, 100, 40), 2, 5)60 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 310), 20, 5)616263# calculate distances of 5 places64def checking_distance_1(game_location, guess_location, distance=0):65 # calculate distance66 guess = guess_location67 location_1 = geolocator.geocode(guess)68 location_2 = geolocator.geocode(game_location)69 loc1 = (location_1.latitude, location_1.longitude)70 loc2 = (location_2.latitude, location_2.longitude)71 dis = str(int(geodesic(loc1, loc2).km))72 guess1 = font_2.render(guess, True, (255, 51, 153))73 distance = font_2.render(dis, True, (255, 51, 153))74 screen.blit(guess1, guess1.get_rect(center=(x_screen // 2 + 150, y_screen // 16 + 30)))75 screen.blit(distance, distance.get_rect(center=(x_screen // 2 + 290, y_screen // 16 + 30)))76 if dis == '0':77 pygame.draw.rect(screen, true_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 10, 100, 40), 2, 5)78 else:79 pygame.draw.rect(screen, false_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 10, 100, 40), 2, 5)80 # calculate compass direction81 alpha_1 = loc1[1] * (math.pi / 180)82 alpha_2 = loc2[1] * math.pi / 18083 phi_1 = loc1[0] * math.pi / 18084 phi_2 = loc2[0] * math.pi / 18085 delta_alpha = (alpha_2 - alpha_1)86 y = math.sin(delta_alpha) * math.cos(phi_2)87 x = math.cos(phi_1) * math.sin(phi_2) - math.sin(phi_1) * math.cos(phi_2) * math.cos(delta_alpha)88 angle = math.atan2(y, x)89 bearing = int((angle * 180 / math.pi + 360) % 360)90 if '0' == dis:91 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 30), 5, 5)92 elif 0 <= bearing < 90:93 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 30),94 (x_screen // 2 + 405, y_screen // 16 + 15), 4)95 elif 90 <= bearing < 180:96 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 30),97 (x_screen // 2 + 420, y_screen // 16 + 30), 4)98 elif 180 <= bearing < 270:99 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 30),100 (x_screen // 2 + 405, y_screen // 16 + 45), 4)101 elif 270 <= bearing < 360:102 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 45),103 (x_screen // 2 + 390, y_screen // 16 + 30), 4)104 print(dis)105 print(bearing)106107108def checking_distance_2(game_location, guess_location, distance=0):109 guess = guess_location110 location_1 = geolocator.geocode(guess)111 location_2 = geolocator.geocode(game_location)112 loc1 = (location_1.latitude, location_1.longitude)113 loc2 = (location_2.latitude, location_2.longitude)114 dis = str(int(geodesic(loc1, loc2).km))115 guess1 = font_2.render(guess, True, (255, 51, 153))116 distance = font_2.render(dis, True, (255, 51, 153))117 screen.blit(guess1, guess1.get_rect(center=(x_screen // 2 + 150, y_screen // 16 + 100)))118 screen.blit(distance, distance.get_rect(center=(x_screen // 2 + 290, y_screen // 16 + 100)))119 if dis == '0':120 pygame.draw.rect(screen, true_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 80, 100, 40), 2, 5)121 else:122 pygame.draw.rect(screen, false_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 80, 100, 40), 2, 5)123124 alpha_1 = loc1[1] * (math.pi / 180)125 alpha_2 = loc2[1] * math.pi / 180126 phi_1 = loc1[0] * math.pi / 180127 phi_2 = loc2[0] * math.pi / 180128 delta_alpha = (alpha_2 - alpha_1)129 y = math.sin(delta_alpha) * math.cos(phi_2)130 x = math.cos(phi_1) * math.sin(phi_2) - math.sin(phi_1) * math.cos(phi_2) * math.cos(delta_alpha)131 angle = math.atan2(y, x)132 bearing = int((angle * 180 / math.pi + 360) % 360)133 if '0' == dis:134 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 100), 5, 5)135 elif 0 <= bearing < 90:136 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 100),137 (x_screen // 2 + 405, y_screen // 16 + 85), 4)138 elif 90 <= bearing < 180:139 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 100),140 (x_screen // 2 + 420, y_screen // 16 + 100), 4)141 elif 180 <= bearing < 270:142 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 100),143 (x_screen // 2 + 405, y_screen // 16 + 115), 4)144 elif 270 <= bearing < 360:145 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 115),146 (x_screen // 2 + 390, y_screen // 16 + 100), 4)147 print(dis)148149150def checking_distance_3(game_location, guess_location, distance=0):151 guess = guess_location152 location_1 = geolocator.geocode(guess)153 location_2 = geolocator.geocode(game_location)154 loc1 = (location_1.latitude, location_1.longitude)155 loc2 = (location_2.latitude, location_2.longitude)156 dis = str(int(geodesic(loc1, loc2).km))157 guess1 = font_2.render(guess, True, (255, 51, 153))158 distance = font_2.render(dis, True, (255, 51, 153))159 screen.blit(guess1, guess1.get_rect(center=(x_screen // 2 + 150, y_screen // 16 + 170)))160 screen.blit(distance, distance.get_rect(center=(x_screen // 2 + 290, y_screen // 16 + 170)))161 if dis == '0':162 pygame.draw.rect(screen, true_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 150, 100, 40), 2, 5)163 else:164 pygame.draw.rect(screen, false_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 150, 100, 40), 2, 5)165166 alpha_1 = loc1[1] * (math.pi / 180)167 alpha_2 = loc2[1] * math.pi / 180168 phi_1 = loc1[0] * math.pi / 180169 phi_2 = loc2[0] * math.pi / 180170 delta_alpha = (alpha_2 - alpha_1)171 y = math.sin(delta_alpha) * math.cos(phi_2)172 x = math.cos(phi_1) * math.sin(phi_2) - math.sin(phi_1) * math.cos(phi_2) * math.cos(delta_alpha)173 angle = math.atan2(y, x)174 bearing = int((angle * 180 / math.pi + 360) % 360)175 if '0' == dis:176 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 170), 5, 5)177 elif 0 <= bearing < 90:178 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 170),179 (x_screen // 2 + 405, y_screen // 16 + 155), 4)180 elif 90 <= bearing < 180:181 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 170),182 (x_screen // 2 + 420, y_screen // 16 + 170), 4)183 elif 180 <= bearing < 270:184 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 170),185 (x_screen // 2 + 405, y_screen // 16 + 185), 4)186 elif 270 <= bearing < 360:187 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 185),188 (x_screen // 2 + 390, y_screen // 16 + 170), 4)189 print(dis)190191192def checking_distance_4(game_location, guess_location, distance=0):193 guess = guess_location194 location_1 = geolocator.geocode(guess)195 location_2 = geolocator.geocode(game_location)196 loc1 = (location_1.latitude, location_1.longitude)197 loc2 = (location_2.latitude, location_2.longitude)198 dis = str(int(geodesic(loc1, loc2).km))199 guess1 = font_2.render(guess, True, (255, 51, 153))200 distance = font_2.render(dis, True, (255, 51, 153))201 screen.blit(guess1, guess1.get_rect(center=(x_screen // 2 + 150, y_screen // 16 + 240)))202 screen.blit(distance, distance.get_rect(center=(x_screen // 2 + 290, y_screen // 16 + 240)))203204 if dis == '0':205 pygame.draw.rect(screen, true_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 220, 100, 40), 2, 5)206 else:207 pygame.draw.rect(screen, false_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 220, 100, 40), 2, 5)208209 alpha_1 = loc1[1] * (math.pi / 180)210 alpha_2 = loc2[1] * math.pi / 180211 phi_1 = loc1[0] * math.pi / 180212 phi_2 = loc2[0] * math.pi / 180213 delta_alpha = (alpha_2 - alpha_1)214 y = math.sin(delta_alpha) * math.cos(phi_2)215 x = math.cos(phi_1) * math.sin(phi_2) - math.sin(phi_1) * math.cos(phi_2) * math.cos(delta_alpha)216 angle = math.atan2(y, x)217 bearing = int((angle * 180 / math.pi + 360) % 360)218 if '0' == dis:219 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 240), 5, 5)220 elif 0 <= bearing < 90:221 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 240),222 (x_screen // 2 + 405, y_screen // 16 + 225), 4)223 elif 90 <= bearing < 180:224 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 240),225 (x_screen // 2 + 420, y_screen // 16 + 240), 4)226 elif 180 <= bearing < 270:227 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 240),228 (x_screen // 2 + 405, y_screen // 16 + 255), 4)229 elif 270 <= bearing < 360:230 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 255),231 (x_screen // 2 + 390, y_screen // 16 + 240), 4)232 print(dis)233234235def checking_distance_5(game_location, guess_location, distance=0):236 guess = guess_location237 location_1 = geolocator.geocode(guess)238 location_2 = geolocator.geocode(game_location)239 loc1 = (location_1.latitude, location_1.longitude)240 loc2 = (location_2.latitude, location_2.longitude)241 dis = str(int(geodesic(loc1, loc2).km))242 guess1 = font_2.render(guess, True, (255, 51, 153))243 distance = font_2.render(dis, True, (255, 51, 153))244 screen.blit(guess1, guess1.get_rect(center=(x_screen // 2 + 150, y_screen // 16 + 310)))245 screen.blit(distance, distance.get_rect(center=(x_screen // 2 + 290, y_screen // 16 + 310)))246 if dis == '0':247 pygame.draw.rect(screen, true_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 290, 100, 40), 2, 5)248 else:249 pygame.draw.rect(screen, false_color, pygame.Rect(x_screen // 2 + 100, y_screen // 16 + 290, 100, 40), 2, 5)250251 alpha_1 = loc1[1] * (math.pi / 180)252 alpha_2 = loc2[1] * math.pi / 180253 phi_1 = loc1[0] * math.pi / 180254 phi_2 = loc2[0] * math.pi / 180255 delta_alpha = (alpha_2 - alpha_1)256 y = math.sin(delta_alpha) * math.cos(phi_2)257 x = math.cos(phi_1) * math.sin(phi_2) - math.sin(phi_1) * math.cos(phi_2) * math.cos(delta_alpha)258 angle = math.atan2(y, x)259 bearing = int((angle * 180 / math.pi + 360) % 360)260 if '0' == dis:261 pygame.draw.circle(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 310), 5, 5)262 elif 0 <= bearing < 90:263 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 310),264 (x_screen // 2 + 405, y_screen // 16 + 295), 4)265 elif 90 <= bearing < 180:266 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 310),267 (x_screen // 2 + 420, y_screen // 16 + 310), 4)268 elif 180 <= bearing < 270:269 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 310),270 (x_screen // 2 + 405, y_screen // 16 + 325), 4)271 elif 270 <= bearing < 360:272 pygame.draw.line(screen, location_color, (x_screen // 2 + 405, y_screen // 16 + 325),273 (x_screen // 2 + 390, y_screen // 16 + 310), 4)274 print(dis)275276# def checking_distance(x, game_location, guess_location, distance = 0):277# guess_1 = ''278# guess_2 = ''279# guess_3 = ''280# guess_4 = ''281# guess_5 = ''282# dis_1 = ''283# dis_2 = ''284# if x == 1:285# guess_1 = guess_location286# location_1 = geolocator.geocode(game_location)287# location_2 = geolocator.geocode(guess_1)288# loc1 = (location_1.latitude, location_1.longitude)289# loc2 = (location_2.latitude, location_2.longitude)290# dis_1 = str(int(geodesic(loc1, loc2).km))291# guess1 = font_2.render(guess_1, True, (255, 51, 153))292# distance_1 = font_2.render(dis_1, True, (255, 51, 153))293# screen.blit(guess1, guess1.get_rect(center = (x_screen// 2 + 150, y_screen//16 + 30)))294# screen.blit(distance_1, distance_1.get_rect(center = (x_screen// 2 + 290, y_screen//16 + 30)))295# print(dis_1)296# if x == 2:297# guess_2 = guess_location298#299# location_1 = geolocator.geocode(game_location)300# location_2 = geolocator.geocode(guess_2)301# loc1 = (location_1.latitude, location_1.longitude)302# loc2 = (location_2.latitude, location_2.longitude)303# dis_2 = str(int(geodesic(loc1, loc2).km))304#305# screen.blit(guess1, guess1.get_rect(center = (x_screen// 2 + 150, y_screen//16 + 30)))306# screen.blit(distance_1, distance_1.get_rect(center = (x_screen// 2 + 290, y_screen//16 + 30)))307# print(dis_1)308#309# guess2 = font_2.render(guess_2, True, (255, 51, 153))310# distance_2 = font_2.render(dis_2, True, (255, 51, 153))311# screen.blit(guess2, guess2.get_rect(center = (x_screen// 2 + 150, y_screen//16 + 100)))312# screen.blit(distance_2, distance_2.get_rect(center = (x_screen// 2 + 290, y_screen//16 + 100)))313# print(dis_2)314315316def getting_guess():317 guess = str(input('doan dia diem: '))318 return guess319320321x = 1322exit = False323guess_1 = ''324guess_2 = ''325guess_3 = ''326guess_4 = ''327guess_5 = ''328guess_6 = ''329while not exit:330 for event in pygame.event.get():331 if event.type == pygame.QUIT:332 exit = True333 timer.tick(fps)334 screen.fill(background_color)335 screen.blit(wordle, wordle.get_rect(center=(x_namegame - 55, 20)))336 screen.blit(vietnam, vietnam.get_rect(center=(x_namegame + 55, 20)))337 draw_checking_distance()338 print(x)339 if x == 1:340 guess_1 = getting_guess()341 checking_distance_1(guess_location=guess_1, game_location=game_location)342 if x == 2:343 guess_2 = getting_guess()344 checking_distance_1(guess_location=guess_1, game_location=game_location)345 checking_distance_2(guess_location=guess_2, game_location=game_location)346 if x == 3:347 guess_3 = getting_guess()348 checking_distance_1(guess_location=guess_1, game_location=game_location)349 checking_distance_2(guess_location=guess_2, game_location=game_location)350 checking_distance_3(guess_location=guess_3, game_location=game_location)351 if x == 4:352 guess_4 = getting_guess()353 checking_distance_1(guess_location=guess_1, game_location=game_location)354 checking_distance_2(guess_location=guess_2, game_location=game_location)355 checking_distance_3(guess_location=guess_3, game_location=game_location)356 checking_distance_4(guess_location=guess_4, game_location=game_location)357 if x == 5:358 guess_5 = getting_guess()359 checking_distance_1(guess_location=guess_1, game_location=game_location)360 checking_distance_2(guess_location=guess_2, game_location=game_location)361 checking_distance_3(guess_location=guess_3, game_location=game_location)362 checking_distance_4(guess_location=guess_4, game_location=game_location)363 checking_distance_5(guess_location=guess_5, game_location=game_location)364 if x == 6:365 guess_6 = getting_guess()366 pygame.display.update()367 pygame.display.flip()368 x += 1369 # checking_distance(x, game_location, guess_location)370 # if x == 1:371 # guess_location = str(input())372 # checking_distance(x, game_location, guess_location)
...
StandardLocations.py
Source:StandardLocations.py
1import pygame2from pygame.locals import *3class StandardLocations():4 """5 This class can be used to call offscreen and onscreen locations to position things on a screen.6 It is used by the following code:7 screen = initialize_kelpy( dimensions=(800,600) ) ## INITIALIZE THE SCREEN OBJECT...8 spots = Spots(screen) ## FEED THE SCREEN OBJECT TO THE StandardLocations OBJECT...9 print spots.west ## YOU CAN NOW CALL THE POSITIONS FROM THE OBJECT AS ATTRIBUTES! YAY!10 """11 def __init__(self, screen):12 """13 This initializes everything.14 """15 ## offscreen spots16 self.west = ( -screen.get_width(), screen.get_height() /2 )17 self.northwest = ( -screen.get_width(), -screen.get_height() )18 self.north = ( screen.get_width()/2, -screen.get_height() )19 self.northeast = ( screen.get_width() *2, -screen.get_height() )20 self.east = ( screen.get_width() * 2, screen.get_height()/2 )21 self.southeast= ( screen.get_width() * 2, screen.get_height() * 2 )22 self.south = ( screen.get_width()/2 , screen.get_height() * 2 )23 self.southwest = ( -screen.get_width(), screen.get_height()*2 )24 25 ## 4 spots along the screen from right to left (1-4)26 ## and 4 rows top to bottom (a-d)27 self.a1 = ((screen.get_width()/5) * 1, (screen.get_height()/5)*1 )28 self.a2 = ((screen.get_width()/5) * 2, (screen.get_height()/5)*1 )29 self.a3 = ((screen.get_width()/5) * 3, (screen.get_height()/5)*1 )30 self.a4 = ((screen.get_width()/5) * 4, (screen.get_height()/5)*1 )31 self.b1 = ((screen.get_width()/5) * 1, (screen.get_height()/5)*2 )32 self.b2 = ((screen.get_width()/5) * 2, (screen.get_height()/5)*2 )33 self.b3 = ((screen.get_width()/5) * 3, (screen.get_height()/5)*2 )34 self.b4 = ((screen.get_width()/5) * 4, (screen.get_height()/5)*2 )35 self.c1 = ((screen.get_width()/5) * 1, (screen.get_height()/5)*3 )36 self.c2 = ((screen.get_width()/5) * 2, (screen.get_height()/5)*3 )37 self.c3 = ((screen.get_width()/5) * 3, (screen.get_height()/5)*3 )38 self.c4 = ((screen.get_width()/5) * 4, (screen.get_height()/5)*3 )39 40 self.d1 = ((screen.get_width()/5) * 1, (screen.get_height()/5)*4 )41 self.d2 = ((screen.get_width()/5) * 2, (screen.get_height()/5)*4 )42 self.d3 = ((screen.get_width()/5) * 3, (screen.get_height()/5)*4 )43 self.d4 = ((screen.get_width()/5) * 4, (screen.get_height()/5)*4 )44 # middle row spots45 self.midrow1 = ((screen.get_width() /5 ) * 1, (screen.get_height() /2 ) )46 self.midrow2 = ((screen.get_width() /5 ) * 2, (screen.get_height() /2 ) )47 self.midrow3 = ((screen.get_width() /5 ) * 3, (screen.get_height() /2 ) )48 self.midrow4 = ((screen.get_width() /5 ) * 4, (screen.get_height() /2 ) )49 #middle column spots50 self.midcol1 = ((screen.get_width() /2 ), (screen.get_height() /5 ) * 1)51 self.midcol2 = ((screen.get_width() /2 ), (screen.get_height() /5 ) * 2)52 self.midcol3 = ((screen.get_width() /2 ), (screen.get_height() /5 ) * 3)53 self.midcol4 = ((screen.get_width() /2 ), (screen.get_height() /5 ) * 4)54 self.center = ((screen.get_width() /2 ), (screen.get_height() /2 ) )55 self.cu=((screen.get_width() /2 ), (screen.get_height() /5)*1 )56 self.cd=((screen.get_width() /2 ), (screen.get_height()/5)*3 )57 58 59 60 #laura custom spots-spots closer to center61 #four spots across screen from left to right (1-4)62 #and in four columns top to bottom (w-z)63 self.w1 = ((screen.get_width()/8) * 2, (screen.get_height()/8)*2 )64 self.w2 = ((screen.get_width()/8) * 3, (screen.get_height()/8)*2 )65 self.w3 = ((screen.get_width()/8) * 5, (screen.get_height()/8)*2 )66 self.w4 = ((screen.get_width()/8) * 6, (screen.get_height()/8)*2 )67 self.x1 = ((screen.get_width()/8) * 2, (screen.get_height()/8)*3 )68 self.x2 = ((screen.get_width()/8) * 3, (screen.get_height()/8)*3 )69 self.x3 = ((screen.get_width()/8) * 5, (screen.get_height()/8)*3 )70 self.x4 = ((screen.get_width()/8) * 6, (screen.get_height()/8)*3 )71 #bottom right quadrant72 self.y1 = ((screen.get_width()/8) * 2, (screen.get_height()/8)*5 )73 self.y2 = ((screen.get_width()/8) * 3, (screen.get_height()/8)*5 )74 self.y3 = ((screen.get_width()/8) * 5, (screen.get_height()/8)*5 )75 self.y4 = ((screen.get_width()/8) * 6, (screen.get_height()/8)*5 )76 #bottom right quadrant77 self.z1 = ((screen.get_width()/8) * 2, (screen.get_height()/8)*6 )78 self.z2 = ((screen.get_width()/8) * 3, (screen.get_height()/8)*6 )79 self.z3 = ((screen.get_width()/8) * 5, (screen.get_height()/8)*6 )...
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!!