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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
|
#!/usr/bin/python
# -*- coding: UTF-8 -*-
###########################################################################
# displayconfig.py - description #
# ------------------------------ #
# begin : Fri Mar 26 2004 #
# copyright : (C) 2004-2006 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 *
from tdecore import *
from tdeui import *
import xorgconfig
import xf86misc
import string
import os
import select
import sys
import csv
import time
import signal
import shutil
from ktimerdialog import *
from displayconfigwidgets import *
from displayconfigabstraction import *
from execwithcapture import *
programname = "Display and Graphics Configuration"
version = "0.8.0"
DUAL_PREVIEW_SIZE = 240
# Are we running as a separate standalone application or in KControl?
standalone = __name__=='__main__'
# Running as the root user or not?
isroot = os.getuid()==0
############################################################################
class GfxCardDialog(KDialogBase):
video_ram_list = [256,512,1024,2048,4096,8192,16384,32768,65536]
def __init__(self,parent):
KDialogBase.__init__(self,parent,None,True,"Choose Graphics Card",
KDialogBase.Ok|KDialogBase.Cancel, KDialogBase.Cancel)
self.gfxcarddb = None
self.updatingGUI = True
self.card2listitem = {}
topbox = QVBox(self)
topbox.setSpacing(KDialog.spacingHint())
self.setMainWidget(topbox)
label = QLabel(topbox)
label.setText(i18n("Select Graphics Card:"))
self.listview = KListView(topbox)
self.listview.addColumn("")
self.listview.header().hide()
self.listview.setRootIsDecorated(True)
self.connect(self.listview,SIGNAL("selectionChanged(QListViewItem *)"),self.slotListClicked)
topbox.setStretchFactor(self.listview,1)
self.driver = KListViewItem(self.listview)
self.driver.setText(0,i18n("Drivers"))
self.driver.setSelectable(False)
self.manufacturer = KListViewItem(self.listview)
self.manufacturer.setText(0,i18n("Manufacturers"))
self.manufacturer.setSelectable(False)
hbox = QHBox(topbox)
topbox.setStretchFactor(hbox,0)
vbox = QVBox(hbox)
self.detected_label = QLabel("",vbox)
self.detected_button = KPushButton(vbox)
self.detected_button.setText(i18n("Select"))
self.connect(self.detected_button,SIGNAL("clicked()"),self.slotSelectDetectedClicked)
spacer = QWidget(vbox)
vbox.setStretchFactor(self.detected_button,0)
vbox.setStretchFactor(spacer,1)
hbox.setStretchFactor(vbox,0)
spacer = QWidget(hbox)
hbox.setStretchFactor(spacer,1)
drivergrid = QGrid(2,hbox)
drivergrid.setSpacing(KDialog.spacingHint())
QLabel(i18n("Driver:"),drivergrid)
self.standarddriverradio = QRadioButton(i18n("Standard"),drivergrid)
self.connect(self.standarddriverradio,SIGNAL("clicked()"),self.slotStandardDriverClicked)
QWidget(drivergrid)
self.proprietarydriverradio = QRadioButton(i18n("Proprietary"),drivergrid)
self.connect(self.proprietarydriverradio,SIGNAL("clicked()"),self.slotProprietaryDriverClicked)
QLabel(i18n("Video RAM:"),drivergrid)
self.videoramcombo = QComboBox(drivergrid)
for s in [i18n("256 kB"),
i18n("512 kB"),
i18n("1 MB"),
i18n("2 MB"),
i18n("4 MB"),
i18n("8 MB"),
i18n("16 MB"),
i18n("32 MB"),
i18n("64 MB or more")]:
self.videoramcombo.insertItem(s)
self.updatingGUI = False
self._setGfxCardDB(GetGfxCardModelDB())
def _setGfxCardDB(self,gfxcarddb):
self.updatingGUI = True
self.gfxcarddb = gfxcarddb
# Add the GfxCards under the Manufacturer item.
keys = gfxcarddb.vendordb.keys()
keys.sort()
for key in keys:
cardkeys = self.gfxcarddb.vendordb[key].keys()
vendoritem = KListViewItem(self.manufacturer)
vendoritem.setText(0,key)
vendoritem.setSelectable(False)
for cardkey in cardkeys:
item = KListViewItem(vendoritem)
item.setText(0,cardkey)
self.card2listitem[self.gfxcarddb.vendordb[key][cardkey]] = item
# Add the GfxCard _drivers_ under the Drivers item
drivers = gfxcarddb.driverdb.keys()
drivers.sort()
for driver in drivers:
driveritem = KListViewItem(self.driver)
driveritem.setText(0,driver)
self.card2listitem[gfxcarddb.driverdb[driver]] = driveritem
self.updatingGUI = False
def do(self,card,proprietarydriver,detected_card,video_ram):
self.updatingGUI = True
item = self.card2listitem[card]
self.listview.setSelected(item,True)
self.listview.ensureItemVisible(item)
self.selected_video_ram = video_ram
if detected_card is None:
self.detected_button.setEnabled(False)
self.detected_label.setText(i18n("Detected graphics card:\n(unknown)"))
else:
self.detected_button.setEnabled(True)
self.detected_label.setText(i18n("Detected graphics card:\n'%1'.").arg(detected_card.getName()))
self.__syncDriver(card,proprietarydriver,video_ram)
self.detected_card = detected_card
self.selected_card = card
self.updatingGUI = False
if self.exec_loop()==QDialog.Accepted:
return (self.selected_card,
self.proprietarydriverradio.isChecked() and (self.selected_card is not None),
self.video_ram_list[self.videoramcombo.currentItem()])
else:
return (card, proprietarydriver,video_ram)
def __syncDriver(self,card,proprietarydriver,videoram):
if card.getProprietaryDriver() is None:
self.standarddriverradio.setChecked(True)
self.standarddriverradio.setEnabled(False)
self.proprietarydriverradio.setEnabled(False)
else:
self.standarddriverradio.setEnabled(True)
self.proprietarydriverradio.setEnabled(True)
self.standarddriverradio.setChecked(not proprietarydriver)
self.proprietarydriverradio.setChecked(proprietarydriver)
self.videoramcombo.setEnabled(card.getNeedVideoRam())
if card.getNeedVideoRam():
self.videoramcombo.setCurrentItem(self.video_ram_list.index(videoram))
def slotSelectDetectedClicked(self):
self.updatingGUI = True
item = self.card2listitem[self.detected_card]
self.listview.setSelected(item,True)
self.listview.ensureItemVisible(item)
self.selected_card = self.detected_card
self.__syncDriver(self.selected_card, self.proprietarydriverradio.isChecked(), self.selected_video_ram)
self.updatingGUI = False
def slotListClicked(self,item):
if self.updatingGUI:
return
for key in self.card2listitem:
value = self.card2listitem[key]
if value is item:
self.selected_card = key
self.__syncDriver(self.selected_card, self.proprietarydriverradio.isChecked(), self.selected_video_ram)
def slotStandardDriverClicked(self):
self.proprietarydriverradio.setChecked(False)
self.standarddriverradio.setChecked(True)
def slotProprietaryDriverClicked(self):
self.standarddriverradio.setChecked(False)
self.proprietarydriverradio.setChecked(True)
############################################################################
class MonitorDialog(KDialogBase):
def __init__(self,parent):
KDialogBase.__init__(self,parent,None,True,"Choose Monitor",
KDialogBase.Ok|KDialogBase.Cancel, KDialogBase.Cancel)
self.monitordb = None
self.selectedmonitor = None
self.aspect = ModeLine.ASPECT_4_3
self.monitor2listitem = {}
self.updatingGUI = True
topbox = QVBox(self)
topbox.setSpacing(KDialog.spacingHint())
self.setMainWidget(topbox)
label = QLabel(topbox)
label.setText(i18n("Select Monitor:"))
self.listview = KListView(topbox)
self.listview.addColumn("")
self.listview.header().hide()
self.listview.setRootIsDecorated(True)
self.connect(self.listview,SIGNAL("selectionChanged(QListViewItem *)"),self.slotListClicked)
self.generic = KListViewItem(self.listview)
self.generic.setText(0,i18n("Generic"))
self.generic.setSelectable(False)
self.manufacturer = KListViewItem(self.listview)
self.manufacturer.setText(0,i18n("Manufacturers"))
self.manufacturer.setSelectable(False)
grid = QGroupBox(4,QGroupBox.Horizontal,topbox)
grid.setTitle(i18n("Details"))
label = QLabel(grid)
label.setText(i18n("Horizontal Range:"))
self.horizrange = KLineEdit(grid)
self.horizrange.setReadOnly(True)
label = QLabel(grid)
label.setText(i18n("Vertical Refresh:"))
self.vertrange = KLineEdit(grid)
self.vertrange.setReadOnly(True)
hbox = QHBox(topbox)
self.detectbutton = KPushButton(hbox)
self.detectbutton.setText(i18n("Detect Monitor")) # FIXME better label/text?
self.connect(self.detectbutton,SIGNAL("clicked()"),self.slotDetectClicked)
spacer = QWidget(hbox)
hbox.setStretchFactor(self.detectbutton,0)
hbox.setStretchFactor(spacer,1)
label = QLabel(hbox)
label.setText(i18n("Image format:"))
hbox.setStretchFactor(label,0)
self.aspectcombobox = KComboBox(hbox)
self.aspectcombobox.insertItem(i18n("Standard 4:3"))
self.aspectcombobox.insertItem(i18n("Widescreen 16:9"))
hbox.setStretchFactor(self.aspectcombobox,0)
self.updatingGUI = False
def setMonitorDB(self,monitordb):
self.monitordb = monitordb
# Add the Monitors
vendors = monitordb.vendordb.keys()
vendors.sort()
for vendor in vendors:
monitorkeys = self.monitordb.vendordb[vendor].keys()
vendoritem = KListViewItem(self.manufacturer)
vendoritem.setText(0,vendor)
vendoritem.setSelectable(False)
for monitorkey in monitorkeys:
item = KListViewItem(vendoritem)
item.setText(0,monitorkey)
self.monitor2listitem[self.monitordb.vendordb[vendor][monitorkey]] = item
generics = monitordb.genericdb.keys()
generics.sort()
for generic in generics:
genericitem = KListViewItem(self.generic)
genericitem.setText(0,generic)
self.monitor2listitem[monitordb.genericdb[generic]] = genericitem
customs = monitordb.getCustomMonitors().keys()
customs.sort()
for custom in customs:
customitem = KListViewItem(self.listview)
customitem.setText(0,custom)
self.monitor2listitem[monitordb.getCustomMonitors()[custom]] = customitem
def do(self,monitor,aspect,is_primary_monitor=True):
"""Run the monitor selection dialog.
Parameters:
monitor - Currently selected 'Monitor' object.
Returns the newly selected monitor object and aspect ratio as a tuple.
"""
if monitor is not None:
self.selectedmonitor = monitor
item = self.monitor2listitem[monitor]
self.listview.setSelected(item,True)
self.listview.ensureItemVisible(item)
else:
self.selectedmonitor = None
self.listview.clearSelection()
self.aspect = aspect
# Only the first/primary monitor can be detected. :-/
self.detectbutton.setEnabled(is_primary_monitor)
self.updatingGUI = True
self._syncGUI()
self.updatingGUI = False
if self.exec_loop()!=QDialog.Accepted:
# Dialog was cancelled. Return the original monitor.
self.selectedmonitor = monitor
else:
self.aspect = [ModeLine.ASPECT_4_3,ModeLine.ASPECT_16_9][self.aspectcombobox.currentItem()]
return (self.selectedmonitor,self.aspect)
def slotDetectClicked(self):
detectedmonitor = self.monitordb.detect()
if detectedmonitor is not None:
self.selectedmonitor = detectedmonitor
self._syncGUI()
else:
KMessageBox.error(self, i18n("Sorry, the model and capabilities of your\nmonitor couldn't be detected."),
i18n("Monitor detection failed"))
def slotListClicked(self,item):
if self.updatingGUI:
return
self.updatingGUI = True
for key in self.monitor2listitem:
value = self.monitor2listitem[key]
if value is item:
self.selectedmonitor = key
break
self._syncGUI()
self.updatingGUI = False
def _syncGUI(self):
if self.selectedmonitor is not None:
item = self.monitor2listitem[self.selectedmonitor]
self.listview.setSelected(item,True)
self.listview.ensureItemVisible(item)
self.vertrange.setText(self.selectedmonitor.getVerticalSync())
self.horizrange.setText(self.selectedmonitor.getHorizontalSync())
else:
self.vertrange.setText("-")
self.horizrange.setText("-")
self.aspectcombobox.setCurrentItem({ModeLine.ASPECT_4_3:0,ModeLine.ASPECT_16_9:1}[self.aspect])
############################################################################
if standalone:
programbase = KDialogBase
else:
programbase = TDECModule
############################################################################
class DisplayApp(programbase):
########################################################################
def __init__(self,parent=None,name=None):
global standalone,isroot,kapp
TDEGlobal.locale().insertCatalogue("guidance")
if standalone:
KDialogBase.__init__(self,KJanusWidget.Tabbed,"Display Configuration",\
KDialogBase.Apply|KDialogBase.User1|KDialogBase.User2|KDialogBase.Close, KDialogBase.Close)
self.setButtonText(KDialogBase.User1,i18n("Reset"))
self.setButtonText(KDialogBase.User2,i18n("About"))
else:
TDECModule.__init__(self,parent,name)
self.setButtons(TDECModule.Apply|TDECModule.Reset)
self.aboutdata = MakeAboutData()
# This line has the effect of hiding the "Admin only" message and also forcing
# the Apply/Reset buttons to be shown. Yippie! Only had to read the source
# to work that out.
self.setUseRootOnlyMsg(False)
# Create a configuration object.
self.config = TDEConfig("displayconfigrc")
# Compact mode means that we have to make the GUI
# much smaller to fit on low resolution screens.
self.compact_mode = kapp.desktop().height()<=600
TDEGlobal.iconLoader().addAppDir("guidance")
global imagedir
imagedir = unicode(TDEGlobal.dirs().findDirs("data","guidance/pics/displayconfig")[0])
self.imagedir = imagedir
self.xconfigchanged = False
self.xconfigtested = True
self.availabletargetgammas = [unicode(i18n('1.4')),unicode(i18n('1.6')),unicode(i18n('1.8')),unicode(i18n('2.0')),unicode(i18n('2.2')),unicode(i18n('2.4'))]
self.lightimages = []
self.mediumimages = []
self.darkimages = []
# X Server stuff
self.xf86server = xf86misc.XF86Server()
self.xconfigpath = self._findXorgConfig()
SetDataFileDir(unicode(TDEGlobal.dirs().findResourceDir("data","guidance/pcitable")) + "guidance/")
self.xsetup = XSetup(self.xconfigpath)
self.updatingGUI = True
self.gfxcarddb = GfxCardModelDB()
self.monitordb = GetMonitorModelDB()
self.monitormodedb = GetMonitorModeDB()
self._buildGUI()
# Work out if the currently running Gfxdriver is safe enough that we
# can test other drivers at the same time.
self.badfbrestore = self._badFbRestore()
self.testbutton.setEnabled(isroot and not self._badFbRestore())
if isroot and not self._badFbRestore():
self.testunavailablelabel.hide()
else:
self.testunavailablelabel.show()
# Load up some of our databases, and initialise our state variables.
if len(self.xsetup.getUsedScreens()):
self.currentsizescreen = self.xsetup.getUsedScreens()[0]
self.currentgammascreen = self.xsetup.getUsedScreens()[0]
else:
# FIXME
print "Houston, we have a problem: No screens found in configuration file, exiting. :("
sys.exit(1)
self.monitordialog.setMonitorDB(self.monitordb)
self.aboutus = KAboutApplication(self)
# For centering the timed Apply dialog.
self.applytimerdialog = None
self.connect(kapp.desktop(), SIGNAL("resized(int)"), self.slotDesktopResized)
self.applydialogscreenindex = 0
self.__loadImages()
self._loadConfig()
self._syncGUI()
if standalone:
self.enableButton(KDialogBase.User1,False) # Reset button
self.enableButtonApply(False) # Apply button
self.updatingGUI = False
def _findXorgConfig(self):
# Lookup location of X configfile
for line in ExecWithCapture("xset", ["xset","q"],True).split('\n'):
if line.strip().startswith("Config file"):
return line.split(":")[1].strip()
# Sometimes, xset doesn't know about the configfile location, hence ...
if os.path.isfile("/etc/X11/xorg.conf"):
return "/etc/X11/xorg.conf"
return None
def _buildGUI(self):
global standalone
if not standalone:
toplayout = QVBoxLayout( self, 0, KDialog.spacingHint() )
tabcontrol = QTabWidget(self)
toplayout.addWidget(tabcontrol)
toplayout.setStretchFactor(tabcontrol,1)
#--- Size, Orientation and Positioning ---
tabname = i18n("Size, Orientation && Positioning")
if standalone:
sopage = self.addGridPage(1,QGrid.Horizontal,tabname)
sopage.setSpacing(0)
self.SizePage = SizeOrientationPage(sopage,self.xsetup,self.compact_mode)
else:
self.SizePage = SizeOrientationPage(tabcontrol,self.xsetup,self.compact_mode)
self.SizePage.setMargin(KDialog.marginHint())
# Connect all PYSIGNALs from SizeOrientationPage Widget to appropriate actions.
self.connect(self.SizePage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)
self.connect(self.SizePage,PYSIGNAL("resolutionChange(int)"),self.slotResolutionChange)
if not standalone:
tabcontrol.addTab(self.SizePage,tabname)
#--- Color & Gamma tab ---
tabname = i18n("Color && Gamma")
if standalone:
gammapage = self.addVBoxPage(tabname)
vbox = QVBox(gammapage)
else:
vbox = QVBox(tabcontrol)
vbox.setMargin(KDialog.marginHint())
vbox.setSpacing(KDialog.spacingHint())
hbox = QHBox(vbox)
hbox.setSpacing(KDialog.spacingHint())
vbox.setStretchFactor(hbox,0)
label = QLabel(hbox,"textLabel1")
label.setText(i18n("Screen:"))
hbox.setStretchFactor(label,0)
self.gammadisplaycombobox = QComboBox(0,hbox,"comboBox11")
hbox.setStretchFactor(self.gammadisplaycombobox,0)
spacer = QWidget(hbox)
hbox.setStretchFactor(spacer,1)
self.connect(self.gammadisplaycombobox,SIGNAL("activated(int)"),self.slotGammaScreenCombobox)
# fill the combobox.
for screen in self.xsetup.getUsedScreens():
self.gammadisplaycombobox.insertItem(screen.getName())
if not self.compact_mode:
# Create the colour matching pics
label = QLabel(vbox)
label.setText(i18n("Color calibration image:"))
vbox.setStretchFactor(label,0)
hbox = QWidget(vbox)
hboxlayout = QHBoxLayout(hbox)
hboxlayout.setSpacing(KDialog.spacingHint())
self.mediumpic = QLabel(hbox)
self.mediumpic.setFixedSize(305,105)
hboxlayout.addWidget(self.mediumpic,0,Qt.AlignTop)
label = QLabel(hbox)
label.setPixmap(SmallIcon('info'))
hboxlayout.addWidget(label,0,Qt.AlignTop)
label = QLabel(i18n("<qt><p>Gamma controls how your monitor displays colors.</p><p>For accurate color reproduction, adjust the gamma correction sliders until the squares blend into the background as much as possible.</p></qt>"),hbox)
label.setTextFormat(Qt.RichText)
hboxlayout.addWidget(label,1,Qt.AlignTop)
sliderspace = QWidget(vbox)
grid = QGridLayout(sliderspace, 9, 4, 0, KDialog.spacingHint())
grid.setSpacing(KDialog.spacingHint())
grid.setColStretch(0,0)
grid.setColStretch(1,0)
grid.setColStretch(2,0)
grid.setColStretch(3,1)
label = QLabel(i18n("Gamma correction:"),sliderspace)
grid.addWidget(label, 0, 0)
self.gammaradiogroup = QButtonGroup()
self.gammaradiogroup.setRadioButtonExclusive(True)
self.connect(self.gammaradiogroup,SIGNAL("clicked(int)"),self.slotGammaRadioClicked)
self.allradio = QRadioButton(sliderspace)
grid.addWidget(self.allradio, 0, 1, Qt.AlignTop)
label = QLabel(i18n("All:"),sliderspace)
grid.addWidget(label, 0, 2)
self.gammaslider = KDoubleNumInput(0.4, 3.5, 2.0, 0.05, 2, sliderspace, 'gammaslider')
grid.addMultiCellWidget(self.gammaslider,0,1,3,3)
self.gammaslider.setRange(0.5, 2.5, 0.05, True)
self.connect(self.gammaslider, SIGNAL("valueChanged(double)"), self.slotGammaChanged)
self.componentradio = QRadioButton(sliderspace)
grid.addWidget(self.componentradio, 2, 1, Qt.AlignTop)
label = QLabel(i18n("Red:"),sliderspace)
grid.addWidget(label, 2, 2)
self.redslider = KDoubleNumInput(self.gammaslider,0.4, 3.5, 2.0, 0.05, 2, sliderspace, 'redslider')
grid.addMultiCellWidget(self.redslider,2,3,3,3)
self.redslider.setRange(0.5, 2.5, 0.05, True)
self.connect(self.redslider, SIGNAL("valueChanged(double)"), self.slotRedChanged)
label = QLabel(i18n("Green:"),sliderspace)
grid.addWidget(label, 4, 2)
self.greenslider = KDoubleNumInput(self.redslider,0.4, 3.5, 2.0, 0.05, 2, sliderspace, 'greenslider')
grid.addMultiCellWidget(self.greenslider,4,5,3,3)
self.greenslider.setRange(0.5, 2.5, 0.05, True)
self.connect(self.greenslider, SIGNAL("valueChanged(double)"), self.slotGreenChanged)
label = QLabel(i18n("Blue:"),sliderspace)
grid.addWidget(label, 6, 2)
self.blueslider = KDoubleNumInput(self.greenslider,0.4, 3.5, 2.0, 0.05, 2, sliderspace, 'blueslider')
grid.addMultiCellWidget(self.blueslider,6,7,3,3)
self.blueslider.setRange(0.5, 2.5, 0.05, True)
self.connect(self.blueslider, SIGNAL("valueChanged(double)"), self.slotBlueChanged)
self.gammaradiogroup.insert(self.allradio,0)
self.gammaradiogroup.insert(self.componentradio,1)
if not self.compact_mode:
label = QLabel(i18n("Target gamma:"),sliderspace)
grid.addWidget(label, 8, 0)
hbox = QHBox(sliderspace)
self.targetgammacombo = KComboBox(False,hbox)
self.targetgammacombo.insertItem(i18n('1.4'))
self.targetgammacombo.insertItem(i18n('1.6'))
self.targetgammacombo.insertItem(i18n('1.8 Apple Macintosh standard'))
self.targetgammacombo.insertItem(i18n('2.0 Recommend'))
self.targetgammacombo.insertItem(i18n('2.2 PC standard, sRGB'))
self.targetgammacombo.insertItem(i18n('2.4'))
hbox.setStretchFactor(self.targetgammacombo,0)
spacer = QWidget(hbox)
hbox.setStretchFactor(spacer,1)
grid.addMultiCellWidget(hbox, 8, 8, 1, 3)
self.connect(self.targetgammacombo,SIGNAL("activated(int)"),self.slotTargetGammaChanged)
spacer = QWidget(vbox)
vbox.setStretchFactor(spacer,1)
if not standalone:
tabcontrol.addTab(vbox,tabname)
#--- Hardware tab ---
if standalone:
hardwarepage = self.addVBoxPage(i18n("Hardware"))
vbox = QVBox(hardwarepage)
else:
vbox = QVBox(tabcontrol)
vbox.setMargin(KDialog.marginHint())
self.gfxcarddialog = GfxCardDialog(None)
self.monitordialog = MonitorDialog(None)
self.xscreenwidgets = []
for gfxcard in self.xsetup.getGfxCards():
w = GfxCardWidget(vbox,self.xsetup, gfxcard, self.gfxcarddialog, self.monitordialog)
self.xscreenwidgets.append(w)
self.connect(w,PYSIGNAL("configChanged"),self.slotConfigChanged)
spacer = QWidget(vbox)
vbox.setStretchFactor(spacer,1)
if not self.xsetup.mayModifyXorgConfig():
QLabel(i18n("Changes on this tab require 'root' access."),vbox)
if not standalone:
QLabel(i18n("Click the \"Administrator Mode\" button to allow modifications on this tab."),vbox)
hbox = QHBox(vbox)
hbox.setSpacing(KDialog.spacingHint())
self.testbutton = KPushButton(i18n("Test"),hbox)
self.connect(self.testbutton,SIGNAL("clicked()"),self.slotTestClicked)
hbox.setStretchFactor(self.testbutton,0)
self.testunavailablelabel = QHBox(hbox)
self.testunavailablelabel.setSpacing(KDialog.spacingHint())
tmplabel = QLabel(self.testunavailablelabel)
self.testunavailablelabel.setStretchFactor(tmplabel,0)
tmplabel.setPixmap(SmallIcon('info'))
label = QLabel(i18n("This configuration cannot be safely tested."),self.testunavailablelabel)
self.testunavailablelabel.setStretchFactor(label,1)
self.testunavailablelabel.hide()
spacer = QWidget(hbox)
hbox.setStretchFactor(spacer,1)
vbox.setStretchFactor(hbox,0)
if not standalone:
tabcontrol.addTab(vbox,i18n("Hardware"))
#--- Display Power Saving ---
tabname = i18n("Power saving")
if standalone:
powerpage = self.addGridPage(1,QGrid.Horizontal,tabname)
self.dpmspage = DpmsPage(powerpage)
else:
self.dpmspage = DpmsPage(tabcontrol)
self.dpmspage.setMargin(KDialog.marginHint())
#self.SizePage.setScreens(self.xsetup.getScreens())
# Connect all PYSIGNALs from SizeOrientationPage Widget to appropriate actions.
#self.connect(self.SizePage,PYSIGNAL("dualheadEnabled(bool)"),self.slotDualheadEnabled)
self.connect(self.dpmspage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)
if not standalone:
tabcontrol.addTab(self.dpmspage,tabname)
def save(self): # TDECModule
xorg_config_changed = self.xsetup.isXorgConfigChanged()
restart_recommended = self.xsetup.getRestartHint()
# Check the Size & Orientation tab.
if self.applytimerdialog is None:
self.applytimerdialog = KTimerDialog(15000, KTimerDialog.CountDown, self, "mainKTimerDialog",
True, i18n("Confirm Display Setting Change"), KTimerDialog.Ok | KTimerDialog.Cancel, \
KTimerDialog.Cancel)
self.applytimerdialog.setButtonOK(KGuiItem(i18n("&Keep"), "button_ok"))
self.applytimerdialog.setButtonCancel(KGuiItem(i18n("&Cancel"), "button_cancel"))
label = KActiveLabel(i18n("Trying new screen settings. Keep these new settings? (Automatically cancelling in 15 seconds.)"),
self.applytimerdialog, "userSpecifiedLabel")
self.applytimerdialog.setMainWidget(label)
if self.xsetup.isLiveResolutionConfigChanged():
if self.xsetup.applyLiveResolutionChanges():
# running X server config has changed. Ask the user.
KDialog.centerOnScreen(self.applytimerdialog, 0)
if self.applytimerdialog.exec_loop():
self.xsetup.acceptLiveResolutionChanges()
else:
try:
self.xsetup.rejectLiveResolutionChanges()
except:
"""Workaround! FIXME: Use isGammaLive function in displayconfigabstraction when this is implemented"""
print "Live gamma change not supported"
return
else:
# Nothing really changed, just accept the changes.
self.xsetup.acceptLiveResolutionChanges()
self.xsetup.acceptLiveGammaChanges()
self.dpmspage.apply()
# Save the X server config.
if isroot and xorg_config_changed:
if not self.xconfigtested:
if self.badfbrestore or self._badFbRestore():
if KMessageBox.warningContinueCancel(self, \
i18n("The selected driver and monitor configuration can not be safely tested on this computer.\nContinue with this configuration?"),
i18n("Configuration not tested"))!=KMessageBox.Continue:
return
else:
if KMessageBox.warningContinueCancel(self,
i18n("The selected driver and monitor configuration has not been successfully tested on this computer.\nContinue with this configuration?"),
i18n("Configuration not tested"))!=KMessageBox.Continue:
return
try:
# Backup up the current config file.
i = 1
while os.path.exists("%s.%i" % (self.xconfigpath,i)):
i += 1
try:
shutil.copyfile(self.xconfigpath,"%s.%i" % (self.xconfigpath,i))
except IOError, errmsg:
print "IOError", errmsg, " - while trying to save new xorg.conf - trying to fix"
self.xconfigpath = "/etc/X11/xorg.conf"
xorgfile = open(self.xconfigpath, 'a')
xorgfile.close()
shutil.copyfile(self.xconfigpath,"%s.%i" % (self.xconfigpath,i))
# Write out the new config
tmpfilename = self.xconfigpath + ".tmp"
self.xsetup.writeXorgConfig(tmpfilename)
os.rename(tmpfilename,self.xconfigpath)
except (IOError,TypeError):
print "******* Bang"
raise
return
# FIXME error
# FIXME the instructions in these messages are probably not quite right.
if restart_recommended==XSetup.RESTART_X:
KMessageBox.information(self,
i18n("Some changes require that the X server be restarted before they take effect. Log out and select \"Restart X server\" from the menu button."),
i18n("X Server restart recommend"))
if restart_recommended==XSetup.RESTART_SYSTEM:
KMessageBox.information(self,
i18n("Some changes require that the entire system be restarted before they take effect. Log out and select \"Restart computer\" from the log in screen."),
i18n("System restart recommend"))
self._saveConfig()
self._sendChangedSignal()
# Called when the desktop is resized. Just center the confirm dialog.
def slotDesktopResized(self):
if self.applytimerdialog is not None:
KDialog.centerOnScreen(self.applytimerdialog, self.applydialogscreenindex)
def slotApply(self): # KDialogBase
self.save()
def slotClose(self): # KDialogBase
try:
self.xsetup.rejectLiveGammaChanges()
except:
"""Workaround! FIXME: Use isGammaLive function in displayconfigabstraction when this is implemented"""
print "Live gamma change not supported"
KDialogBase.slotClose(self)
def load(self): # TDECModule
self.__reset()
self._sendChangedSignal()
def slotUser1(self): # Reset button, KDialogBase
self.load()
def slotUser2(self): # About button, KDialogBase
self.aboutus.show()
def slotResolutionChange(self,i):
self.currentsizescreen.setResolutionIndex(i)
self._sendChangedSignal()
def slotTargetGammaChanged(self,i):
self.targetgamma = i
self._selectGamma(self.targetgamma)
self._sendChangedSignal()
def slotGammaRadioClicked(self,i):
self.settingall = i==0
self.gammaslider.setDisabled(not self.settingall)
self.redslider.setDisabled(self.settingall)
self.greenslider.setDisabled(self.settingall)
self.blueslider.setDisabled(self.settingall)
try:
if self.settingall:
self.currentgammascreen.setAllGamma(self.currentgammascreen.getAllGamma())
else:
self.currentgammascreen.setRedGamma(self.currentgammascreen.getRedGamma())
self.currentgammascreen.setGreenGamma(self.currentgammascreen.getGreenGamma())
self.currentgammascreen.setBlueGamma(self.currentgammascreen.getBlueGamma())
except:
"""Workaround! FIXME: Use isGammaLive function in displayconfigabstraction when this is implemented"""
print "Live gamma change not supported"
self._sendChangedSignal()
def slotGammaChanged(self,value):
if self.updatingGUI:
return
try:
self.currentgammascreen.setAllGamma(value)
except:
"""Workaround! FIXME: Use isGammaLive function in displayconfigabstraction when this is implemented"""
print "Live gamma change not supported"
self._sendChangedSignal()
def slotRedChanged(self,value):
if self.updatingGUI:
return
try:
self.currentgammascreen.setRedGamma(value)
except:
"""Workaround! FIXME: Use isGammaLive function in displayconfigabstraction when this is implemented"""
print "Live gamma change not supported"
self._sendChangedSignal()
def slotGreenChanged(self,value):
if self.updatingGUI:
return
try:
self.currentgammascreen.setGreenGamma(value)
except:
"""Workaround! FIXME: Use isGammaLive function in displayconfigabstraction when this is implemented"""
print "Live gamma change not supported"
self._sendChangedSignal()
def slotBlueChanged(self,value):
if self.updatingGUI:
return
try:
self.currentgammascreen.setBlueGamma(value)
except:
"""Workaround! FIXME: Use isGammaLive function in displayconfigabstraction when this is implemented"""
print "Live gamma change not supported"
self._sendChangedSignal()
def slotGammaScreenCombobox(self,i):
self.currentgammascreen = self.xsetup.getUsedScreens()[i]
self._syncGUI()
self._sendChangedSignal()
def slotConfigChanged(self):
self.xconfigchanged = True
self.xconfigtested = False
# Check if the current X config can be tested.
self.SizePage._syncGUI()
for widget in self.xscreenwidgets:
widget.syncConfig()
self._syncTestButton()
self._sendChangedSignal()
def slotTestClicked(self):
self.xconfigtested = self.testX()
def testX(self):
self.xserverbin = "/usr/X11R6/bin/XFree86"
if not os.path.isfile(self.xserverbin):
self.xserverbin = "/usr/X11R6/bin/Xorg"
rc = False
# Remove an stale X server lock
try: os.remove("/tmp/.X9-lock")
except OSError: pass
# Try to find a safe tmp dir.
tmp_dir = None
if os.environ.get("TMPDIR") is not None:
tmp_dir = os.environ.get("TMPDIR")
if tmp_dir is None or not os.path.isdir(tmp_dir):
tmp_dir = os.path.join(os.environ.get("HOME"),"tmp")
if not os.path.isdir(tmp_dir):
tmp_dir = "/tmp"
working_tmp_dir = os.path.join(tmp_dir,"guidance."+str(os.getpid()))
error_filename = os.path.join(working_tmp_dir,"testserver.xoutput")
config_filename = os.path.join(working_tmp_dir,"testserver.config")
auth_filename = os.path.join(working_tmp_dir,"xauthority")
# Start the Xserver up with the new config file.
try:
# Create our private dir.
os.mkdir(working_tmp_dir,0700)
# Backup the XAUTHORITY environment variable.
old_xauthority = os.environ.get("XAUTHORITY",None)
# Write out the new config file.
self.xsetup.writeXorgConfig(config_filename)
os.system("xauth -f %s add :9 . `mcookie`" % (auth_filename,) )
# FIXME:: -xf86config is nowhere in man X ??
pid = os.spawnv(os.P_NOWAIT,"/bin/bash",\
["bash","-c","exec %s :9 -xf86config %s -auth %s &> %s" % \
(self.xserverbin, config_filename, auth_filename, error_filename)])
print "Got pid",pid
# Wait for the server to show up.
print str(os.waitpid(pid,os.WNOHANG))
# Use our private xauthority file.
os.environ["XAUTHORITY"] = auth_filename
time.sleep(1) # Wait a sec.
testserver = None
while True:
# Try connecting to the server.
try:
testserver = xf86misc.XF86Server(":9")
break
except xf86misc.XF86Error:
testserver = None
# Check if the server process is still alive.
if os.waitpid(pid,os.WNOHANG) != (0,0):
break
time.sleep(1) # Give the server some more time.
print "checkpoint 1"
print str(testserver)
if testserver is not None:
# Start the timed popup on the :9 display.
#servertestpy = str(TDEGlobal.dirs().findResource("data","guidance/servertestdialog.py"))
servertestpy = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])),"servertestdialog.py")
pythonexe = unicode(KStandardDirs.findExe("python"))
testrc = os.system(pythonexe + " " + servertestpy + " '" + auth_filename+"' ")
rc = (rc >> 8) == 0 # Test is good if the return code was 0.
testserver = None
os.kill(pid,signal.SIGINT)
else:
# Server failed, read the error info.
msg = ""
try:
fhandle = open(error_filename,'r')
for line in fhandle.readlines():
if (line.startswith("(EE)") and ("Disabling" not in line)) or line.startswith("Fatal"):
msg += line
msg = unicode(i18n("Messages from the X server:\n")) + msg
except IOError:
msg += unicode(i18n("Sorry, unable to capture the error messages from the X server."))
KMessageBox.detailedSorry(self,i18n("Sorry, this configuration video card driver\nand monitor doesn't appear to work."),msg)
finally:
# Attempt some cleanup before we go.
try: os.remove(error_filename)
except OSError: pass
try: os.remove(config_filename)
except OSError: pass
try: os.remove(auth_filename)
except OSError: pass
try: os.rmdir(working_tmp_dir)
except OSError: pass
if old_xauthority is None:
del os.environ["XAUTHORITY"]
else:
os.environ["XAUTHORITY"] = old_xauthority
return rc
def _syncGUI(self):
self.SizePage._syncGUI()
for gfxcard_widget in self.xscreenwidgets:
gfxcard_widget.syncConfig()
# Sync the gamma tab.
if not self.compact_mode:
self.targetgammacombo.setCurrentItem(self.targetgamma)
self._selectGamma(self.targetgamma)
if self.currentgammascreen.isGammaEqual():
self.gammaradiogroup.setButton(0)
else:
self.gammaradiogroup.setButton(1)
self.gammaslider.setValue(self.currentgammascreen.getAllGamma())
self.redslider.setValue(self.currentgammascreen.getRedGamma())
self.greenslider.setValue(self.currentgammascreen.getGreenGamma())
self.blueslider.setValue(self.currentgammascreen.getBlueGamma())
self.settingall = self.currentgammascreen.isGammaEqual()
self.gammaslider.setDisabled(not self.settingall)
self.redslider.setDisabled(self.settingall)
self.greenslider.setDisabled(self.settingall)
self.blueslider.setDisabled(self.settingall)
self._syncTestButton()
def _syncTestButton(self):
currentbadfbrestore = self._badFbRestore()
self.testbutton.setEnabled(self.xsetup.mayModifyXorgConfig() and not (self.badfbrestore or currentbadfbrestore))
if not isroot or (self.xsetup.mayModifyXorgConfig() and not (self.badfbrestore or currentbadfbrestore)):
self.testunavailablelabel.hide()
else:
self.testunavailablelabel.show()
def _loadConfig(self):
self.config.setGroup("General")
t = self.config.readEntry("targetgamma",unicode(i18n("2.0")))
if t in self.availabletargetgammas:
t = unicode(i18n('2.0'))
self.targetgamma = self.availabletargetgammas.index(t)
def _saveConfig(self):
global isroot
if isroot:
return
self.config.setGroup("General")
self.config.writeEntry("targetgamma",self.availabletargetgammas[self.targetgamma])
for s in self.xsetup.getUsedScreens():
self.config.setGroup("Screen"+str(s.getScreenIndex()))
self._saveRandRConfig(s)
# Write out the gamma values.
if self.settingall:
self.config.writeEntry("redgamma", str(s.getAllGamma()))
self.config.writeEntry("greengamma", str(s.getAllGamma()))
self.config.writeEntry("bluegamma", str(s.getAllGamma()))
else:
self.config.writeEntry("redgamma", str(s.getRedGamma()))
self.config.writeEntry("greengamma", str(s.getGreenGamma()))
self.config.writeEntry("bluegamma", str(s.getBlueGamma()))
self.config.writeEntry("dpmsSeconds", self.dpmspage.seconds)
self.config.writeEntry("dpmsEnabled", ("off","on")[self.dpmspage.enabled])
self.config.sync()
def _saveRandRConfig(self,screen):
w,h = screen.getAvailableResolutions()[screen.getResolutionIndex()]
self.config.writeEntry("width",w)
self.config.writeEntry("height",h)
self.config.writeEntry("reflectX", int( (screen.getReflection() & screen.RR_Reflect_X)!=0) )
self.config.writeEntry("reflectY", int((screen.getReflection() & screen.RR_Reflect_Y)!=0) )
self.config.writeEntry("refresh", screen.getAvailableRefreshRates()[screen.getRefreshRateIndex()])
rotationmap = {screen.RR_Rotate_0: "0", screen.RR_Rotate_90: "90",
screen.RR_Rotate_180:"180", screen.RR_Rotate_270: "270"}
self.config.writeEntry("rotate", rotationmap[screen.getRotation()])
def _selectGamma(self,i):
self.mediumpic.setPixmap(self.mediumimages[i])
def __loadImages(self):
if not self.compact_mode:
for g in ['14','16','18','20','22','24']:
self.mediumimages.append( QPixmap(self.imagedir+'gammapics/MGam'+g+'.png') )
self.previewscreen = QPixmap(self.imagedir+'monitor_screen_1280x1024.png')
self.previewscreenportrait = QPixmap(self.imagedir+'monitor_screen_1024x1280.png')
def __reset(self):
# Reset the screen settings.
self.xsetup.reset()
self.dpmspage.reset()
self._syncGUI()
# Kcontrol expects updates about whether the contents have changed.
# Also we fake the Apply and Reset buttons here when running outside kcontrol.
def _sendChangedSignal(self):
global standalone
changed = False
for s in self.xsetup.getUsedScreens():
changed = changed or s.isResolutionSettingsChanged()
changed = changed or self.xsetup.isXorgConfigChanged()
changed = changed or self.dpmspage.isChanged()
if standalone:
self.enableButton(KDialogBase.User1,changed) # Reset button
self.enableButtonApply(changed) # Apply button
else:
self.emit(SIGNAL("changed(bool)"), (changed,) )
def _badFbRestore(self):
bad_fb_restore = False
for card in self.xsetup.getGfxCards():
bad_fb_restore = bad_fb_restore or \
((card.getGfxCardModel() is not None) and card.getGfxCardModel().getBadFbRestore(card.isProprietaryDriver()))
return bad_fb_restore
############################################################################
class SizeOrientationPage(QWidget):
"""
A TabPage with all the settings for Size and Orientation of the screens,
also features Refreshrates and Dualheadsettings.
Emits the following signals:
changeSignal()
...
TODO:
* Update __doc__ with emitted signals, connect these.
* Choose screen (more than one preview)
* Relative positioning.
* Call setRefreshCombo after switching screens.
"""
def __init__(self,parent,xsetup,compact):
QWidget.__init__(self,parent)
global imagedir
self.xsetup = xsetup
self.imagedir = imagedir
self.parent = parent
self.current_screen = self.xsetup.getPrimaryScreen()
self.current_is_primary = True
self.compact_mode = compact
self._buildGUI()
self._syncGUI()
def _syncGUI(self):
if self.current_is_primary:
self.current_screen = self.xsetup.getPrimaryScreen()
else:
self.current_screen = self.xsetup.getSecondaryScreen()
self._syncGUILayout()
self._syncGUIScreen()
def _syncGUILayout(self):
# Secondary monitor radios.
available_layouts = self.xsetup.getAvailableLayouts()
may = self.xsetup.mayModifyLayout()
self.secondary_clone_radio.setEnabled(may and available_layouts & self.xsetup.LAYOUT_CLONE)
self.secondary_clone_radio.setShown(available_layouts & self.xsetup.LAYOUT_CLONE)
self.secondary_dual_radio.setEnabled(may and available_layouts & self.xsetup.LAYOUT_DUAL)
self.secondary_dual_radio.setShown(available_layouts & self.xsetup.LAYOUT_DUAL)
self.secondary_position_combo.setEnabled(may and self.xsetup.getLayout()==self.xsetup.LAYOUT_DUAL)
self.secondary_position_combo.setShown(available_layouts & self.xsetup.LAYOUT_DUAL)
self.secondary_groupbox.setEnabled(may and available_layouts != self.xsetup.LAYOUT_SINGLE)
# If only the single layout is available, then we just hide the whole radio group
self.secondary_groupbox.setShown(available_layouts!=self.xsetup.LAYOUT_SINGLE)
if self.xsetup.getLayout()!=self.xsetup.LAYOUT_SINGLE:
self.secondary_radios.setButton(self.secondary_option_ids[self.xsetup.getLayout()])
else:
if available_layouts & XSetup.LAYOUT_CLONE:
self.secondary_radios.setButton(self.secondary_option_ids[XSetup.LAYOUT_CLONE])
else:
self.secondary_radios.setButton(self.secondary_option_ids[XSetup.LAYOUT_DUAL])
self.secondary_groupbox.setChecked(self.xsetup.getLayout() != self.xsetup.LAYOUT_SINGLE)
def _syncGUIScreen(self):
# Sync the size tab.
self.resize_slider.setScreen(self.current_screen)
if self.xsetup.getLayout()!=self.xsetup.LAYOUT_DUAL:
self.resize_slider.setTitle(i18n("Screen size"))
else:
self.resize_slider.setTitle(i18n("Screen size #%1").arg(self.xsetup.getUsedScreens().index(self.current_screen)+1))
if self.xsetup.getLayout()==self.xsetup.LAYOUT_DUAL:
if not self.compact_mode:
self.monitor_preview_stack.raiseWidget(self.dual_monitor_preview)
else:
if not self.compact_mode:
self.monitor_preview_stack.raiseWidget(self.monitor_preview)
# Sync the screen orientation.
width,height = self.current_screen.getAvailableResolutions()[self.current_screen.getResolutionIndex()]
if not self.compact_mode:
self.monitor_preview.setResolution(width,height)
if self.current_screen.getRotation()==Screen.RR_Rotate_0:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_0)
elif self.current_screen.getRotation()==Screen.RR_Rotate_90:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_90)
elif self.current_screen.getRotation()==Screen.RR_Rotate_270:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_270)
else:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_180)
self.monitor_preview.setReflectX(self.current_screen.getReflection() & Screen.RR_Reflect_X)
self.monitor_preview.setReflectY(self.current_screen.getReflection() & Screen.RR_Reflect_Y)
# Set the resolutions for the dual screen preview.
if self.xsetup.getAvailableLayouts() & XSetup.LAYOUT_DUAL:
for i in [0,1]:
screen = [self.xsetup.getPrimaryScreen(), self.xsetup.getSecondaryScreen()][i]
width,height = screen.getAvailableResolutions()[screen.getResolutionIndex()]
self.dual_monitor_preview.setScreenResolution(i,width,height)
self.dual_monitor_preview.setPosition(self.xsetup.getDualheadOrientation())
self._fillRefreshCombo()
self.orientation_radio_group.setButton( \
[Screen.RR_Rotate_0, Screen.RR_Rotate_90, Screen.RR_Rotate_270,
Screen.RR_Rotate_180].index(self.current_screen.getRotation()))
# This construct above just maps an rotation to a radiobutton index.
self.mirror_horizontal_checkbox.setChecked(self.current_screen.getReflection() & Screen.RR_Reflect_X)
self.mirror_vertical_checkbox.setChecked(self.current_screen.getReflection() & Screen.RR_Reflect_Y)
width,height = self.current_screen.getAvailableResolutions()[self.current_screen.getResolutionIndex()]
if not self.compact_mode:
self.monitor_preview.setResolution(width,height)
# Enable/disable the resolution/rotation/reflection widgets.
may_edit = self.xsetup.mayModifyResolution()
self.normal_orientation_radio.setEnabled(may_edit)
available_rotations = self.current_screen.getAvailableRotations()
# Hide the whole group box if there is only one boring option.
self.orientation_group_box.setShown(available_rotations!=Screen.RR_Rotate_0)
self.left_orientation_radio.setEnabled(available_rotations & Screen.RR_Rotate_90 and may_edit)
self.left_orientation_radio.setShown(available_rotations & Screen.RR_Rotate_90)
self.right_orientation_radio.setEnabled(available_rotations & Screen.RR_Rotate_270 and may_edit)
self.right_orientation_radio.setShown(available_rotations & Screen.RR_Rotate_270)
self.upside_orientation_radio.setEnabled(available_rotations & Screen.RR_Rotate_180 and may_edit)
self.upside_orientation_radio.setShown(available_rotations & Screen.RR_Rotate_180)
self.mirror_horizontal_checkbox.setEnabled(available_rotations & Screen.RR_Reflect_X and may_edit)
self.mirror_horizontal_checkbox.setShown(available_rotations & Screen.RR_Reflect_X)
self.mirror_vertical_checkbox.setEnabled(available_rotations & Screen.RR_Reflect_Y and may_edit)
self.mirror_vertical_checkbox.setShown(available_rotations & Screen.RR_Reflect_Y)
self.resize_slider.setEnabled(may_edit)
self.size_refresh_combo.setEnabled(may_edit)
# Set the dual orientation combo.
self.secondary_position_combo.setCurrentItem(
[XSetup.POSITION_LEFTOF,
XSetup.POSITION_RIGHTOF,
XSetup.POSITION_ABOVE,
XSetup.POSITION_BELOW].index(self.xsetup.getDualheadOrientation()))
def _fillRefreshCombo(self):
# Update refresh combobox
self.size_refresh_combo.clear()
for rate in self.current_screen.getAvailableRefreshRates():
self.size_refresh_combo.insertItem(i18n("%1 Hz").arg(rate))
self.size_refresh_combo.setCurrentItem(self.current_screen.getRefreshRateIndex())
self.current_screen.setRefreshRateIndex(self.size_refresh_combo.currentItem())
def slotMonitorFocussed(self,currentMonitor):
if currentMonitor==0:
self.current_screen = self.xsetup.getPrimaryScreen()
self.current_is_primary = True
else:
self.current_screen = self.xsetup.getSecondaryScreen()
self.current_is_primary = False
self._syncGUIScreen()
def _sendChangedSignal(self):
self.emit(PYSIGNAL("changedSignal()"),())
def _buildGUI(self):
""" Assemble all GUI elements """
# Layout stuff.
top_layout = QHBoxLayout(self,0,KDialog.spacingHint())
self.top_layout = top_layout
# -- Left column with orientation and dualhead box.
vbox = QVBox(self)
top_layout.addWidget(vbox,0)
# -- Orientation group
self.orientation_group_box = QVGroupBox(vbox)
self.orientation_group_box.setTitle(i18n("Monitor Orientation"))
self.orientation_group_box.setInsideSpacing(KDialog.spacingHint())
self.orientation_group_box.setInsideMargin(KDialog.marginHint())
self.orientation_radio_group = QButtonGroup()
self.orientation_radio_group.setRadioButtonExclusive(True)
self.normal_orientation_radio = QRadioButton(self.orientation_group_box)
self.normal_orientation_radio.setText(i18n("Normal"))
self.left_orientation_radio = QRadioButton(self.orientation_group_box)
self.left_orientation_radio .setText(i18n("Left edge on top"))
self.right_orientation_radio = QRadioButton(self.orientation_group_box)
self.right_orientation_radio.setText(i18n("Right edge on top"))
self.upside_orientation_radio = QRadioButton(self.orientation_group_box)
self.upside_orientation_radio.setText(i18n("Upsidedown"))
self.mirror_horizontal_checkbox = QCheckBox(self.orientation_group_box)
self.mirror_horizontal_checkbox.setText(i18n("Mirror horizontally"))
self.connect(self.mirror_horizontal_checkbox,SIGNAL("toggled(bool)"),self.slotMirrorHorizontallyToggled)
self.mirror_vertical_checkbox = QCheckBox(self.orientation_group_box)
self.mirror_vertical_checkbox.setText(i18n("Mirror vertically"))
self.connect(self.mirror_vertical_checkbox,SIGNAL("toggled(bool)"),self.slotMirrorVerticallyToggled)
self.orientation_radio_group.insert(self.normal_orientation_radio,0)
self.orientation_radio_group.insert(self.left_orientation_radio,1)
self.orientation_radio_group.insert(self.right_orientation_radio,2)
self.orientation_radio_group.insert(self.upside_orientation_radio,3)
self.connect(self.orientation_radio_group,SIGNAL("clicked(int)"),self.slotOrientationRadioClicked)
# -- Dualhead Box.
self.secondary_groupbox = QVGroupBox(vbox)
self.secondary_groupbox.setCheckable(True)
self.secondary_groupbox.setTitle(i18n("Second screen"))
self.connect(self.secondary_groupbox,SIGNAL("toggled(bool)"),self.slotSecondMonitorToggled)
self.secondary_radios = QVButtonGroup(None) # Invisible
self.connect(self.secondary_radios,SIGNAL("pressed(int)"),self.slotSecondMonitorRadioPressed)
self.secondary_options = {}
self.secondary_option_ids = {}
# Clone radio
self.secondary_clone_radio = QRadioButton(i18n("Clone primary screen"),self.secondary_groupbox)
radio_id = self.secondary_radios.insert(self.secondary_clone_radio)
self.secondary_options[radio_id] = self.xsetup.LAYOUT_CLONE
self.secondary_option_ids[self.xsetup.LAYOUT_CLONE] = radio_id
# Dual radio
self.secondary_dual_radio = QRadioButton(i18n("Dual screen"),self.secondary_groupbox)
radio_id = self.secondary_radios.insert(self.secondary_dual_radio)
self.secondary_options[radio_id] = self.xsetup.LAYOUT_DUAL
self.secondary_option_ids[self.xsetup.LAYOUT_DUAL] = radio_id
self.secondary_radios.setButton(radio_id)
hbox = QHBox(self.secondary_groupbox)
spacer = QWidget(hbox)
spacer.setFixedSize(20,1)
hbox.setStretchFactor(spacer,0)
self.secondary_position_combo = QComboBox(0,hbox,"")
self.secondary_position_combo.insertItem(i18n("1 left of 2"))
self.secondary_position_combo.insertItem(i18n("1 right of 2"))
self.secondary_position_combo.insertItem(i18n("1 above 2"))
self.secondary_position_combo.insertItem(i18n("1 below 2"))
self.connect(self.secondary_position_combo,SIGNAL("activated(int)"),self.slotSecondaryPositionChange)
spacer = QWidget(vbox)
vbox.setStretchFactor(spacer,1)
vbox = QVBox(self)
top_layout.addWidget(vbox,1)
if not self.compact_mode:
# -- Right columns with preview, size and refresh widgets.
# -- Preview Box.
self.monitor_preview_stack = QWidgetStack(vbox)
self.monitor_preview = MonitorPreview(self.monitor_preview_stack,self.imagedir)
self.monitor_preview_stack.addWidget(self.monitor_preview)
self.connect(self.monitor_preview,PYSIGNAL("focussed()"),self.slotMonitorFocussed)
self.dual_monitor_preview = DualMonitorPreview(self.monitor_preview_stack, DUAL_PREVIEW_SIZE, self.imagedir)
self.monitor_preview_stack.addWidget(self.dual_monitor_preview)
self.connect(self.dual_monitor_preview,PYSIGNAL("pressed()"),self.slotMonitorFocussed)
self.connect(self.dual_monitor_preview,PYSIGNAL("positionChanged()"),self.slotDualheadPreviewPositionChanged)
# -- Size & Refresh Box.
if not self.compact_mode:
hbox = QHBox(vbox)
else:
hbox = QVBox(vbox)
hbox.setSpacing(KDialog.spacingHint())
self.resize_slider = ResizeSlider(hbox)
self.connect(self.resize_slider,PYSIGNAL("resolutionChange(int)"),self.slotResolutionChange)
hbox2 = QHBox(hbox)
self.refresh_label = QLabel(hbox2,"RefreshLabel")
self.refresh_label.setText(i18n("Refresh:"))
self.size_refresh_combo = QComboBox(0,hbox2,"comboBox1") # gets filled in setRefreshRates()
self.connect(self.size_refresh_combo,SIGNAL("activated(int)"),self.slotRefreshRateChange)
if self.compact_mode:
spacer = QWidget(hbox2)
hbox2.setStretchFactor(spacer,1)
spacer = QWidget(vbox)
vbox.setStretchFactor(spacer,1)
self.clearWState(Qt.WState_Polished)
def setNotification(self,text):
self.notify.setText(text)
def slotOrientationRadioClicked(self,i):
self.current_screen.setRotation(
[Screen.RR_Rotate_0, Screen.RR_Rotate_90,Screen.RR_Rotate_270, Screen.RR_Rotate_180][i])
if self.current_screen.getRotation()==Screen.RR_Rotate_0:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_0)
elif self.current_screen.getRotation()==Screen.RR_Rotate_90:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_90)
elif self.current_screen.getRotation()==Screen.RR_Rotate_270:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_270)
else:
self.monitor_preview.setRotation(MonitorPreview.ROTATE_180)
self._sendChangedSignal()
def slotMirrorHorizontallyToggled(self,flag):
# Bit flippin'
if flag:
self.current_screen.setReflection(self.current_screen.getReflection() | Screen.RR_Reflect_X)
else:
self.current_screen.setReflection(self.current_screen.getReflection() & ~Screen.RR_Reflect_X)
self.monitor_preview.setReflectX(flag)
self._sendChangedSignal()
def slotMirrorVerticallyToggled(self,flag):
# Bit flippin'
if flag:
self.current_screen.setReflection(self.current_screen.getReflection() | Screen.RR_Reflect_Y)
else:
self.current_screen.setReflection(self.current_screen.getReflection() & ~Screen.RR_Reflect_Y)
self.monitor_preview.setReflectY(flag)
self._sendChangedSignal()
def slotResolutionChange(self,i):
self.current_screen.setResolutionIndex(i)
width,height = self.current_screen.getAvailableResolutions()[i]
if not self.compact_mode:
self.monitor_preview.setResolution(width,height)
self.dual_monitor_preview.setScreenResolution(
self.xsetup.getUsedScreens().index(self.current_screen),
width,height)
self._fillRefreshCombo()
self._sendChangedSignal()
def slotRefreshRateChange(self,index):
self.current_screen.setRefreshRateIndex(index)
self._sendChangedSignal()
def setScreen(self,screen):
self.current_screen = screen
self._syncGUI()
def slotSecondMonitorToggled(self,enabled):
if enabled:
pressed_id = self.secondary_radios.selectedId()
self.xsetup.setLayout(self.secondary_options[pressed_id])
else:
self.xsetup.setLayout(self.xsetup.LAYOUT_SINGLE)
if self.xsetup.getLayout()!=self.xsetup.LAYOUT_DUAL:
self.current_screen = self.xsetup.getUsedScreens()[0]
self.secondary_position_combo.setEnabled(self.xsetup.getLayout()==XSetup.LAYOUT_DUAL)
self._syncGUIScreen()
self._sendChangedSignal()
def slotSecondMonitorRadioPressed(self,pressedId):
self.xsetup.setLayout(self.secondary_options[pressedId])
if self.xsetup.getLayout()!=XSetup.LAYOUT_DUAL:
self.current_screen = self.xsetup.getUsedScreens()[0]
self.secondary_position_combo.setEnabled(self.xsetup.getLayout()==XSetup.LAYOUT_DUAL)
if self.xsetup.getLayout()==XSetup.LAYOUT_DUAL:
if not self.compact_mode:
self.monitor_preview_stack.raiseWidget(self.dual_monitor_preview)
else:
if not self.compact_mode:
self.monitor_preview_stack.raiseWidget(self.monitor_preview)
self._syncGUIScreen()
self._sendChangedSignal()
def slotSecondaryPositionChange(self,index):
position = [XSetup.POSITION_LEFTOF,XSetup.POSITION_RIGHTOF,XSetup.POSITION_ABOVE,XSetup.POSITION_BELOW][index]
self.xsetup.setDualheadOrientation(position)
self.dual_monitor_preview.setPosition(position)
self._sendChangedSignal()
def slotDualheadPreviewPositionChanged(self,position):
self.xsetup.setDualheadOrientation(position)
index = {
XSetup.POSITION_LEFTOF:0,
XSetup.POSITION_RIGHTOF:1,
XSetup.POSITION_ABOVE:2,
XSetup.POSITION_BELOW:3
}[position]
self.secondary_position_combo.setCurrentItem(index)
self._sendChangedSignal()
def setMargin(self,margin):
self.top_layout.setMargin(margin)
def setSpacing(self,spacing):
self.top_layout.setSpacing(spacing)
############################################################################
class DpmsPage(QWidget):
# Mapping values in seconds to human-readable labels.
intervals = (
(60,i18n("1 minute")),
(120,i18n("2 minutes")),
(180,i18n("3 minutes")),
(300,i18n("5 minutes")),
(600,i18n("10 minutes")),
(900,i18n("15 minutes")),
(1200,i18n("20 minutes")),
(1500,i18n("25 minutes")),
(1800,i18n("30 minutes")),
(2700,i18n("45 minutes")),
(3600,i18n("1 hour")),
(7200,i18n("2 hours")),
(10800,i18n("3 hours")),
(14400,i18n("4 hours")),
(18000,i18n("5 hours")))
def __init__(self,parent = None,name = None,modal = 0,fl = 0):
global imagedir
QWidget.__init__(self,parent)
# Where to find xset.
self.xset_bin = os.popen('which xset').read()[:-1]
if not name:
self.setName("DPMSTab")
dpms_tab_layout = QVBoxLayout(self,0,0,"DPMSTabLayout")
self.top_layout = dpms_tab_layout
hbox = QHBox(self)
hbox.setSpacing(KDialog.spacingHint())
dpms_tab_layout.addWidget(hbox)
self.dpmsgroup = QHGroupBox(hbox,"dpmsgroup")
self.dpmsgroup.setInsideSpacing(KDialog.spacingHint())
self.dpmsgroup.setInsideMargin(KDialog.marginHint())
self.dpmsgroup.setTitle(i18n("Enable power saving"))
self.dpmsgroup.setCheckable(1)
self.connect(self.dpmsgroup,SIGNAL("toggled(bool)"),self.slotDpmsToggled)
hbox2 = QHBox(self.dpmsgroup)
hbox2.setSpacing(KDialog.spacingHint())
dpmstext = QLabel(hbox2,"dpmstext")
dpmstext.setText(i18n("Switch off monitor after:"))
self.dpmscombo = QComboBox(0,hbox2,"dpmscombo")
self.fillCombo(self.dpmscombo)
self.connect(self.dpmscombo,SIGNAL("activated(int)"),self.slotDpmsActivated)
spacer = QWidget(hbox2)
hbox2.setStretchFactor(spacer,1)
self.energystarpix = QLabel(hbox,"energystarpix")
self.energystarpix.setSizePolicy(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed,0,0,self.energystarpix.sizePolicy().hasHeightForWidth()))
self.energystarpix.setMinimumSize(QSize(150,77))
self.energystarpix.setPixmap(QPixmap(imagedir+"../energystar.png"))
self.energystarpix.setScaledContents(1)
bottomspacer = QSpacerItem(51,160,QSizePolicy.Minimum,QSizePolicy.Expanding)
dpms_tab_layout.addItem(bottomspacer)
self.clearWState(Qt.WState_Polished)
self.readDpms()
def fillCombo(self,combo):
""" Fill the combobox with the values from our list """
for interval in self.intervals:
combo.insertItem(interval[1])
def slotDpmsActivated(self,index):
""" Another dpms value has been chosen, update buttons at bottom. """
self.emit(PYSIGNAL("changedSignal()"), ())
def slotDpmsToggled(self,bool):
""" Dpms checkbox has been toggled, update buttons at bottom. """
self.emit(PYSIGNAL("changedSignal()"), ())
def readDpms(self):
# FIXME it is not the widget's job to read or change the values, just to present the GUI.
""" Read output from xset -q and parse DPMS settings from it. """
# FIXME: localisation problem running this command.
lines = ExecWithCapture(self.xset_bin,[self.xset_bin,'-q']).split('\n')
self.dpms_min = 1800
self.dpms_enabled = False
for line in lines:
if line.strip().startswith("Standby"):
self.dpms_min = int(line.strip().split()[5]) # TODO: More subtle exception handling. ;)
if line.strip().startswith("DPMS is"):
self.dpms_enabled = line.strip().split()[2]=="Enabled"
if self.dpms_min==0: # 0 also means don't use Standby mode.
self.dpms_enabled = False
self.dpms_min = 1800
self.dpmsgroup.setChecked(self.dpms_enabled)
for i in range(len(self.intervals)):
diff = abs(self.intervals[i][0] - self.dpms_min)
if i==0:
last_diff = diff
if (last_diff <= diff and i!=0) or (last_diff < diff):
i = i-1
break
last_diff = diff
self.dpmscombo.setCurrentItem(i)
def isChanged(self):
""" Check if something has changed since startup or last apply(). """
if self.dpmsgroup.isChecked():
if self.intervals[self.dpmscombo.currentItem()][0] != self.dpms_min:
return True
if self.dpmsgroup.isChecked() != self.dpms_enabled:
return True
return False
else:
# self.dpmsgroup.isChecked() is False
return self.dpms_enabled # self.dpms_enabled != False
def applyDpms(self):
""" Use xset to apply new dpms settings. """
self.enabled = self.dpmsgroup.isChecked()
self.seconds = self.intervals[self.dpmscombo.currentItem()][0]
if self.enabled:
# Switch dpms on and set timeout interval.
cmd_on = "%s +dpms" % self.xset_bin
cmd_set = "%s dpms %i %i %i" % (self.xset_bin, self.seconds,self.seconds,self.seconds)
print cmd_set
if os.system(cmd_set) != 0:
print "DPMS command failed: ", cmd_set
else:
# Switch dpms off.
cmd_on = "%s -dpms" % self.xset_bin
if os.system(cmd_on) != 0:
print "DPMS command failed: ", cmd_on
self.readDpms()
self.emit(PYSIGNAL("changedSignal()"), ())
def apply(self):
self.applyDpms()
def reset(self):
for i in range(len(self.intervals)):
if self.intervals[i][0] == self.dpms_min:
self.dpmscombo.setCurrentItem(i)
break
self.dpmsgroup.setChecked(self.dpms_enabled)
def setMargin(self,margin):
self.top_layout.setMargin(margin)
def setSpacing(self,spacing):
self.top_layout.setSpacing(spacing)
############################################################################
def create_displayconfig(parent,name):
""" Factory function for KControl """
global kapp
kapp = TDEApplication.kApplication()
return DisplayApp(parent, name)
############################################################################
def MakeAboutData():
aboutdata = TDEAboutData("guidance",programname,version, \
"Display and Graphics Configuration Tool", TDEAboutData.License_GPL, \
"Copyright (C) 2003-2007 Simon Edwards", \
"Thanks go to Phil Thompson, Jim Bublitz and David Boddie.")
aboutdata.addAuthor("Simon Edwards","Developer","simon@simonzone.com", \
"http://www.simonzone.com/software/")
aboutdata.addAuthor("Sebastian Kügler","Developer","sebas@kde.org", \
"http://vizZzion.org");
aboutdata.addCredit("Pete Andrews","Gamma calibration pictures/system",None, \
"http://www.photoscientia.co.uk/Gamma.htm")
return aboutdata
if standalone:
aboutdata = MakeAboutData()
TDECmdLineArgs.init(sys.argv,aboutdata)
kapp = TDEApplication()
displayapp = DisplayApp()
displayapp.exec_loop()
|