Skip to content

Commit 7400b76

Browse files
committed
Added file location in title bar
1 parent 4982821 commit 7400b76

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

__pycache__/tktools.cpython-37.pyc

306 Bytes
Binary file not shown.

main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
print('Starting Fedit', version)
88
print('Home dir:', os.path.expanduser('~'))
99

10-
root = tktools.Window('Fedit ('+str(version)+')').window_raw()
10+
root_title = 'Fedit ('+str(version)+')'
11+
root = tktools.Window(root_title).window_raw()
1112

13+
def set_root_title(title):
14+
root.title(title)
15+
root.update()
1216
## Main text editor
1317
frame_maintextedit = tk.Frame(root)
14-
widget_maintextedit = tktools.TextEditor(frame_maintextedit)
18+
widget_maintextedit = tktools.TextEditor(frame_maintextedit, root_title, set_root_title)
1519

1620
## MenuBar
1721
frame_menubar = tk.Frame(root)

tktools.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def window_raw(self):
2727

2828

2929
class TextEditor:
30-
def __init__(self, parent):
30+
def __init__(self, parent, root_title, set_root_title):
3131
## Init
3232
self.parent = parent
3333
self.widget = tk.Text(self.parent)
@@ -41,13 +41,22 @@ def __init__(self, parent):
4141
]
4242
self.initial_dir = os.path.expanduser('~')
4343
self.curr_file = None
44+
self.set_root_title = set_root_title
45+
self.root_title = root_title
4446
def __savefiledata__(self, f_name, data):
4547
print('Saving', f_name)
4648
self.initial_dir = os.path.dirname(f_name)
4749
f_obj = open(f_name, 'w')
4850
f_obj.write(data)
4951
f_obj.close()
5052
self.curr_file = f_name
53+
def __updatetitle__(self, f_name=None):
54+
if f_name == None:
55+
f_name = self.curr_file
56+
if f_name == None:
57+
self.set_root_title(self.root_title)
58+
else:
59+
self.set_root_title(self.root_title+' - '+f_name)
5160
def widget_raw(self):
5261
## Return the raw Tk text widget
5362
return self.widget
@@ -79,6 +88,7 @@ def open_file(self, *args, **kwargs):
7988
f_text = open(f_name, 'r').read()
8089
self.set_text(text=f_text)
8190
self.curr_file = f_name
91+
self.__updatetitle__()
8292
def save_file(self, *args, **kwargs):
8393
if verify_f_name(self.curr_file):
8494
#Save file as currently open file
@@ -107,6 +117,7 @@ def new_file(self, *args, **kwargs):
107117
#User has saved/pressed no
108118
self.clear_text(0.0, 'end')
109119
self.curr_file = None
120+
self.__updatetitle__()
110121

111122

112123
class MenuBar:

0 commit comments

Comments
 (0)