From 09cc100424a9177b3bad1d0a21b07cafb9b94238 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Mon, 12 Sep 2022 15:28:53 +0530 Subject: [PATCH] Update resolution and fix format --- .buildbot/kivy/test.sh | 1 + setup.py | 2 +- src/backend/address_generator.py | 6 +- src/bitmessagekivy/main.kv | 6 -- src/bitmessagekivy/mpybit.py | 69 ++++++++++--------- src/bitmessagekivy/screens_data.json | 19 ----- .../tests/test_load_screen_data_file.py | 5 +- tests-kivy.py | 1 + 8 files changed, 44 insertions(+), 65 deletions(-) diff --git a/.buildbot/kivy/test.sh b/.buildbot/kivy/test.sh index 429db9d0..3231f250 100755 --- a/.buildbot/kivy/test.sh +++ b/.buildbot/kivy/test.sh @@ -1,3 +1,4 @@ #!/bin/bash +export INSTALL_TESTS=True xvfb-run --server-args="-screen 0, 720x1280x24" python3 tests-kivy.py diff --git a/setup.py b/setup.py index 5e0386d8..3bd0d29e 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,7 @@ if __name__ == "__main__": ) if os.environ.get('INSTALL_TESTS', False): - packages.extend(['pybitmessage.mock', 'pybitmessage.backend']) + packages.extend(['pybitmessage.mock', 'pybitmessage.backend', 'pybitmessage.bitmessagekivy.tests']) # this will silently accept alternative providers of msgpack # if they are already installed diff --git a/src/backend/address_generator.py b/src/backend/address_generator.py index 39220e01..312c313b 100644 --- a/src/backend/address_generator.py +++ b/src/backend/address_generator.py @@ -2,9 +2,9 @@ Common methods and functions for kivy and qt. """ -import queues -from bmconfigparser import config -from defaults import ( +from pybitmessage import queues +from pybitmessage.bmconfigparser import config +from pybitmessage.defaults import ( networkDefaultProofOfWorkNonceTrialsPerByte, networkDefaultPayloadLengthExtraBytes ) diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 99aacdd0..e92a2b23 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -212,12 +212,6 @@ MDNavigationLayout: id:sc6 Random: id:id_newidentity - Payment: - id:id_payment - MailDetail: - id:sc14 - ShowQRCode: - id:id_showqrcode MDNavigationDrawer: id: nav_drawer diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index d9a4665e..1cff0b2e 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -1,6 +1,6 @@ -# 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, too-many-instance-attributes +# pylint: disable=too-many-public-methods, unused-variable, too-many-ancestors +# pylint: disable=no-name-in-module, too-few-public-methods, unused-argument +# pylint: disable=attribute-defined-outside-init, too-many-instance-attributes """ Bitmessage android(mobile) interface @@ -10,6 +10,7 @@ import os import logging import sys from functools import partial +from PIL import Image as PilImage from kivy.clock import Clock from kivy.lang import Builder @@ -39,6 +40,7 @@ from pybitmessage.bitmessagekivy.baseclass.common import toast, load_image_path, from pybitmessage.bitmessagekivy.load_kivy_screens_data import load_screen_json from pybitmessage.bitmessagekivy.baseclass.popup import AddAddressPopup +from pybitmessage.bitmessagekivy.baseclass.login import * # noqa: F401, F403 logger = logging.getLogger('default') @@ -90,8 +92,13 @@ class NavigateApp(MDApp): window_size = kivy_state.screen_density tr = Lang("en") # for changing in franch replace en with fr + if os.environ.get('INSTALL_TESTS', False): + # Set kivy app resolution while running kivy tests + window_size = (720, 1280) + def __init__(self): super(NavigateApp, self).__init__() + # workaround for relative imports sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) self.data_screens, self.all_data, self.data_screen_dict, response = load_screen_json() self.kivy_state_obj = KivyStateVariables() @@ -164,18 +171,12 @@ class NavigateApp(MDApp): def savecontact(self, instance): """Method is used for saving contacts""" - pupup_obj = self.add_popup.content_cls - label = pupup_obj.ids.label.text.strip() - address = pupup_obj.ids.address.text.strip() - if label == '' and address == '': - pupup_obj.ids.label.focus = True - pupup_obj.ids.address.focus = True - elif address == '': - pupup_obj.ids.address.focus = True - elif label == '': - pupup_obj.ids.label.focus = True - else: - pupup_obj.ids.address.focus = True + popup_obj = self.add_popup.content_cls + label = popup_obj.ids.label.text.strip() + address = popup_obj.ids.address.text.strip() + popup_obj.ids.label.focus = not label + # default focus on address field + popup_obj.ids.address.focus = label or not address def close_pop(self, instance): """Close the popup""" @@ -233,6 +234,7 @@ class NavigateApp(MDApp): self.file_manager.previous = False self.file_manager.current_path = '/' if platform == 'android': + # pylint: disable=import-error from android.permissions import request_permissions, Permission, check_permission if check_permission(Permission.WRITE_EXTERNAL_STORAGE) and \ check_permission(Permission.READ_EXTERNAL_STORAGE): @@ -247,21 +249,21 @@ class NavigateApp(MDApp): 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) + os.path.join(os.environ['ANDROID_PRIVATE'], 'app', 'images', 'kivy') + ) + if not os.path.exists(os.path.join(android_path, 'default_identicon')): + os.makedirs(os.path.join(android_path, 'default_identicon')) + newImg.save(os.path.join(android_path, 'default_identicon', '{}.png'.format( + self.kivy_state_obj.association)) ) else: - if not os.path.exists(self.image_dir + '/default_identicon/'): - os.makedirs(self.image_dir + '/default_identicon/') - newImg.save(self.image_dir + '/default_identicon/{0}.png'.format( - self.kivy_state_obj.association) + if not os.path.exists(os.path.join(self.image_dir, 'default_identicon')): + os.makedirs(os.path.join(self.image_dir, 'default_identicon')) + newImg.save(os.path.join(self.image_dir, 'default_identicon', '{0}.png'.format( + self.kivy_state_obj.association)) ) self.load_selected_Image(self.kivy_state_obj.association) toast('Image changed') @@ -277,7 +279,7 @@ class NavigateApp(MDApp): 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.image_dir + '/default_identicon/{0}.png'.format(curerentAddr) + top_box_obj.source = os.path.join(self.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() @@ -285,8 +287,8 @@ class NavigateApp(MDApp): def rest_default_avatar_img(self): """set default avatar generated image""" self.set_identicon(self.kivy_state_obj.association) - img_path = self.image_dir + '/default_identicon/{}.png'.format( - self.kivy_state_obj.association + img_path = os.path.join( + self.image_dir, 'default_identicon', '{}.png'.format(self.kivy_state_obj.association) ) try: if os.path.exists(img_path): @@ -303,14 +305,18 @@ class NavigateApp(MDApp): first_addr = self.identity_list[0] if config.getboolean(str(first_addr), 'enabled'): if os.path.exists( - self.image_dir + '/default_identicon/{}.png'.format(first_addr) + os.path.join( + self.image_dir, 'default_identicon', '{}.png'.format(first_addr) + ) ): - return self.image_dir + '/default_identicon/{}.png'.format(first_addr) + return os.path.join( + self.image_dir, 'default_identicon', '{}.png'.format(first_addr) + ) else: img = identiconGeneration.generate(first_addr) instance.texture = img.texture return - return self.image_dir + '/drawer_logo1.png' + return os.path.join(self.image_dir, 'drawer_logo1.png') def reset_login_screen(self): """This method is used for clearing the widgets of random screen""" @@ -334,5 +340,4 @@ class PaymentMethodLayout(BoxLayout): if __name__ == '__main__': - # workaround for relative imports NavigateApp().run() diff --git a/src/bitmessagekivy/screens_data.json b/src/bitmessagekivy/screens_data.json index 06398463..4628ef8e 100644 --- a/src/bitmessagekivy/screens_data.json +++ b/src/bitmessagekivy/screens_data.json @@ -1,25 +1,6 @@ { - "Address Book": { - "kv_string": "addressbook", - "name_screen": "addressbook", - "Import": "from pybitmessage.bitmessagekivy.baseclass.addressbook import AddressBook" - }, - "Payment": { - "kv_string": "payment", - "name_screen": "payment", - "Import": "from pybitmessage.bitmessagekivy.baseclass.payment import Payment" - }, - "MailDetail": { - "kv_string": "maildetail", - "name_screen": "mailDetail", - "Import": "from pybitmessage.bitmessagekivy.baseclass.maildetail import MailDetail" - }, "Login": { "kv_string": "login", "Import": "from pybitmessage.bitmessagekivy.baseclass.login import *" - }, - "Qrcode": { - "kv_string": "qrcode", - "Import": "from pybitmessage.bitmessagekivy.baseclass.qrcode import ShowQRCode" } } diff --git a/src/bitmessagekivy/tests/test_load_screen_data_file.py b/src/bitmessagekivy/tests/test_load_screen_data_file.py index 0a7556d0..619daf25 100644 --- a/src/bitmessagekivy/tests/test_load_screen_data_file.py +++ b/src/bitmessagekivy/tests/test_load_screen_data_file.py @@ -1,21 +1,18 @@ import unittest from pybitmessage.bitmessagekivy.load_kivy_screens_data import load_screen_json -from .common import skip_screen_checks from .common import ordered class TestLoadScreenData(unittest.TestCase): """Screen Data Json test""" - @skip_screen_checks @ordered def test_load_json(self): """Test to load a valid json""" loaded_screen_names = load_screen_json() - self.assertEqual(loaded_screen_names[2], 'success') + self.assertEqual(loaded_screen_names[3], 'success') - @skip_screen_checks @ordered def test_load_invalid_file(self): """Test to load an invalid json""" diff --git a/tests-kivy.py b/tests-kivy.py index 43132652..c5e3dcd0 100644 --- a/tests-kivy.py +++ b/tests-kivy.py @@ -35,6 +35,7 @@ if __name__ == "__main__": ]) sleep(2) # let ffmpeg start result = unittest.TextTestRunner(verbosity=2).run(unittest_discover()) + sleep(1) if in_docker: ffmpeg.terminate() try: