当前位置: 首页>>代码示例>>Python>>正文


Python ScrolledText.get方法代码示例

本文整理汇总了Python中ScrolledText.get方法的典型用法代码示例。如果您正苦于以下问题:Python ScrolledText.get方法的具体用法?Python ScrolledText.get怎么用?Python ScrolledText.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScrolledText的用法示例。


在下文中一共展示了ScrolledText.get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class editor:
    def __init__(self, rt):
        if rt == None:
            self.t = Tk()
        else:
            self.t = Toplevel(rt)
        self.t.title("Tkeditor %d" % len(t1))
        self.bar = Menu(rt)

        self.filem = Menu(self.bar)
        self.filem.add_command(label="打开", command=self.openfile)
        self.filem.add_command(label="新建", command=neweditor)
        self.filem.add_command(label="保存", command=self.savefile)
        self.filem.add_command(label="关闭", command=self.close)
        self.filem.add_separator()
        self.filem.add_command(label="退出", command=die)

        self.helpm = Menu(self.bar)
        self.helpm.add_command(label="关于", command=about)
        self.bar.add_cascade(label="文件", menu=self.filem)
        self.bar.add_cascade(label="帮助", menu=self.helpm)
        self.t.config(menu=self.bar)

        self.f = Frame(self.t, width=512)
        self.f.pack(expand=1, fill=BOTH)

        self.st = ScrolledText(self.f, background="white")
        self.st.pack(side=LEFT, fill=BOTH, expand=1)

        self.open = Button(self)
        self.open["text"] = "open"
        self.open["fg"] = "Blue"
        self.open["command"] = self.openfile
        self.open.pack({"side": "left"})
        self.open.pack({"anchor": "nw"})

    def close(self):
        self.t.destroy()
        print "close"

    def openfile(self):
        p1 = END
        oname = askopenfilename(filetypes=[("Python file", "*.*")])
        if oname:
            for line in fileinput.input(oname):
                self.st.insert(p1, line)
            self.t.title(oname)

    def savefile(self):
        sname = asksaveasfilename()
        if sname:
            ofp = open(sname, "w")
            ofp.write(self.st.get(1.0, END))
            ofp.flush()
            ofp.close()
            self.t.title(sname)
开发者ID:shawn0lee0,项目名称:OMOOC2py,代码行数:58,代码来源:notebook_.py

示例2: __init__

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class editor:
    def __init__(self,rt):

        self.top=Tk()
        self.top.title('记事本')
        self.top.geometry('300x400')
        self.bar=Menu(self.top)
  
        self.filem=Menu(self.bar)
        self.filem.add_command(label="打开",command=self.openfile)
        self.filem.add_command(label="新建",command=self.neweditor)
        self.filem.add_command(label="保存",command=self.savefile)
        self.filem.add_command(label="关闭",command=self.close)

        self.helpm=Menu(self.bar)
        self.helpm.add_command(label="Help",command=self.about)
        self.bar.add_cascade(label="文件",menu=self.filem)
        self.bar.add_cascade(label="帮助",menu=self.helpm)
        self.top.config(menu=self.bar)
  
        self.f=Frame(self.top,width=512)
        self.f.pack(expand=1,fill=BOTH)
  
        self.st=ScrolledText(self.f,background="white")
        self.st.pack(side=LEFT,fill=BOTH,expand=1)
        
    def close(self):
        self.top.destroy()
 
    def openfile(self):
        p1=END
        oname=askopenfilename()#filetypes=[("Python file","*.*")])
        if oname:
            for line in fileinput.input(oname):
                self.st.insert(p1,line)
                self.top.title(oname)
 
    def savefile(self):
        sname=asksaveasfilename()
        if sname:
            ofp=open(sname,"w")
            ofp.write(self.st.get(1.0,END).encode('utf-8'))
            ofp.flush()
            ofp.close()
            self.top.title(sname)
 
    def neweditor(self):
        global root
        self.top.append(editor(root))
        
        
    def about(self):
        tkMessageBox.showwarning("Tkeditor",'What?\n记事本也要帮助?')
开发者ID:wsywxywr,项目名称:free-mini,代码行数:55,代码来源:final.py

