2010-02-25 6 views
0

J'utilise IronPython 2.6 et un WebbrowserControl sur un formulaire appelé TridentForm. Ceci est utilisé pour afficher les rapports, etc.IronPython WebbrowserControl - problème de création de formulaire

Le formulaire principal, LaunchForm, a un bouton qui a un gestionnaire d'événement OnClick. Ce gestionnaire d'événements met en place des éléments puis lance un BackgroundWorker. Le travailleur de fond est terminée, et dans ce rappel, il instancie TridentForm, il montre, etc, etc.

maintenant Cela fonctionne bien, voici un code actuel abrégé:

class LaunchForm(Form): 
def __init__(self): 
      #blah blah, InitilizeComponents(), blah 
    self.form_splash = None 
    self.form_report = None 

    self._report_worker = BackgroundWorker() 
    self._report_worker.DoWork += self.runReport 
    self._report_worker.RunWorkerCompleted += self.runReport_finished 

def runReport_handler(self, sender, args): 
    self._report_worker.RunWorkerAsync(job_type) 
    log.debug("renReport_handler called on thread %s"%(Thread.CurrentThread.ManagedThreadId)) 

def runReport(self, sender, args): #run by a backgroundworker 
    #do stuff, doesn't matter 

def runReport_finished(self, sender, args): 
    #error checking, etc 
    log.debug("reunReport_finished called on thread %s"%(Thread.CurrentThread.ManagedThreadId)) 

    if not self.form_report: 
    log.debug("Creating TridentForm") 
      self.form_report = TridentForm() 
    log.debug("Getting TridentForm") 
    vf = self.form_report 

Comme vous pouvez le voir, self.form_report (TridentForm) est réutilisé après sa première création. La raison en est que entre les instructions de journal "Création de TridentForm" et "Getting TridentForm" jusqu'à 7 secondes est passé à faire (apparemment) rien. Le journal ne dit aucun mensonge. Quoi qu'il en soit, je suppose que c'est le temps d'initialisation du composant pour le contrôle ActvieX d'IE.

Évidemment, je ne veux pas attendre 7 secondes à ce sujet.

Donc, j'ai décidé d'essayer de créer le formulaire à la fin de runReport_handler - cela va faire un peu geler l'interface utilisateur, mais le thread d'arrière-plan fonctionne, donc pas de problème. Notez les instructions de journalisation sur les identifiants de threads - j'ai confirmé que runReport_handler et runReport_finished sont tous deux appelés sur le même thread.

Donc, mon problème: Il suffit de déplacer que jusqu'à la création à la fin de runReport_handler me donne plusieurs amusantes exceptions de fil non gérée:

Traceback (most recent call last): 

    File "C:\completely\unrelated\control\subclass\used\on\the\mainform.py", line 33, in OnMouseUp 

TypeError: cannot access protected member OnMouseUp without a python subclass of Control 

Microsoft.Scripting.ArgumentTypeException: cannot access protected member OnMouseUp without a python subclass of Control 

    at IronPython.Runtime.Types.BuiltinFunction.<>c__DisplayClass6.<MakeBuiltinFunctionDelegate>b__0(Object[] callArgs, Boolean& shouldOptimize) 

    at IronPython.Runtime.Types.BuiltinFunction.BuiltinMethodCaller`2.Call1(CallSite site, CodeContext context, TFuncType func, T0 arg0) 

    at Microsoft.Scripting.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) 

    at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame) 

    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) 

    at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2) 

    at IronPython.Compiler.PythonCallTargets.OriginalCallTarget2(PythonFunction function, Object arg0, Object arg1) 

    at IronPython.Runtime.PythonFunction.FunctionCaller`2.Call2(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1) 

    at Microsoft.Scripting.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) 

    at IronPython.Runtime.PythonFunction.FunctionCaller`2.Default1Call2(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1) 

    at CallSite.Target(Closure , CallSite , CodeContext , Object , Object) 

    at Microsoft.Scripting.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) 

    at IronPython.NewTypes.System.Windows.Forms.Control_13$14.OnMouseUp(MouseEventArgs) 

    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 

    at System.Windows.Forms.Control.WndProc(Message& m) 

    at IronPython.NewTypes.System.Windows.Forms.Control_13$14.WndProc(Message&) 

    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 

    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 

    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

et

Traceback (most recent call last): 

    File "C:\TridentForm.py", line 159, in TridentNavigating 

TypeError: cannot access protected member OnMouseUp without a python subclass of Control 

Microsoft.Scripting.ArgumentTypeException: cannot access protected member OnMouseUp without a python subclass of Control 

    at IronPython.Runtime.Types.BuiltinFunction.<>c__DisplayClass6.<MakeBuiltinFunctionDelegate>b__0(Object[] callArgs, Boolean& shouldOptimize) 

    at IronPython.Runtime.Types.BuiltinFunction.BuiltinMethodCaller`2.Call1(CallSite site, CodeContext context, TFuncType func, T0 arg0) 

    at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame) 

    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) 

    at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2) 

    at IronPython.Runtime.PythonFunction.FunctionCaller`2.Call2(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1) 

    at CallSite.Target(Closure , CallSite , CodeContext , Object , Object) 

    at IronPython.NewTypes.System.Windows.Forms.Control_13$14.OnMouseUp(MouseEventArgs) 

    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 

    at System.Windows.Forms.Control.WndProc(Message& m) 

    at IronPython.NewTypes.System.Windows.Forms.Control_13$14.WndProc(Message&) 

    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 

    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 

    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

qui tous deux ne font pas sens. En bonus, maintenant en cliquant sur le formulaire principal produit également ce message.

Le Référé des exceptions:

ligne 33 du contrôle indépendant:

def OnMouseUp (auto, e): self.pressed = False si self.image_down: self.Invalidate() super (SimpleImageButton, auto) .OnMouseUp (e) #dies ici. Oui, ceci est une sous-classe de Control.

et le code TridentForm:

def TridentNavigating (auto, expéditeur, e): si e.Url = self.dest_url et e.Url = PLEASE_WAIT_URL:! #dies ici. self est un formulaire qui, je suppose, est une sous-classe de Control. Mais encore, aucune des choses dans cette ligne ne touche jamais les types clr - self.dest_url est un attribut python

Donc, je suis perdu. Alternativement, si vous pouviez trouver un moyen de "précharger" TridentForm d'une autre manière, ce serait génial. Merci. e.Cancel = true

Répondre

0

Ugh, c'était l'appel super (...) Désolé de perdre du temps tout le monde :)