Skip to content

Instantly share code, notes, and snippets.

@jondoesntgit
Created December 2, 2018 01:20
Show Gist options
  • Save jondoesntgit/1ce7a8facb1e46639675ec350142efd4 to your computer and use it in GitHub Desktop.
Save jondoesntgit/1ce7a8facb1e46639675ec350142efd4 to your computer and use it in GitHub Desktop.
slide_creator.py
#!/usr/bin/python
import tkFileDialog
from Tkinter import *
import sys
import re
class scrollTxtArea:
def __init__(self,root):
frame=Frame(root)
frame.pack()
self.textPad(frame)
return
def textPad(self,frame):
#add a frame and put a text area into it
textPad=Frame(frame)
self.text=Text(textPad,height=50,width=90)
# add a vertical scroll bar to the text area
scroll=Scrollbar(textPad)
self.text.configure(yscrollcommand=scroll.set)
#pack everything
self.text.pack(side=LEFT)
scroll.pack(side=RIGHT,fill=Y)
textPad.pack(side=TOP)
return
def convert(text):
paragraphs = re.split('\n\s*\n', text)
paragraphs = [paragraph.replace('\n', '\n<br>') for paragraph in paragraphs]
paragraphs = ["<section>\n%s\n</section>" % paragraph for paragraph in paragraphs]
content = "\n".join(paragraphs)
template = TEMPLATE.replace('{{ content }}', content)
return template
def main():
root = Tk()
text_area=scrollTxtArea(root)
def save():
f = tkFileDialog.asksaveasfile(mode='wb', defaultextension='.html')
input_text = text_area.text.get('1.0', 'end')
output = convert(input_text)
f.write(output)
f.close()
b = Button(root, text="Save", command=save)
b.pack()
root.title('Jonathan\'s Rapid Slide Creator')
root.mainloop()
TEMPLATE = """
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0/css/reveal.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0/css/theme/white.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
{{ content }}
</section>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0/js/reveal.js"></script>
<script>
Reveal.initialize();
</script>
</body>
</html>
"""
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment