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

Skip to content

Commit a30ec66

Browse files
committed
On Windows, initialize the animation.convert_path setting from the Registry
1 parent 87c968b commit a30ec66

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

lib/matplotlib/animation.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from matplotlib.cbook import iterable, is_string_like
3434
from matplotlib.compat import subprocess
3535
from matplotlib import verbose
36-
from matplotlib import rcParams
36+
from matplotlib import rcParams, rcParamsDefault
3737

3838
# Process creation flag for subprocess to prevent it raising a terminal
3939
# window. See for example:
@@ -262,9 +262,7 @@ def isAvailable(cls):
262262
Check to see if a MovieWriter subclass is actually available by
263263
running the commandline tool.
264264
'''
265-
if platform.system() == 'Windows' and cls.bin_path() == 'convert':
266-
# On Windows, the full path to convert must be specified in
267-
# matplotlibrc since convert is also the name of a system tool.
265+
if not cls.bin_path():
268266
return False
269267
try:
270268
p = subprocess.Popen(cls.bin_path(),
@@ -549,6 +547,27 @@ def delay(self):
549547
def output_args(self):
550548
return [self.outfile]
551549

550+
@classmethod
551+
def _init_from_registry(cls):
552+
if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
553+
return
554+
from matplotlib.externals.six.moves import winreg
555+
for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
556+
try:
557+
hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
558+
'Software\\Imagemagick\\Current',
559+
0, winreg.KEY_QUERY_VALUE | flag)
560+
binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
561+
winreg.CloseKey(hkey)
562+
binpath += '\\convert.exe'
563+
break
564+
except Exception:
565+
binpath = ''
566+
rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath
567+
568+
569+
ImageMagickBase._init_from_registry()
570+
552571

553572
@writers.register('imagemagick')
554573
class ImageMagickWriter(MovieWriter, ImageMagickBase):

0 commit comments

Comments
 (0)