Skip to content

Commit c300724

Browse files
committed
Add documentation
1 parent ebf9261 commit c300724

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

__pycache__/tktools.cpython-37.pyc

3 Bytes
Binary file not shown.

main.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,33 @@
44
version = '0.0.0.2'
55

66

7-
initial_dir = os.path.expanduser('~')
8-
97
print('Starting Fedit '+version)
108

119
root = tktools.Window('Fedit ('+str(version)+')').window_raw()
1210

11+
## Main text editor
1312
frame_maintextedit = tk.Frame(root)
14-
frame_menubar = tk.Frame(root)
1513
widget_maintextedit = tktools.TextEditor(frame_maintextedit)
1614

17-
15+
## MenuBar
16+
frame_menubar = tk.Frame(root)
1817
menubar = tktools.MenuBar(frame_menubar)
1918

20-
2119
menubar.add_button('open', widget_maintextedit.open_file, 'Open')
2220
menubar.add_button('save', widget_maintextedit.save_file, 'Save')
2321

2422
menubar.grid_button('open', row=0, column=0)
2523
menubar.grid_button('save', row=0, column=1)
2624

27-
25+
## Main text editor
2826
widget_maintextedit.pack(expand=1, fill='both')
2927

28+
## Packing
3029
frame_menubar.pack(side='top', expand=1, fill='both')
3130
frame_maintextedit.pack(expand=1, fill='both')
3231

32+
## Start the window
3333
root.mainloop()
34+
35+
## Exited
3436
print('Exiting')

tktools.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
## Import modules
12
import tkinter as tk
23
from tkinter import filedialog as tkfd
34
import os
45

6+
7+
## Classes
8+
def verify_f_name(f_name):
9+
if f_name in [None, (), '']:
10+
return False
11+
return True
12+
513
root_window = False
614
class Window:
715
def __init__(self, title):
@@ -17,13 +25,9 @@ def window_raw(self):
1725
return self.win
1826

1927

20-
def verify_f_name(f_name):
21-
if f_name in [None, (), '']:
22-
return False
23-
return True
24-
2528
class TextEditor:
2629
def __init__(self, parent):
30+
## Init
2731
self.parent = parent
2832
self.widget = tk.Text(self.parent)
2933
self.ftypes = [
@@ -36,20 +40,27 @@ def __init__(self, parent):
3640
]
3741
self.initial_dir = os.path.expanduser('~')
3842
def widget_raw(self):
43+
## Return the raw Tk text widget
3944
return self.widget
4045
def pack(self, *args, **kwargs):
46+
## Pack the text widget
4147
self.widget.pack(kwargs)
4248
def grid(self, *args, **kwargs):
49+
## Grid the text widget
4350
self.widget.grid(kwargs)
4451
def clear_text(self, *args, **kwargs):
52+
## Clear text from text widget
4553
self.widget.delete(*args, **kwargs)
4654
def set_text(self, text, *args, **kwargs):
55+
## Clears and sets the text
4756
self.clear_text(0.0)
4857
self.widget.insert(0.0, text, args, kwargs)
4958
def get_text(self, *args, **kwargs):
59+
## Gets the text from the text widget
5060
text = self.widget.get(*args, **kwargs)
5161
return text
5262
def open_file(self, *args, **kwargs):
63+
## Asks for a file to open and shows it in text widget
5364
#args and kwargs to this function are thrown away
5465
global initial_dir
5566
f_name = tkfd.askopenfilename(filetypes=self.ftypes, initialdir=self.initial_dir)
@@ -60,6 +71,8 @@ def open_file(self, *args, **kwargs):
6071
f_text = open(f_name, 'r').read()
6172
self.set_text(text=f_text)
6273
def save_file(self, *args, **kwargs):
74+
## Asks for a file to save the contents of the text widget
75+
## in and saves it there
6376
#args and kwargs to this function are thrown away
6477
global initial_dir
6578
f_name = tkfd.asksaveasfilename(filetypes=self.ftypes, initialdir=self.initial_dir)
@@ -74,16 +87,21 @@ def save_file(self, *args, **kwargs):
7487

7588
class MenuBar:
7689
def __init__(self, parent):
90+
## Init
7791
self.parent = parent
7892
self.buttons = {}
7993
def add_button(self, button_name, command, text):
94+
## Add a button
8095
button = tk.Button(self.parent, text=text, command=command)
8196
self.buttons[button_name] = {'cmd': command, 'text': text, 'raw': button}
8297
def pack_button(self, button_name, *args, **kwargs):
98+
## Pack a button
8399
self.buttons[button_name]['raw'].pack(args, kwargs)
84100
def grid_button(self, button_name, *args, **kwargs):
101+
## Grid a button
85102
self.buttons[button_name]['raw'].grid(kwargs)
86103
def raw_button(self, button_name):
104+
## Returns the raw Tk button widget
87105
return self.buttons[button_name]['raw']
88106

89107

0 commit comments

Comments
 (0)