Skip to content

Commit

Permalink
properly define root path and locations of the app data files
Browse files Browse the repository at this point in the history
  • Loading branch information
vesellov committed Jun 26, 2024
1 parent 078bddb commit ef4054d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 52 deletions.
34 changes: 33 additions & 1 deletion src/components/all_components.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

_Debug = True

#------------------------------------------------------------------------------

KV_IMPORT = """
#:import root_path components.all_components.root_path
#:import NoTransition kivy.uix.screenmanager.NoTransition
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
Expand Down Expand Up @@ -52,4 +59,29 @@
'components/file_browser.kv',
]

KV_FILES_BASE = './'

ROOT_APP_PATH = '.'


def root_path(sub_dir=None, filename=None):
global ROOT_APP_PATH
import os
if sub_dir:
if filename:
ret = os.path.join(ROOT_APP_PATH, sub_dir, filename)
if _Debug:
print('all_components.root_path', ret)
return ret
ret = os.path.join(ROOT_APP_PATH, sub_dir)
if _Debug:
print('all_components.root_path', ret)
return ret
if filename:
ret = os.path.join(ROOT_APP_PATH, filename)
if _Debug:
print('all_components.root_path', ret)
return ret
ret = ROOT_APP_PATH
if _Debug:
print('all_components.root_path', ret)
return ret
5 changes: 1 addition & 4 deletions src/components/main_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ def open_screen(self, screen_id, screen_type, **kwargs):
return
screen_class_name, screen_kv_file = self.screens_map[screen_type]
if screen_kv_file:
if system.is_android():
screen_kv_file = os.path.abspath(os.path.join(os.environ['ANDROID_ARGUMENT'], screen_kv_file))
else:
screen_kv_file = all_components.KV_FILES_BASE + '/' + screen_kv_file
screen_kv_file = all_components.root_path(filename=screen_kv_file)
if screen_kv_file in self.screens_loaded:
if _Debug:
print('MainWin.open_screen KV file already loaded: %r' % screen_kv_file)
Expand Down
44 changes: 25 additions & 19 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#------------------------------------------------------------------------------

_Debug = False
_Debug = True
_DebugProfilingEnabled = False
_DebugKivyOutputEnabled = True

Expand Down Expand Up @@ -53,6 +53,19 @@

#------------------------------------------------------------------------------

ROOT_PATH = ''

if system.is_android():
ROOT_PATH = os.path.abspath(os.environ['ANDROID_ARGUMENT'])
elif system.is_osx():
ROOT_PATH = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
elif system.is_ios():
ROOT_PATH = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
else:
ROOT_PATH = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))

#------------------------------------------------------------------------------

if _Debug:
print('BitDustApp __file__', os.path.dirname(os.path.abspath(__file__)))
print('BitDustApp __name__', __name__)
Expand All @@ -62,15 +75,13 @@
print('BitDustApp os.getcwd()', os.path.abspath(os.getcwd()))
print('BitDustApp os.listdir()', os.listdir(os.getcwd()))
print('BitDustApp platform.uname()', platform.uname())
print('BitDustApp ROOT_PATH', ROOT_PATH)

#------------------------------------------------------------------------------

from kivy.config import Config

if system.is_osx():
Config.set('kivy', 'window_icon', './images/bitdust.png')
else:
Config.set('kivy', 'window_icon', 'bitdust.png')
Config.set('kivy', 'window_icon', os.path.join(ROOT_PATH, 'images', 'bitdust.png'))

if 'ANDROID_ARGUMENT' not in os.environ:
Config.set('input', 'mouse', 'mouse,disable_multitouch')
Expand Down Expand Up @@ -130,6 +141,11 @@ class BitDustApp(styles.AppStyle, MDApp):
main_window = None
finishing = threading.Event()

def __init__(self, **kwargs):
global ROOT_PATH
self.ROOT_PATH = ROOT_PATH
super().__init__(**kwargs)

def apply_styles(self):
from kivy.app import App
from kivy.core.text import LabelBase
Expand All @@ -143,13 +159,7 @@ def apply_styles(self):
self.theme_cls.primary_hue = "400"
self.theme_cls.accent_palette = 'Green'

fonts_path = './src/fonts'
if system.is_android():
fonts_path = os.path.join(os.environ['ANDROID_ARGUMENT'], 'fonts')
elif system.is_osx():
fonts_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fonts')
elif system.is_ios():
fonts_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fonts')
fonts_path = os.path.join(self.ROOT_PATH, 'fonts')
# https://materialdesignicons.com
LabelBase.register(name="IconMD", fn_regular=os.path.join(fonts_path, "md.ttf"))
theme_font_styles.append('IconMD')
Expand All @@ -176,10 +186,7 @@ def build(self):
print('BitDustApp.build mActivity=%r' % mActivity)

self.title = 'BitDust p2p-app'
if system.is_osx():
self.icon = './images/bitdust.png'
else:
self.icon = './bitdust.png'
self.icon = os.path.join(self.ROOT_PATH, 'images', 'bitdust.png')
self.granted = False

self.apply_styles()
Expand All @@ -205,11 +212,10 @@ def build(self):

def init_components(self):
from components import all_components
all_components.ROOT_APP_PATH = self.ROOT_PATH
Builder.load_string(all_components.KV_IMPORT)
if system.is_osx():
all_components.KV_FILES_BASE = os.path.join(os.path.dirname(os.path.abspath(__file__)))
for kv_file in all_components.KV_FILES:
Builder.load_file(all_components.KV_FILES_BASE + '/' + kv_file)
Builder.load_file(os.path.join(all_components.ROOT_APP_PATH, kv_file))

@mainthread
def do_start(self, *args, **kwargs):
Expand Down
52 changes: 25 additions & 27 deletions src/screens/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,58 @@
# 5. to open screen use: screen.main_window().select_screen(screen_id='xxx_screen')
#------------------------------------------------------------------------------

KV_FILES_BASE = './'

def all_screens():
return {
'startup_screen': (
f'{KV_FILES_BASE}screens/screen_startup.kv', 'screens.screen_startup', 'StartUpScreen', ),
'screens/screen_startup.kv', 'screens.screen_startup', 'StartUpScreen', ),
'engine_status_screen': (
f'{KV_FILES_BASE}screens/screen_engine_status.kv', 'screens.screen_engine_status', 'EngineStatusScreen', ),
'screens/screen_engine_status.kv', 'screens.screen_engine_status', 'EngineStatusScreen', ),
'connecting_screen': (
f'{KV_FILES_BASE}screens/screen_connecting.kv', 'screens.screen_connecting', 'ConnectingScreen', ),
'screens/screen_connecting.kv', 'screens.screen_connecting', 'ConnectingScreen', ),
'new_identity_screen': (
f'{KV_FILES_BASE}screens/screen_new_identity.kv', 'screens.screen_new_identity', 'NewIdentityScreen', ),
'screens/screen_new_identity.kv', 'screens.screen_new_identity', 'NewIdentityScreen', ),
'recover_identity_screen': (
f'{KV_FILES_BASE}screens/screen_recover_identity.kv', 'screens.screen_recover_identity', 'RecoverIdentityScreen', ),
'screens/screen_recover_identity.kv', 'screens.screen_recover_identity', 'RecoverIdentityScreen', ),
'backup_identity_screen': (
f'{KV_FILES_BASE}screens/screen_backup_identity.kv', 'screens.screen_backup_identity', 'BackupIdentityScreen', ),
'screens/screen_backup_identity.kv', 'screens.screen_backup_identity', 'BackupIdentityScreen', ),
'welcome_screen': (
f'{KV_FILES_BASE}screens/screen_welcome.kv', 'screens.screen_welcome', 'WelcomeScreen', ),
'screens/screen_welcome.kv', 'screens.screen_welcome', 'WelcomeScreen', ),
'settings_screen': (
f'{KV_FILES_BASE}screens/screen_settings.kv', 'screens.screen_settings', 'SettingsScreen', ),
'screens/screen_settings.kv', 'screens.screen_settings', 'SettingsScreen', ),
'my_id_screen': (
f'{KV_FILES_BASE}screens/screen_my_id.kv', 'screens.screen_my_id', 'MyIDScreen', ),
'screens/screen_my_id.kv', 'screens.screen_my_id', 'MyIDScreen', ),
'about_screen': (
f'{KV_FILES_BASE}screens/screen_about.kv', 'screens.screen_about', 'AboutScreen', ),
'screens/screen_about.kv', 'screens.screen_about', 'AboutScreen', ),
'search_people_screen': (
f'{KV_FILES_BASE}screens/screen_search_people.kv', 'screens.screen_search_people', 'SearchPeopleScreen', ),
'screens/screen_search_people.kv', 'screens.screen_search_people', 'SearchPeopleScreen', ),
'friends_screen': (
f'{KV_FILES_BASE}screens/screen_friends.kv', 'screens.screen_friends', 'FriendsScreen', ),
'screens/screen_friends.kv', 'screens.screen_friends', 'FriendsScreen', ),
'select_friend_screen': (
f'{KV_FILES_BASE}screens/screen_select_friend.kv', 'screens.screen_select_friend', 'SelectFriendScreen', ),
'screens/screen_select_friend.kv', 'screens.screen_select_friend', 'SelectFriendScreen', ),
'conversations_screen': (
f'{KV_FILES_BASE}screens/screen_conversations.kv', 'screens.screen_conversations', 'ConversationsScreen', ),
'screens/screen_conversations.kv', 'screens.screen_conversations', 'ConversationsScreen', ),
'create_group_screen': (
f'{KV_FILES_BASE}screens/screen_create_group.kv', 'screens.screen_create_group', 'CreateGroupScreen', ),
'screens/screen_create_group.kv', 'screens.screen_create_group', 'CreateGroupScreen', ),
'private_chat_screen': (
f'{KV_FILES_BASE}screens/screen_private_chat.kv', 'screens.screen_private_chat', 'PrivateChatScreen', ),
'screens/screen_private_chat.kv', 'screens.screen_private_chat', 'PrivateChatScreen', ),
'group_chat_screen': (
f'{KV_FILES_BASE}screens/screen_group_chat.kv', 'screens.screen_group_chat', 'GroupChatScreen', ),
'screens/screen_group_chat.kv', 'screens.screen_group_chat', 'GroupChatScreen', ),
'group_info_screen': (
f'{KV_FILES_BASE}screens/screen_group_info.kv', 'screens.screen_group_info', 'GroupInfoScreen', ),
'screens/screen_group_info.kv', 'screens.screen_group_info', 'GroupInfoScreen', ),
'private_files_screen': (
f'{KV_FILES_BASE}screens/screen_private_files.kv', 'screens.screen_private_files', 'PrivateFilesScreen', ),
'screens/screen_private_files.kv', 'screens.screen_private_files', 'PrivateFilesScreen', ),
'single_private_file_screen': (
f'{KV_FILES_BASE}screens/screen_single_private_file.kv', 'screens.screen_single_private_file', 'SinglePrivateFileScreen', ),
'screens/screen_single_private_file.kv', 'screens.screen_single_private_file', 'SinglePrivateFileScreen', ),
'shares_screen': (
f'{KV_FILES_BASE}screens/screen_shares.kv', 'screens.screen_shares', 'SharesScreen', ),
'screens/screen_shares.kv', 'screens.screen_shares', 'SharesScreen', ),
'create_share_screen': (
f'{KV_FILES_BASE}screens/screen_create_share.kv', 'screens.screen_create_share', 'CreateShareScreen', ),
'screens/screen_create_share.kv', 'screens.screen_create_share', 'CreateShareScreen', ),
'shared_location_screen': (
f'{KV_FILES_BASE}screens/screen_shared_location.kv', 'screens.screen_shared_location', 'SharedLocationScreen', ),
'screens/screen_shared_location.kv', 'screens.screen_shared_location', 'SharedLocationScreen', ),
'shared_location_info_screen': (
f'{KV_FILES_BASE}screens/screen_shared_location_info.kv', 'screens.screen_shared_location_info', 'SharedLocationInfoScreen', ),
'screens/screen_shared_location_info.kv', 'screens.screen_shared_location_info', 'SharedLocationInfoScreen', ),
'single_shared_file_screen': (
f'{KV_FILES_BASE}screens/screen_single_shared_file.kv', 'screens.screen_single_shared_file', 'SingleSharedFileScreen', ),
'screens/screen_single_shared_file.kv', 'screens.screen_single_shared_file', 'SingleSharedFileScreen', ),
}


Expand Down
2 changes: 1 addition & 1 deletion src/screens/screen_about.kv
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
pos_hint: {"left": 1, "top": 1}
allow_stretch: True
keep_ratio: True
source: "./src/images/bitdust_logo.png"
source: root_path("images", "bitdust_logo.png")

MarkupLabel:
id: about_text
Expand Down

0 comments on commit ef4054d

Please sign in to comment.