Skip to content

Commit fbf7758

Browse files
Add files via upload
1 parent 18c5178 commit fbf7758

File tree

1 file changed

+194
-19
lines changed

1 file changed

+194
-19
lines changed

Elements.py

Lines changed: 194 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
from pynput.keyboard import Key, Listener ## detect keyboard press for shortcuts with listener
3838
from pynput import keyboard ## keyboard press for shortcut
3939
import random ## import random generator
40+
from tkinter import colorchooser ## Choose Colour
41+
from tkinter.commondialog import Dialog
42+
## font chooser import
43+
from sys import platform ## platform details
44+
from tkfontchooser import askfont ## import font chooser
4045

4146
############################################################### Class ####################################################################
4247
#Hover button Class
@@ -53,15 +58,56 @@ def on_enter(self, e):
5358
def on_leave(self, e):
5459
self['background'] = self.defaultBackground
5560

61+
# option not used
62+
class MyOptionMenu(OptionMenu):
63+
def __init__(self, master, status, *options):
64+
self.var = StringVar(master)
65+
self.var.set(status)
66+
OptionMenu.__init__(self, master, self.var, *options)
67+
self.config(font=('calibri',(10)),bg='#1a1a1a',width=16, activebackground="#2a2a2a", bd ="0", fg = "white")
68+
self['menu'].config(font=('calibri',(10)),bg='#1a1a1a', bd = "0", fg = "white")
69+
70+
# Colour Picker tkinter class
71+
# __all__ = ["Chooser", "askcolor"]
72+
class Chooser(Dialog):
73+
"Ask for a color"
74+
75+
command = "tk_chooseColor"
76+
77+
def _fixoptions(self):
78+
try:
79+
# make sure initialcolor is a tk color string
80+
color = self.options["initialcolor"]
81+
if isinstance(color, tuple):
82+
# assume an RGB triplet
83+
self.options["initialcolor"] = "#%02x%02x%02x" % color
84+
except KeyError:
85+
pass
86+
87+
def _fixresult(self, widget, result):
88+
# result can be somethings: an empty tuple, an empty string or
89+
# a Tcl_Obj, so this somewhat weird check handles that
90+
if not result or not str(result):
91+
return None, None # canceled
92+
93+
# to simplify application code, the color chooser returns
94+
# an RGB tuple together with the Tk color string
95+
r, g, b = widget.winfo_rgb(result)
96+
# return (r/256, g/256, b/256), str(result)
97+
return str(result)
98+
5699
############################################################ Main Window #################################################################
57100
#define Main Window and configuration
58101
mainwin = tkinter.Tk()
59102
mixer.init()
60103
mainwin.geometry("1200x800+150+15")
61104
#mainwin.maxsize(1200,800)
105+
mainwin.resizable(FALSE,FALSE) ## Disable resizing
62106
mainwin.title("Elements Voiced Image Editing")
63107
mainwin.iconbitmap(r"elements2.0Images\logofull2_1TB_icon.ico")
64108
mainwin.configure(bg="#0d0d0d")
109+
# mainwin.iconify()
110+
# mainwin.deiconify()
65111

66112
#canvas for workspace
67113
canvas = tkinter.Canvas(mainwin, width = 1200, height =800 ,bg="#0d0d0d", bd="0",borderwidth = "0", highlightthickness = "0", cursor="arrow" )
@@ -101,8 +147,8 @@ def connection():
101147
first_time = False
102148
internet_access = False
103149

104-
#logo Button FunctionS
105-
def logobtn_clicked():
150+
# splash screen Function
151+
def splash_screen():
106152
random_number = str(random.randint(0, 21))
107153
logo_win = Toplevel(mainwin)
108154
img1_logo = Image.open(r"elements2.0Images/splashscreen/"+ random_number + ".png")
@@ -112,13 +158,32 @@ def logobtn_clicked():
112158
l1.pack()
113159
l1.photo=photo_logo
114160

