-
Notifications
You must be signed in to change notification settings - Fork 4
/
gokien_welcome.py
executable file
·102 lines (87 loc) · 2.92 KB
/
gokien_welcome.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
#!/usr/bin/env python
import sys
import os
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import QWebView
import string as String
import xdg.IconTheme
import logging
from gi.repository import Gio
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
HTML_DIR = os.path.join(ROOT_DIR, 'templates/') # Don't forget the last slash
HTML_PATH = os.path.join(ROOT_DIR, 'templates/welcome.html')
def _(string):
"""
Placeholder for GNU gettext
"""
return string
class WelcomeSreen(QWebView):
def __init__(self, app, width, height):
QWebView.__init__(self)
self.app = app
self._html = self._parse_html(HTML_PATH)
self.setHtml(self._html, baseUrl=QUrl('file://' + HTML_DIR))
self.setFixedSize(width, height)
# Move to the center
screen_geometry = app.desktop().screenGeometry()
self.move((screen_geometry.width() - width) / 2,
(screen_geometry.height() - height) / 2)
# Remove the border
self.setWindowFlags(Qt.FramelessWindowHint)
# Handle event titleChanged
self.titleChanged.connect(self._title_changed)
def _parse_html(self, file_path):
"""
Parse the template file and return the resultant content
"""
subs = {
"title": _('Welcome to GokienOS'),
"show": _('Open this dialog in the next startup'),
"close": _('Close'),
"working": _('Working'),
"document": _('Document'),
"spreadsheet": _('Spreadsheet'),
"presentation": _('Presentation'),
"networking": _('Networking'),
"web_browser": _('Web Browser'),
"chat": _('Chat'),
"extra": _('Extra'),
"help": _('Help')
}
apps = [
'firefox',
'empathy',
'libreoffice-writer',
"libreoffice-writer",
"libreoffice-calc",
"libreoffice-impress",
"help"
]
s = Gio.Settings.new('org.gnome.desktop.interface')
theme = s.get_string('icon-theme')
for app in apps:
# TODO Determine current theme
subs['icon_' + app.replace('-', '_')] = \
xdg.IconTheme.getIconPath(app, theme=theme)
template = open(file_path, 'r').read()
html = String.Template(template).safe_substitute(subs)
logging.debug(html)
return html
def _title_changed(self, title):
"""
Handle the signal titleChanged
"""
if title == 'close':
self.app.exit()
else:
os.system(title)
print(title)
def main(sys_argv):
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
app = QApplication(sys_argv)
gokien_welcome_screen = WelcomeSreen(app, 654, 350)
gokien_welcome_screen.show()
app.exec_()
if __name__ == '__main__':
main(sys.argv)