views:

53

answers:

1

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
A: 

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()
Toni Ruža
Thanks for replying! I apologize, What you mentioned above was originally part of the code and is what gives off the segfault. The code has been updated, but the problem still exists.
dbdii407
I tested the code before replying, worked just fine. I was using wxPython 2.9.1.1 on windows. Try using wxFormBuilder to design your form and see if the code that it generates works.
Toni Ruža
I will try that, looks like a good app! Sadly, I won't be able to start for another 4.5 hours. Until then, is it possible to post the file you used to test? You mentioned you were using windows, while I'm on Arch Linux. Don't know if that means any different.
dbdii407
The difference is in the underlying gui library. While it is possible you have stumbled on to some wxGTK bug it is unlikely, the use case you have presented here is too common.
Toni Ruža
Sadly, it's still segfaulting and I can't install the version you have because python is giving me an error. This is gonna be a while...
dbdii407