Merge branch 'app-gui'
commit
8b0347eece
@ -0,0 +1,26 @@
|
||||
|
||||
export KOMRADE_SHOW_LOG=0
|
||||
|
||||
echo "`which python`"
|
||||
|
||||
|
||||
|
||||
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
pathvenv=`realpath "$SCRIPTPATH/../venv"`
|
||||
pathconda=`realpath "$SCRIPTPATH/../../lib/miniconda3"`
|
||||
|
||||
echo $SCRIPTPATH
|
||||
echo $pathvenv
|
||||
echo $pathconda
|
||||
|
||||
source $pathconda/etc/profile.d/conda.sh
|
||||
|
||||
export PATH="$pathconda/bin:$PATH"
|
||||
#echo $PATH
|
||||
|
||||
echo "`which conda`"
|
||||
conda activate
|
||||
conda activate "$pathvenv"
|
||||
|
||||
|
||||
#echo "`which python`"
|
@ -1 +1 @@
|
||||
gAN9cQAoWAgAAABPcGVyYXRvcnEBfXECWAYAAABwdWJrZXlxA0MtVUVDMgAAAC1hgN9lAxyIsxYZOs5gwowpdARUV1USe4lzL4CPljTKdAesbmxUcQRzWAkAAABUZWxlcGhvbmVxBX1xBihoA0MtVUVDMgAAAC0P2f2HAoNhL9nipoQ/H+gKWULQQHLqszP/5Afq3THpyDNtqppJcQdYBwAAAHByaXZrZXlxCEMtUkVDMgAAAC3k7DbkAD3PjjYZ65798z6aljzN06lvRY3G1wkOUi6KjjEKDil1cQl1WAgAAABrb21yYWRlc3EKfXELaANDLVVFQzIAAAAtfeN2+gPzW/S3F9stS20ic6W5q1ockOAE6LglnVP8Y0r+iU+StnEMc3Uu
|
||||
gAN9cQAoWAgAAABPcGVyYXRvcnEBfXECWAYAAABwdWJrZXlxA0MtVUVDMgAAAC0bxo2LAoEjBd2zolM21IdPVglscIHT7Zej01DESrM7a7xsqA4ScQRzWAkAAABUZWxlcGhvbmVxBX1xBihoA0MtVUVDMgAAAC3HJMkiA8dBmuaFcjSspwDzMuzsFQ2XqeUOUUWLM+bP6dBoEYfZcQdYBwAAAHByaXZrZXlxCEMtUkVDMgAAAC1HY+cbAMyEsX5ev9h2K3frWRrP2zISYVpH2jBE+Er7LNHwR96UcQl1WAgAAABrb21yYWRlc3EKfXELaANDLVVFQzIAAAAtqvUigQNGhPzEhUr1azXSzfbfeEmeyfWfK7nE9mSVZzCvqiweiXEMc3Uu
|
Binary file not shown.
After Width: | Height: | Size: 286 KiB |
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
@ -0,0 +1,598 @@
|
||||
"""
|
||||
Components/Dialog
|
||||
=================
|
||||
|
||||
.. seealso::
|
||||
|
||||
`Material Design spec, Dialogs <https://material.io/components/dialogs>`_
|
||||
|
||||
|
||||
.. rubric:: Dialogs inform users about a task and can contain critical
|
||||
information, require decisions, or involve multiple tasks.
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialogs.png
|
||||
:align: center
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from kivy.lang import Builder
|
||||
|
||||
from kivymd.app import MDApp
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.dialog import MDDialog2
|
||||
|
||||
KV = '''
|
||||
FloatLayout:
|
||||
|
||||
MDFlatButton:
|
||||
text: "ALERT DIALOG"
|
||||
pos_hint: {'center_x': .5, 'center_y': .5}
|
||||
on_release: app.show_alert_dialog()
|
||||
'''
|
||||
|
||||
|
||||
class Example(MDApp):
|
||||
dialog = None
|
||||
|
||||
def build(self):
|
||||
return Builder.load_string(KV)
|
||||
|
||||
def show_alert_dialog(self):
|
||||
if not self.dialog:
|
||||
self.dialog = MDDialog2(
|
||||
text="Discard draft?",
|
||||
buttons=[
|
||||
MDFlatButton(
|
||||
text="CANCEL", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
MDFlatButton(
|
||||
text="DISCARD", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
],
|
||||
)
|
||||
self.dialog.open()
|
||||
|
||||
|
||||
Example().run()
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/alert-dialog.png
|
||||
:align: center
|
||||
"""
|
||||
|
||||
__all__ = ("MDDialog2",)
|
||||
|
||||
from kivy.clock import Clock
|
||||
from kivy.core.window import Window
|
||||
from kivy.lang import Builder
|
||||
from kivy.metrics import dp
|
||||
from kivy.properties import (
|
||||
ListProperty,
|
||||
NumericProperty,
|
||||
ObjectProperty,
|
||||
OptionProperty,
|
||||
StringProperty,
|
||||
)
|
||||
from kivy.uix.modalview import ModalView
|
||||
|
||||
from kivymd.material_resources import DEVICE_TYPE
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivymd.uix.button import BaseButton
|
||||
from kivymd.uix.card import MDSeparator
|
||||
from kivymd.uix.list import BaseListItem
|
||||
|
||||
Builder.load_string(
|
||||
"""
|
||||
#:import images_path kivymd.images_path
|
||||
|
||||
|
||||
<BaseDialog>
|
||||
background: '{}/transparent.png'.format(images_path)
|
||||
canvas.before:
|
||||
PushMatrix
|
||||
RoundedRectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
radius: [5]
|
||||
Scale:
|
||||
origin: self.center
|
||||
x: root._scale_x
|
||||
y: root._scale_y
|
||||
canvas.after:
|
||||
PopMatrix
|
||||
|
||||
<MDDialog2>
|
||||
|
||||
MDCard:
|
||||
id: container
|
||||
orientation: "vertical"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
elevation: 4
|
||||
md_bg_color: 0, 0, 0, 0
|
||||
padding: "24dp", "24dp", "8dp", "8dp"
|
||||
|
||||
canvas:
|
||||
Color:
|
||||
rgba: root.color_bg #root.theme_cls.bg_dark
|
||||
RoundedRectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
radius: root.radius
|
||||
|
||||
MDLabel:
|
||||
id: title
|
||||
text: root.title
|
||||
font_style: "H6"
|
||||
bold: True
|
||||
markup: True
|
||||
size_hint_y: None
|
||||
height: self.texture_size[1]
|
||||
valign: "top"
|
||||
|
||||
BoxLayout:
|
||||
id: spacer_top_box
|
||||
size_hint_y: None
|
||||
height: root._spacer_top
|
||||
|
||||
MDLabel:
|
||||
id: text
|
||||
text: root.text
|
||||
font_style: "Body1"
|
||||
theme_text_color: "Custom"
|
||||
text_color: root.theme_cls.disabled_hint_text_color
|
||||
size_hint_y: None
|
||||
height: self.texture_size[1]
|
||||
markup: True
|
||||
|
||||
ScrollView:
|
||||
id: scroll
|
||||
size_hint_y: None
|
||||
height: root._scroll_height
|
||||
|
||||
MDGridLayout:
|
||||
id: box_items
|
||||
adaptive_height: True
|
||||
cols: 1
|
||||
|
||||
BoxLayout:
|
||||
id: spacer_bottom_box
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
|
||||
AnchorLayout:
|
||||
id: root_button_box
|
||||
size_hint_y: None
|
||||
height: "52dp"
|
||||
anchor_x: "right"
|
||||
|
||||
MDBoxLayout:
|
||||
id: button_box
|
||||
adaptive_size: True
|
||||
spacing: "8dp"
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
class BaseDialog(ThemableBehavior, ModalView):
|
||||
_scale_x = NumericProperty(1)
|
||||
_scale_y = NumericProperty(1)
|
||||
|
||||
|
||||
class MDDialog2(BaseDialog):
|
||||
title = StringProperty()
|
||||
"""
|
||||
Title dialog.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
self.dialog = MDDialog2(
|
||||
title="Reset settings?",
|
||||
buttons=[
|
||||
MDFlatButton(
|
||||
text="CANCEL", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
MDFlatButton(
|
||||
text="ACCEPT", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-title.png
|
||||
:align: center
|
||||
|
||||
:attr:`title` is an :class:`~kivy.properties.StringProperty`
|
||||
and defaults to `''`.
|
||||
"""
|
||||
|
||||
text = StringProperty()
|
||||
"""
|
||||
Text dialog.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
self.dialog = MDDialog2(
|
||||
title="Reset settings?",
|
||||
text="This will reset your device to its default factory settings.",
|
||||
buttons=[
|
||||
MDFlatButton(
|
||||
text="CANCEL", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
MDFlatButton(
|
||||
text="ACCEPT", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-text.png
|
||||
:align: center
|
||||
|
||||
:attr:`text` is an :class:`~kivy.properties.StringProperty`
|
||||
and defaults to `''`.
|
||||
"""
|
||||
|
||||
radius = ListProperty([7, 7, 7, 7])
|
||||
|
||||
color_bg=ListProperty([0,0,0,1])
|
||||
|
||||
"""
|
||||
Dialog corners rounding value.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
self.dialog = MDDialog2(
|
||||
text="Oops! Something seems to have gone wrong!",
|
||||
radius=[20, 7, 20, 7],
|
||||
)
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-radius.png
|
||||
:align: center
|
||||
|
||||
:attr:`radius` is an :class:`~kivy.properties.ListProperty`
|
||||
and defaults to `[7, 7, 7, 7]`.
|
||||
"""
|
||||
|
||||
buttons = ListProperty()
|
||||
"""
|
||||
List of button objects for dialog.
|
||||
Objects must be inherited from :class:`~kivymd.uix.button.BaseButton` class.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
self.dialog = MDDialog2(
|
||||
text="Discard draft?",
|
||||
buttons=[
|
||||
MDFlatButton(text="CANCEL"), MDRaisedButton(text="DISCARD"),
|
||||
],
|
||||
)
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-buttons.png
|
||||
:align: center
|
||||
|
||||
:attr:`buttons` is an :class:`~kivy.properties.ListProperty`
|
||||
and defaults to `[]`.
|
||||
"""
|
||||
|
||||
items = ListProperty()
|
||||
"""
|
||||
List of items objects for dialog.
|
||||
Objects must be inherited from :class:`~kivymd.uix.list.BaseListItem` class.
|
||||
|
||||
With type 'simple'
|
||||
-----------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import StringProperty
|
||||
|
||||
from kivymd.app import MDApp
|
||||
from kivymd.uix.dialog import MDDialog2
|
||||
from kivymd.uix.list import OneLineAvatarListItem
|
||||
|
||||
KV = '''
|
||||
<Item>
|
||||
|
||||
ImageLeftWidget:
|
||||
source: root.source
|
||||
|
||||
|
||||
FloatLayout:
|
||||
|
||||
MDFlatButton:
|
||||
text: "ALERT DIALOG"
|
||||
pos_hint: {'center_x': .5, 'center_y': .5}
|
||||
on_release: app.show_simple_dialog()
|
||||
'''
|
||||
|
||||
|
||||
class Item(OneLineAvatarListItem):
|
||||
divider = None
|
||||
source = StringProperty()
|
||||
|
||||
|
||||
class Example(MDApp):
|
||||
dialog = None
|
||||
|
||||
def build(self):
|
||||
return Builder.load_string(KV)
|
||||
|
||||
def show_simple_dialog(self):
|
||||
if not self.dialog:
|
||||
self.dialog = MDDialog2(
|
||||
title="Set backup account",
|
||||
type="simple",
|
||||
items=[
|
||||
Item(text="user01@gmail.com", source="user-1.png"),
|
||||
Item(text="user02@gmail.com", source="user-2.png"),
|
||||
Item(text="Add account", source="add-icon.png"),
|
||||
],
|
||||
)
|
||||
self.dialog.open()
|
||||
|
||||
|
||||
Example().run()
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-items.png
|
||||
:align: center
|
||||
|
||||
With type 'confirmation'
|
||||
-----------------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from kivy.lang import Builder
|
||||
|
||||
from kivymd.app import MDApp
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.dialog import MDDialog2
|
||||
from kivymd.uix.list import OneLineAvatarIconListItem
|
||||
|
||||
KV = '''
|
||||
<ItemConfirm>
|
||||
on_release: root.set_icon(check)
|
||||
|
||||
CheckboxLeftWidget:
|
||||
id: check
|
||||
group: "check"
|
||||
|
||||
|
||||
FloatLayout:
|
||||
|
||||
MDFlatButton:
|
||||
text: "ALERT DIALOG"
|
||||
pos_hint: {'center_x': .5, 'center_y': .5}
|
||||
on_release: app.show_confirmation_dialog()
|
||||
'''
|
||||
|
||||
|
||||
class ItemConfirm(OneLineAvatarIconListItem):
|
||||
divider = None
|
||||
|
||||
def set_icon(self, instance_check):
|
||||
instance_check.active = True
|
||||
check_list = instance_check.get_widgets(instance_check.group)
|
||||
for check in check_list:
|
||||
if check != instance_check:
|
||||
check.active = False
|
||||
|
||||
|
||||
class Example(MDApp):
|
||||
dialog = None
|
||||
|
||||
def build(self):
|
||||
return Builder.load_string(KV)
|
||||
|
||||
def show_confirmation_dialog(self):
|
||||
if not self.dialog:
|
||||
self.dialog = MDDialog2(
|
||||
title="Phone ringtone",
|
||||
type="confirmation",
|
||||
items=[
|
||||
ItemConfirm(text="Callisto"),
|
||||
ItemConfirm(text="Luna"),
|
||||
ItemConfirm(text="Night"),
|
||||
ItemConfirm(text="Solo"),
|
||||
ItemConfirm(text="Phobos"),
|
||||
ItemConfirm(text="Diamond"),
|
||||
ItemConfirm(text="Sirena"),
|
||||
ItemConfirm(text="Red music"),
|
||||
ItemConfirm(text="Allergio"),
|
||||
ItemConfirm(text="Magic"),
|
||||
ItemConfirm(text="Tic-tac"),
|
||||
],
|
||||
buttons=[
|
||||
MDFlatButton(
|
||||
text="CANCEL", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
MDFlatButton(
|
||||
text="OK", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
],
|
||||
)
|
||||
self.dialog.open()
|
||||
|
||||
|
||||
Example().run()
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-confirmation.png
|
||||
:align: center
|
||||
|
||||
:attr:`items` is an :class:`~kivy.properties.ListProperty`
|
||||
and defaults to `[]`.
|
||||
"""
|
||||
|
||||
type = OptionProperty(
|
||||
"alert", options=["alert", "simple", "confirmation", "custom"]
|
||||
)
|
||||
"""
|
||||
Dialog type.
|
||||
Available option are `'alert'`, `'simple'`, `'confirmation'`, `'custom'`.
|
||||
|
||||
:attr:`type` is an :class:`~kivy.properties.OptionProperty`
|
||||
and defaults to `'alert'`.
|
||||
"""
|
||||
|
||||
content_cls = ObjectProperty()
|
||||
"""
|
||||
Custom content class.
|
||||
|
||||
.. code-block::
|
||||
|
||||
from kivy.lang import Builder
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
|
||||
from kivymd.app import MDApp
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.dialog import MDDialog2
|
||||
|
||||
KV = '''
|
||||
<Content>
|
||||
orientation: "vertical"
|
||||
spacing: "12dp"
|
||||
size_hint_y: None
|
||||
height: "120dp"
|
||||
|
||||
MDTextField:
|
||||
hint_text: "City"
|
||||
|
||||
MDTextField:
|
||||
hint_text: "Street"
|
||||
|
||||
|
||||
FloatLayout:
|
||||
|
||||
MDFlatButton:
|
||||
text: "ALERT DIALOG"
|
||||
pos_hint: {'center_x': .5, 'center_y': .5}
|
||||
on_release: app.show_confirmation_dialog()
|
||||
'''
|
||||
|
||||
|
||||
class Content(BoxLayout):
|
||||
pass
|
||||
|
||||
|
||||
class Example(MDApp):
|
||||
dialog = None
|
||||
|
||||
def build(self):
|
||||
return Builder.load_string(KV)
|
||||
|
||||
def show_confirmation_dialog(self):
|
||||
if not self.dialog:
|
||||
self.dialog = MDDialog2(
|
||||
title="Address:",
|
||||
type="custom",
|
||||
content_cls=Content(),
|
||||
buttons=[
|
||||
MDFlatButton(
|
||||
text="CANCEL", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
MDFlatButton(
|
||||
text="OK", text_color=self.theme_cls.primary_color
|
||||
),
|
||||
],
|
||||
)
|
||||
self.dialog.open()
|
||||
|
||||
|
||||
Example().run()
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/dialog-custom.png
|
||||
:align: center
|
||||
|
||||
:attr:`content_cls` is an :class:`~kivy.properties.ObjectProperty`
|
||||
and defaults to `'None'`.
|
||||
"""
|
||||
|
||||
_scroll_height = NumericProperty("28dp")
|
||||
_spacer_top = NumericProperty("24dp")
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.color_bg = kwargs.get('color_bg',self.theme_cls.bg_dark)
|
||||
if 'color_bg' in kwargs:
|
||||
del kwargs['color_bg']
|
||||
|
||||
if self.size_hint == [1, 1] and DEVICE_TYPE == "mobile":
|
||||
self.size_hint = (None, None)
|
||||
self.width = dp(280)
|
||||
elif self.size_hint == [1, 1] and DEVICE_TYPE == "desktop":
|
||||
self.size_hint = (None, None)
|
||||
self.width = dp(560)
|
||||
|
||||
if not self.title:
|
||||
self._spacer_top = 0
|
||||
|
||||
if not self.buttons:
|
||||
self.ids.root_button_box.height = 0
|
||||
else:
|
||||
self.create_buttons()
|
||||
|
||||
update_height = False
|
||||
if self.type in ("simple", "confirmation"):
|
||||
if self.type == "confirmation":
|
||||
self.ids.spacer_top_box.add_widget(MDSeparator())
|
||||
self.ids.spacer_bottom_box.add_widget(MDSeparator())
|
||||
self.create_items()
|
||||
if self.type == "custom":
|
||||
if self.content_cls:
|
||||
self.ids.container.remove_widget(self.ids.scroll)
|
||||
self.ids.container.remove_widget(self.ids.text)
|
||||
self.ids.spacer_top_box.add_widget(self.content_cls)
|
||||
self.ids.spacer_top_box.padding = (0, "24dp", "16dp", 0)
|
||||
update_height = True
|
||||
if self.type == "alert":
|
||||
self.ids.scroll.bar_width = 0
|
||||
|
||||
if update_height:
|
||||
Clock.schedule_once(self.update_height)
|
||||
|
||||
def update_height(self, *_):
|
||||
self._spacer_top = self.content_cls.height + dp(24)
|
||||
|
||||
def on_open(self):
|
||||
# TODO: Add scrolling text.
|
||||
self.height = self.ids.container.height
|
||||
|
||||
def set_normal_height(self):
|
||||
self.size_hint_y = 0.8
|
||||
|
||||
def get_normal_height(self):
|
||||
return (
|
||||
(Window.height * 80 / 100)
|
||||
- self._spacer_top
|
||||
- dp(52)
|
||||
- self.ids.container.padding[1]
|
||||
- self.ids.container.padding[-1]
|
||||
- 100
|
||||
)
|
||||
|
||||
def edit_padding_for_item(self, instance_item):
|
||||
instance_item.ids._left_container.x = 0
|
||||
instance_item._txt_left_pad = "56dp"
|
||||
|
||||
def create_items(self):
|
||||
self.ids.container.remove_widget(self.ids.text)
|
||||
height = 0
|
||||
|
||||
for item in self.items:
|
||||
if issubclass(item.__class__, BaseListItem):
|
||||
height += item.height # calculate height contents
|
||||
self.edit_padding_for_item(item)
|
||||
self.ids.box_items.add_widget(item)
|
||||
|
||||
if height > Window.height:
|
||||
self.set_normal_height()
|
||||
self.ids.scroll.height = self.get_normal_height()
|
||||
else:
|
||||
self.ids.scroll.height = height
|
||||
|
||||
def create_buttons(self):
|
||||
for button in self.buttons:
|
||||
if issubclass(button.__class__, BaseButton):
|
||||
self.ids.button_box.add_widget(button)
|
@ -0,0 +1,282 @@
|
||||
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..','..')))
|
||||
from komrade.app.screens.dialog import MDDialog2
|
||||
import cartopy
|
||||
import cartopy.crs as ccrs
|
||||
import matplotlib.pyplot as plt
|
||||
from kivymd.uix.boxlayout import MDBoxLayout
|
||||
from kivymd.uix.gridlayout import MDGridLayout
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.label import MDLabel
|
||||
print('\n'.join(sys.path))
|
||||
from komrade.constants import *
|
||||
# from komrade.app.main import rgb
|
||||
import io
|
||||
from kivy.core.image import Image as CoreImage
|
||||
from kivy.uix.image import Image,AsyncImage
|
||||
from kivy.core.window import Window
|
||||
from kivy.app import App
|
||||
import logging
|
||||
logger=logging.getLogger(__name__)
|
||||
|
||||
def rgb(r,g,b,a=1):
|
||||
return (r/255,g/255,b/255,a)
|
||||
|
||||
class MapImage(AsyncImage):
|
||||
pass
|
||||
|
||||
|
||||
class MapWidget(MDDialog2):
|
||||
@property
|
||||
def projection(self):
|
||||
# return ccrs.PlateCarree()
|
||||
return ccrs.EckertI()
|
||||
|
||||
@property
|
||||
def figsize(self):
|
||||
# fig = plt.figure()
|
||||
# dpi=fig.dpi // 2
|
||||
dpi=40
|
||||
width,height=Window.size
|
||||
return (width//dpi, height//dpi)
|
||||
# bbox = fig.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
|
||||
# width, height = bbox.width*fig.dpi, bbox.height*fig.dpi
|
||||
# return (width,height)
|
||||
|
||||
@property
|
||||
def color_land(self): return rgb(*darksienna3,a=0) #darksienna3)
|
||||
@property
|
||||
def color_water(self): return rgb(*russiangreen)
|
||||
@property
|
||||
def color_label(self): return rgb(*COLOR_ICON)
|
||||
@property
|
||||
def color_marker(self): return rgb(*COLOR_ICON)
|
||||
@property
|
||||
def color_line(self): return rgb(*COLOR_ICON)
|
||||
|
||||
def __init__(self):
|
||||
self.last_lat = None
|
||||
self.last_long = None
|
||||
self.points = []
|
||||
self.opened=False
|
||||
self.label=None
|
||||
|
||||
# self.fig = fig = plt.figure(figsize=(20,10))
|
||||
plt.rcParams["figure.figsize"] = self.figsize
|
||||
self.ax = ax = plt.axes(
|
||||
projection=self.projection,
|
||||
)
|
||||
# ax.set_extent([-170, 165, -55, 75])
|
||||
|
||||
# ax.background_patch.set_facecolor(rgb(*COLOR_CARD)[:3])
|
||||
# ax.outline_patch.set_facecolor(rgb(*COLOR_CARD)[:3])
|
||||
# self.ax.stock_img()
|
||||
# self.ax.coastlines(color=rgb(*COLOR_CARD))
|
||||
ax.add_feature(cartopy.feature.OCEAN, zorder=0, color=self.color_water,edgecolor=self.color_water)
|
||||
ax.add_feature(cartopy.feature.LAND, zorder=0, color=self.color_land, edgecolor=self.color_land)
|
||||
ax.outline_patch.set_visible(False)
|
||||
ax.background_patch.set_visible(False)
|
||||
# ax.set_global()
|
||||
# ax.gridlines()
|
||||
|
||||
|
||||
self.layout=MDBoxLayout()
|
||||
self.layout.orientation='vertical'
|
||||
self.layout.cols=1
|
||||
self.layout.size_hint=(None,None)
|
||||
self.layout.size=(Window.size[0],Window.size[1]) # ('666sp','666sp')
|
||||
self.layout.md_bg_color=rgb(*eerieblack) #rgb(*COLOR_BG,a=1)
|
||||
# self.layout.adaptive_height=True
|
||||
# self.layout.height=self.layout.minimum_height
|
||||
self.layout.spacing='0sp'
|
||||
self.layout.padding='0sp'
|
||||
self.img=None
|
||||
self.label_layout=MDGridLayout()
|
||||
self.label_layout.orientation='vertical'
|
||||
self.label_layout.cols=1
|
||||
self.label_layout.row_default_height='25sp'
|
||||
self.label_layout.row_force_default='25sp'
|
||||
self.label_layout.rows=10
|
||||
self.label_layout.pos_hint={'y':0}
|
||||
self.label_layout.size_hint=(None,None)
|
||||
self.label_layout.width=Window.size[0]
|
||||
self.label_layout.height='300sp'
|
||||
# self.label_layout.size=(Window.size[0],'400sp')
|
||||
# self.label_layout.size=Window.size # ('666sp','666sp')
|
||||
# self.layout.add_widget(self.label_layout)
|
||||
|
||||
# do dialog's intro
|
||||
super().__init__(
|
||||
type='custom',
|
||||
text='',
|
||||
content_cls=self.layout,
|
||||
buttons=[
|
||||
MDFlatButton(
|
||||
text="disconnect",
|
||||
text_color=rgb(*COLOR_TEXT),
|
||||
md_bg_color = rgb(*eerieblack), #(0,0,0,1),
|
||||
theme_text_color='Custom',
|
||||
on_release=self.dismiss,
|
||||
font_name=FONT_PATH
|
||||
)
|
||||
],
|
||||
color_bg = rgb(*eerieblack), #(0,0,0,1),
|
||||
overlay_color=(0,0,0,0),
|
||||
background_color=(0,0,0,0)
|
||||
)
|
||||
self.ids.text.text_color=rgb(*COLOR_TEXT)
|
||||
self.ids.text.font_name=FONT_PATH
|
||||
self.size=Window.size #('666sp','666sp')
|
||||
# self.
|
||||
# self.adaptive_height=True
|
||||
|
||||
def draw(self):
|
||||
from matplotlib import transforms
|
||||
from PIL import Image as pImage
|
||||
from PIL import ImageOps
|
||||
tr = transforms.Affine2D().rotate_deg(90)
|
||||
|
||||
|
||||
# buf = io.BytesIO()
|
||||
# plt.ion()
|
||||
odir=f'/home/ryan/komrade/data/maps/'
|
||||
if not os.path.exists(odir): os.makedirs(odir)
|
||||
ofn=os.path.join(odir,f't_{len(self.points)}.png')
|
||||
# plt.gca().invert_yaxis()
|
||||
plt.savefig(ofn, format='png',transparent=True,pad_inches=0.1,bbox_inches = 'tight')
|
||||
|
||||
# flip?
|
||||
# im = pImage.open(ofn)
|
||||
# im = im.rotate(90)
|
||||
# im.save(ofn)
|
||||
|
||||
if not self.img:
|
||||
self.img= AsyncImage(source=ofn)
|
||||
self.img.background_color=(0,0,0,0)
|
||||
self.img.overlay_color=(0,0,0,0)
|
||||
# self.img.texture.flip_horizontal()
|
||||
self.img.pos_hint={'center_x':0.48,'center_y':0.5}
|
||||
# self.img.size=Window.size
|
||||
# self.img.texture = img
|
||||
self.img.add_widget(self.label_layout,1)
|
||||
self.layout.add_widget(self.img,1)
|
||||
|
||||
else:
|
||||
self.img.source=ofn
|
||||
# self.img.size_hint=(1,1)
|
||||
# self.img.width=Window.size[0]
|
||||
# self.img.allow_stretch=True
|
||||
|
||||
def add_point(self,lat,long,desc):
|
||||
logger.info(f'adding point? {desc} {lat}, {long}')
|
||||
# plt.text(
|
||||
# long+3,
|
||||
# lat-12,
|
||||
# desc,
|
||||
# horizontalalignment='left',
|
||||
# transform=self.projection
|
||||
# )
|
||||
import random
|
||||
from komrade.constants import ALL_COLORS
|
||||
color = random.choice(ALL_COLORS)
|
||||
self.points+=[(lat,long,desc)]
|
||||
|
||||
# point
|
||||
plt.plot(
|
||||
long,
|
||||
lat,
|
||||
'+',
|
||||
markersize=25,
|
||||
linewidth=10,
|
||||
color=self.color_marker,#rgb(*color),
|
||||
transform=ccrs.Geodetic(),
|
||||
)
|
||||
|
||||
# line
|
||||
if self.last_lat and self.last_long:
|
||||
plt.plot(
|
||||
[self.last_long, long],
|
||||
[self.last_lat, lat],
|
||||
color=self.color_line,#rgb(*color), #self.color_line,
|
||||
linewidth=4, marker='',
|
||||
transform=ccrs.Geodetic(),
|
||||
)
|
||||
|
||||
|
||||
desc = '\n'.join('--> '+desc for lat,long,desc in self.points[-1:])
|
||||
#if self.label:
|
||||
# self.img.remove_widget(self.label)
|
||||
|
||||
def makelabel(txt):
|
||||
label=MDLabel(text=txt)
|
||||
label.color=self.color_label #rgb(*color) #self.color_label
|
||||
label.font_name=FONT_PATH
|
||||
label.font_size='20sp'
|
||||
# label.size_hint=(1,1)
|
||||
label.width=Window.size[0]
|
||||
label.height='25sp'
|
||||
label.valign='top'
|
||||
return label
|
||||
|
||||
|
||||
if len(self.points)==1:
|
||||
intro_label = makelabel(
|
||||
'Routing you through the global maze of Tor ...'
|
||||
)
|
||||
self.label_layout.add_widget(intro_label)
|
||||
|
||||
self.label=label=makelabel(desc)
|
||||
# label.height='400sp'
|
||||
# label.pos_hint = {'center_y':0.1+(0.1 * len(self.points))}
|
||||
# label.pos = (0.5,0)
|
||||
self.label_layout.add_widget(label)
|
||||
|
||||
|
||||
|
||||
self.last_lat,self.last_long = lat,long
|
||||
self.ax.set_global()
|
||||
|
||||
|
||||
# wait and show
|
||||
def open(self,maxwait=666,pulse=0.1):
|
||||
self.draw()
|
||||
super().open()
|
||||
self.opened=True
|
||||
# await asyncio.sleep(pulse)
|
||||
# waited=0
|
||||
# while not self.ok_to_continue:
|
||||
# await asyncio.sleep(pulse)
|
||||
# waited+=pulse
|
||||
# if waited>maxwait: break
|
||||
# # logger.info(f'waiting for {waited} seconds... {self.ok_to_continue} {self.response}')
|
||||
# return self.response
|
||||
|
||||
def dismiss(self):
|
||||
super().dismiss()
|
||||
if hasattr(self.layout,'img'):
|
||||
self.layout.remove_widget(self.img)
|
||||
if self.layout:
|
||||
self.remove_widget(self.layout)
|
||||
|
||||
default_places = {
|
||||
'Cambridge':(52.205338,0.121817),
|
||||
'Sydney':(-33.868820,151.209290),
|
||||
'New York':(40.712776,-74.005974),
|
||||
'Hong Kong':(22.278300,114.174700),
|
||||
'Cape Town':(-33.9249, 18.4241),
|
||||
'San Francisco':(37.774929,-122.419418),
|
||||
'Honolulu':(21.306944,-157.858337),
|
||||
'Tokyo':(35.689487,139.691711),
|
||||
'Ushuaia':(-54.801910,-68.302948),
|
||||
'Reykjavik':(64.126518,-21.817438)
|
||||
|
||||
}
|
||||
|
||||
|
||||
def test_map():
|
||||
map = MapWidget()
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
|
||||
test_map()
|
@ -1,4 +1,6 @@
|
||||
from screens.base import ProtectedScreen
|
||||
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..')))
|
||||
from komrade import *
|
||||
|
||||
|
||||
class NotificationsScreen(ProtectedScreen): pass
|
||||
|
@ -0,0 +1,319 @@
|
||||
"""
|
||||
Storage for both keys and data
|
||||
"""
|
||||
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..')))
|
||||
from komrade import *
|
||||
from simplekv.fs import FilesystemStore
|
||||
from simplekv.memory.redisstore import RedisStore
|
||||
import redis
|
||||
import hashlib,os
|
||||
import zlib
|
||||
from pythemis.exception import ThemisError
|
||||
|
||||
|
||||
|
||||
LOG_GET_SET = 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Crypt(Logger):
|
||||
def __init__(self,
|
||||
name=None,
|
||||
fn=None,
|
||||
use_secret=CRYPT_USE_SECRET,
|
||||
path_secret=PATH_CRYPT_SECRET,
|
||||
encrypt_values=False,
|
||||
encryptor_func=None,
|
||||
decryptor_func=None):
|
||||
|
||||
# defaults
|
||||
if not name and fn: name=os.path.basename(fn).replace('.','_')
|
||||
self.name,self.fn=name,fn
|
||||
|
||||
|
||||
# use secret? for salting
|
||||
if use_secret and path_secret:
|
||||
if not os.path.exists(path_secret):
|
||||
self.secret = get_random_binary_id()
|
||||
from komrade.backend.keymaker import make_key_discreet
|
||||
self.log('shhh! creating secret:',make_key_discreet(self.secret))
|
||||
with open(path_secret,'wb') as of:
|
||||
of.write(self.secret)
|
||||
else:
|
||||
with open(path_secret,'rb') as f:
|
||||
self.secret = f.read()
|
||||
else:
|
||||
self.secret = b''
|
||||
self.encrypt_values = encrypt_values
|
||||
if self.secret and encrypt_values and (not encryptor_func or not decryptor_func):
|
||||
from komrade.backend.keymaker import KomradeSymmetricKeyWithPassphrase
|
||||
self.key = KomradeSymmetricKeyWithPassphrase(
|
||||
passphrase=self.secret
|
||||
)
|
||||
encryptor_func = self.key.encrypt
|
||||
decryptor_func = self.key.decrypt
|
||||
self.encryptor_func=encryptor_func
|
||||
self.decryptor_func=decryptor_func
|
||||
|
||||
self.store = FilesystemStore(self.fn)
|
||||
# self.store = RedisStore(redis.StrictRedis())
|
||||
|
||||
|
||||
def log(self,*x):
|
||||
if LOG_GET_SET:
|
||||
super().log(*x)
|
||||
|
||||
def hash(self,binary_data):
|
||||
return hasher(binary_data,self.secret)
|
||||
|
||||
def force_binary(self,k_b):
|
||||
if k_b is None: return None
|
||||
if type(k_b)==str: k_b=k_b.encode()
|
||||
if type(k_b)!=bytes: k_b=k_b.decode()
|
||||
return k_b
|
||||
|
||||
def package_key(self,k,prefix=''):
|
||||
if not k: return b''
|
||||
k_b = self.force_binary(k)
|
||||
k_b2 = self.force_binary(prefix) + k_b
|
||||
return k_b2
|
||||
|
||||
def package_val(self,k,encrypt=None):
|
||||
if encrypt is None: encrypt=self.encrypt_values
|
||||
k_b = self.force_binary(k)
|
||||
if encrypt:
|
||||
try:
|
||||
k_b = self.encryptor_func(k_b)
|
||||
except ThemisError as e:
|
||||
self.log('!! ENCRYPTION ERROR:',e)
|
||||
return k_b
|
||||
|
||||
def unpackage_val(self,k_b,encrypt=None):
|
||||
if encrypt is None: encrypt=self.encrypt_values
|
||||
if encrypt:
|
||||
try:
|
||||
k_b = self.decryptor_func(k_b)
|
||||
except ThemisError as e:
|
||||
self.log('!! DECRYPTION ERROR:',e)
|
||||
return k_b
|
||||
|
||||
def has(self,k,prefix=''):
|
||||
return bool(self.get(k,prefix=prefix))
|
||||
|
||||
|
||||
def set(self,k,v,prefix='',override=False,encrypt=True):
|
||||
if self.has(k,prefix=prefix) and not override:
|
||||
self.log(f"I'm afraid I can't let you do that, overwrite someone's data!\n\nat {prefix}{k} = {v}")
|
||||
return False #(False,None,None)
|
||||
|
||||
k_b=self.package_key(k,prefix=prefix)
|
||||
k_b_hash = self.hash(k_b)
|
||||
v_b=self.package_val(v,encrypt = (self.encrypt_values and encrypt))
|
||||
if not override:
|
||||
self.log(f'''Crypt.set(\n\t{k_b}\n\n\t{k_b_hash}\n\n\t{v_b}\n)''')
|
||||
self.store.put(k_b_hash,v_b)
|
||||
return True
|
||||
|
||||
def exists(self,k,prefix=''):
|
||||
return self.has(k,prefix=prefix)
|
||||
|
||||
def key2hash(self,k,prefix=''):
|
||||
return self.hash(
|
||||
self.package_key(
|
||||
prefix + k
|
||||
)
|
||||
)
|
||||
|
||||
def delete(self,k,prefix=''):
|
||||
k_b=self.package_key(k,prefix=prefix)
|
||||
k_b_hash = self.hash(k_b)
|
||||
r=self.store.delete(k_b_hash)
|
||||
return r
|
||||
|
||||
|
||||
def get(self,k,prefix=''):
|
||||
k_b=self.package_key(k,prefix=prefix)
|
||||
k_b_hash = self.hash(k_b)
|
||||
try:
|
||||
v=self.store.get(k_b_hash)
|
||||
except KeyError:
|
||||
return None
|
||||
v_b=self.unpackage_val(v)
|
||||
return v_b
|
||||
|
||||
|
||||
class KeyCrypt(Crypt):
|
||||
def __init__(self):
|
||||
return super().__init__(name=PATH_CRYPT_CA_KEYS.replace('.','_'))
|
||||
|
||||
|
||||
class DataCrypt(Crypt):
|
||||
def __init__(self):
|
||||
return super().__init__(name=PATH_CRYPT_CA_DATA.replace('.','_'))
|
||||
|
||||
|
||||
|
||||
class CryptList(Crypt): # like inbox
|
||||
def __init__(self,
|
||||
crypt,
|
||||
keyname,
|
||||
prefix='',
|
||||
encryptor_func=lambda x: x,
|
||||
decryptor_func=lambda x: x):
|
||||
|
||||
self.crypt=crypt
|
||||
self.keyname=keyname
|
||||
self.prefix=prefix
|
||||
self.encryptor_func=encryptor_func
|
||||
self.decryptor_func=decryptor_func
|
||||
|
||||
def __repr__(self):
|
||||
return f"""
|
||||
(CryptList)
|
||||
val_b_encr = {self.val_b_encr}
|
||||
val_b = {self.val_b}
|
||||
values = {self.values}
|
||||
"""
|
||||
|
||||
@property
|
||||
def val_b_encr(self):
|
||||
res = self.crypt.get(
|
||||
self.keyname,
|
||||
prefix=self.prefix
|
||||
)
|
||||
self.log('res from crypt:',res)
|
||||
return res
|
||||
|
||||
@property
|
||||
def val_b(self):
|
||||
val_b_encr=self.val_b_encr
|
||||
if not val_b_encr: return None
|
||||
return self.decryptor_func(val_b_encr)
|
||||
|
||||
@property
|
||||
def values(self):
|
||||
if not hasattr(self,'_values') or not self._values:
|
||||
val_b=self.val_b
|
||||
if not val_b: return []
|
||||
self._values = pickle.loads(val_b)
|
||||
return self._values
|
||||
|
||||
def prepend(self,x_l):
|
||||
return self.append(x_l,insert=0)
|
||||
|
||||
def append(self,x_l,insert=None):
|
||||
if type(x_l)!=list: x_l=[x_l]
|
||||
val_l = self.values
|
||||
self.log('val_l =',val_l)
|
||||
x_l = [x for x in x_l if not x in set(val_l)]
|
||||
# print('val_l =',val_l)
|
||||
for x in x_l:
|
||||
if insert is not None:
|
||||
val_l.insert(insert,x)
|
||||
else:
|
||||
val_l.append(x)
|
||||
# print('val_l2 =',val_l)
|
||||
return self.set(val_l)
|
||||
|
||||
def set(self,val_l):
|
||||
self._values = val_l
|
||||
|
||||
val_b = pickle.dumps(val_l)
|
||||
val_b_encr = self.encryptor_func(val_b)
|
||||
return self.crypt.set(
|
||||
self.keyname,
|
||||
val_b_encr,
|
||||
prefix=self.prefix,
|
||||
override=True
|
||||
)
|
||||
|
||||
def remove(self,l):
|
||||
if type(l)!=list: l=[l]
|
||||
lset=set(l)
|
||||
values = [x for x in self.values if x not in lset]
|
||||
return self.set(values)
|
||||
|
||||
|
||||
|
||||
|
||||
# !!!!
|
||||
# @TODO: CAUSING PROBLEMS
|
||||
# !!!
|
||||
|
||||
class CryptListRedis(Logger):
|
||||
def __init__(self,keyname,prefix='',**y):
|
||||
self.redis = redis.StrictRedis()
|
||||
# self.store = RedisStore(self.redis)
|
||||
self.keyname=b64enc_s(prefix)+b64enc_s(keyname)
|
||||
self.log('loading CryptList',keyname,prefix,self.keyname)
|
||||
|
||||
def package_val(self,val):
|
||||
if type(val)==bytes: val=val.decode()
|
||||
# return b64enc_s(val)
|
||||
return val
|
||||
|
||||
def unpackage_val(self,val):
|
||||
if type(val)==str: val=val.encode()
|
||||
# return b64dec(val)
|
||||
return val
|
||||
|
||||
def append(self,val):
|
||||
self.log('<--val',val)
|
||||
if type(val)==list: return [self.append(x) for x in val]
|
||||
val_x = self.package_val(val)
|
||||
res = self.redis.rpush(self.keyname,val_x)
|
||||
self.log('-->',res)
|
||||
return res
|
||||
|
||||
def prepend(self,val):
|
||||
self.log('<--val',val)
|
||||
if type(val)==list: return [self.prepend(x) for x in val]
|
||||
val_x = self.package_val(val)
|
||||
res = self.redis.lpush(self.keyname,val_x)
|
||||
self.log('-->',res)
|
||||
return res
|
||||
|
||||
@property
|
||||
def values(self):
|
||||
l = self.redis.lrange(self.keyname, 0, -1 )
|
||||
vals = [self.unpackage_val(x) for x in l]
|
||||
self.log('-->',vals)
|
||||
return vals
|
||||
|
||||
def remove(self,val):
|
||||
self.log('<--',val)
|
||||
if type(val)==list: return [self.remove(x) for x in val]
|
||||
val_x = self.package_val(val)
|
||||
res = self.redis.lrem(self.keyname, 0, val_x)
|
||||
self.log('-->',res)
|
||||
return res
|
||||
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
crypt = Crypt('testt')
|
||||
|
||||
from komrade import KomradeSymmetricKeyWithPassphrase
|
||||
key = KomradeSymmetricKeyWithPassphrase()
|
||||
|
||||
|
||||
crypt_list = CryptListRedis(
|
||||
keyname='MyInbox2',
|
||||
# crypt=crypt
|
||||
)
|
||||
|
||||
print(crypt_list.values)
|
||||
|
||||
# print(crypt_list.remove('cool thing 0'))
|
||||
|
||||
# print(crypt_list.append('cool thing 1'))
|
||||
|
||||
print(crypt_list.append('#1 baby'))
|
||||
print(crypt_list.append('cool thing 0'))
|
||||
print(crypt_list.prepend('#0 baby'))
|
||||
|
||||
# print(crypt_list.remove('cool thing 0'))
|
||||
|
||||
print(crypt_list.values)
|
Loading…
Reference in New Issue