P
Piet
Hello wxPythoneers.
I have a problem with a dialog box derived from wxFrame which has a
wxComboBox as main element. Depending on the entry selected from the
ComboBox, the dialog box will be populated with a number of controls.
This works fine for the first selection of a combobox item, but
subsequent selections from the combobox cause problems. This is
because the event function for the combobox populates the sizer for
the window with items though the sizer already has some items. Thus, I
think that I need a method to clear the items from a sizer. Please let
me know your suggestions about how to reach this goal. When you find
other odds in the following script, please let me know these as well.
I have described the problems with this "dyamic dialog" in two other
threads, but I believe that the information supplied there was not
sufficient to make the problem clear.
BTW, I am aware of the Detach-Function of Sizers, but I dont think
they are the solution to my problem. This method seems only to be able
to remove a
sizer completely (which is not want I want, because the sizer will be
repopulated in the next step, and I dont want to recreate it, because
the sizer has to keep its position in the dialog relative to the other
sizers) or to remove the item with the specified position (which is no
alternative as well, because the number of childs or controls in the
sizer will vary).
Many thanks in advance
Piet
Code:
####
#-*- coding: UTF-8 -*-
from wxPython.wx import *
from wxPython.lib.rcsizer import RowColSizer
#____________________________
class MainWindow(wxFrame):
def __init__(self,parent,id,title):
wxFrame.__init__(self,parent,id, title,
style=wxDEFAULT_FRAME_STYLE|wxFULL_REPAINT_ON_RESIZE)
self.panel = wxPanel(self,-1)
self.mainsizer = wxBoxSizer(wxVERTICAL)
self.mainsizer.Add(self.panel,1,wxEXPAND|wxALL)
self.ID_LBOX = 100
self.ID_CBOX_VARTYPES = 101
self.ID_CBOX_ACTIONS = 102
self.BtnSave = wxButton(self.panel,wxID_OK,"Save")
self.BtnClose = wxButton(self.panel,wxID_CANCEL,"Close")
self.DlgBtnSizer = wxBoxSizer(wxHORIZONTAL)
self.DlgBtnSizer.Add(self.BtnSave,1,wxALIGN_CENTER|wxALL,)
self.DlgBtnSizer.Add(self.BtnClose,1,wxALIGN_CENTER|wxALL)
self.ControlSizer = RowColSizer()
self.HeaderSizer = wxBoxSizer(wxVERTICAL)
self.SubHeaderSizer = wxBoxSizer(wxVERTICAL)
self.Textbox = []
self.Textlabels = []
self.MasterSizer=wxBoxSizer(wxVERTICAL)
self.MasterSizer.Add(self.HeaderSizer,0,wxALIGN_CENTER)
self.MasterSizer.Add(self.SubHeaderSizer,0,wxALIGN_CENTER)
self.MasterSizer.AddSizer(self.ControlSizer,0,wxALIGN_CENTER)
self.MasterSizer.AddSizer(self.DlgBtnSizer,0,wxALIGN_CENTER)
self.ChooseAction =
wxComboBox(self.panel,self.ID_CBOX_ACTIONS,"New Column",choices =
["New Database","New Table","New
Column"],size=(180,-1),style=wxCB_READONLY)
EVT_COMBOBOX(self,self.ID_CBOX_ACTIONS,self.OnActionsCboxChange)
self.HeaderSizer.Add(wxStaticText(self.panel,-1,"Actions:",size=(200,48)),1,wxALIGN_LEFT)
self.HeaderSizer.Add(self.ChooseAction,0,wxEXPAND)
self.panel.SetSizer(self.MasterSizer)
self.panel.SetAutoLayout(True)
self.MasterSizer.Fit(self.panel)
self.panel.Fit()
self.Fit()
self.Show(True)
def OnActionsCboxChange(self,event):
if self.ChooseAction.GetValue() == "New Column":
self.columnTypes =
wxComboBox(self.panel,self.ID_CBOX_VARTYPES,"Varchar",choices =
["Char","Varchar","Tinyint","Smallint","Mediumint","Integer","Float"],size=(180,-1),style=wxCB_READONLY)
self.SubHeaderSizer.Add(wxStaticText(self.panel,-1,"Column
types:",size=(200,48)),1,wxALIGN_LEFT)
self.SubHeaderSizer.Add(self.columnTypes,0,wxEXPAND)
controls = ["Name","Width","Decimals"]
for i in range(len(controls)):
self.Textlabels.append(wxStaticText(self.panel,-1,controls))
self.Textbox.append(wxTextCtrl(self.panel,-1,"",size=(180,-1),name=controls))
self.ControlSizer.Add(self.Textlabels,row=i+1,col=0,flag=wxALIGN_CENTER_VERTICAL|wxALL)
self.ControlSizer.Add(self.Textbox,row=i+1,col=1,flag=wxALIGN_CENTER_VERTICAL|wxALL)
self.extras =
wxListBox(self.panel,self.ID_LBOX,choices=[],size=(96,96),style =
wxLB_MULTIPLE)
self.ControlSizer.Add(wxStaticText(self.panel,-1,"Extras"),row=4,col=0,flag=wxALIGN_CENTER_VERTICAL|wxALL)
self.ControlSizer.Add(self.extras,row=4,col=1,flag=wxALIGN_TOP)
self.MasterSizer.RecalcSizes()
self.panel.Fit()
self.Fit()
#____________________________
app = wxPySimpleApp()
frame = MainWindow(None, -1, "MySQL Frontend")
frame.Show(1)
app.MainLoop()####
I have a problem with a dialog box derived from wxFrame which has a
wxComboBox as main element. Depending on the entry selected from the
ComboBox, the dialog box will be populated with a number of controls.
This works fine for the first selection of a combobox item, but
subsequent selections from the combobox cause problems. This is
because the event function for the combobox populates the sizer for
the window with items though the sizer already has some items. Thus, I
think that I need a method to clear the items from a sizer. Please let
me know your suggestions about how to reach this goal. When you find
other odds in the following script, please let me know these as well.
I have described the problems with this "dyamic dialog" in two other
threads, but I believe that the information supplied there was not
sufficient to make the problem clear.
BTW, I am aware of the Detach-Function of Sizers, but I dont think
they are the solution to my problem. This method seems only to be able
to remove a
sizer completely (which is not want I want, because the sizer will be
repopulated in the next step, and I dont want to recreate it, because
the sizer has to keep its position in the dialog relative to the other
sizers) or to remove the item with the specified position (which is no
alternative as well, because the number of childs or controls in the
sizer will vary).
Many thanks in advance
Piet
Code:
####
#-*- coding: UTF-8 -*-
from wxPython.wx import *
from wxPython.lib.rcsizer import RowColSizer
#____________________________
class MainWindow(wxFrame):
def __init__(self,parent,id,title):
wxFrame.__init__(self,parent,id, title,
style=wxDEFAULT_FRAME_STYLE|wxFULL_REPAINT_ON_RESIZE)
self.panel = wxPanel(self,-1)
self.mainsizer = wxBoxSizer(wxVERTICAL)
self.mainsizer.Add(self.panel,1,wxEXPAND|wxALL)
self.ID_LBOX = 100
self.ID_CBOX_VARTYPES = 101
self.ID_CBOX_ACTIONS = 102
self.BtnSave = wxButton(self.panel,wxID_OK,"Save")
self.BtnClose = wxButton(self.panel,wxID_CANCEL,"Close")
self.DlgBtnSizer = wxBoxSizer(wxHORIZONTAL)
self.DlgBtnSizer.Add(self.BtnSave,1,wxALIGN_CENTER|wxALL,)
self.DlgBtnSizer.Add(self.BtnClose,1,wxALIGN_CENTER|wxALL)
self.ControlSizer = RowColSizer()
self.HeaderSizer = wxBoxSizer(wxVERTICAL)
self.SubHeaderSizer = wxBoxSizer(wxVERTICAL)
self.Textbox = []
self.Textlabels = []
self.MasterSizer=wxBoxSizer(wxVERTICAL)
self.MasterSizer.Add(self.HeaderSizer,0,wxALIGN_CENTER)
self.MasterSizer.Add(self.SubHeaderSizer,0,wxALIGN_CENTER)
self.MasterSizer.AddSizer(self.ControlSizer,0,wxALIGN_CENTER)
self.MasterSizer.AddSizer(self.DlgBtnSizer,0,wxALIGN_CENTER)
self.ChooseAction =
wxComboBox(self.panel,self.ID_CBOX_ACTIONS,"New Column",choices =
["New Database","New Table","New
Column"],size=(180,-1),style=wxCB_READONLY)
EVT_COMBOBOX(self,self.ID_CBOX_ACTIONS,self.OnActionsCboxChange)
self.HeaderSizer.Add(wxStaticText(self.panel,-1,"Actions:",size=(200,48)),1,wxALIGN_LEFT)
self.HeaderSizer.Add(self.ChooseAction,0,wxEXPAND)
self.panel.SetSizer(self.MasterSizer)
self.panel.SetAutoLayout(True)
self.MasterSizer.Fit(self.panel)
self.panel.Fit()
self.Fit()
self.Show(True)
def OnActionsCboxChange(self,event):
if self.ChooseAction.GetValue() == "New Column":
self.columnTypes =
wxComboBox(self.panel,self.ID_CBOX_VARTYPES,"Varchar",choices =
["Char","Varchar","Tinyint","Smallint","Mediumint","Integer","Float"],size=(180,-1),style=wxCB_READONLY)
self.SubHeaderSizer.Add(wxStaticText(self.panel,-1,"Column
types:",size=(200,48)),1,wxALIGN_LEFT)
self.SubHeaderSizer.Add(self.columnTypes,0,wxEXPAND)
controls = ["Name","Width","Decimals"]
for i in range(len(controls)):
self.Textlabels.append(wxStaticText(self.panel,-1,controls))
self.Textbox.append(wxTextCtrl(self.panel,-1,"",size=(180,-1),name=controls))
self.ControlSizer.Add(self.Textlabels,row=i+1,col=0,flag=wxALIGN_CENTER_VERTICAL|wxALL)
self.ControlSizer.Add(self.Textbox,row=i+1,col=1,flag=wxALIGN_CENTER_VERTICAL|wxALL)
self.extras =
wxListBox(self.panel,self.ID_LBOX,choices=[],size=(96,96),style =
wxLB_MULTIPLE)
self.ControlSizer.Add(wxStaticText(self.panel,-1,"Extras"),row=4,col=0,flag=wxALIGN_CENTER_VERTICAL|wxALL)
self.ControlSizer.Add(self.extras,row=4,col=1,flag=wxALIGN_TOP)
self.MasterSizer.RecalcSizes()
self.panel.Fit()
self.Fit()
#____________________________
app = wxPySimpleApp()
frame = MainWindow(None, -1, "MySQL Frontend")
frame.Show(1)
app.MainLoop()####