Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A tiny Tk GUI for compiling GDoc/LaTeX, requires Rob Miller's gdoc2latex (which you can find here: https://github.com/uid/gdoc-downloader)
#!/usr/bin/env python
import Tkinter as tk
import subprocess
import os
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
self.texbasneame = "MyGdocLatexPaper"
def createWidgets(self):
self.gdocFileInput = tk.Text(self,height=1,width=50,wrap=tk.NONE)
self.gdocFileInput.grid(row=0,column=0)
self.gdocFileInput.insert('0.0','<<<YOUR GDOC http ADDRESS>>');
self.fetchBtn = tk.Button(self, text='Compile',command=self.compile)
self.fetchBtn.grid(row=0,column=1)
# a text area where the output goes
self.textW = tk.Text(self,height=20,bg='black',fg='green',wrap=tk.NONE)
self.textW.grid(row=1,columnspan=2)
def __quit(self,event):
self.quit()
def compile(self):
self.textW.delete('0.0',tk.END)
self.textW.update()
self.addLine("=========== fetch from Google Drive ===========\n")
# get file from GDrive
with open(self.texbasneame + ".tex","w") as texfile:
proc = self.runprocess(['python','gdoc2latex.py',self.gdocFileInput.get('0.0',tk.END)], stdoutf = texfile)
proc.wait() # must wait for finish, or else it deadlocks on the file handle
self.addLine("done\n")
self.addLine("=========== run bibtex ===========\n")
# run bibtex
self.runprocess(['/usr/texbin/bibtex',self.texbasneame])
self.addLine("=========== run pdflatex ===========\n")
# run pdflatex
self.runprocess(['/usr/texbin/pdflatex',self.texbasneame + '.tex'])
def runprocess(self, programAndArgs, stdoutf = subprocess.PIPE):
# simply run the shell script
proc = subprocess.Popen(programAndArgs,stdout=stdoutf,stderr=subprocess.PIPE)
if stdoutf == subprocess.PIPE:
# show the progress in the app, also good for finding out if something went wrong
for line in iter(proc.stdout.readline,''):
self.addLine(line)
return proc
def addLine(self,line):
self.textW.insert(tk.END, line)
self.textW.see(tk.END)
self.textW.update()
os.chdir(os.path.dirname(os.path.abspath(__file__))) # change to the current directory, cuz Finders runs it who-knows-where
app = Application()
app.master.title('GDoc LaTeX Compiler')
app.master.bind('<Escape>', lambda e: e.widget.quit()) #<Escape> will kill the app
app.master.resizable(tk.FALSE,tk.FALSE)
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.