-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddplaneform.py
More file actions
268 lines (182 loc) · 9.23 KB
/
Addplaneform.py
File metadata and controls
268 lines (182 loc) · 9.23 KB
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
# -*- coding: utf-8 -*-
"""
Created on Thu May 20 16:50:44 2021
@author: Asus-Pc
"""
from tkinter import *
from Classes.airplane import Airplane
from Classes.model import Model
from tkinter import ttk,filedialog
import tkinter.messagebox as MessageBox
from tkcalendar import DateEntry
class FormNewAirplane:
def __init__(self,filePath = './'):
Airplane.read('Data/')
Model.read('Data/')
self.root = Tk()
self.root.configure(bg='#464646')
self.filePath = filePath
self.classObj = Airplane
self.classObj.read(self.filePath)
self.list=Model.lst
self.classmodel = Model
self.classmodel.read(self.filePath)
# self.classmodel.remove('')
# Set attribute names and labels
obj = self.classmodel.first()
print(self.classmodel.obj)
#self.att = list(obj.__dict__.keys())
# Set attribute names and labels
obja = self.classObj.first()
# self.att = list(obj.__dict__.keys())
# Set root title
self.root.title('Airplane')
self.root.iconbitmap("Images/plane_takeoff_13263.ico")
#root geometry
self.app_width=1300
self.app_height=730
#Find width and height screen's
self.screen_width=self.root.winfo_screenwidth()
self.screen_height=self.root.winfo_screenheight()
self.x=int((self.screen_width/2)-(self.app_width/2))
self.y=int((self.screen_height/2)-(self.app_height/2))
self.root.geometry(f'{self.app_width}x{self.app_height}+{self.x}+{self.y}')
#options combobox
# self.classObj.remove(".!entry7")
self.options=self.list.copy()
print(self.options)
self.options.append("New")
#buttons
self.center=self.app_width/2
self.button_submit = Button(self.root,text="SUBMIT", command=self.msg ,bg='white',padx=20,pady=8,fg="black",font=("AIGDT",12)).place(x=500,y=650)
self.button_cancel = Button(self.root,text="CANCEL", command= lambda: self.button_cancel_click(),bg='white',padx=20,pady=8,fg="black",font=("AIGDT",12)).place(x=730,y=650)
#title
self.title=Label(self.root, text="N E W A I R P L A N E", fg="white",bg="#464646", font=("AMGDT",30))
self.title.place(x=300,y=30)
#labels and entries
self.modellb=Label(self.root, text="M O D E L", fg="white",bg="#464646", font=("AMGDT",10))
self.modellb.place(x=50,y=170)
#combobox
self.combobox=ttk.Combobox(self.root,values=self.options)
self.combobox.place(x=90,y=220)
self.model=self.combobox.get()
print(self.model, 'jhjh')
self.combobox.bind("<<ComboboxSelected>>", self.fillcamps)
#Date of Fabrication
self.dof=Label(self.root, text="D A T E O F F A B R I C A T I O N", fg="white",bg="#464646", font=("AMGDT",10))
self.dof.place(x=50,y=280)
self.dof=DateEntry(self.root,width=40,bg=" ", fg="", date_pattern='dd/mm/YY')
self.dof.place(x=90,y=320)
# #Client code
# self.clientlb=Label(self.root, text="C L I E N T C O D E", fg="white",bg="#464646", font=("AMGDT",10))
# self.clientlb.place(x=50,y=280)
# self.clientIB=Entry(self.root, width=40)
# self.clientIB.place(x=90,y=320)
#Capacity
self.caplb=Label(self.root, text="C A P A C I T Y ", fg="white",bg="#464646", font=("AMGDT",10))
self.caplb.place(x=50,y=380)
self.capIB=Entry(self.root, width=40)
self.capIB.place(x=90,y=420)
#Autonomy
self.autlb=Label(self.root, text="A U T O N O M Y ", fg="white",bg="#464646", font=("AMGDT",10))
self.autlb.place(x=480,y=170)
self.autIB=Entry(self.root, width=40)
self.autIB.place(x=520,y=220)
#cargo
self.cargolb=Label(self.root, text="C A R G O", fg="white",bg="#464646", font=("AMGDT",10))
self.cargolb.place(x=480,y=280)
self.cargoIB=Entry(self.root, width=40)
self.cargoIB.place(x=520,y=320)
#Price
self.pricelb=Label(self.root, text="P R I C E", fg="white",bg="#464646", font=("AMGDT",10))
self.pricelb.place(x=480,y=380)
self.priceIB=Entry(self.root, width=40)
self.priceIB.place(x=520,y=420)
#Image path
self.imagelb=Label(self.root, text="I M A G E", fg="white",bg="#464646", font=("AMGDT",10))
self.imagelb.place(x=880,y=170)
self.imageIB=Entry(self.root, width=40)
self.imageIB.place(x=920,y=220)
self.openBt=Button(self.root,text="S E L E C T ", command=self.add_path,bg='#b6b6b6',padx=15,pady=7,fg="black")
self.openBt.place(x=1100,y=170)
#staff
self.stafflb=Label(self.root, text="STAFF", fg="white",bg="#464646", font=("AMGDT",10))
self.stafflb.place(x=880,y=280)
self.staffIB=Entry(self.root, width=40)
self.staffIB.place(x=920,y=320)
self.registration_Status = "Not Registed"
# Let the root wait for any events
self.root.mainloop()
def fillcamps(self,event):
print(self.combobox.get(), "jskd",self.list)
if self.combobox.get()in self.list:
self.model=self.combobox.get()
self.capIB.delete(0,END)
self.capIB.insert(0, self.classmodel.obj[self.model].capacity)
self.autIB.delete(0,END)
self.autIB.insert(0, self.classmodel.obj[self.model].autonomy)
self.cargoIB.delete(0,END)
self.cargoIB.insert(0,self.classmodel.obj[self.model].cargo)
self.priceIB.delete(0,END)
self.priceIB.insert(0,self.classmodel.obj[self.model].price)
self.imageIB.delete(0,END)
self.imageIB.insert(0,self.classmodel.obj[self.model].image_path)
self.staffIB.delete(0,END)
self.staffIB.insert(0, self.classmodel.obj[self.model].staff)
else:
self.modelIB=Entry(self.root, width=40)
self.modelIB.place(x=90,y=240)
def button_cancel_click(self):
self.login_Status = "cancel"
self.root.destroy()
def open_image(self):
self.pathimage= filedialog.asksaveasfilename()
return self.pathimage
def add_path(self):
self.imageIB.delete(0,END)
self.pathimage=self.open_image()
self.imageIB.insert(0,self.pathimage)
def msg(self):
self.all=True
try:
self.set_background(self.modelIB)
self.set_background(self.capIB)
self.set_background(self.cargoIB)
self.set_background(self.priceIB)
self.set_background(self.imageIB)
self.set_background(self.staffIB)
except:
self.set_background(self.capIB)
self.set_background(self.cargoIB)
self.set_background(self.priceIB)
self.set_background(self.imageIB)
self.set_background(self.staffIB)
if self.all==True:
self.save()
def save(self):
self.db=self.dof.get_date()
self.d=self.db.strftime('%Y-%m-%d')
if Airplane.lst==[]:
self.code=0
else:
self.code=int(Airplane.lst[-1])+1
#creat object and add to csv
# Airplane.read('Data/')
if self.combobox.get()in self.list:
self.new_airplane= Airplane(self.combobox.get(),self.capIB.get(),self.autIB.get(),self.staffIB.get(), self.cargoIB.get(), self.priceIB.get(),self.imageIB.get(), self.code,self.d)
self.new_airplane.write(self.filePath)
else:
self.new_airplane= Airplane(self.modelIB.get(),self.capIB.get(),self.autIB.get(),self.staffIB.get(), self.cargoIB.get(), self.priceIB.get(),self.imageIB.get(), self.code,self.d)
self.new_airplane.write(self.filePath)
self.new_model= Model(self.modelIB.get(),self.capIB.get(),self.autIB.get(),self.staffIB.get(), self.cargoIB.get(), self.priceIB.get(),self.imageIB.get())
self.new_model.write(self.filePath)
MessageBox.showinfo("regist successfully")
self.root.destroy()
def set_background(self,button_name):
data = button_name.get()
if len(data) == 0:
button_name.config({"highlightbackground": "red"},highlightthickness=2)
self.all=False
else:
button_name.configure(highlightthickness=0)
#FormNewAirplane('Data/')