summaryrefslogtreecommitdiff
path: root/trunk/reprap/miscellaneous/python-beanshell-scripts/skeinforge_tools/skeinforge_utilities/settings.py
blob: c7c789cef492c510236de712300f40f09a129e88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
"""
Settings is a collection of utilities to display, read & write the settings and position widgets.

"""

from __future__ import absolute_import
#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
import __init__

from skeinforge_tools.skeinforge_utilities import euclidean
from skeinforge_tools.skeinforge_utilities import gcodec
import cStringIO
import os
import shutil
import webbrowser
try:
	import Tkinter
except:
	print( 'You do not have Tkinter, which is needed for the graphical interface, you will only be able to use the command line.' )
	print( 'Information on how to download Tkinter is at:\nwww.tcl.tk/software/tcltk/' )


__author__ = "Enrique Perez (perez_enrique@yahoo.com)"
__date__ = "$Date: 2008/23/04 $"
__license__ = "GPL 3.0"

globalRepositoryDialogListTable = {}
globalProfileSaveListenerListTable = {}
globalCloseListTables = [ globalRepositoryDialogListTable, globalProfileSaveListenerListTable ]
globalSpreadsheetSeparator = '\t'


def addAcceleratorCommand( acceleratorBinding, commandFunction, master, menu, text ):
	"Add accelerator command."
	acceleratorText = acceleratorBinding[ 1 : - 1 ]
	lastIndexOfMinus = acceleratorText.rfind( '-' )
	if lastIndexOfMinus > - 1:
		acceleratorText = acceleratorText[ : lastIndexOfMinus + 1 ] + acceleratorText[ lastIndexOfMinus + 1 : ].capitalize()
	acceleratorText = acceleratorText.replace( 'KeyPress-', '' )
	acceleratorText = acceleratorText.replace( '-', '+' )
	acceleratorText = acceleratorText.replace( 'Control', 'Ctrl' )
	acceleratorBinding = acceleratorBinding.replace( 'KeyPress', '' )
	menu.add_command( accelerator = acceleratorText, label = text, underline = 0, command = commandFunction )
	master.bind( acceleratorBinding, commandFunction )

def addElementToListTableIfNotThere( element, key, listTable ):
	"Add the value to the lists."
	if key in listTable:
		elements = listTable[ key ]
		if element not in elements:
			elements.append( element )
	else:
		listTable[ key ] = [ element ]

def addEmptyRow( gridPosition ):
	"Add an empty row."
	gridPosition.increment()
	Tkinter.Label( gridPosition.master ).grid( row = gridPosition.row, column = gridPosition.column )

def addListsSetCraftProfileArchive( craftSequence, defaultProfile, repository, fileNameHelp ):
	"Set the craft profile archive."
	addListsToRepository( fileNameHelp, '', repository )
	repository.craftSequenceLabel = LabelDisplay().getFromName( 'Craft Sequence: ', repository )
	craftToolStrings = []
	for craftTool in craftSequence[ : - 1 ]:
		craftToolStrings.append( getEachWordCapitalized( craftTool ) + '->' )
	craftToolStrings.append( getEachWordCapitalized( craftSequence[ - 1 ] ) )
	for craftToolStringIndex in xrange( 0, len( craftToolStrings ), 5 ):
		craftLine = ' '.join( craftToolStrings[ craftToolStringIndex : craftToolStringIndex + 5 ] )
		LabelDisplay().getFromName( craftLine, repository )
	LabelDisplay().getFromName( '', repository )
	repository.profileList = ProfileList().getFromName( 'Profile List:', repository )
	repository.profileListbox = ProfileListboxSetting().getFromListSetting( repository.profileList, 'Profile Selection:', repository, defaultProfile )
	repository.addListboxSelection = AddProfile().getFromProfileListboxSettingRepository( repository.profileListbox, repository )
	repository.deleteListboxSelection = DeleteProfile().getFromProfileListboxSettingRepository( repository.profileListbox, repository )
	directoryName = getProfilesDirectoryPath()
	makeDirectory( directoryName )
	repository.windowPosition.value = '0+400'

def addListsToRepository( fileNameHelp, profileDirectory, repository ):
	"Add the value to the lists."
	repository.archive = []
	repository.displayEntities = []
	repository.executeTitle = None
	repository.fileNameHelp = fileNameHelp
	repository.fileNameInput = None
	repository.lowerName = fileNameHelp.split( '.' )[ - 2 ]
	repository.baseName = os.path.join( profileDirectory, repository.lowerName + '.csv' )
	repository.capitalizedName = getEachWordCapitalized( repository.lowerName )
	repository.openLocalHelpPage = HelpPage().getOpenFromDocumentationSubName( repository.fileNameHelp )
	repository.openWikiManualHelpPage = None
	repository.repositoryDialog = None
	repository.saveListenerTable = {}
	repository.title = repository.capitalizedName + ' Settings'
	repository.menuEntities = []
	repository.saveCloseTitle = 'Save and Close'
	repository.windowPosition = WindowPosition().getFromValue( repository, '0+0' )
	WindowVisibilities().getFromRepository( repository )
	for setting in repository.archive:
		setting.repository = repository

def addMenuEntitiesToMenu( menu, menuEntities ):
	"Add the menu entities to the menu."
	for menuEntity in menuEntities:
		menuEntity.addToMenu( menu )

def addMenuEntitiesToMenuFrameable( menu, menuEntities ):
	"Add the menu entities to the menu."
	for menuEntity in menuEntities:
		menuEntity.addToMenuFrameable( menu )

def addPluginsParentToMenu( directoryPath, menu, parentPath, pluginFileNames ):
	"Add plugins and the parent to the menu."
	ToolDialog().addPluginToMenu( menu, parentPath[ : parentPath.rfind( '.' ) ] )
	menu.add_separator()
	addPluginsToMenu( directoryPath, menu, pluginFileNames )

def addPluginsToMenu( directoryPath, menu, pluginFileNames ):
	"Add plugins to the menu."
	for pluginFileName in pluginFileNames:
		ToolDialog().addPluginToMenu( menu, os.path.join( directoryPath, pluginFileName ) )

def cancelRepository( repository ):
	"Read the repository then set all the entities to the read archive values."
	getReadRepository( repository )
	for setting in repository.displayEntities:
		if setting in repository.archive:
			setting.setStateToValue()

def deleteDirectory( directory, subfolderName ):
	"Delete the directory if it exists."
	subDirectory = os.path.join( directory, subfolderName )
	if os.path.isdir( subDirectory ):
		shutil.rmtree( subDirectory )

def deleteMenuItems( menu ):
	"Delete the menu items."
	try:
		lastMenuIndex = menu.index( Tkinter.END )
		if lastMenuIndex != None:
			menu.delete( 0, lastMenuIndex )
	except:
		print( 'this should never happen, the lastMenuIndex in deleteMenuItems in settings could not be determined.' ) 

def getAlongWayHexadecimalColor( beginBrightness, colorWidth, difference, endColorTuple, wayLength ):
	"Get a color along the way from begin brightness to the end color."
	alongWay = 1.0
	if wayLength != 0.0:
		alongWay = min( 1.0, float( difference ) / float( wayLength ) )
	hexadecimalColor = '#'
	oneMinusAlongWay = 1.0 - alongWay
	for primaryIndex in xrange( 3 ):
		hexadecimalColor += getAlongWayHexadecimalPrimary( beginBrightness, oneMinusAlongWay, colorWidth, endColorTuple[ primaryIndex ], alongWay )
	return hexadecimalColor

def getAlongWayHexadecimalPrimary( beginBrightness, beginRatio, colorWidth, endBrightness, endRatio ):
	"Get a primary color along the way from grey to the end color."
	brightness = beginRatio * float( beginBrightness ) + endRatio * float( endBrightness )
	return getWidthHex( int( round( brightness ) ), colorWidth )

def getArchiveText( repository ):
	"Get the text representation of the archive."
	archiveWriter = cStringIO.StringIO()
	archiveWriter.write( 'Format is tab separated %s.\n' % repository.title.lower() )
	archiveWriter.write( 'Name                          %sValue\n' % globalSpreadsheetSeparator )
	for setting in repository.archive:
		setting.writeToArchiveWriter( archiveWriter )
	return archiveWriter.getvalue()

def getDirectoryInAboveDirectory( directory ):
	"Get the directory in the above directory."
	aboveDirectory = os.path.dirname( os.path.dirname( os.path.abspath( __file__ ) ) )
	return os.path.join( aboveDirectory, directory )

def getDisplayedDialogFromConstructor( repository ):
	"Display the repository dialog."
	getReadRepository( repository )
	return RepositoryDialog( repository, Tkinter.Tk() )
	try:
		getReadRepository( repository )
		return RepositoryDialog( repository, Tkinter.Tk() )
	except:
		print( 'this should never happen, getDisplayedDialogFromConstructor in settings could not open' )
		print( repository )
		return None

def getDisplayedDialogFromPath( path ):
	"Display the repository dialog."
	pluginModule = gcodec.getModuleWithPath( path )
	if pluginModule == None:
		return None
	return getDisplayedDialogFromConstructor( pluginModule.getNewRepository() )

def getDisplayToolButtonsRepository( directoryPath, importantFileNames, names, repository ):
	"Get the display tool buttons."
	displayToolButtons = []
	for name in names:
		displayToolButton = DisplayToolButton().getFromPath( name in importantFileNames, name, os.path.join( directoryPath, name ), repository )
		displayToolButtons.append( displayToolButton )
	return displayToolButtons

def getDocumentationPath( subName = '' ):
	"Get the documentation file path."
	numberOfLevelsDeepInPackageHierarchy = 2
	packageFilePath = os.path.abspath( __file__ )
	for level in xrange( numberOfLevelsDeepInPackageHierarchy + 1 ):
		packageFilePath = os.path.dirname( packageFilePath )
	documentationIndexPath = os.path.join( packageFilePath, 'documentation' )
	return os.path.join( documentationIndexPath, subName )

def getEachWordCapitalized( name ):
	"Get the capitalized name."
	withSpaces = name.lower().replace( '_', ' ' )
	words = withSpaces.split( ' ' )
	capitalizedStrings = []
	for word in words:
		capitalizedStrings.append( word.capitalize() )
	return ' '.join( capitalizedStrings )

