Python bpy.app() Examples

The following are 30 code examples of bpy.app(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bpy , or try the search function .
Example #1
Source File: addon_updater_ops.py    From blender-addon-updater with GNU General Public License v3.0 6 votes vote down vote up
def updater_run_success_popup_handler(scene):
	global ran_update_sucess_popup
	ran_update_sucess_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		if "scene_update_post" in dir(bpy.app.handlers):
			bpy.app.handlers.scene_update_post.remove(
					updater_run_success_popup_handler)
		else:
			bpy.app.handlers.depsgraph_update_post.remove(
					updater_run_success_popup_handler)
	except:
		pass

	atr = addon_updater_updated_successful.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #2
Source File: addon_updater_ops.py    From Sorcar with GNU General Public License v3.0 6 votes vote down vote up
def background_update_callback(update_ready):
	"""Passed into the updater, background thread updater"""
	global ran_autocheck_install_popup

	# in case of error importing updater
	if updater.invalidupdater == True:
		return
	if updater.showpopups == False:
		return
	if update_ready != True:
		return
	if updater_run_install_popup_handler not in \
				bpy.app.handlers.scene_update_post and \
				ran_autocheck_install_popup==False:
		bpy.app.handlers.scene_update_post.append(
				updater_run_install_popup_handler)
		ran_autocheck_install_popup = True 
Example #3
Source File: addon_updater_ops.py    From kaleidoscope with GNU General Public License v3.0 6 votes vote down vote up
def updater_run_success_popup_handler(scene):
	global ran_update_sucess_popup
	ran_update_sucess_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		bpy.app.handlers.scene_update_post.remove(
				updater_run_success_popup_handler)
	except:
		pass

	atr = addon_updater_updated_successful.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #4
Source File: addon_updater_ops.py    From Sorcar with GNU General Public License v3.0 6 votes vote down vote up
def updater_run_success_popup_handler(scene):
	global ran_update_sucess_popup
	ran_update_sucess_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		bpy.app.handlers.scene_update_post.remove(
				updater_run_success_popup_handler)
	except:
		pass

	atr = addon_updater_updated_successful.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #5
Source File: addon_updater_ops.py    From kaleidoscope with GNU General Public License v3.0 6 votes vote down vote up
def background_update_callback(update_ready):
	"""Passed into the updater, background thread updater"""
	global ran_autocheck_install_popup

	# in case of error importing updater
	if updater.invalidupdater == True:
		return
	if updater.showpopups == False:
		return
	if update_ready != True:
		return
	if updater_run_install_popup_handler not in \
				bpy.app.handlers.scene_update_post and \
				ran_autocheck_install_popup==False:
		bpy.app.handlers.scene_update_post.append(
				updater_run_install_popup_handler)
		ran_autocheck_install_popup = True 
Example #6
Source File: addon_updater_ops.py    From object_alignment with GNU General Public License v3.0 6 votes vote down vote up
def background_update_callback(update_ready):
	"""Passed into the updater, background thread updater"""
	global ran_autocheck_install_popup

	# in case of error importing updater
	if updater.invalidupdater == True:
		return
	if updater.showpopups == False:
		return
	if update_ready != True:
		return
	if updater_run_install_popup_handler not in \
				bpy.app.handlers.scene_update_post and \
				ran_autocheck_install_popup==False:
		bpy.app.handlers.scene_update_post.append(
				updater_run_install_popup_handler)
		ran_autocheck_install_popup = True 
Example #7
Source File: addon_updater_ops.py    From object_alignment with GNU General Public License v3.0 6 votes vote down vote up
def updater_run_success_popup_handler(scene):
	global ran_update_sucess_popup
	ran_update_sucess_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		bpy.app.handlers.scene_update_post.remove(
				updater_run_success_popup_handler)
	except:
		pass

	atr = addon_updater_updated_successful.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #8
Source File: __init__.py    From blender-plugin with Apache License 2.0 5 votes vote down vote up
def draw(self, context):
        skfb = get_sketchfab_props()

        if not skfb.is_plugin_enabled:
            self.layout.operator('wm.skfb_enable', text='Activate add-on', icon="LINKED").enable = True
        else:
            # LOGIN
            skfb_login = get_sketchfab_login_props()
            layout = self.layout.box().column(align=True)
            layout.enabled = get_plugin_enabled()
            if skfb_login.skfb_api.is_user_logged():
                login_row = layout.row()
                login_row.label(text='Logged in as {}'.format(skfb_login.skfb_api.get_user_info()))
                login_row.operator('wm.sketchfab_login', text='Logout', icon='DISCLOSURE_TRI_RIGHT').authenticate = False
                if skfb_login.status:
                    layout.prop(skfb_login, 'status', icon=skfb_login.status_type)
            else:
                layout.label(text="Login to your Sketchfab account", icon='INFO')
                layout.prop(skfb_login, "email")
                layout.prop(skfb_login, "password")
                ops_row = layout.row()
                ops_row.operator('wm.sketchfab_signup', text='Create an account', icon='PLUS')
                login_icon = "LINKED" if bpy.app.version < (2,80,0) else "USER"
                ops_row.operator('wm.sketchfab_login', text='Log in', icon=login_icon).authenticate = True
                if skfb_login.status:
                    layout.prop(skfb_login, 'status', icon=skfb_login.status_type) 
Example #9
Source File: addon_updater_ops.py    From blender-addon-updater with GNU General Public License v3.0 5 votes vote down vote up
def updater_run_install_popup_handler(scene):
	global ran_autocheck_install_popup
	ran_autocheck_install_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		if "scene_update_post" in dir(bpy.app.handlers):
			bpy.app.handlers.scene_update_post.remove(
					updater_run_install_popup_handler)
		else:
			bpy.app.handlers.depsgraph_update_post.remove(
					updater_run_install_popup_handler)
	except:
		pass

	if "ignore" in updater.json and updater.json["ignore"] == True:
		return # don't do popup if ignore pressed
	# elif type(updater.update_version) != type((0,0,0)):
	# 	# likely was from master or another branch, shouldn't trigger popup
	# 	updater.json_reset_restore()
	# 	return
	elif "version_text" in updater.json and "version" in updater.json["version_text"]:
		version = updater.json["version_text"]["version"]
		ver_tuple = updater.version_tuple_from_text(version)

		if ver_tuple < updater.current_version:
			# user probably manually installed to get the up to date addon
			# in here. Clear out the update flag using this function
			if updater.verbose:
				print("{} updater: appears user updated, clearing flag".format(\
						updater.addon))
			updater.json_reset_restore()
			return
	atr = addon_updater_install_popup.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #10
Source File: addon_updater_ops.py    From blender-addon-updater with GNU General Public License v3.0 5 votes vote down vote up
def background_update_callback(update_ready):
	"""Passed into the updater, background thread updater"""
	global ran_autocheck_install_popup

	# in case of error importing updater
	if updater.invalidupdater == True:
		return
	if updater.showpopups == False:
		return
	if update_ready != True:
		return

	# see if we need add to the update handler to trigger the popup
	handlers = []
	if "scene_update_post" in dir(bpy.app.handlers): # 2.7x
		handlers = bpy.app.handlers.scene_update_post
	else: # 2.8x
		handlers = bpy.app.handlers.depsgraph_update_post
	in_handles = updater_run_install_popup_handler in handlers

	if in_handles or ran_autocheck_install_popup:
		return

	if "scene_update_post" in dir(bpy.app.handlers): # 2.7x
		bpy.app.handlers.scene_update_post.append(
				updater_run_install_popup_handler)
	else: # 2.8x
		bpy.app.handlers.depsgraph_update_post.append(
				updater_run_install_popup_handler)
	ran_autocheck_install_popup = True 
Example #11
Source File: addon_updater_ops.py    From material-combiner-addon with MIT License 5 votes vote down vote up
def make_annotations(cls):
    if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
        return cls
    bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
    if bl_props:
        if '__annotations__' not in cls.__dict__:
            setattr(cls, '__annotations__', {})
        annotations = cls.__dict__['__annotations__']
        for k, v in bl_props.items():
            annotations[k] = v
            delattr(cls, k)
    return cls 
Example #12
Source File: addon_updater_ops.py    From material-combiner-addon with MIT License 5 votes vote down vote up
def layout_split(layout, factor=0.0, align=False):
    if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
        return layout.split(percentage=factor, align=align)
    return layout.split(factor=factor, align=align) 
Example #13
Source File: addon_updater_ops.py    From material-combiner-addon with MIT License 5 votes vote down vote up
def get_update_post():
    if hasattr(bpy.app.handlers, 'scene_update_post'):
        return bpy.app.handlers.scene_update_post
    else:
        return bpy.app.handlers.depsgraph_update_post 
Example #14
Source File: addon_updater_ops.py    From material-combiner-addon with MIT License 5 votes vote down vote up
def execute(self, context):
        if Updater.invalidupdater is True:
            return {'CANCELLED'}

        if Updater.async_checking is True and Updater.error is None:
            return {'CANCELLED'}

        settings = get_user_preferences(context)
        if not settings:
            if Updater.verbose:
                print("Could not get {} preferences, update check skipped".format(__package__))
            return {'CANCELLED'}
        Updater.set_check_interval(enable=settings.auto_check_update,
                                   months=settings.updater_intrval_months,
                                   days=settings.updater_intrval_days,
                                   hours=settings.updater_intrval_hours,
                                   minutes=settings.updater_intrval_minutes)
        Updater.check_for_update_now(ui_refresh)
        try:
            import pip
            call([bpy.app.binary_path_python, '-m', 'pip', 'install', 'pip', '--user', '--upgrade'], shell=True)
            call([bpy.app.binary_path_python, '-m', 'pip', 'install', 'Pillow', '--user', '--upgrade'], shell=True)
        except ImportError:
            call([bpy.app.binary_path_python, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'operators',
                                                           'get-pip.py'), '--user'], shell=True)
            call([bpy.app.binary_path_python, '-m', 'pip', 'install', 'Pillow', '--user', '--upgrade'], shell=True)
        return {'FINISHED'} 
