-
Notifications
You must be signed in to change notification settings - Fork 0
/
MplCanvasDict.py
85 lines (72 loc) · 2.87 KB
/
MplCanvasDict.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys
from numpy import *
from collections import deque
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import (QApplication, QDialog, QLineEdit, QTextBrowser,
QVBoxLayout, QHBoxLayout, QSizePolicy,
QToolBar, QMenuBar, QMenu, QAction, QMainWindow, QWidget)
from PyQt5.QtGui import QKeySequence
"""from PySide import QtCore, QtGui
from PySide.QtCore import Qt
from PySide.QtCore import Signal
from PySide.QtGui import (QApplication, QDialog, QLineEdit, QTextBrowser,
QVBoxLayout, QHBoxLayout, QKeySequence, QSizePolicy,
QToolBar, QMenuBar, QMenu, QAction, QMainWindow, QWidget)
"""
import matplotlib
matplotlib.rcParams['backend.qt4']='PySide'
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.ticker import EngFormatter
import EngMplCanvas
import ImgMplCanvas
# TODO: Refactor to take more canvas types.
class MplCanvasDict():
def __init__(self, parent=None, width=5, height=4, dpi=72):
self.cd= {}
self.active= ''
self.parent= parent
self.width= width
self.height= height
self.dpi= dpi
def setActive(self, canvasName):
if (canvasName in self.cd):
self.active= canvasName
else:
print("Error: no canvas is named " + str(canvasName))
return
def getActiveCanvas(self):
if (self.active in self.cd):
return self.cd[self.active]
else:
print("Error: the active canvas " + str(canvasName) + " does not exist")
def getActiveCanvasName(self):
return self.active
def create(self, canvasName='', parent=None, width=5, height=4, dpi=72):
if canvasName == '':
canvasCount= len(self.cd) + 1
canvasName= "PyPost_" + str(canvasCount)
c= EngMplCanvas.EngMplCanvas(parent=parent, width=width, height=height, dpi=dpi)
c.setWindowTitle(canvasName)
c.name= canvasName
self.cd[canvasName]= c
return canvasName
def createImg(self, canvasName='', parent=None, width=5, height=4, dpi=72):
if canvasName == '':
canvasCount= len(self.cd) + 1
canvasName= "PyPost_" + str(canvasCount)
c= ImgMplCanvas.ImgMplCanvas(parent=parent, width=width, height=height, dpi=dpi)
# c.setWindowTitle(canvasName)
c.name= canvasName
self.cd[canvasName]= c
return canvasName
def remove(self, canvasName):
if canvasName == 'PyPost_1':
print("Can't delete main graph window PyPost_1")
return
if self.active == canvasName:
self.active= 'PyPost_1'
c= self.cd[canvasName]
del(self.cd[canvasName])
c.deleteLater()