Source

vpackager / src / vpackager / historymanager.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
import dbutils

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

class Main(gtk.VBox):
    ''' Container holding a treeview with convinient methods to work with the
    job history'''
    def __init__(self):
        gtk.VBox.__init__(self)
        self.model = gtk.ListStore(
                int, str, str, str, str, str)
        self.pack_start(gtk.Label('Job History'), False, True, 2)
        scroll = gtk.ScrolledWindow()
        scroll.set_policy(gtk.POLICY_AUTOMATIC,
                gtk.POLICY_AUTOMATIC)
        self.pack_start(scroll, True, True, 2)
        scroll.add(self._get_tree())
        #self.pack_start(self._get_tree())
        self.show_all()
        self._refresh_history_display()


    def _get_tree(self):
        self.tree = gtk.TreeView(model = self.model)
        i = 0
        for field in ('ID','Application', 'Version',
                'Build Start', 'Build End', 'Result'):
        #for field in ('ID', 'Package', 'Version', 'Source URI', 'Description',
        #   'Release','Type', 'Build Start', 'Build End', 'Output', 'Result'):
            col = gtk.TreeViewColumn(field)
            col.set_resizable(True)
            crt = gtk.CellRendererText()
            col.pack_start(crt)
            col.add_attribute(crt, 'text', i)
            self.tree.append_column(col)
            i += 1
        return self.tree

    def _refresh_history_display(self):
        self.tree.set_model(
                gtk.ListStore(int,str, str, str, str, str))
        lst = dbutils.GetHistory()
        for entry in lst:
            self.tree.get_model().append(entry)