Ejemplo n.º 1
0
    def _phase_play_game(self):
        if self._game_over:
            return

        logging.debug('_phase_play_game, _client_start_time: ' +
                      str(self._client_start_time) + ' _game_number: ' +
                      str(self._game_number) + ' _player_number: ' +
                      str(self._player_number))

        while self._keep_running:
            self._user_input.get_input()
            messages = self._user_input.get_and_delete_messages()
            if messages != []:
                self._connection.send_message(
                    Messages.tick(self._tick_number, self._game_number,
                                  messages))

            self._connection.poll(0, 4)

            if self._tick_number + 2 in self._messages_on_tick:
                self._process_messages()
                sleep_time = Settings.TICK - (time.time() -
                                              self._last_tick_time)
                if sleep_time > 0.001:
                    time.sleep(sleep_time)
                self._last_tick_time = time.time()
                self._update_display()
                self._no_message_ticks = 0
                self._use_ai()
            else:
                self._no_message_ticks += 1
                if self._no_message_ticks > 5:
                    self._connection.send_message(
                        Messages.resend_tick(self._tick_number,
                                             self._game_number))
                    logging.debug('_no_message_ticks: ' +
                                  str(self._no_message_ticks) +
                                  ' _game_number: ' + str(self._game_number) +
                                  ' _player_number: ' +
                                  str(self._player_number) +
                                  ' _tick_number: ' + str(self._tick_number))
                if self._no_message_ticks > Settings.CLIENT_SECONDS_TO_WAIT / Settings.TICK:
                    self._game_over = True
                    logging.debug('no message tick game over, _game_number: ' +
                                  str(self._game_number) +
                                  ' _player_number: ' +
                                  str(self._player_number) +
                                  ' _tick_number: ' + str(self._tick_number))
                time.sleep((Settings.TICK / 2.0))

            if self._game_over:
                break

            self._connection.poll(Settings.TICK / 2.0, 2)

        logging.debug('_phase_play_game, _client_start_time: ' +
                      str(self._client_start_time) + ' _game_number: ' +
                      str(self._game_number) + ' _player_number: ' +
                      str(self._player_number) + ' _tick_number: ' +
                      str(self._tick_number))
Ejemplo n.º 2
0
    def _create_light_cycles(self):
        count = 0
        for key in self._connections:
            self._connection_to_cycle[key] = count
            self._connections[key].send_message(
                Messages.tick(0, self._game_number,
                              [Messages.player_number(count)]))
            self._message_resend_count[key] = 0
            self._light_cycles[count] = Light_cycle(None, count, True)
            self._light_cycles[count].set_location(
                Settings.CYCLE_LOCATIONS[count])
            self._light_cycles[count].set_direction(
                Settings.CYCLE_DIRECTIONS[count])
            count += 1

        for i in range(count, Settings.MATCHMAKER_MAXIMUM_PLAYERS):
            self._light_cycles[i] = Light_cycle(None, i, True)
            self._light_cycles[i].set_location(Settings.CYCLE_LOCATIONS[i])
            self._light_cycles[i].set_direction(Settings.CYCLE_DIRECTIONS[i])
            self._light_cycles[i].set_trail_on(None)
            self._light_cycles_ai[i] = Ai(True, self._light_cycles, i)

        for cycle in self._light_cycles.itervalues():
            cycle.move_tick(0)

        self._send_messages_for_tick()

        self._tick_number += 1
Ejemplo n.º 3
0
def removeKeymap():
    targetPath = _keymapTarget()
    if os.path.exists(targetPath):
        xbmcvfs.delete(targetPath)
    xbmc.executebuiltin("action(reloadkeymaps)")
    xbmcgui.Dialog().ok(Messages.get_msg(Messages.REMOVED),
                        Messages.get_msg(Messages.KEYMAP_REMOVED))
