Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26

Thread: [Info] Persistent storage and global variables in apps

  1. #11

    Default

    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!

  2. #12
    skierdb526 Guest

    Default

    So is it possible to use sqlite3 on it then? And if so how do you go about doing it?

    Thanks

  3. #13
    Join Date
    Dec 2010
    Posts
    2

    Default

    Quote Originally Posted by skierdb526 View Post
    So is it possible dle модули 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.

  4. #14
    Join Date
    Feb 2011
    Posts
    7

    Default

    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

    Code:
    space/:
    __init__.py
    
    cache = 0
    To access to this variable I need to import this module and that's all.
    Code:
    import space
    space.cache += 1

  5. #15

    Default

    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

  6. #16

    Default

    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.

  7. #17
    Join Date
    Aug 2011
    Posts
    10

    Default

    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:
    ...
    Code:
    ...
    from shared import Shared
    shared = Shared()
    mc.LogDebug("x value: "+str(shared.x)) # -> 3
    ...
    other.xml:
    Code:
    ...
    # No need for import / define 'shared' again.
    mc.LogDebug("x value: "+str(shared.x)) # -> 3
    ...
    So it's working for me, and can share variables !
    How come it is not documented ?
    Maybe something is wrong here ?

  8. #18

    Default

    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

  9. #19
    Join Date
    Aug 2011
    Posts
    10

    Default

    "as it will not work 100% in all situations":
    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 ?

  10. #20

    Default

    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

    Code:
    main.xml  - declare  variables
      |
     other.xml
    but this not

    Code:
    start.xml
      |
    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
     | 
    main.xml - declare  variables (resets to original values)

    Code wise it is much better to do it like this:

    Code:
    default.py  - declare  variables
       |
    main.xml   - other2.xml
      |
    others.xml
    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.

    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

Similar Threads

  1. Replies: 16
    Last Post: October 15th, 2011, 10:12 AM
  2. Python Variables/Declarations Persistent?
    By phikai in forum boxee applications
    Replies: 2
    Last Post: October 8th, 2010, 10:46 AM
  3. Replies: 0
    Last Post: September 12th, 2010, 04:29 PM
  4. Global variables in Boxee
    By xarragon in forum boxee applications
    Replies: 1
    Last Post: May 30th, 2010, 10:24 PM
  5. Replies: 6
    Last Post: January 24th, 2010, 10:34 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •