From 7fdbf8bc76b70e39b5e598e1be375cdd2c7a657e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 30 Jun 2021 14:42:33 +0800 Subject: [PATCH] bugfix --- kivyblocks/android_rotation.py | 9 +++++---- kivyblocks/camerawithmic.py | 21 +++++++++++++++++++-- kivyblocks/twosides.py | 4 ---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/kivyblocks/android_rotation.py b/kivyblocks/android_rotation.py index 5129531..485a87a 100644 --- a/kivyblocks/android_rotation.py +++ b/kivyblocks/android_rotation.py @@ -1,14 +1,15 @@ from kivy.utils import platform import plyer try: - # - # from android import activity - # get_rotation() failed module 'android.activity' has no attribute 'getWindowManager' from plyer.platforms.android import activity except: - print('android_rotation.py:mport ERROR') + print('android_rotation.py:import ERROR') activity = None +ROTATION_0 = 0 +ROTATION_90 = 1 +ROTATION_180 = 2 +ROTATION_270 = 3 def get_rotation(): try: r = activity.getWindowManager().getDefaultDisplay().getRotation() diff --git a/kivyblocks/camerawithmic.py b/kivyblocks/camerawithmic.py index 7d2dc71..1c88c94 100644 --- a/kivyblocks/camerawithmic.py +++ b/kivyblocks/camerawithmic.py @@ -6,6 +6,8 @@ from kivy.uix.camera import Camera from kivy.properties import NumericProperty from kivy.event import EventDispatcher +from .android_rotation import * + if kivy.platform in [ 'win', 'linux', 'macosx' ]: from PIL import ImageGrab class ScreenWithMic(Micphone, EventDispatcher): @@ -26,13 +28,27 @@ if kivy.platform in [ 'win', 'linux', 'macosx' ]: } return d +VS={ + ROTATION_0:270, + ROTATION_90:0, + ROTATION_180:90, + ROTATION_270:180, +} class CameraWithMic(Micphone, Camera): angle = NumericProperty(0) def __init__(self, **kw): super(CameraWithMic, self).__init__(**kw) self.isAndroid = kivy.platform == 'android' - if self.isAndroid: - self.angle = -90 + self.set_angle(-90) + + def set_angle(self, angle): + self.angle = angle + + def image_rotation(self): + if not self.isAndroid: + return + x = get_rotation() + self.angle = VS[x] def get_image_data(self): image = np.frombuffer(self.texture.pixels, dtype='uint8') @@ -41,6 +57,7 @@ class CameraWithMic(Micphone, Camera): return imgdata def get_fps_data(self, *args): + # self.image_rotation() ad = super(CameraWithMic, self).get_fps_data() vd = self.get_image_data() d = { diff --git a/kivyblocks/twosides.py b/kivyblocks/twosides.py index f076236..36ad3af 100644 --- a/kivyblocks/twosides.py +++ b/kivyblocks/twosides.py @@ -131,16 +131,12 @@ class TwoSides(WidgetReady, BoxLayout): pass def on_afterswitch_landscape(self, *args): - print('twosides.py:Window.rotation=', Window.rotation, - Window.size) pass def on_beforeswitch_portrait(self, *args): pass def on_afterswitch_portrait(self, *args): - print('twosides.py:Window.rotation=', Window.rotation, - Window.size) pass def on_interactive(self, *args):