def pl_send_new_parameter_list(self, parameters): """ Used to inform the PaPI framework about all DParameters provided by this plugins. :param parameters: List of DParameters :return: """ if not isinstance(parameters, list): raise pe.WrongType("parameters", list) if len(parameters) == 0: raise pe.WrongLength("parameters", len(parameters), ">0") parameter_list_to_send = [] # The callback handler cannot be send over process boundaries, so we need to remove it before sending for i in range(len(parameters)): parameter = parameters[i] if not isinstance(parameter, DParameter): raise pe.WrongType('parameters['+str(i)+']', DParameter) self.__plugin_parameter_list[parameter.name] = parameter tmp_parameter = copy.copy(parameter) tmp_parameter.callback_function_handler = None parameter_list_to_send.append(tmp_parameter) opt = DOptionalData() opt.parameter_list = parameter_list_to_send event = Event.data.NewParameter(self.__id__, 0, opt) self._Core_event_queue__.put(event)
def do_unsubscribe(self, subscriber_id, source_id, block_name, signal_index=None): """ Something like a callback function for gui triggered events. User wants one plugin to do not get any more data from another plugin :param subscriber_id: plugin id which wants to lose a data source :type subscriber_id: int :param source_id: plugin id of data source :type source_id: int :param block_name: name of block to unsubscribe :type block_name: basestring :return: """ # create optional data with source id and block_name opt = DOptionalData() opt.source_ID = source_id opt.block_name = block_name opt.signals = signal_index # sent event to Core with origin subscriber_id event = Event.instruction.Unsubscribe(subscriber_id, 0, opt) self.core_queue.put(event)
def do_create_plugin(self, plugin_identifier, uname, config={}, autostart=True): """ Something like a callback function for gui triggered events e.a. when a user wants to create a new plugin. :param plugin_identifier: plugin to create :type plugin_identifier: basestring :param uname: uniqe name to set for new plugin :type uname: basestring :param config: additional configuration for creation :type config: :return: """ # create new optional Data for event opt = DOptionalData() # set important information # plugin to create opt.plugin_identifier = plugin_identifier # uname to create plugin with opt.plugin_uname = uname # additional config opt.plugin_config = config opt.autostart = autostart # check if plugin with uname already exists allPlugins = self.gui_data.get_all_plugins() for pluginID in allPlugins: plugin = allPlugins[pluginID] if plugin.uname == uname: return False # create event object and sent it to core event = Event.instruction.CreatePlugin(self.gui_id, 0, opt) self.core_queue.put(event)
def pl_send_new_parameter_list(self, parameters): """ Used to inform the PaPI framework about all DParameters provided by this plugins. :param parameters: List of DParameters :return: """ if not isinstance(parameters, list): raise pe.WrongType("parameters", list) if len(parameters) == 0: raise pe.WrongLength("parameters", len(parameters), ">0") parameter_list_to_send = [ ] # The callback handler cannot be send over process boundaries, so we need to remove it before sending for i in range(len(parameters)): parameter = parameters[i] if not isinstance(parameter, DParameter): raise pe.WrongType('parameters[' + str(i) + ']', DParameter) self.__plugin_parameter_list[parameter.name] = parameter tmp_parameter = copy.copy(parameter) tmp_parameter.callback_function_handler = None parameter_list_to_send.append(tmp_parameter) opt = DOptionalData() opt.parameter_list = parameter_list_to_send event = Event.data.NewParameter(self.__id__, 0, opt) self._Core_event_queue__.put(event)
def do_set_parameter(self, plugin_id, parameter_name, value, only_db_update = False): """ Something like a callback function for gui triggered events. User wants to change a parameter of a plugin :param plugin_id: id of plugin which owns the parameter :type plugin_id: int :param parameter_name: name of parameter to change :type parameter_name: basestring :param value: new parameter value to set :type value: :param only_db_update: do_set_parameter of the target plugin will not be called. Updates only the internal database. :type boolean: """ # get plugin from DGUI dplug = self.gui_data.get_dplugin_by_id(plugin_id) # check for existance if dplug is not None: # it exists # get its parameter list parameters = dplug.get_parameters() # check if there are any parameter if parameters is not None: # there is a parameter list # get the parameter with parameter_name if parameter_name in parameters: p = parameters[parameter_name] # check if this specific parameter exists if p is not None: # parameter with name parameter_name exists # build an event to send this information to Core opt = DOptionalData() opt.data = value opt.is_parameter = True opt.parameter_alias = parameter_name opt.block_name = None if only_db_update: e = Event.instruction.UpdateParameter(self.gui_id, dplug.id, opt) else: e = Event.instruction.SetParameter(self.gui_id, dplug.id, opt) self.core_queue.put(e)
def do_close_program(self): """ Tell core to close papi. Core will respond and will close all open plugins. GUI will close all VIP Plugins due to calling their quit function """ plugins = self.gui_data.get_all_plugins() for dplugin_id in plugins: dplugin = plugins[dplugin_id] if dplugin.type == PLUGIN_VIP_IDENTIFIER: try: dplugin.plugin.cb_quit() except Exception as E: tb = traceback.format_exc() self.plugin_died.emit(dplugin, E, tb) opt = DOptionalData() opt.reason = 'User clicked close Button' event = Event.instruction.CloseProgram(self.gui_id, 0, opt) self.core_queue.put(event)
def do_subscribe(self, subscriber_id, source_id, block_name, signals=None, sub_alias=None): """ Something like a callback function for gui triggered events. In this case, user wants one plugin to subscribe another :param subscriber_id: Plugin id of plugin which should get the data :type subscriber_id: int :param source_id: plugin uname of plugin that should send the data :type source_id: int :param block_name: name of block to subscribe :type block_name: basestring :return: """ # build optional data object and add id and block name to it opt = DOptionalData() opt.source_ID = source_id opt.block_name = block_name opt.signals = signals opt.subscription_alias = sub_alias # send event with subscriber id as the origin to CORE event = Event.instruction.Subscribe(subscriber_id, 0, opt) self.core_queue.put(event)
def pl_send_new_data(self, block_name, time_line, data): """ This function is called by plugins to send new data for a single block. :param block_name: Name of the block :param time_line: A time vector :param data: Data containing the values in a hash array of signal names as key. :return: """ if not isinstance(time_line, list): raise pe.WrongType("time", list) if not isinstance(data, dict): raise pe.WrongType("data", dict) dataHash = data dataHash[CORE_TIME_SIGNAL] = time_line opt = DOptionalData(DATA=dataHash) opt.data_source_id = self.__id__ opt.block_name = block_name event = Event.data.NewData(self.__id__, 0, opt, None) self._Core_event_queue__.put(event)
def pl_send_new_data(self, block_name, time_line, data): """ This function is called by plugins to send new data for a single block. :param block_name: Name of the block :param time_line: A time vector :param data: Data containing the values in a hash array of signal names as key. :return: """ if not isinstance(time_line, list): raise pe.WrongType("time", list) if not isinstance(data, dict): raise pe.WrongType("data", dict) dataHash = data dataHash[CORE_TIME_SIGNAL] = time_line opt = DOptionalData(DATA = dataHash) opt.data_source_id = self.__id__ opt.block_name = block_name event = Event.data.NewData(self.__id__, 0, opt, None) self._Core_event_queue__.put(event)
def _send_parameter_change(self, data, block): """ Internal function, should be not directly used anymore. :param data: :param block: :return: """ opt = DOptionalData(DATA=data) opt.data_source_id = self.__id__ opt.is_parameter = True if isinstance(block, DBlock) is False and isinstance(block, str) is False: raise pe.WrongType("block", [DBlock, str]) if isinstance(block, DBlock): opt.block_name = block.name if isinstance(block, str): opt.block_name = block event = Event.data.NewData(self.__id__, 0, opt, None) self._Core_event_queue__.put(event)
def pl_send_new_block_list(self, blocks): """ Used to inform the PaPI framework about all DBlocks provided by this plugins. :param blocks: List of DBlocks :return: """ if not isinstance(blocks, list): raise pe.WrongType("blocks", list) if len(blocks) == 0: raise pe.WrongLength("blocks", len(blocks), ">0") for i in range(len(blocks)): block = blocks[i] if not isinstance(block, DBlock): raise pe.WrongType('blocks[' + str(i) + ']', DBlock) opt = DOptionalData() opt.block_list = blocks event = Event.data.NewBlock(self.__id__, 0, opt) self._Core_event_queue__.put(event)
def do_set_parameter_uname(self, plugin_uname, parameter_name, value): """ Something like a callback function for gui triggered events. User wants to change a parameter of a plugin :param plugin_uname: name of plugin which owns the parameter :type plugin_uname: basestring :param parameter_name: name of parameter to change :type parameter_name: basestring :param value: new parameter value to set :type value: """ # id = self.do_get_plugin_id_from_uname(plugin_uname) # if id is not None: # self.do_set_parameter(id, parameter_name, value) # print(parameter_name, value) opt = DOptionalData() opt.data = value opt.is_parameter = True opt.parameter_alias = parameter_name opt.block_name = None e = Event.instruction.SetParameterByUname(self.gui_id,plugin_uname, opt) self.core_queue.put(e)
def pl_send_new_block_list(self, blocks): """ Used to inform the PaPI framework about all DBlocks provided by this plugins. :param blocks: List of DBlocks :return: """ if not isinstance(blocks, list): raise pe.WrongType("blocks", list) if len(blocks) == 0: raise pe.WrongLength("blocks", len(blocks), ">0") for i in range(len(blocks)): block = blocks[i] if not isinstance(block, DBlock): raise pe.WrongType('blocks['+str(i)+']', DBlock) opt = DOptionalData() opt.block_list = blocks event = Event.data.NewBlock(self.__id__, 0, opt) self._Core_event_queue__.put(event)
def pl_send_new_parameter_list(self, parameters): """ Used to inform the PaPI framework about all DParameters provided by this plugins. :param parameters: List of DParameters :return: """ if not isinstance(parameters, list): raise pe.WrongType("parameters", list) if len(parameters) == 0: raise pe.WrongLength("parameters", len(parameters), ">0") for i in range(len(parameters)): parameter = parameters[i] if not isinstance(parameter, DParameter): raise pe.WrongType('parameters[' + str(i) + ']', DParameter) opt = DOptionalData() opt.parameter_list = parameters event = Event.data.NewParameter(self.__id__, 0, opt) self._Core_event_queue__.put(event)
def pl_send_new_parameter_list(self, parameters): """ Used to inform the PaPI framework about all DParameters provided by this plugins. :param parameters: List of DParameters :return: """ if not isinstance(parameters, list): raise pe.WrongType("parameters", list) if len(parameters) == 0: raise pe.WrongLength("parameters", len(parameters), ">0") for i in range(len(parameters)): parameter = parameters[i] if not isinstance(parameter, DParameter): raise pe.WrongType('parameters['+str(i)+']', DParameter) opt = DOptionalData() opt.parameter_list = parameters event = Event.data.NewParameter(self.__id__, 0, opt) self._Core_event_queue__.put(event)
def do_resume_plugin_by_id(self, plugin_id): """ Something like a callback function for gui triggered events. User wants to pause a plugin, so this method will send an event to core. :param plugin_id: id of plugin to pause :type plugin_id: int """ if self.gui_data.get_dplugin_by_id(plugin_id) is not None: opt = DOptionalData() event = Event.instruction.ResumePlugin(self.gui_id, plugin_id, opt) self.core_queue.put(event) return 1 else: return -1
def do_set_parameter(self, plugin_id, parameter_name, value, only_db_update=False): """ Something like a callback function for gui triggered events. User wants to change a parameter of a plugin :param plugin_id: id of plugin which owns the parameter :type plugin_id: int :param parameter_name: name of parameter to change :type parameter_name: basestring :param value: new parameter value to set :type value: :param only_db_update: do_set_parameter of the target plugin will not be called. Updates only the internal database. :type boolean: """ # get plugin from DGUI dplug = self.gui_data.get_dplugin_by_id(plugin_id) # check for existance if dplug is not None: # it exists # get its parameter list parameters = dplug.get_parameters() # check if there are any parameter if parameters is not None: # there is a parameter list # get the parameter with parameter_name if parameter_name in parameters: p = parameters[parameter_name] # check if this specific parameter exists if p is not None: # parameter with name parameter_name exists # build an event to send this information to Core opt = DOptionalData() opt.data = value opt.is_parameter = True opt.parameter_alias = parameter_name opt.block_name = None if only_db_update: e = Event.instruction.UpdateParameter( self.gui_id, dplug.id, opt) else: e = Event.instruction.SetParameter( self.gui_id, dplug.id, opt) self.core_queue.put(e)
def do_set_parameter_uname(self, plugin_uname, parameter_name, value): """ Something like a callback function for gui triggered events. User wants to change a parameter of a plugin :param plugin_uname: name of plugin which owns the parameter :type plugin_uname: basestring :param parameter_name: name of parameter to change :type parameter_name: basestring :param value: new parameter value to set :type value: """ # id = self.do_get_plugin_id_from_uname(plugin_uname) # if id is not None: # self.do_set_parameter(id, parameter_name, value) # print(parameter_name, value) opt = DOptionalData() opt.data = value opt.is_parameter = True opt.parameter_alias = parameter_name opt.block_name = None e = Event.instruction.SetParameterByUname(self.gui_id, plugin_uname, opt) self.core_queue.put(e)