Top

video_track module

from io import StringIO

from undo.add_action import AddAction
from undo.delete_time_action import DeleteTimeAction 
from undo.remove_action import RemoveAction 
from undo.undo_manager import UndoManager 
from video.time_code import TimeCode

class VideoTrack(object):
    '''
    This class models a video track which can contain a number of video segments
    called VideoSections. The class contains a set of operations for modifying
    contents of the track. The operations can be both undone and redone using the
    undo() and redo() commands.
    
    VideoTrack contains a list of VideoSections that is guaranteed not to contain
    None-values.
    '''



    #------------ initialization ---------------
    
    
    def __init__(self, name, undo_manager):
        '''
        Constructs a new VideoTrack with the given UndoManager.

        @param name: Name of the track created.

        @param undo_manager: Undo manager for this track.
        '''
        self.track_name = name     # Name of this VideoTrack
        self.sections = []         # An list containing the videosections of this video track.
        self.undo_manager = undo_manager     # UndoManager of this VideoTrack.
    

    def undo(self):
        '''
        Undoes the last action. (add, remove, delete, apply)
        '''
        if self.undo_manager.can_undo():
            self.undo_manager.undo()
            return True
        return False
    

    def redo(self):
        '''
        Redoes the last action. (add, remove, delete, apply)
        '''
        if self.undo_manager.can_redo():
            self.undo_manager.redo()
            return True
        return False

    def describe_undoable_action(self):
        '''
        Describes an available undoable action.

        @return: A description of the undoable action for menus etc.

        @see: UndoManager#describe_undoable_action()
        '''
        return self.undo_manager.describe_undoable_action()
    

    def describe_redoable_action(self):
        '''
        Describes an available redoable action.

        @return: A description of the redoable action for menus etc.

        @see: UndoManager#describe_redoable_action()
        '''
        return self.undo_manager.describe_redoable_action()
    
    
    def add_section(self, section):
        '''
        Performs a single undoable action where a VideoSection is added on this
        VideoTrack. The section is added after the last section currently
        contained in the track. If there are no such sections, the section is
        added at 00:00:00.

        @param section: Section to add.
        '''
        action = AddAction(self, section)
        action.execute()

        self.undo_manager.add_action(action)
    

    def remove_section(self, section):
        '''
        Performs a single undoable action where a VideoSection is removed from
        this VideoTrack.

        @param section: Section to remove.
        '''

        action =  RemoveAction(self, section)
        action.execute()
        
        self.undo_manager.add_action(action)


    def delete_time(self, start, end):
        '''
        Performs a single undoable action where a selected segment of time
        (containing fully or partially 0-N VideoSegments) is deleted from this
        VideoTrack. Partial segments are splitted so that only the requested part
        is deleted. The first and last frames to be deleted are both included in the deleted
        part.

        @param start: First frame to delete.

        @param end: Last frame to delete.
        '''

        action =  DeleteTimeAction(self, start, end)
        action.execute()
        
        self.undo_manager.add_action(action)

    
    def get_section_iterator(self):
        '''
        Returns an iterator for browsing through the contents of the section list.

        @return: an iterator for the section list of this VideoTrack.
        '''
        return iter(self.sections)

    
    def get_section_at(self, time):
        '''
        Returns the section at the given TimeCode.

        @param time: the timecode of the moment of interest.

        @return: reference to the VideoSection object or null if a section could not be found.
        '''

        section_iterator = self.get_section_iterator()
        try:
            while True:
                current = next(section_iterator)
                if time.inclusive_between(current.get_start(), current.get_end()):
                    return current
        except StopIteration:
            return None

    
    def __str__(self):
        '''
        Constructs a String representation of this video track.

        @return: a String representation of this VideoTrack.
        '''
        output = StringIO()
        current_time = TimeCode(0, 0, 0)

        section_iterator = self.get_section_iterator()
        
        try:
            while True:
                current = next(section_iterator)
    
                if current_time.equals(current.get_start()) == False:
                    output.write("UNUSED  :\n\t" + str(current_time) + " - "
                            + str(current.get_start().previous_frame()) + "\n")
                output.write(str(current))
                output.write("\n")
    
                current_time = current.get_end().next_frame()
        except StopIteration:
            return output.getvalue()

    
    def get_name(self):
        '''
        Returns the name of this VideoTrack.

        @return: name of the track.
        ''' 
        return self.track_name

Classes

class VideoTrack

This class models a video track which can contain a number of video segments called VideoSections. The class contains a set of operations for modifying contents of the track. The operations can be both undone and redone using the undo() and redo() commands.

