-
Notifications
You must be signed in to change notification settings - Fork 3
/
UI.py
197 lines (143 loc) · 5.16 KB
/
UI.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
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 25 14:06:06 2019
@author: Hengky Sanjaya
"""
from tkinter import filedialog
from tkinter import *
from tkinter import scrolledtext
from tkinter import messagebox
# import PIL as pl
# from PIL import Image, ImageTk
import PIL.Image
import PIL.ImageTk
import os
import tkinter.font as tkFont
from main_flowchart import draw_flowchart
#
# #open file https://pythonspot.com/tk-file-dialogs/
# root = Tk()
# root.filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
# print (root.filename)
# text editor
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
#Creation of init_window
def init_window(self):
# changing the title of our master widget
self.master.title("Code to Flowchart")
# allowing the widget to take the full space of the root window
self.pack(fill=BOTH, expand=1)
root=Tk()
root.title("Code to Flowchart")
scrollbar = Scrollbar(root)
#size of the window
root.geometry("730x630")
def open_file():
filename = filedialog.askopenfilename(title="Select file",
filetypes=(("C++ File", "*.cpp"), ("All Files", "*.*")))
print(filename)
txt.delete(1.0 , END)
data = open(filename, mode='r').readlines()
for i in data:
print(i)
if i[0] == '/' and i[1] == '/':
txt.insert(INSERT, i, 'comment')
else:
txt.insert(INSERT, i)
# txt.insert(INSERT, data)
messagebox.showinfo("Information", "File imported successfully")
def convert():
code = txt.get("1.0","end-1c")
text_var.set('')
error_message = draw_flowchart(code)
print("error (ui.py)", error_message)
if(error_message != None):
text_var.set(str(error_message))
# w = Label(root, text=str(error_message), fg='red')
# w.pack()
# x = 'flowchart.gv.png'
#
# img = PIL.Image.open(x)
# # img = img.resize((400, 400), PIL.Image.ANTIALIAS)
# img = PIL.ImageTk.PhotoImage(img)
# # panel = Label(root, image=img)
# # panel.image = img
# # panel.place(x=500, y = 10)
#
# canv = Canvas(root, relief=SUNKEN)
# canv.config(width=400, height=200)
# canv.config(highlightthickness=0)
# sbarV = Scrollbar(root, orient=VERTICAL)
# sbarH = Scrollbar(root, orient=HORIZONTAL)
# sbarV.config(command=canv.yview)
# sbarH.config(command=canv.xview)
# canv.config(yscrollcommand=sbarV.set)
# canv.config(xscrollcommand=sbarH.set)
# sbarV.pack(side=RIGHT, fill=Y)
# sbarH.pack(side=BOTTOM, fill=X)
# canv.pack(side=LEFT, expand=YES, fill=BOTH)
#
# width, height = 50,50
# canv.config(scrollregion=(0, 0, width, height))
# canv.create_image(0, 0, anchor="nw", image=img)
# panel.pack()
# img = ImageTk.PhotoImage(Image.open("flowchart.gv.png"))
# panel = Label(root, image=img)
# panel.pack(side="bottom", fill="both", expand="yes")
bigFont = tkFont.Font(family='Monaco', size=11, weight='bold')
txt = scrolledtext.ScrolledText(root, height=23, width=77,font = bigFont, bg='#222222', fg='#EEEEEE')
txt.grid(column=0, row=0)
txt.place(x=10, y= 190)
txt.config(insertbackground='#EEEEEE')
# txt.insert(END, "Ehila", 'name') # <-- tagging `name`
# txt.insert(END, "Now", 'time') # <-- tagging `time`
# txt.tag_config('loop', foreground='green') # <-- Change colors of texts tagged `name`
# txt.tag_config('curly', foreground='red')
# txt.tag_config('variable', foreground='blue')
txt.tag_config('comment', foreground='green')
# textBox = Text(self, height=50, width=50)
# # textBox.pack()
# textBox.place(x=0, y=150)
# creating a menu instance
menu = Menu(root)
root.config(menu=menu)
file = Menu(menu)
# adds a command to the menu option, calling it exit, and the
# command it runs on event is client_exit
file.add_command(label="Import C++ File", command=lambda: open_file())
# added "file" to our menu
menu.add_cascade(label="File", menu=file)
# creating a button instance
convertBtn = Button(root, text="Convert", command=lambda: convert(),bg='#00579a',fg='#ecf0f1', height=1, width=98)
# placing the button on my window
convertBtn.place(x=10, y=590)
img = PIL.Image.open('logo/logo_1.png')
img = img.resize((350, 150), PIL.Image.ANTIALIAS)
img = PIL.ImageTk.PhotoImage(img)
panel = Label(root, image=img)
panel.image = img
panel.place(x=10, y = 10)
img2 = PIL.Image.open('logo/logo_2.png')
img2 = img2.resize((350, 150), PIL.Image.ANTIALIAS)
img2 = PIL.ImageTk.PhotoImage(img2)
panel2 = Label(root, image=img2)
panel2.image = img2
panel2.place(x=350, y = 10)
text_var = StringVar(root)
lbl = Label(root, textvariable=text_var, fg='red')
lbl.place(x=10, y=167)
# lbl.pack()
# def retrieve_input():
# inputValue=textBox.get("1.0","end-1c")
# print(inputValue)
# textBox=Text(root, height=30, width=150)
# textBox.pack()
# buttonCommit=Button(root, height=1, width=10, text="Commit",
# command=lambda: retrieve_input())
# command=lambda: retrieve_input() >>> just means do this when i press the button
# buttonCommit.pack()
root.mainloop()