Пример #1
0
 def __init__(self, parent, sim_method, output_stream, duration=1000):
     super(Explorer, self).__init__(parent)
     self.setWindowTitle('Myokit Explorer')
     self._sim_method = sim_method
     self._stream = output_stream
     # Set guess for run times
     guess_pre = 0
     guess_run = duration
     # Explorer data
     self._data = None
     self._keys = None
     # Fix background color of line edits
     self.setStyleSheet('QLineEdit{background: white;}')
     # Create top widgets
     label1 = QtWidgets.QLabel('Run unlogged for ')
     label2 = QtWidgets.QLabel(' and then log for ')
     self._pre_field = QtWidgets.QLineEdit(str(guess_pre))
     self._pre_valid = QtGui.QDoubleValidator()
     self._pre_valid.setBottom(0)
     self._pre_field.setValidator(self._pre_valid)
     self._run_field = QtWidgets.QLineEdit(str(guess_run))
     self._run_valid = QtGui.QDoubleValidator()
     self._run_valid.setBottom(0)
     self._run_field.setValidator(self._run_valid)
     self._clear_button = QtWidgets.QPushButton('Clear graphs')
     self._clear_button.clicked.connect(self.action_clear)
     self._run_button = QtWidgets.QPushButton('Run')
     self._run_button.clicked.connect(self.action_run)
     # Create graph widgets
     self._axes = None
     self._figure = matplotlib.figure.Figure()
     self._canvas = backend.FigureCanvasQTAgg(self._figure)
     self._toolbar = backend.NavigationToolbar2QT(self._canvas, self)
     self._select_x = QtWidgets.QComboBox()
     self._select_x.currentIndexChanged.connect(self.combo_changed)
     self._select_y = QtWidgets.QComboBox()
     self._select_y.currentIndexChanged.connect(self.combo_changed)
     # Create bottom widgets
     self._close_button = QtWidgets.QPushButton('Close')
     self._close_button.clicked.connect(self.action_close)
     # Create button layout
     button_layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.LeftToRight)
     button_layout.addWidget(label1)
     button_layout.addWidget(self._pre_field)
     button_layout.addWidget(label2)
     button_layout.addWidget(self._run_field)
     button_layout.addWidget(self._clear_button)
     button_layout.addWidget(self._run_button)
     # Create graph options layout
     graph_option_layout = QtWidgets.QBoxLayout(
         QtWidgets.QBoxLayout.LeftToRight)
     graph_option_layout.addWidget(self._select_x)
     graph_option_layout.addWidget(self._select_y)
     # Create bottom layout
     bottom_layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.LeftToRight)
     bottom_layout.addWidget(self._close_button)
     # Create central layout
     layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.TopToBottom)
     layout.addLayout(button_layout)
     layout.addLayout(graph_option_layout)
     layout.addWidget(self._canvas)
     layout.addWidget(self._toolbar)
     layout.addLayout(bottom_layout)
     self.setLayout(layout)
