コード例 #1
0
class Window(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master
        self.myfont = font.Font(family='Helvetica', size=14)
        self.init_window()

    def init_window(self):
        self.master.title("Markdown 编辑器")
        self.pack(fill=BOTH, expand=1)

        self.inputeditor = Text(self, width="1", font=self.myfont)
        self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT)

        self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Markdown 编辑器</h1>")
        self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
        self.outputbox.fit_height()

        self.inputeditor.bind("<<Modified>>", self.onInputChange)

        self.mainmenu = Menu(self)
        self.filemenu = Menu(self.mainmenu)
        self.filemenu.add_command(label="打开", command=self.openfile)
        self.filemenu.add_command(label="另存为", command=self.savefile)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="退出", command=self.quit)
        self.mainmenu.add_cascade(label="文件", menu=self.filemenu)
        self.master.config(menu=self.mainmenu)

    def onInputChange(self, event):
        self.inputeditor.edit_modified(0)
        md2html = Markdown()
        self.outputbox.set_html(md2html.convert(self.inputeditor.get('1.0', END)))

    def openfile(self):
        openfilename = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *mdown , *.markdown"),
                                                             ("Text File", "*.txt"),
                                                             ("All Files", "*.*")))
        if openfilename:
            try:
                self.inputeditor.delete(1.0, END)
                self.inputeditor.insert(END, open(openfilename, encoding='utf-8').read())
            except Exception as e:
                mbox.showerror(f"无法打开文件({openfilename})!Error:{e}")

    def savefile(self):
        filedata = self.inputeditor.get("1.0", END)
        savefilename = filedialog.asksaveasfilename(filetypes=(("Markdown File", "*.md"),
                                                              ("Text File", "*.txt")),
                                                    title="保存Markdown 文件")
        if savefilename:
            try:
                with open(savefilename, 'w', encoding='utf-8') as f:
                    f.write(filedata)
            except Exception as e:
                mbox.showerror("保存文件错误", f"文件{savefilename}保存错误!ERROR: {e}")


    def quit(self):
        self.master.quit()
コード例 #2
0
ファイル: MDText.py プロジェクト: prerakl123/EZ_PY
class MDText(Frame):
    def __init__(self, master, **kwargs):
        Frame.__init__(self, master, **kwargs)
        self.master = master
        self.myfont = font.Font(family="Helvetica", size=14)
        self.init_window()

    def init_window(self):
        self.pack(fill=BOTH, expand=1)
        self.inputeditor = Text(self, width="1", font=self.myfont, bg='black', insertbackground='white', fg='white',
                                wrap=WORD)
        self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT)
        self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Welcome</h1>")
        self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
        self.outputbox.fit_height()
        self.inputeditor.bind("<<Modified>>", self.onInputChange)
        self.mainmenu = Menu(self.master.master)
        self.filemenu = Menu(self.mainmenu)
        self.filemenu.add_command(label="Open", command=self.openfile)
        self.filemenu.add_command(label="Save as", command=self.savefile)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Exit", command=self.quit)
        self.mainmenu.add_cascade(label="File", menu=self.filemenu)
        self.master.master.config(menu=self.mainmenu)

    def onInputChange(self, event):
        self.inputeditor.edit_modified(0)
        md2html = Markdown()
        # self.outputbox.set_html(md2html.convert(self.inputeditor.get("1.0" , END)))
        markdownText = self.inputeditor.get("1.0", END)
        html = md2html.convert(markdownText)
        self.outputbox.set_html(html)

    def openfile(self):
        openfilename = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *.mdown , *.markdown"),
                                                            ("Text File", "*.txt"),
                                                            ("All Files", "*.*")))
        if openfilename:
            try:
                self.inputeditor.delete(1.0, END)
                self.inputeditor.insert(END, open(openfilename).read())
            except:
                # print("Cannot Open File!")
                mbox.showerror("Error Opening Selected File" , "Oops!, The file you selected : {} can not be opened!".format(openfilename))
    
    def savefile(self):
        filedata = self.inputeditor.get("1.0" , END)
        savefilename = filedialog.asksaveasfilename(filetypes = (("Markdown File", "*.md"), ("Text File", "*.txt")),
                                                    title="Save Markdown File")
        if savefilename:
            try:
                f = open(savefilename, "w")
                f.write(filedata)
            except:
                mbox.showerror("Error Saving File", "Oops!, The File : {} can not be saved!".format(savefilename))
コード例 #3
0
def main():
    global p1
    global p2
    global p1engine, p2engine
    global boardCanvas
    global canvasSize
    global app
    global root
    global board
    global clickDragging
    global flipped
    global gameStateVar, gameStateLabel
    global engine1
    global engine2
    global keeprunning
    global gameinprogerss
    global my_html_label
    global button_startpos, button_back, button_forward, button_end
    global checkbutton_highlight
    global movestack, movestackend
    global checkbutton_state

    gameinprogress = False

    flipped = False
    clickDragging = False

    root = tk.Tk()

    # position/dimensions for main tk frame
    x = 100
    y = 100
    w = 887
    h = 505
    oldappheight = h
    oldappwidth = w
    geostring = "%dx%d+%d+%d" % (w, h, x, y)

    root.geometry(geostring)
    app = TkFrame(root)
    app.bind("<Configure>", appresize)

    boardCanvas = Canvas(app, width=480, height=480)

    boardCanvas.bind("<Button-1>", canvasClick)
    boardCanvas.bind("<ButtonRelease-1>", canvasRelease)
    boardCanvas.bind("<B1-Motion>", canvasMotion)

    boardCanvas.pack(expand=YES)
    boardCanvas.place(x=0, y=0)

    gameStateVar = StringVar()

    gameStateLabel = Label(root,
                           font=('calibri', 15),
                           justify=LEFT,
                           anchor="w",
                           textvariable=gameStateVar)
    gameStateLabel.pack()
    gameStateLabel.place(x=0, y=480)

    my_html_label = HTMLLabel(root, html="opening text appears here")
    my_html_label.pack(pady=20, padx=20, fill="both", expand=True)

    button_startpos = Button(root, width=100, height=48, text="<<")
    button_startpos.pack()
    button_back = Button(root, text="<")
    button_back.pack()
    button_forward = Button(root, text=">")
    button_forward.pack()
    button_end = Button(root, text=">>")
    button_end.pack()
    checkbutton_state = IntVar(value=1)
    checkbutton_highlight = Checkbutton(root,
                                        text="Highlight Book Moves",
                                        variable=checkbutton_state)

    button_back.bind("<ButtonRelease-1>", movelistBack)
    button_startpos.bind("<ButtonRelease-1>", movelistStartpos)
    button_forward.bind("<ButtonRelease-1>", movelistForward)
    button_end.bind("<ButtonRelease-1>", movelistEnd)
    checkbutton_highlight.bind("<ButtonRelease-1>", updatehighlight)
    f = open("chessopeningtheory/index.html", "r", encoding="utf-8")
    html = f.read()
    f.close()
    newhtml = ""
    allowwrite = 0
    for line in html.splitlines():
        ignoreline = False
        if "<meta property=\"og:title\"" in line:
            allowwrite = 1
        if "<img" in line: ignoreline = True
        if "<td style=\"padding:0px 0.5em; border-right:1px solid #aaa;\">" in line:
            ignoreline = True
        if "<td style=\"border-bottom:1px solid #aaa;\">" in line:
            ignoreline = True
        if "<td style=\"padding:0px 0.5em; border-left:1px solid #aaa;\">" in line:
            ignoreline = True
        if "<td style=\"border-top:1px solid #aaa;\">" in line:
            ignoreline = True
        if "<td style=\"background-color:white\">" in line and line[
                -1] >= 'a' and line[-1] <= 'h':
            ignoreline = True
        if "<td style=\"background-color:white\">" in line and line[
                -1] >= '1' and line[-1] <= '8':
            ignoreline = True
        if "<td>" in line and "</td>" in line and line[4] >= 'a' and line[
                4] <= 'h':
            ignoreline = True
        if "<td>" in line and "</td>" in line and line[4] >= '1' and line[
                4] <= '8':
            ignoreline = True
        if "id=\"References\">References<" in line: allowwrite = 0
        if allowwrite and not ignoreline: newhtml += line + "\n"
    my_html_label.set_html(newhtml)
    p1 = "Human"
    p2 = "Human"
    """
    if (p1 == "AI"):
        engine1 = chess.engine.SimpleEngine.popen_uci("c:\\engines\\stockfish11.exe")

    if (p2 == "AI"):
        engine2 = chess.engine.SimpleEngine.popen_uci("c:\\c\\raven-weak\\raven-weak.exe")
    """
    initGame(p1, p2)
    #root.update()

    drawBoard()
    drawPieces()
    highlightPieces()
    #root.after(1, mainloop())

    root.protocol("WM_DELETE_WINDOW", on_closing)
    root.mainloop()