def _reload_keypress(self, instance, code, *largs): if code != 286: return for child in Window.children[:]: Window.remove_widget(child) root = Builder.load_file(self.options['filename']) Window.add_widget(root)
def on_touch_down(self, touch: MotionEvent) -> bool: """ On touch down on connection means we are modifying an already existing connection, not creating a new one. """ # TODO: remove start check? if self.start and self.start.collide_point(*touch.pos): self.forward = False # Remove start edge self._unbind_pin(self.start) self.start.on_connection_delete(self) self.start = None # This signals that we are dragging a connection touch.ud['cur_line'] = self Window.add_widget(self.info) return True elif self.end and self.end.collide_point(*touch.pos): # Same as before but with the other edge self.forward = True self._unbind_pin(self.end) self.end.on_connection_delete(self) self.end = None touch.ud['cur_line'] = self Window.add_widget(self.info) return True else: return False
def run(self, kv_file = None): '''Launches the app in standalone mode. ''' if not self.built: self.load_config() self.load_kv(kv_file) root = self.build() if root: self.root = root if self.root: from kivy.core.window import Window Window.add_widget(self.root) # Check if the window is already created from kivy.base import EventLoop window = EventLoop.window if window: self._app_window = window window.set_title(self.get_application_name()) icon = self.get_application_icon() if icon: window.set_icon(icon) self._install_settings_keys(window) else: Logger.critical("Application: No window is created." " Terminating application run.") return self.dispatch('on_start') runTouchApp() self.dispatch('on_stop') # Clear the window children for child in window.children: window.remove_widget(child)
def _transition_outof_intro(self, *args): # Fade out self.fader = ScreenFader(size=Window.size) Window.add_widget(self.fader) anim = Animation(alpha = 1.0, d=0.6) anim.bind(on_complete=self.begin_game) anim.start(self.fader)
def screen_saver(self,arg): self.stop_timer() for child in Window.children: child.opacity=0 child.disabled=True s=SplashScreen(splash_dir=join(self.app.data_dir,'splashscreens'),selector_reference=self,interval=self.app.config.getint('museotouch','splashscreen_interval')) Window.add_widget(s)
def run(self): """Launches the app in standalone mode. """ if not self.built: self.load_config() self.load_kv() root = self.build() if root: self.root = root if self.root: from kivy.core.window import Window Window.add_widget(self.root) # Check if the window is already created from kivy.base import EventLoop window = EventLoop.window if window: self._app_window = window window.set_title(self.get_application_name()) icon = self.get_application_icon() if icon: window.set_icon(icon) self._install_settings_keys(window) self.dispatch("on_start") runTouchApp() self.dispatch("on_stop")
def run(self): '''Launches the app in standalone mode. ''' if not self.built: self.load_config() self.load_kv(filename=self.options.get('kv_file')) root = self.build() if root: self.root = root if self.root: from kivy.core.window import Window Window.add_widget(self.root) # Check if the window is already created from kivy.base import EventLoop window = EventLoop.window if window: self._app_window = window window.set_title(self.get_application_name()) icon = self.get_application_icon() if icon: window.set_icon(icon) self._install_settings_keys(window) else: Logger.critical("Application: No window is created." " Terminating application run.") return self.dispatch('on_start') runTouchApp() self.stop()
def run(self): '''Launches the app in standalone mode. ''' if not self.built: self.load_config() self.load_kv(filename=self.kv_file) root = self.build() if root: self.root = root if self.root: if not isinstance(self.root, Widget): Logger.critical('App.root must be an _instance_ of Widget') raise Exception('Invalid instance in App.root') from kivy.core.window import Window Window.add_widget(self.root) # Check if the window is already created from kivy.base import EventLoop window = EventLoop.window if window: self._app_window = window window.set_title(self.get_application_name()) icon = self.get_application_icon() if icon: window.set_icon(icon) self._install_settings_keys(window) else: Logger.critical("Application: No window is created." " Terminating application run.") return self.dispatch('on_start') runTouchApp() self.stop()
def run(self): """Launches the app in standalone mode. """ if not self.built: self.load_config() self.load_kv(filename=self.options.get("kv_file")) root = self.build() if root: self.root = root if self.root: from kivy.core.window import Window Window.add_widget(self.root) # Check if the window is already created from kivy.base import EventLoop window = EventLoop.window if window: self._app_window = window window.set_title(self.get_application_name()) icon = self.get_application_icon() if icon: window.set_icon(icon) self._install_settings_keys(window) else: Logger.critical("Application: No window is created." " Terminating application run.") return self.dispatch("on_start") runTouchApp() self.stop()
def fps_monitor_start(self): from kivy.core.window import Window from kivymd.utils.fpsmonitor import FpsMonitor monitor = FpsMonitor() monitor.start() Window.add_widget(monitor)
def update(self, *args): Builder.unload_file(join(PATH, TARGET)) for w in Window.children[:]: Window.remove_widget(w) try: Window.add_widget(Builder.load_file(join(PATH, TARGET))) except Exception as e: Window.add_widget(Label(text=e.message if e.message else str(e)))
def _load_file(self, path): try: self.chisel.load(path) except (ValueError, KeyError): open_error_popup(_("The file could not be loaded.")) finally: self.loading_popup.dismiss() Window.add_widget(CURSOR, "after")
def update(self, *args): Builder.unload_file(join(PATH, TARGET)) for w in Window.children[:]: Window.remove_widget(w) try: Window.add_widget(Builder.load_file(join(PATH, TARGET))) except Exception as e: Window.add_widget(Label(text=e.message if e.message else str(e)))
def display_tooltip(self, interval): if not self._tooltip: return Window.add_widget(self._tooltip) pos = self.to_window(self.center_x, self.center_y) x = pos[0] + self.width / 2 y = pos[1] - self.height / 2 self._tooltip.pos = (x, y) Clock.schedule_once(self.animation_tooltip_show, 0)
def show( self, isLong, *args ) : duration = self.duration_long if isLong else self.duration_short timeout_down = duration * 0.1 if timeout_down > 500 : timeout_down = 500 if timeout_down < 100 : timeout_down = 100 self._timeout_down = timeout_down self._duration = duration - timeout_down Window.add_widget(self) Clock.schedule_interval(self.animate, 1/60.0)
def show_info_on_mouse(message=''): if message: if info_label in Window.children: Window.remove_widget(info_label) info_label.text = '' info_label.text = message set_auto_mouse_position(info_label) Window.add_widget(info_label)
def open(self, code_input): self.code_input = code_input self.ids.input.focus = True if not self.parent: Window.add_widget(self) self.top = code_input.top self.right = code_input.right code_input.bind(top=self.setter('top')) code_input.bind(right=self.setter('right'))
def display_tooltip(self, *args): try: if len(self.tooltip.content.children) == 0: self.tooltip.get_name(f_name=self.text) self.tooltip.x = self.x - 35 self.tooltip.y -= self.height Window.add_widget(self.tooltip) except Exception as e: print 'Error occurred in display_tooltip: ', str(e)
def begin(self): if self.button_text == '': self.remove_widget(self.ids['_button']) else: self.ids['_spacer'].width = dp(16) if DEVICE_TYPE == "mobile" else dp(40) self.padding_right = dp(16) Window.add_widget(self) anim = Animation(y=0, duration=.3, t='out_quad') anim.start(self) Clock.schedule_once(lambda dt: self.die(), self.duration)
def set_source_display(display): KivyWindow.clear() for widget in KivyWindow.children: KivyWindow.remove_widget(widget) KivyWindow.add_widget(display) KivyWindow.bind(system_size=display.on_window_resize) Clock.schedule_once(display.fit_to_window, -1)
def begin(self): if self.button_text == '': self.remove_widget(self.ids['_button']) else: self.ids['_spacer'].width = dp(16) if DEVICE_TYPE == "mobile" else dp(40) self.padding_right = dp(16) Window.add_widget(self) anim = Animation(y=0, duration=.3, t='out_quad') anim.start(self) Clock.schedule_once(lambda dt: self.die(), self.duration)
def build(self): if platform.system() == 'Darwin': self._scaler = Scaler(size=Window.size, scale=2) Window.add_widget(self._scaler) parent = self._scaler or Window parent.add_widget(self.simbot) else: Window.add_widget(self.simbot) Clock.schedule_interval(self.simbot.process, self.interval)
def fps_monitor_start(self) -> None: """Adds a monitor to the main application window.""" from kivy.core.window import Window from kivymd.utils.fpsmonitor import FpsMonitor monitor = FpsMonitor() monitor.start() Window.add_widget(monitor)
def show(self, length_long, *largs): duration = 5000 if length_long else 1000 rampdown = duration * 0.1 if rampdown > 500: rampdown = 500 if rampdown < 100: rampdown = 100 self._rampdown = rampdown self._duration = duration - rampdown Window.add_widget(self) Clock.schedule_interval(self._in_out, 1 / 60.0)
def clickfade(self, widget, mode='opacity'): try: Window.remove_widget(self.clickfade_object) except: pass if self.clickfade_object is None: self.clickfade_object = ClickFade() self.clickfade_object.size = widget.size self.clickfade_object.pos = widget.to_window(*widget.pos) self.clickfade_object.begin(mode) Window.add_widget(self.clickfade_object)
def show_select(self, *args): """ fonction qui affiche l'écran de selection du nbre de noeuds """ Window.add_widget(self.rootSelect) self.hide_menu() self.btnOk.bind(on_release=self.toto) self.btnDel.bind(on_press=self.hide_select) self.btnDel.bind(on_release=self.show_menu) self.slid.bind(on_release=self.toto) print "valeur par default", self.nb
def show_bubble(self, *objects, file: Optional[TextIO] = None, **kwargs): """ show popup bubble - compatible to Python print() and AppBase.print_out() """ if not self.info_bubble: self.info_bubble = Factory.DebugBubble() self.info_bubble.message = " ".join( [repr(message) for message in objects]) if not self.info_bubble.parent: # Check if bubble is not already on screen Window.add_widget(self.info_bubble) Clock.schedule_once(lambda dt: Window.remove_widget(self.info_bubble), 9) # Remove bubble after some seconds self.po(*objects, file=file, **kwargs)
def show(self, length_long, *largs): duration = 5000 if length_long else 1000 rampdown = duration * 0.1 if rampdown > 500: rampdown = 500 if rampdown < 100: rampdown = 100 self._rampdown = rampdown self._duration = duration - rampdown Window.add_widget(self) Clock.schedule_interval(self._in_out, 1 / 60.0)
def show_game(self, other_widget, level_number): Window.remove_widget(other_widget) game = Game.Game() if level_number == 1: game.map_image = 'data/landscape.jpg' elif level_number == 2: game.map_image = 'data/landscape_evening.jpg' elif level_number == 3: game.map_image = 'data/landscape_night.jpg' Window.add_widget(game) game.start_game()
def build(self): self.screens = ScreenManager(transition=FadeTransition(duration=0.4)) self.gamescreen = GameScreen(name='game') self.screens.add_widget(HomeScreen(name='home')) self.screens.add_widget(self.gamescreen) self.screens.add_widget(AboutScreen(name='about')) parent = Window if platform() == 'ios' and ( Window.width > 2000 or Window.height > 2000): self._scaler = Scaler(size=Window.size, scale=2) Window.add_widget(self._scaler) parent = self._scaler parent.add_widget(self.screens)
def show_game(self, *args): """ Fonction qui affiche le jeu quand on l'appelera - créer le jeu - add le jeu """ self.rootGame = self.create_game() # on ajoute le jeu crée a la fenetre Window pour qu'il apparaisse à # l'écran Window.add_widget(self.rootGame) # on cache le menu, sinon il y a superposition du menu et du terrain de # jeu self.hide_menu()
def build(self): Window.clearcolor = (1, 1, 1, 1) Window.add_widget((AsyncImage( source= "https://images.unsplash.com/photo-1525723550961-7a8f846d6ba7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1049&q=80", size_hint=(1.3, 1.158)))) sm = ScreenManagement(transition=FadeTransition()) sm.add_widget(LoginWindow(name='login')) sm.add_widget(Current_Window(name='Current')) sm.add_widget(Prediction_Window(name='Prediction')) sm.add_widget(Guide_Window(name='Guide')) sm.add_widget(Setup_Window(name='Setup')) return sm
def bubbprint(self, message): message = repr(message) if not self.info_bubble: self.info_bubble = Factory.InfoBubble() self.info_bubble.message = message # Check if bubble is not already on screen if not self.info_bubble.parent: Window.add_widget(self.info_bubble) # Remove bubble after 2 secs Clock.schedule_once(lambda dt: Window.remove_widget(self.info_bubble), 2)
def reset_window_environment() -> BoxLayout: """Remove PythonHere app widgets and styles.""" # import Window inside function to avoid early loading of the app config from kivy.core.window import Window # pylint: disable=import-outside-toplevel for widget in Window.children: widget.clear_widgets() Window.remove_widget(widget) for filename in Builder.files[1:]: Builder.unload_file(filename) root = BoxLayout(orientation="vertical") Window.add_widget(root) return root
def drag_down(self, source, touch): """Called by :class:`DraggableObjectBehavior` when it got a touch down. """ self.clean_dragging() self.widget_dragged = source self.prepare_preview_widget(source.drag_widget or source) self.touch_dx = self.touch_dy = 0 self.dragging = False self.preview_widget.canvas.opacity = 0 Window.add_widget(self.preview_widget) self.start_widget_pos = self.preview_widget.pos = \ source.to_window(*source.pos) return False
def run(self): '''Launches the app in standalone mode. ''' if not self.built: self.load_kv() root = self.build() if root: self.root = root if self.root: from kivy.core.window import Window Window.add_widget(self.root) self.dispatch('on_start') runTouchApp() self.dispatch('on_stop')
def display_tooltip(self, interval): if not self._tooltip: return Window.add_widget(self._tooltip) pos = self.to_window(self.center_x, self.center_y) x = pos[0] - self._tooltip.width / 2 y = pos[1] - self._tooltip.height / 2 - self.height / 2 - dp(20) x, y = self.adjust_tooltip_position(x, y) self._tooltip.pos = (x, y) if DEVICE_TYPE == "desktop": Clock.schedule_once(self.animation_tooltip_show, self.tooltip_display_delay) else: Clock.schedule_once(self.animation_tooltip_show, 0)
def main_screen(self): """ Создание главного меню, которое отображается при входе """ Window.add_widget(Image(source=picture_in_main)) screen = Screen(name=main_screen) bl = BoxLayout(**main_bl_props) bl.add_widget(Button(text='Книга', **main_buttons)) bl.add_widget( Button(text='Поиск', on_press=lambda x: self.change_screen('find'), **main_buttons)) screen.add_widget(bl) return screen
def show(self, pos, duration, width=None, modal=False, exit=False): '''Animate the bubble into position''' self.modal, self.exit = modal, exit if width: self.width = width if self.modal: from kivy.uix.modalview import ModalView self._modal_view = m = ModalView(background_color=[.5, .5, .5, .2]) Window.add_widget(m) m.add_widget(self) else: Window.add_widget(self) # wait for the bubble to adjust it's size according to text then animate Clock.schedule_once(lambda dt: self._show(pos, duration))
def init_template_widgets(self, *args): Logger.info('TemplateApp: initialising template widgets') self.load_kv('kivy_soil/template_app/themes_layouts/term_and_toast.kv') self.info_widget = InfoWidget() self.term_widget = TerminalWidget() for data in logs.LoggerHistoryProper.data: self.term_widget.add_data(data['text'], data['level']) logs.LoggerHistoryProper.bind( on_add_data=lambda obj, data: self.term_widget.add_data( data['text'], data['level'])) Window.add_widget(self.term_widget) Window.add_widget(self.info_widget) self.init_keybinds()
def display_tooltip(self, *args): cap_dict = {} try: if len(self.tooltip.content.children) == 0: for d in RAW_DEVICES: if d.name == self.text: cap_dict = ast.literal_eval(d.functionality) self.tooltip.get_capabilities(cap_dict=cap_dict) self.tooltip.x = self.width - 100 self.tooltip.y -= self.height * 2 Window.add_widget(self.tooltip) except Exception as e: print 'Error occurred in display_tooltip: ', str(e)
def run(self): '''Launches the app in standalone mode. ''' if not self.built: self.load_kv() root = self.build() if root: self.root = root if self.root: from kivy.core.window import Window Window.add_widget(self.root) self.dispatch('on_start') runTouchApp() self.dispatch('on_stop')
def set_source_display(display: "DisplayWidget") -> None: """Set the source display for the main window.""" # Clean up any existing objects in the window KivyWindow.clear() for widget in KivyWindow.children: KivyWindow.remove_widget(widget) # Add the new display to the window KivyWindow.add_widget(display) # Make sure the display is re-sized whenever the window changes size KivyWindow.bind(system_size=Window.on_size)
def show(self, pos, duration, width=None, modal=False, exit=False): '''Animate the bubble into position''' self.modal, self.exit = modal, exit if width: self.width = width if self.modal: from kivy.uix.modalview import ModalView self._modal_view = m = ModalView(background_color=[.5, .5, .5, .2]) Window.add_widget(m) m.add_widget(self) else: Window.add_widget(self) # wait for the bubble to adjust it's size according to text then animate Clock.schedule_once(lambda dt: self._show(pos, duration))
def on_show_label(self, *largs): '''Shows/hides the :attr:`pos_label` label. ''' state = self.show_label for shape in self.shapes: shape.widget.show_label = state label = self.pos_label if state: Window.add_widget(label) Window.fbind('mouse_pos', self._update_mouse_pos) self._update_mouse_pos(None, Window.mouse_pos) else: Window.remove_widget(label) Window.funbind('mouse_pos', self._update_mouse_pos)
def on_mouse_pos(self, *args): if self.is_shortened and self.parent is not None: pos = args[1] inside = self.collide_point(*pos) if inside and not self.tooltip.open: self.tooltip.pos = pos Window.add_widget(self.tooltip) self.tooltip.open = True elif not inside and self.tooltip.open: Window.remove_widget(self.tooltip) self.tooltip.open = False elif inside and self.tooltip.open: self.tooltip.pos = pos elif self.parent is None: Window.remove_widget(self.tooltip)
def reset_chisel(self, *args): Window.remove_widget(CURSOR) popup = open_loading_popup(_("Resetting the canvas.")) Clock.schedule_once( lambda dt: (self.chisel.reset() or popup.dismiss() or Window.add_widget( CURSOR, "after")), 0.1)
def _show(self, pos, duration): def on_stop(*l): if duration: Clock.schedule_once(self.hide, duration + .5) self.opacity = 0 arrow_pos = self.arrow_pos if arrow_pos[0] in ('l', 'r'): pos = pos[0], pos[1] - (self.height/2) else: pos = pos[0] - (self.width/2), pos[1] self.limit_to = Window self.pos = pos Window.add_widget(self) anim = Animation(opacity=1, d=0.75) anim.bind(on_complete=on_stop) anim.cancel_all(self) anim.start(self)
def begin_game(self, *largs, **kwargs): Builder.load_file("main.kv") self.root = self.fishlife = FishLifeGame() self.fishlife.victory_screen.restart_btn.bind(on_press=self.restart_game) try: Window.remove_widget(self.intro) except: pass Window.add_widget(self.root) # Fade in Window.remove_widget(self.fader) Window.add_widget(self.fader) anim = Animation(alpha = 0.0, d=0.8) anim.bind(on_complete=lambda instance, value: Window.remove_widget(self.fader)) anim.start(self.fader) # Timing game start with fade in if not kwargs.get("restart", False): Clock.schedule_once(self.root.play, 0.85) else: self.root.play()
def __init__(self, **kwargs): super(SlidingPanel, self).__init__(**kwargs) self.shadow = PanelShadow() Clock.schedule_once(lambda x: Window.add_widget(self.shadow, 89), 0) Clock.schedule_once(lambda x: Window.add_widget(self, 90), 0)
fade_in_button = Button(text='fade_in') fade_in_button.bind(on_press=lambda j: set_anim_type('fade_in')) reveal_button = Button(text='reveal_\nbelow_\nanim') reveal_button.bind(on_press= lambda j: set_anim_type('reveal_below_anim')) slide_button = Button(text='reveal_\nbelow_\nsimple') slide_button.bind(on_press= lambda j: set_anim_type('reveal_below_simple')) modes_layout.add_widget(slide_an) modes_layout.add_widget(slide_sim) modes_layout.add_widget(fade_in_button) modes_layout.add_widget(reveal_button) modes_layout.add_widget(slide_button) main_panel.add_widget(modes_layout) button = Button(text='toggle NavigationDrawer state (animate)', size_hint_y=0.2) button.bind(on_press=lambda j: navigationdrawer.toggle_state()) button2 = Button(text='toggle NavigationDrawer state (jump)', size_hint_y=0.2) button2.bind(on_press=lambda j: navigationdrawer.toggle_state(False)) button3 = Button(text='toggle _main_above', size_hint_y=0.2) button3.bind(on_press=navigationdrawer.toggle_main_above) main_panel.add_widget(button) main_panel.add_widget(button2) main_panel.add_widget(button3) Window.add_widget(navigationdrawer) runTouchApp()
def show_quit(self, *args): Window.add_widget(self.rootQuit) self.btnYes.bind(on_release=self.stop) self.btnNo.bind(on_release=self.hide_quit) self.btnNo.bind(on_release=self.show_menu) self.hide_menu()
def open(self, *largs): Window.add_widget(self) Clock.schedule_once(lambda x: self.display_menu(largs[0]), -1)
if filepath_split[-1] in ['jpg', 'jpeg', 'png', 'tif', 'tiff']: im = PIL_Image.open(filepath) im.thumbnail((300,300)) os.remove(self.thumbnail_location) self.thumbnail_location = r"C:\Users\herbz\OneDrive - University Of Cambridge\Documents\GitHub\WaterScope-RPi\motor control\exp\resources\thumbnail{}.jpg".format(self.number) im.save(self.thumbnail_location, "JPEG") im.close() self.image_object = Image(source = self.thumbnail_location, size_hint_x = 0.8, size_hint_y = 0.8) self.number = self.number*-1 #self.image_object = Image(source = filepath) image_viewer_popup.content = self.image_object image_viewer_popup.open() os.remove(self.thumbnail_location) self.folder_chooser.bind(selection = choose_image) folder_chooser_button.bind(on_release = activate_folder_chooser) return folder_chooser_button if __name__ == '__main__': new_buttons = create_buttons() #map_grid = new_buttons.create_grid(resolution = 9) folder_chooser_button = new_buttons.create_gallery() Window.add_widget(folder_chooser_button) runTouchApp()
def finished(self): Window.remove_widget(self.current_widget) novel = Novel('talk2', self.finished) Window.add_widget(novel) self.current_widget = novel
def increment_refcount(): ProgressSpinner.busy_refcount += 1 if ProgressSpinner.instance is None: ProgressSpinner.instance = ProgressSpinner(size_hint=(None, None), size=(100, 100), center=Window.center) Window.add_widget(ProgressSpinner.instance)
def bind_to_window_if_requested(self, _): if self.bind_to_window: Window.add_widget(self)
def show_menu(self, *args): """ fonction qui affiche le menu on ajoute le widget rootMenu(qui contient le create_menu) a la fenetre pour qu'il soit visible """ Window.add_widget(self.rootMenu)
def on_dismiss(self): pass if __name__ == '__main__': from kivy.base import runTouchApp from kivy.uix.button import Button from kivy.uix.label import Label from kivy.uix.gridlayout import GridLayout from kivy.core.window import Window # add view content = GridLayout(cols=1) content.add_widget(Label(text='This is a hello world')) view = ModalView(size_hint=(None, None), size=(256, 256), auto_dismiss=True) view.add_widget(content) def open_view(btn): view.open() layout = GridLayout(cols=3) for x in xrange(9): btn = Button(text='click me %s' % x) btn.bind(on_release=view.open) layout.add_widget(btn) Window.add_widget(layout) view.open() runTouchApp()
def inputhook_myrmidon_kivy(): """The kivy eventloop hook.""" from kivy.base import EventLoop from kivy.utils import platform engine_window = Game.engine['window'] if not engine_window or not engine_window.kivy_app: return 0 kivy_app = engine_window.kivy_app if not kivy_app.built: from kivy.uix.widget import Widget from kivy.core.window import Window from kivy.base import runTouchApp for x in Game._module_list: x._module_setup(cls) kivy_app.load_config() kivy_app.load_kv(filename=kivy_app.kv_file) kivy_app.root = kivy_app.build() if not isinstance(kivy_app.root, Widget): raise Exception('Invalid instance in App.root') Window.add_widget(kivy_app.root) # Check if the window is already created window = EventLoop.window if window: kivy_app._app_window = window window.set_title(kivy_app.get_application_name()) icon = kivy_app.get_application_icon() if icon: window.set_icon(icon) kivy_app._install_settings_keys(window) else: raise Exception("Application: No window is created." " Terminating application run.") kivy_app.dispatch('on_start') runTouchApp(kivy_app.root, slave=True) # Tick forward the Myrmidon event loop one frame Game.app_loop_callback(0) # Tick forward kivy to reflect events and changes from Myrmidon. # This has been directly lifted from `kivy.core.window.window_sdl2`. EventLoop.idle() window = EventLoop.window event = window._win.poll() if event is False or event is None: return 0 action, args = event[0], event[1:] if action == 'quit': EventLoop.quit = True window.close() return 0 elif action in ('fingermotion', 'fingerdown', 'fingerup'): # for finger, pass the raw event to SDL motion event provider # XXX this is problematic. On OSX, it generates touches with 0, # 0 coordinates, at the same times as mouse. But it works. # We have a conflict of using either the mouse or the finger. # Right now, we have no mechanism that we could use to know # which is the preferred one for the application. if platform == "ios": SDL2MotionEventProvider.q.appendleft(event) pass elif action == 'mousemotion': x, y = args x, y = window._fix_mouse_pos(x, y) window._mouse_x = x window._mouse_y = y # don't dispatch motion if no button are pressed if len(window._mouse_buttons_down) == 0: return 0 window._mouse_meta = window.modifiers window.dispatch('on_mouse_move', x, y, window.modifiers) elif action in ('mousebuttondown', 'mousebuttonup'): x, y, button = args x, y = window._fix_mouse_pos(x, y) btn = 'left' if button == 3: btn = 'right' elif button == 2: btn = 'middle' eventname = 'on_mouse_down' window._mouse_buttons_down.add(button) if action == 'mousebuttonup': eventname = 'on_mouse_up' window._mouse_buttons_down.remove(button) window._mouse_x = x window._mouse_y = y window.dispatch(eventname, x, y, btn, window.modifiers) elif action.startswith('mousewheel'): window._update_modifiers() x, y, button = args btn = 'scrolldown' if action.endswith('up'): btn = 'scrollup' elif action.endswith('right'): btn = 'scrollright' elif action.endswith('left'): btn = 'scrollleft' window._mouse_meta = window.modifiers window._mouse_btn = btn #times = x if y == 0 else y #times = min(abs(times), 100) #for k in range(times): window._mouse_down = True window.dispatch('on_mouse_down', window._mouse_x, window._mouse_y, btn, window.modifiers) window._mouse_down = False window.dispatch('on_mouse_up', window._mouse_x, window._mouse_y, btn, window.modifiers) elif action == 'dropfile': dropfile = args window.dispatch('on_dropfile', dropfile[0]) # video resize elif action == 'windowresized': window._size = window._win.window_size # don't use trigger here, we want to delay the resize event cb = window._do_resize from kivy.clock import Clock Clock.unschedule(cb) Clock.schedule_once(cb, .1) elif action == 'windowresized': window.canvas.ask_update() elif action == 'windowrestored': window.canvas.ask_update() elif action == 'windowexposed': window.canvas.ask_update() elif action == 'windowminimized': if Config.getboolean('kivy', 'pause_on_minimize'): window.do_pause() elif action == 'joyaxismotion': stickid, axisid, value = args window.dispatch('on_joy_axis', stickid, axisid, value) elif action == 'joyhatmotion': stickid, hatid, value = args window.dispatch('on_joy_hat', stickid, hatid, value) elif action == 'joyballmotion': stickid, ballid, xrel, yrel = args window.dispatch('on_joy_ball', stickid, ballid, xrel, yrel) elif action == 'joybuttondown': stickid, buttonid = args window.dispatch('on_joy_button_down', stickid, buttonid) elif action == 'joybuttonup': stickid, buttonid = args window.dispatch('on_joy_button_up', stickid, buttonid) elif action in ('keydown', 'keyup'): mod, key, scancode, kstr = args from kivy.core.window import window_sdl2 key_swap = { window_sdl2.SDLK_LEFT: 276, window_sdl2.SDLK_RIGHT: 275, window_sdl2.SDLK_UP: 273, window_sdl2.SDLK_DOWN: 274, window_sdl2.SDLK_HOME: 278, window_sdl2.SDLK_END: 279, window_sdl2.SDLK_PAGEDOWN: 281, window_sdl2.SDLK_PAGEUP: 280, window_sdl2.SDLK_SHIFTR: 303, window_sdl2.SDLK_SHIFTL: 304, window_sdl2.SDLK_SUPER: 309, window_sdl2.SDLK_LCTRL: 305, window_sdl2.SDLK_RCTRL: 306, window_sdl2.SDLK_LALT: 308, window_sdl2.SDLK_RALT: 307, window_sdl2.SDLK_CAPS: 301, window_sdl2.SDLK_INSERT: 277, window_sdl2.SDLK_F1: 282, window_sdl2.SDLK_F2: 283, window_sdl2.SDLK_F3: 284, window_sdl2.SDLK_F4: 285, window_sdl2.SDLK_F5: 286, window_sdl2.SDLK_F6: 287, window_sdl2.SDLK_F7: 288, window_sdl2.SDLK_F8: 289, window_sdl2.SDLK_F9: 290, window_sdl2.SDLK_F10: 291, window_sdl2.SDLK_F11: 292, window_sdl2.SDLK_F12: 293, window_sdl2.SDLK_F13: 294, window_sdl2.SDLK_F14: 295, window_sdl2.SDLK_F15: 296, window_sdl2.SDLK_KEYPADNUM: 300} if platform == 'ios': # XXX ios keyboard suck, when backspace is hit, the delete # keycode is sent. fix it. key_swap[127] = 8 # back try: key = key_swap[key] except KeyError: pass if action == 'keydown': window._update_modifiers(mod, key) else: window._update_modifiers(mod) # ignore the key, it # has been released # if mod in window._meta_keys: if (key not in window._modifiers and key not in window.command_keys.keys()): try: kstr = chr(key) except ValueError: pass #if 'shift' in window._modifiers and key\ # not in window.command_keys.keys(): # return if action == 'keyup': window.dispatch('on_key_up', key, scancode) return 0 # don't dispatch more key if down event is accepted if window.dispatch('on_key_down', key, scancode, kstr, window.modifiers): return 0 window.dispatch('on_keyboard', key, scancode, kstr, window.modifiers) elif action == 'textinput': text = args[0] window.dispatch('on_textinput', text) # XXX on IOS, keydown/up don't send unicode anymore. # With latest sdl, the text is sent over textinput # Right now, redo keydown/up, but we need to seperate both call # too. (and adapt on_key_* API.) #window.dispatch() #window.dispatch('on_key_down', key, None, args[0], # window.modifiers) #window.dispatch('on_keyboard', None, None, args[0], # window.modifiers) #window.dispatch('on_key_up', key, None, args[0], # window.modifiers) # unhandled event ! else: from kivy.logger import Logger Logger.trace('WindowSDL: Unhandled event %s' % str(event)) return 0