Ejemplo n.º 4
0
    def _use_ai(self):
        if not Settings.CLIENT_USE_AI:
            return
        if self._player_number not in self._light_cycles:
            return

        command = self._client_ai.tick(self._tick_number,
                                       self._ai_number_of_commands_received)

        if command == 'left':
            self._connection.send_message(
                Messages.tick(self._tick_number, self._game_number,
                              [Messages.player_input('left')]))
            return
        if command == 'double_left':
            self._connection.send_message(
                Messages.tick(self._tick_number, self._game_number, [
                    Messages.player_input('left'),
                    Messages.player_input('left')
                ]))
            return
        if command == 'right':
            self._connection.send_message(
                Messages.tick(self._tick_number, self._game_number,
                              [Messages.player_input('right')]))
            return
        if command == 'double_right':
            self._connection.send_message(
                Messages.tick(self._tick_number, self._game_number, [
                    Messages.player_input('right'),
                    Messages.player_input('right')
                ]))
            return
Ejemplo n.º 5
0
 def test_continuePrompt(self):
     with mock.patch('builtins.print') as fake_print, \
         mock.patch('builtins.input') as fake_input:
         Messages.continuePrompt("yes")
         fake_input.assert_called_once()
         fake_print.assert_called_once()
         fake_input.assert_called_with("yes")
Ejemplo n.º 6
0
    def getLinks(self):
        link_types = {}
        i = 0
        while i < len(self.app_data):
            store = False
            if re.search("^LINKS", self.app_data[i], re.IGNORECASE):
                self.app_data.pop(i)
                store = True
            while store:
                if re.search("^END LINKS", self.app_data[i], re.IGNORECASE):
                    self.app_data.pop(i)
                    store = False  #break out of inner loop
                    return link_types
                elif re.search("^\\bLINK\\b", self.app_data[i], re.IGNORECASE):
                    link = list(filter(None, self.app_data[i].split(" ")))

                    link_name = link[LinkType.LINK_NAME]

                    if link_name in link_types.keys():
                        error_msg = MessageCodes.ERROR_UNIQUE_PARAM_NAME
                        error_msg.setMsg(error_msg.msg %
                                         ("LINK-%s" % link_name,
                                          "LINKS \n\n%s" % self.app_data[i]))
                        Messages.showError(error_msg)

                    link_types[link_name] = LinkType(link)
                    self.app_data.pop(i)
                else:
                    self.app_data.pop(i)
            i += 1

        return link_types
Ejemplo n.º 7
0
    def test_showWarning(self):
        with mock.patch('builtins.print') as fake_print, \
            mock.patch.object(Messages, 'promptUser') as fake_prompt:

            Messages.showWarning(mock.Mock())
            fake_prompt.assert_called_once()
            assert fake_print.call_count == 3
Ejemplo n.º 8
0
    def select_backend(self):
        self._logger.enter()
        choices, current_choice_index = self.get_backend_choices()
        if current_choice_index < 0:
            current_choice_index = 0
        script_path = Constants.ADDON_PATH
        self._logger.debug_verbose('SettingsDialog ADDON_PATH: {}'.format(
            Constants.ADDON_PATH))
        selection_dialog = SelectionDialog('selection-dialog.xml',
                                           script_path,
                                           'Default',
                                           title=Messages.get_msg(
                                               Messages.SELECT_SPEECH_ENGINE),
                                           choices=choices,
                                           initial_choice=current_choice_index)

        selection_dialog.show()
        selection_dialog.doModal()
        idx = selection_dialog.getCurrentListPosition()
        self._logger.debug_verbose('SelectionDialog value:',
                                   Messages.get_msg(Messages.CHOOSE_BACKEND),
                                   'idx:', str(idx))
        if idx < 0:
            return None

        engine = choices[idx]
        self._logger.debug_verbose('select_backend value: {} idx: {}'.format(
            engine.getLabel(), str(idx)))

        self.engine_engine_value.setLabel(engine.getLabel())
        new_backend = engine.getLabel2()
        if new_backend != self.previous_backend:
            self.set_backend(new_backend)
Ejemplo n.º 9
0
    def getMonitoredText(self,
                         isSpeaking=False
                         ):  #getLabel() Doesn't work currently with FadeLabels
        if self._visible: return None
        if not addoninfo.checkForNewVersions(): return None
        details = addoninfo.getUpdatedAddons()
        if not details: return None
        ret = ['{0}... '.format(Messages.get_msg(Messages.ADDONS_UPDATED))]
        for d in details:
            item = '{0} {1} {2}'.format(d['name'],
                                        Messages.get_msg(Messages.VERSION),
                                        d['version'])
            if not item in ret:
                ret.append(item)
        #print ret
        return ret


