1
|
|
|
# |
2
|
|
|
# Copyright 2001 - 2018 Ludek Smid [http://www.ospace.net/] |
3
|
|
|
# |
4
|
|
|
# This file is part of Outer Space. |
5
|
|
|
# |
6
|
|
|
# Outer Space is free software; you can redistribute it and/or modify |
7
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
9
|
|
|
# (at your option) any later version. |
10
|
|
|
# |
11
|
|
|
# Outer Space is distributed in the hope that it will be useful, |
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
# GNU General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
# along with Outer Space; if not, write to the Free Software |
18
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19
|
|
|
# |
20
|
|
|
|
21
|
|
|
import pygameui as ui |
22
|
|
|
from osci import gdata |
23
|
|
|
|
24
|
|
View Code Duplication |
class PasswordDlg: |
|
|
|
|
25
|
|
|
|
26
|
|
|
def __init__(self, app, hide): |
27
|
|
|
self.app = app |
28
|
|
|
self.createUI() |
29
|
|
|
if hide: |
30
|
|
|
self.win.vPassword.showChar = '*' |
31
|
|
|
|
32
|
|
|
def display(self, confirmAction): |
33
|
|
|
self.confirmAction = confirmAction |
34
|
|
|
self.win.show() |
35
|
|
|
self.app.setFocus(self.win.vPassword) |
36
|
|
|
# register for updates |
37
|
|
|
if self not in gdata.updateDlgs: |
38
|
|
|
gdata.updateDlgs.append(self) |
39
|
|
|
|
40
|
|
|
def hide(self): |
41
|
|
|
self.win.setStatus(_("Ready.")) |
42
|
|
|
self.win.hide() |
43
|
|
|
# unregister updates |
44
|
|
|
if self in gdata.updateDlgs: |
45
|
|
|
gdata.updateDlgs.remove(self) |
46
|
|
|
|
47
|
|
|
def update(self): |
48
|
|
|
self.show() |
49
|
|
|
|
50
|
|
|
def onOK(self, widget, action, data): |
51
|
|
|
self.password = self.win.vPassword.text |
52
|
|
|
if not self.password: |
53
|
|
|
self.win.setStatus(_("Please enter password.")) |
54
|
|
|
return |
55
|
|
|
self.hide() |
56
|
|
|
self.confirmAction(self.password) |
57
|
|
|
|
58
|
|
|
def onCancel(self, widget, action, data): |
59
|
|
|
self.password = '' |
60
|
|
|
self.hide() |
61
|
|
|
|
62
|
|
|
def createUI(self): |
63
|
|
|
w, h = gdata.scrnSize |
64
|
|
|
self.win = ui.Window(self.app, |
65
|
|
|
modal = 1, |
66
|
|
|
escKeyClose = 1, |
67
|
|
|
movable = 0, |
68
|
|
|
title = _('Enter password'), |
69
|
|
|
rect = ui.Rect((w - 264) / 2, (h - 104) / 2, 264, 104), |
70
|
|
|
layoutManager = ui.SimpleGridLM(), |
71
|
|
|
) |
72
|
|
|
# creating dialog window |
73
|
|
|
self.win.subscribeAction('*', self) |
74
|
|
|
|
75
|
|
|
ui.Label(self.win, |
76
|
|
|
text = _("Password:"), |
77
|
|
|
align = ui.ALIGN_E, |
78
|
|
|
layout = (0, 1, 5, 1) |
79
|
|
|
) |
80
|
|
|
ui.Entry(self.win, id = 'vPassword', |
81
|
|
|
align = ui.ALIGN_W, |
82
|
|
|
layout = (5, 1, 5, 1), |
83
|
|
|
) |
84
|
|
|
ui.Title(self.win, layout = (0, 3, 3, 1)) |
85
|
|
|
ui.TitleButton(self.win, layout = (3, 3, 5, 1), text = _("Cancel"), action = "onCancel") |
86
|
|
|
okBtn = ui.TitleButton(self.win, layout = (8, 3, 5, 1), text = _("OK"), action = 'onOK') |
87
|
|
|
self.win.acceptButton = okBtn |
88
|
|
|
|