Skip to content

Instantly share code, notes, and snippets.

@sambler
Created January 4, 2016 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sambler/690403179d7efa8529bb to your computer and use it in GitHub Desktop.
Save sambler/690403179d7efa8529bb to your computer and use it in GitHub Desktop.
blender addon to add some macbook specific options
# from
# http://blender.stackexchange.com/q/44014/935
bl_info = {
"version": (1, 0),
"blender": (2, 75, 0),
"name": "Macbook Options",
"description": """Some user settings to assist macbook users.""" ,
"category": "UI",
}
import bpy
screen_options = [ ('0','None',''),
('1','Brightness',''),
('2','Backlit Keys',''),
('3','Volume','')]
class IgnitProperties(bpy.types.PropertyGroup):
title = bpy.props.StringProperty(default='MacBook')
collapse = bpy.props.BoolProperty(default=False)
isight_camera_indicator = bpy.props.BoolProperty(default=True)
menubar_and_dock = bpy.props.BoolProperty(default=True)
backlit_keys = bpy.props.BoolProperty(default=True)
screen_brightness = bpy.props.BoolProperty(default=True)
dirt_and_dust_factor = bpy.props.BoolProperty(default=True)
screen_icons = bpy.props.EnumProperty(items=screen_options,
default=screen_options[1][0])
icons = bpy.props.StringProperty(default='Default icons')
icon_factor = bpy.props.IntProperty(default=1)
screen_rotation = bpy.props.FloatProperty(default=0.0)
screen_path = bpy.props.StringProperty(default='Enter path')
colors = bpy.props.FloatVectorProperty(name='', subtype='COLOR',
size=3, default=(0.2,0.5,0.8))
class AddMacBook(bpy.types.Operator):
bl_label = "Add MacBook"
bl_idname = "macbook_controller.add_macbook"
def execute(self, context):
item = context.scene.ignit_panel.add()
def unique_name(names):
# from wm.py
prop = "MacBook"
prop_new = prop
i = 1
while prop_new in names:
prop_new = prop + str(i)
i += 1
return prop_new
item.title = unique_name([i.title for i in context.scene.ignit_panel])
return{'FINISHED'}
class RemoveMacBook(bpy.types.Operator):
bl_label = "Remove MacBook"
bl_idname = "macbook_controler.remove_macbook"
del_item = bpy.props.IntProperty(name='item index to remove')
def execute(self, context):
context.scene.ignit_panel.remove(self.del_item)
return{'FINISHED'}
class IGLayoutDemoPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "MacBook Controller"
bl_idname = "macbook_controller.macbook_controller"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
split = layout.split()
scene = context.scene
camera = scene.camera.data
obj = context.object
# Add
row = layout.row()
layout.operator("macbook_controller.add_macbook")
for idx,ignit_options in enumerate(scene.ignit_panel):
# Box
box = layout.box()
row = box.row()
# Collapsable Menu
if ignit_options.collapse:
row.prop(ignit_options, "collapse",
icon="RIGHTARROW",
icon_only=True, emboss=False
)
else:
row.prop(ignit_options, "collapse",
icon="DOWNARROW_HLT",
icon_only=True, emboss=False
)
# Title (per object)
row.prop(ignit_options, 'title')
# Remove
row.operator("macbook_controler.remove_macbook", text="",
icon = "X", emboss = False).del_item = idx
# Collapsing everything inside the box
if not ignit_options.collapse:
# Main Features
row = box.row()
row.label(text = "Main Features:")
row = box.row()
row.prop(ignit_options, "isight_camera_indicator")
row = box.row()
row.prop(ignit_options, "menubar_and_dock")
row = box.row()
row.prop(ignit_options, "backlit_keys")
row = box.row()
row.prop(ignit_options, "screen_brightness")
row = box.row()
row.prop(ignit_options, "dirt_and_dust_factor")
# Screen Icons
row = box.row()
row.prop(ignit_options, 'screen_icons', text = "Screen Icons:")
if int(ignit_options.screen_icons) > 0:
icon_box = box.box()
row = icon_box.row()
row.prop(ignit_options, 'icons')
row = icon_box.row()
if ignit_options.screen_icons == screen_options[1][0]:
row.prop(ignit_options, "icon_factor", text = "Brightness Icon")
elif ignit_options.screen_icons == screen_options[2][0]:
row.prop(ignit_options, "icon_factor", text = "Backlit Keys Icon")
elif ignit_options.screen_icons == screen_options[3][0]:
row.prop(ignit_options, "icon_factor", text = "Volume Icon")
# Screen Rotation
row = box.row()
row.label(text = "Screen Rotation:")
row = box.row()
row.prop(ignit_options, "screen_rotation")
# Screen Texture
row = box.row()
row.label(text = "Screen Texture:")
row = box.row()
row.prop(ignit_options, "screen_path")
row.operator("macbook_controller.identifier_file_selector",
text="", icon='FILESEL')
# MacBook Colors
row = box.row()
row.label(text = "MacBook Color:")
row.prop(ignit_options, "colors")
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.ignit_panel = bpy.props.CollectionProperty(type=IgnitProperties)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.ignit_panel
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment