Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/Adding+Tk+to+an+Existing+Xt+Program?V=5
QUERY_STRINGV=5
CONTENT_TYPE
DOCUMENT_URI/revision/Adding+Tk+to+an+Existing+Xt+Program
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.71.223.187
REMOTE_PORT55246
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR44.201.96.213
HTTP_CF_RAY86c0feeb6fcb29b8-IAD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTclaudebot
HTTP_CF_CONNECTING_IP44.201.96.213
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {Adding Tk to an Existing Xt Program} {'''Updated Sep 1, 2004 to have proper links.'''

[George Peter Staplin]: 2001 Thu Sep 13 - This is a nice example for those of you that have an existing Xt program and want to add Tk.  This could also be a solution for those of you that have existing custom Xt widgets, and want to use Tk widgets as well.  I place the code below in the public domain.  Use it however you want.  It does have some issues, such as timers not working because of the event loop, and file handlers not triggering on write/read.  For the file handler issue I have a solution at the bottom.


(I was new to Xaw/Xt/Tk's event loop when I wrote this.  This code could use a little cleanup, and the FAQ entry at the end has a good solution as well.  There aren't a lot of examples of Xaw usage in modern applications, but it's an interesting toolkit.)
----
===C
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <X11/Intrinsic.h> 
  #include <X11/StringDefs.h> 
  #include <X11/IntrinsicP.h>
  #include <X11/Xaw/Command.h>  
  #include <X11/Xaw/Box.h>
  #include <X11/Xaw/Form.h>
  #include <X11/Xaw/AsciiText.h>
  #include <tcl.h>
  #include <tk.h>
  
  Tcl_Interp *interp;
  Display *dis;
  int screen;
  
  #define winIdLength 16
                                  
  void PressMe () {
          fprintf (stderr, "You pressed me.\n");
  }
  
                  
  void Action () { 
          fprintf (stderr, "Now I'm going to exit.\n");
          exit (0); 
  }
  
  
  void addTkToplevelToXtBox (char *winName, Widget parent) {
          char tCmd[] = "toplevel $winName -use $winId";
          char winId[winIdLength];
                  
          sprintf (winId, "%ld", XtWindow (parent)); 
          
          Tcl_SetVar (interp, "winName", winName, 0);
          Tcl_SetVar (interp, "winId", winId, 0);
  
          if (Tcl_Eval (interp, tCmd) != TCL_OK) {
                  fprintf (stderr, "Error evaluating tCmd within addTkToplevelToXtBoxCmd() %s", Tcl_GetStringResult (interp));
          }
  }
  
  
  Widget addXtBox (char *wClass, Widget wParent) {
  
          return (XtVaCreateManagedWidget (
                  wClass,
                  boxWidgetClass,
                  wParent,
                  NULL,
                  0)
          );
  }
  
  
  void makeXtBoxFitToplevel (Widget wid, char *winName) {
          Tk_Window twin = Tk_NameToWindow (interp, winName, Tk_MainWindow (interp));
          Tcl_Eval (interp, "update idletasks");
          XtResizeWidget (wid, Tk_Width (twin), Tk_Height (twin), 1);
          XFlush (dis);        
  }
  
  
  int main (int argc, char *argv[]) {
          Widget win, button;
          Widget testButton;
          Widget buttonShell;
          Widget xtBox2;
          Widget entry;
          XEvent event;
          XtAppContext appContext;
          char entryBuffer;
                  
  
          Tcl_FindExecutable (argv[0]);
          interp = Tcl_CreateInterp ();
  
          if (Tcl_Init (interp) != TCL_OK) {
                  fprintf (stderr, "Tcl_Init error"); 
                  exit (-1);
          }
  
          if (Tk_Init (interp) != TCL_OK) {
                  fprintf (stderr, "Tk_Init error");
                  exit (-1);
          }
  
  
          win = XtVaAppInitialize(
                  &appContext,          
                  "mainWindow",           
                  NULL, 
                  0,                
                  &argc, 
                  argv,      
                  NULL,
                  0
          );   
  
  
          dis = XtDisplay (win);               
          screen = DefaultScreen (dis);
  
          buttonShell = addXtBox ("mainPanel", win);
  
          testButton = XtVaCreateManagedWidget (
                  "Press Me",
                  commandWidgetClass,
                  buttonShell,
                  NULL,
                  0
          );
          
          button = XtVaCreateManagedWidget (
                  "Exit",              
                  commandWidgetClass,     
                  buttonShell,               
                  NULL,
                  0
          );      
  
  
          xtBox2 = addXtBox ("xtBox2", buttonShell);
  
          entry = XtVaCreateManagedWidget (
                  "entry",
                  asciiTextWidgetClass, 
                  buttonShell,
                  XtNtype, XawAsciiString,
                  XtNlength, sizeof (entryBuffer),
                  XtNeditType, XawtextEdit,
                  NULL,
                  0
          ) ;
  
  
          XtRealizeWidget (win);
          XtAddCallback (button, XtNcallback, Action, 0);
          XtAddCallback (testButton, XtNcallback, PressMe, 0);
          XtResizeWidget (win, 400, 400, 1);
          /*This MUST be here:*/
          XSync (dis, 0);
  
                  
          addTkToplevelToXtBox (".t", xtBox2);
  
          if (Tcl_EvalFile (interp, "test_script") != TCL_OK) {
                  fprintf (stderr, "Tcl_EvalFile error %s", Tcl_GetStringResult (interp));
          }
  
          makeXtBoxFitToplevel (xtBox2, ".t");
                  
          
          {
                  fd_set readfds;
                  int nfds;
                  int tkFd = ConnectionNumber (Tk_Display (Tk_MainWindow (interp)));
                  int xtFd = ConnectionNumber (XtDisplay (win));
                  
                  nfds = (tkFd > xtFd) ? tkFd : xtFd;
                  nfds++;
  
                  for (;;) {
                          FD_ZERO (&readfds);
                          FD_SET (tkFd, &readfds);
                          FD_SET (xtFd, &readfds);
  
                          select (nfds, &readfds, NULL, NULL, (struct timeval *) NULL);
          
                          while (XtAppPending (appContext) > 0) {
                                  XtAppNextEvent (appContext, &event);
                                  XtDispatchEvent (&event);
                          }
                  
                          while (Tcl_DoOneEvent (TCL_DONT_WAIT))
                          ;                        
                  }
          }        
  return 0;
  }
===  
----
The source code above invokes Tcl_EvalFile on test_script, which in this case looks like the code below:
----
======
  proc main {} {        
          wm withdraw .
  
          pack [button .t.b -text Hello -command {puts Hello}]
          pack [listbox .t.l]
          pack [button .t.b2 -text {Can you see me?} -command {.t.l insert end Yes}] -fill x
          .t.l insert end {John Doe} {Jane Doe}
  }
  main
======

----
Download a working example here (Linux users add -ldl to the Makefile): http://www.xmission.com/~georgeps/documentation/examples/TclTk_With_Others Note: You may need to change -ltcl83 and -ltk83 using a scheme like -ltcl8.3, depending on the name of your libtcl and libtk libraries.

It looks like this:
[http://www.xmission.com/~georgeps/images/wiki/TclTk_With_Xt.png]
----
You can solve the file handler problem using something like this:

int data;

Tcl_GetChannelHandle (Tcl_GetChannel (interp, Tcl_GetVar (interp, "inputSocket", NULL), NULL), TCL_READABLE, &data);

Then add the data to the FD_SET but make sure that nfds is one greater than the largest file descriptor.  See my Panache window manager if you need more of an example.

----
Of related interest is this
[http://tcl.sourceforge.net/faqs/tk/#wm/Tk-Xt]
FAQ entry.

<<categories>> Tk | GUI} regexp2} CALL {my render {Adding Tk to an Existing Xt Program} {'''Updated Sep 1, 2004 to have proper links.'''

[George Peter Staplin]: 2001 Thu Sep 13 - This is a nice example for those of you that have an existing Xt program and want to add Tk.  This could also be a solution for those of you that have existing custom Xt widgets, and want to use Tk widgets as well.  I place the code below in the public domain.  Use it however you want.  It does have some issues, such as timers not working because of the event loop, and file handlers not triggering on write/read.  For the file handler issue I have a solution at the bottom.


(I was new to Xaw/Xt/Tk's event loop when I wrote this.  This code could use a little cleanup, and the FAQ entry at the end has a good solution as well.  There aren't a lot of examples of Xaw usage in modern applications, but it's an interesting toolkit.)
----
===C
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <X11/Intrinsic.h> 
  #include <X11/StringDefs.h> 
  #include <X11/IntrinsicP.h>
  #include <X11/Xaw/Command.h>  
  #include <X11/Xaw/Box.h>
  #include <X11/Xaw/Form.h>
  #include <X11/Xaw/AsciiText.h>
  #include <tcl.h>
  #include <tk.h>
  
  Tcl_Interp *interp;
  Display *dis;
  int screen;
  
  #define winIdLength 16
                                  
  void PressMe () {
          fprintf (stderr, "You pressed me.\n");
  }
  
                  
  void Action () { 
          fprintf (stderr, "Now I'm going to exit.\n");
          exit (0); 
  }
  
  
  void addTkToplevelToXtBox (char *winName, Widget parent) {
          char tCmd[] = "toplevel $winName -use $winId";
          char winId[winIdLength];
                  
          sprintf (winId, "%ld", XtWindow (parent)); 
          
          Tcl_SetVar (interp, "winName", winName, 0);
          Tcl_SetVar (interp, "winId", winId, 0);
  
          if (Tcl_Eval (interp, tCmd) != TCL_OK) {
                  fprintf (stderr, "Error evaluating tCmd within addTkToplevelToXtBoxCmd() %s", Tcl_GetStringResult (interp));
          }
  }
  
  
  Widget addXtBox (char *wClass, Widget wParent) {
  
          return (XtVaCreateManagedWidget (
                  wClass,
                  boxWidgetClass,
                  wParent,
                  NULL,
                  0)
          );
  }
  
  
  void makeXtBoxFitToplevel (Widget wid, char *winName) {
          Tk_Window twin = Tk_NameToWindow (interp, winName, Tk_MainWindow (interp));
          Tcl_Eval (interp, "update idletasks");
          XtResizeWidget (wid, Tk_Width (twin), Tk_Height (twin), 1);
          XFlush (dis);        
  }
  
  
  int main (int argc, char *argv[]) {
          Widget win, button;
          Widget testButton;
          Widget buttonShell;
          Widget xtBox2;
          Widget entry;
          XEvent event;
          XtAppContext appContext;
          char entryBuffer;
                  
  
          Tcl_FindExecutable (argv[0]);
          interp = Tcl_CreateInterp ();
  
          if (Tcl_Init (interp) != TCL_OK) {
                  fprintf (stderr, "Tcl_Init error"); 
                  exit (-1);
          }
  
          if (Tk_Init (interp) != TCL_OK) {
                  fprintf (stderr, "Tk_Init error");
                  exit (-1);
          }
  
  
          win = XtVaAppInitialize(
                  &appContext,          
                  "mainWindow",           
                  NULL, 
                  0,                
                  &argc, 
                  argv,      
                  NULL,
                  0
          );   
  
  
          dis = XtDisplay (win);               
          screen = DefaultScreen (dis);
  
          buttonShell = addXtBox ("mainPanel", win);
  
          testButton = XtVaCreateManagedWidget (
                  "Press Me",
                  commandWidgetClass,
                  buttonShell,
                  NULL,
                  0
          );
          
          button = XtVaCreateManagedWidget (
                  "Exit",              
                  commandWidgetClass,     
                  buttonShell,               
                  NULL,
                  0
          );      
  
  
          xtBox2 = addXtBox ("xtBox2", buttonShell);
  
          entry = XtVaCreateManagedWidget (
                  "entry",
                  asciiTextWidgetClass, 
                  buttonShell,
                  XtNtype, XawAsciiString,
                  XtNlength, sizeof (entryBuffer),
                  XtNeditType, XawtextEdit,
                  NULL,
                  0
          ) ;
  
  
          XtRealizeWidget (win);
          XtAddCallback (button, XtNcallback, Action, 0);
          XtAddCallback (testButton, XtNcallback, PressMe, 0);
          XtResizeWidget (win, 400, 400, 1);
          /*This MUST be here:*/
          XSync (dis, 0);
  
                  
          addTkToplevelToXtBox (".t", xtBox2);
  
          if (Tcl_EvalFile (interp, "test_script") != TCL_OK) {
                  fprintf (stderr, "Tcl_EvalFile error %s", Tcl_GetStringResult (interp));
          }
  
          makeXtBoxFitToplevel (xtBox2, ".t");
                  
          
          {
                  fd_set readfds;
                  int nfds;
                  int tkFd = ConnectionNumber (Tk_Display (Tk_MainWindow (interp)));
                  int xtFd = ConnectionNumber (XtDisplay (win));
                  
                  nfds = (tkFd > xtFd) ? tkFd : xtFd;
                  nfds++;
  
                  for (;;) {
                          FD_ZERO (&readfds);
                          FD_SET (tkFd, &readfds);
                          FD_SET (xtFd, &readfds);
  
                          select (nfds, &readfds, NULL, NULL, (struct timeval *) NULL);
          
                          while (XtAppPending (appContext) > 0) {
                                  XtAppNextEvent (appContext, &event);
                                  XtDispatchEvent (&event);
                          }
                  
                          while (Tcl_DoOneEvent (TCL_DONT_WAIT))
                          ;                        
                  }
          }        
  return 0;
  }
===  
----
The source code above invokes Tcl_EvalFile on test_script, which in this case looks like the code below:
----
======
  proc main {} {        
          wm withdraw .
  
          pack [button .t.b -text Hello -command {puts Hello}]
          pack [listbox .t.l]
          pack [button .t.b2 -text {Can you see me?} -command {.t.l insert end Yes}] -fill x
          .t.l insert end {John Doe} {Jane Doe}
  }
  main
======

----
Download a working example here (Linux users add -ldl to the Makefile): http://www.xmission.com/~georgeps/documentation/examples/TclTk_With_Others Note: You may need to change -ltcl83 and -ltk83 using a scheme like -ltcl8.3, depending on the name of your libtcl and libtk libraries.

It looks like this:
[http://www.xmission.com/~georgeps/images/wiki/TclTk_With_Xt.png]
----
You can solve the file handler problem using something like this:

int data;

Tcl_GetChannelHandle (Tcl_GetChannel (interp, Tcl_GetVar (interp, "inputSocket", NULL), NULL), TCL_READABLE, &data);

Then add the data to the FD_SET but make sure that nfds is one greater than the largest file descriptor.  See my Panache window manager if you need more of an example.

----
Of related interest is this
[http://tcl.sourceforge.net/faqs/tk/#wm/Tk-Xt]
FAQ entry.

<<categories>> Tk | GUI}} CALL {my revision {Adding Tk to an Existing Xt Program}} CALL {::oo::Obj1420182 process revision/Adding+Tk+to+an+Existing+Xt+Program} CALL {::oo::Obj1420180 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4