Source

vpackager / bot.py

#!/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
from vpackager import guitools
import jobmanage
import historymanager

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

class Tab(gtk.VBox):
    ''' Generic tab for use in the tabstrip '''
    def __init__(self, label='', stock=None, parent=None):
        gtk.VBox.__init__(self)
        ibox = gtk.VBox()
        img = gtk.Image()
        img.set_from_stock(stock, gtk.ICON_SIZE_BUTTON)
        ibox.pack_start(img, False, False, 2)
        lbl = gtk.Label()
        lbl.set_use_markup(True)
        lbl.set_markup(label)
        ibox.pack_start(lbl, False, False, 2)
        self.label = ibox
        self.label.show_all()
        self._parent = parent

class TabStatus(Tab):
    ''' Bot control and status tab '''
    def __init__(self, *args, **kwargs):
        Tab.__init__(self, label='Bot Status', stock=gtk.STOCK_PREFERENCES,
                **kwargs)
        topbox = gtk.HBox()
        flt = gtk.Frame('Bot Status')
        lvbox = gtk.VBox()
        flt.add(lvbox)
        ltbox = gtk.HBox()
        lbbox = gtk.HBox()
        lvbox.pack_start(ltbox, False , True, 2)
        lvbox.pack_start(lbbox, False, True, 2)
        lb0 = gtk.Label()
        lb1 = gtk.Label()
        lb0.set_use_markup(True)
        lb1.set_use_markup(True)
        lb0.set_markup('<b>Current Status:</b>')
        lb1.set_markup('<b>Current Job:</b>')
        ltbox.pack_start(lb0, False, False, 2)
        lbbox.pack_start(lb1, False, False, 2)

        frt = gtk.Frame('Bot Control')
        rvbox = gtk.VBox()
        frt.add(rvbox)
        rtbox = gtk.HBox()
        rbbox = gtk.HBox()

        btStopBot = guitools.vButton(label='Stop', stock=gtk.STOCK_NO)
        btStartBot = guitools.vButton(label='Start', stock=gtk.STOCK_YES)
        rtbox.pack_start(btStartBot, False, False, 2)
        rtbox.pack_start(btStopBot, False, False, 2)

        rvbox.pack_start(rtbox, False, True, 2)
        rvbox.pack_start(rbbox, False, True, 2)

        topbox.pack_start(flt, True, True, 2)
        topbox.pack_start(frt, False, False, 2)
        self.pack_start(topbox, False, True, 4)

        # add a textview inside a scrolled window for output monitoring.
        self.scroll = gtk.ScrolledWindow()
        self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.stdoutmon = gtk.TextView()
        self.stdoutmon.set_property('editable', False)
        for edge in (gtk.TEXT_WINDOW_LEFT, gtk.TEXT_WINDOW_RIGHT,
                gtk.TEXT_WINDOW_TOP, gtk.TEXT_WINDOW_BOTTOM):
            self.stdoutmon.set_border_window_size(edge, 4)
        self.scroll.add(self.stdoutmon)

        frmoutput = gtk.Frame('Build Output')
        frmoutput.add(self.scroll)

        self.pack_start(frmoutput, True, True, 4)

class TabQueue(Tab):
    """ Job queue tab. Used to manage build jobs."""
    def __init__(self, *args, **kwargs):
        Tab.__init__(self, label = 'Job Queue',
                stock = gtk.STOCK_INDEX, **kwargs)
        cont = jobmanage.Main()
        self.pack_start(cont, True, True, 2)
        self._parent.queueman = cont

class TabHistory(Tab):
    """ Tab displaying the job build history"""
    def __init__(self, *args, **kwargs):
        Tab.__init__(self, label = 'Job History',
                stock=gtk.STOCK_JUSTIFY_FILL, **kwargs)
        cont = historymanager.Main()
        self.pack_start(cont, True, True, 2)
        self._parent.historyman = cont

class TabStrip(gtk.Notebook):
    """ Tabstrip used to display the main content of the application"""
    def __init__(self):
        gtk.Notebook.__init__(self)
        self.set_property('tab-pos', gtk.POS_LEFT)

class App(gtk.Window):
    """ Main app GUI """
    def __init__(self):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_title('vpackager')
        self.connect('destroy', self._exit)
        self.set_size_request(600, 400)
        self.body = gtk.VBox()
        self.body.pack_start(self._get_menubar(), False, True, 4)
        self.body.pack_start(self._get_notebook(), True, True, 4)
        self.body.pack_start(self._get_bottombar(), False, False, 4)

        self.queueman = None
        self.historyman = None

        self.add(self.body)


    def _get_notebook(self):
        """ Main content notebook"""
        strip = TabStrip()
        stats = TabStatus(parent=self)
        strip.append_page(stats, stats.label)

        queuet = TabQueue(parent=self)
        strip.append_page(queuet, queuet.label)

        history = TabHistory(parent=self)
        strip.append_page(history, history.label)


        return strip

    def _get_bottombar(self):
        return gtk.Label('Bottom bar')

    def _get_menubar(self):
        return gtk.Label('Menu here')


    def _exit(self, widget=None):
        return gtk.main_quit()

if __name__ == '__main__':
    gtk.gdk.threads_init()
    w = App()
    w.show_all()
    gtk.gdk.threads_enter()
    gtk.main()
#    gdk.gdk.threads_leave()