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
| #-*- coding:utf-8 -*-
import wx
import os.path
import Graph
ID_EXPORT = 101
class Root(wx.Frame):
def __init__(self, titre):
wx.Frame.__init__(self, None, -1, title = titre)
##---------------
## Création des barres de menus et status
##---------------
menuFichier = wx.Menu()
menuFichier.Append(ID_EXPORT, "Export pdf", "Exporte le projet")
menuFichier.Append(wx.ID_EXIT, "Quitter", "Quitter l'application")
menuBarre = wx.MenuBar()
menuBarre.Append(menuFichier, "Fichier")
self.SetMenuBar(menuBarre)
##---------------
## Création des Widgets
##---------------
##___________________
## Création des Font et Sizer
font1 = wx.Font(8, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, 'Verdana')
font2 = wx.Font(8, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Verdana')
sizerMenu_0 = wx.GridBagSizer()
sizer_0 = wx.GridBagSizer()
sizer_4 = wx.FlexGridSizer(cols = 5, hgap = 5, vgap = 5)
##____________________
## Création des Titres
conteneurTitre1= wx.Panel(self, -1)
conteneurTitre1.SetSizer(sizer_0)
titre0 = wx.StaticText(conteneurTitre1, -1, u"EXEMPLE y = ax+b", style = wx.ALIGN_RIGHT)
titre0.SetFont(font1)
sizer_0.Add(titre0, (1,1))
##____________________
## Création du coprs du programme
conteneur0 = wx.Panel(self, -1)
conteneur0.SetSizer(sizer_4)
a = wx.StaticText(conteneur0, -1,
u"valeur de a:", style = wx.ALIGN_CENTRE)
a.SetFont(font2)
b = wx.StaticText(conteneur0, -1,
u"valeur de b:", style = wx.ALIGN_CENTRE)
b.SetFont(font2)
self.a = wx.TextCtrl(conteneur0, -1,'', size = (100,-1))
self.b = wx.TextCtrl(conteneur0, -1,'0', size = (100,-1))
sizer_4.Add(a, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTRE_VERTICAL)
sizer_4.Add(self.a, 0, wx.EXPAND)
sizer_4.Add((0,0), 0, wx.EXPAND)
sizer_4.Add(b, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTRE_VERTICAL)
sizer_4.Add(self.b, 0, wx.EXPAND)
##____________________
## Disposition sur la fenêtre
sizer_v = wx.BoxSizer(wx.VERTICAL)
sizer_h = wx.BoxSizer(wx.HORIZONTAL)
sizer_v.Add(conteneurTitre1, 0, wx.EXPAND)
sizer_v.Add(conteneur0, 0, wx.EXPAND)
self.SetSizer(sizer_v)
sizer_v.SetSizeHints(self)
self.SetSize((-1,-1))
##---------------
## Création des Méthodes
##---------------
wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
wx.EVT_MENU(self, ID_EXPORT, self.Export)
def OnExit(self, evt):
self.Destroy()
evt.Skip()
def Export(self,evt):
A = float(self.a.GetValue())
B = float(self.b.GetValue())
file = 'Courbes projet'
selection = wx.FileDialog(self, 'Enregistrer sous',"" , file, wildcard = "*.pdf",
style = wx.SAVE)
retour = selection.ShowModal()
chemin = selection.GetPath()
fichier = selection.GetFilename()
selection.Destroy()
def f_1(x):
y = A*x +B
return y
#Traçage de la courbe.
if os.path.isfile("data_curve1.txt") == True:
os.remove("data_curve1.txt")
z = 0.001
while z <= 10:
y = f_1(z)
txt = str(z) + ';' + str(y) + "\n"
donnee = open("data_curve1.txt","a")
donnee.write(txt)
donnee.close()
z = z + 0.1
Graph.rapport(chemin)
##---------------
## Lancement de l'Application
##---------------
class MonApp(wx.App):
def OnInit(self):
fen = Root('Exemple')
fen.Show(True)
self.SetTopWindow(fen)
return True
app = MonApp()
app.MainLoop() |
Partager