Mercurial > libervia-desktop-kivy
changeset 205:9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 May 2018 12:01:47 +0200 |
parents | 37638765c97b |
children | 890b48e41998 |
files | cagou/plugins/plugin_wid_file_sharing.py |
diffstat | 1 files changed, 13 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_file_sharing.py Fri May 25 11:59:16 2018 +0200 +++ b/cagou/plugins/plugin_wid_file_sharing.py Fri May 25 12:01:47 2018 +0200 @@ -37,6 +37,7 @@ from kivy.garden import modernmenu from kivy.clock import Clock from kivy.metrics import dp +from kivy import utils as kivy_utils from functools import partial import os.path import json @@ -52,8 +53,16 @@ MODE_LOCAL = u"local" SELECT_INSTRUCTIONS = _(u"Please select entities to share with") - -dist = modernmenu.dist +if kivy_utils.platform == "android": + from jnius import autoclass + Environment = autoclass("android.os.Environment") + base_dir = Environment.getExternalStorageDirectory().getAbsolutePath() + def expanduser(path): + if path == u'~' or path.startswith(u'~/'): + return path.replace(u'~', base_dir, 1) + return path +else: + expanduser = os.path.expanduser class ModeBtn(Button): @@ -213,7 +222,7 @@ float_layout = properties.ObjectProperty() layout = properties.ObjectProperty() mode = properties.OptionProperty(MODE_LOCAL, options=[MODE_VIEW, MODE_LOCAL]) - local_dir = properties.StringProperty(os.path.expanduser(u'~')) + local_dir = properties.StringProperty(expanduser(u'~')) remote_dir = properties.StringProperty(u'') remote_entity = properties.StringProperty(u'') shared_paths = properties.ListProperty() @@ -264,12 +273,11 @@ self.mode = opt[new_idx] def on_mode(self, instance, new_mode): - print(instance) self.update_view(None, self.local_dir) def onHeaderInput(self): if u'/' in self.header_input.text or self.header_input.text == u'~': - self.current_dir = os.path.expanduser(self.header_input.text) + self.current_dir = expanduser(self.header_input.text) def onHeaderInputComplete(self, wid, text, **kwargs): """we filter items when text is entered in input box"""