2016-11-30, 01:40
I am having an inconsistency when adding a search by calling keyboard in the addon.
I wish that when the user closes the keyboard without doing any search, it remains in the same directory.
However when doing the search using the code:
It returns a new directory with the items I want. But if the user does not search and close the keyboard Kodi advances to a new empty directory. For "isFolder = True"
However, if you search using the code below:
It does not return the new directory with the items. But if the user does not search and close the keyboard, Kodi will remain in the same directory. For "isFolder = False"
-----------
I want the code to add a new directory with the items of the "mySearch ()" function only when a text is searched, but when the user closes the keyboard without doing the search I want it to continue in the same directory, without advancing to that empty directory.
How can I fix this problem?
Simple example:
Thank you.
I wish that when the user closes the keyboard without doing any search, it remains in the same directory.
However when doing the search using the code:
Code:
AddDir ( 'My Search - Folder True', '-', 1, 'search.jpg', True)
It returns a new directory with the items I want. But if the user does not search and close the keyboard Kodi advances to a new empty directory. For "isFolder = True"
However, if you search using the code below:
Code:
AddDir ( 'My Search - Folder False', '-', 1, 'search.jpg', False)
It does not return the new directory with the items. But if the user does not search and close the keyboard, Kodi will remain in the same directory. For "isFolder = False"
-----------
I want the code to add a new directory with the items of the "mySearch ()" function only when a text is searched, but when the user closes the keyboard without doing the search I want it to continue in the same directory, without advancing to that empty directory.
How can I fix this problem?
Simple example:
Code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import urllib, urllib2, re, xbmcplugin, xbmcgui, xbmc, xbmcaddon, HTMLParser, os
#=########################################################################################################=#
# MENU #
#=########################################################################################################=#
def CATEGORIES():
addDir('My Search - Folder False', '-', 1, 'search.jpg', False)
addDir('My Search - Folder True', '-', 1, 'search.jpg', True)
###################################################################################
#=########################################################################################################=#
# FUNCTIONS #
#=########################################################################################################=#
def mySearch():
keyb = xbmc.Keyboard('', 'XBMC Search')
keyb.doModal()
if keyb.isConfirmed() and len(keyb.getText().strip()) > 0 :
search = keyb.getText()
myParam = str(urllib.quote(search)).strip()
addDir(myParam, 'myUrl', 2, 'other.jpg', False)
def myOther():
dialog = xbmcgui.Dialog()
ok = dialog.ok('XBMC', 'Hello World')
def addDir(name, url, mode, iconimage, pasta=True, total=1):
u=sys.argv[0]+'?url='+urllib.quote_plus(url)+'&mode='+str(mode)+'&name='+urllib.quote_plus(name)
ok = True
liz = xbmcgui.ListItem(name, iconImage='DefaultFolder.png', thumbnailImage=iconimage)
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=pasta, totalItems=total)
return ok
###################################################################################
#=########################################################################################################=#
# GET PARAMS #
#=########################################################################################################=#
def get_params():
param = []
paramstring = sys.argv[2]
if len(paramstring) >= 2 :
params = sys.argv[2]
cleanedparams = params.replace('?', '')
if (params[len(params) - 1] == '/') :
params = params[0:len(params) - 2]
pairsofparams = cleanedparams.split('&')
param = {}
for i in range(len(pairsofparams)) :
splitparams = {}
splitparams = pairsofparams[i].split('=')
if (len(splitparams)) == 2:
param[splitparams[0]] = splitparams[1]
return param
params = get_params()
url = None
name = None
mode = None
iconimage = None
try:
url = urllib.unquote_plus(params['url'])
except:
pass
try:
name = urllib.unquote_plus(params['name'])
except:
pass
try:
mode = int(params['mode'])
except:
pass
try:
iconimage = urllib.unquote_plus(params['iconimage'])
except:
pass
###################################################################################
#=###########################################################################################################=#
# MODES #
#=###########################################################################################################=#
if mode == None or url == None or len(url) < 1 :
CATEGORIES()
elif mode == 1 :
mySearch()
elif mode == 2 :
myOther()
###################################################################################
xbmcplugin.endOfDirectory(int(sys.argv[1]))
Thank you.