How to update a variable in a dialog?



  • On 11/02/2017 at 13:53, xxxxxxxx wrote:

    Hello there,

    How to update a variable in a dialog "CreateLayout(self)".
    in the script below I want to passing the value from the path field or the self.DIRECTORY to the variable "dirs".

    import c4d, re, os  
    from c4d import gui  
      
    class Dialog(c4d.gui.GeDialog) :  
      SELECT_DIR = 40  
                    
      def CreateLayout(self) :          
          self.GroupBegin(0,c4d.BFH_SCALEFIT,3,0,"");  
          self.AddStaticText(0, c4d.BFH_RIGHT, 0, 0, "Path :", c4d.BORDER_NONE)  
          **self.AddEditText(1, c4d.BFH_SCALEFIT, 250, 15)** **#Path to pass**  
          self.AddButton(self.SELECT_DIR, flags=c4d.BFH_RIGHT,inith=15, name="...")         
          self.GroupEnd()  
            
          self.AddComboBox(1000, c4d.BFH_SCALEFIT, 0, 15)           
          self.AddChild(1000,0,"Folders :&i" + str(c4d.RESOURCEIMAGE_OPENED) + "&" )  
          self.AddChild(1000,0,"")  
       
          **dirs = os.listdir(os.path.join( self.GetString(1))) # Passing the path value or the self.DIRECTORY here**  
     **         # or** **:  
          # dirs = os.listdir(os.path.join(** ** ** ** **self.DIRECTORY****** )) **       
          id = 2000  
          for plugin_name in dirs:          
              self.AddChild(1000,id,plugin_name)  
              id += 1  
          return True   
      
      def UpdateDlg(self, id) :  
          self.SetString(1,self.DIRECTORY)          
          return True  
        
      def Command(self, id, msg) :  
          if id == self.SELECT_DIR:  
              **self.DIRECTORY** = c4d.storage.LoadDialog(flags=c4d.FILESELECT_DIRECTORY)  
          self.UpdateDlg(self.GetLong(1000))  
      
          return True  
        
      def CoreMessage(self, id, msg) :  
          if id==c4d.EVMSG_CHANGE:  
              self.UpdateDlg(self.GetBool(self.DIRECTORY))  
          return True  
        
    def main() :  
      global Dialog  
      Dialog = Dialog()  
      Dialog.Open(c4d.DLG_TYPE_MODAL, xpos=700, ypos= 200, defaultw=516, defaulth=10)      
      return True  
    if __name__=='__main__':  
      main()
    

    I want to obtain this result:

    Thanks



  • On 13/02/2017 at 01:49, xxxxxxxx wrote:

    Hi,

    To dynamically update the ComboBox children list, just call self.AddChild() in Command() with the sub-directories returned by os.listdir().
    The ComboBox is updated automatically because this doesn't change the layout of the dialog.



  • On 13/02/2017 at 04:51, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Hi,
    To dynamically update the ComboBox children list, just call self.AddChild() in Command() with the sub-directories returned by os.listdir().
    The ComboBox is updated automatically because this doesn't change the layout of the dialog.

    Hi,

    Sorry, I wasn't clear on your response, please can you give me a small example?

    Thanks.



  • On 13/02/2017 at 04:57, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Originally posted by xxxxxxxx

    Hi,
    To dynamically update the ComboBox children list, just call self.AddChild() in Command() with the sub-directories returned by os.listdir().
    The ComboBox is updated automatically because this doesn't change the layout of the dialog.

    Hi,

    Sorry, I wasn't clear on your response, please can you give me a small example?

    Thanks.

    Simply move your loop with self.AddChild() from CreateLayout() to Command() and the if for the directory selection. CreateLayout() doesn't get called every time a command or an interaction in the dialog happens.



  • On 13/02/2017 at 05:33, xxxxxxxx wrote:

    def Command(self, id, msg) :  
      dirs = os.listdir(os.path.join(self.GetString(1)))          
      id = 2000  
      for plugin_name in dirs:          
          self.AddChild(1000,id,plugin_name)  
          id += 1
    

    I tried this but nothing happen.


Log in to reply