简体   繁体   中英

wxPython and StaticBox(Sizer) issue

Recently I've been having an issue with the code shown below and it's been bugging me for a while now. I don't know why it's happening, the only thing I know is that the python code brings up a segfault on the line noted and gdb brings up something about memory. Am I doing something wrong or is this a bug? I'd really like to get this working, so if you can help I'd greatly appreciate it.

C++ code:

static int win_width = 364;
static int win_height = 478;

netlist = new wxDialog(NULL, wxID_ANY, "Network List", wxDefaultPosition, wxSize(win_width-8, win_height-8), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);

wxBoxSizer *hszr = new wxBoxSizer(wxHORIZONTAL),
  *vszr = new wxBoxSizer(wxVERTICAL), *vszr2 = new wxBoxSizer(wxVERTICAL);

wxStaticBoxSizer* sszr = new wxStaticBoxSizer(wxVERTICAL, netlist, "User Information");
wxFlexGridSizer* fgszr = new wxFlexGridSizer(2);

fgszr->Add(new wxStaticText(sszr->GetStaticBox(), wxID_ANY, "Nick Name: "));

Python code:

win_width = 364
win_height = 478

netlist = wx.Dialog(None, wx.ID_ANY, "Network List", wx.DefaultPosition, wx.Size(win_width-8, win_height-8), wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)

hszr = wx.BoxSizer(wx.HORIZONTAL)
vszr = wx.BoxSizer(wx.VERTICAL)
vszr2 = wx.BoxSizer(wx.VERTICAL)

sszr = wx.StaticBoxSizer(wx.StaticBox(netlist, wx.ID_ANY, "User Information"), orient=wx.VERTICAL)
fgszr = wx.FlexGridSizer(2)

fgszr.Add(wx.StaticText(sszr.GetStaticBox(), wx.ID_ANY, "Nick Name: ")) # Segmentation Fault

On the python side, the Add method has the following arguments:

Add(self, item, int proportion=0, int flag=0, int border=0, userData=None)

proportion is not an id (but that silently passes because they are both integers) and flag is not a string.

Compared to the C++ version a working line would be:

fgszr.Add(wx.StaticText(sszr.GetStaticBox(), wx.ID_ANY, "Nick Name: "))

UPDATE:

The following code successfully executed on windows using wxPython 2.9.1.1

import wx

app = wx.PySimpleApp()

win_width = 364
win_height = 478

netlist = wx.Dialog(None, wx.ID_ANY, "Network List", wx.DefaultPosition, wx.Size(win_width-8, win_height-8), wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)

hszr = wx.BoxSizer(wx.HORIZONTAL)
vszr = wx.BoxSizer(wx.VERTICAL)
vszr2 = wx.BoxSizer(wx.VERTICAL)

sszr = wx.StaticBoxSizer(wx.StaticBox(netlist, wx.ID_ANY, "User Information"), orient=wx.VERTICAL)
fgszr = wx.FlexGridSizer(2)

fgszr.Add(wx.StaticText(sszr.GetStaticBox(), wx.ID_ANY, "Nick Name: ")) # Segmentation Fault

netlist.ShowModal()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM