[docs]@dataclassclassCategory:""" A data class that represents a category in the main widget. Attributes: widget: A callable that returns a QWidget, taking a JobManager as an argument. tool_tip: A string representing the tooltip text for the category. """widget:Callable[[JobManager],QWidget]tool_tip:str=""
CATEGORIES={"Build MSA":Category(widget=lambdajob_manager:MSAOptionsWidget(job_manager),tool_tip="Select parameters to build MSA",),"Make Predictions":Category(widget=lambdajob_manager:MakePredictionsWidget(job_manager),tool_tip="Select parameters to make predictions",),"Analysis":Category(widget=lambdajob_manager:AnalysisConfigWidget(job_manager),tool_tip="Select parameters to analyze results",),}
[docs]classMainWidget(QWidget):""" MainWidget serves as the central widget for managing different tasks such as building MSA, making predictions, and analyzing results. It provides an interface for selecting tasks and displaying the appropriate configuration widgets. Methods: create_dock_widget: Creates a new dock widget for selecting options. create_new_job_widget: Creates the widget that allows the user to select a new job. wrap_with_border: Wraps a given widget with a border layout. _on_item_clicked: Handles the event when an item in the icon grid is clicked. clear_dock_widget: Clears the contents of the current dock widget. show_job_status_page: Displays the job status page in a dock widget. show_new_job_page: Displays the new job selection page in a dock widget. clear_layout: Clears the contents of a given layout. """def__init__(self,parent,job_manager):""" Initialize the MainWidget with a parent widget and job manager. Args: parent: The parent widget that contains the MainWidget. job_manager: The manager responsible for handling job execution. """super().__init__(parent)self.parent=parentself.job_manager=job_manager# Main layoutself.layout=QVBoxLayout()self.layout.setAlignment(Qt.AlignTop|Qt.AlignHCenter)# Create the welcome pageself.clear_layout(self.layout)self.new_job_dock=Noneself.dock_widgets={}# Set the main layoutself.setLayout(self.layout)
[docs]defcreate_dock_widget(self):""" Creates a new dock widget for selecting options. If an existing dock widget is present, it is cleared before creating the new one. """ifself.new_job_dock:self.clear_dock_widget()self.new_job_dock=QDockWidget("Select options",self)self.new_job_dock.setAllowedAreas(Qt.TopDockWidgetArea|Qt.RightDockWidgetArea)self.new_job_dock.setWidget(self.create_new_job_widget())ifself.parent:self.parent.addDockWidget(Qt.RightDockWidgetArea,self.new_job_dock)
[docs]defcreate_new_job_widget(self):""" Creates a widget that allows the user to select a new job. Returns: new_job_widget: A QWidget that contains the options for selecting a new job. """new_job_widget=QWidget()# Setting specific style for this widgetnew_job_widget.setStyleSheet(""" QWidget { background-color: #CCCCCC; } """)layout=QVBoxLayout(new_job_widget)widget=QLabel("Select:")font=widget.font()font.setPointSize(14)widget.setFont(font)widget.setMinimumWidth(800)widget.setAlignment(Qt.AlignLeft|Qt.AlignTop)layout.addWidget(widget)self.icon_grid=Icons(self)self.icon_grid.addItems(CATEGORIES)self.icon_grid.itemClicked.connect(self._on_item_clicked)new_job_widget.setMinimumSize(600,400)layout.addWidget(self.icon_grid)returnnew_job_widget
[docs]defwrap_with_border(self,widget):""" Wraps a given widget with a border layout. Args: widget: The QWidget to be wrapped. Returns: container_widget: A QWidget that wraps the input widget in a border layout. """container_widget=QWidget()layout=QVBoxLayout(container_widget)layout.addWidget(widget)returncontainer_widget
[docs]def_on_item_clicked(self,item):""" Handles the event when an item in the icon grid is clicked. It creates a dock widget with the selected category's options. Args: item: The item clicked in the icon grid. """ifself.new_job_dock:self.new_job_dock.setVisible(False)self.create_dock_widget()name=item.text()widget=CATEGORIES[name].widget(self.job_manager)widget.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)self.new_job_dock.widget().layout().addWidget(self.wrap_with_border(widget))
[docs]defclear_dock_widget(self):""" Clears the contents of the current dock widget, removing all its child widgets. """dock_widget=self.new_job_dock.widget()layout=dock_widget.layout()foriinreversed(range(layout.count())):item=layout.itemAt(i)widget=item.widget()ifwidget:widget.deleteLater()
[docs]defshow_job_status_page(self):""" Displays the job status page in a dock widget. """job_status_page=JobStatusPage(self.job_manager)self.parent.show_dock_widget("Job Status",lambda:job_status_page)
[docs]defshow_new_job_page(self):""" Displays the new job selection page in a dock widget. If the dock widget already exists, it is made visible again. """ifself.parent:self.parent.toolbar.setVisible(True)ifself.new_job_dock:self.new_job_dock.setVisible(False)self.create_dock_widget()
[docs]defclear_layout(self,layout,start_index=0):""" Clears the contents of a given layout, starting from a specified index. Args: layout: The QLayout to clear. start_index: The index from which to start clearing the layout. """whilelayout.count()>start_index:item=layout.takeAt(start_index)widget=item.widget()ifwidget:widget.deleteLater()