i started modifying this code snippet for error message
but still errors
can someone help debug this
and work in either 2.8 / 2.9 latest version
"""
error message
code snippet
https://web.archive.org/web/20120824033549/http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Interface#A_popup_dialog
"""
import bpy
from bpy.props import *
#
# The error message operator. When invoked, pops up a dialog
# window with the given message.
#
class MessageOperator(bpy.types.Operator):
bl_idname = "error.message"
bl_label = "Message"
type = StringProperty()
message = StringProperty()
def execute(self, context):
self.report({'INFO'}, self.message)
print(self.message)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_popup(self, width=400, height=200)
def draw(self, context):
self.layout.label("A message has arrived")
row = self.layout.split(0.25)
row.prop(self, "type")
row.prop(self, "message")
row = self.layout.split(0.80)
row.label("")
row.operator("error.ok")
#
# The OK button in the error dialog
#
class OkOperator(bpy.types.Operator):
bl_idname = "error.ok"
bl_label = "OK"
def execute(self, context):
return {'FINISHED'}
#
# Opens a file select dialog and starts scanning the selected file.
#
class ScanFileOperator(bpy.types.Operator):
bl_idname = "error.scan_file"
bl_label = "Scan file for return"
filepath = bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
scanFile(self.filepath)
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
#
# Scan the file. If a line contains the word "return", invoke error
# dialog and quit. If reached end of file, display another message.
#
def scanFile(filepath):
fp = open(filepath, "rU")
n = 1
for line in fp:
words = line.split()
if "return" in words:
bpy.ops.error.message('INVOKE_DEFAULT',
type = "Error",
message = 'Found "return" on line %d' % n)
return
n += 1
fp.close()
bpy.ops.error.message('INVOKE_DEFAULT',
type = "Message",
message = "No errors found in %d lines" % n)
return
#
# Registration
classes = (
MessageOperator ,
OkOperator ,
ScanFileOperator
)
###
def register():
# bpy.utils.register_class(HelloWorldPanel)
from bpy.utils import register_class
for cls in classes:
register_class(cls)
###
def unregister():
# bpy.utils.unregister_class(HelloWorldPanel)
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
###
if __name__ == "__main__":
register()
thanks
happy bl