def on_start(self): self.spacing = 0.5 * self.root.width self.background = self.root.ids.background self.bird = self.root.ids.bird Clock.schedule_interval(self.update, 1.0/500.0) Window.bind(on_key_down=self.on_key_down) self.background.on_touch_down = self.user_action
def my_screen(self): self.ws = WeatherScreen() self._image_path = os.path.join(graphics_dir, "na.png") self.ws.change_image(self._image_path, self._image_path) self._weather_updater() Clock.schedule_interval(self._weather_updater, 300) return self.ws
def __init__(self, **kwargs): # Make sure opengl context exists EventLoop.ensure_window() self.canvas = RenderContext(use_parent_projection=True, use_parent_modelview=True) with self.canvas: self.fbo = Fbo(size=self.size) with self.fbo.before: PushMatrix() with self.fbo: ClearColor(0, 0, 0, 0) ClearBuffers() self._background_color = Color(*self.background_color) self.fbo_rectangle = Rectangle(size=self.size) with self.fbo.after: PopMatrix() super(EffectWidget, self).__init__(**kwargs) Clock.schedule_interval(self._update_glsl, 0) self.bind(size=self.refresh_fbo_setup, effects=self.refresh_fbo_setup, background_color=self._refresh_background_color) self.refresh_fbo_setup() self._refresh_background_color() # In case thi was changed in kwargs
def build(self): view=View() Clock.schedule_interval(view.update, 1./10.) return view
def __init__(self, cache_dir='cache', **kwargs): from kivy.base import EventLoop EventLoop.ensure_window() CACHE['directory'] = cache_dir self._invalid_scale = True self._tiles = [] self._tiles_bg = [] self._tilemap = {} self._layers = [] self._default_marker_layer = None self._need_redraw_all = False self._transform_lock = False self.trigger_update(True) self.canvas = Canvas() self._scatter = MapViewScatter() self.add_widget(self._scatter) with self._scatter.canvas: self.canvas_map = Canvas() self.canvas_layers = Canvas() with self.canvas: self.canvas_layers_out = Canvas() self._scale_target_anim = False self._scale_target = 1. self._touch_count = 0 Clock.schedule_interval(self._animate_color, 1 / 60.) self.lat = kwargs.get("lat", self.lat) self.lon = kwargs.get("lon", self.lon) super(MapView, self).__init__(**kwargs)
def __init__(self, **kwargs): self.slides = [] super(Slides, self).__init__(**kwargs) Window.bind(on_keyboard=self.on_keyboard) Clock.schedule_interval(self.increase_time, 1 / 30.0) Clock.schedule_once(self.init, 0) self.add_widget(SlidesForeground(slides=self))
def build(self): self.service = None self.start_service() global RootApp RootApp = self # NavigationDrawer self.navigationdrawer = NavDrawer() # SidePanel side_panel = SidePanel() self.navigationdrawer.add_widget(side_panel) # MainPanel self.main_panel = MainPanel() # color picker self.color_selector = ColorSelector() # size selector self.size_selector = SizeSelector() self.navigationdrawer.anim_type = 'slide_above_simple' self.navigationdrawer.add_widget(self.main_panel) osc.init() oscid = osc.listen(port=3002) osc.bind(oscid, self.reCallback, '/date') Clock.schedule_interval(lambda *x: osc.readQueue(oscid), 0) return self.navigationdrawer
def __init__(self): android.accelerometer_enable(True) Clock.schedule_interval(self.detect_motion, 0.1) self.last = None self.history = deque() self.shake_callback = None self.enabled = True
def setupView(self): # Check gromacs version self.checkGromacVersion() #Check if folder is exits call('mkdir '+self.dataController.getdata('path '), shell=True) call('mkdir '+self.dataController.getdata('path ')+'/run', shell=True) call('mkdir '+self.dataController.getdata('path ')+'/output', shell=True) call('mkdir '+self.dataController.getdata('path ')+'/output/receptor', shell=True) call('mkdir '+self.dataController.getdata('path ')+'/output/ligand', shell=True) call('mkdir '+self.dataController.getdata('path ')+'/analyse', shell=True) runfolders = check_output('ls '+self.dataController.getdata('path ')+'/run/', shell = True).splitlines() if len(runfolders) > 0: popup = RemoveDialog() popup.open() else: call('rm -r '+self.dataController.getdata('path ')+'/run/*', shell=True) call('rm -r '+self.dataController.getdata('path ')+'/output/ligand/*', shell=True) call('rm -r '+self.dataController.getdata('path ')+'/output/receptor/*', shell=True) self.thread = Process(target= self.gromacsRun.main) self.thread.start() #Check log repeat_times = int(self.dataController.getdata('repeat_times ')) self.progressUnit = 1000/(4.5 + repeat_times)/len(Variable.parsepdb.Ligands) self.progressPoint = 0 self.dataController.setdata('status', '') Clock.schedule_interval(self.check_log, 5) Clock.schedule_interval(self.spin_progress, 0.05) # Clock.schedule_interval(self.pymol_log, 300) #close pymol self.pymol.cmd.window('hide')
def __init__(self, **kwargs): super(KYRScreenManager, self).__init__(**kwargs) self.loadAssets() self.room1 = KYRScreen(name='room1', bg = 'assets/art/room1.png', music = self.overworld, startLocations = dict(top = (512, 96), bottom = (512, 416), left = (928, 256), right = (96, 256) )) # inverse directions, based on direction you enter from self.room2 = KYRScreen(name='room2', bg = 'assets/art/room2.png', startLocations = dict(top = (512, 96), bottom = (512, 416), left = (928, 256), right = (96, 256) )) #self.add_widget(room1) #self.add_widget(room2) self.buildLocationEvent() self.transition=WipeTransition() self.switch_to(self.room1) self.room1.isCurrent = True Clock.schedule_interval(self.updatePlayerLocation, 0.5)
def build(self): self.settings_cls = SettingsWithSidebar game = PlanetGame(do_rotation=False,do_translation=False) # Settings come in as unicode! sunmass = float(App.get_running_app().config.get('planetapp','defaultsunmass')) game.sunmass = sunmass game.gravity = float(App.get_running_app().config.get('planetapp','gravity')) game.planetmass = float(App.get_running_app().config.get('planetapp','planetmass')) game.resetmass = float(App.get_running_app().config.get('planetapp','resetmass')) game.add_planet(True, (100,100), (0,0), sunmass, 10, (1,1,1)) Clock.schedule_interval(game.update, 1.0 / 120.0) self.root = PlanetGameLayout() self.root.add_widget(game) b = Button(text="Reset",size_hint=(.3,.05),pos_hint={'x':.7,'y':0}) b.bind(on_press=self.root.clear_planets) self.root.add_widget(b) b2 = SettingsButton(text="Settings",size_hint=(.3,.05),pos_hint={'x':.4,'y':0}) self.root.add_widget(b2) b3 = Button(text="Next",size_hint=(.3,.05),pos_hint={'x':.1,'y':0}) b3.bind(on_press=self.root.next_trajectory) self.root.add_widget(b3) self.root.reset_game()
def __init__(self, **kwargs): kwargs.setdefault('filename', None) kwargs.setdefault('eos', 'stop') kwargs.setdefault('async', True) kwargs.setdefault('autoplay', False) super(VideoBase, self).__init__() self._wantplay = False self._buffer = None self._filename = None self._texture = None self._volume = 1. self._state = '' self._autoplay = kwargs.get('autoplay') self._async = kwargs.get('async') self.eos = kwargs.get('eos') if self.eos == 'pause': Logger.warning("'pause' is deprecated. Use 'stop' instead.") self.eos = 'stop' self.filename = kwargs.get('filename') Clock.schedule_interval(self._update, 1 / 30.) if self._autoplay: self.play()
def __init__(self, **kwargs): super(TheCatWidget, self).__init__(**kwargs) Clock.schedule_interval(self.Update, 1.0 / 60.0) self._StateMachine = statemachine.StateMachine(self) self._StateMachine.SetState(statemachine.StateCatWander()) self._CatPettingCounter = 0
def build(self): """Initializes the user interface and starts timed events.""" #TODO: Reorganize and consolidate; make necessary helper functions self.title = 'Open Lighting Architecture' self.ui_queue = Queue() self.layout = BoxLayout(orientation='vertical') self.selected_universe_service = UniverseSelectedService() self.ola_listener = OLAListener(self.ui_queue, self.create_select_server, self.create_ola_client, self.start_ola, self.stop_ola) #Screen creation and layout placing self.screen_tabs = ScreenTabs() self.monitor_screen = MonitorScreen(self.ola_listener, self.selected_universe_service, name='DMX Monitor') self.console_screen = ConsoleScreen(self.ola_listener, self.selected_universe_service, name='DMX Console') self.devsets = MainScreen(self.ola_listener, self.selected_universe_service, name='Device Settings') self.screen_tabs.ids.monitor_screen.add_widget(self.monitor_screen) self.screen_tabs.ids.console_screen.add_widget(self.console_screen) self.screen_tabs.ids.settings_screen.add_widget(self.devsets) self.layout.add_widget(self.screen_tabs) Clock.schedule_interval(lambda dt: self.display_tasks(), self.EVENT_POLL_INTERVAL) Clock.schedule_interval(self._update_clock, 1 / 60.) return self.layout
def render_boggle_game_screen(self): logging.info("Rendering game screen.") self.clear_widgets() def handle_swipe_callback(self): # TODO: add in swipes or keyboard for user to input words. pass self.solve_boggle.set_board(self.num_columns, self.num_rows, None) logging.info("Solve Boggle created.") self.render_boggle_layout("", handle_swipe_callback, self.grid) logging.info("About to loop through buttons.") for i, button in enumerate(self.buttons): if i not in self.ignore: button.text = "[size=%s]%s[/size]" % (int(self.font), self.solve_boggle.boggle.boggle_array[i].upper()) else: button.text = "" timer = Label(text="%s" % self.game_time, size_hint=(1, 1.0/self.num_rows), font_size=self.font) def timer_callback(dt): timer.text = str(int(timer.text) -1) if int(timer.text) == 0: self.render_boggle_solution_screen() Clock.schedule_interval(timer_callback, 1) self.add_widget(self.grid) self.add_widget(timer) # TODO: make this part of a function for a timer callback so it doesn't take time away from displaying the screen. self.words = self.solve_boggle.solve(ignore_indexes=self.ignore) logging.info("Got words.")
def build(self): self.load_data() root = Widget(size=(1080,1920), size_hint=(None, None)) self.movie_screen = MovieScreen(app=self) root.add_widget(self.movie_screen) self.thank_you_screen = ThankYouScreen(app=self) root.add_widget(self.thank_you_screen) self.info_screen = InfoScreen(app=self) root.add_widget(self.info_screen) self.layout = root viewport = Viewport(size=(1080,1920)) Clock.schedule_once(viewport.fit_to_window) viewport.add_widget(Image(source='images/mainbg.png', pos=(0,0), size=(1080,1920))) viewport.add_widget(root) self.logo = LogoImage(source='images/logo.png', y=1620, size=(1080,300), bgcolor=[.1,.1,.1]) viewport.add_widget(self.logo) self.active_screen = self.info_screen Clock.schedule_once(self.start) Clock.schedule_interval(self.print_fps, 2.0) return viewport
def __init__(self, **kwargs): super(MainView, self).__init__(**kwargs) data_items = [] data_items.append(DataItem()) data_items.append(DataItem()) data_items.append(DataItem()) list_item_args_converter = lambda row_index, obj: {'text': obj.name, 'size_hint_y': None, 'height': 25} self.list_adapter = \ ListAdapter(data=data_items, args_converter=list_item_args_converter, selection_mode='single', propagate_selection_to_data=False, allow_empty_selection=False, cls=ListItemButton) self.list_view = ListView(adapter=self.list_adapter) self.add_widget(self.list_view) self.toggle = 'adding' Clock.schedule_interval(self.update_list_data, 1)
def __init__(self, **kwargs): self.app = App.get_running_app() self.app.pfish = self self.eatsound = SoundLoader.load(self.app.path+'/eat.wav') self.diesound = SoundLoader.load(self.app.path+'/die.wav') super(PlayerFish, self).__init__(**kwargs) Clock.schedule_interval(self.collision, 1/60.0)
def play(self): if not self._data: return self._channel = self._data.play() # schedule event to check if the sound is still playing or not Clock.schedule_interval(self._check_play, 0.1) super(SoundPygame, self).play()
def use(self, direction, active): if active and self.manager.current == 'game': Clock.unschedule(self.func) self.func = partial(self.move, direction) Clock.schedule_interval(self.func, self.player_speed) else: Clock.unschedule(self.func)
def restart(self): self.ids.highscore.text = '' self.running = 1 Clock.schedule_interval(self.is_running, 1/60.0) Clock.schedule_interval(self.app.pfish.collision, 1/60.0) self.show_buttons() self.current = 'game'
def build(self): self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.buildOrganells() root = FloatLayout(width=(Window.width),height=(Window.height),) with root.canvas: Line(circle=(Window.width/2,Window.height/2,Window.height/2)) for obj in self.organelles: root.add_widget(obj[1]) for obj in self.mitochondria: root.add_widget(obj[1]) self.buildATP() root.add_widget(self.ATP) Clock.schedule_interval(self.makeSureOrganellesAreAlive, 1) Clock.schedule_interval(self.updateGlucose,10) return root
def restart_button(obj): #reset game self.removeScore() for k in self.asteroidList: self.remove_widget(k) self.ship.xpos = Window.width*0.25 self.ship.ypos = Window.height*0.5 self.minProb = 1780 self.asteroidScore = 0 self.asteroidList = [] self.parent.remove_widget(restartButton) Clock.unschedule(self.update) Clock.schedule_interval(self.update, 1.0/60.0) restartButton.size = (Window.width*.3,Window.width*.1) restartButton.pos = Window.width*0.5-restartButton.width/2, Window.height*0.53 restartButton.bind(on_release=restart_button) #we will want to bind the parent to listen for things from certain bubbles #*** It's important that the parent get the button so you can click on it #otherwise you can't click through the main game's canvas self.parent.add_widget(restartButton) #now draw the score widget self.showScore()
def on_focus(self, instance, value, *largs): win = self._win if not win: self._win = win = self.get_root_window() if not win: # we got argument, it could be the previous schedule # cancel focus. if len(largs): Logger.warning('Textinput: ' 'Cannot focus the element, unable to get root window') return else: Clock.schedule_once(partial(self.on_focus, self, value), 0) return if value: keyboard = win.request_keyboard(self._keyboard_released, self) self._keyboard = keyboard keyboard.bind( on_key_down=self._keyboard_on_key_down, on_key_up=self._keyboard_on_key_up) Clock.schedule_interval(self._do_blink_cursor, 1 / 2.) else: keyboard = self._keyboard keyboard.unbind( on_key_down=self._keyboard_on_key_down, on_key_up=self._keyboard_on_key_up) keyboard.release() self.cancel_selection() Clock.unschedule(self._do_blink_cursor) self._win = None
def build(self): Builder.load_file('bouncing.kv') self.title = 'Two bouncing balls' root = RootWidget() Clock.schedule_interval(root.update1, 1.0/60) Clock.schedule_interval(root.update2, 1.0/60) return root
def __init__(self, **kwargs): super(GUI, self).__init__(**kwargs) #setup label for the score self.score = Label(text = '0') self.score.y = Window.height*0.8 self.score.x = Window.width*0.2 def check_score(self,obj): #update credits self.score.text = str(self.asteroidScore) self.bind(asteroidScore = check_score) self.add_widget(self.score) #now we create a ship object self.ship = Ship(imageStr = './ship.png') self.ship.x = Window.width/4 self.ship.y = Window.height/2 self.add_widget(self.ship) #self.ship.drawArrow()#start the flames Clock.schedule_interval((self.ship.drawArrow), 0.1) ##l = Label(text='Flappy Ship') #give the game a title ##l.x = Window.width/2 - l.width/2 ##l.y = Window.height*0.8 ##self.add_widget(l) #add the label to the screen #now we create a ship object #notice how we specify the ship image self.ship = Ship(imageStr = './ship.png') self.ship.x = Window.width/4 self.ship.y = Window.height/2 self.add_widget(self.ship)
def handle_trash_talk(self, trigger): if trigger in [Trigger.GAME_END, Trigger.GAME_PAUSE]: Clock.unschedule(self.trash) if trigger in [Trigger.GAME_START, Trigger.GAME_RESUME, Trigger.GOAL]: Clock.unschedule(self.trash) Clock.schedule_interval(self.trash, random.randint(settings.TRASH_MIN_DELAY, settings.TRASH_MAX_DELAY))
def build(self): ''' build the app ''' #text field for easting self.e_txt = TextInput(multiline=False) self.e_txt.text = '' #text field for northing self.n_txt = TextInput(multiline=False) self.n_txt.text = '' #sets the accordion panel for the timestamp root = Accordion(orientation='horizontal') self.item = AccordionItem(title='Current time is '+time.asctime()) image = CameraWidget(size_hint = (3.5, 1.0)) #initiate serial port for gps self = init_serial(self,COMNUM) # is the com number this needs to read a config file or something # add image to AccordionItem self.item.add_widget(image) #set clock to poll time and posotion on different threads Clock.schedule_interval(self._update_time, 1) #update time Clock.schedule_interval(self._update_pos, 1) #1.6) #update position root.add_widget(self.item) return root
def install_gobject_iteration(): '''Import and install gobject context iteration inside our event loop. This is used as soon as gobject is used (like gstreamer) ''' from kivy.clock import Clock import gobject if hasattr(gobject, '_gobject_already_installed'): # already installed, don't do it twice. return gobject._gobject_already_installed = True # get gobject mainloop / context loop = gobject.MainLoop() gobject.threads_init() context = loop.get_context() # schedule the iteration each frame def _gobject_iteration(*largs): # XXX we need to loop over context here, otherwise, we might have a lag. loop = 0 while context.pending() and loop < 10: context.iteration(False) loop += 1 Clock.schedule_interval(_gobject_iteration, 0)
def start_timer(self): self.ids["clock"].text = "0:00:00" print(self.time) Clock.schedule_interval(self.count_timer, 1.0)
def __init__(self, **kwargs): super(ImageWidget, self).__init__(**kwargs) self.image_capture = cv2.VideoCapture(0) Clock.schedule_interval(self.update, 1.0 / 30)
def __init__(self, **kwargs): super(wakeAlarmController, self).__init__(**kwargs) Clock.schedule_interval(partial(myAlarm.checkAlarm, self.alarm_func), 1)
def __init__(self, cap, **kwargs): super(KivyCamera, self).__init__(**kwargs) self.register_event_type("on_update") self._capture = None self._capture = cap Clock.schedule_interval(self.update, 1.0 / self.fps)
def start_new_clock(self): self.schedule = Clock.schedule_interval(self.thread_netcheck, 3)
def start_updating(self): if self.capture: self.player_clock = Clock.schedule_interval( self.update, 1.0 / self.fps)
def build(self): #self._cap = cv2.VideoCapture(video_file) # define botton kvButtonPlay = Button(text="play", size_hint=(1.0, 0.1)) kvButtonPlay.bind(on_press=self.buttonCallbackPlay) kvButtonStop = Button(text="stop", size_hint=(1.0, 0.1)) kvButtonStop.bind(on_press=self.buttonCallbackStop) # define image self.kvImage_raw = Image() self.kvImage_pros = Image() # define video layout and add image #VideoLayout = BoxLayout(orientation='vertical') VideoLayout = GridLayout(cols=2) VideoLayout.add_widget(self.kvImage_raw) VideoLayout.add_widget(self.kvImage_pros) # BoxLayout #scrollLayout = BoxLayout(orientation='vertical', size_hint=(1.0, 0.2)) self.SliderLabel = Label(text='...', size_hint=(1.0, 0.1), halign='center') SliderBar = Slider(min=1, max=self.num_frames, size_hint=(1.0, 0.1)) SliderBar.bind(value=self.slideCallback) #kvLayout1.add_widget(kvLayout2) #kvLayout2.add_widget(kvSlider1) # add buttons to layout self.subtitle = Label(text='subtitle: ' + '...', halign='left', color=(1, 1, 1, 1), size_hint=(1.0, 0.4)) self.relation_obj = Label(text='relation_obj: ' + '...', halign='left', color=(1, 1, 1, 1)) ButtonLayout = BoxLayout(orientation='vertical', size_hint=(1.0, 1.0)) VideoLayout.add_widget(ButtonLayout) ButtonLayout.add_widget(self.subtitle) #ButtonLayout.add_widget(self.relation_obj) ButtonLayout.add_widget(self.SliderLabel) ButtonLayout.add_widget(SliderBar) ButtonLayout.add_widget(kvButtonPlay) ButtonLayout.add_widget(kvButtonStop) # add text self.second_label = Label(text='second: ' + str(self.seconds), halign='left', color=(1, 1, 1, 1)) self.sound_label = Label(text='sound: ' + '...', halign='left', color=(1, 1, 1, 1)) self.place_label = Label(text='place: ' + '...', halign='left', color=(1, 1, 1, 1)) self.behavior_label = Label(text='behavior: ' + '...', halign='left', color=(1, 1, 1, 1)) self.emotion_label = Label(text='emotion: ' + '...', halign='left', color=(1, 1, 1, 1)) self.relation_kbb = Label(text='knowlege_base: ' + '...', halign='left', color=(1, 1, 1, 1)) # add information in Label layout LabelLayout = BoxLayout(orientation='vertical', size_hint=(1.0, 1.0)) VideoLayout.add_widget(LabelLayout) LabelLayout.add_widget(self.second_label) LabelLayout.add_widget(self.sound_label) LabelLayout.add_widget(self.place_label) LabelLayout.add_widget(self.behavior_label) LabelLayout.add_widget(self.emotion_label) LabelLayout.add_widget(self.relation_kbb) LabelLayout.add_widget(self.relation_obj) # wait for opencv video capture #while not self._cap.isOpened(): # pass #self._cap.set(cv2.CAP_PROP_FPS, 5) # update/clear schedules Clock.schedule_interval(self.update, 1.0 / self.frame_rate) Clock.schedule_interval(self.clear, self.clear_rate) Clock.schedule_interval(self.clear_kb, self.clear_rate * 5) return VideoLayout
def Cancelar_(self, arg): self.screen_manager.current = "Scr_2" Clock.schedule_interval(self.animate, 0.01)
def enable(self): self.light.enable() Clock.schedule_interval(self.get_illumination, 1 / 20.)
def __init__(self): super(ShowGUI, self).__init__() print("ShowGUI.__init__() entry") Clock.schedule_interval(self.get_from_queue, 1.0)
def on_start(self): Clock.schedule_interval(self.update, 0)
def request_keyboard(self, callback, target, input_type='text'): self._sdl_keyboard = super(WindowSDL, self).\ request_keyboard(callback, target, input_type) self._win.show_keyboard(self._system_keyboard, self.softinput_mode) Clock.schedule_interval(self._check_keyboard_shown, 1 / 5.) return self._sdl_keyboard
def build(self): #print('\n\n\n*********building**********\n\n\n') display = FrictionDisplay() Clock.schedule_interval(display.update, 30.0 / 60.0) return display
def do_the_update( self, args ): # Активує виконання функції self.to_add_every_second раз в одну секундку Clock.schedule_interval(self.to_add_every_second, 1)
def on_press(self): self.source = self.realtexture_pressed self.reload() Clock.schedule_interval(self.function, 1.0 / 10.0)
def on_enter(self): self.timer = Clock.schedule_interval(self.update, 120) self.update()
def callback(self, *args): Clock.schedule_interval(self.getStatusPlayrs, 1)
def solve(self): self.solve_thread = threading.Thread(target=self._solve) self.solve_thread.start() Clock.schedule_interval(self.progress_msg, 0.1)
def build(self): spawning = SpawningScreen() Clock.schedule_interval(spawning.update, 1.0 / 60.0) return spawning
def clientCallback(self, *args): Clock.schedule_interval(self.callbackAllSettings, 1) Clock.schedule_interval(self.callbackVotingResult, 1)
def start(self): self.serve_ball() Clock.schedule_interval(self.update, 1.0 / 60.0)
def build(self): game = PongGame() game.serve_ball() Clock.schedule_interval(game.update, 1.0/60.0) return game
def on_start(self): """When app is started, this is called, which starts a clock calling update""" Clock.schedule_interval(self.update, 0.1)
def __init__(self, **kwargs): self.app = kwargs.pop('app') self.micro_sim = kwargs.pop('micro_sim') self.dpi = kwargs.pop('dpi') super(RunWindow, self).__init__(**kwargs) self.ascii = ASCIIGrid(dpi=self.dpi) self.reg_table = RegisterTable(dpi=self.dpi) self.mem_table = MemoryTable(dpi=self.dpi) self.inst_table = InstructionTable(dpi=self.dpi) self.light = TrafficLights() self.editor = TextEditor(dpi=self.dpi) self.seven_segment_display = SevenSegmentDisplay() self.reg_table.get_data() self.mem_table.data_list.clear() self.mem_table.get_data() self.inst_table.get_data(self.micro_sim.program_counter, self.micro_sim.disassembled_instruction()) self.hex_keyboard_label = Label(text='HEX KEYBOARD', font_size=sp(20), color=(0, 0, 0, 1)) # Create variable of scheduling instance so that it can be turned on and off, # to avoid repeat of the same thread self.editor_loader = Clock.schedule_interval(self.check_loader, 0.1) self.blinking_on = Clock.schedule_interval(self.light.intermittent_on, 0.5) self.blinking_off = Clock.schedule_interval( self.light.intermittent_off, 0.3) # Creates a clock thread that updates all tables and i/o's every 0.2 seconds. Does not get cancelled. self.event_io = Clock.create_trigger(self.update_io) # Since the instancing of the events actually starts the scheduling, needs to be canceled right away self.blinking_on.cancel() self.blinking_off.cancel() self.hex_keyboard_layout = HexKeyboard(mem_table=self.mem_table, dpi=self.dpi) box = FloatLayout() box.add_widget(self.hex_keyboard_layout) box.add_widget(self.hex_keyboard_label) self.popup = Popup( title='Hex Keyboard', content=box, background='assets/images/plain-white-background.jpg', title_color=(0, 0, 0, 0), separator_color=(1, 1, 1, 1)) if self.dpi < 192: self.popup.size_hint = (None, None) self.popup.size = (450, 400) self.hex_keyboard_label.pos_hint = {'x': dp(0.01), 'y': dp(0.35)} else: self.popup.size_hint_x = dp(0.3) self.popup.size_hint_y = dp(0.3) self.popup.pos_hint = {'x': dp(0.1), 'y': dp(0.13)} self.hex_keyboard_label.pos_hint = {'x': dp(0.01), 'y': dp(0.13)} self.add_widget(self.reg_table) self.add_widget(self.inst_table) self.add_widget(self.mem_table) self.add_widget(self.light) self.add_widget(self.seven_segment_display) self.add_widget(self.editor) self.add_widget(self.ascii)
def do_start_stop_toggle(self): if not self.reading_thread_enabled: # to open the serial port, start a reading thread, and schedule a drawing timer selected_device = self.ids.device_list.get_first_selected_device_name( ) if selected_device is not None: try: if platform == 'android': device = usb.get_usb_device(selected_device) if not device: raise SerialException( "Device {} not present!".format( selected_device)) if not usb.has_usb_permission(device): if self.is_asking_permission != True: self.is_asking_permission = True usb.request_usb_permission(device) Clock.schedule_once( lambda dt: self.do_start_stop_toggle(), 0.5) return self.is_asking_permission = False self.serial_port = serial4a.get_serial_port( selected_device, App.get_running_app().config.getint( 'communication', 'baud_rate'), App.get_running_app().config.getint( 'communication', 'data_bits'), App.get_running_app().config.get( 'communication', 'parity'), float(App.get_running_app().config.get( 'communication', 'stop_bits')), timeout=1) else: self.serial_port = Serial( selected_device, App.get_running_app().config.getint( 'communication', 'baud_rate'), App.get_running_app().config.getint( 'communication', 'data_bits'), App.get_running_app().config.get( 'communication', 'parity'), float(App.get_running_app().config.get( 'communication', 'stop_bits')), timeout=1) except SerialException: self.popup_a_notification( "The selected device can not be configured.\r\nPlease check the permissions and close me!" ) if self.serial_port is not None and self.serial_port.is_open and not self.read_thread: self.serial_port.reset_input_buffer() self.read_thread = threading.Thread( target=self.read_serial_msg_thread) self.reading_thread_enabled = True self.read_thread.start() # Since there is a queue to adjust inconsistent throughputs, we can set a small time interval to check if sampes exist in queue . Clock.schedule_interval(self.draw_waveform, 1 / 50.) self.ids.toggle_button.text = "Stop acquisition" else: self.popup_a_notification("No device selected. Close me!") else: # to unschedule the drawing timer and stop the reading thread self.reset_plots() Clock.unschedule(self.draw_waveform) self.reading_thread_enabled = False with self.port_thread_lock: self.serial_port.close() self.read_thread.join() self.read_thread = None self.ids.toggle_button.text = "Start acquisition"
def label_countdown(self): self.count_down_clock = Clock.schedule_interval( self.update_label, UPDATE_INTERVAL) return 'Page closing in {} seconds'.format(self.seconds)
def __init__(self, **kwargs): super(FireSleep, self).__init__(**kwargs) Clock.schedule_interval(partial(myAlarm.checkSleep, self.sleep_func), 1)
def __init__(self, **kwargs): super(ClockLabel, self).__init__(**kwargs) Clock.schedule_interval(self.update, 1)
def nfc_enable(self): Logger.debug('NFC: enable') if self._initialised: Clock.schedule_interval(self.on_new_intent, 22)
def on_enter(self): # We only need to update the clock every second. self.timer = Clock.schedule_interval(self.update, 1)
def anim_reset(self, allow_anim): '''Reset an animation if available. .. versionadded:: 1.0.8 :Parameters: `allow_anim`: bool Indicate whether the animation should restart playing or not. Usage:: # start/reset animation image.anim_reset(True) # or stop the animation image.anim_reset(False) You can change the animation speed whilst it is playing:: # Set to 20 FPS image.anim_delay = 1 / 20. ''' # stop animation Clock.unschedule(self._anim) if allow_anim and self._anim_available: Clock.schedule_interval(self._anim, self.anim_delay) self._anim()