Re: How to dynamically create and populate widgets in wxglade created code.

Dennis DeBerry via wxGlade-general <wxglade-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Newsgroups gmane.comp.python.wxglade
Message-ID <[email protected]>
 Thank you for your very quick reply. I was not expecting a reply for at least 3 day More likely a week. 
In any case I am not really set upon using a radiobutton or a radiobox. Those to just seemed the most logical to me since the only allow the user to select ONE of  multiple choices. Checkboxes allow the user to select multiple choices which I do not want.. The table query will return a list of tuples. With each element being a string with the name of the table. The user should only be able to select on table to add records to. The grid in the main window will then query that table for the field names and create a one cell grid with no column headers but with the row headers replaced but the field names. I know how to turn off the column headers of a grid and how to loop thru the row headers and change the names of the row. 
I guess really my question boils down to how to use wxglade to make ONE radiobutton( if I will stay with that for the table choice. I am looking at the documentation for a wx.ListCtrl and that looks like it might be a better option) but then let me adjust the number of radiobuttons at the time the program is run. In the grid situation how to use wxglade to create just a one cell grid that can then be expanded from my own code at run time.
I have seen the extra code sections on in wxglade but for some widgets wx glade will actually write code before or after the widget and for some widgets even though I type in code in that box in the interface it is not generated when glade generates the python code. ????
I hope this makes thing clearer in what I am trying to do.
Thanks AGAIN.

    On Monday, March 11, 2019, 10:35:18 AM PDT, Dietmar Schwertberger <[email protected]> wrote:  
 
  On 11.03.2019 00:21, Dennis DeBerry via wxGlade-general wrote:
  
 
What I want to do is to create a series of radiobuttons whose lables are the table names. Then after accessing that table create a wx.grid where the row names are replaced by the field names and each cell next to those row names are where the user enters the data that will be written to that table 
The easiest solution would be to use a wx.Choice. A Choice control is ready to be updated with new values and actually it's more what I would expect as user.
 
 
Radio buttons are a rather unusual solution. If you want to stick to it, you need to remove and add them dynamically.
 
Anyway, you should not try to do that in the constructor of your dialog.
 
 
To be able to access the sizer, you need to check the box "Store as attribute".
 Then you can access it as e.g. dlg.grid_sizer1 and add a sizer using e.g. dlg.grid_sizer1.Add().
 
 
Just instantiate the dialog, add/remove the radio buttons to match the required number. You can update a button's label using SetLabel. When done, show your dialog.
 The link you have posted, shows how to add/remove controls to/from a sizer.
 
How to add, you can also see from the auto-generated code: 

     grid_sizer_1.Add(self.radio_btn_1, 0, 0, 0) 
Also, wxGlade internally does this when you add a RadioBox (as a RadioBox can't be updated later on, wxGlade uses a static box plus RadioButtons to simulate it).
 Seehttps://github.com/wxGlade/wxGlade/blob/master/widgets/radio_box/radio_box.py
 The methods are _set_choices and _create_button.
 

 
 
For more information about removing, you can look at the sizer documentation.
https://wxpython.org/Phoenix/docs/html/wx.Sizer.html?highlight=sizer
 
Look at the methods Detach, Remove, Add.
 
 
 
You could also use a Radiobox. On update you would need to remove the box from the sizer, destroy it, re-create it with the new values, add it to the sizer again.
 

 
 
wx.grid has all kinds of methods to set rows, columns and the contents. Just have a look at the documentation or the demo.
 
 

 
 
Also, please always use the simplest sizer that does the job. In your case, I would suggest to use a box sizer or a static box sizer instead of a grid sizer.
 
Regards,
 
Dietmar
 

 
 _______________________________________________
wxGlade-general mailing list
wxGlade-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/wxglade-general

_______________________________________________
wxGlade-general mailing list
wxGlade-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/wxglade-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.