Hello Guest, if you are reading this it means you have not registered yet. Please take a second, Click here to register, and in a few simple steps you will be able to enjoy our community and use our OpenViX support section.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Plugin Development - Settings - Help needed

  1. #1

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post

    Plugin Development - Settings - Help needed

    Hi,
    I'm nearing the end of creating my first plugin from scratch - Lots of trial and error, looking at other code to see if I can work out how the core enigma2 code is put together with standard python scripting and I've got something usable at the moment, but I have a question about making use of the 'central' settings file.

    I think I've worked out how to set settings where none exist, such as:
    config.pluginname.pluginsettingname = ConfigText("1.2a", False)

    I believe this would set the 'variable' config.pluginname.pluginsettingname to "1.2a" if it didn't already exist in the settings file, although I'm not sure what the 'False' does

    I'd like to work out how to do the following
    Setting (enforcing) a setting even if a previous setting has already been chosen (I think this might be config.pluginname.pluginsettingname.value ("1.2b") or config.pluginname.pluginsettingname = "1.2b" but these do not appear to work

    I'd also like to know how to set one setting based on another existing setting, so for example something like
    if config.pluginname.pluginsettingname1 == "1.2b":
    config.pluginname.pluginsettingname2 = "Beta Version"

    Thank you all in advance for any help

  2. #2

    Title
    Senior Member
    Join Date
    Nov 2010
    Posts
    687
    Thanks
    35
    Thanked 89 Times in 76 Posts
    hi,
    you just have to add .value:
    if config.pluginname.pluginsettingname1.value == "1.2b":
    config.pluginname.pluginsettingname2.value = "Beta Version";
    and before you exit the plugin:
    config.pluginname.save() to save the values in the settings file.
    Last edited by 2stein; 28-03-16 at 09:34.

  3. The Following User Says Thank You to 2stein For This Useful Post:

    Daviemck (31-03-16)

  4. #3

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post
    Thanks - I've had mixed success with this. For the most part I'm able to write to the config file, but on occaions there are settings which just won't take and on other occasions settings that seem to accept the complete opposite to what I set.

    For example, as this is just to demonstrate the issue here, I'm trying to write the following - config.autolanguage.audio_usecache.value = "true"
    What ends up in the settings file is config.autolanguage.audio_usecache=false

    Any ideas why this would be doing this?

  5. #4

    Title
    Senior Member
    Join Date
    Nov 2010
    Posts
    687
    Thanks
    35
    Thanked 89 Times in 76 Posts
    boolean values are true and false without quotes.

  6. The Following User Says Thank You to 2stein For This Useful Post:

    Daviemck (31-03-16)

  7. #5

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post
    When I write those in without quote, the box crash with an error globalname false is not defined - Do I have to import a specific function to use that?

  8. #6

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post
    As i was writing that I realised what I had done - I needed false to be False - I've been pulling my hair out over this. But now it works. thx

  9. #7

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post
    OK, another question - How do I remove a value from the settings file - I don't want to set the value to "", I want to remove the entry altogether.

  10. #8

    Title
    Senior Member
    Join Date
    Nov 2010
    Posts
    687
    Thanks
    35
    Thanked 89 Times in 76 Posts
    del config.xxxx.yyyy

  11. The Following User Says Thank You to 2stein For This Useful Post:

    Daviemck (31-03-16)

  12. #9

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post
    2stein - You really are the man for this. Thank you so much for your help. Everything you have given here is working well and I'm getting a much better understanding of how this all fits together.

    I seem to have another issue to try and overcome. I am trying to store a time setting in the config file, but when I write let's say 10:30 into the config, upon reading this back in I get an invalid literal for int() with base 10. Do I have to perform some treatment to the number before I write it? Float() maybe? But not sure how best to deal with this.

  13. #10

    Title
    Senior Member
    Join Date
    Nov 2010
    Posts
    687
    Thanks
    35
    Thanked 89 Times in 76 Posts
    great to hear that it is working for you... went thru the same stuff a while ago...
    if you just want to save 10:30... i would use a string: "10:30".
    if you want work with real date/time you have to use python's date/time functions.
    e.g. https://docs.python.org/2/library/time.html

  14. #11

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post
    Is there any documentation on the core enigma2 code?

    I'm having difficulty with the delete option - Can you give me any more details? I've tried del config.pluginname.pluginsetting and del config.pluginname.pluginsetting.value and many other option and through up an error.

    In terms of my time problem, I've 'declared' the setting as config.pluginx.settime = ConfigClock(default = 0) - as soon as I write to this value as a string, I get an error when reading the value back in. I've readup on Python time function, but the time setting here isn't the actual time (ie, it isn't NOW) and therefor I'm not sure how to use this for this function. I want to express the time as something like 08:30 or 23:10 and other plugins I've delved into don't seem to have this issue.

  15. #12
    birdman's Avatar
    Title
    Moderator
    Join Date
    Sep 2014
    Location
    Hitchin, UK
    Posts
    7,780
    Thanks
    237
    Thanked 1,658 Times in 1,306 Posts
    Quote Originally Posted by Daviemck View Post
    Is there any documentation on the core enigma2 code?
    Not that I've found - and I have asked.

    I'm having difficulty with the delete option - Can you give me any more details? I've tried del config.pluginname.pluginsetting and del config.pluginname.pluginsetting.value and many other option and through up an error.
    Can't you just treat a value (e.g. -1 or 0) as "no set" and proceed from there?

    In terms of my time problem, I've 'declared' the setting as config.pluginx.settime = ConfigClock(default = 0) - as soon as I write to this value as a string, I get an error when reading the value back in.
    But it's not a string - it's a Clock, which is an integer (seconds since the Epoch).

    If you want to set the default to "now", use:

    Code:
    now = localtime()
    config.pluginx.settime = ConfigClock(default = now)
    if you want to set it to, say, 08:30 today, use:

    Code:
    now = [x for x in localtime()]
    now[3] = 8
    now[4] = 30
    then = mktime(now)
    config.pluginx.settime = ConfigClock(default = then)

    I've readup on Python time function, but the time setting here isn't the actual time (ie, it isn't NOW) and therefor I'm not sure how to use this for this function.
    The simplest thing to do is to grep the source tree for existing usage.
    I found the one above in the AutoTimer code (which is in the enigma2-plugins git repository).
    MiracleBox Prem Twin HD - 2@DVB-T2 + Xtrend et8000 - 5(incl. 2 different USBs)@DVB-T2[terrestrial - UK Freeview HD, Sandy Heath] - LAN/USB-stick/HDD

  16. #13

    Title
    Member
    Join Date
    Mar 2016
    Posts
    38
    Thanks
    5
    Thanked 1 Time in 1 Post
    Quote Originally Posted by birdman View Post

    Can't you just treat a value (e.g. -1 or 0) as "no set" and proceed from there?

    But it's not a string - it's a Clock, which is an integer (seconds since the Epoch).

    If you want to set the default to "now", use:

    Code:
    now = localtime()
    config.pluginx.settime = ConfigClock(default = now)
    if you want to set it to, say, 08:30 today, use:

    Code:
    now = [x for x in localtime()]
    now[3] = 8
    now[4] = 30
    then = mktime(now)
    config.pluginx.settime = ConfigClock(default = then)
    OK, so the problem with using something such as -1 or 0 is now that i've declared it as a Clock, my plugin crashes unless I have a whole number in the value - I could reflash and start again, but I'd like to use this as a learning opportunity. So I'd really like to know how to remove the setting all together.

    I did give you code a try, but unfortunately this seem to crash at the point I attempt to write the value (I tends to be saying ... is not iterable...). I have searched through a bunch of other files but most import functions from else where and it just becomes a bit of finding a needle in a haystack.

    BTW, have you found anyway to get interactive access to perform testing inside the enigma2 environment as testing from command line, even with importing the same functions doesn't work well if at all, so at the moment it's a lot of saving, uploading, rebooting, testing and looking at error logs.

  17. #14

    Title
    Senior Member
    Join Date
    Nov 2010
    Posts
    687
    Thanks
    35
    Thanked 89 Times in 76 Posts
    if you don't use any gui classes you can just run your code on the box in a telnet session with python test.py

  18. #15
    birdman's Avatar
    Title
    Moderator
    Join Date
    Sep 2014
    Location
    Hitchin, UK
    Posts
    7,780
    Thanks
    237
    Thanked 1,658 Times in 1,306 Posts
    Quote Originally Posted by Daviemck View Post
    I did give you code a try, but unfortunately this seem to crash at the point I attempt to write the value (I tends to be saying ... is not iterable...).
    Did you import localtime from time?

    I have searched through a bunch of other files but most import functions from else where and it just becomes a bit of finding a needle in a haystack.
    For generic python code I find
    Code:
    https://docs.python.org/2/index.html
    very useful.

    BTW, have you found anyway to get interactive access to perform testing inside the enigma2 environment as testing from command lin...
    No. It actually all runs through a compiled executable (enigma2) that starts up the python bit (mytest.py) via a function call. So any interactive start-up isn't going to work. I just put lots of print statement around (tagged with my initials, so that they are easier to find amongst the other lines) and look at the log file.
    MiracleBox Prem Twin HD - 2@DVB-T2 + Xtrend et8000 - 5(incl. 2 different USBs)@DVB-T2[terrestrial - UK Freeview HD, Sandy Heath] - LAN/USB-stick/HDD

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.