2020-08-21 02:28:14 +08:00
|
|
|
from kivy.event import EventDispatcher
|
2020-08-26 07:15:17 +08:00
|
|
|
from kivy.core.window import Window
|
|
|
|
from kivy.utils import platform
|
|
|
|
from kivy.properties import BooleanProperty
|
|
|
|
|
|
|
|
desktopOSs=[
|
|
|
|
"win",
|
|
|
|
"linux",
|
|
|
|
"macosx"
|
|
|
|
]
|
2019-12-19 11:13:47 +08:00
|
|
|
|
2020-08-21 02:28:14 +08:00
|
|
|
class WidgetReady(EventDispatcher):
|
2020-08-26 07:15:17 +08:00
|
|
|
fullscreen = BooleanProperty(False)
|
|
|
|
_fullscreen_state = False
|
|
|
|
|
2020-08-21 02:28:14 +08:00
|
|
|
def __init__(self):
|
|
|
|
self.register_event_type('on_ready')
|
2020-11-13 18:00:26 +08:00
|
|
|
self.register_event_type('on_key_down')
|
2020-08-21 02:28:14 +08:00
|
|
|
self._ready = False
|
2019-12-19 11:13:47 +08:00
|
|
|
|
2020-08-21 02:28:14 +08:00
|
|
|
def on_ready(self):
|
|
|
|
pass
|
2020-11-13 18:00:26 +08:00
|
|
|
def on_key_down(self,keyinfo):
|
|
|
|
"""
|
|
|
|
keyinfo is a dict with:
|
|
|
|
keyname
|
|
|
|
modifiers
|
|
|
|
keys
|
|
|
|
"""
|
|
|
|
print(kinfo)
|
2019-12-19 11:13:47 +08:00
|
|
|
|
2020-08-21 02:28:14 +08:00
|
|
|
def ready(self):
|
|
|
|
if self._ready:
|
|
|
|
return
|
|
|
|
self.dispatch('on_ready')
|
|
|
|
self._ready = True
|
2020-08-25 10:17:49 +08:00
|
|
|
|
|
|
|
def reready(self):
|
|
|
|
self._ready = False
|
|
|
|
self.ready()
|
2020-08-26 07:15:17 +08:00
|
|
|
|
2020-11-13 18:00:26 +08:00
|
|
|
def use_keyboard(self, keyinfos=[]):
|
|
|
|
"""
|
|
|
|
keyinfos is a list of aceepted keys keyinfo
|
|
|
|
if the on_key_down's key is one of the keyinfos,
|
|
|
|
fire a event, and return True,
|
|
|
|
else just return False
|
|
|
|
"""
|
|
|
|
self.my_kb = Window.request_keyboard(self.unuse_keyboard, self, "text")
|
|
|
|
self.my_kb.bind(on_key_down=self._on_keyboard_down)
|
|
|
|
if self.my_kb.widget:
|
2020-11-13 18:13:46 +08:00
|
|
|
pass #self.my_kb.set_mode_free()
|
2020-11-13 18:00:26 +08:00
|
|
|
self.keyinfos = keyinfos
|
|
|
|
|
|
|
|
def unuse_keyboard(self):
|
|
|
|
print('My keyboard have been closed!')
|
|
|
|
self.my_kb.unbind(on_key_down=self._on_keyboard_down)
|
|
|
|
self.my_kb = None
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
def listqual(l1,l2):
|
|
|
|
a = [i for i in l1 if i not in l2]
|
|
|
|
b = [i for i in l2 if i not in l1]
|
|
|
|
if len(a) == 0 and len(b) == 0:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
# Keycode is composed of an integer + a string
|
|
|
|
# If we hit escape, release the keyboard
|
2020-11-13 21:56:44 +08:00
|
|
|
keyinfo = {
|
|
|
|
"keyname":keycode[1],
|
|
|
|
"modifiers":modifiers
|
|
|
|
}
|
|
|
|
self.dispatch('on_key_down',keyinfo)
|
|
|
|
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
|
|
|
|
|
|
|
|
if value:
|
|
|
|
Window.fullscreen = True
|
|
|
|
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:
|
|
|
|
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)
|