Editorial Workflows

Wikipedia Sidebar

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: NOTE: This workflow is designed for iPad only.

Shows Wikipedia in a non-modal sidebar, next to the editor.

If a word is selected when the workflow is invoked, it is put into the search field automatically.

Internal (Wikipedia) links are opened within the sidebar, external websites are opened in the full in-app browser.

Shared by: @olemoritz

Comments: Comment Feed (RSS)

anonymous — 03 Jun 2014
Long shot tangent: Might you be able to share the Python code needed to open a URL or the output from another action into a URL which loads in a sidebar like this?
anonymous — 15 Mar 2015
Can the sidebar's width be changed?

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
#coding: utf-8
import ui
import editor

def search_wikipedia(webview, word):
	import urllib
	s = urllib.quote(word, '')
	url = 'http://en.m.wikipedia.org/w/index.php?search=' + s
	webview.load_url(url)

class TextFieldDelegate (object):
	def textfield_should_return(self, textfield):
		textfield.end_editing()
		if textfield.text:
			search_wikipedia(textfield.superview['webview1'], textfield.text)
		return True

class WebViewDelegate (object):
	def webview_should_start_load(self, webview, url, nav_type):
		if nav_type == 'link_clicked':
			if '.wikipedia.org' not in url:
				import webbrowser
				webbrowser.open(url)
				return False
		return True

def main():
	import platform
	if not platform.machine().startswith('iPad'):
		import console 
		console.alert('iPad Required',
		              'Sorry, this workflow is designed for iPad only.', 'OK',
		              hide_cancel_button=True)
		return
	v = ui.load_view()
	v['textfield1'].delegate = TextFieldDelegate()
	v['textfield1'].clear_button_mode = 'always'
	v['webview1'].delegate = WebViewDelegate()

	sel = editor.get_selected_text()
	if sel and len(sel) < 80:
		search_wikipedia(v['webview1'], sel)
		v['textfield1'].text = sel
	else:
		v['webview1'].load_url('http://en.m.wikipedia.org')
		v['textfield1'].begin_editing()
	v.present('sidebar')

main()