VideoTrack contains a list of VideoSections that is guaranteed not to contain None-values.

class VideoTrack(object):
    '''
    This class models a video track which can contain a number of video segments
    called VideoSections. The class contains a set of operations for modifying
    contents of the track. The operations can be both undone and redone using the
    undo() and redo() commands.
    
    VideoTrack contains a list of VideoSections that is guaranteed not to contain
    None-values.
    '''



    #------------ initialization ---------------
    
    
    def __init__(self, name, undo_manager):
        '''
        Constructs a new VideoTrack with the given UndoManager.

        @param name: Name of the track created.

        @param undo_manager: Undo manager for this track.
        '''
        self.track_name = name     # Name of this VideoTrack
        self.sections = []         # An list containing the videosections of this video track.
        self.undo_manager = undo_manager     # UndoManager of this VideoTrack.
    

    def undo(self):
        '''
        Undoes the last action. (add, remove, delete, apply)
        '''
        if self.undo_manager.can_undo():
            self.undo_manager.undo()
            return True
        return False
    

    def redo(self):
        '''
        Redoes the last action. (add, remove, delete, apply)
        '''
        if self.undo_manager.can_redo():
            self.undo_manager.redo()
            return True
        return False

    def describe_undoable_action(self):
        '''
        Describes an available undoable action.

        @return: A description of the undoable action for menus etc.

        @see: UndoManager#describe_undoable_action()
        '''
        return self.undo_manager.describe_undoable_action()
    

    def describe_redoable_action(self):
        '''
        Describes an available redoable action.

        @return: A description of the redoable action for menus etc.

        @see: UndoManager#describe_redoable_action()
        '''
        return self.undo_manager.describe_redoable_action()
    
    
    def add_section(self, section):
        '''
        Performs a single undoable action where a VideoSection is added on this
        VideoTrack. The section is added after the last section currently
        contained in the track. If there are no such sections, the section is
        added at 00:00:00.

        @param section: Section to add.
        '''
        action = AddAction(self, section)
        action.execute()

        self.undo_manager.add_action(action)
    

    def remove_section(self, section):
        '''
        Performs a single undoable action where a VideoSection is removed from
        this VideoTrack.

        @param section: Section to remove.
        '''

        action =  RemoveAction(self, section)
        action.execute()
        
        self.undo_manager.add_action(action)


    def delete_time(self, start, end):
        '''
        Performs a single undoable action where a selected segment of time
        (containing fully or partially 0-N VideoSegments) is deleted from this
        VideoTrack. Partial segments are splitted so that only the requested part
        is deleted. The first and last frames to be deleted are both included in the deleted
        part.

        @param start: First frame to delete.

        @param end: Last frame to delete.
        '''

        action =  DeleteTimeAction(self, start, end)
        action.execute()
        
        self.undo_manager.add_action(action)

    
    def get_section_iterator(self):
        '''
        Returns an iterator for browsing through the contents of the section list.

        @return: an iterator for the section list of this VideoTrack.
        '''
        return iter(self.sections)

    
    def get_section_at(self, time):
        '''
        Returns the section at the given TimeCode.

        @param time: the timecode of the moment of interest.

        @return: reference to the VideoSection object or null if a section could not be found.
        '''

        section_iterator = self.get_section_iterator()
        try:
            while True:
                current = next(section_iterator)
                if time.inclusive_between(current.get_start(), current.get_end()):
                    return current
        except StopIteration:
            return None

    
    def __str__(self):
        '''
        Constructs a String representation of this video track.

        @return: a String representation of this VideoTrack.
        '''
        output = StringIO()
        current_time = TimeCode(0, 0, 0)

        section_iterator = self.get_section_iterator()
        
        try:
            while True:
                current = next(section_iterator)
    
                if current_time.equals(current.get_start()) == False:
                    output.write("UNUSED  :\n\t" + str(current_time) + " - "
                            + str(current.get_start().previous_frame()) + "\n")
                output.write(str(current))
                output.write("\n")
    
                current_time = current.get_end().next_frame()
        except StopIteration:
            return output.getvalue()

    
    def get_name(self):
        '''
        Returns the name of this VideoTrack.

        @return: name of the track.
        ''' 
        return self.track_name

Ancestors (in MRO)

Instance variables

var sections

var track_name

var undo_manager

Methods

def __init__(

self, name, undo_manager)

Constructs a new VideoTrack with the given UndoManager.

@param name: Name of the track created.

@param undo_manager: Undo manager for this track.

