button press have no effect

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

button press have no effect

Pablo Rodríguez
Hi there,

I have an old code that I don’t remember very well. (Sample included below.)

Everything works fine, but I need to implement a button_press_event().
This part doesn’t work at all.

As far as I can remember, this should work.

Would anyone be so kind to point me to my mistake?

Many thanks for your help,


Pablo



import gnomevfs
import gtk
import pygtk
try:
    import poppler
except:
    print "poppler is not available"
import sys
import cairo
import gtk.glade

class rec_presentation:
    def __init__(self):

        uri = gnomevfs.make_uri_from_shell_arg(sys.argv[1])

        self.filename = sys.argv[1]

        self.document = poppler.document_new_from_file (uri, None)
        self.n_pages = self.document.get_n_pages()
        self.page_selector = self.document.get_page(0)
        self.current_page = 0

        self.gui = gtk.glade.XML("recslides.glade","mainwindow",
domain="recslides")
        self.win = self.gui.get_widget("mainwindow")
        self.area = self.gui.get_widget("pdfdocument_area")
        self.gui.signal_autoconnect(self)
        self.win.add_events(gtk.gdk.BUTTON_PRESS_MASK)

        self.width, self.height = self.win.get_size()
        self.page_width, self.page_height= self.page_selector.get_size()

        self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24,
                                          int(self.width),
                                          int(self.height))

        black = gtk.gdk.color_parse("black")
        self.area.modify_bg(gtk.STATE_NORMAL, black)
        self.area.set_size_request(int(self.width), int(self.height))

        self.win.show_all()

    def button_press_event(self, widget, event):
        if event.button == 1:
            print 'Clicked at x={0}, y={0}'.format(event.x, event.y)

        self.win.connect('button-press-event', button_press_event)

    def on_expose_event(self, widget, event):
        add_x = 0
        add_y = 0

        if (self.area.allocation.width/self.page_width) <
(self.area.allocation.height/self.page_height):
            self.scale = self.area.allocation.width/self.page_width
        else:
            self.scale = self.area.allocation.height/self.page_height

        if (self.area.allocation.width/self.page_width) >
(self.area.allocation.height/self.page_height):
            add_x=
int(((self.area.allocation.width-(self.page_width*self.scale))/2)/self.scale)
        else:
            add_y=
int(((self.area.allocation.height-(self.page_height*self.scale))/2)/self.scale)

        cr = widget.window.cairo_create()
        cr.set_source_surface(self.surface)
        cr.set_source_rgb(1, 1, 1)

        if self.scale != 1:
            cr.scale(self.scale, self.scale)

        cr.translate(add_x, add_y)
        cr.rectangle(0, 0, self.page_width, self.page_height)
        cr.fill()
        self.page_selector.render(cr)

    def gtk_main_quit(self, widget, event):
        gtk.main_quit()

    def main(self):
        gtk.main()


rec = rec_presentation()
rec.main()

--
http://www.ousia.tk
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/