Re: How to access wxglade generated widgets from generic python code.
Dietmar Schwertberger <[email protected]>
| Newsgroups | gmane.comp.python.wxglade |
|---|---|
| Message-ID | <[email protected]> |
On 09.04.2019 01:35, Dennis DeBerry via wxGlade-general wrote: > Here is the error that I am getting: > > Traceback (most recent call last): > File "c:\Users\<My Name>\Desktop\My Projects\Sqlite > Docs\testdataentry6b.py", line 158, in OpenFile > create_connection(filename) > File "c:\Users\<My Name>\Desktop\My Projects\Sqlite > Docs\testdataentry6b.py", line 36, in create_connection > list1 = TableList(None,wx.ID_ANY,choices = tablenames) > File "c:\Users\<My Name>\Desktop\My Projects\Sqlite > Docs\testdataentry6b.py", line 278, in __init__ > wx.ListBox.__init__(self,parent,id) > File > "C:\Python27\lib\site-packages\wx-2.8-msw-ansi\wx\_controls.py", line > 1290, in __init__ > _controls_.ListBox_swiginit(self,_controls_.new_ListBox(*args, **kwargs)) > wx._core.PyAssertionError: C++ assertion "parent" failed at > ..\..\src\common\ctrlcmn.cpp(79) in wxControlBase::CreateControl(): > all controls must have parents You're using wxGlade to generate a class TableList(wx.ListBox) and then you call this with parent=None. This can't work. Why are you doing so? Things are much easier if you just leave the Class property of listtables at the default value wxListBox, instantiate the dialog, set the ListBox to the required values, show the dialog and finally read back the selection. The generated code would look like this (note the wx.ListBox instead of TableList): class TableChoice(wx.Dialog): def __init__(self, *args, **kwds): ..... self.listtables = wx.ListBox(self.panel_3, wx.ID_ANY, choices=[""], style=wx.LB_NEEDED_SB | wx.LB_SINGLE | wx.LB_SORT) Usage would be like this: dlg = TableChoice(parent) dlg.listtables.SetItems(....) dlg.ShowModal() table = dlg.listtables.GetSelection() You could probably use Code -> ExtraProperties for listtables to make your TableChoice dialog accept the choices. E.g. something like Property: Items Value: kwds["tables"] Then you could use this to instantiate the dialog: dlg = TableChoice(tables=["table1","table2"]) As Brendan pointed out, it's not a good idea to place all the user code into the wxGlade generated Python files. E.g. your create_connection() function should definitely not be there. Placing code in the file is fine for prototypes, but once things get more complicated, it's better to have a proper structure. > Here is a link to the wxg file > https://drive.google.com/open?id=1rH5BFxhmk_bFQCO5ImWv6DSo8-jQbRjT It's always easier to follow if you attach the files here to the message and in the message only quote the relevant parts. Regards, Dietmar _______________________________________________ wxGlade-general mailing list wxGlade-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/wxglade-general