def pickFileNames(self):
        """
        This method saves the selected files in a list and add this to the filemanager window
        This method ensures that only supported files are displayed and can be used.
        """
        self.full_path = Project.get_instance().path
        self.directory_strings = self.full_path.split('/')
        self.project_name = self.directory_strings[-2]
        self.directory_strings.pop(-1)
        self.directory_strings.pop(-1)
        self.project_path = os.path.join(
            '/', *self.directory_strings
        )  #* takes every element of the list as single argument

        supported_filetypes = Settings.get_instance().get_dict_settings(
        )["Invisible"]["filemanager_import_formats"]
        fileNames, _ = QFileDialog.getOpenFileNames(
            self.__filemanager_view, 'QFileDialog.getOpenFileNames()', '',
            (supported_filetypes))

        if not fileNames:
            return

        for file in fileNames:
            QApplication.processEvents()
            self.addFileNames(file)

        project = Project.get_instance()
        if not project.changed:
            project.changed = True
            self.__filemanager_view.changed.emit()
    def handle_drop(self, item, path):
        list_widget = self.__filemanager_view.listWidget

        # get the source item
        item_list = list_widget.findItems(os.path.basename(path),
                                          Qt.MatchExactly)
        if not item_list:
            return

        source_item = item_list[0]

        # find folder
        file_list = self.get_current_file_list()
        for file in file_list:
            if isinstance(file, Folder) and file.get_name() == item.text():
                # check if file already exists in folder
                if path in file.get_content():
                    return

                # remove old file
                file_list.remove(source_item.statusTip())
                list_widget.removeItemWidget(source_item)
                self.update_file_list(self.get_current_file_list())

                # add to foldeer
                file.add_to_content(path)

                project = Project.get_instance()
                if not project.changed:
                    project.changed = True
                    self.__filemanager_view.changed.emit()

                return
    def remove(self):
        """
        This method removes a single file or directory in the filemanager from
        the list it is stored in.
        """
        item = self.__filemanager_view.listWidget.currentItem()
        file_list = self.get_current_file_list()

        is_folder = False
        for file in file_list:
            if isinstance(file, Folder):
                if file.get_name() == item.text():
                    is_folder = True
                    item = file
                    break

        if is_folder:
            file_list.remove(item)
        else:
            file_list.remove(item.statusTip())

        self.__filemanager_view.remove_selected_item()

        project = Project.get_instance()
        if not project.changed:
            project.changed = True
            self.__filemanager_view.changed.emit()
    def __start_open(self):
        """ Open a project """
        self.__video_editor_view.previewview.stop()
        filetypes = Settings.get_instance().get_dict_settings()[
            "Invisible"]["project_formats"]
        path, _ = QFileDialog.getOpenFileName(self.__video_editor_view,
                                              'Open Project', '', filetypes)

        # do nothing if cancel was clicked
        if path == "":
            return

        with open(path, 'r') as f:
            project_data = json.load(f)

        # set up timeline
        self.__timeline_controller.clear_timeline()

        if "timeline" in project_data:
            self.__timeline_controller.create_project_timeline(project_data["timeline"])
        else:
            self.__timeline_controller.create_default_tracks()

        # set up filemanager
        self.__filemanager_controller.clear()

        if "filemanager" in project_data:
            filemanager_data = project_data["filemanager"]
            self.__filemanager_controller.create_project_filemanager(filemanager_data)

        # set project path
        project = Project.get_instance()
        project.path = path
        project.changed = False
        self.set_title_saved()
    def __init__(self):
        """
        Virtually private constructor.

        Loads the settings file (projectconfig.py) for default settings and saved projectsettings.
        If 'projectconfig.uc" contains values that are
        different from the values in 'projectconfig.py', this values will be
        overwritten.
        Then the JSON gets converted into an object, where the settings can
        be accessed via dot-notation.
        """

        if Projectsettings.__instance is not None:
            raise Exception("This class is a singleton!")
        else:
            Projectsettings.__instance = self
            project_config = Project.get_instance().path
            if project_config is not None and os.path.exists(project_config):
                with open(project_config, 'r') as read_file:
                    self.project_config_data = json.load(
                        read_file)["projectsettings"]
                    projectconfig.default_settings.update(
                        self.project_config_data)
                    self.parsed_data = projectconfig.default_settings

            else:
                self.parsed_data = projectconfig.default_settings

            self.parsed_json = json.dumps(self.parsed_data, ensure_ascii=False)

            self.dict = json.loads(self.parsed_json)

            self.settings = json.loads(
                self.parsed_json,
                object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
    def __start_save(self):
        """ Save the Project """
        project = Project.get_instance()
        if project.path is None:
            self.__start_save_as()
            return

        self.__write_project_data(project.path)
    def new_folder(self):
        """Starts the creation of a new folder."""

        self.addFileNames(None)

        project = Project.get_instance()
        if not project.changed:
            project.changed = True
            self.__filemanager_view.changed.emit()
Esempio n. 8
0
    def dragLeaveEvent(self, event):
        """ Gets called when something is dragged out of the track """
        if self.current_timeable is not None:
            # delete dragged timeable if mouse leaves track
            self.current_timeable.delete(hist=False)
            if not self.drag_from_track:
                Project.get_instance().get_history().remove_last_operation()
            if self.current_timeable_2 is not None:
                self.current_timeable_2.delete(hist=False)

            # clear data
            self.item_dropped = False
            self.current_timeable = None
            self.current_timeable_2 = None

            event.ignore()

        self.update()
        event.accept()
    def new_project(self, path):
        """
        Initially saves the project to the project file.

        :param path: String - Path to the projects file.
        """
        self.__write_project_data(path)
        project = Project.get_instance()
        project.path = path

        Projectsettings.add_project(path)
Esempio n. 10
0
    def create_group(self, group_id, timeables):
        """
        Create a TimeableGroup with all timeables in ids in it.
        The group will be added to the timeline model.

        @param ids: list of ids of timeable views
        @return: Nothing
        """
        self.groups[group_id] = TimeableGroup(group_id, timeables)
        project = Project.get_instance()
        if not project.changed:
            project.changed = True
Esempio n. 11
0
    def remove_timeable(self, timeable):
        """
        Removes the timeable with the given id from the group

        @param timeable: the timeable view that will be removed
        @return: Nothing
        """
        while timeable in self.timeables:
            self.timeables.remove(timeable)

        project = Project.get_instance()
        if not project.changed:
            project.changed = True
    def add_track(self, name, width, height, index, is_video):
        """
        Creates a new Track.

        @param track_id: id of the track which will be created
        @return: Nothing
        """
        track_id = max(self.__timeline_view.tracks.keys()) + 1
        op = CreateTrackOperation(track_id, name, width, height, index,
                                  is_video, self)
        self.__history.do_operation(op)

        self.__timeline_view.changed.emit()
        Project.get_instance().changed = True
Esempio n. 13
0
    def add_timeable(self, timeable):
        """
        Adds a timeable to a timeable group.

        @param timeable: the timeable view that will be added
        @return: Nothing
        """
        if timeable in self.timeables:
            return

        self.timeables.append(timeable)
        timeable.group_id = self.group_id

        project = Project.get_instance()
        if not project.changed:
            project.changed = True
    def __start_save_as(self):
        """ Lets the user select a file and saves the project in that file """
        # select file
        file_dialog = QFileDialog(self.__video_editor_view)
        file_dialog.setAcceptMode(QFileDialog.AcceptSave)
        file_dialog.setNameFilter('uc files (*.uc)')
        file_dialog.setDefaultSuffix('uc')
        if file_dialog.exec_() == QFileDialog.Accepted:
            filename = file_dialog.selectedFiles()[0]
        else:
            return

        self.__write_project_data(filename)

        project = Project.get_instance()
        project.path = filename

        Projectsettings.add_project(filename)
Esempio n. 15
0
    def __init__(self, window, key_sequence, operation):
        """
        Creates a new QShortcut

        @type  window: QMainWindow
        @param window: The window, the shortcut gets assigned to.
        @type  key_sequence: string
        @param key_sequence: The key sequence to activate the shortcut
        @type  operation: string
        @param operation: Operation that should be executed when the shortcut
                            keys are pressed
        """
        shortcut = QShortcut(QKeySequence(key_sequence), window)
        shortcut.activated.connect(lambda: self.__execute(operation))

        self.__history = Project.get_instance().get_history()

        self.video_editor_view = window
Esempio n. 16
0
    def change(self, change_type, key, data):
        """
        @param change_type: insert, delete or update
        @param key: defines what will be changed (clips or effects)
        @param data: dict with data to update
        """
        update_dict = {
            "type": change_type,
            "key": key,
            "value": data
        }

        update_string = json.dumps([update_dict])
        self.timeline.ApplyJsonDiff(update_string)

        project = Project.get_instance()
        if not project.changed:
            project.changed = True
Esempio n. 17
0
    def __load_project(self):
        """ Closes the start window and loads the selected project """
        # get path from listwidget
        project_list = self.__start_view.select_project_widget.projects_list_view
        # return if no project is selected
        if project_list.currentItem() is None:
            return

        path = project_list.currentItem().statusTip()

        # check if file exists
        if os.path.isfile(path):

            self.init_video_editor()

            with open(path, 'r') as f:
                project_data = json.load(f)
            # set up timeline
            timeline_controller = TimelineController.get_instance()
            if "timeline" in project_data:
                timeline_controller.create_project_timeline(
                    project_data["timeline"])
            else:
                timeline_controller.create_default_tracks()

            # set up filemanager
            if "filemanager" in project_data:
                filemanager = self.__video_editor_controller.get_filemanager_controller(
                )
                filemanager.create_project_filemanager(
                    project_data["filemanager"])

            if "groups" in project_data:
                timeline_controller.create_project_groups(
                    project_data["groups"])

            # set project path
            project = Project.get_instance()
            project.path = path
            project.changed = False

            # show videoeditor
            self.__start_view.close()
            self.__video_editor_controller.start()
    def delete_track(self, track_id):
        """
        Removes a track and all the timeables in it.

        @param track_id: id of the track which will be deleted
        @return: Nothing
        """
        track = self.__timeline_view.tracks[track_id]
        if track is None:
            return

        track_data = track.get_info_dict()
        timeables = [t.get_info_dict() for t in track.items()]
        index = self.get_track_index(track)

        op = DeleteTrackOperation(track_id, track_data, timeables, index, self)
        self.__history.do_operation(op)

        self.__timeline_view.changed.emit()
        Project.get_instance().changed = True
    def __write_project_data(self, filename):
        """ Saves project data into a file """
        # get timeline data
        timeline_data = self.__timeline_controller.get_project_timeline()

        # get filemanager data
        filemanager_data = self.__filemanager_controller.get_project_filemanager()

        project_data = {
            "timeline": timeline_data,
            "filemanager": filemanager_data,
            "projectsettings": Projectsettings.get_instance().get_dict_projectsettings(),
            "groups": TimelineModel.get_instance().get_group_dict()
        }

        # write data
        with open(filename, 'w') as f:
            json.dump(project_data, f, ensure_ascii=False)

        Project.get_instance().changed = False
        self.set_title_saved()
    def closeEvent(self, event):
        """ Closes all open Windows """
        self.previewview.stop()
        if Project.get_instance().changed:
            msgbox = QMessageBox()
            res = msgbox.question(
                self, str(Language.current.errors.unsaved.msgboxtitle),
                str(Language.current.errors.unsaved.msgboxtext),
                QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)

            if res == QMessageBox.Yes:
                self.save_project.emit()
                QApplication.closeAllWindows()

                QMainWindow.closeEvent(self, event)

            elif res == QMessageBox.Cancel:
                event.ignore()
        else:
            QApplication.closeAllWindows()
            QMainWindow.closeEvent(self, event)
    def __init__(self, view):
        self.__video_editor_view = view
        self.__video_editor_view.save_project.connect(self.__start_save)
        self.__video_editor_view.timeline_view.changed.connect(self.set_title_unsaved)

        self.__timeline_controller = TimelineController.get_instance()
        self.__filemanager_view = FilemanagerView(self.__video_editor_view)
        self.__filemanager_view.changed.connect(self.set_title_unsaved)
        self.__filemanager_controller = FilemanagerController(self.__filemanager_view)

        self.__video_editor_view.set_filemanager_view(self.__filemanager_view)
        self.__video_editor_view.action_settings.triggered.connect(
            self.__start_settings_controller)

        self.settings_view = SettingsView()
        self.__settings_controller = SettingsController(self.settings_view)

        self.__video_editor_view.action_projectsettings.triggered.connect(
            self.__start_projectsettings_controller)
        self.projectsettings_view = ProjectSettingsView()
        self.projectsettings_view.changed.connect(self.set_title_unsaved)
        self.__projectsettings_controller = ProjectSettingsController(
            self.projectsettings_view)
        self.__video_editor_view.actionExport.triggered.connect(
            self.__start_export_controller)
        self.__video_editor_view.actionUndo.triggered.connect(
            self.__start_undo)
        self.__video_editor_view.actionRedo.triggered.connect(
            self.__start_redo)
        self.__video_editor_view.actionSpeichern.triggered.connect(
            self.__start_save)
        self.__video_editor_view.actionSpeichern_als.triggered.connect(
            self.__start_save_as)
        self.__video_editor_view.actionOeffnen.triggered.connect(
            self.__start_open)

        self.__history = Project.get_instance().get_history()
        ShortcutLoader(self.__video_editor_view)
    def __init__(self, timeline_view):
        TimelineController.__instance = self

        self.__timeline_view = timeline_view
        self.__timeline_model = TimelineModel.get_instance()
        self.__history = Project.get_instance().get_history()
 def set_title_saved(self):
     """ shows UbiCut in the windowtitle """
     name = Project.get_instance().get_project_name()
     self.__video_editor_view.setWindowTitle("UbiCut - " + name)
 def set_title_unsaved(self):
     """
     Shows a star in the window title to indicate that there are unsaved changes.
     """
     name = Project.get_instance().get_project_name()
     self.__video_editor_view.setWindowTitle("UbiCut - " + name + "*")