Adding a button with editbox
#1
Hi all,
I am using kodi android application. I am trying to add a button on the home screen with editbox for username and password fields. Means when user enters the correct username and password, the kodi app has to close.
For this I have used the Home.xml to add a button and used the ActivateWindow inbuilt function. With this I have the gui containing editbox and submit button. Now I want to write a code for the button press which will take a input from the two editboxes and compares it with available buffers. And Do the appropriate operation.
But I am not getting the location where to write the code in c++ and how to access the contents from the editboxes.
OR Is their any way to access the python code, if yes please tell me how? Please someone help me with this?
Reply
#2
yes, you could create a python addon that handles this.

if you add this to the submit button to run your addon:
Code:
<onclick>RunScript(script.foo)</onclick>

in your python code, you can retrieve the values of the edit buttons like this:
Code:
user = xbmcgui.Window(1234).getControl(501).getText()
where 1234 is the id of the dialog you've created, and 501 is the id of the edit button.


^untested, but it should get you started :-)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
But when I use user = xbmcgui.Window(1234).getControl(501).getText(), the app is crashing.
I want to know the method by which I can read the input from the editbox. Please help me with this
Reply
#4
ah, two things:
- if the id of your window is 1234, you need to add 10000 to it in python, so it will be 11234
- split the command in two, to prevent the crash

Code:
window = xbmcgui.Window(11234)
user = window.getControl(501).getLabel()
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
Thanks for your reply. Even after splitting the command into two, the app is crashing.
Is their any way to avoid the app crash?
Reply
#6
hey can you post the error if you can please?
Reply
#7
please post both your python code and your xml code.
i'll try to reproduce it if i can.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#8
Thanks, I have solved the problem.
I am using the control edit box for password field.
With above method,How to accept the data in * form for password filed instead of text?
Reply
#9
that can't be done in xml as far as i'm aware.
if you require such functionality, you should create the dialog using the python WindowXMLDialog class.
http://mirrors.xbmc.org/docs/python-docs...wXMLDialog
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#10
I have used the xbmcgui.ControlEdit with isPassword=1. But it is not reading the data inserted into the editbox. So I have used above method with xml file, instead of below method and it is reading input inserted into the editbox.
Please tell me the changes in the following code if any.

import xbmc
import xbmcaddon
import xbmcgui

addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')

ACTION_PREVIOUS_MENU = 10

class MyClass(xbmcgui.WindowDialog):
def __init__(self):
self.strActionInfo = xbmcgui.ControlLabel(100, 120, 200, 200, '', 'font13', '0xFFFF00FF')
self.addControl(self.strActionInfo)
self.strActionInfo.setLabel('Push BACK to quit')
self.name = xbmcgui.ControlEdit(530, 320, 400, 120, '', 'font13', '0xDD171717')
self.addControl(self.name)
self.pswd = xbmcgui.ControlEdit(530, 320, 400, 120, '', font='font16', textColor='0xDD171717', isPassword=1)
self.addControl(self.pswd)
self.button0 = xbmcgui.ControlButton(350, 500, 80, 30, "HELLO")
self.addControl(self.button0)
self.setFocus(self.button0)
self.setFocus(self.name)
self.name.setPosition(600, 320)
self.name.setWidth(400)
self.name_txt = ""
self.pswd_txt = ""

def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()

def onControl(self, control):
if control == self.button0:
self.name_txt = self.name.getText()
self.pswd_txt = self.pswd.getText()
#self.message(self.name)

def message(self, message):
dialog = xbmcgui.Dialog()
dialog.ok(" My message title", message)

mydisplay = MyClass()
mydisplay .doModal()
del mydisplay
Reply
#11
i've tested your code and it works ok here.
perhaps your indenting is messed up?
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#12
How did you tested my code? When I run the above code, I have the GUI but I will not be able to enter any text inside the textbox. Can you please tell me the changes in this code so that it should read input from user?
Reply
#13
i didn't modify the code. just click on a textbox and the keyboard dialog pops up.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply

Logout Mark Read Team Forum Stats Members Help
Adding a button with editbox0