Storing Keyboards Searches

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
How do i go bout saving searches woul i have to somehow create a cache file i have looked at 1Ch**nel and used that but i would prefer like wtf that actually saves all searches

only thing is as i am a beginner i do not understand fully how wtf was written or how to go about storing searches
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
This is where you can be creative, there's no one real way of how to do it

1Ch**nel might be storing in it's own sqlite db, where other addons might be writing to a text file.. it's up to you really, the text file might be the easiest especially if you want to keep a long history

Even take a peak at the Youtube addon, I like how it handles them on the user interface side
 

Bstrdsmkr

New member
Mar 16, 2012
763
0
0
Yeah I think the Youtube addon has the best history so far, haven't looked at how they did it though

Just to complicate things and throw another option in there, you can also store it in a set of addon settings, and set them to visible=false
Then UP the list and for example set addon_history_10 = addon_history_9, addon_history_8 = addon_history_9, all the way up to addon_history_1 set to the new query

In the end, like Eldorado said, a text file might be the simplest solution
 

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
this is what i have in my settings
Code:
def addon_history_10():
        return addon_history_9()
        visible=false        

def addon_history_9():
        return addon_history_8()
        visible=false

def addon_history_8():
        return addon_history_7()
        visible=false

def addon_history_7():
        return addon_history_6()
        visible=false

def addon_history_6():
        return addon_history_5()
        visible=false

def addon_history_5():
        return addon_history_4()
        visible=false
        
def addon_history_4():
        return addon_history_3()
        visible=false        

def addon_history_3():
        return addon_history_2()
        visible=false        

def addon_history_2():
        return addon_history_1()
        visible=false

def addon_history_1():
        return 'Search Here'
        visible=false

all it does is read all the way down to 1

Code:
def SEARCH(url):
        search_entered = settings.addon_history_10()
        keyboard = xbmc.Keyboard(search_entered, 'Search Mikeys Karaoke...XBMCHUB.COM')
        keyboard.doModal()
        if keyboard.isConfirmed():
            search_entered = keyboard.getText() .replace(' ','+')  # sometimes you need to replace spaces with + or %20#
            if search_entered == None:
                return False


what i dont understand is how it would store it because all its doing is reading all the way to 1


am i missing something
 
Last edited:

Bstrdsmkr

New member
Mar 16, 2012
763
0
0
In the example above, I was assuming you had something set in all of them. First, knock the oldest one off the list. Then move all the others down one slot which leaves the first slot empty. Fill in the first slot with the new entry. This leaves you with a rotating list of the 10 most recent searches

Code:
def SEARCH(url):
        search_entered = settings.addon_history_10()
        keyboard = xbmc.Keyboard(search_entered, 'Search Mikeys Karaoke...XBMCHUB.COM')
        keyboard.doModal()
        if keyboard.isConfirmed():
            search_entered = keyboard.getText() .replace(' ','+')  # sometimes you need to replace spaces with + or %20#
            if search_entered == None:
                return False
            addon.setSetting('history_10', addon.getSetting('history_9'))
            addon.setSetting('history_9', addon.getSetting('history_8'))
            addon.setSetting('history_8', addon.getSetting('history_7'))
            addon.setSetting('history_7', addon.getSetting('history_6'))
            addon.setSetting('history_6', addon.getSetting('history_5'))
            addon.setSetting('history_5', addon.getSetting('history_4'))
            addon.setSetting('history_4', addon.getSetting('history_3'))
            addon.setSetting('history_3', addon.getSetting('history_2'))
            addon.setSetting('history_2', addon.getSetting('history_1'))
            addon.setSetting('history_1', search_entered)
Again, not tested and I have no idea how efficient it would be, but it should demonstrate the idea of keeping the history. Now you just have to decide how to display it
 

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
this is the error im getting

Code:
rror Contents: 'str' object has no attribute 'setSetting'
16:58:29 T:7372   ERROR: Traceback (most recent call last):
                                              File "C:\Users\Mike\AppData\Roaming\XBMC\addons\plugin.video.MikeysKaraoke\default.py", line 344, in <module>
                                                SEARCH(url)
                                              File "C:\Users\Mike\AppData\Roaming\XBMC\addons\plugin.video.MikeysKaraoke\default.py", line 130, in SEARCH
                                                addon.setSetting('history_10', addon.getSetting('history_9'))
                                            AttributeError: 'str' object has no attribute 'setSetting'

in my settings i still have the same


Code:
def addon_history_10():
        return addon_history_9()
        visible=false        

def addon_history_9():
        return addon_history_8()
        visible=false
