It's important to note that Boxee has an internal python version of 2.4 and sqlite3 requires 2.5. So you can't just import and use it. Just fyi.
It's important to note that Boxee has an internal python version of 2.4 and sqlite3 requires 2.5. So you can't just import and use it. Just fyi.
Common issues w/ Boxee:
Beta Important Info | FAQ & Support Requests | Hulu Mature Content | Search
UnBoxeed app development:
Comics.com | ESPN360 | Weather
For more info, follow app development on Twitter!
So is it possible to use sqlite3 on it then? And if so how do you go about doing it?
Thanks
создание сайтов в Тюмени
I am also very interested in it? join issue
квартиры посуточно в тюмени
Last edited by sutki72; October 5th, 2012 at 11:15 AM.
What about storing variables in module?
In my app I made a module and in __init__.py I defined some variables. Now i can access to these variables across different windows/event
To access to this variable I need to import this module and that's all.Code:space/: __init__.py cache = 0
Code:import space space.cache += 1
Does anyone know if text files work on the Boxee Box for storage? Or what to do about sqlite3? Looking for a persistent storage solution...
~Kai
Website: http://kaiarmstrong.com
Twitter: @phikai
Boxee Development: Think One Zero Boxee Development - Feel free to donate here to help support it!
Twitter: @ThinkOneZero - Support/News/Updates/Statues about Think One Zero Services
I've modified an small python db program to work with the boxee api to store data. PyDbLite is a lite in memory db app made by Pierre Quentel. It is very fast almost equal to sqlite. You can use it with a nice pythonic syntax. When you make a save commit the data will be stored in the boxee settings.xml file (compressed). The advantage that it is that the data is persistent and not cleared on app upgrades or when the user reboots the box.
Confirmed working with the latest firmware 1.1.
Depending on what you store in the database, make sure you clean it if you use large amounts of data (remove non used/old records). The box has limited space and keep in mind the data is loaded in memory.
Download the module here :
http://bartsidee.nl
Some example code:
Code:# Init database, replace 'dummy' with your own id tag from PyDbLite import Base db = Base('dummy') # create new base with field names db.create('name','age','size') # create new base with field names and open if already exists (also possible mode = 'override') db.create('name','age','size', mode = 'open') # existing base db.open() # insert new record db.insert(name='homer',age=23,size=1.84) # records are dictionaries with a unique integer key __id__ # simple selection by field value records = db(name="homer") # complex selection by list comprehension res = [ r for r in db if 30 > r['age'] >= 18 and r['size'] < 2 ] # or generator expression for r in (r for r in db if r['name'] in ('homer','marge') ): # delete a record or a list of records db.delete(one_record) db.delete(list_of_records) # delete a record by its id del db[rec_id] # direct access by id record = db[rec_id] # the record such that record['__id__'] == rec_id # create an index on a field db.create_index('age') # update db.update(record,age=24) # add and drop fields db.add_field('new_field',default=0) db.drop_field('name') # save changes to boxee storage db.commit()
If you want to store objects, lists or dicts in the database just use pickle:
Code:try: import cPickle except: import pickle as cPickle #example dict dict = {'test1':True, ''test2':'new', 'platform':'boxee'} #Convert dict to pickled string string = cPickle.dumps(dict, cPickle.HIGHEST_PROTOCOL) #Convert pickled string back to dict dict = cPickle.loads(string)
Last edited by bartsidee; May 12th, 2011 at 07:58 AM.
Maybe this is old thread, and at the newer versions it's different ?
My app has:
(It's with classes, but the same is true for regular Python files I think)
shared.py # A Python file, located at the app's folder.
Code:class Shared: def __init__(self): self.x = 3
main.xml:
...
other.xml:Code:... from shared import Shared shared = Shared() mc.LogDebug("x value: "+str(shared.x)) # -> 3 ...
So it's working for me, and can share variables !Code:... # No need for import / define 'shared' again. mc.LogDebug("x value: "+str(shared.x)) # -> 3 ...
How come it is not documented ?
Maybe something is wrong here ?
This topic is more about persistant storage so it would be better to open a seperate thread for it. You can indeed share variables, but the way you have proposed is not recommended as it will not work 100% in all situations. It is better actually to launch an app with a python file instead of a skin file and declare all you variables there. Those will then be accessable from all windows and dialogs.
Have a look at my repo at www.bartsidee.nl
Why ? I need some Python variables, not only strings, to be shared among the XML files. And my way is seems to be working. Why will it not work ?"as it will not work 100% in all situations":
I'm not saying you can't use the variables, I'm saying it is not recommended to have a setup like you have. Although all windows share the same global space, not all windows are declared right away or exist the entire app length. Which makes them vulnerable to be deleted by the python garage collector.
Also as you are declaring your variable in one window, it will only exist as global as long as it as has been declared.
So this might will work
but this notCode:main.xml - declare variables | other.xml
Or for example when you are going to use window states there is the possibility that to global var is reset as the window is called again.Code:start.xml | main.xml - declare variables | other.xml
Code:start.xml | main.xml - declare variables | other.xml | main.xml - declare variables (resets to original values)
Code wise it is much better to do it like this:
This way you have a nice separation between gui and back-end coding and you have declared you global vars at start-up in the python environment which guarantees they are available no matter which windows configuration you are going to use. Default.py will also only be called on the launch of the app.Code:default.py - declare variables | main.xml - other2.xml | others.xml
It is to bad there are no examples of this on the wiki, I generally can say starting your app with a skin file (although speedy for very simple apps) is a bad way of coding.
for some examples see also:
http://github.com/bartsidee
Have a look at my repo at www.bartsidee.nl
Bookmarks