Exemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     self.main_window = kwargs.pop("main_window", None)
     self.player = Player()
     self.api = self.main_window.api
     self.skip_secs = self.prev_skip_secs = 0
     super(TvDialog, self).__init__(**kwargs)
Exemplo n.º 2
0
class TvDialog(xbmcgui.WindowXMLDialog, WindowMixin):
    CTRL_DUMMY = 999
    CTRL_PROGRAM_TITLE = 4000
    CTRL_PROGRAM_PLAYTIME = 4001
    CTRL_PROGRESS = 4002
    CTRL_SLIDER = 4003
    CTRL_PROGRAM_DURATION = 4004
    CTRL_SKIP_PLAYBACK = 4005
    CTRL_PROGRAM_STARTTIME = 4006
    CTRL_SLIDER_BUTTON = 4007
    CTRL_PROGRAM_CHANNEL_ICON = 4008
    CTRL_DUMMY_ICON = 4009
    CTRL_GROUPS = 4100
    CTRL_CHANNELS = 4200
    CTRL_PROGRAMS = 4300

    ICON_OPEN = "open"
    ICON_CLOSE = "close"
    ICON_ERROR = "error"
    ICON_PLAY = "play"
    ICON_NONPLAY = "nonplay"
    ICON_END = "end"
    ICON_STOP = "stop"
    ICON_SWING = "swing"

    WINDOW_HOME = 10000
    WINDOW_FULLSCREEN_VIDEO = 12005

    ctrl_program_title = None  # type: ControlLabel
    ctrl_program_playtime = None  # type: ControlLabel
    ctrl_program_channel_icon = None  # type: ControlImage
    ctrl_dummy_icon = None  # type: ControlImage
    ctrl_progress = None  # type: ControlProgress
    ctrl_slider = None  # type: ControlSlider
    ctrl_program_duration = None  # type: ControlLabel
    ctrl_skip_playback = None  # type: ControlLabel
    ctrl_program_starttime = None  # type: ControlLabel
    ctrl_groups = None  # type: ControlList
    ctrl_channels = None  # type: ControlList
    ctrl_programs = None  # type: ControlList

    main_window = None
    player = None  # type: Player
    api = None  # type: Api
    skip_secs = None  # type: int
    prev_skip_secs = None  # type: int
    prev_focused_id = None  # type: int
    playback_info_program = None  # type: Program

    timer_refocus = None  # type: Timer
    timer_slider_update = None  # type: Timer
    timer_skip_playback = None  # type: Timer
    timer_load_program_list = None  # type: Timer
    timer_idle = None  # type: Timer

    is_closing = False  # type: bool

    def __init__(self, *args, **kwargs):
        self.main_window = kwargs.pop("main_window", None)
        self.player = Player()
        self.api = self.main_window.api
        self.skip_secs = self.prev_skip_secs = 0
        super(TvDialog, self).__init__(**kwargs)

    @property
    def addon_id(self):
        return "%s:%s" % (self.api.__class__.__name__, addon.getAddonInfo('version'))

    def close(self):
        if self.is_closing:
            return
        self.is_closing = True

        self.preload_icon(self.ICON_CLOSE, self.addon_id)

        if self.timer_refocus:
            self.timer_refocus.cancel()
        del self.timer_refocus

        if self.timer_slider_update:
            self.timer_slider_update.cancel()
            del self.timer_slider_update

        if self.timer_skip_playback:
            self.timer_skip_playback.cancel()
            del self.timer_skip_playback

        if self.player.isPlaying():
            self.player.stop()
        del self.player

        if self.timer_load_program_list:
            self.timer_load_program_list.cancel()
            del self.timer_load_program_list

        if self.timer_idle:
            self.timer_idle.cancel()
            del self.timer_idle

        super(TvDialog, self).close()

    def onInit(self):
        try:
            self.ctrl_program_title = self.getControl(self.CTRL_PROGRAM_TITLE)
            self.ctrl_program_playtime = self.getControl(self.CTRL_PROGRAM_PLAYTIME)
            self.ctrl_program_channel_icon = self.getControl(self.CTRL_PROGRAM_CHANNEL_ICON)
            self.ctrl_dummy_icon = self.getControl(self.CTRL_DUMMY_ICON)
            self.ctrl_progress = self.getControl(self.CTRL_PROGRESS)
            self.ctrl_slider = self.getControl(self.CTRL_SLIDER)
            self.ctrl_program_duration = self.getControl(self.CTRL_PROGRAM_DURATION)
            self.ctrl_skip_playback = self.getControl(self.CTRL_SKIP_PLAYBACK)
            self.ctrl_program_starttime = self.getControl(self.CTRL_PROGRAM_STARTTIME)
            self.ctrl_groups = self.getControl(self.CTRL_GROUPS)
            self.ctrl_channels = self.getControl(self.CTRL_CHANNELS)
            self.ctrl_programs = self.getControl(self.CTRL_PROGRAMS)

            self.defer_refocus_window()
            self.preload_icon(self.ICON_OPEN, self.addon_id)

            program = Program.factory(self.get_last_played_channel())
            self.play_program(program)
            self.load_lists()
            self.reset_idle_timer()
        except ApiException, ex:
            log("Exception %s: message=%s" % (type(ex), ex.message))
            log(traceback.format_exc(), xbmc.LOGDEBUG)
            dialog = xbmcgui.Dialog()
            if ex.code == Api.E_API_ERROR:
                dialog.ok(
                    addon.getAddonInfo("name"),
                    get_string(TEXT_SERVICE_ERROR_OCCURRED_ID) + ":",
                    ex.message
                )
            elif ex.code == Api.E_HTTP_REQUEST_FAILED:
                error = ex.message
                if "Errno 8" in ex.message:
                    error = get_string(TEXT_PLEASE_CHECK_INTERNET_CONNECTION_ID)
                dialog.ok(
                    addon.getAddonInfo("name"),
                    get_string(TEXT_HTTP_REQUEST_ERROR_ID) + ":",
                    error
                )
            elif ex.code == Api.E_JSON_DECODE:
                dialog.ok(
                    addon.getAddonInfo("name"),
                    get_string(TEXT_UNEXPECTED_RESPONSE_FROM_SERVICE_PROVIDER_ID) + ":",
                    ex.message
                )
            else:
                dialog.ok(
                    addon.getAddonInfo("name"),
                    get_string(TEXT_UNEXPECTED_ERROR_OCCURRED_ID) + ":",
                    ex.message
                )
            self.main_window.close()
        except Exception, ex:
            self.preload_icon(self.ICON_ERROR, quote(ex.message.encode('utf-8')))
            log("Exception %s: message=%s" % (type(ex), ex.message))
            log(traceback.format_exc(), xbmc.LOGDEBUG)
            line1, line2 = (ex.message + "\n").split("\n", 1)
            dialog = xbmcgui.Dialog()
            dialog.ok(
                addon.getAddonInfo("name"),
                get_string(TEXT_UNEXPECTED_ERROR_OCCURRED_ID) + ":",
                line1,
                line2
            )
            self.main_window.close()