示例3: Add_Group

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class Add_Group(Frame):
	def __init__(self, parent, app):
		Frame.__init__(self, parent)
		self.parent = parent
		self.app = app

		#Frame to hold Keyword Group new Entry and new keywords text box
		addKGFrame = Frame(parent, bg="#E8E8E8", relief=RAISED)
		addKGFrame.pack(fill=BOTH, expand=True, side=LEFT, padx=10, pady=10)

		#Label for Entry Box
		addGroupLabel = Label(addKGFrame, text="Enter New Group Name",bg="#E8E8E8")
		addGroupLabel.pack(side=TOP)

		#Entry Box for new Keyword Group
		self.addGroup = Entry(addKGFrame, width=30, relief=SUNKEN)
		self.addGroup.pack(side=TOP, fill=X, expand=True, pady=5)

		#Label for New Keywords for Group Text Box
		addKGLabel = Label(addKGFrame, text="Enter New Keywords (Optional)",bg="#E8E8E8")
		addKGLabel.pack(side=TOP, fill=X, expand=True, pady=5)

		#Canvas for Text Box to Enter New Keywords for New Group
		addKGCanvas = Canvas(addKGFrame, bg="#E8E8E8", relief=SUNKEN)
		addKGCanvas.pack(side=TOP, fill=BOTH, expand=True, pady=5)

		#Keywords for new group scrollable text box
		self.addKGText = ScrolledText(addKGCanvas, wrap=WORD, width=25, 
			height=15, relief=SUNKEN, highlightthickness=0, bd=1, padx=1, pady=1)
		self.addKGText.pack(fill=BOTH, side=TOP, expand=True)

		#Button to add new Keyword Group and Keywords
		addKGButton = Button(addKGFrame, text="Add Group", 
			width=30, highlightbackground='#E8E8E8', command=self.group_add)
		addKGButton.pack(side=TOP, fill=BOTH, expand=True)

	#Function to add the keyword group
	def group_add(self):
		newGroup = self.addGroup.get()
		if newGroup != "":
			self.app.key_group.keyword_groups[newGroup] = []

			text = self.addKGText.get('1.0', 'end-1c').splitlines()
			for line in text:
				self.app.key_group.keyword_groups[newGroup].append(line)
			self.app.Groups.groupList.delete(0, END)
			for x in self.app.key_group.keyword_groups:
				self.app.Groups.groupList.insert(END, '%s' % x)

			self.addKGText.delete('1.0', END)
			self.addGroup.delete(0, END)
开发者ID:Cmiller9,项目名称:KW_GRPR,代码行数:53,代码来源:KwGui.py

示例4: LogWindow

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class LogWindow(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master.title("Network Simulator Log")
        self.text = ScrolledText(self)
        self.text.pack(fill=BOTH, expand=1)
        self.pack(fill=BOTH, expand=1)
        self.text.config(
            background="black",
            foreground="white",
            font=Font(
                family="Courier", weight="bold"),
            # state=DISABLED,
            wrap=NONE, )

        self.text.tag_config("DEBUG", foreground="green")
        self.text.tag_config("ERROR", foreground="red")
        self.text.tag_config("CRITICAL", foreground="red")
        self.text.tag_config("EXCEPTION", foreground="red")
        self.text.tag_config("WARNING", foreground="yellow")
        self.text.tag_config("INFO", foreground="white")

        self.text.bind("<Key>", lambda e: 'break')
        self.text.bind("<Return>", self._clear)
        self.queue = Queue()
        self._update()

    def _clear(self, event):
        self.text.delete(1.0, END)
        return 'break'

    def _update(self):
        try:
            while True:
                text, level = self.queue.get(block=False)

                at_bottom = self.text.yview()[1] == 1.0
                # self.text.config(state=NORMAL)
                if len(self.text.get(1.0, END).strip()) != 0:
                    text = "\n" + text
                self.text.insert(END, text, str(level))
                # self.text.config(state=DISABLED)
                if at_bottom:
                    self.text.yview_moveto(1.0)
        except Empty:
            pass
        self.after(50, self._update)

    def append(self, entry, level="INFO"):
        self.queue.put((entry, level))
开发者ID:VladJamir,项目名称:cmsc135,代码行数:52,代码来源:logviewer.py

示例5: __init__

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
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()
#.........这里部分代码省略.........
开发者ID:cenan,项目名称:snpptmngr,代码行数:103,代码来源:snip.py

示例6: PyGrbl_Editor

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class PyGrbl_Editor(Frame):
    def __init__(self, master, app):
        Frame.__init__(self, master = master)

        ##  WHO AM I ?
        #print("Who am I:  " + self.winfo_class())  # = 'Frame' !!
        #print("Who is my master: " + master.__class__.__name__) # = Frame
        #print("Who is my app: " + app.__class__.__name__) # = PyGrbl_GUI
        #print("Who am I:  " + self.__class__.__name__) # = 'PyGrbl_Editor'

        self.app = app
        self.app.servicemenu.entryconfig("Editor", state = "normal")
        self.app.apps.append(self.__class__.__name__)
        self.openFileTrace = self.app.fileOpenFlag.trace_variable('w', self.fileOpenTraceAction)

        self.editorWaiting = False # to prevent conflict gCodeChecker & Editor 'fileOpenTrace'

        self.createEditorWidgets()
        
        self.master.rowconfigure(0, weight = 1)
        self.master.columnconfigure(0, weight = 1)
        self.grid(column = 0, row = 0, sticky = (N, S, W, E))


    def createEditorWidgets(self):
        # Text Pad
        self.textPad = ScrolledText(self, width = 30, height = 10, font = "TkTextFont")
        self.textPad.grid(row = 0, column = 0, padx = 10, pady = 10, sticky = (N, S, W, E))
        self.columnconfigure(0, weight = 1)
        self.rowconfigure(0, weight = 1)

        self.save = Button(self, text = "Save", width = 6, command = lambda: self.saveFile())
        self.save.grid(row = 0, column = 1, padx = 10, pady = 10, sticky = N)

    def fileOpenTraceAction(self, name, index, mode):
        try:
            if self.app.fileOpenFlag.get() == True:
                if self.app.currentApp == self.app.Editor:
                    contents = self.app.inFile.read()
                    contents = contents.replace('\r', '')
                    self.app.inFile.seek(0) # reset inFile cursor to top of file
                    self.textPad.insert(1.0, contents)
                elif self.editorWaiting:
                    contents = self.app.inFile.read()
                    self.app.inFile.seek(0) # reset inFile cursor to top of file
                    self.textPad.insert(1.0, contents)
                    self.editorWaiting = False
                else:
                    self.editorWaiting = True
                    self.after(1000, self.fileOpenTraceAction(name, index, mode))

            elif self.app.fileOpenFlag.get() == False:
                self.textPad.delete(1.0, END)

            if self.app.debugMode > 1: print("fileOpenTraceAction: Ok")

        except:
            print("fileOpenTraceAction: Error")

    def saveFile(self):
        filename = asksaveasfile(mode = 'w')
        if filename:
            data = self.textPad.get(1.0, END+'-1c')
            filename.write(data)
            filename.close()
开发者ID:daisyfox,项目名称:PyGrbl-WiP,代码行数:67,代码来源:PyGrbl_GUI.py

示例7: diary

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class diary(Frame):

 def __init__(self,rt):
    if rt == None:
      self.t=Tk()    #创建顶层窗口t
    else:
      self.t=Toplevel(rt) #使用toplevel窗口模式
    self.t.title("窗口- %d"%len(t1))
    Frame.__init__(self,rt)
    self.pack(fill=BOTH, expand=1)
    


    '''定义按钮'''
    '''Possible values are specified as compass directions:
    "n" (north, or top edge), "ne", (north-east, or top right corner), 
    "e", "se", "s", "sw", "w", "nw" or "center".
    Layout布局
    pack side :It can be top, bottom, left and right. The default is top
    color: color names (e.g. "red") or hex RGB codes (e.g. "#ff340a").
    anchor :Pack widget will be anchored to specific side if the width is less than space is assigned. The valid edges are n,e,w,s(东西南北)
    '''

    self.f=Frame(self,width=512)
    self.f.pack(expand=1,fill=BOTH)
   
    self.st=ScrolledText(self.f,background="beige")
    self.st.tag_configure('bold_italics', font=('Arial', 12, 'bold', 'italic'))
    self.st.tag_configure('big', font=('Verdana', 20, 'bold'))
    self.st.tag_configure('color', foreground='#476042', 
                        font=('Tempus Sans ITC', 12, 'bold'))
    self.st.pack(side=LEFT,fill=BOTH,expand=1)
    
    self.open = Button(self)
    self.open["text"] = "打开文件"
    self.open["fg"] = "Blue"
    self.open["command"] = self.diary_open_txt
    self.open.pack({"side":"left"})
    self.open.pack({"anchor":"nw"})
    
    self.newfile = Button(self)
    self.newfile["text"] = "新建"
    self.newfile["fg"] = "black"
    self.newfile["command"] = neweditor
    self.newfile.pack({"side":"left"})
    self.newfile.pack({"anchor":"nw"})
   
    self.save = Button(self)
    self.save["text"] = "保存"
    self.save["fg"] = "black" 
    self.save["command"] = self.savefile
    self.save.pack({"side":"left"})
    self.save.pack({"anchor":"n"})
    
    self.quit = Button(self)
    self.quit["text"] = "关闭"
    self.quit["fg"] = "red"
    self.quit["command"] = self.close
    self.quit.pack({"side":"left"})
    self.quit.pack({"anchor":"center"})

    self.guan_yu = Button(self)
    self.guan_yu["text"] = "关于"
    self.guan_yu["fg"] = "red"
    self.guan_yu["command"] = lambda:self.about1()
    '''lambda后面跟的是表达式,注意调用函数需要增加()
    可以多试试它,挺不错的'''
    self.guan_yu.pack({"side":"right"})
    self.guan_yu.pack({"anchor":"center"})

    self.contents = StringVar()
    self.ent=Entry(self,textvariable=self.contents)    #http://effbot.org/tkinterbook/entry.htm
    self.ent.pack({"side":"bottom"},expand=1,fill='x')
    self.ent.bind("<Enter>",self.entry_enter)
    
 def entry_enter(self,event):
    entry_text = self.contents.get()
    print entry_text
    self.st.insert(END,entry_text)
    self.ent.delete(0,'end') #输入完成清空输入框信息
    


#定义打开文件函数    
 def diary_open_txt(self):
    p1=END
    oname=askopenfilename(filetypes=[("文本文件","*.txt*")])
    txt_open=codecs.open(oname, 'r', "GB2312")
    txt_read=txt_open.read()
    print txt_read
    if oname:
     for line in txt_read:  #fileinput.input(oname): 更新为
      self.st.insert(p1,line,'color') #调用字体
    
    '''
    if oname:
        for line in fileinput.input(oname):  #fileinput.input(oname): 更新为
         self.st.insert(p1,line)
         '''

#.........这里部分代码省略.........
开发者ID:beyondcly,项目名称:OMOOC2py,代码行数:103,代码来源:main.py

示例8: quit_error_label

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
    global g_name,f_param_name,f_param_type,g_type,f_isfunc
    g_name = None
    g_type = None
    f_param_name = []
    f_param_type = []
    f_isfunc = False

###################################### UI Segment ######################################

def quit_error_label():
	src_program = textPad.get('1.0',END)
	file_writer = open('src_program.c','w')
	file_writer.write(src_program.strip())
	file_writer.close()
	root.destroy()

def print_error(err_msg):
	global error_label
	# parser.stop_yacc()
	label = Label(text=err_msg)
	label.pack()
	# button = Button(text='Quit', command=quit_error_label)
	# button.pack()

textPad.pack()
src_program = textPad.get('1.0',END)
lexer = lex.lex()
parser = yacc.yacc()
parser.parse(src_program)

root.mainloop()
开发者ID:dpkm95,项目名称:13CS306,代码行数:33,代码来源:main.py

示例9: MemoPadFrame

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class MemoPadFrame( Frame ):

    def __init__(self, master=None):
        Frame.__init__(self, master)

        # Modelの初期化
        self.version = (0, 2, 5)
        self.memos = MemoPad()
        self.memos.addObserver(self)

        # change-logger のバインド
        self.changeLogger = ChangeLogger()
        self.memos.addObserver( self.changeLogger )

        # View-Controller の初期化
        self.master.title( 'MemoPad %d.%d.%d' % self.version )
        self.make_listPanel(self)
        self.make_editAria(self)
        self.pack(fill=BOTH)

        # データの復帰
        self.memos.loadImage()


        def bye():
            self.saveMemo()    # 現在編集中のメモをセーブ
            self.memos.saveImage()

            print 'bye'
            self.master.destroy()

        self.master.protocol('WM_DELETE_WINDOW', bye )


    def make_listPanel(self, parent):
        frm = Frame(parent)

        # リストの生成・配置
        def changeTarget(evt):
            try: index = int(self.memoList.curselection()[0])
            except: index = None

            self.saveMemo()
            if index != None: self.selectMemo( index )


        self.memoList = ScrolledListbox(frm,
                                        selectmode=BROWSE,
                                        width=72,
                                        height=7 )
        self.memoList.bind("<ButtonRelease>", changeTarget )
        self.memoList.bind('<B1-Motion>', changeTarget )
        self.memoList.pack(side=LEFT, fill=BOTH)


        # ボタンの作成
        btnfrm = Frame(frm)

        def appendMemo():
            self.saveMemo()
            self.memos.appendMemo()

        Button( btnfrm,
                text='new',
                command=appendMemo ).pack(side=TOP, fill=X)


        def deleteMemo():
            self.saveMemo()
            self.memos.removeMemo()

        Button( btnfrm,
                text='delete',
                command=deleteMemo ).pack(side=TOP, fill=X)


        btnfrm.pack(side=LEFT)

        frm.pack(side=TOP, fill=X)



    def make_editAria(self, parent):
        self.text = ScrolledText( parent )
        self.text.pack(side=TOP, fill=BOTH)

        def updateTitle(evt):
            '''実験コード。まだ
            改行や行末改行の削除に弱いです
            '''
#            print self.text.index('1.end')
#            print self.text.index(INSERT)

            if self.text.index(INSERT).split('.')[0] == '1': # 1行目
                itemnum = self.memos.getSelectedIndex()

                self.memoList.delete(itemnum)
                self.memoList.insert(itemnum,
                             "%s | %s" % (self.memos[itemnum].getDatetime().strftime("%Y-%m-%d %H:%M"),
                                          u'%s%s%s' % ( self.text.get('1.0', INSERT), 
#.........这里部分代码省略.........
开发者ID:minekoa,项目名称:memopad,代码行数:103,代码来源:memopad.py

示例10: TextEditor

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class TextEditor(EventBasedAnimationClass):

    @staticmethod
    def make2dList(rows, cols):
        # From 15-112 class notes
        a=[]
        for row in xrange(rows): a += [[0]*cols]
        return a

    @staticmethod
    def readFile(filename, mode="rt"):
        # From 15-112 class notes
        # rt = "read text"
        with open(filename, mode) as fin:
            return fin.read()

    @staticmethod
    def writeFile(filename, contents, mode="wt"):
        # From 15-112 class notes
        # wt = "write text"
        with open(filename, mode) as fout:
            fout.write(contents)


    def highlightError(self, lineNumber):
        # highlights error in the code based on line number
        self.textWidget.tag_remove("error",1.0,END)
        self.textWidget.tag_add("error", "%d.0"%lineNumber,
            "%d.end"%lineNumber)
        self.textWidget.tag_config("error", underline = 1)

    def colorIsBlack(self, color):
        # ranks whether a color is nearing black or white
        color = color[1:]
        count = int(color,16)
        if(count<(16**len(color) -1 )/2):
            return True
        return False

    def styleTokens(self,tokenisedText,colorScheme,
                    startIndex,seenlen,seenLines,flag):
        # apply style to tokens in the text
        for token in tokenisedText:
            styleForThisToken = colorScheme.style_for_token(token[0])
            if(styleForThisToken['color']):
                self.currentColor = "#" + styleForThisToken['color'] 
            else:
                if(self.colorIsBlack(colorScheme.background_color)):
                    self.currentColor = "White"
                else: self.currentColor = "Black"
            if(token[1] == "\n"): seenLines += 1
            if(seenLines > 23 and flag): break
            # the '#' is to denote hex value
            textWidget = self.textWidget
            newSeenLen = seenlen + len(token[1])
            textWidget.tag_add(startIndex+"+%dc"%seenlen,
                startIndex+"+%dc"%(seenlen),
                startIndex+"+%dc"%(newSeenLen))
            self.textWidget.tag_config(startIndex+"+%dc"%seenlen,
                foreground = self.currentColor)
            seenlen = newSeenLen

    def checkErrors(self):
        # checks whether there is an error in the code by parsing it
        # and analysing the traceback
        errors = MyParse().pythonCodeContainsErrorOnParse(self.currentText)
        if(errors[0]):
            try:
                lineNumber=int(errors[1][-5][errors[1][-5].find("line ")+5:])
            except:
                lineNumber=int(errors[1][-7][errors[1][-7].find("line ")+5:])
            self.highlightError(lineNumber)
        else:
            self.textWidget.tag_remove("error",1.0,END)

    def highlightText(self,lineCounter = "1",columnCounter = "0",flag = False):
        # highlight text since syntax mode is on
        text = self.currentText.split("\n")
        text = "\n".join(text[int(lineCounter)-1:])
        startIndex = lineCounter + "." + columnCounter
        seenlen, seenLines = 0,0
        tokenisedText = pygments.lex(text, self.lexer)
        if(self.colorScheme):
            colorScheme = pygments.styles.get_style_by_name(self.colorScheme)
        else:
            colorScheme = pygments.styles.get_style_by_name(
                self.defaultColorScheme)
        if(self.colorIsBlack(colorScheme.background_color)):
            self.insertColor = "White"
        else: self.insertColor = "Black"
        self.textWidget.config(background = colorScheme.background_color,
            highlightbackground = colorScheme.highlight_color,
            highlightcolor = colorScheme.highlight_color,
            insertbackground = self.insertColor)
        self.styleTokens(tokenisedText,colorScheme,startIndex,seenlen,
            seenLines, flag)
        if(self.fileExtension == ".py" and self.errorDetectionMode):
            self.checkErrors()

    def editDistance(self,currentWord, word):
#.........这里部分代码省略.........
开发者ID:manikpanwar,项目名称:CollaborativeCoder,代码行数:103,代码来源:textEditor.py

示例11: terminalApp_tk

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]

#.........这里部分代码省略.........
		self.terminal4 = Tkinter.Entry(self,textvariable=self.terminalVariable4)#Create text box
		self.terminal4.grid(column=0, row=6,sticky='EW')						#Align in GUI
		self.terminal4.bind("<Return>", self.commandEnter4)						#Add "enter key" event handler to text box
		self.terminalVariable4.set(defaultCommands[4])							#Set textbox default text	
		
		self.lumpText = ScrolledText(self, undo=True, wrap=WORD, width = 25, height = 5)
		self.lumpText.grid(column=0,row=8,columnspan=2,sticky='EW')
		
		#Buttons
		button0 = Tkinter.Button(self,text=u"Send 1",command=self.commandButton0)	#Create button with OnButtonClick event handler
		button0.grid(column=1,row=2)
		
		button1 = Tkinter.Button(self,text=u"Send 2",command=self.commandButton1)	#Create button with OnButtonClick event handler
		button1.grid(column=1,row=3)
		
		button2 = Tkinter.Button(self,text=u"Send 3",command=self.commandButton2)	#Create button with OnButtonClick event handler
		button2.grid(column=1,row=4)

		button3 = Tkinter.Button(self,text=u"Send 4",command=self.commandButton3)	#Create button with OnButtonClick event handler
		button3.grid(column=1,row=5)
		
		button4 = Tkinter.Button(self,text=u"Send 5",command=self.commandButton4)	#Create button with OnButtonClick event handler
		button4.grid(column=1,row=6)
		
		button5 = Tkinter.Button(self,text=u"Send Bulk Commands", 
									width=35, command=self.commandButton5)			#Create button with OnButtonClick event handler
		button5.grid(column=0,row=9,columnspan=2)
		
		self.seperator0 = Frame(height=2,bd=1,relief=SUNKEN,bg='#000000')
		self.seperator0.grid(column=0,row=1,columnspan=2,padx=0,pady=5,sticky='EW')
		
		self.seperator1 = Frame(height=2,bd=1,relief=SUNKEN,bg='#000000')
		self.seperator1.grid(column=0,row=7,columnspan=2,padx=0,pady=10,sticky='EW')
		
		#Labels
		#self.labelVariable = Tkinter.StringVar()
		#label = Tkinter.Label(self,textvariable=self.labelVariable,	#Create label
		#						anchor="w",fg="white",bg="blue")	
		#label.grid(column=0,row=5,columnspan=2,sticky='EW')
		#self.labelVariable.set(u"")
		
		self.grid_columnconfigure(0,weight=1)							#Resize columns and rows when window is resized
		self.resizable(True,False)										#Prevent vertical sizing
		self.update()													#Render Objects
		self.geometry(self.geometry())									#Fix box size to box size
		#self.terminal0.focus_set()										#Set focus to entry box
		#self.terminal0.selection_range(0, Tkinter.END)					#Select text in entry box
		
	def logCheckFunction(self):
		global log
		terminalProcess.loggingStatus = self.logCheckValue.get()
		if (terminalProcess.loggingStatus == 0):
			if (log.closed == False):
				log.close()
		elif (terminalProcess.loggingStatus == 1):
			if (log.closed == True):
				log = open((os.path.join(os.path.dirname(sys.executable),'terminal_tools_log.txt')), 'a')

	def commandEnter0(self, event):
		self.commandButton0()
	def commandEnter1(self, event):
		self.commandButton1()
	def commandEnter2(self, event):
		self.commandButton2()
	def commandEnter3(self, event):
		self.commandButton3()
	def commandEnter4(self, event):
		self.commandButton4()	
			
	def commandButton0(self):
		terminalProcess.command = self.terminalVariable0.get() + '\r'
		terminalProcess.writeInterrupt = 1
		#self.labelVariable.set("Command 1" + terminalProcess.confirmation)			#Set label to textbox + "enter" on hitting return
		
	def commandButton1(self):
		terminalProcess.command = self.terminalVariable1.get() + '\r'
		terminalProcess.writeInterrupt = 1											#Interrupt to write to serial
		#self.labelVariable.set("Command 2" + terminalProcess.confirmation)			#Set label to success or failure
		
	def commandButton2(self):
		terminalProcess.command = self.terminalVariable2.get() + '\r'
		terminalProcess.writeInterrupt = 1
		#self.labelVariable.set("Command 3" + terminalProcess.confirmation)			#Set label to success or failure
		
	def commandButton3(self):
		terminalProcess.command = self.terminalVariable3.get() + '\r'
		terminalProcess.writeInterrupt = 1											#Interrupt to write to serial
		#self.labelVariable.set("Command 4" + terminalProcess.confirmation)			#Set label to success or failure
		
	def commandButton4(self):
		#self.labelVariable.set(terminalProcess.confirmation)						#Set label to textbox + "enter" on hitting return
		terminalProcess.command = self.terminalVariable4.get() + '\r'
		terminalProcess.writeInterrupt = 1		
		#self.labelVariable.set("Command 5" + terminalProcess.confirmation)			#Set label to success or failure
		
	def commandButton5(self):
		commandLumpText = self.lumpText.get(1.0, END)
		commandSplit = commandLumpText.split('\n')
		terminalProcess.commandArray = commandSplit
		terminalProcess.writeInterrupt = 2	
开发者ID:eebrenner,项目名称:TerminalTools,代码行数:104,代码来源:terminalTools.py

示例12: __init__

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
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
#.........这里部分代码省略.........
开发者ID:rajeshvaya,项目名称:playground-textee,代码行数:103,代码来源:Textee.py

示例13: __init__

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import get [as 别名]
class SimpleTextEditor:

    def __init__(self, parent):
        self.parent = parent
        self.textWidget = ScrolledText(parent, width=80, height=50, font=(tkFont.Font(family= "Consolas", size= "12")))
        self.textWidget.pack()

        self.menuBar = tk.Menu(parent, tearoff=0)
        # About Menu
        self.about_menu = tk.Menu(self.menuBar, tearoff= 0)
        self.menuBar.add_cascade(label= "Text Perfect", menu= self.about_menu)
        self.about_menu.add_command(label= "About", command= self.about_command)

        # File Menu
        self.file_menu = tk.Menu(self.menuBar, tearoff = 0)
        self.menuBar.add_cascade(label = "File", menu=self.file_menu)
        self.file_menu.add_command(label="New", command=self.new_command, accelerator="Cmd+N")
        self.parent.bind_all("<Command-n>", self.new_command)
        self.parent.bind_all("<Command-N>", self.new_command)
        self.file_menu.add_command(label="New Tab", command=self.new_tab, accelerator="Cmd+Opt+N")
        self.parent.bind_all("<Command-Option-n>", self.new_tab)
        self.parent.bind_all("<Command-Option-N>", self.new_tab)
        self.file_menu.add_separator()
        self.file_menu.add_command(label="Open", command=self.open_command, accelerator="Cmd+O")
        self.parent.bind_all("<Command-o>", self.open_command)
        self.parent.bind_all("<Command-O>", self.open_command)
        self.file_menu.add_command(label="Save", command=self.save_command, accelerator="Cmd+S")
        self.parent.bind_all("<Command-s>", self.save_command)
        self.parent.bind_all("<Command-S>", self.save_command)
        self.file_menu.add_separator()
        self.file_menu.add_command(label= "Quit", command= self.exit_program, accelerator="Cmd+W")
        self.parent.bind_all("<Command-w>", self.exit_program)
        self.parent.bind_all("<Command-W>", self.exit_program)

        # Edit Menu
        self.edit_menu = tk.Menu(self.menuBar, tearoff=0)
        self.menuBar.add_cascade(label= "Edit", menu= self.edit_menu)
        self.edit_menu.add_command(label = "Cut", command = self.cut_command, accelerator="Cmd+X")
        self.parent.bind_all("<Command-Shift-x>", self.cut_command)
        self.parent.bind_all("<Command-Shift-X>", self.cut_command)
        self.edit_menu.add_command(label = "Copy", command = self.copy_command, accelerator="Cmd+C")
        self.parent.bind_all("<Command-Shift-c>", self.copy_command)
        self.parent.bind_all("<Command-Shift-C>", self.copy_command)
        self.edit_menu.add_command(label = "Paste", command = self.paste_command, accelerator="Cmd+V")
        self.parent.bind_all("<Command-Shift-v>", self.paste_command)
        self.parent.bind_all("<Command-Shift-V>", self.paste_command)
        self.edit_menu.add_separator()
        self.edit_menu.add_command(label= "Find", command= self.find_command)

        parent.config(menu=self.menuBar)
        
##################################################

    def open_command(self, event=None):
        file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Select a file')
        if file != None:
            contents = file.read()
            self.textWidget.insert("1.0",contents)
            file.close()

    def save_command(self, event=None):
        file = tkFileDialog.asksaveasfile(mode= 'w')
        if file != None:
            data = self.textWidget.get("1.0", END+'-1c')   #strip trailing \n at EOF
            file.write(data)
            file.close()

    def exit_program(self, event=None):
        if tkMessageBox.askokcancel("Quit", "Are you sure you want to quit?"):
            self.parent.destroy()
     
    #Opens up new text widget correctly but screws up closing the parent window via the menu       
    def new_command(self, event=None):
        win = Toplevel()
        SimpleTextEditor.__init__(self, win)
        
    #Currently under construction    
    def new_tab(self, event=None):
        #self.parent.add(self.textWidget, text="new tab", state='normal')
        new_frame = tk.Frame(self.parent)
        self.parent.add(new_frame, text='new', state='normal')
        
    def cut_command(self, event=None):
        text = self.textWidget.get(SEL_FIRST, SEL_LAST)
        self.textWidget.delete(SEL_FIRST, SEL_LAST)
        self.textWidget.clipboard_clear()
        self.textWidget.clipboard_append(text) 
        
    def copy_command(self, event=None):
        text = self.textWidget.get(SEL_FIRST, SEL_LAST)
        self.textWidget.clipboard_clear()
        self.textWidget.clipboard_append(text)
        
    def paste_command(self, event=None):
        try:
            text = self.textWidget.selection_get(selection= 'CLIPBOARD')
            self.textWidget.insert(INSERT, text)
        except TclError:
            pass
            
#.........这里部分代码省略.........
开发者ID:austenLacy,项目名称:simple-OSX-text-editor,代码行数:103,代码来源:text_editor.py


注:本文中的ScrolledText.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。