Commits

Anonymous committed 5ec68ec

hggtk/recovery: add button to stop command execution

Comments (0)

Files changed (1)

hggtk/recovery.py

         # toolbar
         self.tbar = gtk.Toolbar()
         self.tips = gtk.Tooltips()
+        self._stop_button = self._toolbutton(gtk.STOCK_STOP,
+                'Stop', self._stop_clicked, tip='Stop the hg operation')
+        self._stop_button.set_sensitive(False)
         tbuttons = [
                 self._toolbutton(gtk.STOCK_CLEAR,
                                  'clean', 
                                  self._verify_clicked,
                                  tip='Validate repository consistency'),
                 gtk.SeparatorToolItem(),
+                self._stop_button,
+                gtk.SeparatorToolItem(),
             ]
         for btn in tbuttons:
             self.tbar.insert(btn, -1)
         cmd = ['verify']
         self._exec_cmd(cmd)
     
-    def _exec_cmd(self, cmd, postfunc=None):            
+    def _stop_clicked(self, toolbutton, data=None):
+        if self.hgthread and self.hgthread.isAlive():
+            self.hgthread.terminate()
+            self._stop_button.set_sensitive(False)
+
+    def _exec_cmd(self, cmd, postfunc=None):
+        self._stop_button.set_sensitive(True)
         cmdline = cmd
         cmdline.append('--verbose')
         cmdline.append('--repository')
                 pass
         if threading.activeCount() == 1:
             self.stbar.end()
+            self._stop_button.set_sensitive(False)
+            if self.hgthread.return_code() is None:
+                self.write("[command interrupted]")
             return False # Stop polling this function
         else:
             return True