Esempio n. 1
0
 def start(self):
     self.__loadHintsData()
     if self._data.hintsCount == 0:
         return False
     self._gui = HintsProxy()
     self._gui.init()
     self._gui.loadConfig(self._data.getGuiFilePath())
     self._gui.onHintClicked += self.__onGUIInput
     self._gui.onHintItemFound += self.__onItemFound
     self._gui.onHintItemLost += self.__onItemLost
     return True
 def start(self):
     self.__loadHintsData()
     if self._data.getHintsCount() == 0:
         return False
     else:
         self.__hintsWithClientTriggers = None
         self._gui = HintsProxy()
         self._gui.onGUILoaded += self.__onGUILoaded
         self._gui.onHintClicked += self.__onGUIInput
         self._gui.onHintItemFound += self.__onItemFound
         self._gui.onHintItemLost += self.__onItemLost
         self._gui.onVisibleChanged += self.__onItemVisibleChanged
         self._gui.onEnabledChanged += self.__onItemEnabledChanged
         self.__startSettingsListening()
         self._gui.loadConfig(self._data.getGuiFilePath())
         self._gui.init()
         return True
Esempio n. 3
0
 def start(self):
     self.__loadHintsData()
     if self._data.hintsCount == 0:
         return False
     self._gui = HintsProxy()
     self._gui.init()
     self._gui.loadConfig(self._data.getGuiFilePath())
     self._gui.onHintClicked += self.__onGUIInput
     self._gui.onHintItemFound += self.__onItemFound
     self._gui.onHintItemLost += self.__onItemLost
     return True
Esempio n. 4
0
class HintsManager(object):

    def __init__(self):
        super(HintsManager, self).__init__()
        self._data = None
        self._gui = None
        self.__activeHints = {}
        return

    def start(self):
        self.__loadHintsData()
        if self._data.hintsCount == 0:
            return False
        self._gui = HintsProxy()
        self._gui.init()
        self._gui.loadConfig(self._data.getGuiFilePath())
        self._gui.onHintClicked += self.__onGUIInput
        self._gui.onHintItemFound += self.__onItemFound
        self._gui.onHintItemLost += self.__onItemLost
        return True

    def stop(self):
        if self._data is not None:
            self._data = None
        for itemID in self.__activeHints.keys():
            self.__hideHint(itemID)

        if self._gui is not None:
            self._gui.fini()
        self._gui = None
        return

    def __loadHintsData(self):
        LOG_DEBUG('Hints are loading')
        shownHints = g_settingsCore.serverSettings.getOnceOnlyHintsSettings()
        shownHints = [ key for key, value in shownHints.iteritems() if value == 1 ]
        self._data = HintsParser.parse(_DESCRIPTOR_PATH, shownHints)

    def __showHint(self, hint):
        text = hint['text']
        uniqueID = hintID = hint['hintID']
        props = HintProps(uniqueID, hintID, hint['itemID'], text, True, hint['arrow'], None)
        self._gui.showHint(props)
        self.__activeHints[hint['itemID']] = hint
        return

    def __hideHint(self, itemID):
        if itemID in self.__activeHints:
            hint = self.__activeHints[itemID]
            self._gui.hideHint(hint['hintID'])
            del self.__activeHints[itemID]

    def __onGUIInput(self, event):
        itemID = event.getTargetID()
        if itemID in self.__activeHints:
            hint = self.__activeHints[itemID]
            self.__hideHint(itemID)
            self._data.markAsShown(hint)
            g_settingsCore.serverSettings.setOnceOnlyHintsSettings({hint['hintID']: 1})
            if self._data.hintsCount == 0:
                self.stop()

    def __onItemFound(self, itemID):
        hint = self._data.hintForItem(itemID)
        if hint is not None and itemID not in self.__activeHints:
            self.__showHint(hint)
        return

    def __onItemLost(self, itemID):
        if itemID in self.__activeHints:
            self.__hideHint(itemID)
class HintsManager(object):
    __settingsCore = dependency.descriptor(ISettingsCore)
    __slots__ = ('_data', '_gui', '__activeHints', '__hintsWithClientTriggers')

    def __init__(self):
        super(HintsManager, self).__init__()
        self._data = None
        self._gui = None
        self.__activeHints = {}
        self.__hintsWithClientTriggers = None
        return

    def start(self):
        self.__loadHintsData()
        if self._data.getHintsCount() == 0:
            return False
        else:
            self.__hintsWithClientTriggers = None
            self._gui = HintsProxy()
            self._gui.onGUILoaded += self.__onGUILoaded
            self._gui.onHintClicked += self.__onGUIInput
            self._gui.onHintItemFound += self.__onItemFound
            self._gui.onHintItemLost += self.__onItemLost
            self._gui.onVisibleChanged += self.__onItemVisibleChanged
            self._gui.onEnabledChanged += self.__onItemEnabledChanged
            self.__startSettingsListening()
            self._gui.loadConfig(self._data.getGuiFilePath())
            self._gui.init()
            return True

    def stop(self):
        if self._data is not None:
            self._data = None
        hintsIDs = self.__activeHints.keys()
        for itemID in hintsIDs:
            self.__hideHint(itemID)

        if self._gui is not None:
            self._gui.fini()
        self._gui = None
        self.__hintsWithClientTriggers = None
        self.__stopSettingsListening()
        return

    def __loadHintsData(self):
        _logger.debug('Hints are loading')
        shownHints = self.__settingsCore.serverSettings.getOnceOnlyHintsSettings(
        )
        shownHints = [
            key for key, value in shownHints.iteritems()
            if value == HINT_SHOWN_STATUS
        ]
        self._data = HintsParser.parse(_DESCRIPTOR_PATH, shownHints)

    def __setTriggeredComponents(self):
        self.__hintsWithClientTriggers = ClientTriggers()
        self.__hintsWithClientTriggers.setStates(self._data.getHints())
        if self._gui.app is not None and self._gui.app.tutorialManager is not None:
            self._gui.app.tutorialManager.setHintsWithClientTriggers(
                self.__hintsWithClientTriggers)
        return

    def __showHint(self, hint):
        text = hint['text']
        uniqueID = hintID = hint['hintID']
        props = HintProps(uniqueID,
                          hintID,
                          hint['itemID'],
                          text,
                          hasBox=hint['hasBox'],
                          arrow=hint['arrow'],
                          padding=None,
                          updateRuntime=hint['updateRuntime'],
                          hideImmediately=hint['hideImmediately'],
                          checkViewArea=hint['checkViewArea'])
        actionType = hint.get('ignoreOutsideClick')
        self._gui.showHint(props, actionType)
        self.__activeHints[hint['itemID']] = hint
        return

    def __hideHint(self, itemID, hintID=''):
        if itemID in self.__activeHints:
            hintID = hintID or self.__getActiveHintIdByItemId(itemID)
            self._gui.hideHint(hintID)
            if itemID in self.__activeHints:
                del self.__activeHints[itemID]

    def __onGUILoaded(self):
        self.__setTriggeredComponents()

    def __onGUIInput(self, event):
        itemID = event.getTargetID()
        if itemID in self.__activeHints:
            hintID = self.__getActiveHintIdByItemId(itemID)
            self.__hideHint(itemID)
            self.__stopOnceOnlyHint(itemID, hintID)
            if self._data.getHintsCount() == 0:
                self.stop()

    def __onItemFound(self, itemID):
        if itemID not in self.__activeHints:
            hints = self._data.hintsForItem(itemID)
            for hint in hints:
                if not self.__hintsWithClientTriggers.checkState(itemID):
                    continue
                if self.__checkConditions(hint):
                    if itemID not in self.__activeHints:
                        self.__showHint(hint)
                        break

    def __onItemLost(self, itemID):
        if itemID in self.__activeHints:
            hint = self.__activeHints[itemID]
            if hint['equalActions']:
                self.__stopOnceOnlyHint(itemID, hint['hintID'])
            self.__hideHint(itemID)

    def __onItemVisibleChanged(self, event):
        self.__updateItemState(event)

    def __onItemEnabledChanged(self, event):
        self.__updateItemState(event)

    def __updateItemState(self, event):
        itemID = event.getTargetID()
        state = event.getStateName()
        newStateValue = event.getStateValue()
        componentsWithClientTriggers = self.__hintsWithClientTriggers.getNeededStates(
        )
        if itemID not in componentsWithClientTriggers or state not in componentsWithClientTriggers[
                itemID]:
            return
        self.__hintsWithClientTriggers.updateRealState(itemID, state,
                                                       newStateValue)
        if not self.__hintsWithClientTriggers.isStateChanged(itemID, state):
            return
        if self.__hintsWithClientTriggers.checkState(itemID):
            hints = self._data.hintsForItem(itemID)
            for hint in hints:
                self.__hintsWithClientTriggers.addActiveHint(itemID)
                if self.__checkConditions(hint):
                    self.__showHint(hint)

        else:
            self.__hintsWithClientTriggers.removeActiveHint(itemID)
            self.__hideHint(itemID)

    def __getActiveHintIdByItemId(self, itemID):
        return self.__activeHints[itemID]['hintID']

    def __stopOnceOnlyHint(self, itemID, hintID):
        if self._data is None:
            return
        else:
            hints = self._data.hintsForItem(itemID)
            for hint in hints:
                if hint['hintID'] == hintID:
                    self.__stopSettingsListening()
                    self.__settingsCore.serverSettings.setOnceOnlyHintsSettings(
                        {hintID: HINT_SHOWN_STATUS})
                    self.__startSettingsListening()
                    self._data.markAsShown(itemID, hintID)

            return

    @staticmethod
    def __checkConditions(hint):
        conditions = hint['conditions']
        return True if conditions is None else FunctionalConditions(
            conditions).allConditionsOk()

    def __startSettingsListening(self):
        self.__settingsCore.onOnceOnlyHintsChanged += self.__onSettingsChanged

    def __stopSettingsListening(self):
        self.__settingsCore.onOnceOnlyHintsChanged -= self.__onSettingsChanged

    def __onSettingsChanged(self, diff):
        diffKeys = diff.viewkeys()
        if diffKeys & set(OnceOnlyHints.ALL()):
            self._data.markHintsAsShown(diffKeys)
            for itemID, hint in self.__activeHints.items():
                hintID = hint['hintID']
                if hintID in diffKeys:
                    self.__hideHint(itemID, hintID)

            if self._data.getHintsCount() == 0:
                self.stop()
                return
