forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qpreso
executable file
·90 lines (65 loc) · 2.68 KB
/
qpreso
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# Copyright (C) 2018 by Akkana Peck.
# Share and enjoy under the GPL v2 or later.
"""Viewer for HTML presentations."""
import sys
import os
import argparse
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QShortcut, QDesktopWidget
from PyQt5.QtWebEngineWidgets import QWebEngineView
class PresoView(QWebEngineView):
def __init__(self, url, zoom=1.0, show_notes=True):
super(PresoView, self).__init__()
# Are we making screenshots? TODO: make this a command-line param.
self.make_screenshots = False
self.imgnum = 0
# Size the audience will see (used for converting to images):
displaysize = QDesktopWidget().screenGeometry(-1)
self.displaywidth = displaysize.width()
self.displayheight = displaysize.height()
# Size of the window we'll actually display:
if show_notes:
self.fullwidth = 1366
else:
self.fullwidth = 1024
self.fullheight = 768
if zoom != 1.0 :
self.displaywidth = int(self.displaywidth * zoom)
self.displayheight = int(self.displayheight * zoom)
self.fullwidth = int(self.fullwidth * zoom)
self.fullheight = int(self.fullheight * zoom)
print("Display size: %d x %d" % (self.displaywidth,
self.displayheight))
print("Full size: %d x %d" % (self.fullwidth,
self.fullheight))
# Run fullscreen if the display is XGA or smaller.
# displaysize = QApplication.desktop.screenGeometry()
if self.displayheight <= 768:
self.showFullScreen()
# Key bindings
# For keys like function keys, use QtGui.QKeySequence("F12")
QShortcut("Ctrl+Q", self, activated=self.close)
QShortcut("Ctrl+R", self, activated=self.reload)
QShortcut("Alt+Left", self, activated=self.back)
QShortcut("Alt+Right", self, activated=self.forward)
self.resize(self.fullwidth, self.fullheight)
self.load(QUrl.fromUserInput(url))
def parse_args():
"""Parse commandline arguments."""
parser = argparse.ArgumentParser()
parser.add_argument('url', help='The URL to open')
args = parser.parse_known_args()[0]
# Figure out if the url is a filename or a url
if args.url.find(':') < 0 :
if args.url[0] == '/' :
args.url = 'file://' + args.url
else :
args.url = 'file://' + os.getcwd() + '/' + args.url
return args
if __name__ == '__main__':
args = parse_args()
app = QApplication(sys.argv)
pv = PresoView(args.url)
pv.show()
app.exec_()