etc......


how do i tell it to know what setSetting is....


then im sure ill get error of getSetting................lol


sorry Bstrdsmkr


but learning fast

and thank you
 

Bstrdsmkr

New member
Mar 16, 2012
763
0
0
No worries, you need an entry defined in your addon's settings.xml

But it looks like you might have addon defined somewhere as a string already. You need to call getSetting and setSetting on an instance of an xbmcaddon object. For example:

Code:
myAddon = xbmcaddon.Addon(id='plugin.video.MikeysKaraoke')
setting1 = myAddon.getSetting('history_9')
Docs for xbmcaddon methods: http://mirrors.xbmc.org/docs/python-docs/xbmcaddon.html
Docs for settings.xml: http://wiki.xbmc.org/index.php?title=Addon_Settings
 

Bstrdsmkr

New member
Mar 16, 2012
763
0
0
I think the Youtube search history has it beat because it shows the clip thumbnail for the history results
 

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
im getting this error
Code:
                                              File "C:\Users\Mike\AppData\Roaming\XBMC\addons\plugin.video.MikeysKaraoke\default.py", line 5, in <module>
                                                self = ADDON.setSetting('history_10')
                                            TypeError: Required argument 'value' (pos 2) not found

this is what i have in default

Code:
ADDON = settings.addon()
[B]self = ADDON.setSetting('history_10')<-----------------------line 5[/B]
self = ADDON.setSetting('history_9')
self = ADDON.setSetting('history_8')
self = ADDON.setSetting('history_7')
self = ADDON.setSetting('history_6')
self = ADDON.setSetting('history_5')
self = ADDON.setSetting('history_4')
self = ADDON.setSetting('history_3')
self = ADDON.setSetting('history_2')
self = ADDON.setSetting('history_1')
self1 = ADDON.getSetting('history_10')
self1 = ADDON.getSetting('history_8')
self1 = ADDON.getSetting('history_6')
self1 = ADDON.getSetting('history_5')
self1 = ADDON.getSetting('history_4')
self1 = ADDON.getSetting('history_3')
self1 = ADDON.getSetting('history_3')
self1 = ADDON.getSetting('history_2')
self1 = ADDON.getSetting('history_1')

this is the search

Code:
def SEARCH(url):
        search_entered = ''
        keyboard = xbmc.Keyboard(search_entered, 'Search Mikeys Karaoke...XBMCHUB.COM')
        keyboard.doModal()
        if keyboard.isConfirmed():
            search_entered = keyboard.getText() .replace(' ','+')  # sometimes you need to replace spaces with + or %20#
            if search_entered == None:
                return False
            self.setSetting('history_10', [B]self1.getSetting('history_9'))<-------Im presuming this is pos 2[/B]
            self.setSetting('history_9', self1.getSetting('history_8'))
            self.setSetting('history_8', self1.getSetting('history_7'))
            self.setSetting('history_7', self1.getSetting('history_6'))
            self.setSetting('history_6', self1.getSetting('history_5'))
            self.setSetting('history_5', self1.getSetting('history_4'))
            self.setSetting('history_4', self1.getSetting('history_3'))
            self.setSetting('history_3', self1.getSetting('history_2'))
            self.setSetting('history_2', self1.getSetting('history_1'))
            self.setSetting('history_1', search_entered)
and this is what i have in seperate settings.py

Code:
ADDON = xbmcaddon.Addon(id='plugin.video.MikeysKaraoke')
DATA_PATH = os.path.join(xbmc.translatePath('special://profile/data/plugin.video.MikeysKaraoke'), '')


def addon():
    return ADDON

def setView():
    if ADDON.getSetting('auto-view') == 'true':
        return True
    else:
        return False

def history_10():
        return ADDON.setSetting('history_10')
        return ADDON.getSetting('history_10')        
        return history_9()
def history_9():
        return ADDON.getSetting('history_9')
        return ADDON.setSetting('history_9')        
        return history_8()
        

def history_8():
        return ADDON.setSetting('history_8')
        return ADDON.getSetting('history_8')        
        return history_7()
        

def history_7():
        return ADDON.setSetting('history_7')
        return ADDON.getSetting('history_7')        
        return history_6()
        

def history_6():
        return ADDON.setSetting('history_6')
        return ADDON.getSetting('history_6')        
        return history_5()
        

def history_5():
        return ADDON.setSetting('history_5')
        return ADDON.getSetting('history_5')        
        return history_4()
        
        
def history_4():
        return ADDON.setSetting('history_4')
        return ADDON.getSetting('history_4')        
        return history_3()
                

def history_3():
        return ADDON.setSetting('history_3')
        return ADDON.getSetting('history_3')        
        return history_2()
                

def history_2():
        return ADDON.setSetting('history_2')
        return ADDON.getSetting('history_2')        
        return history_1()
        

def history_1():
        return ADDON.setSetting('history_1')
        return ADDON.getSetting('history_1')
this is my settings.xml


Code:
<settings>
<category label="Auto-View">
	<setting id="auto-view" type="bool" label="30600" default="false"/>
	<setting id="MAIN" type="number" label="30601" default="50" enable="!eq(-1,false)"/>
	<setting id="A-Z" type="number" label="30602" default="50" enable="!eq(-2,false)"/>
	<setting id="GENRE" type="number" label="30603" default="50" enable="!eq(-3,false)"/>	
	<setting id="VIDEO" type="number" label="30604" default="53" enable="!eq(-4,false)"/>
	<setting id="DEFAULT" type="number" label="30605" default="50" enable="!eq(-4,false)"/>/>
</category>	
<category label="History_Search">
	<setting id="History" type="bool" label="30607" default="false"/>
	<setting id="history_10" type="text" label="30608" default="history_10" visible="false" enable="!eq(-1,false)"/>
	<setting id="history_9" type="text" label="30609" default="history_9" visible="false" enable="!eq(-2,false)"/>
	<setting id="history_8" type="text" label="306010" default="history_8" visible="false" enable="!eq(-3,false)"/>	
	<setting id="history_7" type="text" label="306011" default="history_7" visible="false" enable="!eq(-4,false)"/>
	<setting id="history_6" type="text" label="306012" default="history_6" visible="false" enable="!eq(-5,false)"/>
	<setting id="history_5" type="text" label="306013" default="history_5" visible="false" enable="!eq(-6,false)"/>
	<setting id="history_4" type="text" label="306014" default="history_4" visible="false" enable="!eq(-7,false)"/>
	<setting id="history_3" type="text" label="306015" default="history_3" visible="false" enable="!eq(-8,false)"/>
	<setting id="history_2" type="text" label="306016" default="history_2" visible="false" enable="!eq(-8,false)"/>
	<setting id="history_1" type="text" label="306017" default="history_1" visible="false" enable="!eq(-8,false)"/>/>
</category>
</settings>

and my string is all ok

Code:
<strings>
	    <!-- Auto View -->
    <string id="30600">auto-view</string>
    <string id="30601">MAIN</string>
    <string id="30602">A-Z</string>
    <string id="30603">GENRE</string>
    <string id="30604">VIDEO</string>
    <string id="30605">DEFAULT</string>
     
    <!--History Search -->
    <string id="30607">History</string>
    <string id="30608">history_10</string>
    <string id="30609">history_9</string>
    <string id="306010">history_8</string>
    <string id="306011">history_7</string>
    <string id="306012">history_6</string>
    <string id="306013">history_5</string>
    <string id="306014">history_4</string>
    <string id="306015">history_3</string>
    <string id="306016">history_2</string>
    <string id="306017">history_1</string>

    

</strings>


really bugging me now im supposed to be working and this has now taken over my life..........

My hats go off to you and eldorado and anarkintosh and any dev........didnt realise how much it really does take over your life when you get into a problem

and once you sort the problem your not happy with the way you plugin looks and are constantly trying to make it better


aaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!!!!!!
 
Last edited:

Bstrdsmkr

New member
Mar 16, 2012
763
0
0
No worries, it takes a bit to get used to deciphering error messages. Keep in mind that it generally shows you the function that's receiving the bad info. In this case, take a look at the docs for setSetting:
setSetting(...)
setSetting(id, value) -- Sets a script setting.

id : string - id of the setting that the module needs to access.
value : string or unicode - value of the setting.

*Note, You can use the above as keywords for arguments.

example:
- self.Settings.setSetting(id='username', value='teamxbmc')
You've only given it one argument, so the second argument (position 2) is empty. You told it what setting to set, but not what to set it to =)
Code:
self = ADDON.setSetting('history_10', 'Some Value')
 

Mikey1234

Banned
May 6, 2012
1,441
0
0
UK
Did you manage to have a look ?

All the searches store in the settings.xml all ok

But when you click on search all the 10 stored searches doesn't show ?
 

Bstrdsmkr

New member
Mar 16, 2012
763
0
0
Yeah that just gives you a way to store and retrieve them. You'll probably want to have your search function point to a list which has those, and a "New search" option. On my phone or I'd give some code