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

Proposed by Mark Tully
Status: Merged
Approved by: David Callé
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é Approve
PS Jenkins bot (community) continuous-integration Approve
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.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
David Callé (davidc3) wrote :

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

Revision history for this message
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.

Revision history for this message
David Callé (davidc3) wrote :

+1

Revision history for this message
David Callé (davidc3) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/unity_zotero_daemon.py'
--- src/unity_zotero_daemon.py 2013-03-19 22:32:08 +0000
+++ src/unity_zotero_daemon.py 2013-04-29 15:56:39 +0000
@@ -63,7 +63,19 @@
6363
64FILTERS = []64FILTERS = []
6565
66EXTRA_METADATA = []66META0 = {'id': 'authors',
67 'type': 's',
68 'field': Unity.SchemaFieldType.OPTIONAL}
69META1 = {'id': 'journal',
70 'type': 's',
71 'field': Unity.SchemaFieldType.OPTIONAL}
72META2 = {'id': 'abstract',
73 'type': 's',
74 'field': Unity.SchemaFieldType.OPTIONAL}
75META3 = {'id': 'fulltitle',
76 'type': 's',
77 'field': Unity.SchemaFieldType.OPTIONAL}
78EXTRA_METADATA = [META0, META1, META2, META3]
6779
6880
69def search(search, filters):81def search(search, filters):
@@ -81,7 +93,6 @@
81 extras metadata fields(variant)93 extras metadata fields(variant)
82 '''94 '''
83 results = []95 results = []
84 icon_hint = Gio.ThemedIcon.new("text-html").to_string()
8596
86 dbFile = ""97 dbFile = ""
87 for path in PATHS:98 for path in PATHS:
@@ -101,8 +112,6 @@
101 c.close()112 c.close()
102 for record in records:113 for record in records:
103 title = record[0]114 title = record[0]
104 if len(title) > 70:
105 shorttitle = title[:69] + u"…"
106 uri = record[1]115 uri = record[1]
107 journal = record[2]116 journal = record[2]
108 author1 = record[3]117 author1 = record[3]
@@ -112,69 +121,45 @@
112 author5 = record[7]121 author5 = record[7]
113 authors = "%s, %s, %s, %s, %s" % (author1, author2, author3, author4, author5)122 authors = "%s, %s, %s, %s, %s" % (author1, author2, author3, author4, author5)
114 abstract = record[8]123 abstract = record[8]
115 if len(authors) > 30:
116 authors = authors[:26] + " et al"
117 icon_hint = Gio.ThemedIcon.new('text-html').to_string()
118 if search.lower() in title.lower():124 if search.lower() in title.lower():
119 if uri:125 if uri:
120 results.append({'uri': uri,126 results.append({'uri': uri,
121 'icon': icon_hint,127 'title': title,
122 'category': 0,128 'authors': authors,
123 'title': shorttitle,129 'journal': journal,
124 'comment': '%s\n%s\n%s\n%s' % (authors, journal, title, abstract)})130 'abstract': abstract})
125 return results131 return results
126132
127133
128def preview(scope, uri):134class Preview(Unity.ResultPreviewer):
129 """Preview request handler"""135 '''
130 model = scope.props.results_model136 Creates the preview for the result
131 iteration = model.get_first_iter()137 '''
132 end_iter = model.get_last_iter()138 def do_run(self):
133 preview = None139 '''
134 while iteration != end_iter:140 Create a preview and return it
135 if model.get_value(iteration, 0) == uri:141 '''
136 title = ""142 preview = Unity.GenericPreview.new(self.result.title, '', None)
137 description = ""143 preview.props.image_source_uri = 'file://%s' % self.result.icon_hint
138 preview_info = model.get_value(iteration, 5)144 try:
139 try:145 preview.props.subtitle = self.result.metadata['authors'].get_string()
140 description += "<big><b>" + preview_info.split("\n")[2].title() + "</b></big>\n\n"146 except KeyError as e:
141 except:147 print(e)
142 print("No Title")148 description = ''
143149 try:
144 try:150 description += self.result.metadata['journal'].get_string() + '\n\n'
145 description += "<b>" + preview_info.split("\n")[1].title() + "</b>\n\n"151 except KeyError as e:
146 except:152 print(e)
147 print("No Journal")153 try:
148154 description += self.result.metadata['abstract'].get_string()
149 try:155 except KeyError as e:
150 description += "<b>" + preview_info.split("\n")[0].title() + "</b>\n\n"156 print(e)
151 except:157 preview.props.description_markup = description
152 print("No Authors")158
153159 # Add the "View" action
154 try:160 show_action = Unity.PreviewAction.new("show", _("View Article"), None)
155 description += preview_info.split("\n")[3].title()161 preview.add_action(show_action)
156 except:162 return preview
157 print("No Abstract")
158
159 # Assemble the preview
160 preview = Unity.GenericPreview.new(title, description, None)
161 preview.props.image_source_uri = "file://" + model.get_value(iteration, 1)
162
163 # Add the "View" action
164 view_action = Unity.PreviewAction.new("activate_uri", "View Article", None)
165 view_action.connect("activated", activate)
166 preview.add_action(view_action)
167
168 break
169
170 iteration = model.next(iteration)
171 if preview is None:
172 print("Couldn't find model row for requested preview uri: '%s'", uri)
173 return preview
174
175
176def activate(scope, uri):
177 return Unity.ActivationResponse(handled=Unity.HandledType.NOT_HANDLED)
178163
179164
180# Classes below this point establish communication165# Classes below this point establish communication
@@ -210,19 +195,8 @@
210 i['comment'] = ''195 i['comment'] = ''
211 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':196 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
212 i['dnd_uri'] = i['uri']197 i['dnd_uri'] = i['uri']
213 i['metadata'] = {}198 i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
214 if EXTRA_METADATA:199 result_set.add_result(**i)
215 for e in i:
216 for m in EXTRA_METADATA:
217 if m['id'] == e:
218 i['metadata'][e] = i[e]
219 i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
220 result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
221 i['category'], i['result_type'],
222 str(i['mimetype']), str(i['title']),
223 str(i['comment']), str(i['dnd_uri']),
224 i['metadata'])
225 result_set.add_result(result)
226 except Exception as error:200 except Exception as error:
227 print(error)201 print(error)
228202
@@ -278,6 +252,20 @@
278 se = MySearch(search_context)252 se = MySearch(search_context)
279 return se253 return se
280254
255 def do_activate(self, result, metadata, action):
256 '''
257 What to do when a resut is clicked
258 '''
259 return Unity.ActivationResponse(handled=Unity.HandledType.NOT_HANDLED, goto_uri=None)
260
261 def do_create_previewer(self, result, metadata):
262 '''
263 Creates a preview when a resut is right-clicked
264 '''
265 result_preview = Preview()
266 result_preview.set_scope_result(result)
267 result_preview.set_search_metadata(metadata)
268 return result_preview
281269
282def load_scope():270def load_scope():
283 return Scope()271 return Scope()
284272
=== modified file 'tests/test_zotero.py'
--- tests/test_zotero.py 2013-03-14 00:31:22 +0000
+++ tests/test_zotero.py 2013-04-29 15:56:39 +0000
@@ -38,9 +38,9 @@
38 self.scope = None38 self.scope = None
39 self.scope_module = None39 self.scope_module = None
4040
41 def test_valid_searches(self):41 def test_valid_search(self):
42 self.scope_module.PATHS = ['tests/data/mock_zotero_pass/']42 self.scope_module.PATHS = ['tests/data/mock_zotero_pass/']
43 expected_results = ['[Qualitative and quantitative analysis of fluoxetine hydrochloride by…',43 expected_results = ['[Qualitative and quantitative analysis of fluoxetine hydrochloride by 19F NMR]',
44 'http://www.ncbi.nlm.nih.gov/pubmed/22812008']44 'http://www.ncbi.nlm.nih.gov/pubmed/22812008']
45 results = []45 results = []
46 for s in ['fluoxetine']:46 for s in ['fluoxetine']:
@@ -55,6 +55,13 @@
55 result_set = self.perform_query(s)55 result_set = self.perform_query(s)
56 self.assertEqual(len(result_set.results), 0)56 self.assertEqual(len(result_set.results), 0)
5757
58 def test_activation(self):
59 result = Unity.ScopeResult()
60 result.uri = "http://www.ncbi.nlm.nih.gov/pubmed/2281200"
61 activation = self.scope.activate(result, Unity.SearchMetadata(), None)
62 self.assertEqual(activation.props.goto_uri, None)
63 self.assertEqual(activation.props.handled, Unity.HandledType.NOT_HANDLED)
64
5865
59if __name__ == '__main__':66if __name__ == '__main__':
60 unittest.main()67 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: