Beispiel #1
0
class Section(Frame):
    def __init__(self,parent,snippet,source,link):
        Frame.__init__(self,parent)
        self.html_code = f"""
                <h5> Source : <b style="color:red"> {source} </b> </h5>
                <a href="{link}">original code link</a>
        """
        self.source = HTMLLabel(self,html=self.html_code,height=5,background='white')
        self.source.pack(side='top')
        self.snippet = snippet

        self.code = Text(self, wrap='none', undo=1,background='black',fg='white',height=10)
        self.code.tag_configure("bigfont", font=("Helvetica", "24", "bold"))
        self.code.pack(side='top')
        self.code.insert(END,snippet)
        self.code.config(state=DISABLED)

        self.code_syntax_color=ColorLight.ColorLight(txtbox=self.code)
        self.code_syntax_color.trigger()

        self.copy = Button(self,text='COPY',command=self.copy_code)
        self.copy.pack(side='top')
    
    def copy_code(self):
        pyperclip.copy(self.snippet)
Beispiel #2
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()
Beispiel #3
0
    def __createHTMLFrame(self, __w, __h, code):
        from tkhtmlview import HTMLLabel

        html = HTMLLabel(self.__HTMLviewer,
                         html=code,
                         width=__w,
                         height=__h - 140)
        html.pack(side=BOTTOM)
Beispiel #4
0
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))
Beispiel #5
0
    def google_search(self):
        try:
            from googlesearch import search
        except ImportError:
            print("An error when importing googlesearch has occurred.")
            return
        query = self.google_entry_str.get()
        self.result_screen.deiconify()
        self.result_screen.geometry("700x500")
        Label(self.result_screen,
              text="A list of URL's compiled by google.").pack()
        Label(self.result_screen, text="Keyword Searched: " + query).pack()

        for j in search(query, tld="co.in", num=5, stop=5):
            temp_label = HTMLLabel(self.result_screen,
                                   html='<a href="' + j + '">' + j + '</a>',
                                   fg="blue")
            temp_label.config(height=5)
            temp_label.pack()
Beispiel #6
0
def main_func():
    global start, lbl3, country, textExample, countryCode_button, html_label
    lbl2.destroy()
    countries.destroy()
    lbl3 = Label(
        root,
        text="-------------"
        "--                                                 ---------------"
        "--\n    'The future is ours to shape.\n I feel we"
        "are in a race that we need to win.\n It’s a race between the growing"
        " power\nof the technology and the growing\n wisdom"
        " we need to manage it.'\n                                  "
        "   ~Max Tegmark"
        "                    \n---------------                               "
        "                  -----------------",
        bg="black",
        fg="white",
        font="Times 18",
        pady=10)
    lbl3.config(anchor=CENTER)
    lbl3.pack(pady=10)
    start.destroy()
    country = Label(root,
                    text='Enter the country code to setup the alerts',
                    bg="black",
                    fg="white",
                    font="Times 18",
                    pady=10)
    country.pack(side=TOP, pady=10)
    textExample = Text(root, height=1, width=12)
    textExample.pack(side=TOP, pady=5)
    countryCode_button = Button(root, text="Enter", command=retrieve_input)
    countryCode_button.pack(side=TOP, pady=10)
    html_label = HTMLLabel(root,
                           html='<a href="https://blockchain.info/ticker"'
                           'style="color: green; text-align: center"> '
                           ' Please visit:- https://blockchain.info/ticker,  '
                           ' to know all the listed countries </a>')
    # html_label.pack(fill="both", expand=True)
    html_label.pack()
    html_label.fit_height()
class Window(tk.Frame):

    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.master = master
        self.font = font.Font(family='Helvetica', size=14)
        self.init_window()

    def openfile(self):
        filename = \
            filedialog.askopenfilename(filetypes=(('Markdown File',
                                                   '*.md , *.mdown'),
                                                  ('Text file', '*.txt')))
        if filename:
            try:
                md2html = Markdown()
                self.outputbox.set_html(md2html.convert(open(filename,
                                                             'r').read()))
            except Exception:
                mbox.showerror('Error opening file',
                               'The selected file cannot be opened !')

    def init_window(self):
        self.master.title('Mardown Viewer')
        self.pack(fill=tk.BOTH, expand=1)

        self.mainmenu = tk.Menu(self)
        self.filemenu = tk.Menu(self.mainmenu)
        self.filemenu.add_command(label='Open', command=self.openfile)
        self.filemenu.add_separator()
        self.filemenu.add_command(label='Exit', command=self.quit)
        self.mainmenu.add_cascade(label='File', menu=self.filemenu)
        self.master.config(menu=self.mainmenu)

        self.outputbox = HTMLLabel(self, width='1', background='white',
                                   html='<h1>Welcome</h1>')
        self.outputbox.pack(fill=tk.BOTH, expand=1, side=tk.RIGHT)
        self.outputbox.fit_height()
Beispiel #8
0
from tkinter import *
from tkhtmlview import HTMLLabel

root = Tk()
root.title("Python Tkinter How To Use HTML In Your Tkinter App")
root.geometry("500x600")

my_label = HTMLLabel(root,
                     html="\
    <h1>\
    <a href='https://www.python.org/'>Download Python</a>\
    </h1>\
    <ul>\
    <li>One </li>\
    <li>Two </li>\
    <li>three </li>\
    </ul>\
    <img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTr9vl91PpaNrX7_EiOaWpTyftYzOFEiQixBA&usqp=CAU'> "
                     )

my_label.pack(pady=20, padx=20, fill="both", expand=True)

root.mainloop()
Beispiel #9
0
import tkinter as tk
from tkhtmlview import HTMLLabel

root = tk.Tk()
html_label = HTMLLabel(
    root, html='<a href="http://www.google.com"> Google Hyperlink </a>')
html_label.pack()
root.mainloop()
Beispiel #10
0
Button(quickmenu, text="斜体", command=unc, width=6, height=3).place(x=300, y=50)
Button(quickmenu, text="引用", command=userfrom, width=6, height=3).place(x=360,
                                                                        y=50)
Button(quickmenu, text="图片", command=pic, width=6, height=3).place(x=420, y=50)
Button(quickmenu, text="超链接", command=superlink, width=6,
       height=3).place(x=480, y=50)

tools.place(x=0, y=0)


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


inputeditor = Text(showbar, height=70, width=60)
#inputeditor.pack(fill=BOTH, expand=1, side=LEFT)
inputeditor.pack(side=LEFT, fill=BOTH)
outputbox = HTMLLabel(showbar,
                      background="white",
                      html="<h1>这里什么也没有写</h1>",
                      height=600,
                      width=55)
outputbox.pack(side=RIGHT, fill=BOTH)
inputeditor.bind("<<Modified>>", onInputChange)
#outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
outputbox.fit_height()
#Button(showbar).place(x=0,y=0)\

root.mainloop()
import tkinter as tk
from tkhtmlview import HTMLLabel

root = tk.Tk()
root.title("Test Html on Tkinter")
root.configure(bg='black')

data = """<!-- Dynamic Coding output code  -->
<p style="border: 2px solid rgb(51, 103, 214); font-size: 15px; padding: 0.2em 0.6em;"><font face="arial">
<kbd style="border-radius: 0px; border: 1px solid rgb(51, 103, 214); padding: 3px;color:#3367d6;"><b>&nbsp;  Output &nbsp;</b></kbd>
<br />
<code style="color:#ff0000">
deque(['A', 'B', 'C', 'D'])


</code>
</font></p>
<br />


"""
html_label = HTMLLabel(root, html=data)
html_label.pack(fill="both", expand=True)
html_label.fit_height()
root.mainloop()
    markdown = Markdown()
    markdownText = markdown_editor.get("1.0", END)
    html = markdown.convert(markdownText)
    result.set_html(html)


# Creating tkinter window
window = Tk()
window.title('Markdown viewer')
window.geometry('1200x1000')
window.configure(bg='white')

