コード例 #1
0
def defaultcheck():
    global w3
    w3 = Toplevel()
    w3.wm_attributes('-fullscreen', 1)
    of = open('License.dat', 'r')
    for of2 in of:
        of2==of2
    root.iconify()
    if of2 == ugoku:
        p = open('Path.dat', 'r')
        for i in p:
            if not os.path.exists(i):
                Dialog.Dialog(root, title = 'alert', bitmap = 'info',
                              text = u'プログラムファイルが見つかりません。%s' % i,
                              strings = ['OK'], default = 0)
                sys.exit()
            else:
                actlog()
                w3.destroy()
    elif of2 == eke:
        actname.set(ids)
        os.chdir(currentdir)
        f1 = Frame(w3)
        f2 = Frame(w3)
        f3 = Frame(w3)
        f4 = Frame(w3)
        Label(w3, text = '%s' % osnam).pack()
        t0 = ScrolledText(w3)
        t0.pack()
        fi = open('README.txt')
        t0.delete('1.0', 'end')
        for x in fi:
            t0.insert('end', x.decode('shift_jis'))
        fi.close()
        t0.focus_set()
        Label(w3, text = u'管理者登録').pack()
        Label(w3, textvariable = pwcon).pack()
        Label(f1, textvariable = actname).pack(side = RIGHT)
        Label(f1, text = u'管理者名').pack(side = LEFT)
        Entry(f2, textvariable = actpw, show = '*').pack(side = RIGHT)
        Label(f2, text = u'パスワード(8文字)').pack(side = LEFT)
        Entry(f3, textvariable = actpwc, show = '*').pack(side = RIGHT)
        Label(f3, text = u'確認のためもう一度入力').pack(side = LEFT)
        Button(f4, text = u'作成', command = makeid).pack(side = LEFT)
        Button(f4, text = u'キャンセル', command = sys.exit).pack(side = RIGHT)
        f1.pack()
        f2.pack()
        f3.pack()
        f4.pack()
        root.lower()
    else:
        Dialog.Dialog(root, title = 'alert', bitmap = 'info',
                      text = u'ライセンス認証されていないため、本ソフトを起動できませんでした',
                      strings = ['OK'], default = 0)
        sys.exit()
コード例 #2
0
ファイル: snip.py プロジェクト: cenan/snpptmngr
class MainWnd:
    def __init__(self, parent):
        self.search_str = StringVar()
        self.parent = parent

        root.protocol("WM_DELETE_WINDOW", self.ask_quit)

        self.parent.title("snippets")
        self.parent.configure(padx=10, pady=10)
        self.parent.minsize(630, 480)
        self.create_widgets()

        db_path = os.path.join(abspath(dirname(__file__)), "snip.db")
        db_exists = os.path.isfile(db_path)
        self.connection = sqlite3.connect(db_path)
        self.connection.row_factory = dict_factory
        self.cursor = self.connection.cursor()

        if not db_exists:
            self.cursor.execute('create table snippet (caption, content)')

        self.fill_list()
        self.snip_content.focus_set()

    def ask_quit(self):
        if tkMessageBox.askokcancel("Quit", "You want to quit now?"):
            self.parent.destroy()

    def __del__(self):
        self.connection.close()

    def create_widgets(self):
        self.search_box = Entry(self.parent, textvariable=self.search_str)
        self.search_str.set("New snippet")
        self.search_box.pack(fill=X)

        self.toolbar_f = Frame(self.parent, pady=5)
        self.toolbar_f.pack(fill=X)

        self.newbtn = Button(self.toolbar_f, text="New", command=self.on_new)
        self.newbtn.pack(side=LEFT)

        self.savebtn = Button(self.toolbar_f, text="Save", command=self.on_save)
        self.savebtn.pack(side=LEFT)

        self.updatebtn = Button(self.toolbar_f, text="Update", command=self.on_update)
        self.updatebtn.pack(side=LEFT)

        self.delbtn = Button(self.toolbar_f, text="Delete", command=self.on_delete)
        self.delbtn.pack(side=LEFT)

        self.copybtn = Button(self.toolbar_f, text="Copy to clipboard", command=self.on_copy)
        self.copybtn.pack(side=LEFT)

        self.quitbtn = Button(self.toolbar_f, text="Quit", command=self.on_quit)
        self.quitbtn.pack(side=LEFT)

        self.pwin = PanedWindow(self.parent, showhandle=True)
        self.pwin.pack(fill=BOTH, expand=1)

        self.list_f = Frame(self.pwin)
        self.list_sb = Scrollbar(self.list_f, orient=VERTICAL)
        self.snip_list = Listbox(self.list_f, yscrollcommand=self.list_sb.set)
        self.list_sb.config(command=self.snip_list.yview)
        self.snip_list.bind('<ButtonRelease-1>', self.on_snippet_selected)
        self.snip_list.pack(side=LEFT, fill=BOTH, expand=1)
        self.list_sb.pack(side=RIGHT, fill=Y)
        self.pwin.add(self.list_f)
        self.pwin.paneconfigure(self.list_f, minsize=177)

        self.snippetFont = Font(family="courier", size=11, weight=NORMAL)
        self.snip_content = ScrolledText(self.pwin, height=20, width=40,
                                         padx=5, pady=5,
                                         font=self.snippetFont)
        self.pwin.add(self.snip_content)


    # noinspection PyTypeChecker
    def fill_list(self):
        self.snip_list.delete(0, END)
        self.cursor.execute('select * from snippet')
        for r in self.cursor.fetchall():
            self.snip_list.insert(END, r['caption'])

    def on_new(self):
        self.search_str.set("")
        self.snip_content.delete(1.0, END)

    def on_save(self):
        self.cursor.execute(
            'insert into snippet (caption,content) values (?,?)',
            (self.search_str.get(), self.snip_content.get(1.0, END),))
        self.connection.commit()
        self.fill_list()

    def on_update(self):
        self.cursor.execute(
            'update snippet set content=? where caption=?',
            (self.snip_content.get(1.0, END), self.search_str.get()))
        self.connection.commit()

    def on_delete(self):
        index = self.snip_list.curselection()[0]
        seltext = self.snip_list.get(index)
        self.cursor.execute(
            'delete from snippet where caption=?',
            (seltext,))
        self.connection.commit()
        self.snip_list.delete(ANCHOR)
        self.on_new()

    def on_copy(self):
        self.parent.clipboard_clear()
        self.parent.clipboard_append(self.snip_content.get(1.0, END))

    def on_quit(self):
        self.parent.destroy()

    # noinspection PyTypeChecker
    def on_snippet_selected(self, _):
        try:
            index = self.snip_list.curselection()[0]
        except IndexError:
            return
        selected_text = self.snip_list.get(index)
        self.snip_content.delete(1.0, END)
        self.cursor.execute(
            'select * from snippet where caption=?',
            (selected_text,))
        r = self.cursor.fetchone()
        if r['caption']:
            self.search_str.set(r['caption'])
        if r['content']:
            self.snip_content.insert(INSERT, r['content'])
        self.snip_content.focus_set()
