IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

wxPython Discussion :

Gestion layout avec wx.StaticBox, wx.StaticBoxSizer et wx.GridBagSizer


Sujet :

wxPython

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1
    Par défaut Gestion layout avec wx.StaticBox, wx.StaticBoxSizer et wx.GridBagSizer
    Bonjour,
    J'ai un problème pour afficher correctement des widgets.
    J'aimerais afficher les 3 elements :
    StaticBox contenant staticboxsizer
    StaticBox2 contenant staticboxsizer2
    et Quelques button;

    Voici la classe que j'ai créée :

    Merci de votre aide
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    class ConfigurationDialog(wx.Dialog,WndProcHookMixin):
    	def __init__(self, parent, enable=True):
    		WndProcHookMixin.__init__(self)
    		wx.Dialog.__init__(self, None, -1, "Configuration", size=(405,320))
    		panel = wx.Panel(self)
     
    		staticBox1 = wx.StaticBox(self, -1, "AAAAA:")
    		StaticBoxSizer1 = wx.StaticBoxSizer(staticBox1, wx.VERTICAL)	
    		COM_Label = wx.StaticText(panel, -1, "Modem port:")
    		if enable:
    			list = self.__ReadComList()
    			list.sort(self.sort_COM)
    			self.COM = wx.Choice(panel,choices=list)
    			print self.COM.GetStrings()
    			if str("COM"+str(VarGlobal.COM_Port)) in self.COM.GetStrings():
    				self.COM.SetStringSelection(str("COM"+str(VarGlobal.COM_Port)))
    		else:
    			self.COM = wx.TextCtrl(panel,size=(10,-1),value=VarGlobal.COM_Port)
    			self.COM.SetMaxLength(2)
    		Speed_Label = wx.StaticText(panel, -1, "          Modem speed:")
    		self.SpeedListBox = wx.Choice(panel,choices=VarGlobal.SpeedList)
    		self.SpeedListBox.SetStringSelection(VarGlobal.COM_Speed)
    		Trace_Label = wx.StaticText(panel, -1, "Trace port:")
    		if enable:
    			list = self.__ReadComList()
    			list.sort(self.sort_COM)
    			self.COM2 = wx.Choice(panel,choices=list)
    			if str("COM"+str(VarGlobal.Trace_Port)) in self.COM2.GetStrings():
    				self.COM2.SetStringSelection(str("COM"+str(VarGlobal.Trace_Port)))
    		else:
    			self.COM2 = wx.TextCtrl(panel,size=(10,-1),value=VarGlobal.Trace_Port)
    			self.COM2.SetMaxLength(2)
    		Speed_Label2 = wx.StaticText(panel, -1, "          Trace speed:")
    		self.SpeedListBox2 = wx.Choice(panel,choices=VarGlobal.SpeedList)
    		self.SpeedListBox2.SetStringSelection(VarGlobal.Trace_Speed)	
    		# Layout
    		sizer = wx.GridBagSizer(hgap=10,vgap=10)
    		sizer.Add(COM_Label,pos=(0,0),flag=wx.TOP,border=3)
    		sizer.Add(self.COM,(0,1))
    		sizer.Add(Speed_Label,pos=(0,2),flag=wx.TOP,border=3)
    		sizer.Add(self.SpeedListBox,(0,3))
    		sizer.Add(Trace_Label,pos=(1,0),flag=wx.TOP,border=3)
    		sizer.Add(self.COM2,(1,1))
    		sizer.Add(Speed_Label2,pos=(1,2),flag=wx.TOP,border=3)
    		sizer.Add(self.SpeedListBox2,(1,3))		
    		panel.SetSizer(sizer)
     
    		StaticBoxSizer1.Add(panel,0,wx.ALL,10)
    		self.SetSizer(StaticBoxSizer1)
     
    		# Layout
    		Box = wx.BoxSizer(wx.VERTICAL)
    		Box.Add(panel, 0,wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP,20)	
     
    		# Enable or not
    		self.Enable(enable)
    		path = "Logs"		
    		# if the folder "Logs doesn't exist it will created
    		if os.path.exists(os.path.abspath(os.getcwd() + "\\" + path)):
    			VarGlobal.log_dir = os.path.abspath(os.getcwd() + "\\" + path)
    		elif os.path.exists(os.path.abspath(os.path.dirname(os.getcwd()) + "\\" + path)):
    			VarGlobal.log_dir = os.path.abspath(os.path.dirname(os.getcwd()) + "\\" + path)				
    		else:
    			os.mkdir(os.path.abspath(os.getcwd() + "\\" + path))		
    			VarGlobal.log_dir = os.path.abspath(os.path.abspath(os.getcwd() + "\\" + path))
    		self.enable = enable
     
    		#wx.Panel.__init__(self,parent)
    		# Create objects to display
    		staticBox2 = wx.StaticBox(self, -1, "Log/Trace:")  # static ox with title and line arround it
    		StaticBoxSizer2 = wx.StaticBoxSizer(staticBox2,wx.VERTICAL)  # enables to put several widgets into a row or a column
     
    		panel2 = wx.Panel(self)
    		LogDirLabel = wx.StaticText(panel2, -1, label = "Directory:     ")
    		self.log_dir = wx.TextCtrl(panel2, -1, size=(220,-1),value=VarGlobal.log_dir)  #taille du champs en pixels
    		self.log_dir.SetMaxLength(120) #taille du champs
    		LogBrowseLabel = wx.Button(panel2, -1, " ... ", size=(20,20))
    		self.Bind(wx.EVT_BUTTON, self.OnButtonBrowse, LogBrowseLabel)	
    		LogNameLabel = wx.StaticText(panel2, -1, label = "Name:         ")
    		self.log_name = wx.TextCtrl(panel2, -1, size=(220,-1),value=VarGlobal.log_name)
    		self.log_name.SetMaxLength(50) #taille du champs
    		if enable:
    			# Event to catch USB COM Arrival/Remove10
    			#self.GetParent().hookMsgHandler(self.__onDeviceArrival,self.__onDeviceRemove)
    			pass
    		else:
    			ToolTip = "To modify those options please see Configuration menu"
    			self.SetToolTip(wx.ToolTip(ToolTip))
    			panel2.SetToolTip(wx.ToolTip(ToolTip))
    			LogDirLabel.SetToolTip(wx.ToolTip(ToolTip))
    			Speed_Label.SetToolTip(wx.ToolTip(ToolTip))
    			LogBrowseLabel.SetToolTip(wx.ToolTip(ToolTip))
    			LogDirLabel.SetToolTip(wx.ToolTip(ToolTip))
     
    		# Layout
    		sizer2 = wx.GridBagSizer(hgap=7,vgap=7)
    		sizer2.Add(LogDirLabel,pos=(0,0),flag=wx.TOP,border=3)
    		sizer2.Add(self.log_dir,pos=(0,1),flag=wx.TOP,border=3) #span=(0,1),flag=wx.EXPAND)
    		sizer2.Add(LogBrowseLabel,pos=(0,2),flag=wx.TOP,border=3)
    		sizer2.Add(LogNameLabel,pos=(1,0),flag=wx.TOP,border=3)
    		sizer2.Add(self.log_name,pos=(1,1),flag=wx.TOP,border=3) #span=(0,1),flag=wx.EXPAND)	
    		panel2.SetSizer(sizer2)
    		StaticBoxSizer2.Add(panel2,0,wx.ALL,10)
    		print "staticBox1 avant = ", staticBox1			
    		self.SetSizer(StaticBoxSizer2)
    		print "staticBox1 apres = ", staticBox1
     
    		# Enable or not
    		self.Enable(enable)		
     
    		#self.GPRS = GPRS(self)
    		ButtonPanel = wx.Panel(self)
    		self.SaveButton = wx.Button(ButtonPanel, -1, "Save")
    		self.CancelButton = wx.Button(ButtonPanel, -1, "Cancel")
    		#print staticBox1
    		#print staticBox2
    		#Box.Add(staticBox2, 0,wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP,20)
     
    		ButtonBox = wx.BoxSizer(wx.HORIZONTAL)
    		ButtonBox.Add(self.SaveButton, 0,wx.RIGHT,15)
    		ButtonBox.Add(self.CancelButton, 0)
    		ButtonPanel.SetSizer(ButtonBox)
    		Box.Add(ButtonPanel, 0,wx.LEFT|wx.RIGHT|wx.TOP|wx.ALIGN_CENTER_HORIZONTAL,20)
     
    		#self.SetSizer(Box)
     
    		# Events
    		self.Bind(wx.EVT_BUTTON, self.__OnSave, self.SaveButton)			# When Clic on Save Button
    		self.Bind(wx.EVT_BUTTON, self.__OnCancel, self.CancelButton)		# When Clic on Cancel Button
    		self.Bind(wx.EVT_TEXT, self.__OnTxtChange)							# When Text Change active or desactive buttons
    		self.Bind(wx.EVT_CHOICE, self.__OnTxtChange)						# When List box Change active or desactive buttons
    		self.Bind(wx.EVT_CLOSE, self.__OnClose)								# When List box Change active or desactive buttons
     
    		self.__OnTxtChange()												# Init activation of buttons
     
    		self.ShowModal()													# Display Dialog

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    328
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 328
    Par défaut
    Salut,

    Un petit conseil : dessine ton interface avec wxGlade. Ca prend quelques minutes, et insère le code qu'il te sort dans ton fichier... C'est le plus simple.

    A +

  3. #3
    Membre éprouvé
    Inscrit en
    Octobre 2006
    Messages
    92
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 92
    Par défaut
    Bonjour,

    Pour que l'on puisse te répondre il faudrait tout de même que tu fasses l'effort de modifier ton code pour que l'on puisse l'utiliser. Là il nous manque des variables, il n'y a pas de wx.app...

    Avis totalement perso : utiliser wx.glade est une mauvaise idée car il gère mal les sizers. D'une façon générale, si l'on utilise des sizers il vaut mieux faire son IHM à la mano.

    Mais même sans pouvoir tester ton code des erreur bloquantes sont faciles à repérer. Ainsi, lignes 48 et 53 tu assignes deux fois le même widget (panel) à deux sizers différents ! Il y a gros à parier que, si tu as des problèmes, ils viennent essentiellement de là...

    Note que ligne 53 tu déclares un sizer en lui donnant le nom Box. Je ne trouve pas que ce nom soit bien trouvé car c'est pas un nom très évocateur pour un sizer, et ce peut être une source de confusion (la preuve !). Ce nom convient mieux pour un widget. Pour un nom de sizer, je veille à ce que le nom comprenne l'expression "sizer".

Discussions similaires

  1. overflow et table-layout avec IE et FF
    Par nihaoma dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 25/01/2007, 12h39
  2. gestion congés avec fichier xls
    Par didou038 dans le forum C++Builder
    Réponses: 9
    Dernier message: 15/01/2007, 14h48
  3. [DOM] gestion tableau avec DOm
    Par ivanoe25 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 17/11/2006, 08h33
  4. Problème gestion souris avec glademm
    Par flow++ dans le forum Matériel
    Réponses: 1
    Dernier message: 23/05/2006, 10h20
  5. Gestion utilisateurs avec droits
    Par dr_look dans le forum Décisions SGBD
    Réponses: 1
    Dernier message: 27/04/2005, 16h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo