I have a couple of TextInputs with a Checkbox next to them. I want to tab through them (press Tab > go to next Textinput without checking Checkbox. Enter value and press Enter > go to next Textinput and check Checkbox). This all works by setting up this definition of TextInput:
<TextInput>:
multiline: False
size_hint_x: None
padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0] #centers middle
halign: 'center'
write_tab: False
input_type: 'number'
input_filter: 'int'
Additionally i have done some things like only allow number input and centering the text, as you can see. My actual CheckBoxes and TextInputs look like this:
CheckBox:
id: gre3
on_active: root.change_gain(*args, gre3Val.text)
TextInput:
id: gre3Val
hint_text: 'Green #4 Gain [%]'
on_text_validate:
gre3.trigger_action() if self.text != '' else 0
red4Val.focus = True if self.text != '' else 0
from which i call this function:
def change_gain(self, *argv):
checkBox = self.getID(argv[0]) #this simply returns the actual id of the object
checkBoxValue = argv[1] #True/False
gainValue = argv[2] #int
if int(gainValue) >= 100:
gainValue = 100
tempObj = checkBox + 'Val'
self.ids[tempObj].text = '100'
# if color == 'red':
# print('Not yet implemented')
# #change_laser(s, )
print(checkBox)
print(checkBoxValue)
print(gainValue)
if checkBox[0:3] == 'red':
tempColor = 'Red'
elif checkBox[0:3] == 'gre':
tempColor = 'Green'
else:
tempColor = 'Blue'
tempNo = int(checkBox[3])
if checkBoxValue:
self.statusText = tempColor + ' #' + str(tempNo+1) + ' enabled ' + '(' + str(gainValue) + ' %)'
else:
self.statusText = tempColor + ' #' + str(tempNo+1) + ' disabled'
The function isnt finished yet. However, what you can see is that i limited the input to 100. Now my problem is: When im in the TextInput field which is linked to an already checked Checkbox and update the value, the checkbox gets unchecked because of the way i link the both widgets (checkboxName.trigger_action()). Is there a better way for this, so i both call the linked action of the checkbox and check it?
Aucun commentaire:
Enregistrer un commentaire