-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
207 lines (150 loc) · 6.1 KB
/
main.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import tkinter as tk
from tkinter import *
import translator as tsl
#Tkinter Development
class TextWithPlaceHolder(tk.Entry):
def __init__(self, master=None, placeholder="PLACEHOLDER", color='grey'):
super().__init__(master)
self.placeholder = placeholder
self.placeholder_color = color
self.default_fg_color = self['fg']
self.bind("<FocusIn>", self.foc_in)
self.bind("<FocusOut>", self.foc_out)
self.put_placeholder()
def put_placeholder(self):
self.insert(0, self.placeholder)
self['fg'] = self.placeholder_color
def foc_in(self, *args):
if self['fg'] == self.placeholder_color:
self.delete('0', 'end')
self['fg'] = self.default_fg_color
def foc_out(self, *args):
if not self.get():
self.put_placeholder()
if __name__ == "__main__":
#Creates the window
window = tk.Tk()
#Window Title Sets
window.title("Morse Code Translator 2020")
#Screen Resolution Info and Application to Program
pc_resol_width = window.winfo_screenwidth()
pc_resol_height = window.winfo_screenheight()
#print("pc screen resolution width: "+str(pc_resol_width)) #for debugging only
#print("pc screen resolution height: "+str(pc_resol_height)) #for debugging only
#Set the window geometry
program_width=pc_resol_width//2 #set program width
program_height=pc_resol_height//2 #set program height
window.geometry("{}x{}+{}+{}".format(program_width,program_height,program_width//10,program_height//10)) #optimized with screen resolution
#set the program as resizable
#window.resizable(False,False) #width and height values are closed to resize # it can be uncomment.
#Input label
label_input = tk.Label(
window,
text="Input",
anchor="w",
padx=5,
pady=5,
font=("Open Sans","12","bold")
)
label_input.pack(anchor="ne",fill="x")
#tex1 - entry place for data.
placeholder_message = "Type your message here:"
text1 = TextWithPlaceHolder(window, placeholder_message, color="grey")
#text1.place(width=program_width,height=program_height/3)
#text1.pack(anchor="ne",fill="x",expand=1,padx=5,pady=5) #side="left"
#text1.place(bordermode="outside",height=100,width=100) #side="left"
text1.pack(anchor="ne",fill="x") #I have the height problem, #BUG make tex1 height more better
#Output label
label_output = tk.Label(
window,
text="Output",
anchor="w",
padx=5,
pady=5,
font=("Open Sans","12","bold")
)
label_output.pack(anchor="ne",fill="x")
#text2 output of converting data
text2 = tk.Text(
window,
height=5,
width=program_width,
padx=5,
pady=5,
font=("Open Sans","12","normal"),
)
text2.configure(state="disabled") #it disable the text for input
text2.pack()
def get_data():
#Get the data from expession and declare as expession
expression = text1.get()
#Multiple spaces turns to one spaace between words.
expression = " ".join(expression.split())
#This statement prevents to converting placeholder_message any time.
if expression == placeholder_message:
expression = ""
#Converting step
converted_expression_object = tsl.MorseTranslator(expression)
converted_expression = (converted_expression_object.morse_translation_func())
text2.configure(state="normal") #it enables the text for input
text2.delete("1.0","end") # tex2 is clearing for the old converting
text2.insert(INSERT,converted_expression) #conterting data is inserting to text2
text2.configure(state="disabled") #it disable the text for input
def exit_func():
quit()
def clear_texts():
clear_text1()
clear_text2()
TextWithPlaceHolder().put_placeholder()
def clear_text1():
text1.delete(0,"end")
TextWithPlaceHolder().put_placeholder() ###################
def clear_text2():
text2.configure(state="normal") #it disable the text for input
text2.delete("1.0","end")
text2.configure(state="disabled") #it disable the text for input
#Convert button
button_convert = Button(
text="Convert",
command=get_data
)
button_convert.pack(anchor="ne",side="left",padx=5,pady=5)
#Clear button
button_exit = Button(
text="Clear",
command=clear_texts
)
button_exit.pack(anchor="ne",side="left",padx=5,pady=5)
#Exit button
button_exit = Button(
text="Exit",
command=exit_func
)
button_exit.pack(anchor="ne",side="left",padx=5,pady=5)
window.mainloop()
# #Terminal Program is starting with text bellow, it is writing on the screen only one time
# #########################################################################################
# # print("""....................................................
# # - Morse Code Translation Application - ozy_csfb
# # ....................................................\n
# # - Write your expression and press the enter!
# # ....................................................\n
# # - Only English letters and numbers can be converted.
# # ....................................................
# # Write you expression please.""")
# #########################################################################################
# #While loop is working for the program as infinite state
# # while True:
# # expression = tsl.get_expression()
# # result = tsl.MorseTranslator(expression)
# # print(result.morse_translation_func())
# # loop_status = tsl.exit_quest()
# # #This statement check the answer from user. If loop_status is true, loop will break.
# # if loop_status == True:
# # break
# #This step for keep the terminal alive after end the while loop.
# # print("........................")
# # input("For exit press the Enter.")
# #########################################################################################
# #for continuity of the window - it is also important to turn down the program
# mainloop()