[wxpython-users] three intern windows in one window

EL GON NOUNI abdessamadg at gmail.com
Sat May 17 12:47:15 PDT 2008


C M a écrit :
> 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.
> _______________________________________________
> wxpython-users mailing list
> wxpython-users at lists.wxwidgets.org
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>   

thank you very much C M, I know now how to use panels in order to 
organize my window. here is my new code:

from networkx import *
import pylab as P
from Simulateur import *
ID_OPEN=001
ID_ABOUT=101
ID_EXIT=110
import wx

class InterfaceGraphique(wx.Frame):
    def __init__(self, titre):
        wx.Frame.__init__(self, None, -1, title = titre, size=(1100, 800))
        self.panel3 = wx.Panel(self, -1,pos=(0,550), size=(1100,200))
        
        self.etiquette3 = wx.StaticText(self.panel3, -1, "Status")
        self.etiquette31 = wx.TextCtrl(self.panel3, -1, pos=(0, 15), size=(1100,145),style=wx.TE_MULTILINE)



        
        self.panel2 = wx.Panel(self, -1,pos=(700,0),size=(400,550))
        self.etiquette2 = wx.StaticText(self.panel2, -1, "Configuration")
        self.box2 = wx.StaticBox(self.panel2, -1, pos=(0,10), size=(400, 530))
        self.button1 = wx.Button(self.panel2, -1, pos=(0, 481), size=(190,30), label='Apply changes')
        self.button2 = wx.Button(self.panel2, -1, pos=(0, 510), size=(200,30), label='Change environement')
        self.button3 = wx.Button(self.panel2, -1, pos=(189, 481), size=(210,30), label='Change connexion parameters')
        self.button4 = wx.Button(self.panel2, -1, pos=(199, 510), size=(200,30), label='Start simulation')
        
        self.etiquette3 = wx.StaticText(self.panel2, -1, pos=(1,18), label='Local data')
        self.box3 = wx.StaticBox(self.panel2, -1, pos=(0,10), size=(400, 100))
        
        self.etiquette4 = wx.StaticText(self.panel2, -1, pos=(1,115), label='Node')
        self.box4 = wx.StaticBox(self.panel2, -1, pos=(0,105), size=(400, 180))
        
        
        self.etiquette5 = wx.StaticText(self.panel2, -1, pos=(1,288), label='Environement')
        self.box5 = wx.StaticBox(self.panel2, -1, pos=(0,280), size=(400, 200))
        




        self.panel1 = wx.Panel(self, -1,pos=(0,0),size=(700,550))
        self.etiquette2 = wx.StaticText(self.panel1, -1, "Environement state")
        self.box2 = wx.StaticBox(self.panel1, -1, pos=(0,10), size=(690, 530))

        """
        sizer = wx.GridBagSizer(0,0,vgap=4,hgap=4)
        sizer.Add(self.etiquette31,pos=(0,500), (500,800), flag=wx.BOTTOM,0)"""

        


        
        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)


        #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):
        pass
    
    def OnNew(selfself, event):
        pass
    
    
    def 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+1
        
    def OnLink(self,event):
        self.G.add_edge(self.j,self.j+1)
        self.j=self.j+1
        
    def 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):
        fen = InterfaceGraphique("Simulateur reseau")
        fen.Show(True)
        self.SetTopWindow(fen)
        return True
 
app = MonApp()
app.MainLoop()


the problem now is that I have to specify exactely the position and the 
size of every thing in the window, and the size of the intern windows 
dont change if I change the main window size. I know that I have to use 
sizers, but I didn't understand how they work, and I dont  want to 
change every thing now. so if there is a simple way to make windows 
flexible, I'll be greatful to hear it from you.
thanks


More information about the wxpython-users mailing list