在 Pepper 的平板电脑上加载 Url
Load Url on Pepper's Tablet
我正在尝试在 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()
如果您想显示网页,请考虑改用方框 "Show Web View"。我发现 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()
我正在尝试在 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()
如果您想显示网页,请考虑改用方框 "Show Web View"。我发现 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()