Index: channels/search.py ================================================================== --- channels/search.py +++ channels/search.py @@ -1,10 +1,10 @@ # encoding: utf-8 # api: streamtuner2 # title: Search feature # description: Provides the quick search box, and server/cache search window. -# version: 0.9 +# version: 1.0 # type: feature # category: ui # config: - # priority: core # @@ -51,24 +51,30 @@ def cancel(self, *args): self.search_dialog.hide() return True # stop any other gtk handlers - # prepare variables + # Prepare self.q and self.targets, empty streams{search} result store def prepare_search(self): - self.main.status("Searching... Stand back.") self.cancel() self.q = self.search_full.get_text().lower() + if not len(self.q): + self.main.status("No search terms given.") + return False + else: + self.main.status("Searching... Stand back.") if self.search_dialog_all.get_active(): self.targets = self.main.channels.keys() else: self.targets = [self.current] self.main.bookmarks.streams["search"] = [] + return True # perform search def cache_search(self, *w): - self.prepare_search() + if not self.prepare_search(): + return entries = [] # which fields? fields = ["title", "playing", "homepage"] # traverse all channels modules for c in self.targets: @@ -83,27 +89,15 @@ if text.lower().find(self.q) >= 0: row = copy(row) row["genre"] = "%s %s" % (c or "", row.get("genre") or "") entries.append(row) uikit.do(self.show_results, entries) - - # display "search" in "bookmarks" - def show_results(self, entries): - self.main.status(1.0) - self.main.status("") - # set contents right away - self.main.channels["bookmarks"].streams["search"] = entries - # switch to bookmarks›search tab - self.main.channel_switch_by_name("bookmarks") - self.main.bookmarks.set_category("search") - # insert data and show - self.main.bookmarks.load("search") - # live search on directory server homepages def server_search(self, w): - self.prepare_search() + if not self.prepare_search(): + return entries = [] for i,cn in enumerate([self.main.channels[c] for c in self.targets]): if cn.has_search: # "search" in cn.update_streams.func_code.co_varnames: self.main.status("Server searching: " + cn.module) log.PROC("has_search:", cn.module) @@ -116,10 +110,22 @@ log.WARN("server_search: update_streams error in {}:".format(cn.module), e) continue #main.status(main, 1.0 * i / 15) uikit.do(self.show_results, entries) + # display "search" in "bookmarks" + def show_results(self, entries): + self.main.status(1.0) + self.main.status("") + # set contents right away + self.main.channels["bookmarks"].streams["search"] = entries + # switch to bookmarks›search tab + uikit.do(self.main.channel_switch_by_name, "bookmarks") + uikit.do(self.main.bookmarks.set_category, "search") + # insert data and show + self.main.bookmarks.load("search") + # search text edited in text entry box def quicksearch_set(self, w, *eat, **up): # keep query string @@ -132,12 +138,10 @@ # callback to compare (+highlight) rows m = c.gtk_list.get_model() m.foreach(self.quicksearch_treestore, (rows, self.main.q, col, col+1)) search_set = quicksearch_set - - # callback that iterates over whole gtk treelist, # looks for search string and applies TreeList color and flag if found def quicksearch_treestore(self, model, path, iter, extra_data): i = path[0]