add_action module
from video.time_code import TimeCode class AddAction(object): ''' AddAction implements a single undoable action where a VideoSection is added on a VideoTrack. ''' def __init__(self, track, section): ''' Creates an AddAction that adds the given VideoSection to the given VideoTrack. @param section: The section to be added. ''' # Save the item to add and the list to add to self.section_list = track.sections # Section list of the video track self.section_to_add = section # Section to be added on the video track # Save the old and new video track self.new_track = track # VideoTrack of the VideoSection after addition self.old_track = section.get_track() # VideoTrack of the VideoSection before addition # If there are no other sections, the section is placed at 00:00:00. if not self.section_list: self.new_time = TimeCode(0, 0, 0) # new beginning timecode for this section. else: # If there are other sections, the section begins one frame after # the last section in the sectionlist ends last_section = self.section_list[len(self.section_list) - 1] self.new_time = last_section.get_end().next_frame() # Store the old beginning time for undo. self.old_time = self.section_to_add.get_start() # original beginning timecode for this section # Future position of the section in the section list. self.add_index = len(self.section_list) # index where in the section list the section is to be added. def get_description(self): ''' Returns a brief explanation of the action. Can be used for example to provide action descriptions for a GUI such as "undo adding a section". @return: description of this action. ''' return "adding a section" def redo(self): ''' This method re-does an action performed and recorded in an UndoManager. ''' self.execute() def undo(self): ''' This method undoes an action performed and recorded in an UndoManager. ''' # remove the section from the section list self.section_list.pop(self.add_index) # restore the old starting and ending times for this section. self.section_to_add.transpose(self.old_time) # restore the old track self.section_to_add.set_track(self.old_track) def execute(self): ''' This method performs the original action. It should be executed only once. The redo-implementation calls this method. ''' # Set the new starting and ending times for this section. self.section_to_add.transpose(self.new_time) # Is the section added in the end or in the middle? if self.add_index > len(self.section_list): self.section_list.append(self.section_to_add) else: self.section_list.insert(self.add_index, self.section_to_add) self.section_to_add.set_track(self.new_track)
Classes
class AddAction
AddAction implements a single undoable action where a VideoSection is added on a VideoTrack.
class AddAction(object): ''' AddAction implements a single undoable action where a VideoSection is added on a VideoTrack. ''' def __init__(self, track, section): ''' Creates an AddAction that adds the given VideoSection to the given VideoTrack. @param section: The section to be added. ''' # Save the item to add and the list to add to self.section_list = track.sections # Section list of the video track self.section_to_add = section # Section to be added on the video track # Save the old and new video track self.new_track = track # VideoTrack of the VideoSection after addition self.old_track = section.get_track() # VideoTrack of the VideoSection before addition # If there are no other sections, the section is placed at 00:00:00. if not self.section_list: self.new_time = TimeCode(0, 0, 0) # new beginning timecode for this section. else: # If there are other sections, the section begins one frame after # the last section in the sectionlist ends last_section = self.section_list[len(self.section_list) - 1] self.new_time = last_section.get_end().next_frame() # Store the old beginning time for undo. self.old_time = self.section_to_add.get_start() # original beginning timecode for this section # Future position of the section in the section list. self.add_index = len(self.section_list) # index where in the section list the section is to be added. def get_description(self): ''' Returns a brief explanation of the action. Can be used for example to provide action descriptions for a GUI such as "undo adding a section". @return: description of this action. ''' return "adding a section" def redo(self): ''' This method re-does an action performed and recorded in an UndoManager. ''' self.execute() def undo(self): ''' This method undoes an action performed and recorded in an UndoManager. ''' # remove the section from the section list self.section_list.pop(self.add_index) # restore the old starting and ending times for this section. self.section_to_add.transpose(self.old_time) # restore the old track self.section_to_add.set_track(self.old_track) def execute(self): ''' This method performs the original action. It should be executed only once. The redo-implementation calls this method. ''' # Set the new starting and ending times for this section. self.section_to_add.transpose(self.new_time) # Is the section added in the end or in the middle? if self.add_index > len(self.section_list): self.section_list.append(self.section_to_add) else: self.section_list.insert(self.add_index, self.section_to_add) self.section_to_add.set_track(self.new_track)
Ancestors (in MRO)
- AddAction
- __builtin__.object
Instance variables
var add_index
var new_track
var old_time
var old_track
var section_list
var section_to_add
Methods
def __init__(
self, track, section)
Creates an AddAction that adds the given VideoSection to the given VideoTrack.
@param section: The section to be added.
def __init__(self, track, section): ''' Creates an AddAction that adds the given VideoSection to the given VideoTrack. @param section: The section to be added. ''' # Save the item to add and the list to add to self.section_list = track.sections # Section list of the video track self.section_to_add = section # Section to be added on the video track # Save the old and new video track self.new_track = track # VideoTrack of the VideoSection after addition self.old_track = section.get_track() # VideoTrack of the VideoSection before addition # If there are no other sections, the section is placed at 00:00:00. if not self.section_list: self.new_time = TimeCode(0, 0, 0) # new beginning timecode for this section. else: # If there are other sections, the section begins one frame after # the last section in the sectionlist ends last_section = self.section_list[len(self.section_list) - 1] self.new_time = last_section.get_end().next_frame() # Store the old beginning time for undo. self.old_time = self.section_to_add.get_start() # original beginning timecode for this section # Future position of the section in the section list. self.add_index = len(self.section_list) # index where in the section list the section is to be added.
def execute(
self)
This method performs the original action. It should be executed only once. The redo-implementation calls this method.
def execute(self): ''' This method performs the original action. It should be executed only once. The redo-implementation calls this method. ''' # Set the new starting and ending times for this section. self.section_to_add.transpose(self.new_time) # Is the section added in the end or in the middle? if self.add_index > len(self.section_list): self.section_list.append(self.section_to_add) else: self.section_list.insert(self.add_index, self.section_to_add) self.section_to_add.set_track(self.new_track)
def get_description(
self)
Returns a brief explanation of the action. Can be used for example to provide action descriptions for a GUI such as "undo adding a section".
@return: description of this action.
def get_description(self): ''' Returns a brief explanation of the action. Can be used for example to provide action descriptions for a GUI such as "undo adding a section". @return: description of this action. ''' return "adding a section"
def redo(
self)
This method re-does an action performed and recorded in an UndoManager.
def redo(self): ''' This method re-does an action performed and recorded in an UndoManager. ''' self.execute()
def undo(
self)
This method undoes an action performed and recorded in an UndoManager.
def undo(self): ''' This method undoes an action performed and recorded in an UndoManager. ''' # remove the section from the section list self.section_list.pop(self.add_index) # restore the old starting and ending times for this section. self.section_to_add.transpose(self.old_time) # restore the old track self.section_to_add.set_track(self.old_track)