-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
112 lines (91 loc) · 3.14 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
import platform, tkinter as tk
from tkinter import END, TOP, ttk
#Set OS ttk theme data
if platform.system() == "Linux":
OS_THEME = "classic"
elif platform.system() == "Darwin":
OS_THEME = "aqua"
else:
OS_THEME = "xpnative"
class Window(tk.Tk):
def __init__(self,*args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.button_box=tk.Frame(self)
self.button_box.pack(padx=10,side=tk.LEFT,expand=True,fill="y")
self.is_multiline=tk.IntVar()
languages=['c++','python', "java"]#available programming languages
self.language=ttk.Combobox(self.button_box,values=languages)
self.language.pack(pady=10)
self.language.set("c++")
self.multiline=tk.Checkbutton(self.button_box,variable=self.is_multiline,onvalue=1,offvalue=0,text="multiline")
self.multiline.pack(padx=10)
self.convert=ttk.Button(self.button_box,text="convert",command=self.stringify)
self.convert.pack(pady=10,side=TOP,fill="x")
self.style=ttk.Style(self)
self.style.theme_use(OS_THEME)
self.itext=tk.Text(self)
self.itext.pack(padx=10,expand=True,fill="y",side=tk.LEFT)
self.otext=tk.Text(self)
self.otext.pack(padx=10,expand=True,fill="y",side=tk.LEFT)
self.otext.config(state=tk.DISABLED)
#convert function
def stringify(self):
i =self.itext.get("1.0",END)[0:-1]
lang=self.language.get()
out=str
if lang=="c++":
out='"'
for c in i :
if(c == '"'):
out+='\\\"'
elif(c=='\n'):
out +='\\n'
if(self.is_multiline.get()==1):
out+='"\n"'
elif(c=='\t'):
out+='\\t'
elif(c=='\\'):
out+='\\\\'
else:
out+=c
out+='"'
elif lang=="python":
if self.is_multiline.get()==1:
out='\"\"\"'+i+'\"\"\"'
else:
out='"'
for c in i :
if(c == '"'):
out+='\\\"'
elif(c=='\n'):
out +='\\n'
elif(c=='\t'):
out+='\\t'
elif(c=='\\'):
out+='\\\\'
else:
out+=c
out+='"'
elif lang=="java":
out='"'
for c in i :
if(c == '"'):
out+='\\\"'
elif(c=='\n'):
out +='\\n'
if(self.is_multiline.get()==1):
out+='"\n"'
elif(c=='\t'):
out+='\\t'
elif(c=='\\'):
out+='\\\\'
else:
out+=c
out+='"'
self.otext.config(state=tk.NORMAL)
self.otext.delete('1.0',END)
self.otext.insert("1.0",out)
self.otext.config(state=tk.DISABLED)
if __name__=="__main__":
window=Window()
window.mainloop()