Size: 3635
Comment: make the error pretty...
|
Size: 3649
Comment: Updated sample
|
Deletions are marked like this. | Additions are marked like this. |
Line 18: | Line 18: |
from wxPython.wx import * | import wx |
Line 21: | Line 21: |
class MyTabbedDlg(wxDialog): def __init__(self, parent): title = "Resize the dialog and see how controls adapt!" wxDialog.__init__(self, parent, -1, title, style=wxRESIZE_BORDER) |
class MyTabbedDlg(wx.Dialog): def __init__(self, parent): title = "Resize the dialog and see how controls adapt!" wx.Dialog.__init__(self, parent, -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) notebook = wx.Notebook(self, -1, size=(450,300)) panel1 = wx.Panel(notebook) panel2 = wx.Panel(notebook) notebook.AddPage(panel1, "Panel 1") notebook.AddPage(panel2, "Panel 2") dialog_sizer = wx.BoxSizer(wx.VERTICAL) dialog_sizer.Add(notebook, 1, wx.EXPAND|wx.ALL, 5) panel1_sizer = wx.BoxSizer(wx.VERTICAL) text = wx.TextCtrl(panel1, -1, "Hi!", size=(400,90), style=wx.TE_MULTILINE) button1 = wx.Button(panel1, -1, "I only resize horizontally...") panel1_sizer.Add(text, 1, wx.EXPAND|wx.ALL, 10) panel1_sizer.Add(button1, 0, wx.EXPAND|wx.ALL, 10) panel1.SetSizer(panel1_sizer) panel2_sizer = wx.BoxSizer(wx.HORIZONTAL) button2 = wx.Button(panel2, -1, "I resize vertically") button3 = wx.Button(panel2, -1, "I don't like resizing!") panel2_sizer.Add(button2, 0, wx.EXPAND|wx.ALL, 20) panel2_sizer.Add(button3, 0, wx.ALL, 100) panel2.SetSizer(panel2_sizer) self.SetSizerAndFit(dialog_sizer) self.Centre() self.Bind(wx.EVT_BUTTON, self.OnButton) def OnButton(self, evt): self.EndModal(0) |
Line 26: | Line 59: |
notebook = wxNotebook(self, -1, size=(450,300)) panel1 = wxPanel(notebook, -1, style = wxNO_BORDER) panel2 = wxPanel(notebook, -1, style = wxNO_BORDER) notebook.AddPage(panel1, "Panel 1") notebook.AddPage(panel2, "Panel 2") dialog_sizer = wxBoxSizer(wxVERTICAL) dialog_sizer.Add(notebook, 1, wxEXPAND|wxALL, 5) panel1_sizer = wxBoxSizer(wxVERTICAL) text = wxTextCtrl(panel1, -1, "Hi!", size=(400,90), style=wxTE_MULTILINE) button1 = wxButton(panel1, -1, "I only resize horizontally...") panel1_sizer.Add(text, 1, wxEXPAND|wxALL, 10) panel1_sizer.Add(button1, 0, wxEXPAND|wxALL, 10) panel1.SetSizer(panel1_sizer) panel1.SetAutoLayout(true) panel2_sizer = wxBoxSizer(wxHORIZONTAL) button2 = wxButton(panel2, -1, "I resize vertically") button3 = wxButton(panel2, -1, "I don't like resizing!") panel2_sizer.Add(button2, 0, wxEXPAND|wxALL, 20) panel2_sizer.Add(button3, 0, wxALL, 100) panel2.SetSizer(panel2_sizer) panel2.SetAutoLayout(true) self.SetSizer(dialog_sizer) self.SetAutoLayout(true) self.Fit() self.Centre() |
|
Line 57: | Line 61: |
class MyApp(wxApp): def OnInit(self): frame = wxFrame(NULL, -1, 'Tabbed/wxNotebook Dialog with resizable controls') frame.Show(true) dlg = MyTabbedDlg(frame) dlg.ShowModal() dlg.Destroy() frame.Close() return true myapp = MyApp(0) |
class MyApp(wx.App): def OnInit(self): dlg = MyTabbedDlg(None) dlg.ShowModal() dlg.Destroy() return True myapp = MyApp(redirect=False) |
Introduction
This is an example of using a Tabbed (wxNotebook) Dialog with resizable controls. BR (It took me more than 2 days to realize I had to use wxPanel instead of wxWindows controls) BRBR Hope it helps someone... BR -- jbalague BRBR See also: UsingSizers BR
Code Sample
1 import wx
2
3 #----------------------------------------------------------------------
4 class MyTabbedDlg(wx.Dialog):
5 def __init__(self, parent):
6 title = "Resize the dialog and see how controls adapt!"
7 wx.Dialog.__init__(self, parent, -1, title,
8 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
9
10 notebook = wx.Notebook(self, -1, size=(450,300))
11 panel1 = wx.Panel(notebook)
12 panel2 = wx.Panel(notebook)
13 notebook.AddPage(panel1, "Panel 1")
14 notebook.AddPage(panel2, "Panel 2")
15
16 dialog_sizer = wx.BoxSizer(wx.VERTICAL)
17 dialog_sizer.Add(notebook, 1, wx.EXPAND|wx.ALL, 5)
18
19 panel1_sizer = wx.BoxSizer(wx.VERTICAL)
20 text = wx.TextCtrl(panel1, -1, "Hi!", size=(400,90), style=wx.TE_MULTILINE)
21 button1 = wx.Button(panel1, -1, "I only resize horizontally...")
22 panel1_sizer.Add(text, 1, wx.EXPAND|wx.ALL, 10)
23 panel1_sizer.Add(button1, 0, wx.EXPAND|wx.ALL, 10)
24 panel1.SetSizer(panel1_sizer)
25
26 panel2_sizer = wx.BoxSizer(wx.HORIZONTAL)
27 button2 = wx.Button(panel2, -1, "I resize vertically")
28 button3 = wx.Button(panel2, -1, "I don't like resizing!")
29 panel2_sizer.Add(button2, 0, wx.EXPAND|wx.ALL, 20)
30 panel2_sizer.Add(button3, 0, wx.ALL, 100)
31 panel2.SetSizer(panel2_sizer)
32
33 self.SetSizerAndFit(dialog_sizer)
34 self.Centre()
35
36 self.Bind(wx.EVT_BUTTON, self.OnButton)
37
38
39 def OnButton(self, evt):
40 self.EndModal(0)
41
42
43 #----------------------------------------------------------------------
44 class MyApp(wx.App):
45 def OnInit(self):
46 dlg = MyTabbedDlg(None)
47 dlg.ShowModal()
48 dlg.Destroy()
49 return True
50
51 myapp = MyApp(redirect=False)
52 myapp.MainLoop()
Comments
I like the example, but it would be better if it were possible to get it to stop running. Since the dialog appears to have no way to quit, and it's modal, the controlling application can't be terminated. Or is this only a problem on Windows?
It works better if the dialog style is set to wxRESIZE_BORDER+wxDEFAULT_DIALOG_STYLE, then the dialog can be closed in a controlled way. SteveHolden
This example crashes with a Bus error (core dump) on MacOSX 10.3, wxPython 2.5.3.1. It only works if you add the wxDEFAULT_DIALOG_STYLE as mentioned above. Here is the trace...maybe some smart individual will see this and fix the source code to window.cpp...
0 libwx_macu-2.5.3.dylib 0x027b4ec4 wxWindow::MacSetBackgroundBrush(wxBrush const&) + 0x40 1 libwx_macu-2.5.3.dylib 0x027b4e2c wxWindow::SetBackgroundColour(wxColour const&) + 0x128 2 libwx_macu-2.5.3.dylib 0x027b126c wxTopLevelWindowMac::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) + 0xdc 3 libwx_macu-2.5.3.dylib 0x027865f4 wxDialog::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) + 0x6c 4 _windows_.so 0x02e0c590 _wrap_new_Dialog + 0x480 (dialog.h:57)
In addition, the demo has all sorts of refresh/paint issues once you get it running. Especially when you click on Panel 2.