Skip to content

Commit e3b15c6

Browse files
committed
Update function name to better describe its purpose and remove unused code.
1 parent 91569e2 commit e3b15c6

File tree

1 file changed

+7
-89
lines changed

1 file changed

+7
-89
lines changed

tkintermd/tkintermd_frame.py

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def __init__(self, master, **kwargs):
5959
self.paste_btn.pack(side="left", padx=0, pady=0)
6060
self.find_btn = tk.Button(self.top_bar, text="Find", command=self.find)
6161
self.find_btn.pack(side="left", padx=0, pady=0)
62-
self.bold_btn = tk.Button(self.top_bar, text="Bold", command=lambda: self.check_bold_italic(constants.bold_md_syntax, constants.bold_md_ignore, constants.bold_md_special))
62+
# self.heading_btn = tk.Button(self.top_bar, text="Heading")
63+
# self.heading_btn.pack(side="left", padx=0, pady=0)
64+
self.bold_btn = tk.Button(self.top_bar, text="Bold", command=lambda: self.check_markdown_both_sides(constants.bold_md_syntax, constants.bold_md_ignore, constants.bold_md_special))
6365
self.bold_btn.pack(side="left", padx=0, pady=0)
64-
self.italic_btn = tk.Button(self.top_bar, text="Italic", command=lambda: self.check_bold_italic(constants.italic_md_syntax, constants.italic_md_ignore, constants.italic_md_special))
66+
self.italic_btn = tk.Button(self.top_bar, text="Italic", command=lambda: self.check_markdown_both_sides(constants.italic_md_syntax, constants.italic_md_ignore, constants.italic_md_special))
6567
self.italic_btn.pack(side="left", padx=0, pady=0)
66-
self.bold_italic_btn = tk.Button(self.top_bar, text="Bold Italic", command=lambda: self.check_bold_italic(constants.bold_italic_md_syntax, constants.bold_italic_md_ignore, constants.bold_italic_md_special))
68+
self.bold_italic_btn = tk.Button(self.top_bar, text="Bold Italic", command=lambda: self.check_markdown_both_sides(constants.bold_italic_md_syntax, constants.bold_italic_md_ignore, constants.bold_italic_md_special))
6769
self.bold_italic_btn.pack(side="left", padx=0, pady=0)
68-
# self.heading_btn = tk.Button(self.top_bar, text="Heading")
69-
# self.heading_btn.pack(side="left", padx=0, pady=0)
70-
self.strikethrough_btn = tk.Button(self.top_bar, text="Strikethrough", command=lambda: self.check_bold_italic(constants.strikethrough_md_syntax, constants.strikethrough_md_ignore, constants.strikethrough_md_special))
70+
self.strikethrough_btn = tk.Button(self.top_bar, text="Strikethrough", command=lambda: self.check_markdown_both_sides(constants.strikethrough_md_syntax, constants.strikethrough_md_ignore, constants.strikethrough_md_special))
7171
self.strikethrough_btn.pack(side="left", padx=0, pady=0)
7272
# self.unordered_list_btn = tk.Button(self.top_bar, text="Unordered List")
7373
# self.unordered_list_btn.pack(side="left", padx=0, pady=0)
@@ -376,7 +376,7 @@ def remove_markdown_both_sides(self, selection, md_syntax):
376376
self.text_area.insert(INSERT, self.remove_md)
377377
return
378378

379-
def check_bold_italic(self, md_syntax, md_ignore, md_special=None):
379+
def check_markdown_both_sides(self, md_syntax, md_ignore, md_special=None):
380380
self.md_syntax = md_syntax
381381
self.md_ignore = md_ignore
382382
self.md_special = md_special
@@ -399,88 +399,6 @@ def check_bold_italic(self, md_syntax, md_ignore, md_special=None):
399399
self.apply_markdown_both_sides(self.cur_selection, self.md_syntax)
400400

401401

402-
403-
404-
# try:
405-
406-
# # Try to remove formatting from start/end of string for each option
407-
# # if none of the options are True then apply the formatting, these
408-
# # need to be in the correct order. Custom logic for each formatting
409-
# # option (headings, lists, etc) should now be easier to
410-
# # differentiate and stop things firing incorrectly.
411-
# self.cur_selection = self.text_area.selection_get()
412-
# # Bold-italic
413-
# if str(self.cur_selection).startswith(constants.bold_italic_md_syntax) and str(self.cur_selection).endswith(constants.bold_italic_md_syntax):
414-
# self.remove_md = str(self.cur_selection).strip(self.md_syntax[0]).strip(self.md_syntax[1])
415-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
416-
# self.text_area.insert(INSERT, self.remove_md)
417-
# return
418-
# # Bold
419-
# if str(self.cur_selection).startswith(constants.bold_md_syntax) and str(self.cur_selection).endswith(constants.bold_md_syntax):
420-
# self.remove_md = str(self.cur_selection).strip(self.md_syntax[0]).strip(self.md_syntax[1])
421-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
422-
# self.text_area.insert(INSERT, self.remove_md)
423-
# return
424-
# # Italic
425-
# if str(self.cur_selection).startswith(constants.italic_md_syntax) and str(self.cur_selection).endswith(constants.italic_md_syntax):
426-
# self.remove_md = str(self.cur_selection).strip(self.md_syntax[0]).strip(self.md_syntax[1])
427-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
428-
# self.text_area.insert(INSERT, self.remove_md)
429-
# return
430-
# # Strikethrough
431-
# if str(self.cur_selection).startswith(constants.strikethrough_md_syntax) and str(self.cur_selection).endswith(constants.strikethrough_md_syntax):
432-
# self.remove_md = str(self.cur_selection).strip(self.md_syntax[0]).strip(self.md_syntax[1])
433-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
434-
# self.text_area.insert(INSERT, self.remove_md)
435-
# return
436-
# #
437-
# #
438-
# # Insert the rest of the button formatting options here.
439-
# #
440-
# #
441-
442-
# else:
443-
# self.insert_md = f"{self.md_syntax[0]}{self.cur_selection}{self.md_syntax[0]}"
444-
445-
# except:
446-
# # This needs replacing with logging.
447-
# print("EXCEPTION: Application/removal of markdown formatting failed.")
448-
# pass
449-
450-
451-
452-
# try:
453-
# self.cur_selection = self.text_area.selection_get()
454-
# if len(self.md_syntax) == 2 and self.md_syntax[0] == "**" and self.md_syntax[1] == "__" and str(self.cur_selection)[1] != "*" and str(self.cur_selection)[1] != "_":
455-
# if str(self.cur_selection).startswith(self.md_syntax) == False and str(self.cur_selection).startswith(self.md_ignore) == False and str(self.cur_selection)[0] != "*" and str(self.cur_selection)[0] != "_":
456-
# self.with_md_selection = f"{self.md_syntax[0]}{self.cur_selection}{self.md_syntax[0]}"
457-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
458-
# self.text_area.insert(INSERT, self.with_md_selection)
459-
# return
460-
# else:
461-
# return
462-
# if str(self.cur_selection).startswith(self.md_syntax) == True and str(self.cur_selection).endswith(self.md_syntax) == True and str(self.cur_selection).startswith(self.md_ignore) == False:
463-
# self.without_md_selection = str(self.cur_selection).replace(self.md_syntax[0], "").replace(self.md_syntax[1], "")
464-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
465-
# self.text_area.insert(INSERT, self.without_md_selection)
466-
# return
467-
# elif str(self.cur_selection).startswith(self.md_syntax) == True and str(self.cur_selection).startswith(self.md_ignore) == True:
468-
# return
469-
# elif str(self.cur_selection).startswith(self.md_syntax) == True and str(self.cur_selection).startswith(self.md_ignore) == False:
470-
# self.without_md_selection = str(self.cur_selection).replace(self.md_syntax[0], "").replace(self.md_syntax[1], "")
471-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
472-
# self.text_area.insert(INSERT, self.without_md_selection)
473-
# return
474-
# elif str(self.cur_selection).startswith(self.md_syntax) == False and str(self.cur_selection).startswith(self.md_ignore) == False:
475-
# self.with_md_selection = f"{self.md_syntax[0]}{self.cur_selection}{self.md_syntax[0]}"
476-
# self.text_area.delete(index1=SEL_FIRST, index2=SEL_LAST)
477-
# self.text_area.insert(INSERT, self.with_md_selection)
478-
# return
479-
# except:
480-
# # This needs replacing with logging.
481-
# print("EXCEPTION: Application/removal of markdown formatting failed.")
482-
# pass
483-
484402
class Lexer(MarkdownLexer):
485403
"""Extend MarkdownLexer to add markup for bold-italic.
486404

0 commit comments

Comments
 (0)