5
$\begingroup$

When opening Edit > Preferences > Themes > Text Editor and hovering over Line Numbers color picker, Python Tooltip shows:

ThemeTextEditor.line_numbers

enter image description here

How can I read the value? Python reports:

AttributeError: type object 'ThemeTextEditor' has no attribute 'line_numbers'

Some more info. I am trying to create an addon that can change the Text Editor highlight settings, and then save them. I can save them, but, I can't get the theme colors into my function.

def execute( self, context ):
    bpy.ops.wm.save_userpref()
    return {'FINISHED'} #from an operator function

def CreateColorPicker( name, size, prop ) -> FloatVectorProperty:
    return FloatVectorProperty( 
        name = name,
        subtype = "COLOR",
        size = size, #RGB = 3, RGBA = 4
        min = 0.0,
        max = 1.0,
        #default = [1.0, 1.0, 1.0]
        default = prop
    )

Scene.LineNumbersColor = CreateColorPicker( "Line Numbers", RGB, theme.text_editor.line_numbers )

And yes Mr McKenzie your code does work.

$\endgroup$
0

1 Answer 1

4
$\begingroup$

ThemeTextEditor is a class and only serves as a blueprint from which you can instantiate objects. You cannot access this attribute on that class directly unless it is static. See python classes for more information. You are looking for the instance of type ThemeTextEditor which you can access with the following script:

import bpy

theme = bpy.context.preferences.themes.items()[0][1]
line_numbers_color = theme.text_editor.line_numbers

print(line_numbers_color)

Here's an example how you can modify the color:

line_numbers_color.s = 0.8
line_numbers_color.v = 0.8
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .