Skip to content

Commit c588367

Browse files
authored
Merge pull request #3739 from BsAtHome/fix_tcl9-part2
Fix running with tcl/tk 9
2 parents 91af271 + 969ee42 commit c588367

10 files changed

Lines changed: 79 additions & 37 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.var
22
*.var.bak
33
position*.txt
4-
4+
qtaxis.pref
5+
qtvcp/

lib/python/rs274/OpenGLTk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ def tkPrint(self, file):
380380
self.activate()
381381

382382
def zoomwheel(self, event):
383-
if event.delta > 0: self.zoomin(event)
384-
else: self.zoomout(event)
383+
if event.delta > 0: self.zoomin()
384+
else: self.zoomout()
385385

386386
def tkStartZoom(self, event):
387387
self.startZoom(event.y)

src/configure.ac

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ if test "xyes" = "x$RUN_IN_PLACE"; then
700700
EMC2_HELP_DIR=$EMC2_HOME/docs/help
701701
EMC2_RTLIB_DIR=$EMC2_HOME/rtlib
702702
LINUXCNC_CONFIG_PATH="~/linuxcnc/configs:$EMC2_HOME/configs"
703+
LINUXCNC_CONFIG_PATH_TCL="$::env(HOME)/linuxcnc/configs:$EMC2_HOME/configs"
703704
EMC2_NCFILES_DIR=$EMC2_HOME/nc_files
704705
REALTIME=$EMC2_HOME/scripts/realtime
705706
EMC2_IMAGE_DIR=$EMC2_HOME
@@ -722,6 +723,7 @@ else
722723
*) EMC2_RTLIB_DIR=$MODULE_DIR/linuxcnc
723724
esac
724725
LINUXCNC_CONFIG_PATH="~/linuxcnc/configs:/usr/local/etc/linuxcnc/configs:"$(eval echo $EMC2_HELP_DIR)"/examples/sample-configs"
726+
LINUXCNC_CONFIG_PATH_TCL="$::env(HOME)/linuxcnc/configs:/usr/local/etc/linuxcnc/configs:"$(eval echo $EMC2_HELP_DIR)"/examples/sample-configs"
725727
EMC2_NCFILES_DIR=${prefix}/share/linuxcnc/ncfiles
726728
REALTIME=${prefix}/lib/linuxcnc/realtime
727729
EMC2_IMAGE_DIR=$(fe "$datadir")/linuxcnc
@@ -746,6 +748,7 @@ AC_SUBST([EMC2_HELP_DIR])
746748
AC_SUBST([EMC2_RTLIB_DIR])
747749
AC_SUBST([EMC2_LANG_DIR])
748750
AC_SUBST([LINUXCNC_CONFIG_PATH])
751+
AC_SUBST([LINUXCNC_CONFIG_PATH_TCL])
749752
AC_SUBST([EMC2_NCFILES_DIR])
750753
AC_SUBST([REALTIME])
751754
AC_SUBST([EMC2_IMAGE_DIR])
@@ -1354,9 +1357,9 @@ if test -z "$TKCONFIG"; then
13541357
fi
13551358
if (test "x$TKCONFIG" = "x"); then
13561359
# search for tkConfig.sh
1357-
TKCONFIG=$(find /usr/lib -maxdepth 2 -name tkConfig.sh | sort -r | head -n1)
1360+
TKCONFIG=$(find /usr/lib* -maxdepth 2 -name tkConfig.sh | sort -r | head -n1)
13581361
if (test "x$TKCONFIG" = "x"); then
1359-
TKCONFIG=$(find /usr/local/lib -maxdepth 2 -name tkConfig.sh | head -n1)
1362+
TKCONFIG=$(find /usr/local/lib* -maxdepth 2 -name tkConfig.sh | head -n1)
13601363
fi
13611364
fi
13621365

@@ -1380,6 +1383,14 @@ Tcl $TCL_VERSION and Tk $TK_VERSION. You can use --with-tkConfig= and --with-tc
13801383
to override the autodetected versions.])
13811384
fi
13821385

1386+
if test -z "$TCL_MAJOR_VERSION" || test -z "$TCL_MINOR_VERSION" ; then
1387+
AC_MSG_ERROR([tclConfig was not found or did not export TCL_MAJOR_VERSION/TCL_MINOR_VERSION. Cannot determine exact Tcl version.])
1388+
fi
1389+
1390+
if test "(" "$TCL_MAJOR_VERSION" -lt 8 ")" -o "(" "(" "$TCL_MAJOR_VERSION" -eq 8 ")" -a "(" "$TCL_MINOR_VERSION" -lt 4 ")" ")" ; then
1391+
AC_MSG_ERROR([Tcl version must be 8.4 or better. Your Tcl version ${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION} is too old.])
1392+
fi
1393+
13831394
if test -f $TCL_EXEC_PREFIX/bin/wish$TCL_VERSION; then
13841395
WISH=$TCL_EXEC_PREFIX/bin/wish$TCL_VERSION
13851396
elif test -f $TCL_EXEC_PREFIX/bin/wish; then
@@ -1424,13 +1435,16 @@ if test "$RUNTIME_CHECK" = "yes"; then
14241435
AC_MSG_RESULT([not found])
14251436
fi
14261437

1427-
AC_MSG_CHECKING([for tclX using $TCLSH])
1428-
if (unset DISPLAY; echo ["catch { package require Tclx }; exit [expr [lsearch [package names] Tclx] == -1]"] | $TCLSH); then
1429-
AC_MSG_RESULT([found])
1430-
else
1431-
AC_MSG_RESULT(no)
1432-
AC_MSG_ERROR([Tclx not found!
1433-
install with "sudo apt-get install tclx"])
1438+
# Don't need tclX anymore in Tcl9
1439+
if test "$TCL_MAJOR_VERSION" -lt 9; then
1440+
AC_MSG_CHECKING([for tclX using $TCLSH])
1441+
if (unset DISPLAY; echo ["catch { package require Tclx }; exit [expr [lsearch [package names] Tclx] == -1]"] | $TCLSH); then
1442+
AC_MSG_RESULT([found])
1443+
else
1444+
AC_MSG_RESULT(no)
1445+
AC_MSG_ERROR([Tclx not found!
1446+
install with "sudo apt-get install tclx"])
1447+
fi
14341448
fi
14351449

14361450
AC_MSG_CHECKING([for python pango module])

src/emc/usr_intf/axis/extensions/_toglmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ PyObject *install(PyObject *s, PyObject *arg) {
3333
PyErr_SetString(PyExc_TypeError, "get_interpreter() returned NULL");
3434
return NULL;
3535
}
36-
if (Tcl_InitStubs(trp, "8.1", 0) == NULL)
36+
if (Tcl_InitStubs(trp, TCL_VERSION, 0) == NULL)
3737
{
3838
PyErr_SetString(PyExc_RuntimeError, "Tcl_InitStubs returned NULL");
3939
return NULL;
4040
}
41-
if (Tk_InitStubs(trp, "8.1", 0) == NULL)
41+
if (Tk_InitStubs(trp, TK_VERSION, 0) == NULL)
4242
{
4343
PyErr_SetString(PyExc_RuntimeError, "Tk_InitStubs returned NULL");
4444
return NULL;

src/emc/usr_intf/axis/extensions/togl.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
#undef Tcl_InitHashTable
7979
#define Tcl_InitHashTable (tclStubsPtr->tcl_InitHashTable)
8080
#endif
81-
#if (TK_MAJOR_VERSION>=8 && TK_MINOR_VERSION>=4)
81+
#if TK_MAJOR_VERSION * 100 + TK_MINOR_VERSION >= 804
8282
# define HAVE_TK_SETCLASSPROCS
8383
#endif
8484

@@ -87,6 +87,14 @@
8787
* (this is needed for Tcl ver =< 8.4a3)
8888
*/
8989

90+
#ifndef _ANSI_ARGS_
91+
#define _ANSI_ARGS_(x) x
92+
#endif
93+
94+
#ifndef Tk_Offset
95+
#define Tk_Offset offsetof
96+
#endif
97+
9098
typedef int (TkBindEvalProc) _ANSI_ARGS_((ClientData clientData,
9199
Tcl_Interp *interp, XEvent *eventPtr, Tk_Window tkwin,
92100
KeySym keySym));
@@ -700,18 +708,18 @@ int Togl_Init(Tcl_Interp *interp)
700708
int major,minor,patchLevel,releaseType;
701709

702710
#ifdef USE_TCL_STUBS
703-
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {return TCL_ERROR;}
711+
if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {return TCL_ERROR;}
704712
#endif
705713
#ifdef USE_TK_STUBS
706-
if (Tk_InitStubs(interp, "8.1", 0) == NULL) {return TCL_ERROR;}
714+
if (Tk_InitStubs(interp, TK_VERSION, 0) == NULL) {return TCL_ERROR;}
707715
#endif
708716

709717
/* Skip all this on Tcl/Tk 8.0 or older. Seems to work */
710718
#if TCL_MAJOR_VERSION * 100 + TCL_MINOR_VERSION > 800
711719
Tcl_GetVersion(&major,&minor,&patchLevel,&releaseType);
712720

713721
#ifndef HAVE_TK_SETCLASSPROCS
714-
if (major >= 8 && minor >= 4) {
722+
if (major * 100 + minor >= 804) {
715723
TCL_ERR(interp,"Sorry, this instance of Togl was not compiled to work with Tcl/Tk 8.4 or higher.");
716724
}
717725
#endif
@@ -1049,13 +1057,26 @@ int Togl_Configure(Tcl_Interp *interp, struct Togl *togl,
10491057
int oldStencilSize = togl->StencilSize;
10501058
int oldAuxNumber = togl->AuxNumber;
10511059

1052-
#ifndef CONST84
1053-
#define CONST84
1060+
#if TK_MAJOR_VERSION >= 9
1061+
// Version 9+ uses Tcl_Obj* array as config whereas older uses a char* array
1062+
Tcl_Obj **optr = calloc(argc+1, sizeof(*optr)); // argc+1 to terminate list with a NULL pointer
1063+
for(int u = 0; u < argc; u++) {
1064+
optr[u] = Tcl_NewStringObj(argv[u], -1);
1065+
}
1066+
#else
1067+
char **optr = argv;
10541068
#endif
10551069
if (Tk_ConfigureWidget(interp, togl->TkWin, configSpecs,
1056-
argc, (CONST84 char**)argv, (char *)togl, flags) == TCL_ERROR) {
1070+
argc, (void *)optr, (char *)togl, flags) == TCL_ERROR) {
10571071
return(TCL_ERROR);
10581072
}
1073+
#if TK_VERSION_MAJOR >= 9
1074+
for(int u = 0; u < argc; u++) {
1075+
Tcl_DecrRefCount(optr[u]);
1076+
}
1077+
free(optr);
1078+
#endif
1079+
10591080
#ifndef USE_OVERLAY
10601081
if (togl->OverlayFlag) {
10611082
TCL_ERR(interp,"Sorry, overlay was disabled");
@@ -1126,7 +1147,7 @@ int Togl_Widget(ClientData clientData, Tcl_Interp *interp,
11261147
return TCL_ERROR;
11271148
}
11281149

1129-
Tk_Preserve((ClientData)togl);
1150+
Tcl_Preserve((ClientData)togl);
11301151

11311152
if (!strncmp(argv[1], "configure", MAX(1, strlen(argv[1])))) {
11321153
if (argc == 2) {
@@ -1237,12 +1258,10 @@ int Togl_Widget(ClientData clientData, Tcl_Interp *interp,
12371258
}
12381259
}
12391260

1240-
Tk_Release((ClientData)togl);
1261+
Tcl_Release((ClientData)togl);
12411262
return result;
12421263
}
12431264

1244-
1245-
12461265
/*
12471266
* Togl_Cmd
12481267
*
@@ -1421,7 +1440,7 @@ static int Togl_Cmd(ClientData clientData, Tcl_Interp *interp,
14211440

14221441
/* If defined, setup timer */
14231442
if (togl->TimerProc){
1424-
Tk_CreateTimerHandler( togl->TimerInterval, Togl_Timer, (ClientData)togl );
1443+
Tcl_CreateTimerHandler( togl->TimerInterval, Togl_Timer, (ClientData)togl );
14251444
}
14261445

14271446
Tcl_AppendResult(interp, Tk_PathName(tkwin), NULL);
@@ -2153,7 +2172,11 @@ static void ToglCmdDeletedProc( ClientData clientData )
21532172
* Gets called when an Togl widget is destroyed.
21542173
*/
21552174
#if (TK_MAJOR_VERSION * 100 + TK_MINOR_VERSION) >= 401
2175+
#if TK_MAJOR_VERSION >= 9
2176+
static void Togl_Destroy( void *clientData )
2177+
#else
21562178
static void Togl_Destroy( char *clientData )
2179+
#endif
21572180
#else
21582181
static void Togl_Destroy( ClientData clientData )
21592182
#endif
@@ -2284,7 +2307,7 @@ void Togl_PostRedisplay( struct Togl *togl )
22842307
{
22852308
if (!togl->UpdatePending) {
22862309
togl->UpdatePending = GL_TRUE;
2287-
Tk_DoWhenIdle( Togl_Render, (ClientData) togl );
2310+
Tcl_DoWhenIdle( Togl_Render, (ClientData) togl );
22882311
}
22892312
}
22902313

@@ -2863,7 +2886,7 @@ void Togl_PostOverlayRedisplay( struct Togl *togl )
28632886
{
28642887
if (!togl->OverlayUpdatePending
28652888
&& togl->OverlayWindow && togl->OverlayDisplayProc) {
2866-
Tk_DoWhenIdle( RenderOverlay, (ClientData) togl );
2889+
Tcl_DoWhenIdle( RenderOverlay, (ClientData) togl );
28672890
togl->OverlayUpdatePending = 1;
28682891
}
28692892
}

src/emc/usr_intf/axis/scripts/axis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ def __init__(self, title, text, default, unit_str=''):
16601660
self.buttons = f = Tkinter.Frame(t)
16611661
self.ok = Tkinter.Button(f, text=_("OK"), command=self.do_ok, width=10,height=1,padx=0,pady=.25, default="active")
16621662
self.cancel = Tkinter.Button(f, text=_("Cancel"), command=self.do_cancel, width=10,height=1,padx=0,pady=.25, default="normal")
1663-
v.trace("w", self.check_valid)
1663+
v.trace_add("write", self.check_valid)
16641664
t.wm_protocol("WM_DELETE_WINDOW", self.cancel.invoke)
16651665
t.bind("<Return>", lambda event: (self.ok.flash(), self.ok.invoke()))
16661666
t.bind("<KP_Enter>", lambda event: (self.ok.flash(), self.ok.invoke()))
@@ -1769,7 +1769,7 @@ def __init__(self, title, text_pattern, default, tool_only, defaultsystem):
17691769
f = Frame(t)
17701770
self.c = c = StringVar(t)
17711771
c.set(defaultsystem)
1772-
c.trace_variable("w", self.change_system)
1772+
c.trace_add("write", self.change_system)
17731773
if not tool_only:
17741774
l = Label(f, text=_("Coordinate System:"))
17751775
mb = OptionMenu(f, c, *systems)
@@ -4268,7 +4268,7 @@ def forget(widget, *pins):
42684268

42694269
set_motion_teleop(0) # start in joint mode
42704270

4271-
root_window.tk.call("trace", "variable", "metric", "w", "update_units")
4271+
root_window.tk.call("trace", "add", "variable", "metric", "write", "update_units")
42724272
install_help(root_window)
42734273

42744274
widgets.numbers_text.bind("<Configure>", commands.redraw_soon)

src/emc/usr_intf/emcsh.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
#define setresult(t,s) Tcl_SetObjResult((t), Tcl_NewStringObj((s),-1))
4141

42+
#ifndef CONST
43+
#define CONST const
44+
#endif
45+
4246
/*
4347
Using tcl package Linuxcnc:
4448
Using emcsh:
@@ -3421,7 +3425,7 @@ extern "C"
34213425
int Linuxcnc_Init(Tcl_Interp * interp);
34223426
int Linuxcnc_Init(Tcl_Interp * interp)
34233427
{
3424-
if (Tcl_InitStubs(interp, "8.1", 0) == NULL)
3428+
if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL)
34253429
{
34263430
return TCL_ERROR;
34273431
}

src/hal/utils/halsh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int Hal_Init(Tcl_Interp *interp) {
9494
return TCL_ERROR;
9595
}
9696

97-
if (Tcl_InitStubs(interp, "8.1", 0) == NULL)
97+
if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL)
9898
{
9999
return TCL_ERROR;
100100
}

tcl/bin/halshow.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ if {[info exists ::env(CONFIG_DIR)]} {
4242
set ::INIDIR "${config_path}"
4343
set ::INIFILE "${config_path}halshow.preferences"
4444
} else {
45-
set ::INIDIR "~"
46-
set ::INIFILE "~/.halshow_preferences"
45+
set ::INIDIR "$::env(HOME)"
46+
set ::INIFILE "$::env(HOME)/.halshow_preferences"
4747
}
4848
# puts stderr "Halshow inifile: $::INIFILE"
4949

tcl/linuxcnc.tcl.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ namespace eval linuxcnc {
2525
variable TCL_SCRIPT_DIR @EMC2_TCL_DIR@/scripts
2626
variable HELP_DIR @EMC2_HELP_DIR@
2727
variable RTLIB_DIR @EMC2_RTLIB_DIR@
28-
variable CONFIG_PATH {@LINUXCNC_CONFIG_PATH@}
28+
variable CONFIG_PATH {@LINUXCNC_CONFIG_PATH_TCL@}
2929
variable NCFILES_DIR @EMC2_NCFILES_DIR@
3030
variable LANG_DIR @EMC2_LANG_DIR@
3131
variable IMAGEDIR @EMC2_IMAGE_DIR@
3232
variable REALTIME @REALTIME@
3333
variable RTS @RTS@
3434
variable CONFIG_DIR {}
3535
variable _dir
36-
foreach _dir [split {@LINUXCNC_CONFIG_PATH@} :] {
36+
foreach _dir [split {@LINUXCNC_CONFIG_PATH_TCL@} :] {
3737
lappend CONFIG_DIR [file normalize $_dir]
3838
}
3939
unset _dir

0 commit comments

Comments
 (0)