first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,67 @@
|
|||
"""
|
||||
asynckivy
|
||||
=========
|
||||
|
||||
Copyright (c) 2019 Nattōsai Mitō
|
||||
|
||||
GitHub -
|
||||
https://github.com/gottadiveintopython
|
||||
GitHub Gist -
|
||||
https://gist.github.com/gottadiveintopython/5f4a775849f9277081c396de65dc57c1
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ("start", "sleep", "event")
|
||||
|
||||
import types
|
||||
from collections import namedtuple
|
||||
from functools import partial
|
||||
|
||||
from kivy.clock import Clock
|
||||
|
||||
CallbackParameter = namedtuple("CallbackParameter", ("args", "kwargs"))
|
||||
|
||||
|
||||
def start(coro):
|
||||
def step(*args, **kwargs):
|
||||
try:
|
||||
coro.send(CallbackParameter(args, kwargs))(step)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
try:
|
||||
coro.send(None)(step)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
|
||||
@types.coroutine
|
||||
def sleep(duration):
|
||||
# The partial() here looks meaningless. But this is needed in order
|
||||
# to avoid weak reference.
|
||||
param = yield lambda step_coro: Clock.schedule_once(
|
||||
partial(step_coro), duration
|
||||
)
|
||||
return param.args[0]
|
||||
|
||||
|
||||
class event:
|
||||
def __init__(self, ed, name):
|
||||
self.bind_id = None
|
||||
self.ed = ed
|
||||
self.name = name
|
||||
|
||||
def bind(self, step_coro):
|
||||
self.bind_id = bind_id = self.ed.fbind(self.name, self.callback)
|
||||
assert bind_id > 0 # check if binding succeeded
|
||||
self.step_coro = step_coro
|
||||
|
||||
def callback(self, *args, **kwargs):
|
||||
self.parameter = CallbackParameter(args, kwargs)
|
||||
ed = self.ed
|
||||
ed.unbind_uid(self.name, self.bind_id)
|
||||
self.step_coro()
|
||||
|
||||
def __await__(self):
|
||||
yield self.bind
|
||||
return self.parameter
|
|
@ -0,0 +1,48 @@
|
|||
"""
|
||||
Monitor module
|
||||
==============
|
||||
|
||||
The Monitor module is a toolbar that shows the activity of your current
|
||||
application :
|
||||
|
||||
* FPS
|
||||
|
||||
"""
|
||||
|
||||
from kivy.clock import Clock
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import NumericProperty, StringProperty, OptionProperty
|
||||
from kivy.uix.label import Label
|
||||
|
||||
Builder.load_string(
|
||||
"""
|
||||
<FpsMonitor>:
|
||||
size_hint_y: None
|
||||
height: self.texture_size[1]
|
||||
text: root._fsp_value
|
||||
pos_hint: {root.anchor: 1}
|
||||
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: app.theme_cls.primary_dark
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
class FpsMonitor(Label):
|
||||
updated_interval = NumericProperty(0.5)
|
||||
"""FPS refresh rate."""
|
||||
|
||||
anchor = OptionProperty("top", options=["top", "bottom"])
|
||||
"""Monitor position."""
|
||||
|
||||
_fsp_value = StringProperty()
|
||||
|
||||
def start(self):
|
||||
Clock.schedule_interval(self.update_fps, self.updated_interval)
|
||||
|
||||
def update_fps(self, *args):
|
||||
self._fsp_value = "FPS: %f" % Clock.get_fps()
|
|
@ -0,0 +1,128 @@
|
|||
# The code is taken from AKivyMD project -
|
||||
# https://github.com/kivymd-extensions/akivymd
|
||||
#
|
||||
# Source code -
|
||||
# kivymd_extensions/akivymd/uix/statusbarcolor.py
|
||||
#
|
||||
# Author Sina Namadian -
|
||||
# https://github.com/quitegreensky
|
||||
|
||||
from typing import Union
|
||||
|
||||
from kivy.utils import get_hex_from_color, platform
|
||||
|
||||
|
||||
def set_bars_colors(
|
||||
status_bar_color: Union[None, list],
|
||||
navigation_bar_color: Union[None, list],
|
||||
icons_color: str = "Light",
|
||||
):
|
||||
"""
|
||||
Sets the color of the status of the StatusBar and NavigationBar.
|
||||
|
||||
.. warning:: Works only on Android devices.
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/status-bar-color-light.png
|
||||
:align: center
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from kivy.lang import Builder
|
||||
|
||||
from kivymd.app import MDApp
|
||||
from kivymd.utils.set_bars_colors import set_bars_colors
|
||||
|
||||
KV = '''
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDTopAppBar:
|
||||
title: "MDTopAppBar"
|
||||
|
||||
MDBottomNavigation:
|
||||
panel_color: app.theme_cls.primary_color
|
||||
text_color_active: .2, .2, .2, 1
|
||||
text_color_normal: .9, .9, .9, 1
|
||||
use_text: False
|
||||
|
||||
MDBottomNavigationItem:
|
||||
icon: 'gmail'
|
||||
|
||||
MDBottomNavigationItem:
|
||||
icon: 'twitter'
|
||||
|
||||
MDBottomNavigationItem:
|
||||
icon: 'youtube'
|
||||
'''
|
||||
|
||||
|
||||
class Test(MDApp):
|
||||
def build(self):
|
||||
self.set_bars_colors()
|
||||
return Builder.load_string(KV)
|
||||
|
||||
def set_bars_colors(self):
|
||||
set_bars_colors(
|
||||
self.theme_cls.primary_color, # status bar color
|
||||
self.theme_cls.primary_color, # navigation bar color
|
||||
"Light", # icons color of status bar
|
||||
)
|
||||
|
||||
|
||||
Test().run()
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/navigation-bar-color.png
|
||||
:align: center
|
||||
|
||||
.. rubric:: Dark icon mode
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def set_bars_colors(self):
|
||||
set_bars_colors(
|
||||
self.theme_cls.primary_color, # status bar color
|
||||
self.theme_cls.primary_color, # navigation bar color
|
||||
"Dark", # icons color of status bar
|
||||
)
|
||||
|
||||
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/status-bar-color-dark.png
|
||||
:align: center
|
||||
|
||||
.. versionadded:: 1.0.0
|
||||
"""
|
||||
|
||||
if platform == "android":
|
||||
from android.runnable import run_on_ui_thread
|
||||
from jnius import autoclass
|
||||
|
||||
Color = autoclass("android.graphics.Color")
|
||||
WindowManager = autoclass("android.view.WindowManager$LayoutParams")
|
||||
activity = autoclass("org.kivy.android.PythonActivity").mActivity
|
||||
View = autoclass("android.view.View")
|
||||
|
||||
def statusbar(*args):
|
||||
status_color = None
|
||||
navigation_color = None
|
||||
|
||||
if status_bar_color:
|
||||
status_color = get_hex_from_color(status_bar_color)[:7]
|
||||
if navigation_bar_color:
|
||||
navigation_color = get_hex_from_color(navigation_bar_color)[:7]
|
||||
window = activity.getWindow()
|
||||
|
||||
if icons_color == "Dark":
|
||||
window.getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
)
|
||||
elif icons_color == "Light":
|
||||
window.getDecorView().setSystemUiVisibility(0)
|
||||
|
||||
window.clearFlags(WindowManager.FLAG_TRANSLUCENT_STATUS)
|
||||
window.addFlags(WindowManager.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
|
||||
if status_color:
|
||||
window.setStatusBarColor(Color.parseColor(status_color))
|
||||
if navigation_color:
|
||||
window.setNavigationBarColor(Color.parseColor(navigation_color))
|
||||
|
||||
return run_on_ui_thread(statusbar)()
|
Loading…
Add table
Add a link
Reference in a new issue