Пример #2
0
 def __init__(self, filename=None):
     super(DataBlockViewer, self).__init__()
     # Set application icon
     self.setWindowIcon(icon())
     # Set size, center
     self.resize(800, 600)
     self.setMinimumSize(600, 400)
     qr = self.frameGeometry()
     cp = QtWidgets.QDesktopWidget().availableGeometry().center()
     qr.moveCenter(cp)
     self.move(qr.topLeft())
     # Status bar
     self._label_cursor = QtWidgets.QLabel()
     self.statusBar().addPermanentWidget(self._label_cursor)
     self.statusBar().showMessage('Ready')
     # Menu bar
     self.create_menu()
     # Timer
     self._timer_interval = 50
     self._timer = QtCore.QTimer(self)
     self._timer.setInterval(self._timer_interval)
     self._timer.setSingleShot(False)
     self._timer.timeout.connect(self.action_next_frame)
     self._timer_paused = False
     try:
         self._timer.setTimerType(Qt.PreciseTimer)
     except AttributeError:
         pass  # Qt4 uses precise timer by default
     # Video widget
     self._video_scene = VideoScene()
     self._video_scene.mouse_moved.connect(self.event_mouse_move)
     self._video_scene.single_click.connect(self.event_single_click)
     self._video_scene.double_click.connect(self.event_double_click)
     self._video_view = VideoView(self._video_scene)
     #self._video_view.setViewport(QtOpenGL.QGLWidget())
     self._video_pixmap = None
     self._video_item = None
     self._video_frames = None
     self._video_iframe = None
     self._colormap_pixmap = None
     self._colormap_item = None
     # Video slider
     self._slider = QtWidgets.QSlider(Qt.Horizontal)
     self._slider.setTickPosition(QtWidgets.QSlider.NoTicks)
     #self._slider.setTickPosition(QtWidgets.QSlider.TicksBothSides)
     self._slider.setSingleStep(1)
     self._slider.setMinimum(0)
     self._slider.setMaximum(0)
     self._slider.sliderPressed.connect(self.action_pause_timer)
     self._slider.sliderReleased.connect(self.action_depause_timer)
     self._slider.valueChanged.connect(self.action_set_frame)
     # Controls
     style = QtWidgets.QApplication.style()
     # Play button
     self._play_icon_play = style.standardIcon(style.SP_MediaPlay)
     self._play_icon_pause = style.standardIcon(style.SP_MediaPause)
     self._play_button = QtWidgets.QPushButton()
     self._play_button.setIcon(self._play_icon_play)
     self._play_button.pressed.connect(self.action_start_stop)
     # Frame indicator
     self._frame_label = QtWidgets.QLabel('Frame')
     self._frame_field = QtWidgets.QLineEdit('0')
     self._frame_field.setReadOnly(True)
     self._frame_field.setMaxLength(6)
     self._frame_field.setMaximumWidth(100)
     self._frame_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
     # Time indicator
     self._time_label = QtWidgets.QLabel('Time')
     self._time_field = QtWidgets.QLineEdit('0')
     self._time_field.setReadOnly(True)
     self._time_field.setMaxLength(6)
     self._time_field.setMaximumWidth(100)
     self._time_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
     # Speed indicator
     self._rate_label = QtWidgets.QLabel('Delay')
     self._rate_field = QtWidgets.QLineEdit(str(self._timer_interval))
     self._rate_field.setValidator(QtGui.QIntValidator(1, 2**20, self))
     self._rate_field.editingFinished.connect(self.event_rate_changed)
     self._rate_field.setMaximumWidth(100)
     self._rate_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
     # Graph controls
     self._graph_clear_button = QtWidgets.QPushButton('Clear graphs')
     self._graph_clear_button.pressed.connect(self.action_clear_graphs)
     # Variable selection
     self._variable_select = QtWidgets.QComboBox()
     self._variable_select.activated.connect(self.event_variable_selected)
     self._variable_select.setMinimumWidth(120)
     # Colormap selection
     self._colormap = myokit.ColorMap.names().next()
     self._colormap_select = QtWidgets.QComboBox()
     for cmap in myokit.ColorMap.names():
         self._colormap_select.addItem(cmap)
     self._colormap_select.activated.connect(self.event_colormap_selected)
     self._colormap_select.setMinimumWidth(120)
     # Control layout
     self._control_layout = QtWidgets.QHBoxLayout()
     self._control_layout.addWidget(self._play_button)
     self._control_layout.addWidget(self._frame_label)
     self._control_layout.addWidget(self._frame_field)
     self._control_layout.addWidget(self._time_label)
     self._control_layout.addWidget(self._time_field)
     self._control_layout.addWidget(self._rate_label)
     self._control_layout.addWidget(self._rate_field)
     self._control_layout.addWidget(self._graph_clear_button)
     self._control_layout.addWidget(self._variable_select)
     self._control_layout.addWidget(self._colormap_select)
     # Graph area
     self._graph_area = GraphArea()
     self._graph_area.mouse_moved.connect(self.event_mouse_move)
     # Video Layout
     self._video_layout = QtWidgets.QVBoxLayout()
     self._video_layout.addWidget(self._video_view)
     self._video_layout.addWidget(self._slider)
     self._video_layout.addLayout(self._control_layout)
     self._video_widget = QtWidgets.QWidget()
     self._video_widget.setLayout(self._video_layout)
     # Central layout
     self._central_widget = QtWidgets.QSplitter(Qt.Vertical)
     self._central_widget.addWidget(self._video_widget)
     self._central_widget.addWidget(self._graph_area)
     self.setCentralWidget(self._central_widget)
     # Current path, current file, recent files
     self._path = QtCore.QDir.currentPath()
     self._file = None
     self._recent_files = []
     # Current data block, display variable
     self._data = None
     self._variable = None
     # Load settings from ini file
     self.load_config()
     self.update_window_title()
     # Set controls to correct values
     self._colormap_select.setCurrentIndex(
         self._colormap_select.findText(self._colormap))
     self._rate_field.setText(str(self._timer_interval))
     self._timer.setInterval(self._timer_interval)
     # Pause video playback during resize
     self._resize_timer = QtCore.QTimer()
     self._resize_timer.timeout.connect(self._resize_timeout)
     self._video_view.resize_event.connect(self._resize_started)
     # Attempt to load selected file
     if filename and os.path.isfile(filename):
         self.load_data_file(filename)