0
$\begingroup$

Is there an option for controlling the 3D-view background gradient (and perhaps the grid for some situations) when switching between ortho and perspective?

Specifically, when I switch to top or side orthographic view the grid takes on a color opposite the gradient and it's slightly irritating... I would turn the gradient off but I like my theme the way it is.

$\endgroup$
1
$\begingroup$

Modal Timer Handler,

Run script, adds a button to info header. Uses no gradient in ortho mode and gradient in perspective view for all 3d views on screen when ON. Add a comment if you want changes re side view etc, or setting a default, prob gradient on when OFF.

enter image description here

wm.event_timer_add(2.0, context.window) makes it tick over every 2 seconds. Change for faster / slower updates.

import bpy
from bpy.props import BoolProperty

class ModalTimerOperator(bpy.types.Operator):
    """Operator which runs its self from a timer"""
    bl_idname = "wm.modal_timer_operator"
    bl_label = "Modal Timer Operator"

    _timer = None

    def modal(self, context, event):
        screen = context.screen
        theme = context.user_preferences.themes[0]

        if not screen.toggle_grad:
            self.cancel(context)
            return {'CANCELLED'}

        if event.type == 'TIMER':
            views = [(a, s) for a in screen.areas 
               if a.type.startswith("VI")
               for s in a.spaces
               if s.type.startswith("VI")]

            for a, s in views:
                theme.view_3d.space.gradients.show_grad = s.region_3d.is_perspective

        return {'PASS_THROUGH'}

    def execute(self, context):
        wm = context.window_manager
        self._timer = wm.event_timer_add(2.0, context.window)
        wm.modal_handler_add(self)
        return {'RUNNING_MODAL'}

    def cancel(self, context):
        wm = context.window_manager
        wm.event_timer_remove(self._timer)

def register():
    bpy.utils.register_class(ModalTimerOperator)

def unregister():
    bpy.utils.unregister_class(ModalTimerOperator)

if __name__ == "__main__":
    register()

def theme_gradient_toggle(screen, context):
    if screen.toggle_grad:
        bpy.ops.wm.modal_timer_operator('INVOKE_DEFAULT')

bpy.types.Screen.toggle_grad = BoolProperty("Auto Gradient", update=theme_gradient_toggle)    
# draw a button in the info header
def draw_button(self, context):
    screen = context.screen
    text = "ON" if screen.toggle_grad else "OFF"
    self.layout.prop(context.screen, "toggle_grad", toggle=True, text=text, icon='RADIOBUT_%s' % text)

bpy.types.INFO_HT_header.prepend(draw_button)
#bpy.types.INFO_HT_header.remove(draw_button)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.