如何将fig
Orthocanvas 类中的变量作为参数传递给aw = ApplicationWindow
?
global fig
class OrthoCanvas(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self._figs = set([a.figure for a in self.axes])
data = load_nii('d_crop_mni_s01_t1w_hires_defaced_MNI.nii')
data_read = read_img_data(data)
for fig in self._figs:
fig.canvas.mpl_connect('scroll_event', self._on_scroll)
fig.canvas.mpl_connect('motion_notify_event', self._on_mouse)
fig.canvas.mpl_connect('button_press_event', self._on_mouse)
fig.canvas.mpl_connect('key_press_event', self._on_keypress)
fig.canvas.mpl_connect('close_event', self._cleanup)
ortho = OrthoView3D(fig)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
class Orthoview3D(self, fig, data, OrthoCanvas):
def __init__ (self, fig, data):
super().__init__(self)
data = np.asanyarray(data)
xrows, xcols = 2,2
self._axes = [fig.add_subplot(xrows, xcols, i + 1) for i in range(xrows * xcols)
fig.set_size_inches((8, 8), forward=True)
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self, fig):
super().__init__(self, fig)
self.canvas = OrthoCanvas()
self.main_widget = QtWidgets.QWidget(self)
self.main_widget.resize(1000,1000)
self.main_widget.move(700,50)
qApp = QtWidgets.QApplication(sys.argv)
aw = ApplicationWindow()
aw.show()
sys.exit(qApp.exec_())