Skip to content

Commit

Permalink
add alpha panel
Browse files Browse the repository at this point in the history
  • Loading branch information
tyshoe committed Mar 19, 2024
1 parent 0b106a5 commit 2c19c5b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 43 deletions.
35 changes: 4 additions & 31 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def __init__(self):
self.mainloop()

def init_parameters(self):
self.order_var = StringVar(value="RGBA")
self.add_r_var = IntVar(value=0)
self.add_g_var = IntVar(value=0)
self.add_b_var = IntVar(value=0)
self.add_a_var = IntVar(value=0)

self.channels_var = ctk.StringVar(value = CHANNELS[0])
self.channels_var = StringVar(value = CHANNELS[0])

def import_image(self, path):
global image
Expand All @@ -55,7 +55,7 @@ def resize_image(self, event):

canvas_ratio = event.width / event.height

# reize image
# resize image
if canvas_ratio > self.image_ratio: # canvas wider than image
image_height = int(event.height)
image_width = int(image_height * self.image_ratio)
Expand All @@ -70,8 +70,6 @@ def resize_image(self, event):
self.image_output.create_image(
event.width/2, event.height/2, image=self.image_tk)

# self.tab_view = MyTabView(master=self)
# self.tab_view.grid(row=0, column=0, padx=20, pady=20)

def export_image(self, name, file, path):
export_string = f'{path}/{name}.{file}'
Expand All @@ -89,26 +87,6 @@ def export_image(self, name, file, path):
# elif image.mode == "RGB":
# return False

# def open_add_alpha_window():
# add_alpha_window = Toplevel(root)
# add_alpha_window.title("Add Value to Channel A")

# # Slider to add value to channel A
# alpha_slider = Scale(add_alpha_window, from_=0.0, to=1.0, resolution=0.01,
# orient=ctk.HORIZONTAL, length=200, label="Add to Channel A")
# alpha_slider.set(add_alpha_var.get())
# alpha_slider.pack()

# # Button to confirm and apply the value
# confirm_alpha_button = ctk.Button(add_alpha_window, text="Confirm", command=lambda: save_and_add_alpha(
# alpha_slider.get(), add_alpha_window))
# confirm_alpha_button.pack()

# def save_and_add_alpha(add_alpha, window):
# add_alpha_var.set(add_alpha)
# window.destroy()
# apply_color() # Call the function to update the modified image after changing channel A

# def apply_color():
# global image, modified_image

Expand Down Expand Up @@ -261,9 +239,4 @@ def export_image(self, name, file, path):

# add_button = ctk.CTkButton(frame, text="Adjust RGB",
# command=open_add_values_window)
# add_button.grid(row=2, column=1, padx=20, pady=20)

# add_alpha_var = DoubleVar(value=1.0)
# add_alpha_button = ctk.CTkButton(
# frame, text="Adjust A", command=open_add_alpha_window)
# add_alpha_button.grid(row=2, column=2, padx=20, pady=20)
# add_button.grid(row=2, column=1, padx=20, pady=20)
15 changes: 8 additions & 7 deletions menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from panels import *
from settings import *


class Menu(ctk.CTkTabview):
def __init__(self, parent, export_image, channels_var):
super().__init__(master=parent)
self.grid(column=0, row=0, sticky='nsew', padx = 10, pady = 10)
self.grid(column=0, row=0, sticky='nsew', padx=10, pady=10)

# create tabs
self.add("Import")
Expand All @@ -22,24 +23,24 @@ def __init__(self, parent, export_image, channels_var):

class EditFrame(ctk.CTkFrame):
def __init__(self, parent, channels_var):
super().__init__(master=parent, fg_color = 'transparent')
super().__init__(master=parent, fg_color='transparent')
self.pack(expand=True, fill='both')

DropdownPanel(self, channels_var, CHANNELS)
AlphaPanel(self)
EditPanel(self)



class ExportFrame(ctk.CTkFrame):
def __init__(self, parent, export_image):
super().__init__(master=parent, fg_color = 'transparent')
super().__init__(master=parent, fg_color='transparent')
self.pack(expand=True, fill='both')

self.name_string = ctk.StringVar()
self.file_string = ctk.StringVar(value = 'jpg')
self.file_string = ctk.StringVar(value='jpg')
self.path_string = ctk.StringVar()

FileNamePanel(self, self.name_string, self.file_string)
FilePathPanel(self, self.path_string)
SaveButton(self, export_image, self.name_string, self.file_string, self.path_string)

SaveButton(self, export_image, self.name_string,
self.file_string, self.path_string)
22 changes: 17 additions & 5 deletions panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,27 @@ def __init__(self, parent):
super().__init__(parent=parent)
self.pack(fill='x', pady=4)

add_alpha_var = ctk.DoubleVar(value=1.0)
add_alpha_button = ctk.CTkButton(self, text="Add to Channel A")
add_alpha_button.pack(side='top', pady=10)

# Create a button to apply color substitution
apply_button = ctk.CTkButton(self, text="Apply color")
apply_button.pack(side='top', pady=10)

add_button = ctk.CTkButton(self, text="Add Colors")
add_button.pack(side='top', pady=10)


class AlphaPanel(Panel):
def __init__(self, parent):
super().__init__(parent=parent)
self.pack(fill='x', pady=4)

self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1, uniform='a')
self.columnconfigure(1, weight=3, uniform='a')

label = ctk.CTkLabel(self, text="Alpha")
label.grid(column=0, row=0, pady=5, sticky='E')
alpha = ctk.CTkEntry(self, placeholder_text="100")
alpha.grid(column=1, row=0, pady=5)
add_alpha_button = ctk.CTkButton(self, text="Apply Alpha",)
add_alpha_button.grid(column=0, row=1, columnspan=2, pady=(0, 10))
#TODO add command to save alpha value

0 comments on commit 2c19c5b

Please sign in to comment.