-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgalahad_gui.py
executable file
·6770 lines (5650 loc) · 265 KB
/
galahad_gui.py
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
#!/usr/bin/python2 -uO
# TkGalahad class
# A python/Tk windowing environment for GALAHAD
# Nick Gould, January 2004
# for GALAHAD productions 2002-2004
from Tkinter import *
import os
import tkFont
import re
import sys
import threading
# set colours
Black = "#%02x%02x%02x" % ( 0, 0, 0 )
White = "#%02x%02x%02x" % ( 255, 255, 255 )
Red = "#%02x%02x%02x" % ( 255, 0, 0 )
Green = "#%02x%02x%02x" % ( 0, 255, 0 )
Blue = "#%02x%02x%02x" % ( 0, 0, 255 )
Yellow = "#%02x%02x%02x" % ( 255, 255, 0 )
Gold = "#%02x%02x%02x" % ( 255, 215, 0 )
DarkGreen = "#%02x%02x%02x" % ( 0, 100, 0 )
Brown = "#%02x%02x%02x" % ( 165, 42, 42 )
Wheat = "#%02x%02x%02x" % ( 245, 222, 179 )
Grey80 = "#%02x%02x%02x" % ( 204, 204, 204 )
Grey90 = "#%02x%02x%02x" % ( 229, 229, 229 )
Purple = "#%02x%02x%02x" % ( 160, 32, 240 )
# select fixed colours
logobackground = White
logoforeground = Blue
warningbackground = White
warningforeground = Red
# text for help windows
helpcommandstext = "LEFT BUTTONS\n \
\nCD: change current directory \
\nREFRESH: refresh list of .SIF files displayed from current directory \
\nSPEC: set package specification options via a form \
\nPACKAGE: select which GALAHAD package & architecture to use \
\nSOLVE: decode current problem and then solve using selected GALAHAD package \
\nRESOLVE: run selected GALAHAD package on the currently decoded problem \
\nSOLUTION: display the solution file SOLUTION.d from the last run \
\nSUMMARY: display the summary file SUMMARY.d from the last run \
\nSTOP: stop the current galahad run \
\nEXIT: terminate the session\n \
\nMOUSE BUTTONS\n \
\nLEFT SINGLE CLICK: focus on problem under cursor \
\nLEFT DOUBLE CLICK: edit problem under cursor \
\nMIDDLE SINGLE CLICK: decode problem under cursor and run selected \
GALAHAD package \
\nRIGHT CLICK: decode problem under cursor, print problem info, \
and run selected GALAHAD package"
# \nMIDDLE DOUBLE CLICK: decode problem under cursor, print problem info, \
#and run GALAHAD\
# \nMIDDLE TRIPLE CLICK: decode problem under cursor in debug mode, \
#and run GALAHAD\
helpabouttext = "A GALAHAD windowing environment written in python/Tk \n \
\n GALAHAD copyright GALAHAD Productions 2002-2004 \
\n http://galahad.rl.ac.uk/galahad-www"
helptext = helpcommandstext + "\n \n" + helpabouttext
# text for help window
preftext = "There are no preferences to set at present"
##############################################################################
# TkGalahad class #
##############################################################################
#class TkGalahad( Frame ):
class TkGalahad:
' TkGalahad class definition (GALAHAD productions 2002-2004)'
instancesopen = 0
def __init__( self ):
# next line should work (but doesn't)
# def __init__( self, master=None ):
# Frame.__init__( self, master, class_="TkGalahad" )
# initial values
self.dir = os.getcwd( )
self.dotsif = re.compile( r'.SIF$' )
self.threads =[ ]
self.specwindowopen = 0
self.helpwindowopen = 0
self.advicewindowopen = 0
self.helpaboutwindowopen = 0
self.helpcommandswindowopen = 0
self.prefwindowopen = 0
self.cdmenuwindowopen = 0
self.selectwindowopen = 0
self.lanbspec_used = 'no'
self.filtranespec_used = 'no'
self.qpaspec_used = 'no'
self.qpbspec_used = 'no'
self.lsqpspec_used = 'no'
#######################
# Root window setup #
#######################
self.root = Tk( )
# titles and positions
self.root.title( 'GALAHAD tool' )
self.root.iconname( 'galahad' )
self.root.minsize( width = '1', height='1' )
self.root.geometry( '+68+10' )
# select default package
self.var_package = StringVar( )
self.var_package.set( 'lanb' )
# self.var_package.set( 'filt' )
# self.var_package.set( 'qpa' )
# self.var_package.set( 'qpb' )
self.var_package_label = StringVar( )
if self.var_package.get( ) == 'lanb' :
self.var_package_label.set( "LANCELOT B" )
elif self.var_package.get( ) == 'filt' :
self.var_package_label.set( "FILTRANE" )
elif self.var_package.get( ) == 'qpb' :
self.var_package_label.set( "QPB / LSQP" )
elif self.var_package.get( ) == 'qpa' :
self.var_package_label.set( "QPA" )
else : self.var_package_label.set( "" )
# select default fonts
self.normalfont = tkFont.Font( family="Helvetica",size=9, weight="bold" )
self.bigfont = tkFont.Font( family="Helvetica",size=24 )
self.helpfont = tkFont.Font( family="Helvetica",size=14 )
# set default option values
self.root.option_add( "*Font", self.normalfont )
self.root.option_add( "*Foreground", Gold )
self.root.option_add( "*Background", DarkGreen )
self.root.option_add( "*activeForeground", DarkGreen )
self.root.option_add( "*activeBackground", Yellow )
self.root.option_add( "*selectColor", Grey90 )
self.root.option_add( "*selectForeground", Grey90 )
self.root.option_add( "*selectBackground", Black )
self.root.option_add( "*highlightColor", Gold )
self.root.option_add( "*highlightBackground", Gold )
self.root.option_add( "*disabledForeground", Grey90 )
self.root.option_add( "*insertBackground", Grey90 )
self.root.option_add( "*troughColor", DarkGreen )
# listbox defaults
self.root.option_add( "*Listbox*Foreground", Black )
self.root.option_add( "*Listbox*Background", Grey90 )
# button defaults
self.root.option_add( "*Button*Foreground", White )
self.root.option_add( "*Button*Background", Red )
self.root.option_add( "*Button*activeForeground", Black )
self.root.option_add( "*Button*activeBackground", Green )
# entry defaults
self.root.option_add( "*Entry*Foreground", Gold )
self.root.option_add( "*Entry*Background", Brown )
self.root.option_add( "*Entry*highlightBackground", DarkGreen )
self.root.option_add( "*Entry*insertBackground", Brown )
# menu defaults
self.root.option_add( "*Menu*Foreground", Black )
self.root.option_add( "*Menu*Background", Grey90 )
self.root.option_add( "*Menu*activeForeground", Black )
self.root.option_add( "*Menu*activeBackground", Grey80 )
# scrollbar defaults
self.root.option_add( "*Scrollbar*Background", Grey90 )
self.root.option_add( "*Scrollbar*activeBackground", Grey80 )
# checkbutton defaults
self.root.option_add( "*Checkbutton*selectColor", Purple )
self.root.option_add( "*Checkbutton*selectForeground", DarkGreen )
self.root.option_add( "*Checkbutton*selectBackground", Gold )
self.root.option_add( "*Checkbutton*activeForeground", DarkGreen )
self.root.option_add( "*Checkbutton*activeBackground", Gold )
# radiobutton defaults
self.root.option_add( "*Radiobutton*selectColor", Purple )
self.root.option_add( "*Radiobutton*selectForeground", DarkGreen )
self.root.option_add( "*Radiobutton*selectBackground", Gold )
self.root.option_add( "*Radiobutton*activeForeground", DarkGreen )
self.root.option_add( "*Radiobutton*activeBackground", Gold )
# cd window defaults
self.root.option_add( "*cdwindow*Foreground", White )
self.root.option_add( "*cdwindow*Background", Red )
self.root.option_add( "*cdwindowEntry*Foreground", Black )
self.root.option_add( "*cdwindowEntry*Background", White )
self.root.option_add( "*cdwindowButton*Foreground", White )
self.root.option_add( "*cdwindowButton*Background", Red )
self.root.option_add( "*cdwindowButton*activeForeground", Black )
self.root.option_add( "*cdwindowButton*activeBackground", Green )
# check for installed galahad
self.frame = Frame( self.root )
self.logo = Text( self.frame, borderwidth=1, pady=3, padx=10,
width=9, height=2, font=self.bigfont,
# background=logoforeground,
# foreground=logobackground,
)
self.logo.insert( END, "GALAHAD\nstarting..." )
self.logo.pack( side=LEFT )
self.frame.pack( fill=BOTH, side=TOP, expand=1 )
self.galahad = os.environ.get("GALAHAD")
if self.galahad == None :
print "GALAHAD environment variable not set"
self.advicetext = "GALAHAD environment variable is not set"
self.advice( )
return
if os.path.exists( self.galahad ) == 1 :
self.architecture = os.listdir( self.galahad+"/makefiles" )
self.architecture.sort( )
self.var_arch = StringVar( )
self.var_arch.set( self.architecture[0] )
else :
print "GALAHAD environment does not appear to be present"
self.advicetext = "GALAHAD does not appear to be installed"
self.advice( )
return
self.galahadpython = os.environ.get("GALAHADPYTHON")
if self.galahadpython == None :
print "GALAHADPYTHON environment variable not set"
self.advicetext = "GALAHADPYTHON environment variable is not set"
self.advice( )
return
self.frame.destroy( )
# read resorce file to override style defaults
home = os.environ["HOME"]
if os.path.exists( home+'/.GalahadStyle' ) == 1 :
self.root.option_clear()
self.root.option_readfile( home+"/.GalahadStyle", priority=60 )
print "Reading style resources from user resorce file ~/.GalahadStyle"
elif os.path.exists( self.galahadpython+'/GalahadStyle' ) == 1 :
self.root.option_clear()
self.root.option_readfile( self.galahadpython+"/GalahadStyle",
priority=100 )
print "Reading style resources from system resorce file \n "\
+self.galahadpython+"/GalahadStyle"
# read resorce file to override package and architecture defaults
if os.path.exists( home+'/.GalahadDefaults' ) == 1 :
self.readdefaults( home+"/.GalahadDefaults" )
print "Reading package/achitecture resources from user resorce file" \
+" ~/.GalahadDefaults"
elif os.path.exists( self.galahadpython+'/GalahadDefaults' ) == 1 :
self.readdefaults( self.galahadpython+"/GalahadDefaults" )
print "Reading package/achitecture resources from system resorce file \n "\
+self.galahadpython+"/GalahadDefaults"
menubar = Menu( self.root )
# create pulldown menus, and add them to the menu bar
filemenu = Menu( menubar, tearoff=0 )
filemenu.add_command(label="Exit", command = self.root.destroy )
# filemenu.add_separator( )
# filemenu.add_command( label="Quit", command = self.root.destroy )
menubar.add_cascade( label="File", menu=filemenu )
editmenu = Menu( menubar, tearoff=0 )
editmenu.add_command( label="Preferences", command = self.prefset )
menubar.add_cascade( label="Edit", menu=editmenu )
helpmenu = Menu( menubar, tearoff=0 )
helpmenu.add_command( label="About", command = self.presshelpabout )
helpmenu.add_command( label="Commands", command = self.presshelpcommands )
menubar.add_cascade( label="Help", menu=helpmenu )
# display the menu
self.root.config( menu=menubar )
# construct the frames
self.frame = Frame( self.root )
self.frame1 = Frame( self.frame )
self.frame2 = Frame( self.frame )
# construct the button box (left-hand side)
self.buttons = Listbox( self.frame1, relief=SUNKEN,
width=5, height=10, setgrid=Y )
# construct a scrollbar (right-hand side)
self.scroll = Scrollbar( self.frame2 )
self.scroll.pack( side=RIGHT, fill=Y )
# construct a list box (right-hand side)
self.list = Listbox( self.frame2, relief=SUNKEN,
width=15, height=10, setgrid=Y,
yscrollcommand=self.scroll.set )
self.list.pack( side=LEFT, fill=BOTH, expand=1 )
# Tie the scrollbar to the list
self.scroll.config( command=self.list.yview )
#############
# LHS box #
#############
# assemble buttons for button box
# Button( self.buttons,
# width=10, height=1,
# text="help",
# command=self.presshelp
# ).pack( )
Button( self.buttons,
width=10, height=1,
text="cd",
command=self.presscdmenu
).pack( )
Button( self.buttons,
width=10, height=1,
text="refresh",
command=self.runrefresh
).pack( )
Button( self.buttons,
width=10, height=1,
text="spec",
command=self.pressspec
).pack( )
Button( self.buttons,
width=10, height=1,
text="package",
command=self.selectsolver
).pack( )
Button( self.buttons,
width=10, height=1,
text="solve",
command=self.runsdgal
).pack( )
Button( self.buttons,
width=10, height=1,
text="resolve",
command=self.rungal
).pack( )
Button( self.buttons,
width=10, height=1,
text="solution",
command=self.printsol
).pack( )
Button( self.buttons,
width=10, height=1,
text="summary",
command=self.printsum
).pack( )
Button( self.buttons,
width=10, height=1,
text="stop",
command=self.delalive
).pack( )
Button( self.buttons,
width=10, height=1,
text="exit",
command=self.root.destroy
).pack( )
self.buttons.pack( side=TOP, fill=Y )
# Create package/logo box
self.space( )
self.createpacklogobox( )
#############
# RHS box #
#############
# Fill the listbox with a list of all the SIF files in the directory
self.files = os.listdir( self.dir )
self.files.sort( )
for eachfile in self.files:
if self.dotsif.search( eachfile ) != None:
self.list.insert( END, eachfile )
###################
# Assemble boxes #
###################
# Pack it all together
self.frame1.pack( fill=BOTH, side=LEFT )
self.frame2.pack( fill=BOTH, side=LEFT )
self.frame.pack( fill=BOTH, side=TOP, expand=1 )
####################
# event bindings #
####################
# Set up bindings for the mouse buttons
self.root.bind_all( "<Control-c>", self.cntrlcdestroy )
# left mouse button
self.list.bind( "<Double-Button-1>", self.editfile )
# middle mouse button (last two don't appear to work here)
self.list.bind( "<Button-2>", self.runsdgalevent )
self.list.bind( "<Double-Button-2>", self.runsdgaleventdetails )
self.list.bind( "<Triple-Button-2>", self.runsdgaleventdebug )
# right mouse button
self.list.bind( "<Button-3>", self.runsdgaleventdetails )
##############################################################################
# function definitions #
##############################################################################
# function to bind Control-c to destroy
# -------------------------------------
def cntrlcdestroy( self, event ):
self.root.destroy( )
if TkGalahad.instancesopen <= 0:
import sys
sys.exit( 0 )
# function to bind double-mouse-1 to edit
# ---------------------------------------
def editfile( self, event ):
try:
editor = os.environ["VISUAL"]
except KeyError:
try:
editor = os.environ["EDITOR"]
except KeyError:
editor = emacs
os.popen( editor+' '+self.list.get( self.list.curselection( )[0], last=None))
# function to refresh list of files
# ---------------------------------
def runrefresh( self ):
self.files = os.listdir( self.dir )
self.files.sort( )
self.list.delete( 0, END )
for eachfile in self.files:
if self.dotsif.search( eachfile ) != None:
self.list.insert( END, eachfile )
# function to display help
# ------------------------
def presshelp( self ):
if self.helpwindowopen == 1 :
return
self.helpwindowopen = 1
self.helpwindow = Toplevel( self.root )
self.helpwindow.geometry( '+300+100' )
self.helpwindow.title( 'About GALAHAD tool' )
self.helpwindow.menubar = Menu( self.helpwindow )
self.helpwindow.menubar.add_command( label = "Quit",
command=self.helpwindowdestroy )
self.helpwindow.config( menu=self.helpwindow.menubar )
Label( self.helpwindow, anchor=W, justify=LEFT,
takefocus=1, text=helptext ).pack( side=TOP )
def presshelpabout( self ):
if self.helpaboutwindowopen == 1 :
return
self.helpaboutwindowopen = 1
self.helpaboutwindow = Toplevel( self.root )
self.helpaboutwindow.geometry( '+300+100' )
self.helpaboutwindow.title( 'About GALAHAD tool' )
self.helpaboutwindow.menubar = Menu( self.helpaboutwindow )
self.helpaboutwindow.menubar.add_command( label = "Quit",
command=self.helpaboutwindowdestroy )
self.helpaboutwindow.config( menu=self.helpaboutwindow.menubar )
Label( self.helpaboutwindow, anchor=W, justify=LEFT,
takefocus=1, text=helpabouttext ).pack( side=TOP )
def presshelpcommands( self ):
if self.helpcommandswindowopen == 1 :
return
self.helpcommandswindowopen = 1
self.helpcommandswindow = Toplevel( self.root )
self.helpcommandswindow.geometry( '+300+100' )
self.helpcommandswindow.title( 'GALAHAD tool commands' )
self.helpcommandswindow.menubar = Menu( self.helpcommandswindow )
self.helpcommandswindow.menubar.add_command( label = "Quit",
command=self.helpcommandswindowdestroy )
self.helpcommandswindow.config( menu=self.helpcommandswindow.menubar )
Label( self.helpcommandswindow, anchor=W, justify=LEFT,
takefocus=1, text=helpcommandstext ).pack( side=TOP )
# function to destroy help windows
# --------------------------------
def helpwindowdestroy( self ):
self.helpwindowopen = 0
self.helpwindow.destroy( )
def helpaboutwindowdestroy( self ):
self.helpaboutwindowopen = 0
self.helpaboutwindow.destroy( )
def helpcommandswindowdestroy( self ):
self.helpcommandswindowopen = 0
self.helpcommandswindow.destroy( )
# function to display preferences
# -------------------------------
def prefset( self ):
if self.prefwindowopen == 1 :
return
self.prefwindowopen = 1
self.prefwindow = Toplevel( self.root )
self.prefwindow.geometry( '+300+100' )
self.prefwindow.title( 'GALAHAD tool preferences' )
self.prefwindow.menubar = Menu( self.prefwindow )
self.prefwindow.menubar.add_command( label = "Quit",
command=self.prefwindowdestroy )
self.prefwindow.config( menu=self.prefwindow.menubar )
Label( self.prefwindow, anchor=W, justify=LEFT,
takefocus=1, text=preftext ).pack( side=TOP )
# function to destroy pref window
# -------------------------------
def prefwindowdestroy( self ):
self.prefwindowopen = 0
self.prefwindow.destroy( )
# function to start spec window
# -----------------------------
def pressspec( self ):
if self.specwindowopen == 1 :
return
self.specwindowopen = 1
if self.var_package.get( ) == 'lanb' :
self.lanbspec( )
elif self.var_package.get( ) == 'filt' :
self.filtranespec( )
elif self.var_package.get( ) == 'qpb' :
self.qpbspec( )
elif self.var_package.get( ) == 'qpa' :
self.qpaspec( )
else :
print 'unavailable at the present time, defaults will be used'
self.specwindowopen = 0
self.advicetext = "Sorry, no spec window available " \
+ "for package "+self.var_package_label.get( ) \
+ " at present. Default values will be used",
self.advice( )
return
# Another function to change directory
# ------------------------------------
def presscdmenu( self ):
if self.cdmenuwindowopen == 1 :
return
self.cdmenuwindowopen = 1
self.cdmenuwindow = Toplevel( self.root )
self.cdmenuwindow.geometry('+300+100')
self.cdmenuwindow.title('GALAHAD cd tool')
self.menubar = Menu( self.cdmenuwindow )
self.menubar.add_command( label = "Quit", command=self.cdmenuwindowdestroy )
self.cdmenuwindow.config( menu=self.menubar )
self.cdmenuwindow.frame = Frame( self.cdmenuwindow,
name="cdmenuwindow" )
self.cdmenuwindow.frame1 = Frame( self.cdmenuwindow.frame,
name="cdmenuwindow1" )
self.cdmenuwindow.frame2 = Frame( self.cdmenuwindow.frame,
name="cdmenuwindow2" )
self.cdmenuwindow.frame3 = Frame( self.cdmenuwindow.frame,
name="cdmenuwindow3" )
self.cdmenuwindow.frame4 = Frame( self.cdmenuwindow.frame,
name="cdmenuwindow4" )
self.cdmenuwindow.frame5 = Frame( self.cdmenuwindow.frame,
name="cdmenuwindow5" )
Label( self.cdmenuwindow.frame1, height=1, text="" ).pack( side=TOP )
self.cdmenuwindow.label = Label( self.cdmenuwindow.frame1,
text="Current directory is \n " + \
self.dir +"\nChange directory to ...",
anchor=W,
relief=FLAT,
borderwidth=0
)
self.cdmenuwindow.label.pack( side=TOP )
Label( self.cdmenuwindow.frame1, height=1, text="" ).pack( side=TOP )
self.cdmenuwindow.frame1.pack( fill=BOTH, side=TOP, expand=1 )
self.cdmenuwindow.scroll = Scrollbar( self.cdmenuwindow.frame2 )
self.cdmenuwindow.scroll.pack( side=RIGHT, fill=Y )
self.cdmenuwindow.list = Listbox( self.cdmenuwindow.frame2, relief=SUNKEN,
width=15, height=10, setgrid=Y,
yscrollcommand=self.cdmenuwindow.scroll.set )
self.cdmenuwindow.list.pack( side=TOP, fill=BOTH, expand=1 )
self.cdmenuwindow.scroll.config( command=self.cdmenuwindow.list.yview )
self.cdmenuwindow.list.bind( "<Double-Button-1>", self.cdmenuupdateevent )
self.cdmenu_listdirs( )
self.cdmenuwindow.frame2.pack( fill=BOTH, side=TOP, expand=1 )
Label( self.cdmenuwindow.frame3, height=1, text="" ).pack( side=TOP )
self.cdmenuwindow.label = Label( self.cdmenuwindow.frame3,
text=" ... or choose it yourself ...",
anchor=W,
relief=FLAT,
borderwidth=0
)
self.cdmenuwindow.label.pack( side=TOP )
Label( self.cdmenuwindow.frame3, height=1, text="" ).pack( side=TOP )
self.cdmenuwindow.frame3.pack( fill=BOTH, side=TOP, expand=1 )
self.stringnewdir = StringVar( )
self.cdmenuwindow.entry = Entry( self.cdmenuwindow.frame4,
name="cdwindowEntry",
textvariable=self.stringnewdir,
borderwidth=2, width=49,
relief=SUNKEN,
)
self.cdmenuwindow.entry.delete( 0, END )
self.cdmenuwindow.entry.insert( END, self.dir )
self.cdmenuwindow.entry.bind( "<KeyPress-Return>", self.cdmenuupdateevent )
self.cdmenuwindow.entry.pack( side=TOP )
self.cdmenuwindow.frame4.pack( fill=BOTH, side=TOP, expand=1 )
Label( self.cdmenuwindow.frame5, height=1, text="" ).pack( side=TOP )
self.cdmenuwindow.buttons = Frame( self.cdmenuwindow.frame5 )
self.space_cdmenu( )
Button( self.cdmenuwindow.buttons,
width=6, pady=2,
text="ok",
command=self.cdmenuupdate
).pack( side=LEFT, fill=BOTH )
self.space_cdmenu( )
Button( self.cdmenuwindow.buttons,
width=6, pady=2,
text="quit",
command=self.cdmenuwindowdestroy
).pack( side=LEFT, fill=BOTH )
self.space_cdmenu( )
self.cdmenuwindow.buttons.pack( side=TOP, fill=BOTH )
Label( self.cdmenuwindow.frame5, height=1, text="" ).pack( side=TOP )
self.cdmenuwindow.frame5.pack( fill=BOTH, side=TOP, expand=1 )
self.cdmenuwindow.frame.pack( fill=BOTH, side=TOP, expand=1 )
self.cdmenuwindow.mainloop( )
# function to build a list of sub-directories of the current directory
# --------------------------------------------------------------------
def cdmenu_listdirs( self ):
self.files = os.listdir( self.dir )
self.files.sort( )
self.cdmenuwindow.list.insert( END, '../' )
self.cdmenuwindow.list.insert( END, './' )
for eachfile in self.files:
if os.path.isdir( eachfile ) != 0:
self.cdmenuwindow.list.insert( END, eachfile )
# Another function to change directory and refresh list of files
# --------------------------------------------------------------
def cdmenuupdateevent( self, event ):
self.cdmenuupdatemain( )
def cdmenuupdate( self ):
self.cdmenuupdatemain( )
def cdmenuupdatemain( self ):
n = self.cdmenuwindow.list.curselection( )
if len( n ) == 0 :
self.newdir = self.stringnewdir.get( )
if os.path.exists( self.newdir ) :
if os.path.isdir( self.newdir ) :
self.dir = self.newdir
os.chdir( self.dir )
else:
self.advicetext = "File '"+self.newdir+"' is not a directory \n " +\
"Please try again"
self.advice( )
return
else:
self.advicetext = "Directory '"+self.newdir+"' not found. \n " +\
"Please try again"
self.advice( )
return
else:
self.dir = self.dir+"/"+self.cdmenuwindow.list.get( n[0], last=None )
os.chdir( self.dir )
self.dir = os.getcwd( )
print "Working directory is now "+self.dir
self.runrefresh( )
self.cdmenuwindowopen = 0
self.cdmenuwindow.destroy( )
self.presscdmenu( )
def cdmenuwindowdestroy( self ):
self.cdmenuwindowopen = 0
self.cdmenuwindow.destroy( )
# function to select solver to be used
# ------------------------------------
def selectsolver( self ):
if self.selectwindowopen == 1 :
return
self.selectwindowopen = 1
self.selectwindow = Toplevel( self.root )
self.selectwindow.geometry('+300+100')
self.selectwindow.title('GALAHAD package selection tool')
# self.menubar = Menu( self.selectwindow )
# self.menubar.add_command( label = "Quit", command=self.selectwindowdestroy )
# self.selectwindow.config( menu=self.menubar )
self.selectwindow.frame = Frame( self.selectwindow, name="selectwindow2" )
self.selectwindow.frameb = Frame( self.selectwindow, name="selectwindow2b" )
self.selectwindow.frame1 = Frame( self.selectwindow.frame,
name="selectwindowf1" )
self.selectwindow.frame2 = Frame( self.selectwindow.frame,
name="selectwindowf2" )
Label( self.selectwindow.frame1, width=2, text="" ).pack( side=LEFT )
Label( self.selectwindow.frame1,
anchor=W, relief=FLAT, borderwidth=0, width=14,
text="\nPackage to use:"
).pack( side=TOP )
self.selectwindow.packagesframe1 = Frame( self.selectwindow.frame1,
name="selectwindow" )
for packages in [ 'lanb', 'filt', 'qpb', 'qpa' ]:
if packages == 'lanb' : label = "LANCELOT B"
elif packages == 'filt' : label = "FILTRANE"
elif packages == 'qpb' : label = "QPB / LSQP"
elif packages == 'qpa' : label = "QPA"
else :label = ""
Radiobutton( self.selectwindow.packagesframe1,
highlightthickness=0, relief=FLAT,
width=14, anchor=W,
variable=self.var_package,
value=packages,
text=label
).pack( side=TOP, fill=NONE )
self.selectwindow.packagesframe1.pack( side=TOP )
self.selectwindow.frame1.pack( side=LEFT )
Label( self.selectwindow.frame2,
anchor=W, relief=FLAT, borderwidth=0, width=17,
text="\nArchitecture to use:"
).pack( side=TOP )
self.selectwindow.packagesframe2 = Frame( self.selectwindow.frame2,
name="selectwindow2" )
if os.path.exists( self.galahad ) == 1 :
self.architecture = os.listdir( self.galahad+"/makefiles" )
self.architecture.sort( )
for eachfile in self.architecture :
Radiobutton( self.selectwindow.packagesframe2,
highlightthickness=0, relief=FLAT,
width=17, anchor=W,
variable=self.var_arch,
value=eachfile,
text=eachfile
).pack( side=TOP, fill=NONE )
Label( self.selectwindow.frame2, width=2, text="" ).pack( side=LEFT )
self.selectwindow.packagesframe2.pack( side=TOP )
self.selectwindow.frame2.pack( side=TOP )
self.selectwindow.frame.pack( fill=BOTH, side=TOP, expand=1 )
Label( self.selectwindow.frameb, height=1, text="" ).pack( side=TOP )
self.selectwindow.buttons = Frame( self.selectwindow.frameb )
self.space_select( )
Button( self.selectwindow.buttons,
width=6, pady=2,
text="ok",
command=self.selectupdate
).pack( side=LEFT, fill=BOTH )
self.space_select( )
Button( self.selectwindow.buttons,
width=6, pady=2,
text="cancel",
command=self.selectcancel
).pack( side=LEFT, fill=BOTH )
self.space_select( )
self.selectwindow.buttons.pack( side=TOP, fill=BOTH )
Label( self.selectwindow.frameb, height=1, text="" ).pack( side=TOP )
self.selectwindow.frameb.pack( fill=BOTH, side=TOP, expand=1 )
self.selectwindow.mainloop( )
# function to display advice message
# ----------------------------------
def advice( self ):
if self.advicewindowopen == 1 :
return
self.advicewindowopen = 1
self.advicewindow = Toplevel( self.root )
self.advicewindow.geometry('+100+100')
self.advicewindow.title('GALAHAD advice')
# self.menubar = Menu( self.advicewindow )
# self.menubar.add_command( label = "Quit", command=self.advicewindowdestroy )
# self.advicewindow.config( menu=self.menubar )
self.advicewindow.frame = Frame( self.advicewindow,
background=warningbackground,
name="advicewindow2" )
Label( self.advicewindow.frame, height=1, background=warningbackground,
text="" ).pack( side=TOP )
Label( self.advicewindow.frame,
relief=FLAT, borderwidth=1,
foreground=warningforeground,
background=warningbackground,
font=self.helpfont,
text=" "+self.advicetext+" "
).pack( side=TOP )
Label( self.advicewindow.frame, height=1, background=warningbackground,
text="" ).pack( side=TOP )
self.advicewindow.buttons = Frame( self.advicewindow.frame,
background=warningbackground )
Button( self.advicewindow.buttons,
width=6, pady=2,
text="ok",
command=self.advicecancel
).pack( side=TOP, fill=BOTH )
self.advicewindow.buttons.pack( side=TOP, fill=Y )
Label( self.advicewindow.frame, height=1, background=warningbackground,
text="" ).pack( side=TOP )
self.advicewindow.frame.pack( fill=BOTH, side=TOP, expand=1 )
self.advicewindow.mainloop( )
# function to select and record solver to be used
# -----------------------------------------------
def selectupdateevent( self, event ):
self.selectupdatemain( )
def selectupdate( self ):
self.selectupdatemain( )
def selectupdatemain( self ):
self.selectwindowdestroy( )
def selectwindowdestroy( self ):
self.selectwindowopen = 0
if self.var_package.get( ) == 'lanb' :
self.var_package_label.set( "LANCELOT B" )
elif self.var_package.get( ) == 'filt' :
self.var_package_label.set( "FILTRANE" )
elif self.var_package.get( ) == 'qpb' :
self.var_package_label.set( "QPB / LSQP" )
elif self.var_package.get( ) == 'qpa' :
self.var_package_label.set( "QPA" )
else : self.var_package_label.set( "" )
# Destroy existing packag/logo box
self.destroypacklogobox( )
# Create new package/logo box
self.createpacklogobox( )
self.selectwindow.destroy( )
def selectcancel( self ):
self.selectwindowopen = 0
self.selectwindow.destroy( )
def advicecancel( self ):
self.advicewindowopen = 0
self.advicewindow.destroy( )
# function to run SIF decoder followed by selected GALAHAD package
# ----------------------------------------------------------------
def runsdgalevent( self, event ):
self.sdgalout = ''
self.runsdgalmain( )
def runsdgaleventdetails( self, event ):
self.sdgalout = '-o 1'
self.runsdgalmain( )
def runsdgaleventdebug( self, event ):
self.sdgalout = '-o -1'
self.runsdgalmain( )
def runsdgal( self ):
self.sdgalout = ''
self.runsdgalmain( )
def runsdgalmain( self ):
if len( self.threads ) != 0 :
while self.threads[0].isAlive( ) :
self.advicetext = "Please wait for run to terminate and try again"
self.advice( )
return
n = self.list.curselection( )
if len( n ) == 0 :
self.advicetext = "Please select a test problem"
self.advice( )
return
self.file = self.dotsif.sub( '', self.list.get( n[0], last=None ) )
self.threads =[ ]
self.t = threading.Thread( target=self.sdgalthread )
self.threads.append( self.t )
# print self.threads
self.threads[0].start( )
def sdgalthread( self ):
print 'sdgal '+self.var_arch.get( )+' '+self.var_package.get( ) \
+' '+self.sdgalout+' '+self.file
os.system( 'sdgal '+self.var_arch.get( )+' '+self.var_package.get( ) \
+' '+self.sdgalout+' '+self.file )
# function to run selected GALAHAD on previously-decoded SIF problem
# ------------------------------------------------------------------
def rungal( self ):
if len( self.threads ) != 0 :
while self.threads[0].isAlive( ) :
self.advicetext = "Please wait for run to terminate and try again"
self.advice( )
return
if os.path.exists( 'OUTSDIF.d' ) == 0 or \
os.path.exists( 'ELFUN.f' ) == 0 or \
os.path.exists( 'GROUP.f' ) == 0 :
self.advicetext = "There is no test problem to be"+ \
"re-solved in the current directory"
self.advice( )
return
self.threads = [ ]
self.t = threading.Thread( target=self.galthread )
self.threads.append( self.t )
self.threads[0].start( )
def galthread( self ):
print 'gal '+self.var_arch.get( )+' '+self.var_package.get( )
os.system( 'gal '+self.var_arch.get( )+' '+self.var_package.get( ) )
# function to run selected GALAHAD package on previously-decoded
# SIF problem using current spec values