def getFileInAlterationsOrGivenDirectory( directory, fileName ):
	"Get the file from the fileName or the lowercase fileName in the alterations directories, if there is no file look in the given directory."
	settingsAlterationsDirectory = getSettingsDirectoryPath( 'alterations' )
	makeDirectory( settingsAlterationsDirectory )
	fileInSettingsAlterationsDirectory = getFileInGivenDirectory( settingsAlterationsDirectory, fileName )
	if fileInSettingsAlterationsDirectory != '':
		return fileInSettingsAlterationsDirectory
	alterationsDirectory = getDirectoryInAboveDirectory( 'alterations' )
	fileInAlterationsDirectory = getFileInGivenDirectory( alterationsDirectory, fileName )
	if fileInAlterationsDirectory != '':
		return fileInAlterationsDirectory
	if directory == '':
		directory = os.getcwd()
	return getFileInGivenDirectory( directory, fileName )

def getFileInGivenDirectory( directory, fileName ):
	"Get the file from the fileName or the lowercase fileName in the given directory."
	directoryListing = os.listdir( directory )
	lowerFileName = fileName.lower()
	for directoryFile in directoryListing:
		if directoryFile.lower() == lowerFileName:
			return getFileTextGivenDirectoryFileName( directory, directoryFile )
	return ''

def getFileTextGivenDirectoryFileName( directory, fileName ):
	"Get the entire text of a file with the given file name in the given directory."
	absoluteFilePath = os.path.join( directory, fileName )
	return gcodec.getFileText( absoluteFilePath )

def getFolders( directory ):
	"Get the folder list in a directory."
	makeDirectory( directory )
	directoryListing = []
	try:
		directoryListing = os.listdir( directory )
	except OSError:
		print( 'Skeinforge can not list the directory:' )
		print( directory )
		print( 'so give it read/write permission for that directory.' )
	folders = []
	for fileName in directoryListing:
		if os.path.isdir( os.path.join( directory, fileName ) ):
			folders.append( fileName )
	return folders

def getPathFromFileNameHelp( fileNameHelp ):
	"Get the directory path from file name help."
	skeinforgePath = getSkeinforgeDirectoryPath()
	splitFileNameHelps = fileNameHelp.split( '.' )
	splitFileNameDirectoryNames = splitFileNameHelps[ : - 1 ]
	for splitFileNameDirectoryName in splitFileNameDirectoryNames:
		skeinforgePath = os.path.join( skeinforgePath, splitFileNameDirectoryName )
	return skeinforgePath

def getRadioPluginsAddPluginFrame( directoryPath, importantFileNames, names, repository ):
	"Get the radio plugins and add the plugin frame."
	repository.pluginFrame = PluginFrame()
	radioPlugins = []
	for name in names:
		radioPlugin = RadioPlugin().getFromRadio( name in importantFileNames, repository.pluginFrame.latentStringVar, name, repository, name == importantFileNames[ 0 ] )
		radioPlugin.updateFunction = repository.pluginFrame.update
		radioPlugins.append( radioPlugin )
	defaultRadioButton = getSelectedRadioPlugin( importantFileNames + [ radioPlugins[ 0 ].name ], radioPlugins )
	repository.pluginFrame.getFromPath( defaultRadioButton, directoryPath, repository )
	return radioPlugins

def getProfilesDirectoryPath( subfolder = '' ):
	"Get the profiles directory path, which is the settings directory joined with profiles."
	profilesDirectory = getSettingsDirectoryPath( 'profiles' )
	if subfolder == '':
		return profilesDirectory
	return os.path.join( profilesDirectory, subfolder )

def getProfilesDirectoryInAboveDirectory( subName = '' ):
	"Get the profiles directory path in the above directory."
	aboveProfilesDirectory = getDirectoryInAboveDirectory( 'profiles' )
	if subName == '':
		return aboveProfilesDirectory
	return os.path.join( aboveProfilesDirectory, subName )

def getReadRepository( repository ):
	"Read and return settings from a file."
	text = gcodec.getFileText( getProfilesDirectoryPath( repository.baseName ), 'r', False )
	if text == '':
		print( 'The default %s will be written in the .skeinforge folder in the home directory.' % repository.title.lower() )
		text = gcodec.getFileText( getProfilesDirectoryInAboveDirectory( repository.baseName ), 'r', False )
		if text != '':
			readSettingsFromText( repository, text )
		writeSettings( repository )
		return repository
	readSettingsFromText( repository, text )
	return repository

def getSelectedPluginModuleFromPath( filePath, plugins ):
	"Get the selected plugin module."
	for plugin in plugins:
		if plugin.value:
			return gcodec.getModuleFromPath( plugin.name, filePath )
	return None

def getSelectedPluginName( plugins ):
	"Get the selected plugin name."
	for plugin in plugins:
		if plugin.value:
			return plugin.name
	return ''

def getSelectedRadioPlugin( names, radioPlugins ):
	"Get the selected radio button if it exists, None otherwise."
	for radioPlugin in radioPlugins:
		if radioPlugin.value:
			return radioPlugin
	for name in names:
		for radioPlugin in radioPlugins:
			if radioPlugin.name == name:
				radioPlugin.value = True
				return radioPlugin
	print( 'this should never happen, no getSelectedRadioPlugin in settings' )
	print( names )
	return radioPlugin[ 0 ]

def getSettingsDirectoryPath( subfolder = '' ):
	"Get the settings directory path, which is the home directory joined with .skeinforge."
	settingsDirectory = os.path.join( os.path.expanduser( '~' ), '.skeinforge' )
	if subfolder == '':
		return settingsDirectory
	return os.path.join( settingsDirectory, subfolder )

def getSkeinforgeToolsDirectoryPath():
	"Get the skeinforge tools directory path."
	return os.path.dirname( os.path.dirname( os.path.abspath( __file__ ) ) )

def getSkeinforgeDirectoryPath():
	"Get the skeinforge directory path."
	return os.path.dirname( getSkeinforgeToolsDirectoryPath() )

def getSubfolderWithBasename( basename, directory ):
	"Get the subfolder in the directory with the basename."
	makeDirectory( directory )
	directoryListing = os.listdir( directory )
	for fileName in directoryListing:
		joinedFileName = os.path.join( directory, fileName )
		if os.path.isdir( joinedFileName ):
			if basename == fileName:
				return joinedFileName
	return None

def getTitleFromName( title ):
	"Get the title of this setting."
	if title[ - 1 ] == ':':
		title = title[ : - 1 ]
	spaceBracketIndex = title.find( ' (' )
	if spaceBracketIndex > - 1:
		return title[ : spaceBracketIndex ]
	return title

def getWidthHex( number, width ):
	"Get the first width hexadecimal digits."
	return ( '0000%s' % hex( number )[ 2 : ] )[ - width : ]

def liftRepositoryDialogs( repositoryDialogs ):
	"Lift the repository dialogs."
	for repositoryDialog in repositoryDialogs:
		repositoryDialog.root.withdraw() # the withdraw & deiconify trick is here because lift does not work properly on my linux computer
		repositoryDialog.root.lift() # probably not necessary, here in case the withdraw & deiconify trick does not work on some other computer
		repositoryDialog.root.deiconify()
		repositoryDialog.root.lift() # probably not necessary, here in case the withdraw & deiconify trick does not work on some other computer
		repositoryDialog.root.update_idletasks()

def makeDirectory( directory ):
	"Make a directory if it does not already exist."
	if os.path.isdir( directory ):
		return
	try:
		os.makedirs( directory )
	except OSError:
		print( 'Skeinforge can not make the directory %s so give it read/write permission for that directory and the containing directory.' % directory )

def openWebPage( webPagePath ):
	"Open a web page in a browser."
	if webPagePath.find( '#' ) != - 1: # to get around # encode bug
		redirectionText = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n<html>\n<head>\n'
		redirectionText += '<meta http-equiv="REFRESH" content="0;url=%s"></head>\n</HTML>\n' % webPagePath
		webPagePath = getDocumentationPath( 'redirect.html' )
		gcodec.writeFileText( webPagePath, redirectionText )
	webPagePath = '"%s"' % webPagePath # " to get around space in url bug
	try:
		os.startfile( webPagePath )#this is available on some python environments, but not all
		return
	except:
		pass
	webbrowserName = webbrowser.get().name
	if webbrowserName == '':
		print( 'Skeinforge was not able to open the documentation file in a web browser.  To see the documentation, open the following file in a web browser:' )
		print( webPagePath )
		return
	os.system( webbrowserName + ' ' + webPagePath )#used this instead of webbrowser.open() to workaround webbrowser open() bug

def quitWindow( root ):
	"Quit a window."
	try:
		root.destroy()
	except:
		pass

def quitWindows( event = None ):
	"Quit all windows."
	global globalRepositoryDialogListTable
	globalRepositoryDialogValues = euclidean.getListTableElements( globalRepositoryDialogListTable )
	for globalRepositoryDialogValue in globalRepositoryDialogValues:
		quitWindow( globalRepositoryDialogValue.root )

def readSettingsFromText( repository, text ):
	"Read settings from a text."
	lines = gcodec.getTextLines( text )
	settingTable = {}
	for setting in repository.archive:
		settingTable[ setting.name ] = setting
	for lineIndex in xrange( len( lines ) ):
		setArchiveToLine( lineIndex, lines, settingTable )

def saveRepository( repository ):
	"Set the entities to the dialog then write them."
	for setting in repository.archive:
		setting.setToDisplay()
	writeSettingsPrintMessage( repository )
	for saveListener in repository.saveListenerTable.values():
		saveListener()

def setArchiveToLine( lineIndex, lines, settingTable ):
	"Set an archive to a setting line."
	line = lines[ lineIndex ]
	splitLine = line.split( globalSpreadsheetSeparator )
	if len( splitLine ) < 2:
		return
	fileSettingName = splitLine[ 0 ]
	if fileSettingName in settingTable:
		settingTable[ fileSettingName ].setValueToSplitLine( lineIndex, lines, splitLine )

def setButtonFontWeightString( button, isBold ):
	"Set button font weight given isBold."
	try:
		weightString = 'normal'
		if isBold:
			weightString = 'bold'
		splitFont = button[ 'font' ].split()
		button[ 'font' ] = ( splitFont[ 0 ], splitFont[ 1 ], weightString )
	except:
		pass

def setEntryText( entry, value ):
	"Set the entry text."
	if entry == None:
		return
	entry.delete( 0, Tkinter.END )
	entry.insert( 0, str( value ) )

def setIntegerValueToString( integerSetting, valueString ):
	"Set the integer to the string."
	dotIndex = valueString.find( '.' )
	if dotIndex > - 1:
		valueString = valueString[ : dotIndex ]
	try:
		integerSetting.value = int( valueString )
		return
	except:
		print( 'Warning, can not read integer ' + integerSetting.name + ' ' + valueString )
		print( 'Will try reading as a boolean, which might be a mistake.' )
	integerSetting.value = 0
	if valueString.lower() == 'true':
		integerSetting.value = 1

def setSpinColor( setting ):
	"Set the spin box color to the value, yellow if it is lower than the default and blue if it is higher."
	if setting.entry == None:
		return
	if setting.backgroundColor == None:
		setting.backgroundColor = setting.entry[ 'background' ]
		if setting.backgroundColor[ 0 ] != '#':
			setting.backgroundColor = '#ffffff'
		setting.colorWidth = len( setting.backgroundColor ) / 3
		setting.grey = int( setting.backgroundColor[ 1 : 1 + setting.colorWidth ], 16 )
		setting.white = int( 'f' * setting.colorWidth, 16 )
	if abs( setting.value - setting.defaultValue ) < 0.02 * setting.width:
		setting.entry[ 'background' ] = setting.backgroundColor
		return
	difference = setting.value - setting.defaultValue
	if difference > 0.0:
		wayLength = setting.to - setting.defaultValue
		setting.entry[ 'background' ] = getAlongWayHexadecimalColor( setting.grey, setting.colorWidth, difference, ( 0, setting.white, setting.white ), wayLength )
		return
	wayLength = setting.from_ - setting.defaultValue
	setting.entry[ 'background' ] = getAlongWayHexadecimalColor( setting.grey, setting.colorWidth, difference, ( setting.white, setting.white, 0 ), wayLength )

def startMainLoopFromConstructor( repository ):
	"Display the repository dialog and start the main loop."
	getDisplayedDialogFromConstructor( repository ).root.mainloop()

def updateProfileSaveListeners():
	"Call the save function of all the update profile save listeners."
	global globalProfileSaveListenerListTable
	for globalProfileSaveListener in euclidean.getListTableElements( globalProfileSaveListenerListTable ):
		globalProfileSaveListener.save()

def writeValueListToArchiveWriter( archiveWriter, setting ):
	"Write tab separated name and list to the archive writer."
	archiveWriter.write( setting.name )
	for item in setting.value:
		if item != '[]':
			archiveWriter.write( globalSpreadsheetSeparator )
			archiveWriter.write( item )
	archiveWriter.write( '\n' )

def writeSettings( repository ):
	"Write the settings to a file."
	profilesDirectoryPath = getProfilesDirectoryPath( repository.baseName )
	makeDirectory( os.path.dirname( profilesDirectoryPath ) )
	gcodec.writeFileText( profilesDirectoryPath, getArchiveText( repository ) )

def writeSettingsPrintMessage( repository ):
	"Set the settings to the dialog then write them."
	writeSettings( repository )
	print( repository.title.lower().capitalize() + ' have been saved.' )


class AddProfile:
	"A class to add a profile."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.entry = Tkinter.Entry( gridPosition.master )
		self.entry.bind( '<Return>', self.addSelectionWithEvent )
		self.entry.grid( row = gridPosition.row, column = 1, columnspan = 3, sticky = Tkinter.W )
		self.addButton = Tkinter.Button( gridPosition.master, activebackground = 'black', activeforeground = 'white', text = 'Add Profile', command = self.addSelection )
		self.addButton.grid( row = gridPosition.row, column = 0 )

	def addSelection( self ):
		"Add the selection of a listbox setting."
		entryText = self.entry.get()
		if entryText == '':
			print( 'To add to the profiles, enter the material name.' )
			return
		self.profileListboxSetting.listSetting.setValueToFolders()
		if entryText in self.profileListboxSetting.listSetting.value:
			print( 'There is already a profile by the name of %s, so no profile will be added.' % entryText )
			return
		self.entry.delete( 0, Tkinter.END )
		craftTypeProfileDirectory = getProfilesDirectoryPath( self.profileListboxSetting.listSetting.craftTypeName )
		destinationDirectory = os.path.join( craftTypeProfileDirectory, entryText )
		shutil.copytree( self.profileListboxSetting.getSelectedFolder(), destinationDirectory )
		self.profileListboxSetting.listSetting.setValueToFolders()
		self.profileListboxSetting.value = entryText
		self.profileListboxSetting.setStateToValue()

	def addSelectionWithEvent( self, event ):
		"Add the selection of a listbox setting, given an event."
		self.addSelection()

	def getFromProfileListboxSettingRepository( self, profileListboxSetting, repository ):
		"Initialize."
		self.profileListboxSetting = profileListboxSetting
		self.repository = repository
		repository.displayEntities.append( self )
		return self


class StringSetting:
	"A class to display, read & write a string."
	def __init__( self ):
		"Set the update function to none."
		self.entry = None
		self.updateFunction = None

	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.label = Tkinter.Label( gridPosition.master, text = self.name )
		self.label.grid( row = gridPosition.row, column = 0, columnspan = 3, sticky = Tkinter.W )
		self.createEntry( gridPosition.master )
		self.setStateToValue()
		self.entry.grid( row = gridPosition.row, column = 3, columnspan = 2, sticky = Tkinter.W )
		self.bindEntry()
		LabelHelp( self.repository.fileNameHelp, gridPosition.master, self.name, self.label )

	def addToMenu( self, repositoryMenu ):
		"Do nothing because this should only be added to a frameable repository menu."
		pass

	def addToMenuFrameable( self, repositoryMenu ):
		"Add this to the frameable repository menu."
		titleFromName = getTitleFromName( self.name )
		helpWindowMenu = Tkinter.Menu( repositoryMenu, tearoff = 0 )
		repositoryMenu.add_cascade( label = titleFromName, menu = helpWindowMenu, underline = 0 )
		if self.name in self.repository.frameList.value:
			helpWindowMenu.add_command( label = 'Remove from Window', command = self.removeFromWindow )
		else:
			helpWindowMenu.add_command( label = 'Add to Window', command = self.addToWindow )
		helpWindowMenu.add_separator()
		helpWindowMenu.add_command( label = 'Help', command = HelpPage().getOpenFromDocumentationSubName( self.repository.fileNameHelp + '#' + titleFromName ) )

	def addToWindow( self ):
		"Add this to the repository frame list."
		self.repository.frameList.addToList( self.name )

	def bindEntry( self ):
		"Bind the entry to the update function."
		if self.updateFunction != None:
			self.entry.bind( '<Return>', self.updateFunction )

	def createEntry( self, root ):
		"Create the entry."
		self.entry = Tkinter.Entry( root )

	def getFromValue( self, name, repository, value ):
		"Initialize."
		return self.getFromValueOnlyAddToRepository( name, repository, value )

	def getFromValueOnly( self, name, repository, value ):
		"Initialize."
		self.defaultValue = value
		self.name = name
		self.repository = repository
		self.value = value
		return self

	def getFromValueOnlyAddToRepository( self, name, repository, value ):
		"Initialize."
		repository.archive.append( self )
		repository.displayEntities.append( self )
		repository.menuEntities.append( self )
		return self.getFromValueOnly( name, repository, value )

	def removeFromWindow( self ):
		"Remove this from the repository frame list."
		self.repository.frameList.removeFromList( self.name )

	def setStateToValue( self ):
		"Set the entry to the value."
		setEntryText( self.entry, self.value )

	def setToDisplay( self ):
		"Set the string to the entry field."
		try:
			valueString = self.entry.get()
			self.setValueToString( valueString )
		except:
			pass

	def setUpdateFunction( self, updateFunction ):
		"Set the update function."
		self.updateFunction = updateFunction

	def setValueToSplitLine( self, lineIndex, lines, splitLine ):
		"Set the value to the second word of a split line."
		self.setValueToString( splitLine[ 1 ] )

	def setValueToString( self, valueString ):
		"Set the value to the value string."
		self.value = valueString

	def writeToArchiveWriter( self, archiveWriter ):
		"Write tab separated name and value to the archive writer."
		archiveWriter.write( '%s%s%s\n' % ( self.name, globalSpreadsheetSeparator, self.value ) )


class BooleanSetting( StringSetting ):
	"A class to display, read & write a boolean."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.checkbutton = Tkinter.Checkbutton( gridPosition.master, command = self.toggleCheckbutton, text = self.name )
#toggleCheckbutton is being used instead of a Tkinter IntVar because there is a weird bug where it doesn't work properly if this setting is not on the first window.
		self.checkbutton.grid( row = gridPosition.row, columnspan = 5, sticky = Tkinter.W )
		self.setStateToValue()
		LabelHelp( self.repository.fileNameHelp, gridPosition.master, self.name, self.checkbutton )

	def addToMenu( self, repositoryMenu ):
		"Add this to the repository menu."
		self.activateToggleMenuCheckbutton = False
#activateToggleMenuCheckbutton is being used instead of setting command after because add_checkbutton does not return a checkbutton.
		repositoryMenu.add_checkbutton( label = getTitleFromName( self.name ), command = self.toggleMenuCheckbutton )
		if self.value:
			repositoryMenu.invoke( repositoryMenu.index( Tkinter.END ) )
		self.activateToggleMenuCheckbutton = True

	def addToMenuFrameable( self, repositoryMenu ):
		"Add this to the frameable repository menu."
		titleFromName = getTitleFromName( self.name )
		helpWindowMenu = Tkinter.Menu( repositoryMenu, tearoff = 0 )
		repositoryMenu.add_cascade( label = titleFromName, menu = helpWindowMenu, underline = 0 )
		self.addToMenu( helpWindowMenu )
		helpWindowMenu.add_separator()
		helpWindowMenu.add_command( label = 'Help', command = HelpPage().getOpenFromDocumentationSubName( self.repository.fileNameHelp + '#' + titleFromName ) )

	def setStateToValue( self ):
		"Set the checkbutton to the boolean."
		try:
			if self.value:
				self.checkbutton.select()
			else:
				self.checkbutton.deselect()
		except:
			pass

	def setToDisplay( self ):
		"Do nothing because toggleCheckbutton is handling the value."
		pass

	def setValueToString( self, valueString ):
		"Set the boolean to the string."
		self.value = ( valueString.lower() == 'true' )

	def toggleCheckbutton( self ):
		"Workaround for Tkinter bug, toggle the value."
		self.value = not self.value
		self.setStateToValue()
		if self.updateFunction != None:
			self.updateFunction()

	def toggleMenuCheckbutton( self ):
		"Workaround for Tkinter bug, toggle the value."
		if self.activateToggleMenuCheckbutton:
			self.value = not self.value
			if self.updateFunction != None:
				self.updateFunction()


