So I've worked on a local add-on that would allow me to adjust the start frame and the end frame of the playback loop. I created an enum list with three options: default, A, and B. Basically want I want to do is:

1. Adjust the start and end of the playback by selecting either default, A, or B on the add-on
2. A's playback would loop from 60-180 in the first time and then loop from 120-180. Same with B starting from 180-300 the first time and then from 240-300

If I select 'default' and play the animation it would work perfectly. But if I select 'default' again after I select either A or B, the first playback loop will go from 0-60, and then both start and end are at 120. Every time the animation will go from 0 to 120. Then clicking on A or B is even worse, the animation will run the desired range in the first time, then run from 0-120.

It seems like something is being overridden here. I'm not exactly sure how and why. Can anyone please help?

 def execute(self, context):
# execute() is called by blender when running the operator.

## helper function used to modify the start keyframe of the second loop
def keep(command):
scene = bpy.context.scene
if scene.frame_current == scene.frame_end:
if command == 'A':
scene.frame_start = 120
elif command == 'B':
scene.frame_start = 240
else:
raise TypeError("Invalid Input Command")

def handlerA(scene):
keep('A')
def handlerB(scene):
keep('B')

if self.options == 'default':
bpy.context.scene.frame_start = 0
bpy.context.scene.frame_current = 0
bpy.context.scene.frame_end = 60
elif self.options == 'A':
bpy.context.scene.frame_start = 60
bpy.context.scene.frame_current = 60
bpy.context.scene.frame_end = 180
bpy.app.handlers.frame_change_pre.append(handlerA)
elif self.options == 'B':
bpy.context.scene.frame_start = 180
bpy.context.scene.frame_current = 180
bpy.context.scene.frame_end = 300
bpy.app.handlers.frame_change_pre.append(handlerB)

return {'FINISHED'}            # this lets blender know the operator finished successfully.