#        #print 'x'
#        heading = self.win.getControl(401).getLabel()
#        message = self.win.getControl(402).getLabel()
#        #print repr(message)
#        self.addNotice(heading,message)
#        if not isSpeaking: return self.takeNoticesForSpeech()
#        return None

#class NoticeDialogReader(NoticeHandler,WindowReaderBase): pass
Ejemplo n.º 10
0
 def checkBuild(self):
     if self.build > Constants.CURRENT_BUILD:
         Messages.showError(MessageCodes.ERROR_LATER_VERSION)
     elif self.build < Constants.CURRENT_BUILD:
         Messages.showWarning(MessageCodes.WARNING_EARLIER_VERSION)
     else:
         #build number and file being run are compatible
         pass
Ejemplo n.º 11
0
 def getSettingControlText(self, controlID):
     text = xbmc.getInfoLabel('System.CurrentControl')
     if text.endswith(')'):  #Skip this most of the time
         text = text.replace('( )', '{0} {1}'.format(
             self.service.tts.pauseInsert,
             Messages.get_msg(Messages.NO)).replace(
                 '(*)', '{0} {1}'.format(
                     self.service.tts.pauseInsert,
                     Messages.get_msg(
                         Messages.YES))))  #For boolean settings
     return text
Ejemplo n.º 12
0
    def getSpanLinks(self, props, build):
        links = []
        if (build < Constants.CURRENT_BUILD):
            return links
        try:
            links = props[Span.SPAN_LINKS]
        except KeyError:
            warning = MessageCodes.WARNING_NO_LINKS
            warning.setMsg(warning.msg%(self.beam_name, self.name))
            Messages.showWarning(warning)

        return links
Ejemplo n.º 13
0
Archivo: dxf.py Proyecto: itrevex/adds
 def addDimEntity(self, dim):
     '''
     add dimesion
     '''
     if SHOW_DIMENSIONS:
         layer = self.getLayer(dim.layer)
         Messages.d("dxf.py", dim.points, dim.starting_point, dim.angle)
         dimline = LinearDimension(dim.starting_point,
                                   dim.points,
                                   dim.angle,
                                   layer=layer)
         dimline.render(self.msp)
Ejemplo n.º 14
0
 def getControlText(self,controlID):
     if self.slideoutHasFocus():
         return self.getSlideoutText(controlID)
     if not controlID: return ('','')
     text = xbmc.getInfoLabel('ListItem.Label')
     if not text: return base.DefaultWindowReader.getControlText(self,controlID)
     status = ''
     if xbmc.getCondVisibility('ListItem.IsResumable'):
         status = ': {0}'.format(Messages.get_msg(Messages.RESUMABLE))
     else:
         if xbmc.getInfoLabel('ListItem.Overlay') == 'OverlayWatched.png':
             status = ': {0}'.format(Messages.get_msg(Messages.WATCHED))
     return ('{0}{1}'.format(text,status),text)
Ejemplo n.º 15
0
 def getControlPostfix(
     self,
     controlID,
 ):
     if not self.service.speakListCount:
         return ''
     numItems = xbmc.getInfoLabel('Container({0}).NumItems'.format(
         self.service.controlID))
     if numItems:
         return '... {0} {1}'.format(
             numItems, numItems != '1' and Messages.get_msg(Messages.ITEMS)
             or Messages.get_msg(Messages.ITEM))
     return ''
