11import tktools
2- from tktools import os , tk
3- from tkinter import colorchooser
2+ from tktools import os , tk , sys
3+ from tkinter import colorchooser , messagebox
4+ from ast import literal_eval
45
56version = '0.0.1.5'
67
@@ -14,6 +15,33 @@ def set_root_title(title):
1415 root .title (title )
1516 root .update ()
1617
18+
19+ ## Config file
20+ def load_config_file ():
21+ global config
22+ print ('Loading config file...' , end = ' ' )
23+ config_file_obj = open (os .path .expanduser ('~' )+ '/.fedit' , 'r' )
24+ config_file = config_file_obj .read ()
25+ config_file_obj .close ()
26+ config = {}
27+ for line in config_file .split ('\n ' ):
28+ tup = line .split (',' )
29+ config [tup [0 ]] = ',' .join (tup [1 :])
30+ print ('Done' )
31+
32+ if os .path .isfile (os .path .expanduser ('~' )+ '/.fedit' ):
33+ load_config_file ()
34+ else :
35+ print ('First time running Fedit, creating config file...' , end = ' ' )
36+ config_file_obj = open (os .path .expanduser ('~' )+ '/.fedit' , 'w' )
37+ print (os .path .expanduser ('~' )+ '/.fedit' )
38+ import requests
39+ data = requests .get ('https://smallbytes.pythonanywhere.com/Fedit/newuser' )
40+ config_file_obj .write (str (data .content , encoding = 'ascii' ))
41+ config_file_obj .close ()
42+ load_config_file ()
43+ print (config )
44+
1745## Main text editor
1846frame_maintextedit = tk .Frame (root )
1947widget_maintextedit = tktools .TextEditor (frame_maintextedit , root_title , set_root_title )
@@ -37,31 +65,31 @@ def set_root_title(title):
3765
3866## Theme
3967theme_current = False #False=Light True=Dark
40- theme_light = '#f5f5f5'
41- theme_dark = '#000000'
42- def update_theme (theme , text_theme , custom = 0 ):
68+ themes = literal_eval ( config [ 'Themes' ])
69+
70+ def update_theme (theme , text_theme , button_theme , button_text_theme , custom = 0 ):
4371 print ('Custom:' , custom , 'BG:' , theme , 'FG:' , text_theme )
4472 root .config (bg = theme )
4573 widget_maintextedit .config (bg = theme , fg = text_theme , insertbackground = text_theme )
4674 frame_menubar .config (bg = theme )
4775 for button in menubar .buttons :
48- menubar .buttons [button ]['raw' ].config (bg = theme , fg = text_theme )
76+ menubar .buttons [button ]['raw' ].config (bg = button_theme , fg = button_text_theme )
4977
5078def switch_theme ():
5179 global theme_current
5280 theme_current = not theme_current
5381 messages = {True : 'Switching theme to Dark' , False : 'Switching theme to Light' }
5482 print (messages [theme_current ])
55- if theme_current == True :
56- update_theme (theme_dark , theme_light )
57- else :
58- update_theme (theme_light , theme_dark )
83+ theme = themes [theme_current ]
84+ update_theme (theme ['main' ], themes [not theme_current ]['main' ], theme ['buttons' ], theme ['buttons_text' ])
5985 root .update ()
6086
6187def set_theme ():
6288 bg_col = colorchooser .askcolor (title = 'Choose background colour' )[1 ]
6389 fg_col = colorchooser .askcolor (title = 'Choose foreground colour' )[1 ]
64- update_theme (bg_col , fg_col , custom = 1 )
90+ bt_col = colorchooser .askcolor (title = 'Choose button background colour' )[1 ]
91+ btt_col = colorchooser .askcolor (title = 'Choose button foreground colour' )[1 ]
92+ update_theme (bg_col , fg_col , bt_col , btt_col , custom = 1 )
6593
6694def prefs_window ():
6795 win = tktools .Window ('Preferences' , root_win = root ).window_raw ()
@@ -71,7 +99,7 @@ def prefs_window():
7199 button_set_theme .pack (fill = 'both' , expand = 1 )
72100
73101menubar .add_button ('prefs' , prefs_window , 'Prefrences' )
74- update_theme ( theme_light , theme_dark )
102+ switch_theme ( )
75103
76104menubar .grid_button ('prefs' , row = 0 , column = 4 )
77105
@@ -93,33 +121,19 @@ def changing_theme_func():
93121 root .after (10 , changing_theme_func )
94122#changing_theme_func()
95123
96- ## Config file
97- def load_config_file ():
98- print ('Loading config file...' , end = ' ' )
99- config_file_obj = open (os .path .expanduser ('~' )+ '/.fedit' , 'r' )
100- config_file = config_file_obj .read ()
101- config_file_obj .close ()
102- print ('Done' )
103-
104- if os .path .isfile (os .path .expanduser ('~' )+ '/.fedit' ):
105- load_config_file ()
106- else :
107- print ('First time running Fedit, creating config file...' , end = ' ' )
108- config_file_obj = open (os .path .expanduser ('~' )+ '/.fedit' , 'w' )
109- print (os .path .expanduser ('~' )+ '/.fedit' )
110- import requests
111- data = requests .get ('https://smallbytes.pythonanywhere.com/Fedit/newuser' )
112- config_file_obj .write (str (data .content , encoding = 'ascii' ))
113- config_file_obj .close ()
114- load_config_file ()
115-
116-
117-
118-
119124## Packing
120125frame_menubar .pack (side = 'top' , expand = 1 , fill = 'both' )
121126frame_maintextedit .pack (expand = 1 , fill = 'both' )
122127
128+ ## Complete exit
129+ def complete_exit ():
130+ if messagebox .askokcancel ("Quit" , "Do you want to quit? The open file may not be saved." ):
131+ root .destroy ()
132+ print ('Exiting via Quit' )
133+ sys .exit ()
134+
135+ root .protocol ("WM_DELETE_WINDOW" , complete_exit )
136+
123137## Start the window
124138root .mainloop ()
125139
0 commit comments