Page 3 of 3 FirstFirst 123
Results 21 to 26 of 26

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

  1. #21
    Join Date
    Aug 2011
    Posts
    10

    Default

    So from what your say:
    if I have:

    load_file.py:
    Code:
    x=3
    descriptor.xml:
    Code:
    <startWindow>load_file<startWindow>
    main.xml:
    Code:
    x # -> 3
    other.xml:
    Code:
    x # -> 3
    So this is a good way to share Python variables, right ? For all of them (the ones I need to be shared) to be at load_file.py ?

  2. #22

    Default

    Yes that is correct

    You can launch a window from load_file.py using the api command mc.activatewindow(14000)

    You can even import those globals to another py module, to do that place in the module on top
    Last edited by bartsidee; August 18th, 2011 at 10:12 AM.
    Have a look at my repo at www.bartsidee.nl

  3. #23
    Join Date
    Aug 2011
    Posts
    10

    Default

    Thanks !

  4. #24

    Default

    Update:
    Here an example to prevent cross imports:

    load_file.py
    Code:
    import os
    import sys
    
    # SET APP WIDE GLOBAL VARS
    CWD  = os.getcwd().replace(";","")
    X      = 5
    
    
    # Init App
    if ( __name__ == "__main__" ):
       import external
       mc.ActivateWindow(15000)
       APP = external.load()
    external.py
    Code:
    from load_file import *
    
    class load():
        def __init__(self):
           #Your Code
    Note that you want to prevent a cross import so 'load_file' imports 'external' and 'external' import 'load_file' etc. To prevent this you introduce the following code:
    if ( __name__ == "__main__" ):
    This is only executed if the file is launched directly (as main), but not on an import, thus preventing the execution of the code below it. Now you can call variable X from both the module and all the windows, but you can only call APP from your windows, but not from your module external as it is called after the main check.
    Have a look at my repo at www.bartsidee.nl

  5. #25
    Join Date
    Apr 2011
    Posts
    108

    Default

    Hi. Old thread, but I have some new questions.

    I use mc.GetApp().GetLocalConfig() for storing/retrieving some state information.

    This seems to work fine on Boxee under windows (settings are shared between windows, and shared between sessions).

    Unfortunately, when I try running the same code on BB, state seems to be only partly sharede between windows, and cleaned between sessions (invocations of the addon).

    Has anyone else been experiencing this? Does anyone know how to get BB to actually store the values... persistently?
    ---
    In theory, theory and practice are the same. In practice they're not.
    http://razorax-repo.googlecode.com/svn/trunk/boxee

  6. #26
    Join Date
    Oct 2011
    Posts
    10

    Default

    As I am working with large XML files dragged from the internet I dont want to spam the host with to many requests. For that I store the XML files, however when I try this:

    <![CDATA[mc.ShowDialogNotification('File is being generated!')
    f = open('test_variable','w')
    f.write('Exists')
    f.close()]]>

    It works fine and creates a file. But it is located in /Home/name/ as I use ubuntu 11.10. Why is it not stored in the directory where the script is being called? I would assume this would either be .boxee/UserData/apps/myapp/ or ......./myapp/skin/Boxee Skin NG/720p/main.xml

    Why is this? As when running in future prospects on different OS's it would be nice to have it in the boxee directory.

    Found a solution:

    <![CDATA[import os
    mc.ShowDialogNotification('File is being generated!')
    dir = mc.GetApp().GetAppMediaDir()
    if os.path.isdir(dir+'/storage/') == False:
    os.mkdir(dir+'/storage/')
    f = open(dir+'/storage/test_variable','w')
    f.write('Exists')
    f.close()]]>

    Not sure if this is insanely crazy though... or is this a good approach?
    Last edited by Xienixs; November 3rd, 2011 at 08:36 AM.

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
  •