Page MenuHomePhabricator

No OneTemporary

diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,29 @@
+pkgname=lt_presentation
+pkgver=1.0
+pkgrel=1
+pkgdesc="A presentation tool for Logitech Presenters"
+arch=(any)
+depends=('python' 'python-evdev' 'python-pyqt4')
+source=(lt_presentation.tar.gz)
+url="http://www.aboehler.at/"
+license=("GPL")
+sha256sums=(SKIP)
+
+build() {
+ cd ${pkgname}
+ msg "Nothing to be done"
+}
+
+package() {
+ mkdir -p "${pkgdir}"/usr/bin
+ mkdir -p "${pkgdir}"/usr/share/applications
+ mkdir -p "${pkgdir}"/usr/lib/udev/rules.d
+ mkdir -p "${pkgdir}"/usr/share/icons
+ cd ${pkgname}
+ install -m755 lt_presentation.py "${pkgdir}"/usr/bin/lt_presentation
+ install -m644 lt_presentation.png "${pkgdir}"/usr/share/icons
+ install -m644 lt_presentation.desktop "${pkgdir}"/usr/share/applications
+ install -m644 12-logitech-usb.rules "${pkgdir}"/usr/lib/udev/rules.d
+}
+
+# vim:set ts=2 sw=2 et:
diff --git a/lt_presentation.desktop b/lt_presentation.desktop
new file mode 100644
--- /dev/null
+++ b/lt_presentation.desktop
@@ -0,0 +1,20 @@
+[Desktop Entry]
+Comment[en_US]=
+Comment=
+Exec=/usr/bin/lt_presentation
+GenericName[en_US]=Logitech Presentation Tool
+GenericName=Logitech Presentation Tool
+Icon=lt_presentation.png
+MimeType=
+Name[en_US]=lt_presentation
+Name=lt_presentation
+NoDisplay=false
+Path=
+StartupNotify=true
+Terminal=false
+Type=Application
+X-DBUS-ServiceName=
+X-DBUS-StartupType=
+X-KDE-SubstituteUID=false
+X-KDE-Username=
+Categories=Utility;Python;
diff --git a/lt_presentation.py b/lt_presentation.py
--- a/lt_presentation.py
+++ b/lt_presentation.py
@@ -1,240 +1,240 @@
#!/usr/bin/env python
# This is lt_presentation
# A simple system tray tool to send LogiTech Presenter events
# directly to the desired presentation tool.
#
# It wraps around Atril, xdotool and wmctrl and requires python-evdev
# to communicate with the Presenter.
#
# Xfce's Presentation Mode is automatically activated and reset whenever
# a presentation is active.
import dbus
import evdev
import subprocess
import sys
import time
from PyQt4.QtCore import QTimer
from PyQt4 import QtGui
DEV_C = "Logitech USB Receiver"
class Manager():
def __init__(self, parent = None):
self.parent = parent
self.timer = QTimer()
self.timer.timeout.connect(self.check_events)
self.process = None
self.device = None
self.wid = None
self.pm_cookie = None
self.presentation_mode = False
self.presentation_active = False
def check_events(self):
if self.process:
if self.process.poll() == None:
try:
for event in self.device.read():
if event.type == evdev.ecodes.EV_KEY:
if event.code == evdev.ecodes.KEY_PAGEUP and event.value == 1:
self.send_key(self.wid, 'Page_Up')
elif event.code == evdev.ecodes.KEY_PAGEDOWN and event.value == 1:
self.send_key(self.wid, 'Page_Down')
elif event.code == evdev.ecodes.KEY_F5 and event.value == 1:
self.send_key(self.wid, 'F5')
elif event.code == evdev.ecodes.KEY_ESC and event.value == 1:
self.send_key(self.wid, 'Escape')
elif event.code == evdev.ecodes.KEY_DOT and event.value == 1:
self.send_key(self.wid, 'b')
except BlockingIOError:
pass
else:
self.stop_presentation()
else:
self.stop_presentation()
def stop_presentation(self):
print('Stopping Presentation')
self.presentation_active = False
self.timer.stop()
try:
self.device.ungrab()
except IOError:
pass
self.device.close()
self.device = None
self.wid = None
pm = dbus.SessionBus().get_object("org.freedesktop.PowerManagement", "/org/freedesktop/PowerManagement/Inhibit")
pm.UnInhibit(self.pm_cookie)
xfc = dbus.SessionBus().get_object('org.xfce.Xfconf', '/org/xfce/Xfconf')
xfc.SetProperty('xfce4-power-manager', '/xfce4-power-manager/presentation-mode', self.presentation_mode)
def check_viewer(self):
ret = subprocess.run(["atril", "--version"], stdout = subprocess.PIPE,
universal_newlines = True)
if ret.returncode == 0:
version = ret.stdout.replace('MATE Document Viewer ', '').replace('\n', '')
return version
else:
return False
def check_xdotool(self):
ret = subprocess.run(["xdotool", "--version"], stdout = subprocess.PIPE,
universal_newlines = True)
if ret.returncode == 0:
version = ret.stdout.replace('xdotool version ', '').replace('\n', '')
return version
else:
return False
def check_wmctrl(self):
ret = subprocess.run(["wmctrl", "--version"], stdout = subprocess.PIPE,
universal_newlines = True)
if ret.returncode == 0:
version = ret.stdout.replace('\n', '')
return version
else:
return False
def find_window_for_pid(self, pid):
print('Looking for window for PID: ' + str(pid))
ret = subprocess.run(["wmctrl", "-l", "-p"], stdout = subprocess.PIPE,
universal_newlines = True)
if ret.returncode == 0:
wpid = 0
wmid = 0
for line in ret.stdout.split('\n'):
args = line.split(' ')
pos = 1
for arg in args:
if arg == '':
continue
if pos == 1:
wmid = arg
elif pos == 3:
wpid = arg
pos += 1
if wpid == str(pid):
return wmid
return False
else:
return False
def get_window(self, pattern):
ret = subprocess.run(["xdotool", "search", "--name", pattern],
stdout = subprocess.PIPE, universal_newlines = True)
if ret.returncode == 0:
return ret.stdout.replace('\n', '')
else:
return False
def get_device(self, devname):
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for dev in devices:
if dev.name == devname:
print('Found device: ', dev.fn)
return dev.fn
return False
def send_key(self, wid, key):
ret = subprocess.run(["xdotool", "key", "--window", wid, key])
return ret.returncode
def startPresentation(self):
print('Start Presentation')
if self.presentation_active:
QtGui.QMessageBox.critical(self.parent, 'Presentation already running!',
'There is already a presentation running.')
return False
device = self.get_device(DEV_C)
if not device:
QtGui.QMessageBox.critical(self.parent, 'Device not found!',
'Could not find presentation remote control')
return False
self.device = evdev.InputDevice(device)
try:
self.device.grab()
except IOError:
QtGui.QMessageBox.critical(self.parent, 'Error grabbing device',
'Could not grab Input device.')
return False
fname = QtGui.QFileDialog.getOpenFileName(self.parent, 'Open file', '', 'PDF (*.pdf)')
self.process = subprocess.Popen(["atril", fname])
# Give Atril some time to show its window
wid = self.find_window_for_pid(self.process.pid)
count = 0
while not wid and count < 10:
time.sleep(0.5)
wid = self.find_window_for_pid(self.process.pid)
count += 1
if not wid:
QtGui.QMessageBox.critical(self.parent, 'Atril not found!',
'Could not fin Atril presentation window in time')
return False
self.wid = wid
print('Found Atril Window: ' + wid)
# Inhibit power management
pm = dbus.SessionBus().get_object("org.freedesktop.PowerManagement", "/org/freedesktop/PowerManagement/Inhibit")
self.pm_cookie = pm.Inhibit("lt_presentation", "Presentation Starting")
xfc = dbus.SessionBus().get_object('org.xfce.Xfconf', '/org/xfce/Xfconf')
self.presentation_mode = xfc.GetProperty('xfce4-power-manager', '/xfce4-power-manager/presentation-mode')
xfc.SetProperty('xfce4-power-manager', '/xfce4-power-manager/presentation-mode', dbus.Boolean(True, variant_level=1))
self.presentation_active = True
self.timer.start(10)
class SystemTrayIcon(QtGui.QSystemTrayIcon):
def __init__(self, icon, m, parent=None):
self.parent = parent
QtGui.QSystemTrayIcon.__init__(self, icon, parent)
menu = QtGui.QMenu(parent)
presentationAction = menu.addAction("Start Presentation...")
presentationAction.triggered.connect(m.startPresentation)
exitAction = menu.addAction("Exit")
exitAction.triggered.connect(QtGui.qApp.quit)
self.setContextMenu(menu)
def main():
app = QtGui.QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False);
w = QtGui.QWidget()
m = Manager(w)
version = m.check_xdotool()
if version:
print('Running on xdotool version ' + version)
else:
QtGui.QMessageBox.critical(w, 'Tool not found', 'Could not find xdotool, will now quit')
sys.exit(1)
atrilVersion = m.check_viewer()
if atrilVersion:
print('Running on Atril version ' + atrilVersion)
else:
QtGui.QMessageBox.critical(w, 'Tool not found', 'Could not find Atril, will now quit')
sys.exit(1)
wmctrlVersion = m.check_wmctrl()
if wmctrlVersion:
print('Running on wmctrl version ' + wmctrlVersion)
else:
QtGui.QMssageBox.critical(w, 'Tool not found', 'Could not find wmctrl, will now quit')
sys.exit(1)
- trayIcon = SystemTrayIcon(QtGui.QIcon("lt_presentation.png"), m, w)
+ trayIcon = SystemTrayIcon(QtGui.QIcon("/usr/share/icons/lt_presentation.png"), m, w)
trayIcon.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

File Metadata

Mime Type
text/x-diff
Expires
Fri, Jan 24, 3:28 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
540452
Default Alt Text
(10 KB)

Event Timeline