[meld] Replace the final use of misc.struct and remove it



commit 5659f43223eb695d49d6c45ebd688bf383afd1f7
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jan 9 10:10:13 2011 +1000

    Replace the final use of misc.struct and remove it

 meld/filediff.py |   20 ++++++++++----------
 meld/misc.py     |   18 ------------------
 2 files changed, 10 insertions(+), 28 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 778c35b..2a1fba4 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -39,6 +39,7 @@ import paths
 import merge
 
 from util.sourceviewer import srcviewer
+from util.namedtuple import namedtuple
 
 
 class CachedSequenceMatcher(object):
@@ -863,20 +864,19 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             msgarea.show_all()
             return msgarea
 
-        for i,f in enumerate(files):
-            buf = textbuffers[i]
-            if f:
+        TaskEntry = namedtuple('TaskEntry',
+                               'filename file buf codec pane was_cr')
+        for pane, filename in enumerate(files):
+            buf = textbuffers[pane]
+            if filename:
                 try:
-                    task = misc.struct(filename = f,
-                                       file = codecs.open(f, "rU", try_codecs[0]),
-                                       buf = buf,
-                                       codec = try_codecs[:],
-                                       pane = i,
-                                       was_cr = False)
+                    handle = codecs.open(filename, "rU", try_codecs[0])
+                    task = TaskEntry(filename, handle, buf, try_codecs[:],
+                                     pane, False)
                     tasks.append(task)
                 except (IOError, LookupError), e:
                     buf.delete(*buf.get_bounds())
-                    add_dismissable_msg(i, gtk.STOCK_DIALOG_ERROR,
+                    add_dismissable_msg(pane, gtk.STOCK_DIALOG_ERROR,
                                         _("Could not read file"), str(e))
         yield _("[%s] Reading files") % self.label_text
         while len(tasks):
diff --git a/meld/misc.py b/meld/misc.py
index 6434e38..755bf6d 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -135,24 +135,6 @@ def make_tool_button_widget(label):
     hbox.show_all()
     return hbox
 
-class struct(object):
-    """Similar to a dictionary except that members may be accessed as s.member.
-
-    Usage:
-    s = struct(a=10, b=20, d={"cat":"dog"} )
-    print s.a + s.b
-    """
-    def __init__(self, **args):
-        self.__dict__.update(args)
-    def __repr__(self):
-        r = ["<"]
-        for i in self.__dict__.keys():
-            r.append("%s=%s" % (i, getattr(self, i)))
-        r.append(">\n")
-        return " ".join(r)
-    def __cmp__(self, other):
-        return cmp(self.__dict__, other.__dict__)
-
 def all_equal(alist):
     """Return true if all members of the list are equal to the first.
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]