hi every body,
this is what I have written till now for my graphic interface:
from networkx import *
import pylab as P
import wx
from Simulateur import *
ID_OPEN=001
ID_ABOUT=101
ID_EXIT=110class MainWindow(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self,None,wx.ID_ANY,'Construction reseau')
self.CreateStatusBar()
#setup du menu
filemenu = wx.Menu()
filemenu.Append(1000, "New", "New configuration")
filemenu.Append(1100, "Open", "Open an existing configuration")
filemenu.Append(1200, "Save", "Save configuration")
filemenu.AppendSeparator()
filemenu.Append(1300, "Exit", "Exit the programm")editmenu = wx.Menu()
editmenu.Append(2000, "Ajouter Noeud", "Ajoute un noeud")
editmenu.Append(2100, "Ajouter Lien", "Ajoute un lien")
editmenu.Append(2200, "Mettre a jour", "Met a jour")helpmenu=wx.Menu()
helpmenu.Append(3000, "HowTo", "What you should know")
filemenu.AppendSeparator()
helpmenu.Append(3100, "About", "Informations")#creation du menu
menubar = wx.MenuBar()
menubar.Append(filemenu, "&File")
menubar.Append(editmenu, "&Edit")
menubar.Append(helpmenu, "&Help")
self.SetMenuBar(menubar)#Inside windows
panel= wx.Panel(self, -1)#creation du sizer
sizer = wx.GridBagSizer(hgap=4, vgap=4)#creation des fenetres
status = wx.StaticText(panel, -1, 'Status')
sizer.Add(status, pos=(19,0), flag=wx.BOTTOM, border=0)fen2 = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE)
sizer.Add(fen2, (20,0), (5,35), wx.EXPAND, 0)envirTex = wx.StaticText(panel, -1, 'Environement')
sizer.Add(envirTex, pos=(0,0), flag=wx.BOTTOM, border=0)envir=wx.StaticBox(panel, -1)
sizer.Add(envir, (1, 0), (18,35), wx.EXPAND, 0)configTex = wx.StaticText(panel, -1, 'Configuration')
sizer.Add(configTex, pos=(0,36), flag=wx.BOTTOM, border=0)config=wx.StaticBox(panel, -1)
sizer.Add(config, (1, 36), (24,15), wx.EXPAND, 0)panel.SetSizerAndFit(sizer)
self.Fit()
#evenements
wx.EVT_MENU(self,3100,self.OnAbout)
wx.EVT_MENU(self,1100,self.OnOpen)
wx.EVT_MENU(self,1300,self.OnExit)
wx.EVT_MENU(self,2000,self.OnNode)
wx.EVT_MENU(self,2100,self.OnLink)
wx.EVT_MENU(self,2200,self.OnUpdate)
self.Show(True)
self.Centre()def OnOpen(self,event):
#Open a file
self.dirname = ''
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*",
wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename=dlg.GetFilename()
self.dirname=dlg.GetDirectory()
f=open(os.path.join(self.dirname,self.filename),'r')
self.control.SetValue(f.read())
f.close()
dlg.Destroy()def OnSave(selfself, event):
passdef OnNew(selfself, event):
passdef OnExit(self,event):
self.Close(True)def OnAbout(self,event):
d=wx.MessageDialog(self, "Simulateur de reseaux de machines en
Python \nAuteurs : Chollet Mathieu, Cladiere Pierre-Yves\nEl Gon Nouni
Abdessamaed \nProjet DEV 2008 \nTELECOM Bretagne", "A propos", wx.OK)
d.ShowModal()
d.Destroy()def OnNode(self,event):
self.G.add_node(self.i)
self.i=self.i+1def OnLink(self,event):
self.G.add_edge(self.j,self.j+1)
self.j=self.j+1def OnUpdate(self,event):
#ajout de l'image
if self.panel !=None:
self.panel.Destroy()
self.panel = wx.Panel(self, -1)
sizerH= wx.BoxSizer(wx.HORIZONTAL)
draw(self.G)
P.savefig("construction.png")
img= wx.Image('construction.png',wx.BITMAP_TYPE_PNG)
bmp= wx.BitmapFromImage(img)
staticBmp= wx.StaticBitmap(self,wx.ID_ANY,bmp)
sizerH.Add(staticBmp)
self.SetAutoLayout(1)
sizerH.Fit(self)self.Center()
self.Show(True)class MonApp(wx.App):
def OnInit(self):
self.MainWindow = MainWindow(title='Simulateur reseau')
self.MainWindow.Show()
self.SetTopWindow(self.MainWindow)
return Trueapp = MonApp()
app.MainLoop()Now I have to add some fields in the staticBox "environement" but I tryied
without results. I didn't know how to pass the staticBox as a parent to
another static box a texCtrl or a button. any idea please?
Reading this will help I hope:
From the wxWidgets API found at
http://docs.wxwidgets.org/2.8.6/wx_wxstaticbox.html
wxStaticBox
A static box is a rectangle drawn around other panel items to denote a
logical grouping of items.
Please note that a static box should not be used as the parent for the
controls it contains, instead they should be siblings of each other.
Although using a static box as a parent might work in some versions of
wxWidgets, it results in a crash under, for example, wxGTK.
Also, please note that because of this, the order in which you create
new controls is important. Create your wxStaticBox control before any
siblings that are to appear inside the wxStaticBox in order to
preserve the correct Z-Order of controls.
···
On Fri, May 16, 2008 at 4:06 PM, Abdessamad EL GON-NOUNI <abdessamadg@gmail.com> wrote: