Index: st2.py ================================================================== --- st2.py +++ st2.py @@ -70,11 +70,11 @@ # object containers widgets = {} # non-glade widgets (any manually instantiated ones) channels = {} # channel modules features = {} # non-channel plugins - working = [] # threads + #working = [] # threads hooks = { "play": [], # observers queue here "record": [], "init": [], "quit": [action.cleanup_tmp_files], @@ -212,10 +212,19 @@ if name in self.widgets: return self.widgets[name] else: return gtk.Builder.get_object(self, name) + + # Run a function in thread + 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] @@ -262,11 +271,11 @@ # Play button def on_play_clicked(self, widget, event=None, *args): self.status("Starting player...") channel = self.channel() - pixstore = [channel._ls, channel._pix_entry, channel.rowno()] + pixstore = [channel.ls, channel.pix_entry, channel.rowno()] row = channel.play() self.status("") [callback(row, pixstore=pixstore) for callback in self.hooks["play"]] # Recording: invoke streamripper for current stream URL @@ -289,24 +298,16 @@ action.browser(url) # Reload stream list in current channel-category def on_reload_clicked(self, widget=None, reload=1): log.UI("on_reload_clicked()", "reload=", reload, "current_channel=", self.current_channel, "c=", self.channels[self.current_channel], "cat=", self.channel().current) - category = self.channel().current - self.thread( - #@TODO: should get a wrapper, for HTTP errors, and optionalize bookamrks - lambda: ( self.channel().load(category,reload), reload and self.bookmarks.heuristic_update(self.current_channel,category) ) - ) - - # Thread a function, add to worker pool (for utilizing stop button) - 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) - + self.thread(self._on_reload, self.channel(), reload) + def _on_reload(self, channel, reload): + self.channel().load(channel.current, force=reload) + if reload: + try: self.bookmarks.heuristic_update(self.current_channel, channel.category) + except: pass # Click in category list def on_category_clicked(self, widget, event, *more): category = self.channel().currentcat() log.UI("on_category_clicked", category, self.current_channel) @@ -320,17 +321,17 @@ # refresh bookmarks tab self.bookmarks.load(self.bookmarks.default) # Reload category tree def update_categories(self, widget): - Thread(target=self.channel().reload_categories).start() + self.thread(self.channel().reload_categories) # Menu invocation: refresh favicons for all stations in current streams category def update_favicons(self, widget): if "favicon" in self.features: ch = self.channel() - self.features["favicon"].update_all(entries=ch.stations(), pixstore=[ch._ls, ch._pix_entry, None]) + self.features["favicon"].update_all(entries=ch.stations(), pixstore=[ch.ls, ch.pix_entry, None]) # Save stream to file (.m3u) def save_as(self, widget): row = self.row() default_fn = row["title"] + ".m3u"