[wxPython] how to automatically resize a window?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Curzio Basso

    #1

    [wxPython] how to automatically resize a window?


    Hi all,

    I have a problem for which I wasn't able to find an answer anywhere
    else, maybe someone can give me a hint...

    I designed with XRCed a small GUI (the code is at the bottom of the
    message) made up of a menu and a frame in which there are two panels,
    placed by an horizontal sizer.

    Now, what I would like to do is to be able to load an image and display
    it on the left panel, automatically resizing the panel depending on the
    image size (the code is at the end again). There are actually two problems:

    1) if I load an image the panel is not resized automatically

    2) if I resize the panel manually after having loaded the image, the DC
    is not repainted. that is, the portion of the image which was invisible
    is not painted

    Is there anyone with a bit of time to explain me how to solve these
    problems?

    thanks, qrz

    ------------------ XRC ----------------------------

    <?xml version="1.0" ?>
    <resource>
    <object class="wxFrame" name="MAIN">
    <title>test</title>
    <object class="wxBoxSiz er">
    <orient>wxHORIZ ONTAL</orient>
    <object class="sizerite m">
    <object class="wxPanel" name="IMAGE">
    <size>100,100 </size>
    </object>
    <border>5</border>
    </object>
    <object class="sizerite m">
    <object class="wxPanel" name="CONTROLS" >
    <size>100,100 </size>
    </object>
    <border>5</border>
    </object>
    </object>
    </object>
    <object class="wxMenuBa r" name="MENU">
    <object class="wxMenu" name="MENU_FILE ">
    <label>File</label>
    <object class="wxMenuIt em" name="MENU_FILE _OPEN">
    <label>Open</label>
    </object>
    </object>
    </object>
    </resource>

    ---------------- PYTHON -----------------------------

    from wxPython.wx import *
    from wxPython.xrc import *
    import Image

    def pilToWx(pil):
    image = wxEmptyImage(pi l.size[0], pil.size[1])
    image.SetData(p il.convert('RGB ').tostring())
    return image

    class MyApp(wxApp):

    def OnInit(self):
    self.res = wxXmlResource(" test.xrc")
    self.InitFrame( )
    self.InitMenu()
    self.InitEveryt hingElse()
    self.image = None
    return True

    def InitFrame(self) :
    self.frame = self.res.LoadFr ame(None, "MAIN")
    self.ipanel = XRCCTRL(self.fr ame, "IMAGE")
    EVT_PAINT(self. ipanel, self.OnPaint)
    self.cpanel = XRCCTRL(self.fr ame, "CONTROLS")

    def InitMenu(self):
    self.menuBar = self.res.LoadMe nuBar("MENU")
    EVT_MENU(self.f rame, XRCID("MENU_FIL E_OPEN"), self.Open)
    self.frame.SetM enuBar(self.men uBar)

    def InitEverythingE lse(self):
    self.sizer = self.frame.GetS izer()
    self.frame.SetA utoLayout(True)
    self.sizer.Fit( self.frame)
    self.sizer.SetS izeHints(self.f rame)
    self.frame.Show (1)
    self.SetTopWind ow(self.frame)

    def Open(self, evt):
    fd = wxFileDialog(se lf.frame, "Open image", "", "", \
    "PNG image (*.png)|*.png|J PEG image
    (*.jpg)|*.jpg", \
    wxOPEN)
    if fd.ShowModal() == wxID_OK:
    im = Image.open(fd.G etPath())
    self.image = pilToWx(im)
    self.ipanel.Set Size(im.size)
    self.ipanel.Ref resh(True)
    fd.Destroy()

    def OnPaint(self, evt):
    if self.image:
    dc = wxPaintDC(self. ipanel)
    dc.DrawBitmap(s elf.image.Conve rtToBitmap(), 0,0)

    def main():
    app = MyApp(0)
    app.MainLoop()

    if __name__ == '__main__':
    main()
  • David Fraser

    #2
    Re: [wxPython] how to automatically resize a window?

    Curzio Basso wrote:[color=blue]
    >
    > Hi all,
    >
    > I have a problem for which I wasn't able to find an answer anywhere
    > else, maybe someone can give me a hint...
    >
    > I designed with XRCed a small GUI (the code is at the bottom of the
    > message) made up of a menu and a frame in which there are two panels,
    > placed by an horizontal sizer.
    >
    > Now, what I would like to do is to be able to load an image and display
    > it on the left panel, automatically resizing the panel depending on the
    > image size (the code is at the end again). There are actually two problems:
    >
    > 1) if I load an image the panel is not resized automatically
    >
    > 2) if I resize the panel manually after having loaded the image, the DC
    > is not repainted. that is, the portion of the image which was invisible
    > is not painted
    >
    > Is there anyone with a bit of time to explain me how to solve these
    > problems?
    >
    > thanks, qrz[/color]

    You probably want to go to the wxPython users mailing list for this (see
    the links on the wxpython home page)

    David

    Comment

    Working...