Commits

Moises Henriquez committed bc4bb28

Added right-click menues and functionality to re-build a job from the job history

Comments (0)

Files changed (5)

src/vpackager/bot.py

             rel = dbutils.GetJobProp(_id,'release')
             _type = dbutils.GetJobProp(_id, 'install')
             patches = dbutils.GetJobProp(_id, 'patches')
+            toinstall = dbutils.GetJobProp(_id,'install')
             patchlist = []
             if patches:
                 patchlist = patches.split(',')
         self.pack_start(cont, True, True, 2)
         self._parent.queueman = cont
 
+    def _refresh_ui(self):
+        return self._parent.queueman._update_queue()
+
 class TabHistory(Tab):
     """ Tab displaying the job build history"""
     def __init__(self, *args, **kwargs):
         self.pack_start(cont, True, True, 2)
         self._parent.historyman = cont
 
+    def _refresh_ui(self):
+        return self._parent.historyman._refresh_history_display()
+
 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)
+        self.connect('switch-page', self._switch_page_event)
+
+    def _switch_page_event(self, widget=None, page=None, page_num=0):
+        if page_num in (1,2):
+            return self.get_nth_page(page_num)._refresh_ui()
+        #print page_num
+        #return
+
+        child = self.get_nth_page(page_num)
+        #return child.
 
 class App(gtk.Window):
     """ Main app GUI """

src/vpackager/dbutils.py

 def __verify_tables():
     ''' Verify that the essential tables for the vpackager environment
     exist'''
-    if os.path.exists(dbpath):
-        os.remove(dbpath)
-    return True
+    #if os.path.exists(dbpath):
+        #        os.remove(dbpath)
+    #return True
     # FIXME: ^^^ Remove this before final release ^^
 
     db = sqlite3.connect(dbpath)
         return ret[0]
     return None
 
+def GetTaskProp(taskid, prop):
+    """ Returns Taskid's property (prop) """
+    db = sqlite3.connect(dbpath)
+    c = db.cursor()
+    c.execute('select %s from history where id=%s'% (prop,taskid))
+    try:
+        ret = c.next()
+    except StopIteration:
+        ret = None
+    c.close()
+    if ret:
+        return ret[0]
+    return None
+
 def GetTaskDetails(jobid):
     """ Returns all information from the job history about jobid"""
     db = sqlite3.connect(dbpath)
     c = db.cursor()
-    c.execute('select * from history where id=?',jobid)
+    t = (jobid,)
+    c.execute('select * from history where id=?',t)
     try:
         ret = c.next()
     except StopIteration:

src/vpackager/guitools.py

         topbox.pack_start(lbl, True, True, 2)
         lbl.set_property('xalign', 0.0)
         self.body.pack_start(topbox, False, True, 4)
+        self._selected_jobid = jobid
 
         self.body.pack_start(self._get_tree(), True, True, 2)
         self.set_size_request(500,400)
         scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
         mod = gtk.ListStore(str, str)
         tree = gtk.TreeView(model=mod)
-        col0 = gtk.TreeviewColumn()
-        col1 = gtk.TreeviewColumn()
+        col0 = gtk.TreeViewColumn()
+        col1 = gtk.TreeViewColumn()
         cr0 = gtk.CellRendererText()
         cr1 = gtk.CellRendererText()
         col0.pack_start(cr0)
         col1.pack_start(cr1)
         col0.add_attribute(cr0, 'markup', 0)
         col1.add_attribute(cr1, 'markup', 1)
+        tree.append_column(col0)
+        tree.append_column(col1)
         tree.set_headers_visible(False)
 
         # Get the data we need
         mod.append(['Build ended', buildend])
         mod.append(['Build result', result])
         mod.append(['Output log', stdout])
-        lpatches = patches.split(',')
-        mod.append(['Patches applied', lpatches[0]])
-        for x in range(1, len(lpatches)):
-            mod.append(['',lpatches[x]])
+        if patches:
+            lpatches = patches.split(',')
+            mod.append(['Patches applied', lpatches[0]])
+            for x in range(1, len(lpatches)):
+                mod.append(['',lpatches[x]])
+
+        scroll.add(tree)
 
 
 
         return scroll
 
-
-
-
 class About(gtk.AboutDialog):
     """ About dialog for vpackager"""
     def __init__(self):
         for _type in ('Auto','Autotools','Python','CMake','Perl','Waf'):
             types.append([_type])
         cbsrcsel = gtk.ComboBox(types)
+        self.srcTypeSel = cbsrcsel
         cbsrcsel.connect('changed', self._srctype_changed)
         crt = gtk.CellRendererText()
         cbsrcsel.pack_start(crt)

src/vpackager/historymanager.py

 import dbutils
 import guitools
 import message
+import os
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 __version__ = '0.1'
 
+class TaskMenu(gtk.Menu):
+    """Menu that pops up when right-clicking a task"""
+    def __init__(self, selected, parent=None):
+        gtk.Menu.__init__(self)
+        self.selected = selected
+        self._parent = parent
+        item_rebuild = gtk.MenuItem('Build again')
+        item_rebuild.connect('activate',
+                self._rebuild_event)
+        item_details = gtk.MenuItem('Build Details')
+        item_details.connect('activate',
+                self._task_details_event)
+        item_rebuild.show()
+        item_details.show()
+        self.append(item_rebuild)
+        self.append(item_details)
+
+    def _rebuild_event(self, widget=None):
+        _id = self.selected
+        _srcuri = dbutils.GetTaskProp(_id, 'srcURI')
+        if _srcuri.startswith('/'):
+            if not os.path.exists(_srcuri):
+                # FIXME: Source package can no longer be found
+                err = message.Error(parent=self,
+                        text="The source package for this job can no longer "+\
+                                "be found on the system. Please specify " +\
+                                "the new location of the source package")
+                if err.run():
+                    err.destroy()
+        _descuri = dbutils.GetTaskProp(_id, 'descURI')
+        _patches = dbutils.GetTaskProp(_id, 'patches')
+        _type = dbutils.GetTaskProp(_id, 'type')
+        _app = dbutils.GetTaskProp(_id, 'app')
+        _ver = dbutils.GetTaskProp(_id, 'ver')
+        dia = guitools.JobAddDialog()
+        dia.SrcURI = _srcuri
+        dia.DescURI = _descuri
+        dia.appEntry.set_text(_app)
+        dia.verEntry.set_text(_ver)
+        dia.srcentry.set_text(_srcuri)
+        dia.descEntry.set_text(_descuri)
+        if _type == 'autotools':
+            typeid = 1
+        elif _type == 'python':
+            typeid = 2
+        elif _type == 'cmake':
+            typeid = 3
+        elif _type == 'perl':
+            typeid = 4
+        elif _type == 'waf':
+            typeid = 5
+        else:
+            typeid = 0
+
+        dia.srcTypeSel.set_active(typeid)
+        #dia.cbsrcTypeSel.set_active(
+        #        dia.dbsrcTypeSel.get_model())
+        if _patches:
+            mod = dia.patchestree.get_model()
+            for patch in _patches:
+                mod.append([patch])
+
+        res = dia.run()
+        dia.hide()
+        if res == gtk.RESPONSE_OK:
+            app = dia.app
+            ver = dia.ver
+            desc = dia.DescURI
+            src = dia.SrcURI
+            rel = dia.release
+            srctype = dia.srctype
+            toinstall = dia.install
+            patches = ','.join(dia.patches)
+            dbutils.NewJob(app, ver, src, desc,
+                    rel, srctype, toinstall, patches)
+        dia.destroy()
+
+    def _task_details_event(self, widget=None):
+        return self._parent._task_details_event(widget)
+
+
 class Main(gtk.VBox):
     ''' Container holding a treeview with convinient methods to work with the
     job history'''
                 len(dbutils.GetHistory()) > 0)
 
     def _task_details_event(self, widget=None):
-        pass
+        dia = guitools.AboutTask(self._selected_jobid)
+        if dia.run():
+            dia.destroy()
 
     def _get_bottom_toolbar(self):
         '''toolbar at the bottom of the job history'''
                 label='Build Details')
         self.btTaskDetails.connect('clicked', self._task_details_event)
         self.btWipeHistory.connect('clicked', self._do_wipe_history)
-        btWipe.connect('clicked', self._do_wipe_history)
         box.pack_start(btWipe, False, False, 2)
         box.pack_start(self.btTaskDetails, False, False, 2)
 
         return box
 
+    def _tree_button_press(self, widget, event):
+        if event.button == 3:
+            m = TaskMenu(selected = self._selected_jobid,
+                    parent=self)
+            m.popup(None, None, None, event.button, event.time)
+
     def _tree_click_event(self, tree=None):
         """ Events triggered by clicking on the treeview"""
         sel = tree.get_selection()
             self.tree.append_column(col)
             i += 1
         self.tree.connect('cursor-changed', self._tree_click_event)
+        self.tree.connect('button-press-event', self._tree_button_press)
         return self.tree
 
     def _do_wipe_history(self, widget=None):
         """ Wipe the entire history """
-        dia = message.Question(parent = self.parent,
+        dia = message.Question(
                 text='This will erase you entire build history. \n' + \
                         'Are you sure you want to continue?')
         res = dia.run()
-        dia.hide()
-        if dia.response == gtk.RESPONSE_YES:
+        dia.destroy()
+        if res == gtk.RESPONSE_YES:
             dbutils.WipeHistory()
-        dia.destroy()
         return self._refresh_history_display()
 
     def _refresh_history_display(self):

src/vpackager/jobmanage.py

 import dbutils
 import guitools
 import buildutils
+import time
 
 __author__ = 'M0E-lnx'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 __version__ = '0.1'
 
+class RMenu(gtk.Menu):
+    """Menu that pops up when the right button is clicked """
+    def __init__(self, selected=None, parent=None):
+        gtk.Menu.__init__(self)
+        self.selected = selected
+        self._parent = parent
+        item_delete = gtk.MenuItem('Remove')
+        item_delete.connect('activate', self._item_delete_event)
+        item_delete.show()
+        item_details = gtk.MenuItem('Details')
+        item_details.connect('activate',
+                self._item_details_event)
+        item_details.show()
+        self.append(item_delete)
+        self.append(item_details)
+
+    def _item_delete_event(self, widget=None):
+        """ Removes a job from que queue using the right-click menu"""
+        return self._parent._btDeleteClick(widget)
+
+    def _item_details_event(self, widget=None):
+        """ Triggers display of job details from the right-click menu"""
+        return self._parent._job_details_event(widget)
+
 
 class Main(gtk.VBox):
     '''job manager main container'''
         for entry in lst:
             self.tree.get_model().append(entry)
 
+    def _tree_button_press(self, widget, event, data=None):
+        if event.button == 3:
+            self.rmenu = RMenu(selected=self._selected_jobid,
+                    parent=self)
+            self.rmenu.popup(None,None,None,
+                    event.button, event.time)
+
     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)
+        self.tree.connect('button-press-event', self._tree_button_press)
 
         i = 0
         for field in ('ID', 'Application', 'Version',
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.