Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/_tkagg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
// Global vars for Tcl functions. We load these symbols from the tkinter
// extension module or loaded Tcl libraries at run-time.
static Tcl_SetVar_t TCL_SETVAR;
static Tcl_SetVar2_t TCL_SETVAR2;

static void
mpl_tk_blit(py::object interp_obj, const char *photo_name,
Expand Down Expand Up @@ -173,7 +174,15 @@
std::string dpi = std::to_string(LOWORD(wParam));

Tcl_Interp* interp = (Tcl_Interp*)dwRefData;
TCL_SETVAR(interp, var_name.c_str(), dpi.c_str(), 0);
if (TCL_SETVAR) {
TCL_SETVAR(interp, var_name.c_str(), dpi.c_str(), 0);
} else if (TCL_SETVAR2) {
TCL_SETVAR2(interp, var_name.c_str(), NULL, dpi.c_str(), 0);
} else {
// This should be prevented at import time, and therefore unreachable.
// But defensively throw just in case.
throw std::runtime_error("Unable to call Tcl_SetVar or Tcl_SetVar2");
}
}
return 0;
case WM_NCDESTROY:
Expand Down Expand Up @@ -246,13 +255,16 @@
if (auto ptr = dlsym(lib, "Tcl_SetVar")) {
TCL_SETVAR = (Tcl_SetVar_t)ptr;
}
if (auto ptr = dlsym(lib, "Tcl_SetVar2")) {
TCL_SETVAR2 = (Tcl_SetVar2_t)ptr;
}
if (auto ptr = dlsym(lib, "Tk_FindPhoto")) {
TK_FIND_PHOTO = (Tk_FindPhoto_t)ptr;
}
if (auto ptr = dlsym(lib, "Tk_PhotoPutBlock")) {
TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)ptr;
}
return TCL_SETVAR && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
return (TCL_SETVAR || TCL_SETVAR2) && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
}

#ifdef WIN32_DLL
Expand Down Expand Up @@ -343,8 +355,8 @@
throw py::error_already_set();
}

if (!TCL_SETVAR) {
throw py::import_error("Failed to load Tcl_SetVar");
if (!(TCL_SETVAR || TCL_SETVAR2)) {
throw py::import_error("Failed to load Tcl_SetVar or Tcl_SetVar2");

Check warning on line 359 in src/_tkagg.cpp

View check run for this annotation

Codecov / codecov/patch

src/_tkagg.cpp#L359

Added line #L359 was not covered by tests
} else if (!TK_FIND_PHOTO) {
throw py::import_error("Failed to load Tk_FindPhoto");
} else if (!TK_PHOTO_PUT_BLOCK) {
Expand Down
3 changes: 3 additions & 0 deletions src/_tkmini.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ typedef int (*Tk_PhotoPutBlock_t) (Tcl_Interp *interp, Tk_PhotoHandle handle,
/* Tcl_SetVar typedef */
typedef const char *(*Tcl_SetVar_t)(Tcl_Interp *interp, const char *varName,
const char *newValue, int flags);
/* Tcl_SetVar2 typedef */
typedef const char *(*Tcl_SetVar2_t)(Tcl_Interp *interp, const char *part1, const char *part2,
const char *newValue, int flags);

#ifdef __cplusplus
}
Expand Down
Loading