hachoir / hachoir-gtk / hachoir-gtk

#!/usr/bin/env python
import pygtk
import sys
import os
pygtk.require ('2.0') # 2.2 for Clipboard
import gtk.glade
from hachoir_core.cmd_line import unicodeFilename
from hachoir_parser import createParser

UI_FILENAME = os.path.dirname( __file__ ) + "/hachoir.glade"

class Interface:
    def __init__(self, fieldset, filename):
        self.xml = gtk.glade.XML(UI_FILENAME, "main_window")
        self.fieldset = fieldset
        self.table = self.xml.get_widget("table")

        self.xml.get_widget("main_window").set_title("Hachoir - %s" % filename)


    def quit(self):

    def on_quit_activate(self, widget):

    def on_window_destroy(self, widget, data=None):

    def treeview_add_column(self, treeview, name, num):
        col = gtk.TreeViewColumn(name)
        cell = gtk.CellRendererText()
        col.pack_start(cell, True)
        col.add_attribute(cell, 'text', num)
        return num+1

    def display_tree(self, parent):
        treeStore = gtk.TreeStore(str, str)
        self.treeview_add_column(self.table, "name", 0)
        self.treeview_add_column(self.table, "value", 1)

    def fill_tree(self, parent, treeparent, treeStore):
        for field in parent:
            if field.hasValue():
                value = field.display
                #value = field.raw_display
                value = field.description
            newparent = treeStore.append(treeparent,(field.name,value))
            if field.is_field_set:
                self.fill_tree(field, newparent, treeStore)

def resultSearchCb (model, column, key, it):
    """Callback function for searching in treeview"""
    plainText = model.get_value(it, column)

    # if search text contains only lower-case characters, do case-insensitive matching:
    if key.islower():
        plainText = plainText.lower()

    # if the line contains the search text, it matches:
    if plainText.find(key) >= 0:
        return False

    # line doesn't match:
    return True

#import cProfile
# import profile

def main():
    if(len(sys.argv)!=2 ):
        print "usage: %s file" %sys.argv[0]
    filename = sys.argv[1]

    # Create parser
    filename, realname = unicodeFilename(filename), filename
    fieldset = createParser(filename, realname)

    # test if there is a least one tree
    if  fieldset is  None :
        print "No fields to display in this file. This is probably a text file."

    # Create window and gtk event loop
    interface = Interface(fieldset, filename)

if __name__ == "__main__":
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.