在Pepper's Tablet上加载网址

时间:2019-07-17 21:33:08

标签: pepper

我正在尝试在Pepper上加载“ www.google.com”之类的网站

我确定我们连接在同一网络上。我也尝试在ShowApp对话框上执行“ http://www.google.com”。

我看过本指南:http://kokorobot.com/2016/08/08/how-to-use-pepper-tablet

class MyClass(GeneratedClass):

    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        self.isRunning = False

    def onUnload(self):
        self.isRunning = False

    def _getTabletService(self):
        tabletService = None
        try:
            tabletService = self.session().service("ALTabletService")
        except Exception as e:
            self.logger.error(e)
        return tabletService

    def onInput_onStart(self):
        if self.isRunning:
            return # already running, nothing to do
        self.isRunning = True
        # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        tabletService = self._getTabletService()
        appName = self.packageUid()
        state = False
        if appName:
            if tabletService:
                if tabletService.loadApplication(appName):
                    tabletService.loadUrl("www.google.com")                    self.logger.info("Successfully set application: %s" % appName)
                    tabletService.showWebview()
                    state = True
                else:
                    self.logger.warning("Got tablet service, but failed to set application: %s" % appName)
            else:
                self.logger.warning("Couldn't find tablet service, so can't set application: %s" % appName)
        if state:
            self.onSuccess()
        else:
            self.onFailure()

1 个答案:

答案 0 :(得分:0)

如果要显示网页,请考虑使用“显示网页视图”框。我发现Show App带来的麻烦多于其应有的价值。

class MyClass(GeneratedClass):

    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        pass

    def onUnload(self):
        pass

    def _getTabletService(self):
        tabletService = None
        try:
            tabletService = self.session().service("ALTabletService")
        except Exception as e:
            self.logger.error(e)
        return tabletService

    def _getAbsoluteUrl(self, partial_url):
        import os
        subPath = os.path.join(self.packageUid(), os.path.normpath(partial_url).lstrip("\\/"))
        # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        return "http://%s/apps/%s" %(self._getTabletService().robotIp(), subPath.replace(os.path.sep, "/"))

    def onInput_onStart(self):
         # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        tabletService = self._getTabletService()
        if tabletService:
            try:
                url = "http://www.google.com/"
                if url == '':
                    self.logger.error("URL of the image is empty")
                if not url.startswith('http'):
                    url = self._getAbsoluteUrl(url)
                self.logger.info(url)
                tabletService.showWebview(url)
            except Exception as err:
                self.logger.error("Error during ShowImage : %s " % err)
                self.onStopped()
        self.onStopped()