Source

vpackager / src / vpackager / botcontroller.py

Full commit
#!/usr/bin/env python

#    This file is part of vpackager.
#
#    vpackager is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License v2 as published by
#    the Free Software Foundation.
#
#    vpackager is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with vpackager.  If not, see <http://www.gnu.org/licenses/>.

import gtk
import dbutils
import dbviews
import guitools
import viewcontrollers

__author__ = 'M0E-lnx'
__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
__version__ = '0.1'

class StatusTab(gtk.VBox):
    """ Content of the status tab packed in a vbox that can be
    appended as a page to the tabstrip"""

    def __init__(self):
        gtk.VBox.__init__(self)
        self.bot_state_indicators = {}
        self.bot_control_buttons = {}
        self.bot_state_indicators['state'] = gtk.Label()
        self.bot_state_indicators['running_job'] = gtk.Label()
        self.bot_control_buttons['start'] = guitools.vButton(
            stock=gtk.STOCK_YES, label='Start')
        self.bot_control_buttons['stop'] = guitools.vButton(
            stock=gtk.STOCK_NO, label='Stop')
        for lb  in self.bot_state_indicators.values():
            lb.set_use_markup(True)
        self.pack_start(self._get_top_frames(), False, True, 4)
        self.pack_start(self._get_output_display(), True, True, 4)

    def _get_top_frames(self):
        """ Top frames that show the bot status and bot control buttons."""
        section = gtk.HBox()
        frm_tl = gtk.Frame('Bot Status')
        frm_tr = gtk.Frame('Build Bot Control')
        frm_tl_vbox = gtk.VBox()
        frm_tl.add(frm_tl_vbox)
        line1 = gtk.HBox()
        line2 = gtk.HBox()
        frm_tl_vbox.pack_start(line1, False, True, 2)
        frm_tl_vbox.pack_start(line2, False, True, 2)
        lb_bot_state = gtk.Label('Current Bot State:')
        lb_running_job = gtk.Label('Current Job:')
        line1.pack_start(lb_bot_state, False, False, 2)
        line2.pack_start(lb_running_job, False, False, 2)
        line1.pack_start(
            self.bot_state_indicators['state'], True, True, 2)
        line2.pack_start(
            self.bot_state_indicators['running_job'], True, True, 2)

        # Pack the bot control widgets
        rvbox = gtk.VBox()
        rhbox = gtk.HBox()
        rvbox.pack_start(rhbox, True, True, 2)
        rhbox.pack_start(
            self.bot_control_buttons['start'], False, False, 2)
        rhbox.pack_start(
            self.bot_control_buttons['stop'], False, False, 2)
        frm_tr.add(rvbox)

        section.pack_start(frm_tl, True, True, 2)
        section.pack_start(frm_tr, False, False, 2)


        return section

    def _get_output_display(self):
        scrl = gtk.ScrolledWindow()
        scrl.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.textview = gtk.TextView()
        for edge in (gtk.TEXT_WINDOW_LEFT, gtk.TEXT_WINDOW_RIGHT,
                     gtk.TEXT_WINDOW_TOP, gtk.TEXT_WINDOW_BOTTOM):
            self.textview.set_border_window_size(edge, 4)
        scrl.add(self.textview)

        return scrl


class Gui(gtk.Window):
    """ Main window for vpackager"""
    def __init__(self, dbase_model):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.dbase_model = dbase_model
        self.body = gtk.VBox()
        self.set_title('vpackager')
        self.set_position(gtk.WIN_POS_CENTER)
        self.body.pack_start(gtk.Label('Menu goes here'), False, True, 2)
        self.tabstrip = guitools.TabStrip()
        self.bot_tab = StatusTab()
        self.queue_view = dbviews.QueueView()
        self.history_view = dbviews.HistoryView()
        queue_controller = viewcontrollers.QueueController(
            model = self.dbase_model, view = self.queue_view)
        history_controller = viewcontrollers.HistoryController(
            model = self.dbase_model, view = self.history_view)

        self.tabstrip.append_page(self.bot_tab,
                                  guitools.TabIcon(
                                    label='Bot Status',
                                    stock=gtk.STOCK_PREFERENCES))
        self.tabstrip.append_page(self.queue_view,
                                  guitools.TabIcon(
                                    label = 'Job Queue',
                                    stock=gtk.STOCK_INDEX))
        self.tabstrip.append_page(self.history_view,
                                  guitools.TabIcon(
                                    label = 'Job History',
                                    stock=gtk.STOCK_JUSTIFY_FILL))

        self.body.pack_start(self.tabstrip, True, True, 2)
        self.add(self.body)
        self.show_all()
        self.connect('destroy', gtk.main_quit)
        self.set_size_request(600,400)

        # Force initial display of the queue and history
        self.dbase_model.RefreshQueue()
        self.dbase_model.RefreshHistory()





if __name__ == '__main__':
    model = dbutils.dbase()
    w = Gui(dbase_model = model)
    w.show_all()
    gtk.main()