bunny 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/env python3
  2. from tkinter import *
  3. from tkinter import ttk
  4. #
  5. # A class for .gmi markup
  6. #
  7. class GmiText(Text):
  8. def __init__(self, *args):
  9. Text.__init__(self, *args)
  10. self.tag_configure('h1', font='serif 24 bold', wrap='word')
  11. self.tag_configure('h2', font='serif 20 bold', wrap='word')
  12. self.tag_configure('h3', font='serif 16 bold', wrap='word')
  13. self.tag_configure('list', font='sans 12', wrap='word', lmargin1=30, lmargin2=30, rmargin=30)
  14. self.tag_configure('link', font='sans 12 bold', foreground='blue', wrap='word')
  15. self.tag_configure('block', font='serif 12 bold', wrap='word', lmargin1=50, lmargin2=50, rmargin=50)
  16. self.tag_configure('preform', font='mono 12', wrap='none')
  17. #
  18. # Main window
  19. #
  20. root = Tk()
  21. root.title("🐇️ Bunny -- a gemini browser")
  22. root.columnconfigure(0, weight=1)
  23. root.rowconfigure(0, weight=1)
  24. mainframe = ttk.Frame(root, padding="0 10")
  25. mainframe.grid(column=0, row=0, sticky=(N, S, E, W))
  26. #
  27. # Buttons and address bar
  28. #
  29. ttk.Button(mainframe, text='⬅️').grid(column=0, row=0, sticky=(N, W))
  30. ttk.Button(mainframe, text='⬆️').grid(column=1, row=0, sticky=(N, W))
  31. ttk.Button(mainframe, text='➡️').grid(column=2, row=0, sticky=(N, W))
  32. ttk.Entry(mainframe, width=200).grid(column=3, row=0, sticky=(E, W), padx=5)
  33. mainframe.columnconfigure(0, weight=0)
  34. mainframe.columnconfigure(1, weight=0)
  35. mainframe.columnconfigure(2, weight=0)
  36. mainframe.columnconfigure(3, weight=5)
  37. mainframe.rowconfigure(0, weight=0)
  38. #
  39. # Set up tabbed window
  40. #
  41. tabwindow = ttk.Notebook(mainframe)
  42. tabwindow.grid(column=0, row=1, sticky=(N, S, E, W), padx=5, pady=5, columnspan=4)
  43. mainframe.rowconfigure(1, weight=1)
  44. tab1 = ttk.Frame(tabwindow, height=500)
  45. tab1.columnconfigure(0, weight=1)
  46. tab1.rowconfigure(0, weight=1)
  47. tabwindow.add(tab1, text='♊️ Start')
  48. #
  49. # Define our styles for the text
  50. #
  51. #
  52. # Let's have some text
  53. #
  54. text = GmiText(tab1)
  55. text.grid(column=0, row=0, sticky=(N, S, E, W), padx=5, pady=5)
  56. text.insert('end', 'A Heading1! A long one at that! Superlong. Lalalalala.\n', ('h1'))
  57. text.insert('end', 'Some random text. Not very much. (Just normal text)\n', ('text'))
  58. text.insert('end', 'And this is a link!\n', ('link'))
  59. text.insert('end', ' Preformatted text with leading spaces\n', ('preform'))
  60. text.insert('end', 'A Heading2!\n', ('h2'))
  61. text.insert('end', '"Some random text in a blockquote. Not very much."\n', ('block'))
  62. text.insert('end', 'Heading3.\n', ('h3'))
  63. text.insert('end', '- And this is a list!\n', ('list'))
  64. text.insert('end', 'And more preform\n', ('preform'))
  65. text['state'] = 'disabled'
  66. #
  67. # Start
  68. #
  69. root.mainloop()