 under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
    "name": "Render Settings",
    "author": "meta-androcto, Saidenka",
    "version": (0, 1, 1),
    "blender": (2, 80, 0),
    "location": "Render Menu, UV Editor Render Tab",
    "description": "Render Settings BI & Cycles",
    "warning": "",
    "wiki_url": "https://github.com/meta-androcto/blenderpython/wiki/AF_Render_Settings",
    "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
    "category": "Render"
}

import bpy
import sys
import subprocess


class RenderBackground(bpy.types.Operator):
    bl_idname = "render.render_background"
    bl_label = "Background Render"
    bl_description = "Render From The Commandline"
    bl_options = {'REGISTER'}

    is_quit: bpy.props.BoolProperty(name="Quit Blender", default=True)
    items = [
        ('IMAGE', "Image", "", 1),
        ('ANIME', "Animation", "", 2),
    ]
    mode: bpy.props.EnumProperty(items=items, name="Mode", default='IMAGE')
    thread: bpy.props.IntProperty(name="Threads", default=2, min=1, max=16, soft_min=1, soft_max=16)

    def execute(self, context):
        blend_path = bpy.data.filepath
        if (not blend_path):
            self.report(type={'ERROR'}, message="Save File First")
            return {'CANCELLED'}
        if (self.mode == 'IMAGE'):
            subprocess.Popen([sys.argv[0], '-b', blend_path, '-f', str(context.scene.fram