示例#1
0
class TwitchChannelDetails(Screen):
	TMP_BANNER_FILE_PATH = "/tmp/twitch_channel_banner.jpg"

	def __init__(self, session, stream=None, channel=None):
		Screen.__init__(self, session, windowTitle=_("TwitchTV - Channel Details"))

		self.twitch = Twitch()
		self.twitchMiddleware = TwitchMiddleware.instance
		self.stream = stream
		self.channel = channel or stream.channel
		self.setTitle(_("TwitchTV - %s") %(self.channel.name,))
		self.is_online = False
		self.is_live = self.stream and self.stream.type == TwitchStream.TYPE_LIVE

		self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
		{
			"cancel": self.close,
			"red": self.addToFav,
			"green": self.startLive,
			"blue": self.getChannelDetails,
			"yellow": self.getChannelVideos
		}, -1)

		self["key_red"] = StaticText(_("Add to Fav"))
		self["key_green"] = StaticText(_("Watch Live"))
		self["key_yellow"] = StaticText(_("Videos"))
		self["key_blue"] = StaticText(_("Refresh"))

		self["channel_name"] = StaticText()
		self["channel_status"] = StaticText()
		self["channel_game"] = StaticText()
		self["channel_viewers"] = StaticText()

		self._banner = Pixmap()
		self["banner"] = self._banner

		self._cachingDeferred = None
		self._picload = ePicLoad()
		self._picload.setPara((1000, 480, 0, 0, False, 0, '#ffff0000'))
		self._picload_conn = self._picload.PictureData.connect(self._onBannerReady)

		if self.channel.banner and self.stream:
			self.showChannelDetails()
		else:
			if self.channel.banner:
				self.checkLiveStream()
			else:
				self.getChannelDetails()

		self.onClose.append(self.__onClose)

	def __onClose(self):
		if self._cachingDeferred:
			Log.w("Cancelling pending image download...")
			self._cachingDeferred.cancel()
		self._picload_conn = None
		self._picload = None

	def addToFav(self):
		self.twitchMiddleware.addToFavorites(self.channel)

	def startLive(self):
		self.twitchMiddleware.watchLivestream(self.session, self.channel)

	def showChannelDetails(self, isvod=False):
		if self.is_live:
			if isvod:
				self["channel_name"].setText(self.channel_name + _(" (Live VOD)"))
			else:
				self["channel_name"].setText(self.channel.display_name)
		else:
			self["channel_name"].setText(self.channel.display_name + " " + _("is currently offline"))
		self["channel_status"].setText(self.channel.status)
		self["channel_game"].setText(self.channel.game)
		if self.stream:
			self["channel_viewers"].setText(_("Viewers: %s") %(self.stream.viewers,))
		else:
			self["channel_viewers"].setText("")

		if self.channel.banner:
			self.getBanner()

	def getBanner(self):
		Log.i(self.channel.banner)
		if self.channel.banner:
			self._cachingDeferred = downloadPage(self.channel.banner, self.TMP_BANNER_FILE_PATH).addCallbacks(self._onBannerLoadFinished, self._onBannerError)

	def _onBannerLoadFinished(self, *args):
		self._cachingDeferred = None
		self._picload.startDecode(self.TMP_BANNER_FILE_PATH)

	def _onBannerError(self, *args):
		self._cachingDeferred = None
		Log.w(args)

	def _onBannerReady(self, info):
		pixmap = self._picload.getData()
		self._banner.setPixmap(pixmap)

	def getChannelDetails(self):
		self["channel_name"].setText("loading ...")
		self["channel_status"].setText("")
		self["channel_game"].setText("")
		self["channel_viewers"].setText("")
		self.twitch.channelDetails(self.channel.id, self._onChannelDetails)

	def _onChannelDetails(self, channel):
		if not channel:
			return
		self.channel = channel
		self.getBanner()
		self.checkLiveStream()

	def checkLiveStream(self):
		self.twitch.liveStreamDetails(self.channel.id, self._onLiveStreamDetails)

	def _onLiveStreamDetails(self, stream):
		isvod = False
		self.is_live = False
		if not stream:
			self["channel_viewers"].setText("")
		else:
			self.is_live = True
			self.stream = stream
			isvod = self.stream.type != TwitchStream.TYPE_LIVE
		self.showChannelDetails(isvod)

	def getChannelVideos(self):
		self.session.open(TwitchChannelVideos, self.channel)
示例#2
0
文件: plugin.py 项目: OpenDMM/enigma2
class RemoteControlSelection(Screen):
	SKIN_DEFAULT = "skin_default"

	skin = """
		<screen name="RemoteControlSelection" position="center,80" size="420,610" title="RemoteControlSelection" >
			<widget name="rc" pixmap="skin_default/rc0.png" position="20,10" size="380,500" alphatest="on"/>
			<widget name="color_hint" position="10,520" size="400,50" font="Regular;18" halign="center" valign="center" backgroundColor="background" transparent="0" />
			<widget name="ok" position="10,580" size="400,24" font="Regular;22" halign="center" valign="center" backgroundColor="background" transparent="0" />
		</screen>
	"""

	def __init__(self, session):
		Screen.__init__(self, session)

		self["color_hint"] = Label(_("Some Remotes may exist in other Colors"))
		self["ok"] = Label(_("Press OK to apply"))

		self._pixmap = Pixmap()
		self["rc"] = self._pixmap

		self["actions"] = ActionMap(["DirectionActions", "OkCancelActions"],
			{
				"ok": self._ok,
				"cancel": self._cancel,
				"right": self._next,
				"left": self._prev,
			})

		self._pixmaps = []
		for i in (0, 1, 2):
			self._pixmaps.append(
				LoadPixmap(
					resolveFilename(SCOPE_SKIN, "skin_default/rc%s.png" % (i))
				)
			)

		self._index = -1
		self.onFirstExecBegin.append(self._firstExecBegin)

	def _firstExecBegin(self):
		self.setTitle(_("Select your Remote"))
		self.setCurrentPixmap(config.misc.rcused.value)

	def _ok(self):
		config.misc.rcused.value = self._index
		config.misc.rcused.save()
		Log.i("RC is now set to Model %s" %(config.misc.rcused.value))
		self.close()

	def _cancel(self):
		self.close()

	def setCurrentPixmap(self, index):
		if index > 2:
			index = 0
		if index < 0:
			index = 2
		self._index = index
		self._pixmap.setPixmap(self._pixmaps[index])

	def _next(self):
		self._pixmap.setShowHideAnimation("slide_right_to_left")
		self.setCurrentPixmap(self._index + 1)

	def _prev(self):
		self._pixmap.setShowHideAnimation("slide_left_to_right")
		self.setCurrentPixmap(self._index - 1)
示例#3
0
class RemoteControlSelection(Screen):
    SKIN_DEFAULT = "skin_default"

    skin = """
		<screen name="RemoteControlSelection" position="center,80" size="420,610" title="RemoteControlSelection" >
			<widget name="rc" pixmap="skin_default/rc0.png" position="20,10" size="380,500" alphatest="on"/>
			<widget name="color_hint" position="10,520" size="400,50" font="Regular;18" halign="center" valign="center" backgroundColor="background" transparent="0" />
			<widget name="ok" position="10,580" size="400,24" font="Regular;22" halign="center" valign="center" backgroundColor="background" transparent="0" />
		</screen>
	"""

    def __init__(self, session):
        Screen.__init__(self, session)

        self["color_hint"] = Label(_("Some Remotes may exist in other Colors"))
        self["ok"] = Label(_("Press OK to apply"))

        self._pixmap = Pixmap()
        self["rc"] = self._pixmap

        self["actions"] = ActionMap(
            ["DirectionActions", "OkCancelActions"], {
                "ok": self._ok,
                "cancel": self._cancel,
                "right": self._next,
                "left": self._prev,
            })

        self._pixmaps = []
        for i in (0, 1, 2, 3):
            self._pixmaps.append(
                LoadPixmap(
                    resolveFilename(SCOPE_SKIN,
                                    "skin_default/rc%s.png" % (i))))

        self._index = -1
        self.onFirstExecBegin.append(self._firstExecBegin)

    def _firstExecBegin(self):
        self.setTitle(_("Select your Remote"))
        self.setCurrentPixmap(config.misc.rcused.value)

    def _ok(self):
        config.misc.rcused.value = self._index
        config.misc.rcused.save()
        Log.i("RC is now set to Model %s" % (config.misc.rcused.value))
        self.close()

    def _cancel(self):
        self.close()

    def setCurrentPixmap(self, index):
        if index > 3:
            index = 0
        if index < 0:
            index = 3
        self._index = index
        self._pixmap.setPixmap(self._pixmaps[index])

    def _next(self):
        self._pixmap.setShowHideAnimation("slide_right_to_left")
        self.setCurrentPixmap(self._index + 1)

    def _prev(self):
        self._pixmap.setShowHideAnimation("slide_left_to_right")
        self.setCurrentPixmap(self._index - 1)