Ejemplo n.º 16
0
    def record_played_trailer(self, trailer, use_movie_path=False, msg=''):
        # type: (Dict[str, Any], bool, str) -> None
        """

        :param trailer:
        :param use_movie_path:
        :param msg:
        :return:
        """
        if self.playlist_format:
            use_movie_path = True

        name = trailer.get(Movie.TITLE, 'unknown Title')
        year = '(' + str(trailer.get(Movie.YEAR, 'unknown Year')) + ')'
        movie_type = trailer.get(Movie.TYPE, 'Unknown MovieType')
        movie_path = trailer.get(Movie.FILE, None)
        if movie_path is None:
            if use_movie_path:  # Nothing to do if there is no movie path
                return
            movie_path = 'Unknown movie path'
        trailer_path = trailer.get(Movie.TRAILER, '')
        cache_path_prefix = Settings.get_downloaded_trailer_cache_path()
        trailer_path = trailer_path.replace(cache_path_prefix, '<cache_path>')
        missing_detail_msg = Messages.get_msg(Messages.MISSING_DETAIL)
        if trailer_path == missing_detail_msg:
            trailer_path = ''
        if name is None:
            name = 'name is None'
        if year is None:
            year = 'year is None'
        if movie_type is None:
            movie_type = 'movie_type is None'

        path = trailer_path
        if use_movie_path:
            path = movie_path

        formatted_title = Messages.get_formated_title(trailer)

        with Playlist._playlist_lock:
            # file closed
            if self._file is None:
                return

        if self.playlist_format:
            line = Playlist.PLAYLIST_ENTRY_PREFIX + name + '\n'
            line += path + '\n'
        else:
            line = name + '  ' + year + '  # path: ' + formatted_title + ' ' +\
                path + ' ' + msg + '\n'
        self._file.writelines(line)
Ejemplo n.º 17
0
 def getControlText(self, controlID):
     ID = self.window().getFocusId()
     if ID == 9:
         text = xbmc.getLocalizedString(19133)
     else:
         text = xbmc.getInfoLabel('System.CurrentControl')
         text = text.replace(
             '( )', '{0} {1}'.format(
                 self.service.tts.pauseInsert, Messages.get_msg(
                     Messages.NO))).replace('(*)', '{0} {1}'.format(
                         self.service.tts.pauseInsert,
                         Messages.get_msg(
                             Messages.YES)))  # For boolean settings
     return (text, text)
Ejemplo n.º 18
0
    def setTitle(self):
        if self.title: return
        tail = utils.tailXBMCLog()
        for t in reversed(tail):
            l = t.lower()
            if 'thread epgupdater start' in l:
                self.title = Messages.get_msg(Messages.IMPORTING_PVR_EPG)
                return
            elif 'thread pvrguiinfo start' in l:
                self.title = Messages.get_msg(Messages.LOADING_PVR_EPG)
                return

        if self.progress:
            self.title = Messages.get_msg(Messages.BACKGROUND_PROGRESS_STARTED)
Ejemplo n.º 19
0
 def fallbackTTS(self, reason=None):
     if reason == 'RESET':
         return resetAddon()
     backend = backends.getBackendFallback()
     module_logger.info('Backend falling back to: {0}'.format(
         backend.provider))
     self.initTTS(backend)
     self.sayText(Messages.get_msg(
         Messages.SPEECH_ENGINE_FALLING_BACK_TO).format(
             backend.displayName),
                  interrupt=True)
     if reason:
         self.sayText('{0}: {1}'.format(Messages.get_msg(Messages.Reason),
                                        reason),
                      interrupt=False)
Ejemplo n.º 20
0
    def getSectionRight(self, props):
        section = ""
        try:
           section = props[Span.SPAN_SECTION_RIGHT]
        except KeyError:
            try:
                section = props[Span.SPAN_SECTION_LEFT]
            except:
                try:
                    section = props[Span.SPAN_SECTION]
                except:
                    Messages.showError(MessageCodes.ERROR_NO_BEAM_SECTIONS)


        return section
