Create a poll function for the purpose of graying out an operator

I’m working on an addon which has different functionalities for Cycles and Blender Render. Rather than have these options disappear when switching between modes, I’d prefer for them to just get grayed out. I’ve read you can do this by creating a poll function for an operator but I have no idea what the code for that looks like in application. Could anyone create or point me to a small example of this? Thanks.

e.g. check the template Operator Simple:

import bpy


def main(context):
    for ob in context.scene.objects:
        print(ob)


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

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


def register():
    bpy.utils.register_class(SimpleOperator)
    bpy.types.VIEW3D_HT_header.prepend(lambda s, c: s.layout.operator("object.simple_operator"))


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


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.simple_operator()


I added a line of code to add a button of that operator to the 3d view header.

Delete the active object to make context.object equal to None. Poll function will return False and the button is grayed out.

Thankyou! This is excellent.