2 # -*- coding: utf-8 -*-
4 # Copyright (C) 2010 Jose Aliste <jose.aliste@gmail.com>
5 # 2011 Benjamin Kellermann <Benjamin.Kellermann@tu-dresden.de>
7 # This program is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public Licence as published by the Free Software
9 # Foundation; either version 2 of the Licence, or (at your option) any later
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more
17 # You should have received a copy of the GNU General Public Licence along with
18 # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 # Street, Fifth Floor, Boston, MA 02110-1301, USA
21 # This file offers forward search for evince.
22 from __future__ import print_function
29 if sys.version_info < (3,):
30 from urllib import quote
32 from urllib.parse import quote
34 if __name__ == '__main__':
36 print('Usage: evince_forward_search pdf_file line_number tex_file')
39 if len(sys.argv) != 4:
42 line_number = int(sys.argv[2])
46 pdf_file = os.path.abspath(sys.argv[1])
47 line = int(sys.argv[2])
48 tex_file = os.path.abspath(sys.argv[3])
51 bus = dbus.SessionBus()
52 daemon = bus.get_object(
53 'org.gnome.evince.Daemon', '/org/gnome/evince/Daemon'
55 dbus_name = daemon.FindDocument(
56 # The PDF file name MUST be URI-encoded
57 # RFC 1738: unreserved = alpha | digit | safe | extra
58 # safe = "$" | "-" | "_" | "." | "+"
59 # extra = "!" | "*" | "'" | "(" | ")" | ","
60 'file://' + quote(pdf_file, "/$+!*'(),@=~"),
62 dbus_interface="org.gnome.evince.Daemon"
64 window = bus.get_object(dbus_name, '/org/gnome/evince/Window/0')
68 0, # GDK_CURRENT_TIME constant
69 dbus_interface="org.gnome.evince.Window"
71 except dbus.DBusException: