def collect_failed(self, message):
     # this is to work around the remote access problem
     dispatcher.send("collect_finished")
     self.get_view().setText(1, "Failed")
     self.status = QUEUE_ENTRY_STATUS.FAILED
     logging.getLogger("queue_exec").error(message.replace("\n", " "))
     raise QueueExecutionException(message.replace("\n", " "), self)
 def get_grid(self):
     """
     Returns the current grid object.
     """
     grid_dict = dict()
     dispatcher.send("grid", self, grid_dict)
     return grid_dict
 def set_state(self, value):
     if value in self.valid_states:
         self._state = value
         dispatcher.send("stateChanged", self, self._state)
     else:
         raise RuntimeError(
             "GphlWorkflowConnection set to invalid state: %s" % value)
 def get_grid(self):
     """
     Returns the current grid object.
     """
     grid_dict = dict()
     dispatcher.send("grid", self, grid_dict)
     return grid_dict
Beispiel #5
0
    def __ledit_update_value(self, field_name, widget, new_value, type_fn, validator):
        if not self.bindings[field_name][3]:
            origin_value = new_value
            if type_fn == float and validator:
                pattern = "%." + str(validator.decimals()) + "f"
                new_value = pattern % float(new_value)

            # fix validation if PyQt4 and sipapi 1 is used
            if isinstance(new_value, str):
                if "QString" in globals():
                    new_value = QtImport.QString(new_value)

            self.__validated(
                field_name, validator, self.bindings[field_name][0], new_value
            )
            if isinstance(widget, QtImport.QLineEdit):
                if type_fn is float and validator:
                    widget.setText(
                        "{:g}".format(
                            round(float(origin_value), validator.decimals())
                        )
                    )
            try:
                setattr(self.__model, field_name, type_fn(origin_value))
            except ValueError:
                if origin_value != "":
                    raise
            else:
                dispatcher.send("model_update", self.__model, field_name, self)
Beispiel #6
0
    def __ledit_update_value(self, field_name, widget, new_value, type_fn,
                             validator):
        if not self.bindings[field_name][3]:
            origin_value = new_value
            if type_fn == float and validator:
                pattern = "%." + str(validator.decimals()) + 'f'
                new_value = pattern % float(new_value)

            # fix validation if PyQt4 and sipapi 1 is used
            if type(new_value) is str:
                if "QString" in globals():
                    new_value = QString(new_value)

            self.__validated(field_name, validator,
                             self.bindings[field_name][0], new_value)
            if True:
                if isinstance(widget, QLineEdit):
                    if type_fn is float and validator:
                        widget.setText('{:g}'.format(round(float(origin_value), \
                                       validator.decimals())))
                try:
                    setattr(self.__model, field_name, type_fn(origin_value))
                except ValueError:
                    if origin_value != '':
                        raise
                else:
                    dispatcher.send("model_update", self.__model, field_name,
                                    self)
 def set_state(self, value):
     if value in self.valid_states:
         self._state = value
         dispatcher.send("stateChanged", self, self._state)
     else:
         raise RuntimeError(
             "GphlWorkflowConnection set to invalid state: %s" % value
         )
Beispiel #8
0
    def _set_started(self):
        """
        Emits procedureStarted signal
        Returns:

        """
        self._state = ProcedureState.BUSY
        dispatcher.send(self, "procedureStarted")
Beispiel #9
0
    def _set_successful(self):
        """
        Emits procedureSuccessful signal
        Returns:

        """
        self._state = ProcedureState.READY
        dispatcher.send(self, "procedureSuccessful", self.results)
Beispiel #10
0
    def _set_error(self):
        """
        Emits procedure error signal
        Returns:

        """
        self._state = ProcedureState.ERROR
        dispatcher.send(self, "procedureError", self.msg)
