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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [5f8afee363]

Overview
Comment:Make configwin construction slightly more readable, use new pluginconf functions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5f8afee363949efe4e0642d3efa0bbc49121e553
User & Date: mario on 2015-05-04 15:22:34
Other Links: manifest | tags
Context
2015-05-04
15:23
Moved dependency() into pluginconf module, which shortens adding new installable modules to the vbox. check-in: 686c553354 user: mario tags: trunk
15:22
Make configwin construction slightly more readable, use new pluginconf functions. check-in: 5f8afee363 user: mario tags: trunk
15:21
Split pluginconf from config module. check-in: 0d6acc5aef user: mario tags: trunk
Changes

Modified channels/configwin.py from [227cef2658] to [2e64bb2fe7].

11
12
13
14
15
16
17

18
19
20
21
22
23
24
# general settings, and plugin activaiton and
# their options.


from uikit import *
import channels
from config import *

import re


# Settings window
#
# Interacts with main.* window (gtkBuilder widgets)
# and conf.* dictionary.







>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# general settings, and plugin activaiton and
# their options.


from uikit import *
import channels
from config import *
from pluginconf import all_plugin_meta
import re


# Settings window
#
# Interacts with main.* window (gtkBuilder widgets)
# and conf.* dictionary.
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137


138
139

140
141
142
143
144
145
146
147
148
149

150
151

152
153
154
155

156
157
158
159

160
161
162
163
164
165
166
167





168
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183
184
        else:
            return gtk.STOCK_NEW
        


    # iterate over channel and feature plugins
    def add_plugins(self):
        ls = {name: plugin_meta(module=name) for name in module_list()}
        #for name in module_list():
        #    if name in self.channels:
        #        ls[name] = self.channels[name].meta
        #    elif name in self.features:
        #        ls[name] = self.features[name].meta
        #    else:
        #        ls[name] = plugin_meta(module=name)
        for name,meta in sorted(ls.items(), key=lambda e: e[1]["type"]+e[1]["title"].lower(), reverse=False):
            if not name in conf.plugins:
                conf.plugins[name] = False
            add_ = self.add_channels if meta.get("type") == "channel" else self.add_features
            self.add_plg(name, meta, add_)
        pass

    # add configuration setting definitions from plugins
    plugin_text = "<span size='larger' weight='heavy'>%s</span> "\
                + "<span style='italic' foreground='slate blue'>(%s/%s)</span> "\
                + "<span weight='bold' foreground='#777777'>%s</span>\n"\
                + "<span size='smaller' stretch='ultraexpanded'>%s</span>"


    def add_plg(self, name, meta, add_):
        # add plugin load entry

        cb = gtk.CheckButton(name)
        cb.set_sensitive(not meta.get("priority") in ("core", "required", "builtin"))
        cb.get_children()[0].set_markup(self.plugin_text % (meta.get("title", name), meta.get("type", "plugin"), meta.get("category", "addon"), meta.get("version", "./."), meta.get("description", "no description")))
        doc = meta.get("doc", "").strip()
        if ver < 3:
            doc = re.sub("(?<=\S) *\n(?! *\n)", " ", doc)
        cb.set_tooltip_text(doc)
        add_( "config_plugins_"+name, cb, color=meta.get("color"), image=meta.get("png"), align=0)

        # default values are already in conf[] dict (now done in conf.add_plugin_defaults)

        for opt in meta["config"]:
            color = opt.get("color", None)

            # display checkbox
            if opt["type"] == "boolean":
                cb = gtk.CheckButton(opt["description"])
                add_( "config_"+opt["name"], cb, color=color )

            # drop down list
            elif opt["type"] == "select":
                cb = ComboBoxText(ComboBoxText.parse_options(opt["select"])) # custom uikit widget
                add_( "config_"+opt["name"], cb, opt["description"], color )

            # text entry
            else:
                add_( "config_"+opt["name"], gtk.Entry(), opt["description"], color )

        # spacer 
        add_( "filler_pl_"+name, gtk.HSeparator() )








    # Put config widgets into channels/features configwin notebooks
    def add_channels(self, id=None, w=None, label=None, color=None, image=None, align=20):
        self.plugin_options.pack_start(uikit.wrap(self.widgets, id, w, label, color, image, align))

    # Separate tab for non-channel plugins
    def add_features(self, id=None, w=None, label=None, color=None, image=None, align=20):
        self.feature_options.pack_start(uikit.wrap(self.widgets, id, w, label, color, image, align))


    # save config
    def save(self, widget):
        self.save_config(conf.__dict__, "config_")
        self.save_config(conf.plugins, "config_plugins_")
        [callback() for callback in self.hooks["config_save"]]
        conf.save(nice=1)
        self.hide()