Esempio n. 6
0
class HintsManager(object):
    def __init__(self):
        super(HintsManager, self).__init__()
        self._data = None
        self._gui = None
        self.__activeHints = {}
        return

    def start(self):
        self.__loadHintsData()
        if self._data.hintsCount == 0:
            return False
        self._gui = HintsProxy()
        self._gui.init()
        self._gui.loadConfig(self._data.getGuiFilePath())
        self._gui.onHintClicked += self.__onGUIInput
        self._gui.onHintItemFound += self.__onItemFound
        self._gui.onHintItemLost += self.__onItemLost
        return True

    def stop(self):
        if self._data is not None:
            self._data = None
        for itemID in self.__activeHints.keys():
            self.__hideHint(itemID)

        if self._gui is not None:
            self._gui.fini()
        self._gui = None
        return

    def __loadHintsData(self):
        LOG_DEBUG('Hints are loading')
        shownHints = g_settingsCore.serverSettings.getOnceOnlyHintsSettings()
        shownHints = [
            key for key, value in shownHints.iteritems() if value == 1
        ]
        self._data = HintsParser.parse(_DESCRIPTOR_PATH, shownHints)

    def __showHint(self, hint):
        text = hint['text']
        uniqueID = hintID = hint['hintID']
        props = HintProps(uniqueID, hintID, hint['itemID'], text, True,
                          hint['arrow'], None)
        self._gui.showHint(props)
        self.__activeHints[hint['itemID']] = hint
        return

    def __hideHint(self, itemID):
        if itemID in self.__activeHints:
            hint = self.__activeHints[itemID]
            self._gui.hideHint(hint['hintID'])
            del self.__activeHints[itemID]

    def __onGUIInput(self, event):
        itemID = event.getTargetID()
        if itemID in self.__activeHints:
            hint = self.__activeHints[itemID]
            self.__hideHint(itemID)
            self._data.markAsShown(hint)
            g_settingsCore.serverSettings.setOnceOnlyHintsSettings(
                {hint['hintID']: 1})
            if self._data.hintsCount == 0:
                self.stop()

    def __onItemFound(self, itemID):
        hint = self._data.hintForItem(itemID)
        if hint is not None and itemID not in self.__activeHints:
            self.__showHint(hint)
        return

    def __onItemLost(self, itemID):
        if itemID in self.__activeHints:
            self.__hideHint(itemID)
Esempio n. 7
0
class HintsManager(object):
    settingsCore = dependency.descriptor(ISettingsCore)

    def __init__(self):
        super(HintsManager, self).__init__()
        self._data = None
        self._gui = None
        self.__activeHints = {}
        return

    def start(self):
        self.__loadHintsData()
        if self._data.hintsCount == 0:
            return False
        self._gui = HintsProxy()
        self._gui.init()
        self._gui.loadConfig(self._data.getGuiFilePath())
        self._gui.onHintClicked += self.__onGUIInput
        self._gui.onHintItemFound += self.__onItemFound
        self._gui.onHintItemLost += self.__onItemLost
        return True

    def stop(self):
        if self._data is not None:
            self._data = None
        hintsIDs = self.__activeHints.keys()
        for itemID in hintsIDs:
            self.__hideHint(itemID)

        if self._gui is not None:
            self._gui.fini()
        self._gui = None
        return

    def stopOnceOnlyHint(self, itemID):
        if self._data is None:
            return
        else:
            hint = self._data.hintForItem(itemID)
            if hint is not None:
                self._data.markAsShown(hint)
                self.settingsCore.serverSettings.setOnceOnlyHintsSettings(
                    {hint['hintID']: HINT_SHOWN_STATUS})
            return

    def __loadHintsData(self):
        LOG_DEBUG('Hints are loading')
        shownHints = self.settingsCore.serverSettings.getOnceOnlyHintsSettings(
        )
        shownHints = [
            key for key, value in shownHints.iteritems()
            if value == HINT_SHOWN_STATUS
        ]
        self._data = HintsParser.parse(_DESCRIPTOR_PATH, shownHints)

    def __showHint(self, hint):
        text = hint['text']
        uniqueID = hintID = hint['hintID']
        props = HintProps(uniqueID, hintID, hint['itemID'], text, True,
                          hint['arrow'], None)
        self._gui.showHint(props)
        self.__activeHints[hint['itemID']] = hint
        return

    def __hideHint(self, itemID):
        if itemID in self.__activeHints:
            hint = self.__activeHints[itemID]
            self._gui.hideHint(hint['hintID'])
            del self.__activeHints[itemID]

    def __onGUIInput(self, event):
        itemID = event.getTargetID()
        if itemID in self.__activeHints:
            self.__hideHint(itemID)
            self.stopOnceOnlyHint(itemID)
            if self._data.hintsCount == 0:
                self.stop()

    def __onItemFound(self, itemID):
        hint = self._data.hintForItem(itemID)
        if hint is not None and itemID not in self.__activeHints and self.__checkConditions(
                hint):
            self.__showHint(hint)
        return

    def __onItemLost(self, itemID):
        if itemID in self.__activeHints:
            hint = self.__activeHints[itemID]
            if hint['equalActions']:
                self.stopOnceOnlyHint(itemID)
            self.__hideHint(itemID)

    def __checkConditions(self, hint):
        conditions = hint['conditions']
        if conditions is None:
            return True
        else:
            return FunctionalConditions(conditions).allConditionsOk()