473,756 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython and loading multiple panels (code included)

Hi,

i need to develop a gui which will load several "windows" depending on
what the users selects in the menu and i thought i could accomplish this
with panels.
What i'm trying to do to test this is load an initial panel and then
when the user hits a button load a second panel. This doesn't seem to work.

1. what's the appropriate way of switching panels?
2. the loadNewPanel function seem wrong. I always get loading panel two".

Thanks,
Benedict

=============== ===== multi.py =============== ============
import wx
from multi_panel import *

active_frame = 1

class MyFrame(wx.Fram e):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAM E_STYLE
wx.Frame.__init __(self, *args, **kwds)
self.panel = PanelOne(self)
self.__set_prop erties()
self.__do_layou t()

def __set_propertie s(self):
self.SetTitle(" frame_1")

def __do_layout(sel f):
self.sizer_1 = wx.BoxSizer(wx. VERTICAL)
self.sizer_1.Ad d(self.panel, 1, wx.EXPAND, 0)
self.SetAutoLay out(True)
self.SetSizer(s elf.sizer_1)
self.sizer_1.Fi t(self)
self.sizer_1.Se tSizeHints(self )
self.Layout()

def loadNewPanel(se lf,invoker):
if isinstance(invo ker,PanelOne):
print "loading panel two"
self.panel = PanelTwo(self)
else:
print "loading panel one"
self.panel = PanelOne(self)
self.sizer_1.Fi t(self)
self.sizer_1.Se tSizeHints(self )

class MyApp(wx.App):
def OnInit(self):
wx.InitAllImage Handlers()
frame = MyFrame(None, -1, "This is a
wx.Frame",pos=( 0,0),size=(640, 480),style = wx.DEFAULT_FRAM E_STYLE)
self.SetTopWind ow(frame)
frame.Show()
return 1

if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
=============== ===== multi.py =============== ============

and

=============== ===== panels.py =============== ============
import wx

class PanelOne(wx.Pan el):
def __init__(self,p arent):
wx.Panel.__init __(self, parent, -1)
self.parent = parent
self.label = wx.StaticText(s elf, -1, "panel one")
self.switch_pan el = wx.Button(self, -1, "Switch to panel two",
(50,50))
self.Bind(wx.EV T_BUTTON, self.__OnButton , self.switch_pan el)
self.__do_layou t()

def __do_layout(sel f):
self.grid_sizer = wx.GridSizer(5, 5, 4, 4)
self.grid_sizer .Add(self.label , 0, wx.FIXED_MINSIZ E, 0)
self.grid_sizer .Add(self.switc h_panel, 0, wx.FIXED_MINSIZ E, 0)

self.SetAutoLay out(True)
self.SetSizer(s elf.grid_sizer)

self.grid_sizer .Fit(self)
self.grid_sizer .SetSizeHints(s elf)

def __OnButton(self ,event):
print "OnButton"
self.parent.loa dNewPanel(self)

class PanelTwo(wx.Pan el):
def __init__(self,p arent):
wx.Panel.__init __(self, parent, -1)
self.label = wx.StaticText(s elf, -1, "panel two")
self.switch_pan el = wx.Button(self, -1, "Switch to panel one",
(50,50))
self.Bind(wx.EV T_BUTTON, self.__OnButton , self.switch_pan el)
self.__do_layou t()

def __do_layout(sel f):
self.grid_sizer = wx.GridSizer(5, 5, 4, 4)
self.grid_sizer .Add(self.label , 0, wx.FIXED_MINSIZ E, 0)
self.grid_sizer .Add(self.switc h_panel, 0, wx.FIXED_MINSIZ E, 0)

self.SetAutoLay out(True)
self.SetSizer(s elf.grid_sizer)

self.grid_sizer .Fit(self)
self.grid_sizer .SetSizeHints(s elf)

def __OnButton(self ,event):
print "OnButton"
self.parent.loa dNewPanel(self)
=============== ===== panels.py =============== ============
Jul 18 '05 #1
0 1640

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

Similar topics

19
3426
by: Grant Edwards | last post by:
I've decided to learn wxPython, and I'm afraid I just don't grok the whole "id" thing where you have to pull unique integers out of your, er, the air and then use those to refer to objects: From whe wxPython wiki examples: self.button =wxButton(self, 10, "Save", wxPoint(200, 325)) EVT_BUTTON(self, 10, self.OnClick)
3
3013
by: Piet | last post by:
Hi, I am trying to generate an "hierarchical" layout based on wx.NoteBooks. That means, every page of a Notebook should be a NoteBookon its own. Here is a (short but complicated) piece of code that I put together to see whether it works: import wx #____________________________ class MainWindow(wx.Frame):
1
7678
by: pfnus | last post by:
Hi, I want to display different forms when the buttons are clicked and all the forms are having different controls on it. So instead of adding new windows forms to the project, i enlarged the form and used many panels on the same form, which i think is easier to manage. However, i am having problems. Should i need to put the panels on the same location on the design layout? i put the panels at different places and it doesn't get...
1
1908
by: py | last post by:
I have the following code: class MainFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, wx.ID_ANY, title, style=wx.DEFAULT_FRAME_STYLE |wx.NO_FULL_REPAINT_ON_RESIZE) # build top area topSizer = self.buildTopPanel() # build input area inputSizer = self.buildInputPanel()
10
35949
by: markwalker84 | last post by:
Hello everyone! Got a bit of a problem... Two of the panels on my program contain a number of check boxes. The exact number of which is determined by a pair of variables. I have recently implemented a Wizard which changes that number, as well as a save and load function to the program. I know the number of being altered in memory (i added a quick check button) but what i'm struggling with is how to refresh the panel with the new...
5
2417
by: Che M | last post by:
Hello, I'm curious if it is easy to get panels on your wxPython apps to have backgrounds which are given by a jpg or other bitmap. I found http://www.5etdemi.com/blog/archives/2006/06/making-a-panel-with-a-background-in-wxpython/ on a blog, which seems to be the way to do it, but I am too new to Python and wxPython to understand how to implement it. Can anyone help me understand how to go from this to specifying an image to serve as...
0
1937
by: Soren | last post by:
Hi, I'm trying to create a small GUI program where I can do plots using Matplotlib. I've been trying to borrow code from the examples at the matplotlib website, but I can't get it to work. I want to be able to create a wx.Panel that contains an axis for plotting. Around it i want other panels containing various settings, buttons etc. to control the plot. So far I can't even get the program to actually show a plot in a panel.
0
3404
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?
1
4588
by: aeroumr | last post by:
In the following code, I have created a panel with a button and a textctrl object on it. I have also created a menubar that will create a new text file (i.e. textctrl object). My problem is that when I create a new file, it displays the textctrl over the top left of my existing panel. I know that the reason is because I have specified the parent as self (i.e. Frame). How do I get the new file to display in the textctrl widget on my panel? I...
0
9152
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,...
0
9716
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9716
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9571
tracyyun
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...
1
7116
isladogs
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...
0
6410
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();...
0
4996
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3185
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2542
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.