コード例 #3
0
class MyTkAppFrame(ttk.Notebook):

    # the req is a list
    def cb_task(self, tid, req):
        L.debug("do task: tid=" + str(tid) + ", req=" + str(req))
        reqstr = req[0]
        resp = self.serv.get_request_block(reqstr)
        if resp != None:
            if resp.strip() != "":
                self.mymailbox.mailbox_serv.put(req[1], resp)

    def do_stop(self):
        isrun = False;
        if self.runth_svr != None:
            if self.runth_svr.isAlive():
                #L.info('signal server to stop ...')
                self.server.shutdown()
                #L.info('server close ...')
                self.server.server_close()
                #L.info('server closed.')
                isrun = True
        if isrun == False:
            L.info('server is not running. skip')
        if self.serv != None:
            self.serv.close()
            self.serv = None

        self.btn_svr_start.config(state=tk.NORMAL)
        self.btn_svr_stop.config(state=tk.DISABLED)

        #return

    def do_start(self):
        import socketserver as ss
        import neatocmdsim as nsim

        class ThreadedTCPRequestHandler(ss.BaseRequestHandler):
            # override base class handle method
            def handle(self):
                BUFFER_SIZE = 4096
                MAXIUM_SIZE = BUFFER_SIZE * 5
                data = ""
                L.info("server connectd by client: " + str(self.client_address))
                mbox_id = self.server.mydata.mailbox_serv.declair()

                cli_log_head = "CLI" + str(self.client_address)
                while 1:
                    try:
                        # receive the requests
                        recvdat = self.request.recv(BUFFER_SIZE)
                        if not recvdat:
                            # EOF, client closed, just return
                            L.info(cli_log_head + " disconnected: " + str(self.client_address))
                            break
                        data += str(recvdat, 'ascii')
                        L.debug(cli_log_head + " all of data: " + data)
                        cntdata = data.count('\n')
                        L.debug(cli_log_head + " the # of newline: %d"%cntdata)
                        if (cntdata < 1):
                            L.debug(cli_log_head + " not receive newline, skip: " + data)
                            continue
                        # process the requests after a '\n'
                        requests = data.split('\n')
                        for i in range(0, cntdata):
                            # for each line:
                            request = requests[i].strip()
                            L.info(cli_log_head + " request [" + str(i+1) + "/" + str(cntdata) + "] '" + request + "'")
                            self.server.serv.request ([request, mbox_id])
                            response = self.server.mydata.mailbox_serv.get(mbox_id)
                            if response != "":
                                L.debug(cli_log_head + 'send data back: sz=' + str(len(response)))
                                self.request.sendall(bytes(response, 'ascii'))

                        data = requests[-1]

                    except BrokenPipeError:
                        L.error (cli_log_head + 'remote closed: ' + str(self.client_address))
                        break
                    except ConnectionResetError:
                        L.error (cli_log_head + 'remote reset: ' + str(self.client_address))
                        break
                    except Exception as e1:
                        L.error (cli_log_head + 'Error in read serial: ' + str(e1))
                        break

                L.error (cli_log_head + 'close: ' + str(self.client_address))
                self.server.mydata.mailbox_serv.close(mbox_id)


        # pass the data strcture from main frame to all of subclasses
        # mailbox_serv, mailbox_servcli

        class ThreadedTCPServer(ss.ThreadingMixIn, ss.TCPServer):
            daemon_threads = True
            allow_reuse_address = True
            # pass the serv to handler
            def __init__(self, host_port_tuple, streamhandler, serv, mydata):
                super().__init__(host_port_tuple, streamhandler)
                self.serv = serv
                self.mydata = mydata

        if self.runth_svr != None:
            if self.runth_svr.isAlive():
                L.info('server is already running. skip')
                return True

        L.info('connect to ' + self.conn_port.get())
        self.serv = neatocmdapi.NCIService(target=self.conn_port.get().strip(), timeout=0.5)
        if self.serv.open(self.cb_task) == False:
            L.error ('Error in open serial')
            return False

        L.info('start server ' + self.bind_port.get())
        b = self.bind_port.get().split(":")
        L.info('b=' + str(b))
        HOST=b[0]
        PORT=3333
        if len(b) > 1:
            PORT=int(b[1])
        L.info('server is running ...')
        try:
            self.server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler, self.serv, self.mymailbox)
        except Exception as e:
            L.error("Error in starting service: " + str(e))
            return False
        ip, port = self.server.server_address
        L.info("server listened to: " + str(ip) + ":" + str(port))
        self.runth_svr = Thread(target=self.server.serve_forever)
        self.runth_svr.setDaemon(True) # When closing the main thread, which is our GUI, all daemons will automatically be stopped as well.
        self.runth_svr.start()

        self.btn_svr_start.config(state=tk.DISABLED)
        self.btn_svr_stop.config(state=tk.NORMAL)
        L.info('server started.')
        return True

    def get_log_text(self):
        return self.text_log

    def __init__(self, tk_frame_parent):
        global config_use_textarea_log
        ttk.Notebook.__init__(self, tk_frame_parent)
        nb = self
        self.runth_svr = None
        self.serv = None
        self.serv_cli = None

        class MyMailbox(object):
            "mymailbox"
            def __init__(self):
                self.mailbox_serv = neatocmdapi.MailPipe()
                self.mailbox_servcli = neatocmdapi.MailPipe()

        self.mymailbox = MyMailbox()

        guilog.rClickbinder(tk_frame_parent)

        # page for About
        page_about = ttk.Frame(nb)
        lbl_about_head = tk.Label(page_about, text=_("About"), font=LARGE_FONT)
        lbl_about_head.pack(side="top", fill="x", pady=10)
        lbl_about_main = tk.Label(page_about
                , font=NORM_FONT
                , text="\n" + str_progname + "\n" + str_version + "\n"
                    + _("Forward Neato XV control over network") + "\n"
                    + "\n"
                    + _("Copyright © 2015–2016 The nxvForward Authors") + "\n"
                    + "\n"
                    + _("This program comes with absolutely no warranty.") + "\n"
                    + _("See the GNU General Public License, version 3 or later for details.")
                )
        lbl_about_main.pack(side="top", fill="x", pady=10)

        # page for server
        page_server = ttk.Frame(nb)
        lbl_svr_head = tk.Label(page_server, text=_("Server"), font=LARGE_FONT)
        lbl_svr_head.pack(side="top", fill="x", pady=10)

        frame_svr = ttk.LabelFrame(page_server, text=_("Setup"))

        line=0
        bind_port_history = ('localhost:3333', '127.0.0.1:4444', '0.0.0.0:3333')
        self.bind_port = tk.StringVar()
        lbl_svr_port = tk.Label(frame_svr, text=_("Bind Address:"))
        lbl_svr_port.grid(row=line, column=0, padx=5, sticky=tk.N+tk.S+tk.W)
        combobox_bind_port = ttk.Combobox(frame_svr, textvariable=self.bind_port)
        combobox_bind_port['values'] = bind_port_history
        combobox_bind_port.grid(row=line, column=1, padx=5, pady=5, sticky=tk.N+tk.S+tk.W)
        combobox_bind_port.current(0)

        line += 1
        conn_port_history = ('dev://ttyACM0:115200', 'dev://ttyUSB0:115200', 'dev://COM11:115200', 'dev://COM12:115200', 'sim:', 'tcp://localhost:3333', 'tcp://192.168.3.163:3333')
        self.conn_port = tk.StringVar()
        lbl_svr_port = tk.Label(frame_svr, text=_("Connect to:"))
        lbl_svr_port.grid(row=line, column=0, padx=5, sticky=tk.N+tk.S+tk.W)
        combobox_conn_port = ttk.Combobox(frame_svr, textvariable=self.conn_port)
        combobox_conn_port['values'] = conn_port_history
        combobox_conn_port.grid(row=line, column=1, padx=5, pady=5, sticky=tk.N+tk.S+tk.W)
        combobox_conn_port.current(0)

        line -= 1
        self.btn_svr_start = tk.Button(frame_svr, text=_("Start"), command=self.do_start)
        self.btn_svr_start.grid(row=line, column=2, padx=5, sticky=tk.N+tk.S+tk.W+tk.E)
        #self.btn_svr_start.pack(side="right", fill="both", padx=5, pady=5, expand=True)

        line += 1
        self.btn_svr_stop = tk.Button(frame_svr, text=_("Stop"), command=self.do_stop)
        self.btn_svr_stop.grid(row=line, column=2, padx=5, sticky=tk.N+tk.S+tk.W+tk.E)
        #self.btn_svr_stop.pack(side="right", fill="both", padx=5, pady=5, expand=True)

        frame_svr.pack(side="top", fill="x", pady=10)

        self.text_log = None
        if config_use_textarea_log:
            self.text_log = tk.scrolledtext.ScrolledText(page_server, wrap=tk.WORD, height=1)
            self.text_log.configure(state='disabled')
            self.text_log.pack(expand=True, fill="both", side="top")
            #self.text_log.grid(row=line, column=1, columnspan=2, padx=5)
            self.text_log.bind("<1>", lambda event: self.text_log.focus_set()) # enable highlighting and copying
            #set_readonly_text(self.text_log, "Version Info\nver 1\nver 2\n")

            btn_log_clear = tk.Button(page_server, text=_("Clear"), command=lambda: (set_readonly_text(self.text_log, ""), self.text_log.update_idletasks()))
            #btn_log_clear.grid(row=line, column=0, columnspan=2, padx=5, sticky=tk.N+tk.S+tk.W+tk.E)
            btn_log_clear.pack(side="right", fill="both", padx=5, pady=5, expand=True)

        # page for client
        page_client = ttk.Frame(nb)
        lbl_cli_head = tk.Label(page_client, text=_("Test Client"), font=LARGE_FONT)
        lbl_cli_head.pack(side="top", fill="x", pady=10)

        frame_cli = ttk.LabelFrame(page_client, text=_("Connection"))

        line=0
        client_port_history = ('tcp://192.168.3.163:3333', 'dev://ttyACM0:115200', 'dev://ttyUSB0:115200', 'dev://COM11:115200', 'dev://COM12:115200', 'sim:', 'tcp://localhost:3333')
        self.client_port = tk.StringVar()
        lbl_cli_port = tk.Label(frame_cli, text=_("Connect to:"))
        lbl_cli_port.grid(row=line, column=0, padx=5, sticky=tk.N+tk.S+tk.W)
        combobox_client_port = ttk.Combobox(frame_cli, textvariable=self.client_port)
        combobox_client_port['values'] = client_port_history
        combobox_client_port.grid(row=line, column=1, padx=5, pady=5, sticky=tk.N+tk.S+tk.W)
        combobox_client_port.current(0)

        self.btn_cli_connect = tk.Button(frame_cli, text=_("Connect"), command=self.do_cli_connect)
        self.btn_cli_connect.grid(row=line, column=2, columnspan=1, padx=5, sticky=tk.N+tk.S+tk.W+tk.E)
        #self.btn_cli_connect.pack(side="left", fill="both", padx=5, pady=5, expand=True)

        self.btn_cli_disconnect = tk.Button(frame_cli, text=_("Disconnect"), command=self.do_cli_disconnect)
        self.btn_cli_disconnect.grid(row=line, column=3, columnspan=1, padx=5, sticky=tk.N+tk.S+tk.W+tk.E)
        #self.btn_cli_disconnect.pack(side="left", fill="both", padx=5, pady=5, expand=True)

        frame_cli.pack(side="top", fill="x", pady=10)

        page_command = page_client
        frame_top = tk.Frame(page_command)#, background="green")
        frame_bottom = tk.Frame(page_command)#, background="yellow")
        frame_top.pack(side="top", fill="both", expand=True)
        frame_bottom.pack(side="bottom", fill="x", expand=False)

        self.text_cli_command = ScrolledText(frame_top, wrap=tk.WORD)
        #self.text_cli_command.insert(tk.END, "Some Text\ntest 1\ntest 2\n")
        self.text_cli_command.configure(state='disabled')
        self.text_cli_command.pack(expand=True, fill="both", side="top")
        # make sure the widget gets focus when clicked
        # on, to enable highlighting and copying to the
        # clipboard.
        self.text_cli_command.bind("<1>", lambda event: self.text_cli_command.focus_set())

        btn_clear_cli_command = tk.Button(frame_bottom, text=_("Clear"), command=lambda: (set_readonly_text(self.text_cli_command, ""), self.text_cli_command.update_idletasks()) )
        btn_clear_cli_command.pack(side="left", fill="x", padx=5, pady=5, expand=False)
        self.cli_command = tk.StringVar()
        self.combobox_cli_command = ttk.Combobox(frame_bottom, textvariable=self.cli_command)
        self.combobox_cli_command['values'] = ('Help', 'GetAccel', 'GetButtons', 'GetCalInfo', 'GetCharger', 'GetDigitalSensors', 'GetErr', 'GetLDSScan', 'GetLifeStatLog', 'GetMotors', 'GetSchedule', 'GetTime', 'GetVersion', 'GetWarranty', 'PlaySound 0', 'Clean House', 'DiagTest MoveAndBump', 'DiagTest DropTest', 'RestoreDefaults', 'SetDistanceCal DropMinimum', 'SetFuelGauge Percent 100', 'SetIEC FloorSelection carpet', 'SetLCD BGWhite', 'SetLDSRotation On', 'SetLED BacklightOn', 'SetMotor VacuumOn', 'SetSchedule Day Sunday Hour 17 Min 0 House ON', 'SetSystemMode Shutdown', 'SetTime Day Sunday Hour 12 Min 5 Sec 25', 'SetWallFollower Enable', 'TestMode On', 'Upload' )
        self.combobox_cli_command.pack(side="left", fill="both", padx=5, pady=5, expand=True)
        self.combobox_cli_command.bind("<Return>", self.do_cli_run_ev)
        self.combobox_cli_command.bind("<<ComboboxSelected>>", self.do_select_clicmd)
        self.combobox_cli_command.current(0)
        btn_run_cli_command = tk.Button(frame_bottom, text=_("Run"), command=self.do_cli_run)
        btn_run_cli_command.pack(side="right", fill="x", padx=5, pady=5, expand=False)

        self.check_mid_cli_command()


        # last
        nb.add(page_server, text=_("Server"))
        nb.add(page_client, text=_("Test Client"))
        nb.add(page_about, text=_("About"))
        combobox_bind_port.focus()

        self.do_stop()
        self.do_cli_disconnect()
        return

    #
    # connection and command: support functions
    #
    def do_select_clicmd(self, event):
        self.combobox_cli_command.select_range(0, tk.END)
        return

    # the req is a list
    def cb_task_cli(self, tid, req):
        L.debug("do task: tid=" + str(tid) + ", req=" + str(req))
        reqstr = req[0]
        resp = self.serv_cli.get_request_block(reqstr)
        if resp != None:
            if resp.strip() != "":
                self.mymailbox.mailbox_servcli.put(req[1], resp.strip())
        return

    def do_cli_connect(self):
        self.do_cli_disconnect()
        L.info('client connect ...')
        L.info('connect to ' + self.client_port.get())
        self.serv_cli = neatocmdapi.NCIService(target=self.client_port.get().strip(), timeout=0.5)
        if self.serv_cli.open(self.cb_task_cli) == False:
            L.error ('Error in open serial')
            return
        self.mid_cli_command = self.mymailbox.mailbox_servcli.declair();
        L.info ('serial opened')
        self.btn_cli_connect.config(state=tk.DISABLED)
        self.btn_cli_disconnect.config(state=tk.NORMAL)
        return

    def do_cli_disconnect(self):
        if self.serv_cli != None:
            L.info('client disconnect ...')
            self.serv_cli.close()
        else:
            L.info('client is not connected, skip.')
        self.serv_cli = None
        self.mid_cli_command = -1;
        self.btn_cli_connect.config(state=tk.NORMAL)
        self.btn_cli_disconnect.config(state=tk.DISABLED)
        return

    def do_cli_run(self):
        if self.serv_cli == None:
            L.error('client is not connected, please connect it first!')
            return
        L.info('client run ...')
        reqstr = self.cli_command.get().strip()
        if reqstr != "":
            self.serv_cli.request([reqstr, self.mid_cli_command])
        return

    def do_cli_run_ev(self, event):
        self.do_cli_run()
        return

    def check_mid_cli_command(self):
        if self.serv_cli != None and self.mid_cli_command >= 0:
            try:
                resp = self.mymailbox.mailbox_servcli.get(self.mid_cli_command, False)
                respstr = resp.strip() + "\n\n"
                # put the content to the end of the textarea
                guilog.textarea_append (self.text_cli_command, respstr)
                self.text_cli_command.update_idletasks()
            except queue.Empty:
                # ignore
                pass
        # setup next
        self.after(300, self.check_mid_cli_command)
        return
