예제 #1
0
    def __init__(self):
        """
        Create the GTK window
        """
        self.images = []
        self.image_index = 0

        self.svg_viewer = SVGViewer()

        screen = gtk.ScrolledWindow()
        screen.add_with_viewport(self.svg_viewer)
        # This makes large graph to expand window outside of screen
        #        svg_reqx, svg_reqy = self.svg_viewer.size_request()
        #        screen.set_size_request(svg_reqx, svg_reqy)
        #        print "screen says: ", screen.size_request()

        self.pos_label = gtk.Label(" -- / -- ")
        self.b_prev = gtk.Button("< Previous")
        self.b_prev.connect("clicked", self.change_image, True)
        self.button = gtk.Button("Next >")
        self.button.connect("clicked", self.change_image, None)

        h_box = gtk.HBox(homogeneous=False, spacing=0)
        h_box.pack_start(self.pos_label, expand=False, fill=False, padding=4)
        h_box.pack_start(self.b_prev, expand=False, fill=False, padding=4)
        h_box.pack_start(self.button, expand=False, fill=False, padding=4)

        v_box = gtk.VBox(homogeneous=False, spacing=0)
        v_box.pack_start(screen, expand=True, fill=True, padding=0)
        v_box.pack_start(h_box, expand=False, fill=False, padding=4)

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", gtk.main_quit)
        self.window.add(v_box)
        self.window.maximize()
        self.window.set_size_request(300, 200)  # Allows some space to see at least a part of the graph when demaximized
        self.window.show_all()
예제 #2
0
class Test(object):
    """
    Shows a window with several graph pictures to test
    """

    def __init__(self):
        """
        Create the GTK window
        """
        self.images = []
        self.image_index = 0

        self.svg_viewer = SVGViewer()

        screen = gtk.ScrolledWindow()
        screen.add_with_viewport(self.svg_viewer)
        # This makes large graph to expand window outside of screen
        #        svg_reqx, svg_reqy = self.svg_viewer.size_request()
        #        screen.set_size_request(svg_reqx, svg_reqy)
        #        print "screen says: ", screen.size_request()

        self.pos_label = gtk.Label(" -- / -- ")
        self.b_prev = gtk.Button("< Previous")
        self.b_prev.connect("clicked", self.change_image, True)
        self.button = gtk.Button("Next >")
        self.button.connect("clicked", self.change_image, None)

        h_box = gtk.HBox(homogeneous=False, spacing=0)
        h_box.pack_start(self.pos_label, expand=False, fill=False, padding=4)
        h_box.pack_start(self.b_prev, expand=False, fill=False, padding=4)
        h_box.pack_start(self.button, expand=False, fill=False, padding=4)

        v_box = gtk.VBox(homogeneous=False, spacing=0)
        v_box.pack_start(screen, expand=True, fill=True, padding=0)
        v_box.pack_start(h_box, expand=False, fill=False, padding=4)

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", gtk.main_quit)
        self.window.add(v_box)
        self.window.maximize()
        self.window.set_size_request(300, 200)  # Allows some space to see at least a part of the graph when demaximized
        self.window.show_all()

    def delete_event(self, widget, event, data=None):
        """ Close window """
        return False

    def add_image(self, image):
        self.images.append(image)
        self.svg_viewer.update_svg(self.images[self.image_index])

    def change_image(self, widget, data=None):
        """
        Toggles to previous or next image
        """
        if data:
            self.image_index = (self.image_index - 1) % len(self.images)
        else:
            self.image_index = (self.image_index + 1) % len(self.images)
        self.svg_viewer.update_svg(self.images[self.image_index])
        self.pos_label.set_text(str(self.image_index + 1) + " / " + str(len(self.images)))