-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_final.py
More file actions
362 lines (322 loc) · 14.6 KB
/
app_final.py
File metadata and controls
362 lines (322 loc) · 14.6 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# /usr/bin/env python
#
# GUI module generated by PAGE version 4.9
# In conjunction with Tcl version 8.6
from test_final import Test
from Tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
test=Test()
top=0
#demarage et parametrage de l'interface graphique
def vp_start_gui():
#creation de l'interface graphique
global val, w, root
root = Tk()
#root.iconbitmap('appicon.ico')
root.resizable(False, False)
top = Application_filtre_anti_spam (root)
root.mainloop()
w = None
def create_Application_filtre_anti_spam(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
top = Application_filtre_anti_spam (w)
return (w, top)
def destroy_Application_filtre_anti_spam():
global w
w.destroy()
w = None
class Application_filtre_anti_spam:
check=0
c = 0
#initialisation de l'interface graphique
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#d9d9d9' # X11 color: 'gray85'
font11 = "-family {Century Gothic} -size 9 -weight normal " \
"-slant roman -underline 0 -overstrike 0"
font12 = "-family {Century Gothic} -size 9 -weight bold -slant" \
" roman -underline 0 -overstrike 0"
font13 = "-family {Century Gothic} -size 10 -weight bold " \
"-slant italic -underline 0 -overstrike 0"
font14 = "-family {Century Gothic} -size 13 -weight bold " \
"-slant roman -underline 0 -overstrike 0"
font9 = "-family {Segoe UI} -size 9 -weight normal -slant " \
"roman -underline 0 -overstrike 0"
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
top.geometry("700x550")
top.title("Filtre Anti Spam")
top.configure(background="#2c3e50")
top.configure(highlightbackground="#d9d9d9")
top.configure(highlightcolor="black")
self.Labelframe1 = LabelFrame(top)
self.Labelframe1.place(relx=0.03, rely=0.09, relheight=0.14
, relwidth=0.94)
self.Labelframe1.configure(relief=GROOVE)
self.Labelframe1.configure(font=font13)
self.Labelframe1.configure(foreground="#ffffff")
self.Labelframe1.configure(text='''Sujet de l'email''')
self.Labelframe1.configure(background="#2c3e50")
self.Labelframe1.configure(highlightbackground="#d9d9d9")
self.Labelframe1.configure(highlightcolor="black")
self.Labelframe1.configure(width=640)
self.Entry1 = Entry(self.Labelframe1)
self.Entry1.place(relx=0.03, rely=0.31, relheight=0.46, relwidth=0.94)
self.Entry1.configure(background="white")
self.Entry1.configure(disabledforeground="#a3a3a3")
self.Entry1.configure(font="TkTextFont")
self.Entry1.configure(foreground="#000000")
self.Entry1.configure(highlightbackground="#d9d9d9")
self.Entry1.configure(highlightcolor="black")
self.Entry1.configure(insertbackground="black")
self.Entry1.configure(selectbackground="#c4c4c4")
self.Entry1.configure(selectforeground="black")
self.Labelframe3 = LabelFrame(top)
self.Labelframe3.place(relx=0.03, rely=0.24, relheight=0.33
, relwidth=0.94)
self.Labelframe3.configure(relief=GROOVE)
self.Labelframe3.configure(font=font13)
self.Labelframe3.configure(foreground="#ffffff")
self.Labelframe3.configure(text='''Corps de l'email''')
self.Labelframe3.configure(background="#2c3e50")
self.Labelframe3.configure(highlightbackground="#d9d9d9")
self.Labelframe3.configure(highlightcolor="black")
self.Labelframe3.configure(width=640)
self.Scrolledtext1 = ScrolledText(self.Labelframe3)
self.Scrolledtext1.place(relx=0.03, rely=0.13, relheight=0.78
, relwidth=0.94)
self.Scrolledtext1.configure(background="white")
self.Scrolledtext1.configure(font="TkTextFont")
self.Scrolledtext1.configure(foreground="black")
self.Scrolledtext1.configure(highlightbackground="#d9d9d9")
self.Scrolledtext1.configure(highlightcolor="black")
self.Scrolledtext1.configure(insertbackground="black")
self.Scrolledtext1.configure(insertborderwidth="3")
self.Scrolledtext1.configure(selectbackground="#c4c4c4")
self.Scrolledtext1.configure(selectforeground="black")
self.Scrolledtext1.configure(takefocus="0")
self.Scrolledtext1.configure(width=10)
self.Scrolledtext1.configure(wrap=NONE)
self.Label1 = Label(top)
self.Label1.place(relx=0.03, rely=0.73, height=73, width=323)
self.Label1.configure(activebackground="#f9f9f9")
self.Label1.configure(activeforeground="black")
self.Label1.configure(background="#2c3e50")
self.Label1.configure(disabledforeground="#a3a3a3")
self.Label1.configure(font=font11)
self.Label1.configure(anchor=W)
self.Label1.configure(foreground="#ffffff")
self.Label1.configure(highlightbackground="#d9d9d9")
self.Label1.configure(highlightcolor="black")
self.Label1.configure(width=323)
self.Label2 = Label(top)
self.Label2.place(relx=0.55, rely=0.95, height=23, width=309)
self.Label2.configure(activebackground="#f9f9f9")
self.Label2.configure(activeforeground="black")
self.Label2.configure(anchor=E)
self.Label2.configure(background="#34495e")
self.Label2.configure(disabledforeground="#a3a3a3")
self.Label2.configure(font=font11)
self.Label2.configure(text='Veuillez remplir tous les champs')
self.Label2.configure(foreground="#ffffff")
self.Label2.configure(highlightbackground="#d9d9d9")
self.Label2.configure(highlightcolor="black")
self.Label3 = Label(top)
self.Label3.place(relx=0.0, rely=0.02, height=27, width=700)
self.Label3.configure(activebackground="#f9f9f9")
self.Label3.configure(activeforeground="black")
self.Label3.configure(background="#34495e")
self.Label3.configure(disabledforeground="#a3a3a3")
self.Label3.configure(font=font14)
self.Label3.configure(foreground="#ffffff")
self.Label3.configure(highlightbackground="#d9d9d9")
self.Label3.configure(highlightcolor="black")
self.Label3.configure(text='''Filtre anti-spam''')
self.Button2 = Button(top)
self.Button2.place(relx=0.60, rely=0.63, height=30, width=250)
self.Button2.configure(activebackground="#27ae60")
self.Button2.configure(activeforeground="#ffffff")
self.Button2.configure(background="#27ae60")
self.Button2.configure(command=self.verifierEmail)
self.Button2.configure(disabledforeground="#27ae60")
self.Button2.configure(font=font12)
self.Button2.configure(foreground="#ffffff")
self.Button2.configure(highlightbackground="#27ae60")
self.Button2.configure(highlightcolor="black")
self.Button2.configure(pady="0")
self.Button2.configure(takefocus="0")
self.Button2.configure(text='''Vérifier''')
self.Button3 = Button(top)
self.Button3.place(relx=0.60, rely=0.7, height=30, width=250)
self.Button3.configure(activebackground="#d35400")
self.Button3.configure(activeforeground="#ffffff")
self.Button3.configure(background="#d35400")
self.Button3.configure(command=self.statistiques)
self.Button3.configure(disabledforeground="#d35400")
self.Button3.configure(font=font12)
self.Button3.configure(foreground="#ffffff")
self.Button3.configure(highlightbackground="#27ae60")
self.Button3.configure(highlightcolor="black")
self.Button3.configure(pady="0")
self.Button3.configure(takefocus="0")
self.Button3.configure(text='''Evaluation du modèle''')
self.Button1 = Button(top)
self.Button1.place(relx=0.01, rely=0.96, height=24, width=150)
self.Button1.configure(activebackground="#d9d9d9")
self.Button1.configure(background="#2c3e50")
self.Button1.configure(disabledforeground="#2c3e50")
self.Button1.configure(foreground="#2980b9")
self.Button1.configure(command=self.aide)
self.Button1.configure(highlightbackground="#d9d9d9")
self.Button1.configure(highlightcolor="black")
self.Button1.configure(relief=FLAT)
self.Button1.configure(text='''A propos de nous''')
self.Checkbutton1 = Checkbutton(top)
self.Checkbutton1.place(relx=0.03, rely=0.61, relheight=0.05
, relwidth=0.35)
self.Checkbutton1.configure(activebackground="#2c3e50")
self.Checkbutton1.configure(activeforeground="white")
self.Checkbutton1.configure(background="#2c3e50")
self.Checkbutton1.configure(disabledforeground="#2c3e50")
self.Checkbutton1.configure(font=font12)
self.Checkbutton1.configure(foreground="#ffffff")
self.Checkbutton1.configure(highlightbackground="#2c3e50")
self.Checkbutton1.configure(highlightcolor="#000000")
self.Checkbutton1.configure(justify=LEFT)
self.Checkbutton1.configure(selectcolor="#2c3e50",onvalue=1, offvalue=0)
self.Checkbutton1.configure(text='''Alimenter la base de connaissances''')
self.Checkbutton1.configure(variable=self.check)
self.Checkbutton1.configure(width=241)
self.Checkbutton1.configure(command=self.check_chbx)
self.menubar = Menu(top,font=font9,bg=_bgcolor,fg=_fgcolor)
top.configure(menu = self.menubar)
self.chargementBaseDeConnaissance()
pass
def check_chbx(self):
if self.c%2==0:
self.check=1
else:
self.check=0
self.c=self.c+1
pass
# Chargement des données
def chargementBaseDeConnaissance(self):
test.chargement()
self.Label1.configure(text='Basé sur une base de connaissances de :\n * ' + str(test.nb_hams) + ' hams\n * ' + str(test.nb_spams) + ' spams')
pass
# Fonction de traitement principal
def verifierEmail(self):
if self.Scrolledtext1.get(1.0,END)=="" or self.Entry1.get()=="":
self.Label2.config(text='Veuillez remplir tous les champs')
else:
type=str(test.verifier(self.Entry1.get() + '\n\n' + str(self.Scrolledtext1.get(1.0, END))))
self.Label2.config(text='Cet email est un '+type)
if self.check==1:
print(str(type) + "s/h" + str(test.nb_hams))
mssg=str(self.Entry1.get()) + '\n\n' + str(self.Scrolledtext1.get(1.0, END))
if type == "spam":
with open(str(type)+"s/s"+str(test.nb_spams), "a") as file:
file.write(mssg)
elif type == "ham":
with open(type+"s/h"+str(test.nb_hams), "a") as file:
file.write(mssg)
self.chargementBaseDeConnaissance()
pass
# Affichage du frame de statistiques
def statistiques(self):
test.statistiques()
pass
# Section d'aide
def aide(self):
# creation du menu d'aide pour l'application
top1 = Toplevel()
top1.title("A propos de nous !")
msg = Message(top1, text="-LARAQUI Omar\n-KARIM Kaoutar\n\nApplication réalisée dans le cadre du projet IA")
msg.pack()
button = Button(top1, text="Fermer", command=top1.destroy)
button.pack()
pass
# La partie scrollbar du corps du mail
class AutoScroll(object):
'''Configure the scrollbars for a widget.'''
def __init__(self, master):
# Rozen. Added the try-except clauses so that this class
# could be used for scrolled entry widget for which vertical
# scrolling is not supported. 5/7/14.
try:
vsb = ttk.Scrollbar(master, orient='vertical', command=self.yview)
except:
pass
hsb = ttk.Scrollbar(master, orient='horizontal', command=self.xview)
#self.configure(yscrollcommand=_autoscroll(vsb),
# xscrollcommand=_autoscroll(hsb))
try:
self.configure(yscrollcommand=self._autoscroll(vsb))
except:
pass
self.configure(xscrollcommand=self._autoscroll(hsb))
self.grid(column=0, row=0, sticky='nsew')
try:
vsb.grid(column=1, row=0, sticky='ns')
except:
pass
hsb.grid(column=0, row=1, sticky='ew')
master.grid_columnconfigure(0, weight=1)
master.grid_rowconfigure(0, weight=1)
# Copy geometry methods of master (taken from ScrolledText.py)
if py3:
methods = Pack.__dict__.keys() | Grid.__dict__.keys() \
| Place.__dict__.keys()
else:
methods = Pack.__dict__.keys() + Grid.__dict__.keys() \
+ Place.__dict__.keys()
for meth in methods:
if meth[0] != '_' and meth not in ('config', 'configure'):
setattr(self, meth, getattr(master, meth))
@staticmethod
def _autoscroll(sbar):
'''Hide and show scrollbar as needed.'''
def wrapped(first, last):
first, last = float(first), float(last)
if first <= 0 and last >= 1:
sbar.grid_remove()
else:
sbar.grid()
sbar.set(first, last)
return wrapped
def __str__(self):
return str(self.master)
def _create_container(func):
'''Creates a ttk Frame with a given master, and use this new frame to
place the scrollbars and the widget.'''
def wrapped(cls, master, **kw):
container = ttk.Frame(master)
return func(cls, container, **kw)
return wrapped
class ScrolledText(AutoScroll, Text):
'''A standard Tkinter Text widget with scrollbars that will
automatically show/hide as needed.'''
@_create_container
def __init__(self, master, **kw):
Text.__init__(self, master, **kw)
AutoScroll.__init__(self, master)
# Lancement de l'application
if __name__ == '__main__':
vp_start_gui()