473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

wxPython: Need method to remove items from sizer

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_RESI ZE)
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_CENTE R|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_CE NTER)
self.MasterSizer.Add(self.SubHeaderSizer,0,wxALIGN _CENTER)
self.MasterSizer.AddSizer(self.ControlSizer,0,wxAL IGN_CENTER)
self.MasterSizer.AddSizer(self.DlgBtnSizer,0,wxALI GN_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.OnActi onsCboxChange)
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,"Varch ar",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,wxEXPAN D)
controls = ["Name","Width","Decimals"]
for i in range(len(controls)):
self.Textlabels.append(wxStaticText(self.panel,-1,controls[i]))
self.Textbox.append(wxTextCtrl(self.panel,-1,"",size=(180,-1),name=controls[i]))
self.ControlSizer.Add(self.Textlabels[i],row=i+1,col=0,flag=wxALIGN_CENTER_VERTICAL|wxALL)
self.ControlSizer.Add(self.Textbox[i],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_VERTIC AL|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()####
Jul 18 '05 #1
0 2144

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wang xiaoyu | last post by:
Hello: i want use activex in wxpython program,but when i use MakeActiveXClass an exception occurs. this is my source code dealing the DICOM ocx.I must note that in this program "hwtxcontrol" is...
15
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems...
0
by: Piet | last post by:
Hello, I need some help with the design of a "dynamic" wxDialog. The dialog window is divided into several sizers, the first contains a wxComboBox. When choosing an entry from this wxComboBox, a...
3
by: John Salerno | last post by:
I'm using the sample code of the file 'simple.py' and trying to make a single window with a panel in it, but I keep getting an error. Here's my code: (I know I might need something else, like a...
4
by: kkt49 | last post by:
# vim: et sw=4 ts=8 sts from wxPython.wx import * import sys, os, time import pywintypes import win32serviceutil import win32service import win32event import win32process
0
by: arcsecond | last post by:
I feel like an idiot. I've been struggling with this for 4 days. I can make a window but I can't seem to close them. I think I've narrowed down the problem being with my button event bindings. They...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
0
by: Soren | last post by:
Hi, I've been trying to embed matplotlib in wxpython. I want to be able to put a figure (axes) in a wx.Panel and place it somewhere in my GUI. The GUI should have other panels with buttons etc....
3
by: Soren | last post by:
Hi, Id like to make my own special listbox.. I want to able (at the push of a button) to add another item to my special listbox... each item is a panel with a label, some buttons and maybe a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.