Example #15
Source File: addon_updater_ops.py    From blender-addon-updater with GNU General Public License v3.0 5 votes vote down vote up
def make_annotations(cls):
	"""Add annotation attribute to class fields to avoid Blender 2.8 warnings"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return cls
	bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
	if bl_props:
		if '__annotations__' not in cls.__dict__:
			setattr(cls, '__annotations__', {})
		annotations = cls.__dict__['__annotations__']
		for k, v in bl_props.items():
			annotations[k] = v
			delattr(cls, k)
	return cls 
Example #16
Source File: addon_updater_ops.py    From Sorcar with GNU General Public License v3.0 5 votes vote down vote up
def make_annotations(cls):
	"""Add annotation attribute to class fields to avoid Blender 2.8 warnings"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return cls
	bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
	if bl_props:
		if '__annotations__' not in cls.__dict__:
			setattr(cls, '__annotations__', {})
		annotations = cls.__dict__['__annotations__']
		for k, v in bl_props.items():
			annotations[k] = v
			delattr(cls, k)
	return cls 
Example #17
Source File: addon_updater_ops.py    From Sorcar with GNU General Public License v3.0 5 votes vote down vote up
def layout_split(layout, factor=0.0, align=False):
	"""Intermediate method for pre and post blender 2.8 split UI function"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return layout.split(percentage=factor, align=align)
	return layout.split(factor=factor, align=align) 
Example #18
Source File: addon_updater_ops.py    From Sorcar with GNU General Public License v3.0 5 votes vote down vote up
def updater_run_install_popup_handler(scene):
	global ran_autocheck_install_popup
	ran_autocheck_install_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		bpy.app.handlers.scene_update_post.remove(
				updater_run_install_popup_handler)
	except:
		pass

	if "ignore" in updater.json and updater.json["ignore"] == True:
		return # don't do popup if ignore pressed
	# elif type(updater.update_version) != type((0,0,0)):
	# 	# likely was from master or another branch, shouldn't trigger popup
	# 	updater.json_reset_restore()
	# 	return
	elif "version_text" in updater.json and "version" in updater.json["version_text"]:
		version = updater.json["version_text"]["version"]
		ver_tuple = updater.version_tuple_from_text(version)

		if ver_tuple < updater.current_version:
			# user probably manually installed to get the up to date addon
			# in here. Clear out the update flag using this function
			if updater.verbose:
				print("{} updater: appears user updated, clearing flag".format(\
						updater.addon))
			updater.json_reset_restore()
			return
	atr = addon_updater_install_popup.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #19
Source File: addon_updater_ops.py    From Sorcar with GNU General Public License v3.0 5 votes vote down vote up
def showReloadPopup():
	"""For use in register only, to show popup after re-enabling the addon

	Must be enabled by developer
	"""
	if updater.invalidupdater == True:
		return
	saved_state = updater.json
	global ran_update_sucess_popup

	a = saved_state != None
	b = "just_updated" in saved_state
	c = saved_state["just_updated"]

	if a and b and c:
		updater.json_reset_postupdate() # so this only runs once

		# no handlers in this case
		if updater.auto_reload_post_update == False: return

		if updater_run_success_popup_handler not in \
					bpy.app.handlers.scene_update_post \
					and ran_update_sucess_popup==False:
			bpy.app.handlers.scene_update_post.append(
					updater_run_success_popup_handler)
			ran_update_sucess_popup = True


# -----------------------------------------------------------------------------
# Example UI integrations
# ----------------------------------------------------------------------------- 
Example #20
Source File: addon_updater_ops.py    From blender-addon-updater with GNU General Public License v3.0 5 votes vote down vote up
def layout_split(layout, factor=0.0, align=False):
	"""Intermediate method for pre and post blender 2.8 split UI function"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return layout.split(percentage=factor, align=align)
	return layout.split(factor=factor, align=align) 