# Styling font and button
myfont = font.Font(family="Helvetica", size=14)
style = Style()
style.configure('TButton', font=('calibri', 20, 'bold'), foreground='Blue')

# Placing widgets into Tkinter window
submit_btn = Button(text="View Markdown", command=onKeyUp, style='TButton')
submit_btn.pack(ipadx=30, ipady=6)

markdown_editor = Text(width="1", insertborderwidth=2, selectborderwidth=2)
markdown_editor.insert(END, '# Add Markdown here')
markdown_editor.pack(fill=BOTH, expand=1, side=LEFT, padx=10, pady=10)
markdown_editor.configure(font=myfont)

result = HTMLLabel(width="1", html="<h1>Markdown Viewer</h1>")
result.pack(fill=BOTH, expand=1, side=RIGHT, padx=10, pady=10)

window.mainloop()
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()

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

    # Function to save File
    def savefile(self, event):
        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))

    # FUnction to open file
    def openfile(self, event):
        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:
                mbox.showerror(
                    "Error Opening Selected File",
                    "Oops!, The file you selected : {} can not be opened!".
                    format(openfilename))

    def md2html(self):
        filedata = markdown.markdown(self.inputeditor.get("1.0", END))
        savefilename = filedialog.asksaveasfilename(
            filetypes=(("HTML File", "*.html"), ("Text File", "*.txt")),
            title="Save HTML 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))

    def saveonly(self, event):
        filedata = markdown.markdown(self.inputeditor.get("1.0", END))

    def init_window(self):
        self.master.title("MDitor")
        self.pack(fill=BOTH, expand=1)

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

        # For output window
        self.outputbox = HTMLLabel(self,
                                   width="1",
                                   background="lightgray",
                                   html="START TYPING TO SEE OUTPUT...")
        self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT)
        self.outputbox.fit_height()

        # change output as we type
        self.inputeditor.bind("<<Modified>>", self.onInputChange)
        # ctrl-s shortcut
        self.inputeditor.bind('<Control-s>', self.savefile)
        # ctrl-o shortcut
        self.inputeditor.bind('<Control-o>', self.openfile)
        # ctrl-h shortcut
        self.inputeditor.bind('<Control-h>', self.md2html)

        # File and Open
        self.mainmenu = Menu(self)
        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.mainmenu.add_cascade(label="Save HTML", command=self.md2html)
        self.master.config(menu=self.mainmenu)
