-
Notifications
You must be signed in to change notification settings - Fork 0
/
panels.py
132 lines (100 loc) · 4.84 KB
/
panels.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import customtkinter as ctk
from tkinter import filedialog
from settings import *
# Panels
class Panel(ctk.CTkFrame):
def __init__(self, parent):
super().__init__(master=parent, fg_color=DARK_GREY)
self.pack(fill='x', pady='4', ipady='8')
class SliderPanel(Panel):
def __init__(self, parent, text, data_var, min_value, max_value):
super().__init__(parent=parent)
# Layout
self.rowconfigure((0, 1), weight=1)
self.columnconfigure((0, 1), weight=1)
self.data_var = data_var
self.data_var.trace('w', self.update_text)
ctk.CTkLabel(self, text=text).grid(column=0, row=0, sticky='W', padx=5)
self.num_label = ctk.CTkLabel(self, text=data_var.get())
self.num_label.grid(column=1, row=0, sticky='E', padx=5)
ctk.CTkSlider(self, fg_color=SLIDER_BG, variable=self.data_var, from_=min_value, to=max_value).grid(
row=1, column=0, columnspan=2, sticky='ew', padx=5, pady=5)
def update_text(self, *args):
self.num_label.configure(text=f'{round(self.data_var.get(), 2)}')
class SegmentedPanel(Panel):
def __init__(self, parent, text, data_var, options):
super().__init__(parent=parent)
ctk.CTkLabel(self, text=text).pack()
ctk.CTkSegmentedButton(self, variable=data_var, values=options).pack(
expand=True, fill='both', padx=4, pady=4)
class SwitchPanel(Panel):
def __init__(self, parent, *args): # ((var, text), (var, text)) ~ basically tuples
super().__init__(parent=parent)
for var, text in args:
switch = ctk.CTkSwitch(
self, text=text, variable=var, button_color=BLUE, fg_color=SLIDER_BG)
switch.pack(side='left', expand=True, fill='both', padx=5, pady=5)
class FileNamePanel(Panel):
def __init__(self, parent, name_string, file_string):
super().__init__(parent=parent)
self.name_string = name_string
self.name_string.trace('w', self.update_text)
self.file_string = file_string
# checkboxes for file format
ctk.CTkEntry(self, textvariable=self.name_string).pack(
fill='x', padx=20, pady=5)
frame = ctk.CTkFrame(self, fg_color='transparent')
jpg_check = ctk.CTkCheckBox(frame, text='jpg', variable=self.file_string,
command=lambda: self.click('jpg'), onvalue='jpg', offvalue='png')
png_check = ctk.CTkCheckBox(frame, text='png', variable=self.file_string,
command=lambda: self.click('png'), onvalue='png', offvalue='jpg')
jpg_check.pack(side='left', fill='x', expand=True)
png_check.pack(side='left', fill='x', expand=True)
frame.pack(expand=True, fill='x', padx=20)
# preview text
self.output = ctk.CTkLabel(self, text='')
self.output.pack()
def click(self, value):
self.file_string.set(value)
self.update_text()
def update_text(self, *args):
if self.name_string.get():
text = self.name_string.get().replace(' ', '_') + '.' + self.file_string.get()
self.output.configure(text=text)
class FilePathPanel(Panel):
def __init__(self, parent, path_string):
super().__init__(parent=parent)
self.path_string = path_string
ctk.CTkButton(self, text='Open Explorer',
command=self.open_file_dialog).pack(pady=5)
ctk.CTkEntry(self, textvariable=self.path_string).pack(expand=True, fill='both', padx=5, pady=5)
def open_file_dialog(self):
self.path_string.set(filedialog.askdirectory())
class DropDownPanel(ctk.CTkOptionMenu):
# ((var, text), (var, text)) ~ basically tuples
def __init__(self, parent, data_var, options):
super().__init__(master=parent, values=options, fg_color=DARK_GREY, button_color=DROPDOWN_MAIN_COLOR,
button_hover_color=DROPDOWN_Hover_COLOR, dropdown_fg_color=DROPDOWN_MENU_COLOR, variable=data_var)
self.pack(fill='x', pady=4)
class RevertButton(ctk.CTkButton):
def __init__(self, parent, *args):
super().__init__(master=parent, text='Revert', command=self.revert)
self.pack(side='bottom', pady=10)
self.args = args
def revert(self):
for var, value in self.args:
var.set(value)
class SaveButton(ctk.CTkButton):
def __init__(self, parent, export_image, name_string, file_string, path_string):
super().__init__(master=parent, text='save', command=self.save)
self.pack(side = 'bottom', pady = 10)
self.export_image = export_image
self.name_string = name_string
self.file_string = file_string
self.path_string = path_string
def save(self):
self.export_image(
self.name_string.get(),
self.file_string.get(),
self.path_string.get()
)