def __init__(self, name, undo_manager):
    '''
    Constructs a new VideoTrack with the given UndoManager.
    @param name: Name of the track created.
    @param undo_manager: Undo manager for this track.
    '''
    self.track_name = name     # Name of this VideoTrack
    self.sections = []         # An list containing the videosections of this video track.
    self.undo_manager = undo_manager     # UndoManager of this VideoTrack.

def add_section(

self, section)

Performs a single undoable action where a VideoSection is added on this VideoTrack. The section is added after the last section currently contained in the track. If there are no such sections, the section is added at 00:00:00.

@param section: Section to add.

def add_section(self, section):
    '''
    Performs a single undoable action where a VideoSection is added on this
    VideoTrack. The section is added after the last section currently
    contained in the track. If there are no such sections, the section is
    added at 00:00:00.
    @param section: Section to add.
    '''
    action = AddAction(self, section)
    action.execute()
    self.undo_manager.add_action(action)

def delete_time(

self, start, end)

Performs a single undoable action where a selected segment of time (containing fully or partially 0-N VideoSegments) is deleted from this VideoTrack. Partial segments are splitted so that only the requested part is deleted. The first and last frames to be deleted are both included in the deleted part.

@param start: First frame to delete.

@param end: Last frame to delete.

def delete_time(self, start, end):
    '''
    Performs a single undoable action where a selected segment of time
    (containing fully or partially 0-N VideoSegments) is deleted from this
    VideoTrack. Partial segments are splitted so that only the requested part
    is deleted. The first and last frames to be deleted are both included in the deleted
    part.
    @param start: First frame to delete.
    @param end: Last frame to delete.
    '''
    action =  DeleteTimeAction(self, start, end)
    action.execute()
    
    self.undo_manager.add_action(action)

def describe_redoable_action(

self)

Describes an available redoable action.

@return: A description of the redoable action for menus etc.

@see: UndoManager#describe_redoable_action()

def describe_redoable_action(self):
    '''
    Describes an available redoable action.
    @return: A description of the redoable action for menus etc.
    @see: UndoManager#describe_redoable_action()
    '''
    return self.undo_manager.describe_redoable_action()

def describe_undoable_action(

self)

Describes an available undoable action.

@return: A description of the undoable action for menus etc.

@see: UndoManager#describe_undoable_action()

def describe_undoable_action(self):
    '''
    Describes an available undoable action.
    @return: A description of the undoable action for menus etc.
    @see: UndoManager#describe_undoable_action()
    '''
    return self.undo_manager.describe_undoable_action()

def get_name(

self)

Returns the name of this VideoTrack.

@return: name of the track.

def get_name(self):
    '''
    Returns the name of this VideoTrack.
    @return: name of the track.
    ''' 
    return self.track_name

def get_section_at(

self, time)

Returns the section at the given TimeCode.

@param time: the timecode of the moment of interest.

@return: reference to the VideoSection object or null if a section could not be found.

def get_section_at(self, time):
    '''
    Returns the section at the given TimeCode.
    @param time: the timecode of the moment of interest.
    @return: reference to the VideoSection object or null if a section could not be found.
    '''
    section_iterator = self.get_section_iterator()
    try:
        while True:
            current = next(section_iterator)
            if time.inclusive_between(current.get_start(), current.get_end()):
                return current
    except StopIteration:
        return None

def get_section_iterator(

self)

Returns an iterator for browsing through the contents of the section list.

@return: an iterator for the section list of this VideoTrack.

def get_section_iterator(self):
    '''
    Returns an iterator for browsing through the contents of the section list.
    @return: an iterator for the section list of this VideoTrack.
    '''
    return iter(self.sections)

def redo(

self)

Redoes the last action. (add, remove, delete, apply)

def redo(self):
    '''
    Redoes the last action. (add, remove, delete, apply)
    '''
    if self.undo_manager.can_redo():
        self.undo_manager.redo()
        return True
    return False

def remove_section(

self, section)

Performs a single undoable action where a VideoSection is removed from this VideoTrack.

@param section: Section to remove.

def remove_section(self, section):
    '''
    Performs a single undoable action where a VideoSection is removed from
    this VideoTrack.
    @param section: Section to remove.
    '''
    action =  RemoveAction(self, section)
    action.execute()
    
    self.undo_manager.add_action(action)

def undo(

self)

Undoes the last action. (add, remove, delete, apply)

def undo(self):
    '''
    Undoes the last action. (add, remove, delete, apply)
    '''
    if self.undo_manager.can_undo():
        self.undo_manager.undo()
        return True
    return False