]> git.lyx.org Git - lyx.git/blob - 3rdparty/evince_sync/evince_sync_lyx
Add forgotten replacement
[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
24
25 # The lyxclient command for backward search
26 editor_cmd = "lyxclient -g %f %l"
27
28 # Check we have (only) one argument
29 if len(sys.argv) != 2:
30     print("Usage: evince_sync_lyx pdf_file")
31     sys.exit(1)
32
33 # Arg 1 is supposed to be the PDF file
34 pdf_file = os.path.abspath(sys.argv[1])
35
36 # Check whether the file exists & is readable
37 if not os.path.isfile(pdf_file):
38     print("%s is not valid/readable PDF file." % pdf_file)
39     sys.exit(1)
40
41 # The accompanying synctex file has the same name than the PDF
42 # but with .synctex.gz extension
43 synctex_file, ext = os.path.splitext(pdf_file)
44 synctex_file += ".synctex.gz"
45
46 # If we have a synctex file, start the evince_backward_search script
47 SyncTeX = False
48 if os.path.isfile(synctex_file):
49     bsproc = Popen(["evince_backward_search", pdf_file, editor_cmd])
50     SyncTeX = True
51
52 # Notwithstanding the previous, start evince and open the PDF
53 vproc = Popen(['evince', pdf_file])
54 vproc.wait()
55
56 # If evince has been closed (hence vproc.wait()), we terminate
57 # the evince_backward_search script (if we have started it)
58 if SyncTeX:
59     bsproc.terminate()
60