/usr/lib/python2.7/dist-packages/Plframe.py is in python-plplot 5.10.0+dfsg2-0.1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | from Tkinter import *
#from pl import *
from plplot import *
from TclSup import *
from string import *
from math import *
CMD='cmd'
# Physically imported this function from Tkinter.py, b/c it evidently
# isn't made available via the above import statement.
def _flatten(tuple):
res = ()
for item in tuple:
if type(item) in (TupleType, ListType):
res = res + _flatten(item)
elif item is not None:
res = res + (item,)
return res
#=============================================================================#
# class Plframe
#=============================================================================#
class Plframe(Widget):
def __init__( self, master=None, cnf={}, **kw ):
"""Constructor.
Initialize the Tk base class, and squirel away the stream id,
so that we will be able to ensure that future draw requests
show up in the right place."""
Widget.__init__( self, master, 'plframe', cnf, kw )
self.strm = plgstrm()
def cmd( s, *args ):
"Invoke a subcommand on the plframe widget."
apply( s.tk.call, (s._w, 'cmd',) + _flatten(args) )
def info(s, what):
return s.tk.call( s._w, 'info', what )
## Now implement the PLplot API. For simple functions, can call
## straight to Tk, which is probably the most straightforward way, in
## the sense of making the Python/Tk widget look and act most like
## it's older brother the Tcl version. However, functions which rely
## on the Numeric extensions cannot work this way, so for those we
## call straight to the Python compiled interface to the PLplot API.
def plenv( s, xmin, xmax, ymin, ymax, i, j ):
s.cmd( 'plenv', xmin, xmax, ymin, ymax, i, j )
def pleop(s):
s.cmd( 'pleop' )
def pllab( s, xlab, ylab, tlab ):
s.cmd( 'pllab', xlab, ylab, tlab )
def plline( s, x, y ):
plsstrm( s.strm )
plline( x, y )
def plpoin( s, xs, ys, mark ):
plsstrm( s.strm )
plpoin( xs, ys, mark )
#=============================================================================#
# class PlXframe
#=============================================================================#
class PlXframe(Frame):
"""This class provides the same facilities as the Plframe, plus
several additional facilities for advanced plot interaction, which
are provided through menus and bindings."""
def __init__( s, master=None, cnf={}, **kw ):
"""Constructor.
Configure the widget database, and then set up the internal
members. Namely, a menubar and a contained Plframe."""
Frame.__init__( s, master )
s.setup_defaults()
# We will be using the grid geometry manager to pack a plframe
# widget along with some additional addornments. The top row
# (row 0) will contain the menubar. The next row (row 1) will
# hold the actual plframe, as well as the vertical scrollbar
# when present.. And the last row (row 2) will hold the
# horizontal scrollbar when present. We want the menubar and
# the horizontal scrollbar to use only the required space, and
# we want the plframe to expand to fill any remaining space.
# To accomplish this we set the weights for the top and bottom
# row to zero, thus preventing them from expanding.
s.rowconfigure( 0, weight=0, minsize=0 )
s.rowconfigure( 1, weight=1, minsize=0 )
s.rowconfigure( 2, weight=0, minsize=0 )
# Similarly for the columns, we will use the left column (col
# 0) for the plframe and the horizontal scrollbar, and the
# right column (col 1) for the vertical scrollbar. Moreover, the
# menubar in the top row will span columns 0 and 1. Again, we
# want the rightmost column (col 0) to stay at whatever is the
# minimum width to display its contents, and want the plframe
# in the leftmost column to grow to fill all space.
s.columnconfigure( 0, weight=1, minsize=0 )
s.columnconfigure( 1, weight=0, minsize=0 )
# Okay, now get the actual plframe widget so we can display
# it. And we pack it into its grid cell with all four sides
# of the plframe sticking to the expandable size of the
# enclosing grid cell, as arranged by the row,col weighting
# scheme described above.
s.plf = Plframe( s, kw )
s.plf.grid( row=1, column=0, sticky=NSEW )
s.build_menu_bar()
s.strm = plgstrm()
s.setup_bindings()
s.hscroll_exists = 0
s.vscroll_exists = 0
## All this stuff is being based heavily on the Pltkwin.tcl thing by
## Vince, for itcl/itk (which in turn was based heavily on the
## plwidgets.tcl stuff by Maurice).
def setup_defaults(s):
#s.saveopt_dev = StringVar()
s.saveopt_dev = "psc"
#s.saveopt_dev.set( "psc" )
#s.saveopt_file = IntVar()
s.saveopt_file = 0
#s.saveopt_file.set( 0 )
# Now do the zoom support stuff.
s.zidx = 0
s.zxl = [ 0. ]; s.zyl = [ 0. ]
s.zxr = [ 1. ]; s.zyr = [ 1. ]
def setup_bindings(s):
s.plf.bind( "<Any-KeyPress>", s.key_filter )
s.plf.bind( "<Any-ButtonPress>", s.user_mouse )
s.plf.bind( "<Any-Enter>", s.set_focus )
def set_focus(s,e):
# print "in set_focus"
s.plf.focus()
def build_menu_bar(s):
"Create the menubar at the top of the PlXframe"
s.ftop = Frame( s )
s.ftop.grid( row=0, columnspan=2, sticky='ew' )
s.ftop.plot = Menubutton( s.ftop, text="Plot", underline=0,
relief=RAISED )
s.ftop.plot.m = Menu( s.ftop.plot )
s.ftop.plot["menu"] = s.ftop.plot.m
s.ftop.plot.pack( side=LEFT )
s.create_menu_print( s.ftop.plot.m )
s.create_menu_save( s.ftop.plot.m )
s.create_menu_orient( s.ftop.plot.m )
s.create_menu_zoom( s.ftop.plot.m )
s.create_menu_page( s.ftop.plot.m )
s.create_menu_options( s.ftop.plot.m )
s.create_menu_debug ( s.ftop.plot.m )
s.ftop.eop = Button( s.ftop, text="Clear",
command=s.clearpage )
s.ftop.eop.pack( side=RIGHT )
s.ftop.lstat = Label( s.ftop, anchor=W, relief=RAISED )
s.ftop.lstat.pack( side=RIGHT, expand=1, fill=BOTH )
def create_menu_print( s, m ):
m.add( "command", label="Print", command=s.cmd_print )
def create_menu_save( s, pmenu ):
"""Create the menu which lets us control the whole business of
saving plots to disk."""
m = Menu( pmenu )
pmenu.add( "cascade", label='Save', menu=m )
# Save - As
m.add( "command", label="As", command=s.save_as )
# Save - Again
m.add( "command", label="Again", command=s.save_again,
state=DISABLED )
# Save - Close
m.add( "command", label="Close", command=s.save_close,
state=DISABLED )
m.add( "separator" )
# Save - Set device.. (another cascade)
m.sdev = Menu( m )
m.add( "cascade", label="Set device", menu=m.sdev )
# Generate the device list in the "Save/Set device" widget
# menu, by querying the plframe widget for the available
# output devices (which are listed).
devnames = s.plf.info( "devnames" )
devkeys = s.plf.info( "devkeys" )
# Oh no, these came back as Tcl lists. Have to convert them
# to Python lists.
devnamlst = TclList2Py( devnames )
devkeylst = TclList2Py( devkeys )
print "devnamlst = ", devnamlst
print "devkeylst = ", devkeylst
print "len(devnamlst) = ", len(devnamlst)
## for i in range( len(devnamlst) ):
## devnam = devnamlst[i]
## devkey = devkeylst[i]
##
## m.sdev.add( "radio", label=devnam, variable=s.saveopt_dev,
## value=devkey )
# Now get the ball rolling by preinvoking one of these.
# Default to the first one, whatever it is, but use psc
# (Postscript color), if we can find it in the list of
# available devices.
## ivk = 1
## for i in range( len(devnamlst) ):
## if devkeylst[i] == "psc":
## ivk = i+1
## break
##
## m.sdev.invoke( ivk )
# Save - Set file type.. (another cascade)
m.sfile = Menu( m )
m.add( "cascade", label="Set file type", menu=m.sfile )
m.sfile.add( "radio", label="Single file (one plot/file)",
variable=s.saveopt_file, value=0 )
m.sfile.add( "radio", label="Archive file( many plots/file)",
variable=s.saveopt_file, value=1 )
m.sfile.invoke( 1 )
def create_menu_orient( s, pmenu ):
m = Menu( pmenu )
pmenu.add( "cascade", label='Orient', menu=m )
m.config( postcommand=lambda o=s, x=m: o.update_orient(x) )
# Orient - 0 degrees
m.add( 'radio', label="0 degrees",
command=lambda o=s: o.orient(0) )
# Orient - 90 degrees
m.add( 'radio', label="90 degrees",
command=lambda o=s: o.orient(1) )
# Orient - 180 degrees
m.add( 'radio', label="180 degrees",
command=lambda o=s: o.orient(2) )
# Orient - 270 degrees
m.add( 'radio', label="270 degrees",
command=lambda o=s: o.orient(3) )
def create_menu_zoom( s, pmenu ):
m = Menu( pmenu )
pmenu.add( "cascade", label='Zoom', menu=m )
m.config( postcommand=lambda o=s, x=m: o.update_zoom(x) )
# Zoom - select (by mouse)
m.add( 'command', label="Select",
command=lambda o=s: o.zoom_select() )
# Zoom - back (go back 1 zoom level)
m.add( 'command', label="Back",
command=lambda o=s: o.zoom_back(),
state='disabled' )
# Zoom - forward (go forward 1 zoom level)
m.add( 'command', label="Forward",
command=lambda o=s: o.zoom_forward(),
state='disabled' )
# Zoom - enter bounds
m.add( 'command', label="Enter bounds..",
command=lambda o=s: o.zoom_enter() )
# Zoom - reset
m.add( 'command', label="Reset",
command=lambda o=s: o.zoom_reset() )
# Zoom - options (another cascade)
zom = Menu( m )
m.add( 'cascade', label="Options", menu=zom )
s.zoomopts_asp = IntVar()
s.zoomopts_sel = IntVar()
zom.add( 'check', label="Preserve aspect ratio",
variable=s.zoomopts_asp )
zom.add( 'separator' )
zom.add( 'radio', label="Start from corner",
variable=s.zoomopts_sel, value=0 )
zom.add( 'radio', label="Start from center",
variable=s.zoomopts_sel, value=1 )
s.zoomopts_sel = 1
s.zoomopts_asp = 1
zom.invoke(1)
zom.invoke(4)
def create_menu_page( s, pmenu ):
m = Menu( pmenu )
pmenu.add( "cascade", label='Page', menu=m )
# Page - enter bounds
m.add( 'command', label="Setup..", command=s.page_enter )
# Page - reset
m.add( 'command', label="Reset", command=s.page_reset )
def create_menu_options( s, pmenu ):
m = Menu( pmenu )
pmenu.add( 'cascade', label="Options", menu=m )
m.add( 'command', label="Palette 0", command=s.plcmap0_edit )
m.add( 'command', label="Palette 1", command=s.plcmap1_edit )
def create_menu_debug( s, pmenu ):
pmenu.add( "command", label="Debug PlXframe", command=s.debug )
## Now the commands needed to implement the menus.
def key_filter( s, e ):
"""Process keystroke events, and parcell out to various control
functions."""
kn = e.keysym
if kn == 'z':
s.zoom_select()
elif kn == 'b':
s.zoom_back()
elif kn == 'f':
s.zoom_forward()
elif kn == 'r':
s.zoom_reset()
else:
pass
#print "Unknown keyname ", kn
def user_mouse( s, e ):
print "in user_mouse"
## flash
def cmd_print(s):
s.label_set( "Printing plot..." )
s.tk.call( s.plf._w, 'print' )
# Should see about error trapping, like the itk widget does.
def sucky_save(s):
"""A sucky save menu thing. Needs to be enhanced to work like
the one in Tcl/Itcl."""
s.tk.call( s.plf._w, 'save', 'as', 'ps', 'xx.ps' )
s.tk.call( s.plf._w, 'save', 'close' )
print "Plot saved to xx.ps"
def save_as(s): pass
def save_again(s): pass
def save_close(s): pass
def update_zoom(s,m):
"""Configure zoom menu.
Responsible for making sure zoom menu entries are normal or
disabled as appropriate. In particular, that 'Back' or 'Forward'
are only displayed if it is possible to traverse the zoom windows
list in that direction."""
zframes = len( s.zxl )
if s.zidx == 0:
#print "disable back"
m.entryconfig( 2, state=DISABLED )
else:
#print "enable back"
m.entryconfig( 2, state=ACTIVE )
if s.zidx == zframes-1:
#print "disable forward"
m.entryconfig( 3, state=DISABLED )
else:
#print "enable forward"
m.entryconfig( 3, state=ACTIVE )
def zoom_select(s):
"Zooms plot in response to mouse selection."
# In itk we save the existing binding so it can be restored.
# Don't know how to save a binding for future use in Python/Tk.
## s.def_button_cmd = s.plf.bind( "<ButtonPress>" )
## global def_button_cmd zoomopts
##
## set def_button_cmd [bind [plwin] <ButtonPress>]
if s.zoomopts_sel == 0:
s.label_set( "Click on one corner of zoom region." )
elif s.zoomopts_sel == 1:
s.label_set( "Click on center of zoom region." )
s.plf.bind( "<ButtonPress>", s.zoom_start )
def zoom_enter(s):
print "zoom_enter"
##----------------------------------------------------------------------------
## zoom_reset
##
## Resets after zoom.
## Note that an explicit redraw is not necessary since the packer
## issues a resize after the scrollbars are unmapped.
##----------------------------------------------------------------------------
def zoom_reset(s):
## global def_button_cmd
s.label_reset()
## bind [plwin] <ButtonPress> $def_button_cmd
s.tk.call( s.plf._w, 'view', 'reset' )
if s.hscroll_exists and atoi( s.tk.call( 'winfo', 'ismapped',
s.hscroll._w ) ):
s.hscroll.grid_forget()
if s.vscroll_exists and atoi( s.tk.call( 'winfo', 'ismapped',
s.vscroll._w ) ):
s.vscroll.grid_forget()
## Reset zoom windows list
s.zidx = 0
s.zxl = [ 0. ]; s.zyl = [ 0. ]
s.zxr = [ 1. ]; s.zyr = [ 1. ]
def update_orient(s,m):
r = s.tk.call( s.plf._w, 'orient' )
# Grr, this is a floating point string. Must stand on our
# heads to get an actual integer out of it.
f = atof( r )
fsi = "%.0f" % f
i = atoi( fsi )
n = i / 90
n = i % 4
m.invoke( n+1 )
def orient(s, n):
"""Set the orientation of the plframe, but check to make sure
we only do this if the new orientation is different from the
old one."""
oldori = s.tk.call( s.plf._w, 'orient' )
oldf = atof( oldori )
oldn = atoi( "%.0f" % oldf ) % 4
if n != oldn:
rots = "%d" % n
s.tk.call( s.plf._w, 'orient', rots )
def page_enter(s):
print "in page_enter"
def page_reset(s):
print "in page_reset"
def zoom_start( s, e ):
"Starts plot zoom."
s.wx = e.x
s.wy = e.y
## Restore previous binding, but don't know how to do this in Python/Tk.
## s.plf.bind( "<ButtonPress>", s.def_button_cmd )
## global def_button_cmd
##
## bind [plwin] <ButtonPress> $def_button_cmd
## Maybe what I should do for now is just remove the one we instlaled,
## but punt on restoring the prexisting binding.
s.plf.bind( "<ButtonPress>", None )
## Hmpffff. That didn't work... Grrrrrr.
s.label_set( "Select zoom region by dragging mouse, then release." )
s.tk.call( s.plf._w, 'draw', 'init' )
s.plf.bind( "<B1-Motion>", s.zoom_mouse_draw )
s.plf.bind( "<B1-ButtonRelease>", s.zoom_mouse_end )
##----------------------------------------------------------------------------
## zoom_coords
##
## Transforms the initial and final mouse coordinates to either:
##
## opt = 0 device coordinates
## opt = 1 normalized device coordinates
##
## The global variable "zoomopts" is used to determine zoom behavior:
##
## zoomopts($this,0):
## 0 box follows mouse movements exactly
## 1 box follows mouse movements so that aspect ratio is preserved (default)
##
## zoomopts($this,1):
## 0 first and last points specified determine opposite corners
## of zoom box.
## 1 box is centered about the first point clicked on,
## perimeter follows mouse (default)
##
##----------------------------------------------------------------------------
def zoom_coords( s, x0, y0, x1, y1, opt ):
# Convert the integer input to float, prevents problems with
# division.
x0 = float(x0)
y0 = float(y0)
x1 = float(x1)
y1 = float(y1)
Lx = s.plf.winfo_width()
Ly = s.plf.winfo_height()
# Enforce boundaries in device coordinate space
bounds = split( s.tk.call( s.plf._w, 'view', 'bounds' ) )
xmin = Lx * atof( bounds[0] )
ymin = Ly * atof( bounds[1] )
xmax = Lx * atof( bounds[2] )
ymax = Ly * atof( bounds[3] )
x1 = max( xmin, min( xmax, x1 ) )
y1 = max( ymin, min( ymax, y1 ) )
# Two-corners zoom.
if s.zoomopts_sel == 0:
pass
## if { $zoomopts($this,1) == 0 } then {
# Get box lengths
dx = x1 - x0
dy = y1 - y0
## set dx [expr $x1 - $x0]
## set dy [expr $y1 - $y0]
sign_dx = sign(dx)
sign_dy = sign(dy)
## set sign_dx [expr ($dx > 0) ? 1 : -1]
## set sign_dy [expr ($dy > 0) ? 1 : -1]
xl = x0
yl = y0
## set xl $x0
## set yl $y0
# Constant aspect ratio
if s.zoomopts_asp == 1:
pass
## if { $zoomopts($this,0) == 1 } then {
##
## # Scale factors used to maintain plot aspect ratio
##
## set xscale [expr $xmax - $xmin]
## set yscale [expr $ymax - $ymin]
##
## # Adjust box size for proper aspect ratio
##
## set rx [expr double(abs($dx)) / $xscale]
## set ry [expr double(abs($dy)) / $yscale]
##
## if { $rx > $ry } then {
## set dy [expr $yscale * $rx * $sign_dy]
## } else {
## set dx [expr $xscale * $ry * $sign_dx]
## }
##
## set xr [expr $xl + $dx]
## set yr [expr $yl + $dy]
##
## # Now check again to see if in bounds, and adjust if not
##
## if { $xr < $xmin || $xr > $xmax } then {
## if { $xr < $xmin } then {
## set dx [expr $xmin - $x0]
## } else {
## set dx [expr $xmax - $x0]
## }
## set rx [expr double(abs($dx)) / $xscale]
## set dy [expr $yscale * $rx * $sign_dy]
## }
##
## if { $yr < $ymin || $yr > $ymax } then {
## if { $yr < $ymin } then {
## set dy [expr $ymin - $y0]
## } else {
## set dy [expr $ymax - $y0]
## }
## set ry [expr double(abs($dy)) / $yscale]
## set dx [expr $xscale * $ry * $sign_dx]
## }
## }
# Final box coordinates
xr = xl + dx
yr = yl + dy
## set xr [expr $xl + $dx]
## set yr [expr $yl + $dy]
### zoom from center out, preserving aspect ratio
else:
# Get box lengths, adjusting downward if necessary to keep
# in bounds
dx = abs( x1 - x0 )
dy = abs( y1 - y0 )
xr = x0 + dx;
xl = x0 - dx
yr = y0 + dy
yl = y0 - dy
if xl < xmin: dx = x0 - xmin
if xr > xmax: dx = xmax - x0
if yl < ymin: dy = y0 - ymin
if yr > ymax: dy = ymax - y0
# Constant aspect ratio
if s.zoomopts_asp == 1:
# Scale factors used to maintain plot aspect ratio
xscale = xmax - xmin
yscale = ymax - ymin
# Adjust box size for proper aspect ratio
rx = dx / xscale
ry = dy / yscale
if rx > ry:
dy = yscale * rx
else:
dx = xscale * ry
xr = x0 + dx
xl = x0 - dx
yr = y0 + dy
yl = y0 - dy
# Now check again to see if in bounds, and adjust
# downward if not
if xl < xmin:
dx = x0 - xmin
rx = dx / xscale
dy = yscale * rx
if yr > ymax:
dx = xmax - x0
rx = dx / xscale
dy = yscale * rx
if yl < ymin:
dy = y0 - ymin
ry = dy / yscale
dx = xscale * ry
if yr > ymax:
dy = ymax - y0
ry = dy / yscale
dx = xscale * ry
# Final box coordinates
xr = x0 + dx
xl = x0 - dx
yr = y0 + dy
yl = y0 - dy
## Optional translation to relative device coordinates.
if opt == 1:
wxl = xl / Lx
wxr = xr / Lx
wyl = 1.0 - float(yr) / Ly
wyr = 1.0 - float(yl) / Ly
else:
wxr = xl
wxl = xr
wyr = yl
wyl = yr
return wxl, wyl, wxr, wyr
def zoom_mouse_draw(s,e):
"Draws zoom box in response to mouse motion (with button held down)."
coords = s.zoom_coords( s.wx, s.wy, e.x, e.y, 0 )
s.tk.call( s.plf._w, 'draw', 'rect',
coords[0], coords[1], coords[2], coords[3] )
def zoom_mouse_end( s, e ):
"Performs actual zoom, invoked when user releases mouse button."
# Finish rubber band draw
s.plf.bind( "<B1-ButtonRelease>" )
s.plf.bind( "<B1-Motion>" )
## bind [plwin] <B1-ButtonRelease> {}
## bind [plwin] <B1-Motion> {}
s.label_reset()
s.tk.call( s.plf._w, 'draw', 'end' )
# Select new plot region
coords = s.zoom_coords( s.wx, s.wy, e.x, e.y, 1 )
s.view_zoom( coords[0], coords[1], coords[2], coords[3] )
### Hmm, view_select is only called by update_view, which isn't called
### by anything...
## def view_select( s, x0, y0, x1, y1 ):
## """Handles change of view into plot.
## Given in relative plot window coordinates."""
##
## print "in view_select"
####body Pltkwin::view_select {x0 y0 x1 y1} {
##
#### Adjust arguments to be in bounds and properly ordered (xl < xr, etc)
##
#### set xl [min $x0 $x1]
#### set yl [min $y0 $y1]
#### set xr [max $x0 $x1]
#### set yr [max $y0 $y1]
##
## xl = min( x0, x1 ); yl = min( y0, y1 )
## xr = max( x0, x1 ); yr = max( y0, y1 )
##
#### set xmin 0.
#### set ymin 0.
#### set xmax 1.
#### set ymax 1.
##
## xmin = 0.; ymin = 0.
## xmax = 1.; ymax = 1.
##
#### set xl [max $xmin [min $xmax $xl]]
#### set yl [max $ymin [min $ymax $yl]]
#### set xr [max $xmin [min $xmax $xr]]
#### set yr [max $ymin [min $ymax $yr]]
##
## xl = max( xmin, min( xmax, xl ) )
## yl = max( ymin, min( ymax, yl ) )
## xr = max( xmin, min( xmax, xr ) )
## yr = max( ymin, min( ymax, yr ) )
##
#### Only create scrollbars if really needed.
##
#### if {($xl == $xmin) && ($xr == $xmax)} \
#### then {set hscroll 0} else {set hscroll 1}
####
#### if {($yl == $xmin) && ($yr == $xmax)} \
#### then {set vscroll 0} else {set vscroll 1}
####
#### if { ! ($hscroll || $vscroll)} {return}
##
## if xl == xmin and xr == xmax:
## hscroll = 0
## else:
## hscroll = 1
##
## if yl == ymin and yr == ymax:
## vscroll = 0
## else:
## vscroll = 1
##
## if not (hscroll or vscroll):
## return
##
#### Select plot region
##
#### [plwin] view select $xl $yl $xr $yr
##
## s.tk.call( s.plf._w, 'view', 'select', xl, yl, xr, yr )
##
#### Fix up view
##
#### fixview $hscroll $vscroll
## s.fixview( hscroll, vscroll )
def view_zoom( s, x0, y0, x1, y1 ):
"Handles zoom. Given in relative device coordinates."
## Adjust arguments to be properly ordered (xl < xr, etc)
xl = min( x0, x1 )
yl = min( y0, y1 )
xr = max( x0, x1 )
yr = max( y0, y1 )
## Check for double-click (specified zoom region less than a few
## pixels wide). In this case, magnification is 2X in each direction,
## centered at the mouse location. At the boundary, the magnification
## is determined by the distance to the boundary.
stdzoom = .5
if (xr - xl) < .02 and (yr - yl) < .02:
nxl = xl - .5 * stdzoom
nxr = xl + .5 * stdzoom
if nxl < 0.:
nxl = 0.
nxr = 2. * xl
if nxr > 1.:
nxr = 1.
nxl = 2. * xl - 1.
xl = nxl
xr = nxr
nyl = yl - .5 * stdzoom
nyr = yl + .5 * stdzoom
if nyl < 0.:
nyl = 0.
nyr = 2. * yl
if nyr > 1.:
nyr = 1.
nyl = 2. * yl - 1.
yl = nyl
yr = nyr
## Adjust arguments to be in bounds (in case margins are in effect).
bounds = split( s.tk.call( s.plf._w, 'view', 'bounds' ) )
xmin = atof( bounds[0] )
ymin = atof( bounds[1] )
xmax = atof( bounds[2] )
ymax = atof( bounds[3] )
xl = max( xmin, min( xmax, xl ) )
yl = max( ymin, min( ymax, yl ) )
xr = max( xmin, min( xmax, xr ) )
yr = max( ymin, min( ymax, yr ) )
## Only create scrollbars if really needed.
hscroll, vscroll = 0, 0
if xl != xmin or xr != xmax: hscroll = 1
if yl != ymin or yr != ymax: vscroll = 1
if not (hscroll or yscroll):
s.tk.call( s.plf._w, 'redraw' )
return
## Select plot region
s.tk.call( s.plf._w, 'view', 'zoom', xl, yl, xr, yr )
## Fix up view
s.fixview( hscroll, vscroll )
## Add window to zoom windows list
coords = split( s.tk.call( s.plf._w, 'view' ) )
s.zidx = s.zidx + 1
if s.zidx == len( s.zxl ):
# Adding onto the end, no big deal
s.zxl.append( atof( coords[0] ) )
s.zyl.append( atof( coords[1] ) )
s.zxr.append( atof( coords[2] ) )
s.zyr.append( atof( coords[3] ) )
else:
# Adding into the middle...
s.zxl[ s.zidx ] = atof( coords[0] )
s.zyl[ s.zidx ] = atof( coords[1] )
s.zxr[ s.zidx ] = atof( coords[2] )
s.zyr[ s.zidx ] = atof( coords[3] )
if s.zidx < len( s.zxl ) - 1:
# Now chop off the end.
s.zxl = s.zxl[0:s.zidx+1]
s.zyl = s.zyl[0:s.zidx+1]
s.zxr = s.zxr[0:s.zidx+1]
s.zyr = s.zyr[0:s.zidx+1]
def zoom_back(s):
"Traverse the zoom windows list backward."
if s.zidx > 0:
s.zidx = s.zidx - 1
xl = s.zxl[ s.zidx ]; yl = s.zyl[ s.zidx ]
xr = s.zxr[ s.zidx ]; yr = s.zyr[ s.zidx ]
# Select plot region
s.tk.call( s.plf._w, 'view', 'select', xl, yl, xr, yr )
def zoom_forward(s):
"Traverse the zoom windows list forward."
zframes = len( s.zxl )
if zframes == 1 or s.zidx == zframes-1:
return
s.zidx = s.zidx + 1
xl = s.zxl[ s.zidx ]; yl = s.zyl[ s.zidx ]
xr = s.zxr[ s.zidx ]; yr = s.zyr[ s.zidx ]
# Select plot region
s.tk.call( s.plf._w, 'view', 'select', xl, yl, xr, yr )
def view_scroll(s):
print "in view_scroll"
def fixview( s, hscroll, vscroll ):
"Handles updates of scrollbars & plot after view change."
## Create scrollbars if they don't already exist.
created_sb = 0
if hscroll and not s.hscroll_exists:
s.hscroll = Scrollbar( s, relief=SUNKEN, orient=HORIZONTAL )
s.hscroll['command'] = ( s.plf._w, 'xscroll' )
s.plf.config( xscroll=( s.hscroll, 'set' ) )
s.hscroll_exists = 1
created_sb = 1
if vscroll and not s.vscroll_exists:
s.vscroll = Scrollbar( s, relief=SUNKEN, orient=VERTICAL )
s.vscroll['command'] = ( s.plf._w, 'yscroll' )
s.plf.config( yscroll=( s.vscroll, 'set' ) )
s.vscroll_exists = 1
created_sb = 1
## When scrollbars are first created, it may be necessary to unmap
## then map the plframe widget so that it has a chance to initialize
## the scrollbars before they are mapped.
if created_sb:
s.plf.grid_forget()
s.plf.grid( row=1, column=0, sticky='nsew' )
## Map scrollbars if not already mapped. To get packing right, need
## to unmap then remap plot widget. Otherwise need to do explicit
## redraw.
if hscroll and not atoi( s.tk.call( 'winfo', 'ismapped',
s.hscroll._w ) ) \
or vscroll and not atoi( s.tk.call( 'winfo', 'ismapped',
s.vscroll._w ) ) :
s.update()
s.plf.grid_forget()
if hscroll:
s.hscroll.grid( row=2, column=0, sticky='ew' )
if vscroll:
s.vscroll.grid( row=1, column=1, sticky='ns' )
s.plf.grid( row=1, column=0, sticky='nsew' )
else:
s.tk.call( s.plf._w, 'redraw' )
## Hmmm. Actually, "update_view" doesn't seem to be used by anything...
## def update_view(s):
## """Updates view.
## Results in scrollbars being added if they are appropriate.
## Does nothing if the plot window is unchanged from the default."""
##
## print "in update_view"
#### set coords [[plwin] view]
####
#### set xl [lindex "$coords" 0]
#### set yl [lindex "$coords" 1]
#### set xr [lindex "$coords" 2]
#### set yr [lindex "$coords" 3]
####
#### view_select $xl $yl $xr $yr
def status_msg(s,msg):
s.label_set(msg)
# schedule removal of the message with Tk "after"
s.after( 2500, s.label_reset )
def label_reset(s):
s.ftop.lstat.config( text='' )
def label_set(s,msg):
s.ftop.lstat.config( text=msg )
def plcmap0_edit(s):
print "in plcmap0_edit"
def plcmap1_edit(s):
print "in plcmap1_edit"
## Now do the PLplot API. Just vector these off to the contained
## Plframe widget.
def cmd( s, *args ):
"Invoke a subcommand on the plframe widget."
apply( s.tk.call, (s.plf._w, 'cmd',) + _flatten(args) )
def pladv( s, page ):
s.cmd( 'pladv', page )
def plaxes( s, x0, y0, xopt, xtick, nxsub, yopt, ytick, nysub ):
s.cmd( 'plaxes', x0, y0, xopt, xtick, nxsub, yopt, ytick, nysub )
def plbin(s): pass
def plbop(s):
s.cmd( 'plbop' )
def plbox( s, xopt, xtick, nxsub, yopt, ytick, nysub ):
s.cmd( 'plbox', xopt, xtick, nxsub, yopt, ytick, nysub )
def plbox3( s, xopt, xlabel, xtick, nsubx,
yopt, ylabel, ytick, nsuby,
zopt, zlabel, ztick, nsubz ):
s.cmd( 'plbox3',
xopt, xlabel, xtick, nsubx,
yopt, ylabel, ytick, nsuby,
zopt, zlabel, ztick, nsubz )
def plcol0( s, col0 ):
s.cmd( 'plcol0', col0 )
def plcol1( s, col1 ):
s.cmd( 'plcol1', col1 )
# def plcont( s ): pass
## def plcontxxx( s, z, kx, lx, ky, ly, clev, pltr, xg, yg, wrap ):
## plsstrm( s.strm )
## plcont( z, kx, lx, ky, ly, clev, pltr, xg, yg, wrap )
def plcont( s, *args ):
plsstrm( s.strm )
apply( plcont, args )
def plfcont( s ): pass
def plcpstream( s ): pass
def plenv( s, xmin, xmax, ymin, ymax, i, j ):
s.cmd( 'plenv', xmin, xmax, ymin, ymax, i, j )
def pleop(s):
s.cmd( 'pleop' )
#print "should've waited here, but it didn't."
s.plf.setvar( 'wv', '0' )
s.label_set( "Plotting paused ... (Hit Clear to continue)" )
#print "preparing to wait for wv to change"
s.plf.waitvar( 'wv' )
#print "it changed."
s.label_reset()
s.update()
def clearpage(s):
s.plf.setvar( 'wv', 1 )
def plfill( s, x, y ):
plsstrm( s.strm )
plfill( x, y )
def plfont( s, ifnt ):
s.cmd( 'plfont', ifnt )
def plfontld( s, fnt ):
s.cmd( 'plfontld', fnt )
def plhist( s, data, datmin, datmax, nbin, oldwin ):
plsstrm( s.strm )
plhist( data, datmin, datmax, nbin, oldwin )
def plhls( s, h, l, sat ):
s.cmd( 'plhls', h, l, sat )
def pljoin( s, x1, y1, x2, y2 ):
s.cmd( 'pljoin', x1, y1, x2, y2 )
def pllab( s, xlab, ylab, tlab ):
s.cmd( 'pllab', xlab, ylab, tlab )
def plline( s, x, y ):
plsstrm( s.strm )
plline( x, y )
def plline3( s, x, y, z ):
plsstrm( s.strm )
plline3( x, y, z )
def pllsty( s, lin ):
s.cmd( 'pllsty', lin )
# map and merridians ommitted.
def plmesh( s, x, y, z, opt ):
plsstrm( s.strm )
plmesh( x, y, z, opt )
def plmtex( s, side, disp, pos, just, text ):
s.cmd( 'plmtex', side, disp, pos, just, text )
def plot3d( s, x, y, z, opt, side ):
plsstrm( s.strm )
plplot3d( x, y, z, opt, side )
def plplot3d( s, x, y, z, opt, side ):
plsstrm( s.strm )
plplot3d( x, y, z, opt, side )
def plpoin( s, xs, ys, mark ):
plsstrm( s.strm )
plpoin( xs, ys, mark )
def plpoin3( s, x, y, z, code ):
plsstrm( s.strm )
plpoin3( x, y, z, code )
def plpoly3( s, x, y, z, draw ):
plsstrm( s.strm )
plpoly3( x, y, z, draw )
def plprec( s, setp, prec ):
s.cmd( 'plprec', setp, prec )
def plpsty( s, patt ):
s.cmd( 'plpsty', patt )
def plptex( s, x, y, dx, dy, just, text ):
s.cmd( 'plptex', x, y, dx, dy, just, text )
def plreplot( s ):
s.cmd( 'plreplot' )
def plrgb( s, r, g, b ):
s.cmd( 'plrgb', r, g, b )
def plrgb1( s, r, g, b ):
s.cmd( 'plrgb1', r, g, b )
def plschr( s, dflt, scale ):
s.cmd( 'plschr', dflt, scale )
def plshade( s, z, xmin, xmax, ymin, ymax,
sh_min, sh_max, sh_cmap, sh_color, sh_width,
min_col, min_wid, max_col, max_wid, rect,
pltr='pltr0', xg=None, yg=None, wrap=0 ):
"Color filled shad plot."
plsstrm( s.strm );
plshade( z, xmin, xmax, ymin, ymax,
sh_min, sh_max, sh_cmap, sh_color, sh_width,
min_col, min_wid, max_col, max_wid, rect,
pltr, xg, yg, wrap )
## def plshade2( s, z, xmin, xmax, ymin, ymax,
## sh_min, sh_max, sh_cmap, sh_color, sh_width,
## min_col, min_wid, max_col, max_wid, rect,
## pltr, xg, yg, wrap ):
## "Was unable to fix plshade, must make new plshade2, grrr."
##
## print "in plshade2"
## plsstrm( s.strm );
## plshade( z, xmin, xmax, ymin, ymax,
## sh_min, sh_max, sh_cmap, sh_color, sh_width,
## min_col, min_wid, max_col, max_wid, rect,
## pltr, xg, yg, wrap )
# Only works for special conditions so comment it out for now.
# def plsmem( ny, ny, plotmem ):
# s.cmd('plsmem', nx, ny plotmem )
def plssub( s, nx, ny ):
s.cmd( 'plssub', nx, ny )
def plssym( s, dflt, scale ):
s.cmd( 'plssym', dflt, scale )
# plstar and plstart not relevant
#def plstyl( s, ...
def plsvpa( s, xmin, xmax, ymin, ymax ):
s.cmd( 'plsvpa', xmin, xmax, ymin, ymax )
def plsxax( s, digmax, digits ):
s.cmd( 'plsxax', digmax, digits )
def plsyax( s, digmax, digits ):
s.cmd( 'plsyax', digmax, digits )
def plsym( s, x, y, code ):
plsstrm( s.strm )
plsym( x, y, code )
def plszax( s, digmax, digits ):
s.cmd( 'plszax', digmax, digits )
def plvasp( s, aspect ):
s.cmd( 'plvasp', aspect )
def plvpas( s, xmin, xmax, ymin, ymax, aspect ):
s.cmd( 'plvpas', xmin, xmax, ymin, ymax, aspect )
def plvpor( s, xmin, xmax, ymin, ymax ):
s.cmd( 'plvpor', xmin, xmax, ymin, ymax )
def plvsta(s):
s.cmd( 'plvsta' )
def plw3d( s, basex, basey, height, xmin0,
xmax0, ymin0, ymax0, zmin0, zmax0, alt, az):
s.cmd( 'plw3d',
basex, basey, height, xmin0,
xmax0, ymin0, ymax0, zmin0, zmax0, alt, az)
def plwid( s, width ):
s.cmd( 'plwid', width )
def plwind( s, xmin, xmax, ymin, ymax ):
s.cmd( 'plwind', xmin, xmax, ymin, ymax )
def debug(s):
print "Debugging dump for PlXframe:"
print "s.saveopt_dev = ", s.saveopt_dev
## End of Plframe.py
|