class CloseListener:
	"A class to listen to link a window to the global repository dialog list table."
	def __init__( self, window, closeFunction = None ):
		"Add the window to the global repository dialog list table."
		self.closeFunction = closeFunction
		self.window = window
		self.shouldWasClosedBeBound = True
		global globalRepositoryDialogListTable
		addElementToListTableIfNotThere( window, window, globalRepositoryDialogListTable )

	def listenToWidget( self, widget ):
		"Listen to the destroy message of the widget."
		if self.shouldWasClosedBeBound:
			self.shouldWasClosedBeBound = False
			widget.bind( '<Destroy>', self.wasClosed )

	def wasClosed( self, event ):
		"The dialog was closed."
		global globalCloseListTables
		for globalCloseListTable in globalCloseListTables:
			if self.window in globalCloseListTable:
				del globalCloseListTable[ self.window ]
		if self.closeFunction != None:
			self.closeFunction()


class DeleteProfile( AddProfile ):
	"A class to delete the selection of a listbox profile."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.deleteButton = Tkinter.Button( gridPosition.master, activebackground = 'black', activeforeground = 'white', text = "Delete Profile", command = self.deleteSelection )
		self.deleteButton.grid( row = gridPosition.row, column = 0 )

	def deleteSelection( self ):
		"Delete the selection of a listbox setting."
		DeleteProfileDialog( self.profileListboxSetting, Tkinter.Tk() )


class DeleteProfileDialog:
	def __init__( self, profileListboxSetting, root ):
		"Display a delete dialog."
		self.profileListboxSetting = profileListboxSetting
		self.root = root
		self.row = 0
		root.title( 'Delete Warning' )
		self.gridPosition.increment()
		self.label = Tkinter.Label( self.root, text = 'Do you want to delete the profile?' )
		self.label.grid( row = self.row, column = 0, columnspan = 3, sticky = Tkinter.W )
		columnIndex = 1
		deleteButton = Tkinter.Button( root, activebackground = 'black', activeforeground = 'red', command = self.delete, fg = 'red', text = 'Delete' )
		deleteButton.grid( row = self.row, column = columnIndex )
		columnIndex += 1
		noButton = Tkinter.Button( root, activebackground = 'black', activeforeground = 'darkgreen', command = self.no, fg = 'darkgreen', text = 'Do Nothing' )
		noButton.grid( row = self.row, column = columnIndex )

	def delete( self ):
		"Delete the selection of a listbox setting."
		self.profileListboxSetting.setToDisplay()
		self.profileListboxSetting.listSetting.setValueToFolders()
		if self.profileListboxSetting.value not in self.profileListboxSetting.listSetting.value:
			return
		lastSelectionIndex = 0
		currentSelectionTuple = self.profileListboxSetting.listbox.curselection()
		if len( currentSelectionTuple ) > 0:
			lastSelectionIndex = int( currentSelectionTuple[ 0 ] )
		else:
			print( 'No profile is selected, so no profile will be deleted.' )
			return
		deleteDirectory( getProfilesDirectoryPath( self.profileListboxSetting.listSetting.craftTypeName ), self.profileListboxSetting.value )
		deleteDirectory( getProfilesDirectoryInAboveDirectory( self.profileListboxSetting.listSetting.craftTypeName ), self.profileListboxSetting.value )
		self.profileListboxSetting.listSetting.setValueToFolders()
		if len( self.profileListboxSetting.listSetting.value ) < 1:
			defaultSettingsDirectory = getProfilesDirectoryPath( os.path.join( self.profileListboxSetting.listSetting.craftTypeName, self.profileListboxSetting.defaultValue ) )
			makeDirectory( defaultSettingsDirectory )
			self.profileListboxSetting.listSetting.setValueToFolders()
		lastSelectionIndex = min( lastSelectionIndex, len( self.profileListboxSetting.listSetting.value ) - 1 )
		self.profileListboxSetting.value = self.profileListboxSetting.listSetting.value[ lastSelectionIndex ]
		self.profileListboxSetting.setStateToValue()
		self.no()

	def no( self ):
		"The dialog was closed."
		self.root.destroy()


class DisplayToolButton:
	"A class to display the tool dialog button, in a two column wide table."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		self.displayButton = Tkinter.Button( gridPosition.master, activebackground = 'black', activeforeground = 'white', text = getEachWordCapitalized( self.name ), command = self.displayDialog )
		setButtonFontWeightString( self.displayButton, self.important )
		gridPosition.incrementGivenNumberOfColumns( 2 )
		self.displayButton.grid( row = gridPosition.row, column = gridPosition.column, columnspan = 2 )

	def displayDialog( self ):
		"Display function."
		ToolDialog().getFromPath( self.path ).display()

	def getFromPath( self, important, name, path, repository ):
		"Initialize."
		self.important = important
		self.name = name
		self.path = path
		self.repository = repository
		repository.displayEntities.append( self )
		return self


class FileHelpMenuBar:
	def __init__( self, root ):
		"Create a menu bar with a file and help menu."
		self.underlineLetters = []
		self.menuBar = Tkinter.Menu( root )
		self.root = root
		root.config( menu = self.menuBar )
		self.fileMenu = Tkinter.Menu( self.menuBar, tearoff = 0 )
		self.menuBar.add_cascade( label = "File", menu = self.fileMenu, underline = 0 )
		self.underlineLetters.append( 'f' )

	def addMenuToMenuBar( self, labelText, menu ):
		"Add a menu to the menu bar."
		lowerLabelText = labelText.lower()
		for underlineLetterIndex in xrange( len( lowerLabelText ) ):
			underlineLetter = lowerLabelText[ underlineLetterIndex ]
			if underlineLetter not in self.underlineLetters:
				self.underlineLetters.append( underlineLetter )
				self.menuBar.add_cascade( label = labelText, menu = menu, underline = underlineLetterIndex )
				return
		self.menuBar.add_cascade( label = labelText, menu = menu )

	def addPluginToMenuBar( self, modulePath, repository, window ):
		"Add a menu to the menu bar from a tool."
		pluginModule = gcodec.getModuleWithPath( modulePath )
		if pluginModule == None:
			print( 'this should never happen, pluginModule in addMenuToMenuBar in settings is None.' )
			return None
		repositoryMenu = Tkinter.Menu( self.menuBar, tearoff = 0 )
		labelText = getEachWordCapitalized( os.path.basename( modulePath ) )
		self.addMenuToMenuBar( labelText, repositoryMenu )
		pluginModule.addToMenu( self.root, repositoryMenu, repository, window )

	def completeMenu( self, closeFunction, repository, saveFunction, window ):
		"Complete the menu."
		self.closeFunction = closeFunction
		self.saveFunction = saveFunction
		addAcceleratorCommand( '<Control-KeyPress-s>', saveFunction, self.root, self.fileMenu, 'Save' )
		self.fileMenu.add_command( label = "Save and Close", command = self.saveClose )
		addAcceleratorCommand( '<Control-KeyPress-w>', closeFunction, self.root, self.fileMenu, 'Close' )
		self.fileMenu.add_separator()
		addAcceleratorCommand( '<Control-KeyPress-q>', quitWindows, self.root, self.fileMenu, 'Quit' )
		skeinforgeToolsDirectoryPath = getSkeinforgeToolsDirectoryPath()
		pluginFileNames = gcodec.getPluginFileNamesFromDirectoryPath( skeinforgeToolsDirectoryPath )
		for pluginFileName in pluginFileNames:
			self.addPluginToMenuBar( os.path.join( skeinforgeToolsDirectoryPath, pluginFileName ), repository, window )

	def saveClose( self ):
		"Call the save function then the close function."
		self.saveFunction()
		self.closeFunction()


class FileNameInput( StringSetting ):
	"A class to display, read & write a fileName."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		self.gridPosition = gridPosition
		gridPosition.executables.append( self )

	def execute( self ):
		"Open the file picker."
		self.wasCancelled = False
		parent = self.gridPosition.master
		try:
			import tkFileDialog
			summarized = gcodec.getSummarizedFileName( self.value )
			initialDirectory = os.path.dirname( summarized )
			if len( initialDirectory ) > 0:
				initialDirectory += os.sep
			else:
				initialDirectory = "."
			fileName = tkFileDialog.askopenfilename( filetypes = self.getFileNameFirstTypes(), initialdir = initialDirectory, initialfile = os.path.basename( summarized ), parent = parent, title = self.name )
			self.setCancelledValue( fileName )
			return
		except:
			print( 'Could not get the old directory in settings, so the file picker will be opened in the default directory.' )
		try:
			fileName = tkFileDialog.askopenfilename( filetypes = self.getFileNameFirstTypes(), initialdir = '.', initialfile = '', parent = parent, title = self.name )
			self.setCancelledValue( fileName )
		except:
			print( 'Error in execute in FileName in settings, ' + self.name )

	def getFileNameFirstTypes( self ):
		"Get the file types with the file type of the fileName moved to the front of the list."
		try:
			basename = os.path.basename( self.value )
			splitFile = basename.split( '.' )
			allFiles = [ ( 'All', '*.*' ) ]
			allReadables = []
			if len( self.fileTypes ) > 1:
				for fileType in self.fileTypes:
					allReadable = ( ( 'All Readable', fileType[ 1 ] ) )
					allReadables.append( allReadable )
			if len( splitFile ) < 1:
				return self.fileTypes + allReadables + allFiles
			baseExtension = splitFile[ - 1 ]
			for fileType in self.fileTypes:
				fileExtension = fileType[ 1 ].split( '.' )[ - 1 ]
				if fileExtension == baseExtension:
					fileNameFirstTypes = self.fileTypes[ : ]
					fileNameFirstTypes.remove( fileType )
					return [ fileType ] + fileNameFirstTypes + allReadables + allFiles
			return self.fileTypes + allReadables + allFiles
		except:
			return allFiles

	def getFromFileName( self, fileTypes, name, repository, value ):
		"Initialize."
		self.getFromValueOnly( name, repository, value )
		self.fileTypes = fileTypes
		repository.archive.append( self )
		repository.displayEntities.append( self )
		return self

	def setCancelledValue( self, fileName ):
		"Set the value to the file name and wasCancelled true if a file was not picked."
		if ( str( fileName ) == '()' or str( fileName ) == '' ):
			self.wasCancelled = True
		else:
			self.value = fileName

	def setToDisplay( self ):
		"Do nothing because the file dialog is handling the value."
		pass


class FloatSetting( StringSetting ):
	"A class to display, read & write a float."
	def setValueToString( self, valueString ):
		"Set the float to the string."
		try:
			self.value = float( valueString )
		except:
			print( 'Oops, can not read float' + self.name + ' ' + valueString )


class FloatSpin( FloatSetting ):
	"A class to display, read & write an float in a spin box."
	def addToMenuFrameable( self, repositoryMenu ):
		"Add this to the frameable repository menu."
		titleFromName = getTitleFromName( self.name )
		helpWindowMenu = Tkinter.Menu( repositoryMenu, tearoff = 0 )
		repositoryMenu.add_cascade( label = titleFromName, menu = helpWindowMenu, underline = 0 )
		if self.name in self.repository.frameList.value:
			helpWindowMenu.add_command( label = 'Remove from Window', command = self.removeFromWindow )
		else:
			helpWindowMenu.add_command( label = 'Add to Window', command = self.addToWindow )
		helpWindowMenu.add_separator()
		changeString = ' by %s' % self.increment
		helpWindowMenu.add_command( label = 'Increase' + changeString, command = self.increase )
		helpWindowMenu.add_command( label = 'Decrease' + changeString, command = self.decrease )
		helpWindowMenu.add_separator()
		helpWindowMenu.add_command( label = 'Help', command = HelpPage().getOpenFromDocumentationSubName( self.repository.fileNameHelp + '#' + titleFromName ) )

	def bindEntry( self ):
		"Bind the entry to the update function."
		self.entry.bind( '<Return>', self.entryUpdated )
		self.setColor()

	def createEntry( self, root ):
		"Create the entry."
		self.entry = Tkinter.Spinbox( root, command = self.setColorToDisplay, from_ = self.from_, increment = self.increment, to = self.to )

	def decrease( self ):
		"Decrease the value then set the state and color to the value."
		self.value -= self.increment
		self.setStateUpdateColor()

	def entryUpdated( self, event = None ):
		"Create the entry."
		self.setColorToDisplay()
		if self.updateFunction != None:
			self.updateFunction( event )

	def getFromValue( self, from_, name, repository, to, value ):
		"Initialize."
		self.backgroundColor = None
		self.from_ = from_
		self.width = to - from_
		rank = euclidean.getRank( 0.05 * self.width )
		self.increment = euclidean.getIncrementFromRank( rank )
		self.to = to
		return self.getFromValueOnlyAddToRepository( name, repository, value )

	def increase( self ):
		"Increase the value then set the state and color to the value."
		self.value += self.increment
		self.setStateUpdateColor()

	def setColor( self, event = None ):
		"Set the color to the value, yellow if it is lower than the default and blue if it is higher."
		setSpinColor( self )

	def setColorToDisplay( self, event = None ):
		"Set the color to the value, yellow if it is lower than the default and blue if it is higher."
		self.setToDisplay()
		self.setColor()

	def setStateToValue( self ):
		"Set the entry to the value."
		setEntryText( self.entry, self.value )
		self.setColor()

	def setStateUpdateColor( self ):
		"Set the state to the value, call the update function, then set the color."
		self.setStateToValue()
		if self.updateFunction != None:
			self.updateFunction()


class FloatSpinNotOnMenu( FloatSpin ):
	"A class to display, read & write an float in a spin box, which is not to be added to a menu."
	def getFromValueOnlyAddToRepository( self, name, repository, value ):
		"Initialize."
		repository.archive.append( self )
		repository.displayEntities.append( self )
		return self.getFromValueOnly( name, repository, value )


class FloatSpinUpdate( FloatSpin ):
	"A class to display, read, update & write an float in a spin box."
	def createEntry( self, root ):
		"Create the entry."
		self.entry = Tkinter.Spinbox( root, command = self.entryUpdated, from_ = self.from_, increment = self.increment, to = self.to )


class FrameList:
	"A class to list the frames."
	def addToList( self, word ):
		"Add the word to the sorted list."
		self.value.append( word )
		self.value.sort()
		self.repository.window.redisplayWindowUpdate()

	def getFromValue( self, name, repository, value ):
		"Initialize."
		repository.archive.append( self )
		self.name = name
		self.repository = repository
		self.value = value
		return self

	def removeFromList( self, word ):
		"Remove the word from the sorted list."
		self.value.remove( word )
		self.value.sort()
		self.repository.window.redisplayWindowUpdate()

	def setToDisplay( self ):
		"Do nothing because frame list does not have a display."
		pass

	def setValueToSplitLine( self, lineIndex, lines, splitLine ):
		"Set the value to the second and later words of a split line."
		self.value = splitLine[ 1 : ]

	def writeToArchiveWriter( self, archiveWriter ):
		"Write tab separated name and list to the archive writer."
		writeValueListToArchiveWriter( archiveWriter, self )


class GridHorizontal:
	"A class to place elements horizontally on a grid."
	def __init__( self, column, row ):
		"Initialize the column and row."
		self.column = column
		self.columnStart = column
		self.row = row

	def getCopy( self ):
		"Get a copy."
		copy = GridHorizontal( self.column, self.row )
		copy.columnStart = self.columnStart
		return copy

	def increment( self ):
		"Increment the position horizontally."
		self.column += 1


class GridVertical:
	"A class to place elements vertically on a grid."
	def __init__( self, column, row ):
		"Initialize the column and row."
		self.column = column
		self.columnOffset = column
		self.columnStart = column
		self.row = row
		self.rowStart = row

	def execute( self ):
		"The execute button was clicked."
		for executable in self.executables:
			executable.execute()
		saveRepository( self.repository )
		self.repository.execute()

	def getCopy( self ):
		"Get a copy."
		copy = GridVertical( self.column, self.row )
		copy.columnOffset = self.columnOffset
		copy.columnStart = self.columnStart
		copy.rowStart = self.rowStart
		return copy

	def increment( self ):
		"Increment the position vertically."
		self.column = self.columnStart
		self.columnOffset = self.columnStart
		self.row += 1

	def incrementGivenNumberOfColumns( self, numberOfColumns ):
		"Increment the position vertically and offset it horizontally by the given number of columns."
		self.column = self.columnOffset
		if self.columnOffset == self.columnStart:
			self.columnOffset = self.columnStart + 1
			self.row += 1
			return
		if self.columnOffset < self.columnStart + numberOfColumns - 1:
			self.columnOffset += 1
			return
		self.columnOffset = self.columnStart

	def setExecutablesRepository( self, repository ):
		"Set the executables to an empty list and set the repository."
		self.executables = []
		self.repository = repository


class HelpPage:
	"A class to open a help page."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		self.displayButton = Tkinter.Button( gridPosition.master, activebackground = 'black', activeforeground = 'white', text = getEachWordCapitalized( self.name ), command = self.openPage )
		self.displayButton.grid( row = gridPosition.row, column = 3, columnspan = 2 )

	def addToMenu( self, repositoryMenu ):
		"Add this to the repository menu."
		repositoryMenu.add_command( label = getTitleFromName( self.name ), command = self.openPage )

	def addToMenuFrameable( self, repositoryMenu ):
		"Add this to the frameable repository menu."
		self.addToMenu( repositoryMenu )

	def getFromNameAfterHTTP( self, afterHTTP, name, repository ):
		"Initialize."
		self.setToNameRepository( name, repository )
		self.hypertextAddress = 'http://' + afterHTTP
		return self

	def getFromNameAfterWWW( self, afterWWW, name, repository ):
		"Initialize."
		self.setToNameRepository( name, repository )
		self.hypertextAddress = 'http://www.' + afterWWW
		return self

	def getFromNameSubName( self, name, repository, subName = '' ):
		"Initialize."
		self.setToNameRepository( name, repository )
		self.hypertextAddress = getDocumentationPath( subName )
		return self

	def getOpenFromAbsolute( self, hypertextAddress ):
		"Get the open help page function from the hypertext address."
		self.hypertextAddress = hypertextAddress
		return self.openPage

	def getOpenFromAfterHTTP( self, afterHTTP ):
		"Get the open help page function from the part of the address after the HTTP."
		self.hypertextAddress = 'http://' + afterHTTP
		return self.openPage

	def getOpenFromAfterWWW( self, afterWWW ):
		"Get the open help page function from the afterWWW of the address after the www."
		self.hypertextAddress = 'http://www.' + afterWWW
		return self.openPage

	def getOpenFromDocumentationSubName( self, subName = '' ):
		"Get the open help page function from the afterWWW of the address after the www."
		self.hypertextAddress = getDocumentationPath( subName )
		return self.openPage

	def openPage( self, event = None ):
		"Open the browser to the hypertext address."
		openWebPage( self.hypertextAddress )

	def setToNameRepository( self, name, repository ):
		"Set to the name and repository."
		self.name = name
		self.repository = repository
		repository.displayEntities.append( self )
		repository.menuEntities.append( self )


class HelpPageRepository:
	"A class to open a repository help page."
	def __init__( self, repository ):
		"Add this to the dialog."
		self.repository = repository

	def openPage( self, event = None ):
		"Open the browser to the repository help page."
		if self.repository.openWikiManualHelpPage == None:
			self.repository.openLocalHelpPage()
			return
		from skeinforge_tools import help
		helpRepository = getReadRepository( help.HelpRepository() )
		if helpRepository.wikiManualPrimary.value:
			self.repository.openWikiManualHelpPage()
			return
		self.repository.openLocalHelpPage()


class HiddenScrollbar( Tkinter.Scrollbar ):
	"A class to hide the scrollbar if it is not needed."
	def set( self, lo, hi ):
		"Add to grid is needed, remove if not."
		if float( lo ) <= 0.0 and float( hi ) >= 1.0:
			self.tk.call( 'grid', 'remove', self )
		else:
			self.grid()
		Tkinter.Scrollbar.set( self, lo, hi )


class IntSetting( FloatSetting ):
	"A class to display, read & write an int."
	def setValueToString( self, valueString ):
		"Set the integer to the string."
		setIntegerValueToString( self, valueString )


class IntSpin( FloatSpin ):
	"A class to display, read & write an int in a spin box."
	def getFromValue( self, from_, name, repository, to, value ):
		"Initialize."
		self.backgroundColor = None
		self.from_ = from_
		self.width = to - from_
		rank = euclidean.getRank( 0.05 * self.width )
		self.increment = max( 1, int( euclidean.getIncrementFromRank( rank ) ) )
		self.to = to
		return self.getFromValueOnlyAddToRepository( name, repository, value )

	def getSingleIncrementFromValue( self, from_, name, repository, to, value ):
		"Initialize."
		self.backgroundColor = None
		self.from_ = from_
		self.width = to - from_
		self.increment = 1
		self.to = to
		return self.getFromValueOnlyAddToRepository( name, repository, value )

	def setValueToString( self, valueString ):
		"Set the integer to the string."
		setIntegerValueToString( self, valueString )



class IntSpinNotOnMenu( IntSpin ):
	"A class to display, read & write an integer in a spin box, which is not to be added to a menu."
	def getFromValueOnlyAddToRepository( self, name, repository, value ):
		"Initialize."
		repository.archive.append( self )
		repository.displayEntities.append( self )
		return self.getFromValueOnly( name, repository, value )


class IntSpinUpdate( IntSpin ):
	"A class to display, read, update & write an int in a spin box."
	def createEntry( self, root ):
		"Create the entry."
		self.entry = Tkinter.Spinbox( root, command = self.entryUpdated, from_ = self.from_, increment = self.increment, to = self.to )


class LabelDisplay:
	"A class to add a label."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.label = Tkinter.Label( gridPosition.master, text = self.name )
		self.label.grid( row = gridPosition.row, column = 0, columnspan = 3, sticky = Tkinter.W )
		LabelHelp( self.repository.fileNameHelp, gridPosition.master, self.name, self.label )

	def getFromName( self, name, repository ):
		"Initialize."
		self.name = name
		self.repository = repository
		repository.displayEntities.append( self )
		return self


class LabelHelp:
	"A class to add help to a widget."
	def __init__( self, fileNameHelp, master, name, widget ):
		"Add menu to the widget."
		if len( name ) < 1:
			return
		self.popupMenu = Tkinter.Menu( master, tearoff = 0 )
		titleFromName = getTitleFromName( name.replace( '- ', '' ).replace( ' -', '' ) )
		self.popupMenu.add_command( label = 'Help', command = HelpPage().getOpenFromDocumentationSubName( fileNameHelp + '#' + titleFromName ) )
		widget.bind( '<Button-1>', self.unpostPopupMenu )
		widget.bind( '<Button-2>', self.unpostPopupMenu )
		widget.bind( '<Button-3>', self.displayPopupMenu )

	def unpostPopupMenu( self, event = None ):
		'Unpost the popup menu.'
		self.popupMenu.unpost()

	def displayPopupMenu( self, event = None ):
		'Display the popup menu when the button is right clicked.'
		try:
			self.popupMenu.tk_popup( event.x_root + 30, event.y_root, 0 )
		finally:
			self.popupMenu.grab_release()


class LabelSeparator:
	"A class to add a label and menu separator."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.label = Tkinter.Label( gridPosition.master, text = '' )
		self.label.grid( row = gridPosition.row, column = 0, columnspan = 3, sticky = Tkinter.W )

	def addToMenu( self, repositoryMenu ):
		"Add this to the repository menu."
		repositoryMenu.add_separator()

	def addToMenuFrameable( self, repositoryMenu ):
		"Add this to the frameable repository menu."
		self.addToMenu( repositoryMenu )

	def getFromRepository( self, repository ):
		"Initialize."
		self.repository = repository
		repository.displayEntities.append( self )
		repository.menuEntities.append( self )
		return self


class LatentStringVar:
	"A class to provide a StringVar when needed."
	def __init__( self ):
		"Set the string var."
		self.stringVar = None

	def getVar( self ):
		"Get the string var."
		if self.stringVar == None:
			self.stringVar = Tkinter.StringVar()
		return self.stringVar

	def getString( self ):
		"Get the string."
		return self.getVar().get()

	def setString( self, word ):
		"Set the string."
		self.getVar().set( word )


class MenuButtonDisplay:
	"A class to add a menu button."
	def addRadiosToDialog( self, gridPosition ):
		"Add the menu radios to the dialog."
		for menuRadio in self.menuRadios:
			menuRadio.addToDialog( gridPosition )

	def addToMenu( self, repositoryMenu ):
		"Add this to the repository menu."
		if len( self.menuRadios ) < 1:
			print( 'The MenuButtonDisplay in settings should have menu items.' )
			print( self.name )
			return
		self.menu = Tkinter.Menu( repositoryMenu, tearoff = 0 )
		repositoryMenu.add_cascade( label = getTitleFromName( self.name ), menu = self.menu )
		self.setRadioVarToName( self.menuRadios[ 0 ].name )

	def addToMenuFrameable( self, repositoryMenu ):
		"Add this to the frameable repository menu."
		titleFromName = getTitleFromName( self.name )
		self.addToMenu( repositoryMenu )
		self.menu.add_command( label = 'Help', command = HelpPage().getOpenFromDocumentationSubName( self.repository.fileNameHelp + '#' + titleFromName ) )
		self.menu.add_separator()

	def getFromName( self, name, repository ):
		"Initialize."
		self.menuRadios = []
		self.name = name
		self.radioVar = None
		self.repository = repository
		repository.menuEntities.append( self )
		return self

	def removeMenus( self ):
		"Remove all menus."
		deleteMenuItems( self.menu )
		self.menuRadios = []

	def setRadioVarToName( self, name ):
		"Get the menu button."
		self.optionList = [ name ]
		self.radioVar = Tkinter.StringVar()
		self.radioVar.set( self.optionList[ 0 ] )

	def setToNameAddToDialog( self, name, gridPosition ):
		"Get the menu button."
		if self.radioVar != None:
			return
		gridPosition.increment()
		self.setRadioVarToName( name )
		self.label = Tkinter.Label( gridPosition.master, text = self.name )
		self.label.grid( row = gridPosition.row, column = 0, columnspan = 3, sticky = Tkinter.W )
		self.menuButton = Tkinter.OptionMenu( gridPosition.master, self.radioVar, self.optionList )
		self.menuButton.grid( row = gridPosition.row, column = 3, columnspan = 2, sticky = Tkinter.W )
		self.menuButton.menu = Tkinter.Menu( self.menuButton, tearoff = 0 )
		self.menu = self.menuButton.menu
		self.menuButton[ 'menu' ]  =  self.menu
		LabelHelp( self.repository.fileNameHelp, gridPosition.master, self.name, self.label )


class MenuRadio( BooleanSetting ):
	"A class to display, read & write a boolean with associated menu radio button."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		self.menuButtonDisplay.setToNameAddToDialog( self.name, gridPosition )
		self.addToSubmenu()

	def addToMenu( self, repositoryMenu ):
		"Add this to the submenu set by MenuButtonDisplay, the repository menu is ignored"
		self.addToSubmenu()

	def addToMenuFrameable( self, repositoryMenu ):
		"Add this to the frameable repository menu."
		self.addToMenu( repositoryMenu )

	def addToSubmenu( self ):
		"Add this to the submenu."
		self.activate = False
		menu = self.menuButtonDisplay.menu
		menu.add_radiobutton( label = self.name, command = self.clickRadio, value = self.name, variable = self.menuButtonDisplay.radioVar )
		self.menuLength = menu.index( Tkinter.END )
		if self.value:
			self.menuButtonDisplay.radioVar.set( self.name )
			self.invoke()
		self.activate = True

	def clickRadio( self ):
		"Workaround for Tkinter bug, invoke and set the value when clicked."
		if not self.activate:
			return
		self.menuButtonDisplay.radioVar.set( self.name )
		if self.updateFunction != None:
			self.updateFunction()

	def getFromMenuButtonDisplay( self, menuButtonDisplay, name, repository, value ):
		"Initialize."
		self.getFromValueOnlyAddToRepository( name, repository, value )
		self.menuButtonDisplay = menuButtonDisplay
		self.menuButtonDisplay.menuRadios.append( self )
		return self

	def invoke( self ):
		"Workaround for Tkinter bug, invoke to set the value when changed."
		self.menuButtonDisplay.menu.invoke( self.menuLength )

	def setStateToValue( self ):
		"Set the checkbutton to the boolean."
		try:
			if self.value:
				self.invoke()
		except:
			pass

	def setToDisplay( self ):
		"Set the boolean to the checkbutton."
		if self.menuButtonDisplay.radioVar != None:
			self.value = ( self.menuButtonDisplay.radioVar.get() == self.name )


class PluginFrame:
	"A class to list the profiles."
	def __init__( self ):
		"Set the radio."
		self.gridTable = {}
		self.latentStringVar = LatentStringVar()
		self.oldLatentString = ''

	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.gridPosition = gridPosition.getCopy()
		self.gridPosition.master = gridPosition.master
		self.createFrame( gridPosition )

	def createFrame( self, gridPosition ):
		"Create the frame."
		gridVertical = GridVertical( 0, 0 )
		gridVertical.master = Tkinter.LabelFrame( gridPosition.master, borderwidth = 3, relief = 'raised' )
		gridVertical.master.grid( row = gridPosition.row, column = gridPosition.column, columnspan = 10, sticky = Tkinter.E + Tkinter.W + Tkinter.N + Tkinter.S )
		gridPosition.master.grid_rowconfigure( gridPosition.row, weight = 1 )
		gridPosition.master.grid_columnconfigure( gridPosition.column + 9, weight = 1 )
		if self.latentStringVar.getString() == '':
			self.defaultRadioButton.setSelect()
		self.gridTable[ self.latentStringVar.getString() ] = gridVertical
		path = os.path.join( self.directoryPath, self.latentStringVar.getString() )
		pluginModule = gcodec.getModuleWithPath( path )
		if pluginModule == None:
			print( 'this should never happen, pluginModule in addToDialog in PluginFrame in settings is None' )
			print( path )
			return
		gridVertical.repository = getReadRepository( pluginModule.getNewRepository() )
		gridVertical.frameGridVertical = GridVertical( 0, 0 )
		gridVertical.frameGridVertical.setExecutablesRepository( gridVertical.repository )
		executeTitle = gridVertical.repository.executeTitle
		if executeTitle != None:
			executeButton = Tkinter.Button( gridVertical.master, activebackground = 'black', activeforeground = 'blue', text = executeTitle, command = gridVertical.frameGridVertical.execute )
			executeButton.grid( row = gridVertical.row, column = gridVertical.column )
			gridVertical.column += 1
		self.helpButton = Tkinter.Button( gridVertical.master, activebackground = 'black', activeforeground = 'white', text = "?", command = HelpPageRepository( gridVertical.repository ).openPage )
		self.helpButton.grid( row = gridVertical.row, column = gridVertical.column )
		addEmptyRow( gridVertical )
		gridVertical.increment()
		gridVertical.xScrollbar = HiddenScrollbar( gridVertical.master, orient = Tkinter.HORIZONTAL )
		gridVertical.xScrollbar.grid( row = gridVertical.row + 1, column = gridVertical.column, columnspan = 10, sticky = Tkinter.E + Tkinter.W )
		gridVertical.yScrollbar = HiddenScrollbar( gridVertical.master )
		gridVertical.yScrollbar.grid( row = gridVertical.row, column = gridVertical.column + 11, sticky = Tkinter.N + Tkinter.S )
		canvasHeight = min( 1000, gridPosition.master.winfo_screenheight() - 400 ) - 6 - int( gridVertical.xScrollbar[ 'width' ] )
		canvasWidth = min( 650, gridPosition.master.winfo_screenwidth() - 100 ) - 6 - int( gridVertical.yScrollbar[ 'width' ] )
		gridVertical.canvas = Tkinter.Canvas( gridVertical.master, height = canvasHeight, highlightthickness = 0, width = canvasWidth )
		gridVertical.frameGridVertical.master = Tkinter.Frame( gridVertical.canvas )
		for setting in gridVertical.repository.displayEntities:
			setting.addToDialog( gridVertical.frameGridVertical )
		gridVertical.frameGridVertical.master.update_idletasks()
		gridVertical.xScrollbar.config( command = gridVertical.canvas.xview )
		gridVertical.canvas[ 'xscrollcommand' ] = gridVertical.xScrollbar.set
		gridVertical.yScrollbar.config( command = gridVertical.canvas.yview )
		gridVertical.canvas[ 'yscrollcommand' ] = gridVertical.yScrollbar.set
		gridVertical.canvas.create_window( 0, 0, anchor = Tkinter.NW, window = gridVertical.frameGridVertical.master )
		gridVertical.canvas[ 'scrollregion' ] = gridVertical.frameGridVertical.master.grid_bbox()
		gridVertical.canvas.grid( row = gridVertical.row, column = gridVertical.column, columnspan = 10, sticky = Tkinter.E + Tkinter.W + Tkinter.N + Tkinter.S )
		gridVertical.master.grid_rowconfigure( gridVertical.row, weight = 1 )
		gridVertical.master.grid_columnconfigure( gridVertical.column + 9, weight = 1 )
		gridVertical.frameGridVertical.master.lift()
		self.oldLatentString = self.latentStringVar.getString()

	def getFromPath( self, defaultRadioButton, directoryPath, repository ):
		"Initialize."
		self.defaultRadioButton = defaultRadioButton
		self.directoryPath = directoryPath
		self.name = 'PluginFrame'
		self.repository = repository
		repository.archive.append( self )
		repository.displayEntities.append( self )
		return self

	def setStateToValue( self ):
		"Set the state of all the plugins to the value."
		for gridTableValue in self.gridTable.values():
			cancelRepository( gridTableValue.repository )

	def setToDisplay( self ):
		"Set the plugins to the display."
		pass

	def update( self ):
		"Update the frame."
		if self.oldLatentString == self.latentStringVar.getString():
			return
		self.oldLatentString = self.latentStringVar.getString()
		self.repository.archive.remove( self )
		for setting in self.repository.archive:
			setting.setToDisplay()
		writeSettingsPrintMessage( self.repository )
		self.repository.archive.append( self )
		if self.latentStringVar.getString() in self.gridTable:
			gridPosition = self.gridTable[ self.latentStringVar.getString() ]
			gridPosition.master.lift()
			gridPosition.frameGridVertical.master.focus_set()
			return
		self.createFrame( self.gridPosition )

	def writeToArchiveWriter( self, archiveWriter ):
		"Write tab separated name and value to the archive writer."
		gridTableKeys = self.gridTable.keys()
		gridTableKeys.sort()
		for gridTableKey in gridTableKeys:
			saveRepository( self.gridTable[ gridTableKey ].repository )


class ProfileList:
	"A class to list the profiles."
	def getFromName( self, name, repository ):
		"Initialize."
		self.craftTypeName = repository.lowerName
		self.name = name
		self.repository = repository
		self.setValueToFolders()
		return self

	def setValueToFolders( self ):
		"Set the value to the folders in the profiles directories."
		self.value = getFolders( getProfilesDirectoryPath( self.craftTypeName ) )
		defaultFolders = getFolders( getProfilesDirectoryInAboveDirectory( self.craftTypeName ) )
		for defaultFolder in defaultFolders:
			if defaultFolder not in self.value:
				self.value.append( defaultFolder )
		self.value.sort()


class ProfileListboxSetting( StringSetting ):
	"A class to handle the profile listbox."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
#http://www.pythonware.com/library/tkinter/introduction/x5453-patterns.htm
		self.root = gridPosition.master
		gridPosition.increment()
		scrollbar = HiddenScrollbar( gridPosition.master )
		self.listbox = Tkinter.Listbox( gridPosition.master, selectmode = Tkinter.SINGLE, yscrollcommand = scrollbar.set )
		self.listbox.bind( '<ButtonRelease-1>', self.buttonReleaseOne )
		gridPosition.master.bind( '<FocusIn>', self.focusIn )
		scrollbar.config( command = self.listbox.yview )
		self.listbox.grid( row = gridPosition.row, column = 0, sticky = Tkinter.N + Tkinter.S )
		scrollbar.grid( row = gridPosition.row, column = 1, sticky = Tkinter.N + Tkinter.S )
		self.setStateToValue()
		self.repository.saveListenerTable[ 'updateProfileSaveListeners' ] = updateProfileSaveListeners

	def buttonReleaseOne( self, event ):
		"Button one released."
		self.setValueToIndex( self.listbox.nearest( event.y ) )

	def focusIn( self, event ):
		"The root has gained focus."
		getReadRepository( self.repository )
		self.setStateToValue()

	def getFromListSetting( self, listSetting, name, repository, value ):
		"Initialize."
		self.getFromValueOnly( name, repository, value )
		self.listSetting = listSetting
		repository.archive.append( self )
		repository.displayEntities.append( self )
		return self

	def getSelectedFolder( self ):
		"Get the selected folder."
		settingProfileSubfolder = getSubfolderWithBasename( self.value, getProfilesDirectoryPath( self.listSetting.craftTypeName ) )
		if settingProfileSubfolder != None:
			return settingProfileSubfolder
		toolProfileSubfolder = getSubfolderWithBasename( self.value, getProfilesDirectoryInAboveDirectory( self.listSetting.craftTypeName ) )
		return toolProfileSubfolder

	def setStateToValue( self ):
		"Set the listbox items to the list setting."
		self.listbox.delete( 0, Tkinter.END )
		for item in self.listSetting.value:
			self.listbox.insert( Tkinter.END, item )
			if self.value == item:
				self.listbox.select_set( Tkinter.END )

	def setToDisplay( self ):
		"Set the selection value to the listbox selection."
		currentSelectionTuple = self.listbox.curselection()
		if len( currentSelectionTuple ) > 0:
			self.setValueToIndex( int( currentSelectionTuple[ 0 ] ) )

	def setValueToIndex( self, index ):
		"Set the selection value to the index."
		valueString = self.listbox.get( index )
		self.setValueToString( valueString )

	def setValueToString( self, valueString ):
		"Set the value to the value string."
		self.value = valueString
		if self.getSelectedFolder() == None:
			self.value = self.defaultValue
		if self.getSelectedFolder() == None:
			if len( self.listSetting.value ) > 0:
				self.value = self.listSetting.value[ 0 ]


class Radio( BooleanSetting ):
	"A class to display, read & write a boolean with associated radio button."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.createRadioButton( gridPosition )
		self.radiobutton.grid( row = gridPosition.row, column = 0, columnspan = 3, sticky = Tkinter.W )
		self.setStateToValue()

	def clickRadio( self ):
		"Workaround for Tkinter bug, set the value."
		self.latentStringVar.setString( self.radiobutton[ 'value' ] )
		if self.updateFunction != None:
			self.updateFunction()

	def createRadioButton( self, gridPosition ):
		"Create the radio button."
		self.radiobutton = Tkinter.Radiobutton( gridPosition.master, command = self.clickRadio, text = self.name, value = self.name, variable = self.latentStringVar.getVar() )
		LabelHelp( self.repository.fileNameHelp, gridPosition.master, self.name, self.radiobutton )

	def getFromRadio( self, latentStringVar, name, repository, value ):
		"Initialize."
		self.getFromValueOnly( name, repository, value )
		self.latentStringVar = latentStringVar
		repository.archive.append( self )
		repository.displayEntities.append( self )
#when addToMenu is added to this entity, the line below should be uncommented
#		repository.menuEntities.append( self )
		return self

	def setToDisplay( self ):
		"Set the boolean to the checkbutton."
		self.value = ( self.latentStringVar.getString() == self.radiobutton[ 'value' ] )

	def setSelect( self ):
		"Set the int var and select the radio button."
		self.latentStringVar.setString( self.radiobutton[ 'value' ] )
		self.radiobutton.select()

	def setStateToValue( self ):
		"Set the checkbutton to the boolean."
		if self.value:
			self.setSelect()


class RadioCapitalized( Radio ):
	"A class to display, read & write a boolean with associated radio button."
	def createRadioButton( self, gridPosition ):
		"Create the radio button."
		capitalizedName = getEachWordCapitalized( self.name )
		self.radiobutton = Tkinter.Radiobutton( gridPosition.master, command = self.clickRadio, text = capitalizedName, value = self.name, variable = self.latentStringVar.getVar() )


class RadioCapitalizedButton( Radio ):
	"A class to display, read & write a boolean with associated radio button."
	def createRadioButton( self, gridPosition ):
		"Create the radio button."
		capitalizedName = getEachWordCapitalized( self.name )
		self.radiobutton = Tkinter.Radiobutton( gridPosition.master, command = self.clickRadio, text = capitalizedName, value = self.name, variable = self.latentStringVar.getVar() )
		self.displayButton = Tkinter.Button( gridPosition.master, activebackground = 'black', activeforeground = 'white', text = capitalizedName, command = self.displayDialog )
		self.displayButton.grid( row = gridPosition.row, column = 3, columnspan = 2 )

	def displayDialog( self ):
		"Display function."
		ToolDialog().getFromPath( self.path ).display()
		self.setSelect()

	def getFromPath( self, latentStringVar, name, path, repository, value ):
		"Initialize."
		self.getFromRadio( latentStringVar, name, repository, value )
		self.path = path
		return self


