Q:

PyGTK FileChooserDialog Keep Getting Errors

Now I made WidgetArea originally for Windows, but being primarily a Linux user. I wanted to make it for Linux as well, but mainly to learn more about the file dialog in PyGTK. So I took a look at this tutorial to have a better understanding of it, while working on this simple, yet small application, as that's easier for me to learn, and understand by experimentation.
So here's my source code.
#!/usr/bin/env python

import sys, os
import pygtk, gtk, gobject
import pygst
pygst.require("0.10")
import gst

class WidgetArea(gtk.Window):

   def addwidget(self, w):
    self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.win.set_title("Widget")
    self.win.set_decorated(False)
    self.win.set_has_frame(False)
    self.win.set_resizable(False)
    self.win.set_keep_above(True)
    self.win.set_property('skip-taskbar-hint', True)
    self.previewimage = gtk.Image()
    self.win.add(self.previewimage)
    self.win.show_all()

   def pinning(self, checkbox):
    if checkbox.get_active():
     self.set_keep_above(True)
    else:
     self.set_keep_above(False)

   def change_size(self, w):
     width = int(self.entryw.get_text())
     height = int(self.entryh.get_text())
     self.win.set_size_request(width,height)

   def __init__(self):
    super(WidgetArea, self).__init__()
    self.set_position(gtk.WIN_POS_CENTER)
    self.set_title("WidgetArea")
    self.set_resizable(False)
    self.set_keep_above(True)
    self.set_property('skip-taskbar-hint', True)
    self.connect("destroy", gtk.main_quit, "WM destroy")
    vbox = gtk.VBox(spacing=0)
    hbox = gtk.HBox(spacing=0)
    hbox2 = gtk.HBox(spacing=0)
    hbox3 = gtk.HBox(spacing=0)
    hbox4 = gtk.HBox(spacing=0)

    self.widgetsize = gtk.Label("Widget Size:")
    self.widgetsize.set_size_request(100, 30)

    self.entryw = gtk.Entry()
    self.entryh = gtk.Entry()
    self.entryw.set_text("270")
    self.entryw.set_size_request(75, 30)
    labelcoma = gtk.Label(",")
    labelcoma.set_size_request(10, 30)
    self.entryh.set_text("221")
    self.entryh.set_size_request(75, 30)
    labelspac1 = gtk.Label(" ")
    labelspac1.set_size_request(10, 30)
    hbox.pack_start(self.widgetsize)
    hbox.pack_start(self.entryw)
    hbox.pack_start(labelcoma)
    hbox.pack_start(self.entryh)
    hbox.pack_start(labelspac1, 0, 0, 10)

    check = gtk.CheckButton("Pin This Window")
    check.set_active(True)
    check.connect("clicked", self.pinning)
    hbox.pack_start(check, 0, 0, 10)

    labelspac2 = gtk.Label(" ")
    labelspac2.set_size_request(250, 15)
    hbox2.pack_start(labelspac2)

    filefilter = gtk.FileFilter()
    filefilter.set_name("Images")
    filefilter.add_mime_type("image/png")
    filefilter.add_mime_type("image/jpeg")
    filefilter.add_mime_type("image/gif")
    filefilter.add_mime_type("image/tiff")
    filefilter.add_mime_type("image/svg+xml")
    filefilter.add_pattern("*.jpg")

    self.ref_file_button = gtk.FileChooserButton('Add Widget')
    self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))
    self.ref_file_button.set_filter(filefilter)
    self.ref_file_button.connect("file-set", self.on_open_clicked)
    hbox3.pack_start(self.ref_file_button, 150, 150, 10)

    labelspac5 = gtk.Label(" ")
    labelspac5.set_size_request(0, 10)
    hbox4.pack_start(labelspac5)

    vbox.pack_start(hbox)
    vbox.pack_start(hbox2)
    vbox.pack_start(hbox3)
    vbox.pack_start(hbox4)
    self.add(vbox)
    self.show_all()

   def on_open_clicked(self, widget, data=None):
    ref_image_path = widget.get_filename()
    self.previewimage.set_from_file(ref_image_path)
    self.addwidg.connect("clicked", self.addwidget)
    self.addwidg.connect("clicked", self.change_size)
    ref_image_path.destroy()

WidgetArea()
gtk.gdk.threads_init()
gtk.main()

I removed the following code (1st), due to the following error (2nd).
self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))

Traceback (most recent call last):
  File "./widgetarea.py", line 109, in <module>
    WidgetArea()
  File "./widgetarea.py", line 86, in __init__
    self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))
AttributeError: 'WidgetArea' object has no attribute 'rootdir'

Now this isn't a big deal at this point. My main goal is to get the image displayed in a new window. So after I removed the code above, due to that error I got another one.
Traceback (most recent call last):
  File "./widgetarea.py", line 103, in on_open_clicked
    self.previewimage.set_from_file(ref_image_path)
AttributeError: 'WidgetArea' object has no attribute 'previewimage'

All I'm having problems with is when you browse to select an image I want the chosen image, when pressed OK to launch as a new window displaying the chosen image in that window, as stated above.

A:

I have used something like this in one of my projects. And it's working well for me in Linux.
def __init__(self):
    # Define all the widgets   
    image_filter = gtk.FileFilter()
    image_filter.set_name("Images")
    image_filter.add_mime_type("image/png")
    image_filter.add_mime_type("image/jpeg")
    image_filter.add_mime_type("image/gif")
    image_filter.add_mime_type("image/tiff")
    image_filter.add_mime_type("image/svg+xml")
    image_filter.add_pattern("*.jpg")

    self.ref_file_button = gtk.FileChooserButton('Select Image')
    self.ref_file_button.set_size_request(100,30)
    self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"])) # set directory path
    self.ref_file_button.set_filter(image_filter)
    self.ref_file_button.set_tooltip_text('Select Image')
    self.ref_file_button.connect("file-set", self.ref_image_selected)

def ref_image_selected(self,widget,data=None):
    ref_image_path = widget.get_filename()
    print ref_image_path

After getting the path of the image, you can load it using gtk.Image
EDIT:
Your code is a bit erroneous. You are never calling the function addwidget(), and hence self.previewimage is not defined. and so it gives AttributeError.
def __init__(self):
    # your code
    self.add(vbox)
    self.addwidget(200)   # I don't know what 'w' is. so I took a random number.
    self.show_all()

def  on_open_clicked(self, widget, data=None):
    ref_image_path = widget.get_filename()
    self.previewimage.set_from_file(ref_image_path)
    self.addwidg.connect("clicked", self.addwidget)
    self.addwidg.connect("clicked", self.change_size)
    ref_image_path.destroy()

What is self.addwidg ?
And I am able to view the image now.

