Пример #1
0
def displayhtml():

    global fram1
    frame = HtmlFrame(fram1, horizontal_scrollbar="true")
    frame.grid(sticky=NSEW)
    file_read = open("dialog.html", "r")
    frame.set_content(file_read.read())
Пример #2
0
    def clickAboutButton(self):
        with open("resources/LICENSE.md") as license:
            about = tk.Toplevel(self.master)
            about.title("About")

            content = HtmlFrame(about)
            content.set_content(md.markdown(license.read()))
            content.grid()
Пример #3
0
class MainWindow(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)

        self.setupUI()

    def setupUI(self):
        self.master.title("Markwhat")
        self.style = Style()
        self.style.theme_use("default")
        self.pack(fill=BOTH, expand=1)
        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)
        self.rowconfigure(1, weight=1)

        self.markwhat_label = Label(self, text="Markwhat")
        self.markwhat_label.grid(sticky=W, row=0, column=0)

        self.markwhat_textarea = WhatText(self, background='white')
        self.markwhat_textarea.grid(row=1, column=0, sticky=NSEW)
        self.markwhat_textarea.beenModified = self.on_markwhat_modfified

        self.markup_label = Label(self, text="Markup")
        self.markup_label.grid(sticky=W, row=0, column=1)

        self.markup_preview = HtmlFrame(self)
        self.markup_preview.grid(row=1, column=1, sticky=NSEW)

        self.preview_button_text = StringVar()
        self.preview_button = Button(
            self,
            textvariable=self.preview_button_text,
            command=self.on_preview_click,
        )
        self.preview_button_text.set('HTML')
        self.preview_button.grid(row=2, column=1, sticky=W)

    def on_markwhat_modfified(self, event):
        text = self.markwhat_textarea.get('1.0', END)
        markup_text = parse_markdown(text)

        if isinstance(self.markup_preview, HtmlFrame):
            self.markup_preview.set_content(markup_text)
        else:
            self.markup_preview.delete('1.0', END)
            self.markup_preview.insert('1.0', markup_text)

    def on_preview_click(self):
        if isinstance(self.markup_preview, HtmlFrame):
            self.markup_preview = WhatText(self, background="white")
            self.preview_button_text.set('HTML')
        else:
            self.markup_preview = HtmlFrame(self)
            self.preview_button_text.set('HTML Source')

        self.markup_preview.grid(row=1, column=1, sticky=NSEW)
        self.on_markwhat_modfified(None)
Пример #4
0
def open_about_window():
    """Opens About window, which displays README.md."""
    about_window = Toplevel(root)

    about_window.title("About")

    dir_path = os.path.dirname(os.path.realpath(__file__))

    with open(os.path.join(dir_path, 'README.md')) as readme:
        text = readme.read()
    html_readme = markdown.markdown(text)
    frm_readme = HtmlFrame(about_window, horizontal_scrollbar="auto")
    frm_readme.grid(sticky=tk.NSEW)
    frm_readme.set_content(html_readme)
Пример #5
0
def open_contact_window():
    """Opens Contact window, which displays contact info."""
    contact_window = Toplevel(root)
    contact_window.title("Contact")

    text = '''
           Please direct your comments and suggestions to this email:
           [email protected]

           You can also open issues or create pull requests in this github repository:
           github.com/ceferisbarov/ANL-book-retriever/
           '''
    html_contact = markdown.markdown(text)
    frm_contact = HtmlFrame(contact_window, horizontal_scrollbar="auto")
    frm_contact.grid(sticky=tk.NSEW)
    frm_contact.set_content(html_contact)
Пример #6
0
# -*- coding=utf-8 -*-
import urllib

try:
    import tkinter as tk
except ImportError:
    import Tkinter as tk

from tkinterhtml import HtmlFrame

root = tk.Tk()

frame = HtmlFrame(root, horizontal_scrollbar="auto")
frame.grid(sticky=tk.NSEW)

frame.set_content("""
<html>

<head>
<meta name=标题 content="">
<meta name=关键词 content="">
<meta http-equiv=Content-Type content="text/html; charset=x-mac-chinesesimp">
<meta name=Generator content="Microsoft Word 14 (filtered)">
<style>
<!--
 /* Font Definitions */
@font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:宋体;
Пример #7
0
# -*- coding=utf-8 -*-
import urllib

try:
    import tkinter as tk
except ImportError:
    import Tkinter as tk

from tkinterhtml import HtmlFrame

root = tk.Tk()

frame = HtmlFrame(root, horizontal_scrollbar="auto")
frame.grid(sticky=tk.NSEW)

frame.set_content("""
<html>

<head>
<meta name=标题 content="">
<meta name=关键词 content="">
<meta http-equiv=Content-Type content="text/html; charset=x-mac-chinesesimp">
<meta name=Generator content="Microsoft Word 14 (filtered)">
<style>
<!--
 /* Font Definitions */
@font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:宋体;
Пример #8
0
class EmailRenderingScreen(
        ttk.Frame
):  # implementarea frame-ului pentru randarea mail-urilor html si text
    def __init__(self, parent: MainWindow):
        super().__init__(parent)
        self.__parent = parent
        self.__email_renderer = HtmlFrame(self)
        self.__text_display = Text(self)
        self.back_button = ttk.Button(self)
        self.respond_button = ttk.Button(self)
        self.redirect_button = ttk.Button(self)
        self.header = ttk.Label(self)

        self.__setup__email_rendering_screen()

    def __setup__email_rendering_screen(self):
        self.configure(borderwidth=3, relief="sunken")

        self.back_button.configure(text="Back")
        self.respond_button.configure(text="Respond")
        self.redirect_button.configure(text="Redirect")

        self.back_button.grid(row=2, column=0, sticky=W)
        self.redirect_button.grid(row=2, column=2, sticky=E)
        self.respond_button.grid(row=2, column=1, sticky=E)
        self.header.grid(row=0, column=0, columnspan=3, sticky=(N, S, E, W))

        self.rowconfigure(1, weight=1)
        self.columnconfigure(1, weight=1)

    @staticmethod
    def process_content(content: str):
        bs = BeautifulSoup(content, features="lxml")
        for tag in bs.find_all("style"):
            content = content.replace(str(tag), "")

        return content.split("--- mail_boundary ---")[-1]

    def set_content(self, content: str, subtype: str = "plain"):
        if subtype == "plain":
            self.__text_display.configure(state="normal")
            self.__text_display.delete(1.0, "end")
            self.__text_display.insert(1.0, content)
            self.__text_display.configure(state="disabled")
            self.__text_display.grid(row=1,
                                     column=0,
                                     columnspan=3,
                                     sticky=(N, S, E, W))
        else:
            content = self.process_content(content)
            self.__email_renderer.set_content(content)
            self.__email_renderer.grid(row=1,
                                       column=0,
                                       columnspan=3,
                                       sticky=(N, S, E, W))
            self.__parent.geometry("800x300")

    def grid_rmv(self):
        self.__text_display.grid_remove()
        self.__email_renderer.grid_remove()
        self.grid_remove()

    def set_header(self, header: MIMEText):
        from_address = header["From"]
        to_address = header["To"]
        subject = header["Subject"]
        date = header["Date"]
        self.header[
            "text"] = f"From: {from_address}\nTo: {to_address}\nSubject: {subject}\nDate: {date}"

    def show(self):
        self.grid(column=0, row=0, sticky=(N, S, E, W))

    def clear_all(self):
        self.__text_display.delete(1.0, "end")
        self.header["text"] = ""