#!bpy
"""
Name: 'SceneConfigurator'
Blender: 2.7x
Group: 'Low poly'
Tooltip: 'Configure standard settings in a new scene'
"""
import bpy


class SceneConfigurator:
    """Configure a scene"""

    def __init__(self):
        pass

    def cam2empty(self):
        """Trac camera to empty

        Move the empty and the camera will point in this direction
        """
        bpy.ops.object.empty_add(type='PLAIN_AXES',
                                 view_align=False,
     			    location=(0, 0, 0))
        bpy.ops.object.camera_add(view_align=True,
                                  enter_editmode=False,
     			     location=(8, 8, 30),
     			     rotation=(0, 0, 0))
        bpy.ops.object.select_pattern(pattern='Empty')
        bpy.ops.object.select_pattern(pattern='Camera')
        bpy.ops.object.constraint_add(type='TRACK_TO')
        bpy.context.object.constraints["Track To"].target = bpy.data.objects["Empty"]
        bpy.context.object.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'
        bpy.context.object.constraints["Track To"].up_axis = 'UP_Y'

    def sky(self):        
        bpy.context.scene.world.use_sky_paper = True
        bpy.context.scene.world.use_sky_blend = True
        bpy.context.scene.world.horizon_color = (0.606907, 0.613911, 0.837134)

    def remove(self, name=None):
        """ Delete an object by name"""

        if name:
            bpy.ops.object.select_pattern(pattern=name)
        else:
            print('nothing to do')
         
        bpy.ops.object.delete()

if __name__ == "__main__":

    # switch to object mode, if nessasary
    if bpy.ops.object.mode_set.poll():
        bpy.ops.object.mode_set(mode='OBJECT')
    ctrl = SceneConfigurator()
    ctrl.remove(name="Empty")
    ctrl.remove(name="Camera")
    ctrl.cam2empty()
    ctrl.sky()