@@ -199,29 +199,46 @@ def popup(self, event):
199
199
self .right_click .tk_popup (event .x_root , event .y_root )
200
200
201
201
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
+ """
203
206
self .text_area .yview (* args )
204
207
# # This links the scrollbars but is currently causing issues.
205
208
# self.preview_area.html.yview(*args)
206
209
207
210
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
+ """
209
217
self .scrollbar .set (* args )
210
218
# # This links the scrollbars but is currently causing issues.
211
219
# self.preview_area.vsb.set(*args)
212
220
self .on_scrollbar ('moveto' , args [0 ])
213
221
214
222
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
+ """
216
229
self .text_area .tag_add (SEL , "1.0" , END )
217
230
self .text_area .mark_set (0.0 , END )
218
231
self .text_area .see (INSERT )
219
232
220
233
def find (self , * args ):
221
- """Simple search for a string within the editor window.
234
+ """Simple search dialog for within the editor window.
222
235
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.
225
242
"""
226
243
self .text_area .tag_remove ('found' , '1.0' , END )
227
244
target = simpledialog .askstring ('Find' , 'Search String:' )
@@ -241,6 +258,12 @@ def open_md_file(self):
241
258
242
259
Opens a native OS dialog and expects markdown formatted files. Shows an
243
260
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.
244
267
"""
245
268
open_filename_md = filedialog .askopenfilename (filetypes = (("Markdown File" , "*.md , *.mdown , *.markdown" ), ("Text File" , "*.txt" ), ("All Files" , "*.*" )))
246
269
if open_filename_md :
@@ -258,7 +281,12 @@ def save_as_md_file(self):
258
281
"""Saves the file with the given filename.
259
282
260
283
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.
262
290
"""
263
291
self .file_data = self .text_area .get ("1.0" , END )
264
292
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):
273
301
def save_md_file (self ):
274
302
"""Quick saves the file with its current name.
275
303
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.
278
308
"""
279
309
self .file_data = self .text_area .get ("1.0" , END )
280
310
try :
@@ -303,7 +333,14 @@ def on_input_change(self, event):
303
333
self .text_area .edit_modified (0 ) # resets the text widget to generate another event when another change occours
304
334
305
335
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
+ """
307
344
self .style = get_style_by_name (stylename )
308
345
self .syntax_highlighting_tags = []
309
346
for token , opts in self .style .list_styles ():
0 commit comments