]> git.lyx.org Git - lyx.git/blob - 3rdparty/evince_sync/evince_sync_lyx
Scripts for connecting LyX with evince for backward/forward search
[lyx.git] / 3rdparty / evince_sync / evince_sync_lyx
1 #!/usr/bin/python
2
3 # Copyright (C) 2010 Jose Aliste <jose.aliste@gmail.com>
4 #               2011 Benjamin Kellermann <Benjamin.Kellermann@tu-dresden.de>
5 #
6 # Translated from Bash to Python by Juergen Spitzmueller <spitz@lyx.org> 2017.
7 #
8 # This program is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public Licence as published by the Free Software
10 # Foundation; either version 2 of the Licence, or (at your option) any later
11 # version.
12 #
13 # This program is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 # FOR A PARTICULAR PURPOSE.  See the GNU General Public Licence for more 
16 # details.
17 #
18 # You should have received a copy of the GNU General Public Licence along with
19 # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
20 # Street, Fifth Floor, Boston, MA  02110-1301, USA
21
22 import sys, os.path
23 from subprocess import Popen, call
24
25 editor_cmd = "lyxclient -g %f %l"
26
27 def print_usage():
28     print("Usage: evince_sync_lyx pdf_file")
29     sys.exit(1)
30
31 if len(sys.argv) != 2:
32     print_usage()
33
34 pdf_file = os.path.abspath(sys.argv[1])
35
36 if not os.path.isfile(pdf_file):
37     print_usage()
38
39 synctex_file, ext = os.path.splitext(pdf_file)
40
41 synctex_file += ".synctex.gz"
42
43 SyncTeX = False
44
45 if os.path.isfile(synctex_file):
46     bsproc = Popen(["evince_backward_search", pdf_file, editor_cmd])
47     SyncTeX = True
48
49 vproc = Popen(['evince', pdf_file])
50 vproc.wait()
51
52 if SyncTeX:
53     bsproc.terminate()
54