Skip to content

Commit

Permalink
Restructures the frame layout so buttons are now split into two groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
hreikin committed Apr 16, 2022
1 parent a85869a commit b76e385
Showing 1 changed file with 48 additions and 38 deletions.
86 changes: 48 additions & 38 deletions tkintermd/frame.py
Expand Up @@ -43,83 +43,93 @@ def __init__(self, master, **kwargs):
self.logger = log.create_logger()

# Toolbar.
self.top_bar = tk.Frame(self.master)
self.open_btn = tk.Button(self.top_bar, text="Open", command=self.open_md_file)
self.root_toolbar = tk.Frame(self.master)
self.open_btn = tk.Button(self.root_toolbar, text="Open", command=self.open_md_file)
self.open_btn.pack(side="left", padx=0, pady=0)
self.save_as_btn = tk.Button(self.top_bar, text="Save As", command=self.save_as_md_file)
self.save_as_btn = tk.Button(self.root_toolbar, text="Save As", command=self.save_as_md_file)
self.save_as_btn.pack(side="left", padx=0, pady=0)
self.save_btn = tk.Button(self.top_bar, text="Save", command=self.save_md_file)
self.save_btn = tk.Button(self.root_toolbar, text="Save", command=self.save_md_file)
self.save_btn.pack(side="left", padx=0, pady=0)
self.export_as_btn = tk.Button(self.top_bar, text="Export HTML", command=self.save_as_html_file)
self.export_as_btn = tk.Button(self.root_toolbar, text="Export HTML", command=self.save_as_html_file)
self.export_as_btn.pack(side="left", padx=0, pady=0)
self.undo_btn = tk.Button(self.top_bar, text="Undo", command=lambda: self.text_area.event_generate("<<Undo>>"))
# Button to choose pygments style for editor, preview and HTML.
self.style_opt_btn = tk.Menubutton(self.root_toolbar, text="Editor Style", relief="raised")
self.style_opt_btn.pack(side="left", padx=0, pady=0)
self.root_toolbar.pack(side="top", fill="x")

# Creating the widgets
self.editor_pw = tk.PanedWindow(self.master, orient="horizontal")
# Root editor frame
self.editor_root_frame = tk.Frame(self.editor_pw)
# Toolbar buttons
self.editor_toolbar = tk.Frame(self.editor_root_frame)
self.undo_btn = tk.Button(self.editor_toolbar, text="Undo", command=lambda: self.text_area.event_generate("<<Undo>>"))
self.undo_btn.pack(side="left", padx=0, pady=0)
self.redo_btn = tk.Button(self.top_bar, text="Redo", command=lambda: self.text_area.event_generate("<<Redo>>"))
self.redo_btn = tk.Button(self.editor_toolbar, text="Redo", command=lambda: self.text_area.event_generate("<<Redo>>"))
self.redo_btn.pack(side="left", padx=0, pady=0)
self.cut_btn = tk.Button(self.top_bar, text="Cut", command=lambda: self.text_area.event_generate("<<Cut>>"))
self.cut_btn = tk.Button(self.editor_toolbar, text="Cut", command=lambda: self.text_area.event_generate("<<Cut>>"))
self.cut_btn.pack(side="left", padx=0, pady=0)
self.copy_btn = tk.Button(self.top_bar, text="Copy", command=lambda: self.text_area.event_generate("<<Copy>>"))
self.copy_btn = tk.Button(self.editor_toolbar, text="Copy", command=lambda: self.text_area.event_generate("<<Copy>>"))
self.copy_btn.pack(side="left", padx=0, pady=0)
self.paste_btn = tk.Button(self.top_bar, text="Paste", command=lambda: self.text_area.event_generate("<<Paste>>"))
self.paste_btn = tk.Button(self.editor_toolbar, text="Paste", command=lambda: self.text_area.event_generate("<<Paste>>"))
self.paste_btn.pack(side="left", padx=0, pady=0)
self.find_btn = tk.Button(self.top_bar, text="Find", command=self.find)
self.find_btn = tk.Button(self.editor_toolbar, text="Find", command=self.find)
self.find_btn.pack(side="left", padx=0, pady=0)
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))
self.bold_btn = tk.Button(self.editor_toolbar, text="Bold", command=lambda: self.check_markdown_both_sides(constants.bold_md_syntax, constants.bold_md_ignore, constants.bold_md_special))
self.bold_btn.pack(side="left", padx=0, pady=0)
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))
self.italic_btn = tk.Button(self.editor_toolbar, text="Italic", command=lambda: self.check_markdown_both_sides(constants.italic_md_syntax, constants.italic_md_ignore, constants.italic_md_special))
self.italic_btn.pack(side="left", padx=0, pady=0)
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))
self.bold_italic_btn = tk.Button(self.editor_toolbar, 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))
self.bold_italic_btn.pack(side="left", padx=0, pady=0)
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, md_special=None, strikethrough=True))
self.strikethrough_btn = tk.Button(self.editor_toolbar, text="Strikethrough", command=lambda: self.check_markdown_both_sides(constants.strikethrough_md_syntax, constants.strikethrough_md_ignore, md_special=None, strikethrough=True))
self.strikethrough_btn.pack(side="left", padx=0, pady=0)
# self.heading_btn = tk.Button(self.top_bar, text="Heading")
# self.heading_btn = tk.Button(self.editor_toolbar, text="Heading")
# self.heading_btn.pack(side="left", padx=0, pady=0)
# self.unordered_list_btn = tk.Button(self.top_bar, text="Unordered List")
# self.unordered_list_btn = tk.Button(self.editor_toolbar, text="Unordered List")
# self.unordered_list_btn.pack(side="left", padx=0, pady=0)
# self.ordered_list_btn = tk.Button(self.top_bar, text="Ordered List")
# self.ordered_list_btn = tk.Button(self.editor_toolbar, text="Ordered List")
# self.ordered_list_btn.pack(side="left", padx=0, pady=0)
# self.checklist_btn = tk.Button(self.top_bar, text="Checklist")
# self.checklist_btn = tk.Button(self.editor_toolbar, text="Checklist")
# self.checklist_btn.pack(side="left", padx=0, pady=0)
# self.blockquote_btn = tk.Button(self.top_bar, text="Blockquote")
# self.blockquote_btn = tk.Button(self.editor_toolbar, text="Blockquote")
# self.blockquote_btn.pack(side="left", padx=0, pady=0)
# self.codeblock_btn = tk.Button(self.top_bar, text="Codeblock")
# self.codeblock_btn = tk.Button(self.editor_toolbar, text="Codeblock")
# self.codeblock_btn.pack(side="left", padx=0, pady=0)
# self.table_btn = tk.Button(self.top_bar, text="Table")
# self.table_btn = tk.Button(self.editor_toolbar, text="Table")
# self.table_btn.pack(side="left", padx=0, pady=0)
# self.link_btn = tk.Button(self.top_bar, text="Link")
# self.link_btn = tk.Button(self.editor_toolbar, text="Link")
# self.link_btn.pack(side="left", padx=0, pady=0)
# self.image_btn = tk.Button(self.top_bar, text="Image")
# self.image_btn = tk.Button(self.editor_toolbar, text="Image")
# self.image_btn.pack(side="left", padx=0, pady=0)

self.style_opt_btn = tk.Menubutton(self.top_bar, text="Editor Style", relief="raised")
self.style_opt_btn.pack(side="left", padx=0, pady=0)

self.top_bar.pack(side="top", fill="x")

# Creating the widgets
self.editor_pw = tk.PanedWindow(self.master, orient="horizontal")
self.editor_frame = ScrolledTextBox(self.editor_pw)
self.editor_toolbar.pack(side="top", fill="x")
# Editor frame with scrollbar and text area.
self.editor_frame = ScrolledTextBox(self.editor_root_frame)
self.text_area = self.editor_frame.tbox
self.editor_frame.pack(fill="both", expand=1)
# Tabs for the preview and export options.
self.preview_tabs = Notebook(self.editor_pw)
#make the previews
# HTML rendered preview.
self.preview_document = HtmlFrame(self.preview_tabs)

# Root frame for export options.
self.export_options_root_frame = tk.Frame(self.preview_tabs)
# Export options frame.
self.export_options_frame = tk.Frame(self.export_options_root_frame)
self.export_options_placeholder = tk.Label(self.export_options_frame, text="Placeholder", justify="center")
self.export_options_placeholder.pack(fill="both", expand=1)
self.export_options_frame.pack(fill="both", expand=1)
# HTML code preview/edit before export with scrollbar and text area.
self.export_options_text_area_frame = ScrolledTextBox(self.export_options_root_frame)
self.export_options_text_area = self.export_options_text_area_frame.tbox
self.export_options_text_area_frame.pack(fill="both", expand=1)
# Add the rendered preview and export options to the Notebook tabs.
self.preview_tabs.add(self.preview_document, text="Preview Document")
self.preview_tabs.add(self.export_options_root_frame, text="Export Options")
#add the areas to the paned window
self.editor_pw.add(self.editor_frame)
# Add the editor and preview/export areas to the paned window.
self.editor_pw.add(self.editor_root_frame)
self.editor_pw.add(self.preview_tabs)
self.editor_pw.pack(side="left", fill="both", expand=1)

# load the self.style_opt_btn menu
# Load the self.style_opt_btn menu, this needs to be after the editor.
self.style_menu = tk.Menu(self.style_opt_btn, tearoff=False)
for style_name in get_all_styles():
# dynamcially get names of styles exported by pygments
Expand Down

0 comments on commit b76e385

Please sign in to comment.