Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ ⎇ branch:  streamtuner2


Check-in [f117d88494]

Overview
Comment:New plugin: prefstore and updated .win.pack+resetprefs.cmd
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f117d8849442c085095bff979821ca833f5bf2f2
User & Date: mario on 2016-12-10 12:23:41
Other Links: manifest | tags
Context
2016-12-10
13:55
Use `module = __name__` consistently for all plugins check-in: 88aac7840a user: mario tags: trunk
12:23
New plugin: prefstore and updated .win.pack+resetprefs.cmd check-in: f117d88494 user: mario tags: trunk
12:22
Better window presence check for taskkill check-in: 41a5f3a096 user: mario tags: trunk
Changes

Added .win.pack version [a4570b6588].















>
>
>
>
>
>
>
1
2
3
4
5
6
7
# pack:
#    dev/install_python_gtk.*, dev/*.cmd,
#    dev/librezlooks.dll,
#    dev/*.ico=/usr/share/pixmaps/,
#    help/help.chm,
#    contrib/disabled/win_theme_rezlooks.py=channels/,
#    .win.pack=

Added contrib/prefstore.py version [6fbcbf2d8d].

























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# encoding: UTF-8
# api: streamtuner2
# title: Config save/import/reset
# description: Allows to store, reimport or delete all preferences
# version: 0.1
# type: feature
# category: config
# priority: optional
#
# Adds a context menu "Staton > Extensions > Config ...", which allows
# to save or restore settings, or reset them to defaults.


from config import *
from channels import *
import ahttp
from uikit import uikit
import action
import re
import json


# hooks three functions to the main extension menu
class prefstore():

    meta = plugin_meta()
    module = "prefstore"

    # Register callback
    def __init__(self, parent):
        if not parent:
            return
        self.parent = parent
        uikit.add_menu([parent.extensions], "Config save", self.save)
        uikit.add_menu([parent.extensions], "Config restore", self.restore)
        uikit.add_menu([parent.extensions], "Config delete", self.reset)

    # Save conf.
    def save(self, *w):
        fn = uikit.save_file(title="Export streamtuner2 config",fn="streatuner2-config.json", formats=[("*.json", "*.json")])
        if not fn:
            return
        data = vars(conf)
        del data["args"]
        with open(fn, "w") as f:
            f.write(json.dumps(data, indent=4, sort_keys=True))
        self.parent.status("Settings saved to " + fn)

    # Save conf.
    def restore(self, *w):
        fn = uikit.save_file(title="Import streamtuner2 config",fn="streatuner2-config.json", formats=[("*.json", "*.json")])
        if not fn:
            return
        with open(fn, "r") as f:
            conf.update(json.load(f))
        conf.save()
        self.parent.status("Restart streamtuner2 for changes to take effect.")

    # Clean conf.*
    def reset(self, *w):
        # clean up
        for key, value in vars(conf).items():
            if isinstance(value, dict):
                conf[key] = {}
            elif key in ("dir", "share", "args"):
                pass
            else:
                del conf[key]
        # add defs
        conf.defaults()
        for name in module_list():
            if not name in conf.plugins:
                conf.add_plugin_defaults(plugin_meta(module=name), name)
        # show configwin
        self.parent.status("Default settings restored. Press [save] to apply them, then restart Streamtuner2.")
        self.parent.configwin.open(None)

Added dev/resetprefs.cmd version [454d73f68d].





















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@echo off
set PrefsFolder=%APPDATA%\streamtuner2
set ST2=Streamtuner2
cls
echo  -----------------------------------------------------------------------------
echo ^|                                                                             ^|
echo ^|       _____/\\\\\\\\\\\____/\\\\\\\\\\\\\\\____/\\\\\\\\\_____              ^|
echo ^|        ___/\\\/////////\\\_\///////\\\/////___/\\\///////\\\___             ^|
echo ^|         __\//\\\______\///________\/\\\_______\///______\//\\\__            ^|
echo ^|          ___\////\\\_______________\/\\\_________________/\\\/___           ^|
echo ^|           ______\////\\\____________\/\\\______________/\\\//_____          ^|
echo ^|            _________\////\\\_________\/\\\___________/\\\//________         ^|
echo ^|             __/\\\______\//\\\________\/\\\_________/\\\/___________        ^|
echo ^|              _\///\\\\\\\\\\\/_________\/\\\________/\\\\\\\\\\\\\\\_       ^|
echo ^|               ___\///////////___________\///________\///////////////__      ^|
echo ^|                                                                             ^|
echo ^|    Streamtuner2 for Windows                               Version 2.2.0     ^|
echo ^|                                                                             ^|
echo ^|    Reset personal preferences                                               ^|
echo  ----------------------------------------------------------------------------- 
echo.

dir %PrefsFolder%\*.* 1>nul 2>&1
if %errorlevel% EQU 1 goto EmptyDir
dir %PrefsFolder%\*.* |find " 0 Bytes" 1>nul 2>&1
if %errorlevel% EQU 1 goto Proceed
:EmptyDir
echo.
echo No files have been found in your personal folder!
echo.
pause
exit

:Proceed
tasklist /fi "Imagename eq python.exe" /fi "Windowtitle eq %ST2%*" /v | find "%ST2%" >nul
if %errorlevel% EQU 0 goto ST2isRunning
tasklist /fi "Imagename eq pythonw.exe" /fi "Windowtitle eq %ST2%*" /v | find "%ST2%" >nul
if %errorlevel% EQU 0 goto ST2isRunning
tasklist /fi "Imagename eq python.exe" | find "python.exe" >nul
if %errorlevel% EQU 1 goto NotRunning
echo.
echo There's a Python process running.
echo Please make sure it's not related to %ST2%. 
echo | set /p= Do you want to proceed? [y/N]
set /P INPUT=%=%
If /I NOT '%INPUT%' == 'Y' exit
goto NotRunning


:ST2isRunning
echo.
echo %ST2% is still running!
echo Please close all instances of %ST2% before resetting your preferences!
echo.
pause
exit

:NotRunning
echo Your personal files are in %PrefsFolder%
echo.
echo This will delete all settings of %ST2% and the cached files. 
echo If you want to save your bookmarks before, then quit now and come back later...
echo.
echo.
echo | set /p=Do you want to clear all settings of %ST2% now? [y/N]
set /P INPUT=%=%
If /I NOT '%INPUT%' == 'Y' exit

del %PrefsFolder%\*.*  /F /S /Q 1>nul
rd %PrefsFolder% /S /Q 
echo.
echo.
echo Your %ST2% settings have been deleted.
pause