class ExpandableLine(QWidget, object): def __init__(self, title='', animation_duration=300, parent=None): super(ExpandableLine, self).__init__(parent=parent) self._animation_duration = animation_duration base_layout = layouts.GridLayout(margins=(0, 0, 0, 0)) base_layout.setVerticalSpacing(0) self.setLayout(base_layout) self.expand_btn = QToolButton() self.expand_btn.setText(str(title)) self.expand_btn.setStyleSheet('QToolButton { border : none; }') self.expand_btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.expand_btn.setArrowType(Qt.ArrowType.RightArrow) self.expand_btn.setCheckable(True) self.expand_btn.setChecked(True) header_line = QFrame() header_line.setFrameShape(QFrame.HLine) header_line.setFrameShadow(QFrame.Sunken) header_line.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self.content_area = QScrollArea() self.content_area.setStyleSheet('QScrollArea { border: none;}') self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.content_area.setMaximumHeight(0) self.content_area.setMinimumHeight(0) self.toggle_anim = QParallelAnimationGroup() self.toggle_anim.addAnimation(QPropertyAnimation(self, 'minimumHeight')) self.toggle_anim.addAnimation(QPropertyAnimation(self, 'maximumHeight')) self.toggle_anim.addAnimation(QPropertyAnimation(self.content_area, 'maximumHeight')) row = 0 base_layout.addWidget(self.expand_btn, row, 0, 1, 1, Qt.AlignLeft) base_layout.addWidget(header_line, row, 2, 1, 1) row += 1 base_layout.addWidget(self.content_area, row, 0, 1, 3) def expand_view(checked): arrow_type = Qt.DownArrow if checked else Qt.RightArrow direction = QAbstractAnimation.Forward if checked else QAbstractAnimation.Backward self.expand_btn.setArrowType(arrow_type) self.toggle_anim.setDirection(direction) self.toggle_anim.start() # === SIGNALS === # self.expand_btn.toggled.connect(expand_view) expand_view(True) def set_content_layout(self, content_layout): self.content_area.destroy() self.content_area.setLayout(content_layout) collapsed_height = self.sizeHint().height() - self.content_area.maximumHeight() content_height = content_layout.sizeHint().height() + 300 for i in range(self.toggle_anim.animationCount() - 1): expand_anim = self.toggle_anim.animationAt(i) expand_anim.setDuration(self._animation_duration) expand_anim.setStartValue(collapsed_height) expand_anim.setEndValue(collapsed_height + content_height) content_anim = self.toggle_anim.animationAt(self.toggle_anim.animationCount() - 1) content_anim.setDuration(self._animation_duration) content_anim.setStartValue(0) content_anim.setEndValue(content_height)
def _build_ui(self): layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.tree = QTreeWidget() self.tree.setSelectionMode(QTreeWidget.ExtendedSelection) self.tree.setHeaderLabels([ "name", "status", "server", "prioritize", "kill", "delete", "browse" ]) self.tree.setUniformRowHeights(True) self.tree.setColumnWidth(0, 150) layout.addWidget(self.tree, 0, 0, 6, 1, Qt.AlignTop) row = 0 pause_button = QPushButton( "pause new jobs" if not self.session.seqcrow_job_manager.paused else "resume jobs") pause_button.setCheckable(True) pause_button.clicked.connect(lambda check: pause_button.setText( "pause new jobs" if not check else "resume jobs")) pause_button.setChecked(self.session.seqcrow_job_manager.paused) pause_button.clicked.connect(self.pause_queue) layout.addWidget(pause_button, row, 1, 1, 1, Qt.AlignTop) row += 1 open_button = QPushButton("open structure") open_button.clicked.connect(self.open_jobs) layout.addWidget(open_button, row, 1, 1, 1, Qt.AlignTop) row += 1 log_button = QPushButton("log") log_button.clicked.connect(self.open_log) layout.addWidget(log_button, row, 1, 1, 1, Qt.AlignTop) row += 1 output_button = QPushButton("raw output") output_button.clicked.connect(self.open_output) layout.addWidget(output_button, row, 1, 1, 1, Qt.AlignTop) row += 1 refresh_button = QToolButton() refresh_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding) refresh_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) refresh_button.setIcon( QIcon(refresh_button.style().standardIcon( QStyle.SP_BrowserReload))) refresh_button.setText('check jobs') refresh_button.clicked.connect( lambda *args: self.session.seqcrow_job_manager.triggers. activate_trigger(JOB_QUEUED, "refresh")) layout.addWidget(refresh_button, row, 1, 1, 1, Qt.AlignTop) row += 1 for i in range(0, row - 1): layout.setRowStretch(i, 0) layout.setRowStretch(row - 1, 1) layout.setColumnStretch(0, 1) layout.setColumnStretch(1, 0) self.tool_window.ui_area.setLayout(layout) self.tool_window.manage(None)