コード例 #4
0
from common_imports import *
from tkFileDialog import *
from tkMessageBox import *
from tkFont import Font
from ScrolledText import *
import file_menu
import edit_menu
import format_menu
import help_menu

root = Tk()

root.title("Text Editor-Untiltled")
root.geometry("300x250+300+300")
root.minsize(width=400, height=400)

font = Font(family="Verdana", size=10)

text = ScrolledText(root, state='normal', height=400, width=400, wrap='word', font = font, pady=2, padx=3, undo=True)
text.pack(fill=Y, expand=1)
text.focus_set()

menubar = Menu(root)

file_menu.main(root,text,menubar)
edit_menu.main(root,text,menubar)
format_menu.main(root,text,menubar)
help_menu.main(root,text,menubar)
root.mainloop()
コード例 #5
0
ファイル: IMGui.py プロジェクト: pcoss3413/pyIMSafe-OSX
class GUI:
    def __init__(self):
        self.version = "2.1"

        self.root = Tk()
        self.root.title("IMSafe %s ---  By: Patrick T. Cossette" %
                        self.version)

        self.encryptionFunction = IMCrypt2.encryptText
        self.decryptionFunction = IMCrypt2.decryptText

        self.useNewMethod = IntVar()
        self.useNewMethod.set(1)

        self.key = "Red Castle"
        self.server = StringVar()
        self.username = StringVar()
        self.username.set(environ["USER"])
        self.settingsUp = False
        self.connected = False
        self.master = None
        self.usernamePreview = StringVar()
        self.usernamePreview.set(self.username.get())
        self.all_recipts = []

        self.keyTxt = StringVar()
        self.keyTxt2 = StringVar()

        self.keyTxt.set(self.key)
        self.keyTxt2.set(self.key)

        self.queue = Queue.Queue()

        self.server.set("http://www.example.com/IMSafe.php")

        self.network = IMNetwork.IMNetwork()
        self.network.screen_name = self.username.get()
        self.network.address = self.server.get()

        self.scheme = IntVar()
        self.scheme.set(1)  #color scheme, 1 = green on black.

        #Foreground, background, insertion cursor, entry background, username highlight, foreign username highlight
        self.colorSchemes = [
            ("green", "black", "red", "gray", "red", "blue"),
            ("black", "white", "black", "white", "blue", "red"),
            ("red", "black", "green", "gray", "green", "blue"),
            ("yellow", "black", "blue", "gray", "blue", "green"),
            ("blue", "black", "purple", "gray", "red", "black"),
            ("black", "gray", "black", "gray", "blue", "red"),
            ("black", "blue", "white", "blue", "white", "black"),
            ("black", "white", "black", "white", "blue", "red"),
            ("green", "black", "red", "gray", "red", "blue")
        ]

        self.fontSize = 15
        self.checked = IntVar()
        self.checked.set(1)

        self.alwaysOntop = IntVar()
        self.alwaysOntop.set(0)

        self.fullscreen = IntVar()
        self.fullscreen.set(0)
        self.previousSize = ""

        self.playSoundWithFocus = IntVar()
        self.playSoundWithoutFocus = IntVar()
        self.playSoundOnRecieve = IntVar()
        self.playSoundOnSend = IntVar()
        self.mute = IntVar()

        self.playingSound = False  #Prevents overlap when recieving a massive numbger of messages

        self.playSoundWithFocus.set(1)
        self.playSoundWithoutFocus.set(1)
        self.playSoundOnRecieve.set(1)
        self.playSoundOnSend.set(1)
        self.mute.set(0)

        self.tags = 0  #Keep up with tags while highlighting text

        filemenu = Menu(self.root, tearoff=0)
        filemenu.add_command(label="Open Encrypted File           ⌘O",
                             command=self.openFile)
        filemenu.add_command(label="Save Encrypted File            ⌘S",
                             command=self.saveFile)
        filemenu.add_command(label="Open Text File                   ⌘T",
                             command=self.openText)
        filemenu.add_command(label="Save Text File", command=self.saveText)
        filemenu.add_separator()
        filemenu.add_command(label="Encrypt File                         ⌘E",
                             command=self.encryptFile)
        filemenu.add_command(label="Decrypt File                        ⌘D",
                             command=self.decryptFile)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=self.root.destroy)

        encryptmenu = Menu(self.root, tearoff=0)
        encryptmenu.add_checkbutton(label="Use Latest Encryption Method",
                                    command=self.setMethod,
                                    variable=self.useNewMethod)

        self.chatmenu = Menu(self.root, tearoff=0)
        self.chatmenu.add_command(
            label="Connect",
            command=lambda: self.connectToServer(self.server.get()))
        self.chatmenu.add_command(label="Disconnect",
                                  command=self.disconnectFromServer,
                                  state="disabled")
        self.chatmenu.add_separator()
        self.chatmenu.add_command(label="Settings", command=self.settings)

        viewmenu = Menu(self.root, tearoff=0)
        viewmenu.add_checkbutton(label="Word Wrap                        ⌘W",
                                 command=self.toggleWrap,
                                 variable=self.checked)
        viewmenu.add_command(label="Clear Screen",
                             command=lambda: self.txt.delete(1.0, END))
        viewmenu.add_separator()
        viewmenu.add_command(label="Increase Font                    ⌘Num+",
                             command=self.increaseFont)
        viewmenu.add_command(label="Decrease Font                   ⌘Num-",
                             command=self.decreaseFont)
        viewmenu.add_checkbutton(label="Always Ontop",
                                 command=lambda: self.root.wm_attributes(
                                     "-topmost", self.alwaysOntop.get()),
                                 variable=self.alwaysOntop)
        viewmenu.add_checkbutton(
            label="Fullscreen                                F11",
            command=self.toggleFullscreen,
            variable=self.fullscreen)
        viewmenu.add_separator()

        colrmenu = Menu(self.root, tearoff=0)

        colrmenu.add_radiobutton(
            label="Color Scheme 1                         F1",
            command=self.changeScheme,
            variable=self.scheme,
            value=1)
        colrmenu.add_radiobutton(
            label="Color Scheme 2                         F2",
            command=self.changeScheme,
            variable=self.scheme,
            value=2)
        colrmenu.add_radiobutton(
            label="Color Scheme 3                         F3",
            command=self.changeScheme,
            variable=self.scheme,
            value=3)
        colrmenu.add_radiobutton(
            label="Color Scheme 4                         F4",
            command=self.changeScheme,
            variable=self.scheme,
            value=4)
        colrmenu.add_radiobutton(
            label="Color Scheme 5                         F5",
            command=self.changeScheme,
            variable=self.scheme,
            value=5)
        colrmenu.add_radiobutton(
            label="Color Scheme 6                         F6",
            command=self.changeScheme,
            variable=self.scheme,
            value=6)
        colrmenu.add_radiobutton(
            label="Color Scheme 7                         F7",
            command=self.changeScheme,
            variable=self.scheme,
            value=7)
        colrmenu.add_radiobutton(
            label="Color Scheme 8                         F8",
            command=self.changeScheme,
            variable=self.scheme,
            value=8)
        colrmenu.add_radiobutton(
            label="Color Scheme 9                         F9",
            command=self.changeScheme,
            variable=self.scheme,
            value=9)
        viewmenu.add_cascade(label="Color Scheme", menu=colrmenu)

        soundmenu = Menu(self.root, tearoff=0)
        soundmenu.add_command(label="Play Sound When:", state="disabled")
        soundmenu.add_checkbutton(label="Chat has focus",
                                  command=self.saveConfiguration,
                                  variable=self.playSoundWithFocus)
        soundmenu.add_checkbutton(label="Chat doesn't have focus",
                                  command=self.saveConfiguration,
                                  variable=self.playSoundWithoutFocus)
        soundmenu.add_checkbutton(label="Recieving Messages",
                                  command=self.saveConfiguration,
                                  variable=self.playSoundOnRecieve)
        soundmenu.add_checkbutton(label="Sending Messages",
                                  command=self.saveConfiguration,
                                  variable=self.playSoundOnSend)
        soundmenu.add_separator()
        soundmenu.add_checkbutton(
            label="Mute                                 ⌘M",
            command=self.saveConfiguration,
            variable=self.mute)

        helpmenu = Menu(self.root, tearoff=0)
        helpmenu.add_command(label="Help", command=self.showHelp)
        helpmenu.add_command(label="About", command=self.showAbout)

        menubar = Menu(self.root)
        menubar.add_cascade(label="File", menu=filemenu)
        menubar.add_cascade(label="Encryption", menu=encryptmenu)
        menubar.add_cascade(label="Chat", menu=self.chatmenu)
        menubar.add_cascade(label="View", menu=viewmenu)
        menubar.add_cascade(label="Sound", menu=soundmenu)
        menubar.add_cascade(label="Help", menu=helpmenu)
        self.root.config(menu=menubar)

        self.chat = StringVar()

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

        self.txt = ScrolledText(self.root,
                                wrap=WORD,
                                fg='green',
                                bg='black',
                                font=("Courier", 14),
                                width=80,
                                insertbackground="red",
                                insertwidth=3,
                                maxundo=5,
                                undo=True)
        self.txt.grid(sticky=N + S + E + W)
        self.txt.rowconfigure(0, weight=1)
        self.txt.columnconfigure(0, weight=1)

        self.inputVar = StringVar()
        self.input = Entry(self.root,
                           textvariable=self.inputVar,
                           font=("Courier", 14),
                           width=115,
                           bg="gray",
                           fg="black")
        self.input.grid(sticky=N + S + E + W)
        self.input.bind("<Return>", self.sendText)
        self.input.rowconfigure(0, weight=1)
        self.input.columnconfigure(0, weight=1)
        self.input.focus()

        self.root.bind("<Command-s>", self.saveFile)
        self.root.bind("<Command-o>", self.openFile)
        self.root.bind("<Command-t>", self.openText)
        self.root.bind("<Command-d>", self.decryptFile)
        self.root.bind("<Command-e>", self.encryptFile)
        self.root.bind("<Command-+>", self.increaseFont)
        self.root.bind("<Command-=>", self.increaseFont)
        self.root.bind("<Command-minus>", self.decreaseFont)
        self.root.bind("<Command-a>", self.selectAll)
        self.root.bind("<Command-m>", self.toggleMute)
        self.root.bind("<F11>", self.toggleFullscreen)

        self.root.bind("<F1>", lambda (Event): self.setScheme(1))
        self.root.bind("<F2>", lambda (Event): self.setScheme(2))
        self.root.bind("<F3>", lambda (Event): self.setScheme(3))
        self.root.bind("<F4>", lambda (Event): self.setScheme(4))
        self.root.bind("<F5>", lambda (Event): self.setScheme(5))
        self.root.bind("<F6>", lambda (Event): self.setScheme(6))
        self.root.bind("<F7>", lambda (Event): self.setScheme(7))
        self.root.bind("<F8>", lambda (Event): self.setScheme(8))
        self.root.bind("<F9>", lambda (Event): self.setScheme(9))

        self.root.wm_iconbitmap("%s\\icon.ico" % getcwd())
        self.addText("IMSafe %s\nBy: Patrick T. Cossette\n\n" % self.version)
        self.network.updateCallback = self.recvMessage

        self.loadConfiguration()

    def setMethod(self):
        if self.useNewMethod.get():
            print "using new method"
            self.encryptionFunction = IMCrypt2.encryptText
            self.decryptionFunction = IMCrypt2.decryptText
        else:
            print "using old method"
            self.encryptionFunction = IMCrypt.encryptText
            self.decryptionFunction = IMCrypt.decryptText

    def toggleMute(self, Event):
        if self.mute.get():
            self.mute.set(0)
        else:
            self.mute.set(1)

    def saveConfiguration(self):
        f = file(r"%s\settings.conf" % getcwd(), 'w')
        f.write(
            "%d\n%s\n%s\n%s\n%s\n%s\n%s\n%s" %
            (self.scheme.get(), self.server.get(), self.username.get(),
             self.playSoundWithFocus.get(), self.playSoundWithoutFocus.get(),
             self.playSoundOnRecieve.get(), self.playSoundOnSend.get(),
             self.mute.get()))

        f.close()

    def loadConfiguration(self):
        try:
            f = file(r"%s\settings.conf" % getcwd(), 'r')
            settings = f.read()
            settings = settings.split("\n")
            if len(settings
                   ) < 8:  #Make sure the settings file is intact and complete
                self.saveDefaultSettings()
            else:
                self.scheme.set(int(settings[0]))
                self.server.set(settings[1])
                self.username.set(settings[2])
                self.playSoundWithFocus.set(int(settings[3]))
                self.playSoundWithoutFocus.set(int(settings[4]))
                self.playSoundOnRecieve.set(int(settings[5]))
                self.playSoundOnSend.set(int(settings[6]))
                self.mute.set(int(settings[7]))
                self.setScheme(self.scheme.get())

            f.close()
        except:  #make sure the file is actually there, and intact with proper values, if not, revert to default settings
            self.saveDefaultSettings()

    def saveDefaultSettings(self):
        f = file(r"%s\settings.conf" % getcwd(), 'w')
        f.write(
            "1\nhttp://www.example.com/imsafe/IMSafe.php\n%s\n1\n1\n1\n1\n0" %
            environ["USER"])
        f.close()

    def updateChatMenu(self):
        if self.connected:
            #self.txt["state"] = "disabled"
            self.chatmenu.entryconfig(0, state="disabled")
            self.chatmenu.entryconfig(1, state="normal")
        else:
            #self.txt["state"] = "normal"
            self.chatmenu.entryconfig(0, state="normal")
            self.chatmenu.entryconfig(1, state="disabled")

    def recvMessage(self, message):

        if message[0:6] == "update":
            message = message[6::]

            highlight = 5  #If the message is from the user, use a different highlight color for  the username ^_^
            allMessages = message.split("<message_separator>")

            for message in allMessages:
                seg = message.split("<time_separator>")
                name = seg[0]
                print "appending recipts"
                self.network.recipts.append(seg[1])  #Log this message recipt
                if seg[1] in self.all_recipts:
                    return

                self.all_recipts.append(seg[1])

                d = seg[2]  #Encrypted Message
                id = name.split(" ")[0][1::]
                if id == self.username.get():
                    #Sent a message!
                    highlight = 4
                    if self.playSoundOnSend.get():
                        self.notifacation(txt="send")
                else:
                    #Recieving a message!
                    if self.playSoundOnRecieve.get():
                        self.notifacation(txt="recv")

                self.addText(name)  #Usernames get fancy color shit.
                lines = len(self.txt.get(1.0, END).split("\n")) - 1
                columns = len(name)

                self.txt.tag_add(
                    str(self.tags), float(lines),
                    ".".join([str(lines), str(columns + 1)])
                )  #just for the record, the way the tag index works is F*****G RETARDED.
                self.txt.tag_config(
                    str(self.tags),
                    foreground=self.colorSchemes[self.scheme.get() -
                                                 1][highlight],
                    font=("courier", self.fontSize, "bold"))

                self.tags += 1
                self.txt.update_idletasks()
                self.txt.tag_add(
                    str(self.tags),
                    ".".join([str(lines),
                              str(len(name.split(" ")[0]) + 1)]),
                    ".".join([str(lines), str(columns)]))
                self.txt.tag_config(str(self.tags),
                                    font=("courier", self.fontSize - 1))

                self.tags += 1

                self.addText(self.decryptionFunction(d, self.key) + "\n")

        elif message[0:4] == "list":
            message = message[4::]
            self.addText("\n\nUsers currently logged in: \n")
            for user in message.split(","):
                self.addText(user + "\n")
                lines = len(self.txt.get(1.0, END).split("\n")) - 2
                columns = len(user)

                self.txt.tag_add(str(self.tags), float(lines),
                                 ".".join([str(lines),
                                           str(columns + 1)]))
                self.txt.tag_config(
                    str(self.tags),
                    foreground=self.colorSchemes[self.scheme.get() - 1][4])
                self.tags += 1

    def notifacation(self, txt="recv"):
        if self.mute.get(): return

        if (self.root.focus_displayof() and self.playSoundWithFocus.get()
                or (not self.root.focus_displayof()
                    and self.playSoundWithoutFocus.get())):
            threading._start_new_thread(self.playSound, ("%s.wav" % txt, ))

    def selectAll(self, event=None):
        return
        self.txt.focus_set()
        self.txt.tag_add(SEL, "1.0", END)
        self.root.after(4, self.selectAll)

    def toggleFullscreen(self, event=None):
        if event:
            if self.fullscreen.get():
                self.fullscreen.set(0)
            else:
                self.fullscreen.set(1)

        if self.fullscreen.get():
            self.previousSize = self.root.geometry()
            #self.root.geometry("%dx%d+0+0" % (self.root.winfo_screenwidth(), self.root.winfo_screenheight()))  #Using state("zoomed") instead. this method causes the user's text Entry bar to fall off the screen unless the window is maximized first
            self.root.state("zoomed")
            self.root.overrideredirect(1)

        else:
            self.root.state("normal")
            self.root.overrideredirect(0)
            self.root.geometry(self.previousSize)

    def increaseFont(self, event=None):
        geo = self.root.geometry()  #preserve window size
        self.fontSize += 1
        self.txt["font"] = ("courier", self.fontSize)
        self.input["font"] = ("courier", self.fontSize)
        self.root.geometry(geo)

    def decreaseFont(self, event=None):
        geo = self.root.geometry()
        if self.fontSize < 6: return
        self.fontSize -= 1
        self.txt["font"] = ("courier", self.fontSize)
        self.input["font"] = ("courier", self.fontSize)
        self.root.geometry(geo)

    def setScheme(self, s):
        self.scheme.set(s)
        self.changeScheme()

    def changeScheme(self):
        s = self.scheme.get() - 1
        self.txt["fg"] = self.colorSchemes[s][0]
        self.txt["bg"] = self.colorSchemes[s][1]
        self.txt["insertbackground"] = self.colorSchemes[s][2]
        self.input["bg"] = self.colorSchemes[s][3]

        if s > 5:  #Black on blue gets bold text =D
            self.txt["font"] = ("courier", self.fontSize, "bold")
            self.input["font"] = ("courier", self.fontSize, "bold")
        else:
            self.txt["font"] = ("courier", self.fontSize)
            self.input["font"] = ("courier", self.fontSize)

        self.saveConfiguration()

    def toggleWrap(self, event=None):
        if self.txt["wrap"] == WORD:
            self.txt["wrap"] = NONE
        else:
            self.txt["wrap"] = WORD

    def showHelp(self):
        self.addText(
            "\n\nCommands:\n /help - display this help screen\n /about - show the about page\n /clear - clear all text from the screen\n /me - send text in 3rd person\n /setkey <key> - change the encryption key to '<key>'\n /setname <name> - set your display name in the chatroom to '<name>'\n /list - Get a list of people currenlty logged on\n /settings - Show current settings\n /connect <ip address> - connect to an IMSafe server\n /disconnect - disconnect from the IMSafe server\n /exit - close the window\n\nThis software's encryption methods are only suitable for plain text. Attempting to encrypt videos, images, or any files other than those containing plain text will likely result in error!\n\nThe default key is \"Red Castle\", it is highly recommended that you change the key prior to using this software; the key will reset to the default every time the program is opened, for security purposes the key you choose is not remembered, you will have to re-enter it every time you wish to use this software, this can be done by going to Chat->Settings or using the /setkey command.\n\n"
        )

        #Highlight all the commands
        lines = len(self.txt.get(1.0, END).split("\n"))
        for a, b in zip(
            (7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17),
            ("6", "12", "9", "10", "6", "9", "8", "4", "7", "7", "6")):
            self.txt.tag_add(str(self.tags), float(lines - a),
                             ".".join([str(lines - a), b]))

        self.txt.tag_config(str(self.tags),
                            foreground=self.colorSchemes[self.scheme.get() -
                                                         1][4])

    def showAbout(self):
        self.addText(
            "\n\nCreated By: Patrick T. Cossette\nwww.DigitalDiscrepancy.com\n\nThis software is an example of a simple encryption algorithm. This software was written for the purpose of demonstration and experimentation and is probably not suitable to send or store sensitive information. Use at your own risk.\n\n Licensed under GNU General Public License, version 2, see LICENSE for more info"
        )
        lines = len(self.txt.get(1.0, END).split("\n"))
        self.txt.tag_add(str(self.tags),
                         float(lines - 7) + .12,
                         ".".join([str(lines - 7), '33']))
        self.txt.tag_config(str(self.tags),
                            foreground=self.colorSchemes[self.scheme.get() -
                                                         1][4])

    def encryptFile(self, event=None):
        f = self.openText(show=False)
        if not f: return
        self.saveFile(fileName=f[0], text=f[1])

    def decryptFile(
        self,
        event=None
    ):  #Attempt to decrypt something thats not encrypted and you'll lose that file. forever. seriously. don't do it.
        f = self.openFile(show=False)
        if not f: return
        self.saveText(fileName=f[0], text=f[1])

    def openText(self, event=None, show=True):
        fileName = tkFileDialog.askopenfilename(title="Open Text File",
                                                filetypes=[
                                                    ("Text File", ".txt"),
                                                    ("All Files", ".*")
                                                ])
        if fileName == "":
            return False
        self.txt.delete(1.0, END)

        open = file(fileName, 'r')
        text = open.read()

        if show: self.txt.insert(END, text)
        open.close()

        return (fileName, text)

    def saveText(self, event=None, fileName=None, text=None):
        if fileName == None:
            fileName = tkFileDialog.asksaveasfilename(title="Save Text File",
                                                      filetypes=[("Text File",
                                                                  ".txt"),
                                                                 ("All Files",
                                                                  ".*")])
            if fileName == "":
                return False
        if len(fileName) > 3:
            if fileName[-4::] != ".txt":
                fileName += ".txt"
        else:
            fileName += ".txt"

        save = file(fileName, 'w')
        if text:
            save.write(text)
        else:
            save.write(self.txt.get(1.0, END))
        save.close()

    def openFile(self, event=None, show=True):
        fileName = tkFileDialog.askopenfilename(title="Open Encrypted File",
                                                filetypes=[
                                                    ("Encrypted Text File",
                                                     ".txt"),
                                                    ("All Files", ".*")
                                                ])
        if fileName == "":
            return False

        self.txt.delete(1.0, END)

        open = file(fileName, 'rb')
        text = open.read()

        open.close()
        if show:
            self.txt.insert(END, self.decryptionFunction(text, self.key))
        else:
            return (fileName, self.decryptionFunction(text, self.key))

    def saveFile(self, event=None, fileName=None, text=False):
        if fileName == None:
            fileName = tkFileDialog.asksaveasfilename(
                title="Save Encrypted File",
                filetypes=[("Encrypted Text File", ".txt"),
                           ("All Files", ".*")])
            if fileName == "":
                return False

        if len(fileName) > 3:
            if fileName[-4::] != ".txt":
                fileName += ".txt"
        else:
            fileName += ".txt"

        save = file(fileName, 'wb')
        if text:
            save.write(self.encryptionFunction(text, self.key))
        else:
            save.write(
                self.encryptionFunction(self.txt.get(1.0, END), self.key))
        save.close()

    def sendText(self, event):
        text = self.inputVar.get()
        if not len(text): return
        if text[0] == "/":  #user has entered a command, not a message
            if len(text) > 5 and text[0:6] == "/clear":
                self.txt.delete(1.0, END)

            elif len(text) > 8 and text[0:7] == "/setkey":
                self.key = text.split("/setkey ")[1]

            elif len(text) > 9 and text[0:8] == "/setname":

                self.username.set(text.split("/setname ")[1])
                self.usernamePreview.set(self.username.get())
                self.network.screen_name = self.username.get()

                self.saveConfiguration()

            elif len(text) > 7 and text[0:8] == "/connect":
                if len(text) > 9 and text[0:9] == "/connect ":
                    self.server.set(text.split("/connect ")[1])
                    self.saveConfiguration()

                self.connectToServer(self.server.get())

            elif len(text) > 10 and text[0:11] == "/disconnect":
                self.disconnectFromServer()

            elif len(text) > 4 and text[0:5] == "/exit":
                self.root.destroy()

            elif len(text) > 4 and text[0:5] == "/help":
                self.showHelp()

            elif len(text) > 8 and text[0:9] == "/settings":
                self.addText(
                    "\n\nServer: %s\nUsername: %s\nkey: %s\n" %
                    (self.server.get(), self.username.get(), self.key))

            elif len(text) > 5 and text[0:6] == "/about":
                self.showAbout()

            elif len(text) > 2 and text[0:3] == "/me":
                self.sendChat(
                    text
                )  #This command will be caught within the sendChat function, as it is a message manipulator

            elif len(text) > 4 and text[0:5] == "/list":
                if self.connected:
                    self.network.list()  #List other users on the server
                else:
                    self.addText(
                        "You are not currently connected to a chatroom!\n")

            else:
                self.addText(
                    "Invalid Command - Type /help for a list of commands\n")

        else:
            self.sendChat(text)

        self.inputVar.set("")

    def playSound(self, sound):
        if self.playingSound:  #Prevent overlap!
            return

        return_code = subprocess.call(["afplay", sound])

        chunk = 1024

