PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
tkshell.c
Go to the documentation of this file.
1 // $Id: tkshell.c 12084 2011-12-01 20:27:18Z andrewross $
2 //
3 // Maurice LeBrun
4 // 6-May-93
5 //
6 // A miscellaneous assortment of Tcl support functions.
7 //
8 //
9 // Copyright (C) 2004 Joao Cardoso
10 //
11 // This file is part of PLplot.
12 //
13 // PLplot is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU Library General Public License as published
15 // by the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // PLplot is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU Library General Public License
24 // along with PLplot; if not, write to the Free Software
25 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 //
27 
28 #include "plserver.h"
29 
30 //--------------------------------------------------------------------------
31 // Pltk_Init
32 //
33 // Initialization routine for extended wish'es.
34 // Creates the plframe, matrix, wait_until, and host_id (w/Tcl-DP only)
35 // commands. Also sets the auto_path variable.
36 //--------------------------------------------------------------------------
37 
38 int
39 Pltk_Init( Tcl_Interp *interp )
40 {
41  Tk_Window main;
42 
43  main = Tk_MainWindow( interp );
44 
45 // plframe -- PLplot graphing widget
46 
47  Tcl_CreateCommand( interp, "plframe", (Tcl_CmdProc *) plFrameCmd,
48  (ClientData) main, (Tcl_CmdDeleteProc *) NULL );
49 
50 // matrix -- matrix support command
51 
52  Tcl_CreateCommand( interp, "matrix", (Tcl_CmdProc *) Tcl_MatrixCmd,
53  (ClientData) main, (Tcl_CmdDeleteProc *) NULL );
54 
55 // wait_until -- waits for a specific condition to arise
56 // Can be used with either Tcl-DP or TK
57 
58  Tcl_CreateCommand( interp, "wait_until", (Tcl_CmdProc *) plWait_Until,
59  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL );
60 
61 // host_id -- returns host IP number. Only for use with Tcl-DP
62 
63 #ifdef PLD_dp
64  Tcl_CreateCommand( interp, "host_id", (Tcl_CmdProc *) plHost_ID,
65  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL );
66 #endif
67 
68 // Set up auto_path
69 
70  if ( pls_auto_path( interp ) == TCL_ERROR )
71  return TCL_ERROR;
72 
73 // Save initial RGB colormap components
74 // Disabled for now
75 
76 #if 0
77  {
78  Display *display;
79  Colormap map;
80 
81  display = Tk_Display( main );
82  map = DefaultColormap( display, DefaultScreen( display ) );
83 
84 // Convert this to use esc function if it's going to be used
85 // SaveColormap(display, map);
86  }
87 #endif
88  return TCL_OK;
89 }
90 
91 //--------------------------------------------------------------------------
92 // plWait_Until
93 //
94 // Tcl command -- wait until the specified condition is satisfied.
95 // Processes all events while waiting.
96 //
97 // This command is more capable than tkwait, and has the added benefit
98 // of working with Tcl-DP as well. Example usage:
99 //
100 // wait_until {[info exists foobar]}
101 //
102 // Note the [info ...] command must be protected by braces so that it
103 // isn't actually evaluated until passed into this routine.
104 //--------------------------------------------------------------------------
105 
106 int
107 plWait_Until( ClientData clientData, Tcl_Interp *interp, int argc, char **argv )
108 {
109  int result = 0;
110 
111  dbug_enter( "plWait_Until" );
112 
113  for (;; )
114  {
115  if ( Tcl_ExprBoolean( interp, argv[1], &result ) )
116  {
117  fprintf( stderr, "wait_until command \"%s\" failed:\n\t %s\n",
118  argv[1], Tcl_GetStringResult( interp ) );
119  break;
120  }
121  if ( result )
122  break;
123 
124  Tk_DoOneEvent( 0 );
125  }
126  return TCL_OK;
127 }