Index: channels/__init__.py ================================================================== --- channels/__init__.py +++ channels/__init__.py @@ -13,11 +13,12 @@ # filtermusic.py, global_key.py, history.py, internet_radio.py, # itunes.py, jamendo.py, links.py, live365.py, modarchive.py, # myoggradio.py, pluginmanager2.py, radiobrowser.py, radionomy.py, # radiotray.py, search.py, shoutcast.py, somafm.py, streamedit.py, # surfmusik.py, timer.py, tunein.py, ubuntuusers.py, youtube.py, -# useragentswitcher.py, xiph.py, favicon.py, filter_bitrate.py +# useragentswitcher.py, xiph.py, favicon.py, filter_bitrate.py, +# ui_cht.py # config: - # priority: core # # GenericChannel implements the basic GUI functions and defines # the default channel data structure. It implements fallback logic Index: config.py ================================================================== --- config.py +++ config.py @@ -147,10 +147,19 @@ self.google_homepage = 0 self.windows = platform.system()=="Windows" self.pyquery = 1 self.debug = 0 + # update old setting names + def migrate(self): + # 2.1.1 + if "audio/mp3" in self.play: + self.play["audio/mpeg"] = self.play["audio/mp3"] + del self.play["audio/mp3"] + # 2.1.7 + if self.tmp == "/tmp": + self.tmp = "/tmp/streamtuner2" # Add plugin names and default config: options from each .meta def add_plugin_defaults(self, meta, name): pluginconf.add_plugin_defaults(self, self.plugins, meta, name) @@ -217,11 +226,10 @@ f.write(data.encode("utf-8")) except TypeError as e: f.write(data) # Python3 sometimes wants to write strings rather than bytes f.close() - # retrieve data from config file def load(self, name): name = name + ".json" file = self.dir + "/" + name try: @@ -237,46 +245,26 @@ f.close() return r except Exception as e: log.ERR("JSON parsing error (in "+name+")", e) - # recursive dict update def update(self, with_new_data): for key,value in with_new_data.items(): if type(value) == dict: self[key].update(value) else: self[key] = value # descends into sub-dicts instead of wiping them with subkeys - - # update old setting names - def migrate(self): - # 2.1.1 - if "audio/mp3" in self.play: - self.play["audio/mpeg"] = self.play["audio/mp3"] - del self.play["audio/mp3"] - if self.tmp == "/tmp": - self.tmp = "/tmp/streamtuner2" - - # Shortcut to `state.json` loading (currently selected categories etc.) def state(self, module=None, d={}): if not d: d.update(conf.load("state") or {}) if module: return d.get(module, {}) return d - - - # check for existing filename in directory list - def find_in_dirs(self, dirs, file): - for d in dirs: - if os.path.exists(d+"/"+file): - return d+"/"+file - # standard user account storage in ~/.netrc or less standard but contemporarily in ~/.config/netrc def netrc(self, varhosts=("shoutcast.com")): global netrc if not netrc: @@ -291,21 +279,19 @@ log.STAT("No .netrc") for server in varhosts: if server in netrc: return netrc[server] - # Use config:-style definitions for argv extraction, # such as: { arg: -D, name: debug, type: bool } def init_args(self, ap): for opt in plugin_meta(frame=1).get("config"): kwargs = pluginconf.argparse_map(opt) if kwargs: #print(kwargs) ap.add_argument(*kwargs.pop("args"), **kwargs) return ap.parse_args() - # Copy args fields into conf. dict def apply_args(self, args): self.debug = args.debug self.nothreads = args.nothreads @@ -313,12 +299,10 @@ sys.exit(1) for p_id in (args.disable or []): self.plugins[p_id] = 0 for p_id in (args.enable or []): self.plugins[p_id] = 1 - - # Simplified print wrapper: `log.err(...)` class log_printer(object): @@ -366,11 +350,9 @@ # populate global conf instance conf = ConfigDict() log.PROC("ConfigDict() initialized") # tie in pluginconf.* -pluginconf.log_WARN = log.WARN pluginconf.log_ERR = log.ERR pluginconf.module_base = "config" pluginconf.plugin_base = ["channels", "plugins"]#, conf.share+"/channels", conf.dir+"/plugins"] - Index: st2.py ================================================================== --- st2.py +++ st2.py @@ -199,13 +199,13 @@ #-- Shortcut for glade.get_widget() # Allows access to widgets as direct attributes instead of using .get_widget() # Also looks in self.channels[] for the named channel plugins def __getattr__(self, name): - if (name in self.channels): + if name in self.channels: return self.channels[name] # like self.shoutcast - elif (name in self.features): + elif name in self.features: return self.features[name] # like self.configwin else: return self.get_object(name) # or gives an error if neither exists # Custom-named widgets are available from .widgets{} not via .get_widget() @@ -214,17 +214,17 @@ return self.widgets[name] else: return gtk.Builder.get_object(self, name) - # Run a function in thread + # Run function in separate thread. + # Often used in conjunction with uikit.do() for Gtk interactions. def thread(self, target, *args, **kwargs): if conf.nothreads: return target(*args, **kwargs) thread = Thread(target=target, args=args, kwargs=kwargs) thread.start() - #self.working.append(thread) # Returns the currently selected directory/channel object (remembered position) def channel(self): return self.channels[self.current_channel]