def show(self): if self.class_: self.root = Toplevel(slef.master, class_=self.class_) else: self.root = Toplevel(self.master) self.root.title(self.title) self.root.iconname(self.title) self.frame = Frame(self.root, padx=5, pady=5) self.stf = Frame(self.frame) stext = ScrolledText(self.stf, bg='white', height=20, width=120) stext.insert(END, self.text) stext.pack(fill=BOTH, side=LEFT, expand=True) stext.focus_set() self.stf.pack(expand=True, fill=BOTH) self.frame.pack(expand=True, fill=BOTH) self.root.bind('<Return>', self.return_evt) b = Button(self.frame, text='Close', width=10, command=self.wm_delete_window) b.pack(side=TOP, pady=5) self.root.protocol('WM_DELETE_WINDOW', self.wm_delete_window) self._set_transient(self.relx, self.rely) self.root.wait_visibility() self.root.grab_set() self.root.mainloop() self.root.destroy()
def history(self): from ScrolledText import ScrolledText win = ScrolledText(Toplevel(), width=100) history = self.guicommander.gethistory() win.insert(END, history) win.pack(expand=1, fill=BOTH) win.focus_set()
def example(): import __main__ from Tkconstants import END stext = ScrolledText(bg='white', height=10) stext.insert(END, __main__.__doc__) f = Font(family="times", size=30, weight="bold") stext.tag_config("font", font=f) stext.insert(END, "Hello", "font") stext.pack(fill=BOTH, side=LEFT, expand=True) stext.focus_set() stext.mainloop()
class Application(Frame): def runCode(self): import traceback reload(main) s = main.Scm() #print self.editor.get("1.0", "end-1c") code = self.editor.get("1.0", "end-1c") try: code = s.sh("(begin %s)"%code) self.output.delete("1.0", "end-1c") self.output.insert("1.0", code) except Exception as e: code = str(e) self.output.delete("1.0", "end-1c") self.output.insert("1.0", code) traceback.format_exc() if ShowDebugInfo: tkMessageBox.showwarning("Error", traceback.format_exc()) #traceback.print_exc() self.output.delete("1.0", "end-1c") self.output.insert("1.0", code) def help(self): code = """A Simple Editor For Casuistry Scheme""" self.output.delete("1.0", "end-1c") self.output.insert("1.0", code) def createWidgets(self): self.debug = Checkbutton(self,text="debug") self.quit = Button(self,text="Quit",command=self.quit) self.run = Button(self,text="Run",command= self.runCode) self.help = Button(self,text="Help",command=self.help) self.editor = ScrolledText(wrap="word") self.output = ScrolledText(wrap="word",height=7) self.debug.pack({"side": "left"}) self.run.pack({"side": "left"}) self.help.pack({"side": "left"}) self.quit.pack({"side": "left"}) self.output.pack(side=BOTTOM,expand=TRUE,fill=BOTH) self.editor.pack(side=BOTTOM,expand=TRUE,fill=BOTH) self.editor.focus_set() def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.createWidgets()
class PopupScrolledTextWindow(basicWindow): """ Creates a modal dialog window with only a multi-line text input box (with scrollbar), and a few buttons. Useful for displaying text that the user should be able to select/copy, or for input. """ def __init__(self, master, message='', defaultText='', title='', width=100, height=8, button1Text='Ok'): basicWindow.__init__(self, master, windowTitle=title) self.entryText = '' # Add the explanation text and text input field self.label = ttk.Label(self.window, text=message) self.label.pack(pady=5) self.entry = ScrolledText(self.window, width=width, height=height) self.entry.insert('end', defaultText) self.entry.pack(padx=5) # Add the confirm/cancel buttons buttonsFrame = ttk.Frame(self.window) self.okButton = ttk.Button(buttonsFrame, text=button1Text, command=self.cleanup) self.okButton.pack(side='left', padx=10) ttk.Button(buttonsFrame, text='Cancel', command=self.cancel).pack(side='left', padx=10) buttonsFrame.pack(pady=5) # Move focus to this window (for keyboard control), and pause execution of the calling function until this window is closed. self.entry.focus_set() master.wait_window( self.window ) # Pauses execution of the calling function until this window is closed. def cleanup(self, event=''): self.entryText = self.entry.get('1.0', 'end').strip() self.window.destroy() def cancel(self, event=''): self.entryText = '' self.window.destroy()
lines= str(len(raw.split("\n"))) chars=str(len(raw.replace("\n",""))) raw = raw.translate(string.maketrans("",""), string.punctuation) a= str(" ".join(raw.split())) if chars=="0" and lines == "1": wordcount.set("0 Words 0 Lines 0 Characters") else: b=a.split(" ") if b[0]=="": wordcount.set("0 Words "+lines+ " Lines "+chars+" Characters") else: wordcount.set(str(len(b))+" Words "+lines+ " Lines "+chars+" Characters") master.after(100,autoupdate) wordcount=StringVar() textbox = ScrolledText(master) textbox.pack() textbox.focus_set() textbox.event_generate('<<Paste>>') textbox.bind('<Control-a>', highlightall) textbox.bind('<Control-A>', highlightall) words=Label(master,textvariable=wordcount) words.pack(side=BOTTOM,padx=20) autoupdate() mainloop()
def __init__(self, master): Client.__init__(self) self.started = False # use it to not try stopping if didn't start self.parent = master # used to distroy it on exit master.title("TomIRC") # app's title master.resizable(0, 0) # user cannot resize it # master.config(width = 720, height = 526) # master.grid_propagate(False) # doesn't change size because of inner elements result = InitialDialog(master, "Connection settings").result if not result: self.onExit() return self.started = True self.start(result[0], result[1]) self.name = result[2] master.protocol("WM_DELETE_WINDOW", self.onExit) # add a menu menu = Menu(master) master.config(menu = menu) filemenu = Menu(menu) menu.add_cascade(label = "File", menu = filemenu) filemenu.add_command(label = "Change your username", command = self.changeName) filemenu.add_separator() filemenu.add_command(label = "Quit", command = self.onExit) menu.add_command(label = "About", command = self.aboutBox) # use a menu entry as an information bar menu.add_command(label = " ", state = DISABLED) menu.add_command(label = "Connected to %s:%s as %s" % (result[0], result[1],\ self.name), state = DISABLED, background = "gray", \ font = tkFont.Font(family = "Times", weight = tkFont.BOLD,\ size = 10)) menu.add_command(label = " ",\ state = DISABLED) menu.add_command(label = " Connected users ",\ state = DISABLED, background = "gray", \ font = tkFont.Font(family = "Times", weight = tkFont.BOLD, \ size = 10)) menu.config(disabledforeground = "#777") self.menu = menu # list of connected users self.connectedUsers = StringVar() # used to update the userList self.userList = Listbox(master, height = 15, width = 21, selectmode = MULTIPLE, \ listvariable = self.connectedUsers) self.userList.bind('<<ListboxSelect>>', self.onListSelect) # self.connectedUsers.set("default_user\n" + self.name) # add widget for displaying incoming text text = ScrolledText(master, height = 20, width = 75, state = DISABLED) text.tag_config("a", background = "lightgray") # set a tag for the author text.tag_config('s', background = "darkgray") # set a tag for the server self.display = text # add the text input text = ScrolledText(master, height = 5, width = 75) text.bind('<KeyRelease-Return>', self.sendMessage) text.focus_set() self.input = text # add a label to state errors and warnings self.infoLabel = StringVar(value = "Registered successfully...") label = Label(master, textvariable = self.infoLabel, anchor = W, fg = "#555") label.grid(row = 2, column = 0, columnspan = 2, sticky = W) self.display.grid(row = 0, column = 0, sticky = N) self.input.grid(row = 1, column = 0) self.userList.grid(row = 0, column = 1, rowspan = 2, sticky = N + S) self.send("REG " + self.name) # register the user self.populateList()
class BlockdiagEditor(object): """ Interactive editor UI for blockdiag """ def __init__(self, diag_method, source, diag_image): self.diag_method = diag_method self.source = intern(source.encode("utf-8")) self.image_format = "PNG" self.tmp = NamedTemporaryFile(mode="wb") self.root = Tk.Tk() self.root.geometry("1024x768") self.root.protocol("WM_DELETE_WINDOW", self.quit) # Frames self.frame = Tk.Frame(self.root) self.frame.master.title("blockdiag editor") self.frame.pack(fill=Tk.BOTH, expand=1, padx=3, pady=3) self.btn_frame = Tk.Frame(self.frame) self.btn_frame.pack(fill=Tk.BOTH, padx=3, pady=3) self.text_frame = Tk.Frame(self.frame) self.text_frame.pack(fill=Tk.BOTH, expand=1, padx=3, pady=3) self.image_frame = Tk.Frame(self.frame) self.image_frame.pack(fill=Tk.BOTH, expand=1, padx=3, pady=3) self.image_frame.grid_rowconfigure(0, weight=1, minsize=0) self.image_frame.grid_columnconfigure(0, weight=1, minsize=0) # Button self.upd_btn = Tk.Button(self.btn_frame, bd=2, text="Update Canvas", command=self.redraw_diag_image) self.upd_btn.pack(side=Tk.LEFT) self.link_btn = Tk.Button(self.btn_frame, bd=2, text="Permanent link", command=self.open_permanent_link) self.link_btn.pack(side=Tk.LEFT) self.quit_btn = Tk.Button(self.btn_frame, bd=2, text="Quit", command=self.quit) self.quit_btn.pack(side=Tk.LEFT) # Text Editor self.text = ScrolledText(self.text_frame, wrap=Tk.WORD) self.text.pack(fill=Tk.BOTH, expand=1) self.text.insert(Tk.END, source) self.text.focus_set() self.text.bind("<KeyRelease-Control_L>", self.redraw_diag_image) self.text.bind("<KeyRelease-Control_R>", self.redraw_diag_image) # Image Viewer self.image = ImageTk.PhotoImage(file=diag_image) self.canvas = Tk.Canvas(self.image_frame, scrollregion=(0, 0, self.image.width(), self.image.height())) self.canvas.grid(row=0, column=0, sticky=Tk.N + Tk.E + Tk.W + Tk.S) # Add Scrollbar xscr = Tk.Scrollbar(self.image_frame, orient=Tk.HORIZONTAL, command=self.canvas.xview) xscr.grid(row=1, column=0, sticky=Tk.E + Tk.W) yscr = Tk.Scrollbar(self.image_frame, orient=Tk.VERTICAL, command=self.canvas.yview) yscr.grid(row=0, column=1, sticky=(Tk.N, Tk.S)) self.canvas.config(xscrollcommand=xscr.set, yscrollcommand=yscr.set) self.canvas.create_image(0, 0, image=self.image, anchor=Tk.NW) def redraw_canvas(self, file_name): self.image = ImageTk.PhotoImage(file=file_name) self.canvas.config(scrollregion=(0, 0, self.image.width(), self.image.height())) self.canvas.create_image(0, 0, image=self.image, anchor=Tk.NW) def redraw_diag_image(self, event=None): source = intern(self.text.get("1.0", Tk.END).encode("utf-8")) if source is not self.source: self.diag_method(source, self.tmp.name, self.image_format) if getsize(self.tmp.name) > 0: self.redraw_canvas(self.tmp.name) self.source = source def open_permanent_link(self): url = self.make_permanent_link() webbrowser.open_new_tab(url) def make_permanent_link(self): import base64 source = intern(self.text.get("1.0", Tk.END).encode("utf-8")) url = _DIAG_LINK_PREFIX + base64.urlsafe_b64encode(source) print url return url def quit(self): self.tmp.close() self.root.destroy()
def showlicense(): from ScrolledText import ScrolledText win = ScrolledText(Toplevel(), width=100) win.insert(END, license) win.pack(expand=1, fill=BOTH) win.focus_set()
class Globby_Text_Editor(tk.Frame): def __init__(self, parent_widget, settings): # some initial values # TODO this Values are obsolete since Project_Settings covers them # --> self.settings.projects_path self.hash_opened_filename = None self.opened_filename = None self.settings = settings self.edit_button_list=[ {'text':'new page', 'cmd':self.on_new_page, 'keytxt':'CTRL+n','hotkey':'<Control-n>'}, {'text':'del page', 'cmd':self.on_del_page, 'keytxt':'CTRL+n','hotkey':'<DELETE>'} , {'text':'save', 'cmd':self.on_save, 'keytxt':'CTRL+s','hotkey':'<Control-s>'}, {'text':'undo', 'cmd':self.on_undo, 'keytxt':'CTRL+z','hotkey':'<Control-z>'}, {'text':'redo', 'cmd':self.on_redo, 'keytxt':'CTRL+y','hotkey':'<Control-y>'}] self.syntax_button_list=[ {'text':'**bold**', 'cmd':self.on_tag_insert, 'open_tag':'**', 'close_tag':'**','keytxt':'CTRL+b','hotkey':'<Control-b>'}, {'text':'//italic//', 'cmd':self.on_tag_insert, 'open_tag':'//', 'close_tag':'//', 'keytxt':'CTRL+i','hotkey':'<Control-i>'}, {'text':'__underline__', 'cmd':self.on_tag_insert, 'open_tag':'__', 'close_tag':'__', 'keytxt':'CTRL+u','hotkey':'<Control-u>'}, {'text':'[Link]', 'cmd':self.on_tag_insert, 'open_tag':'[', 'close_tag':']', 'keytxt':'CTRL+l','hotkey':'<Control-l>'}, {'text':'¸¸sub¸¸', 'cmd':self.on_tag_insert, 'open_tag':'¸¸', 'close_tag':'¸¸', 'keytxt':'CTRL+d','hotkey':'<Control-d>'}, {'text':'^^upper^^', 'cmd':self.on_tag_insert, 'open_tag':'^^', 'close_tag':'^^', 'keytxt':'CTRL+q','hotkey':'<Control-q>'}, {'text':'-~smaller~-', 'cmd':self.on_tag_insert, 'open_tag':'-~', 'close_tag':'~-', 'keytxt':'CTRL+w','hotkey':'<Control-w>'}, {'text':'+~bigger~+', 'cmd':self.on_tag_insert, 'open_tag':'+~', 'close_tag':'~+', 'keytxt':'CTRL+e','hotkey':'<Control-e>'}, {'text':'~~strike_thru~~', 'cmd':self.on_tag_insert, 'open_tag':'~~', 'close_tag':'~~', 'keytxt':'CTRL+t','hotkey':'<Control-t>'} ] # build Widgets tk.Frame.__init__(self, parent_widget) self.pack(fill=tk.BOTH, expand=tk.YES) #self.baseframe = tk.Frame(parent_widget) #self.baseframe.pack(fill=tk.BOTH, expand=tk.YES) self.editor() self.button_frame() # start tracking text changes inside the editfield thread.start_new_thread(self.on_txt_changes, ('',)) def editor(self): """ combine some Widgets to an enhanced editor (incl. Scrollbar) --> self.text the text widget itself --> self.opened_file_label Label on top of the editfield to show the name of the current opened File It can be used to show textchanges """ # build widgets self.txtfrm = tk.Frame(self) self.txtfrm.pack(fill=tk.BOTH, side=tk.LEFT, expand=tk.YES) self.opened_file_label = tk.Label(self.txtfrm, text="No File chosen") self.opened_file_label.pack(fill=tk.X) self.text = ScrolledText(self.txtfrm, bg="white", undo=1, maxundo=30, wrap=tk.WORD) self.text.pack(fill=tk.BOTH, expand=tk.YES, side=tk.LEFT) self.text.insert(1.0, u"Please open a File to edit") # build first(reference -- new name??) hash for comparison on changes self.hash_opened_filename = hash(self.text.get(1.0,tk.END)) # Set focus on textwidget and move cursor to the upper left self.text.focus_set() self.text.mark_set(tk.INSERT, '0.0') # goto line self.text.see(tk.INSERT) # scroll to line def label_button_row(self, parent_widget=None, btnlst=None, start_count=0): """Build a 2 column table with a label beside each button in a row. Bind a keyboard sequence to the button command. Display this keyboard sequence on the label. todo: - think about a parameter for the widget to bind the Hotkeys - rename to: labled_button_row, draw_labled_button_row Parameter: --> parent_widget: Parent widget to place the table --> btnlst: Type: List of dicts representing a button Example: {'text':'**bold**', # displayed on the Button (string) 'cmd':self.on_tag_insert, # command 'open_tag':'**', # chars representing the beginning # of a tag for inserting (string) 'close_tag':'**', # chars representing the end # of a tag for inserting (string) 'keytxt':'CTRL+b', # displayed on the Label (string) 'hotkey':'<Control-b>'} # keyboard sequence (string) Note: The existence of 'open_tag' and 'close_tag' in btnlst decides which command is bound to the Button. If they aren't there 'cmd' must be a function without parameters!!! otherwise 'cmd' needs following parameters: otag = btn['open_tag'] ctag = btn['close_tag'] event = None # Placeholder for a keysequence --> start_count: Type: int Description: The table is relized with tkinter grid layout manager. start_count is used if there is already a grid (with a Label beside a button). start_count can add the automatic genrated buttons under the existing. In Globby_Editor it is used to put a label_button_row under a Tkinter menubutton(file choose, headlines). """ i = start_count for btn in btnlst: try: otag = btn['open_tag'] ctag = btn['close_tag'] event = None doit = lambda e=event, o=otag, c=ctag:self.on_tag_insert(e,o,c) tk.Button(parent_widget, text=btn['text'], command=doit, relief=tk.RIDGE ).grid(column=0, row=i, sticky=tk.W+tk.E) self.text.bind(btn['hotkey'],doit) except KeyError: tk.Button(parent_widget, text=btn['text'], command=btn['cmd'], relief=tk.RIDGE ).grid(column=0, row=i, sticky=tk.W+tk.E) tk.Label(parent_widget, text=btn['keytxt'], relief=tk.FLAT ).grid(column=1, row=i, sticky=tk.W) i +=1 def button_frame(self): """draws a frame to hold a edit- and syntax-buttons under each other """ self.btnfrm = tk.Frame(self) self.btnfrm.pack(fill=tk.BOTH, side=tk.LEFT) self.edit_buttons() self.syntax_buttons() def edit_buttons(self): """draws a frame with buttons for editing (save, undo, redo, open) """ # genrate a labelframe self.efrm = tk.LabelFrame(self.btnfrm, text="Edit Buttons") self.efrm.pack(fill=tk.BOTH, padx=5, pady=5) # generate a button with a pulldown menue to open a file to edit self.file_open_mbtn = tk.Menubutton(self.efrm, text='Open File') # generate the pulldown menue self.file_open_menu = tk.Menu(self.file_open_mbtn, postcommand=self.gen_file2edit_menu) # bind the pulldown menue to the menubutton self.file_open_mbtn.config(menu=self.file_open_menu, relief=tk.RIDGE) self.file_open_mbtn.grid(column=0,row=0, sticky=tk.W+tk.E) # label beside the Button to display the associated keyboard shortcut self.file_open_lbl = tk.Label(self.efrm, text='CTRL+o', relief=tk.FLAT) self.file_open_lbl.grid(column=1, row=0, sticky=tk.W+tk.E) # generate buttons as described in self.edit_button_list self.label_button_row(self.efrm, self.edit_button_list, 2) # bind keyboard shortcut to the menue self.text.bind('<Control-o>', lambda e: self.file_open_menu.tk_popup(e.x_root, e.y_root)) def gen_file2edit_menu(self): """generates a (new) menu bound to the file chooser button so every time when a project is created or deleted gen_choose_project_menu should be called """ # delete all existing menue entrys self.file_open_menu.delete(0,tk.END) proj_path = os.path.join(self.settings.projects_path, self.settings.current_project ) print "proj_path", proj_path for this_file in os.listdir(proj_path): splitted = os.path.splitext(this_file) if splitted[1] == ".txt" and splitted[0] != "menue": #print "this_file",this_file open_file = os.path.join(proj_path, this_file) do_it = lambda bla = open_file:self.on_open(bla) self.file_open_menu.add_command(label=splitted, command=do_it) def syntax_buttons(self): """draws a frame with buttons for insert (wiki)markup idea: new parameter for on_tag_insert() jump_in_between=True/False so a pulldown list for different levels of headlines arn't necessary """ # genrate a labelframe self.sfrm = tk.LabelFrame(self.btnfrm, text="Syntax Buttons") self.sfrm.pack(fill=tk.BOTH, padx=5, pady=5) # generate a button with a pulldown menue für headline Syntax self.headln_menubtn = tk.Menubutton(self.sfrm, text='= Headlines =') # generate the pulldown menue self.headln_menu = tk.Menu(self.headln_menubtn) # bind the pulldown menue to the menubutton self.headln_menubtn.config(menu=self.headln_menu, relief=tk.RIDGE) # generate menue entrys i=1 for entry in ('h1','h2','h3','h4','h5','h6'): otag = '\n\n'+'='*i+' ' ctag = ' '+'='*i+'\n\n' doit = lambda event=None, o=otag, c=ctag:self.on_tag_insert(event,o,c) self.headln_menu.add_command(label=entry, command=doit) i+=1 self.headln_menubtn.grid(column=0,row=0, sticky=tk.W+tk.E) # label beside the Button to display the associated keyboard shortcut self.headln_lbl = tk.Label(self.sfrm, text='CTRL+h', relief=tk.FLAT) self.headln_lbl.grid(column=1, row=0, sticky=tk.W+tk.E) # generate buttons as described in self.edit_button_list self.label_button_row(self.sfrm, self.syntax_button_list, 1) # bind keyboard shortcut to the menue self.text.bind('<Control-h>', lambda e: self.headln_menu.tk_popup(e.x_root, e.y_root)) def on_txt_changes(self, dummy_value=tk.NONE): """ tracks text changes inside the editfield by comparing hash values new name: visualize_txt_changes??? """ while True: new_hash = hash(self.text.get(1.0, tk.END)) if new_hash != self.hash_opened_filename: #print "changes" self.opened_file_label.configure(fg="red") else: #print "no changes" self.opened_file_label.configure(fg="black") sleep(0.2) def on_open(self, file_to_open=None): """- opens a *.txt file from project folder - generates a reference hash. - Brings the cursor to the upper left and show this position in the textfield Parameter: --> file_to_open: complete path for file to open idea: - rename file_to_open to openfile or file_to_open """ self.opened_file_to_open = file_to_open self.opened_file_label.configure(text=file_to_open) self.text.delete(1.0, tk.END) self.opened_filename = os.path.basename(file_to_open) # write file content into the editfield editfile = codecs.open(file_to_open,'r', 'utf-8') self.text.insert(1.0, editfile.read()) editfile.close() # generate reference hash for a comparison to track text changes self.hash_opened_filename = hash(self.text.get(1.0,tk.END)) self.text.edit_reset() # clear tk's undo/redo stacks self.text.focus_set() # focus to textfield self.text.mark_set(tk.INSERT, '0.0') # place cursor to upper left self.text.see(tk.INSERT) # and display this line def on_save(self): """ Safes the current edited file""" if self.opened_filename: print "on_safe_" print " self.opened_filename",self.opened_filename self.hash_opened_filename = hash(self.text.get(1.0,tk.END)) path_to_safe_file = os.path.join(self.settings.projects_path, self.settings.current_project, self.opened_filename) safefile = codecs.open(path_to_safe_file,'w', 'utf-8') safefile.write(self.text.get(1.0,tk.END)) safefile.close() self.text.edit_reset() #clear tk's undo/redo stacks else: showinfo('Globby Text Editor','No File to save \n\n' 'You need to choose a File before editing') def on_undo(self): try: # tk8.4 keeps undo/redo stacks self.text.edit_undo( ) # exception if stacks empty except tk.TclError: showinfo('Globby Text Editor', 'Nothing to undo') def on_redo(self): print "redo" try: # tk8.4 keeps undo/redo stacks self.text.edit_redo() # exception if stacks empty except tk.TclError: showinfo('Globby Text Editor', 'Nothing to redo') def on_new_page(self): """ Ask the user to name the new File, create a blank File and load it into the Editorwidget TODO: check if file with the new filename allready exists check if Filename contains Specialchars """ print "on_new_page" nfile_name = tkSimpleDialog.askstring("New File Name", "Fill in a new File Name") proj_path = os.path.join(self.settings.projects_path, self.settings.current_project) nfile_name = os.path.join(proj_path, nfile_name.strip()+'.txt') nfile = codecs.open(nfile_name, 'w', 'utf-8') current_project = self.settings.current_project infostring1 = u'# Diese Datei wurde automatisch mit ' infostring2 = u'dem Projekt "%s" erstellt' % current_project nfile.write(infostring1+infostring2 ) nfile.close() self.on_open(nfile_name) def on_del_page(self): """""" print "del page" # self.settings.current_project del_file = os.path.join(self.settings.projects_path, self.settings.current_project, self.opened_filename) del_page = askyesno("Do you really want to delete ", del_file) if del_page: #self.set_project(self.new_project_name) print "%s geloescht" % del_file os.remove(del_file) def on_tag_insert(self, event=None, open_tag=None, close_tag=None): """ inserts a (wiki)tag to the current cursor position. If there is no text marked in the editfield, open_tag and close_tag are inserted to the current cursor position behind each other and the cursor jumps in between. Otherwise the marked string is enclosed by open_tag and close_tag and inserted to the current cursor position. Here the new cursor position is right behind the complete inserted string with tags. At this moment this behavior is quite buggy :-( idea: - new parameter for on_tag_insert() jump_in_between=True/False so a pulldown list for different levels of headlines arn't necessary - rename to: on_insert_tag?? on_tag_insert Parameter: --> event # keyboard shortcut --> open_tag # string --> close_tag # string """ #print 'event',event #print 'open_tag',open_tag #print 'close_tag',close_tag ## when no String is selected: if not self.text.tag_ranges(tk.SEL): print "no String is selected" insert_point = self.text.index('insert') insertline = insert_point.split('.')[0] addit = 1 if event != None: print "event not None" addit = 2 insertrow = str(int(insert_point.split('.')[1])+len(open_tag)+addit) new_insert_point = insertline+'.'+ insertrow self.text.insert(insert_point, open_tag+''+close_tag) # place cursor to insert_point self.text.mark_set(tk.INSERT, new_insert_point) # display this position on the editfield self.text.see(tk.INSERT) ## when a String is selected: else: #print "im else" marked_text = self.text.get(self.text.index(tk.SEL_FIRST), self.text.index(tk.SEL_LAST)) replace_index = self.text.index(tk.SEL_FIRST) print "replace_index in selected", replace_index self.text.delete(self.text.index(tk.SEL_FIRST), self.text.index(tk.SEL_LAST)) self.text.insert(replace_index, open_tag+marked_text+close_tag)
master.tk.call('wm', 'iconphoto', master._w, image) # To enable wrapping of text in the horizontal direction, as well as scrolling in the vertical direction. text = ScrolledText(master, width=400, height=380, wrap='word', font=("Verdana", 10), highlightthickness=0, bd=2, undo=True, pady=2, padx=3) text.pack(fill=Y, expand=1) text.focus_set() menu = Menu(master) master.config(menu=menu) # Creating Menus to work with. file_menu = Menu(menu) edit_menu = Menu(menu) clip_util = Menu(menu) format_menu = Menu(menu) help_menu = Menu(menu) spell_menu = Menu(menu) morse_translate = Menu(menu) # Normal-menus are those which yield a drop-down menu when clicked.
def compile_code(self, event=None): if not hasattr(self.editwin.io, 'filename') or self.editwin.io.filename is None: return filename = self.editwin.io.filename try: f = self.editwin.ftype.get() except: return if f in ('C/l',): compiler = 'gcc' command = idleConf.GetOption('extensions', 'CompileCode', 'compile_c') elif f in ('C++/l',): compiler = 'g++' command = idleConf.GetOption('extensions', 'CompileCode', 'compile_cpp') else: return def close_(w, event=None): w.grab_release() w.withdraw() raw_name = os.path.splitext(filename)[0] exe_name = raw_name+'.exe' basename = os.path.basename(filename) args = command.format(raw_name) sub_win = Toplevel(self.text) sub_win.title('In compilation') ce = ScrolledText( sub_win, width=80, height=24, fg='#b7b7b7', bg='black', font='Consolas 10', insertbackground='white', ) ce.bind('<Escape>', lambda event: close_(sub_win, event)) ce.pack(fill='both', expand=True) ce.focus_set() def compile_(): sp = subprocess.Popen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, ) self.compile_failed = compile_failed = sp.wait() compile_message = sp.communicate()[1] compile_message = re.sub( r'^{}:'.format(filename.replace('\\', r'\\')), basename+':', compile_message, flags=re.M, ) self.compile_message = compile_message if not compile_message: return if compile_failed: title = 'Compilation failed' else: title = 'Compilation succeeded (with warning)' sub_win.title(title) ## ce.insert('1.0', compile_message) ## ce.focus_set() d = threading.Thread(name='comp', target=compile_) d.start() d.join(6) if d.is_alive(): p = subprocess.Popen( 'taskkill /im {} /f /t'.format(compiler), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, ) stdout, stderr = p.communicate() if not self.compile_message: close_(sub_win, None) tkMessageBox.showinfo( parent=self.text, title=compiler, message='Compilation succeeded.', ) else: ce.insert('end', self.compile_message) ce.focus_set()