Ejemplo n.º 21
0
class PVRWindowReader(PVRWindowReaderBase):
    ID = 'pvr'
    timelineInfo = (Messages.get_msg(Messages.CHANNEL),
                        '$INFO[ListItem.ChannelNumber]',
                        '$INFO[ListItem.ChannelName]',
                        '$INFO[ListItem.StartTime]',
                        19160,
                        '$INFO[ListItem.EndTime]',
                        '$INFO[ListItem.Plot]'
    )

    channelInfo = (    '$INFO[ListItem.StartTime]',
                        19160,
                        '$INFO[ListItem.EndTime]',
                        '$INFO[ListItem.Plot]'
    )

    nowNextInfo = (Messages.get_msg(Messages.CHANNEL),
                        '$INFO[ListItem.ChannelNumber]',
                        '$INFO[ListItem.ChannelName]',
                        '$INFO[ListItem.StartTime]',
                        '$INFO[ListItem.Plot]'
    )

    def controlIsOnView(self,controlID):
        return controlID > 9 and controlID < 18

    def getControlText(self,controlID):
        if not controlID: return ('','')
        text = None
        if controlID == 11 or controlID == 12: #Channel (TV or Radio)
            text = '{0}... {1}... {2}'.format(xbmc.getInfoLabel('ListItem.ChannelNumber'),xbmc.getInfoLabel('ListItem.Label'),xbmc.getInfoLabel('ListItem.Title'))
        else:
            text = xbmc.getInfoLabel('System.CurrentControl')
        if not text: return ('','')
        compare = text + xbmc.getInfoLabel('ListItem.StartTime') + xbmc.getInfoLabel('ListItem.EndTime')
        return (text,compare)

    def getItemExtraTexts(self,controlID):
        text = None
        if self.controlIsOnView(controlID):
            if controlID == 10: #EPG: Timeline
                text = guitables.convertTexts(self.winID,self.timelineInfo)
            elif controlID == 11 or controlID == 12: #Channel (TV or Radio)
                text = guitables.convertTexts(self.winID,self.channelInfo)
            elif controlID == 16: #EPG: Now/Next
                text = guitables.convertTexts(self.winID,self.nowNextInfo)
        return text
Ejemplo n.º 22
0
    def select_voice(self):
        choices, current_choice_index = self.get_voice_choices()
        script_path = Constants.ADDON_PATH
        selection_dialog = SelectionDialog('selection-dialog.xml',
                                           script_path,
                                           'Default',
                                           title=Messages.get_msg(
                                               Messages.SELECT_VOICE),
                                           choices=choices,
                                           initial_choice=current_choice_index)

        selection_dialog.show()
        selection_dialog.doModal()
        idx = selection_dialog.getCurrentListPosition()
        self._logger.debug_verbose('SelectionDialog voice idx: {}'.format(
            str(idx)))
        if idx < 0:
            return

        voice = choices[idx].getLabel()
        voice_id = choices[idx].getLabel2()
        self._logger.debug_verbose(
            'select_voice value: {} setting: {} idx: {:d}'.format(
                voice, voice_id, idx))

        self.engine_voice_value.setLabel(voice)
        self.setSetting(Settings.VOICE, voice_id)
Ejemplo n.º 23
0
    def checkWindow(self, newN):
        winID = xbmcgui.getCurrentWindowId()
        dialogID = xbmcgui.getCurrentWindowDialogId()
        if dialogID != 9999:
            winID = dialogID
        if winID == self.winID:
            return newN
        self.winID = winID
        self.updateWindowReader()
        if module_logger.isEnabledFor(LazyLogger.DEBUG):
            module_logger.debug('Window ID: {0} Handler: {1} File: {2}'.format(
                winID, self.windowReader.ID,
                xbmc.getInfoLabel('Window.Property(xmlfile)')))

        name = self.windowReader.getName()
        if name:
            self.sayText('{0}: {1}'.format(Messages.get_msg(Messages.WINDOW),
                                           name),
                         interrupt=not newN)
            self.insertPause()
        else:
            self.sayText(' ', interrupt=not newN)

        heading = self.windowReader.getHeading()
        if heading:
            self.sayText(heading)
            self.insertPause()

        texts = self.windowReader.getWindowTexts()
        if texts:
            self.insertPause()
            for t in texts:
                self.sayText(t)
                self.insertPause()
        return True
