When resizing (e.g. making bigger) a window with the mouse I want the
controls inside wx.EXPAND only horizontal but not verticaly.
I don't know how to do this.
I created a minimal example for that.
I want MyCtrl expanding from left to right but not from top to bottom.
But currently it is expanded verticaly but not horizontaly. Very
confusing.
I am using Python3.4 with wxPhoenix '3.0.3.dev1684+6933551 gtk2
(phoenix)'.
[code]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import wx
class MyCtrl(wx.Control):
def __init__(self, parent):
super(MyCtrl, self).__init__(parent)
sz = wx.BoxSizer(wx.HORIZONTAL)
sz.Add(wx.TextCtrl(self), wx.EXPAND)
sz.Add(wx.TextCtrl(self), wx.EXPAND)
self.SetSizer(sz)
class MyDialog(wx.Dialog):
def __init__(self, parent):
super(MyDialog, self).__init__(parent,
style=wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE) sz =
wx.BoxSizer(wx.VERTICAL) sz.Add(MyCtrl(self), wx.EXPAND)
sz.Add(MyCtrl(self), wx.EXPAND)
sz.Add(MyCtrl(self), wx.EXPAND)
self.SetSizer(sz)
if __name__ == '__main__':
app = wx.App()
dlg = MyDialog(None)
dlg.ShowModal()
app.MainLoop()
[/code]
I think what you want is:
sz.Add(MyCtrl(self), proportion=1)
As an alternative way to deal with sizers you might want to look at wx.lib.sized_controls (http://wxpython.org/Phoenix/docs/html/lib.sized_controls.html#module-lib.sized_controls), see below.
Note that I also used the WIT (http://wiki.wxpython.org/Widget%20Inspection%20Tool|\), which is very useful in debugging sizer issues and use 'with' to ensure that the dialog is destroyed.
[code]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import wx
import wx.lib.sized_controls as sc
class MyCtrl(sc.SizedPanel):
def __init__(self, parent):
super(MyCtrl, self).__init__(parent)
self.SetSizerType('horizontal')
self.SetSizerProp('expand', True)
tc1 = wx.TextCtrl(self)
tc2 = wx.TextCtrl(self)
tc2.SetSizerProp('proportion', 1)
class MyDialog(sc.SizedDialog):
def __init__(self, parent):
super(MyDialog, self).__init__(parent,
style=wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE)
pane = self.GetContentsPane()
pane.SetSizerProp('expand', True)
MyCtrl(pane)
if __name__ == '__main__':
import wx.lib.mixins.inspection as WIT
app = WIT.InspectableApp()
with MyDialog(None) as dlg:
dlg.ShowModal()
app.MainLoop()
[/code]
···
On 4/1/2015 4:55, c.buhtz@posteo.jp wrote:
When resizing (e.g. making bigger) a window with the mouse I want the
controls inside wx.EXPAND only horizontal but not verticaly.
I don't know how to do this.
I created a minimal example for that.
I want MyCtrl expanding from left to right but not from top to bottom.
But currently it is expanded verticaly but not horizontaly. Very
confusing.
As an alternative way to deal with sizers you might want to look at
wx.lib.sized_controls
(http://wxpython.org/Phoenix/docs/html/lib.sized_controls.html#module-lib.sized_controls),
see below.
Outch. Looks to complex and again not well documented (because of the
sphinx-use-autogenerated-around-c-wrapped-py-code-problem).
Note that I also used the WIT
(http://wiki.wxpython.org/Widget%20Inspection%20Tool|\), which is very
useful in debugging sizer issues and use 'with' to ensure that the
dialog is destroyed.
Looks great. But I still have problems to get it work.
class MyCtrl(sc.SizedPanel):
It is a control, not a panel. I think all the sc-stuff is to much for a
simple task.
if __name__ == '__main__':
import wx.lib.mixins.inspection as WIT
app = WIT.InspectableApp()
with MyDialog(None) as dlg:
dlg.ShowModal()
app.MainLoop()
The dialog comes up but the inspector window doesn't.
I checked the wiki page about it and the example. But the code there
doesn't fit to my wx.Dialog.ShowModal() use case. It work only for
simple frames.
···
On 2015-04-01 09:46 Werner <wernerfbd@gmx.ch> wrote:
As an alternative way to deal with sizers you might want to look at
wx.lib.sized_controls
(http://wxpython.org/Phoenix/docs/html/lib.sized_controls.html#module-lib.sized_controls),
see below.
Outch. Looks to complex and again not well documented (because of the
sphinx-use-autogenerated-around-c-wrapped-py-code-problem).
I do all my stuff using it, so I am a bit biased.
Note that I also used the WIT
(http://wiki.wxpython.org/Widget%20Inspection%20Tool|\), which is very
useful in debugging sizer issues and use 'with' to ensure that the
dialog is destroyed.
Looks great. But I still have problems to get it work.
class MyCtrl(sc.SizedPanel):
It is a control, not a panel. I think all the sc-stuff is to much for a
simple task.
Why not use a Panel as the container for the two controls?
if __name__ == '__main__':
import wx.lib.mixins.inspection as WIT
app = WIT.InspectableApp()
with MyDialog(None) as dlg:
dlg.ShowModal()
app.MainLoop()
The dialog comes up but the inspector window doesn't.
You need to press ctrl-alt-i to see the inspector, you can make it show automatically but I don't like it to get in my way when I don't need it.
I checked the wiki page about it and the example. But the code there
doesn't fit to my wx.Dialog.ShowModal() use case. It work only for
simple frames.
Not sure what you mean it only works for simple frames. I use it in my app which uses wx.lib.agw.aui, on dialogs and on frames.
Werner
P.S.
I think it still has issues in Phoenix with some things.
···
On 4/1/2015 19:18, c.buhtz@posteo.jp wrote:
On 2015-04-01 09:46 Werner <wernerfbd@gmx.ch> wrote:
You answered your question with the question itself. See your word
"controls"? It is a control so I derive from wx.Control.
But thinking deeper about it brings me to the question: What the hack
is the diff between wx.Contro, wx.Panel, wx.Frame, etc?
Which one should I use to create a control? (diss)advantages?
···
On 2015-04-01 19:37 Werner <wernerfbd@gmx.ch> wrote:
Why not use a Panel as the container for the two controls?
Hi,
Keep in mind that I am a hobby programmer and probably don't always do things by the book.
Why not use a Panel as the container for the two controls?
You answered your question with the question itself. See your word
"controls"? It is a control so I derive from wx.Control.
But thinking deeper about it brings me to the question: What the hack
is the diff between wx.Contro, wx.Panel, wx.Frame, etc?
Which one should I use to create a control? (diss)advantages?
I would do what is easiest to get to the result I want.
- for a control I would probably use wx.Control as base
- for a combined control (e.g. a StaticText and TextCtrl or two TextCtrl's) I would use a panel and put the two controls onto it, especially true if I want to use sized_controls (which automatically give me default HIG per platform)
- a wx.Frame or wx.Dialog is for top level type windows, I don't think I would them for a 'control' as it would prevent you from re-using it in e.g. another Panel.
Maybe look at the intro of these in the Phoenix doc:
http://wxpython.org/Phoenix/docs/html/Control.html
http://wxpython.org/Phoenix/docs/html/Window.html
http://wxpython.org/Phoenix/docs/html/Panel.html
http://wxpython.org/Phoenix/docs/html/Frame.html
http://wxpython.org/Phoenix/docs/html/Dialog.html
Werner
···
On 4/3/2015 16:04, c.buhtz@posteo.jp wrote:
On 2015-04-01 19:37 Werner <wernerfbd@gmx.ch> wrote: