我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用kivy.app.App()。
def build_notification(self, **kwargs): if kwargs['activity'] == 'App': for k in ( 'id', 'ticker', 'subtext', 'message', 'ongoing', 'autocancel', 'title'): self.nbuilder.kwargs[k] = kwargs[k] if kwargs['vibrate']: self.nbuilder.kwargs['vibrate'] = 1.0 else: self.nbuilder.kwargs['vibrate'] = 0.0 if kwargs['sound']: self.nbuilder.kwargs['sound'] = path[4] + '/audio/beep1.wav' else: self.nbuilder.kwargs['sound'] = '' self.nbuilder.build() else: msg = json.dumps( {'method': 'build_notification', 'kwargs': kwargs}) Logger.info('build_notification: %s' % (msg)) self.send_msg(msg)
def on_touch_up( self, touch ): global minUITimer global lightOffTimer if touch.grab_current is self: touch.ungrab( self ) with thermostatLock: Clock.unschedule( light_off ) if minUITimer != None: Clock.unschedule( show_minimal_ui ) minUITimer = Clock.schedule_once( show_minimal_ui, minUITimeout ) lighOffTimer = Clock.schedule_once( light_off, lightOff ) GPIO.output( lightPin, GPIO.HIGH ) self.manager.current = "thermostatUI" log( LOG_LEVEL_DEBUG, CHILD_DEVICE_SCREEN, MSG_SUBTYPE_TEXT, "Full" ) return True ############################################################################## # # # Kivy Thermostat App class # # # ##############################################################################
def on_touch_up( self, touch ): global minUITimer if touch.grab_current is self: touch.ungrab( self ) with thermostatLock: if minUITimer != None: Clock.unschedule( show_minimal_ui ) minUITimer = Clock.schedule_once( show_minimal_ui, minUITimeout ) self.manager.current = "thermostatUI" log( LOG_LEVEL_DEBUG, CHILD_DEVICE_SCREEN, MSG_SUBTYPE_TEXT, "Full" ) return True ############################################################################## # # # Kivy Thermostat App class # # # ##############################################################################
def __init__(self, **kwargs): super(WebUpdate, self).__init__(**kwargs) self.rv_append('Init Apache App') self.apu = ApacheUpdater() if platform == 'android': self.apu.version_path = path[4]+'/web_updater/version.txt' self.apu.update_path = path[4]+'/' self.ids.fcs.path = path[4] else: self.apu.version_path =path[0]+'/web_updater/version.txt' self.apu.update_path = path[0]+'/' self.ids.fcs.path = path[0] self.apu.http_path = 'http://localhost/' self.apu.logger = self.rv_append try: self.apu.check_update_thread() except: self.rv_append(traceback.format_exc()) self.ids.pep_widget.on_pep1 = self.browse_pep1 self.ids.pep_widget.on_pep8 = self.browse_pep8 self.ids.pep_widget.on_pep249 = self.browse_pep249 self.ids.pep_widget.on_pep255 = self.browse_pep255
def handle_msg(self, *args): if self.client: msg = self.client.read_queue() if msg: Logger.info('App: msg={}'.format(msg))
def remove_notification(self, **kwargs): if kwargs['activity'] == 'App': self.nbuilder.remove_notification(id=kwargs['id']) else: msg = json.dumps( {'method': 'remove_notification', 'kwargs': kwargs}) self.send_msg(msg)
def load_screen(self, screen, manager=None, store_back=True): '''Load the provided screen: arguments:: `screen`: is the name of the screen to be loaded `manager`: the manager to load this screen, this defaults to the main class. ''' store_back = False if screen == 'StartupScreen' else store_back manager = manager or self.root # load screen modules dynamically # for example load_screen('LoginScreen') # will look for uix/screens/loginscreen # load LoginScreen module_path = screen.lower() if not hasattr(self, module_path): import imp module = imp.load_module(screen, *imp.find_module(module_path)) screen_class = getattr(module, screen) sc = screen_class() sc.from_back = not store_back setattr(self, module_path, sc) manager.add_widget(sc) else: sc = getattr(self, module_path) sc.from_back = not store_back manager.current = screen if store_back: self._navigation_higherarchy.append(sc) return getattr(self, module_path) # Check if app is started as main and only then insitantiate the App class.
def main(): # Start Web Server webThread = threading.Thread( target=startWebServer ) webThread.daemon = True webThread.start() # Start Scheduler reloadSchedule() schedThread = threading.Thread( target=startScheduler ) schedThread.daemon = True schedThread.start() # Start Thermostat UI/App ThermostatApp().run()
def print_something(self, *args): print('App print tick', Clock.get_boottime())
def on_dropfile(self, win, path): '''Appends dropped file to self.dropped_files and schedules _on_dropfile_after() for next frame. App is blocking and nothing else is done before this method is called for all dropped files''' self.dropped_files.append(get_unicode(path)) Clock.unschedule(self._on_dropfile_after) Clock.schedule_once(self._on_dropfile_after, 0)
def mgui_open_settings(self, *args): logs.not_implemented(feature='App settings')
def on_start(self): self.store_name = 'MMplayerApp' self.store_properties = [ ('last_size', [Window.width, Window.height]), ('last_pos', [Window.left, Window.top]) ] self.update_store_properties() self.root.init_widgets() self.last_frame_time = time() - TIME0 Logger.info('App: on_start: %s' % (round(self.last_frame_time, 2))) Clock.schedule_once(lambda dt: self.on_some_frame(1, 7), 0) Clock.schedule_once(self._load_window_pos_size, 0)
def on_some_frame(self, current, fmax): this_time = time() - TIME0 fps = 1 / (this_time - self.last_frame_time) Logger.info('App: on_frame {0: >2}: {1: >5} - {2: >3}'.format( current, round(this_time, 3), str(int(fps)))) current += 1 self.last_frame_time = this_time if current != fmax: Clock.schedule_once( lambda dt: self.on_some_frame(current, fmax), 0)
def main(): app = None try: from Libs.loadplugin import loadplugin # ???????? ???????? from program import Program # ???????? ????? ????????? # ?????? ??????????. app = Program() loadplugin(app) app.run() except Exception as exc: print(traceback.format_exc()) traceback.print_exc(file=open("{}/error.log".format( os.path.split(os.path.abspath(sys.argv[0]))[0]), "w")) if app: # ??????? ????? ?????????? ?? ???? ???????? app.start_screen.clear_widgets() class Error(App): """??????? ????? ? ??????? ??????.""" def callback_report(self, *args): """??????? ???????? ???-???????""" try: txt = six.moves.urllib.parse.quote( self.win_report.txt_traceback.text.encode( "utf-8")) url = "https://github.com/HeaTTheatR/HeaTDV4A/issues/new" \ "?body=" + txt webbrowser.open(url) except Exception: sys.exit(1) def build(self): self.win_report = BugReporter( callback_report=self.callback_report, txt_report=str(exc), icon_background="Data/Images/logo.png") return self.win_report Error().run()
def main(): app = None try: from Libs.loadplugin import load_plugin # ???????? ???????? from program import Program # ???????? ????? ????????? # ?????? ??????????. app = Program() load_plugin(app) app.run() except Exception: text_error = traceback.format_exc() open('{}/error.log'.format(directory), 'w').write(text_error) print(text_error) if app: # ??????? ????? ?????????? ?? ???? ???????? app.start_screen.clear_widgets() class Error(App): '''??????? ????? ? ??????? ??????.''' def callback_report(self, *args): '''??????? ???????? ???-???????''' try: txt = six.moves.urllib.parse.quote( self.win_report.txt_traceback.text.encode('utf-8')) url = 'https://github.com/HeaTTheatR/EasyBuild/issues' \ '/new?body=' + txt webbrowser.open(url) except Exception: sys.exit(1) def build(self): self.win_report = BugReporter( callback_report=self.callback_report, txt_report=text_error, icon_background='Data/Images/logo.png' ) return self.win_report Error().run()
def main(): app = None try: from libs.loadplugin import load_plugin # ???????? ???????? from program import Program # ???????? ????? ????????? # ?????? ??????????. app = Program() load_plugin(app) app.run() except Exception: text_error = traceback.format_exc() open('{}/error.log'.format(directory), 'w').write(text_error) print(text_error) if app: # ??????? ????? ?????????? ?? ???? ???????? try: app.screen.clear_widgets() except AttributeError: pass class Error(App): '''??????? ????? ? ??????? ??????.''' def callback_report(self, *args): '''??????? ???????? ???-???????''' try: txt = six.moves.urllib.parse.quote( self.win_report.txt_traceback.text.encode('utf-8')) url = 'https://github.com/HeaTTheatR/DemoKivyContacts/issues/new?body=' + txt webbrowser.open(url) except Exception: sys.exit(1) def build(self): self.win_report = BugReporter( callback_report=self.callback_report, txt_report=text_error, icon_background='data/images/logo.png' ) return self.win_report Error().run()
def main(): app = None try: from libs.loadplugin import load_plugin # ???????? ???????? from program import Program # ???????? ????? ????????? # ?????? ??????????. app = Program() load_plugin(app) app.run() except Exception: text_error = traceback.format_exc() open('{}/error.log'.format(directory), 'w').write(text_error) print(text_error) if app: # ??????? ????? ?????????? ?? ???? ???????? try: app.screen.clear_widgets() except AttributeError: pass class Error(App): '''??????? ????? ? ??????? ??????.''' def callback_report(self, *args): '''??????? ???????? ???-???????''' try: txt = six.moves.urllib.parse.quote( self.win_report.txt_traceback.text.encode('utf-8')) url = 'https://github.com/HeaTTheatR/Conversations' \ '/issues/new?body=' + txt webbrowser.open(url) except Exception: sys.exit(1) def build(self): self.win_report = BugReporter( callback_report=self.callback_report, txt_report=text_error, icon_background='data/images/logo.png' ) return self.win_report Error().run()
def main(): app = None try: from program import Program # ???????? ????? ????????? # ?????? ??????????. app = Program() app.run() except Exception as exc: print(traceback.format_exc()) traceback.print_exc(file=open("{}/error.log".format( os.path.split(os.path.abspath(sys.argv[0]))[0]), "w")) if app: # ??????? ????? ?????????? ?? ???? ???????? app.start_screen.clear_widgets() class Error(App): """??????? ????? ? ??????? ??????.""" def callback_report(self, *args): """??????? ???????? ???-???????""" try: import webbrowser import six.moves.urllib txt = six.moves.urllib.parse.quote( self.win_report.txt_traceback.text.encode( "utf-8")) url = "https://github.com/HeaTTheatR/KivyCleanMasterDemo" \ "/issues/new?body=" + txt webbrowser.open(url) except Exception: sys.exit(1) def build(self): self.win_report = BugReporter( callback_report=self.callback_report, txt_report=str(exc), icon_background="Data/Images/logo.png") return self.win_report Error().run()