Saturday, April 20, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 457  / 1 Year ago, wed, november 23, 2022, 8:42:34

A lot of the unity-scopes do not work in ubuntu (for example the unity-scope-gmusicbrowser), thus I've tried to "correct" them in order to get results in the dash.



Ok, I succeeded in doing this (for the file: /usr/share/unity-scopes/gmusicbrowser/unity_gmusicbrowser_deamon.py: the "corrected" code: https://gist.github.com/wa4557/d6cc4ec5354bbb95042b (is it ok to post it here, even if the main part is not from me?)). This works flawlessly, and results from gmusicbrowser are now visible in the music-dash, like I want them to show up.



But I have still one small problem: How can i implement the available filters in the scopes? I think the relevant lines in the code are (line 372 ff):



def do_get_filters(self):
'''
Adds filters
'''
fs = Unity.FilterSet.new()
#if FILTERS:
#
return fs


Unfortunately however there's everything commented out, and there is no serious documentation or something similar



Filters in the scope would let me to filter Music, so for example to select only Rock music etc.; I think the screenshot explains what I mean (it's german).



enter image description here



As you can see, there are no results even though I have a lot of music from the 00s in my collection...



EDIT: I have found a scope with a similar loader (unity-gdrive-scope) : https://gist.github.com/wa4557/e3a9cdef5806dc3c13c9, where the filters are added. Frankly I don't understand how this works. But there is definitely something in the do_get_filters function...


More From » unity

 Answers
0

I'm trying to do something similar for the clementine scope and I think I made some progress. I modified the do_get_filters in the following way




def do_get_filters(self):
'''
Adds filters
'''
fs = Unity.FilterSet.new()
if FILTERS:
fil = Unity.MultiRangeFilter.new(FILTERS[0]['id'], FILTERS[0]['name'],
Gio.ThemedIcon.new(FILTERS[0]['icon']),
FILTERS[0]['collapsed'])
fs.add(fil)

fil = Unity.RadioOptionFilter.new(FILTERS[1]['id'], FILTERS[1]['name'],
Gio.ThemedIcon.new(FILTERS[1]['icon']),
FILTERS[1]['collapsed'])
fs.add(fil)
return fs


after defining FILTERS as




f1 = {'id': 'decade',
'name': _('Decade'),
'icon': '',
'collapsed': True}

f2 = {'id': 'genre',
'name': _('Genre'),
'icon': '',
'collapsed': True}

FILTERS = [f1, f2]


At this point, you can do something like this in the do_run method of the MySearch class




def do_run(self):
'''
Adds results to the model
'''
try:
decade, genre = self.search_context.filter_state.get_filters()

if decade.get_first_active():
start_year = int( decade.get_first_active().get_property('id') )
else:
start_year = 0
if decade.get_last_active():
if decade.get_last_active().get_property('id') == '0':
end_year = 1950 + 9
else:
end_year = int( decade.get_last_active().get_property('id') ) + 9
else:
end_year = 3000



and after that


result_set = self.search_context.result_set
for i in search(self.search_context.search_query,
self.search_context.filter_state):
if not (start_year < i['year'].get_int32() < end_year) :
continue
if not 'uri' in i or not i['uri'] or i['uri'] == '':
continue
if not 'icon' in i or not i['icon'] or i['icon'] == '':
i['icon'] = DEFAULT_RESULT_ICON
if not 'mimetype' in i or not i['mimetype'] or i['mimetype'] == '':
i['mimetype'] = DEFAULT_RESULT_MIMETYPE
if not 'result_type' in i or not i['result_type'] or i['result_type'] == '':
i['result_type'] = DEFAULT_RESULT_TYPE
if not 'category' in i or not i['category'] or i['category'] == '':
i['category'] = 0
if not 'title' in i or not i['title']:
i['title'] = ''
if not 'comment' in i or not i['comment']:
i['comment'] = ''
if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
i['dnd_uri'] = i['uri']
i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
result_set.add_result(**i)
except Exception as error:
print(error)

The genre part should be similar, I have to implement it yet though.


[#27338] Thursday, November 24, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sweetrifiabl

Total Points: 422
Total Questions: 94
Total Answers: 120

Location: Bonaire
Member since Sat, Sep 24, 2022
2 Years ago
sweetrifiabl questions
Mon, Apr 4, 22, 16:02, 2 Years ago
Sat, Jul 17, 21, 01:40, 3 Years ago
Thu, Nov 18, 21, 17:36, 2 Years ago
Mon, Jan 17, 22, 19:02, 2 Years ago
;