1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/bin/env python3
- from tkinter import *
- from tkinter import ttk
- #
- # A class for .gmi markup
- #
- class GmiText(Text):
- def __init__(self, *args):
- Text.__init__(self, *args)
- self.tag_configure('h1', font='serif 24 bold', wrap='word')
- self.tag_configure('h2', font='serif 20 bold', wrap='word')
- self.tag_configure('h3', font='serif 16 bold', wrap='word')
- self.tag_configure('list', font='sans 12', wrap='word', lmargin1=30, lmargin2=30, rmargin=30)
- self.tag_configure('link', font='sans 12 bold', foreground='blue', wrap='word')
- self.tag_configure('block', font='serif 12 bold', wrap='word', lmargin1=50, lmargin2=50, rmargin=50)
- self.tag_configure('preform', font='mono 12', wrap='none')
- #
- # Main window
- #
- root = Tk()
- root.title("🐇️ Bunny -- a gemini browser")
- root.columnconfigure(0, weight=1)
- root.rowconfigure(0, weight=1)
- mainframe = ttk.Frame(root, padding="0 10")
- mainframe.grid(column=0, row=0, sticky=(N, S, E, W))
- #
- # Buttons and address bar
- #
- ttk.Button(mainframe, text='⬅️').grid(column=0, row=0, sticky=(N, W))
- ttk.Button(mainframe, text='⬆️').grid(column=1, row=0, sticky=(N, W))
- ttk.Button(mainframe, text='➡️').grid(column=2, row=0, sticky=(N, W))
- ttk.Entry(mainframe, width=200).grid(column=3, row=0, sticky=(E, W), padx=5)
- mainframe.columnconfigure(0, weight=0)
- mainframe.columnconfigure(1, weight=0)
- mainframe.columnconfigure(2, weight=0)
- mainframe.columnconfigure(3, weight=5)
- mainframe.rowconfigure(0, weight=0)
- #
- # Set up tabbed window
- #
- tabwindow = ttk.Notebook(mainframe)
- tabwindow.grid(column=0, row=1, sticky=(N, S, E, W), padx=5, pady=5, columnspan=4)
- mainframe.rowconfigure(1, weight=1)
- tab1 = ttk.Frame(tabwindow, height=500)
- tab1.columnconfigure(0, weight=1)
- tab1.rowconfigure(0, weight=1)
- tabwindow.add(tab1, text='♊️ Start')
- #
- # Define our styles for the text
- #
- #
- # Let's have some text
- #
- text = GmiText(tab1)
- text.grid(column=0, row=0, sticky=(N, S, E, W), padx=5, pady=5)
- text.insert('end', 'A Heading1! A long one at that! Superlong. Lalalalala.\n', ('h1'))
- text.insert('end', 'Some random text. Not very much. (Just normal text)\n', ('text'))
- text.insert('end', 'And this is a link!\n', ('link'))
- text.insert('end', ' Preformatted text with leading spaces\n', ('preform'))
- text.insert('end', 'A Heading2!\n', ('h2'))
- text.insert('end', '"Some random text in a blockquote. Not very much."\n', ('block'))
- text.insert('end', 'Heading3.\n', ('h3'))
- text.insert('end', '- And this is a list!\n', ('list'))
- text.insert('end', 'And more preform\n', ('preform'))
- text['state'] = 'disabled'
- #
- # Start
- #
- root.mainloop()
|