|
33 | 33 | from matplotlib.cbook import iterable, is_string_like |
34 | 34 | from matplotlib.compat import subprocess |
35 | 35 | from matplotlib import verbose |
36 | | -from matplotlib import rcParams |
| 36 | +from matplotlib import rcParams, rcParamsDefault |
37 | 37 |
|
38 | 38 | # Process creation flag for subprocess to prevent it raising a terminal |
39 | 39 | # window. See for example: |
@@ -262,9 +262,7 @@ def isAvailable(cls): |
262 | 262 | Check to see if a MovieWriter subclass is actually available by |
263 | 263 | running the commandline tool. |
264 | 264 | ''' |
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(): |
268 | 266 | return False |
269 | 267 | try: |
270 | 268 | p = subprocess.Popen(cls.bin_path(), |
@@ -549,6 +547,27 @@ def delay(self): |
549 | 547 | def output_args(self): |
550 | 548 | return [self.outfile] |
551 | 549 |
|
| 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 | + |
552 | 571 |
|
553 | 572 | @writers.register('imagemagick') |
554 | 573 | class ImageMagickWriter(MovieWriter, ImageMagickBase): |
|
0 commit comments