Newer
Older
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
# scroll for it.
if codebox:
bottomScrollbar.pack(side=BOTTOM, fill=X)
rightScrollbar.pack(side=RIGHT, fill=Y)
textbox.pack(side=LEFT, fill=BOTH, expand=YES)
# ---------- put a message widget in the message frame-------------------
messageWidget = Message(messageFrame, anchor=NW, text=message, width=int(root_width * 0.9))
messageWidget.configure(font=(DEFAULT_FONT_FAMILY,DEFAULT_FONT_SIZE))
messageWidget.pack(side=LEFT, expand=YES, fill=BOTH, padx='1m', pady='1m')
# put the buttons in the buttonsFrame
okButton = Button(buttonsFrame, takefocus=YES, text="OK", height=1, width=6)
okButton.pack(expand=NO, side=TOP, padx='2m', pady='1m', ipady="1m", ipadx="2m")
okButton.bind("<Return>" , __textboxOK)
okButton.bind("<Button-1>", __textboxOK)
okButton.bind("<Escape>" , __textboxOK)
# ----------------- the action begins ----------------------------------------
try:
# load the text into the textbox
if type(text) == type("abc"): pass
else:
try:
text = "".join(text) # convert a list or a tuple to a string
except:
msgbox("Exception when trying to convert "+ str(type(text)) + " to text in textbox")
sys.exit(16)
textbox.insert(END,text, "normal")
# disable the textbox, so the text cannot be edited
textbox.configure(state=DISABLED)
except:
msgbox("Exception when trying to load the textbox.")
sys.exit(16)
try:
okButton.focus_force()
except:
msgbox("Exception when trying to put focus on okButton.")
sys.exit(16)
root.mainloop()
root.destroy()
return __replyButtonText
def __textboxOK(event):
global root
root.quit()
#-------------------------------------------------------------------
# diropenbox
#-------------------------------------------------------------------
def diropenbox(msg=None, title=None, argInitialDir=None):
"""A dialog to get a directory name.
Note that the msg argument, if specified, is ignored.
Returns the name of a directory, or None if user chose to cancel.
If an initial directory is specified in argument 3,
and that directory exists, then the
dialog box will start with that directory.
"""
root = Tk()
root.withdraw()
if argInitialDir == None:
f = tkFileDialog.askdirectory(parent=root, title=title)
else:
f = tkFileDialog.askdirectory(parent=root, title=title, initialdir=argInitialDir)
if f == "": return None
return f
#-------------------------------------------------------------------
# fileopenbox
#-------------------------------------------------------------------
def fileopenbox(msg=None, title=None, argInitialFile=None):
"""A dialog to get a file name.
Returns the name of a file, or None if user chose to cancel.
if argInitialFile contains a valid filename, the dialog will
be positioned at that file when it appears.
"""
root = Tk()
root.withdraw()
f = tkFileDialog.askopenfilename(parent=root,title=title, initialfile=argInitialFile)
if f == "": return None
return f
#-------------------------------------------------------------------
# filesavebox
#-------------------------------------------------------------------
def filesavebox(msg=None, title=None, argInitialFile=None):
"""A file to get the name of a file to save.
Returns the name of a file, or None if user chose to cancel.
if argInitialFile contains a valid filename, the dialog will
be positioned at that file when it appears.
"""
root = Tk()
root.withdraw()
f = tkFileDialog.asksaveasfilename(parent=root, title=title, initialfile=argInitialFile)
if f == "": return None
return f
#-------------------------------------------------------------------
# utility routines
#-------------------------------------------------------------------
# These routines are used by several other functions in the EasyGui module.
def __buttonEvent(event):
"""Handle an event that is generated by a person clicking a button.
"""
global root, __widgetTexts, __replyButtonText
__replyButtonText = __widgetTexts[event.widget]
root.quit() # quit the main loop
def __put_buttons_in_buttonframe(choices):
"""Put the buttons in the buttons frame
"""
global __widgetTexts, __firstWidget, buttonsFrame
__widgetTexts = {}
i = 0
for buttonText in choices:
tempButton = Button(buttonsFrame, takefocus=1, text=buttonText)
tempButton.pack(expand=YES, side=LEFT, padx='1m', pady='1m', ipadx='2m', ipady='1m')
# remember the text associated with this widget
__widgetTexts[tempButton] = buttonText
# remember the first widget, so we can put the focus there
if i == 0:
__firstWidget = tempButton
i = 1
# bind the keyboard events to the widget
tempButton.bind("<Return>", __buttonEvent)
tempButton.bind("<Button-1>", __buttonEvent)
#-------------------------------------------------------------------
# test driver code
#-------------------------------------------------------------------
def _test():
# simple way to clear the console
print "\n" * 100
# START DEMONSTRATION DATA ===================================================
choices_abc = ["This is choice 1", "And this is choice 2"]
message = "Pick one! This is a huge choice, and you've got to make the right one " \
"or you will surely mess up the rest of your life, and the lives of your " \
"friends and neighbors!"
title = ""
# ============================= define a code snippet =========================
code_snippet = ("dafsdfa dasflkj pp[oadsij asdfp;ij asdfpjkop asdfpok asdfpok asdfpok"*3) +"\n"+\
"""# here is some dummy Python code
for someItem in myListOfStuff:
do something(someItem)
do something()
do something()
if somethingElse(someItem):
doSomethingEvenMoreInteresting()
"""*16
#======================== end of code snippet ==============================
#================================= some text ===========================
text_snippet = ((\
"""It was the best of times, and it was the worst of times. The rich ate cake, and the poor had cake recommended to them, but wished only for enough cash to buy bread. The time was ripe for revolution! """ \
*5)+"\n\n")*10
#===========================end of text ================================
intro_message = ("Pick the kind of box that you wish to demo.\n\n"
+ "In EasyGui, all GUI interactions are invoked by simple function calls.\n\n" +
"EasyGui is different from other GUIs in that it is NOT event-driven. It allows" +
" you to program in a traditional linear fashion, and to put up dialogs for simple" +
" input and output when you need to. If you are new to the event-driven paradigm" +
" for GUIs, EasyGui will allow you to be productive with very basic tasks" +
" immediately. Later, if you wish to make the transition to an event-driven GUI" +
" paradigm, you can move to an event-driven style with a more powerful GUI package" +
"such as anygui, PythonCard, Tkinter, wxPython, etc."
+ "\n\nEasyGui is running Tk version: " + str(TkVersion)
)
#========================================== END DEMONSTRATION DATA
while 1: # do forever
choices = [
"msgbox",
"buttonbox",
"choicebox",
"multchoicebox",
"textbox",
"ynbox",
"ccbox",
"enterbox",
"codebox",
"integerbox",
"boolbox",
"indexbox",
"filesavebox",
"fileopenbox",
"passwordbox",
"multenterbox",
"multpasswordbox",
"diropenbox"
]
choice = choicebox(intro_message, "EasyGui " + EasyGuiRevisionInfo, choices)
if choice == None: return
reply = choice.split()
if reply[0] == "msgbox":
reply = msgbox("short message", "This is a long title")
print "Reply was:", reply
elif reply[0] == "buttonbox":
reply = buttonbox()
print "Reply was:", reply
reply = buttonbox(message, "Demo of Buttonbox with many, many buttons!", choices)
print "Reply was:", reply
elif reply[0] == "boolbox":
reply = boolbox()
print "Reply was:", reply
elif reply[0] == "integerbox":
reply = integerbox(
"Enter a number between 3 and 333",
"Demo: integerbox WITH a default value",
222, 3, 333)
print "Reply was:", reply
reply = integerbox(
"Enter a number between 0 and 99",
"Demo: integerbox WITHOUT a default value"
)
print "Reply was:", reply
elif reply[0] == "diropenbox":
title = "Demo of diropenbox"
msg = "This is a test of the diropenbox.\n\nPick the directory that you wish to open."
d = diropenbox(msg, title)
print "You chose directory...:", d
elif reply[0] == "fileopenbox":
f = fileopenbox()
print "You chose to open file:", f
elif reply[0] == "filesavebox":
f = filesavebox()
print "You chose to save file:", f
elif reply[0] == "indexbox":
title = reply[0]
msg = "Demo of " + reply[0]
choices = ["Choice1", "Choice2", "Choice3", "Choice4"]
reply = indexbox(msg, title, choices)
print "Reply was:", reply
elif reply[0] == "passwordbox":
reply = passwordbox("Demo of password box WITHOUT default"
+ "\n\nEnter your secret password", "Member Logon")
print "Reply was:", str(reply)
reply = passwordbox("Demo of password box WITH default"
+ "\n\nEnter your secret password", "Member Logon", "alfie")
print "Reply was:", str(reply)
elif reply[0] == "enterbox":
reply = enterbox("Enter the name of your best friend:", "Love!", "Suzy Smith")
print "Reply was:", str(reply)
reply = enterbox("Enter the name of your worst enemy:", "Hate!")
print "Reply was:", str(reply)
elif reply[0] == "multenterbox":
msg = "Enter your personal information"
title = "Credit Card Application"
fieldNames = ["Name","Street Address","City","State","ZipCode"]
fieldValues = [] # we start with blanks for the values
fieldValues = multenterbox(msg,title, fieldNames)
# make sure that none of the fields was left blank
while 1:
if fieldValues == None: break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues[i].strip() == "":
errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
if errmsg == "": break # no problems found
fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)
print "Reply was:", fieldValues
elif reply[0] == "multpasswordbox":
msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["Server ID", "User ID", "Password"]
fieldValues = [] # we start with blanks for the values
fieldValues = multpasswordbox(msg,title, fieldNames)
# make sure that none of the fields was left blank
while 1:
if fieldValues == None: break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues[i].strip() == "":
errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
if errmsg == "": break # no problems found
fieldValues = multpasswordbox(errmsg, title, fieldNames, fieldValues)
print "Reply was:", fieldValues
elif reply[0] == "ynbox":
reply = ynbox(message, title)
print "Reply was:", reply
elif reply[0] == "ccbox":
reply = ccbox(message)
print "Reply was:", reply
elif reply[0] == "choicebox":
longchoice = "This is an example of a very long option which you may or may not wish to choose."*2
listChoices = ["nnn", "ddd", "eee", "fff", "aaa", longchoice
, "aaa", "bbb", "ccc", "ggg", "hhh", "iii", "jjj", "kkk", "LLL", "mmm" , "nnn", "ooo", "ppp", "qqq", "rrr", "sss", "ttt", "uuu", "vvv"]
message = "Pick something. " + ("A wrapable sentence of text ?! "*30) + "\nA separate line of text."*6
reply = choicebox(message, None, listChoices)
print "Reply was:", reply
message = "Pick something. "
reply = choicebox(message, None, listChoices)
print "Reply was:", reply
message = "Pick something. "
reply = choicebox("The list of choices is empty!", None, [])
print "Reply was:", reply
elif reply[0] == "multchoicebox":
listChoices = ["aaa", "bbb", "ccc", "ggg", "hhh", "iii", "jjj", "kkk"
, "LLL", "mmm" , "nnn", "ooo", "ppp", "qqq"
, "rrr", "sss", "ttt", "uuu", "vvv"]
message = "Pick as many choices as you wish."
reply = multchoicebox(message,"DEMO OF multchoicebox", listChoices)
print "Reply was:", reply
elif reply[0] == "textbox":
message = "Here is some sample text. " * 16
reply = textbox(message, "Text Sample", text_snippet)
print "Reply was:", reply
elif reply[0] == "codebox":
message = "Here is some sample code. " * 16
reply = codebox(message, "Code Sample", code_snippet)
print "Reply was:", reply
else:
msgbox("Choice\n\n" + choice + "\n\nis not recognized", "Program Logic Error")
return
if __name__ == '__main__':
args = []
title = "TOPS Software Installer"
message1 = """SciDAC TOPS Software Installer"""
message2 = """The DOE Mathematics SciDAC TOPS ISIC develops software for the
scalable solution of optimizations, eigenvalues and algebraic systems. More
information on TOPS may be found at http://www.tops-scidac.org. \n\n
The software installed is covered by a variety of licenses, please refer to
each package's license information before redistributing it. This installer
can also install additional packages that are used by the TOPS packages."""
result = buttonbox(message=message1, title="TOPS Software Installer", choices = ["Cancel", "Continue"],fontSize = 20,message2=message2)
if result == "Cancel": sys.exit()
result = buttonbox(message='This preview version of the installer uses\nthe nightly snapshot of the development\nversion of PETSc.\n\nShould you encounter problems please send email\nto petsc-maint@mcs.anl.gov with all output\n', title="TOPS Software Installer", choices = ["Cancel", "Continue"])
if result == "Cancel": sys.exit()
options = []
packages = ["hypre (parallel preconditioners)","SuperLU_dist (parallel sparse direct solver)", "SuperLU","Sundials (parallel ODE integrators)"]
reply = multchoicebox("Pick the optional TOPS packages to install. PETSc will \nalways be installed. \n\nNote: many of these packages are not portable\nfor all machines, hence select only the packages you truly need.",title, packages)
for i in reply:
i = i.lower().replace(' ','')
f = i.find('(')
if f > 0: i = i[0:f]
args.append('--download-'+i+'=1')
packages = ["Spooles (parallel sparse direct solvers)"," DSCPack"," MUMPS","Parmetis (parallel partitioning)"," Chaco"," Jostle"," Party"," Scotch","Prometheus (parallel preconditioner)"," Blocksolve95"," ml"," SPAI","Matlab"]
reply = multchoicebox("Pick the other packages to install.\n\nAgain, only select the packages you truly need.",title, packages)
for i in reply:
i = i.lower().replace(' ','')
f = i.find('(')
if f > 0: i = i[0:f]
args.append('--download-'+i+'=1')
reply = indexbox('Compiler to use for PETSc?',title,['C','C++'])
if reply == 1: args.append( '--with-clanguage=c++')
reply = ynbox('Compile libraries so they may be used from Fortran?',title)
if reply: args.append( '--with-fortran=1')
else: args.append('--with-fc=0')
reply = ynbox('Compile libraries so they may be used from Python?',title)
if reply:
args.append( '--with-python=1')
reply = indexbox('Compilers to use?',title,['Any','GNU','non-GNU',"I'll indicate the compilers"])
if reply == 1: args.append( '--with-vendor-compilers=0')
elif reply == 2: args.append('--with-gnu-compilers=0')
if reply == 3:
reply = fileopenbox("Location of C compiler","Location of C compiler")
args.append('--with-cc='+reply)
if '--with-clanguage=c++' in args:
reply = fileopenbox("Location of C++ compiler","Location of C++ compiler")
args.append('--with-cxx='+reply)
if '--with-fortran=1' in args:
reply = fileopenbox("Location of Fortran compiler","Location of Fortran compiler")
args.append('--with-fc='+reply)
reply = ynbox('Compile debug versions of libraries? Recommended for all development.',title)
if not reply: args.append('--with-debugging=0')
reply = indexbox('Which version of BLAS and LAPACK do you wish to use?',title,['Have installer locate it', 'Install it',"I'll indicate its location"])
if reply == 1:
if '--with-fortran=1' in args: args.append('--download-f-blas-lapack')
else: args.append('--download-c-blas-lapack')
elif reply == 2:
reply = diropenbox("Directory of BLAS and LAPACK libraries","Directory of BLAS and LAPACK libraries")
if not reply: sys.exit()
args.append('--with-blas-lapack-dir='+reply)
reply = indexbox('Which version of MPI do you wish to use?',title,['Have installer locate it', 'Install MPICH-2','Install LAM','None',"I'll indicate its location"])
if reply == 3: args.append( '--with-mpi=0')
elif reply == 1: args.append('--download-mpich=1')
elif reply == 2: args.append('--download-lam=1')
elif reply == 4:
reply = diropenbox("Directory of MPI installation","Directory of MPI installation")
if not reply: sys.exit()
args.append('--with-mpi-dir='+reply)
reply = buttonbox('Install TOPS Solver Components?',title,['Yes','No'],message2="You must have CCAFE and BABEL\n already installed to use them.")
if reply == 'Yes':
reply = diropenbox("Directory of Babel","Directory of Babel")
if not reply: sys.exit()
args.append('--with-babel-dir='+reply)
reply = diropenbox("Directory of CCafe","Directory of CCAFE")
if not reply: sys.exit()
args.append('--with-ccafe-dir='+reply)
reply = ynbox('Do MPI jobs need to be submitted with a batch system?',title)
if reply: args.append('--with-batch=1')
arch = ''
while not arch:
arch = enterbox("Name of this configuration",title)
args.append('-PETSC_ARCH='+arch)
reply = diropenbox("Location to compile and install packages","Location to compile and install packages")
if not reply: sys.exit()
import os.path
import sys
petscroot = os.path.join(reply,'petsc-dev')
if not os.path.isfile(os.path.join(petscroot,'include','petsc.h')):
y = ynbox('Could not locate PETSc directory, should I download it?',title)
if not y: sys.exit()
# download PETSc
import urllib
try:
urllib.urlretrieve('ftp://info.mcs.anl.gov/pub/petsc/petsc-dev.tar.gz', os.path.join(reply,'petsc.tar.gz'))
except Exception, e:
raise RuntimeError('Unable to download PETSc')
import commands
try:
commands.getoutput('cd '+reply+'; gunzip petsc.tar.gz ; tar xf petsc.tar')
except RuntimeError, e:
raise RuntimeError('Error unzipping petsc.tar.gz'+str(e))
os.unlink(os.path.join(reply, 'petsc.tar'))
args.append('--with-shared=1')
args.append('--with-dynamic=1')
args.append('--with-external-packages-dir='+reply)
args = multenterbox("Configure options you have selected.", title, None, args)
if not args: sys.exit()
configfile=os.path.join(petscroot,'config-'+arch+'.py')
f = file(configfile, 'w')
f.write('#!/usr/bin/env python\n')
f.write('if __name__ == \'__main__\':\n')
f.write(' import sys\n')
f.write(' sys.path.insert(0, "'+os.path.join(petscroot,'config')+'")\n')
f.write(' import configure\n')
f.write(' configure_options = '+repr(args)+'\n')
f.write(' configure.petsc_configure(configure_options)\n')
f.close()
os.chmod(configfile,0755)
msgbox('After hitting OK run\n\n cd '+petscroot+'\npython config-'+arch+'.py\n\nto continue the install')