예제 #1
0
def getDictionary(type):
    profile = config.conf.getActiveProfile()
    if (type == "voice"):
        return _getVoiceDictionary(profile)
    # if we are om default profile or the specific dictionary profile is already loaded
    if not profile.name or _hasDictionaryProfile(profile.name, f"{type}.dic"):
        # we are with the correct dictionary loaded. Just return it.
        log.debug(
            f"{type} dictionary, backed by {dictionaries[type].fileName} was requested"
        )
        return dictionaries[type]
    # we are on a user profile for which there is no dictionary created.
    # The current loaded dictionary is the default profile one.
    # As we have beem called to get the current profile dictionary and it still does not exist,
    # We will create it now and pass the new, empty dictionary to the caller, but won't save it.
    # This is a task the caller should do when and if they wish
    dic = speechDictHandler.SpeechDict()
    dic.create(
        os.path.join(dictFormatUpgrade.speechDictsPath, profile.name,
                     f"{type}.dic"))
    log.debug(
        f"{type} dictionary was requested for profile {profile.name}, but the backing file does not exist."
        f" A New dictionary was created, set to be backed by {dic.fileName} if it is ever saved."
    )
    return dic
예제 #2
0
 def loadSpeechDict(self):
     if not os.path.isfile(self.path):
         if not os.path.exists(profileDictsPath):
             os.makedirs(profileDictsPath)
         open(self.path, "a").close()
     self.speechDict = speechDictHandler.SpeechDict()
     self.speechDict.load(self.path)
예제 #3
0
def _getVoiceDictionary(profile):
    from synthDriverHandler import getSynth
    synth = getSynth()
    dictionaryFilename = _getVoiceDictionaryFileName(synth)
    # if we are om default profile or the specific dictionary profile is already loaded
    if not profile.name or _hasVoiceDictionaryProfile(profile.name, synth.name,
                                                      dictionaryFilename):
        # we are with the correct dictionary loaded. Just return it.
        log.debug(
            f"Voice dictionary, backed by {dictionaries['voice'].fileName} was requested"
        )
        return dictionaries["voice"]
    # we are on a user profile for which there is no dictionary created for the current voice.
    # The current loaded dictionary is the default profile one.
    # As we have beem called to get the profile dictionary for the current voice and it still does not exist,
    # We will create it now and pass the new, empty dictionary to the caller, but won't save it.
    # This is a task the caller should do when and if they wish
    dic = speechDictHandler.SpeechDict()
    dic.create(
        os.path.join(getProfileVoiceDictsPath(), synth.name,
                     dictionaryFilename))
    log.debug(
        f"voice dictionary was requested for profile {profile.name}, but the backing file does not exist."
        f" A New dictionary was created, set to be backed by {dic.fileName} if it is ever saved."
    )
    return dic
예제 #4
0
 def __init__(self):
     super(globalPluginHandler.GlobalPlugin, self).__init__()
     self.ltx = False
     self.dicFile = getDicPath()
     if self.dicFile is not None:
         self.SD = speechDictHandler.SpeechDict()
     else:
         self.SD = None
def getDict(appName):
    dict = None
    if appName in dicts:
        dictFilePath = getDictFilePath(appName)
        if dicts[appName] is None:
            dict = speechDictHandler.SpeechDict()
            dict.load(dictFilePath)
            dicts[appName] = dict
        else:
            dict = dicts[appName]
    return dict
    def script_editDict(self, gesture):
        appName = getAppName()
        dict = getDict(appName)
        if dict is None:
            dictFilePath = getDictFilePath(appName)
            open(dictFilePath, "a").close()
            dict = speechDictHandler.SpeechDict()
            dict.load(dictFilePath)
            dicts[appName] = dict
# Translators: title of application dictionary dialog.
        title = _("Dictionary for {arg0}").format(arg0=appName)
        gui.mainFrame._popupSettingsDialog(gui.DictionaryDialog, title, dict)