115-
logo_win.title("Credits")
161+
logo_win.title("Loading Assets")
116162
logo_win.iconbitmap(r"elements2.0Images\logofull2_1TB_icon.ico")
117163
logo_win.geometry("900x563+400+200")
118164
logo_win.maxsize(900,563)
119165
logo_win.attributes('-topmost', 'true') ## bring savve window top and visible
166+
logo_win.wm_overrideredirect(1)
120167
logo_win.after(3456, logo_win.destroy)
121168

169+
#logo Button FunctionS
170+
def logobtn_clicked():
171+
172+
logo_win = Toplevel(mainwin)
173+
img1_logo = Image.open(r"elements2.0Images\assets\splashscreen.png")
174+
img1_logo = img1_logo.resize((900,400), Image.ANTIALIAS)
175+
photo_logo = ImageTk.PhotoImage(img1_logo)
176+
l1= Label(logo_win, bg="grey", image=photo_logo)
177+
l1.pack()
178+
l1.photo=photo_logo
179+
180+
logo_win.title("Credits")
181+
logo_win.iconbitmap(r"elements2.0Images\logofull2_1TB_icon.ico")
182+
logo_win.geometry("900x400+400+200")
183+
logo_win.maxsize(900,400)
184+
logo_win.attributes('-topmost', 'true') ## bring window top and visible
185+
logo_win.after(5000, logo_win.destroy)
186+
122187
#logo button
123188
img_logo = Image.open(r"elements2.0Images\elementslogo.png")
124189
img_logo = img_logo.resize((35,35), Image.ANTIALIAS)
@@ -133,23 +198,36 @@ def logobtn_clicked():
133198
global current_img
134199
current_img = None
135200

136-
#canvas where image shows
201+
# canvas where image shows
137202
canvas1 = Canvas(canvas, bg="black", bd="0", borderwidth = "0", highlightthickness = "0", cursor="plus")
138203
canvas1.place(x="30", y="30", relwidth="0.85", relheight="0.75")
139204
labelshow = Label(canvas1, bg="black", bd="0", borderwidth = "0", highlightthickness = "0",image= None)
140205
labelshow.pack(fill= BOTH)
141206

142-
# calling logobtn clicked for spalsh screen
143-
logobtn_clicked()
207+
# calling spalsh screen
208+
splash_screen()
209+
210+
# color picker for board and text
211+
def askcolor(color = None, **options):
212+
"Ask for a color"
213+
global text_newcl_button
214+
global text_colour
215+
if color:
216+
options = options.copy()
217+
options["initialcolor"] = color
144218

219+
text_colour = Chooser(**options).show()
220+
text_newcl_button.config(bg = text_colour)
221+
145222
# asks for import option function
146223
def import_options():
147224
global import_win
148225
import_win = Toplevel(mainwin)
149226
import_win.title("Import image")
150227
import_win.iconbitmap(r"elements2.0Images\logofull2_1TB_icon.ico")
151228
import_win.geometry("900x500+400+200")
152-
import_win.maxsize(900,500)
229+
# import_win.maxsize(900,500)
230+
import_win.resizable(FALSE,FALSE) ## Disable resizing
153231
import_win.config(bg="#1c1c1c")
154232
import_win.grab_set() ## prevent duplication of same window and block main window
155233

@@ -806,14 +884,111 @@ def filter_clicked():
806884

