Merge lp:~submarine/unity-scope-zotero/zotero-previews into lp:unity-scope-zotero

Proposed by Mark Tully on 2013-04-29
Status: Merged
Approved by: David Callé on 2013-05-02
Approved revision: 18
Merged at revision: 18
Proposed branch: lp:~submarine/unity-scope-zotero/zotero-previews
Merge into: lp:unity-scope-zotero
Diff against target: 217 lines (+71/-76)
2 files modified
src/unity_zotero_daemon.py (+62/-74)
tests/test_zotero.py (+9/-2)
To merge this branch: bzr merge lp:~submarine/unity-scope-zotero/zotero-previews
Reviewer Review Type Date Requested Status
David Callé 2013-04-29 Approve on 2013-05-02
PS Jenkins bot (community) continuous-integration Approve on 2013-04-29
Review via email: mp+161449@code.launchpad.net

Commit message

Added previews

Description of the change

Updates Previews from old API to new API
Adds some metadata fields to aid with previews.

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
David Callé (davidc3) wrote :

I'm having some trouble with Zotero here, would you mind posting a screenshot?

Mark Tully (markjtully) wrote :

It appears that there have been some changes to the zotero database in version 4 (the scope was developed using zotero 3) whcih leaves the uri blank. The sql query will need to be adjusted to take this into account. That may be why you're not getting results. I've filed bug #1174987 for this issue.

A screenshot of the previews is available at http://ubuntuone.com/6c1RKAGhGjF4GUilGA5bwS There is no icon currently, but either text-x-generic or x-office-document might be suitable.

David Callé (davidc3) wrote :

+1

