mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-18 12:11:52 +00:00
e79782c4cc
The scripts have been initially developed by Benjamin Kellermann (2011) as a derivation of gedit-synctex-plugin by José Aliste (https://github.com/jaliste/gedit-synctex-plugin, 2010) and published on https://ubuntuforums.org/showthread.php?t=1716268. The work here is based on a further derivation of this work for Sublime Text LaTeX Tools (https://github.com/SublimeText/LaTeXTools/tree/master/evince). Adaptations for the use with LyX as well as the initial translation of the evince_sync bash script to python have been done by myself. The python code (particularly evince_sync_lyx) needs audit!
73 lines
2.4 KiB
Python
Executable File
73 lines
2.4 KiB
Python
Executable File
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2010 Jose Aliste <jose.aliste@gmail.com>
|
|
# 2011 Benjamin Kellermann <Benjamin.Kellermann@tu-dresden.de>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU General Public Licence as published by the Free Software
|
|
# Foundation; either version 2 of the Licence, or (at your option) any later
|
|
# version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU General Public Licence along with
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
|
# Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
# This file offers forward search for evince.
|
|
from __future__ import print_function
|
|
|
|
import dbus
|
|
import sys
|
|
import os
|
|
import traceback
|
|
|
|
if sys.version_info < (3,):
|
|
from urllib import quote
|
|
else:
|
|
from urllib.parse import quote
|
|
|
|
if __name__ == '__main__':
|
|
def print_usage():
|
|
print('Usage: evince_forward_search pdf_file line_number tex_file')
|
|
sys.exit(1)
|
|
|
|
if len(sys.argv) != 4:
|
|
print_usage()
|
|
try:
|
|
line_number = int(sys.argv[2])
|
|
except ValueError:
|
|
print_usage()
|
|
|
|
pdf_file = os.path.abspath(sys.argv[1])
|
|
line = int(sys.argv[2])
|
|
tex_file = os.path.abspath(sys.argv[3])
|
|
|
|
try:
|
|
bus = dbus.SessionBus()
|
|
daemon = bus.get_object(
|
|
'org.gnome.evince.Daemon', '/org/gnome/evince/Daemon'
|
|
)
|
|
dbus_name = daemon.FindDocument(
|
|
# The PDF file name MUST be URI-encoded
|
|
# RFC 1738: unreserved = alpha | digit | safe | extra
|
|
# safe = "$" | "-" | "_" | "." | "+"
|
|
# extra = "!" | "*" | "'" | "(" | ")" | ","
|
|
'file://' + quote(pdf_file, "/$+!*'(),@=~"),
|
|
True,
|
|
dbus_interface="org.gnome.evince.Daemon"
|
|
)
|
|
window = bus.get_object(dbus_name, '/org/gnome/evince/Window/0')
|
|
window.SyncView(
|
|
tex_file,
|
|
(line_number, 1),
|
|
0, # GDK_CURRENT_TIME constant
|
|
dbus_interface="org.gnome.evince.Window"
|
|
)
|
|
except dbus.DBusException:
|
|
traceback.print_exc()
|