# Simple "fire and forget" notification

    doesntWorkonMac = """
		self.playingSound = True
		wf = wave.open(sound, 'rb')
		p = pyaudio.PyAudio()

		stream = p.open(format =
                p.get_format_from_width(wf.getsampwidth()),
                channels = wf.getnchannels(),
                rate = wf.getframerate(),
                output = True)

		data = wf.readframes(chunk)

		while data != '':
			stream.write(data)
			data = wf.readframes(chunk)

		stream.close()
		p.terminate()
		self.playingSound = False """

    def sendChat(self, message):

        if not self.connected:
            self.addText(
                "\nYou are not connected to an IMSafe server. Use the /connect command to connect to a server or go to Chat -> Connect\n\n"
            )
        else:
            print "\n\nsending  chat: ", message
            if len(message) > 4 and message[0:3] == "/me":
                responce = self.network.sendData(self.encryptionFunction(
                    message[4::], self.key),
                                                 options="first_person")
            else:
                responce = self.network.sendData(
                    self.encryptionFunction(message, self.key))
            if responce[0] != 2:
                self.connected = False
                self.updateChatMenu()
                self.addText(responce[1] + "\n")

            print "\n\nresponse: ", responce

    def addText(self, text):
        self.txt.insert(END, text)
        self.txt.yview(MOVETO, 1.0)
        #self.root.after(500, self.update_me)

    def show(self):
        self.loadConfiguration
        self.root.mainloop()

    def closeSettings(self):
        self.settingsUp = False

    def disconnectFromServer(self):
        self.addText("\n\nYou have disconnected from the server\n\n")
        self.network.disconnect()
        self.connected = False
        self.updateChatMenu()

    def connectToServer(self, address):
        self.network.screen_name = self.username.get()
        self.network.address = self.server.get()
        self.addText("\n\nConnecting to server at " + address + " ...\n\n")
        self.root.update()
        res = self.network.connect()
        if res[0]:
            self.connected = True
            self.addText(res[1] + "\n")
        else:
            self.connected = False
            self.addText("Connection Failed!\n\n%s\n" % res[1])
        self.updateChatMenu()

    def saveSettings(self):
        if self.txtKey.get() == "" or self.txtKey2.get() == "":
            showerror(
                "D=",
                "Your key can't be blank!\n\nPlease enter a valid key, the longer the better!."
            )
        elif self.txtKey.get() != self.txtKey2.get():
            showerror("D=", "The keys you entered do not match!")
        else:
            showinfo(":)", "Your settings haved been saved!")
            self.key = self.txtKey.get()

        self.username.set(self.usernamePreview.get())

        self.network.screen_name = self.username.get()
        self.network.address = self.server.get()
        self.saveConfiguration()
        self.master.focus_force()

    def settings(self):
        self.settingsUp = True

        self.master = Toplevel(self.root)
        self.master.title("Settings")
        self.master.wm_iconbitmap("%s\\icon.ico" % getcwd())
        if self.alwaysOntop.get():
            self.alwaysOntop.set(0)
            self.root.wm_attributes("-topmost", 0)
            self.addText("\"Always onotop\" feature deactivated\n")

        self.usernamePreview.set(self.username.get())

        self.keyTxt.set(self.key)
        self.keyTxt2.set(self.key)
        self.f = Frame(self.master)

        self.lblServer = Label(self.f, text="Server: ")
        self.lblServer.grid(row=0, column=0, sticky=E, pady=2, padx=2)
        self.txtServer = Entry(self.f, textvariable=self.server)
        self.txtServer.grid(row=0, column=1, pady=2, padx=2)

        self.lblUser = Label(self.f, text="Screename: ")
        self.lblUser.grid(row=1, column=0, sticky=E, pady=2, padx=2)
        self.txtUser = Entry(self.f, textvariable=self.usernamePreview)
        self.txtUser.grid(row=1, column=1, pady=2, padx=2)

        self.lblKey = Label(self.f, text="Key: ")
        self.lblKey.grid(row=2, column=0, sticky=E, pady=2, padx=2)
        self.txtKey = Entry(self.f, textvariable=self.keyTxt, show="*")
        self.txtKey.grid(row=2, column=1, pady=2, padx=2)

        self.lblKey2 = Label(self.f, text="Confirm: ")
        self.lblKey2.grid(row=3, column=0, sticky=E, pady=2, padx=2)
        self.txtKey2 = Entry(self.f, textvariable=self.keyTxt2, show="*")
        self.txtKey2.grid(row=3, column=1, pady=2, padx=2)
        self.f.grid(rowspan=2, columnspan=4)

        Button(self.master,
               width=15,
               text="Save Settings",
               command=self.saveSettings).grid(row=5, column=0, pady=4, padx=4)
        Button(self.master, width=15, text="Exit",
               command=self.master.destroy).grid(row=5,
                                                 column=1,
                                                 pady=4,
                                                 padx=4)

        self.master.focus_set()
        self.master.grab_set()
        self.root.wait_window(self.master)

        self.master.mainloop()
コード例 #6
0
class Textee:
    def __init__(self, master):
        self.master = master
        self.theme = 'dark' # the startup will always be opposite
        self.options = TexteeOptions()
        self.status_bar = TexteeStatusBar(master)
        self.create_menu(master)
        self.create_ui(master)
        self.set_bindings(master)
        self.file = None
        self.find_text = ''
        self.font_dialog = None
        self.find_and_replace_dialog = None
        self.windows = []
        
    def create_menu(self, master):
        self.menu = Menu(master)
        master.config(menu=self.menu)
        
        filemenu = Menu(self.menu)
        self.menu.add_cascade(label="File", menu=filemenu)
        filemenu.add_command(label="New", command=self.new_file)
        filemenu.add_command(label="Open...", command=self.open_file)
        filemenu.add_command(label="Save", command=self.save_file)
        filemenu.add_command(label="Save As", command=lambda: self.save_file(save_as=True))
        filemenu.add_separator()
        filemenu.add_command(label="New window", command=self.new_window)
        filemenu.add_separator()
        filemenu.add_command(label="Print", command=self.printer)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=self.exit)

        editmenu = Menu(self.menu)
        self.menu.add_cascade(label='Edit', menu=editmenu)
        editmenu.add_command(label='Copy', command=lambda: event_generate(self.editor, 'Copy'))
        editmenu.add_command(label='Paste', command=lambda: event_generate(self.editor, 'Paste'))
        editmenu.add_command(label='Undo', command=lambda: event_generate(self.editor, 'Undo'))
        editmenu.add_separator()
        editmenu.add_command(label='Goto', command=self.goto_line) # need to develop custom find with regex
        editmenu.add_command(label='Find', command=self.find) # need to develop custom find with regex
        editmenu.add_command(label='Find & Replace', command=self.find_and_replace) # need to test the replace logic in separate playground
        editmenu.add_separator()
        editmenu.add_command(label='Check spelling', command=self.spell_check) # need to see how to use system's grammer check.. if not possible remove it.

        formatmenu = Menu(self.menu)
        self.menu.add_cascade(label='Format', menu=formatmenu)
        formatmenu.add_command(label='Font', command=self.select_font) # pop-up to select system fonts
        formatmenu.add_checkbutton(label='Wrap', onvalue=True, offvalue=False, variable=self.options.wrap, command=self.toggle_wrap)
        
        viewmenu = Menu(self.menu)
        self.menu.add_cascade(label='View', menu=viewmenu)
        viewmenu.add_checkbutton(label='Status bar', onvalue=True, offvalue=False, variable=self.options.status_bar, command=lambda: self.status_bar.display(self.options.status_bar.get()))
        viewmenu.add_command(label='Toggle theme', command=self.toggle_theme)
        
        helpmenu = Menu(self.menu)
        self.menu.add_cascade(label="Help", menu=helpmenu)
        helpmenu.add_command(label="About", command=lambda : self.about())

    def create_ui(self, master):
        self.editor = ScrolledText(master, width=100, height=50, highlightthickness=0)
        self.editor.config(undo=True)
        self.editor.pack(expand=YES, fill='both', padx=0, pady=0)
        self.toggle_theme()
        #print_configs(self.editor)
        
        # Create pop-menu for the entire editor.. do some cool stuff with it
        self.editor.popmenu = Menu(self.master, tearoff=0)
        # TODO : later need to do smart copy/paste i.e. selected text copy of entire line copy
        self.editor.popmenu.add_command(label='Copy', command=lambda: event_generate(self.editor, 'Copy'))
        self.editor.popmenu.add_command(label='Paste', command=lambda: event_generate(self.editor, 'Paste'))
        # TODO : disable undo when not available, not sure if its possible. Need to check research later
        self.editor.popmenu.add_command(label='Undo', command=lambda: event_generate(self.editor, 'Undo'))
        self.editor.popmenu.add_separator()
        # TODO : 'share' this will be the best feature in the editor, share the file with the future textee sharing api
        self.editor.popmenu.add_command(label='Share', command=do_nothing)

        # add status bar by default, it can be hidden from menu
        self.status_bar.update_status('Hi there')
        
    def set_bindings(self, master):
        master.bind_class('Text', '<Control-a>', select_all)
        master.bind_class('Text', '<Control-s>', lambda event: self.save_file())
        master.bind_class('Text', '<Control-o>', lambda event: self.open_file())
        master.bind_class('Text', '<Control-n>', lambda event: self.new_file())
        master.bind_class('Text', '<Control-g>', lambda event: self.goto_line())
        master.bind_class('Text', '<Control-f>', lambda event: self.find())
        master.bind_class('Text', '<Control-p>', lambda event: self.printer())
        master.bind_class('Text', '<Control-;>', lambda event: self.find_and_replace()) # this function is only for temporoy use - for dev purpose only

        # editor section bindings only
        self.editor.bind('<Button-2>', self.show_right_click_menu) # for right-click
        self.editor.bind('<Button-3>', self.show_right_click_menu) # for middle-click (scroll press)

        #display the current cursor position
        self.display_current_position()


    def new_file(self):
        self.file = None
        self.editor.delete('1.0', END+'-1c') # clear all the contents

    def open_file(self):
        self.file = tkFileDialog.askopenfilename(parent=self.master,title='Select a file')
        if self.file != None and self.file != '':
            self.editor.delete('1.0', END+'-1c') # clear all the contents
            infile = open(self.file, 'r')
            contents = infile.read()
            self.editor.insert('1.0',contents)
            infile.close()

    def save_file(self, save_as=False):
        data = self.editor.get('1.0', END+'-1c')
        save_as_file = None

        # if saving the file by creation
        if self.file == None or save_as == True:
            save_as_file = tkFileDialog.asksaveasfilename() # attempt to select the filename, the user can select cancel so check agian below

        # the above could result in None if the user cancels the dialog
        if save_as_file:
            self.file = save_as_file

        # final check, as both the above could result in None
        if self.file != None:
            outfile = open(self.file, 'w')
            outfile.write(data)
            outfile.close()

    def goto_line(self):
        lineno = tkSimpleDialog.askinteger('Textee', 'Goto line:')
        if lineno > 0:
            self.editor.mark_set(INSERT, lineno + 0.0) #convert to float
            self.editor.see(INSERT)
        self.editor.focus_set()

    def toggle_theme(self):
        if self.theme == 'light':
            self.editor.config(bg='black', fg='white', insertbackground='white',highlightcolor='black')
            self.editor.frame.config(bg='black')
            # theme for misspelled words
            self.editor.tag_configure("misspelled", foreground="red", underline=True)
            self.theme = 'dark'
        else:
            self.editor.config(bg='white', fg='black', insertbackground='black',highlightcolor='white')
            self.editor.frame.config(bg='white')
            # theme for misspelled words
            self.editor.tag_configure("misspelled", foreground="red", underline=True)
            self.theme = 'light'

    def toggle_wrap(self):
        # self.editor.cget('wrap') # gets the config value
        if not self.options.wrap.get():
            self.editor.config(wrap='none')
        else:
            self.editor.config(wrap='word')

    def find(self):
        find_text = tkSimpleDialog.askstring("Textee", "Enter text to search", initialvalue=self.find_text)
        if find_text:
            if find_text == self.find_text:
                start_pos = self.editor.search(find_text, self.editor.index('insert'), stopindex=END, nocase=True)
            else:
                start_pos = self.editor.search(find_text, '1.0', stopindex=END, nocase=True)
                
            self.find_text = find_text
            if(start_pos):
                end_pos = '%s+%sc' % (start_pos, len(self.find_text))
                self.editor.tag_add(SEL, start_pos, end_pos)
                self.editor.mark_set(INSERT, end_pos) # mark the cursor to end of find text to start editing
                self.editor.see(INSERT) # bing the cursor position in the viewport incase of long text causinng scrollbar
                self.editor.focus_set() # strangely tkinter doesnt return focus after prompt
            else:
                tkMessageBox.showinfo("Textee", "No morw matches found")
        else:
            self.editor.focus_set() # strangely tkinter doesnt return focus after prompt

    def find_and_replace(self):
        #show the custom dialog
        self.find_and_replace_dialog = TexteeFindAndReplaceDialog(self.master)
        if self.find_and_replace_dialog.find_text:
            start_pos = self.editor.search(self.find_and_replace_dialog.find_text, '1.0', stopindex=END, nocase=True)
            # lazy recursive replace for all the matched elements, no need to parse whole dataset again and again
            while start_pos:
                self.editor.delete(start_pos, '%s+%sc' % (start_pos, len(self.find_and_replace_dialog.find_text)))
                self.editor.insert(start_pos, self.find_and_replace_dialog.replace_with)
                # break after first replace if replace all flag is off
                if not self.find_and_replace_dialog.replace_all:
                    break
                start_pos = self.editor.search(self.find_and_replace_dialog.find_text, '%s+%sc' % (start_pos, len(self.find_and_replace_dialog.replace_with)), stopindex=END, nocase=True)


    def select_font(self):
        self.font_dialog = TexteeFontDialog(self.master)
        fs = 12 # default size for any font selected

        if self.font_dialog.selected_font_family:
            ff = self.font_dialog.selected_font_family
        
        if self.font_dialog.selected_font_size:
            fs = self.font_dialog.selected_font_size

        print ff, fs, " - font properties"

        if ff and fs > 0:
            self.default_font = tkFont.Font(self.master, family=ff, size=fs)
            self.editor.config(font=self.default_font)

    def show_right_click_menu(self, event):
        print 'going to display popmenu at', event.x_root, event.y_root
        try:
            self.editor.popmenu.tk_popup(event.x_root, event.y_root, 0)
        finally:
            # TODO: not sure why we need this, pasting it from the documentation. Later check to remove it
            self.editor.popmenu.grab_release()

    def spell_check(self):
        # check if the dictonary exists in the system (only mac and linux have it at this location)
        # TODO: to check on windows how to do?
        print "inside the spell check"
        if not os.path.exists('/usr/share/dict/words'):
            return

        with open('/usr/share/dict/words', 'r') as words_file:
            system_words = words_file.read().split('\n') 
            current_file_lines = self.editor.get('1.0', END+'-1c').split('\n') 

            for lineno, current_line in enumerate(current_file_lines):
                current_line_words = re.split('\W', current_line)
                columnposition = 0 # this is to ignore the white space with which we split above, the marking of the invalid word should be be without the space
                for word in current_line_words:
                    start_index = '%s.%s' % (lineno+1, columnposition)
                    end_index = '%s+%dc' % (start_index, len(word))
                    if word in system_words:
                        self.editor.tag_remove('misspelled', start_index, end_index)
                    else:
                        self.editor.tag_add('misspelled', start_index, end_index)
                    columnposition += len(word)+1 # take into account the space
     
    def display_current_position(self):
        cursor_position =  self.editor.index("insert").replace('.', ',')
        self.status_bar.update_status(cursor_position)
        self.master.after(self.status_bar.update_interval, self.display_current_position)

    def printer(self):
        if not os.path.exists('/usr/bin/lpr'):
            tkMessageBox.showerror('Printing is not supported with your operating system')
            return
        lpr = subprocess.Popen('/usr/bin/lpr', stdin=subprocess.PIPE)
        text = self.editor.get('1.0', END+'-1c')
        lpr.stdin.write(text)
        lpr.stdin.close()

    def new_window(self):
        #allow multiple windows to be opened
        root = Tkinter.Tk(className=" Textee")
        root.title("Textee - A Stupid Text Editor")
        app = Textee(root)
        self.windows.append(app)
        root.mainloop()
        

    def about(self):
        tkMessageBox.showinfo("About", "Textee - A stupid text editor")

    def exit(self, master):
        if tkMessageBox.askokcancel("Quit", "Are you sure?"):
            master.destroy()
