Created
March 10, 2023 11:06
-
-
Save williamchange/791aeb267e8b3ddb3943e3f06acd234f to your computer and use it in GitHub Desktop.
Simple Theme Generator (Add-on)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ##### BEGIN GPL LICENSE BLOCK ##### | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it 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 ##### | |
from bpy.props import BoolProperty, IntProperty, FloatProperty, FloatVectorProperty | |
from bpy.types import ( | |
AddonPreferences, | |
ThemeWidgetColors | |
) | |
import colorsys | |
import os | |
import bpy | |
bl_info = { | |
"name": "Theme Generator", | |
"author": "none", | |
"version": (0, 0, 1), | |
"blender": (3, 0, 0), | |
"description": "Simple theme generator from a single color", | |
"category": "Interface", | |
} | |
def c(color, value, alpha=None): | |
hsv = colorsys.rgb_to_hsv(*color) | |
hsv = (hsv[0], hsv[1], hsv[2] * value) | |
rgb = colorsys.hsv_to_rgb(*hsv) | |
if alpha != None: | |
rgb = (*rgb, alpha) | |
return rgb | |
class theme_generatorPreferences(AddonPreferences): | |
bl_idname = __name__ | |
darkest: FloatProperty( | |
name="Darkest", | |
default=0.11, | |
min=0.0, | |
max=1.0, | |
precision=3, | |
description="Darkest", | |
) | |
darker: FloatProperty( | |
name="Darker", | |
default=0.2, | |
min=0.0, | |
max=1.0, | |
precision=3, | |
description="Darker", | |
) | |
dark: FloatProperty( | |
name="Dark", | |
default=0.25, | |
min=0.0, | |
max=1.0, | |
precision=3, | |
description="Dark", | |
) | |
base: FloatProperty( | |
name="Base", | |
default=0.3, | |
min=0.0, | |
max=1.0, | |
precision=3, | |
description="Base", | |
) | |
bright: FloatProperty( | |
name="Bright", | |
default=0.45, | |
min=0.0, | |
max=1.0, | |
precision=3, | |
description="Bright", | |
) | |
brighter: FloatProperty( | |
name="Brighter", | |
default=0.585, | |
min=0.0, | |
max=1.0, | |
precision=3, | |
description="Brighter", | |
) | |
base_color: FloatVectorProperty( | |
name="Base Color", | |
subtype="COLOR", | |
size=3, | |
default=(1.0, 1.0, 1.0), | |
min=0.0, | |
max=1.0, | |
description="Tint", | |
) | |
def draw(self, context): | |
layout = self.layout | |
box = layout.box() | |
row1 = box.row() | |
row1.prop(self, "base_color") | |
row1.operator("thmgen.apply_theme", text="Apply Theme") | |
row2 = box.row() | |
row2.prop(self, "brighter") | |
row3 = box.row() | |
row3.prop(self, "bright") | |
row4 = box.row() | |
row4.prop(self, "base") | |
row5 = box.row() | |
row5.prop(self, "dark") | |
row6 = box.row() | |
row6.prop(self, "darker") | |
row7 = box.row() | |
row7.prop(self, "darkest") | |
class theme_generator_OT_ApplyThemeOperator(bpy.types.Operator): | |
bl_idname = "thmgen.apply_theme" | |
bl_label = "Apply Theme" | |
def execute(self, context): | |
prefs = bpy.context.preferences | |
theme = prefs.themes[0] | |
props = prefs.addons[__name__].preferences | |
COL = props.base_color | |
DARKEST = props.darkest | |
DARKER = props.darker | |
DARK = props.dark | |
BASE = props.base | |
BRIGHT = props.bright | |
BRIGHTER = props.brighter | |
tui = theme.user_interface | |
# SpaceListGeneric | |
for t in [theme.clip_editor, theme.dopesheet_editor, theme.graph_editor, | |
theme.nla_editor, theme.node_editor, theme.spreadsheet]: | |
t.space_list.list = c(COL, DARK) | |
# Outliner | |
theme.outliner.active = c(COL, DARKER) | |
theme.outliner.selected_object = c(COL, BRIGHT) | |
theme.outliner.active_object = c(COL, BRIGHTER) | |
theme.outliner.selected_highlight = c(COL, DARK) | |
# Graph/Sequence/DopeSheet Editor | |
for t in [theme.graph_editor, theme.sequence_editor, theme.dopesheet_editor]: | |
t.grid = c(COL, DARKEST) | |
t.time_scrub_background = c(COL, DARK, alpha=1.0) | |
t.frame_current = c(COL, DARKER) | |
# Node Editor | |
theme.node_editor.node_backdrop = c(COL, DARKER, alpha=0.4) | |
# User Interface | |
tui.editor_outline = c(COL, DARKEST) | |
tui.wcol_numslider.item = c(COL, DARK, alpha=0.1) | |
tui.wcol_pie_menu.item = c(COL, DARK, alpha=0.8) | |
tui.wcol_tab.text = c(COL, BRIGHTER) | |
tui.wcol_progress.item = c(COL, DARKER, alpha=0.2) | |
# 3D View | |
theme.view_3d.space.gradients.high_gradient = c(COL, DARKEST) | |
theme.view_3d.space.gradients.background_type = "SINGLE_COLOR" | |
theme.view_3d.grid = c(COL, BASE, alpha=0.1) | |
theme.view_3d.space.header = c(COL, DARK, alpha=0.1) | |
theme.view_3d.space.button = c(COL, DARK, alpha=0.1) | |
theme.view_3d.space.tab_active = c(COL, DARK) | |
theme.view_3d.space.tab_inactive = c(COL, DARK) | |
theme.view_3d.space.tab_back = c(COL, DARKER, alpha=0.1) | |
theme.view_3d.space.tab_outline = c(COL, DARK) | |
theme.view_3d.space.navigation_bar = c(COL, DARKER, alpha=0.1) | |
theme.view_3d.space.execution_buts = c(COL, DARKER, alpha=0.1) | |
# ThemeWidgetColors | |
for i in dir(tui): | |
if isinstance(getattr(tui, i), ThemeWidgetColors): | |
getattr(tui, i).outline = c(COL, DARK) | |
getattr(tui, i).inner = c(COL, BASE, alpha=1.0) | |
getattr(tui, i).inner_sel = c(COL, BRIGHTER, alpha=1.0) | |
# ThemeSpace | |
for t in [theme.clip_editor, theme.console, theme.dopesheet_editor, | |
theme.file_browser, theme.graph_editor, theme.image_editor, | |
theme.info, theme.nla_editor, theme.node_editor, | |
theme.outliner, theme.preferences, theme.properties, | |
theme.sequence_editor, theme.spreadsheet, theme.statusbar, | |
theme.text_editor, theme.topbar]: | |
t = t.space | |
t.button = c(COL, DARK, alpha=0.1) | |
t.header = c(COL, DARK, alpha=0.1) | |
t.back = c(COL, DARK) | |
t.tab_active = c(COL, BRIGHT) | |
t.tab_inactive = c(COL, DARK) | |
t.tab_back = c(COL, DARKER, alpha=0.1) | |
t.tab_outline = c(COL, DARK) | |
t.panelcolors.header = c(COL, BASE, alpha=0.1) | |
t.navigation_bar = c(COL, DARKER, alpha=1.0) | |
t.execution_buts = c(COL, DARKEST, alpha=0.0) | |
t.panelcolors.back = c(COL, DARK, alpha=0.1) | |
return {"FINISHED"} | |
def register(): | |
bpy.utils.register_class(theme_generatorPreferences) | |
bpy.utils.register_class(theme_generator_OT_ApplyThemeOperator) | |
def unregister(): | |
bpy.utils.unregister_class(theme_generatorPreferences) | |
bpy.utils.unregister_class(theme_generator_OT_ApplyThemeOperator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment