summaryrefslogtreecommitdiffstats
path: root/displayconfig/servertestdialog.py
blob: 209552276618344edaecbab965db4cf8c8b556ae (plain)
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
#!/usr/bin/python
###########################################################################
# servertestdialog.py -                                                   #
# ------------------------------                                          #
# copyright : (C) 2004 by Simon Edwards                                   #
# email     : simon@simonzone.com                                         #
#                                                                         #
###########################################################################
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 2 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
###########################################################################
from qt import * # Just use Qt for this.
import os
import sys

############################################################################
class ServerTestDialog(QDialog):
    def __init__(self):
        QDialog.__init__(self)

        msec = 10000
        margin = 4
        spacing = 4

        self.totaltimer = QTimer(self)
        self.updatetimer = QTimer(self)
        self.msectotal = self.msecremaining = msec
        self.updateinterval = 1000

        self.connect(self.totaltimer, SIGNAL("timeout()"), self.slotInternalTimeout)
        self.connect(self.updatetimer, SIGNAL("timeout()"), self.slotUpdateTime)

        layout = QHBoxLayout(self)
        # create the widgets
        self.mainwidget = QVBox(self, "mainWidget")
        self.mainwidget.setMargin(margin)
        self.mainwidget.setSpacing(spacing)
        
        layout.addWidget(self.mainwidget,1)
        
        label = QLabel(self.mainwidget)
        label.setText(i18n("Are these settings acceptable?"))
        QWidget(self.mainwidget)
        
        self.timerwidget = QHBox(self.mainwidget, "timerWidget")
        self.timerlabel = QLabel(self.timerwidget)
        self.timerprogress = QProgressBar(self.timerwidget)
        self.timerprogress.setTotalSteps(self.msectotal)
        self.timerprogress.setPercentageVisible(False)

        hbox = QHBox(self.mainwidget)
        self.okbutton = QPushButton(i18n("Yes"),hbox)
        QWidget(hbox)
        self.cancelbutton = QPushButton(i18n("No"),hbox)
        self.connect(self.okbutton, SIGNAL("clicked()"), self.slotOk)
        self.connect(self.cancelbutton, SIGNAL("clicked()"), self.slotCancel)
        
        self.slotUpdateTime(False)

    def show(self):
        QDialog.show(self)
        self.totaltimer.start(self.msectotal, True)
        self.updatetimer.start(self.updateinterval, False)

    def exec_loop(self):
        self.totaltimer.start(self.msectotal, True)
        self.updatetimer.start(self.updateinterval, False)
        return QDialog.exec_loop(self)

    def setRefreshInterval(self, msec):
        self.updateinterval = msec;
        if self.updatetimer.isActive():
            self.updatetimer.changeInterval(self.updateinterval)

    def timeoutButton(self):
        return self.buttonontimeout

    def setTimeoutButton(self, newbutton):
        self.buttonontimeout = newbutton

    def slotUpdateTime(self, update=True):
        self.msecremaining -= self.updateinterval
        
        self.timerprogress.setProgress(self.msecremaining)
        self.timerlabel.setText( i18n("Automatically cancelling in %1 seconds:").arg(self.msecremaining/1000.0) )

    def slotInternalTimeout(self):
        self.reject()

    def slotOk(self):
        self.accept()
        
    def slotCancel(self):
        self.reject()
############################################################################
        
os.environ["DISPLAY"] = ":9"
os.environ["XAUTHORITY"] = sys.argv[1]

# FIXME set the application name / string catalog, for i18n().
qapp = QApplication(sys.argv)
dialog = ServerTestDialog()
dialog.show()
dialog.exec_loop()

if dialog.result()==QDialog.Accepted:
    sys.exit(0)
else:
    sys.exit(1)