コード例 #1
0
 def __init__(self, session):
     self.session = session
     self.url = ""
     self.languageDict = None
     self.formLoaded = qi.Signal("(ss)")
     self.questionLoaded = qi.Signal("(sss[s])")
     self.answerGiven = qi.Signal("(sss)")
コード例 #2
0
 def _connect_signals(self):
     """Init qi.Signals and memory events (for compatibility)"""
     self.onGesture = qi.Signal()
     self.onRelease = qi.Signal()
     self.gestureEvent = '{}/{}'.format(self.module_name, 'Gesture')
     self.releaseEvent = '{}/{}'.format(self.module_name, 'Release')
     self.memory.declareEvent(self.gestureEvent, self.module_name)
     self.memory.declareEvent(self.releaseEvent, self.module_name)
コード例 #3
0
 def _create_signals(self):
     """
     Create signals and events required by BarcodeReader.
     """
     self.logger.info('Creating required signals and events...')
     self.onBarcodeDetected = qi.Signal()
     self.logger.info('All signals have been created')
コード例 #4
0
    def __init__(self, session):
        """init of the Class

        Arguments:
            self -- Local class instance
            session -- Current open session to the naoqi-interface
        """
        super(SpeechLocalization, self).__init__()
        # keep a reference on the current session
        self.session = session
        # wait for needed services to be started:
        self.session.waitForService("ALMemory");
        self.session.waitForService("ALSoundLocalization");
        self.session.waitForService("ALSpeechRecognition");
        self.memory_interface = EventInterface(self.session)
        self.service_best_sound_loc = self.session.service("ALSoundLocalization")
        # create ouput signal event (naoqi-2)
        self.speechLocated = qi.Signal('((sf)((ii)(ffff)(ffffff)(ffffff)))', self.on_remote_connect)
        # configure internal parameters:
        self.param_separative_angle = math.pi/8
        self.param_coef_aggregation = 0.1
        self.param_time_latency = 2.0
        self.param_delay_event_sound_loc_before_asr = 0.8
        #configure local variables:
        self.best_sound_loc_reset = {"internal_confidence":0.0,
                                "value":[[0L, 0L], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]],
                                "main_angle":[0.0, 0.0, 0.0],
                                "time":0.0}
        self.best_sound_loc = copy.deepcopy(self.best_sound_loc_reset)
        self.best_sound_loc_old = copy.deepcopy(self.best_sound_loc_reset)
コード例 #5
0
def test_signal():
    print("\nInit...")
    sub1 = subscriber()
    sub2 = subscriber()
    mysignal = qi.Signal()

    print("\nTest #1 : Multiple subscribers to signal")
    callback = sub1.callback
    callback2 = sub2.callback
    mysignal.connect(callback)
    signalid = mysignal.connect(callback2)

    mysignal()
    sub2.wait()
    sub1.wait()

    print("\nTest #2 : Disconnect only one")
    mysignal.disconnect(signalid)

    sub1.done = False
    sub2.done = False
    mysignal()
    sub1.wait()

    print("\nTest #3 : Disconnect All")
    mysignal.connect(callback2)
    assert mysignal.disconnectAll() == True

    sub1.done = False
    sub2.done = False
    mysignal()
    time.sleep(0.5)

    assert sub1.done == False
    assert sub2.done == False

    print("\nTest #4 : Trigger with one parameter")
    mysignal.connect(sub1.callback_42)

    sub1.done = False
    sub2.done = False
    mysignal(42)
    sub1.wait()

    assert sub1.done == True
    assert sub2.done == False

    assert mysignal.disconnectAll() == True
    print("\nTest #5 : Trigger with five parameters")
    mysignal.connect(sub1.callback_5args)

    sub1.done = False
    sub2.done = False
    mysignal(42, "hey", "a", 0.42, (0, 1))
    sub1.wait()
    assert sub1.done == True
    assert sub2.done == False
コード例 #6
0
def test_signal_strand():
    obj = Stranded(30)

    sig = qi.Signal("m")
    for i in range(30):
        sig.connect(obj.cb)
    sig(None)

    obj.end.future().value()
