Merge lp:~stolowski/phablet-extras/unity-lens-mock-new-api into lp:phablet-extras/unity-lens-mock

Proposed by Paweł Stołowski
Status: Superseded
Proposed branch: lp:~stolowski/phablet-extras/unity-lens-mock-new-api
Merge into: lp:phablet-extras/unity-lens-mock
Diff against target: 325 lines (+18/-63)
4 files modified
debian/changelog (+6/-0)
debian/control (+1/-0)
unity-lens-mock (+11/-10)
unity_lens_mock/scope.py (+0/-53)
To merge this branch: bzr merge lp:~stolowski/phablet-extras/unity-lens-mock-new-api
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
Review via email: mp+167721@code.launchpad.net

This proposal has been superseded by a proposal from 2013-06-19.

Commit message

Updated for new scopes API.

Description of the change

Updated for new scopes API.

Please have a look at https://code.launchpad.net/~stolowski/unity/phablet-new-libunity/+merge/167717 before approving.

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote :

This should depend on unity-scopes-runner, probably?

review: Needs Fixing
16. By Paweł Stołowski

Require unity-scopes-runner.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

> This should depend on unity-scopes-runner, probably?
Right, done.

Revision history for this message
Michał Sawicz (saviq) wrote :
review: Approve

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2013-02-15 17:08:02 +0000
+++ debian/changelog 2013-06-19 14:03:24 +0000
@@ -1,3 +1,9 @@
1unity-lens-mock (0.5) UNRELEASED; urgency=low
2
3 * Ported to new scopes API.
4
5 -- Pawel Stolowski <pawel.stolowski@ubuntu.com> Wed, 05 Jun 2013 16:47:30 +0200
6
1unity-lens-mock (0.4) quantal; urgency=low7unity-lens-mock (0.4) quantal; urgency=low
28
3 * Search in description, too9 * Search in description, too
410
=== modified file 'debian/control'
--- debian/control 2013-02-05 12:21:24 +0000
+++ debian/control 2013-06-19 14:03:24 +0000
@@ -15,6 +15,7 @@
15Depends: ${misc:Depends},15Depends: ${misc:Depends},
16 ${python:Depends},16 ${python:Depends},
17 gir1.2-unity-5.0,17 gir1.2-unity-5.0,
18 unity-scopes-runner (>= 7.0.3)
18Breaks: unity (<< 6.0.0)19Breaks: unity (<< 6.0.0)
19Description: Unity Lens driven by JSON files20Description: Unity Lens driven by JSON files
20 This Lens allows you to provide data via JSON files for testing and mocking Unity21 This Lens allows you to provide data via JSON files for testing and mocking Unity
2122
=== modified file 'unity-lens-mock' (properties changed: -x to +x)
--- unity-lens-mock 2013-02-01 14:41:46 +0000
+++ unity-lens-mock 2013-06-19 14:03:24 +0000
@@ -4,6 +4,8 @@
4 -- unity-lens-mock4 -- unity-lens-mock
55
6 Reads a json file and starts a Unity lens / scope pair based on data in the file. 6 Reads a json file and starts a Unity lens / scope pair based on data in the file.
7 It's meant to be run via scope-runner, e.g.
8 /usr/share/unity-scopes/scope-runner-dbus.py /usr/bin/unity-lens-mock <data file>
79
8@author: Michał Sawicz <michal.sawicz@canonical.com>10@author: Michał Sawicz <michal.sawicz@canonical.com>
9 11
@@ -22,11 +24,11 @@
2224
23from gi.repository import GObject25from gi.repository import GObject
2426
25from unity_lens_mock.lens import MockLens27from unity_lens_mock.scope import MockScope
2628
27__all__ = []29__all__ = []
28__version__ = 0.130__version__ = 0.5
29__updated__ = '2013-01-30'31__updated__ = '2013-06-05'
3032
31__program_name__ = os.path.basename(sys.argv[0])33__program_name__ = os.path.basename(sys.argv[0])
32__program_version__ = "v%s" % __version__34__program_version__ = "v%s" % __version__
@@ -36,19 +38,22 @@
3638
37DEBUG = 139DEBUG = 1
3840
39if __name__ == "__main__":41def load_scope():
40 try:42 try:
41 # setup option parser43 # setup option parser
42 parser = OptionParser(44 parser = OptionParser(
43 version=__program_version_string__,45 version=__program_version_string__,
44 usage=__program_usage_string__46 usage=__program_usage_string__
45 )47 )
46 48
47 # process options49 # process options
48 (opts, args) = parser.parse_args(sys.argv)50 (opts, args) = parser.parse_args(sys.argv)
49 51
50 if len(args) != 2:52 if len(args) < 2:
51 raise ValueError("provide a path to the json file")53 raise ValueError("provide a path to the json file")
54
55 data = json.load(open(args[-1]), encoding='utf-8')
56 return MockScope(data)
52 57
53 except Exception, e:58 except Exception, e:
54 indent = len(__program_name__) * " "59 indent = len(__program_name__) * " "
@@ -56,7 +61,3 @@
56 sys.stderr.write(indent + " for help use --help" + "\n")61 sys.stderr.write(indent + " for help use --help" + "\n")
57 raise SystemExit(2)62 raise SystemExit(2)
5863
59
60 mockLens = MockLens(json.load(open(args[1]), encoding='utf-8'))
61
62 GObject.MainLoop().run()
6364
=== renamed file 'unity_lens_mock/lens.py' => 'unity_lens_mock/scope.py'
--- unity_lens_mock/lens.py 2013-02-01 11:22:22 +0000
+++ unity_lens_mock/scope.py 2013-06-19 14:03:24 +0000
@@ -8,8 +8,6 @@
8 Unity8 Unity
9)9)
1010
11from scope import MockScope
12
13__rendererMap__ = {11__rendererMap__ = {
14 'vertical_tile': Unity.CategoryRenderer.VERTICAL_TILE12 'vertical_tile': Unity.CategoryRenderer.VERTICAL_TILE
15}13}
@@ -18,70 +16,83 @@
18 'radio': Unity.RadioOptionFilter16 'radio': Unity.RadioOptionFilter
19}17}
2018
21class MockLens(object):19__resultTypeMap__ = [
22 '''Mock Unity lens'''20 Unity.ResultType.DEFAULT
21]
22
23class MockSearch (Unity.ScopeSearchBase):
24 def __init__(self, search_context, data):
25 Unity.ScopeSearchBase.__init__(self)
26 self.__data = data
27 self.set_search_context(search_context)
28
29 def __search(self):
30 result_set = self.search_context.result_set
31 query = self.search_context.search_query.lower()
32 if query == "":
33 if (self.search_context.search_type == Unity.SearchType.DEFAULT):
34 for entry in self.__data['data']:
35 result_set.add_result(Unity.ScopeResult.create(entry[0], entry[1], entry[2], __resultTypeMap__[entry[3]], entry[4], entry[5], entry[6], entry[7], {}))
36 else:
37 for entry in self.__data['global_data']:
38 result_set.add_result(Unity.ScopeResult.create(entry[0], entry[1], entry[2], __resultTypeMap__[entry[3]], entry[4], entry[5], entry[6], entry[7], {}))
39 else:
40 if (self.search_context.search_type == Unity.SearchType.DEFAULT):
41 for entry in self.__data.get('search_data', self.__data.get('common_search_data', self.__data.get('data', ()))):
42 if (query in entry[5].lower() or query in entry[6].lower()):
43 result_set.add_result(Unity.ScopeResult.create(entry[0], entry[1], entry[2], __resultTypeMap__[entry[3]], entry[4], entry[5], entry[6], entry[7], {}))
44 else:
45 for entry in self.__data.get('global_search_data', self.__data.get('common_search_data', self.__data.get('global_data', ()))):
46 if (query in entry[5].lower() or query in entry[6].lower()):
47 result_set.add_result(Unity.ScopeResult.create(entry[0], entry[1], entry[2], __resultTypeMap__[entry[3]], entry[4], entry[5], entry[6], entry[7], {}))
48
49 def do_run(self):
50 try:
51 result_set = self.search_context.result_set
52 self.__search()
53 except Exception as error:
54 print(error)
55
56class MockScope(Unity.AbstractScope):
57 '''Mock Unity Scope'''
2358
24 __data = None59 __data = None
25 __lens = None
2660
27 def __init__(self, data):61 def __init__(self, data):
28 '''Command line options.'''62 '''Command line options.'''
63 Unity.AbstractScope.__init__(self)
29 self.__data = data64 self.__data = data
30 self.__requestName(self.__data['lens']['dbusname'])65 self.__unique_name = self.__data['scope']['dbusname']
31 66 self.__unique_path = self.__data['scope']['dbuspath']
32 self.__lens = Unity.Lens.new(self.__data['lens']['dbuspath'], self.__data['lens']['id'])67
33 68 #self.__lens.props.visible = self.__data['lens']['visible']
34 self.__lens.props.search_hint = self.__data['lens']['searchhint']69 #self.__lens.props.search_in_global = self.__data['lens']['global']
35 self.__lens.props.visible = self.__data['lens']['visible']70
36 self.__lens.props.search_in_global = self.__data['lens']['global']71 def do_get_schema(self):
3772 schema = Unity.Schema.new()
38 self.__populate_categories()73 return schema
39 self.__populate_filters()74
4075 def do_get_search_hint(self):
41 for scope in self.__data['scopes']:76 return self.__data['scope']['searchhint']
42 s = MockScope(scope)77
43 self.__lens.add_local_scope(s.getUnityScope())78 def do_get_categories(self):
44
45 self.__lens.export()
46
47 def __requestName(self, dbusname):
48 '''Connect to the session bus, exit if there is a running instance.'''
49 try:
50 session_bus_connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
51 session_bus = Gio.DBusProxy.new_sync(session_bus_connection, 0, None,
52 'org.freedesktop.DBus',
53 '/org/freedesktop/DBus',
54 'org.freedesktop.DBus', None)
55 result = session_bus.call_sync('RequestName',
56 GLib.Variant("(su)", (dbusname, 0x4)),
57 0, -1, None)
58
59 # Unpack variant response with signature "(u)". 1 means we got it.
60 result = result.unpack()[0]
61
62 if result != 1:
63 print >> sys.stderr, "Failed to own dbusname %s. Bailing out." % dbusname
64 raise SystemExit(1)
65 except:
66 raise SystemExit(1)
67
68 def __populate_categories(self):
69 '''Populate categories'''79 '''Populate categories'''
70 categories = []80 cs = Unity.CategorySet.new ()
71 for category in self.__data['lens']['categories']:81 for category in self.__data['scope']['categories']:
72 categories.append(82 cat = Unity.Category.new(
73 Unity.Category.new(83 category['id'],
74 category['name'],84 category['name'],
75 Gio.ThemedIcon.new(category['iconpath']),85 Gio.ThemedIcon.new(category['iconpath']),
76 __rendererMap__[category['renderer']]86 __rendererMap__[category['renderer']]
77 ))87 )
78 88 cs.add(cat)
79 self.__lens.props.categories = categories89 return cs
80 90
81 def __populate_filters(self):91 def do_get_filters(self):
92 fs = Unity.FilterSet.new ()
82 filters = []93 filters = []
83 try:94 try:
84 for filterData in self.__data['lens']['filters']:95 for filterData in self.__data['scope']['filters']:
85 f = __filterMap__[filterData['type']].new(96 f = __filterMap__[filterData['type']].new(
86 filterData['id'],97 filterData['id'],
87 filterData['name'],98 filterData['name'],
@@ -90,8 +101,23 @@
90 )101 )
91 for optionData in filterData['options']:102 for optionData in filterData['options']:
92 f.add_option(*optionData)103 f.add_option(*optionData)
93 filters.append(f)104 fs.add(f)
94 except KeyError:105 except KeyError:
95 pass106 pass
96
97 self.__lens.props.filters = filters
98\ No newline at end of file107\ No newline at end of file
108 return fs
109
110 def do_get_group_name(self):
111 return self.__unique_name
112
113 def do_get_unique_name(self):
114 return self.__unique_path
115
116 def do_create_search_for_query (self, search_context):
117 se = MockSearch(search_context, self.__data['scope'])
118 return se
119
120 def do_create_previewer(self, result, metadata):
121 return None #TODO
122
123 def do_activate (self, result, metadata, id):
124 return Unity.ActivationResponse.new (Unity.HandledType.NOT_HANDLED, uri)
99125
=== removed file 'unity_lens_mock/scope.py'
--- unity_lens_mock/scope.py 2013-02-15 17:08:02 +0000
+++ unity_lens_mock/scope.py 1970-01-01 00:00:00 +0000
@@ -1,53 +0,0 @@
1# encoding: utf-8
2
3from gi.repository import (
4 Unity,
5 Gio
6)
7
8class MockScope(object):
9
10 __scope = None
11 __data = None
12
13 def __init__ (self, data):
14 self.__data = data
15 self.__scope = Unity.Scope.new(self.__data['dbuspath'])
16
17 # Listen for changes and requests
18 self.__scope.connect("search_changed", self._on_search_changed)
19 self.__scope.connect("filters-changed", self._on_filters_changed)
20 self.__scope.connect("activate-uri", self._activate_uri)
21
22 def getUnityScope(self):
23 return self.__scope
24
25 def _activate_uri (self, scope, uri):
26 return Unity.ActivationResponse.new (Unity.HandledType.NOT_HANDLED, uri)
27
28 def _on_search_changed (self, scope, search, searchType, cancellable):
29 search.props.results_model.clear()
30
31 if search.props.search_string == "":
32 if (searchType == Unity.SearchType.DEFAULT):
33 for entry in self.__data['data']:
34 search.props.results_model.append(*entry)
35 else:
36 for entry in self.__data['global_data']:
37 search.props.results_model.append(*entry)
38 else:
39 if (searchType == Unity.SearchType.DEFAULT):
40 for entry in self.__data.get('search_data', self.__data.get('common_search_data', self.__data.get('data', ()))):
41 query = search.props.search_string.lower()
42 if (query in entry[4].lower() or query in entry[5].lower()):
43 search.props.results_model.append(*entry)
44 else:
45 for entry in self.__data.get('global_search_data', self.__data.get('common_search_data', self.__data.get('global_data', ()))):
46 query = search.props.search_string.lower()
47 if (query in entry[4].lower() or query in entry[5].lower()):
48 search.props.results_model.append(*entry)
49
50 search.finished()
51
52 def _on_filters_changed(self, scope):
53 pass

Subscribers

People subscribed via source and target branches