Beispiel #11
0
    def _set_stopped(self):
        """
        Emits procedureStoped signal
        Returns:

        """
        self._state = ProcedureState.READY
        dispatcher.send(self, "procedureStopped", self.results)
    def emit(self, signal, *args):

        signal = str(signal)

        if len(args) == 1:
            if isinstance(args[0], tuple):
                args = args[0]
        dispatcher.send(signal, self, *args)
Beispiel #13
0
 def __ledit_update_value(self, field_name, new_value, type_fn, validator):
     if self.__validated(validator, self.bindings[field_name][0], new_value):
         try:
             setattr(self.__model, field_name, type_fn(new_value))
         except ValueError:
             if new_value != "":
                 raise
         else:
             dispatcher.send("model_update", self.__model, field_name, self)
Beispiel #14
0
 def __ledit_update_value(self, field_name, new_value, type_fn, validator):
     if self.__validated(validator, self.bindings[field_name][0],
                         new_value):
         try:
             setattr(self.__model, field_name, type_fn(new_value))
         except ValueError:
             if new_value != '':
                 raise
         else:
             dispatcher.send("model_update", self.__model, field_name, self)
Beispiel #15
0
 def __ledit_text_edited(self, field_name, widget, new_value, type_fn,
                         validator):
     self.bindings[field_name][3] = True
     if self.__validated(field_name, validator,
                         self.bindings[field_name][0], new_value):
         try:
             setattr(self.__model, field_name, type_fn(new_value))
         except ValueError:
             if new_value != "":
                 raise
         else:
             dispatcher.send("model_update", self.__model, field_name, self)
Beispiel #16
0
 def __ledit_text_edited(self, field_name, widget, new_value, type_fn, validator):
     self.bindings[field_name][3] = True
     if self.__validated(field_name,
                         validator,
                         self.bindings[field_name][0],
                         new_value):
         try:
             setattr(self.__model, field_name, type_fn(new_value))
         except ValueError:
             if new_value != '':
                 raise
         else:
             dispatcher.send("model_update", self.__model, field_name, self)
    def emit(self, signal, *args):
        """Emit signal. Accepts both multiple args and a single tuple of args.

        TODO This function would be unnecessary if all callers used
        dispatcher.send(signal, self, *argtuple)

        Args:
            signal (hashable object): Signal. In practice a string, or dispatcher.Any
            *args (tuple): Arguments sent with signal"""

        signal = str(signal)

        if len(args) == 1:
            if isinstance(args[0], tuple):
                args = args[0]
        dispatcher.send(signal, self, *args)
Beispiel #18
0
 def __ledit_update_value(self, field_name, widget, new_value, type_fn, validator): 
     if not self.bindings[field_name][3]:
         origin_value = new_value
         if type_fn == float and validator:
             pattern = "%." + str(validator.decimals()) + 'f'
             new_value = QtCore.QString(pattern % float(new_value))
         if self.__validated(field_name,
                             validator,
                             self.bindings[field_name][0], 
                             new_value):
             if isinstance(widget, QtGui.QLineEdit):
                 if type_fn is float and validator:
                     widget.setText('{:g}'.format(round(float(origin_value), \
                                    validator.decimals())))
             try:
                 setattr(self.__model, field_name, type_fn(origin_value)) 
             except ValueError:
                 if origin_value != '':
                     raise
             else:
                 dispatcher.send("model_update", self.__model, field_name, self)
    def discardHardwareObject(self, hoName):
        """Remove a Hardware Object from the Hardware Repository

        Parameters :
          hoName -- the name of the Hardware Object to remove

        Emitted signals :
          hardwareObjectDiscarded (<object name>) -- emitted when the object has been removed
        """
        try:
            del self.hardwareObjects[hoName]
        except KeyError:
            pass
        try:
            self.invalidHardwareObjects.remove(hoName)
        except BaseException:
            pass
        try:
            del self.requiredHardwareObjects[hoName]
        except KeyError:
            pass

        dispatcher.send("hardwareObjectDiscarded", hoName, self)
    def discardHardwareObject(self, hoName):
        """Remove a Hardware Object from the Hardware Repository

        Parameters :
          hoName -- the name of the Hardware Object to remove

        Emitted signals :
          hardwareObjectDiscarded (<object name>) -- emitted when the object has been removed
        """
        try:
            del self.hardwareObjects[hoName]
        except KeyError:
            pass
        try:
            self.invalidHardwareObjects.remove(hoName)
        except Exception:
            pass
        try:
            del self.requiredHardwareObjects[hoName]
        except KeyError:
            pass

        dispatcher.send("hardwareObjectDiscarded", hoName, self)
