Python kivy.utils.platform() Examples
The following are 30
code examples of kivy.utils.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.utils
, or try the search function
.
Example #1
Source File: app.py From kivy-launcher with MIT License | 9 votes |
def build(self): self.log('start of log') if KIVYLAUNCHER_PATHS: self.paths.extend(KIVYLAUNCHER_PATHS.split(",")) else: from jnius import autoclass Environment = autoclass('android.os.Environment') sdcard_path = Environment.getExternalStorageDirectory().getAbsolutePath() self.paths = [ sdcard_path + "/kivy", ] self.root = Builder.load_string(KV) self.refresh_entries() if platform == 'android': from android.permissions import request_permissions, Permission request_permissions([Permission.READ_EXTERNAL_STORAGE])
Example #2
Source File: main.py From Kivy-Tutorials with GNU General Public License v2.0 | 7 votes |
def share(self): if platform() == 'android': #check if the app is on Android # read more here: http://developer.android.com/training/sharing/send.html PythonActivity = autoclass('org.renpy.android.PythonActivity') #request the activity instance Intent = autoclass('android.content.Intent') # get the Android Intend class String = autoclass('java.lang.String') # get the Java object intent = Intent() # create a new Android Intent intent.setAction(Intent.ACTION_SEND) #set the action # to send a message, it need to be a Java char array. So we use the cast to convert and Java String to a Java Char array intent.putExtra(Intent.EXTRA_SUBJECT, cast('java.lang.CharSequence', String('Fast Perception'))) intent.putExtra(Intent.EXTRA_TEXT, cast('java.lang.CharSequence', String('Wow, I just scored %d on Fast Perception. Check this game: https://play.google.com/store/apps/details?id=com.aronbordin.fastperception' % (self.best_score)))) intent.setType('text/plain') #text message currentActivity = cast('android.app.Activity', PythonActivity.mActivity) currentActivity.startActivity(intent) # show the intent in the game activity # will be called when our screen be displayed
Example #3
Source File: ui.py From kivy-2014 with MIT License | 7 votes |
def init_ui(game): view = Widget() _heading(game, view) _notes(game, view) _scales(game, view) _tuning(game, view) view.add_widget(game) if platform in ('android', 'ios'): from kivy.core.window import Window from kivy.uix.scrollview import ScrollView app_view = view app_view.size = (960, 540) app_view.size_hint = (None, None) view = ScrollView(size=Window.size) view.effect_cls = ScrollEffect view.add_widget(app_view) return view
Example #4
Source File: metrics.py From Tickeys-linux with MIT License | 7 votes |
def fontscale(self): '''Return the fontscale user preference. This value is 1 by default but can vary between 0.8 and 1.2. ''' custom_fontscale = environ.get('KIVY_METRICS_FONTSCALE') if custom_fontscale: return float(custom_fontscale) if platform == 'android': from jnius import autoclass PythonActivity = autoclass('org.renpy.android.PythonActivity') config = PythonActivity.mActivity.getResources().getConfiguration() return config.fontScale return 1.0 #: Default instance of :class:`MetricsBase`, used everywhere in the code #: .. versionadded:: 1.7.0
Example #5
Source File: __init__.py From Tickeys-linux with MIT License | 6 votes |
def on_keyboard(self, key, scancode=None, codepoint=None, modifier=None, **kwargs): '''Event called when keyboard is used. .. warning:: Some providers may omit `scancode`, `codepoint` and/or `modifier`! ''' if 'unicode' in kwargs: Logger.warning("The use of the unicode parameter is deprecated, " "and will be removed in future versions. Use " "codepoint instead, which has identical " "semantics.") # Quit if user presses ESC or the typical OSX shortcuts CMD+q or CMD+w # TODO If just CMD+w is pressed, only the window should be closed. is_osx = platform == 'darwin' if WindowBase.on_keyboard.exit_on_escape: if key == 27 or all([is_osx, key in [113, 119], modifier == 1024]): if not self.dispatch('on_request_close', source='keyboard'): stopTouchApp() self.close() return True
Example #6
Source File: __init__.py From Tickeys-linux with MIT License | 6 votes |
def _ensure_clipboard(self): ''' Ensure that the clipboard has been properly initialised. ''' if hasattr(self, '_clip_mime_type'): return if platform == 'win': self._clip_mime_type = 'text/plain;charset=utf-8' # windows clipboard uses a utf-16 little endian encoding self._encoding = 'utf-16-le' elif platform == 'linux': self._clip_mime_type = 'text/plain;charset=utf-8' self._encoding = 'utf-8' else: self._clip_mime_type = 'text/plain' self._encoding = 'utf-8'
Example #7
Source File: window_pygame.py From Tickeys-linux with MIT License | 6 votes |
def set_icon(self, filename): if not exists(filename): return False try: if platform == 'win': try: if self._set_icon_win(filename): return True except: # fallback on standard loading then. pass # for all others platform, or if the ico is not available, use the # default way to set it. self._set_icon_standard(filename) super(WindowPygame, self).set_icon(filename) except: Logger.exception('WinPygame: unable to set icon')
Example #8
Source File: metrics.py From Tickeys-linux with MIT License | 6 votes |
def fontscale(self): '''Return the fontscale user preference. This value is 1 by default but can vary between 0.8 and 1.2. ''' custom_fontscale = environ.get('KIVY_METRICS_FONTSCALE') if custom_fontscale: return float(custom_fontscale) if platform == 'android': from jnius import autoclass PythonActivity = autoclass('org.renpy.android.PythonActivity') config = PythonActivity.mActivity.getResources().getConfiguration() return config.fontScale return 1.0 #: Default instance of :class:`MetricsBase`, used everywhere in the code #: .. versionadded:: 1.7.0
Example #9
Source File: metrics.py From Tickeys-linux with MIT License | 6 votes |
def density(self): '''Return the density of the screen. This value is 1 by default on desktops but varies on android depending on the screen. ''' custom_density = environ.get('KIVY_METRICS_DENSITY') if custom_density: return float(custom_density) if platform == 'android': import jnius Hardware = jnius.autoclass('org.renpy.android.Hardware') return Hardware.metrics.scaledDensity elif platform == 'ios': # 0.75 is for mapping the same density as android tablet import ios return ios.get_scale() * 0.75 elif platform == 'macosx': from kivy.base import EventLoop EventLoop.ensure_window() return EventLoop.window.dpi / 96. return 1.0
Example #10
Source File: metrics.py From Tickeys-linux with MIT License | 6 votes |
def dpi(self): '''Return the DPI of the screen. Depending on the platform, the DPI can be taken from the Window provider (Desktop mainly) or from a platform-specific module (like android/ios). ''' custom_dpi = environ.get('KIVY_DPI') if custom_dpi: return float(custom_dpi) if platform == 'android': import android return android.get_dpi() elif platform == 'ios': import ios return ios.get_dpi() # for all other platforms.. from kivy.base import EventLoop EventLoop.ensure_window() return EventLoop.window.dpi
Example #11
Source File: main.py From nowallet with MIT License | 6 votes |
def open_url(url): if platform == 'android': ''' Open a webpage in the default Android browser. ''' from jnius import autoclass, cast context = autoclass('org.renpy.android.PythonActivity').mActivity Uri = autoclass('android.net.Uri') Intent = autoclass('android.content.Intent') intent = Intent() intent.setAction(Intent.ACTION_VIEW) intent.setData(Uri.parse(url)) currentActivity = cast('android.app.Activity', context) currentActivity.startActivity(intent) else: import webbrowser webbrowser.open(url)
Example #12
Source File: __init__.py From Tickeys-linux with MIT License | 6 votes |
def _ensure_clipboard(self): ''' Ensure that the clipboard has been properly initialised. ''' if hasattr(self, '_clip_mime_type'): return if platform == 'win': self._clip_mime_type = 'text/plain;charset=utf-8' # windows clipboard uses a utf-16 little endian encoding self._encoding = 'utf-16-le' elif platform == 'linux': self._clip_mime_type = 'text/plain;charset=utf-8' self._encoding = 'utf-8' else: self._clip_mime_type = 'text/plain' self._encoding = 'utf-8'
Example #13
Source File: __init__.py From Tickeys-linux with MIT License | 6 votes |
def on_keyboard(self, key, scancode=None, codepoint=None, modifier=None, **kwargs): '''Event called when keyboard is used. .. warning:: Some providers may omit `scancode`, `codepoint` and/or `modifier`! ''' if 'unicode' in kwargs: Logger.warning("The use of the unicode parameter is deprecated, " "and will be removed in future versions. Use " "codepoint instead, which has identical " "semantics.") # Quit if user presses ESC or the typical OSX shortcuts CMD+q or CMD+w # TODO If just CMD+w is pressed, only the window should be closed. is_osx = platform == 'darwin' if WindowBase.on_keyboard.exit_on_escape: if key == 27 or all([is_osx, key in [113, 119], modifier == 1024]): if not self.dispatch('on_request_close', source='keyboard'): stopTouchApp() self.close() return True
Example #14
Source File: __init__.py From Tickeys-linux with MIT License | 6 votes |
def on_motion(self, etype, me): '''Event called when a Motion Event is received. :Parameters: `etype`: str One of 'begin', 'update', 'end' `me`: :class:`~kivy.input.motionevent.MotionEvent` The Motion Event currently dispatched. ''' if me.is_touch: w, h = self.system_size if platform == 'ios': w, h = self.size me.scale_for_screen(w, h, rotation=self._rotation, smode=self.softinput_mode, kheight=self.keyboard_height) if etype == 'begin': self.dispatch('on_touch_down', me) elif etype == 'update': self.dispatch('on_touch_move', me) elif etype == 'end': self.dispatch('on_touch_up', me) FocusBehavior._handle_post_on_touch_up(me)
Example #15
Source File: preferences.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def __init__(self, settings, **kwargs): Builder.load_file(PREFERENCES_KV_FILE) super(PreferencesView, self).__init__(**kwargs) self.settings = settings self.base_dir = kwargs.get('base_dir') self.register_event_type('on_pref_change') self.settings_view = SettingsWithNoMenu() self.settings_view.bind(on_config_change=self._on_preferences_change) # So, Kivy's Settings object doesn't allow you to add multiple json panels at a time, only 1. If you add # multiple, the last one added 'wins'. So what we do is load the settings JSON ourselves and then merge it # with any platform-specific settings (if applicable). It's silly, but works. settings_json = json.loads(open(os.path.join(self.base_dir, 'resource', 'settings', 'settings.json')).read()) if platform == 'android': android_settings_json = json.loads(open(os.path.join(self.base_dir, 'resource', 'settings', 'android_settings.json')).read()) settings_json = settings_json + android_settings_json self.settings_view.add_json_panel('Preferences', self.settings.userPrefs.config, data=json.dumps(settings_json)) self.content = kvFind(self, 'rcid', 'preferences') self.content.add_widget(self.settings_view)
Example #16
Source File: window_pygame.py From Tickeys-linux with MIT License | 6 votes |
def set_icon(self, filename): if not exists(filename): return False try: if platform == 'win': try: if self._set_icon_win(filename): return True except: # fallback on standard loading then. pass # for all others platform, or if the ico is not available, use the # default way to set it. self._set_icon_standard(filename) super(WindowPygame, self).set_icon(filename) except: Logger.exception('WinPygame: unable to set icon')
Example #17
Source File: metrics.py From Tickeys-linux with MIT License | 6 votes |
def density(self): '''Return the density of the screen. This value is 1 by default on desktops but varies on android depending on the screen. ''' custom_density = environ.get('KIVY_METRICS_DENSITY') if custom_density: return float(custom_density) if platform == 'android': import jnius Hardware = jnius.autoclass('org.renpy.android.Hardware') return Hardware.metrics.scaledDensity elif platform == 'ios': # 0.75 is for mapping the same density as android tablet import ios return ios.get_scale() * 0.75 elif platform == 'macosx': from kivy.base import EventLoop EventLoop.ensure_window() return EventLoop.window.dpi / 96. return 1.0
Example #18
Source File: metrics.py From Tickeys-linux with MIT License | 6 votes |
def dpi(self): '''Return the DPI of the screen. Depending on the platform, the DPI can be taken from the Window provider (Desktop mainly) or from a platform-specific module (like android/ios). ''' custom_dpi = environ.get('KIVY_DPI') if custom_dpi: return float(custom_dpi) if platform == 'android': import android return android.get_dpi() elif platform == 'ios': import ios return ios.get_dpi() # for all other platforms.. from kivy.base import EventLoop EventLoop.ensure_window() return EventLoop.window.dpi
Example #19
Source File: fileBrowser.py From GroundControl with GNU General Public License v3.0 | 6 votes |
def reload_drives(self): nodes = [(node, node.text + node.path) for node in\ self._computer_node.nodes if isinstance(node, TreeLabel)] sigs = [s[1] for s in nodes] nodes_new = [] sig_new = [] for path, name in get_drives(): if platform == 'win': text = u'{}({})'.format((name + ' ') if name else '', path) else: text = name nodes_new.append((text, path)) sig_new.append(text + path + sep) for node, sig in nodes: if sig not in sig_new: self.remove_node(node) for text, path in nodes_new: if text + path + sep not in sigs: self.add_node(TreeLabel(text=text, path=path + sep), self._computer_node)
Example #20
Source File: __init__.py From PyCon-Mobile-App with GNU General Public License v3.0 | 6 votes |
def scan_qr(on_complete): if platform != 'android': return from jnius import autoclass from android import activity PythonActivity = autoclass('org.kivy.android.PythonActivity') SimpleScannerActivity = autoclass( "org.pythonindia.qr.SimpleScannerActivity") Intent = autoclass('android.content.Intent') intent = Intent(PythonActivity.mActivity, SimpleScannerActivity) def on_qr_result(requestCode, resultCode, intent): try: if resultCode == -1: # RESULT_OK: # this doesn't work due to some bug in jnius: # contents = intent.getStringExtra("text") String = autoclass("java.lang.String") contents = intent.getStringExtra(String("text")) on_complete(contents) finally: activity.unbind(on_activity_result=on_qr_result) activity.bind(on_activity_result=on_qr_result) PythonActivity.mActivity.startActivityForResult(intent, 0)
Example #21
Source File: main.py From Kivy-Tutorials with GNU General Public License v2.0 | 6 votes |
def share(self): if platform() == 'android': #check if the app is on Android # read more here: http://developer.android.com/training/sharing/send.html PythonActivity = autoclass('org.renpy.android.PythonActivity') #request the Kivy activity instance Intent = autoclass('android.content.Intent') # get the Android Intend class String = autoclass('java.lang.String') # get the Java object intent = Intent() # create a new Android Intent intent.setAction(Intent.ACTION_SEND) #set the action # to send a message, it need to be a Java char array. So we use the cast to convert and Java String to a Java Char array intent.putExtra(Intent.EXTRA_SUBJECT, cast('java.lang.CharSequence', String('Byte::Debugger() Tutorial #7'))) intent.putExtra(Intent.EXTRA_TEXT, cast('java.lang.CharSequence', String("Testing Byte::Debugger() Tutorial #7, with Python for Android"))) intent.setType('text/plain') #text message currentActivity = cast('android.app.Activity', PythonActivity.mActivity) currentActivity.startActivity(intent) # show the intent in the game activity
Example #22
Source File: systemsettings.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def get_default_user_files_dir(self): if platform == 'android': from jnius import autoclass env = autoclass('android.os.Environment') return path.join(env.getExternalStorageDirectory().getPath(), 'racecapture') else: return self.get_default_desktop_config_dir()
Example #23
Source File: systemsettings.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def get_default_data_dir(self): if platform == 'android': from jnius import autoclass PythonActivity = autoclass('org.kivy.android.PythonActivity') activity = PythonActivity.mActivity return activity.getExternalFilesDir(None).getPath() else: return self.data_dir
Example #24
Source File: systemsettings.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def get_default_desktop_config_dir(self): if platform == 'win': return path.join(dirname(expanduser('~')), 'Documents') else: return path.join(expanduser('~'), 'Documents')
Example #25
Source File: main.py From Kivy-Tutorials with GNU General Public License v2.0 | 5 votes |
def run(self): self.best_score = self.app.store.get('score')['best'] # get the best score saved self.ids.label_best.text = 'Best score: ' + str(self.best_score) #show it if platform() == 'android': # if we are using android, we can show an ADs if(random.randint(0, 5) == 1): # get a random and show a ads in the menu revmob.show_popup() #Our game screen, where everything happens :)
Example #26
Source File: main.py From Kivy-Tutorials with GNU General Public License v2.0 | 5 votes |
def build(self): data_dir = getattr(self, 'user_data_dir') #get a writable path to save our score self.store = JsonStore(join(data_dir, 'score.json')) # create a JsonScore file in the available location if(not self.store.exists('score')): # if there is no file, we need to save the best score as 1 self.store.put('score', best=1) if platform() == 'android': # if we are on Android, we can initialize the ADs service revmob.start_session('54c247f420e1fb71091ad44a') self.screens = {} # list of app screens self.screens['menu'] = MenuScreen(self) #self the MainApp instance, so others objects can change the screen self.screens['game'] = GameScreen(self) self.root = FloatLayout() self.open_screen('menu') self.sound = SoundLoader.load('res/background.mp3') # open the background music # kivy support music loop, but it was not working on Android. I coded in a different way to fix it # but if fixed, we can just set the loop to True and call the play(), so it'll auto repeat # self.sound.loop = True It # was not working on android, so I wrote the following code: self.sound.play() # play the sound Clock.schedule_interval(self.check_sound, 1) #every second force the music to be playing return self.root # play the sound
Example #27
Source File: main.py From Kivy-Tutorials with GNU General Public License v2.0 | 5 votes |
def on_pause(self): self.sound.stop() # the stop the sound Clock.unschedule(self.check_sound) if platform() == 'android': #if on android, we load an ADs and show it revmob.show_popup() return True # when the app is resumed
Example #28
Source File: main.py From nowallet with MIT License | 5 votes |
def start_zbar(self): if platform != "android": return self.root.ids.sm.current = "zbar" self.root.ids.detector.start()
Example #29
Source File: __init__.py From pydelhi_mobile with GNU Affero General Public License v3.0 | 5 votes |
def pause_app(): ''' ''' from kivy.utils import platform if platform == 'android': from jnius import cast from jnius import autoclass PythonActivity = autoclass('org.kivy.android.PythonActivity') currentActivity = cast('android.app.Activity', PythonActivity.mActivity) currentActivity.moveTaskToBack(True) else: app = App.get_running_app() app.stop()
Example #30
Source File: __init__.py From Tickeys-linux with MIT License | 5 votes |
def _copy(self, data): # explicitly terminate strings with a null character # so as to avoid putting spurious data after the end. # MS windows issue. self._ensure_clipboard() if not isinstance(data, bytes): data = data.encode(self._encoding) if platform == 'win': data += b'\x00' self.put(data, self._clip_mime_type)