[chirp_devel] [PATCH 2 of 3] Refactor paste so import logic is performed before validation. #185

Tom Hayward
Wed Feb 6 09:09:01 PST 2013


# HG changeset patch
# User Tom Hayward <tom at tomh.us>
# Date 1360126791 28800
# Node ID 8acf7f0440e42453cd920cb4397bec207da1db97
# Parent  257d98b3f5717671face8ae70680a50d83c81a1c
Refactor paste so import logic is performed before validation. #185

diff -r 257d98b3f571 -r 8acf7f0440e4 chirpui/memedit.py
--- a/chirpui/memedit.py	Tue Feb 05 20:58:39 2013 -0800
+++ b/chirpui/memedit.py	Tue Feb 05 20:59:51 2013 -0800
@@ -1307,27 +1307,29 @@
 
             src_number = mem.number
             mem.number = loc
-            msgs = self.rthread.radio.validate_memory(mem)
-            errs = [x for x in msgs if isinstance(x,
-                                                  chirp_common.ValidationError)]
-            if errs:
-                d = miscwidgets.YesNoDialog(title=_("Incompatible Memory"),
-                                            buttons=(gtk.STOCK_OK, 1,
-                                                     gtk.STOCK_CANCEL, 2))
-                d.set_text(_("Pasted memory {number} is not compatible with "
-                             "this radio because:").format(number=src_number) +\
-                               os.linesep + os.linesep.join(msgs))
-                r = d.run()
-                d.destroy()
-                if r == 2:
-                    break
-                else:
-                    iter = store.iter_next(iter)
-                    continue
-
-            mem = import_logic.import_mem(self.rthread.radio,
-                                          src_features,
-                                          mem)
+            
+            try:
+                mem = import_logic.import_mem(self.rthread.radio,
+                                              src_features,
+                                              mem)
+            except import_logic.DestNotCompatible:
+                msgs = self.rthread.radio.validate_memory(mem)
+                errs = [x for x in msgs if isinstance(x,
+                                                      chirp_common.ValidationError)]
+                if errs:
+                    d = miscwidgets.YesNoDialog(title=_("Incompatible Memory"),
+                                                buttons=(gtk.STOCK_OK, 1,
+                                                         gtk.STOCK_CANCEL, 2))
+                    d.set_text(_("Pasted memory {number} is not compatible with "
+                                 "this radio because:").format(number=src_number) +\
+                                   os.linesep + os.linesep.join(msgs))
+                    r = d.run()
+                    d.destroy()
+                    if r == 2:
+                        break
+                    else:
+                        iter = store.iter_next(iter)
+                        continue
 
             self._set_memory(iter, mem)
             iter = store.iter_next(iter)



More information about the chirp_devel mailing list