807885
#add Text button
808886
def addtext_clicked():
809-
print("on progress")
810-
canvas_add_text = Canvas(canvas, bg ="gray", bd="0", borderwidth = "0", highlightthickness = "0" )
811-
canvas_add_text.place(x="950", y="230", relwidth="0.123", relheight="0.45")
812-
813887
global current_img
814-
draw = ImageDraw.Draw(current_img)
815-
content_get_label="content"
816-
888+
if current_img != None:
889+
print("on progress")
890+
canvas_add_text = Canvas(canvas, bg ="#0d0d0d", bd="0", borderwidth = "0", highlightthickness = "0")
891+
canvas_add_text.place(x="750", y="290", relwidth="0.25", relheight="0.42")
892+
893+
# get text
894+
get_text_label = Label(canvas_add_text, text = "enter text :", fg="white", bg = "#0d0d0d")
895+
get_text_label.place(x="20", y="20")
896+
get_text=Entry(canvas_add_text, bg="#1a1a1a" , bd="0", fg="white")
897+
get_text.place(x="140", y="15", relwidth=".5", relheight="0.1")
898+
899+
# get font size
900+
get_font_size_label = Label(canvas_add_text, text = "enter font size :", fg="white", bg = "#0d0d0d")
901+
get_font_size_label.place(x="20", y="60")
902+
get_font_size=Entry(canvas_add_text,bg="#1a1a1a" , bd="0", fg="white")
903+
get_font_size.place(x="140", y="55", relwidth=".5", relheight="0.1")
904+
905+
# choose font type and style
906+
get_font_label = Label(canvas_add_text, text = "Select font :", fg="white", bg = "#0d0d0d")
907+
get_font_label.place(x="20", y="100")
908+
## select_font_option = MyOptionMenu(canvas_add_text, 'Select Font', 'arial','impact','times new roman')
909+
## select_font_option.place(x="140", y="100")
910+
selected_font_label = Label(canvas_add_text, text = "Select font :", fg="white", bg = "#0d0d0d")
911+
selected_font_label.place(x="140", y="100")
912+
select_font_button= tkinter.Button(canvas_add_text, bg ="gray",text="new", bd =".5",width= "3", height = "1", command =lambda: askcolor())
913+
select_font_button.place(x="268", y="175")
914+
915+
# get font colour
916+
get_text_colour = Label(canvas_add_text, text = "Select font colour :", fg="white", bg = "#0d0d0d")
917+
get_text_colour.place(x="20", y="140")
918+
919+
def choose_colour(colour):
920+
global text_colour
921+
text_colour = colour
922+
#sprint (text_colour)
923+
924+
red_button = tkinter.Button(canvas_add_text, bg ="red", bd= ".5",width= "3", height = "1", command =lambda: choose_colour("red"))
925+
red_button.place(x="140", y="145")
926+
927+
blue_button = tkinter.Button(canvas_add_text, bg ="blue", bd =".5", width= "3", height = "1",command =lambda: choose_colour("blue"))
928+
blue_button.place(x="172", y="145")
929+
930+
yellow_button= tkinter.Button(canvas_add_text, bg ="yellow", bd =".5",width= "3", height = "1",command =lambda: choose_colour("yellow"))
931+
yellow_button.place(x="204", y="145")
932+
933+
green_button= tkinter.Button(canvas_add_text, bg ="green", bd =".5",width= "3", height = "1", command = lambda: choose_colour("green"))
934+
green_button.place(x="236", y="145")
935+
936+
violet_button= tkinter.Button(canvas_add_text, bg ="violet", bd =".5" ,width= "3", height = "1",command =lambda: choose_colour("violet"))
937+
violet_button.place(x="268", y="145")
938+
939+
orange_button= tkinter.Button(canvas_add_text, bg ="orange", bd =".5" ,width= "3", height = "1",command =lambda: choose_colour("orange"))
940+
orange_button.place(x="140", y="175")
941+
942+
black_button= tkinter.Button(canvas_add_text, bg ="black", bd =".5", width= "3", height = "1",command =lambda: choose_colour("black"))
943+
black_button.place(x="172", y="175")
944+
945+
white_button= tkinter.Button(canvas_add_text, bg ="white", bd =".5",width= "3", height = "1", command =lambda: choose_colour("white"))
946+
white_button.place(x="204", y="175")
947+
948+
gray_button= tkinter.Button(canvas_add_text, bg ="gray", bd =".5",width= "3", height = "1", command =lambda: choose_colour("white"))
949+
gray_button.place(x="236", y="175")
950+
951+
## choose colour Manually
952+
global text_newcl_button
953+
text_newcl_button= tkinter.Button(canvas_add_text, bg ="gray",text="new", bd =".5",width= "3", height = "1", command =lambda: askcolor())
954+
text_newcl_button.place(x="268", y="175")
955+
956+
def apply():
957+
global current_img
958+
global text_colour
959+
# get text
960+
text = get_text.get()
961+
print(text)
962+
# text size
963+
text_size = int(get_font_size.get())
964+
print(text_size)
965+
# font
966+
cfont=str(select_font_option.var)
967+
print (cfont)
968+
# text colour
969+
f_c =text_colour
970+
print(f_c)
971+
# apply font
972+
draw = ImageDraw.Draw(current_img)
973+
font = ImageFont.truetype(cfont+'.ttf', size=text_size)
974+
draw.text((300, 300), text, fill=f_c, font=font)
975+
976+
## show image
977+
image = draw
978+
width, height = image.size
979+
image_resized = resize_image(width, height,label_width,label_height,image)
980+
text_added = ImageTk.PhotoImage(image=image_resized)
981+
labelshow.image= text_added
982+
labelshow.configure(image= text_added)
983+
current_img=image
984+
Undo.append(current_img)
985+
986+
canvas_add_text.after(1000, canvas_add_text.destroy)
987+
canvastoolbar.destroy
988+
989+
button_apply_font = HoverButton(canvas_add_text, bg = "#0d0d0d", bd="0", height = "1", width ="15",text = "Apply Font", compound= "left",fg ="gray",command=lambda:apply())
990+
button_apply_font.place(x="20", y="300")
991+
817992
#add text function
818993
img_addtext = Image.open(r"elements2.0Images\assets\addtext.png")
819994
img_addtext = img_addtext.resize((30,32), Image.ANTIALIAS)
@@ -1161,7 +1336,7 @@ def reset_image():
11611336
current_img= original_img
11621337

