-
hvmhvm
Here is the python script I used to install everything (I have a directory 'scripts' that contains all python stuff):
<pre>
import urllib
import tarfile
from zipfile import ZipFile
import shutil
import console
import os
import editor
from os.path import expanduseros.chdir(expanduser('~/Documents/'))
url = 'http://www.reportlab.com/ftp/reportlab-2.7.tar.gz'
fname='reportlab-2.7'
sname='src/reportlab'
dname='scripts/reportlab'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.tar.gz')print 'Extracting...'
t = tarfile.open(fname+'.tar.gz')
t.extractall()if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.tar.gz')url='http://pybrary.net/pyPdf/pyPdf-1.13.tar.gz'
fname='pyPdf-1.13'
sname='pyPdf'
dname='scripts/pyPdf'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.tar.gz')print 'Extracting...'
t = tarfile.open(fname+'.tar.gz')
t.extractall()if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.tar.gz')url = 'https://github.com/html5lib/html5lib-python/archive/master.zip'
fname='html5lib-python-master'
sname='html5lib'
dname='scripts/html5lib'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.zip')print 'Extracting...'
with ZipFile(fname+'.zip', 'r') as z:
z.extractall()if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.zip')url='https://github.com/chrisglass/xhtml2pdf/archive/master.zip'
fname='xhtml2pdf-master'
sname='xhtml2pdf'
dname='scripts/xhtml2pdf'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.zip')print 'Extracting...'
with ZipFile(fname+'.zip', 'r') as z:
z.extractall()if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.zip')url='http://www.reportlab.com/ftp/pfbfer-20070710.zip'
fname='scripts/xhtml2pdf/fonts/pfbfer-20070710'
sname='pfbfer-20070710'
dname='scripts/xhtml2pdf/fonts'
if os.path.isdir(dname):
shutil.rmtree(dname)
os.mkdir(dname)
print 'Downloading '+sname+'...'
urllib.urlretrieve(url, fname+'.zip')print 'Extracting...'
dr=os.getcwd()
os.chdir(dname)
with ZipFile(sname+'.zip', 'r') as z:
z.extractall()
os.chdir(dr)print 'Cleaning up...'
os.remove(fname+'.zip')editor.reload_files()
print 'Done'</pre>
Then the workflow contains a 'Document Text' step, followed by a 'Convert Markdown to HTML' step, followed by the following 'Run Python Script' step:
<pre>
#coding: utf-8
import sys
from os.path import expanduser
if not(expanduser('~/Documents/scripts') in sys.path):
sys.path.append(expanduser('~/Documents/scripts'))
import workflow
import os.path
import editor
import xhtml2pdf.pisa as pisa
import StringIO
from urllib import unquotepisa.showLogging()
def link_callback(uri,rel):
if not(uri.startswith('/')):
return dir+'/'+unquote(uri)
return unquote(uri)action_in = workflow.get_input()
pre='<html>\n<head>\n<meta charset="utf-8"/>\n<style>\n p {font-size:12pt}\n</style>\n</head>\n\n<body>\n'
post='\n</body>\n</html>'
inp=StringIO.StringIO(pre+action_in.encode('ascii', 'xmlcharrefreplace')+post)
p = editor.get_path()
dir = os.path.split(p)[0]
f = os.path.split(p)[1]
fn= os.path.splitext(f)[0]
fl = file(dir+'/'+fn+".pdf", "w+b")
print('processing '+p)
pdf = pisa.CreatePDF(inp,fl,dir,link_callback=link_callback)
fl.close()
if pdf.err!=0:
print(pdf.err)
else:
print('done!')
</pre> -
hvmhvm
Does anyone know if there is a way to detect when a running program (scene) is in the background (e.g. Because the user has pressed the home button)? I tried it with notifications (since I thought it reacts differently when the program scheduling a notification is in the background), but unfortunately all I managed was to crash Pythonista :-(
-
hvmhvm
In the end, using the pause, and using notification('',0,'','pythonista://test?action=run') it 'works' because that crashes the app in the background (but that is not the right way to do it)...
-
hvmhvm
Nice suggestion! Unfortunately what I'm trying to do is quit the scene when the user presses the home button, but putting a sys.exit() in there doesn't stop the scene. I also tried to use a delay(0,lambda: sys.exit()), but then the scene ends after relaunching Pythonista. Since what I really want to do is allow for the launch of another program using the pythonista:// custom url, I get the error message 'Already running script' :-(
-
hvmhvm
I created my own keyboard (using screenshots of the real thing)...
-
hvmhvm
I did it using a webclip in a profile (despite the fact that <a href="http://developer.apple.com/library/ios/featuredarticles/iPhoneConfigurationProfileRef/iPhoneConfigurationProfileRef.pdf">the documentation</a> says the URL needs to start with http or https).
... <key>PayloadType</key> <string>com.apple.webClip.managed</string> <key>PayloadUUID</key> <string>70F36BDC-51AC-448E-B945-06837A970E2E</string> <key>PayloadVersion</key> <integer>1</integer> <key>URL</key> <string>pythonista://Domotica?action=run</string> ...
-