@@ -709,7 +709,7 @@ def stretch_to_fit(self, val: bool) -> None:
709709 self ._shared .boolean_property (self .root , 'stretch_image' , val )
710710
711711class _Actions (object ):
712- def _add_action (self , action_type , description , args , macros = None ):
712+ def _add_action (self , action_type , description , args , isScript , macros = None ):
713713 root_action = self .root .find ('actions' )
714714 if root_action is None :
715715 root_action = SubElement (self .root , 'actions' )
@@ -723,9 +723,16 @@ def _add_action(self, action_type, description, args, macros=None):
723723 else :
724724 for key , val in macros .items ():
725725 self ._shared .add_macro (key , val , action )
726- for arg , val in args .items ():
727- sub = SubElement (action , arg )
728- sub .text = str (val )
726+ if isScript :
727+ script_element = SubElement (action , 'script' )
728+ script_element .attrib ['file' ] = args ['file' ]
729+ if args .get ('script' ) is not None :
730+ text_element = SubElement (script_element , 'text' )
731+ text_element .text = args ['script' ]
732+ else :
733+ for arg , val in args .items ():
734+ sub = SubElement (action , arg )
735+ sub .text = str (val )
729736
730737 def action_execute_as_one (self , val : bool ) -> None :
731738 """
@@ -769,7 +776,7 @@ def action_open_display(self, file: str, target: str, description: str = None, m
769776 print ('The macro parameter must be a dictionary with key=MacroName and val=MacroValue' )
770777 return
771778 args = {'file' : file , 'target' : target .lower ()}
772- self ._add_action ('open_display' , description , args , macros )
779+ self ._add_action ('open_display' , description , args , False , macros )
773780
774781 def action_write_pv (self , pv_name : str , value : Union [str , int , float ], description : str = None ) -> None :
775782 """
@@ -782,7 +789,7 @@ def action_write_pv(self, pv_name: str, value: Union[str, int, float], descripti
782789 if description is None :
783790 description = 'Write PV'
784791 args = {'pv_name' : pv_name , 'value' : value }
785- self ._add_action ('write_pv' , description , args )
792+ self ._add_action ('write_pv' , description , args , False )
786793
787794 def action_execute_command (self , command : str , description : str = None ) -> None :
788795 """
@@ -794,7 +801,43 @@ def action_execute_command(self, command: str, description: str = None) -> None:
794801 if description is None :
795802 description = 'Execute Command'
796803 args = {'command' : command }
797- self ._add_action ('command' , description , args )
804+ self ._add_action ('command' , description , args , False )
805+
806+ def action_execute_python_script (self , script : str , description : str = None ) -> None :
807+ """
808+ Add Execute Command action to widget. description is optional
809+
810+ :param script: Python script to execute as action
811+ :param description: Description of action. Default is None
812+ """
813+ if description is None :
814+ description = 'Execute Script'
815+ args = {'file' : 'EmbeddedPy' , 'script' : script }
816+ self ._add_action ('execute' , description , args , True )
817+
818+ def action_execute_javascript_script (self , script : str , description : str = None ) -> None :
819+ """
820+ Add Execute Command action to widget. description is optional
821+
822+ :param script: Javascript code to execute as action
823+ :param description: Description of action. Default is None
824+ """
825+ if description is None :
826+ description = 'Execute Script'
827+ args = {'file' : 'EmbeddedJs' , 'script' : script }
828+ self ._add_action ('execute' , description , args , True )
829+
830+ def action_execute_external_script (self , file_name : str , description : str = None ) -> None :
831+ """
832+ Add Execute Command action to widget. description is optional
833+
834+ :param file_name: External script file name
835+ :param description: Description of action. Default is None
836+ """
837+ if description is None :
838+ description = 'Execute Script'
839+ args = {'file' : file_name }
840+ self ._add_action ('execute' , description , args , True )
798841
799842 def action_open_file (self , file : str , description : str = None ) -> None :
800843 """
@@ -806,7 +849,7 @@ def action_open_file(self, file: str, description: str = None) -> None:
806849 if description is None :
807850 description = 'Open File'
808851 args = {'file' : file }
809- self ._add_action ('open_file' , description , args )
852+ self ._add_action ('open_file' , description , args , False )
810853
811854 def action_open_webpage (self , url : str , description : str = None ) -> None :
812855 """
@@ -818,7 +861,7 @@ def action_open_webpage(self, url: str, description: str = None) -> None:
818861 if description is None :
819862 description = 'Open Webpage'
820863 args = {'url' : url }
821- self ._add_action ('open_webpage' , description , args )
864+ self ._add_action ('open_webpage' , description , args , False )
822865
823866class _Label (object ):
824867 def label (self , val : str ) -> None :
0 commit comments