本文整理汇总了Python中matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg.deleteLater方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QTAgg.deleteLater方法的具体用法?Python NavigationToolbar2QTAgg.deleteLater怎么用?Python NavigationToolbar2QTAgg.deleteLater使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg
的用法示例。
在下文中一共展示了NavigationToolbar2QTAgg.deleteLater方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DisplayFiguresWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import deleteLater [as 别名]
class DisplayFiguresWidget(QtGui.QWidget):
def __init__(self):
"""
"""
super(DisplayFiguresWidget, self).__init__()
self.init_ui()
self.m_widget = None
def init_ui(self):
"""
"""
self.setWindowTitle('Test')
self.setLayout(QtGui.QVBoxLayout())
self.layout_buttons = QtGui.QHBoxLayout()
self.layout().addLayout(self.layout_buttons)
self.layout_buttons.addStretch(1)
self.status = QtGui.QLabel(self)
self.layout_buttons.addWidget(self.status)
self.previous_figure_button = QtGui.QPushButton("Previous")
self.layout_buttons.addWidget(self.previous_figure_button)
self.next_figure_button = QtGui.QPushButton("Next")
self.layout_buttons.addWidget(self.next_figure_button)
self.next_figure_button.clicked.connect(self.next_figure)
self.previous_figure_button.clicked.connect(self.previous_figure)
self.plot_canvas = None
self.nav_toolbar = None
self.fig_generator = None
self.current_fig = None
self.figures_list = []
self.i = -1
def add_figures(self, fig_generator):
"""
"""
self.fig_generator = fig_generator
self.next_figure()
def add_figure(self, args):
"""
"""
figure, title = args
mess = "{} | Figure n°{}"
self.status.setText(mess.format(title, self.i))
self.current_fig = figure
if figure not in self.figures_list:
self.figures_list.append(args)
self.remove_figure()
self.plot_canvas = MatplotlibWidget(figure, self)
self.nav_toolbar = NavigationToolbar(self.plot_canvas, self)
self.layout().insertWidget(0, self.nav_toolbar)
self.layout().insertWidget(1, self.plot_canvas)
def remove_figure(self):
"""
"""
if self.plot_canvas:
self.layout().removeWidget(self.plot_canvas)
self.plot_canvas.deleteLater()
self.plot_canvas = None
if self.nav_toolbar:
self.layout().removeWidget(self.nav_toolbar)
self.nav_toolbar.deleteLater()
self.nav_toolbar = None
def next_figure(self):
"""
"""
if self.i == -1 or self.current_fig == self.figures_list[-1][0]:
self.i += 1
try:
fig, title = self.fig_generator.__next__()
self.add_figure((fig, title))
except StopIteration:
self.status.setText("No next figure")
else:
self.i += 1
self.add_figure(self.figures_list[self.i])
def previous_figure(self):
"""
"""
if self.i > 0:
self.i -= 1
self.add_figure(self.figures_list[self.i])
else:
self.status.setText("No previous figure")