Solved How can you get text while its being entered?
#1
Id like to have active search suggestions(Like the ones you have from many different websites) in the addon Im making but I cant figure out how to get the text while its being entered.

This is what I ended up trying:

Code:
import xbmc
import sys
import xbmcgui
import xbmcplugin
import threading

class getTextThread(threading.Thread):

    def __init__(self, keyboard):
        threading.Thread.__init__(self)
        self.running = 1
        self.keyboard = keyboard

    def run (self):
        while self.running == 1:
            Text = self.keyboard.getText()
            print "Text = " + Text
            xbmc.sleep(100)
    
    def closeThread(self):
        self.running = 0

addon_id = int(sys.argv[1])
paramstring = sys.argv[2]

if paramstring == '?test=true':
    keyboard = xbmc.Keyboard()
    a = getTextThread(keyboard)
    a.start()
    keyboard.doModal()
    a.closeThread()
    if keyboard.isConfirmed():
        print "Final Keyboard Output = " + keyboard.getText()
else:
    xbmcplugin.addDirectoryItem(addon_id, sys.argv[0] + '?test=true', xbmcgui.ListItem('Text Thread Test'), isFolder=False)
    xbmcplugin.endOfDirectory(addon_id)

But that just ended up spiting out the following in xbmc.log

Code:
01:36:24 T:140015205263104  NOTICE: Text =
01:36:24 T:140015205263104  NOTICE: Text =
01:36:24 T:140015205263104  NOTICE: Text =
01:36:25 T:140015205263104  NOTICE: Text =
01:36:25 T:140014910428928  NOTICE: Final Keyboard Output = asdsdadsadcdacddacacsacacsacssscsccacsccasacas
Reply
#2
Hi Fordask,

I'm not too sure on how you would be able to do this through python but using XBMC with the keyboard dialog open, if you use $INFO[Control.GetLabel(310)] then this will get whatever the user types in to XBMC. (I think it's id 310, or it may be 311)

Using Python you may be able to use it with something like:
PHP Code:
xbmc.GetInfoLabel'$INFO[Control.GetLabel(310)]' 
Or it could be:
PHP Code:
xbmc.GetInfoLabel'$INFO[Control.GetLabel(311)]' 
I'm not really sure though as my skills with Python aren't the best.
Reply
#3
Thx Toyota,
You're a lifesaver.
Code:
xbmc.getInfoLabel('Control.GetLabel(310)')
Did the job perfectly.


The test script now looks like this:
Code:
import xbmc
import sys
import xbmcgui
import xbmcplugin
import threading

class getTextThread(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.running = 1
        self.keyboard = keyboard

    def run (self):
        otext = ''
        while self.running == 1:
            ntext = xbmc.getInfoLabel('Control.GetLabel(310)')
            if ntext != otext:
                print "Text = " + ntext
                otext = ntext
            xbmc.sleep(100)
    
    def closeThread(self):
        self.running = 0

addon_id = int(sys.argv[1])
paramstring = sys.argv[2]

if paramstring == '?test=true':
    keyboard = xbmc.Keyboard()
    a = getTextThread()
    a.start()
    keyboard.doModal()
    a.closeThread()
    if keyboard.isConfirmed():
        print "Final Keyboard Output = " + keyboard.getText()
else:
    xbmcplugin.addDirectoryItem(addon_id, sys.argv[0] + '?test=true', xbmcgui.ListItem('Text Thread Test'), isFolder=False)
    xbmcplugin.endOfDirectory(addon_id)

And the output in xbmc.log looks like this:
Code:
12:09:15 T:140550237837056  NOTICE: Text = T
12:09:16 T:140550237837056  NOTICE: Text = Te
12:09:17 T:140550237837056  NOTICE: Text = Tes
12:09:17 T:140550237837056  NOTICE: Text = Test
12:09:18 T:140550237837056  NOTICE: Text = Test
12:09:19 T:140550237837056  NOTICE: Text = Test I
12:09:20 T:140550237837056  NOTICE: Text = Test In
12:09:20 T:140550237837056  NOTICE: Text = Test Inp
12:09:21 T:140550237837056  NOTICE: Text = Test Inpu
12:09:21 T:140550237837056  NOTICE: Text = Test Input
12:09:23 T:140550237837056  NOTICE: Text =
12:09:23 T:140549204985600  NOTICE: Final Keyboard Output = Test Input
Reply
#4
Hi, is your code working in Kodi helix? I've tried but I get empty string. It works for me in Eden...
I try to implement suggestions feature, but I can't get text...
Reply

Logout Mark Read Team Forum Stats Members Help
How can you get text while its being entered?0