Commits

Moises Henriquez committed 0e7c8cf

Added functionality to edit existing jobs

  • Participants
  • Parent commits 6e886d6

Comments (0)

Files changed (1)

 todo = dbconn.refresh_todo()
 
 _busy = False
+_dbchange = False
 class Monitor(threading.Thread):
     def __init__(self, label):
         super(Monitor, self).__init__()
 
     def update_status(self, status):
         w.info_label3.set_text(status)
-class gui(gtk.Window):
-    def __init__(self):
-        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
-        body = gtk.VBox(False, 4)
-        self.add(body)
-        
-        banner = gtk.Label('This is a build bot')
-        body.pack_start(banner, 0, 0, False)
-        
-        srcline = gtk.HBox(False, 4)
-        src_lbl = gtk.Label('Pick Source Archive')
-        srcline.pack_start(src_lbl, False)
-        src_input = gtk.Entry()
-        self.pathbox = src_input
-        srcline.pack_start(src_input,True)
-        bt_load_src = gtk.Button(stock=gtk.STOCK_OPEN)
-        bt_load_src.connect('clicked', self.bt_load_src_click)
-        srcline.pack_start(bt_load_src, False)
-        
-        body.pack_start(srcline, 0, 0, True)
 
-        info_area = gtk.Frame('About Selection')
-        blank1=gtk.Label()
-        blank2 = gtk.Label()
-        self.info_label1 = gtk.Label('No source has been selected')
-        self.info_label2 = gtk.Label()
-        self.info_label3 = gtk.Label()
-        area = gtk.VBox(False, 4)
-        area.pack_start(blank1)
-        area.pack_start(self.info_label1)
-        area.pack_start(self.info_label2)
-        area.pack_start(self.info_label3)
-        area.pack_start(blank2)
-        
-        
-        info_area.add(area)
-        
-        btgo = gtk.Button('GO')
-        btgo.connect('clicked', self.start_build)
-        body.pack_start(btgo, 0, 0, False)
-        body.pack_start(info_area, 0, 0, True)
-        self.connect('destroy', gtk.main_quit)
-    def start_build(self, widget):
-        dispatch = dispatcher()
-        dispatch.start()
-
-    def bt_load_src_click(self, widget):
-        dia = gtk.FileChooserDialog(title='Select source file',
-            parent = self, buttons=(gtk.STOCK_OPEN,
-            gtk.RESPONSE_OK,
-            gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
-        dia.set_default_response(gtk.RESPONSE_OK)
-        
-        flt = gtk.FileFilter()
-        flt.set_name('Compressed Archives')
-        flt.add_pattern('*.tar.*')
-        
-        dia.add_filter(flt)
-        res = dia.run()
-        if res == gtk.RESPONSE_OK:
-            self.pathbox.set_text(dia.get_filename())
-            self.info_label1.set_property('xalign', 0.5)
-            self.info_label2.set_property('label', '')
-            self.info_label3.set_property('label', '')
-            self.info_label1.set_property('label', 'Loading information...')
-            gobject.idle_add(self.update_src_about, dia.get_filename())
-            
-        else:
-            self.pathbox.set_text('')
-        
-        dia.destroy()
-    
-    def update_src_about(self, path):
-        self.src = bbot.Source(path)
-        self.info_label1.set_property('use-markup', True)
-        self.info_label2.set_property('use-markup', True)
-        self.info_label3.set_property('use-markup', True)
-        self.info_label1.set_property('xalign', 0.0)
-        self.info_label2.set_property('xalign', 0.0)
-        self.info_label3.set_property('xalign', 0.0)
-        self.info_label1.set_property('label', 
-            '<b>Application: </b>%s'% self.src.app)
-        self.info_label2.set_property('label', 
-            '<b>Version: </b>%s'% self.src.version)
-        self.info_label3.set_property('label',
-            '<b>Source Type: </b>%s'% self.src.type)
 
 class mWindow(gtk.Window):
     def treeview_click(self, treeview):
         self.refresh_task_list()
     def __init__(self):
         self.selected_job = None
+        self.selected_job_dsc = None
+        self.selected_job_src = None
+        treestore = gtk.TreeStore(str, str, str)
+        self._todo_list = treestore
+        
+        
+        ## Get the todo list from the database:
+        _lst = dbconn.refresh_todo()
+        for row in _lst:
+            treestore.append(None, [row[0], row[1], row[2]])
+
+        
         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
         self.set_default_size(600,400)
         self.set_position(gtk.WIN_POS_CENTER)
         
         sw = gtk.ScrolledWindow()
         
-        treestore = gtk.TreeStore(str, str, str)
-        self._todo_list = treestore
-        #treestore.append(None, ['0','Task 1', 'Description Path'])
-        #treestore.append(None,['1','Task 2', 'Description Path'])
         
-        ## Get the todo list from the database:
-        _lst = dbconn.refresh_todo()
-        for row in _lst:
-            treestore.append(None, [row[0], row[1], row[2]])
 
         tv = gtk.TreeView(treestore)
         tv.connect('cursor-changed', self.treeview_click)
         bt_remove.connect('clicked', self.delete_job, self.selected_job)
         
         bt_edit = gtk.Button('Edit Job')
+        bt_edit.connect('clicked', self._show_edit_job)
         img2 = gtk.Image()
         img2.set_from_stock(gtk.STOCK_EDIT, gtk.ICON_SIZE_BUTTON)
         bt_edit.set_image(img2)
         self.info_label1 = gtk.Label()
         self.info_label2 = gtk.Label()
         self.info_label3 = gtk.Label()
-
-
+        
         self.add(body)
         self.connect('destroy', gtk.main_quit)
+    
+    def _show_edit_job(self, widget):
+        if not self.selected_job:
+            err = dialogs.info(message='Nothing selected yet', parent=self)
+            if err.run(): err.destroy()
+            return
+        
+        ej = JobEdit(parent=self,
+            id = self.selected_job,
+            srcpath = self.selected_job_src,
+            descpath = self.selected_job_dsc)
+        
+        res = ej.run()
+        ej.destroy()
+        if res == gtk.RESPONSE_CANCEL:
+            return
+    
+        self._do_edit_job(self.selected_job,
+            ej.srcpath, ej.descpath)
+        
+        
+    def _do_edit_job(self, id, srcpath, descpath):
+        sql = "UPDATE todo SET srcpath='%s' WHERE id='%s'"% (srcpath, id)
+        sql2 = "UPDATE todo SET descpath='%s' WHERE id='%s'"% (descpath, id)
+        
+        dbconn.push_data(sql)
+        dbconn.push_data(sql2)
+        
+        self.refresh_task_list()
+        
     def _show_add_form(self, widget):
-        ###aw = JobWindow()
-        ###aw.show_all()
-        ##print aw.tarball
+
         aj = _AddJobWindow(parent=self)
         res = aj.run()
         if res == gtk.RESPONSE_ACCEPT:
         for row in _lst:
             self._todo_list.append(None, [row[0], row[1], row[2]])
 
+
+
+
+        
 class _AddJobWindow(gtk.Dialog):
     def __init__(self, parent):
         self.srcpath = ''
         dbody = self.vbox
         
         hdr = gtk.Label()
+        self.header = hdr
         hdr.set_property('use-markup', True)
         hdr.set_property('label', 'Add new job')
         hdr.set_property('xalign', 0.0)
         src_line_btn.connect('clicked', self.load_src)
         srcline.pack_start(src_line_btn, False, False, 2)
         self._src_entry = src_line_txt
+        self._src_entry.connect('changed', self._src_entry_changed)
         
         descline = gtk.HBox(False, 4)
         dsc_line_lbl = gtk.Label()
         dsc_line_btn.connect('clicked', self.load_desc)
         descline.pack_start(dsc_line_btn, False, False, 2)
         self._desc_entry = dsc_line_txt
+        self._desc_entry.connect('changed', self._desc_entry_changed)
         
         dbody.pack_start(descline, False, False, 2)
         
 
         self.show_all()
     
+    def _src_entry_changed(self, widget):
+        self.srcpath = widget.get_text()
+        
+    def _desc_entry_changed(self, widget):
+        self.descpath = widget.get_text()
+    
     def load_src(self, widget):
         dia = gtk.FileChooserDialog(buttons = (gtk.STOCK_OPEN,
         gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
         self._desc_entry.set_text(self.descpath)
         dia.destroy()
         
+class JobEdit(_AddJobWindow):
+    def __init__(self, parent, id, srcpath, descpath):
+        _AddJobWindow.__init__(self, parent=parent)
+        self.set_title('Edit Task')
+        self._src_entry.set_text(srcpath)
+        self._desc_entry.set_text(descpath)
+        self.header.set_text('Edit existing task on to-do list')