Multi layout on ControlDesk using Python [solved]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • medlot
    New Member
    • Nov 2006
    • 12

    Multi layout on ControlDesk using Python [solved]

    Hi,

    I m using controDesk Developer V2.7 Unicode under Windows2000 Pack4. I do automotive mesurments with Simulink V6.3 files using a micro-autobox. it works correctly. I want to have a second layout working with the principal one that I can activate and desactivate online with a simple switch (on the principal layout). Is it possible and if yes how this can be done?

    Thnaks.
  • medlot
    New Member
    • Nov 2006
    • 12

    #2
    This is the Python code of the button located in the principal layout:

    # -*- coding: cp1252 -*-


    def On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a():
    """
    Syntax : On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a()

    Purpose : WriteData event handler.

    Parameters : None

    """
    print "On_Instrumenta tion_layout_1_d SPACEPushButton Control_WriteDa ta called"

    and this is the name of the layout I want to activate :
    layout_2.py

    they are located in the same directory

    any questions are welcome
    Thanks

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by medlot
      This is the Python code of the button located in the principal layout:

      # -*- coding: cp1252 -*-


      def On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a():
      """
      Syntax : On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a()

      Purpose : WriteData event handler.

      Parameters : None

      """
      print "On_Instrumenta tion_layout_1_d SPACEPushButton Control_WriteDa ta called"

      and this is the name of the layout I want to activate :
      layout_2.py

      they are located in the same directory

      any questions are welcome
      Thanks
      I like to import at the top of the code to show dependencies:
      Code:
      import layout_2
      Then, in your event handler, it's:
      Code:
      layout_2.SomeFunction()
      If the code has been written "in line" like most scripts, then you need to change it in to a callable like this:
      Code:
      def SomeFunction():
      	# Indent all the code of the script here
       
      if __name__ == "__main__":
      	SomeFuntion()	# Will still run as a script

      Comment

      • medlot
        New Member
        • Nov 2006
        • 12

        #4
        Hi, thanks for the help but unfortunately I didn't succeed to do it. Taking a simple example, I have 2 layouts, layout_1 and layout_2. On the first there is an OnOffButton. In the second one, I ve got a display panel. This is what I wrote in the file _layout_1.py:

        # -*- coding: cp1252 -*-

        def On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a():
        """
        Syntax : On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a()

        Purpose : WriteData event handler.

        Parameters : None

        """
        import layout_2
        print "On_Instrumenta tion_layout_1_d SPACEPushButton Control_WriteDa ta called"

        def On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_Click():
        """
        Syntax : On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_Click()

        Purpose : Click event handler.

        Parameters : None

        """

        print "On_Instrumenta tion_layout_1_d SPACEPushButton Control_Click called"

        def SomeFunction():
        # Indent all the code of the script here
        if __name__ == "__main__":
        SomeFuntion() # Will still run as a script
        """"""""""""""" """"""""""""""" """""

        This is what it is written in the _layout_2.py file:

        def On_Instrumentat ion_layout_2_dS PACEDisplayCont rol_Click():
        """
        Syntax : On_Instrumentat ion_layout_2_dS PACEDisplayCont rol_Click()

        Purpose : Click event handler.

        Parameters : None

        """
        print "On_Instrumenta tion_layout_2_d SPACEDisplayCon trol_Click called"

        def layout_2.SomeFu nction():
        # Indent all the code of the script here

        if __name__ == "__main__":
        SomeFuntion() # Will still run as a script

        '"""""""""""""" """"""""""" ""
        You notice that I added what you have posted in your first message.
        Nothing happens when I click on the button at the animation mode. I access to the Python code through the events window by editing WriteData. What I want to do is to activate and disactivate the layout2 window by clicking on the OnOffButton through the animation mode.

        this is a picture of my interface: http://mederreg.lotfi. free.fr/python/event_python.JP G

        Thanks

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by bartonc
          I like to import at the top of the code to show dependencies:
          Code:
          import layout_2
          Then, in your event handler, it's:
          Code:
          layout_2.SomeFunction()
          If the code has been written "in line" like most scripts, then you need to change it in to a callable like this:
          Code:
          def SomeFunction():
          	# Indent all the code of the script here
           
          if __name__ == "__main__":
          	SomeFuntion()	# Will still run as a script
          Sorry if this wasn't very clear.. The last section describes layout2. layout 1 should look like this:
          Code:
          # -*- coding: cp1252 -*-
          import layout2
          
          def
             On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData():
          	"""
             Syntax : On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData()
          
          	Purpose : WriteData event handler.
          
          	Parameters : None
          
          	"""
          	print "On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData called"
          	layout2.somefunction()

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Please read "posting guidelines or the gray background lettering where you create you post to learn how to use [code] tags. It helps us to help you. Thanks,
            Barton


            Originally posted by medlot
            Hi, thanks for the help but unfortunately I didn't succeed to do it. Taking a simple example, I have 2 layouts, layout_1 and layout_2. On the first there is an OnOffButton. In the second one, I ve got a display panel. This is what I wrote in the file _layout_1.py:

            # -*- coding: cp1252 -*-

            def On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a():
            """
            Syntax : On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_WriteDat a()

            Purpose : WriteData event handler.

            Parameters : None

            """
            import layout_2
            print "On_Instrumenta tion_layout_1_d SPACEPushButton Control_WriteDa ta called"

            def On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_Click():
            """
            Syntax : On_Instrumentat ion_layout_1_dS PACEPushButtonC ontrol_Click()

            Purpose : Click event handler.

            Parameters : None

            """

            print "On_Instrumenta tion_layout_1_d SPACEPushButton Control_Click called"

            def SomeFunction():
            # Indent all the code of the script here
            if __name__ == "__main__":
            SomeFuntion() # Will still run as a script
            """"""""""""""" """"""""""""""" """""

            This is what it is written in the _layout_2.py file:

            def On_Instrumentat ion_layout_2_dS PACEDisplayCont rol_Click():
            """
            Syntax : On_Instrumentat ion_layout_2_dS PACEDisplayCont rol_Click()

            Purpose : Click event handler.

            Parameters : None

            """
            print "On_Instrumenta tion_layout_2_d SPACEDisplayCon trol_Click called"

            def layout_2.SomeFu nction():
            # Indent all the code of the script here

            if __name__ == "__main__":
            SomeFuntion() # Will still run as a script

            '"""""""""""""" """"""""""" ""
            You notice that I added what you have posted in your first message.
            Nothing happens when I click on the button at the animation mode. I access to the Python code through the events window by editing WriteData. What I want to do is to activate and disactivate the layout2 window by clicking on the OnOffButton through the animation mode.

            this is a picture of my interface: http://mederreg.lotfi. free.fr/python/event_python.JP G

            Thanks

            Comment

            • medlot
              New Member
              • Nov 2006
              • 12

              #7
              I did, it will be ok for the next time, any help for my request?

              Comment

              • bartonc
                Recognized Expert Expert
                • Sep 2006
                • 6478

                #8
                Originally posted by medlot
                I did, it will be ok for the next time, any help for my request?
                Yep, Two posts down.

                Comment

                • bartonc
                  Recognized Expert Expert
                  • Sep 2006
                  • 6478

                  #9
                  Originally posted by medlot
                  I did, it will be ok for the next time, any help for my request?
                  Maybe you could post layout_2 also for me to better understand.

                  Comment

                  • medlot
                    New Member
                    • Nov 2006
                    • 12

                    #10
                    I ve posted the python code of layout2 in the previous message but here it is again:

                    Code:
                    #  -*- coding: cp1252 -*-
                    
                    
                    def On_Instrumentation_layout_2_dSPACEDisplayControl_Click():
                        """
                        Syntax      : On_Instrumentation_layout_2_dSPACEDisplayControl_Click()
                    
                        Purpose     : Click event handler.
                    
                        Parameters  : None
                    
                        """
                        print "On_Instrumentation_layout_2_dSPACEDisplayControl_Click called"
                    
                    def layout_2.SomeFunction():
                    	# Indent all the code of the script here
                     
                    if __name__ == "__main__":
                    	SomeFuntion()	# Will still run as a script

                    As you can see, it is just a simple layout with a display control.

                    Comment

                    • medlot
                      New Member
                      • Nov 2006
                      • 12

                      #11
                      The 4 last lines of the layout2 script are the ones you suggested to add.

                      Comment

                      • medlot
                        New Member
                        • Nov 2006
                        • 12

                        #12
                        It seems that there is a problem in the forum, it doesn't mention the posts of the second page.
                        This is the two scripts:

                        layout_1:
                        Code:
                        #  -*- coding: cp1252 -*-
                        
                        
                        
                        import layout_2
                        
                        def
                           On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData():
                        	"""
                           Syntax : On_Instrumentation_layout_1_dSPACEPushButtonContro  l_WriteData()
                        
                        	Purpose : WriteData event handler.
                        
                        	Parameters : None
                        
                        	"""
                        	print "On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData called"
                        	layout2.somefunction()
                        layout_2:

                        Code:
                        #  -*- coding: cp1252 -*-
                        
                        
                        def SomeFunction():
                        	# Indent all the code of the script here
                         
                        if __name__ == "__main__":
                        	SomeFuntion()	# Will still run as a script
                        
                        
                        def On_Instrumentation_layout_2_dSPACEDisplayControl_Click():
                            """
                            Syntax      : On_Instrumentation_layout_2_dSPACEDisplayControl_Click()
                        
                            Purpose     : Click event handler.
                        
                            Parameters  : None
                        
                            """
                            print "On_Instrumentation_layout_2_dSPACEDisplayControl_Click called"
                        When I click on the the button at the animation mode, nothing happens. An error is mentionned in the interpreter:

                        Code:
                        SyntaxError: invalid syntax
                        Traceback (most recent call last):
                          File "<string>", line 1108, in RunScript
                          File "<string>", line 1073, in DoRunScript
                        IndentationError: expected an indented block (_layout_2.py, line 7)
                        line 7 in the script of layout_2 coresponds to:

                        Code:
                        if __name__ == "__main__":
                        any idea ?

                        Comment

                        • bartonc
                          Recognized Expert Expert
                          • Sep 2006
                          • 6478

                          #13
                          Sorry, you interpret me very litterally. I make up names in the absence to actual code.

                          Originally posted by medlot
                          It seems that there is a problem in the forum, it doesn't mention the posts of the second page.
                          This is the two scripts:

                          layout_1:
                          Code:
                          # -*- coding: cp1252 -*-
                           
                           
                           
                          import layout_2
                           
                          def On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData():
                          	"""
                          	Syntax : On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData()
                           
                          	Purpose : WriteData event handler.
                           
                          	Parameters : None
                           
                          	"""
                          	print "On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData called"
                          	layout2.somefunction()
                          layout_2:

                          Code:
                          # -*- coding: cp1252 -*-
                           
                           
                          def SomeFunction():
                          	# Indent all the code of the script here
                           
                          if __name__ == "__main__":
                          	SomeFuntion()	# Will still run as a script
                           
                           
                          def On_Instrumentation_layout_2_dSPACEDisplayControl_Click():
                          """
                          Syntax : On_Instrumentation_layout_2_dSPACEDisplayControl_Click()
                           
                          Purpose : Click event handler.
                           
                          Parameters : None
                           
                          """
                          print "On_Instrumentation_layout_2_dSPACEDisplayControl_Click called"
                          When I click on the the button at the animation mode, nothing happens. An error is mentionned in the interpreter:

                          Code:
                          SyntaxError: invalid syntax
                          Traceback (most recent call last):
                          File "<string>", line 1108, in RunScript
                          File "<string>", line 1073, in DoRunScript
                          IndentationError: expected an indented block (_layout_2.py, line 7)
                          line 7 in the script of layout_2 coresponds to:

                          Code:
                          if __name__ == "__main__":
                          any idea ?
                          More precisely:
                          Code:
                          # -*- coding: cp1252 -*-
                           
                           
                           
                          import layout_2
                           
                          def
                          On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData():
                          	"""
                          	Syntax : On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData()
                           
                          	Purpose : WriteData event handler.
                           
                          	Parameters : None
                           
                          	"""
                          	print "On_Instrumentation_layout_1_dSPACEPushButtonControl_WriteData called"
                          	layout2.On_Instrumentation_layout_2_dSPACEDisplayControl_Click()
                          layout_2:

                          Code:
                          # -*- coding: cp1252 -*-
                           
                          def On_Instrumentation_layout_2_dSPACEDisplayControl_Click():
                          	"""
                          	Syntax : On_Instrumentation_layout_2_dSPACEDisplayControl_Click()
                           
                          	Purpose : Click event handler.
                           
                          	Parameters : None
                           
                          	"""
                          	print "On_Instrumentation_layout_2_dSPACEDisplayControl_Click called"

                          Comment

                          • medlot
                            New Member
                            • Nov 2006
                            • 12

                            #14
                            Thnaks,
                            still not working after using the last code. Here is the error messages:

                            Code:
                            Traceback (most recent call last):
                              File "<string>", line 1108, in RunScript
                              File "<string>", line 1073, in DoRunScript
                              File "c:\user\E287844\multi_layouts\_layout_1.py", line 5, in ?
                                import layout_2
                            ImportError: No module named layout_2
                            Traceback (most recent call last):
                              File "<string>", line 1108, in RunScript
                              File "<string>", line 1073, in DoRunScript
                              File "c:\user\E287844\multi_layouts\_layout_1.py", line 5, in ?
                                import layout_2
                            ImportError: No module named layout_2
                            Traceback (most recent call last):
                              File "<string>", line 1108, in RunScript
                              File "<string>", line 1073, in DoRunScript
                            IndentationError: expected an indented block (_layout_2.py, line 12)
                            I don't understand the first error since the two layouts are in the same directory. This is the contents of the current directory:

                            Code:
                            _layout_1.py
                            _layout_2.py
                            layout_1.lay
                            layout_2.lay
                            The second error seems to be a syntax error but I don't see it.

                            Comment

                            • bartonc
                              Recognized Expert Expert
                              • Sep 2006
                              • 6478

                              #15
                              Originally posted by medlot
                              Thnaks,
                              still not working after using the last code. Here is the error messages:

                              Code:
                              Traceback (most recent call last):
                              File "<string>", line 1108, in RunScript
                              File "<string>", line 1073, in DoRunScript
                              File "c:\user\E287844\multi_layouts\_layout_1.py", line 5, in ?
                              import layout_2
                              ImportError: No module named layout_2
                              Traceback (most recent call last):
                              File "<string>", line 1108, in RunScript
                              File "<string>", line 1073, in DoRunScript
                              File "c:\user\E287844\multi_layouts\_layout_1.py", line 5, in ?
                              import layout_2
                              ImportError: No module named layout_2
                              Traceback (most recent call last):
                              File "<string>", line 1108, in RunScript
                              File "<string>", line 1073, in DoRunScript
                              IndentationError: expected an indented block (_layout_2.py, line 12)
                              I don't understand the first error since the two layouts are in the same directory. This is the contents of the current directory:

                              Code:
                              _layout_1.py
                              _layout_2.py
                              layout_1.lay
                              layout_2.lay
                              The second error seems to be a syntax error but I don't see it.
                              1) You need to import _layout_2 since that is the name of the file.
                              2) Indentation errors come form cut and paste to/from the forum with different brousers. You need to make sure that (figuritively speeking)

                              Code:
                               
                              def somefunction(): # this line starts at the left edge
                              	# everything else is indented 4 spaces (or maybe 1 tab in your case)

                              Comment

                              Working...