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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [708ecda3e9]

Overview
Comment:Check for string length (.q) before starting cache/server search. Wrap channel+cat switching in ukit.do().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 708ecda3e91d7b481c9a8e1a4205051674e44706
User & Date: mario on 2015-05-24 08:49:58
Other Links: manifest | tags
Context
2015-05-24
08:52
Introduce channel.fixed_size=[24,24] to constrain favicon CellRendererPixbuf. Works in conjunction to .img_resize= attribute for favicon/img converter. Set expand:False in default datamap[] for favicon cell. check-in: 39304eb90b user: mario tags: trunk
08:49
Check for string length (.q) before starting cache/server search. Wrap channel+cat switching in ukit.do(). check-in: 708ecda3e9 user: mario tags: trunk
2015-05-23
15:46
Add a "keep all" web links option. check-in: 9f8cacb1dd user: mario tags: trunk
Changes

Modified channels/search.py from [a7c64150ea] to [930ffb7c95].

1
2
3
4
5
6
7
8
9
10
11
12
# encoding: utf-8
# api: streamtuner2
# title: Search feature
# description: Provides the quick search box, and server/cache search window.
# version: 0.9
# type: feature
# category: ui
# config: -
# priority: core
#
# The search dialog implementes a "cache" and a live
# "server" search (only some plugins). It scans through




|







1
2
3
4
5
6
7
8
9
10
11
12
# encoding: utf-8
# api: streamtuner2
# title: Search feature
# description: Provides the quick search box, and server/cache search window.
# version: 1.0
# type: feature
# category: ui
# config: -
# priority: core
#
# The search dialog implementes a "cache" and a live
# "server" search (only some plugins). It scans through
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
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

    # hide dialog box again
    def cancel(self, *args):
        self.search_dialog.hide()
        return True  # stop any other gtk handlers
        

    # prepare variables
    def prepare_search(self):
        self.main.status("Searching... Stand back.")
        self.cancel()
        self.q = self.search_full.get_text().lower()





        if self.search_dialog_all.get_active():
            self.targets = self.main.channels.keys()
        else:
            self.targets = [self.current]
        self.main.bookmarks.streams["search"] = []

        
    # perform search
    def cache_search(self, *w):
        self.prepare_search()

        entries = []
        # which fields?
        fields = ["title", "playing", "homepage"]
        # traverse all channels modules
        for c in self.targets:
            cn = self.main.channels[c]
            if cn.streams:  # skip disabled plugins
                # categories
                for cat in cn.streams.keys():
                    # stations
                    for row in cn.streams[cat]:
                        # assemble text fields to compare
                        text = " ".join([str(row.get(f, " ")) for f in fields])
                        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()

        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)
                try:
                    add = cn.update_streams(cat=None, search=self.q)
                    for row in add:
                        row["genre"] = cn.meta["title"] + " " + row.get("genre", "")
                    entries += add
                except Exception as e:
                    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)














    # search text edited in text entry box
    def quicksearch_set(self, w, *eat, **up):
        
        # keep query string
        self.main.q = self.search_quick.get_text().lower()

        # get streams
        c = self.main.channel()
        rows = c.stations()
        col = c.rowmap.index("search_col") # this is the gtk.ListStore index # which contains the highlighting color

        # 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]
        (rows, q, color, flag) = extra_data








|

<


>
>
>
>
>





>



|
>


















<
<
<
<
<
<
<
<
<
<
<
<
<



|
>
















>
>
>
>
>
>
>
>
>
>
>
>
















<
<







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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93













94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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

    # hide dialog box again
    def cancel(self, *args):
        self.search_dialog.hide()
        return True  # stop any other gtk handlers
        

    # Prepare self.q and self.targets, empty streams{search} result store
    def prepare_search(self):

        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):
        if not self.prepare_search():
            return
        entries = []
        # which fields?
        fields = ["title", "playing", "homepage"]
        # traverse all channels modules
        for c in self.targets:
            cn = self.main.channels[c]
            if cn.streams:  # skip disabled plugins
                # categories
                for cat in cn.streams.keys():
                    # stations
                    for row in cn.streams[cat]:
                        # assemble text fields to compare
                        text = " ".join([str(row.get(f, " ")) for f in fields])
                        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)













        
    # live search on directory server homepages
    def server_search(self, w):
        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)
                try:
                    add = cn.update_streams(cat=None, search=self.q)
                    for row in add:
                        row["genre"] = cn.meta["title"] + " " + row.get("genre", "")
                    entries += add
                except Exception as e:
                    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
        self.main.q = self.search_quick.get_text().lower()

        # get streams
        c = self.main.channel()
        rows = c.stations()
        col = c.rowmap.index("search_col") # this is the gtk.ListStore index # which contains the highlighting color

        # 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]
        (rows, q, color, flag) = extra_data