What I'm attempting to do is load an image, then let it grow and
shrink proportionally within its sizer slot as the frame is resized.
This I've done. Then I want to load a different image, and do the
same thing. This I haven't quite done yet. I can do it, but I have
to manually resize the frame at least several pixels for all the
resizing to be correct, and even then, sometimes the aspect ratio of
the new picture isn't correct, leading it to be compressed or
stretched in one direction. I'm not asking for help in that (yet).
I'm having too much fun trying to figure it out for myself. Though
any suggestions will be gratefully accepted.
I think I've figured out that my problem is that the aspect ratio of
the new picture is (most likely) going to be different from that of
the old picture. In a search of possible tools I could use I came
across a problem in the documentation.
wx.SizerItem holds a widget, such as the Static Bitmap I'm using to
hold the image. It has getter/setter for size, which I think I'll use
to try to figure out and set an initial size for the new picture,
hoping to avoid the manual resizing. While looking through the
wx.SizerItem docs, however, I saw two other attributes: proportion
(which is an integer) and ratio (which is a float). (I assume the
proportion item is a local copy of the proportion argument given when
adding an item to the sizer.) I can surmise that the ratio item is
the current ratio of height to width (or maybe width to height) of the
SizerItem. But that could be very wrong.
The only explanations I can find for the getter/setter of these two
items is basically "Set ratio item" "Get ratio item" Not very helpful
-- I already figured that out. What I want to know is: What IS a
ratio item (and proportion item)? I've googled within an inch of my
life and what I've discovered is that there are hundreds of absolute
copies of that same material; in different formats possibly, but
absolute copies - right down to the misspelling of "ratio' as "ration"
in the original.
So - what is a ratio item? What is a proportion item? What can one
do with them? A pointer to more complete or advanced documentation is
fine too.
According to wxPython in Action (book) - The proportion argument
manages the size amount that the window changes relative to other
windows—it’s only meaningful for a
wx.BoxSizer.
Basically it can cause widgets to grow at different rates. I'm not
sure what this ratio argument is...
As for keeping the aspect ratio, I got this code from a post by Andrea
Gavana quite a while ago that works for me:
<code>
img = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
# scale the image, preserving the aspect ratio
W = img.GetWidth()
H = img.GetHeight()
if W > H:
NewW = self.PhotoMaxSize
NewH = self.PhotoMaxSize * H / W
else:
NewH = self.PhotoMaxSize
NewW = self.PhotoMaxSize * W / H
img = img.Scale(NewW,NewH)
I set PhotoMaxSize to the maximum size I want, so you'll want to
change that, but that should get you going.
···
On Aug 20, 3:06 pm, dncarac <patents...@gmail.com> wrote:
What I'm attempting to do is load an image, then let it grow and
shrink proportionally within its sizer slot as the frame is resized.
This I've done. Then I want to load a different image, and do the
same thing. This I haven't quite done yet. I can do it, but I have
to manually resize the frame at least several pixels for all the
resizing to be correct, and even then, sometimes the aspect ratio of
the new picture isn't correct, leading it to be compressed or
stretched in one direction. I'm not asking for help in that (yet).
I'm having too much fun trying to figure it out for myself. Though
any suggestions will be gratefully accepted.
I think I've figured out that my problem is that the aspect ratio of
the new picture is (most likely) going to be different from that of
the old picture. In a search of possible tools I could use I came
across a problem in the documentation.
wx.SizerItem holds a widget, such as the Static Bitmap I'm using to
hold the image. It has getter/setter for size, which I think I'll use
to try to figure out and set an initial size for the new picture,
hoping to avoid the manual resizing. While looking through the
wx.SizerItem docs, however, I saw two other attributes: proportion
(which is an integer) and ratio (which is a float). (I assume the
proportion item is a local copy of the proportion argument given when
adding an item to the sizer.) I can surmise that the ratio item is
the current ratio of height to width (or maybe width to height) of the
SizerItem. But that could be very wrong.
The only explanations I can find for the getter/setter of these two
items is basically "Set ratio item" "Get ratio item" Not very helpful
-- I already figured that out. What I want to know is: What IS a
ratio item (and proportion item)? I've googled within an inch of my
life and what I've discovered is that there are hundreds of absolute
copies of that same material; in different formats possibly, but
absolute copies - right down to the misspelling of "ratio' as "ration"
in the original.
So - what is a ratio item? What is a proportion item? What can one
do with them? A pointer to more complete or advanced documentation is
fine too.
What I'm attempting to do is load an image, then let it grow and
shrink proportionally within its sizer slot as the frame is resized.
This I've done. Then I want to load a different image, and do the
same thing. This I haven't quite done yet. I can do it, but I have
to manually resize the frame at least several pixels for all the
resizing to be correct, and even then, sometimes the aspect ratio of
the new picture isn't correct, leading it to be compressed or
stretched in one direction. I'm not asking for help in that (yet).
I'm having too much fun trying to figure it out for myself. Though
any suggestions will be gratefully accepted.
Just use the wx.SHAPED flag when adding the static bitmap to the sizer. Whatever aspect ratio it has at that point in time will be maintained by the sizer when it expands the item.
I think I've figured out that my problem is that the aspect ratio of
the new picture is (most likely) going to be different from that of
the old picture. In a search of possible tools I could use I came
across a problem in the documentation.
wx.SizerItem holds a widget, such as the Static Bitmap I'm using to
hold the image. It has getter/setter for size, which I think I'll use
to try to figure out and set an initial size for the new picture,
hoping to avoid the manual resizing. While looking through the
wx.SizerItem docs, however, I saw two other attributes: proportion
(which is an integer) and ratio (which is a float). (I assume the
proportion item is a local copy of the proportion argument given when
adding an item to the sizer.)
Yes.
I can surmise that the ratio item is
the current ratio of height to width (or maybe width to height) of the
SizerItem.
Yes.
PyCrust 0.9.8 - The Flakiest Python Shell
Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> szr = wx.BoxSizer()
>>> pnl = wx.Panel(shell, size=(60,40))
>>> pnl.Size
wx.Size(60, 40)
>>> sitem = szr.Add(pnl, 0, wx.SHAPED)
>>> sitem.Ratio
1.5
>>>
So - what is a ratio item? What is a proportion item? What can one
do with them? A pointer to more complete or advanced documentation is
fine too.
The ratio of an item is used when the wx.SHAPED flag is set to ensure that the aspect ratio stays the same. The proportion value of an item is used in box sizers to determine how to divide up the space left over after the layout of the fixed size items has been done.