Commits

oliver_g committed 8d849b5

display contents of SubFile fields (if a parser can be found)

Comments (0)

Files changed (1)

hachoir-gtk/hachoir-gtk

 import gtk.glade
 from hachoir_core.cmd_line import unicodeFilename
 from hachoir_parser import createParser
+from hachoir_parser import guessParser
+from hachoir_core.field import SubFile
 
 UI_FILENAME = os.path.dirname( __file__ ) + "/hachoir.glade"
 
         self.fieldset = fieldset
         self.table = self.xml.get_widget("table")
 
+        self.table.connect("row-expanded", self.on_row_expanded)
+
         self.xml.get_widget("main_window").set_title("Hachoir - %s" % filename)
 
         self.table.set_search_equal_func(resultSearchCb)
     def on_window_destroy(self, widget, data=None):
         self.quit()
 
+    def on_row_expanded (self, treeview, it, path):
+        model = treeview.get_model()
+        childIt = model.iter_children(it)
+        if childIt and model.get_value(childIt, 0) is None:
+            stream = model.get_value(childIt, 2)
+
+            parser = guessParser(stream)
+            if not parser:
+                print "no parser found for %s" % stream.source
+                model.remove(childIt)
+            else:
+                self.fill_tree(parser, it, model)
+                model[childIt] = ("Subfile", parser.description, None)
+
     def treeview_add_column(self, treeview, name, num):
         col = gtk.TreeViewColumn(name)
         treeview.append_column(col)
         return num+1
 
     def display_tree(self, parent):
-        treeStore = gtk.TreeStore(str, str)
+        treeStore = gtk.TreeStore(str, str, object)
         self.table.set_model(treeStore)
         self.treeview_add_column(self.table, "name", 0)
         self.treeview_add_column(self.table, "value", 1)
                 #value = field.raw_display
             else:
                 value = field.description
-            newparent = treeStore.append(treeparent,(field.name,value))
+            newparent = treeStore.append(treeparent,(field.name,value,None))
             if field.is_field_set:
                 self.fill_tree(field, newparent, treeStore)
+            elif type(field) == SubFile:
+                stream = field.getSubIStream()
+                treeStore.append(newparent,(None, "dummy", stream))
 
 def resultSearchCb (model, column, key, it):
     """Callback function for searching in treeview"""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.