sizer aligning is wrong on Linux

Hi,

import wx

class Absolute(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 180))

        label = wx.StaticText(self, wx.ID_ANY, "emission" )
        txt = wx.TextCtrl(self, wx.ID_ANY, "" )

        hsizer = wx.BoxSizer(wx.HORIZONTAL)

        hsizer.Add(label, 0,
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 10)
        hsizer.SetItemMinSize(label, (100,-1))
        hsizer.Add(txt, 0, wx.ALIGN_CENTER_VERTICAL)

        self.SetSizer( hsizer )
        hsizer.Fit( self )

        self.Centre()
        self.Show(True)

app = wx.App(0)
Absolute(None, -1, '')
app.MainLoop()

The text "emission" should be aligned at right with margin of 10 but it's not.
On windows it's fine. Instead of RIGHT if I use LEFT the results are
as expected.

Prashant

#---- System Information ----#
GUI2Exe Version: 0.5.0
Operating System: Linux 2.6.31-14-generic i686
Python Version: 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11)
[GCC 4.4.1]
wxPython Version: 2.8.10.1 (gtk2-unicode)
wxPython Info: (__WXGTK__, wxGTK, unicode, gtk2, wx-assertions-off,
SWIG-1.3.29)
Python Encoding: Default=UTF-8 File=UTF-8
wxPython Encoding: utf-8
System Architecture: 32bit i686
Byte order: little
Frozen: False
#---- End System Information ----#

snapshot1.png

Hi James,

Why to use wx.All? I need label aligned to right with a margin of 10
unit and I think syntax is correct:

hsizer.Add(label, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT,
10).

Could you please attach a screen shot of what you are getting on you
machine?

Prashant

This is a case of it doing exactly what you are telling it to do, and if you had used the Widget Inspection Tool you probably would have seen it yourself.

         hsizer.SetItemMinSize(label, (100,-1))

This sets the minimum width of the label widget (not the space allocated to it, but the widget itself) to 100 pixels.

         hsizer.Add(label, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 10)

This tells the sizer to align the widget (the whole thing, not just the visible text) to the right side of the space that the sizer would have allocated to the widget, leaving room for 10 empty pixels.

So that is exactly what is happening, the sizer is making the label be 100 pixels wide, and putting it in a space that is 110 pixels wide, and since there needs to be empty 10 pixels on the border the label is positioned at position 0.

Now if you would like the text to be right aligned within the 100 pixel width of the StaticText widget, then you'll need to tell the widget to do that, not the sizer.

         label = wx.StaticText(self, wx.ID_ANY, "emission",
                               style=wx.ALIGN_RIGHT)

···

On 2/10/10 12:15 AM, Prashant Saxena wrote:

Hi,

import wx

class Absolute(wx.Frame):
     def __init__(self, parent, id, title):
         wx.Frame.__init__(self, parent, id, title, size=(250, 180))

         label = wx.StaticText(self, wx.ID_ANY, "emission" )
         txt = wx.TextCtrl(self, wx.ID_ANY, "" )

         hsizer = wx.BoxSizer(wx.HORIZONTAL)

         hsizer.Add(label, 0,
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 10)
         hsizer.SetItemMinSize(label, (100,-1))
         hsizer.Add(txt, 0, wx.ALIGN_CENTER_VERTICAL)

         self.SetSizer( hsizer )
         hsizer.Fit( self )

         self.Centre()
         self.Show(True)

app = wx.App(0)
Absolute(None, -1, '')
app.MainLoop()

The text "emission" should be aligned at right with margin of 10 but it's not.
On windows it's fine. Instead of RIGHT if I use LEFT the results are
as expected.

--
Robin Dunn
Software Craftsman

What I need is something like this:

"""
        emission |
emissionemission |
"""
and the code:

import wx

class Absolute(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title,
size=wx.DefaultSize)

        label1 = wx.StaticText(self, wx.ID_ANY, "emission",
style=wx.ALIGN_RIGHT)
        txt1 = wx.TextCtrl(self, wx.ID_ANY, "" )

        label2 = wx.StaticText(self, wx.ID_ANY, "emissionemission",
style=wx.ALIGN_RIGHT)
        txt2 = wx.TextCtrl(self, wx.ID_ANY, "" )

        # main sizer
        vsizer = wx.BoxSizer(wx.VERTICAL)

        hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer1.Add(label1, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|
wx.RIGHT, 10)
        hsizer1.Add(txt1, 1, wx.ALIGN_CENTER_VERTICAL)

        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer2.Add(label2, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|
wx.RIGHT, 10)
        hsizer2.Add(txt2, 1, wx.ALIGN_CENTER_VERTICAL)

        vsizer.Add(hsizer1, 0)
        vsizer.Add(hsizer2, 0)

        self.SetSizer( vsizer )
        vsizer.Fit( self )

        self.Centre()
        self.Show(True)

app = wx.App(0)
Absolute(None, -1, 'ALIGN_RIGHT')
app.MainLoop()

Now how do I achieve this? The above code is working fine on MS-Win
and giving me desired output.

Prashant

What I need is something like this:

"""
         emission |
emissionemission |
"""

Now how do I achieve this?

Use a wx.FlexGridSizer. See attached.

The above code is working fine on MS-Win
and giving me desired output.

That's highly doubtful, unless I am totally misunderstanding what you are asking for.

align2.py (1000 Bytes)

···

On 2/10/10 10:36 PM, King wrote:

--
Robin Dunn
Software Craftsman