Hey guys,

here's a simple one:

I'm developing a load test suite (for GSM networks) at the moment and i have scripts that create traffic patterns and all that.

I am developing a GUI for the test suite that dynamically adjusts the layout and controls which are displayed on a wxframe. The GUI manipulates the test configuration settings, parameters and traffic patterns. The only problem is that i can't remove the old controls. When i select a different test the new desired layout does appear, but the old one still exists.

I have tried:

self.ClearBackground()
self.Refresh()

but i can understand why these would not be working, as clearBackground applies to the bg, and refresh simply refreshes existing controls.

How do i delete all the controls on a given wxframe? (yes, the controls are all directly on the frame)

I basically want to just clear the frame, but Clear() doesn't exist. I don't really care if the controls are destroyed or not, just as long as they're not visible anymore.

Cheers,

LarZ

Try self.Destroy() The wiki has examples
http://wiki.wxpython.org/Getting_Started

Afraid not my friend. This simply destroys the frame, i don't want to have to recreate it i just want to remove any controls that are on it as if i just instantiated the frame.

I have also tried

for control in self.allControls:
			control.Destroy()

but this causes a segmentation error which is forcing the app to crash out.

What happens if you put all your controls on a Panel and then destroy the Panel?

This may work but i'm having trouble with the panel. with the normal method where i place a control directly on a frame i pass in self as the 1st argument. Then when i try to place it on a panel (declared: self.panel = wxPanel ( self, -1 )) and i pass in self.panel instead of self (which is my frame) all of a sudden it looks for pointers... YUCK... pointers...

I want to stay away from panels i think, although your suggestion could work, i still don't see why i can't just remove one control. When i tried destroy on one single control my application hanged too, so i don't see how it would be different for a wxPanel, other than the fact that it derives from wxwindow and not wxcontrol. But wxcontrol derives from wxwindow so i'm skeptical to say the least.

There will be a lot of UI changing going on as all controls are dynamically created. I don't really want to have to recreate everything ALL the time...

I'm not familiar with python's way of deleting objects. can i say del(myCbx) to remove the object from memory? Would this method have knock on effects? I know it's not great programming but i'm not left a lot of choice. I've never heard of an object belonging to another object without the ability to be removed :s

even if i could hide them and move them around it would help...

LarZ

Generally in Python you can use del myobject , but remember wxPython is a wrapper for wxWindows which is written in C++. Let me play with it! Also, could you give us a short sample code of what you do to hang it up?

Well, I played with it ...

import wx

class Panel1(wx.Panel):
    """create a panel with a label and button on it"""
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        str1 = "War is Hell!"

        self.label1 = wx.StaticText(self, -1, str1 , pos=(20, 30))
        self.button1 = wx.Button(self, id=-1, label='Destroy',
            pos=(20, 60), size=(175, 28))
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)

    def button1Click(self, event):
        # this will just destroy the label
        #self.label1.Destroy()
        # this will destroy the whole panel and the components on it
        self.Destroy()

    
app = wx.PySimpleApp()
# create a window/frame, no parent, -1 is default ID
frame1 = wx.Frame(None, -1, "A label on a panel", size=(300, 150))
# call the derived class, parent is frame and id is -1
Panel1(frame1,-1)
frame1.Show(1)
app.MainLoop()

Works as predicted.

yeah i'll keep tryin at this...

Appreciate your help :)

I seem to have gotten it working... I don't know what the problem was though :D

Thanks a lot for your help!

Please explain why the following is not working for me... it's really frustrating :@
I'm getting a segmentation fault when i change the combobox selection, which forces the panel to be destroyed...

from wxPython.wx import *

currentPoint = wxPoint(10,10)
currentTest = None

def adjustPointForNewLabel(oldPoint):
	return wxPoint(oldPoint.x+155, oldPoint.y+7)
	
def adjustPointForNewComboBox(oldPoint):
	return wxPoint(oldPoint.x+45, oldPoint.y-7)

class MainPanel(wxPanel):
	def __init__(self, parent):
		wxPanel.__init__(self,parent,-1)
		
class MainFrame(wxFrame):
	def __init__(self, parent, ID, title):
		wxFrame.__init__(self, parent, ID, title,wxDefaultPosition, wxSize(1000, 500))
		self.createMainPanel(self)
		
	def createMainPanel(self,frame):
		self.mainPanel = MainPanel(frame)
		self.setTestSelectionControls(self.mainPanel)
		
	def setTestSelectionControls(self,panel):
		global currentPoint
		self.lblTest = wxStaticText(panel, -1, "Test: ",currentPoint)
		available = ["1","2","3","4","5"]
		currentPoint = adjustPointForNewComboBox(currentPoint)
		self.cbxTests = wxComboBox(panel, 106, "select test", currentPoint, wxSize(140, -1),available, wxCB_DROPDOWN)
		EVT_COMBOBOX(self, 106, self.EvtCbx)
		
	def EvtCbx(self,selection):
		print "This is where the app breaks"
		self.mainPanel.Destroy()

class MyApp(wxApp):
	def OnInit(self):
		frame = MainFrame(NULL, -1, "blah")
		frame.Show(1)
		return true

app = MyApp(0)
app.MainLoop()

Note: Looks like really old code and tabs on top of all that. Can't play with it, my programing editor hates tabs for indents.

can anybody help me with the above problem please? It might be something stupid, or it might be the wx framework that's causing the segmentation fault...

parent.layout()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.