<
<
<
<
<
<
<
|







|
|
|
|
|
>
>

|
>


|
<
<
<
|


|
>


>

|


>

|


>




|
|

|
>
>
>
>
>








>









112
113
114
115
116
117
118







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
        else:
            return gtk.STOCK_NEW
        


    # iterate over channel and feature plugins
    def add_plugins(self):







        ls = all_plugin_meta()
        for name,meta in sorted(ls.items(), key=lambda e: e[1]["type"]+e[1]["title"].lower(), reverse=False):
            if not name in conf.plugins:
                conf.plugins[name] = False
            add_ = self.add_channels if meta.get("type") == "channel" else self.add_features
            self.add_plg(name, meta, add_)
        pass

    # Description text
    plugin_text = "<span size='larger' weight='heavy'>{title}</span> "\
                + "<span style='italic' foreground='slate blue'>({type}/{category})</span> "\
                + "<span weight='bold' foreground='#777777'>{version}</span>\n"\
                + "<span size='smaller' stretch='ultraexpanded'>{description}</span>"

    # Add [x] plugin setting, and its configuration definitions, set defaults from conf.*
    def add_plg(self, name, meta, add_):

        # Plugin enable button
        cb = gtk.CheckButton(name)
        cb.set_sensitive(not meta.get("priority") in ("core", "required", "builtin"))
        cb.get_children()[0].set_markup(self.plugin_text.format(**meta))



        cb.set_tooltip_text(self._tooltip(meta))
        add_( "config_plugins_"+name, cb, color=meta.get("color"), image=meta.get("png"), align=0)

        # Default values are already in conf[] dict
        # (now done in conf.add_plugin_defaults)
        for opt in meta["config"]:
            color = opt.get("color", None)

            # display checkbox
            if opt["type"] in ("bool", "boolean"):
                cb = gtk.CheckButton(opt["description"])
                add_( "config_"+opt["name"], cb, color=color )

            # drop down list
            elif opt["type"] in ("select", "choose", "options"):
                cb = ComboBoxText(ComboBoxText.parse_options(opt["select"])) # custom uikit widget
                add_( "config_"+opt["name"], cb, opt["description"], color )

            # text entry
            else:
                add_( "config_"+opt["name"], gtk.Entry(), opt["description"], color )

        # Spacer between plugins
        add_( None, gtk.HSeparator() )

    # Reformat `doc` linebreaks for gtk.tooltip
    def _tooltip(self, meta):
        doc = meta.get("doc", "").strip()
        if ver < 3:
            doc = re.sub("(?<=\S) *\n(?! *\n)", " ", doc)
        return doc

    # Put config widgets into channels/features configwin notebooks
    def add_channels(self, id=None, w=None, label=None, color=None, image=None, align=20):
        self.plugin_options.pack_start(uikit.wrap(self.widgets, id, w, label, color, image, align))

    # Separate tab for non-channel plugins
    def add_features(self, id=None, w=None, label=None, color=None, image=None, align=20):
        self.feature_options.pack_start(uikit.wrap(self.widgets, id, w, label, color, image, align))


    # save config
    def save(self, widget):
        self.save_config(conf.__dict__, "config_")
        self.save_config(conf.plugins, "config_plugins_")
        [callback() for callback in self.hooks["config_save"]]
        conf.save(nice=1)
        self.hide()