class RadioPlugin( RadioCapitalized ):
	"A class to display, read & write a boolean with associated radio button."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		self.createRadioButton( gridPosition )
		self.radiobutton[ 'activebackground' ] = 'black'
		self.radiobutton[ 'activeforeground' ] = 'white'
		self.radiobutton[ 'selectcolor' ] = 'white'
		self.radiobutton[ 'borderwidth' ] = 3
		self.radiobutton[ 'indicatoron' ] = 0
		setButtonFontWeightString( self.radiobutton, self.important )
		self.incrementGridPosition( gridPosition )
		self.setStateToValue()

	def getFromRadio( self, important, latentStringVar, name, repository, value ):
		"Initialize."
		self.important = important
		return RadioCapitalized.getFromRadio( self, latentStringVar, name, repository, value )

	def incrementGridPosition( self, gridPosition ):
		"Increment the grid position."
		gridPosition.incrementGivenNumberOfColumns( 8 )
		self.radiobutton.grid( row = gridPosition.row, column = gridPosition.column, sticky = Tkinter.W )


class TextSetting( StringSetting ):
	"A class to display, read & write a text."
	def __init__( self ):
		"Set the update function to none."
		self.tokenConversions = [
			TokenConversion(),
			TokenConversion( 'carriageReturn', '\r' ),
			TokenConversion( 'doubleQuote', '"' ),
			TokenConversion( 'newline', '\n' ),
			TokenConversion( 'semicolon', ';' ),
			TokenConversion( 'singleQuote', "'" ),
			TokenConversion( 'tab', '\t' ) ]
		self.updateFunction = None

	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		gridPosition.increment()
		self.label = Tkinter.Label( gridPosition.master, text = self.name )
		self.label.grid( row = gridPosition.row, column = 0, columnspan = 3, sticky = Tkinter.W )
		gridPosition.increment()
		self.entry = Tkinter.Text( gridPosition.master )
		self.setStateToValue()
		self.entry.grid( row = gridPosition.row, column = 0, columnspan = 5, sticky = Tkinter.W )
		LabelHelp( self.repository.fileNameHelp, gridPosition.master, self.name, self.label )

	def getFromValue( self, name, repository, value ):
		"Initialize."
		self.getFromValueOnly( name, repository, value )
		repository.archive.append( self )
		repository.displayEntities.append( self )
		return self

	def setToDisplay( self ):
		"Set the string to the entry field."
		valueString = self.entry.get( 1.0, Tkinter.END )
		self.setValueToString( valueString )

	def setStateToValue( self ):
		"Set the entry to the value."
		try:
			self.entry.delete( 1.0, Tkinter.END )
			self.entry.insert( Tkinter.INSERT, self.value )
		except:
			pass

	def setValueToSplitLine( self, lineIndex, lines, splitLine ):
		"Set the value to the second word of a split line."
		replacedValue = splitLine[ 1 ]
		for tokenConversion in reversed( self.tokenConversions ):
			replacedValue = tokenConversion.getTokenizedString( replacedValue )
		self.setValueToString( replacedValue )

	def writeToArchiveWriter( self, archiveWriter ):
		"Write tab separated name and value to the archive writer."
		replacedValue = self.value
		for tokenConversion in self.tokenConversions:
			replacedValue = tokenConversion.getNamedString( replacedValue )
		archiveWriter.write( '%s%s%s\n' % ( self.name, globalSpreadsheetSeparator, replacedValue ) )


class TokenConversion:
	"A class to convert tokens in a string."
	def __init__( self, name = 'replaceToken', token = '___replaced___' ):
		"Set the name and token."
		self.replacedName = '___replaced___' + name
		self.token = token

	def getNamedString( self, text ):
		"Get a string with the tokens changed to names."
		return text.replace( self.token, self.replacedName )

	def getTokenizedString( self, text ):
		"Get a string with the names changed to tokens."
		return text.replace( self.replacedName, self.token )


class ToolDialog:
	"A class to display the tool repository dialog."
	def addPluginToMenu( self, menu, path ):
		"Add the display command to the menu."
		name = os.path.basename( path )
		self.path = path
		menu.add_command( label = getEachWordCapitalized( name ) + '...', command = self.display )

	def display( self ):
		"Display the tool repository dialog."
		global globalRepositoryDialogListTable
		for repositoryDialog in globalRepositoryDialogListTable:
			if getPathFromFileNameHelp( repositoryDialog.repository.fileNameHelp ) == self.path:
				liftRepositoryDialogs( globalRepositoryDialogListTable[ repositoryDialog ] )
				return
		self.repositoryDialog = getDisplayedDialogFromPath( self.path )

	def getFromPath( self, path ):
		"Initialize and return display function."
		self.path = path
		return self


class WindowPosition( StringSetting ):
	"A class to display, read & write a window position."
	def addToDialog( self, gridPosition ):
		"Set the root to later get the geometry."
		self.root = gridPosition.master
		self.setToDisplay()

	def getFromValue( self, repository, value ):
		"Initialize."
		self.getFromValueOnly( 'WindowPosition', repository, value )
		repository.archive.append( self )
		repository.displayEntities.append( self )
		return self

	def setToDisplay( self ):
		"Set the string to the window position."
		try:
			geometryString = self.root.geometry()
		except:
			return
		if geometryString == '1x1+0+0':
			return
		firstPlusIndexPlusOne = geometryString.find( '+' ) + 1
		self.value = geometryString[ firstPlusIndexPlusOne : ]

	def setWindowPosition( self ):
		"Set the window position."
		movedGeometryString = '%sx%s+%s' % ( self.root.winfo_reqwidth(), self.root.winfo_reqheight(), self.value )
		self.root.geometry( movedGeometryString )


class WindowVisibilities:
	"A class to read & write window visibilities and display them."
	def addToDialog( self, gridPosition ):
		"Add this to the dialog."
		if self.repository.repositoryDialog == None:
			self.isActive = False
			return
		self.isActive = self.repository.repositoryDialog.isFirst
		if self.isActive:
			self.repository.repositoryDialog.openDialogListeners.append( self )

	def getFromRepository( self, repository ):
		"Initialize."
		self.isActive = False
		self.name = 'WindowVisibilities'
		self.repository = repository
		repository.archive.append( self )
		repository.displayEntities.append( self )
		self.value = []
		return self

	def openDialog( self ):
		"Create the display button."
		for item in self.value:
			getDisplayedDialogFromPath( item )

	def setToDisplay( self ):
		"Set the string to the window position."
		if not self.isActive:
			return
		self.value = []
		ownPath = getPathFromFileNameHelp( self.repository.fileNameHelp )
		for repositoryDialog in globalRepositoryDialogListTable.keys():
			keyPath = getPathFromFileNameHelp( repositoryDialog.repository.fileNameHelp )
			if keyPath != ownPath:
				if keyPath not in self.value:
					self.value.append( keyPath )

	def setStateToValue( self ):
		"Do nothing because the window visibility is not to be cancelled."
		pass

	def setValueToSplitLine( self, lineIndex, lines, splitLine ):
		"Set the value to the second and later words of a split line."
		self.value = splitLine[ 1 : ]

	def writeToArchiveWriter( self, archiveWriter ):
		"Write tab separated name and list to the archive writer."
		writeValueListToArchiveWriter( archiveWriter, self )


class RepositoryDialog:
	def __init__( self, repository, root ):
		"Add entities to the dialog."
		self.isFirst = ( len( globalRepositoryDialogListTable.keys() ) == 0 )
		self.closeListener = CloseListener( self )
		self.repository = repository
		self.gridPosition = GridVertical( 0, - 1 )
		self.gridPosition.setExecutablesRepository( repository )
		self.gridPosition.master = root
		self.root = root
		self.openDialogListeners = []
		repository.repositoryDialog = self
		root.withdraw()
		title = repository.title
		if repository.fileNameInput != None:
			title = os.path.basename( repository.fileNameInput.value ) + ' - ' + title
		root.title( title )
		fileHelpMenuBar = FileHelpMenuBar( root )
		fileHelpMenuBar.completeMenu( self.close, repository, self.save, self )
		for setting in repository.displayEntities:
			setting.addToDialog( self.gridPosition )
		if self.gridPosition.row < 20:
			addEmptyRow( self.gridPosition )
		self.addButtons( repository, root )
		root.update_idletasks()
		self.setWindowPositionDeiconify()
		root.deiconify()
		for openDialogListener in self.openDialogListeners:
			openDialogListener.openDialog()

	def __repr__( self ):
		"Get the string representation of this RepositoryDialog."
		return self.repository.title

	def addButtons( self, repository, root ):
		"Add buttons to the dialog."
		columnIndex = 0
		self.gridPosition.increment()
		saveCommand = self.save
		saveText = 'Save'
		if self.isFirst:
			saveCommand = self.saveAll
			saveText = 'Save All'
		if repository.executeTitle != None:
			executeButton = Tkinter.Button( root, activebackground = 'black', activeforeground = 'blue', text = repository.executeTitle, command = self.gridPosition.execute )
			executeButton.grid( row = self.gridPosition.row, column = columnIndex )
			columnIndex += 1
		self.helpButton = Tkinter.Button( root, activebackground = 'black', activeforeground = 'white', text = "?", command = HelpPageRepository( self.repository ).openPage )
		self.helpButton.grid( row = self.gridPosition.row, column = columnIndex )
		self.closeListener.listenToWidget( self.helpButton )
		columnIndex += 5
		cancelButton = Tkinter.Button( root, activebackground = 'black', activeforeground = 'orange', command = self.cancel, fg = 'orange', text = 'Cancel' )
		cancelButton.grid( row = self.gridPosition.row, column = columnIndex )
		columnIndex += 1
		self.saveButton = Tkinter.Button( root, activebackground = 'black', activeforeground = 'darkgreen', command = saveCommand, fg = 'darkgreen', text = saveText )
		self.saveButton.grid( row = self.gridPosition.row, column = columnIndex )

	def cancel( self, event = None ):
		"Set all entities to their saved state."
		cancelRepository( self.repository )

	def close( self, event = None ):
		"The dialog was closed."
		try:
			self.root.destroy()
		except:
			pass

	def save( self, event = None ):
		"Set the entities to the dialog then write them."
		saveRepository( self.repository )

	def saveAll( self ):
		"Save all the dialogs."
		global globalRepositoryDialogListTable
		globalRepositoryDialogValues = euclidean.getListTableElements( globalRepositoryDialogListTable )
		for globalRepositoryDialogValue in globalRepositoryDialogValues:
			globalRepositoryDialogValue.save()

	def setWindowPositionDeiconify( self ):
		"Set the window position if that setting exists."
		for setting in self.repository.archive:
			if setting.name == 'WindowPosition':
				setting.setWindowPosition()
				return