/
edit_settings.py
100 lines (86 loc) · 2.98 KB
/
edit_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from tkinter import *
from tkinter import messagebox
import os, sys
import json
def color_handler(color_val):
if color_val is 'Green':
return 'color 0a'
elif color_val is 'Blue':
return 'color 01'
elif color_val is 'Red':
return 'color 04'
elif color_val is 'White':
return 'color 07'
elif color_val is 'Black on White':
return 'color F0'
def ask_reset():
result = messagebox.askquestion("Reset Settings", "Are You Sure?", icon='warning')
print(result)
if 'yes' in result:
default_settings()
def default_settings():
#rewrite in JSON
data = {}
data['color'] = '0a'
data['exit'] = 'exit'
data['minimize'] = 'min'
data['width'] = ''
data['height'] = ''
json_data = json.dumps(data)
json_file = open('settings.json', 'w')
json_file.write(json_data)
json_file.close()
messagebox.showinfo('WinGuake', 'Settings will be applied on next WinGuake restart.')
sys.exit()
def apply_settings(settings_list):
#rewrite in JSON
data = {}
print(settings_list)
data['color'] = settings_list[0]
data['exit'] = settings_list[1]
data['minimize'] = settings_list[4]
data['width'] = settings_list[2]
data['height'] = settings_list[3]
json_data = json.dumps(data)
json_file = open('settings.json', 'w')
json_file.write(json_data)
json_file.close()
messagebox.showinfo("WinGuake", "Settings will be applied on next WinGuake restart.")
sys.exit()
#print(os.path.dirname(os.path.abspath(__file__)))
icon = r'{}/winguake_icon.ico'.format(os.path.dirname(os.path.abspath(__file__)))
root = Tk()
color_text = Label(root, text="Color")
color_text.grid(row=0)
color = StringVar()
color.set('Green')
color_box = OptionMenu(root, color, "Green", "Blue", "Red", "White", "Black on White")
color_box.grid(row=0, column=1)
exit_text = Label(root, text="WinGuake exit command")
exit_text.grid(row=1)
exit_var = StringVar()
exit_box = Entry(root, bd=3, textvariable=exit_var)
exit_box.grid(row=1, column=1)
min_text = Label(root, text="WinGuake minimize command")
min_text.grid(row=2)
min_var = StringVar()
min_box = Entry(root, bd=3, textvariable=min_var)
min_box.grid(row=2, column=1)
width_text = Label(root, text="WinGuake starting width")
width_text.grid(row=3)
width_var = StringVar()
width_box = Entry(root, bd=3, textvariable=width_var)
width_box.grid(row=3, column=1)
height_text = Label(root, text="WinGuake starting height")
height_text.grid(row=4)
height_var = StringVar()
height_box = Entry(root, bd=3, textvariable=height_var)
height_box.grid(row=4, column=1)
apply_button = Button(root, text="Apply", command= lambda: apply_settings([color.get(), exit_var.get(), width_var.get(), height_var.get(), min_var.get()])).grid(row=5) #1: color, 2: exit, 3: width, 4: height
reset_buttom = Button(root, text="Reset Settings", command=ask_reset).grid(row=5, column=1)
root.title("WinGuake Settings")
try:
root.iconbitmap(icon)
except:
print("Icon not found.")
root.mainloop()