-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameplay.py
executable file
·158 lines (129 loc) · 5.23 KB
/
gameplay.py
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
"""
Game✜Play - Yet Another Gamepad Launcher
A Python and PyQt5 based application launcher that uses
HTML5's gamepad API to implement a platform independent
UI that can be controlled via keyboard, mouse and
gamepad/joystick.
Author: Roland Tapken <[email protected]>
License: GPLv3
"""
import os
import sys
from importlib import util
def find_preferred_engine():
if util.find_spec("PyQt5.QtWebKit") is not None:
return 'webkit'
elif util.find_spec("PyQt5.QtWebEngineWidgets") is not None:
return 'webengine'
return None
# Requires at least Python 3.4
if sys.version_info < (3,4):
sys.stderr.write("This program requires at least Python 3.4, found version %d.%d.%d%s" % (
sys.version_info[0], sys.version_info[1], sys.version_info[2], os.linesep
))
sys.exit(1)
# Check for PyQt5 before loading it to create a nice error message if this is missing
if util.find_spec("PyQt5") is None:
sys.stderr.write("Module PyQt5 not found. Maybe you need to install 'python3-pyqt5'.%s" % os.linesep)
sys.exit(1)
if find_preferred_engine() is None:
sys.stderr.write("Neither module 'PyQt5.QtWebKit' nor 'PyQt5.QtWebEngineWidgets' found. Maybe you need to install 'python3-pyqt5.qtwebkit'.%s" % os.linesep)
sys.exit(1)
if util.find_spec("psutil") is None:
sys.stderr.write("Module 'psutil' not found. Maybe you need to install 'python3-psutil'.%s" % os.linesep)
sys.exit(1)
import argparse
import signal
import logging
from PyQt5.Qt import Qt
from PyQt5.QtCore import QDir, QStandardPaths
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon
# Automatically convert between python strings and QString
import sip
sip.setapi('QString', 2)
def do_list_config(name, config):
print('Search paths for %s' % name)
for path in config.search_paths:
if os.path.exists(path):
print("\t# %s" % path)
else:
print("\t# %s (missing)" % path)
print("\t#")
print("\t# Cumulated configuration:")
for s in config.sections():
print("\t[%s]" % s)
for c in config.options(s):
print("\t%s = %s" % (c, config.get(s, c)))
print()
def do_list_apps(name, provider):
print("Apps found by provider '%s':" % name)
for app in provider.get_apps():
print("\t[%s]" % app.id)
for k, v in app.__dict__.items():
if not k.startswith('_'):
print("\t%s = %s" % (k, v))
print()
def main():
basepath=QDir.fromNativeSeparators(os.path.dirname(os.path.abspath(__file__))) + '/ui/'
# Define and parse program arguments
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="be verbose", action="store_true")
parser.add_argument("-d", "--debug", help="be even verboser", action="store_true")
parser.add_argument("-f", "--fullscreen", help="start in fullscreen mode", action="store_true")
parser.add_argument("-s", "--stayontop", help="stay on top (while not running any apps)", action="store_true")
parser.add_argument("-e", "--engine", help="browser engine that should be used ('webkit', 'webengine')", choices=['webkit', 'webengine'], default=find_preferred_engine())
parser.add_argument("-r", "--docroot", help="Document root of UI files (default: %s)" % (basepath), default=basepath)
parser.add_argument("--list-config", help="Show what configuration files are loaded on startup", action="store_true")
parser.add_argument("--list-apps", help="Show what apps where found by each application provider", action="store_true")
args = parser.parse_args()
# Ensure that the given document root ends with /
args.docroot = os.path.abspath(args.docroot) + os.sep
if not os.path.exists(args.docroot):
sys.stderr.write("Document root not found: '%s'%s" % (args.docroot, os.linesep))
sys.exit(1)
# This must be configured before any logger is initialized
if args.debug:
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
elif args.verbose:
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
else:
logging.basicConfig(stream=sys.stdout, level=logging.WARN)
LOGGER = logging.getLogger(__name__)
# This must be imported AFTER logging has been configured!
from gameplay import GamePlay
from gameplay import Frontend
# Import Engine package before QCore is instanceated
if args.engine == 'webkit':
from gameplay.platform.WebkitWebView import WebView, Inspector
else:
from gameplay.platform.WebengineWebView import WebView, Inspector
# Start application (and ensure it can be killed with CTRL-C)
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = QApplication(sys.argv)
app.setApplicationName('gameplay')
app.setWindowIcon(QIcon(args.docroot + 'img' + os.sep + 'Y.svg'))
gameplay = GamePlay()
if args.list_config or args.list_apps:
if args.list_config:
do_list_config('gameplay.ini', gameplay.settings)
do_list_config('emulators.ini', gameplay.providers['emulators'].emulatorIni)
if args.list_apps:
for key, provider in gameplay.providers.items():
do_list_apps(key, provider)
return
# Initialize frontend
frontend = Frontend(args, gameplay)
if args.stayontop:
LOGGER.info('Enable WindowStayOnTop')
frontend.setWindowFlags(int(frontend.windowFlags()) | Qt.WindowStaysOnTopHint)
if args.fullscreen:
LOGGER.info('Fullscreen mode')
frontend.showFullScreen()
else:
frontend.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
# vim: set fenc=utf-8 ts=4 sw=4 noet :