Exemple #1
0
    def __init__(self, config=Configuration(), *args, **kwargs):
        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config

        # Text box to write the motors
        self.text = widgets.Textarea(
            value='',
            placeholder='Example: IOC:m1 IOC:m3 LNLS:TEST:motor_g3',
            description='',
            disabled=False)

        # class Button values for MotorsMonitor
        self.description = 'Start Motor Monitoring'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Boxes
        self.motors_values = {}

        # Motors
        self.motors_list = []

        # Set callback function for click event
        self.monitoring_status = False
        self.on_click(self._monitor_button)

        # Main widget
        self.main_box = widgets.VBox([self, self.text])
        self.output = widgets.Output()
Exemple #2
0
 def __init__(self, motor, config=Configuration(), *args, **kwargs):
     widgets.Button.__init__(self, *args, **kwargs)
     
     # Config
     self.config = config
     
     # Motor associated to the button
     self.motor = motor
     if type(motor) != py4syn.epics.MotorClass.Motor:
         logprint("Passed to class MotorSetValueButton constructor a argument with wrong type. Expected py4syn.epics.MotorClass.Motor, received " + str(type(motor)), config=self.config)
         
         raise("Passed to class MotorSetValueButton constructor a argument with wrong type. Expected py4syn.epics.MotorClass.Motor, received " + str(type(motor)))
     
     # Bounded float text associated to the button
     self.bounded_float = widgets.BoundedFloatText(
                             value=motor.getRealPosition(),
                             min=motor.getLowLimitValue(),
                             max=motor.getHighLimitValue(),
                             step=0.01,
                             description=motor.motorDesc,
                             disabled=False
                           )
     
     # class Button values for MotorSetValueButton
     self.description = 'Set Target VAL'
     self.disabled = False
     self.button_style = 'success'
     self.tooltip = 'Click me'
     self.icon = ''    
     
     # Set callback function for click event
     self.on_click(self._motor_set_val_button)
     
     # Widgets Boxes
     self.output = widgets.Output()
Exemple #3
0
def configurate_motor(motor_pv_name='', motor_name='', config=Configuration()):
    motor = None
    
    try:
        motor = Motor(motor_pv_name, motor_name)
        logprint("Motor: \'" + motor_pv_name + "\' succesfully created as \'" + motor_name + "\'", config=config)
    except Exception as e:
        logprint("Error trying to create Motor: \'" + motor_pv_name + "\' as \'" + motor_name + "\'", "[ERROR]", config=config)
        logprint(str(e), "[ERROR]", config=config)
        
    return motor
