I am attempting to change a set of checkboxes.
These are options that the user can
select from and are a subset of all possible options. I created a window
that will show all possible options and allows the user to change the set
of options shown them. I then call the same function I called from init
to replace the existing checklist with the new version. The checkboxes
are stored in a dictionary, and I delete each member of the dictionary
before assigning new members when a change is made (should this not do
the trick?), also I call self.Layout() afterword to relayout the window.
The result is that both are placed in
the exact same location. A simplified version of the code follows:
import wx
class ControlPanel(wx.Panel):
“”“The control
system for the Manager”""
def init(self, parent):
wx.Panel.__init__(self,parent)
PreviousHeadingChecks={"heading1":True,"heading3":False,"heading6":True}
From save file (saved on close)
self.parent=parent
self.requestSizer
= wx.BoxSizer(orient=wx.VERTICAL)
self.check={}
self.DataHeadings(True,DefaultDict=PreviousHeadingChecks)
self.SetSizer(self.requestSizer)
def DataHeadings(self,
isInit, DefaultDict={}):
"""Changes
the available headings on the fly"""
dataHeadings=self.parent.dataHeadings
for key in self.check.keys():
self.check[key]
del
self.check[key]
this should remove the checkboxes, right?
self.check={}
self.requestSizer.Clear()
for heading in
dataHeadings:
self.check[heading]
= wx.CheckBox(self, label=heading)
self.check[heading].SetValue(DefaultDict.get(heading,
True))
self.requestSizer.Add(self.check[heading])
if not isInit:
self.Layout()
class HeadingEdit(wx.Panel):
def init(self,parent,main):
wx.Panel.__init__(self,
parent)
self.main=main
self.parent=parent
headings = ["heading1","heading2","heading3",
"heading4","heading5","heading6",
"heading7","heading8","heading9"]
colsizer = wx.BoxSizer(orient=wx.HORIZONTAL)
sizercols = [wx.BoxSizer(orient=wx.VERTICAL),
wx.BoxSizer(orient=wx.VERTICAL),
wx.BoxSizer(orient=wx.VERTICAL)]
for col in sizercols:
colsizer.Add(col)
self.check={}
for heading in
headings:
self.check[heading]
= wx.CheckBox(self, label=heading)
self.check[heading].SetValue(heading
in self.main.dataHeadings)
sizercols[headings.index(heading)%len(sizercols)].Add(self.check[heading])
self.SubmitButton
= wx.Button(self, wx.ID_ANY, “OK”)
self.SubmitButton.Bind(wx.EVT_BUTTON,
self.OnSubmit)
sizer = wx.GridBagSizer()
sizer.Add(colsizer,
pos=(1,1))
sizer.Add(self.SubmitButton,
pos=(3,1), flag=wx.ALIGN_CENTER)
sizer.Add(wx.StaticText(self,
wx.ID_ANY, “”), pos=(4,2))
self.SetSizer(sizer)
sizer.Fit(self.parent)
def OnSubmit(self, event):
headings=[]
for heading in
self.check.keys():
if
self.check[heading].GetValue():
headings.append(heading)
self.main.dataHeadings=headings
self.main.Control.DataHeadings(False)
self.GetParent().Destroy()
class EditFrame(wx.Frame):
“”“The frame
where groups and headings are edited”""
def init(self,parent):
wx.Frame.__init__(self,
parent, wx.ID_ANY, ‘Edit Heading’)
panel = HeadingEdit(self,parent)
ID_EDIT_HEADING=101
class MainFrame(wx.Frame):
def init(self):
wx.Frame.__init__(self,
None, wx.ID_ANY, ‘Heading Changer’)
self.dataHeadings=["heading1","heading3","heading6"]
from external file
self.Control =
ControlPanel(self)
menuBar = wx.MenuBar()
editmenu = wx.Menu()
editmenu.Append(ID_EDIT_HEADING,"Edit
&Headings",“Edit headings”)
menuBar.Append(editmenu,"&Edit")
self.SetMenuBar(menuBar)
Adding the MenuBar to the Frame content.
wx.EVT_MENU(self,
ID_EDIT_HEADING, self.OnEditHeading)
def OnEditHeading(self,
event):
editframe=EditFrame(self).Show()
Run the program
if name == ‘main’:
app = wx.App(redirect=False)
frame = MainFrame().Show()
app.MainLoop()
I am using python 2.5.2 and running
under windows xp.
I have been stuck on this problem for
a very long time. I have implimented the solutions I found as best as I
understand them, but I seem to be missing something.
-Brian
Brian Fett
1280 Disc Dr
SHK224
Shakopee, MN 55379
Phone: (952)402-2595