-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui
executable file
·189 lines (169 loc) · 6.63 KB
/
gui
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
import subprocess
import os, sys
SCRIPT_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
class MainWindow(wx.Frame):
"""Fenêtre personnalisée"""
algofile = None
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(400,160))
self.CreateStatusBar() # Créer une barre d'état
# Menu "Fichier"
fichier = wx.Menu()
item = fichier.Append(wx.ID_ANY, "&Tester…", "Lance un test sur un fichier")
self.Bind(wx.EVT_MENU, self.onTest, item)
item = fichier.Append(wx.ID_OPEN, "&Ouvrir…", "Sélectionne un fichier à analyser")
self.Bind(wx.EVT_MENU, self.onOpen, item)
fichier.AppendSeparator()
item = fichier.Append(wx.ID_ANY, "&Analyser", "Lance l'analyse sur le fichier sélectionné")
self.Bind(wx.EVT_MENU, self.onAnalyse, item)
item = fichier.Append(wx.ID_ANY, "&Compiler", "Lance la compilation du fichier sélectionné")
self.Bind(wx.EVT_MENU, self.onCompile, item)
item = fichier.Append(wx.ID_ANY, "&Exécuter", "Exécute le fichier sélectionné")
self.Bind(wx.EVT_MENU, self.onExec, item)
fichier.AppendSeparator()
item = fichier.Append(wx.ID_EXIT, "&Quitter", "Termine l'application")
self.Bind(wx.EVT_MENU, self.onExit, item)
# Menu "Aide"
aide = wx.Menu()
item = aide.Append(wx.ID_HELP, "&Documentation", "Ouvre la documentation")
self.Bind(wx.EVT_MENU, self.onDoc, item)
aide.AppendSeparator()
item = aide.Append(wx.ID_ABOUT, "À &propos…", "À propos de analyser")
self.Bind(wx.EVT_MENU, self.onAbout, item)
menubar = wx.MenuBar()
menubar.Append(fichier, "&Fichier")
menubar.Append(aide, "&Aide")
self.SetMenuBar(menubar)
# Barre d'outils
toolbar = wx.ToolBar(self)
bmp = wx.Bitmap("share/sprocket_dark.png", wx.BITMAP_TYPE_PNG)
item = toolbar.AddSimpleTool(wx.ID_ANY, bmp, "Tester…", "Lance un test sur un fichier")
self.Bind(wx.EVT_TOOL, self.onTest, item)
toolbar.AddSeparator()
bmp = wx.Bitmap("share/help.png", wx.BITMAP_TYPE_PNG)
item = toolbar.AddSimpleTool(wx.ID_HELP, bmp, "Documentation", "Ouvre l'aide en ligne")
self.Bind(wx.EVT_TOOL, self.onDoc, item)
bmp = wx.Bitmap("share/remove.png", wx.BITMAP_TYPE_PNG)
item = toolbar.AddSimpleTool(wx.ID_EXIT, bmp, "Quitter", "Termine l'application")
self.Bind(wx.EVT_TOOL, self.onExit, item)
self.SetToolBar(toolbar)
# Messages affichés (Fichier sélectionné, analyse, compilation, exécution)
box = wx.BoxSizer(wx.VERTICAL)
panel = wx.Panel(self)
self.label = wx.StaticText(panel, label="Aucun fichier ouvert.", pos=(10,10))
box.Add(panel, 0, wx.EXPAND)
panel = wx.Panel(self)
self.labelAnalyse = wx.StaticText(panel, pos=(10,0))
box.Add(panel, 0, wx.EXPAND)
panel = wx.Panel(self)
self.labelCompil = wx.StaticText(panel, pos=(10,0))
box.Add(panel, 0, wx.EXPAND)
panel = wx.Panel(self)
self.labelExec = wx.StaticText(panel, pos=(10,0))
box.Add(panel, 0, wx.EXPAND)
self.SetSizer(box)
self.Show(True)
def clearLabels(self):
self.labelAnalyse.SetLabel("")
self.labelCompil.SetLabel("")
self.labelExec.SetLabel("")
def onAbout(self,e):
dlg = wx.MessageDialog(self, "Analyseur syntaxique d'algorithmes.", "À propos…", wx.OK)
dlg.ShowModal()
dlg.Destroy()
def onAnalyse(self, e):
if self.algofile is not None:
p = subprocess.Popen([SCRIPT_PATH + os.sep + "bin" + os.sep + "analyser", self.algofile], 4096, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(ret,err) = p.communicate()
if ret != "":
dlg = wx.MessageDialog(self, ret, "Erreur d'analyse", wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
self.clearLabels()
self.labelAnalyse.SetLabel("Analyse : Échouée")
return False
elif err != "":
dlg = wx.MessageDialog(self,
"Une erreur s'est produite pendant l'exécution de l'analyseur.\n"+err,
"Analyse échouée", wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
self.clearLabels()
self.labelAnalyse.SetLabel("Analyse : Échouée")
elif p.returncode != 0:
dlg = wx.MessageDialog(self,
"Une erreur s'est produite pendant l'exécution de l'analyseur qui a retourné le code "+str(p.returncode)+".",
"Analyse échouée", wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
self.clearLabels()
self.labelAnalyse.SetLabel("Analyse : Échouée")
else:
#dlg = wx.MessageDialog(self, "L'analyseur avoir fonctionné correctement.", "Analyse réussie", wx.OK)
#dlg.ShowModal()
#dlg.Destroy()
self.clearLabels()
self.labelAnalyse.SetLabel("Analyse : Réussie")
return True
else:
dlg = wx.MessageDialog(self, "Aucun fichier sélectionné.", "Analyse impossible", wx.ICON_EXCLAMATION)
dlg.ShowModal()
dlg.Destroy()
return False
def onCompile(self, e):
if self.algofile is not None:
p = subprocess.Popen(["g++", "-w", self.algofile+".cpp", "-I"+SCRIPT_PATH+"/includes",
"-L"+SCRIPT_PATH+"/lib", "-lamalgo", "-o"+self.algofile+".exe"],
4096, stderr=subprocess.PIPE)
err = p.communicate()[1]
if err == "":
#dlg = wx.MessageDialog(self, "GCC s'est exécuté correctement.", "Compilation réussie", wx.OK)
#dlg.ShowModal()
#dlg.Destroy()
self.labelCompil.SetLabel("Compilation : Réussie")
return True
else:
dlg = wx.MessageDialog(self, "GCC a renvoyé une erreur :\n"+err, "Problème de compilation", wx.ICON_EXCLAMATION)
dlg.ShowModal()
dlg.Destroy()
self.labelCompil.SetLabel("Compilation : Échouée")
return False
else:
dlg = wx.MessageDialog(self, "Aucun fichier sélectionné.", "Compilation impossible", wx.ICON_EXCLAMATION)
dlg.ShowModal()
dlg.Destroy()
return False
def onDoc(self, e):
pass
def onExec(self, e):
if self.algofile is not None:
self.labelExec.SetLabel("Exécution…")
p = subprocess.Popen(["gnome-terminal","-t", self.algofile, "-e", self.algofile+".exe"])
else:
dlg = wx.MessageDialog(self, "Aucun fichier sélectionné.", "Exécution impossible", wx.ICON_EXCLAMATION)
dlg.ShowModal()
dlg.Destroy()
def onOpen(self, e):
dlg = wx.FileDialog(self, "Choisissez un algorithme…",
wildcard="Algorithme (*.algo)|*.algo|Fichier texte (*.txt)|*.txt|Tout type|*.*",
style=wx.FD_OPEN)
dlg.ShowModal()
dlg.Destroy()
if dlg.GetPath() != "":
self.algofile = dlg.GetPath()
self.label.SetLabel(self.algofile)
self.clearLabels()
return dlg.GetPath() != ""
def onTest(self, e):
if self.algofile is not None or self.onOpen(e):
if self.onAnalyse(e):
if self.onCompile(e):
self.onExec(e)
def onExit(self,e):
self.Close(True)
app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
frame = MainWindow(None, "Analyseur d'algorithmes") # A Frame is a top-level window.
app.MainLoop()