Example #21
Source File: effector.py    From Blender_Effectors with GNU General Public License v3.0 5 votes vote down vote up
def bv28():
	"""Check if blender 2.8, for layouts, UI, and properties. """
	global BV_IS_28
	if not BV_IS_28:
		BV_IS_28 = hasattr(bpy.app, "version") and bpy.app.version >= (2, 80)
	return BV_IS_28 
Example #22
Source File: addon_updater_ops.py    From object_alignment with GNU General Public License v3.0 5 votes vote down vote up
def showReloadPopup():
	"""For use in register only, to show popup after re-enabling the addon

	Must be enabled by developer
	"""
	if updater.invalidupdater == True:
		return
	saved_state = updater.json
	global ran_update_sucess_popup

	a = saved_state != None
	b = "just_updated" in saved_state
	c = saved_state["just_updated"]

	if a and b and c:
		updater.json_reset_postupdate() # so this only runs once

		# no handlers in this case
		if updater.auto_reload_post_update == False: return

		if updater_run_success_popup_handler not in \
					bpy.app.handlers.scene_update_post \
					and ran_update_sucess_popup==False:
			bpy.app.handlers.scene_update_post.append(
					updater_run_success_popup_handler)
			ran_update_sucess_popup = True


# -----------------------------------------------------------------------------
# Example UI integrations
# ----------------------------------------------------------------------------- 
Example #23
Source File: addon_updater_ops.py    From object_alignment with GNU General Public License v3.0 5 votes vote down vote up
def updater_run_install_popup_handler(scene):
	global ran_autocheck_install_popup
	ran_autocheck_install_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		bpy.app.handlers.scene_update_post.remove(
				updater_run_install_popup_handler)
	except:
		pass

	if "ignore" in updater.json and updater.json["ignore"] == True:
		return # don't do popup if ignore pressed
	# elif type(updater.update_version) != type((0,0,0)):
	# 	# likely was from master or another branch, shouldn't trigger popup
	# 	updater.json_reset_restore()
	# 	return
	elif "version_text" in updater.json and "version" in updater.json["version_text"]:
		version = updater.json["version_text"]["version"]
		ver_tuple = updater.version_tuple_from_text(version)

		if ver_tuple < updater.current_version:
			# user probably manually installed to get the up to date addon
			# in here. Clear out the update flag using this function
			if updater.verbose:
				print("{} updater: appears user updated, clearing flag".format(\
						updater.addon))
			updater.json_reset_restore()
			return
	atr = addon_updater_install_popup.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #24