Exemple #4
0
    def __init__(self, config=Configuration(), *args, **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        config : :py:class:`Configuration <jupy4syn.Configuration.Configuration>`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        --------
        >>> config = Configuration()
        >>> config.display()
        >>> monitor = PVMonitor(config)
        >>> monitor.display()
        """
        
        widgets.Button.__init__(self, *args, **kwargs)
        
        # Config
        self.config = config
        
        # Text box to write the PV's
        self.text = widgets.Textarea(
            value='',
            placeholder='Example: IOC:m1.DMOV IOC:m3.RBV LNLS:ANEL:corrente.VAL',
            description='',
            disabled=False
        )
        
        # class Button values for PVMonitor
        self.description='Start PV Monitoring'
        self.disabled=False
        self.button_style='success'
        self.tooltip='Click me'
        self.icon=''
        self.layout = widgets.Layout(width='300px')
        
        # PVs
        self.pv_list = []
        self.pv_values = {}
        
        # Set callback function for click event
        self.monitoring_status = False
        self.on_click(self._monitor_button)
        
        # Main widget
        self.main_box = widgets.VBox([self.text, self])
        self.output = widgets.Output()
Exemple #5
0
    def __init__(self,
                 motor="<motor>",
                 config=Configuration(),
                 *args,
                 **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        config: `jupy4syn.Configuration`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        ----------
        >>> config = Configuration()
            config.display()
        >>> move = moveButton(config)
            move.display()
        """

        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config

        # class Button values for MonitorScanSave
        self.description = 'Execute move'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Bounded float text associated to the button
        self.bounded_text = widgets.Text(value=motor + " <value>",
                                         description="arguments",
                                         disabled=False)

        # Logging
        self.output = widgets.Output()

        # Set callback function for click event
        self.on_click(self._start_button)

        # Widgets displays
        self.start_button = widgets.VBox([self])
Exemple #6
0
    def __init__(self, config=Configuration(), *args, **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        command: `string`
            Command that will be executed at the button click
        config: `jupy4syn.Configuration`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        ----------
        >>> config = Configuration()
            config.display()
        >>> command = CommandButton(config)
            command.display()
        """
        
        # Config
        self.config = config

        # Dictionaries
        self.commands_dict = {
            "": userCommand(),
            "ct": ctCommand(),
            "wa": waCommand(),
            "wm": wmCommand(),
            "move": moveCommand(),
            "scaler": scalerCommand(config),
            "scan_gui": scanCommand(config),
            "energy_scan_gui": energyscanCommand(config),
            "vortex": vortexCommand(config),
            "pymca": pymcaCommand(config),
            "put": putCommand(config),
            "get": getCommand(config),
            "slits": slitsCommand(config),
            "motors": motorsCommand(config),
            "xpra_scaler": xpra_scalerCommand(config),
            "xpra_scan_gui": xpra_scanCommand(config),
            "xpra_energy_scan_gui": xpra_energyscanCommand(config),
            "xpra_vortex": xpra_vortexCommand(config),
            "xpra_slits": xpra_slitsCommand(config),
            "xpra_pymca": xpra_pymcaCommand(config),
            "xpra_motors": xpra_motorsCommand(config)
        }
Exemple #7
0
    def __init__(self, config=Configuration(), *args, **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        config: `jupy4syn.Configuration`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        ----------
        >>> config = Configuration()
        >>> config.display()
        >>> scaler = ScalerButton(config)
        >>> scaler.display()
        """

        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config

        # class Button values for MonitorScanSave
        self.description = 'Start Scaler GUI'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Macro textbox
        self.macro = widgets.Text(value='',
                                  placeholder="Type the macro",
                                  description="",
                                  disabled=False,
                                  layout=widgets.Layout(width="300px"))

        # Logging
        self.output = widgets.Output()

        # Set callback function for click event
        self.on_click(self._start_button)

        # Widgets displays
        self.start_button = widgets.VBox([self])
Exemple #8
0
    def __init__(self,
                 m1="",
                 m2="",
                 m3="",
                 m4="",
                 m5="",
                 user_flag=False,
                 config=Configuration(),
                 *args,
                 **kwargs):
        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config
        self.yml_config = scan_utils.Configuration()

        # Motors
        self.m1 = self.get_pv_by_name(m1)
        self.m2 = self.get_pv_by_name(m2)
        self.m3 = self.get_pv_by_name(m3)
        self.m4 = self.get_pv_by_name(m4)
        self.m5 = self.get_pv_by_name(m5)

        self.motors = [self.m1, self.m2, self.m3, self.m4, self.m5]
        self.motors = [motor for motor in self.motors if motor != ""]

        # Flags
        self.user_flag = "--user" if user_flag is True else ""

        # class Button values for MonitorScanSave
        self.description = 'Open Motors Interface'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Set callback function for click event
        self.on_click(self._click_button)

        # Logging
        self.output = widgets.Output()

        # Widgets display box
        self.display_box = widgets.VBox([self, self.output])
Exemple #9
0
def logprint(string, mode="[INFO]", config=Configuration()):
    # Log information has a time stamp using GMT-0 time to avoid local computer time problems
    ts = time.gmtime()
    
    # Logs will be stored in a .log directory that will be created if it doesn't exist
    year_month_day = time.strftime("%Y-%m-%d", ts)
    file_name = Path('.logs/' + year_month_day + '-log.txt')

    if not file_name.parent.is_dir():
        file_name.parent.mkdir()
    
    time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", ts)
    
    # Write log in the file
    with open(str(file_name), "a") as f:
        f.write(time_stamp + ' | ' + mode + ' ' + string + '\n')
    
    # Write log in stdout
    if config.config['log_cell'].value:
        print(time_stamp + ' | ' + mode + ' ' + string)
Exemple #10
0
    def __init__(self, config=Configuration(), show_header=False):
        """
        **Constructor**

        Parameters
        ----------
        command : :obj:`string`
            Command that will be executed at the button click
        config : :py:class:`Configuration <jupy4syn.Configuration.Configuration>`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        ----------
        >>> config = Configuration()
            config.display()
        >>> command = CommandButton(config)
            command.display()
        """

        # Config
        self.config = config

        # Dictionaries
        self.commands_dict = {
            "": UserCommand(config),
            "ct": CtCommand(),
            "wa": WaCommand(),
            "wm": WmCommand(),
            "move": MoveCommand(),
            "scaler": ScalerCommand(config),
            "scan_gui": ScanGuiCommand(config),
            "energy_scan_gui": EnergyScanGuiCommand(config),
            "vortex": VortexCommand(config),
            "pymca": PymcaCommand(config),
            "put": PutCommand(config),
            "get": GetCommand(config),
            "slits": SlitsCommand(config),
            "motors": MotorsCommand(config)
        }
Exemple #11
0
    def __init__(self, config=Configuration(), *args, **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        config: `jupy4syn.Configuration`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        ----------
        >>> config = Configuration()
            config.display()
        >>> wa = waButton(config)
            wa.display()
        """

        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config

        # class Button values for MonitorScanSave
        self.description = 'Execute wa'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Logging
        self.output = widgets.Output()

        # Set callback function for click event
        self.on_click(self._start_button)

        # Widgets displays
        self.start_button = widgets.VBox([self])
Exemple #12
0
    def __init__(self, config=Configuration(), *args, **kwargs):
        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config

        # Text box to write the motors
        self.text = widgets.Textarea(
            value='',
            placeholder='Example: IOC:m1 IOC:m3 LNLS:TEST:motor_g3',
            description='',
            disabled=False)

        # class Button values for StartMotorsButton
        self.description = 'Start Motor Initializaton'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Boxes
        self.motors_value_buttons = []

        # Motors
        self.motors_list = []

        # Set callback function for click event
        self.on_click(self._start_button)

        # Widgets displays
        self.start_button = widgets.VBox([self.text, self])
        self.target_value_buttons = widgets.VBox(
            [widgets.Label("No motors initilized to be showed.")])

        # Logging
        self.output = widgets.Output()
Exemple #13
0
    def __init__(self,
                 left,
                 right,
                 top,
                 bottom,
                 config=Configuration(),
                 *args,
                 **kwargs):
        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config
        self.yml_config = scan_utils.Configuration()

        # Motors
        self.left = self.get_pv_by_name(left)
        self.right = self.get_pv_by_name(right)
        self.top = self.get_pv_by_name(top)
        self.bottom = self.get_pv_by_name(bottom)

        # class Button values for MonitorScanSave
        self.description = 'Open Slits Interface'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Set callback function for click event
        self.on_click(self._click_button)

        # Logging
        self.output = widgets.Output()

        # Widgets display box
        self.display_box = widgets.VBox([self, self.output])
Exemple #14
0
    def __init__(self, interface, config=Configuration(), *args, **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        config: `jupy4syn.Configuration`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        ----------
        >>> config = Configuration()
        >>> config.display()
        >>> scaler = interfaceButton(config)
        >>> scaler.display()
        """

        widgets.Button.__init__(self, *args, **kwargs)
        
        # Config
        self.config = config

        # Interfaces
        self.interface = interface

        self.interfaces_list = ["pydm", "scaler", "vortex", "scan_gui", "energy_scan_gui", "pymca"]
        if interface not in self.interfaces_list:
            raise TypeError("Interface '" + interface + "' is not a valid option. Interfaces available are: " +
                            str(self.interfaces_list))
        
        if interface is "energy_scan_gui":
            macro_value = "energy"
        else:
            macro_value = ""

        
        
        # class Button values for MonitorScanSave
        self.description = 'Start ' + interface
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Macro textbox
        self.macro = widgets.Text(
            value=macro_value,
            placeholder="Type the macro",
            description="",
            disabled=False,
            layout=widgets.Layout(width="300px")
        )
               
        # Logging
        self.output = widgets.Output()
        
        # Set callback function for click event
        self.on_click(self._start_button)
        
        # Widgets displays
        self.start_button = widgets.VBox([self])
Exemple #15
0
    def __init__(self, config=Configuration(), *args, **kwargs):
        widgets.Button.__init__(self, *args, **kwargs)
        
        # Config
        self.config = config
        
        # Text box to write the motors to move
        self.text_motors = widgets.Textarea(
            value='',
            placeholder='Motors names from config.yml\nExample: solm3 gap2',
            description='',
            disabled=False
        )
        
        # Text box to write the configuration file
        self.text_config = widgets.Textarea(
            value='',
            placeholder='Name of the yml configuration file\nExample: default\n(PS: write "default" to load config.default.yml file)',
            description='',
            disabled=False
        )
        
        # Text box for start
        self.text_start = widgets.Text(
            value='',
            placeholder='Example for 2 motors: [1, 3], [7, 8]',
            description='',
            disabled=False
        )
        
        # Text box for end
        self.text_end = widgets.Text(
            value='',
            placeholder='Example for 2 motors: [2, 4], [8, 8.5]',
            description='',
            disabled=False
        )
        
        # Text box for step or points
        self.text_step_points = widgets.Text(
            value='',
            placeholder='Example for 2 motors: [1, 1], [0.5, 0.25]',
            description='',
            disabled=False
        )
        
        # Text box for time
        self.text_time = widgets.Text(
            value='',
            placeholder='Example for 2 motors: [1], [0.4]',
            description='',
            disabled=False
        )
        
        # Text box for output
        self.text_output = widgets.Text(
            value='',
            placeholder='Output file name, if left empty, file name will be the default name, "test"',
            description='',
            disabled=False
        )
        
        # Text box for optimum
        self.text_optimum = widgets.Text(
            value='',
            placeholder="Move motor to the optimal point according to \
                         this counter after scan. Leave empty for no move.",
            description='',
            disabled=True
        )
        
        # Optimum checkbox
        self.checkbox_optimum = widgets.Checkbox(
            value=False,
            description="",
            disabled=False,
            style={'description_width': 'initial'},
            layout = widgets.Layout(width='36px')
        )     

        self.checkbox_optimum.observe(self.change_checkbox_optimum, names=['value'])
        
        # class Button values for ScanButton
        self.description='Start Scan'
        self.disabled=False
        self.button_style='success'
        self.tooltip='Click me'
        self.icon=''
        self.layout = widgets.Layout(width='300px')
        
        # Boxes
        self.pv_values = {}
        
        # PVs
        self.motor_list = []
        
        # Set callback function for click event
        self.on_scan = False
        self.scan_ended = False
        self.config_loaded = False
        self.on_click(self._scan_button)
        
        # Main widget
        self.main_box = widgets.VBox([widgets.HBox([widgets.Label("Motors names", layout=widgets.Layout(width='150px')), self.text_motors]),
                                      widgets.HBox([widgets.Label("Configuration file name", layout=widgets.Layout(width='150px')), self.text_config]),
                                      widgets.HBox([widgets.Label("Start points", layout=widgets.Layout(width='150px')), self.text_start]),
                                      widgets.HBox([widgets.Label("End points", layout=widgets.Layout(width='150px')), self.text_end]),
                                      widgets.HBox([widgets.Label("Step or Points", layout=widgets.Layout(width='150px')), self.text_step_points]), 
                                      widgets.HBox([widgets.Label("Time", layout=widgets.Layout(width='150px')), self.text_time]),
                                      widgets.HBox([self.checkbox_optimum,
                                                    widgets.Label("Go to optimum of: ", layout=widgets.Layout(width='110px')),
                                                    self.text_optimum]),
                                      widgets.HBox([widgets.Label("Output file name", layout=widgets.Layout(width='150px')), self.text_output]),
                                      self])
        self.output = widgets.Output()
Exemple #16
0
 def __init__(self, config=Configuration()):
     self.config = config
Exemple #17
0
    def __init__(self,
                 command,
                 default_args="",
                 config=Configuration(),
                 *args,
                 **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        command: `string`
            Command that will be executed at the button click
        config: `jupy4syn.Configuration`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()

        Examples
        ----------
        >>> config = Configuration()
            config.display()
        >>> command = CommandButton(config)
            command.display()
        """

        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config

        # Command Dictionary
        self.command = command
        self.command_dict = commandDict(config=self.config)

        self.parsed_args = self.command_dict.textbox_args(
            command, default_args)
        self.show_text_box = self.command_dict.show_text_box(
            command, default_args)

        # class Button values for MonitorScanSave
        self.description = 'Execute Command ' + '"' + self.command + '"'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''
        self.layout = widgets.Layout(width='300px')

        # Arguments textbox
        self.arguments = widgets.Text(value=str(self.parsed_args),
                                      placeholder="Type the arguments",
                                      description="",
                                      disabled=False,
                                      layout=widgets.Layout(width="300px"))

        # Logging
        self.output = widgets.Output()

        # Set callback function for click event
        self.on_click(self._start_button)

        # Widgets displays
        self.start_button = widgets.VBox([self])
Exemple #18
0
    def __init__(self, name, config=Configuration(), *args, **kwargs):
        """
        **Constructor**

        Parameters
        ----------
        name : :obj:`str`
            Name of the PV (e.g. "IOC:m1") to be set a value, or name of the mnemonic defined in 
            config.yml (e.g. "solm1") to be set a value
        config : :py:class:`Configuration <jupy4syn.Configuration.Configuration>`, optional
            Configuration object that contains Jupyter Notebook runtime information, by default Configuration()
        
        Examples
        --------
        >>> config = Configuration()
        >>> config.display()
        >>> pv_setter = PVSetter(config)
        >>> pv_setter.display()
        """
        widgets.Button.__init__(self, *args, **kwargs)

        # Config
        self.config = config

        # PV associated to the button
        self.pv = PV(name)

        # Check if name is a PV, if not search it in config.yml motors
        if not self.pv.wait_for_connection():
            if name in config.yml_motors:
                try:
                    self.pv = PV(config.yml_motors[name]['pv'])
                except KeyError:
                    raise ValueError('Motor %s doesn\'t have pv field' % name)
            elif name in config.yml_counters:
                try:
                    self.pv = PV(config.yml_counters[name]['pv'])
                except KeyError:
                    raise ValueError('Counter %s doesn\'t have pv field' %
                                     name)
            else:
                raise ValueError(
                    "Invalid name. Name provided is neither a conencted PV neither a config.yml mnemonic"
                )

            # Check if PV is finally connected
            if not self.pv.wait_for_connection():
                raise Exception("Valid name, but PV connection not possible")

        self.pv_desc = caget(self.pv.pvname + ".DESC")
        self.pv_name = self.pv.pvname

        # If PV is an enum, when its value is get, we get it with "as_string" set to True, so we get
        # the enum string value, not the enum int value
        self.pv_is_enum = True if self.pv.type == "enum" or self.pv.type == "time_enum" else False

        # Bounded float text associated to the button
        self.bounded_text = widgets.Text(value=str(
            self.pv.get(as_string=self.pv_is_enum)),
                                         disabled=False)
        self.label = widgets.Label(self.pv_desc + ": ")

        # class Button values for PVSetter
        self.description = 'Set value'
        self.disabled = False
        self.button_style = 'success'
        self.tooltip = 'Click me'
        self.icon = ''

        # Set callback function for click event
        self.on_click(self._button_click)

        # Widgets Boxes
        self.output = widgets.Output()