forked from luka177/Garden_admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
270 lines (270 loc) · 7.88 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import tkinter as tk
from tkinter import *
import numpy as np
from numpy import zeros
import os
import re
from tkinter import filedialog
import shutil
import zipfile
inmaindir=True
xcell=25
donerec=0
ycell=25
x = 0
created=0
y = 0
def callbackc(event):
xx = canvas.canvasx(event.x)
yy = canvas.canvasy(event.y)
yr = int(yy/ycell)
xr = int(xx/xcell)
if(yr<y and xr<x):
diag = tk.Toplevel(main)
Label(diag, text="Name").grid(row=0)
Label(diag, text="index_of_image").grid(row=1)
name1 = Entry(diag)
name1.grid(row =0, column = 1)
L = tk.Listbox(diag)
gifsdict = {}
i =0
while(i<imnum-1):
L.insert(tk.END, images[i])
i+=1
L.grid(row =1, column = 1)
name1.insert(0,str(mass1[xr][yr]))
img = tk.Label(diag)
img.grid(row=2, column=2)
def list_entry_clicked(*ignore):
global imgname
imgname = L.get(L.curselection()[0])
imgname = re.findall(r'\d+', imgname)
imgname=int(imgname[0])
img.config(image=images[imgname])
def okd():
global imgname
mass1[xr][yr]=name1.get()
mmas[xr][yr]=imgname
canvas.itemconfig(mass2[xr][yr], image = images[imgname])
diag.destroy()
ok = Button(diag, text="OK", command=okd).grid(row= 2, column = 1)
L.bind('<ButtonRelease-1>', list_entry_clicked)
def callbackm(event):
xx = canvas.canvasx(event.x)
yy = canvas.canvasy(event.y)
yr = int(yy/ycell)
xr = int(xx/xcell)
global lastx
global lasty
global created
global rec
if(yr<y and xr<x):
res = int(y/ycell)-int(1200-(x/xcell))
# draw_grid()
v.set(mass1[xr][yr])
if(created==0):
rec=canvas.create_rectangle(xr*xcell, yr*ycell, xr*xcell+xcell, yr*ycell+ycell, outline='red', width=3)
lastx=xr
lasty=yr
created=1
else:
canvas.delete(rec)
rec=canvas.create_rectangle(xr*xcell, yr*ycell, xr*xcell+xcell, yr*ycell+ycell, outline='red', width=3)
def new():
global inmaindir
if (inmaindir!=True):
os.chdir("..")
inmaindir=True
if(os.path.isdir("work")):
shutil.rmtree('work')
os.mkdir("work")
os.chdir("work")
inmaindir=False
diag = tk.Toplevel(main)
Label(diag, text="Rows").grid(row=0)
Label(diag, text="Columes").grid(row=1)
e1 = Entry(diag)
e2 = Entry(diag)
def okd():
global x
global y
x =int(e1.get())
y = int(e2.get())
if(x>5000):
e1.delete(0,END)
e1.insert(0,"5000")
if(y>5000):
e2.delete(0,END)
e2.insert(0,"5000")
return
if(y>5000):
e2.delete(0,END)
e2.insert(0,"5000")
return
global mmas
global mass1
global mass2
mmas = zeros((int(e1.get()),int(e2.get())),dtype ='int')
mass1 = zeros((int(e1.get()),int(e2.get())),dtype ='object')
mass2 = zeros((int(e1.get()),int(e2.get())),dtype ='object')
xfile= open("x","w+")
yfile=open("y","w+")
xfile.write(e1.get())
yfile.write(e2.get())
xfile.close()
yfile.close()
diag.destroy()
draw_grid()
ok = Button(diag, text="OK", command=okd).grid(row= 3, column = 3)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
def file_save():
canvas.postscript(file='/home/luka/father/test.ps', colormode='color')
main =Tk()
canvas = tk.Canvas(main, width=1000, height=700)
canvas.grid(row=0, column=0)
v = StringVar()
v.set("hi")
Label(main, textvariable=v).grid(row=2, column=0)
v.set("hi")
canvas.bind("<Motion>", callbackm)
canvas.bind('<Button>', callbackc)
scroll_x = tk.Scrollbar(main, orient="horizontal", command=canvas.xview)
scroll_x.grid(row=1, column=0, sticky="ew")
scroll_y = tk.Scrollbar(main, orient="vertical", command=canvas.yview)
scroll_y.grid(row=0, column=1, sticky="ns")
canvas.configure(yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set)
main.attributes("-fullscreen", True)
menubar = Menu(main)
main.config(menu=menubar)
def draw_grid():
canvas.delete("all")
global images
global x
global y
global scroll_x
global scroll_y
i=0
canvas.create_line(0, 0, x*xcell, 0)
while(i<x):
i+=1
canvas.create_line(i*xcell, 0, i*xcell, y*ycell)
i=0
canvas.create_line(0, 0, 0, y*ycell)
while(i<y):
i+=1
canvas.create_line(0, i*ycell, x*xcell, i*ycell)
i=0
xy=0
xx=0
yy=0
ylin=0
canvas.configure(scrollregion=canvas.bbox("all"))
while (i<x*y):
mass2[xy][ylin]=canvas.create_image(xx+1, yy+1, image=images[mmas[xy][ylin]], anchor=NW)
i+=1
xx+=xcell
xy+=1
if(xy==x):
xy=0
ylin+=1
xx=0
yy+=ycell
def localsave():
mmasfi=open("mmas",'wb')
np.save(mmasfi, mmas)
mmasfi.close()
mass1fi=open("mass1",'wb')
np.save(mass1fi, mass1)
mass1fi.close()
wi=open("w",'w+')
wi.write(str(xcell))
he=open("h",'w+')
he.write(str(ycell))
savename=filedialog.asksaveasfilename(defaultextension=".sad", filetypes=(("sad file", "*.sad"),("All Files", "*.*") ))
print(savename)
os.chdir("..")
shutil.make_archive(savename, 'zip', "work")
savename = savename[:-4]
print(savename)
shutil.move((savename+".sad.zip"), (savename+".sad"))
os.chdir("work")
def load():
global inmaindir
global x
global y
global mmas
global mass1
global mass2
if(inmaindir!=True):
os.chdir("..")
inmaindir=True
shutil.rmtree("work")
os.mkdir("work")
file_path = filedialog.askopenfilename()
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall("work")
os.chdir("work")
inmaindir=False
mmasfi=open("mmas",'rb')
mmas=np.load(mmasfi)
mmasfi.close()
mass1fi=open("mmas",'rb')
mass1=np.load(mass1fi)
mass1fi.close()
xfile= open("x","r")
yfile=open("y","r")
# w= open("w","r")
# h=open("h","r")
x=int(xfile.read())
y=int(yfile.read())
# xcell=int(w.read())
# ycell=int(h.read())
xfile.close()
yfile.close()
print(x,y)
mass2 = zeros((x,y), dtype='object')
draw_grid()
def csize():
diag = tk.Toplevel(main)
Label(diag, text="width").grid(row=0)
Label(diag, text="heidth").grid(row=1)
e1 = Entry(diag)
e2 = Entry(diag)
def okd():
global xcell
global ycell
xcell =int(e1.get())
ycell = int(e2.get())
if(x>500):
e1.delete(0,END)
e1.insert(0,"500")
if(y>500):
e2.delete(0,END)
e2.insert(0,"500")
return
if(y>500):
e2.delete(0,END)
e2.insert(0,"500")
return
diag.destroy()
draw_grid()
ok = Button(diag, text="OK", command=okd).grid(row= 3, column = 3)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
imnum=4
images=[0]*imnum
i=0
while(i<imnum):
images[i]=PhotoImage(file= str(i)+'.png')
i+=1
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Set cell size", command=csize)
filemenu.add_command(label="New", command=new)
filemenu.add_command(label="Export as image", command=file_save)
#filemenu.add_command(label="Save", command=donothing)
filemenu.add_command(label="Save as...", command=localsave)
filemenu.add_command(label="load", command=load)
menubar.add_cascade(label="File", menu=filemenu)
menubar.add_command(label="Quit", command=main.quit)
main.mainloop()