Beispiel #21
0
    def __ledit_update_value(self, field_name, widget, new_value, type_fn, validator): 
        if not self.bindings[field_name][3]:
            origin_value = new_value
            #logging.getLogger().info('__line_update_value field_name %s new_value %s type_fn %s' % (field_name, new_value, type_fn))
            if type_fn == float and validator and new_value != None:
                pattern = "%." + str(validator.decimals()) + 'f'
                try:
                    new_value = pattern % float(new_value)
                except:
                    logging.getLogger().debug('__line_update_value field_name %s new_value %s type_fn %s' % (field_name, new_value, type_fn))
                    

            # fix validation if PyQt4 and sipapi 1 is used
            if type(new_value) is str:
                 if "QString" in globals(): 
                     new_value = QString(new_value)

            self.__validated(field_name,
                             validator,
                             self.bindings[field_name][0], 
                             new_value)
            if True:
                try:
                    if isinstance(widget, QLineEdit):
                        if type_fn is float and validator:
                            widget.setText('{:g}'.format(round(float(origin_value), \
                                        validator.decimals())))
                except:
                    logging.getLogger().debug('__line_update_value field_name %s origin_value %s type_fn %s' % (field_name, origin_value, type_fn))
                try:
                    setattr(self.__model, field_name, type_fn(origin_value)) 
                except ValueError:
                    if origin_value != '':
                        pass
                        #raise
                else:
                    dispatcher.send("model_update", self.__model, field_name, self)
 def collect_failed(self, message):
     dispatcher.send("collect_finished")
     self.get_view().setText(1, "Failed")
     self.status = QUEUE_ENTRY_STATUS.FAILED
     logging.getLogger("queue_exec").error(message.replace("\n", " "))
     raise QueueExecutionException(message.replace("\n", " "), self)
Beispiel #23
0
 def __combobox_update_value(self, field_name, new_value):
     setattr(self.__model, field_name, new_value)
     dispatcher.send("model_update", self.__model, field_name, self)
