~ulrich3110/lorze/lorze_git_master

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
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
#!/usr/bin/python
# -*- coding: utf-8 -*-

# LORZE erasandcad, a 2D CAD with an intuitive user interface,
# simple and easy. <http://erasand.jimdo.com/projekte/lorze/>
# (C) 2013, Andreas Ulrich
#
# This file is part of "LORZE erasandcad"
# "LORZE erasandcad" 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 3 of the
# License, or (at your option) any later version.
#
# "LORZE erasandcad" is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See the GNU General Public License for more details. You should
# have received a copy of the GNU General Public License along with
# "LORZE erasandcad".  If not, see <http://www.gnu.org/licenses/>.

import locale
import sys
import os
import wx
import wx.lib.mixins.listctrl as listmix
import wx.html as html


# name for translations texts
_ = wx.GetTranslation


class SortedListCtrl(wx.ListCtrl, listmix.ColumnSorterMixin):
    '''SortedListCtrl(parent, selection)
       class for sorted list controls

    from http://zetcode.com/wxpython/
    parent = wx.window
    selection: True = multi selection, False = single selection

    GetListCtrl()  return object

    '''

    def __init__(self, parent, selection):
        if selection == True:
            lcstyle = wx.LC_REPORT
        else:
            lcstyle = wx.LC_REPORT | wx.LC_SINGLE_SEL
        wx.ListCtrl.__init__(self, parent, -1, style=lcstyle)
        sortdic = parent.get_sorted_list_dict()
        listmix.ColumnSorterMixin.__init__(self, len(sortdic))
        self.itemDataMap = sortdic

    def GetListCtrl(self):
        return self


class LorzeDlgOptions(wx.Dialog):
    '''LorzeDlgOptions(parent, LorzeOptions, LorzeValueCheck,
                       LorzeDlgHelper)
       Dialog for lorze options.

    Set dialogue: list control, button [edit], button [ok],
                  button [cancel], button [reset].
    parent= wx.Window

    conv_window_size('width/height', minimum)
    Control window size.

    dialogue_size()
    Calculate the dialogue size.

    edit_option()
    Edit the selected option.

    get_restart()
    Return the value of restart, True or False.

    get_sorted_list_dict()
    Return sorted list-control dictionairy.

    on_cancel(event)
    Event for button [cancel], discard all changes.

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_edit(event)
    Event for button [edit].

    on_item_selected(event)
    Event for doubleclick on list control.

    on_ok(event)
    Event for button [ok].

    on_reset(event)
    Event for button [reset].

    set_defaults()
    Read default values and put them to the dialogue.

    set_list_ctrl_new()
    Clear and set the list control.

    set_sorted_list_dict()
    Set sorted list dictionairy.

    '''

    def __init__(self, parent, options, valchck, dlghelper):
        # Set gui: list control, button [edit], button [ok],
        # button [cancel], button [reset].
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # LorzeValueCheck
        self.__valchck = valchck
        # DialogHelper
        self.__dlg = dlghelper
        # Flag for gui restart
        self.__restart = False
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subcalss
        wx.Dialog.__init__(self, self.__parent, wx.ID_ANY,
                           _(u'Program options'), size=(wdlg, hdlg),
                           style=wx.DEFAULT_DIALOG_STYLE |
                                 wx.RESIZE_BORDER)
        # Datas for list control: orderlist = order to show options
        self.__orderlist = ['sensitive',
                            'scsize',
                            'scwidth',
                            'scmarksize',
                            'sccolpoint',
                            'sccolsegm',
                            'sccolelem',
                            'selcol',
                            'prevcol',
                            'prevwidth',
                            'prevstyle',
                            'dezplcs',
                            'dlgborder',
                            'gdiborder',
                            'cursorwin',
                            'cursorselect',
                            'cursordraw',
                            'stcoordw',
                            'sbrange',
                            'sbsize',
                            'wheelmagnif',
                            'wheelreduce',
                            'maxstylescale',
                            'maxuserscale']
        # Labels of the options: dictionairy
        self.__labeldict = {
             'gdiborder': _(u'Border: Graphic area'),
             'dezplcs': _(u'Number of dezimalplaces'),
             'cursorwin': _(u'Cursor: Menus & dialogues'),
             'cursordraw': _(u'Cursor: Drawing commands'),
             'cursorselect': _(u'Cursor: Selections'),
             'dlgborder': _(u'Size: Border between widgets'),
             'sbrange': _(u'Size: Scrollbar range'),
             'sbsize': _(u'Size: Scrollbar slider'),
             'wheelmagnif': _(u'Mouse wheel: Magnification'),
             'wheelreduce': _(u'Mouse wheel: Reduce'),
             'sensitive': _(u'Size: Smart cursor'),
             'maxstylescale': _(u'Maximal zoom: Line types'),
             'maxuserscale': _(u'Maximal zoom: Drawing'),
             'scsize': _(u'Size: Cursor mark symbol'),
             'scwidth': _(u'Size: Cursor mark pen'),
             'sccolpoint': _(u'Colour: Point mark'),
             'sccolsegm': _(u'Colour: Segment mark'),
             'sccolelem': _(u'Colour: Element mark'),
             'scmarksize': _(u'Size: Marked elements'),
             'prevcol': _(u'Colour: Element preview'),
             'prevwidth': _(u'Size: Preview pen'),
             'prevstyle': _(u'Style: Preview pen'),
             'stcoordw': _(u'Size: Width of coordinate fields'),
             'selcol': _(u'Colour: Selected elements'),
             'defaultattributes': _(u'Defaults: Drawing  attributes')}
        # Text for the TextDialog, dictionairy
        self.__textdict = {
             'dezplcs': _(u'Please enter the number of dezimal places'),
             'dlgborder': _(u'Please enter the distance between ' + \
                          'the widgets in the user interface'),
             'sbrange': _(u'Please enter the range of the scroll bars'),
             'sbsize': _(u'Please enter the size of the scroll bar ' + \
                       'slider'),
             'wheelmagnif': _(u'Please enter the magnification ' + \
                            'using the mouse wheel'),
             'wheelreduce': _(u'Please enter the reduction using ' + \
                            'the mouse wheel'),
             'sensitive': _(u'Please enter the size of the smart ' + \
                          'cursor'),
             'maxstylescale': _(u'Please specify the  highest ' + \
                              'magnification  to ' + \
             'show linetypes'),
             'maxuserscale': _(u'Please enter the highest ' + \
                             'magnification for drawing'),
             'scsize': _(u'Please enter the size of the marker symbol'),
             'scwidth': _(u'Please enter the strength of the ' + \
                        'marking pen'),
             'scmarksize': _(u'Please enter the magnification of ' + \
                           'the line width'),
             'prevwidth': _(u'Please enter the line width for the ' + \
                          'preview'),
             'stcoordw': _(u'Please enter the width of the ' + \
                         'coordinate fields in the status bar')}
        # Values for input dialouges
        # (number of values, minimum, maximum).
        # None for not used
        self.__numberdict = {'dezplcs': (None, 0, 10),
                             'dlgborder': (None, 1, 100),
                             'sbrange': (None, 10, 1000),
                             'sbsize': (None, 1, 100),
                             'wheelmagnif': (None, 1.01, 100.0),
                             'wheelreduce': (None, 0.01, 0.99),
                             'sensitive': (None, 1, 100),
                             'maxstylescale': (None, 2, 10000),
                             'maxuserscale': (None, 2, 10000),
                             'scsize': (None, 2, 100),
                             'scwidth': (None, 1, 100),
                             'scmarksize': (None, 1.0, 100.0),
                             'prevwidth': (None, 0, 100),
                             'stcoordw': (None, 20, 1000)}

        # Set defaults from options
        self.set_defaults()
        # List control
        self.set_sorted_list_dict()
        self.__list = SortedListCtrl(self, False)
        width = self.__options.get_('optlistwidth0')
        self.__list.InsertColumn(0, _(u'Label'),
                                width=width)
        width = self.__options.get_('optlistwidth1')
        self.__list.InsertColumn(1, _(u'Value'),
                                width=width)
        self.set_list_ctrl_new()
        # Dialog buttons
        buttonedit = wx.Button(self, label=_(u'Edit option'))
        buttonok = wx.Button(self, label=_(u'OK'))
        buttoncancel = wx.Button(self, label=_(u'Cancel'))
        buttonreset = wx.Button(self, label=_(u'Reset'))
        # Dialog bindings
        buttonedit.Bind(wx.EVT_BUTTON, self.on_edit)
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        buttoncancel.Bind(wx.EVT_BUTTON, self.on_cancel)
        buttonreset.Bind(wx.EVT_BUTTON, self.on_reset)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        # listcontrol bindings
        self.__list.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
                         self.on_item_selected)
        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.__list, 1, wx.EXPAND | wx.ALL, dlgborder)
        gbox = wx.GridSizer(1, 4, dlgborder, dlgborder)
        gbox.AddMany([(buttonedit, 0, wx.EXPAND, dlgborder),
                      (buttonok, 0, wx.EXPAND, dlgborder),
                      (buttoncancel, 0, wx.EXPAND, dlgborder),
                      (buttonreset, 0, wx.EXPAND, dlgborder)])
        vbox.Add(gbox, 0, wx.EXPAND | wx.ALL, dlgborder)
        self.SetSizer(vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event for button [ok].'''
        for i in ('gdiborder',
                   'dezplcs',
                   'cursorwin',
                   'cursordraw',
                   'cursorselect',
                   'dlgborder',
                   'sbrange',
                   'sbsize',
                   'wheelmagnif',
                   'wheelreduce',
                   'sensitive',
                   'maxstylescale',
                   'maxuserscale',
                   'scsize',
                   'scwidth',
                   'sccolpoint',
                   'sccolsegm',
                   'sccolelem',
                   'scmarksize',
                   'prevcol',
                   'prevwidth',
                   'prevstyle',
                   'stcoordw',
                   'selcol'):
            # Set options to LorzeOptions.
            self.__options.set_(i, self.__valuedict[i])
        # Set restart True (resart the gui).
        self.__restart = True
        self.Close()

    def on_cancel(self, event):
        ''' Event for button [cancel], discard all changes.'''
        self.__restart = False
        self.Close()

    def on_reset(self, event):
        '''Event for button [reset].'''
        # Confirmation, ar you sure.
        dlg = wx.MessageDialog(None,
                               _(u'Are yo sure to put the settings ' + \
                               'back? This command can not be ' + \
                               'undone..'), _(u'Confirmation'),
                                wx.YES_NO | wx.NO_DEFAULT |
                                wx.ICON_QUESTION)
        answer = dlg.ShowModal()

        if answer == wx.ID_YES:
            # Yes: reset options
            # set new defaults and set new the listcontrol
            # set resetted sizes to parent frame
            # set resetted sizes to dialogue
            self.__options.reset()
            self.set_defaults()
            self.set_list_ctrl_new()
            self.__parent.SetSize((self.__options.get_('framewidth'),
                                   self.__options.get_('frameheight')))
            self.__parent.Centre()
            wdlg, hdlg = self.dialogue_size()
            self.SetSize((wdlg, hdlg))
            self.Centre()
            self.__list.SetColumnWidth(0,
                        self.__options.get_('optlistwidth0'))
            self.__list.SetColumnWidth(1,
                        self.__options.get_('optlistwidth1'))

    def get_restart(self):
        '''Return the value of restart, True or False.'''
        return(self.__restart)

    def set_defaults(self):
        '''Read default values and put them to the dialogue.'''
        self.__valuedict = {}
        # set single values
        for i in ('gdiborder',
                  'dezplcs',
                  'cursorwin',
                  'cursordraw',
                  'cursorselect',
                  'dlgborder',
                  'sbrange',
                  'sbsize',
                  'wheelmagnif',
                  'wheelreduce',
                  'sensitive',
                  'maxstylescale',
                  'maxuserscale',
                  'scsize',
                  'scwidth',
                  'sccolpoint',
                  'sccolsegm',
                  'sccolelem',
                  'scmarksize',
                  'prevcol',
                  'prevwidth',
                  'prevstyle',
                  'stcoordw',
                  'selcol'):
            self.__valuedict[i] = str(self.__options.get_(i))

    def set_list_ctrl_new(self):
        '''Clear and set the list control.'''
        self.__list.DeleteAllItems()
        # Get items from SortedListDictionairy and add to listcontrol.
        for key, data in self.__sortedlistdict.items():
            index = self.__list.InsertStringItem(sys.maxint, data[0])
            self.__list.SetStringItem(index, 1, data[1])
            self.__list.SetItemData(index, key)

    def on_item_selected(self, event):
        '''Event for doubleclick on list control.'''
        self.edit_option()

    def on_edit(self, event):
        '''Event for button [edit].'''
        self.edit_option()

    def edit_option(self):
        '''Edit the selected option.'''
        index = self.__list.GetFocusedItem()
        label = self.__list.GetItemText(index)
        for key, data in self.__labeldict.items():
            if data == label:
                seloption = key
        if seloption in ('gdiborder'):
            # Get string from list of selection dialogue
            label = self.__labeldict['gdiborder']
            list_ = self.__parent.get_borders_dict().keys()
            def_ = self.__valuedict['gdiborder']
            text = self.__dlg.list_selection(label, list_, def_)
        elif seloption in ('dezplcs',
                           'dlgborder',
                           'sbrange',
                           'sbsize',
                           'sensitive',
                           'maxuserscale',
                           'maxstylescale',
                           'scsize',
                           'scwidth',
                           'prevwidth',
                           'stcoordw'):
            # Get text from text entry dialogue
            text = self.__dlg.text_dialog(self.__labeldict[seloption],
                                         self.__textdict[seloption],
                                         self.__valuedict[seloption])
        elif seloption in ('cursorwin',
                           'cursordraw',
                           'cursorselect'):
            # Get string from list selection dialogue
            label = self.__labeldict[seloption]
            list_ = self.__parent.get_cursors_dict().keys()
            def_ = self.__valuedict[seloption]
            text = self.__dlg.list_selection(label, list_, def_)
        elif seloption in ('wheelmagnif',
                        'wheelreduce',
                        'scmarksize'):
            # Get text from text entry dialogue
            text = self.__dlg.text_dialog(self.__labeldict[seloption],
                                         self.__textdict[seloption],
                                         self.__valuedict[seloption])
        elif seloption in ('sccolpoint',
                        'sccolsegm',
                        'sccolelem',
                        'prevcol',
                        'selcol'):
            # Get color as html string from color selection dialogue.
            def_ = '#' + self.__valuedict[seloption]
            colour = self.__dlg.color_dialog(def_)
            if colour != '':
                # Clicked ok, get colour html string.
                text = colour.lstrip('#')
            else:
                text = ''
        elif seloption in ('prevstyle'):
            # Get string from list selection dialogue.
            # Get list from dictionairy in GraphicPanel.
            stylelist = self.__parent.get_line_style_dict().keys()
            # Delete 'wx.USER_DASH' from list.
            for i in range(len(stylelist)):
                if stylelist[i] == 'user dash':
                    del stylelist[i]
                    break
            label = self.__labeldict[seloption]
            def_ = self.__valuedict[seloption]
            text = self.__dlg.list_selection(label, stylelist, def_)
            text = text + ' | '
        else:
            # Option not found, no action.
            return
        # Correct value with LorzeOptions.check(..) and set value.
        if text != '':
            self.__valuedict[seloption] = str(self.__options.check(\
                                              seloption, text))
            # Delete selected item from list control.
            self.__list.DeleteItem(index)
            # Set actualized item to list control.
            self.__list.InsertStringItem(index,
                                         self.__labeldict[seloption])
            self.__list.SetStringItem(index, 1,
                                      self.__valuedict[seloption])
            self.__list.SetItemData(index, index)

    def set_sorted_list_dict(self):
        '''Set sorted list dictionairy.'''
        # Dictionairy, {index:('label', 'value'),  }.
        self.__sortedlistdict = {}
        index = 0
        for i in self.__orderlist:
            self.__sortedlistdict[index] = (self.__labeldict[i],
                                            self.__valuedict[i])
            index = index + 1

    def get_sorted_list_dict(self):
        '''Return sorted list-control dictionairy.'''
        return(self.__sortedlistdict)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options.
        wdlg, hdlg = self.GetSize()
        colw0 = self.__list.GetColumnWidth(0)
        colw1 = self.__list.GetColumnWidth(1)
        self.__options.set_('dlgoptwidth', wdlg)
        self.__options.set_('dlgoptheight', hdlg)
        self.__options.set_('optlistwidth0', colw0)
        self.__options.set_('optlistwidth1', colw1)
        event.Skip()

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlgoptwidth')
        hdlg = self.__options.get_('dlgoptheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def conv_window_size(self, text, minimum):
        '''Control window size.'''
        # text = 'width/height', minimum = integer.
        text = str(text)
        try:
            minimum = int(minimum)
        except ValueError:
            minimum = 200
        size = self.__valchck.string_to_list(text, '/', False)
        if size and len(size) > 1:
            wdisp, hdisp = wx.GetDisplaySize()
            if size[0] < minimum:
                size[0] = minimum
            elif size[0] > wdisp:
                size[0] = wdisp
            if size[1] < minimum:
                size[1] = minimum
            elif size[1] > hdisp:
                size[1] = hdisp
            return(str(size[0]) + '/' + str(size[1]))
        else:
            return('')


class LorzeAbout():
    '''LorzeAbout(LorzeOptions), about dialouge

    Dialogue with a about box.

    '''

    def __init__(self, options):
        ''' Dialogue with a about box.'''
        # LorzeOptions
        self.__options = options
        # Set texts and show infobox
        info = wx.AboutDialogInfo()
        info.SetIcon(wx.Icon('../Icons/LORZE_192.png',
                             wx.BITMAP_TYPE_PNG))
        info.SetName(self.__options.get_('frametitle'))
        info.SetDescription(_(u'LORZE erasandcad, a 2D CAD ' + \
                            'with an  intuitive user interface, ' + \
                            'simple and easy.'))
        info.SetCopyright(_(u'(C) 2013 Andreas Ulrich'))
        info.SetWebSite(_(u'http://erasand.jimdo.com/' + \
                        'python-programme/lorze/'))
        t1 = _(u'This program is free software: you can ' + \
             'redistribute it and/or modify it under the')
        t2 = _(u'terms of the GNU General Public License as ' + \
             'published by the Free Software Foundation,')
        t3 = _(u'either version 3 of the License, or (at your ' + \
             'option) any later version.')
        t4 = _(u'This program is distributed in the hope that it ' + \
             'will be useful, but WITHOUT ANY')
        t5 = _(u'WARRANTY; without even the implied warranty of ' + \
             'MERCHANTABILITY or FITNESS FOR A')
        t6 = _(u'PARTICULAR PURPOSE. See the GNU General Public ' + \
             'License for more details.')
        t7 = _(u'You should have received a copy of the ' + \
             'GNU General Public License along with')
        t8 = _(u'this program.  If not, see ' + \
             '<http://www.gnu.org/licenses/>.')
        info.SetLicence(t1 + '\n' + t2 + '\n' + t3 + '\n\n' + t4 + \
                        '\n' + t5 + '\n' + t6 + '\n\n' + t7 + '\n' + t8)
        info.AddDeveloper(_(u'Andreas Ulrich'))
        info.AddDocWriter(_(u'Andreas Ulrich'))
        info.AddArtist(_(u'Tango project ' + \
                       '<http://tango.freedesktop.org>\n' + \
                       'Wikipedia <http://www.wikipedia.org>\n' + \
                       'Andreas Ulrich'))
        info.AddTranslator(_(u'Andeas Ulrich'))
        wx.AboutBox(info)


class LorzeHelp(wx.Dialog):
    '''LorzeHelp(parent, LorzeOptions), help dialouge

    Set dialogue: html window, [ok]
    parent = wx.window

    dialogue_size()  Calculate the dialogue size.

    on_dialogue_close(event)  Event to assume the dialogue sizes.

    on_exit(event)  Event for button [ok].

    '''

    def __init__(self, parent, options):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # Get settings for dialog from options.
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subclass
        wx.Dialog.__init__(self, self.__parent, wx.ID_ANY,
                           _(u'LORZE erasandcad HELP'), size=(wdlg,
                           hdlg), style=wx.DEFAULT_DIALOG_STYLE |
                           wx.RESIZE_BORDER)
        # Help window
        htmlhelp = html.HtmlWindow(self, wx.ID_ANY, style=wx.NO_BORDER)
        # Select language
        wxlang = locale.getdefaultlocale()
        wxlang = wxlang[0][:2]
        if wxlang == 'de':
            htmlhelp.LoadFile('../Documentation/HTML/DE_hilfe.html')
        else:
            htmlhelp.LoadPage('../Documentation/HTML/EN_help.html')
        # Buttons
        buttonok = wx.Button(self, label=_(u'OK'))
        # Dialogue bindings
        buttonok.Bind(wx.EVT_BUTTON, self.on_exit)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(htmlhelp, 2, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(buttonok, 0, wx.ALIGN_RIGHT | wx.ALL, dlgborder)
        self.SetSizer(vbox)
        self.Centre()

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlghelpwidth')
        hdlg = self.__options.get_('dlghelpheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue.  Write the sizes to the options.
        wdlg, hdlg = self.GetSize()
        self.__options.set_('dlghelpwidth', wdlg)
        self.__options.set_('dlghelpheight', hdlg)
        event.Skip()

    def on_exit(self, event):
        '''Event for button [ok].'''
        self.Close()


class LorzeDlgHelper():
    '''LorzeDlgHelper(parent, LorzeOptions), standard dialogues.

    wx.Window

    color_dialog('default')
    Dialog to select color, return '#rrggbb' or '',
    default' in html syntax, '#rrggbb'.

    list_selection('title', [list], 'default')
    Dialogue for list selection. (get_choice() to get selection).
    'title' of the dialogue, string.
    List with strings, [string,  ].
    'default' for selected entry in listbox, string.

    open_dialog('label', 'filedir', 'filename', 'wildcard')
    Dialogue to open files, return 'path' or ''.
    'label' title of dialogue, string.
    'filedir' default directory, string.
    'filename' default file, string.
    'wildcard' string, 'Python (*.py) | *.py|All (*.*) | *.*'

    save_dialog('label', 'filedir', 'filename', 'wildcard', 'defext')
    Save dialogue, extension & overwrite check, return 'path' or ''.
    'label' title of dialogue, string.
    'filedir' default directory, string.
    'filename' default file, string.
    'wildcard' 'Python (*.py) | *.py | All (*.*) | *.*'
    'defext' string, compulsory extension, '.py'

    text_dialog(title, label, default),
    Dialogue to entry text, return 'text' or ''.
    'title' of the dialogue, string.
    'label' description for the input.
    'default' entry text

    '''

    def __init__(self, parent, options):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options

    def open_dialog(self, label, filedir, filename, wildcard):
        '''Dialogue to open files, return 'path' or ''.'''
        # 'label' title of dialogue, string.
        # 'filedir' default directory, string.
        # 'filename' default file, string.
        # 'wildcard' string, 'Python (*.py) | *.py | All (*.*) | *.*'
        dlg = wx.FileDialog(self.__parent, label, filedir, filename,
                            wildcard, wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            # Clicked ok, set path, destroy dialog, return path.
            path = dlg.GetPath()
            dlg.Destroy()
            return(path)
        else:
            # Not clicked ok, destroy dialog, return ''.
            dlg.Destroy()
            return('')

    def save_dialog(self, label, filedir, filename, wildcard, defext):
        '''Save dialogue, overwrite check, return 'path' or ''.'''
        # 'label' title of dialogue, string.
        # 'filedir' default directory, string.
        # 'filename' default file, string.
        # 'wildcard' 'Python (*.py) | *.py | All (*.*) | *.*'
        # 'defext' string, compulsory extension, '.py'
        dlg = wx.FileDialog(self.__parent, label, filedir, filename,
                            wildcard, wx.FD_SAVE)
        if dlg.ShowModal() == wx.ID_OK:
            # clicked ok, set path, destroy dialog
            path = dlg.GetPath()
            dlg.Destroy()
            if path.endswith(defext):
                # Check extension, correct extension, syntax for the os.
                path = os.path.normpath(path + defext)
            if os.path.exists(path):
                # File already exist, overwrite?, show dialog and get
                # answer.
                quest = _(u'The file already exists: ') + path + \
                        _(u'. Do you want to overwrite ?')
                title = _(u'Confirmation')
                style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION
                dlg = wx.MessageDialog(None, quest, title, style)
                answer = dlg.ShowModal()
                if answer == wx.ID_NO:
                    # Do not overwrite, return ''
                    return('')
                else:
                    # Overwrite, return 'path'
                    return(path)
            else:
                # File dont exist, all ok
                return(path)
        else:
            # Not clicked ok, destroy dialog
            dlg.Destroy()
            return('')

    def color_dialog(self, default):
        '''Dialog to select color, return '#rrggbb' or ''.'''
        # 'default' in html syntax, '#rrggbb'.
        defaultdata = wx.ColourData()
        defaultdata.SetColour(default)
        # Dialog
        dlg = wx.ColourDialog(self.__parent, data=defaultdata)
        dlg.GetColourData().SetChooseFull(True)
        # Show dialog
        if dlg.ShowModal() == wx.ID_OK:
            # Clicked ok
            data = dlg.GetColourData()
            return(data.GetColour().GetAsString(wx.C2S_HTML_SYNTAX))
        else:
            # Not clicked ok
            return('')

    def text_dialog(self, title, label, default):
        '''Dialogue to entry text, return 'text' or ''.'''
        # 'title' of the dialogue, string.
        # 'label' description for the input.
        # 'default' entry text
        dlg = wx.TextEntryDialog(self.__parent, label, title)
        dlg.SetValue(default)
        if dlg.ShowModal() == wx.ID_OK:
            # Clicked ok
            text = dlg.GetValue()
        else:
            # Not clicked ok
            text = ''
        dlg.Destroy()
        return(text)

    def list_selection(self, title, choicelist, default):
        '''Dialogue for list selection. To get: get_choice().'''
        # 'title' of the dialogue, string.
        # List with strings, [string,  ].
        # 'default' for selected entry in listbox, string.
        dlg = DlgListSel(self.__parent, self.__options, title,
                         choicelist, default)
        dlg.ShowModal()
        # Get selection, close dialogue, return choice, '' for cancel
        choice = dlg.get_choice()
        dlg.Destroy()
        return(choice)


class DlgListSel(wx.Dialog):
    '''DlgListSel(parent, LorzeOptions, title, list, default)
       List selection dialogue.

    parent = wx.window
    'title' of the dialogue
    list for listbox, [string,  ]
    'default' for selected entry in listbox, string
    GUI: List, ok, cancel

    cancel_dialogue()
    Discard selection, close dialouge.

    dialogue_size()
    Calculate the dialogue size.

    get_choice()
    Return 'selection'.

    ok_dialogue()
    Assume selection, close dialogue.

    on_cancel(event)
    Event for button cancel.

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_key_down(event)
    Event for keys, esc, return, enter.

    on_ok(event)
    Event for button ok.

    '''

    def __init__(self, parent, options, title, choicelist, default):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subclass
        wx.Dialog.__init__(self, parent, wx.ID_ANY, title, size=(wdlg,
                           hdlg), style=wx.DEFAULT_DIALOG_STYLE |
                           wx.RESIZE_BORDER)
        # Choicelist and Choiceindex
        self.__choicelist = choicelist
        self.__choiceindex = None
        # Listbox
        self.__list = wx.ListBox(self, size=(-1, -1),
                                 choices=self.__choicelist)
        # Search index of default and select default.
        for i in range(len(self.__choicelist)):
            if self.__choicelist[i] == default:
                self.__list.SetSelection(i)
        buttonok = wx.Button(self, label=_(u'OK'))
        buttoncancel = wx.Button(self, label=_(u'Cancel'))
        # Bindings
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        buttoncancel.Bind(wx.EVT_BUTTON, self.on_cancel)
        self.__list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_ok)
        self.__list.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.__list, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(buttonok, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox.Add(buttoncancel, 1, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(hbox, 0, wx.EXPAND)
        # Set focus on list for key events.
        self.__list.SetFocus()
        self.SetSizer(vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event for button ok.'''
        self.ok_dialogue()

    def on_cancel(self, event):
        '''Event for button cancel.'''
        self.cancel_dialogue()

    def get_choice(self):
        '''Return 'selection'.'''
        if self.__choiceindex is None:
            return('')
        else:
            return(self.__choicelist[self.__choiceindex])

    def cancel_dialogue(self):
        '''Discard selection, close dialogue.'''
        self.__choiceindex = None
        self.Close()

    def ok_dialogue(self):
        '''Assume selection, close dialogue.'''
        self.__choiceindex = self.__list.GetSelection()
        self.Close()

    def on_key_down(self, event):
        '''Event for keys, esc, return, enter.'''
        if event.GetKeyCode() == wx.WXK_ESCAPE:
            self.cancel_dialogue()
        elif event.GetKeyCode() == wx.WXK_RETURN:
            self.ok_dialogue()
        elif event.GetKeyCode() == wx.WXK_NUMPAD_ENTER:
            self.ok_dialogue()
        elif event.GetKeyCode() == wx.WXK_UP:
            index = self.__list.GetSelection() - 1
            if index < 0:
                index = 0
            self.__list.SetSelection(index)
        elif event.GetKeyCode() == wx.WXK_DOWN:
            index = self.__list.GetSelection() + 1
            if index > len(self.__choicelist) - 1:
                index = len(self.__choicelist) - 1
            self.__list.SetSelection(index)

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlglistselwidth')
        hdlg = self.__options.get_('dlglistselheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options
        wdlg, hdlg = self.GetSize()
        self.__options.set_('dlglistselwidth', wdlg)
        self.__options.set_('dlglistselheight', hdlg)
        event.Skip()


class LorzeDlgSelDrawing(wx.Dialog):
    '''LorzeDlgSelDrawing(parent, LorzeOptions, LorzeDrawManager,
                          LorzeSelection)
       Drawing selection dialogue.

    parent = wx.window
    GUI: listbox, ok button, cancel button

    cancel_dialogue()
    Discard selection, close dialogue.

    dialogue_size()
    Calculate the dialogue size.

    get_choice()
    Return 'selection'.

    ok_dialogue()
    Assume selection, close dialogue.

    on_cancel(event)
    Event for button [cancel].

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_key_down(event)
    Event for keys, [esc], [return], [enter].

    on_ok(event)
    Event for button [ok].

    set_list()
    Set the list with entrys.

    '''

    def __init__(self, parent, options, drawman, selection):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # LorzeDrawManager
        self.__drawman = drawman
        # LorzeSelection
        self.__selection = selection
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subclass
        wx.Dialog.__init__(self, parent, wx.ID_ANY,
                           title=_(u'Selection drawing'),
                           size=(wdlg, hdlg),
                           style=wx.DEFAULT_DIALOG_STYLE |
                           wx.RESIZE_BORDER)
        # Choicelist and Choiceindex
        self.set_list()
        self.__choiceindex = None
        # Infotext
        if self.__mode == 'selection':
            info = _('Set drawing for selection.')
        elif self.__mode == 'default':
            info = _('Set default drawing.')
        else:
            info = ''
        infotext = wx.StaticText(self, label=info)
        # Listbox
        self.__list = wx.ListBox(self, size=(-1, -1),
                                 choices=self.__choicelist)
        # Search index of default and select default.
        for i in range(len(self.__choicelist)):
            if self.__choicelist[i] == self.__default:
                self.__list.SetSelection(i)
        buttonok = wx.Button(self, label=_(u'OK'))
        buttoncancel = wx.Button(self, label=_(u'Cancel'))
        # Bindings
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        buttoncancel.Bind(wx.EVT_BUTTON, self.on_cancel)
        self.__list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_ok)
        self.__list.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(infotext, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(self.__list, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(buttonok, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox.Add(buttoncancel, 1, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(hbox, 0, wx.EXPAND)
        # Set focus on list for key events.
        self.__list.SetFocus()
        self.SetSizer(vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event for button [ok].'''
        self.ok_dialogue()

    def on_cancel(self, event):
        '''Event for button [cancel].'''
        self.cancel_dialogue()

    def get_choice(self):
        '''Return 'selection'.'''
        if self.__choiceindex is None:
            return('')
        else:
            choice = self.__choicelist[self.__choiceindex]
            if choice == self.__default:
                # Selection is the same as the default, no changes.
                return('')
            else:
                return(choice)

    def cancel_dialogue(self):
        '''Discard selection, close dialogue.'''
        self.__choiceindex = None
        self.Close()

    def ok_dialogue(self):
        '''Assume selection, close dialogue.'''
        self.__choiceindex = self.__list.GetSelection()
        self.Close()

    def on_key_down(self, event):
        '''Event for keys, [esc], [return], [enter].'''
        if event.GetKeyCode() == wx.WXK_ESCAPE:
            self.cancel_dialogue()
        elif event.GetKeyCode() == wx.WXK_RETURN:
            self.ok_dialogue()
        elif event.GetKeyCode() == wx.WXK_NUMPAD_ENTER:
            self.ok_dialogue()
        elif event.GetKeyCode() == wx.WXK_UP:
            index = self.__list.GetSelection() - 1
            if index < 0:
                index = 0
            self.__list.SetSelection(index)
        elif event.GetKeyCode() == wx.WXK_DOWN:
            index = self.__list.GetSelection() + 1
            if index > len(self.__choicelist) - 1:
                index = len(self.__choicelist) - 1
            self.__list.SetSelection(index)

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlgseldrawwidth')
        hdlg = self.__options.get_('dlgseldrawheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options
        wdlg, hdlg = self.GetSize()
        self.__options.set_('dlgseldrawwidth', wdlg)
        self.__options.set_('dlgseldrawheight', hdlg)
        event.Skip()

    def set_list(self):
        '''Set the list with entrys.'''
        # Has default list more than 1 entry,
        # set entry 'severals ..' at the top.
        drawlist = self.__selection.get_select_draw()
        if drawlist:
            # Drawings in selection.
            self.__mode = 'selection'
            if len(drawlist) > 1:
                # More than 1 drawing in selection.
                self.__choicelist = [_(u'several')]
                self.__default = self.__choicelist[0]
            else:
                # 1 drawing in selection.
                self.__choicelist = []
                self.__default = drawlist[0]
        else:
            # No drawings in selection.
            self.__mode = 'default'
            self.__choicelist = []
            self.__default = self.__drawman.get_default_draw()
        drawlist = self.__drawman.get_all_drawings().keys()
        drawlist.sort()
        self.__choicelist.extend(drawlist)


class LorzeDlgNewColor(wx.Dialog):
    '''LorzeDlgNewColor(parent, color, names, LorzeOptions,
                        LorzeDlgHelper)
       List selection dialogue.

    parent = wx.window
    color = default colour in html format, '#rrggbb'
    names = list with existing colour names
    GUI: Name & label with text controls, change color button,
    preview panel, ok & cancel button

    cancel_dialogue()
    Discard selection, close dialouge, return empty strings.

    dialogue_size()
    Calculate the dialogue size.

    get_colour()
    Return attribute values, 'name', 'htmlcolor', 'label'.
    'htmlcolor' = '#rrggbb'

    ok_dialogue()
    Assume selection, close dialogue, return attribute values.

    on_cancel(event)
    Event for button cancel.

    on_colour(event)
    Event for button change colour.

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_key_down(event)
    Event for keys, esc, return, enter.

    on_ok(event)
    Event for button ok.

    '''

    def __init__(self, parent, color, existnames, options, attribute,
                 dlghelper):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # DialogHelper
        self.__dlg = dlghelper
        # LorzeAttribute
        self.__attribute = attribute
        # Existing colour attribute names
        self.__existnames = existnames
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subclass
        wx.Dialog.__init__(self, parent, wx.ID_ANY,
                           _(u'New colour atrribute'), size=(wdlg,
                           hdlg), style=wx.DEFAULT_DIALOG_STYLE |
                           wx.RESIZE_BORDER)
        # StaticBox, BoxSizer & TextCtrl
        namebox = wx.StaticBox(self, label=_(u'Name of the colour'))
        namesizer = wx.StaticBoxSizer(namebox, wx.VERTICAL)
        labelbox = wx.StaticBox(self,
                                label=_(u'Description of the colour'))
        labelsizer = wx.StaticBoxSizer(labelbox, wx.VERTICAL)
        self.__name = wx.TextCtrl(self)
        self.__label = wx.TextCtrl(self)
        # Preview
        valuebox = wx.StaticBox(self, label=_(u'Value of the colour'))
        valuesizer = wx.StaticBoxSizer(valuebox, wx.VERTICAL)
        self.__value = wx.Panel(self)
        self.__value.SetBackgroundColour(color)
        buttoncolor = wx.Button(self, label=_(u'Change Colour'))
        # Buttons
        buttonok = wx.Button(self, label=_(u'OK'))
        buttoncancel = wx.Button(self, label=_(u'Cancel'))
        # Bindings
        buttoncolor.Bind(wx.EVT_BUTTON, self.on_colour)
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        buttoncancel.Bind(wx.EVT_BUTTON, self.on_cancel)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        # Name in own attribute.
        self.__colname = ''
        # Layout
        namesizer.Add(self.__name, 0, wx.EXPAND | wx.ALL, dlgborder)
        labelsizer.Add(self.__label, 0, wx.EXPAND | wx.ALL, dlgborder)
        valuesizer.Add(self.__value, 1, wx.EXPAND | wx.ALL, dlgborder)
        valuesizer.Add(buttoncolor, 1, wx.EXPAND | wx.ALL, dlgborder)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(namesizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(labelsizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(valuesizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(buttonok, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox.Add(buttoncancel, 1, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(hbox, 0, wx.EXPAND)
        self.SetSizer(vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event for button ok.'''
        self.ok_dialogue()

    def on_cancel(self, event):
        '''Event for button cancel.'''
        self.cancel_dialogue()

    def get_colour(self):
        '''Return attribute values, 'name', 'htmlcolor', 'label'.'''
        if self.__colname and self.__colname != '':
            label = self.__label.GetValue()
            value = self.__value.GetBackgroundColour().GetAsString(\
                                wx.C2S_HTML_SYNTAX)
            return(self.__colname, value, label)
        else:
            return('', '', '')

    def cancel_dialogue(self):
        '''Discard selection, close dialogue.'''
        # Empty name = cancel dialogue.
        self.__colname = ''
        self.Close()

    def ok_dialogue(self):
        '''Assume selection, close dialogue.'''
        name = self.__name.GetValue()
        label = self.__label.GetValue()
        if name in self.__existnames:
            dlg = wx.MessageDialog(self,
                  _(u'The color name is already in use. Please ' + \
                  'choose a different name.'), _(u'Information'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif name.startswith('__'):
            dlg = wx.MessageDialog(self,
                  _(u'The initial "__" should not be used. Please ' + \
                  'select another beginning.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif not name:
            dlg = wx.MessageDialog(self,
                  _(u'Please give the colour a name.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif not label:
            dlg = wx.MessageDialog(self,
                  _(u'Please give the colour a description.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            self.__colname = name
            self.Close()

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlgnewcolwidth')
        hdlg = self.__options.get_('dlgnewcolheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options
        wdlg, hdlg = self.GetSize()
        self.__options.set_('dlgnewcolwidth', wdlg)
        self.__options.set_('dlgnewcolheight', hdlg)
        event.Skip()

    def on_colour(self, event):
        '''Event for button change colour.'''
        default = self.__value.GetBackgroundColour().GetAsString(\
                                                    wx.C2S_HTML_SYNTAX)
        color = self.__dlg.color_dialog(default)
        if color != '':
            # Clicked ok, get colour html string.
            self.__value.SetBackgroundColour(color)


class LorzeDlgLog(wx.Dialog):
    '''LorzeDlgLog(parent, LorzeOptions, LorzeLog)
       Show text in LorzeLog in a dialogue.

    dialogue_size()
    Calculate the dialogue size.

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_key_down(event)
    Event for keys, esc, return, enter.

    on_ok(event)
    Event for button ok.

    '''

    def __init__(self, parent, options, lorzelog):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # LorzeLog
        self.__log = lorzelog
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subclass
        wx.Dialog.__init__(self, parent, wx.ID_ANY,
                           _(u'LORZE protocoll'),
                           size=(wdlg, hdlg),
                           style=wx.DEFAULT_DIALOG_STYLE |
                                 wx.RESIZE_BORDER)
        # TextCtrl with multiline to show text
        text = ''
        if self.__log.get_log():
            for i in self.__log.get_log():
                text = text + i + '\n'
        textctrl = wx.TextCtrl(self, value=text, style=wx.TE_MULTILINE)
        # Buttons.
        buttonok = wx.Button(self, label='OK')
        # Bindings.
        textctrl.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        # Layout.
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(textctrl, 1, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(buttonok, 0, wx.EXPAND | wx.ALL, dlgborder)
        textctrl.SetFocus()
        self.SetSizer(vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event, close the dialogue'''
        self.Close()

    def on_key_down(self, event):
        '''Event, get key'''
        if event.GetKeyCode() == wx.WXK_ESCAPE:
            self.Close()
        elif event.GetKeyCode() == wx.WXK_RETURN:
            self.Close()
        elif event.GetKeyCode() == wx.WXK_NUMPAD_ENTER:
            self.Close()

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlglogwidth')
        hdlg = self.__options.get_('dlglogheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options
        wdlg, hdlg = self.GetSize()
        self.__options.set_('dlglogwidth', wdlg)
        self.__options.set_('dlglogheight', hdlg)
        event.Skip()


class LorzeDlgNewLayer(wx.Dialog):
    '''LorzeDlgNewLayer(parent, names, LorzeOptions, LorzeDlgHelper)
       List selection dialogue.

    parent = wx.window
    names = list with existing layer names
    GUI: Name & label with text controls, ok & cancel button

    cancel_dialogue()
    Discard selection, close dialouge, return empty strings.

    dialogue_size()
    Calculate the dialogue size.

    get_layer()
    Return attribute values, 'name', 'label'.

    ok_dialogue()
    Assume selection, close dialogue, return attribute values.

    on_cancel(event)
    Event for button cancel.

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_key_down(event)
    Event for keys, esc, return, enter.

    on_ok(event)
    Event for button ok.

    '''

    def __init__(self, parent, existnames, options, attribute,
                 dlghelper):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # DialogHelper
        self.__dlg = dlghelper
        # LorzeAttribute
        self.__attribute = attribute
        # Existing layer attribute names
        self.__existnames = existnames
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subclass
        wx.Dialog.__init__(self, parent, wx.ID_ANY,
                           _(u'New layer atrribute'), size=(wdlg,
                           hdlg), style=wx.DEFAULT_DIALOG_STYLE |
                           wx.RESIZE_BORDER)
        # StaticBox, BoxSizer & TextCtrl
        namebox = wx.StaticBox(self, label=_(u'Name of the layer'))
        namesizer = wx.StaticBoxSizer(namebox, wx.VERTICAL)
        labelbox = wx.StaticBox(self,
                                label=_(u'Description of the layer'))
        labelsizer = wx.StaticBoxSizer(labelbox, wx.VERTICAL)
        self.__name = wx.TextCtrl(self)
        self.__label = wx.TextCtrl(self)
        # Buttons
        buttonok = wx.Button(self, label=_(u'OK'))
        buttoncancel = wx.Button(self, label=_(u'Cancel'))
        # Bindings
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        buttoncancel.Bind(wx.EVT_BUTTON, self.on_cancel)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        # Name in own attribute.
        self.__layname = ''
        # Layout
        namesizer.Add(self.__name, 0, wx.EXPAND | wx.ALL, dlgborder)
        labelsizer.Add(self.__label, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(namesizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(labelsizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(buttonok, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox.Add(buttoncancel, 1, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(hbox, 0, wx.EXPAND)
        self.SetSizer(vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event for button ok.'''
        self.ok_dialogue()

    def on_cancel(self, event):
        '''Event for button cancel.'''
        self.cancel_dialogue()

    def get_layer(self):
        '''Return attribute values, 'name', 'label'.'''
        if self.__layname and self.__layname != '':
            label = self.__label.GetValue()
            return(self.__layname, label)
        else:
            return('', '', '')

    def cancel_dialogue(self):
        '''Discard selection, close dialogue.'''
        # Empty name = cancel dialogue.
        self.__layname = ''
        self.Close()

    def ok_dialogue(self):
        '''Assume selection, close dialogue.'''
        name = self.__name.GetValue()
        label = self.__label.GetValue()
        if name in self.__existnames:
            dlg = wx.MessageDialog(self,
                  _(u'The layer name is already in use. Please ' + \
                  'choose a different name.'), _(u'Information'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif name.startswith('__'):
            dlg = wx.MessageDialog(self,
                  _(u'The initial "__" should not be used. Please ' + \
                  'select another beginning.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif not name:
            dlg = wx.MessageDialog(self,
                  _(u'Please give the layer a name.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif not label:
            dlg = wx.MessageDialog(self,
                  _(u'Please give the layer a description.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            self.__layname = name
            self.Close()

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlgnewlaywidth')
        hdlg = self.__options.get_('dlgnewlayheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options
        wdlg, hdlg = self.GetSize()
        self.__options.set_('dlgnewlaywidth', wdlg)
        self.__options.set_('dlgnewlayheight', hdlg)
        event.Skip()


class LorzeDlgSelCLSW(wx.Dialog):
    '''LorzeDlgSelCLSW(parent, typ, mode, LorzeOptions,
                       LorzeAttribute, LorzeDrawManager,
                       LorzeSelection, LorzeDlgHelper,
                       LorzeValueCheck)
       Attribute selection dialogue for colour, layer, line style,
       line width.

    parent = wx.window
    tpy = 'color', 'style' or 'width'
    mode = 'selection', 'default' or 'options'
    GUI: list control, new button, ok button, cancel button,
    preview panel

    cancel_dialogue()
    Discard selection, close dialogue.

    dialogue_size()
    Calculate the dialogue size.

    get_choice()
    Return 'selection'.

    get_new_created()
    Get the new created attributes.

    get_sorted_list_dict()
    Return sorted list-control dictionairy.

    get_widths()
    Return widths of columns.

    new_color()
    Show new colour dialogue and set colours.

    new_layer()
    Show new layer dialogue and set layers.

    ok_dialogue()
    Assume selection, close dialogue.

    on_cancel(event)
    Event for button cancel.

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_key_down(event)
    Event for keys, esc, return, enter.

    on_paint(event)
    Event, drawing peview panel for style and width.

    on_list(event):
    Event, click on item in list control.

    on_new(event)
    Event for button new attribute.

    on_ok(event)
    Event for button ok.

    read_attributes()
    Prepare list and dictionairys for set_sorted_list_dict.

    set_list_ctrl_new('focusname')
    Set the list control, select attribute with 'focusname'.

    set_sorted_list_dict()
    Set sorted list dictionairy.

    '''

    def __init__(self, parent, typ, mode, options, attribute, drawman,
                 selection, dlghelper, valchck):
        # wx.Window
        self.__parent = parent
        # Type of attribute: 'color', 'style', 'width'
        self.__typ = typ
        # LorzeOptions
        self.__options = options
        # LorzeAttribute
        self.__attribute = attribute
        # LorzeDrawManager
        self.__drawman = drawman
        # LorzeSelection
        self.__selection = selection
        # DialogHelper
        self.__dlg = dlghelper
        # LorzeValueCheck
        self.__valchck = valchck
        # wx.Pen styles: dictionairy to index
        self.__linstyldict = self.__parent.get_line_style_dict()
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Title
        if self.__typ == 'color':
            dlgtitle = _(u'Selection colour')
        elif self.__typ == 'layer':
            dlgtitle = _(u'Selection layer')
        elif self.__typ == 'style':
            dlgtitle = _(u'Selection line style')
        elif self.__typ == 'width':
            dlgtitle = _(u'Selection line width')
        else:
            dlgtitle = u'Unknown __type'
        # Subclass
        wx.Dialog.__init__(self, parent, wx.ID_ANY,
                           title=dlgtitle,
                           size=(wdlg, hdlg),
                           style=wx.DEFAULT_DIALOG_STYLE |
                           wx.RESIZE_BORDER)
        # Set mode, read attributes, set sorted list dictionairy.
        # Set choiceindex, default, newcolor
        self.__mode = mode
        self.read_attributes()
        self.set_sorted_list_dict()
        self.__choiceindex = None
        self.__oldindex = None
        self.__choicename = ''
        self.__newattr = []
        # Infotext, selection
        if self.__mode == 'selection':
            if self.__typ == 'color':
                info = _('Set colour for selection.')
            elif self.__typ == 'layer':
                info = _('Set layer for selection.')
            elif self.__typ == 'style':
                info = _('Set line style for selection.')
            elif self.__typ == 'width':
                info = _('Set line width for selection.')
            else:
                info = u'Unknown __type'
        # Infotext, drawing default.
        elif self.__mode == 'default':
            if self.__typ == 'color':
                info = ('Set colour for drawing defaults.')
                self.__default = self.__attribute.get_default_color()
            elif self.__typ == 'layer':
                info = ('Set layer for drawing defaults.')
                self.__default = self.__attribute.get_default_layer()
            elif self.__typ == 'style':
                info = _('Set line style for drawing defaults.')
                self.__default = self.__attribute.get_default_style()
            elif self.__typ == 'width':
                info = ('Set line width for drawing defaults.')
                self.__default = self.__attribute.get_default_width()
            else:
                info = u'Unknown __type'
                self.__default = info
        # Infotext, drawing options.
        elif self.__mode == 'options':
            if self.__typ == 'color':
                info = _('Set colour for program options.')
                self.__default = self.__options.get_('defcolorname')
            elif self.__typ == 'layer':
                info = _('Set layer for program options.')
                self.__default = self.__options.get_('deflayername')
            elif self.__typ == 'style':
                info = _('Set line style for program options.')
                self.__default = self.__options.get_('defstylename')
            elif self.__typ == 'width':
                info = _('Set line width for program options.')
                self.__default = self.__options.get_('defwidthname')
            else:
                info = u'Unknown __type'
                self.__default = info
        infotext = wx.StaticText(self, label=info)
        # Preview
        self.__prev = wx.Panel(self)
        self.__prevclear = self.__prev.GetBackgroundColour()
        # Set wx default colour value.
        value = self.__options.get_('prevcol')
        self.__prevcol = '#' + value
        # Set wx default line width value.
        self.__prevwid = self.__options.get_('prevwidth')
        # Set wx default line style values.
        attrstyle = self.__options.get_('prevstyle')
        guituple = self.__valchck.attrstyle_to_guituple(attrstyle)
        wxvalue = self.__linstyldict[guituple[0]]
        self.__prevsty = (wxvalue, guituple[1])
        # List control
        if self.__typ == 'color':
            w = (self.__options.get_('collistwidth0'),
                 self.__options.get_('collistwidth1'),
                 self.__options.get_('collistwidth2'),
                 self.__options.get_('collistwidth3'))
        elif self.__typ == 'layer':
            w = (self.__options.get_('laylistwidth0'),
                 self.__options.get_('laylistwidth1'),
                 self.__options.get_('laylistwidth2'))
        elif self.__typ == 'style':
            w = (self.__options.get_('stylistwidth0'),
                 self.__options.get_('stylistwidth1'),
                 self.__options.get_('stylistwidth2'),
                 self.__options.get_('stylistwidth3'))
        elif self.__typ == 'width':
            w = (self.__options.get_('widlistwidth0'),
                 self.__options.get_('widlistwidth1'),
                 self.__options.get_('widlistwidth2'),
                 self.__options.get_('widlistwidth3'))
        else:
            w = (self.__options.get_('collistwidth0'),
                 self.__options.get_('collistwidth0'),
                 self.__options.get_('collistwidth0'),
                 self.__options.get_('collistwidth0'))
        self.__list = SortedListCtrl(self, False)
        if self.__typ == 'layer':
            self.__list.InsertColumn(0, _(u'Name'), width=w[0])
            self.__list.InsertColumn(1, _(u'Description'), width=w[1])
            self.__list.InsertColumn(2, _(u'Used by'), width=w[2])
        else:
            self.__list.InsertColumn(0, _(u'Name'), width=w[0])
            self.__list.InsertColumn(1, _(u'Description'), width=w[1])
            self.__list.InsertColumn(2, _(u'Value'), width=w[2])
            self.__list.InsertColumn(3, _(u'Used by'), width=w[3])
        # Buttons
        buttonok = wx.Button(self, label=_(u'OK'))
        buttoncancel = wx.Button(self, label=_(u'Cancel'))
        if self.__typ == 'color':
            newlabel = _(u'New colour')
        elif self.__typ == 'layer':
            newlabel = _(u'New layer')
        elif self.__typ == 'style':
            newlabel = _(u'New line style')
        elif self.__typ == 'width':
            newlabel = _(u'New line width')
        else:
            newlabel = u'Unknown __type'
        buttonnew = wx.Button(self, label=newlabel)
        # Bindings
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        buttoncancel.Bind(wx.EVT_BUTTON, self.on_cancel)
        buttonnew.Bind(wx.EVT_BUTTON, self.on_new)
        self.__list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_ok)
        self.__list.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
        self.__list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_list)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        if self.__typ in ('style', 'width'):
            self.__prev.Bind(wx.EVT_PAINT, self.on_paint)
        # Layout
        self.__vbox = wx.BoxSizer(wx.VERTICAL)
        self.__vbox.Add(infotext, 0, wx.EXPAND | wx.ALL, dlgborder)
        self.__vbox.Add(self.__list, 1, wx.EXPAND | wx.ALL, dlgborder)
        self.__vbox.Add(self.__prev, 0, wx.EXPAND | wx.ALL, dlgborder)
        self.__vbox.Add(buttonnew, 0, wx.EXPAND | wx.ALL, dlgborder)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(buttonok, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox.Add(buttoncancel, 1, wx.EXPAND | wx.ALL, dlgborder)
        self.__vbox.Add(hbox, 0, wx.EXPAND)
        # Set list, set focus on list for key events.
        self.set_list_ctrl_new(self.__default)
        self.__list.SetFocus()
        self.SetSizer(self.__vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event for button ok.'''
        self.ok_dialogue()

    def on_cancel(self, event):
        '''Event for button cancel.'''
        self.cancel_dialogue()

    def get_choice(self):
        '''Return 'selection'.'''
        # Return 'name' of colour.  '__cancel' for cancel dialogue,
        # '__default' for the choice is the same as the default.
        if self.__choiceindex is None:
            return('__cancel')
        else:
            choice = self.__list.GetItemText(self.__choiceindex)
            if choice == self.__default:
                # Selection is the same as the default, no changes.
                return('__default')
            else:
                return(choice)

    def cancel_dialogue(self):
        '''Discard selection, close dialogue.'''
        self.__choiceindex = None
        self.Close()

    def ok_dialogue(self):
        '''Assume selection, close dialogue.'''
        self.__choiceindex = self.__list.GetFocusedItem()
        self.Close()

    def on_key_down(self, event):
        '''Event for keys, esc, return, enter.'''
        if event.GetKeyCode() == wx.WXK_ESCAPE:
            self.cancel_dialogue()
        elif event.GetKeyCode() == wx.WXK_RETURN:
            self.ok_dialogue()
        elif event.GetKeyCode() == wx.WXK_NUMPAD_ENTER:
            self.ok_dialogue()
        elif event.GetKeyCode() == wx.WXK_UP:
            old = self.__list.GetFocusedItem()
            self.__list.Select(old, on=0)
            new = old - 1
            if new < 0:
                new = 0
            self.__list.Focus(new)
            self.__list.Select(new, on=1)
        elif event.GetKeyCode() == wx.WXK_DOWN:
            old = self.__list.GetFocusedItem()
            self.__list.Select(old, on=0)
            new = old + 1
            if new > len(self.__attrnames) - 1:
                new = len(self.__attrnames) - 1
            self.__list.Focus(new)
            self.__list.Select(new, on=1)

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        if self.__typ == 'color':
            wdlg = self.__options.get_('dlgselcolwidth')
            hdlg = self.__options.get_('dlgselcolheight')
        elif self.__typ == 'layer':
            wdlg = self.__options.get_('dlgsellaywidth')
            hdlg = self.__options.get_('dlgsellayheight')
        elif self.__typ == 'style':
            wdlg = self.__options.get_('dlgselstywidth')
            hdlg = self.__options.get_('dlgselstyheight')
        elif self.__typ == 'width':
            wdlg = self.__options.get_('dlgselwidwidth')
            hdlg = self.__options.get_('dlgselwidheight')
        else:
            wdlg = self.__options.get_('dlgselcolwidth')
            hdlg = self.__options.get_('dlgselcolheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options
        wdlg, hdlg = self.GetSize()
        if self.__typ == 'color':
            self.__options.set_('dlgselcolwidth', wdlg)
            self.__options.set_('dlgselcolheight', hdlg)
        elif self.__typ == 'layer':
            self.__options.set_('dlgsellaywidth', wdlg)
            self.__options.set_('dlgsellayheight', hdlg)
        elif self.__typ == 'style':
            self.__options.set_('dlgselstywidth', wdlg)
            self.__options.set_('dlgselstyheight', hdlg)
        elif self.__typ == 'width':
            self.__options.set_('dlgselwidwidth', wdlg)
            self.__options.set_('dlgselwidheight', hdlg)
        event.Skip()

    def set_sorted_list_dict(self):
        '''Set sorted list dictionairy.'''
        # Dictionairy, {index:('name', 'label', 'value', used'),  }.
        self.__sortedlistdict = {}
        index = 0
        for i in self.__attrnames:
            if self.__typ == 'layer':
                self.__sortedlistdict[index] = (i,
                                                self.__attrlabel[i],
                                                self.__attruse[i])
            else:
                self.__sortedlistdict[index] = (i,
                                                self.__attrlabel[i],
                                                self.__attrvalue[i],
                                                self.__attruse[i])
            index = index + 1

    def get_sorted_list_dict(self):
        '''Return sorted list-control dictionairy.'''
        return(self.__sortedlistdict)

    def get_widths(self):
        '''Return widths of columns.'''
        if self.__typ == 'layer':
            return(self.__list.GetColumnWidth(0),
                   self.__list.GetColumnWidth(1),
                   self.__list.GetColumnWidth(2))
        else:
            return(self.__list.GetColumnWidth(0),
                   self.__list.GetColumnWidth(1),
                   self.__list.GetColumnWidth(2),
                   self.__list.GetColumnWidth(3))

    def on_list(self, event):
        '''Event, click on item in list control.'''
        index = self.__list.GetFocusedItem()
        self.__oldindex = index
        name = self.__list.GetItemText(index)
        if self.__typ != 'layer':
            if index >= 0 and self.__attrvalue[name]:
                if self.__typ == 'color':
                    wxval = self.__wxvalue[name]
                    self.__prev.SetBackgroundColour(wxval)
                elif self.__typ == 'style':
                    self.Refresh()
                elif self.__typ == 'width':
                    self.Refresh()
            elif index >= 0:
                if self.__typ == 'color':
                    self.__prev.SetBackgroundColour(self.__prevclear)
                elif self.__typ == 'style':
                    self.Refresh()
                elif self.__typ == 'width':
                    self.Refresh()

    def on_new(self, event):
        '''Event for button new attribute.'''
        if self.__typ == 'color':
            self.new_color()
        elif self.__typ == 'layer':
            self.new_layer()
        elif self.__typ == 'style':
            self.new_style()
        elif self.__typ == 'width':
            pass

    def new_color(self):
        '''Show new colour dialogue and set colours.'''
        color = self.__prev.GetBackgroundColour().GetAsString(\
                                                  wx.C2S_HTML_SYNTAX)
        dlg = LorzeDlgNewColor(self, color, self.__attrnames,
                               self.__options, self.__attribute,
                               self.__dlg)
        dlg.ShowModal()
        name, htmlcol, label = dlg.get_colour()
        if name and name != '':
            # OK, create colour, to the list and dictionairiys for
            # sortedlistdict, append name in list for new created.
            self.__attrnames.append(name)
            self.__attrlabel[name] = label
            self.__attrvalue[name] = self.__valchck.\
                                     hexdec_to_rgbtxt(htmlcol.\
                                                      lstrip('#'))
            self.__wxvalue[name] = htmlcol
            self.__attruse[name] = ''
            self.__newattr.append(name)
            self.set_sorted_list_dict()
            self.set_list_ctrl_new(name)

    def new_layer(self):
        '''Show new layer dialogue and set layers.'''
        dlg = LorzeDlgNewLayer(self, self.__attrnames, self.__options,
                               self.__attribute, self.__dlg)
        dlg.ShowModal()
        name, label = dlg.get_layer()
        if name and name != '':
            # OK, create layer, to the list and dictionairiys for
            # sortedlistdict, append name in list for new created.
            self.__attrnames.append(name)
            self.__attrlabel[name] = label
            self.__attruse[name] = ''
            self.__newattr.append(name)
            self.set_sorted_list_dict()
            self.set_list_ctrl_new(name)

    def new_style(self):
        '''Show new line style dialogue and set line styles.'''
        index = self.__list.GetFocusedItem()
        name = self.__list.GetItemText(index)
        # Line style as wxvalue, (wxStyle, [integers,  ])
        style = self.__attrvalue[name]
        dlg = LorzeDlgNewStyle(self, style, self.__attrnames,
                               self.__linstyldict, self.__options,
                               self.__attribute, self.__dlg)
        dlg.ShowModal()
        name, wxstyle, label = dlg.get_style()
        if name and name != '':
            # OK, create line style, to the list and dictionairiys for
            # sortedlistdict, append name in list for new created.
            self.__attrnames.append(name)
            self.__attrlabel[name] = label
            attrstyle = ''
            for txtsty, wxsty in self.__linstyldict.keys():
                # search attributestyle text for wxstyle
                if wxstyle == wxsty:
                    guituple = (txtsty, wxstyle[1])
                    attrstyle = self.__valchck.guituple_to_attrstyle(\
                                               guituple)
            if attrstyle:
                #
                self.__attrvalue[name] = attrstyle
            else:
                self.__attrvalue[name] = self.__valchck.\
                                         guituple_to_attrstyle(None)
            self.__wxvalue[name] = wxstyle
            self.__attruse[name] = ''
            self.__newattr.append(name)
            self.set_sorted_list_dict()
            self.set_list_ctrl_new(name)

    def set_list_ctrl_new(self, focusname):
        '''Set the list control, select attribute with 'focusname'.'''
        self.__list.DeleteAllItems()
        # Get items from SortedListDictionairy and add to listcontrol.
        for key, data in self.__sortedlistdict.items():
            index = self.__list.InsertStringItem(sys.maxint, data[0])
            if self.__typ == 'layer':
                self.__list.SetStringItem(index, 1, data[1])
                self.__list.SetStringItem(index, 2, data[2])
            else:
                self.__list.SetStringItem(index, 1, data[1])
                self.__list.SetStringItem(index, 2, data[2])
                self.__list.SetStringItem(index, 3, data[3])
            self.__list.SetItemData(index, key)
        # Search index of default and select default.
        for i in range(len(self.__attrnames)):
            if self.__attrnames[i] == focusname:
                self.__list.Focus(i)
                self.__list.Select(i, on=1)
                self.__oldindex = i

    def read_attributes(self):
        '''Prepare list and dictionairys for set_sorted_list_dict.'''
        # attrnames = ['name',  ]
        # attrdrawuse = {'color': ['drawing',  ],  }
        # attrseluse = {'color': ['drawing',  ],  }
        if self.__typ == 'color':
            self.__attrnames, l, s, w = self.__attribute.\
                                        get_all_attr_names()
            attrdrawuse, l, s, w = self.__drawman.get_used_attr()
            attrseluse, l, s, w = self.__selection.get_select_attr()
        elif self.__typ == 'layer':
            c, self.__attrnames, s, w = self.__attribute.\
                                        get_all_attr_names()
            c, attrdrawuse, s, w = self.__drawman.get_used_attr()
            c, attrseluse, s, w = self.__selection.get_select_attr()
        elif self.__typ == 'style':
            c, l, self.__attrnames, w = self.__attribute.\
                                        get_all_attr_names()
            c, l, attrdrawuse, w = self.__drawman.get_used_attr()
            c, l, attrseluse, w = self.__selection.get_select_attr()
        elif self.__typ == 'width':
            c, l, s, self.__attrnames = self.__attribute.\
                                        get_all_attr_names()
            c, l, s, attrdrawuse = self.__drawman.get_used_attr()
            c, l, s, attrseluse = self.__selection.get_select_attr()
        else:
            self.__attrnames = []
            attrdrawuse = {}
            attrseluse = {}
        # attruse = {'name': ['drawing', 'selection', 'default'],  }
        # attrlabel = {'name': 'label',  }
        # attrvalue = {'name': 'value',  }
        self.__attruse = {}
        self.__attrlabel = {}
        self.__attrvalue = {}
        self.__wxvalue = {}
        # Set dictionairys.
        for i in self.__attrnames:
            # Get label, value and set wxvalue.
            if self.__typ == 'color':
                # label = 'string', value = 'r, g, b',
                # wxvalue = '#hexdec'
                value, label = self.__attribute.get_color_entry(i)
                self.__attrlabel[i] = label
                self.__attrvalue[i] = self.__valchck.hexdec_to_rgbtxt(\
                                       value)
                self.__wxvalue[i] = '#' + value
            elif self.__typ == 'layer':
                # label = 'string'.
                label = self.__attribute.get_layer_entry(i)
                self.__attrlabel[i] = label
            elif self.__typ == 'style':
                # label = 'string', value = 'typ | integer,  ',
                # wxvalue = ('typ', [integer,  ])
                value, label = self.__attribute.get_style_entry(i)
                self.__attrlabel[i] = label
                self.__attrvalue[i] = value
                guituple = self.__valchck.attrstyle_to_guituple(value)
                wxtyp = self.__linstyldict[guituple[0]]
                self.__wxvalue[i] = (wxtyp, guituple[1])
            elif self.__typ == 'width':
                # label = 'string', value = 'float',
                # wxvalue = float
                value, label = self.__attribute.get_width_entry(i)
                self.__attrlabel[i] = label
                self.__attrvalue[i] = str(value)
                self.__wxvalue[i] = value
            # Set string for uses.
            self.__attruse[i] = ''
            if attrdrawuse and i in attrdrawuse:
                # Colour used in drawings.
                for j in attrdrawuse[i]:
                    if self.__attruse[i]:
                        # String is not empty, seperator is ', '.
                        sep = ', '
                    else:
                        # String is empty, seperator is ''.
                        sep = ''
                    # Add drawing to String.
                    self.__attruse[i] = self.__attruse[i] + sep + j
            if attrseluse and i in attrseluse:
                # Colour used in selection.
                if self.__attruse[i]:
                    # String is not empty, seperator is ', '.
                    sep = ', '
                else:
                    # String is empty, seperator is ''.
                    sep = ''
                # Add selection to String.
                self.__attruse[i] = self.__attruse[i] + sep + \
                                     _(u'selection')
            if self.__typ == 'color':
                defopt = self.__options.get_('defcolorname')
                defattr = self.__attribute.get_default_color()
            elif self.__typ == 'layer':
                defopt = self.__options.get_('deflayername')
                defattr = self.__attribute.get_default_layer()
            elif self.__typ == 'style':
                defopt = self.__options.get_('defstylename')
                defattr = self.__attribute.get_default_style()
            elif self.__typ == 'width':
                defopt = self.__options.get_('defwidthname')
                defattr = self.__attribute.get_default_width()
            else:
                defopt = 'Unknown __type'
                defattr = 'Unknown __type'
            if i == defopt:
                # Colour used in options.
                if self.__attruse[i]:
                    # String is not empty, seperator is ', '.
                    sep = ', '
                else:
                    # String is empty, seperator is ''.
                    sep = ''
                self.__attruse[i] = self.__attruse[i] + sep + \
                                     _(u'options')
            if i == defattr:
                # Colour used in defaults.
                if self.__attruse[i]:
                    # String is not empty, seperator is ', '.
                    sep = ', '
                else:
                    # String is empty, seperator is ''.
                    sep = ''
                self.__attruse[i] = self.__attruse[i] + sep + \
                                     _(u'defaults')
        # Set defaults.
        if attrseluse:
            # Attributes in selection.
            self.__mode = 'selection'
            if len(attrseluse) > 1:
                # More than 1 color in selection.
                self.__attrnames.insert(0, _(u'several'))
                self.__attruse[_(u'several')] = ''
                self.__attrlabel[_(u'several')] = ''
                self.__attrvalue[_(u'several')] = ''
                self.__wxvalue[_(u'several')] = ''
                self.__default = self.__attrnames[0]
            else:
                # 1 attribute in selection.
                sellist = self.__selection.get_elements()
                id_, drawkey = sellist[0]
                draw = self.__drawman.get_drawing(drawkey)
                element = draw.get_(id_)
                if self.__typ == 'color':
                    self.__default = element.get_color()
                elif self.__typ == 'layer':
                    self.__default = element.get_layer()
                elif self.__typ == 'style':
                    self.__default = element.get_style()
                elif self.__typ == 'width':
                    self.__default = element.get_width()
                else:
                    self.__default = 'Unknown __type'

    def get_new_created(self):
        '''Get the new created attributes.'''
        # List with tupels, [('name', 'value', 'label'),  ]
        # name = 'text', value = 'hexdec', label = 'text'
        list_ = []
        for i in self.__newattr:
            label = self.__attrlabel[i]
            if self.__typ == 'color':
                value = self.__wxvalue[i].lstrip('#')
                list_.append((i, value, label))
            elif self.__typ == 'layer':
                list_.append((i, label))
            elif self.__typ == 'style':
                value = ''
                list_.append((i, value, label))
            elif self.__typ == 'width':
                value = ''
                list_.append((i, value, label))
        return(list_)

    def on_paint(self, event):
        '''Event, drawing peview panel for style and width.'''
        # Get sizes of the preview panel.
        child = self.__vbox.GetChildren()
        wpanel, hpanel = (child[2].GetSize())
        # Get name of the selected attribute.
        index = self.__list.GetFocusedItem()
        name = self.__list.GetItemText(index)
        # Drawing Client.
        dc = wx.PaintDC(self.__prev)
        # Scale factor.
        scal = float(dc.GetPPI()[0]) / 25.4
        # Set Pen, individually for 'style' and 'width'.
        if self.__typ == 'style':
            sty = self.__wxvalue[name]
            pen = wx.Pen(self.__prevcol, self.__prevwid * scal, sty[0])
            if sty[0] == wx.USER_DASH:
                print(sty[1])
                pen.SetDashes(sty[1])
        elif self.__typ == 'width':
            wid = self.__wxvalue[name]
            pen = wx.Pen(self.__prevcol, wid * scal, self.__prevsty[0])
            if sty[0] == wx.USER_DASH:
                pen.SetDashes(self.__prevsty[1])
        dc.SetPen(pen)
        dc.DrawLine(0, hpanel // 2, wpanel, hpanel // 2)


class LorzeDlgNewStyle(wx.Dialog):
    '''LorzeDlgNewColor(parent, style, names, LorzeOptions,
                        LorzeDlgHelper)
       List selection dialogue.

    parent = wx.window
    style = default line style: 'typ | integer,  '
    names = list with existing line styles names
    GUI: Name & label with text controls, combobx with predefinied
    line styles, preview panel, spin controls for user dash,
    ok & cancel button

    cancel_dialogue([
    Discard selection, close dialouge, return empty strings.

    dialogue_size()
    Calculate the dialogue size.

    get_colour()
    Return attribute values, 'name', 'htmlcolor', 'label'.
    'htmlcolor' = '#rrggbb'

    ok_dialogue()
    Assume selection, close dialogue, return attribute values.

    on_cancel(event)
    Event for button cancel.

    on_colour(event)
    Event for button change colour.

    on_dialogue_close(event)
    Event to assume the dialogue sizes.

    on_key_down(event)
    Event for keys, esc, return, enter.

    on_ok(event)
    Event for button ok.

    '''

    def __init__(self, parent, style, existnames, linstyldict, options,
                 attribute, dlghelper):
        # wx.Window
        self.__parent = parent
        # LorzeOptions
        self.__options = options
        # DialogHelper
        self.__dlg = dlghelper
        # LorzeAttribute
        self.__attribute = attribute
        # Existing colour attribute names
        self.__existnames = existnames
        # Line style dictionairy, {'style': wx.STYLE}
        self.__linstyldict = linstyldict
        # Get settings for dialog from options
        dlgborder = self.__options.get_('dlgborder')
        wdlg, hdlg = self.dialogue_size()
        # Subclass
        wx.Dialog.__init__(self, parent, wx.ID_ANY,
                           _(u'New colour atrribute'), size=(wdlg,
                           hdlg), style=wx.DEFAULT_DIALOG_STYLE |
                           wx.RESIZE_BORDER)
        # StaticBox, BoxSizer & TextCtrl
        namebox = wx.StaticBox(self,
                  label=_(u'Name of the line style'))
        namesizer = wx.StaticBoxSizer(namebox, wx.VERTICAL)
        labelbox = wx.StaticBox(self,
                   label=_(u'Description of the line style'))
        labelsizer = wx.StaticBoxSizer(labelbox, wx.VERTICAL)
        self.__name = wx.TextCtrl(self)
        self.__label = wx.TextCtrl(self)
        # Combobox & Preview
        valuebox = wx.StaticBox(self,
                   label=_(u'Value of the line style'))
        valuesizer = wx.StaticBoxSizer(valuebox, wx.VERTICAL)
        self.__wxlist= wx.ComboBox(self, size= (-1, -1),
                                   choices= self.__linstyldict.keys(),
                                   style=wx.CB_READONLY)
        self.__prev = wx.Panel(self)
        self.__spins = []
        for i in range(10):
            spin = wx.SpinCtrl(self)
            spin.SetRange(0, 1000)
            spin.SetValue(0)
            self.__spins.append(spin)
        # Buttons
        buttonok = wx.Button(self, label=_(u'OK'))
        buttoncancel = wx.Button(self, label=_(u'Cancel'))
        # Bindings
        buttonok.Bind(wx.EVT_BUTTON, self.on_ok)
        buttoncancel.Bind(wx.EVT_BUTTON, self.on_cancel)
        self.Bind(wx.EVT_CLOSE, self.on_dialogue_close)
        for i in self.__spins:
            i.Bind(wx.EVT_SPINCTRL, self.on_spin)
        self.__wxlist.Bind(wx.EVT_COMBOBOX, self.on_wxlist)
        # Name in own attribute.
        self.__styname = ''
        # Layout
        namesizer.Add(self.__name, 0, wx.EXPAND | wx.ALL, dlgborder)
        labelsizer.Add(self.__label, 0, wx.EXPAND | wx.ALL, dlgborder)
        valuesizer.Add(self.__wxlist, 0, wx.EXPAND | wx.ALL, dlgborder)
        valuesizer.Add(self.__prev, 1, wx.EXPAND | wx.ALL, dlgborder)
        spingrid = wx.GridSizer(2, 5, dlgborder, dlgborder)
        spingrid.AddMany([(self.__spins[0], 0, wx.EXPAND, dlgborder),
                          (self.__spins[1], 0, wx.EXPAND, dlgborder),
                          (self.__spins[2], 0, wx.EXPAND, dlgborder),
                          (self.__spins[3], 0, wx.EXPAND, dlgborder),
                          (self.__spins[4], 0, wx.EXPAND, dlgborder),
                          (self.__spins[5], 0, wx.EXPAND, dlgborder),
                          (self.__spins[6], 0, wx.EXPAND, dlgborder),
                          (self.__spins[7], 0, wx.EXPAND, dlgborder),
                          (self.__spins[8], 0, wx.EXPAND, dlgborder),
                          (self.__spins[9], 0, wx.EXPAND, dlgborder)])
        valuesizer.Add(spingrid, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(namesizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(labelsizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(valuesizer, 0, wx.EXPAND | wx.ALL, dlgborder)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(buttonok, 1, wx.EXPAND | wx.ALL, dlgborder)
        hbox.Add(buttoncancel, 1, wx.EXPAND | wx.ALL, dlgborder)
        vbox.Add(hbox, 0, wx.EXPAND)
        self.disable_spins()
        self.enable_spins()
        self.SetSizer(vbox)
        self.Centre()

    def on_ok(self, event):
        '''Event for button ok.'''
        self.ok_dialogue()

    def on_cancel(self, event):
        '''Event for button cancel.'''
        self.cancel_dialogue()

    def get_colour(self):
        '''Return attribute values, 'name', 'htmlcolor', 'label'.'''
        if self.__colname and self.__colname != '':
            label = self.__label.GetValue()
            value = self.__value.GetBackgroundColour().GetAsString(\
                                wx.C2S_HTML_SYNTAX)
            return(self.__colname, value, label)
        else:
            return('', '', '')

    def cancel_dialogue(self):
        '''Discard selection, close dialogue.'''
        # Empty name = cancel dialogue.
        self.__colname = ''
        self.Close()

    def ok_dialogue(self):
        '''Assume selection, close dialogue.'''
        name = self.__name.GetValue()
        label = self.__label.GetValue()
        if name in self.__existnames:
            dlg = wx.MessageDialog(self,
                  _(u'The color name is already in use. Please ' + \
                  'choose a different name.'), _(u'Information'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif name.startswith('__'):
            dlg = wx.MessageDialog(self,
                  _(u'The initial "__" should not be used. Please ' + \
                  'select another beginning.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif not name:
            dlg = wx.MessageDialog(self,
                  _(u'Please give the colour a name.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        elif not label:
            dlg = wx.MessageDialog(self,
                  _(u'Please give the colour a description.'),
                  style=wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            self.__colname = name
            self.Close()

    def dialogue_size(self):
        '''Calculate the dialogue size.'''
        # Get sizes from the option and from the parent window.
        # Control widht and height, if needed correct the values.
        wdlg = self.__options.get_('dlgnewstywidth')
        hdlg = self.__options.get_('dlgnewstyheight')
        wparent, hparent = self.__parent.GetSize()
        if hdlg > hparent:
            hdlg = hparent
        if wdlg > wparent:
            wdlg = wparent
        return(wdlg, hdlg)

    def on_dialogue_close(self, event):
        '''Event to assume the dialogue sizes.'''
        # Get the sizes from dialogue and list control rows.
        # Write the sizes to the options
        wdlg, hdlg = self.GetSize()
        self.__options.set_('dlgnewstywidth', wdlg)
        self.__options.set_('dlgnewstyheight', hdlg)
        event.Skip()

    def on_spin(self, event):
        '''Event for spin controls.'''
        self.set_linestyle()

    def disable_spins(self):
        '''Disalbe all spin controls.'''
        for i in self.__spins:
            i.Disable()

    def enable_spins(self):
        '''Enable all spin controls with value > 0.'''
        index = 0
        last = -1
        for i in self.__spins:
            v = i.GetValue()
            if v!= 0:
                i.Enable()
                last = index
            index = index + 1
        # Enable 1st spin control with value == 0.
        self.__spins[last + 1].Enable()

    def read_spins(self):
        '''Read Values of spin controls and return a list.'''
        valuelist = []
        for i in self.__spins:
            v = i.GetValue()
            if v!= 0:
                valuelist.append(v)
        return(valuelist)

    def on_wxlist(self, event):
        '''Event for combobox wxlist.'''
        self.set_linestyle()

    def set_default_wxlist(self, text):
        '''Set the entry with 'text' highlighted in wxlist.'''
        self.__wxlist.SetStringSelection(text)

    def set_linestyle(self):
        '''Set the line style for the preview an the spins.'''
        style = self.__wxlist.GetValue()
        if style == 'user dash':
            self.enable_spins()
            userdash = self.read_spins()
            self.__prevstyle = (self.__linstyldict[style], userdash)
        else:
            self.disable_spins()
            self.__prevstyle = (self.__linstyldict[style], [])
        self.Refresh()


if __name__ == '__main__':
    print('Please start lrzgui.py or lrzwxtest.py ..')