0

I have a checkbox in a panel. I have assigned a toggle hotkey to it. But when i press the hotkey then the checkbox does not change its state until you move with the mouse over the checkbox.

How can i force a redraw at the checkbox when i press the hotkey?

To reproduce, add keymap item with wm.context_toggle and the Context Attribute window_manager.deselect_bool

The script:

import bpy
from bpy.props import BoolProperty

class LayoutDemoPanel(bpy.types.Panel):
    bl_label = "Demo Panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

    def draw(self, context):
        layout = self.layout

        wm = context.window_manager # Our bool is in the windows_manager
        layout.prop(wm, "deselect_bool") # Our checkbox

def register():
    bpy.types.WindowManager.deselect_bool = bpy.props.BoolProperty(
    name="Checkbox", description="A checkbox", default = False)
    bpy.utils.register_module(__name__)

def unregister():
    del bpy.types.WindowManager.deselect_bool # Unregister our flag when unregister.
    bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
    register()
Tiles
  • 2,028
  • 16
  • 27
  • Tagging the area to force a redraw via context.area.tag_redraw() should work. Here is an example: https://gist.github.com/p2or/8a37617c4565e4ff143b736a0e4a1660 – p2or Jul 24 '16 at 14:10
  • Also see my answer to your last question: http://blender.stackexchange.com/a/58534/3710 – p2or Jul 24 '16 at 15:20
  • Thank you very much for this example. I have to study this. When i install it as an addon then it works. But when i run it as a script then the panel doesn't show. But at least i have a working example now :) – Tiles Jul 24 '16 at 16:11
  • You are welcome! Can't confirm - running this from the text editor also works here without errors in Blender 2.77a on Linux. You can try to remove the bl_info first, but let me know if there is an error... In order to dive in, you can read: http://blender.stackexchange.com/questions/57306/how-to-create-a-custom-ui/57332#57332 (I hope that's helpful at least). – p2or Jul 24 '16 at 16:39
  • To make the checkbox update with pressing the hotkey is a follow up problem of the thread you mention here. I thought it is better to make a separate thread for the separated problem. But we could also delete this one since the follower is solved in the original thread. – Tiles Jul 26 '16 at 07:12
  • Correct, it's required to update the panel anyway (in order to make it work). Let me know what else do you expect or whether there is any real reason to leave this open, then I'll retract my close vote. – p2or Jul 26 '16 at 07:29
  • I have marked it as a duplicate now. Just close it. Thanks :) – Tiles Jul 26 '16 at 07:32

0 Answers0