myWin.py 1.88 KB
Newer Older
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
69
from myplotlib import INFO, SEVR, WARN, DBUG, SPCE
from myplotlib import FigureManager, FigureCanvas
from myplotlib import _G_WINDOWS
from myplotlib import np


class MyWin(FigureManager):
    
    def __init__(self, fig, show=True, *args, **kwargs):
        
        if(fig.dpi != 75.):
            fig.dpi = 75.
        
        num = kwargs.get('fignum', 0)

        if fig.boundedToWin:
            win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
            win.close()
        
        FigureManager.__init__(self, FigureCanvas(fig), num)
        
        self.canvas.figure.boundedToWin = True
        self.canvas.figure.keywords['fignum'] = num
        
        _G_WINDOWS.append(self)

        if show:
            self.refresh()
            self.show()
    
    def _boundFigure_(self, fig):
        
        fig.canvas = self.canvas
        self.canvas.figure = fig
        self.canvas.figure.boundedToWin = True
        self.canvas.figure.keywords['fignum'] = self.num
    
    def _unboundFigure_(self):
        
        self.canvas.figure.boundedToWin = False
        self.canvas.figure.keywords['fignum'] = -1
    
    def set_figure(self, fig):
        
        self._unboundFigure_()
        
        if fig.boundedToWin:
            win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
            win.close()
            
        self._boundFigure_(fig)
    
    def refresh(self):
        
        self.canvas.figure.clf()
        self.canvas.figure.plot()
        self.canvas.draw()
    
    def drawFigure(self, fig):
        if(fig.keywords['fignum'] != self.num):
            self.set_figure(fig)
        
        self.refresh()
    
    def close(self):
        
        self._unboundFigure_()
        self.destroy()
        del _G_WINDOWS[np.where([(window == self) for window in _G_WINDOWS])[0][0]]