Yet another approach for async dialogs.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/06/2011 at 09:42, xxxxxxxx wrote:

And this one is a good one. 😉
I hate restarting cinema 4d because i want to test my async dialog but i can only open it in a command data >.>

from    c4d.gui         import GeDialog  
from    threading       import Thread  
  
class DialogThread(Thread) :  
  """  
  A class to enable opening ASync Dialogs in the Skript Manager.  
  Initialise with a GeDialog subclass instance.  
  """  
  
  class ArgumentError(Exception) :  
      """ Raised when a bad argument is given. """  
  
  def __init__(self, dlg) :  
      # initialise with a GeDialog subclass instance  
      if not issubclass(dlg.__class__, GeDialog) :  
          raise self.ArgumentError, "Overloaded argument 'dlg' is not an instance of GeDialog or an instance of a subclass of GeDialog.\n" \  
                             \+ "It is an instance of:     %s" % dlg.__class__.__name__  
  
      Thread.__init__(self)  
      self.dlg        = dlg  
  
  def run(self) :  
      # wait until the dialog is closed  
      while self.dlg.IsOpen() :  
          pass  
  
  def start(self, opentype = c4d.DLG_TYPE_ASYNC) :  
      # open the dialog and start Superclass' start().  
      self.dlg.Open(opentype)  
      Thread.start(self)  
  
def OpenAsyncDialog(dlg) :  
  dlg_thread = DialogThread(dlg)  
  dlg_thread.start()  
  return dlg_thread

Maybe at least this can be added to the Py4D Standart Library ? Would be pretty useful for skripts, hehe.

Cheers,

//edit:
Hm, again some issues. 😂
is there any way to keep the globals within a Thread ? >.>