Ejemplo n.º 24
0
    def checkNewVersion(self):
        try:
            # Fails on Helix beta 1 on OpenElec #1103
            from distutils.version import LooseVersion
        except ImportError:

            def LooseVersion(v):
                comp = [int(x) for x in re.split(r'a|b', v)[0].split(".")]
                fourth = 2
                fifth = 0
                if 'b' in v:
                    fourth = 1
                    fifth = int(v.split('b')[-1] or 0)
                elif 'a' in 'v':
                    fourth = 0
                    fifth = int(v.split('a')[-1] or 0)
                comp.append(fourth)
                comp.append(fifth)
                return comp

        lastVersion = Settings.getSetting('version', '0.0.0')
        Settings.setSetting(Settings.VERSION, __version__)

        if lastVersion == '0.0.0':
            self.firstRun()
            return True
        elif LooseVersion(lastVersion) < LooseVersion(__version__):
            self.queueNotice('{0}... {1}'.format(
                Messages.get_msg(Messages.NEW_TTS_VERSION), __version__))
            return True
        return False
Ejemplo n.º 25
0
    def showWarning(self, pt2, pt4, pt3, pt6, pt7, pt8, left_section,
                    right_section):
        #check to see if left section is deeper than beam
        if pt2[EntityLine.Y] > pt4[EntityLine.Y] or \
            pt3[EntityLine.Y] > pt4[EntityLine.Y]:

            warning = MessageCodes.WARNING_DEEPER_SECTION
            warning.setMsg(warning.msg % (left_section.name))
            Messages.w(warning)

        #check to see if right section is deeper than beam
        if pt6[EntityLine.Y] > pt8[EntityLine.Y] or \
            pt7[EntityLine.Y] > pt8[EntityLine.Y]:
            warning = MessageCodes.WARNING_DEEPER_SECTION
            warning.setMsg(warning.msg % (right_section.name))
            Messages.w(warning)
    def get_label(self) -> str:
        """
            Gets translated label for the genre

        :return:
        """
        return Messages.get_msg(self._translatable_label_id)
Ejemplo n.º 27
0
 def getControlText(self, controlID):
     if not controlID: return ('', '')
     sub = ''
     text = self.getSettingControlText(controlID)
     if text.startswith('-'):
         sub = '{0}: '.format(Messages.get_msg(Messages.SUB_SETTING))
     return ('{0}{1}'.format(sub, text), text)
Ejemplo n.º 28
0
    def select_player(self):
        (choices, current_choice_index) = self.get_player_choices()
        script_path = Constants.ADDON_PATH
        selection_dialog = SelectionDialog('selection-dialog.xml',
                                           script_path,
                                           'Default',
                                           title=Messages.get_msg(
                                               Messages.SELECT_VOICE_GENDER),
                                           choices=choices,
                                           initial_choice=current_choice_index)

        selection_dialog.show()
        selection_dialog.doModal()
        idx = selection_dialog.getCurrentListPosition()
        if idx < 0:
            return

        player_label = choices[idx].getLabel()
        player_id = choices[idx].getLabel2()
        self._logger.debug_verbose(
            'select_player value: {} setting: {} idx: {:d}'.format(
                player_label, player_id, idx))

        self.engine_player_value.setLabel(player_label)
        self.set_player(player_id)
Ejemplo n.º 29
0
    def select_gender(self):
        (choices, current_choice_index) = self.get_gender_choices()
        script_path = Constants.ADDON_PATH
        # xbmc.executebuiltin('Skin.ToggleDebug')

        selection_dialog = SelectionDialog('selection-dialog.xml',
                                           script_path,
                                           'Default',
                                           title=Messages.get_msg(
                                               Messages.SELECT_VOICE_GENDER),
                                           choices=choices,
                                           initial_choice=current_choice_index)

        selection_dialog.show()
        selection_dialog.doModal()
        idx = selection_dialog.getCurrentListPosition()
        if idx < 0:
            return

        gender_id = choices[idx]
        gender_label = Genders.get_label(gender_id)
        self._logger.debug_verbose(
            'select_gender value: {} setting: {} idx: {:d}'.format(
                gender_label, gender_id, idx))

        self.engine_gender_value.setLabel(gender_label)
        self.setSetting(Settings.GENDER, gender_id)
Ejemplo n.º 30
0
 def getControlText(self, controlID):
     label = xbmc.getInfoLabel('System.CurrentControl')
     selected = xbmc.getCondVisibility(
         'Container({0}).ListItem.IsSelected'.format(controlID)
     ) and ': {0}'.format(Messages.get_msg(Messages.SELECTED)) or ''
     text = '{0}{1}'.format(label, selected)
     return (text, text)