diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index 3932f4cd..761c2ad6 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -1,5 +1,6 @@ -# pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument, unused-import -# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned, unused-variable, too-many-ancestors +# pylint: disable=unused-import, too-many-public-methods, unused-variable, too-many-ancestors +# pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument +# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned """ Bitmessage android(mobile) interface @@ -26,6 +27,7 @@ from kivymd.uix.list import ( ) from kivymd.uix.button import MDRaisedButton from kivymd.uix.bottomsheet import MDCustomBottomSheet +from kivymd.uix.filemanager import MDFileManager from pybitmessage.bitmessagekivy.kivy_state import KivyStateVariables from pybitmessage.bitmessagekivy.base_navigation import ( @@ -34,6 +36,7 @@ from pybitmessage.bitmessagekivy.base_navigation import ( BaseIdentitySpinner ) from pybitmessage.bmconfigparser import config +from pybitmessage.bitmessagekivy import identiconGeneration from pybitmessage.bitmessagekivy.get_platform import platform from pybitmessage.bitmessagekivy.baseclass.common import toast from pybitmessage.bitmessagekivy.baseclass.popup import AddAddressPopup @@ -227,6 +230,94 @@ class NavigateApp(MDApp): except Exception as e: self.root.ids.id_trash.children[0].children[1].active = False + def fileManagerSetting(self): + """This method is for file manager setting""" + if not self.root.ids.content_drawer.ids.file_manager.opacity and \ + self.root.ids.content_drawer.ids.file_manager.disabled: + self.root.ids.content_drawer.ids.file_manager.opacity = 1 + self.root.ids.content_drawer.ids.file_manager.disabled = False + + def set_identicon(self, text): + """Show identicon in address spinner""" + img = identiconGeneration.generate(text) + self.root.ids.content_drawer.ids.top_box.children[0].texture = (img.texture) + + # pylint: disable=import-outside-toplevel + def file_manager_open(self): + """This method open the file manager of local system""" + if not self.kivy_state_obj.file_manager: + self.file_manager = MDFileManager( + exit_manager=self.exit_manager, + select_path=self.select_path, + ext=['.png', '.jpg'] + ) + self.file_manager.previous = False + self.file_manager.current_path = '/' + if platform == 'android': + from android.permissions import request_permissions, Permission, check_permission + if check_permission(Permission.WRITE_EXTERNAL_STORAGE) and \ + check_permission(Permission.READ_EXTERNAL_STORAGE): + self.file_manager.show(os.getenv('EXTERNAL_STORAGE')) + self.manager_open = True + else: + request_permissions([Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE]) + else: + self.file_manager.show(os.environ["HOME"]) + self.manager_open = True + + def select_path(self, path): + """This method is used to set the select image""" + try: + from PIL import Image as PilImage + newImg = PilImage.open(path).resize((300, 300)) + if platform == 'android': + android_path = os.path.join( + os.environ['ANDROID_PRIVATE'] + '/app' + '/images' + '/kivy/') + if not os.path.exists(android_path + '/default_identicon/'): + os.makedirs(android_path + '/default_identicon/') + newImg.save('{1}/default_identicon/{0}.png'.format( + self.kivy_state_obj.association, android_path) + ) + else: + if not os.path.exists(self.kivy_state_obj.image_dir + '/default_identicon/'): + os.makedirs(self.kivy_state_obj.image_dir + '/default_identicon/') + newImg.save(self.kivy_state_obj.image_dir + '/default_identicon/{0}.png'.format( + self.kivy_state_obj.association) + ) + self.load_selected_Image(self.kivy_state_obj.association) + toast('Image changed') + except Exception: + toast('Exit') + self.exit_manager() + + def exit_manager(self, *args): + """Called when the user reaches the root of the directory tree.""" + self.manager_open = False + self.file_manager.close() + + def load_selected_Image(self, curerentAddr): + """This method load the selected image on screen""" + top_box_obj = self.root.ids.content_drawer.ids.top_box.children[0] + top_box_obj.source = self.kivy_state_obj.image_dir + '/default_identicon/{0}.png'.format(curerentAddr) + self.root.ids.content_drawer.ids.reset_image.opacity = 1 + self.root.ids.content_drawer.ids.reset_image.disabled = False + top_box_obj.reload() + + def rest_default_avatar_img(self): + """set default avatar generated image""" + self.set_identicon(self.kivy_state_obj.association) + img_path = self.kivy_state_obj.image_dir + '/default_identicon/{}.png'.format( + self.kivy_state_obj.association + ) + try: + if os.path.exists(img_path): + os.remove(img_path) + self.root.ids.content_drawer.ids.reset_image.opacity = 0 + self.root.ids.content_drawer.ids.reset_image.disabled = True + except Exception as e: + pass + toast('Avatar reset') + def reset_login_screen(self): """This method is used for clearing the widgets of random screen""" if self.root.ids.id_newidentity.ids.add_random_bx.children: