Skip to content

Commit fb9fd51

Browse files
committed
#4: Changed button themes, made all windows close on exit, fixed bugs
1 parent d876c1d commit fb9fd51

File tree

5 files changed

+62
-49
lines changed

5 files changed

+62
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.pyc
2+
__pycache__/

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
To run Fedit, run `python3 main.py` in the root directory
2-
of this repositry.
1+
FEDIT - Pythonic456
32

4-
To install Fedit, run `sudo python3 setup.py install`.
5-
To uninstall Fedit, run `sudo python3 setup.py remove`.
3+
To install:
4+
`cd ~`
5+
`git clone https://github.com/Pythonic456/Fedit/`
6+
`cd ~/Fedit/`
7+
`sudo python3 setup.py install`
8+
9+
To uninstall:
10+
`cd ~/Fedit/`
11+
`sudo python3 setup.py remove`
12+
`rm -r ~/Fedit/`

main.py

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 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

56
version = '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
1846
frame_maintextedit = tk.Frame(root)
1947
widget_maintextedit = tktools.TextEditor(frame_maintextedit, root_title, set_root_title)
@@ -37,31 +65,31 @@ def set_root_title(title):
3765

3866
## Theme
3967
theme_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

5078
def 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

6187
def 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

6694
def 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

73101
menubar.add_button('prefs', prefs_window, 'Prefrences')
74-
update_theme(theme_light, theme_dark)
102+
switch_theme()
75103

76104
menubar.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
120125
frame_menubar.pack(side='top', expand=1, fill='both')
121126
frame_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
124138
root.mainloop()
125139

notes.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

tktools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import tkinter as tk
33
from tkinter import filedialog as tkfd
44
from tkinter import messagebox as tkmb
5-
import os
5+
import os, sys
66

77

88
## Classes

0 commit comments

Comments
 (0)