473,739 Members | 3,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
#-*- coding: UTF-8 -*-
from wxPython.wx import *
from wxPython.lib.rc sizer import RowColSizer

#______________ ______________

class MainWindow(wxFr ame):
def __init__(self,p arent,id,title) :
wxFrame.__init_ _(self,parent,i d, title,
self.panel = wxPanel(self,-1)
self.mainsizer = wxBoxSizer(wxVE RTICAL)
self.mainsizer. Add(self.panel, 1,wxEXPAND|wxAL L)
self.ID_LBOX = 100
self.ID_CBOX_VA RTYPES = 101
self.ID_CBOX_AC TIONS = 102
self.BtnSave = wxButton(self.p anel,wxID_OK,"S ave")
self.BtnClose = wxButton(self.p anel,wxID_CANCE L,"Close")

self.DlgBtnSize r = wxBoxSizer(wxHO RIZONTAL)
self.DlgBtnSize r.Add(self.BtnS ave,1,wxALIGN_C ENTER|wxALL,)
self.DlgBtnSize r.Add(self.BtnC lose,1,wxALIGN_ CENTER|wxALL)

self.ControlSiz er = RowColSizer()
self.HeaderSize r = wxBoxSizer(wxVE RTICAL)
self.SubHeaderS izer = wxBoxSizer(wxVE RTICAL)
self.Textbox = []
self.Textlabels = []
self.MasterSize r=wxBoxSizer(wx VERTICAL)
self.MasterSize r.Add(self.Head erSizer,0,wxALI GN_CENTER)
self.MasterSize r.Add(self.SubH eaderSizer,0,wx ALIGN_CENTER)
self.MasterSize r.AddSizer(self .ControlSizer,0 ,wxALIGN_CENTER )
self.MasterSize r.AddSizer(self .DlgBtnSizer,0, wxALIGN_CENTER)
self.ChooseActi on =
wxComboBox(self .panel,self.ID_ CBOX_ACTIONS,"N ew Column",choices =
["New Database","New Table","New
Column"],size=(180,-1),style=wxCB_R EADONLY)
EVT_COMBOBOX(se lf,self.ID_CBOX _ACTIONS,self.O nActionsCboxCha nge)
self.HeaderSize r.Add(wxStaticT ext(self.panel,-1,"Actions:",si ze=(200,48)),1, wxALIGN_LEFT)
self.HeaderSize r.Add(self.Choo seAction,0,wxEX PAND)
self.panel.SetS izer(self.Maste rSizer)
self.panel.SetA utoLayout(True)
self.MasterSize r.Fit(self.pane l)
self.panel.Fit( )

def OnActionsCboxCh ange(self,event ):
if self.ChooseActi on.GetValue() == "New Column":
self.columnType s =
wxComboBox(self .panel,self.ID_ CBOX_VARTYPES," Varchar",choice s =
["Char","Varchar ","Tinyint","Sm allint","Medium int","Integer", "Float"],size=(180,-1),style=wxCB_R EADONLY)
self.SubHeaderS izer.Add(wxStat icText(self.pan el,-1,"Column
types:",size=(2 00,48)),1,wxALI GN_LEFT)
self.SubHeaderS izer.Add(self.c olumnTypes,0,wx EXPAND)
controls = ["Name","Width", "Decimals"]
for i in range(len(contr ols)):
self.Textlabels .append(wxStati cText(self.pane l,-1,controls[i]))
self.Textbox.ap pend(wxTextCtrl (self.panel,-1,"",size=(18 0,-1),name=control s[i]))
self.ControlSiz er.Add(self.Tex tlabels[i],row=i+1,col=0, flag=wxALIGN_CE NTER_VERTICAL|w xALL)
self.ControlSiz er.Add(self.Tex tbox[i],row=i+1,col=1, flag=wxALIGN_CE NTER_VERTICAL|w xALL)
self.extras =
wxListBox(self. panel,self.ID_L BOX,choices=[],size=(96,96),s tyle =
self.ControlSiz er.Add(wxStatic Text(self.panel ,-1,"Extras"),row =4,col=0,flag=w xALIGN_CENTER_V ERTICAL|wxALL)
self.ControlSiz er.Add(self.ext ras,row=4,col=1 ,flag=wxALIGN_T OP)
self.MasterSize r.RecalcSizes()
self.panel.Fit( )
#______________ ______________

app = wxPySimpleApp()
frame = MainWindow(None , -1, "MySQL Frontend")
app.MainLoop()# ###
Jul 18 '05 #1
0 2175

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

Similar topics

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 a ocx developed my me use vc6,this ocx works fine in wxpython. but you can see i only change this ocx with a new DICOM ocx and set up eventClass,
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 to be more low-level than the other GUI toolkits I've used (Tk, GTK, and Trestle), and there are all sorts exposed details in wxWindows/wxPython that I find weird.
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 second sizer (RowColSizer) will be populated with some controls, the number and type of which will depend on the selected ComboBox-Entry. That works fine for the first selection: The wxDialog is enlarged to give room for the new controls. But when...
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 Show() method for the panel, but the error stops on the first panel line anyway. I've tried a Layout() method but it didn't get that far). import wx class MyFrame(wx.Frame):
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
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 don't seem to take. But I don't get any errors either. So am I missing something? Any help would be appreciated. Thanks in advance. I'm building a tool in XSI 6.0 based on this: http://www.xsi-blog.com/archives/138\ I've copied the...
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 "Run" button, the GUI would close, and the 12 input variables would then be available for the rest of the program. So far, what I have been able to do is mostly a reverse engineering job to get the frame to look right and return the text variable...
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. that can control the output on the figure. I've been looking at the examples from the matplotlib website, but can't seem to get it to work.. Does anyone here have experience in embedding matplotlib in wxpython?
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 text control. I've tried adding a new panel object with the stuff i want to the sizer i'm using for my listbox (which is a panel which can contain other panels)... and then run update() and refresh() on everything... But it doesn't work.. i see a...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.