コード例 #7
0
class MainWnd:
    def __init__(self, parent):
        self.search_str = StringVar()
        self.parent = parent

        root.protocol("WM_DELETE_WINDOW", self.ask_quit)

        self.parent.title("snippets")
        self.parent.configure(padx=10, pady=10)
        self.parent.minsize(630, 480)
        self.create_widgets()

        db_path = os.path.join(abspath(dirname(__file__)), "snip.db")
        db_exists = os.path.isfile(db_path)
        self.connection = sqlite3.connect(db_path)
        self.connection.row_factory = dict_factory
        self.cursor = self.connection.cursor()

        if not db_exists:
            self.cursor.execute('create table snippet (caption, content)')

        self.fill_list()
        self.snip_content.focus_set()

    def ask_quit(self):
        if tkMessageBox.askokcancel("Quit", "You want to quit now?"):
            self.parent.destroy()

    def __del__(self):
        self.connection.close()

    def create_widgets(self):
        self.search_box = Entry(self.parent, textvariable=self.search_str)
        self.search_str.set("New snippet")
        self.search_box.pack(fill=X)

        self.toolbar_f = Frame(self.parent, pady=5)
        self.toolbar_f.pack(fill=X)

        self.newbtn = Button(self.toolbar_f, text="New", command=self.on_new)
        self.newbtn.pack(side=LEFT)

        self.savebtn = Button(self.toolbar_f,
                              text="Save",
                              command=self.on_save)
        self.savebtn.pack(side=LEFT)

        self.updatebtn = Button(self.toolbar_f,
                                text="Update",
                                command=self.on_update)
        self.updatebtn.pack(side=LEFT)

        self.delbtn = Button(self.toolbar_f,
                             text="Delete",
                             command=self.on_delete)
        self.delbtn.pack(side=LEFT)

        self.copybtn = Button(self.toolbar_f,
                              text="Copy to clipboard",
                              command=self.on_copy)
        self.copybtn.pack(side=LEFT)

        self.quitbtn = Button(self.toolbar_f,
                              text="Quit",
                              command=self.on_quit)
        self.quitbtn.pack(side=LEFT)

        self.pwin = PanedWindow(self.parent, showhandle=True)
        self.pwin.pack(fill=BOTH, expand=1)

        self.list_f = Frame(self.pwin)
        self.list_sb = Scrollbar(self.list_f, orient=VERTICAL)
        self.snip_list = Listbox(self.list_f, yscrollcommand=self.list_sb.set)
        self.list_sb.config(command=self.snip_list.yview)
        self.snip_list.bind('<ButtonRelease-1>', self.on_snippet_selected)
        self.snip_list.pack(side=LEFT, fill=BOTH, expand=1)
        self.list_sb.pack(side=RIGHT, fill=Y)
        self.pwin.add(self.list_f)
        self.pwin.paneconfigure(self.list_f, minsize=177)

        self.snippetFont = Font(family="courier", size=11, weight=NORMAL)
        self.snip_content = ScrolledText(self.pwin,
                                         height=20,
                                         width=40,
                                         padx=5,
                                         pady=5,
                                         font=self.snippetFont)
        self.pwin.add(self.snip_content)

    # noinspection PyTypeChecker
    def fill_list(self):
        self.snip_list.delete(0, END)
        self.cursor.execute('select * from snippet')
        for r in self.cursor.fetchall():
            self.snip_list.insert(END, r['caption'])

    def on_new(self):
        self.search_str.set("")
        self.snip_content.delete(1.0, END)

    def on_save(self):
        self.cursor.execute(
            'insert into snippet (caption,content) values (?,?)', (
                self.search_str.get(),
                self.snip_content.get(1.0, END),
            ))
        self.connection.commit()
        self.fill_list()

    def on_update(self):
        self.cursor.execute(
            'update snippet set content=? where caption=?',
            (self.snip_content.get(1.0, END), self.search_str.get()))
        self.connection.commit()

    def on_delete(self):
        index = self.snip_list.curselection()[0]
        seltext = self.snip_list.get(index)
        self.cursor.execute('delete from snippet where caption=?', (seltext, ))
        self.connection.commit()
        self.snip_list.delete(ANCHOR)
        self.on_new()

    def on_copy(self):
        self.parent.clipboard_clear()
        self.parent.clipboard_append(self.snip_content.get(1.0, END))

    def on_quit(self):
        self.parent.destroy()

    # noinspection PyTypeChecker
    def on_snippet_selected(self, _):
        try:
            index = self.snip_list.curselection()[0]
        except IndexError:
            return
        selected_text = self.snip_list.get(index)
        self.snip_content.delete(1.0, END)
        self.cursor.execute('select * from snippet where caption=?',
                            (selected_text, ))
        r = self.cursor.fetchone()
        if r['caption']:
            self.search_str.set(r['caption'])
        if r['content']:
            self.snip_content.insert(INSERT, r['content'])
        self.snip_content.focus_set()
コード例 #8
0
ファイル: projectoop.py プロジェクト: NandishRPatel/PowerPad
class mainwindow:
    def __init__(self, master):
        self.master = master
        if os.path.exists("C:\Python27") or os.path.exists("C:\Python36-32"):

            self.frame2 = tk.LabelFrame(
                self.master,
                text="Editor",
                width=800,
                height=self.master.winfo_screenheight(),
                bd=5)
            self.frame3 = tk.LabelFrame(
                self.master,
                text="Output",
                width=self.master.winfo_screenwidth() - 830,
                height=(self.master.winfo_screenheight()) / 2,
                bd=5)
            self.frame2.grid(row=1, column=0, padx=8)
            self.frame2.pack_propagate(0)
            self.frame3.grid(row=1, column=1, sticky='nw')
            self.frame3.pack_propagate(0)
            self.textPad = ScrolledText(self.frame2, width=800, height=1000)
            self.textPad.focus_set()
            self.textPad.bind('<KeyPress>', self.onKeyPress)
            self.textPad.bind('<Control-Key-a>', self.select_all)
            self.textPad.bind('<Control-Key-A>', self.select_all)
            self.outputpad = Text(self.frame3, width=450, height=400)
            self.textPad.pack()
            self.outputpad.pack()
            self.outputpad.configure(state='disabled')
            self.filename = ""
            self.final_data = ""
            self.entry = 0
            self.s = wincl.Dispatch("SAPI.SpVoice")
            self.s.Rate = 1
            global voice
            self.special_char = {
                '(': 'Parenthesis L',
                ')': 'Parenthestis R',
                '[': 'Bracket L',
                ']': 'Bracket R',
                '{': 'Curly Braces L',
                '}': 'Curly Braces R',
                '<': 'Angle Bracket L',
                '>': 'Angle Bracket R',
                ':': 'Colon',
                '!': 'Exclamation Mark',
                '~': 'Tilde',
                '^': 'Caret',
                '-': 'Hyphen',
                ' ': 'Space',
                '|': 'Pipe',
                ';': 'Semicolon',
                '\'': 'Single Quote',
                '"': 'Double Quote',
                '?': 'Question Mark',
                ',': 'Comma',
                '.': 'Period'
            }
            if os.path.exists("C:\Python27\PowerPad"): pass
            else: os.makedirs("C:\Python27\PowerPad")
            os.chdir("C:\\Python27\\PowerPad")
            os.environ["PATH"] += os.pathsep + "C:\Python27\PowerPad"
        else:
            tkMessageBox.showerror("Python Not Found",
                                   "Sorry, no Python available")
            s = wincl.Dispatch("SAPI.SpVoice")
            s.Rate = 1
            s.Speak(
                "python is not installed, Please intall python on your Computer"
            )
            self.master.destroy()

    def speak(self, string):
        self.s.Speak(string)

    def select_all(self, event):
        self.textPad.tag_add(SEL, "1.0", END)
        self.textPad.mark_set(INSERT, "1.0")
        self.textPad.see(INSERT)
        return 'break'

    def outputconf(self):
        self.outputpad.configure(state='normal')
        self.outputpad.insert('end', '>>> Running Your Code\n')
        self.outputpad.configure(state='disabled')

    def alreadysave(self, data, filename):
        self.speak("SAVING " + filename)
        self.saved_file = open(filename, "w+")
        self.saved_file.write(data)
        self.saved_file.close()

    def popup(self):
        self.w = popupWindow(self.master)
        self.w.e.focus_set()
        self.master.wait_window(self.w.top)
        self.filename = self.w.val

    def open_file(self):
        try:
            self.speak("ENTER THE FILE NAME WITHOUT EXTENSION AND PRESS ENTER")
            self.master.bell()
            self.popup()
            file = open(self.filename, "r")
            contents = file.read()
            self.textPad.delete('0.0', 'end')
            self.outputpad.configure(state='normal')
            self.outputpad.delete('0.0', 'end')
            self.outputpad.configure(state='disabled')
            self.textPad.insert('1.0', contents)
            file.close()
            self.final_data = self.textPad.get('1.0', END + '-1c')
            self.textPad.focus_set()
            self.frame2.configure(text=self.filename)
        except IOError:
            pass

    def SaVe(self, data):
        self.final_data = self.data
        if not self.filename:
            self.speak("ENTER THE FILE NAME WITHOUT EXTENSION AND PRESS ENTER")
            self.master.bell()
            self.popup2()
            if str(self.filename) in os.listdir("C:\\Python27\\PowerPad"):
                if self.onreplace() == "yes":
                    self.alreadysave(self.data, self.filename)
                    self.textPad.focus_set()
                else:
                    self.speak("ENTER THE NAME AGAIN")
                    self.popup2()
                    self.SaVe(self.data)
            else:
                self.SaVe(self.filename)
        else:
            self.alreadysave(self.data, self.filename)
        self.textPad.focus_set()
        self.frame2.configure(text=self.filename)

    def popup2(self):
        self.w1 = popupWindow1(self.master)
        self.w1.e1.focus_set()
        self.master.wait_window(self.w1.top1)
        self.filename = self.w1.val1

    def outputgen(self, filename):
        process = subprocess.Popen(["python", filename],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        self.output = process.stdout.readlines()
        self.error = process.stderr.readlines()
        process.wait()
        '''if not 'prompt' in os.environ:
			self.speak("input")
			print("in")'''

        if self.error:
            self.speak("Error")
            self.errorsay(self.error)
        else:
            self.speak("Output")
            self.outputsay(self.output)

    def errorline(self, error):
        s = ""
        for i in error:
            if not "line" in i:
                pass
            else:
                s += i
        x = s.split(",")
        s = ""
        for i in x:
            if not "line" in i:
                pass
            else:
                s += i
        return s

    def errorsay(self, error):
        s = self.errorline(error)
        x = ((error[-1].split(":"))[0]) + " ON THE "
        self.outputpad.configure(state='normal')
        self.outputpad.insert('end', x + s)
        self.outputpad.configure(state='disabled')
        l = s.split(' ')
        errorline = (self.textPad.get('1.0', END +
                                      '-1c').split("\n"))[int(l[-1][0]) - 1]
        self.textPad.mark_set("insert",
                              "%d.%d" % (int(l[-1][0]), len(errorline)))
        self.speak(x)
        self.speak(s)
        for i in errorline:
            if i in self.special_char.keys(): self.speak(self.special_char[i])
            else: self.speak(i)

    def outputsay(self, output):
        self.outputpad.configure(state='normal')
        for i in output:
            self.speak(i)
            self.outputpad.insert('end', i)
        self.outputpad.configure(state='disabled')

    def onexit(self):
        self.speak("PRESS Y TO EXIT AND N TO CANCEL")
        self.master.bell()
        return tkMessageBox.askquestion("Exit", "Are You Sure?")

    def onopen(self):
        self.speak(
            "THERE ARE SOME UNSAVED CHANGES DO YOU WANT TO SAVE THE FILE BEFORE OPEN A FILE?"
        )
        self.speak("PRESS Y TO SAVE AND N TO CANCEL")
        self.master.bell()
        return tkMessageBox.askquestion("Save and Open", "Are You Sure?")

    def onsave(self):
        self.speak(
            "THERE ARE SOME UNSAVED CHANGES DO YOU WANT TO SAVE THE FILE BEFORE EXIT?"
        )
        self.speak("PRESS Y TO SAVE AND N TO CANCEL")
        self.master.bell()
        return tkMessageBox.askquestion("Save and Exit", "Are You Sure?")

    def onreplace(self):
        self.speak(
            "THERE ALREADY EXIXT FILE WITH THE SAME NAME, DO YOU WANT TO REPLACE IT ?"
        )
        self.speak("PRESS Y TO REPLACE AND N TO CANCEL")
        self.master.bell()
        return tkMessageBox.askquestion("Replace", "Are You Sure?")

    def pressf1(self):
        if self.final_data != self.data:
            if self.onsave() == "yes":
                self.SaVe(self.data)
                self.final_data = ""
                self.filename = ""
                self.textPad.delete('0.0', 'end')
            else:
                self.final_data = ""
                self.filename = ""
                self.textPad.delete('0.0', 'end')
        else:
            self.final_data = ""
            self.filename = ""
            self.textPad.delete('0.0', 'end')

        self.outputpad.configure(state='normal')
        self.outputpad.delete('0.0', 'end')
        self.outputpad.configure(state='disabled')
        self.frame2.configure(text="Editor")
        self.speak("Opening a new Tab")

    def pressf2(self):
        if self.final_data != self.data:
            if self.onopen() == "yes":
                self.SaVe(self.data)
                self.final_data = ""
                self.filename = ""
                self.textPad.delete('0.0', 'end')
                self.open_file()
            else:
                self.alreadysave(self.data, self.filename)
                self.final_data = ""
                self.filename = ""
                self.textPad.delete('0.0', 'end')
                self.open_file()
        else:
            self.open_file()

    def pressf4(self):
        if not self.final_data == self.data:
            if self.onsave() == "yes":
                self.SaVe(self.data)
                self.master.destroy()
            else:
                self.master.destroy()
        else:
            if self.onexit() == "yes": self.master.destroy()
            else: pass

    def pressf5(self):
        if self.filename:
            self.outputconf()
            self.alreadysave(self.data, self.filename)
            self.outputgen(self.filename)
        else:
            self.SaVe(self.data)
            self.outputconf()
            self.outputgen(self.filename)

    def pressf8(self):
        global voice
        if voice == 0:
            voice = 1
            self.s.Voice = self.s.GetVoices().Item(voice)
        else:
            voice = 0
            self.s.Voice = self.s.GetVoices().Item(voice)

    def pressf11(self):
        self.speak("INSTRUCTIONS ARE ")
        self.speak(
            "PRESS F1 FOR NEW FILE, F2 TO OPEN FILE, F3 TO SAVE FILE, F4 TO EXIT, F5 TO COMPILE, F6 TO LISTEN ALL CODE, F7 TO CLEAR ALL, F8 TO CHANGE VOICE, F9 TO KNOW ABOUT US, F11 FOR INSTRUCTIONS"
        )

    def onKeyPress(self, event):
        #global self.filename
        #self.speak(event.keysym)
        #print(event.keysym)
        global row, col
        row, col = self.textPad.index('insert').split('.')
        self.data = self.textPad.get('1.0', END + '-1c')

        if event.keysym == "F1": self.pressf1()

        elif event.keysym == "F2":
            self.speak("OPENING")
            if self.data == "": self.open_file()
            else: self.pressf2()

        elif event.keysym == "F3":
            self.speak("SAVING")
            if self.data == "": pass
            else: self.SaVe(self.data)

        elif event.keysym == "F4":
            self.speak("EXITING")
            if self.data == "":
                if self.onexit() == "yes": self.master.destroy()
                else: pass
            else: self.pressf4()

        elif event.keysym == "F5":
            self.speak("COMPILE")
            if self.data == "": pass
            else: self.pressf5()

        elif event.keysym == "F6":
            self.speak("CODE IS")
            self.speak(self.data)

        elif event.keysym == "F7":
            self.speak("CLEARING ALL CODE")
            self.textPad.delete("0.0", 'end')

        elif event.keysym == "F8":
            self.speak("CHANGING VOICE")
            self.pressf8()

        elif event.keysym == "F9":
            #self.speak("ABOUT Us");
            self.speak("CREATED BY NANDISH PATEL")

        elif event.keysym == "F11":
            self.speak("INSTRUCTIONS")
            self.pressf11()

        else:
            pass