Kivy: Running the App Automatically When Slide To Unlock the Phone - android

I'm building an Android App, using Kivy and Python 2.7, which is going to unlock the phone based on Face Recognition. After downloading the App and initializing it, I would like the App to be opened directly when Slide To Unlock the phone, open a specific screen "The Recognizer Screen, recognize my face and then Unlock the phone.
What should I add to the .KV code or even to the .py code to root the Slide To Unlock to my app?
For example, if this is my .KV code
<ScreenFour>:
name: "screen4"
id: screen_four
FloatLayout:
canvas:
Rectangle:
source: "image1.jpg"
pos:self.pos
size:self.size
Button:
text: 'Next'
font_size: 32 # font size
size_hint: .2,.1
pos_hint:{'right':1, 'y':0}
on_release: app.root.current="screen5"
Button:
text: "Unlock the phone"
font_size: 20
pos_hint:{'right':0.5, 'y':0.5}
size_hint: 0.4,0.2
on_release: app.fr()
where one_release: app.fr() is the root to start the FaceRecognizer code
What do I have to add to this code? Or do I have to add any thing to the Python code on the specific
class ScreenFour(Screen):
pass
Or do I have to add it here:
class FaceRecognitionApp(App):
def fg(self):
FaceGenerator()
def fr(self):
FaceRecognizer()
def build(self):
return sm
if __name__=="__main__":
FaceRecognitionApp().run()
I would really appreciate having an answer, I'm working on a project and I'm running out of time.

Related

ListView in Kivy

I am trying to create a ListView widget in Kivy, but cannot; am using Python 3.10 and Kivy 2.0. Later I changed it to RecycleView. Window is opening but items in the item_strings property of RecycleView are not getting displayed.
AddLocationForm:
<AddLocationForm#BoxLayout>:
orientation: 'vertical'
BoxLayout:
TextInput:
Button:
text: 'Search'
Button:
text: 'Current Location'
RecycleView:
item_strings: ["Kolkata", 'New Delhi']
My main.py is as follows:
from kivy.app import App
class WeatherApp(App):
pass
if __name__ == '__main__':
app = WeatherApp()
app.run()
Can you help me out.

How to disable multi-touch function for Android App

So I have created Mobile App called PushApp using Python library Kivy. App lets user input number of how many pushups he wants to do. Then its supposed to decrement the number by one when chest hits screen(button). If screen is touched by multiple body parts it decrements many numbers. I would like to know how to disable multitouch function for Android phones at least.
Regards,
Highzivs
I have managed to solve this problem by creating function (BUTTON_DOWN()) that returns how many times button has been pushed down and function (BUTTON_UP) that returns button release times.
Then I created function (PUSH_UP) which returns true if BUTTON_DOWN()==BUTTON_UP()
in Python:
class CountScreen(Screen):
DOWN_COUNT=0
UP_COUNT=0
PUSH_UP_COUNT=0
def BUTTON_DOWN(self):
self.DOWN_COUNT=self.DOWN_COUNT+1
return self.DOWN_COUNT
def BUTTON_UP(self):
self.UP_COUNT=self.UP_COUNT+1
return self.UP_COUNT
def PUSH_UP(self):
if self.BUTTON_UP()==self.BUTTON_DOWN():
return True
in Kivy:
<CountScreen>:
name:"CountingWindow"
GridLayout:
cols:1
Label:
id:lbl_1
font_size:400
text:""
Button:
id:"btn_1"
background_color:(0,0,0,.1)
on_press:
root.BUTTON_DOWN()
on_release:
root.BUTTON_UP()
if root.PUSH_UP():lbl_1.text=str(int(lbl_1.text)-1) #DECREMENTS 1 FROM USER INPUT
if lbl_1.text == '0':app.root.current="FinalScreen" #GO TO FINAL WINDOW WHEN FINISHED

Kivy camera does not save pic on android phone

the code from this site is not working for me: https://kivy.org/doc/stable/examples/gen__camera__main__py.html
It works perfectly on my pc. However, when I push it to my android phone with
buildozer -v android debug deploy run
The camera opens up normally and when I press 'Capture', it acts as if it takes a picture. However, when I look into the phone's gallery, I can't find any new picture. Is the picture saved somewhere that's not in the gallery? My app has a few more steps to upload that pic to google firebase. And it can never find the recently taken pic in the root directory. Again, it's working perfectly on PC. My buildozer spec is:
Permissionsandroid.permissions = INTERNET,CAMERA,WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE
I tried WRITE_INTERNAL_STORAGE and it didn't like it. So I guess writing to internal storage permission is given by default.
Another minor issue: the screen on the app is flipped sideways. It's showing the correct live pic but it's a bit weird. I tried switching between 'vertical' and 'horizontal' in the Builder.load_string but nothing changes.
Please assist. I appreciate any input.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import time
Builder.load_string('''
<CameraClick>:
orientation: 'vertical'
Camera:
id: camera
resolution: (640, 480)
play: False
ToggleButton:
text: 'Play'
on_press: camera.play = not camera.play
size_hint_y: None
height: '48dp'
Button:
text: 'Capture'
size_hint_y: None
height: '48dp'
on_press: root.capture()
''')
class CameraClick(BoxLayout):
def capture(self):
'''
Function to capture the images and give them the names
according to their captured time and date.
'''
camera = self.ids['camera']
timestr = time.strftime("%Y%m%d_%H%M%S")
camera.export_to_png("IMG_{}.png".format(timestr))
print("Captured")
class TestCamera(App):
def build(self):
return CameraClick()
TestCamera().run()````
I have figured it out. Somehow the root directory doesn't work. To make it work, simply change
camera.export_to_png("IMG_{}.png".format(timestr))
to
camera.export_to_png("/sdcard/IMG_{}.png".format(timestr))

