From 5abce3c536bec827f49e8e4ad8795c0e3bc9f24e Mon Sep 17 00:00:00 2001 From: qlrd <106913782+qlrd@users.noreply.github.com> Date: Sun, 29 Oct 2023 13:47:05 -0300 Subject: [PATCH 1/3] added 'unload_zbarcam' that unload zbarcam.kv and xcamera.kv files --- src/kivy_garden/zbarcam/zbarcam.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/kivy_garden/zbarcam/zbarcam.py b/src/kivy_garden/zbarcam/zbarcam.py index 67d57e4..410d2fe 100644 --- a/src/kivy_garden/zbarcam/zbarcam.py +++ b/src/kivy_garden/zbarcam/zbarcam.py @@ -1,3 +1,4 @@ +import sys import os from collections import namedtuple @@ -210,3 +211,19 @@ def stop(self): self.xcamera.play = False if platform == "android": self.xcamera._camera._release_camera() + + def unload_zbarcam(self): + id ZBarCam.kv_loaded: + # unload zbarcam.kv + zbar_kv_path = os.path.join(MODULE_DIRECTORY, 'zbarcam.kv') + Builder.unload_file(zbar_kv_path) + + # unload xcamera.kv + mod_path = os.path.dirname( + sys.modules['kivy_garden.xcamera'].__file__ + ) + xcam_kv_path = os.path.join(mod_path, 'xcamera.kv') + Builder.unload_file(xcam_kv_path) + + # set kv_loaded = false + ZBarCam.kv_loaded = False From 5f3326a87625ca59c6ba6863b2c61a6646f74cc2 Mon Sep 17 00:00:00 2001 From: qlrd <106913782+qlrd@users.noreply.github.com> Date: Sun, 29 Oct 2023 21:40:32 +0000 Subject: [PATCH 2/3] Update zbarcam.py Fixed typo: `id` to `if` on `unload_zbarcam method --- src/kivy_garden/zbarcam/zbarcam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kivy_garden/zbarcam/zbarcam.py b/src/kivy_garden/zbarcam/zbarcam.py index 410d2fe..ec59381 100644 --- a/src/kivy_garden/zbarcam/zbarcam.py +++ b/src/kivy_garden/zbarcam/zbarcam.py @@ -213,7 +213,7 @@ def stop(self): self.xcamera._camera._release_camera() def unload_zbarcam(self): - id ZBarCam.kv_loaded: + if ZBarCam.kv_loaded: # unload zbarcam.kv zbar_kv_path = os.path.join(MODULE_DIRECTORY, 'zbarcam.kv') Builder.unload_file(zbar_kv_path) From 6d2f27d5c88181763aba3fde8636bcd721003084 Mon Sep 17 00:00:00 2001 From: qlrd <106913782+qlrd@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:16:21 -0300 Subject: [PATCH 3/3] updated added release device step for non android devices in method changed method to --- src/kivy_garden/zbarcam/zbarcam.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/kivy_garden/zbarcam/zbarcam.py b/src/kivy_garden/zbarcam/zbarcam.py index ec59381..c443259 100644 --- a/src/kivy_garden/zbarcam/zbarcam.py +++ b/src/kivy_garden/zbarcam/zbarcam.py @@ -208,22 +208,37 @@ def start(self): self.xcamera.play = True def stop(self): + """ + Stop xcamera, release device and unload + zbarcam.kv and xcamera.kv + """ self.xcamera.play = False + + # release device and unload kivy files + # in non android devices + if platform != "android": + self.xcamera._camera._device.release() + self._unload() + + # release device in android devices if platform == "android": self.xcamera._camera._release_camera() - def unload_zbarcam(self): + def _unload(self): + """ + Unload `zbarcam.kv` and `xcamera.kv` files + """ if ZBarCam.kv_loaded: # unload zbarcam.kv zbar_kv_path = os.path.join(MODULE_DIRECTORY, 'zbarcam.kv') Builder.unload_file(zbar_kv_path) # unload xcamera.kv - mod_path = os.path.dirname( - sys.modules['kivy_garden.xcamera'].__file__ - ) - xcam_kv_path = os.path.join(mod_path, 'xcamera.kv') + module_path = sys.modules['kivy_garden.xcamera'].__file__ + module_directory = os.path.dirname(module_path) + xcam_kv_path = os.path.join(module_directory, 'xcamera.kv') Builder.unload_file(xcam_kv_path) - # set kv_loaded = false - ZBarCam.kv_loaded = False + # sets kv_loaded + ZBarcam.kv_loaded = False +