11631338
show_on_hover = HoverButton(canvas, bg = "#1f1f1f", bd="0",text = "compare/reset here",fg ="white",activebackground = "#FF6B26", command=lambda: reset_image())
1164-
show_on_hover.place(x="1100", y="750", relwidth=".088", relheight=".05")
1339+
show_on_hover.place(x="1090", y="750", relwidth=".09", relheight=".05")
11651340
show_on_hover.bind("<Enter>", show_on_enter)
11661341
show_on_hover.bind("<Leave>", show_on_leave)
11671342

@@ -1213,7 +1388,8 @@ def save():
12131388
save_win.title("Save image")
12141389
save_win.iconbitmap(r"elements2.0Images\logofull2_1TB_icon.ico")
12151390
save_win.geometry("800x400+400+200")
1216-
save_win.maxsize(800,400)
1391+
# save_win.maxsize(800,400)
1392+
save_win.resizable(FALSE,FALSE) ## Disable resizing
12171393
save_win.config(bg="#1c1c1c")
12181394
save_win.grab_set() ## prevent aditional save window opening
12191395

@@ -1432,7 +1608,7 @@ def on_closing():
14321608
if messagebox.askokcancel("Quit", "Do you want to Stop Editing?"):
14331609
mainwin.destroy()
14341610

1435-
#listen for do!
1611+
# listen for do!
14361612
def do():
14371613
for phrase in LiveSpeech():
14381614
print(phrase)
@@ -1508,18 +1684,17 @@ def on_release(key):
15081684
organise offline editing for indian slang
15091685
customize keybord shortcuts
15101686
mesed up Entry of values
1687+
add text
15111688
15121689
### to add ###
15131690
active voice recognition
15141691
independent value/parameter fetching over voice
15151692
crop
1516-
add text
15171693
Voiced File browser
15181694
Social share
15191695
Auto gama correction
15201696
merge images/add
15211697
histogram
1522-
okey elements "do" recognition
15231698
ruler
15241699
15251700
### try ###

0 commit comments

Comments
 (0)