'Take a screenshot of the widget. You can optionally append a string to the name of the screenshot. The
screenshot itself is saved as a JPEG file.'

def screenshot(self, widget, name=None):

    pixmap = QPixmap(widget.rect().size())
    widget.render(pixmap, QPoint(), QRegion(widget.rect()))
    self.screenshots_taken += 1
    img_name = ('screenshot_%d.jpg' % self.screenshots_taken)
    if (name is not None):
        img_name = ('screenshot_%s.jpg' % name)
    screenshots_dir = os.path.join(os.path.dirname(TriblerGUI.__file__), 'screenshots')
    if (not os.path.exists(screenshots_dir)):
        os.mkdir(screenshots_dir)
    pixmap.save(os.path.join(screenshots_dir, img_name))
