forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqpreso
More file actions
executable file
·112 lines (84 loc) · 3.66 KB
/
qpreso
File metadata and controls
executable file
·112 lines (84 loc) · 3.66 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/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, fullscreen=False, monitor=-1,
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))
if monitor >= 0:
# The number of the monitor where the window should show up
screens = app.screens()
print("screens:", screens)
if monitor > len(screens):
print("There is no monitor", monitor)
sys.exit(1)
geom = screens[monitor].geometry()
self.move(geom.left(), geom.top())
self.showFullScreen()
else:
# Run fullscreen if the display is XGA or smaller,
# or if fullscreen was explicitly set.
# displaysize = QApplication.desktop.screenGeometry()
if fullscreen or 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('-f', "--fullscreen", dest="fullscreen", default=False,
action="store_true",
help="Run fullscreen regardless of screen size")
parser.add_argument('-m', '--monitor', action="store", default=-1,
dest="monitor", type=int,
help='Run fullscreen on this monitor')
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, fullscreen=args.fullscreen, monitor=args.monitor)
pv.show()
app.exec_()