Skip to content

Commit 0762dd0

Browse files
committed
Fedit 0.0.1.4 - Added theme switcher,
preferences window, more structure for future development
1 parent 7400b76 commit 0762dd0

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

__pycache__/tktools.cpython-37.pyc

378 Bytes
Binary file not shown.

main.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import tktools
22
from tktools import os, tk
33

4-
version = '0.0.0.3'
4+
version = '0.0.1.4'
55

66

77
print('Starting Fedit', version)
@@ -13,6 +13,7 @@
1313
def set_root_title(title):
1414
root.title(title)
1515
root.update()
16+
1617
## Main text editor
1718
frame_maintextedit = tk.Frame(root)
1819
widget_maintextedit = tktools.TextEditor(frame_maintextedit, root_title, set_root_title)
@@ -34,6 +35,39 @@ def set_root_title(title):
3435
## Main text editor
3536
widget_maintextedit.pack(expand=1, fill='both')
3637

38+
## Theme
39+
theme_current = False #False=Light True=Dark
40+
theme_light = '#f5f5f5'
41+
theme_dark = '#000000'
42+
def update_theme(theme, text_theme):
43+
root.config(bg=theme)
44+
widget_maintextedit.config(bg=theme, fg=text_theme)
45+
frame_menubar.config(bg=theme)
46+
for button in menubar.buttons:
47+
menubar.buttons[button]['raw'].config(bg=theme, fg=text_theme)
48+
49+
def switch_theme():
50+
global theme_current
51+
theme_current = not theme_current
52+
messages = {True: 'Switching theme to Dark', False: 'Switching theme to Light'}
53+
print(messages[theme_current])
54+
if theme_current == True:
55+
update_theme(theme_dark, theme_light)
56+
else:
57+
update_theme(theme_light, theme_dark)
58+
root.update()
59+
60+
def prefs_window():
61+
win = tktools.Window('Preferences', root_win=root).window_raw()
62+
button_switch_theme = tk.Button(win, text='Switch Theme', command=switch_theme)
63+
button_switch_theme.pack(fill='both', expand=1)
64+
65+
menubar.add_button('prefs', prefs_window, 'Prefrences')
66+
update_theme(theme_light, theme_dark)
67+
68+
menubar.grid_button('prefs', row=0, column=4)
69+
70+
3771
## Packing
3872
frame_menubar.pack(side='top', expand=1, fill='both')
3973
frame_maintextedit.pack(expand=1, fill='both')

tktools.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ def verify_f_name(f_name):
1212
return True
1313

1414
root_window = False
15+
root_window_obj = None
1516
class Window:
16-
def __init__(self, title):
17-
global root_window
17+
def __init__(self, title, root_win=None):
18+
global root_window, root_window_obj
1819
self.title = title
1920
if root_window == False:
2021
self.win = tk.Tk()
22+
root_window_obj = self.win
2123
else:
2224
self.win = tk.Toplevel()
2325
self.win.title(self.title)
@@ -118,6 +120,9 @@ def new_file(self, *args, **kwargs):
118120
self.clear_text(0.0, 'end')
119121
self.curr_file = None
120122
self.__updatetitle__()
123+
def config(self, **kwargs):
124+
print(kwargs)
125+
self.widget_raw().config(kwargs)
121126

122127

123128
class MenuBar:
@@ -138,6 +143,9 @@ def grid_button(self, button_name, *args, **kwargs):
138143
def raw_button(self, button_name):
139144
## Returns the raw Tk button widget
140145
return self.buttons[button_name]['raw']
146+
def config_button(self, button_name, *args, **kwargs):
147+
self.buttons[button_name]['raw'].config(args, kwargs)
148+
141149

142150

143151
if __name__=='__main__':

0 commit comments

Comments
 (0)