Persistant Persistence Problem

More
14 Nov 2012 15:20 #26574 by Miselph
Hello all,

I am trying to use persistence with gladevcp to store some values between sessions.
I included the gladevcp.persistence module and did everything it said in the instructions here

However, it doesn't work. I get the following error:
Traceback (most recent call last):
  File "/usr/bin/gladevcp", line 122, in load_handlers
    objlist = h(halcomp,builder,useropts)
  File "./panel.py", line 62, in get_handlers
    return [HandlerClass(halcomp,builder,useropts)]
  File "./panel.py", line 37, in __init__
    IniFile.vars : { 'nhits' : 0, 'a': 1.67, 'd': True ,'c' : "a string"},
NameError: global name 'IniFile' is not defined

any ideas what is going wrong?

Here is my code:
import hal
import glib
import time
import gtk
import gladevcp.persistence

debug = 1

class HandlerClass:
    '''
    class with gladevcp callback handlers
    '''


    def __init__(self, halcomp,builder,useropts):
        '''
        Handler classes are instantiated in the following state:
        - the widget tree is created, but not yet realized (no toplevel window.show() executed yet)
        - the halcomp HAL component is set up and the widhget tree's HAL pins have already been added to it
        - it is safe to add more hal pins because halcomp.ready() has not yet been called at this point.

        after all handlers are instantiated in command line and get_handlers() order, callbacks will be
        connected with connect_signals()/signal_autoconnect()

        The builder may be either of libglade or GtkBuilder type depending on the glade file format.
        '''
        
        self.halcomp = halcomp
        self.builder = builder
        self.useropts = useropts
        
        self.defaults = {
            # the following names will be saved/restored as method attributes
            # the save/restore mechanism is strongly typed - the variables type will be derived from the type of the
            # initialization value. Currently supported types are: int, float, bool, string
            IniFile.vars : { 'nhits' : 0, 'a': 1.67, 'd': True ,'c' : "a string"},
            # to save/restore all widget's state which might remotely make sense, add this:
            IniFile.widgets : widget_defaults(builder.get_objects())
            # a sensible alternative might be to retain only all HAL output widgets' state:
            # IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(), hal_only=True,output_only = True)),
        }
        self.ini_filename = __name__ + '.ini'
        self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
        
        self.ini.restore_state(self)
        


def on_destroy(self,obj,data=None):
    self.ini.save_state(self)

def get_handlers(halcomp,builder,useropts):
    '''
    this function is called by gladevcp at import time (when this module is passed with '-u <modname>.py')

    return a list of object instances whose methods should be connected as callback handlers
    any method whose name does not begin with an underscore ('_') is a  callback candidate

    the 'get_handlers' name is reserved - gladevcp expects it, so do not change
    '''
    return [HandlerClass(halcomp,builder,useropts)]

Please Log in or Create an account to join the conversation.

More
15 Nov 2012 03:39 #26594 by mhaberler
yes, you need to import IniFile like so:

from gladevcp.persistence import IniFile

see working code in configs/gladevcp/complex/complex.py

- Michael

Please Log in or Create an account to join the conversation.

Moderators: mhaberlerHansU
Time to create page: 0.103 seconds
Powered by Kunena Forum