1
$\begingroup$

anyone knows how to disable Edit Source function? I am developing my project using the blender, I would like to disable Edit Source option whenever user Right Click on the UI, there is an option the user can choose to see the source code. I would like to disable it, how can I do it. I want to prevent the user from Right click and choose to go to the edit source.

Thanks

$\endgroup$
3
  • $\begingroup$ Don't addons become open source when you share them, anyway? Since they're not separate enough from Blender. $\endgroup$ Feb 22 '18 at 11:01
  • $\begingroup$ That's what i am thinking too, if it is open source I couldn't do it or not, i am not so sure too. $\endgroup$
    – Republic
    Feb 22 '18 at 11:09
  • 3
    $\begingroup$ It's just that people who want to find the source will find it, the ones who don't care won't care. And legally you actually have to provide the source code. If you want to sell the addon, focus on your customers and their needs instead. At least that's what I would do. $\endgroup$ Feb 22 '18 at 11:38
2
$\begingroup$

Can override any operator in blender

Unless you are prepared to edit the source code of blender and build without edit souce operator, and remove from ui menu, you can override the operator. Simply a matter of registering another operator with the same bl_idname.

import bpy

def main(context):
    print("foo")

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "ui.editsource"
    bl_label = "No Edit Source"

    @classmethod
    def poll(cls, context):
        return False

    def execute(self, context):
        main(context)
        return {'FINISHED'}

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

def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    
if __name__ == "__main__":
    register()

Now we have an item in the right click menu "No Edit Source", that does nothing because it will never poll.

![enter image description here

The next choice is where and when to run, and register this operator. As long as it is run after the original operator was registered, it will override the behaviour.

Should you wish to take this further can use python type(...) to override operators en mass. Sample scripts take out any bpy.ops.ui operators.

Edit: Updated for 2.8 (Operator.get_rna -> Operator.get_rna_type)

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "ui.editsource"
    bl_label = "No Edit Source"

    @classmethod
    def poll(cls, context):
        return False

classes = []
def register():
    for op in dir(bpy.ops.ui):
        rna = getattr(bpy.ops.ui, op).get_rna_type()
        name = rna.bl_rna.name
        props = {"bl_idname": "ui.%s" % op,
                 "bl_label": name,
                 "bl_description": "Disabled"} #rna.bl_rna.description
        DisOpClass = type(name, (SimpleOperator,), props)
        classes.append(DisOpClass)
        bpy.utils.register_class(DisOpClass)

def unregister():
    for c in classes:
        bpy.utils.unregister_class(c)

if __name__ == "__main__":
    register()
$\endgroup$
2
  • $\begingroup$ thanks batFINGER .. it work, wowww...... What about if I want to disable Right Click on every button I created. How can I disable it ? $\endgroup$
    – Republic
    Feb 23 '18 at 4:25
  • $\begingroup$ I have created Button UI and whenever user right click on the button UI, there is a small window like Change Shortcut, Remove Shortcut, Online Manual, Edit Source, edit Translation. I would like to disable the Right Click, whenever user Right Click, nothing happen. How can I do it ? Thanks $\endgroup$
    – Republic
    Feb 27 '18 at 3:54

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.