vpackager / src / vpackager / jobmanage.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
import guitools
import buildutils

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


class Main(gtk.VBox):
    '''job manager main container'''
    def __init__(self):
        gtk.VBox.__init__(self)
        hbtop = gtk.HBox()
        self.pack_start(hbtop, False, True, 4)
        lbtop = gtk.Label('Manage job queue')
        hbtop.pack_start(lbtop, True, True, 2)

        scrl = gtk.ScrolledWindow()
        scrl.set_policy(gtk.POLICY_AUTOMATIC,
                gtk.POLICY_AUTOMATIC)
        scrl.add(self._get_tree())
        self._fill_tree_with_queue()
        self.pack_start(scrl, True, True, 8)
        hbbot = gtk.HBox()
        self.pack_start(hbbot, False, True, 4)
        self.btAdd = gtk.Button(stock=gtk.STOCK_ADD)
        self.btRem = gtk.Button(stock=gtk.STOCK_REMOVE)
        self.btRem.connect('clicked', self._btDeleteClick)
        self.btAdd.connect('clicked', self._btAddClick)
        frmJobCtrl = gtk.Frame('Job Control')
        jobsvbox = gtk.HBox()
        frmJobCtrl.add(jobsvbox)
        jobsvbox.pack_start(self.btAdd, False, False, 2)
        jobsvbox.pack_start(self.btRem, False, False, 2)
        hbbot.pack_start(frmJobCtrl, True, True , 4)

    def _btAddClick(self, widget=None):
        dia = guitools.JobAddDialog(parent=self)
        res = dia.run()
        dia.hide()
        if res == gtk.RESPONSE_OK:
            app = dia.app
            ver = dia.ver
            desc = dia.DescURI
            srcuri = dia.SrcURI
            rel = dia.release
            srctype = dia.srctype
            toinstall = dia.install
            patches = ','.join(dia.patches)
            dia.destroy()
            dbutils.NewJob(app, ver, srcuri, desc,
                    rel, srctype, toinstall, patches)
            return self._update_queue()

    def _btDeleteClick(self, widget=None):
        if self._selected_jobid:
            dbutils.RemoveJob(self._selected_jobid)
            self._update_queue()

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

    def _get_tree(self):
        mod = gtk.ListStore(int, str, str, str)
        self.tree = gtk.TreeView(model = mod)
        self.tree.connect('cursor-changed', self._tree_click_event)

        i = 0
        for field in ('ID', 'Application', 'Version',
                'Release'):
            col = gtk.TreeViewColumn(field)
            col.set_resizable(True)
            cr = gtk.CellRendererText()
            col.pack_start(cr)
            col.add_attribute(cr, 'text', i)
            self.tree.append_column(col)
            i += 1


        return self.tree

    def _tree_click_event(self, tree=None):
        sel = tree.get_selection()
        (model, iter) = sel.get_selected()
        selrow = tree.get_model()[iter][0]

        self._selected_jobid = selrow


    def _fill_tree_with_queue(self):
        tm = self.tree.get_model()
        q = dbutils.GetQueue()
        for item in q:
            tm.append(item)

if __name__ == '__main__':
    w = gtk.Window(gtk.WINDOW_TOPLEVEL)
    w.connect('destroy', gtk.main_quit)
    w.set_title('Job Queue Manager')
    w.set_size_request(600, 400)
    w.add(Main())
    w.show_all()
    gtk.gdk.threads_init()
    gtk.gdk.threads_enter()
    gtk.main()
    gtk.gdk.threads_leave()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.