Update popup names, ids name main.kv, base_navigation.py
This commit is contained in:
parent
cf4161eab3
commit
85670f3ad6
136
src/bitmessagekivy/base_navigation.py
Normal file
136
src/bitmessagekivy/base_navigation.py
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
from kivy.lang import Observable
|
||||||
|
from kivymd.uix.list import (
|
||||||
|
IRightBodyTouch,
|
||||||
|
OneLineAvatarIconListItem,
|
||||||
|
OneLineListItem
|
||||||
|
)
|
||||||
|
from kivy.properties import (
|
||||||
|
BooleanProperty,
|
||||||
|
ListProperty,
|
||||||
|
NumericProperty,
|
||||||
|
ObjectProperty,
|
||||||
|
StringProperty
|
||||||
|
)
|
||||||
|
from kivy.metrics import dp
|
||||||
|
from kivy.uix.boxlayout import BoxLayout
|
||||||
|
from kivy.uix.spinner import Spinner
|
||||||
|
from kivymd.uix.dialog import MDDialog
|
||||||
|
from kivymd.uix.label import MDLabel
|
||||||
|
from kivymd.uix.button import MDRaisedButton
|
||||||
|
|
||||||
|
from kivy.clock import Clock
|
||||||
|
from kivy.core.clipboard import Clipboard
|
||||||
|
from kivy.core.window import Window
|
||||||
|
from kivy.lang import Builder
|
||||||
|
# from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
|
from bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BaseLanguage(Observable):
|
||||||
|
"""UI Language"""
|
||||||
|
observers = []
|
||||||
|
lang = None
|
||||||
|
|
||||||
|
def __init__(self, defaultlang):
|
||||||
|
super(BaseLanguage, self).__init__()
|
||||||
|
self.ugettext = None
|
||||||
|
self.lang = defaultlang
|
||||||
|
# self.switch_lang(self.lang)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _(text):
|
||||||
|
return text
|
||||||
|
|
||||||
|
def _(self, text):
|
||||||
|
# return self.ugettext(text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
def fbind(self, name, func, args, **kwargs):
|
||||||
|
if name == "_":
|
||||||
|
self.observers.append((func, args, kwargs))
|
||||||
|
else:
|
||||||
|
return super(Lang, self).fbind(name, func, *args, **kwargs)
|
||||||
|
|
||||||
|
def funbind(self, name, func, args, **kwargs):
|
||||||
|
if name == "_":
|
||||||
|
key = (func, args, kwargs)
|
||||||
|
if key in self.observers:
|
||||||
|
self.observers.remove(key)
|
||||||
|
else:
|
||||||
|
return super(Lang, self).funbind(name, func, *args, **kwargs)
|
||||||
|
|
||||||
|
def switch_lang(self, lang):
|
||||||
|
for func, args, kwargs in self.observers:
|
||||||
|
func(args, None, None)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseNavigationItem(OneLineAvatarIconListItem):
|
||||||
|
"""NavigationItem class for kivy Ui"""
|
||||||
|
badge_text = StringProperty()
|
||||||
|
icon = StringProperty()
|
||||||
|
active = BooleanProperty(False)
|
||||||
|
|
||||||
|
def currentlyActive(self):
|
||||||
|
"""Currenly active"""
|
||||||
|
for nav_obj in self.parent.children:
|
||||||
|
nav_obj.active = False
|
||||||
|
self.active = True
|
||||||
|
|
||||||
|
|
||||||
|
class BaseNavigationDrawerDivider(OneLineListItem):
|
||||||
|
"""
|
||||||
|
A small full-width divider that can be placed
|
||||||
|
in the :class:`MDNavigationDrawer`
|
||||||
|
"""
|
||||||
|
|
||||||
|
disabled = True
|
||||||
|
divider = None
|
||||||
|
_txt_top_pad = NumericProperty(dp(8))
|
||||||
|
_txt_bot_pad = NumericProperty(dp(8))
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
# pylint: disable=bad-super-call
|
||||||
|
super(BaseNavigationDrawerDivider, self).__init__(**kwargs)
|
||||||
|
self.height = dp(16)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseNavigationDrawerSubheader(OneLineListItem):
|
||||||
|
"""
|
||||||
|
A subheader for separating content in :class:`MDNavigationDrawer`
|
||||||
|
|
||||||
|
Works well alongside :class:`NavigationDrawerDivider`
|
||||||
|
"""
|
||||||
|
|
||||||
|
disabled = True
|
||||||
|
divider = None
|
||||||
|
theme_text_color = 'Secondary'
|
||||||
|
|
||||||
|
|
||||||
|
class BaseContentNavigationDrawer(BoxLayout):
|
||||||
|
"""ContentNavigationDrawer class for kivy Uir"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
"""Method used for contentNavigationDrawer"""
|
||||||
|
super(BaseContentNavigationDrawer, self).__init__(*args, **kwargs)
|
||||||
|
Clock.schedule_once(self.init_ui, 0)
|
||||||
|
|
||||||
|
def init_ui(self, dt=0):
|
||||||
|
"""Clock Schdule for class contentNavigationDrawer"""
|
||||||
|
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
||||||
|
|
||||||
|
def check_scroll_y(self, instance, somethingelse):
|
||||||
|
"""show data on scroll down"""
|
||||||
|
# if self.ids.identity_dropdown.is_open:
|
||||||
|
# self.ids.identity_dropdown.is_open = False
|
||||||
|
|
||||||
|
|
||||||
|
class BaseCustomSpinner(Spinner):
|
||||||
|
"""BaseCustomSpinner class for kivy Ui"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
"""Method used for setting size of spinner"""
|
||||||
|
super(BaseCustomSpinner, self).__init__(*args, **kwargs)
|
||||||
|
self.dropdown_cls.max_height = Window.size[1] / 3
|
||||||
|
self.values = list(addr for addr in BMConfigParser().addresses()
|
||||||
|
if BMConfigParser().getboolean(str(addr), 'enabled'))
|
|
@ -28,19 +28,19 @@ class LoadingPopup(Popup):
|
||||||
self.dismiss()
|
self.dismiss()
|
||||||
|
|
||||||
|
|
||||||
class GrashofPopup(BoxLayout):
|
class AddAddressPopup(BoxLayout):
|
||||||
"""GrashofPopup class for kivy Ui"""
|
"""AddAddressPopup class for kivy Ui"""
|
||||||
|
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
"""Grash of pop screen settings"""
|
"""Grash of pop screen settings"""
|
||||||
super(GrashofPopup, self).__init__(**kwargs)
|
super(AddAddressPopup, self).__init__(**kwargs)
|
||||||
|
|
||||||
def checkAddress_valid(self, instance):
|
def checkAddress_valid(self, instance):
|
||||||
"""Checking address is valid or not"""
|
"""Checking address is valid or not"""
|
||||||
my_addresses = (
|
my_addresses = (
|
||||||
state.kivyapp.root.ids.content_drawer.ids.btn.values)
|
state.kivyapp.root.ids.content_drawer.ids.identity_dropdown.values)
|
||||||
add_book = [addr[1] for addr in kivy_helper_search.search_sql(
|
add_book = [addr[1] for addr in kivy_helper_search.search_sql(
|
||||||
folder="addressbook")]
|
folder="addressbook")]
|
||||||
entered_text = str(instance.text).strip()
|
entered_text = str(instance.text).strip()
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
size_hint_y: None
|
size_hint_y: None
|
||||||
height: dp(40)
|
height: dp(40)
|
||||||
CustomSpinner:
|
IdentitySpinner:
|
||||||
id: btn
|
id: btn
|
||||||
background_color: app.theme_cls.primary_dark
|
background_color: app.theme_cls.primary_dark
|
||||||
# values: app.identity_list
|
# values: app.identity_list
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
size: root.size
|
size: root.size
|
||||||
|
|
||||||
|
|
||||||
<GrashofPopup>:
|
<AddAddressPopup>:
|
||||||
id: popup_box
|
id: popup_box
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
# spacing:dp(20)
|
# spacing:dp(20)
|
||||||
|
|
|
@ -120,8 +120,8 @@
|
||||||
NavigationItem:
|
NavigationItem:
|
||||||
# size: 50,50
|
# size: 50,50
|
||||||
height: dp(48)
|
height: dp(48)
|
||||||
CustomSpinner:
|
IdentitySpinner:
|
||||||
id: btn
|
id: identity_dropdown
|
||||||
pos_hint:{"x":0,"y":0}
|
pos_hint:{"x":0,"y":0}
|
||||||
option_cls: Factory.get("MySpinnerOption")
|
option_cls: Factory.get("MySpinnerOption")
|
||||||
font_size: '12.5sp'
|
font_size: '12.5sp'
|
||||||
|
|
|
@ -64,9 +64,15 @@ from bitmessagekivy.baseclass.popup import *
|
||||||
from qr_scanner.zbarcam import ZBarCam
|
from qr_scanner.zbarcam import ZBarCam
|
||||||
from pyzbar.pyzbar import ZBarSymbol
|
from pyzbar.pyzbar import ZBarSymbol
|
||||||
|
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
from bitmessagekivy.kivy_state import KivyStateVariables
|
from bitmessagekivy.kivy_state import KivyStateVariables
|
||||||
|
|
||||||
|
from bitmessagekivy.base_navigation import (
|
||||||
|
BaseLanguage, BaseNavigationItem, BaseNavigationDrawerDivider,
|
||||||
|
BaseNavigationDrawerSubheader, BaseContentNavigationDrawer,
|
||||||
|
BaseCustomSpinner
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if platform != "android":
|
if platform != "android":
|
||||||
from kivy.config import Config
|
from kivy.config import Config
|
||||||
Config.set("input", "mouse", "mouse, multitouch_on_demand")
|
Config.set("input", "mouse", "mouse, multitouch_on_demand")
|
||||||
|
@ -119,129 +125,137 @@ def load_screen_json(data_file="screens_data.json"):
|
||||||
# import_from = import_data.split("import")[0].split('from')[1].strip()
|
# import_from = import_data.split("import")[0].split('from')[1].strip()
|
||||||
# exec_import = importlib.import_module(import_from, import_to)
|
# exec_import = importlib.import_module(import_from, import_to)
|
||||||
# exec_import
|
# exec_import
|
||||||
# import pdb; pdb.set_trace()
|
#
|
||||||
|
|
||||||
# importlib.import_module("pybitmessage.bitmessagekivy.baseclass.trash", "Trash")
|
# importlib.import_module("pybitmessage.bitmessagekivy.baseclass.trash", "Trash")
|
||||||
|
|
||||||
# for modules in data_screens:
|
# for modules in data_screens:
|
||||||
# exec(all_data[modules]['Import'])
|
# exec(all_data[modules]['Import'])
|
||||||
# import pdb; pdb.set_trace()
|
#
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods,too-many-arguments,attribute-defined-outside-init
|
# pylint: disable=too-few-public-methods,too-many-arguments,attribute-defined-outside-init
|
||||||
|
|
||||||
|
|
||||||
class Lang(Observable):
|
class Lang(BaseLanguage):
|
||||||
observers = []
|
"""UI Language"""
|
||||||
lang = None
|
# observers = []
|
||||||
|
# lang = None
|
||||||
|
|
||||||
def __init__(self, defaultlang):
|
# def __init__(self, defaultlang):
|
||||||
super(Lang, self).__init__()
|
# super(Lang, self).__init__()
|
||||||
self.ugettext = None
|
# self.ugettext = None
|
||||||
self.lang = defaultlang
|
# self.lang = defaultlang
|
||||||
self.switch_lang(self.lang)
|
# # self.switch_lang(self.lang)
|
||||||
|
|
||||||
def _(self, text):
|
# @staticmethod
|
||||||
# return self.ugettext(text)
|
# def _(text):
|
||||||
return text
|
# return text
|
||||||
|
|
||||||
def fbind(self, name, func, args, **kwargs):
|
# # def _(self, text):
|
||||||
if name == "_":
|
# # # return self.ugettext(text)
|
||||||
self.observers.append((func, args, kwargs))
|
# # return text
|
||||||
else:
|
|
||||||
return super(Lang, self).fbind(name, func, *largs, **kwargs)
|
|
||||||
|
|
||||||
def funbind(self, name, func, args, **kwargs):
|
# # def fbind(self, name, func, args, **kwargs):
|
||||||
if name == "_":
|
# # if name == "_":
|
||||||
key = (func, args, kwargs)
|
# # self.observers.append((func, args, kwargs))
|
||||||
if key in self.observers:
|
# # else:
|
||||||
self.observers.remove(key)
|
# # return super(Lang, self).fbind(name, func, *args, **kwargs)
|
||||||
else:
|
|
||||||
return super(Lang, self).funbind(name, func, *args, **kwargs)
|
|
||||||
|
|
||||||
def switch_lang(self, lang):
|
# # def funbind(self, name, func, args, **kwargs):
|
||||||
# get the right locales directory, and instanciate a gettext
|
# # if name == "_":
|
||||||
# locale_dir = os.path.join(os.path.dirname(__file__), 'translations', 'mo', 'locales')
|
# # key = (func, args, kwargs)
|
||||||
# locales = gettext.translation('langapp', locale_dir, languages=[lang])
|
# # if key in self.observers:
|
||||||
# self.ugettext = locales.gettext
|
# # self.observers.remove(key)
|
||||||
|
# # else:
|
||||||
|
# # return super(Lang, self).funbind(name, func, *args, **kwargs)
|
||||||
|
|
||||||
# update all the kv rules attached to this text
|
# # def switch_lang(self, lang):
|
||||||
for func, largs, kwargs in self.observers:
|
# # for func, args, kwargs in self.observers:
|
||||||
func(largs, None, None)
|
# # func(args, None, None)
|
||||||
|
|
||||||
|
|
||||||
class NavigationItem(OneLineAvatarIconListItem):
|
class NavigationItem(BaseNavigationItem):
|
||||||
"""NavigationItem class for kivy Ui"""
|
"""NavigationItem class for kivy Ui"""
|
||||||
badge_text = StringProperty()
|
# badge_text = StringProperty()
|
||||||
icon = StringProperty()
|
# icon = StringProperty()
|
||||||
active = BooleanProperty(False)
|
# active = BooleanProperty(False)
|
||||||
|
|
||||||
def currentlyActive(self):
|
# def currentlyActive(self):
|
||||||
"""Currenly active"""
|
# """Currenly active"""
|
||||||
for nav_obj in self.parent.children:
|
# for nav_obj in self.parent.children:
|
||||||
nav_obj.active = False
|
# nav_obj.active = False
|
||||||
self.active = True
|
# self.active = True
|
||||||
|
|
||||||
|
|
||||||
class NavigationDrawerDivider(OneLineListItem):
|
class NavigationDrawerDivider(BaseNavigationDrawerDivider):
|
||||||
"""
|
"""
|
||||||
A small full-width divider that can be placed
|
A small full-width divider that can be placed
|
||||||
in the :class:`MDNavigationDrawer`
|
in the :class:`MDNavigationDrawer`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
disabled = True
|
# disabled = True
|
||||||
divider = None
|
# divider = None
|
||||||
_txt_top_pad = NumericProperty(dp(8))
|
# _txt_top_pad = NumericProperty(dp(8))
|
||||||
_txt_bot_pad = NumericProperty(dp(8))
|
# _txt_bot_pad = NumericProperty(dp(8))
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
# def __init__(self, **kwargs):
|
||||||
# pylint: disable=bad-super-call
|
# # pylint: disable=bad-super-call
|
||||||
super(OneLineListItem, self).__init__(**kwargs)
|
# super(OneLineListItem, self).__init__(**kwargs)
|
||||||
self.height = dp(16)
|
# self.height = dp(16)
|
||||||
|
|
||||||
|
|
||||||
class NavigationDrawerSubheader(OneLineListItem):
|
class NavigationDrawerSubheader(BaseNavigationDrawerSubheader):
|
||||||
"""
|
"""
|
||||||
A subheader for separating content in :class:`MDNavigationDrawer`
|
A subheader for separating content in :class:`MDNavigationDrawer`
|
||||||
|
|
||||||
Works well alongside :class:`NavigationDrawerDivider`
|
Works well alongside :class:`NavigationDrawerDivider`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
disabled = True
|
# disabled = True
|
||||||
divider = None
|
# divider = None
|
||||||
theme_text_color = 'Secondary'
|
# theme_text_color = 'Secondary'
|
||||||
|
|
||||||
|
|
||||||
class ContentNavigationDrawer(BoxLayout):
|
class ContentNavigationDrawer(BaseContentNavigationDrawer):
|
||||||
"""ContentNavigationDrawer class for kivy Uir"""
|
"""ContentNavigationDrawer class for kivy Uir"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
# def __init__(self, *args, **kwargs):
|
||||||
"""Method used for contentNavigationDrawer"""
|
# """Method used for contentNavigationDrawer"""
|
||||||
super(ContentNavigationDrawer, self).__init__(*args, **kwargs)
|
# super(ContentNavigationDrawer, self).__init__(*args, **kwargs)
|
||||||
Clock.schedule_once(self.init_ui, 0)
|
# Clock.schedule_once(self.init_ui, 0)
|
||||||
|
|
||||||
def init_ui(self, dt=0):
|
# def init_ui(self, dt=0):
|
||||||
"""Clock Schdule for class contentNavigationDrawer"""
|
# """Clock Schdule for class contentNavigationDrawer"""
|
||||||
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
# self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
||||||
|
|
||||||
def check_scroll_y(self, instance, somethingelse):
|
# def check_scroll_y(self, instance, somethingelse):
|
||||||
"""show data on scroll down"""
|
# """show data on scroll down"""
|
||||||
if self.ids.btn.is_open:
|
# if self.ids.identity_dropdown.is_open:
|
||||||
self.ids.btn.is_open = False
|
# self.ids.identity_dropdown.is_open = False
|
||||||
|
|
||||||
|
|
||||||
class BadgeText(IRightBodyTouch, MDLabel):
|
class BadgeText(IRightBodyTouch, MDLabel):
|
||||||
"""BadgeText class for kivy Ui"""
|
"""BadgeText class for kivy Ui"""
|
||||||
|
|
||||||
|
|
||||||
class CustomSpinner(Spinner):
|
class IdentitySpinner(BaseCustomSpinner):
|
||||||
"""CustomSpinner class for kivy Ui"""
|
"""IdentitySpinner class for kivy Ui"""
|
||||||
|
|
||||||
|
# def __init__(self, *args, **kwargs):
|
||||||
|
# """Method used for setting size of spinner"""
|
||||||
|
# super(IdentitySpinner, self).__init__(*args, **kwargs)
|
||||||
|
# self.dropdown_cls.max_height = Window.size[1] / 3
|
||||||
|
# self.values = list(addr for addr in config.addresses()
|
||||||
|
# if config.getboolean(str(addr), 'enabled'))
|
||||||
|
|
||||||
|
# """IdentitySpinner class for kivy Ui"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Method used for setting size of spinner"""
|
"""Method used for setting size of spinner"""
|
||||||
super(CustomSpinner, self).__init__(*args, **kwargs)
|
super(IdentitySpinner, self).__init__(*args, **kwargs)
|
||||||
self.dropdown_cls.max_height = Window.size[1] / 3
|
self.dropdown_cls.max_height = Window.size[1] / 3
|
||||||
self.values = list(addr for addr in BMConfigParser().addresses()
|
# self.values = list(addr for addr in BMConfigParser().addresses()
|
||||||
if BMConfigParser().get(str(addr), 'enabled') == 'true')
|
# if BMConfigParser().get(str(addr), 'enabled') == 'true')
|
||||||
|
|
||||||
|
|
||||||
def get_identity_list():
|
def get_identity_list():
|
||||||
|
@ -361,7 +375,7 @@ class NavigateApp(MDApp):
|
||||||
self.root.ids.sc16.add_widget(data_screen_dict['Draft'].Draft())
|
self.root.ids.sc16.add_widget(data_screen_dict['Draft'].Draft())
|
||||||
|
|
||||||
self.root.ids.sc5.clear_widgets()
|
self.root.ids.sc5.clear_widgets()
|
||||||
# import pdb; pdb.set_trace()
|
#
|
||||||
self.root.ids.sc5.add_widget(data_screen_dict['Trash'].Trash())
|
self.root.ids.sc5.add_widget(data_screen_dict['Trash'].Trash())
|
||||||
|
|
||||||
self.root.ids.sc17.clear_widgets()
|
self.root.ids.sc17.clear_widgets()
|
||||||
|
@ -387,7 +401,7 @@ class NavigateApp(MDApp):
|
||||||
title='Add contact\'s',
|
title='Add contact\'s',
|
||||||
type="custom",
|
type="custom",
|
||||||
size_hint=(width, .23),
|
size_hint=(width, .23),
|
||||||
content_cls=GrashofPopup(),
|
content_cls=AddAddressPopup(),
|
||||||
buttons=[
|
buttons=[
|
||||||
MDRaisedButton(
|
MDRaisedButton(
|
||||||
text="Save",
|
text="Save",
|
||||||
|
@ -405,8 +419,9 @@ class NavigateApp(MDApp):
|
||||||
)
|
)
|
||||||
# self.add_popup.set_normal_height()
|
# self.add_popup.set_normal_height()
|
||||||
self.add_popup.auto_dismiss = False
|
self.add_popup.auto_dismiss = False
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
self.add_popup.open()
|
self.add_popup.open()
|
||||||
# p = GrashofPopup()
|
# p = AddAddressPopup()
|
||||||
# p.open()
|
# p.open()
|
||||||
|
|
||||||
def scan_qr_code(self, instance):
|
def scan_qr_code(self, instance):
|
||||||
|
|
Reference in New Issue
Block a user