From 404ea59f172a6f6c50d753c0beb273ca19fe0e52 Mon Sep 17 00:00:00 2001 From: "Mr.programmer2938" <78996423+mrprogrammer2938@users.noreply.github.com> Date: Sun, 26 Dec 2021 23:04:55 +0330 Subject: [PATCH] Update black --- black | 158 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 117 insertions(+), 41 deletions(-) diff --git a/black b/black index 389470d..a93059a 100644 --- a/black +++ b/black @@ -111,13 +111,13 @@ file_name = None root.geometry('800x700+300+50') photo = PhotoImage(file='./Scr/black-notepad-logo.png') root.iconphoto(True,photo) + def new_file(event=None): root.title("Black-Notepad Untitled") global file_name file_name = None - - notebook.add(tab1,text="Untitled") - content_text.delete(1.0,END) + content_text.delete(1.0, END) + on_content_changed() def open_file(event=None): input_file_name = tkinter.filedialog.askopenfilename(defaultextension=".txt",filetypes=[("All Files", "*.*"), ("Text Documents", "*.txt"),("HTML", "*.html"),("CSS", "*.css"),("JavaScript", "*.js")]) @@ -136,6 +136,7 @@ def write_to_file(file_name): content = content_text.get(1.0, 'end') with open(file_name, 'w') as the_file: the_file.write(content) + the_file.close() except IOError: pass def save_as(event=None): @@ -201,6 +202,82 @@ def find_text(event=None): search_toplevel.destroy() search_toplevel.protocol('WM_DELETE_WINDOW', close_search_window) return "break" +def get_line_numbers(): + output = '' + if show_line_number.get(): + row, col = content_text.index("end").split('.') + for i in range(1, int(row)): + output += str(i) + '\n' + return output +def on_content_changed(event=None): + update_line_numbers() + update_cursor() +def update_line_numbers(event=None): + line_numbers = get_line_numbers() + line_number_bar.config(state='normal') + line_number_bar.delete('1.0', 'end') + line_number_bar.insert('1.0', line_numbers) + line_number_bar.config(state='disabled') + +def show_cursor(): + show_cursor_info_checked = show_cursor_info.get() + if show_cursor_info_checked: + cursor_info_bar.pack(expand='no', fill=None, side='right', anchor='se') + else: + cursor_info_bar.pack_forget() +def update_cursor(event=None): + row, col = content_text.index(INSERT).split('.') + line_num, col_num = str(int(row)), str(int(col) + 1) + infotext = "Line: {0} | Column: {1}".format(line_num, col_num) + cursor_info_bar.config(text=infotext) + +def highlight_line(interval=100): + content_text.tag_remove("active_line", 1.0, "end") + content_text.tag_add( + "active_line", "insert linestart", "insert lineend+1c") + content_text.after(interval, toggle_highlight) +def get_line_numbers(): + output = '' + if show_line_number.get(): + row, col = content_text.index("end").split('.') + for i in range(1, int(row)): + output += str(i) + '\n' + return output +def on_content_changed(event=None): + update_line_numbers() + update_cursor() +def update_line_numbers(event=None): + line_numbers = get_line_numbers() + line_number_bar.config(state='normal') + line_number_bar.delete('1.0', 'end') + line_number_bar.insert('1.0', line_numbers) + line_number_bar.config(state='disabled') + +def show_cursor(): + show_cursor_info_checked = show_cursor_info.get() + if show_cursor_info_checked: + cursor_info_bar.pack(expand='no', fill=None, side='right', anchor='se') + else: + cursor_info_bar.pack_forget() +def update_cursor(event=None): + row, col = content_text.index(INSERT).split('.') + line_num, col_num = str(int(row)), str(int(col) + 1) + infotext = "Line: {0} | Column: {1}".format(line_num, col_num) + cursor_info_bar.config(text=infotext) + +def highlight_line(interval=100): + content_text.tag_remove("active_line", 1.0, "end") + content_text.tag_add( + "active_line", "insert linestart", "insert lineend+1c") + content_text.after(interval, toggle_highlight) +def undo_highlight(): + content_text.tag_remove("active_line", 1.0, "end") +def toggle_highlight(event=None): + if to_highlight_line.get(): + highlight_line() + else: + undo_highlight() + def search_output(needle,if_ignore_case, content_text, search_toplevel, search_box): content_text.tag_remove('match','1.0', END) matches_found=0 @@ -244,13 +321,7 @@ def exit_editor(event=None): else: root.destroy() -def get_line_numbers(): - output = '' - if show_line_number.get(): - row, col = content_text.index("end").split('.') - for i in range(1, int(row)): - output += str(i) + '\n' - return output + def on_content_changed(event=None): update_line_numbers() update_cursor() @@ -300,8 +371,7 @@ def new_window(event=None): getoutput("python black.py") def print_paper(event=None): try: - # content_text - getoutput(f"") + getoutput(f"print {file_name} /c /d:lpt1") except (Exception,): print(False) def delete(event=None): @@ -508,6 +578,7 @@ font_size.add_command(label="Set Size",command=set_size) view_menu.add_cascade(label="Font Style",menu=font_style) view_menu.add_cascade(label="Font Size",menu=font_size) menu_bar.add_cascade(label='View', menu=view_menu) + def help(event=None): open_new_tab('https://black-software-com.github.io/Black-Help/') def feedback(event=None): @@ -539,10 +610,13 @@ if file_cha_ == 0 or file_cha_ == 1 or file_cha_ == 2 or file_cha_ == 3: notebook.add(tab1,text='UnTitled') notebook.add(tab2,text="Read.txt") - l = Label(tab2,text="Black-Notepad",font=("None",40)) - l.place(bordermode=INSIDE,x=230,y=15) - l_txt = Label(tab2,text="Black-Webbrowser v2.0 Coming Soon...") - l_txt.place(x=300,y=90) + l = Label(tab2,text="Black-Notepad (Beta)",font=("None",25)) + l.place(bordermode=INSIDE,x=240,y=15) + + + l_txt = Label(tab2,text="Black-Notepad v2.0 Coming Soon...",font=("None",15)) + l_txt.place(x=235,y=130) + g = HTMLLabel(tab2,html=' Github ') g.place(bordermode=INSIDE,x=20,y=230) f = HTMLLabel(tab2,html=' Facebook ') @@ -615,33 +689,35 @@ popup_menu.add_command(label="Reload",accelerator='Ctrl+R',underline=6,command=r popup_menu.add_command(label="Delete",accelerator='Delete',underline=7,command=delete) popup_menu.add_separator() popup_menu.add_command(label='Select All', accelerator='Ctrl+A',underline=8, command=selectall) -content_text.bind('', show_popup_menu) -content_text.bind('', new_file) -content_text.bind('', new_file) -content_text.bind('', open_file) -content_text.bind('', open_file) -content_text.bind('', save) -content_text.bind('', save) -content_text.bind('',redo) -content_text.bind('',redo) -content_text.bind('',selectall) -content_text.bind('',selectall) -content_text.bind('',find_text) -content_text.bind('',find_text) -content_text.bind("",reload) -content_text.bind("",reload) -content_text.bind("",help) -content_text.bind("",help) -content_text.bind("",feedback) -content_text.bind("",feedback) -content_text.bind("",license) -content_text.bind("",license) -content_text.bind("",delete) -content_text.bind('', on_content_changed) +root.bind('', show_popup_menu) +root.bind('', new_file) +root.bind('', new_file) +root.bind('', open_file) +root.bind('', open_file) +root.bind('', save) +root.bind('', save) +root.bind('',redo) +root.bind('',redo) +root.bind('',selectall) +root.bind('',selectall) +root.bind('',find_text) +root.bind('',find_text) +root.bind("",reload) +root.bind("",reload) +root.bind("",help) +root.bind("",help) +root.bind("",feedback) +root.bind("",feedback) +root.bind("",license) +root.bind("",license) +root.bind("",delete) +root.bind('', on_content_changed) content_text.tag_configure('active_line', background='ivory2') -content_text.bind('', show_popup_menu) -content_text.focus_set() +root.bind('', show_popup_menu) +root.focus_set() root.protocol('WM_DELETE_WINDOW', exit_editor) + +global black_version,black_help black_version = "Black-Notepad v1.0" black_help = """ --- [ Black-Notepad ]---