You are not logged in.

#1 2008-04-10 16:24:56

alex_anthony
Member
From: UK
Registered: 2007-09-25
Posts: 344

glade image preview

I'm trying to write an app in python with glade. Anyone know if I can make an image preview box? e.g. take a location as a variable from python and then display the image from that location
Or am I going to have to do that in full PyGTK?

Offline

#2 2008-04-10 17:19:20

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: glade image preview

You mean this?

#!/usr/bin/ env python

""" Display an image inside my window """
import wx

class Frame(wx.Frame):
    """ Frame class from wx that displays the image """
    def __init__(self, image, parent= None, id= -1, pos= wx.DefaultPosition, title= "See my picture"):
        """ Create a Frame instance and display the image """
        temp = image.ConvertToBitmap()
        size = temp.GetWidth(), temp.GetHeight()
        wx.Frame.__init__(self, parent, id, title, pos, size)
        self.bmp = wx.StaticBitmap(parent = self, bitmap = temp)
        
class App(wx.App):
    """ Application Class """
    def OnInit(self):
        image = wx.Image('wall.jpg',wx.BITMAP_TYPE_JPEG)
        self.frame = Frame(image)
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

def main():
    app = App()
    app.MainLoop()
        
if __name__ == "__main__":    
    main()

Hope this helps.

R.

Offline

#3 2008-04-10 19:54:21

alex_anthony
Member
From: UK
Registered: 2007-09-25
Posts: 344

Re: glade image preview

Thanks for the code - I think i understand it, but is it using wx? i wanted gtk but I guess its similar just a couple of different calls
I was hoping to be able to do it in glade but I guess I'll have to build it all from the command line... Unless you can make a custom control/display for glade? is it possible to embed code like that above into a glade container?

Offline

#4 2008-04-10 20:19:40

kumico
Member
Registered: 2007-09-28
Posts: 224
Website

Re: glade image preview

glade is a layout engine? for gtk
so yeh, you need pygtk.
in glade you can add a gtkimage widget and from pygtk load the file location directly into it with the set_from_file method
http://www.pygtk.org/docs/pygtk/class-gtkimage.html

Offline

Board footer

Powered by FluxBB