8000 Move _windowing extension into _tkagg. by anntzer · Pull Request #13074 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Move _windowing extension into _tkagg. #13074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2019
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
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
from matplotlib.widgets import SubplotTool

try:
from matplotlib._windowing import GetForegroundWindow, SetForegroundWindow
from ._tkagg import Win32_GetForegroundWindow, Win32_SetForegroundWindow
except ImportError:
@contextmanager
def _restore_foreground_window_at_end():
yield
else:
@contextmanager
def _restore_foreground_window_at_end():
foreground = GetForegroundWindow()
foreground = Win32_GetForegroundWindow()
try:
yield
finally:
if rcParams['tk.window_focus']:
SetForegroundWindow(foreground)
Win32_SetForegroundWindow(foreground)


_log = logging.getLogger(__name__)
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/windowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
try:
if not rcParams['tk.window_focus']:
raise ImportError
from matplotlib._windowing import GetForegroundWindow, SetForegroundWindow
from matplotlib.backends._tkagg import (
Win32_GetForegroundWindow as GetForegroundWindow,
Win32_SetForegroundWindow as SetForegroundWindow)

except ImportError:

Expand Down
3 changes: 0 additions & 3 deletions setup.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#
# - Tk support requires Tk development headers and Tkinter.
# - Mac OSX backend requires the Cocoa headers included with XCode.
# - Windowing is MS-Windows specific, and requires the "windows.h"
# header.
#
# The other GUI toolkits do not require any extension code, and can be
# used as long as the libraries are installed on your system --
Expand All @@ -61,7 +59,6 @@
#agg = auto
#macosx = auto
#tkagg = auto
#windowing = auto

[rc_options]
# User-configurable options
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
setupext.BackendAgg(),
setupext.BackendTkAgg(),
setupext.BackendMacOSX(),
setupext.Windowing(),
'Optional package data',
setupext.Dlls(),
]
Expand Down
32 changes: 4 additions & 28 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,10 @@ def get_extension(self):
def add_flags(self, ext):
ext.include_dirs.insert(0, 'src')
if sys.platform == 'win32':
# PSAPI library needed for finding Tcl/Tk at run time
ext.libraries.extend(['psapi'])
# psapi library needed for finding Tcl/Tk at run time.
# user32 library needed for window manipulation functions.
ext.libraries.extend(['psapi', 'user32'])
ext.extra_link_args.extend(["-mwindows"])
elif sys.platform == 'linux':
ext.libraries.extend(['dl'])

Expand All @@ -1189,32 +1191,6 @@ def get_extension(self):
return ext


class Windowing(OptionalBackendPackage):
"""
Builds the windowing extension.
"""
name = "windowing"

def check_requirements(self):
if sys.platform != 'win32':
raise CheckFailed("Microsoft Windows only")
config = self.get_config()
if config is False:
raise CheckFailed("skipping due to configuration")
return ""

def get_extension(self):
sources = [
"src/_windowing.cpp"
]
ext = make_extension('matplotlib._windowing', sources)
ext.include_dirs.extend(['C:/include'])
ext.libraries.extend(['user32'])
ext.library_dirs.extend(['C:/lib'])
ext.extra_link_args.append("-mwindows")
return ext


class OptionalPackageData(OptionalPackage):
config_category = "package_data"

Expand Down
41 changes: 37 additions & 4 deletions src/_tkagg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

#include <agg_basics.h> // agg:int8u

#ifdef _WIN32
#include <windows.h>
#endif

// Include our own excerpts from the Tcl / Tk headers
#include "_tkmini.h"

Expand Down Expand Up @@ -245,15 +249,45 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args)
}
}

#ifdef _WIN32
static PyObject *
Win32_GetForegroundWindow(PyObject *module, PyObject *args)
{
HWND handle = GetForegroundWindow();
if (!PyArg_ParseTuple(args, ":GetForegroundWindow")) {
return NULL;
}
return PyLong_FromSize_t((size_t)handle);
}

static PyObject *
Win32_SetForegroundWindow(PyObject *module, PyObject *args)
{
HWND handle;
if (!PyArg_ParseTuple(args, "n:SetForegroundWindow", &handle)) {
return NULL;
}
if (!SetForegroundWindow(handle)) {
return PyErr_Format(PyExc_RuntimeError, "Error setting window");
}
Py_INCREF(Py_None);
return Py_None;
}
#endif

static PyMethodDef functions[] = {
/* Tkinter interface stuff */
{ "tkinit", (PyCFunction)_tkinit, 1 },
{ "blit", (PyCFunction)mpl_tk_blit, 1 },
{ "tkinit", (PyCFunction)_tkinit, METH_VARARGS },
{ "blit", (PyCFunction)mpl_tk_blit, METH_VARARGS },
#ifdef _WIN32
{ "Win32_GetForegroundWindow", (PyCFunction)Win32_GetForegroundWindow, METH_VARARGS },
{ "Win32_SetForegroundWindow", (PyCFunction)Win32_SetForegroundWindow, METH_VARARGS },
#endif
{ NULL, NULL } /* sentinel */
};

// Functions to fill global TCL / Tk function pointers by dynamic loading
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#ifdef _WIN32

/*
* On Windows, we can't load the tkinter module to get the TCL or Tk symbols,
Expand All @@ -262,7 +296,6 @@ static PyMethodDef functions[] = {
* Python, we scan all modules in the running process for the TCL and Tk
* function names.
*/
#include <windows.h>
#define PSAPI_VERSION 1
#include <psapi.h>
// Must be linked with 'psapi' library
Expand Down
55 changes: 0 additions & 55 deletions src/_windowing.cpp

This file was deleted.

0