Skip to content

Commit d1d540b

Browse files
committed
Update descriptions in most docstrings to improve the documentation.
1 parent 64b123b commit d1d540b

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

tkintermd/frame.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,46 @@ def popup(self, event):
199199
self.right_click.tk_popup(event.x_root, event.y_root)
200200

201201
def on_scrollbar(self, *args):
202-
"""Scrolls the text area scrollbar when clicked/dragged with a mouse."""
202+
"""Scrolls the text area scrollbar when clicked/dragged with a mouse.
203+
204+
- Queries and changes the vertical position of the text area view.
205+
"""
203206
self.text_area.yview(*args)
204207
# # This links the scrollbars but is currently causing issues.
205208
# self.preview_area.html.yview(*args)
206209

207210
def on_mousewheel(self, *args):
208-
"""Moves the scrollbar and scrolls the text area on mousewheel event."""
211+
"""Moves the scrollbar and scrolls the text area on mousewheel event.
212+
213+
- Sets the fractional values of the slider position (upper and lower
214+
ends as value between 0 and 1).
215+
- Calls `on_scrollbar` function.
216+
"""
209217
self.scrollbar.set(*args)
210218
# # This links the scrollbars but is currently causing issues.
211219
# self.preview_area.vsb.set(*args)
212220
self.on_scrollbar('moveto', args[0])
213221

214222
def select_all(self, *args):
215-
"""Select all text within the editor window."""
223+
"""Select all text within the editor window.
224+
225+
- Add tag TAGNAME to all characters between INDEX1 and INDEX2.
226+
- Set mark MARKNAME before the character at index.
227+
- Scroll so that the character at INDEX is visible.
228+
"""
216229
self.text_area.tag_add(SEL, "1.0", END)
217230
self.text_area.mark_set(0.0, END)
218231
self.text_area.see(INSERT)
219232

220233
def find(self, *args):
221-
"""Simple search for a string within the editor window.
234+
"""Simple search dialog for within the editor window.
222235
223-
Displays a simple dialog with a field to enter the search string into and
224-
two buttons.
236+
- Get the current text area content.
237+
- Displays a simple dialog with a field to enter a search string into
238+
and two buttons.
239+
- If a string is provided then search for it within the text area.
240+
- Add tag TAGNAME to all characters between INDEX1 and INDEX2.
241+
- Highlight any found strings within the text editor.
225242
"""
226243
self.text_area.tag_remove('found', '1.0', END)
227244
target = simpledialog.askstring('Find', 'Search String:')
@@ -241,6 +258,12 @@ def open_md_file(self):
241258
242259
Opens a native OS dialog and expects markdown formatted files. Shows an
243260
error message if it fails.
261+
262+
- Display a native OS dialog and request a filename to open.
263+
- If a filename is provided then `try` to open it in "read" mode.
264+
- Replace the text area content.
265+
- Set the `constants.cur_file` value to the filename that was opened.
266+
- If any of the above fails then display an error message.
244267
"""
245268
open_filename_md = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *.mdown , *.markdown"), ("Text File", "*.txt"), ("All Files", "*.*")))
246269
if open_filename_md:
@@ -258,7 +281,12 @@ def save_as_md_file(self):
258281
"""Saves the file with the given filename.
259282
260283
Opens a native OS dialog for saving the file with a name and markdown
261-
extension. Shows an error message if it fails.'
284+
extension. Shows an error message if it fails.
285+
286+
- Display a native OS dialog and request a filename to save.
287+
- If a filename is provided then `try` to open it in "write" mode.
288+
- Set the `constants.cur_file` value to the filename that was opened.
289+
- If any of the above fails then display an error message.
262290
"""
263291
self.file_data = self.text_area.get("1.0" , END)
264292
self.save_filename_md = filedialog.asksaveasfilename(filetypes = (("Markdown File", "*.md"), ("Text File", "*.txt")) , title="Save Markdown File")
@@ -273,8 +301,10 @@ def save_as_md_file(self):
273301
def save_md_file(self):
274302
"""Quick saves the file with its current name.
275303
276-
If it fails because no name exists it calls the "save_as_md_file"
277-
function.
304+
- Get the current text area content.
305+
- `try` to save the file with the `constants.cur_file` variable.
306+
- If it fails because no name exists it calls the "save_as_md_file"
307+
function.
278308
"""
279309
self.file_data = self.text_area.get("1.0" , END)
280310
try:
@@ -303,7 +333,14 @@ def on_input_change(self, event):
303333
self.text_area.edit_modified(0) # resets the text widget to generate another event when another change occours
304334

305335
def load_style(self, stylename):
306-
"""Load Pygments style for syntax highlighting within the editor."""
336+
"""Load Pygments style for syntax highlighting within the editor.
337+
338+
- Load and configure the text area and `tags` with the Pygments styles
339+
and custom `Lexer` tags.
340+
- Set the background and text colour CSS values to match the values of
341+
the currently selected style.
342+
- Load the CSS into the HTML previeW area.
343+
"""
307344
self.style = get_style_by_name(stylename)
308345
self.syntax_highlighting_tags = []
309346
for token, opts in self.style.list_styles():

0 commit comments

Comments
 (0)