2010/7/8 Michael Foord <[email protected]>

>  On 08/07/2010 22:34, Alex wrote:
>
> Hello
> In my WPF application, I want to have an "expert mode" that lets the
> end-user write inline python code targetting one specific control (a
> sheetmusic). I embed IronPython and when the user code throws an exception I
> catch it and display it but there are a few foolproof problems:
>
>  1) If the user write some bad code in a function and binds it to one of
> the control event, it will crash the whole app. Of course I can recommand my
> users to always wrap event handlers into a try catch block (or ask to use a
> decorator that do it) but it's not really foolproof. I want to make it
> impossible to crash the whole app with user code. Perhaps native events
> mecanism is a bit too low-level to be foolproof?
>
>
> Catch and report exceptions.
>
>
>
hi Mickael

if the user write this code :

#script

def foo():
print 2/0

button.Click = foo

###

the script will execute with no exception, only when the button is clicked,
an exception is raised, how should I handle it ?



>  2) If the user code makes  an infinite loop it will hang the whole app. I
> want to have a "panic button" to stop the script (and even restart the
> python engine if necessary). I suppose I have to run user code in a worker
> thread but then the user have to use Invoke mecanisms each time he touchs an
> UI object? Is there an elegant pattern that deals with this concerns?
>
>
> Execute the user code on a background thread. Provide a means for actions
> to be invoked on the gui thread (wrapped in exception handling) if
> necessary. Provide a button to abort the thread if it goes on too long.
>
>

My only concern is that the users shouldn't have to think about it. Maybe I
should only let them access UI elements through non-UI proxy objects, but
it's a great limitation.

Alex
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to