Beispiel #24
0
 def __combobox_update_value(self, field_name, new_value):
     setattr(self.__model, field_name, new_value)
     dispatcher.send("model_update", self.__model, field_name, self)
    def loadHardwareObject(self, hwobj_name=""):
        """
        Load a Hardware Object

        :param hwobj_name:  string name of the Hardware Object to load, for example '/motors/m0'
        :return: the loaded Hardware Object, or None if it fails
        """

        comment = ""
        class_name = ""
        hwobj_instance = None

        if self.server:
            if self.server.isSpecConnected():
                try:
                    if hwobj_name in self.requiredHardwareObjects:
                        reply_dict = self.requiredHardwareObjects[hwobj_name]
                    else:
                        reply_dict = SpecWaitObject.waitReply(
                            self.server,
                            "send_msg_chan_read",
                            ('xml_get("%s")' % hwobj_name,),
                            timeout=3,
                        )
                except BaseException:
                    logging.getLogger("HWR").exception(
                        'Could not load Hardware Object "%s"' % hwobj_name
                    )
                else:
                    try:
                        # TODO Both variables not used: remove?
                        xml_data = reply_dict["xmldata"]
                        mtime = int(reply_dict["mtime"])
                    except KeyError:
                        logging.getLogger("HWR").error(
                            "Cannot load Hardware Object %s: file does not exist."
                            % hwobj_name
                        )
                        return
            else:
                logging.getLogger("HWR").error(
                    'Cannot load Hardware Object "%s" : not connected to server.'
                    % hwobj_name
                )
        else:
            xml_data = ""
            for xml_files_path in self.serverAddress:
                file_name = (
                    hwobj_name[1:] if hwobj_name.startswith(os.path.sep) else hwobj_name
                )
                file_path = (
                    os.path.join(xml_files_path, file_name) + os.path.extsep + "xml"
                )
                if os.path.exists(file_path):
                    try:
                        xml_data = open(file_path, "r").read()
                    except BaseException:
                        pass
                    break

        start_time = datetime.now()

        if len(xml_data) > 0:
            try:
                hwobj_instance = self.parseXML(xml_data, hwobj_name)
                if isinstance(hwobj_instance, string_types):
                    return self.loadHardwareObject(hwobj_instance)
            except BaseException:
                comment = "Cannot parse xml"
                logging.getLogger("HWR").exception(
                    "Cannot parse XML file for Hardware Object %s", hwobj_name
                )
            else:
                if hwobj_instance is not None:
                    self.xml_source[hwobj_name] = xml_data
                    dispatcher.send("hardwareObjectLoaded", hwobj_name, self)

                    def hardwareObjectDeleted(name=hwobj_instance.name()):
                        logging.getLogger("HWR").debug(
                            "%s Hardware Object has been deleted from Hardware Repository",
                            name,
                        )
                        del self.hardwareObjects[name]

                    hwobj_instance.resolveReferences()

                    try:
                        hwobj_instance._addChannelsAndCommands()
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            "Error while adding commands and/or channels to Hardware Object %s",
                            hwobj_name,
                        )
                        comment = "Failed to add all commands and/or channels"

                    try:
                        hwobj_instance._init()
                        hwobj_instance.init()
                        class_name = str(hwobj_instance.__module__)
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            'Cannot initialize Hardware Object "%s"', hwobj_name
                        )
                        self.invalidHardwareObjects.add(hwobj_instance.name())
                        hwobj_instance = None
                        comment = "Failed to init class"
                    else:
                        if hwobj_instance.name() in self.invalidHardwareObjects:
                            self.invalidHardwareObjects.remove(hwobj_instance.name())

                        self.hardwareObjects[hwobj_instance.name()] = hwobj_instance
                else:
                    logging.getLogger("HWR").error(
                        "Failed to load Hardware object %s", hwobj_name
                    )
                    comment = "Loading failed"
        else:
            logging.getLogger("HWR").error(
                'Cannot load Hardware Object "%s" : file not found.', hwobj_name
            )

        end_time = datetime.now()
        time_delta = end_time - start_time

        self.hwobj_info_list.append(
            (
                hwobj_name,
                class_name,
                "%d ms" % (time_delta.microseconds / 1000),
                comment,
            )
        )

        return hwobj_instance
    def _loadHardwareObject(self, hwobj_name=""):
        """
        Load a Hardware Object. Do NOT use externally,
        as this will mess up object tracking, signals, etc.

        :param hwobj_name:  string name of the Hardware Object to load, e.g. /motors/m0
        :return: the loaded Hardware Object, or None if it fails
        """

        comment = ""
        class_name = ""
        hwobj_instance = None

        if self.server:
            if self.server.isSpecConnected():
                try:
                    if hwobj_name in self.requiredHardwareObjects:
                        reply_dict = self.requiredHardwareObjects[hwobj_name]
                    else:
                        reply_dict = SpecWaitObject.waitReply(
                            self.server,
                            "send_msg_chan_read",
                            ('xml_get("%s")' % hwobj_name, ),
                            timeout=3,
                        )
                except Exception:
                    logging.getLogger("HWR").exception(
                        'Could not load Hardware Object "%s"', hwobj_name)
                else:
                    try:
                        # TODO Both variables not used: remove?
                        xml_data = reply_dict["xmldata"]
                        mtime = int(reply_dict["mtime"])
                    except KeyError:
                        logging.getLogger("HWR").error(
                            "Cannot load Hardware Object %s: file does not exist.",
                            hwobj_name,
                        )
                        return
            else:
                logging.getLogger("HWR").error(
                    'Cannot load Hardware Object "%s" : not connected to server.',
                    hwobj_name,
                )
        else:
            xml_data = ""
            for xml_files_path in self.serverAddress:
                file_name = (hwobj_name[1:] if hwobj_name.startswith(
                    os.path.sep) else hwobj_name)
                file_path = (os.path.join(xml_files_path, file_name) +
                             os.path.extsep + "xml")
                if os.path.exists(file_path):
                    try:
                        xml_data = open(file_path, "r").read()
                    except Exception:
                        pass
                    break

        start_time = datetime.now()

        if xml_data:
            try:
                hwobj_instance = self.parseXML(xml_data, hwobj_name)
                if isinstance(hwobj_instance, string_types):
                    # We have redirection to another file
                    # Enter in dictionaries also under original names
                    result = self._loadHardwareObject(hwobj_instance)
                    if hwobj_name in self.invalidHardwareObjects:
                        self.invalidHardwareObjects.remove(hwobj_name)
                    self.hardwareObjects[hwobj_name] = result
                    return result
            except Exception:
                comment = "Cannot parse xml"
                logging.getLogger("HWR").exception(
                    "Cannot parse XML file for Hardware Object %s", hwobj_name)
            else:
                if hwobj_instance is not None:
                    self.xml_source[hwobj_name] = xml_data
                    dispatcher.send("hardwareObjectLoaded", hwobj_name, self)

                    def hardwareObjectDeleted(name=hwobj_instance.name()):
                        logging.getLogger("HWR").debug(
                            "%s Hardware Object has been deleted from Hardware Repository",
                            name,
                        )
                        del self.hardwareObjects[name]

                    hwobj_instance.resolveReferences()

                    try:
                        hwobj_instance._add_channels_and_commands()
                    except Exception:
                        logging.getLogger("HWR").exception(
                            "Error while adding commands and/or channels to Hardware Object %s",
                            hwobj_name,
                        )
                        comment = "Failed to add all commands and/or channels"

                    try:
                        hwobj_instance._init()
                        hwobj_instance.init()
                        class_name = str(hwobj_instance.__module__)
                    except Exception:
                        logging.getLogger("HWR").exception(
                            'Cannot initialize Hardware Object "%s"',
                            hwobj_name)
                        self.invalidHardwareObjects.add(hwobj_instance.name())
                        hwobj_instance = None
                        comment = "Failed to init class"
                    else:
                        if hwobj_instance.name(
                        ) in self.invalidHardwareObjects:
                            self.invalidHardwareObjects.remove(
                                hwobj_instance.name())

                        self.hardwareObjects[
                            hwobj_instance.name()] = hwobj_instance
                else:
                    logging.getLogger("HWR").error(
                        "Failed to load Hardware object %s", hwobj_name)
                    comment = "Loading failed"
        else:
            logging.getLogger("HWR").error(
                'Cannot load Hardware Object "%s" : file not found.',
                hwobj_name)

        end_time = datetime.now()
        time_delta = end_time - start_time

        self.hwobj_info_list.append((
            hwobj_name,
            class_name,
            "%d ms" % (time_delta.microseconds / 1000),
            comment,
        ))

        return hwobj_instance
 def set_grid_data(self, key, result_data):
     dispatcher.send("set_grid_data", self, key, result_data)
 def set_grid_data(self, key, result_data):
     dispatcher.send("set_grid_data", self, key, result_data)
