def on_code_input_focus(self, *args): '''Focus on CodeInput, to enable/disable keyboard listener ''' if args[1]: Window.bind(on_keyboard=self.on_keyboard) else: Window.unbind(on_keyboard=self.on_keyboard)
def on_listen_key(self, instance, value, *args): """Enable/disable keyboard listener """ if value: Window.bind(on_key_down=self._on_key_down) else: Window.unbind(on_key_down=self._on_key_down)
def exit_mouse_control(self): """ """ Window.unbind(mouse_pos=self._on_bound_mouse_move) self._mouse_controlled.remove(self) if not self._mouse_controlled: Window.ungrab_mouse() Window.show_cursor = True
def _update(self): if self.show_mode == "hover": Window.bind(mouse_pos=self._show_hover) elif self.show_mode == "touch": Window.unbind(mouse_pos=self._show_hover) self.bind(_hintwidget_x=self.ids._float_box.setter("x")) self.bind(_hintwidget_y=self.ids._float_box.setter("y"))
def _update(self): if self.show_mode == 'hover': Window.bind(mouse_pos=self._show_hover) elif self.show_mode == 'touch': Window.unbind(mouse_pos=self._show_hover) self.bind(_hintwidget_x=self.ids._float_box.setter('x')) self.bind(_hintwidget_y=self.ids._float_box.setter('y'))
def deactive(self): ''' This method unbinds event **on_key_down** for the keyboard. ''' Window.unbind(on_key_down=self.adaptee)
def on_pre_leave(self): Window.unbind(on_touch_down=self._listen_screen_touch) if self.go_home_schedule: self.go_home_schedule.cancel() if self.count_down_schedule: self.count_down_schedule.cancel() if self.order_state_schedule: self.order_state_schedule.cancel()
def _update_tooltip_widgets(self, *args): if self.use_tooltips and not self.disabled: Window.bind(mouse_pos=self.on_window_mouse_pos) self.on_window_mouse_pos(Window, Window.mouse_pos) else: Window.unbind(mouse_pos=self.on_window_mouse_pos) if self._last_tooltip_widget: self._last_tooltip_widget.hovered = False self._last_tooltip_widget = None
def _on_finish(self): Clock.unschedule(self._step) Window.unbind(on_keyboard=self._action_keys) self.p_btn.disabled = True self.n_btn.disabled = True position, shape, success = self._compute_statistics() App.get_running_app().add_result(self.history, position, shape, success, self.iter) self._display_statistics(position, shape, success)
def set_active(self, active): if (active and self.manual): #take over the keyboard Window.bind(on_key_down=self.key_down) Window.bind(on_key_up=self.key_up) elif (not active and self.manual): #relinquish the keyboard Window.unbind(on_key_down=self.key_down) Window.unbind(on_key_up=self.key_up)
def remove_bindings(self): # logging.info('Removing bindings for COV {0}'.format(self)) Window.unbind(on_key_down=self.on_key_down) Window.unbind(on_key_up=self.on_key_up) self.unbind(pos=self.update_info_label) self.unbind(size=self.update_info_label) self.unbind(height=self.update_info_label) self.unbind(width=self.update_info_label) App.get_running_app().unbind(editor_scale=self.setter('_editor_scale'))
def on_pre_leave(self): App.get_running_app().closeConnection() # Remove todas as mensagens da sessão. screen = App.get_running_app().root.get_screen("messageBox") screen.ids.box.clear_widgets() Window.unbind(on_request_close = self.stop) Window.unbind(on_keyboard = self.close_by_keyboard)
def on_parent(self, instance, value): try: # don't do keyboard shorcut on android platform import android return except ImportError: pass if value is not None: Window.bind(on_keyboard=self.on_window_keyboard) else: Window.unbind(on_keyboard=self.on_window_keyboard)
def tearDown(self, fake=False): '''When the test is finished, stop the application, and unbind our current flip callback. ''' from kivy.base import stopTouchApp from kivy.core.window import Window Window.unbind(on_flip=self.on_window_flip) stopTouchApp() if not fake and self.test_failed: self.assertTrue(False) super(GraphicUnitTest, self).tearDown()
def thumbnail_drop(self, _, src_path): src_path = src_path.decode(encoding='UTF-8', errors='strict') self.thumbnail = path.split(src_path)[1] self.pic_name = f'{self.filename}.jpg' cache_pic = pure_windows_path(cache_path, self.thumbnail) try: if path.exists(cache_pic): remove(cache_pic) if not path.exists(cache_path): makedirs(cache_path) copyfile(src_path, cache_pic) except Exception as ex: self.popup.title = f'Failed to generate thumbnail {ex}' return th = ThumbnailGenerator(src_path=cache_pic, dst_path='') th.start() th.join() if th.ok: self.popup.title = 'Thumbnail generated' cache_pic = pure_windows_path(cache_path, self.destination.strip('/'), thumb_dir, self.pic_name) print('CACHE PIC', th.thumb_path, cache_pic) try: if not path.exists(dst_path(cache_pic)): makedirs(dst_path(cache_pic)) if path.exists(cache_pic): remove(cache_pic) copyfile(th.thumb_path, cache_pic) self.sftp.put(cache_pic, pure_posix_path(self.destination, thumb_dir, self.pic_name), preserve_mtime=True) except Exception as ex: self.popup.title = f'Failed to upload thumbnail for {self.filename} {type(ex)}' ex_log(f'Failed to upload thumbnail for {self.filename} {ex}') else: self.popup.title = 'Thumbnail uploaded succesfully' self.originator.bind_external_drop() def dismiss_popup(_): self.popup.dismiss() self.originator.refresh_thumbnail(self.filename) Clock.schedule_once(dismiss_popup, .8) Window.unbind(on_dropfile=self.thumbnail_drop) else: self.popup.title = 'Failed to upload thumbnail'
def on_mouse_highlight(self, __, is_on): if is_on: Window.bind(mouse_pos=self._update_highlight, on_cursor_enter=self._show_highlight, on_cursor_leave=self._hide_highlight) self._update_highlight(Window, Window.mouse_pos) self._show_highlight() else: Window.unbind(mouse_pos=self._update_highlight, on_cursor_enter=self._show_highlight, on_cursor_leave=self._hide_highlight) self._hide_highlight() Config.mouse_highlight = is_on
def pick(self): widget = [None] ev = threading.Event() def on_touch_down(win, touch): app = App.get_running_app().root widget[0] = pick(app, touch.x, touch.y) ev.set() return True from kivy.core.window import Window Window.bind(on_touch_down=on_touch_down) ev.wait() Window.unbind(on_touch_down=on_touch_down) if widget[0]: return self.path_to(widget[0])
def on_close(self): self.unbind(motion_over_widget_func=self.bind_mouse_motion) self.unbind(motion_flee_widget_func=self.bind_mouse_motion) self.unbind(motion_outside_widget_func=self.bind_mouse_motion) self.unbind(drop_group=self.bind_drop_group) self.unregister_event_types("on_drag_start") self.unregister_event_types("on_being_dragged") self.unregister_event_types("on_drag_finish") self.unregister_event_types("on_motion_over") self.unregister_event_types("on_motion_flee") self.unregister_event_types("on_motion_outside") self.unregister_event_types("on_close") if self.motion_is_bound_to_window: Window.unbind(mouse_pos=self.on_motion) self.motion_is_bound_to_window = False
def on_editor_focus(self, widget, value): """Bind or unbind :py:meth:`.on_keyboard` depending on the focus of the editor It binds an event (with the method :py:meth:`.on_keyboard`) to the :py:attr:`kivy.core.window.Window.on_keyboard` attribute. :param widget: Instance of the :py:attr:`kivy.uix.widget` on which the event ocurred (:py:attr:`.editor`). :param value: Value of the property of the event (:py:attr:`.editor.focus` in this case). """ if value: Window.bind(on_keyboard=self.on_keyboard) Window.bind(on_mouse_down=self.on_mouse_down) else: Window.unbind(on_keyboard=self.on_keyboard) Window.unbind(on_keyboard=self.on_mouse_down)
def disable(self): Window.unbind(mouse_pos=self.highlight) Window.unbind(on_touch_move=self.potentially_resize_button) Window.unbind(on_touch_down=self.select) Window.unbind(on_touch_up=self.reset) for button in self.buttons: button.switch_corners() self.is_active = False
def on_mouse_pos(self, *args): if not self.parent: Window.unbind(mouse_pos=self.on_mouse_pos) if not self.get_root_window(): return # do proceed if I'm not displayed <=> If have no parent pos = args[1] # Next line to_widget allow to compensate for relative layout inside = self.collide_point(*self.to_widget(*pos)) if self.hovered == inside: # We have already done what was needed return self.border_point = pos self.hovered = inside if inside: self.dispatch('on_mouse_enter') else: self.dispatch('on_mouse_leave')
def on_close(self): self.unbind(motion_over_widget_func=self.bind_mouse_motion) self.unbind(motion_flee_widget_func=self.bind_mouse_motion) self.unbind(motion_outside_widget_func=self.bind_mouse_motion) self.unbind(motion_inside_widget_func=self.bind_mouse_motion) self.unbind(drop_group=self.bind_drop_group) self.unregister_event_types("on_motion_over") self.unregister_event_types("on_motion_flee") self.unregister_event_types("on_motion_outside") self.unregister_event_types("on_motion_inside") self.unregister_event_types("on_close") if self.motion_is_bound_to_window: Window.unbind(mouse_pos=self.on_motion) self.motion_is_bound_to_window = False for drop_group in drag_destinations_dict: if drag_destinations_dict[drop_group].get(self): del drag_destinations_dict[drop_group][self]
def on_focus(self, instance, value): if value: # focused if instance is self.txtinput_command_line: Window.unbind(on_keyboard=self.on_keyboard) Window.bind(on_keyboard=self.on_keyboard) else: # defocused if self.txtinput_command_line_refocus: self.txtinput_command_line_refocus = False if self.txtinput_command_line.get_root_window(): self.txtinput_command_line.focus = True self.txtinput_command_line.scroll_x = 0 if self.txtinput_run_command_refocus: self.txtinput_run_command_refocus = False instance.focus = True instance.scroll_x = 0 instance.text = u''
def set_manual(self, manual): self.manual = manual if (manual): #take over the keyboard Window.bind(on_key_down=self.key_down) Window.bind(on_key_up=self.key_up) #enter manual control mode (and stop) args = struct.pack(FORMATS[DRIVE_COMMAND], 0, 0) self.comm.send_command(self.current_id, DRIVE_COMMAND, args) self.control[0] = 0 self.control[1] = 0 else: #relinquish the keyboard Window.unbind(on_key_down=self.key_down) Window.unbind(on_key_up=self.key_up) self.key_matrix = [False, False, False, False] #return to auto control self.comm.send_command(self.current_id, AUTO_COMMAND)
def on_focus(self, instance, value): """Handle the focus on the command input """ if value: # focused if instance is self.txtinput_command_line: Window.unbind(on_key_down=self.on_key_down) Window.bind(on_key_down=self.on_key_down) else: # defocused Window.unbind(on_key_down=self.on_key_down) if self.txtinput_command_line_refocus: self.txtinput_command_line_refocus = False if self.txtinput_command_line.get_root_window(): self.txtinput_command_line.focus = True self.txtinput_command_line.scroll_x = 0 if self.txtinput_run_command_refocus: self.txtinput_run_command_refocus = False instance.focus = True instance.scroll_x = 0 instance.text = u""
def on_focus(self, instance, value): '''Handle the focus on the command input ''' if value: # focused if instance is self.txtinput_command_line: Window.unbind(on_key_down=self.on_key_down) Window.bind(on_key_down=self.on_key_down) else: # defocused Window.unbind(on_key_down=self.on_key_down) if self.txtinput_command_line_refocus: self.txtinput_command_line_refocus = False if self.txtinput_command_line.get_root_window(): self.txtinput_command_line.focus = True self.txtinput_command_line.scroll_x = 0 if self.txtinput_run_command_refocus: self.txtinput_run_command_refocus = False instance.focus = True instance.scroll_x = 0 instance.text = ''
def make_recordings(): names = [ "0-nav-drawer-open", "1-word-0", "2-word-1", "3-word-images", "4-import", "5-export", ] toast(f"Screenshot with F8.") for i, name in enumerate(names): print(i, name) rec = Recorder(filename=f"recordings/{name}.kvi") stop_rec = partial(stop_recording, recorder=rec) Window.bind(on_keyboard=stop_rec) rec.record = True while rec.record: sleep(0.5) Window.unbind(on_keyboard=stop_rec) main_thread_screenshot(f"../screenshots/{name}.png") rename_screenshots() sleep(2) os._exit(0)
def span_keyboard_on_focus(instance, value): """Span the keyboard when the instance is focus or unfocus (value is bool) """ to_move = Window.children[0] if value: # User focus def move(window, height): if instance.y <= height: offset = 0 if type(to_move) == Contacts else to_move.y y = height - instance.y + offset + 10 # Avoid reset when we change focus Animation.cancel_all(to_move, 'y') Animation(y=y, t='linear', d=0.5).start(to_move) instance._keyboard_move = move Window.bind(keyboard_height=move) move(Window, Window.keyboard_height) else: Window.unbind(keyboard_height=instance._keyboard_move) reset = 0 if type(to_move) == Contacts else \ (Window.height - to_move.height) / 2 Animation(y=reset, t='in_out_cubic').start(to_move)
def on_pre_leave(self): Window.unbind(on_keyboard=self.voltar)
def on_leave(self): Window.unbind(mouse_pos=self.on_mouse_pos) Window.unbind(on_key_down=self.on_key_down)
def cleanup(self): Window.unbind(on_key_down=self.key_action) self._geo_provider.shutdown()
def on_pre_leave(self): Window.unbind(on_keyboard=self.back)
def on_focus(self, instance, value): if value: Window.bind(on_keyboard=self._on_keyboard) else: Window.unbind(on_keyboard=self._on_keyboard) self.dispatch('on_text_validate')
def on_leave(self): Window.unbind(on_keyboard=self.on_key_down) nfc_instance.remove_action(self.attendance_registered)
def on_leave(self): Window.unbind(on_keyboard=self.on_key_down) self.clean_widgets() nfc_instance.remove_action(self.update_tag_id)
def on_pre_leave(self): Window.unbind( on_keyboard=self.voltar) #desativa a funcionalidade da tecla
def on_leave(self): Window.unbind(on_keyboard=self.on_key_down)
def _unbind_keyboard(self): super()._unbind_keyboard() Window.unbind(on_textedit=self.window_on_textedit)
def lose_focus(self): Window.unbind(on_key_down=self.on_key_down)
def on_leave(self): self.save_all_points() Window.unbind(on_motion=self.on_motion) Window.unbind(on_resize=self.on_resize)
def unbind(self): self._km.unbind(movement=self.notify_movement_event) self._km.unbind(action=self.notify_action) Window.unbind(on_touch_down=self.notify_shoot) Window.unbind(mouse_pos=self.notify_orientation)
def on_complete(self, *args): '''Dispatch a completion selection ''' Window.unbind(on_key_down=self.on_key_down)
def cleanup_view(self): Window.unbind(on_motion=self.on_motion)
def on_parent(self, *args): if self.parent: Window.bind(on_key_down=self._on_keyboard_down) else: Window.unbind(on_key_down=self._on_keyboard_down)
def on_cancel(self, *args): '''Disable key listener on cancel ''' Window.unbind(on_key_down=self.on_key_down)