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 @@ static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK;
// 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 @@ DpiSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
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 @@ bool load_tcl_tk(T lib)
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 @@ PYBIND11_MODULE(_tkagg, m, py::mod_gil_not_used())
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");
} 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