Owners

What are owners ?

Every option has an owner, that will indicate who changed the option’s value last. The default owner of every option is “default”, and means that the value is the default one.

1
2
3
4
5
6
7
8
    opt = BoolOption('opt', '', default= False)
    rootod = OptionDescription('root', '', [opt])
    cfg = Config(rootod)

    print(cfg.option('opt').value.get())
    # False
    print(cfg.option('opt').owner.get())
    # default 

As soon as you change the option’s value, the owner will change :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def new_owner():
    opt = BoolOption('opt', '', default= False)
    rootod = OptionDescription('root', '', [opt])
    cfg = Config(rootod)

    print(cfg.option('opt').owner.get())    
    # default
    cfg.option('opt').value.set(True)
    print(cfg.option('opt').owner.get())
    # user

If you use a “reset” instruction to get back to the default value, the owner will get back to “default” as well.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def back_to_default_owner():
    opt = BoolOption('opt', '', default= False)
    rootod = OptionDescription('root', '', [opt])
    cfg = Config(rootod)

    print(cfg.option('opt').owner.get())    
    # default
    cfg.option('opt').value.set(True)
    print(cfg.option('opt').owner.get())
    # user
    cfg.option('opt').value.reset()
    print(cfg.option('opt').owner.get())
    # default

You can also set directly the option’s owner :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def set_option_owner():
    opt = BoolOption('opt', '', default= False)
    rootod = OptionDescription('root', '', [opt])
    cfg = Config(rootod)

    print(cfg.option('opt').owner.get())    
    # default
    cfg.option('opt').value.set(True)
    print(cfg.option('opt').owner.get())
    # user
    cfg.option('opt').owner.set('owner')
    print(cfg.option('opt').owner.get())
    # owner

Note

This will work only if the current owner isn’t “default”.

Config owners

Config objects also have owners :

1
2
3
4
5
6
7
def config_owner():
    opt = BoolOption('opt', '', default= False)
    rootod = OptionDescription('root', '', [opt])
    cfg = Config(rootod)

    print(cfg.owner.get())
    # user

The default user for Configs is “user”. And you can set the owner :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def set_owner():
    opt = BoolOption('opt', '', default= False)
    rootod = OptionDescription('root', '', [opt])
    cfg = Config(rootod)

    print(cfg.option('opt').owner.get())    
    # default
    cfg.owner.set('owner')
    print(cfg.owner.get())
    # owner

But owners don’t have the same function with Configs : the owner you set will be the owner that all the options in the config will get when their value is changed. This explains why earlier, the owner became “user” when changing the option’s value.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def set_owner2():
    opt = BoolOption('opt', '', default= False)
    rootod = OptionDescription('root', '', [opt])
    cfg = Config(rootod)

    print(cfg.option('opt').owner.get())    
    # default
    cfg.owner.set('owner')
    print(cfg.owner.get())
    # owner
    cfg.option('opt').value.set(True)
    print(cfg.option('opt').owner.get())
    # owner

Note

  • When changing the owner with a “set” instruction, the value you specify has to be a string.
  • If you use callbacks, the owner will still be “default” for as long as you don’t set the value.