importsysfrompathlibimportPathfromtypingimportOptional,List,Dict,AnyfromPySide6.QtWidgetsimportQDialog,QFileDialog,QWidgetfromPySide6.QtCoreimportSignalfromPySide6.QtGuiimportQMouseEvent# UI importsfromsrc.ui.project_opening_dialog_uiimportUi_FormasUi_ProjectOpeningDialog# Core importsfromsrc.core.settingsimportget_recent_project_paths,add_recent_project_path# Utils importsfromsrc.utils.logger_utilityimportlogger# Add the parent directory of 'src' to sys.pathcurrent_dir=Path(__file__).resolve().parentparent_dir=current_dir.parent.parent# Adjust according to your project structuresys.path.append(str(parent_dir))
[docs]classProjectOpeningDialog(QDialog):"""Dialog for opening an existing project"""projectSelected=Signal(str)@logger.catchdef__init__(self,parent:Optional[QWidget]=None)->None:"""Initializer"""super().__init__(parent)self.ui:Ui_ProjectOpeningDialog=Ui_ProjectOpeningDialog()self.ui.setupUi(self)self.loadRecentProjects()self.ui.openProjectPushButton.clicked.connect(self.openProject)self.ui.projectSelectComboBox.mouseDoubleClickEvent=self.browseForProject
[docs]@logger.catchdefloadRecentProjects(self)->None:"""Load the recent projects into the combo box"""recentProjects:List[Dict[str,Any]]=get_recent_project_paths()forprojectinrecentProjects:self.ui.projectSelectComboBox.addItem(project["path"])
[docs]@logger.catchdefbrowseForProject(self,event:QMouseEvent)->None:"""Browse for a project"""projectPath,_=QFileDialog.getOpenFileName(self,"Select Project","","Manim Studio Projects (*.mstp)")ifprojectPath:self.projectSelected.emit(projectPath)add_recent_project_path(projectPath)self.accept()
[docs]@logger.catchdefopenProject(self)->None:"""Open the selected project"""selectedProject:str=self.ui.projectSelectComboBox.currentText()self.projectSelected.emit(selectedProject)self.accept()