David Callé (davidc3) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity_zotero_daemon.py'
2--- src/unity_zotero_daemon.py 2013-03-19 22:32:08 +0000
3+++ src/unity_zotero_daemon.py 2013-04-29 15:56:39 +0000
4@@ -63,7 +63,19 @@
5
6 FILTERS = []
7
8-EXTRA_METADATA = []
9+META0 = {'id': 'authors',
10+ 'type': 's',
11+ 'field': Unity.SchemaFieldType.OPTIONAL}
12+META1 = {'id': 'journal',
13+ 'type': 's',
14+ 'field': Unity.SchemaFieldType.OPTIONAL}
15+META2 = {'id': 'abstract',
16+ 'type': 's',
17+ 'field': Unity.SchemaFieldType.OPTIONAL}
18+META3 = {'id': 'fulltitle',
19+ 'type': 's',
20+ 'field': Unity.SchemaFieldType.OPTIONAL}
21+EXTRA_METADATA = [META0, META1, META2, META3]
22
23
24 def search(search, filters):
25@@ -81,7 +93,6 @@
26 extras metadata fields(variant)
27 '''
28 results = []
29- icon_hint = Gio.ThemedIcon.new("text-html").to_string()
30
31 dbFile = ""
32 for path in PATHS:
33@@ -101,8 +112,6 @@
34 c.close()
35 for record in records:
36 title = record[0]
37- if len(title) > 70:
38- shorttitle = title[:69] + u"…"
39 uri = record[1]
40 journal = record[2]
41 author1 = record[3]
42@@ -112,69 +121,45 @@
43 author5 = record[7]
44 authors = "%s, %s, %s, %s, %s" % (author1, author2, author3, author4, author5)
45 abstract = record[8]
46- if len(authors) > 30:
47- authors = authors[:26] + " et al"
48- icon_hint = Gio.ThemedIcon.new('text-html').to_string()
49 if search.lower() in title.lower():
50 if uri:
51 results.append({'uri': uri,
52- 'icon': icon_hint,
53- 'category': 0,
54- 'title': shorttitle,
55- 'comment': '%s\n%s\n%s\n%s' % (authors, journal, title, abstract)})
56+ 'title': title,
57+ 'authors': authors,
58+ 'journal': journal,
59+ 'abstract': abstract})
60 return results
61
62
63-def preview(scope, uri):
64- """Preview request handler"""
65- model = scope.props.results_model
66- iteration = model.get_first_iter()
67- end_iter = model.get_last_iter()
68- preview = None
69- while iteration != end_iter:
70- if model.get_value(iteration, 0) == uri:
71- title = ""
72- description = ""
73- preview_info = model.get_value(iteration, 5)
74- try:
75- description += "<big><b>" + preview_info.split("\n")[2].title() + "</b></big>\n\n"
76- except:
77- print("No Title")
78-
79- try:
80- description += "<b>" + preview_info.split("\n")[1].title() + "</b>\n\n"
81- except:
82- print("No Journal")
83-
84- try:
85- description += "<b>" + preview_info.split("\n")[0].title() + "</b>\n\n"
86- except:
87- print("No Authors")
88-
89- try:
90- description += preview_info.split("\n")[3].title()
91- except:
92- print("No Abstract")
93-
94- # Assemble the preview
95- preview = Unity.GenericPreview.new(title, description, None)
96- preview.props.image_source_uri = "file://" + model.get_value(iteration, 1)
97-
98- # Add the "View" action
99- view_action = Unity.PreviewAction.new("activate_uri", "View Article", None)
100- view_action.connect("activated", activate)
101- preview.add_action(view_action)
102-
103- break
104-
105- iteration = model.next(iteration)
106- if preview is None:
107- print("Couldn't find model row for requested preview uri: '%s'", uri)
108- return preview
109-
110-
111-def activate(scope, uri):
112- return Unity.ActivationResponse(handled=Unity.HandledType.NOT_HANDLED)
113+class Preview(Unity.ResultPreviewer):
114+ '''
115+ Creates the preview for the result
116+ '''
117+ def do_run(self):
118+ '''
119+ Create a preview and return it
120+ '''
121+ preview = Unity.GenericPreview.new(self.result.title, '', None)
122+ preview.props.image_source_uri = 'file://%s' % self.result.icon_hint
123+ try:
124+ preview.props.subtitle = self.result.metadata['authors'].get_string()
125+ except KeyError as e:
126+ print(e)
127+ description = ''
128+ try:
129+ description += self.result.metadata['journal'].get_string() + '\n\n'
130+ except KeyError as e:
131+ print(e)
132+ try:
133+ description += self.result.metadata['abstract'].get_string()
134+ except KeyError as e:
135+ print(e)
136+ preview.props.description_markup = description
137+
138+ # Add the "View" action
139+ show_action = Unity.PreviewAction.new("show", _("View Article"), None)
140+ preview.add_action(show_action)
141+ return preview
142
143
144 # Classes below this point establish communication
145@@ -210,19 +195,8 @@
146 i['comment'] = ''
147 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
148 i['dnd_uri'] = i['uri']
149- i['metadata'] = {}
150- if EXTRA_METADATA:
151- for e in i:
152- for m in EXTRA_METADATA:
153- if m['id'] == e:
154- i['metadata'][e] = i[e]
155- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
156- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
157- i['category'], i['result_type'],
158- str(i['mimetype']), str(i['title']),
159- str(i['comment']), str(i['dnd_uri']),
160- i['metadata'])
161- result_set.add_result(result)
162+ i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
163+ result_set.add_result(**i)
164 except Exception as error:
165 print(error)
166
167@@ -278,6 +252,20 @@
168 se = MySearch(search_context)
169 return se
170
171+ def do_activate(self, result, metadata, action):
172+ '''
173+ What to do when a resut is clicked
174+ '''
175+ return Unity.ActivationResponse(handled=Unity.HandledType.NOT_HANDLED, goto_uri=None)
176+
177+ def do_create_previewer(self, result, metadata):
178+ '''
179+ Creates a preview when a resut is right-clicked
180+ '''
181+ result_preview = Preview()
182+ result_preview.set_scope_result(result)
183+ result_preview.set_search_metadata(metadata)
184+ return result_preview
185
186 def load_scope():
187 return Scope()
188
189=== modified file 'tests/test_zotero.py'
190--- tests/test_zotero.py 2013-03-14 00:31:22 +0000
191+++ tests/test_zotero.py 2013-04-29 15:56:39 +0000
192@@ -38,9 +38,9 @@
193 self.scope = None
194 self.scope_module = None
195
196- def test_valid_searches(self):
197+ def test_valid_search(self):
198 self.scope_module.PATHS = ['tests/data/mock_zotero_pass/']
199- expected_results = ['[Qualitative and quantitative analysis of fluoxetine hydrochloride by…',
200+ expected_results = ['[Qualitative and quantitative analysis of fluoxetine hydrochloride by 19F NMR]',
201 'http://www.ncbi.nlm.nih.gov/pubmed/22812008']
202 results = []
203 for s in ['fluoxetine']:
204@@ -55,6 +55,13 @@
205 result_set = self.perform_query(s)
206 self.assertEqual(len(result_set.results), 0)
207
208+ def test_activation(self):
209+ result = Unity.ScopeResult()
210+ result.uri = "http://www.ncbi.nlm.nih.gov/pubmed/2281200"
211+ activation = self.scope.activate(result, Unity.SearchMetadata(), None)
212+ self.assertEqual(activation.props.goto_uri, None)
213+ self.assertEqual(activation.props.handled, Unity.HandledType.NOT_HANDLED)
214+
215
216 if __name__ == '__main__':
217 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: