Switching Control Between Frames

I have been battling with the same general issue for some
time now. I have finally made a simpler example. The code below creates a frame
that access an external data list. The ‘Show List’ button opens a separate
frame set to the index of the main frame. I want a double-click event to update
the main frame and close the list frame.

Any assistance would be greatly appreciated.

···

========================================

small_sample_listbox.py

========================================

#!/usr/bin/env python

import wx

import data

The main working frame for the program:

class DisplayFrame(wx.Frame):

def init(self, *args, **kwds):

kwds[“style”] = wx.DEFAULT_FRAME_STYLE

wx.Frame.init(self, *args, **kwds)

self.text_ctrl_item = wx.TextCtrl(self, -1, “”)

self.button_list
= wx.Button(self, -1, “Show List”)

self.button_prev
= wx.Button(self, -1, “<”)

self.button_next
= wx.Button(self, -1, “>”)

self.position =
data.position

self.text_ctrl_item.SetValue(data.selections[self.position])

self.__set_properties()

self.__do_layout()

self.Bind(wx.EVT_BUTTON, self.onShowList, self.button_list)

self.Bind(wx.EVT_BUTTON, self.onPrev, self.button_prev)

self.Bind(wx.EVT_BUTTON, self.onNext, self.button_next)

def __set_properties(self):

self.SetTitle(“Small Sample Application with ListBox”)

self.SetSize((200, 150))

self.SetPosition((300,300))

def __do_layout(self):

sizer_1 =
wx.BoxSizer(wx.VERTICAL)

sizer_3 =
wx.BoxSizer(wx.VERTICAL)

sizer_4 =
wx.BoxSizer(wx.HORIZONTAL)

sizer_3.Add(self.text_ctrl_item, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)

sizer_3.Add(self.button_list, 0,
wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5)

sizer_4.Add(self.button_prev, 0, wx.ALL, 5)

sizer_4.Add(self.button_next,
0, wx.ALL, 5)

sizer_3.Add(sizer_4, 1, wx.EXPAND, 0)

sizer_1.Add(sizer_3, 1, wx.EXPAND, 0)

self.SetAutoLayout(True)

self.SetSizer(sizer_1)

self.Layout()

def onShowList(self, event): # from
button_list

frame_list =
SimpleListFrame(None,-1,"")

frame_display.Hide()

frame_list.Show()

frame_display.Show()

def onPrev(self, event): # from
button_prev

self.position +=
-1

self.onPosition(self.position)

self.onUpdate(self.position)

def onNext(self, event): # from
button_next

self.position +=
1

self.onPosition(self.position)

self.onUpdate(self.position)

def onPosition(self,item): # share
position information between classes

max =
len(data.selections) - 1

if item < 0:

self.position=0

if item > max:

self.position = max

def onUpdate(self,item): # Update the
main frame

self.text_ctrl_item.SetValue(data.selections[item])

data.position =
self.position

print
self.position

class SimpleListFrame(wx.Frame): # a pick list using listbox

def init(self, *args, **kwds):

options =
data.selections # import external list from data

kwds[“style”] = wx.DEFAULT_FRAME_STYLE

wx.Frame.init(self, *args, **kwds)

self.list_box =
wx.ListBox(self, -1, choices=options)

self.__set_properties()

self.__do_layout()

self.Bind(wx.EVT_LISTBOX_DCLICK, self.onDoubleClick, self.list_box)

def __set_properties(self):

location =
data.position # set position in external file

print location

self.SetTitle(“This is the Pick List!”)

self.list_box.SetSelection(location)

def __do_layout(self):

sizer_6 =
wx.BoxSizer(wx.VERTICAL)

sizer_7 =
wx.BoxSizer(wx.HORIZONTAL)

sizer_7.Add(self.list_box, 0, wx.ALL, 5)

sizer_6.Add(sizer_7, 1, wx.EXPAND, 0)

self.SetAutoLayout(True)

self.SetSizer(sizer_6)

sizer_6.Fit(self)

sizer_6.SetSizeHints(self)

self.Layout()

def onDoubleClick(self, event): # respond
to double-clicked listbox item

print
self.list_box.GetSelection()

data.position =
self.list_box.GetSelection()

#======== Want to do
something like the following: =========

frame_list.Hide()

DisplayFrame.onUpdate(data.position)

if name == “main”:

app = wx.PySimpleApp(0)

wx.InitAllImageHandlers()

frame_display = DisplayFrame(None, -1,
“”)

app.SetTopWindow(frame_display)

frame_display.Show()

app.MainLoop()

========================================

data.py

========================================

selections

[“one”,“two”,“three”,“four”,“five”]

position
= 0

Thank
you,

Hal Kurz

Innovative
Technology Consultants & Company, Inc.

11767
South Dixie Highway #307

Miami,
Florida 33156

(305)
238-6587

www.itccinc.com

“Making
the world of technology accessible to small business.”

I got it working. I guess I didn’t
understand parent/child frames so well or how to call them in the program. I
was working within my classes and not within the main portion of the program.

Thank you,

Hal

···

From: ITC Python
[mailto:python@itccinc.com]
Sent: Friday, May 25, 2007 3:41 PM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] Switching Control Between Frames

I have been battling with the same general issue for some
time now. I have finally made a simpler example. The code below creates a frame
that access an external data list. The ‘Show List’ button opens a
separate frame set to the index of the main frame. I want a double-click event
to update the main frame and close the list frame.

Any assistance would be greatly appreciated.