Python kivy.platform() Examples
The following are 20
code examples of kivy.platform().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
kivy
, or try the search function
.
Example #1
Source File: __init__.py From kivystudio with MIT License | 7 votes |
def get_user_data_dir(name): # Determine and return the user_data_dir. data_dir = "" if platform == 'ios': raise NotImplemented() elif platform == 'android': raise NotImplemented() elif platform == 'win': data_dir = os.path.join(os.environ['APPDATA'], name) elif platform == 'macosx': data_dir = '~/Library/Application Support/{}'.format(name) data_dir = expanduser(data_dir) else: # _platform == 'linux' or anything else...: data_dir = os.environ.get('XDG_CONFIG_HOME', '~/.config') data_dir = expanduser(join(data_dir, name)) if not exists(data_dir): os.mkdir(data_dir) return data_dir
Example #2
Source File: commsfactory.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def comms_factory(device, conn_type): # Connection type can be overridden by user or for testing purposes if conn_type is not None: conn_type = conn_type.lower() if conn_type == 'bluetooth': return android_comm(device) if conn_type == 'wifi': return socket_comm(device) if conn_type == 'serial': return serial_comm(device) else: if platform == 'android': return android_comm(device) elif platform == 'ios': return socket_comm(device) else: return serial_comm(device)
Example #3
Source File: interpreter.py From Pyonic-interpreter with GNU General Public License v3.0 | 6 votes |
def __init__(self, *args, **kwargs): super(InterpreterInput, self).__init__(*args, **kwargs) self.register_event_type('on_request_completions') self.register_event_type('on_clear_completions') self.register_event_type('on_get_completions') if platform != 'android': from pygments.lexers import PythonLexer self.lexer = PythonLexer() App.get_running_app().bind(on_pause=self.on_pause) # self.text = '''for i in range(5): # print(i) # time.sleep(1)'''
Example #4
Source File: main.py From Pyonic-interpreter with GNU General Public License v3.0 | 6 votes |
def on_setting__rotation(self, instance, value): print('new rotation is', value) if platform != 'android': return if value not in ('portrait', 'landscape', 'auto'): print('Orientation error: invalid setting received') from jnius import autoclass ActivityInfo = autoclass('android.content.pm.ActivityInfo') activity = autoclass('org.kivy.android.PythonActivity').mActivity if value == 'portrait': activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT) if value == 'landscape': activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE) if value == 'auto': activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER)
Example #5
Source File: main.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def user_data_dir(self): # this is a workaround for a kivy bug in which /sdcard is the hardcoded path for # the user dir. This fails on Android 7.0 systems. # this function should be removed when the bug is fixed in kivy. if kivy.platform == 'android': from jnius import autoclass env = autoclass('android.os.Environment') data_dir = os.path.join(env.getExternalStorageDirectory().getPath(), self.name) else: data_dir = super(RaceCaptureApp, self).user_data_dir return data_dir
Example #6
Source File: timeutil.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def format_date(dt=datetime.now()): """ format the supplied datetime to the current locale :param the time to format. If not speified, defaults to now :type datetime :return returns the formatted date and time string """ format = '%x' if platform == 'win' else '%Ex' return dt.strftime(format)
Example #7
Source File: timeutil.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def format_time(dt=datetime.now()): """ format the supplied datetime to the current locale :param the time to format. If not speified, defaults to now :type datetime :return returns the formatted date and time string """ format = '%x %X' if platform == 'win' else '%Ex %EX' return dt.strftime(format)
Example #8
Source File: threadutil.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def safe_thread_exit(): if platform == 'android': jnius.detach() # detach the current thread from pyjnius, else hard crash occurs
Example #9
Source File: utils.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def is_windows(): return True if platform == 'win' else False
Example #10
Source File: utils.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def is_android(): return True if platform == 'android' else False
Example #11
Source File: main.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def build(self): self.init_view_builders() Builder.load_file('racecapture.kv') root = self.root status_bar = root.ids.status_bar status_bar.bind(on_main_menu=self.on_main_menu) self.status_bar = status_bar root.ids.main_menu.bind(on_main_menu_item=self.on_main_menu_item) self.mainNav = root.ids.main_nav # reveal_below_anim # reveal_below_simple # slide_above_anim # slide_above_simple # fade_in self.mainNav.anim_type = 'slide_above_anim' rc_api = self._rc_api rc_api.on_progress = lambda value: status_bar.dispatch('on_progress', value) rc_api.on_rx = lambda value: status_bar.dispatch('on_data_rx', value) screenMgr = root.ids.main # NoTransition # SlideTransition # SwapTransition # FadeTransition # WipeTransition # FallOutTransition # RiseInTransition screenMgr.transition = NoTransition() # FallOutTransition() # NoTransition() self.screenMgr = screenMgr self.icon = ('resource/images/app_icon_128x128.ico' if sys.platform == 'win32' else 'resource/images/app_icon_128x128.png') Clock.schedule_once(lambda dt: self.post_launch(), 1.0)
Example #12
Source File: main.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def processArgs(self): parser = argparse.ArgumentParser(description='Autosport Labs Race Capture App') parser.add_argument('-p', '--port', help='Port', required=False) parser.add_argument('--telemetryhost', help='Telemetry host', required=False) parser.add_argument('--conn_type', help='Connection type', required=False, choices=['bt', 'serial', 'wifi']) if sys.platform == 'win32': parser.add_argument('--multiprocessing-fork', required=False, action='store_true') self.app_args = vars(parser.parse_args())
Example #13
Source File: utils.py From Tickeys-linux with MIT License | 5 votes |
def __repr__(self): return 'platform name: \'{platform}\' from: \n{instance}'.format( platform=self._get_platform(), instance=super(Platform, self).__repr__() )
Example #14
Source File: utils.py From Tickeys-linux with MIT License | 5 votes |
def __repr__(self): return 'platform name: \'{platform}\' from: \n{instance}'.format( platform=self._get_platform(), instance=super(Platform, self).__repr__() )
Example #15
Source File: main.py From Pyonic-interpreter with GNU General Public License v3.0 | 5 votes |
def back_button_leave_app(self): if platform != 'android': return from jnius import autoclass activity = autoclass('org.kivy.android.PythonActivity') activity.moveTaskToBack(True)
Example #16
Source File: main.py From Pyonic-interpreter with GNU General Public License v3.0 | 5 votes |
def build(self): self.settings_retrieved = False # used to prevent setting # updates until they have # been fetched from the file Window.clearcolor = (1, 1, 1, 1) Window.softinput_mode = 'pan' self.parse_args() Clock.schedule_once(self.android_setup, 0) Clock.schedule_once(self.retrieve_settings, 0) if platform == 'android': settings_path = '../settings.json' else: settings_path = join(abspath(dirname(__file__)), '..', 'settings.json') self.store = SettingsStore(settings_path) # Retrieve the input throttling argument so that it can be # passed to the service immediately self.setting__throttle_output = self.store.get( 'setting__throttle_output', {'value': self.setting__throttle_output_default})['value'] Window.bind(on_keyboard=self.key_input) for attr in dir(self): if attr.startswith('setting__') and not attr.endswith('_default'): self.bind(**{attr: partial(self.setting_updated, attr)}) self.manager = Manager() return self.manager
Example #17
Source File: filechooser.py From Pyonic-interpreter with GNU General Public License v3.0 | 5 votes |
def go_home(self): self.select(None) if platform == 'android': from jnius import autoclass Environment = autoclass('android.os.Environment') home = Environment.getExternalStorageDirectory().getAbsolutePath() else: home = expanduser('~') self.folder = home
Example #18
Source File: interpreterwrapper.py From Pyonic-interpreter with GNU General Public License v3.0 | 5 votes |
def restart(self): if platform == 'android': from jnius import autoclass service = autoclass('{}.Service{}'.format(package_name, self.service_name)) mActivity = autoclass('org.kivy.android.PythonActivity').mActivity service.stop(mActivity) self.start_interpreter(self.thread_name) else: self.subprocess.kill() self.start_interpreter(self.thread_name) self.lock_input = True self.interpreter_state = 'restarting' Clock.unschedule Clock.schedule_interval(self.ping, 0.3)
Example #19
Source File: interpreterwrapper.py From Pyonic-interpreter with GNU General Public License v3.0 | 5 votes |
def start_interpreter(self, thread_name='default'): # if thread_name == 'interpreter': # return print('trying to start interpreter', self.service_name) interpreter_script_path = join(dirname(realpath(__file__)), 'interpreter_subprocess', 'interpreter.py') # prepare settings to send to interpreter # throttle_output = '1' if App.get_running_app().setting__throttle_output else '0' throttle_output = '1' if self.throttle_output else '0' use_thread = '1' if self.use_thread else '0' argument = ('throttle_output={}:use_thread={}:' 'send_port={}:receive_port={}').format( throttle_output, use_thread, self.receive_port, self.interpreter_port) if platform == 'android': from jnius import autoclass service = autoclass('{}.Service{}'.format(package_name, self.service_name)) mActivity = autoclass('org.kivy.android.PythonActivity').mActivity # service.start(mActivity, argument, thread_name) service.start(mActivity, argument) print('did service start', service, mActivity) else: # This may not actually work everywhere, but let's assume it does print('starting subprocess') python_name = 'python{}'.format(sys.version_info.major) print('python name is', python_name) os.environ['PYTHON_SERVICE_ARGUMENT'] = argument s = subprocess.Popen([python_name, '{}'.format(interpreter_script_path)]) App.get_running_app().subprocesses.append(s) self.subprocess = s pass
Example #20
Source File: main.py From RaceCapture_App with GNU General Public License v3.0 | 4 votes |
def __init__(self, **kwargs): super(RaceCaptureApp, self).__init__(**kwargs) if kivy.platform in ['ios', 'macosx', 'linux']: kivy.resources.resource_add_path(os.path.join(os.path.dirname(os.path.realpath(__file__)), "data")) # We do this because when this app is bundled into a standalone app # by pyinstaller we must reference all files by their absolute paths # sys._MEIPASS is provided by pyinstaller if getattr(sys, 'frozen', False): self.base_dir = sys._MEIPASS else: self.base_dir = os.path.dirname(os.path.abspath(__file__)) self.settings = SystemSettings(self.user_data_dir, base_dir=self.base_dir) self.settings.userPrefs.bind(on_pref_change=self._on_preference_change) self.track_manager = TrackManager(user_dir=self.settings.get_default_data_dir(), base_dir=self.base_dir) self.preset_manager = PresetManager(user_dir=self.settings.get_default_data_dir(), base_dir=self.base_dir) # RaceCapture communications API self._rc_api = RcpApi(on_disconnect=self._on_rcp_disconnect, settings=self.settings) self._databus = DataBusFactory().create_standard_databus(self.settings.systemChannels) self.settings.runtimeChannels.data_bus = self._databus self._datastore = CachingAnalysisDatastore(databus=self._databus) self._session_recorder = SessionRecorder(self._datastore, self._databus, self._rc_api, self.settings, self.track_manager, self._status_pump) self._session_recorder.bind(on_recording=self._on_session_recording) HelpInfo.settings = self.settings # Ensure soft input mode text inputs aren't obstructed Window.softinput_mode = 'below_target' # Capture keyboard events for handling escape / back Window.bind(on_keyboard=self._on_keyboard) self.register_event_type('on_tracks_updated') self.processArgs() self.settings.appConfig.setUserDir(self.user_data_dir) self.setup_telemetry()