Beispiel #1
0
def main():
    for arg in sys.argv[1:]:
        sys.stdout.write(arg + '\n')
        sys.stdout.flush()
        name, ext = os.path.splitext(os.path.basename(arg))
        dotcode = open(arg, 'rb').read()
        widget = TestDotWidget(name)
        window = DotWindow(widget)
        window.connect('delete-event', Gtk.main_quit)
        try:
            window.set_dotcode(dotcode)
        except:
            exc_info = sys.exc_info()
            traceback.print_exception(*exc_info)
            continue
        try:
            window.show()
            Gtk.main()
        finally:
            window.destroy()
Beispiel #2
0
def showDotInXDot(buf):
    try:
        import gtk, thread
        from xdot import DotWindow

        win = DotWindow()
        win.connect('destroy', Gtk.main_quit)
        win.set_filter("dot")
        win.set_dotcode(buf)
        try:
            thread.start_new_thread(Gtk.main, None)
        except:
            pass
    except ImportError:
        print "Python-GTK is not installed"
Beispiel #3
0
def showDotInXDot(buf):
    try:    
        import gtk, thread
        from xdot import DotWindow
        
        win = DotWindow()
        win.connect('destroy', gtk.main_quit)
        win.set_filter("dot")
        win.set_dotcode(buf)
        try:
            thread.start_new_thread(gtk.main, None)
        except:
            pass
    except ImportError:
        print "Python-GTK is not installed"
Beispiel #4
0
 def _on_show_tree(self, *args):
     dotfile = self.pipeline_launcher.dump_dot_file()
     if dotfile:
         from xdot import DotWindow
         dotwindow = DotWindow()
         dotwindow.open_file(dotfile)
Beispiel #5
0
def test(arg):
    sys.stdout.write(arg + '\n')
    sys.stdout.flush()

    import gi
    gi.require_version('Gtk', '3.0')

    from gi.repository import Gtk
    from gi.repository import Gdk

    from xdot import DotWidget, DotWindow

    class TestDotWidget(DotWidget):
        def __init__(self, name):
            DotWidget.__init__(self)
            self.name = name

        def on_draw(self, widget, cr):
            DotWidget.on_draw(self, widget, cr)

            if True:
                # Cairo screenshot

                import cairo

                # Scale to give 96 dpi instead of 72 dpi
                dpi = 96.0
                scale = dpi / 72.0
                w = int(self.graph.width * scale)
                h = int(self.graph.height * scale)

                CAIRO_XMAX = 32767
                CAIRO_YMAX = 32767
                if w >= CAIRO_XMAX:
                    w = CAIRO_XMAX
                    scale = w / self.graph.width
                    h = int(self.graph.height * scale)
                if h >= CAIRO_YMAX:
                    h = CAIRO_YMAX
                    scale = h / self.graph.height
                    w = int(self.graph.width * scale)

                assert w <= CAIRO_XMAX
                assert h <= CAIRO_YMAX

                surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)

                cr = cairo.Context(surface)

                cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
                cr.paint()

                cr.scale(scale, scale)

                self.graph.draw(cr, highlight_items=self.highlight)

                surface.write_to_png(self.name + '.png')

            if False:
                # GTK 3 screenshot

                window = self.get_window()

                w = window.get_width()
                h = window.get_height()

                pixbuf = Gdk.pixbuf_get_from_window(window, 0, 0, w, h)

                pixbuf.savev(self.name + '.png', 'png', (), ())

            Gtk.main_quit()

        def error_dialog(self, message):
            sys.stderr.write(message)
            sys.stderr.write("\n")

    result = True

    name, ext = os.path.splitext(os.path.basename(arg))
    widget = TestDotWidget(name)
    window = DotWindow(widget)
    window.connect('delete-event', Gtk.main_quit)
    try:
        try:
            dotcode = open(arg, 'rb').read()
            window.set_dotcode(dotcode)
        except:
            exc_info = sys.exc_info()
            traceback.print_exception(*exc_info)
            result = False
        else:
            window.show()
            Gtk.main()
    finally:
        window.destroy()

    return result
Beispiel #6
0
def test(arg):
    sys.stdout.write(arg + '\n')
    sys.stdout.flush()


    import gi
    gi.require_version('Gtk', '3.0')

    from gi.repository import Gtk
    from gi.repository import Gdk

    from xdot import DotWidget, DotWindow


    class TestDotWidget(DotWidget):

        def __init__(self, name):
            DotWidget.__init__(self)
            self.name = name

        def on_draw(self, widget, cr):
            DotWidget.on_draw(self, widget, cr)

            if True:
                # Cairo screenshot

                import cairo

                # Scale to give 96 dpi instead of 72 dpi
                dpi = 96.0
                scale = dpi/72.0
                w = int(self.graph.width*scale)
                h = int(self.graph.height*scale)

                CAIRO_XMAX = 32767
                CAIRO_YMAX = 32767
                if w >= CAIRO_XMAX:
                    w = CAIRO_XMAX
                    scale = w/self.graph.width
                    h = int(self.graph.height*scale)
                if h >= CAIRO_YMAX:
                    h = CAIRO_YMAX
                    scale = h/self.graph.height
                    w = int(self.graph.width*scale)

                assert w <= CAIRO_XMAX
                assert h <= CAIRO_YMAX

                surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)

                cr = cairo.Context(surface)

                cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
                cr.paint()

                cr.scale(scale, scale)

                self.graph.draw(cr, highlight_items=self.highlight)

                surface.write_to_png(self.name + '.png')

            if False:
                # GTK 3 screenshot

                window = self.get_window()

                w = window.get_width()
                h = window.get_height()

                pixbuf = Gdk.pixbuf_get_from_window(window, 0, 0, w, h)

                pixbuf.savev(self.name + '.png', 'png', (), ())

            Gtk.main_quit()

        def error_dialog(self, message):
            sys.stderr.write(message)
            sys.stderr.write("\n")


    result = True

    name, ext = os.path.splitext(os.path.basename(arg))
    widget = TestDotWidget(name)
    window = DotWindow(widget)
    window.connect('delete-event', Gtk.main_quit)
    try:
        try:
            dotcode = open(arg, 'rb').read()
            window.set_dotcode(dotcode)
        except:
            exc_info = sys.exc_info()
            traceback.print_exception(*exc_info)
            result = False
        else:
            window.show()
            Gtk.main()
    finally:
        window.destroy()

    return result