1# Copyright (C) 2004 Maurice LeBrun 2# 3# This file is part of PLplot. 4# 5# PLplot is free software; you can redistribute it and/or modify 6# it under the terms of the GNU Library General Public License as published 7# by the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# PLplot is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU Library General Public License for more details. 14# 15# You should have received a copy of the GNU Library General Public License 16# along with PLplot; if not, write to the Free Software 17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18# 19#---------------------------------------------------------------------------- 20# Sets default configuration options for plplot/TK driver. 21# Maurice LeBrun 22# IFS, University of Texas 23# 24# It is very easy to customize plplot/TK settings for a particular site 25# or user. The steps are: 26# 27# 1. Create a directory for holding app-defaults files. $HOME/app-defaults/ 28# is a good choice. Then set the XAPPLRESDIR environmental to this 29# pathname (keep trailing slash). 30# 31# 2. Create a plplot app-defaults file by the name of PLplot or plplot (PLplot 32# is loaded last and thus has preference, if both exist). It should use 33# standard X11 resource syntax. 34# 35# 3. If you wish to load resources based on a different class name, you should 36# call loadAppDefaults with suitable arguments after the pldefaults call. 37# 38# The older syntax using the plconfig.tcl file may still work but is 39# deprecated. 40# 41# BUGS: 42# - should probably replace some of the global variables with resources. 43# 44# Use something like this for widget font settings: 45# option add Tk.BoldFont "*-lucida sans-Bold-R-Normal-*-100-*" widgetDefault 46# 47#---------------------------------------------------------------------------- 48 49# From the TK FAQ, and modified to taste. 50 51# pl_getenv varName 52# Looks up the environment variable named $varName and returns its value 53# OR {} if it does not exist 54 55proc pl_getenv varName { 56 global env 57 if {[info exists env($varName)]} { return $env($varName) } 58} 59 60# loadAppDefaults classNameList ?priority? 61# Searches for the app-default files corresponding to classNames in 62# the order specified by X Toolkit Intrinsics, and loads them with 63# the priority specified (default: startupFile). Stops after first 64# file found for each class. 65 66proc pl_loadAppDefaults {classNameList {priority startupFile}} { 67 set filepath "[split [pl_getenv XUSERFILESEARCHPATH] :] \ 68 [pl_getenv XAPPLRESDIR] \ 69 [split [pl_getenv XFILESEARCHPATH] :] \ 70 /usr/lib/X11" 71 foreach i $classNameList { 72 foreach j $filepath { 73 if {[file exists $j/$i]} { 74 option readfile $j/$i $priority; break 75 } 76 } 77 } 78} 79 80#---------------------------------------------------------------------------- 81# Called by plplot based Tcl apps at startup to set resources. 82 83proc pldefaults {} { 84 #puts "loading library defaults" 85 pl_libdefaults 86 #puts "loading user defaults" 87 pl_loadAppDefaults {plplot PLplot} userDefault 88} 89 90#---------------------------------------------------------------------------- 91# Default resources. 92# This is largely based on options.motif.tk from Ioi K Lam's Tix package. 93# The TK options are set to be somewhat Motif-like. 94 95proc pl_libdefaults {} { 96 global tk_version 97 global gen_font 98 global gen_bold_font 99 global gen_menu_font 100 global gen_italic_font 101 global gen_font_small 102 global gen_bold_font_small 103 global gen_fixed_font 104 105 global dialog_font 106 global dialog_bold_font 107 108# Font-related resources. 109 110 set gen_font -*-helvetica-medium-r-normal-*-*-180-* 111 set gen_bold_font -*-helvetica-bold-r-normal-*-*-180-* 112 set gen_menu_font -*-helvetica-medium-o-normal-*-*-180-* 113 set gen_italic_font -*-helvetica-bold-o-normal-*-*-180-* 114 set gen_font_small -*-helvetica-medium-r-normal-*-*-120-* 115 set gen_bold_font_small -*-helvetica-bold-r-normal-*-*-120-* 116 set gen_fixed_font -*-courier-medium-r-normal-*-*-180-* 117 118 set dialog_font -*-times-medium-r-normal-*-*-180-* 119 set dialog_bold_font -*-times-bold-r-normal-*-*-180-* 120 121#---------------------------------------------------------------------------- 122# Color-related resources. 123# Sort of Motif-y. 124# It doesn't actually hurt to do this if not on a color system. 125 126 set gen_bg lightgray 127 set gen_fg black 128 set gen_darker_bg gray 129 set gen_darker_fg black 130 set gen_active_bg $gen_bg 131 set gen_active_fg $gen_fg 132 133 global tcl_platform 134 if {$tcl_platform(platform) == "unix"} { 135 # geometry of main window if plstdwin is used 136 # "auto" means derive size from root window dimensions 137 option add *geometry auto startupFile 138 139 # fonts 140 option add *font $gen_font startupFile 141 option add *Entry.font $gen_font startupFile 142 option add *Menu*font $gen_menu_font startupFile 143 option add *Menubutton*font $gen_menu_font startupFile 144 option add *Scale.font $gen_bold_font_small startupFile 145 option add *color.font $gen_fixed_font startupFile 146 147 # colors 148 option add *background $gen_bg startupFile 149 option add *foreground $gen_fg startupFile 150 option add *activeBackground $gen_active_bg startupFile 151 option add *activeForeground $gen_active_fg startupFile 152 option add *disabledForeground gray45 startupFile 153 option add *Checkbutton.selector yellow startupFile 154 option add *Radiobutton.selector yellow startupFile 155 #option add *Entry.background #c07070 startupFile 156 option add *Entry.foreground black startupFile 157 option add *Entry.insertBackground black startupFile 158 option add *Listbox.background $gen_darker_bg startupFile 159 option add *Scale.foreground $gen_fg startupFile 160 option add *Scale.activeForeground $gen_bg startupFile 161 option add *Scale.background $gen_bg startupFile 162 option add *Scale.sliderForeground $gen_bg startupFile 163 option add *Scale.sliderBackground $gen_darker_bg startupFile 164 option add *Scrollbar.background $gen_bg startupFile 165 option add *Scrollbar.troughColor $gen_darker_bg startupFile 166 167 # End of page indicator 168 169 option add *leop.off $gen_bg startupFile 170 option add *leop.on gray45 startupFile 171 172 # This specifies the default plplot widget background color. 173 # A white background looks better on grayscale or mono. 174 175 if {[winfo depth .] == 1} { 176 option add *Plframe.background white startupFile 177 } else { 178 option add *Plframe.background black startupFile 179 } 180 181 #---------------------------------------------------------------------------- 182 # Miscellaneous 183 184 option add *anchor w startupFile 185 option add *Button.borderWidth 2 startupFile 186 option add *Button.anchor c startupFile 187 option add *Checkbutton.borderWidth 2 startupFile 188 option add *Radiobutton.borderWidth 2 startupFile 189 option add *Label.anchor w startupFile 190 option add *Labelframe.borderWidth 2 startupFile 191 option add *Entry.relief sunken startupFile 192 option add *Scrollbar.relief sunken startupFile 193 194 # Preserve aspect ratio on zooming. Valid values: true|false. 195 option add *zoom_fixaspect true startupFile 196 197 # Location of initial point when zooming. Valid values: corner|center. 198 option add *zoom_startfrom center startupFile 199 200 # Name of default save device. Valid values are installation-dependent, 201 # but you might try one of: ps, psc, plm, png, jpeg. 202 option add *save_dev psc startupFile 203 204 # Multi plots per file. If true, must explicitly close it before exiting! 205 option add *save_multi false startupFile 206 207 # I have this in here so that applications written before Tk 4.0 still 208 # look the same. More selectivity might be better. 209 210 option add *highlightThickness 0 startupFile 211 212 # Have focus follow mouse, only available in Tk 4.0+ 213 # This is needed if you want to control scales using keystrokes. 214 215 tk_focusFollowsMouse 216 } 217 218# Various options -- use global variables for simplicity. 219 220# Scale widget bindings 221 222 bind Scale <Button-1> {%W set [%W get %x %y] } 223 bind Scale <B1-Motion> {%W set [%W get %x %y] } 224 225# Key shortcut definitions -- change them if you want! 226# Turn them into an empty string to disable. 227 228 global key_resume; set key_resume "Return" 229 global key_zoom_select; set key_zoom_select "z" 230 global key_zoom_back; set key_zoom_back "b" 231 global key_zoom_forward; set key_zoom_forward "f" 232 global key_zoom_reset; set key_zoom_reset "r" 233 global key_print; set key_print "P" 234 global key_save_again; set key_save_again "s" 235 global key_scroll_right; set key_scroll_right "Right" 236 global key_scroll_left; set key_scroll_left "Left" 237 global key_scroll_up; set key_scroll_up "Up" 238 global key_scroll_down; set key_scroll_down "Down" 239 global key_scroll_mag; set key_scroll_mag "5" 240 global key_scroll_speed; set key_scroll_speed "1" 241 242# enable/disable top plot and file menu 243 244 global file_menu_on; set file_menu_on "1" 245 global plot_menu_on; set plot_menu_on "1" 246 247 bind . <m> {toggle_menus %W} 248 249 setup_cursorkeybindings 250} 251 252proc toggle_menus {w} { 253 global file_menu_on plot_menu_on 254 255 if {$file_menu_on} { 256 pack forget .menu 257 pack forget [winfo parent $w].ftop 258 set file_menu_on 0 259 } else { 260 pack .menu -fill x 261 pack [winfo parent $w].ftop -fill x -before [winfo parent $w].plwin 262 set file_menu_on 1 263 } 264} 265 266proc plw_moveCursor {w x y xd yd} { 267 # If not an activeplot, then return. 268 if {[catch {set activeplot [$w cget -activeplot]}]} {return} 269 if {!$activeplot} {return} 270 incr x $xd 271 incr y $yd 272 # Move the cursor as directed. 273 event generate $w <Motion> -warp 1 -x $x -y $y 274} 275 276# Set up cursor-keybindings so that they can be used to 277# manipulate the pointer on top of active Plframes. 278proc setup_cursorkeybindings {} { 279 foreach combo { 280 {} 281 Shift Option Control 282 {Shift Option} {Shift Control} {Option Control} 283 {Shift Option Control} 284 } { 285 set multiply 1 286 for {set i 0} {$i < [llength $combo]} {incr i} { 287 set multiply [expr {$multiply * 5}] 288 } 289 if {[llength $combo]} { 290 set prefix "[join $combo -]-" 291 } else { 292 set prefix "" 293 } 294 foreach dir {Left Right Up Down} x {-1 1 0 0} y {0 0 -1 1} { 295 bind Plframe <${prefix}$dir> "plw_moveCursor %W %x %y\ 296 [expr {$x * $multiply}] [expr {$y * $multiply}]" 297 } 298 } 299} 300