I am using a wxGenToggleButton so I can have the button drawn invisibly (using BORDER_NONE). I use this to create text that looks like a StaticText, but can be clicked to toggle a darker background color. The problem is I would like to have the buttons use wx.EXPAND, so they are all the same size in the column, but still have the text remain left-justified. I have looked through the class hierarchy and I cannot find any style flags to specify this behavior. Does anyone know how I can achieve this?
isn’t wx.EXPAND a property of the Sizer, not the widget you add to a Sizer? Adding the buttons to a VERTICAL Sizer, with the ALIGN and EXPAND options doesn’t work?
···
On Monday, July 28, 2014 7:48:27 AM UTC-7, Aaron Hill wrote:
I am using a wxGenToggleButton so I can have the button drawn invisibly (using BORDER_NONE). I use this to create text that looks like a StaticText, but can be clicked to toggle a darker background color. The problem is I would like to have the buttons use wx.EXPAND, so they are all the same size in the column, but still have the text remain left-justified. I have looked through the class hierarchy and I cannot find any style flags to specify this behavior. Does anyone know how I can achieve this?
If that is the effect you want, you can just use a StaticText and bind the
mouse event to it (like wx.EVT_LEFT_UP).
From a user experience perspective, though, it is not at all conventional
to click on static text in order to request some action; static text is
generally used to report information. Maybe there is a way to make it
clear, though, in your case.
Che
···
On Mon, Jul 28, 2014 at 10:48 AM, Aaron Hill <aaron.hill@optelian.com> wrote:
I am using a wxGenToggleButton so I can have the button drawn invisibly
(using BORDER_NONE). I use this to create text that looks like a
StaticText, but can be clicked to toggle a darker background color.
Yes, EXPAND will have it fill the cell in the sizer, which is what I want. However, this has the unwanted side effect of centering the text within the button. The button itself has no flags for aligning text. The results are shown in the image. The one labelled ‘Actual’ is what actually happens when I use the EXPAND flag.
···
On Monday, 28 July 2014 11:10:54 UTC-4, Nathan McCorkle wrote:
isn’t wx.EXPAND a property of the Sizer, not the widget you add to a Sizer? Adding the buttons to a VERTICAL Sizer, with the ALIGN and EXPAND options doesn’t work?
On Monday, July 28, 2014 7:48:27 AM UTC-7, Aaron Hill wrote:
I am using a wxGenToggleButton so I can have the button drawn invisibly (using BORDER_NONE). I use this to create text that looks like a StaticText, but can be clicked to toggle a darker background color. The problem is I would like to have the buttons use wx.EXPAND, so they are all the same size in the column, but still have the text remain left-justified. I have looked through the class hierarchy and I cannot find any style flags to specify this behavior. Does anyone know how I can achieve this?
Hello Aaron,
add the style=wx.BU_LEFT to your ToggleButton. I think that will do what you want.
···
–
Torsten
This style is only available for regular buttons, it doesn’t have any effect on GenToggleButtons.
···
On Monday, 28 July 2014 11:54:40 UTC-4, Torsten wrote:
Hello Aaron,
add the style=wx.BU_LEFT to your ToggleButton. I think that will do what you want.
–
Torsten
Can you post a demo?
···
On Monday, July 28, 2014 9:46:05 AM UTC-7, Aaron Hill wrote:
This style is only available for regular buttons, it doesn’t have any effect on GenToggleButtons.
On Monday, 28 July 2014 11:54:40 UTC-4, Torsten wrote:
Hello Aaron,
add the style=wx.BU_LEFT to your ToggleButton. I think that will do what you want.
–
Torsten
I do not have time at the moment to create a sample app, but if you guys agree that there is no way to left-justify a label on a GenToggleButton, I will try the method with the StaticText and mouse click event.
I can try to put together a sample app later if it is still needed.
This style is only available for regular buttons, it doesn’t have any effect on GenToggleButtons.
Hello Aaron,
add the style=wx.BU_LEFT to your ToggleButton. I think that will do what you want.
–
Torsten
Ok, i see. But you could replace the DrawLabel method of GenToggleButton with this one:
buttons.py (21 KB)
test5.py (682 Bytes)
···
Am Montag, 28. Juli 2014 18:46:05 UTC+2 schrieb Aaron Hill:
On Monday, 28 July 2014 11:54:40 UTC-4, Torsten wrote:
def DrawLabel(self, dc, width, height, dx=0, dy=0):
dc.SetFont(self.GetFont())
if self.IsEnabled():
dc.SetTextForeground(self.GetForegroundColour())
else:
dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
label = self.GetLabel()
tw, th = dc.GetTextExtent(label)
if not self.up:
dx = dy = self.labelDelta
posx = (width-tw)/2+dx
posy = (height-th)/2+dy
if self.style & wx.BU_LEFT:
posx = dx + 4
elif self.style & wx.BU_RIGHT:
posx = width - tw - dx - 4
if self.style & wx.BU_BOTTOM:
posy = height - th - dy - 4
elif self.style & wx.BU_TOP:
posy = dy + 4
dc.DrawText(label, posx , posy)