Source

pytest-gui / pytest_gui / gtkui / filefails.py

Full commit
'''
detailed information on thefailures within a file
'''
import gtk
from pygtkhelpers.ui.objectlist import ObjectList, Column
from pygtkhelpers.delegates import WindowView


class FileFailView(WindowView):
    fileentry = None

    def create_ui(self):
        self.collection = ObjectList([
            Column('nodeid',
                   format_func=lambda x:x.split('::', 1)[-1]),
        ])
        self.collection.set_headers_visible(False)
        self.collection.show()
        self.collection.set_visible_func(lambda x: x and x.outcome != 'passed')
        self.coll_scroll = gtk.ScrolledWindow()
        self.coll_scroll.add(self.collection)

        self.paned = gtk.HPaned()
        self.paned.add(self.coll_scroll)
        self.paned.show()
        self.textview = gtk.TextView()
        self.text_scroll = gtk.ScrolledWindow()
        self.text_scroll.add(self.textview)
        self.paned.add(self.text_scroll)
        self.widget.add(self.paned)
        self.widget.set_size_request(800, 400)

        self.widget.connect('delete_event', gtk.Widget.hide_on_delete)

    def set_entry(self, fileentry):
        if self.fileentry:
            del self.fileentry.view
        self.collection.clear()
        self.fileentry = fileentry
        if fileentry:
            fileentry.view = self
            self.collection.extend(fileentry.reports)
            self.set_title(fileentry.filename)
        else:
            self.set_title('None')
        if self.fileentry.reports:
            self.collection.selected_item = self.collection[0]

    def on_collection__selection_changed(self, _):
        try:
            print self.collection.selected_item

            repr = self.collection.selected_item.longrepr
        except:
            import traceback
            tb = traceback.format_exec()
            repr = 'INTERNAL GUI ERROR>\n' + tb

        self.textview.get_buffer().set_text(repr)