Source File: addon_updater_ops.py    From object_alignment with GNU General Public License v3.0 5 votes vote down vote up
def layout_split(layout, factor=0.0, align=False):
	"""Intermediate method for pre and post blender 2.8 split UI function"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return layout.split(percentage=factor, align=align)
	return layout.split(factor=factor, align=align) 
Example #25
Source File: addon_updater_ops.py    From object_alignment with GNU General Public License v3.0 5 votes vote down vote up
def make_annotations(cls):
	"""Add annotation attribute to class fields to avoid Blender 2.8 warnings"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return cls
	bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
	if bl_props:
		if '__annotations__' not in cls.__dict__:
			setattr(cls, '__annotations__', {})
		annotations = cls.__dict__['__annotations__']
		for k, v in bl_props.items():
			annotations[k] = v
			delattr(cls, k)
	return cls 
Example #26
Source File: pose-tools.py    From pose-tools with MIT License 5 votes vote down vote up
def bv28():
    """Check if blender 2.8, for layouts, UI, and properties. """
    global BV_IS_28
    if not BV_IS_28:
        BV_IS_28 = hasattr(bpy.app, "version") and bpy.app.version >= (2, 80)
    return BV_IS_28 
Example #27
Source File: addon_updater_ops.py    From kaleidoscope with GNU General Public License v3.0 5 votes vote down vote up
def showReloadPopup():
	"""For use in register only, to show popup after re-enabling the addon

	Must be enabled by developer
	"""
	if updater.invalidupdater == True:
		return
	saved_state = updater.json
	global ran_update_sucess_popup

	a = saved_state != None
	b = "just_updated" in saved_state
	c = saved_state["just_updated"]

	if a and b and c:
		updater.json_reset_postupdate() # so this only runs once

		# no handlers in this case
		if updater.auto_reload_post_update == False: return

		if updater_run_success_popup_handler not in \
					bpy.app.handlers.scene_update_post \
					and ran_update_sucess_popup==False:
			bpy.app.handlers.scene_update_post.append(
					updater_run_success_popup_handler)
			ran_update_sucess_popup = True


