1
|
|
|
# |
2
|
|
|
# Copyright 2001 - 2016 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 client, gdata, res |
23
|
|
|
|
24
|
|
|
class ConfirmDlg: |
25
|
|
|
|
26
|
|
|
def __init__(self, app): |
27
|
|
|
self._agreement = None |
28
|
|
|
self.agreementNeeded = None |
29
|
|
|
self.app = app |
30
|
|
|
self.createUI() |
31
|
|
|
|
32
|
|
|
def display(self, message, okText, cancelText, confirmAction = None, cancelAction = None, agreementNeeded = False): |
33
|
|
|
self.win.vText.text = [message] |
34
|
|
|
self.win.vConfirm.text = okText |
35
|
|
|
if cancelText: |
36
|
|
|
self.win.vCancel.text = cancelText |
37
|
|
|
self.win.vCancel.enabled = True |
38
|
|
|
else: |
39
|
|
|
self.win.vCancel.text = "" |
40
|
|
|
self.win.vCancel.enabled = False |
41
|
|
|
self.agreementNeeded = agreementNeeded |
42
|
|
|
self.confirmAction = confirmAction |
43
|
|
|
self.cancelAction = cancelAction |
44
|
|
|
self.manageAgreement() |
45
|
|
|
self.win.show() |
46
|
|
|
|
47
|
|
|
def manageAgreement(self): |
48
|
|
|
if self.agreementNeeded: |
49
|
|
|
if self._agreement is None: |
50
|
|
|
self._agreement = False |
51
|
|
|
self.win.vAgree.enabled = True |
52
|
|
|
self.win.vAgree.visible = True |
53
|
|
|
self.win.vAgree.checked = False |
54
|
|
|
else: |
55
|
|
|
self.win.vAgree.enabled = False |
56
|
|
|
self.win.vAgree.visible = False |
57
|
|
|
self.win.vAgree.checked = True |
58
|
|
|
|
59
|
|
|
def hide(self): |
60
|
|
|
self.win.hide() |
61
|
|
|
|
62
|
|
|
def onAgree(self, widget, action, data): |
63
|
|
|
self._agreement = not self._agreement |
64
|
|
|
pass |
65
|
|
|
|
66
|
|
|
def onConfirm(self, widget, action, data): |
67
|
|
|
if not self.win.vAgree.checked: |
68
|
|
|
self.win.setStatus(_("You have to agree explicitly to proceed.")) |
69
|
|
|
return |
70
|
|
|
self.hide() |
71
|
|
|
if self.confirmAction: |
72
|
|
|
self.confirmAction() |
73
|
|
|
|
74
|
|
|
def onCancel(self, widget, action, data): |
75
|
|
|
self.hide() |
76
|
|
|
if self.cancelAction: |
77
|
|
|
self.cancelAction() |
78
|
|
|
|
79
|
|
|
def setTitle(self, title): |
80
|
|
|
self.win.title = title |
81
|
|
|
|
82
|
|
View Code Duplication |
def createUI(self): |
|
|
|
|
83
|
|
|
w, h = gdata.scrnSize |
84
|
|
|
self.win = ui.Window(self.app, |
85
|
|
|
modal = 1, |
86
|
|
|
movable = 0, |
87
|
|
|
title = _('Question'), |
88
|
|
|
rect = ui.Rect((w - 424) / 2, (h - 124) / 2, 424, 124), |
89
|
|
|
layoutManager = ui.SimpleGridLM(), |
90
|
|
|
) |
91
|
|
|
self.win.subscribeAction('*', self) |
92
|
|
|
ui.Text(self.win, layout = (5, 0, 16, 3), id = 'vText', background = self.win.app.theme.themeBackground, editable = 0) |
93
|
|
|
ui.Label(self.win, layout = (0, 0, 5, 4), icons = ((res.loginLogoImg, ui.ALIGN_W),)) |
94
|
|
|
ui.Title(self.win, layout = (0, 4, 13, 1), id = 'vStatusBar', align = ui.ALIGN_W) |
95
|
|
|
ui.Check(self.win, layout = (17, 3, 4, 1), text = _('I agree'), id = 'vAgree', action = 'onAgree') |
96
|
|
|
ui.TitleButton(self.win, layout = (13, 4, 4, 1), id = 'vCancel', action = 'onCancel') |
97
|
|
|
ui.TitleButton(self.win, layout = (17, 4, 4, 1), id = 'vConfirm', action = 'onConfirm') |
98
|
|
|
|