kivyblocks/kivyblocks/ready.py

105 lines
2.6 KiB
Python
Raw Normal View History

2020-08-26 07:15:17 +08:00
from kivy.core.window import Window
2021-03-27 14:04:10 +08:00
from kivy.clock import Clock
2020-08-26 07:15:17 +08:00
from kivy.utils import platform
2021-01-04 19:55:38 +08:00
from kivy.app import App
2020-08-26 07:15:17 +08:00
from kivy.properties import BooleanProperty
desktopOSs=[
"win",
"linux",
"macosx"
]
2019-12-19 11:13:47 +08:00
2021-02-03 14:44:59 +08:00
class WidgetReady(object):
2020-08-26 07:15:17 +08:00
fullscreen = BooleanProperty(False)
2021-03-27 14:04:10 +08:00
ready = BooleanProperty(False)
_fullscreen = False
2020-08-26 07:15:17 +08:00
2021-03-27 14:04:10 +08:00
def on_ready(self, *args):
2020-08-21 02:28:14 +08:00
pass
2019-12-19 11:13:47 +08:00
2021-03-27 14:04:10 +08:00
def set_ready(self, *args):
self.ready = True
2020-08-25 10:17:49 +08:00
def reready(self):
2021-03-27 14:04:10 +08:00
self.ready = False
Clock.schedule_once(self.set_ready, 0.1)
2020-08-26 07:15:17 +08:00
2020-11-13 22:12:25 +08:00
def use_keyboard(self):
self.my_kb = Window.request_keyboard(None, self)
if not self.my_kb:
print('my_kb is None........')
return
2020-11-13 18:00:26 +08:00
self.my_kb.bind(on_key_down=self._on_keyboard_down)
if self.my_kb.widget:
2020-11-13 22:12:25 +08:00
self.my_kb.set_mode_free()
2020-11-13 18:00:26 +08:00
2020-11-13 22:25:08 +08:00
def key_handle(self,keyinfo):
pass
2020-11-13 18:00:26 +08:00
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
print('The key', keycode, 'have been pressed')
print(' - text is %r' % text)
print(' - modifiers are %r' % modifiers)
2020-11-13 21:56:44 +08:00
keyinfo = {
"keyname":keycode[1],
"modifiers":modifiers
}
2020-11-13 22:25:08 +08:00
self.key_handle(keyinfo)
2020-11-13 21:56:44 +08:00
return True
2020-11-13 18:00:26 +08:00
2020-08-26 07:15:17 +08:00
def on_fullscreen(self, instance, value):
window = self.get_parent_window()
if not window:
Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
'window not found.')
return
if not self.parent:
Logger.warning('VideoPlayer: Cannot switch to fullscreen, '
'no parent.')
return
2021-01-04 19:55:38 +08:00
app = App.get_running_app()
2020-08-26 07:15:17 +08:00
if value:
Window.fullscreen = True
2021-01-04 19:55:38 +08:00
app.fs_widget = self
2020-08-26 07:15:17 +08:00
self._fullscreen_state = state = {
'parent': self.parent,
'pos': self.pos,
'size': self.size,
'pos_hint': self.pos_hint,
'size_hint': self.size_hint,
'window_children': window.children[:]}
2020-08-30 10:26:43 +08:00
# if platform in desktopOSs:
# Window.maximize()
2020-08-26 07:15:17 +08:00
# remove all window children
for child in window.children[:]:
window.remove_widget(child)
# put the video in fullscreen
if state['parent'] is not window:
state['parent'].remove_widget(self)
window.add_widget(self)
# ensure the video widget is in 0, 0, and the size will be
# readjusted
self.pos = (0, 0)
self.pos_hint = {}
self.size_hint = (1, 1)
else:
2021-01-04 19:55:38 +08:00
app.fs_widget = None
2020-08-26 07:15:17 +08:00
Window.fullscreen = False
2020-09-16 15:08:01 +08:00
#if platform in desktopOSs:
# Window.restore()
2020-08-26 07:15:17 +08:00
state = self._fullscreen_state
window.remove_widget(self)
for child in state['window_children']:
window.add_widget(child)
self.pos_hint = state['pos_hint']
self.size_hint = state['size_hint']
self.pos = state['pos']
self.size = state['size']
if state['parent'] is not window:
state['parent'].add_widget(self)