I am attempting to create a standard numeric keypad that will pop up when the user touches text-inputs on the screen, so that the user can enter number values without using a mouse and keyboard. I was following this question that allows for input into one text box, but when trying to use this to enter values into multiple text inputs I could not get the program to function correctly. I am limited to just using Python, not the Kivy language so I can appreciate that it is a bit more awkward to code.
My plan was to create a class for the Bubble (inputBubble), the Bubble Buttons (inputBubbleButtons) and the text input boxes (text_inputs), with the text_inputs widget calling a function from RHS() (one of my main layouts) that should display the bubble. I can't seem a way to replicate the app.root.text_input.text += self.text from the test.kv file, so my current error is "text_inputs object has no attribute 'bubblein'" and I can't think of a way to move past this.
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.bubble import Bubble, BubbleButton
class inputBubble(Bubble):
def __init__(self, **kwargs):
super(inputBubble, self).__init__(**kwargs)
inputGrid = GridLayout(cols = 3)
keypad_numbers = ['7', '8', '9', '4', '5', '6', '1', '2', '3', 'CLR', '0', '.']
for x in keypad_numbers:
inputGrid.add_widget = inputBubbleButtons(text = x)
self.add_widget(inputGrid)
class inputBubbleButtons(BubbleButton):
def __init__(self, **kwargs):
super(inputBubbleButtons, self).__init__(**kwargs)
self.on_release = self.buttonfunctions
def buttonfunctions(self):
if self.text != 'CLR':
text_input.text += self.text
else:
text_input.text = '0'
class text_inputs(TextInput):
def __init__(self, **kwargs):
super(text_inputs, self).__init__(**kwargs)
self.id = 'text_input'
self.cursor_blink = False
self.multiline = False
self.on_focus = RHS.show_input(self)
class RHS(BoxLayout):
def __init__(self, **kwargs):
super(RHS, self).__init__(**kwargs)
nangleRow = BoxLayout(orientation = 'horizontal')
self.add_widget(nangleRow)
nangleRow.add_widget(Label(text = 'New Angle'))
nangleInput = text_inputs()
nangleRow.add_widget(nangleInput)
def show_input(self, *l):
if not hasattr(self, 'bubblein'):
bubblein = inputBubble()
self.bubblein.arrow_pos = "bottom_mid"
self.add_widget(bubblein)
class Root(GridLayout):
def __init__(self, **kwargs):
super(Root, self).__init__(**kwargs)
self.cols = 1
self.add_widget(RHS(),0)
class MainWindow(App):
def build(self):
return Root()
if __name__ == '__main__':
MainWindow().run()
I expect this to create a bubble when the focus is on nangleInput, but instead I get the error message "AttributeError: 'text_inputs' object has no attribute 'bubblein'".