-
Notifications
You must be signed in to change notification settings - Fork 6
/
kano-login
executable file
·192 lines (151 loc) · 5.34 KB
/
kano-login
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python
#
# kano-login
#
# Copyright (C) 2014 - 2018 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
"""
kano-login shows the different screens for logging in and registering.
Usage:
kano-login [-r]
kano-login <screen>
kano-login [-o] [-g]
Options:
-h, --help Show this message.
-o, --logout Logout current Kano World user
-g, --registration Remove registration on logout
-r, --register
"""
import os
import sys
import docopt
from gi import require_version
require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
if __name__ == '__main__' and __package__ is None:
DIR_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if DIR_PATH != '/usr':
sys.path.insert(1, DIR_PATH)
LOCALE_PATH = os.path.join(DIR_PATH, 'locale')
else:
LOCALE_PATH = None
import kano_i18n.init
kano_i18n.init.install('kano-profile', LOCALE_PATH)
from kano.gtk3.application_window import ApplicationWindow
from kano.gtk3.apply_styles import apply_styling_to_screen
from kano.gtk3.cursor import attach_cursor_events
from kano_profile_gui.paths import media_dir
from kano_registration_gui.PageControl import PageControl
from kano_login.first_screen import FirstScreen
import kano_profile_gui.components.icons as icons
from kano_login.login import Login
from kano.gtk3.kano_dialog import KanoDialog
from kano_world.config import AUTH_URL
from kano_world.functions import get_email, remove_token, remove_registration
try:
from kano_profile.tracker import Tracker
kanotracker = Tracker()
except:
pass
GObject.threads_init()
class MainWindow(ApplicationWindow):
height = 300
width = 300
def __init__(self, screen="login"):
ApplicationWindow.__init__(self,
'Kano-Login',
self.width,
self.height)
self.set_keep_above(True)
self.connect("delete-event", Gtk.main_quit)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
# This is where we store the user data for the registration.
self.data = {}
self.set_decorated(True)
self.headerbar = HeaderBar(self)
self.set_titlebar(self.headerbar)
self.set_icon_name("kano-world")
css_path = os.path.join(media_dir, "CSS/register.css")
apply_styling_to_screen(css_path)
self.select_screen(screen)
self.show_all()
def select_screen(self, screen):
'''
Routes the user to the correct screen based on what screen is desired.
Args:
screen (str): The screen to switch to. Options "login" or
"register".
'''
if screen == "register":
# Jump to the register/skip/login selection screen
FirstScreen(self)
elif screen == "login":
# Launch the web login screen immediately and exit after
os.system('{} {} {}'.format(FirstScreen.webengine, AUTH_URL, FirstScreen.win_size))
self.main_quit()
def set_data(self, data_label, data):
self._data[data_label] = data
def create_page_control(self, selected_page, back_text, next_text):
'''This returns a widget suitable for controlling the flow between
screens
'''
page_control = PageControl(2, selected_page, back_text, next_text)
page_control.set_margin_bottom(25)
page_control.set_margin_top(25)
return page_control
class HeaderBar(Gtk.Box):
def __init__(self, win):
Gtk.Box.__init__(self)
self.get_style_context().add_class("header_bar")
self.win = win
self.close_button = Gtk.Button()
cross_icon = icons.get_ui_icon("cross")
self.close_button.set_image(cross_icon)
self.close_button.connect("clicked", self.close_window)
self.close_button.get_style_context().add_class("close_button")
attach_cursor_events(self.close_button)
self.pack_end(self.close_button, False, False, 0)
def close_window(self, widget=None):
close_window(self.win)
def close_window(window=None):
kd = KanoDialog(
_("Are you sure?"),
_("You'll miss out on the best features of your Kano"),
[
{
"label": _("Don't close").upper(),
"return_value": "dont-close",
"color": "green"
},
{
"label": _("Close").upper(),
"return_value": "close",
"color": "red"
}
],
parent_window=window
)
response = kd.run()
if response == "close":
Gtk.main_quit()
def main():
args = docopt.docopt(__doc__)
if args['--logout']:
print 'Logging out {}'.format(get_email())
remove_token()
if args['--registration']:
print 'Removing user registration data...'
remove_registration()
sys.exit(0)
if args['--register'] or args['<screen>'] == '3':
MainWindow("register")
else:
MainWindow('login')
Gtk.main()
# FIXME: refresh desktop only when login returns success and in classic mode.
# this will redraw the top-right corner icon to display the new logged_in status
os.system('kdesk -r')
return 0
if __name__ == '__main__':
main()