Beispiel #14
0
class TextEditor(tkinter.Frame):
    def __init__(self,parent,controller):

        # Creating Frame
        tkinter.Frame.__init__(self,parent)
        self.controller = controller

        # [Shortcut Bar Main Frame]
        self.shortcut_bar=ttk.Frame(self)
        self.shortcut_bar.pack(expand='no', fill='x')

        self.left = tkinter.Frame(self)
        self.left.pack(side='left',fill='both',expand='no')

        # +++++++++++++++++++++++++ Text Box System ++++++++++++++++++++++++++++++++++++++++++++++
        # Frame For [Text Box]
        frame=ttk.Frame(self.left, borderwidth=5)
        frame.pack(expand='yes', fill='both')
        frame1=ttk.Frame(frame)
        frame1.pack(side='top', expand='yes', fill='both')
        self.text_box=tkinter.Text(frame1, wrap='none', undo=1)
        self.text_box.tag_configure("bigfont", font=("Helvetica", "24", "bold"))
        self.text_box.pack()

        # Assign the dummy variables
        self.controller.textbox = self.text_box
        self.controller.trigger_function = self.trigger

        # Adding Features On Text Box
        self.box=scrollingtext.featured_text(root=frame1, textbox=self.text_box, main=frame)

        #++++++++++++++++++++++++ [System Close] ++++++++++++++++++++++++++++++++++++++++++++++
        # Function For Scrolling Text widget number line Together
        self.cursurinfo=ttk.Label(self.text_box, text='Line 1 | Column 1',padding=3)
        self.cursurinfo.pack(expand='no', fill=None, side='right',anchor='se')

        self.controller.toolinfo=ttk.Label(self.text_box, text='State: - - - ',padding=3)
        self.controller.toolinfo.pack(expand='no', fill=None, side='left',anchor='se')

        self.micState = True # Check mic State

        space=tkinter.Label(self.left, text=' ',width=70)
        space.pack(expand='no', fill=None, side='left')

        # Pause/Resume Button
        space1=tkinter.Label(self.left, text=' ',width=7)
        space1.pack(expand='no', fill=None, side='right')
        self.pauseResumeButton=tkinter.Button(self.left, text='Pause',padx=10,pady=6,command=self.switch_state)
        self.pauseResumeButton.pack(expand='no', fill=None, side='right')

        # Stop Coding Button
        space2=tkinter.Label(self.left, text=' ',width=7)
        space2.pack(expand='no', fill=None, side='right')
        stopCodingButton=tkinter.Button(self.left, text='STOP CODING',padx=10,pady=6,command=self.stopCoding)
        stopCodingButton.pack(expand='no', fill=None, side='right')

        # Adding Syntax Highlighting Feature
        self.syntax_color=ColorLight.ColorLight(txtbox=self.text_box)

        # Binding Triggers
        self.bind_all('<Any-KeyPress>',self.trigger)

        # Right Frame to maintain Code Snippets suggestion section.
        self.right=tkinter.Frame(self,width=350,background='white')
        self.right.pack(side='right',fill='both',expand=1)

        # Frame to display MIC, Input Field, Search Button.
        self.search_frame = tkinter.Frame(self.right)
        self.search_frame.pack(side='top', fill='x',expand='no')

        self.msg_fieldText = tkinter.StringVar()    # Message Variable.
        self.msg_fieldText.set('')
        self.msg_inputField = tkinter.Entry(self.search_frame,font=('Helvetica','14'),width=40,textvariable=self.msg_fieldText)

        self.mic_listening = False  # State of Search Frame MIC
        self.display_frame = ""

        #++++++++++++++++++++++++ [Search Section] ++++++++++++++++++++++++++++++++++++++++++++++
        photo = tkinter.PhotoImage(file = "images/microphone.png")
        mic_button = tkinter.Button(self.search_frame,text='Speak',width=30,height=25,image=photo,command=self.mic_click)
        mic_button.image = photo
        mic_button.pack(side='left',fill=None,expand='no')
        self.msg_inputField.pack(side='left',fill=None)

        search_photo = tkinter.PhotoImage(file = "images/search.png")
        search_button = tkinter.Button(self.search_frame,text='Send',height=25,width=30,image=search_photo,command=self.search_click)
        search_button.image = search_photo
        search_button.pack(side='left')

        self.sections = []

    # Function for MIC actions
    def mic_click(self):
        if self.mic_listening == False:
            self.mic_listening = True
            self.controller.codethread.pause()  # Pause Current Assistant Thread.
            self.add_msg_frame(1)
            self.display_frame.update()
            playsound.playsound('audio_files/tone.mp3',True)

            msg = speech2Text() # Get message from speech detection module
            if msg == -1:
                self.add_msg_frame(-1)
            else:
                self.create_suggestions_frame(command=msg)  # Send recieved message to code searching module.

            self.mic_listening = False
            self.controller.codethread.resume() # Resume Assistant Thread.

    # Function for Search Button actions.
    def search_click(self):
        if self.mic_listening == False:
            msg = self.msg_fieldText.get() # Get message from Input Field

            # Modify the recieved message
            words = msg.split(' ')
            i = 0
            while i < len(words):
                if words[i] == '':
                    words.remove(words[i])
                    i -= 1
                i += 1
            msg = ' '.join(words)
            if len(msg) > 0:
                self.create_suggestions_frame(command=msg)

    # Function to add State of MIC
    def add_msg_frame(self,typeofmsg):

        # Destroy the existing Code Display Frame.
        if type(self.display_frame) is tkinter.Frame:
            self.display_frame.destroy()

        #++++++++++++++++++++++++ [New Code Display Section] ++++++++++++++++++++++++++++++++++++++++++++++
        self.display_frame = tkinter.Frame(self.right)
        self.display_frame.pack(side='top',fill=BOTH,expand=1)

        self.canvas = tkinter.Canvas(self.display_frame)
        self.canvas.pack(side='left',fill=tkinter.BOTH,expand=1)

        self.scrollbar = ttk.Scrollbar(self.display_frame,orient=tkinter.VERTICAL,command=self.canvas.yview)
        self.scrollbar.pack(side='right',fill=tkinter.Y)

        self.canvas.configure(yscrollcommand=self.scrollbar.set)
        self.canvas.bind('<Configure>',lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all")))

        self.sec_frame = tkinter.Frame(self.canvas)
        self.canvas.create_window((0,0),window=self.sec_frame,anchor='nw',width=385)

        # Set MIC Status.
        if typeofmsg == 1:
            self.htmlsnippet = '''
                <div style="background-color:white;">
                <h5 style="color: blue">I'm Listening...</h5>
                <p>speak after the sound</p>
                </div>
            '''         # HTML div to display MIC status.
        else:
            self.htmlsnippet = '''
                <div style="background-color:white;">
                <h5 style="color: red">Error</h5>
                <p>Didn't understand, Please try again</p>
                </div>
            '''      # HTML div to display Error Message.

        self.msg_display = HTMLLabel(self.sec_frame,html=self.htmlsnippet,height=6,background='white')  # Display Status of Tool and MIC
        self.msg_display.pack()

    # Function to Display Searching Message.
    def display_searching(self):

        if type(self.display_frame) is tkinter.Frame:
            self.display_frame.destroy()

        self.display_frame = tkinter.Frame(self.right)
        self.display_frame.pack(side='top',fill=BOTH,expand=1)

        self.canvas = tkinter.Canvas(self.display_frame)
        self.canvas.pack(side='left',fill=tkinter.BOTH,expand=1)

        self.scrollbar = ttk.Scrollbar(self.display_frame,orient=tkinter.VERTICAL,command=self.canvas.yview)
        self.scrollbar.pack(side='right',fill=tkinter.Y)

        self.canvas.configure(yscrollcommand=self.scrollbar.set)
        self.canvas.bind('<Configure>',lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all")))

        self.sec_frame = tkinter.Frame(self.canvas)
        self.canvas.create_window((0,0),window=self.sec_frame,anchor='nw',width=385)

        self.htmlsnippet = '''
            <div style="background-color:white;">
            <h5 style="color: orange">Searching for top results ...</h5>
            </div>
            '''     # HTML template for Searching Message.

        self.msg_display = HTMLLabel(self.sec_frame,html=self.htmlsnippet,height=6,background='white')
        self.msg_display.pack() 

    #++++++++++++++++++++++++ [Code Suggestion Thread] ++++++++++++++++++++++++++++++++++++++++++++++
    # Function to search for Code Snippets and Displaying them.
    def search_thread(self,command):

        self.display_searching()    # Display Searching Message.
        self.snippets = search_web(command) # Get Code Snippets
        self.display_frame.destroy()    # destroy existing display frame.

        # create Display Frame for displaying Search Query and Code Snippets.
        self.display_frame = tkinter.Frame(self.right)
        self.display_frame.pack(side='top',fill=BOTH,expand=1)

        self.canvas = tkinter.Canvas(self.display_frame)
        self.canvas.pack(side='left',fill=tkinter.BOTH,expand=1)

        self.scrollbar = ttk.Scrollbar(self.display_frame,orient=tkinter.VERTICAL,command=self.canvas.yview)
        self.scrollbar.pack(side='right',fill=tkinter.Y)

        self.canvas.configure(yscrollcommand=self.scrollbar.set)
        self.canvas.bind('<Configure>',lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all")))

        self.sec_frame = tkinter.Frame(self.canvas)
        self.canvas.create_window((0,0),window=self.sec_frame,anchor='nw',width=385)

        self.htmlsnippet = f'''
            <div style="background-color:white;">
            <h5 style="color: green">Recieved Command</h5>
            <p>{command}</p>
            </div>
        '''     # HTML template for recieved message.

        self.msg_display = HTMLLabel(self.sec_frame,html=self.htmlsnippet,height=6,background='white')
        self.msg_display.pack()

        self.separator = Label(self.sec_frame,text='--------------------------------------------------------------')
        self.separator.pack(side='top',fill='x',expand='no')

        # Display Code snippets.
        for i in range(len(self.snippets)):
            if len(self.snippets[i][2]) > 0:
                frami = Section(self.sec_frame,self.snippets[i][2],self.snippets[i][0],self.snippets[i][1])
                frami.pack(side='top',fill='x',expand=1)
                self.sections.append(frami)

        # Update Controller.
        self.controller.geometry("1361x600")
        self.controller.update()
        self.controller.geometry("1360x600")
        self.controller.update()
    
    # Function to find code snippets.
    def create_suggestions_frame(self,command):

        self.searching_thread = threading.Thread(target = self.search_thread, args =(command, ))    # create thread for searching code snippets.
        self.searching_thread.setDaemon(True)
        self.searching_thread.start()

    # [ Function to Chnage State of Pause/Resume Button and call Pause/Resume Functions ]
    def switch_state(self):
        if self.mic_listening == False:
            if self.micState:
                self.pauseResumeButton.configure(text='Resume')
                self.update()
                self.controller.codethread.pause()
                self.micState = False
            else:
                self.pauseResumeButton.configure(text='Pause')
                self.update()
                self.controller.codethread.resume()
                self.micState = True

    # [ Function to save textbox text as a python file ]
    def Save_as(self):
        ExtType=[('.py', '*.py')]
        path=tkFileDialog.asksaveasfile(title='Save As', defaultextension='*.py',filetypes=ExtType)
        storeobj=self.text_box.get('1.0', END)
        if path:
            filetmp=open(path.name,'a')
            filetmp.write(storeobj)
            filetmp.close()

    # [ Function to exit Coding State ]
    def stopCoding(self):
        self.Save_as() # Save the text as python file
        time.sleep(3)
        self.controller.show_frame('Assistant') # Change Frame to Assiatant Frame
        self.update() # Update Window GUI
        #dictate('Done Coding')
        

    # [Function to Update Cursor Position]
    def update_cursor_info_bar(self, event=None):
        row, col = self.text_box.index(tkinter.INSERT).split('.')
        line_num, col_num = str(int(row)), str(int(col)+1) # colstarts at 0
        infotext = "Line: {0} | Column: {1}".format(line_num, col_num)
        self.cursurinfo.configure(text=infotext)

    # All-Key Trigger
    def trigger(self, event=None):
        self.box.changed()
        self.update_cursor_info_bar()
        self.syntax_color.trigger()
Beispiel #15
0
root.title("Image viewer and downloader")

# Set styles
style = ttk.Style()
style.theme_use('alt')
style.map('my.TButton', background=[('active', 'white')])
style.configure('my.TButton', font=('Helvetica', 16, 'bold'))
style.configure('my.TButton', background='white')
style.configure('my.TButton', foreground='orange')
style.configure('my.TFrame', background='white')

# Add labels and buttons
my_label = HTMLLabel(root)

search_box = Entry(root, font=("Helvetica 15"), bd=2, width=60)
search_box.pack(side=TOP, pady=5, padx=15, ipadx=5)

search_btn = ttk.Button(text="Scrape Image!",
                        command=showImage,
                        style='my.TButton')
search_btn.pack(side=TOP)

save_btn = ttk.Button(text="Download Image!",
                      command=saveImage,
                      style='my.TButton')
save_btn.pack(side=TOP)

my_label.pack(pady=20, padx=20)
# Execute Tkinter
root.mainloop()
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()