I tried to create a simple window, with wxGlade as a help.
Unfortunately, the window is too small and does not fit its contents.
This is a screenshot from wxGlade to demonstrate my structure.
As you can see, the fields are cropped at the right side and the buttom at the bottom is not fully visible.
How can I make the window large enough to automatically fit my fields?
I am unfortunately not allowed to upload files, since I am a new user.
Here is a pastebin with the contents of the wxg file instead: https://pastebin.com/UPxCNaSq
But shouldn’t the minimum size be at least large enough to contain all elements?
OK, the 400x300 is the default size for a frame.
As noted yesterday in the other thread, for this constellation, no sizer.Fit() code is generated. I will check whether I can add this.
Temporarily you may add this to the frame:
This will add the Fit code:
But, most of the time, frames are not used with Fit(), only dialogs are fitted to the minimum size.
For frames, it’s common to set a size that is larger and make the sizers and elements grow to fill the available space.
Your frame does not seem to be the “main” window. The main frame will certainly display e.g. a list of swimmers and an “Add swimmer” button or menu item which will then show the “Add swimmer” dialog.
A frame is intended to be resized as much as the user wants. The bigger, the more data it can display.
For the sizer in the dialog etc. have a look at the wxGlade manual, section “Dialogs”. When you add a dialog to wxGlade it will generate the most important structures already.
General about sizers: always use the simplest available. Throwing everything at a GridBagSize does not generate a good structure / design and code. The ‘button_1’ should not be part of the grid sizer.
Oh I see.
In this case, the frame was actually intended to not display anything else, so no other main window, since I just wanted to enter one swimmers after the other. (And because I wanted to take small steps )
(How did you manage to make the text boxes in the first two rows span multiple slots with a gridSizer? Isn’t this just possible with a gridbagsizer?)
Nevermind, I guess this is a gridBagSizer based on the screenshot you posted.
Yes, the text boxes were fine in your example, but the action button should not be placed in the gridbag sizer.
It might actually even look better and/or easier to edit if you had taken just a two-column flexgrid sizer with a growable second column. The “Zeit” row would then contain a horizontal box sizer with three boxes. The “Zeit” and “Jahrgang” controls need not grow, so there’s no advantage in placing everything in a many-column grid to align and then span grid cells where the inputs need to grow.
Always use the simplest sizers that do the job. Hierarchies of (simple) sizers are fine and are actually easier to handle once your GUI gets more complex and you want to tune your layout using Proportions and EXPAND.
Especially re-designs are much easier with a reasonable hierarchy than with everything in a grid.
Once you add more fields to your database, it makes sense to group inputs into static box sizers. One box sizer for “Personal data”, one for “Performance” etc.
I did as you suggested and using multiple simple sizers is way more convenient and simple.
Unfortunaltely there seems to be an issue with the generated code from wxGlade.
I tried opening the model with this simple call:
dial = addSwimmerDialog()
dial.ShowModal(self)
but it raises this error:
wx.Dialog.__init__(self, *args, **kwds)
TypeError: Dialog(): arguments did not match any overloaded call:
overload 1: 'style' is not a valid keyword argument
overload 2: 'style' is not a valid keyword argument
Well, actually EVT_CHAR_HOOK might be your best option as these events are propagating. I.e. you can bind the handler for the dialog or frame. EVT_CHAR is only delivered to the active widget.
It looks like you’ve already moved on to using a wx.Dialog, but for the record I’d like to add that a good way to use Fit with a frame is to also give the frame a sizer with just the top-level panel (panel_1) in it, and then call the frame’s Fit not the sizer’s Fit. Something like this:
@DietmarSchwertberger one more question about wxglade, if you don’t mind.
What is the intended way to maintain code to be able to add elements later? As far as I see, the “generate output” function overwrites the file and all changes I made to it.
Well, there are several options.
You can check “Keep user code”. This way, code outside of the begin/end wxglade markers will be kept. That’s not very robust when you rename elements, though.
For small programs and glue code that’s fine.
For larger projects, derive from the wxGlade generated code and implement your functionality there.
With revision 1.0 there is also an optional “Instance class” property. This allows that the application imports your derived code. I need to add this to the documentation.
So, you did not work through the documentation
You may also look at the supplied examples matplotlib vs. matplotlib2. The matplotlib2 example is much cleaner and easier to maintain in the long run.
P.S.: The “Instance Class” property is very flexible. It allows to use user specific widgets.
E.g. if you have a TextCtrl in your wxGlade project, you can enter “mycontrols.UpperCaseTextCtrl” to use a compatible class with your specific behaviour.
I’m using this a lot for measurement and control programs where I allow to enter values including units (e.g. “1mA” instead of “0.001A”).