Example #1
0
 def load_corpus(self, file):
     self.corpus = Corpus("NewCorpus").load(file)
     self.show()
     self.raise_()
     self.main_window.settings.add_recent_corpus2(self.corpus)
     self.onCorpusChanged.emit(self.corpus)
     return self.corpus
 def on_new_corpus(self):
     location = QFileDialog().getExistingDirectory(self, directory=self.main_window.settings.DIR_CORPORA)
     if os.path.isdir(location):
         self.corpus = Corpus("New Corpus", location, template_movie_path="data/template.mp4")
         self.corpus.save(os.path.join(self.corpus.directory, self.corpus.name))
         self.onCorpusChanged.emit(self.corpus)
         self.show()
         self.raise_()
Example #3
0
class CorpusDockWidget(EDockWidget):
    onCorpusChanged = pyqtSignal(object)
    onSelectionChanged = pyqtSignal(object)

    def __init__(self, main_window):
        super(CorpusDockWidget, self).__init__(main_window, False)
        self.setWindowTitle("Corpus")
        self.w = QSplitter(Qt.Horizontal, self)
        self.in_template_mode = False
        self.last_project = None

        self.list = CorpusList(self.w, self)
        self.info_widget = QTabWidget(self.w)
        self.general_widget = CorpusGeneralWidget(self.w)
        self.general_widget.setLayout(QVBoxLayout())
        self.filmography = FilmographyWidget2(self.w)
        self.w.addWidget(self.list)
        self.w.addWidget(self.info_widget)

        self.info_widget.addTab(self.general_widget, "General")
        self.info_widget.addTab(self.filmography, "Filmography")
        self.setWidget(self.w)

        self.file_menu = self.inner.menuBar().addMenu("File")
        self.a_new = self.file_menu.addAction("New Corpus")
        self.a_save = self.file_menu.addAction("Save Corpus")
        self.a_load = self.file_menu.addAction("Load Corpus")
        self.a_create_project = self.file_menu.addAction("Create Projects")
        self.a_import_project = self.file_menu.addAction("Import Projects")

        self.a_new.triggered.connect(self.on_new_corpus)
        self.a_save.triggered.connect(self.on_save_corpus)
        self.a_create_project.triggered.connect(self.on_create_project)
        self.a_load.triggered.connect(self.on_load_corpus)
        self.general_widget.btn_EditTemplate.clicked.connect(
            self.on_edit_template)
        self.general_widget.btn_CloseTemplate.clicked.connect(
            self.on_close_template)
        self.general_widget.btn_SaveTemplate.clicked.connect(
            self.on_save_template)

        self.a_import_project.triggered.connect(self.on_import_projects)

        self.onCorpusChanged.connect(self.list.on_corpus_loaded)
        self.onCorpusChanged.connect(self.general_widget.on_corpus_loaded)

        self.general_widget.btn_ImportTemplate.clicked.connect(
            self.import_template)
        self.filmography.onFilmographyChanged.connect(
            self.save_current_project)

        self.list.onSelectionChanged.connect(self.on_selection_changed)

        self.corpus = None  # type: Optional[Corpus]
        self.current_project = None  # type: Optional[VIANProject]

    def on_new_corpus(self):
        location = QFileDialog().getExistingDirectory(
            self, directory=self.main_window.settings.DIR_CORPORA)
        if os.path.isdir(location):
            self.corpus = Corpus("New Corpus",
                                 location,
                                 template_movie_path="data/template.mp4")
            self.corpus.save(
                os.path.join(self.corpus.directory, self.corpus.name))
            self.onCorpusChanged.emit(self.corpus)
            self.show()
            self.raise_()

    def on_save_corpus(self):
        if self.corpus is None:
            QMessageBox.warning(
                self, "No Corpus loaded",
                "No corpus has been loaded yet. Either load one or create "
                "a new one in the file menu")
            return
        else:
            self.corpus.save()
            self.main_window.settings.add_recent_corpus2(self.corpus)

    def on_create_project(self):
        if self.corpus is None:
            QMessageBox.warning(
                self, "No Corpus loaded",
                "No corpus has been loaded yet. Either load one or create "
                "a new one in the file menu")
            return

        file = QFileDialog.getOpenFileName(self,
                                           caption="Select a Movie File")[0]
        if not os.path.isfile(file):
            return
        self.main_window.on_new_project(file, add_to_current_corpus=True)

    def on_remove_project(self, name, item):
        if self.corpus is None:
            QMessageBox.warning(
                self, "No Corpus loaded",
                "No corpus has been loaded yet. Either load one or create "
                "a new one in the file menu")
            return
        project = item.meta
        if project is None:
            return
        self.corpus.remove_project(project)

    def on_load_corpus(self):
        if self.corpus is not None:
            self.corpus.save(
                os.path.join(self.corpus.directory, self.corpus.name))
        file = QFileDialog.getOpenFileName(
            directory=self.main_window.settings.DIR_CORPORA)[0]
        if not os.path.isfile(file):
            return
        self.load_corpus(file)

    def load_corpus(self, file):
        self.corpus = Corpus("NewCorpus").load(file)
        self.show()
        self.raise_()
        self.main_window.settings.add_recent_corpus2(self.corpus)
        self.onCorpusChanged.emit(self.corpus)
        return self.corpus

    def on_import_projects(self):
        if self.corpus is None:
            QMessageBox.warning(
                self, "No Corpus loaded",
                "No corpus has been loaded yet. Either load one or create "
                "a new one in the file menu")
            return
        file = QFileDialog.getOpenFileName(
            directory=self.main_window.settings.DIR_CORPORA)[0]
        if not os.path.isfile(file):
            return
        self.corpus.add_project(file=file)

        self.corpus.save()
        self.main_window.settings.add_recent_corpus2(self.corpus)

    def on_edit_template(self):
        if self.corpus is None:
            return
        if self.main_window.project is not None:
            self.main_window.on_save_project()
            self.last_project = self.main_window.project.path
        self.main_window.project = self.corpus.template
        self.main_window.dispatch_on_loaded()
        self.set_in_template_mode(True)

    def on_close_template(self):
        if self.main_window.project is self.corpus.template:
            self.corpus.save()
        if self.last_project is not None:
            self.main_window.load_project(self.last_project)
        self.set_in_template_mode(False)
        self.last_project = None

    def on_save_template(self):
        if self.corpus is not None:
            self.corpus.reload()
            self.corpus.apply_template_to_all()
        self.on_close_template()

    def import_template(self):
        file = QFileDialog.getOpenFileName(self,
                                           directory="data/templates",
                                           filter="*.viant")[0]
        if not os.path.isfile(file):
            return
        self.corpus.import_template(file)
        self.on_save_triggered()

    def on_selection_changed(self, selection):
        try:
            if len(selection) > 0:
                project = selection[0].meta
                if project is None:
                    return
                self.filmography.set_filmography(
                    project.movie_descriptor.meta_data)
                self.onSelectionChanged.emit(project)
                self.current_project = project
                self.general_widget.on_project_changed(self.current_project)
            else:
                self.current_project = None
        except Exception as e:
            raise e

    def save_current_project(self):
        if self.current_project is not None:
            self.current_project.movie_descriptor.meta_data = self.filmography.get_filmography(
            )
            self.current_project.store_project()
            self.corpus.reload(self.current_project)

    def on_save_triggered(self):
        if self.corpus is not None:
            self.on_save_corpus()
            self.main_window.settings.add_recent_corpus2(self.corpus)
            self.corpus.reload()

    def on_close_corpus(self):
        if self.corpus is not None:
            self.corpus.save(
                os.path.join(self.corpus.directory, self.corpus.name))
            self.corpus = None
            self.onCorpusChanged.emit(None)

    def set_in_template_mode(self, state):
        if state:
            self.general_widget.templateStack.setCurrentIndex(1)
        else:
            self.general_widget.templateStack.setCurrentIndex(0)
        self.in_template_mode = state
Example #4
0
    def test_project_management(self):
        os.mkdir("data/projects/")

        corpus = Corpus("TestCorpus", directory="data/")

        proj1 = VIANProject("P1", folder="data/projects/p1", movie_path=p1)
        proj1.store_project()
        proj2 = VIANProject("P2", folder="data/projects/p2", movie_path=p2)
        proj2.store_project()
        proj3 = VIANProject("P3", folder="data/projects/p3", movie_path=p3)
        proj3.store_project()
        proj4 = VIANProject("P4", folder="data/projects/p4", movie_path=p4)
        proj4.store_project()

        corpus.add_project(proj1)
        corpus.add_project(proj2)
        corpus.add_project(file=proj3.path)
        corpus.add_project(file=proj4.path)

        self.assertTrue(len(corpus.project_paths) == 4)
        self.assertTrue(len(corpus.projects_loaded) == 4)

        corpus.remove_project(proj1)
        corpus.remove_project(file=proj4.path)

        self.assertTrue(len(corpus.project_paths) == 2)
        self.assertTrue(len(corpus.projects_loaded) == 2)

        corpus.remove_project(file=proj3.path, delete_from_disk=True)
        self.assertTrue(not os.path.isdir(proj3.folder))
Example #5
0
 def test_serialization(self):
     corpus = Corpus("TestCorpus", directory="data/")
     corpus.save("data/corpus.vian_corpus")
     corpus2 = Corpus("TestCorpus", directory="data/")
     corpus2.load("data/corpus.vian_corpus")