Python - Kivy - Builtdozer : Having a button call the android keyboard

Framework: I am talking about an Android app written in Python 2.7 and packaged with Builtdozer
I have a Builder inside the app with a button
Builder.load_string('''
FloatLayout:
orientation: 'horizontal'
Button:
text: str(root.name)
font_size: '20sp'
pos_hint: {'x':.0, 'y':.3}
size_hint: .4, .8
''')
I want to create a function, change_name, that, if I press the above button, opens the android keyboard to accept an user raw_input
The raw_input provided by the user has to replace the text of the above button.
What I thought is:
1) Create a variable name = StringProperty('Me')
2) Create a function:
def change_name(self):
self.name = raw_input()
3) Call the function inside my button with a on_release
Builder.load_string('''
FloatLayout:
orientation: 'horizontal'
Button:
text: str(root.name)
font_size: '20sp'
pos_hint: {'x':.0, 'y':.3}
size_hint: .4, .8
on_release: root.change_name()
''')
It is correct? Because actually, running the app on Ubuntu, I am trying to click on the button but the app does not ask for an input (it seems blocked).
As a consequence I believe it will not work also on Android.
Could you please help me understanding where am I wrong?
raw_input allows to get input from stdin (terminal). On Android you will not have the terminal available. In addition, raw_input is blocking, this causes the main event loop of your app to be freeze and will cause your app to stop responding.
You shouldn't use raw_input but Kivy's own methods.
On the other hand, you want to make your button editable (as if it were a TextInput). You can create your own custom Button class or use WindowBase.request_keyboard() to request the keyboard manually. However, you can do a little trick by hiding a TextInput and use it to enter the text:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
kv_text= ('''
<MyWidget>:
FloatLayout:
orientation: 'horizontal'
Button:
text: 'Hello'
font_size: '20sp'
pos_hint: {'x':.0, 'y':.3}
size_hint: .4, .8
on_release: root.change_name(self)
Button:
text: 'World'
font_size: '20sp'
pos_hint: {'x':0.6, 'y':.3}
size_hint: .4, 0.8
on_release: root.change_name(self)
''')
class MyWidget(FloatLayout):
def __init__(self, **kwargs):
super(MyWidget, self).__init__(**kwargs)
self.hide_input = TextInput(size_hint=(None, None),
size = (0, 0),
multiline = False)
self.hide_input_bind = None
def change_name(self, instance):
if self.hide_input_bind:
self.hide_input.unbind_uid('text', self.hide_input_bind)
self.hide_input.text = instance.text
self.hide_input.focus = True
self.hide_input_bind = self.hide_input.fbind('text', self._update_text, instance)
def _update_text(self, button, instance, value):
button.text = value
class MyKivyApp(App):
def build(self):
return MyWidget()
def main():
Builder.load_string(kv_text)
app = MyKivyApp()
app.run()
if __name__ == '__main__':
main()
App working on Android (Kivy Launcher):

How to build Android App GUI using KV language?

I'm building a simple android App using Python Kivy, but I'm not able to make a simple GUI, what I'm trying to achieve is the following
a text saying "FB"
a user input
a Button
I'm using BoxLayout, below is my KV code and the result that I got ...
How can I make the TextInput above the button? Also, is there any simple Kivy GUI builder I can use?
Builder.load_string('''
<MyInterface>:
orientation: 'vertical'
Label:
text: "FB"
Label:
TextInput:
id: number
size_hint_y: None
size: (400,100)
IntentButton:
size_hint_y: None
size: (400,100)
text: "Dial call via phone"
on_release: self.send_sms()
Label:
''')
class MyInterface(BoxLayout):
pass
result:
Detele Label which is a parent of the TextInput.
If you add a widget to another widget, which isn't a layout, it will receive a default pos of [0, 0] and default size of [100, 100] (in your case, you have overwritten it to [400, 100]).
About a GUI designer - there is an experimental one, but it isn't recommended for beginners.

Categories

Resources