コード例 #7
0
def test_subscribe():
  global lastSubs
  lastSubs = False
  def onSubscriber(subs):
    global lastSubs
    lastSubs = subs
  sig = qi.Signal('m', onSubscriber)
  assert lastSubs == False
  connlink = sig.connect(lambda x: None)
  assert lastSubs == True
  assert sig.disconnect(connlink)
  assert lastSubs == False
コード例 #8
0
    def __init__(self, session):
        """ Helper to configure the network from a QRCode

            Properties:
                status : the current status of the module. Can be
                        Ready : the module is initialized.
                        WaitingForQRCode : The module is scanning for a QRCode.
                        QRCodeDetected : The module has detected a QRCode.
                        Connecting : The module is trying to connect to the network.
                        Connected : The network is connected.
                        Error : Something goes wrong.
        """
        self.session = session

        #logger
        self.logger = qi.logging.Logger("naoqi.core.ALQRCodeWifiConfigurator")
        self.module = qi.module("qicore")
        self.logManager = self.session.service("LogManager")
        self.provider = self.module.createObject("LogProvider",
                                                 self.logManager)
        self.providerId = self.logManager.addProvider(self.provider)

        # init variables
        self.connectingToHiddenNetwork = False  # Setup wifi variable
        self.waitingForConnection = False
        self.cnonce = random.randint(
            1000, 9999
        )  # TODO: figure out if we want to use Head Id or what; for now Nonce is used nowhere in the process
        self.attemptedHiddenNetworks = None
        self.hiddenNetworkFailureReasons = None
        self.cam = 0
        self.status = qi.Signal("(s)")

        self.albarcodereader = self._get_service("ALBarcodeReader")
        if self.albarcodereader is None:
            self.logger.error("ALBarcodeReader is not available")
            return

        self.alconnectionmanager = self._get_service("ALConnectionManager")
        if self.alconnectionmanager is None:
            self.logger.error("ALConnectionManager is not available")
            return

        self.alvideodevice = self._get_service("ALVideoDevice")
        if self.alvideodevice is None:
            self.logger.error("ALVideoDevice is not available")
            return

        self.almemory = self._get_service("ALMemory")
        self.alaudioplayer = self._get_service("ALAudioPlayer")

        self.status(ALQRCodeWifiConfigurator.STATUS_READY)
コード例 #9
0
ファイル: main.py プロジェクト: monteCristoN/pepper-survey
    def __init__(self, qiapp):
        """Init application."""
        self.qiapp = qiapp
        self.s = stk.services.ServiceCache(qiapp.session)
        self.events = stk.events.EventHelper(qiapp.session)
        self.logger = stk.logging.get_logger(qiapp.session, self.APP_ID)

        self._init_dialog(['pepper-survey'], 'pepper-survey')
        self._init_customization()
        self._init_survey()
        self._init_inactivity_watcher()

        # Signals
        self.tabletEvent = qi.Signal()
コード例 #10
0
class SBRAppLauncher(object):
    """Communicates with the tablet and installs the native android app
    launcher.
    """
    def __init__(self, session):
        currPath = os.path.dirname(os.path.realpath(__file__))
        subprocess.call(["chmod", "+x", currPath + "/adb"])
        pathToLink = "/home/nao/.local/share/PackageManager/apps/applauncher"
        try:
            os.symlink(currPath, pathToLink)
        except OSError, e:
            if e.errno == errno.EEXIST:
                os.remove(pathToLink)
                os.symlink(currPath, pathToLink)
        self.session = session
        self.name = 'jp.softbank.rb.rald'
        self.version = '2.1.4'
        self._activityRequestedByUser = qi.Signal('(s)')
        self.touch_expr_obj = None
        self.target_behavior = str()
        self.services_connected = None
        self.log_prefix = 'ApplicationLauncher'
        self.custom_launcher = str()
        try:
            qicore = qi.module("qicore")
            log_manager = self.session.service("LogManager")
            provider = qicore.createObject("LogProvider", log_manager)
            log_manager.addProvider(provider)
            self.logger = qi.Logger(self.log_prefix)
        except (RuntimeError, AttributeError):
            pass

        # Wait for all services to be available
        self.connect_services(90)
        self.mem.declareEvent('ALRALManagerModule/onTouchDown')
        self.alife.userRequestableActivitiesViolations.connect(
            self.on_permissions_changed)
        self.tts.languageTTS.connect(self.on_language_changed)
        self.packman.onPackageRemoved2.connect(
            self.on_package_custom_launcher_removed)

        tablet = self.get_tablet_service()
        self.change_applauncher()
        self.startService()
        try:
            tablet.onTouchDown.connect(self.onTabletTouched)
        except (AttributeError, RuntimeError) as err:
            self.logger.warning(
                'Problem connecting the tablet touched event: {}'.format(err))