# -----------------------------------------------------------------------------
# Example UI integrations
# ----------------------------------------------------------------------------- 
Example #28
Source File: addon_updater_ops.py    From kaleidoscope with GNU General Public License v3.0 5 votes vote down vote up
def updater_run_install_popup_handler(scene):
	global ran_autocheck_install_popup
	ran_autocheck_install_popup = True

	# in case of error importing updater
	if updater.invalidupdater == True:
		return

	try:
		bpy.app.handlers.scene_update_post.remove(
				updater_run_install_popup_handler)
	except:
		pass

	if "ignore" in updater.json and updater.json["ignore"] == True:
		return # don't do popup if ignore pressed
	# elif type(updater.update_version) != type((0,0,0)):
	# 	# likely was from master or another branch, shouldn't trigger popup
	# 	updater.json_reset_restore()
	# 	return
	elif "version_text" in updater.json and "version" in updater.json["version_text"]:
		version = updater.json["version_text"]["version"]
		ver_tuple = updater.version_tuple_from_text(version)

		if ver_tuple < updater.current_version:
			# user probably manually installed to get the up to date addon
			# in here. Clear out the update flag using this function
			if updater.verbose:
				print("{} updater: appears user updated, clearing flag".format(\
						updater.addon))
			updater.json_reset_restore()
			return
	atr = addon_updater_install_popup.bl_idname.split(".")
	getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') 
Example #29
Source File: addon_updater_ops.py    From kaleidoscope with GNU General Public License v3.0 5 votes vote down vote up
def layout_split(layout, factor=0.0, align=False):
	"""Intermediate method for pre and post blender 2.8 split UI function"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return layout.split(percentage=factor, align=align)
	return layout.split(factor=factor, align=align) 
Example #30
Source File: addon_updater_ops.py    From kaleidoscope with GNU General Public License v3.0 5 votes vote down vote up
def make_annotations(cls):
	"""Add annotation attribute to class fields to avoid Blender 2.8 warnings"""
	if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
		return cls
	bl_props = {k: v for k, v in cls.__dict__.items() if isinstance(v, tuple)}
	if bl_props:
		if '__annotations__' not in cls.__dict__:
			setattr(cls, '__annotations__', {})
		annotations = cls.__dict__['__annotations__']
		for k, v in bl_props.items():
			annotations[k] = v
			delattr(cls, k)
	return cls