def open_text_viewer(url, data):
text = data.decode(encoding="latin_1")
window = Toplevel(top)
window.title("Gophersnake text viewer")
textview = Text(window, width=80, height=25, wrap="word")
textview.insert("1.0", text.replace("\r\n", "\n"))
window.bind("<Control-a>", lambda e: select_all())
textview.bind("<Control-c>", lambda e: copy_to_clipboard())
#textview["state"] = "disabled"
def select_all():
textview.tag_remove("sel", "1.0", "end")
textview.tag_add("sel", "1.0", "end")
def copy_to_clipboard():
window.clipboard_clear()
window.clipboard_append(textview.get("sel.first", "sel.last"))
textview.grid(row=0, column=0, sticky=(N, S, E, W))
textview.focus_set()
textscroll = ttk.Scrollbar(
window, orient=VERTICAL, command=textview.yview)
textview["yscrollcommand"] = textscroll.set
textscroll.grid(row=0, column=1, sticky=(N, S))
textstatus = ttk.Label(window, text=url)
textstatus.grid(row=1, column=0, sticky=(E, W))
textgrip = ttk.Sizegrip(window)
textgrip.grid(row=1, column=1, sticky=(S, E))
window.rowconfigure(0, weight=1)
window.columnconfigure(0, weight=1)
# Broken as of 2016-08-29