Beispiel #29
0
    def loadHardwareObject(self, hwobj_name=""):
        """
        Load a Hardware Object

        :param hwobj_name:  string name of the Hardware Object to load, for example '/motors/m0'
        :return: the loaded Hardware Object, or None if it fails
        """

        comment = ""
        class_name = ""
        hwobj_instance = None

        if self.server:
            if self.server.isSpecConnected():
                try:
                    if hwobj_name in self.requiredHardwareObjects:
                        reply_dict = self.requiredHardwareObjects[hwobj_name]
                    else:
                        reply_dict = SpecWaitObject.waitReply(
                            self.server,
                            "send_msg_chan_read",
                            ('xml_get("%s")' % hwobj_name, ),
                            timeout=3,
                        )
                except BaseException:
                    logging.getLogger("HWR").exception(
                        'Could not load Hardware Object "%s"' % hwobj_name)
                else:
                    try:
                        # TODO Both variables not used: remove?
                        xml_data = reply_dict["xmldata"]
                        mtime = int(reply_dict["mtime"])
                    except KeyError:
                        logging.getLogger("HWR").error(
                            "Cannot load Hardware Object %s: file does not exist."
                            % hwobj_name)
                        return
            else:
                logging.getLogger("HWR").error(
                    'Cannot load Hardware Object "%s" : not connected to server.'
                    % hwobj_name)
        else:
            xml_data = ""
            for xml_files_path in self.serverAddress:
                file_name = (hwobj_name[1:] if hwobj_name.startswith(
                    os.path.sep) else hwobj_name)
                file_path = (os.path.join(xml_files_path, file_name) +
                             os.path.extsep + "xml")
                if os.path.exists(file_path):
                    try:
                        xml_data = open(file_path, "r").read()
                    except BaseException:
                        pass
                    break

        start_time = datetime.now()

        if len(xml_data) > 0:
            try:
                hwobj_instance = self.parseXML(xml_data, hwobj_name)
                if isinstance(hwobj_instance, str):
                    return self.loadHardwareObject(hwobj_instance)
            except BaseException:
                comment = "Cannot parse xml"
                logging.getLogger("HWR").exception(
                    "Cannot parse XML file for Hardware Object %s", hwobj_name)
            else:
                if hwobj_instance is not None:
                    self.xml_source[hwobj_name] = xml_data
                    dispatcher.send("hardwareObjectLoaded", hwobj_name, self)

                    def hardwareObjectDeleted(name=hwobj_instance.name()):
                        logging.getLogger("HWR").debug(
                            "%s Hardware Object has been deleted from Hardware Repository",
                            name,
                        )
                        del self.hardwareObjects[name]

                    hwobj_instance.resolveReferences()

                    try:
                        hwobj_instance._addChannelsAndCommands()
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            "Error while adding commands and/or channels to Hardware Object %s",
                            hwobj_name,
                        )
                        comment = "Failed to add all commands and/or channels"

                    try:
                        hwobj_instance._init()
                        hwobj_instance.init()
                        class_name = str(hwobj_instance.__module__)
                    except BaseException:
                        logging.getLogger("HWR").exception(
                            'Cannot initialize Hardware Object "%s"',
                            hwobj_name)
                        self.invalidHardwareObjects.add(hwobj_instance.name())
                        hwobj_instance = None
                        comment = "Failed to init class"
                    else:
                        if hwobj_instance.name(
                        ) in self.invalidHardwareObjects:
                            self.invalidHardwareObjects.remove(
                                hwobj_instance.name())

                        self.hardwareObjects[
                            hwobj_instance.name()] = hwobj_instance
                else:
                    logging.getLogger("HWR").error(
                        "Failed to load Hardware object %s", hwobj_name)
                    comment = "Loading failed"
        else:
            logging.getLogger("HWR").error(
                'Cannot load Hardware Object "%s" : file not found.',
                hwobj_name)

        end_time = datetime.now()
        time_delta = end_time - start_time

        self.hwobj_info_list.append((
            hwobj_name,
            class_name,
            "%d ms" % (time_delta.microseconds / 1000),
            comment,
        ))

        # # Temporary help to get hold of superclasses
        # import inspect
        # for cls in inspect.getmro(hwobj_instance.__class__)[1:]:
        #     tt = ('super', cls.__name__, "0 ms", '@~@~')
        #     if tt not in  self.hwobj_info_list:
        #         self.hwobj_info_list.append(tt)

        return hwobj_instance