예제 #7
0
	def __init__(self, parent, title, speechDict):
		self.title = title
		self.speechDict = speechDict
		self.tempSpeechDict = speechDictHandler.SpeechDict()
		self.tempSpeechDict.extend(self.speechDict)
		globalVars.speechDictionaryProcessing = False
		super().__init__(parent, resizeable=True)
		# Historical initial size, result of L{self.dictList} being (550,350) as of #6287.
		# Setting an initial size on L{self.dictList} by passing a L{size} argument when
		# creating the control would also set its minimum size and thus block the dialog from being shrunk.
		self.SetSize(576, 502)
		self.CentreOnScreen()
예제 #8
0
 def OnResetClick(self, evt):
     self.dictList.DeleteAllItems()
     self.tempSpeechDict = []
     self.dic = speechDictHandler.SpeechDict()
     if config.conf["emoticons"]["speakAddonEmojis"]:
         self.dic = defaultDic
     else:
         self.dic = noEmojisDic
     self.tempSpeechDict.extend(self.dic)
     for entry in self.dic:
         self.dictList.Append(
             (entry.comment, entry.pattern, entry.replacement, True,
              speechDictHandler.ENTRY_TYPE_REGEXP))
     self.dictList.SetFocus()
 def onImportEntriesClick(self, evt):
     sourceFileName = self.speechDict.fileName.replace(
         f"{self._profile.name}\\", "")
     log.debug(
         f"Importing entries from default dictionary at {sourceFileName}")
     source = speechDictHandler.SpeechDict()
     source.load(sourceFileName)
     self.tempSpeechDict.syncFrom(source)
     for entry in self.tempSpeechDict:
         if not self.hasEntry(entry.pattern):
             self.dictList.Append(
                 (entry.comment, entry.pattern, entry.replacement,
                  self.offOn[int(entry.caseSensitive)],
                  EnhancedDictionaryDialog.TYPE_LABELS[entry.type]))
     self.dictList.SetFocus()
예제 #10
0
from validate import Validator

iniFileName = os.path.join(os.path.dirname(__file__), "emoticons.ini")

confspec = ConfigObj(StringIO("""#Configuration file

[Activation settings]
	activateAtStart = integer(default=0)
"""), encoding="UTF-8", list_values=False)
confspec.newlines = "\r\n"
conf = ConfigObj(iniFileName, configspec = confspec, indent_type = "\t", encoding="UTF-8")
val = Validator()
conf.validate(val)

dicFile = os.path.join(os.path.dirname(__file__), "emoticons.dic")
defaultDic = speechDictHandler.SpeechDict()
sD =speechDictHandler.SpeechDict()
emStatus = False
shouldActivateEmoticons = False

def activateEmoticons():
	global emStatus
	speechDictHandler.dictionaries["temp"].extend(sD)
	emStatus = True

def deactivateEmoticons():
	global emStatus
	for entry in sD:
		if entry in speechDictHandler.dictionaries["temp"]:
			speechDictHandler.dictionaries["temp"].remove(entry)
	emStatus = False
def loadDict(appName):
    ensureEntryCacheSize(appName)
    dict = speechDictHandler.SpeechDict()
    dict.load(getDictFilePath(appName))
    dicts[appName] = dict
    return dict
예제 #12
0
    os.path.join(os.path.dirname(__file__), "emoticons"))
EXPORT_DICTS_PATH = os.path.join(speechDictHandler.speechDictsPath,
                                 "emoticons")
ADDON_DIC_DEFAULT_FILE = os.path.join(ADDON_DICTS_PATH, "emoticons.dic")
ADDON_SUMMARY = addonHandler.getCodeAddon().manifest["summary"]
ADDON_PANEL_TITLE = ADDON_SUMMARY

confspec = {
    "announcement": "integer(default=0)",
    "speakAddonEmojis": "boolean(default=False)",
    "cleanDicts": "boolean(default=False)",
}

config.conf.spec["emoticons"] = confspec

defaultDic = speechDictHandler.SpeechDict()
noEmojisDic = speechDictHandler.SpeechDict()
sD = speechDictHandler.SpeechDict()

profileName = oldProfileName = None


def loadDic():
    if profileName is None:
        dicFile = ADDON_DIC_DEFAULT_FILE
    else:
        dicFile = os.path.abspath(
            os.path.join(ADDON_DICTS_PATH, "profiles", "%s.dic" % profileName))
    sD.load(dicFile)
    if not os.path.isfile(dicFile):
        if config.conf["emoticons"]["speakAddonEmojis"]: