Skip to content

Commit

Permalink
Very basic Google style docstrings created that are then used by mkdo…
Browse files Browse the repository at this point in the history
…cs to create content for the pages.
  • Loading branch information
hreikin committed Apr 3, 2022
1 parent 6fe2ee1 commit cfafda6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
16 changes: 12 additions & 4 deletions tkintermd/tkintermd_constants.py
@@ -1,39 +1,46 @@
"""Variables and constants to be used by tkintermd."""
from pathlib import Path

# This is the only variable to be changed from elsewhere. All the rest should
# remain constant.
cur_file = Path()
"""Variable for tracking current open file."""

bold_md_syntax = ("**", "__")
"""Markdown syntax for bold highlighting."""
bold_md_ignore = (
"- ", "> ", "# ", "`",
"--", ">> ", "## ",
"***", "___", "---", ">>> ", "### ", "```", "===",
"####", "#####", "######",
)
"""Markdown syntax to ignore for bold highlighting."""
italic_md_syntax = ("*", "_")
"""Markdown syntax for italic highlighting."""
italic_md_ignore = (
"**", "__", "- ", "> ", "# ", "`",
"--", ">> ", "## ",
"***", "___", "---", ">>> ", "### ", "```", "===",
"####", "#####", "######",
)
"""Markdown syntax to ignore for italic highlighting."""
# Needs adjusting.
bold_italic_md_syntax = ("***", "___")
"""Markdown syntax for bold-italic highlighting."""
bold_italic_md_ignore = (
"*", "_", "- ", "> ", "# ", "`",
"**", "__", "--", ">> ", "## ",
"***", "___", "---", ">>> ", "### ", "```", "===",
"####", "#####", "######",
)
"""Markdown syntax to ignore for bold-italic highlighting."""
strikethrough_md_syntax = ("~~", "~~")
"""Markdown syntax for strikethrough highlighting."""
strikethrough_md_ignore = (
"*", "_", "- ", "> ", "# ", "`",
"**", "__", "--", ">> ", "## ",
"***", "___", "---", ">>> ", "### ", "```", "===",
"####", "#####", "######",
)

"""Markdown syntax to ignore for strikethrough highlighting."""
default_md_string = """
# Heading 1
## Heading 2
Expand Down Expand Up @@ -104,4 +111,5 @@
```
This is a fenced code block.
```
"""
"""
"""Default string to show in editor when it loads."""
50 changes: 27 additions & 23 deletions tkintermd/tkintermd_frame.py
Expand Up @@ -16,22 +16,27 @@
from pygments.styles import get_style_by_name

class TkinterMDFrame(tk.Frame):
def __init__(self, master, **kwargs):
"""
A Markdown editor with HTML Preview window in a tkinter frame. Import it
into your own scripts like so:
from tkintermd.tkintermd_frame import TkinterMDFrame
"""An embeddable tkinter based Markdown editor with HTML preview.
The editor has syntax highlighting supplied by `Pygments` and the HTML
preview window is provided by `tkinterweb`.
Import it into your own scripts like so:
```python
from tkintermd.tkintermd_frame import TkinterMDFrame
import tkinter as tk
from tkinter.constants import *
import tkinter as tk
from tkinter.constants import *
root = tk.Tk()
app = TkinterMDFrame(root)
app.pack(fill="both", expand=1)
app.mainloop()
"""
root = tk.Tk()
app = TkinterMDFrame(root)
app.pack(fill="both", expand=1)
app.mainloop()
```
"""
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master) # no need for super

# Toolbar.
Expand Down Expand Up @@ -190,8 +195,7 @@ def on_scrollbar(self, *args):
# self.preview_area.html.yview(*args)

def on_mousewheel(self, *args):
'''Moves the scrollbar and scrolls text widgets when the mousewheel
is moved on a text widget'''
'''Moves the scrollbar and scrolls the widgets on mousewheel event'''
self.scrollbar.set(*args)
# # This links the scrollbars but is currently causing issues.
# self.preview_area.vsb.set(*args)
Expand Down Expand Up @@ -245,8 +249,9 @@ def save_as_md_file(self):
mbox.showerror(title="Error", message=f"Error Saving File\n\nThe file: {self.save_filename_md} can not be saved!")

def save_md_file(self):
"""Quick saves the file with its current name, if it fails because no
name exists it calls the "save_as_md_file" function."""
"""Quick saves the file with its current name.
If it fails because no name exists it calls the "save_as_md_file" function."""
self.file_data = self.text_area.get("1.0" , END)
try:
with open(constants.cur_file, "w") as stream:
Expand Down Expand Up @@ -311,12 +316,11 @@ def check_markdown(self, start='insert linestart', end='insert lineend'):
self.text_area.mark_set("range_start", "range_end")

def apply_markdown_both_sides(self, md_syntax, md_ignore):
"""
A generic, catch-all attempt to apply and remove markdown from either
side of a selection.
"""Apply and remove markdown from either side of a selection.
:param md_syntax: Tuple of markdown strings to apply/remove.
:param md_ignore: Tuple of markdown strings to ignore.
Args:
md_syntax (tuple): Tuple of markdown strings to apply/remove.
md_ignore (tuple): Tuple of markdown strings to ignore.
"""
self.md_syntax = md_syntax
self.md_ignore = md_ignore
Expand Down

0 comments on commit cfafda6

Please sign in to comment.