I would like to "announce" my quasi-latest control (yes, there is
another one coming right now), called FancyButtonPanel.
"With FancyButtonPanel class you have a panel with gradient coloring on it and
with the possibility to place some buttons on it. Using a standard
panel with normal wx.Buttons leads to an ugly result: the buttons are
placed correctly on the panel - but with grey area around them.
Gradient coloring is kept behind the images - this was achieved due to
the PNG format and the transparency of the bitmaps.
The image are functioning like a buttons and can be caught in your
code using the usual self.Bind(wx.EVT_BUTTON, self.OnButton) method.
The control is generic, and support theming (well, I tested it under
Windows with the three defauls themes: grey, blue, silver and the
classic look)."
The source code, demo and epydoc-generated documentation are available
in the usual place:
The widget has been tested on wxPython 2.6.3.3, with Python 2.4 on Windows XP.
Tried on linux with wx 2.6 and 2.7 and found a problem:
when I resize the frame, if I increase its size, all work, but is I
decrease, the FancyButtonPanel don't resize itself.
After some tries, I see that GetClientRect (line 301), don't return the
right size (may be a wx bug?), so I add a simple patch that solve this:
#Line 302
if not sys.platform.startswith("win"): #Bug solver for gtk
parent_w = self.GetParent().GetSize()[0]
rect = list(rect)
rect = rect[:2] + [parent_w] + [rect[3]]
rect = wx.Rect(*rect)
I would like to "announce" my quasi-latest control (yes, there is
another one coming right now), called FancyButtonPanel.
"With FancyButtonPanel class you have a panel with gradient coloring on it and
with the possibility to place some buttons on it. Using a standard
panel with normal wx.Buttons leads to an ugly result: the buttons are
placed correctly on the panel - but with grey area around them.
Gradient coloring is kept behind the images - this was achieved due to
the PNG format and the transparency of the bitmaps.
The image are functioning like a buttons and can be caught in your
code using the usual self.Bind(wx.EVT_BUTTON, self.OnButton) method.
The control is generic, and support theming (well, I tested it under
Windows with the three defauls themes: grey, blue, silver and the
classic look)."
FancyButtonPanel looks really cool!
Is it possible to place the buttons on the left side of the panel?
Michele: thanks for the bug report: I tried it on my VMWare Ubuntu and
I got the same problem. I updated the source with your changes. It
seems like a bug on wxPython-GTK, or maybe I have misunderstood
something on how OnPaint actually should work. Robin, could you
confirm?
Alexei: with the version Eran posted on wxWidgets forum, there is no
way to align buttons other than right: he's setting the alignment
property as a button property, while in my opinion should be a
FancyButtonPanel property (assigned to the bar itself). So I changed a
little bit the class and demo to show how it works (you just choose
the menu "Edit" and you can change the alignment of the buttons and
the text.
Alexei: with the version Eran posted on wxWidgets forum, there is no
way to align buttons other than right: he's setting the alignment
property as a button property, while in my opinion should be a
FancyButtonPanel property (assigned to the bar itself). So I changed a
little bit the class and demo to show how it works (you just choose
the menu "Edit" and you can change the alignment of the buttons and
the text.
Thanks, Andrea!
Do you plan on implementing a FancyButtonPanel alignment property, or do you intend your implementation to stay as close to the original as possible?
Do you plan on implementing a FancyButtonPanel alignment property, or do
you intend your implementation to stay as close to the original as
possible?
Do you mean that instead of having Set* and Get* method like:
titleBar.SetAlignment(BP_ALIGN_RIGHT)
You would like to have something like:
titleBar.Alignment = BP_ALIGN_RIGHT
? Like in the new refactoring of wxPython in 2.7? (this SetAlignment
and GetAlignment are already in the code)
Well, if this is the case, I will surely try to do it, to have also my
widgets to be more "Pythonic". I only don't know how Robin has
implemented the changes in wxPython from setter and getter to
properties, so if Robin could share some suggestions on how to do it
semi-automatically (faster) I will surely do it.
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
The widget has been tested on wxPython 2.6.3.3, with Python 2.4 on Windows XP.
Tried on linux with wx 2.6 and 2.7 and found a problem:
when I resize the frame, if I increase its size, all work, but is I
decrease, the FancyButtonPanel don't resize itself.
After some tries, I see that GetClientRect (line 301), don't return the
right size (may be a wx bug?),
It is happening because the panel doesn't have a best size or min size defined, so the sizer is always using the current size as the best size. Although the behavior on Windows is more agreeable in this instance, I think it is the one that is incorrect according to the current definitions. However I'm surprised to see the platforms behaving differently here because the code in question is shared between platforms. I'll see if I can figure out what is going on...
so I add a simple patch that solve this:
#Line 302
if not sys.platform.startswith("win"): #Bug solver for gtk
parent_w = self.GetParent().GetSize()[0]
rect = list(rect)
rect = rect[:2] + [parent_w] + [rect[3]]
rect = wx.Rect(*rect)
Or you could save yourself a little confusion and replace the last three lines with
rect.width = parent_w
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Well, if this is the case, I will surely try to do it, to have also my
widgets to be more "Pythonic". I only don't know how Robin has
implemented the changes in wxPython from setter and getter to
properties, so if Robin could share some suggestions on how to do it
semi-automatically (faster) I will surely do it.
I have a little script that scans the classes in a module and looks for methods that start with "Get" and then looks for a matching method that starts with "Set" and then writes to stdout a property line for it (in my case using SWIG syntax.) I then reviewed what had been written and copy/paste/edit it into the sources. It's not anywhere near perfect, but it saved me a bunch of typing.
Do you plan on implementing a FancyButtonPanel alignment property, or do
you intend your implementation to stay as close to the original as
possible?
Do you mean that instead of having Set* and Get* method like:
titleBar.SetAlignment(BP_ALIGN_RIGHT)
You would like to have something like:
titleBar.Alignment = BP_ALIGN_RIGHT
? Like in the new refactoring of wxPython in 2.7? (this SetAlignment
and GetAlignment are already in the code)
Yes, that would be nice.
Well, if this is the case, I will surely try to do it, to have also my
widgets to be more "Pythonic". I only don't know how Robin has
implemented the changes in wxPython from setter and getter to
properties, so if Robin could share some suggestions on how to do it
semi-automatically (faster) I will surely do it.
This and I think it would be nice to move all the code that deals with buttons' alignment (part of the CreateButtons function code) from the app to the FancyButtonPanel class. As I see it now part of the alignment configuration goes on in the FancyButtonPanel class, and another part of it in the applicatin. Or maybe I'm missing something?