Exemple #1
0
def display_dot(Gdot):
    win = xdot.DotWindow()
    win.connect('destroy', gtk.main_quit)
    win.set_filter('dot')
    fname = '.dot'
    Gdot.write(fname, format='dot')
    win.open_file(fname)
    gtk.main()
Exemple #2
0
def view_asm(start=None, end=None, ep=None):
    """
    Display a CFG of the microcode discovered til then.

    This function display a CFG of the microcode that have been run
    through til then. It uses the xdot application to visualize the
    CFG as a DOT graph.

    Parameters:
    - start : set the address of the starting node (entrypoint if None)
    - end   : set the address of an end node (no end node if None)
    - ep    : set the entry point address
    """
    def reset_viewer(arg):
        global dotviewer
        dotviewer = None

    def basic_block_clicked(widget, nodeid, url, event):
        if nodeid is None:
            return False
        return True

    import gtk.keysyms

    def key_pressed_event(widget, event):
        global simulator, startpoint, dotviewer
        if event.keyval == gtk.keysyms.s:
            step()
            return True
        if event.keyval == gtk.keysyms.r:
            run()
            return True
        if event.keyval == gtk.keysyms.c:
            cont()
            return True
        return False

    global simulator, startpoint, dotviewer
    if simulator is None:
        print "Program is not started"
        return
    addrspace = simulator.get_microcode().get_range()
    if start is None:
        start = addrspace[0]
    if end is None:
        end = addrspace[1]
    if ep is None:
        ep = pc()
    dotstring = simulator.get_microcode().dot(ep, start, end)
    if dotviewer is None:
        dotviewer = xdot.DotWindow()
        dotviewer.connect('destroy', reset_viewer)
        dotviewer.widget.connect('clicked', basic_block_clicked)
        dotviewer.widget.connect('key-press-event', key_pressed_event)
        dotviewer.show()
    dotviewer.set_dotcode(dotstring)
Exemple #3
0
def show_graph(dotdata, title="xdot viewer"):
    import gtk
    import gtk.gdk
    import xdot

    window = xdot.DotWindow()
    window.set_dotcode(dotdata)
    window.connect('destroy', gtk.main_quit)
    window.set_title(title)
    gtk.main()
Exemple #4
0
def show_graph(g, package=0):
    drawable = False
    g.write('}')
    if len(g.getvalue()) > 26:
        drawable = True
        window = xdot.DotWindow()
        window.set_dotcode(g.getvalue())
        if package:
            window.set_title('Package {0}'.format(package))
        window.connect('destroy', gtk.main_quit)
    g.close()
    return drawable
Exemple #5
0
def main():
    args = handle_args()
    if getattr(sys, 'frozen', False):
        basedir = sys._MEIPASS
    else:
        basedir = os.getcwd()

    if args.filename is None:
        filename, ignore_list = choose_file()
    else:
        filename = args.filename
        ignore_list = args.ignore_list

    path, filename = split(filename)

    if ignore_list is None:
        ignore_list = []

    os.chdir(path)
    try:
        xmltree = compile_game_to_xml(filename)

    except Exception as e:
        alangrapher_utils.message_dialog(
            "Could not compile to XML!",
            "Do you have an Alan compiler installed "
            "and in the system PATH?\n" + str(e))
        sys.exit(-1)

    location_list = get_locations(xmltree, ignore_list)
    start_location = xmltree.getElementsByTagName(
        "start")[0].attributes['WHERE'].value
    dotcode = init_output(os.path.basename(filename), args.shape)
    for l in location_list:
        name = l.attributes['NAME'].value
        dotcode += "\n    {}    \n".format(
            dot_for_location_header(l, start_location))
        xs = get_exits(l, ignore_list)
        for x in xs:
            dotcode += "      {}\n".format(dot_for_exit(name, x))
    dotcode += terminate_output()

    try:
        window = xdot.DotWindow()
        window.set_dotcode(dotcode)
        window.connect('destroy', gtk.main_quit)
        gtk.main()
    except Exception as e:
        alangrapher_utils.message_dialog(
            "Could not draw graph!",
            "Do you have Graphviz (http://graphviz.org/)\n"
            "installed and in the system PATH?")
        sys.exit(-1)
Exemple #6
0
 def __init__(self, window, model, node_attr, arrow_attr, attrs, screen):
     self.glade = gtk.glade.XML(common.terp_path("openerp.glade"),
                                'widget_view_diagram', gettext.textdomain())
     self.widget = self.glade.get_widget('widget_view_diagram')
     self.model = model
     self.screen = screen
     self.node = node_attr
     self.arrow = arrow_attr
     self.id = None
     if self.screen.current_model:
         self.id = screen.current_model.id
     self.window = xdot.DotWindow(window, self.widget, self.screen,
                                  node_attr, arrow_attr, attrs)
     self.draw_diagram()
Exemple #7
0
 def draw(self,
          colors=None,
          shapes=None,
          start=None,
          window_header=None,
          file_prefix=None):
     if file_prefix is not None:
         self.draw_to_pdf(file_prefix + str(len(self.windows)) + ".pdf",
                          colors, shapes, start, window_header)
         self.windows.append("kek")
     else:
         win = xdot.DotWindow()
         win.set_dotcode(
             bytes(
                 self.dot_str(colors, shapes, start, window_header
                              or len(self.windows)), 'utf-8'))
         self.windows.append(win)
def view_plasm(plasm, title):
    try:
        saveit = sys.argv
        sys.argv = [sys.argv[0]]
        try:
            import gtk
            import xdot
        except ImportError, e:
            print e
            print "view_plasm requires gobject gtk graphviz, possibly more to run..."
            return
        if title is not None:
            # DotWindow doesn't have api for setting the title
            # Could also access the internal variable afterwards and re-show, but this avoids re-showing.
            xdot.DotWindow.base_title = title
        window = xdot.DotWindow()
        x = plasm.viz()
        window.set_dotcode(x)
        window.connect('destroy', gtk.main_quit)
        gtk.main()
        sys.argv = saveit
Exemple #9
0
def view_mc(ep=None):
    """
    Parameters:
    - ep    : set the entry point address
    """
    def reset_viewer(arg):
        global dotviewer
        dotviewer = None

    global simulator, startpoint, dotviewer
    if simulator is None:
        print "Program is not started"
        return
    if ep is None:
        ep = startpoint
    dotstring = simulator.get_microcode().cfg(start=ep)
    if dotviewer is None:
        dotviewer = xdot.DotWindow()
        dotviewer.connect('destroy', reset_viewer)
        dotviewer.show()
    dotviewer.set_dotcode(dotstring)
Exemple #10
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.graph = nx.DiGraph(name="my_tree")
     self.xdot = xdot.DotWindow()
     self.xdot.connect('destroy', gtk.main_quit)
Exemple #11
0
def list_cells(pymodule):
    l = []
    for x in dir(pymodule):
        mod = getattr(pymodule, x)
        if inspect.isclass(mod) and getattr(mod, '__looks_like_a_cell__',
                                            False):
            l.append(mod)
    return l


list_ecto_module = list_cells


def view_plasm(plasm):
    saveit = sys.argv
    sys.argv = [sys.argv[0]]
    try:
        import gtk
        import xdot
    except ImportError, e:
        print e
        print "view_plasm requires gobject gtk graphviz, possibly more to run..."
        return
    window = xdot.DotWindow()
    x = plasm.viz()
    window.set_dotcode(x)
    window.connect('destroy', gtk.main_quit)
    gtk.main()
    sys.argv = saveit