-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatplotlib_fix.py
More file actions
executable file
·68 lines (47 loc) · 1.86 KB
/
Copy pathmatplotlib_fix.py
File metadata and controls
executable file
·68 lines (47 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'''
PyMOL matplotlib integration
matplotlib uses Tk, which conflicts with the PyMOL Tk mainloop. This module
overloads the TkAgg backend to use PyMOLs Tk instance as master widget.
This is likely to be fragile against matplotlib upgrades.
(c) 2012 Thomas Holder, MPI for Developmental Biology
License: BSD-2-Clause
'''
def overload():
import matplotlib
from . import matplotlib_fix_prefs
if matplotlib_fix_prefs['verbose']:
print(' matplotlib_fix: If you have issues with matplotlib and PyMOL, check')
print(' matplotlib_fix: the values of psico.matplotlib_fix_prefs')
if matplotlib_fix_prefs['force_tkagg']:
matplotlib.use('TkAgg')
if matplotlib.get_backend() != 'TkAgg':
return
if not matplotlib_fix_prefs['tkagg_overload']:
return
from matplotlib.backends import backend_tkagg
def _new_figure_manager(num, *args, **kwargs):
import pymol
if pymol._ext_gui is None:
return new_figure_manager(num, *args, **kwargs)
backend_tkagg.show._needmain = False
try:
import Tkinter as Tk
except ImportError:
import tkinter as Tk
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureManagerTkAgg
FigureClass = kwargs.pop('FigureClass', Figure)
figure = FigureClass(*args, **kwargs)
window = Tk.Toplevel(master=pymol._ext_gui.root)
canvas = FigureCanvasTkAgg(figure, master=window)
figManager = FigureManagerTkAgg(canvas, num, window)
if matplotlib.is_interactive():
figManager.show()
return figManager
new_figure_manager = backend_tkagg.new_figure_manager
backend_tkagg.new_figure_manager = _new_figure_manager
try:
overload()
except:
print('matplotlib_fix failed')
# vi:expandtab:smarttab