コード例 #11
0
    def __init__(self, session=None):
        self._session = session
        self._module_name = self.__class__.__name__
        self.__name__ = self._module_name
        self._logger = qi.Logger(self._module_name)
        self._logger.info(":::: Starting {} ::::".format(self._module_name))
        self._pref_domain = "tool.applauncher"  # @TODO: "com.sbr.apps.app-launcher"

        # public variables
        self._logger.info("Initializing public variables...")
        self.current_state = qi.Property("s")
        self.current_state.setValue("")
        self.current_page = qi.Property("s")
        self.current_page.setValue("Home")
        self.apps_full_list = qi.Property()
        self.apps_full_list.setValue({})
        self.pages_definition = qi.Property()
        self.pages_definition.setValue({})
        self.autonomous_enabled = qi.Property("b")
        self.autonomous_enabled.setValue(True)
        self.display_app_name = qi.Property("b")
        self.display_app_name.setValue(True)
        self.ping_required = qi.Signal("(i)")

        # internal variables
        self._logger.info("Initializing internal variables...")
        self._app_uuid = helpers.find_app_name(self._logger)
        self._current_app = ""
        self._preferences_manager = PreferencesManager(self._logger, self._session, self._pref_domain)
        self._app_list_manager = AppListManager(self._logger, self._session, self._preferences_manager,
                                                self._app_uuid, self.apps_full_list, self.pages_definition)
        self._view_manager = ViewManager(self._logger, self._session, self._preferences_manager,
                                         self._app_uuid, self.current_state, self.ping_required)
        self._dialog_manager = DialogManager(self._logger, self._session, self._preferences_manager,
                                             self.pages_definition, self.autonomous_enabled, self.current_page)

        _pref_display_app_name = self._preferences_manager.get_value('behaviorNameDisplayed', True)
        if _pref_display_app_name:
            self.display_app_name.setValue(True)
        else:
            self.display_app_name.setValue(False)

        self._logger.info(":::: Ready! ::::")
コード例 #12
0
def test_all_strand():
    obj = Stranded(81)

    sig = qi.Signal("m")
    prop = qi.Property("m")
    prom = qi.Promise()
    per = qi.PeriodicTask()
    per.setCallback(partial(obj.cb, None))
    per.setUsPeriod(10000)
    for i in range(20):
        prom.future().addCallback(obj.cb)
    for i in range(20):
        sig.connect(obj.cb)
    for i in range(20):
        prop.connect(obj.cb)
    per.start(True)
    sig(None)
    prop.setValue(42)
    prom.setValue(None)
    for i in range(20):
        qi. async (partial(obj.cb, None))

    obj.end.future().value()
    per.stop()
コード例 #13
0
 def __init__(self):
     self.sig = qi.Signal('m')
コード例 #14
0
 def __init__(self):
     self.onFoo = qi.Signal("(i)")
     self.testEvent = qi.Signal("(s)")
     self.testEventGeneric = qi.Signal()
コード例 #15
0
 def __init__(self, app):
     self.startSignal = qi.Signal()
     self.stopSignal = qi.Signal()
     self.service_name = self.__class__.__name__
     self.session = app.session
コード例 #16
0
ファイル: test.py プロジェクト: wezh/libqi-js
 def __init__(self):
     self.signal = qi.Signal()
     self.property = qi.Property()
     self.property.setValue(42)