Rev 3: Decent functionality, including the ability to cancel. in http://bzr.arbash-meinel.com/branches/bzr/merge_into

John Arbash Meinel john at arbash-meinel.com
Fri Dec 21 20:54:28 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/merge_into

------------------------------------------------------------
revno: 3
revision-id:john at arbash-meinel.com-20071221205426-rt82hrvdevdp85ph
parent: john at arbash-meinel.com-20071221204110-3mt64ech9v88hzpl
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: merge_into
timestamp: Fri 2007-12-21 14:54:26 -0600
message:
  Decent functionality, including the ability to cancel.
modified:
  bzr_merge_into.py              bzr_merge_into.py-20071221192513-1fyh868lls6qugcq-1
  bzr_merge_into.wxg             bzr_merge_into.wxg-20071221185509-khngkqvqe1jjzb2i-1
-------------- next part --------------
=== modified file 'bzr_merge_into.py'
--- a/bzr_merge_into.py	2007-12-21 20:41:10 +0000
+++ b/bzr_merge_into.py	2007-12-21 20:54:26 +0000
@@ -35,16 +35,17 @@
         self.label_3 = wx.StaticText(self, -1, "Processing")
         self.lbl_command = wx.StaticText(self, -1, "<command>")
         self.gauge_progress = wx.Gauge(self, -1, 10)
-        self.button_2 = wx.Button(self, wx.ID_CANCEL, "")
+        self.btn_cancel = wx.Button(self, wx.ID_CANCEL, "")
 
         self.__set_properties()
         self.__do_layout()
+
+        self.Bind(wx.EVT_BUTTON, self.onCancel, self.btn_cancel)
         # end wxGlade
 
     def __set_properties(self):
         # begin wxGlade: ProcessDialog.__set_properties
         self.SetTitle("Processing")
-        self.button_2.Enable(False)
         # end wxGlade
 
     def __do_layout(self):
@@ -53,7 +54,7 @@
         sizer_6.Add(self.label_3, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
         sizer_6.Add(self.lbl_command, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5)
         sizer_6.Add(self.gauge_progress, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
-        sizer_6.Add(self.button_2, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 0)
+        sizer_6.Add(self.btn_cancel, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 0)
         self.SetSizer(sizer_6)
         sizer_6.Fit(self)
         self.Layout()
@@ -61,11 +62,15 @@
 
     def runCommand(self, command, *args, **kwargs):
         """Run a command, and poll it until it finishes."""
+        self.canceled = False
+        kill = getattr(os, 'kill', None)
+        if kill is None: # No support for stopping the child
+            self.btn_cancel.Disable()
         self.CenterOnParent()
         self.lbl_command.SetLabel(' '.join(command))
         parent = self.GetParent()
         if parent:
-            parent.Freeze()
+            parent.Disable()
         self.Fit()
         self.Show()
         wx.Yield()
@@ -85,22 +90,36 @@
                     return
             # We want to poll, but we also want to grab sys.stdout and
             # sys.stderr, how do we do that?
-            while p.poll() is None:
+            while p.poll() is None and not self.canceled:
                 self.gauge_progress.Pulse()
                 wx.Yield()
                 time.sleep(0.1)
-            retcode = p.returncode
+            if self.canceled and kill is not None:
+                import signal
+                kill(p.pid, signal.SIGINT)
+            retcode = p.wait()
             if retcode == 0:
-                return
+                return None
+            elif self.canceled and retcode == 3:
+                dlg = wx.MessageDialog(parent,
+                        message='Canceled',
+                        caption='Canceled',
+                        style=wx.OK | wx.ICON_INFORMATION)
+                return dlg
             else:
-                dlg = wx.MessageDialog(self,
+                dlg = wx.MessageDialog(parent,
                         message='Failed with return code: %s\n'
                                 '%s\n'
                                 % (retcode, command))
+                return dlg
         finally:
-            self.Close()
             if parent:
-                parent.Thaw()
+                parent.Enable()
+            self.Close()
+
+    def onCancel(self, event): # wxGlade: ProcessDialog.<event_handler>
+        self.canceled = True
+        event.Skip()
 
 # end of class ProcessDialog
 
@@ -232,7 +251,12 @@
             cmd = ['bzr', '--no-aliases', 'pull', '--overwrite', patch]
 
         dlg = ProcessDialog(self)
-        dlg.runCommand(cmd, cwd=target_branch)
+        err_dlg = dlg.runCommand(cmd, cwd=target_branch)
+        if err_dlg is not None:
+            err_dlg.ShowModal()
+        else:
+            # We are done here
+            self.Close()
 
 # end of class MergeIntoFrame
 

=== modified file 'bzr_merge_into.wxg'
--- a/bzr_merge_into.wxg	2007-12-21 20:41:10 +0000
+++ b/bzr_merge_into.wxg	2007-12-21 20:54:26 +0000
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!-- generated by wxGlade 0.5 on Fri Dec 21 14:39:44 2007 -->
+<!-- generated by wxGlade 0.5 on Fri Dec 21 14:44:03 2007 -->
 
 <application path="bzr_merge_into.py" name="" class="MergeIntoApp" option="0" language="python" top_window="merge_into" encoding="UTF-8" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.8" is_template="0">
     <object class="MergeIntoFrame" name="merge_into" base="EditFrame">
@@ -196,10 +196,12 @@
                 <flag>wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL</flag>
                 <border>0</border>
                 <option>0</option>
-                <object class="wxButton" name="button_2" base="EditButton">
+                <object class="wxButton" name="btn_cancel" base="EditButton">
                     <stockitem>CANCEL</stockitem>
                     <label>&amp;Cancel</label>
-                    <disabled>1</disabled>
+                    <events>
+                        <handler event="EVT_BUTTON">onCancel</handler>
+                    </events>
                 </object>
             </object>
         </object>



More information about the bazaar-commits mailing list