Source

pytest-gui / pytest_gui / gtkui / main.py

import gtk
from pygtkhelpers.delegates import WindowView
from .result import CollectResultView
from .runstate import RunStateView
from ..handler import MessageHandler, make_gw


class MainWindow(WindowView):
    """
    combines the different collect selection and run view
    in a way that allows productive interaction
    """
    _gw = None

    def create_ui(self):
        self.notebook = gtk.Notebook()
        self.notebook.set_show_tabs(False)

        self.message_handler = MessageHandler(self)
        self.collect_view = CollectResultView(self)
        self._col_tab = self.notebook.append_page(self.collect_view.widget)

        self.run_view = RunStateView(master=self)
        self._run_tab = self.notebook.append_page(self.run_view.widget)

        self.widget.add(self.notebook)
        self.widget.set_size_request(800, 400)
        self.widget.show_all()

    def run_once(self, test_ids=None, collectonly=False):
        #XXX: after collect cleanup
        if test_ids is not None:
            self.run_view.set_tests(test_ids)
        if self._gw:
            self._gw.exit()
        self._gw, ch = make_gw(collectonly=collectonly, items=test_ids)
        self.message_handler.setchannel(ch)
        if collectonly:
            self.show_selection()
        else:
            self.show_run()

    def show_selection(self):
        self.notebook.set_current_page(self._col_tab)

    def show_run(self):
        self.notebook.set_current_page(self._run_tab)

    def report_collect(self, item):
        #XXX: run view should print collect information
        self.collect_view.report_collect(item)
        self.run_view.report_collect(item)

    def report_result(self, item):
        self.collect_view.report_result(item)
        self.run_view.report_result(item)

    def report_start(self, item):
        self.run_view.report_start(item)