Exemplo n.º 1
0
 def doMacTweaks(self, actual_ch, ch, mods):
     """Replace MacOS Alt characters."""
     if not g.isMac:
         return actual_ch, ch, mods
     if ch == 'Backspace':
         # On the Mac, the reported char can be DEL (7F)
         return '\b', ch, mods
     if len(mods) == 1 and mods[0] == 'Alt':
         # Patch provided by resi147.
         # See the thread: special characters in MacOSX, like '@'.
         mac_d = {
             '/': '\\',
             '5': '[',
             '6': ']',
             '7': '|',
             '8': '{',
             '9': '}',
             'e': '€',
             'l': '@',
         }
         if ch.lower() in mac_d:
             # Ignore the case.
             actual_ch = ch = g.checkUnicode(mac_d.get(ch.lower()))
             mods = []
     return actual_ch, ch, mods
Exemplo n.º 2
0
 def __init__(self, c, chapterController, name):
     self.c = c
     self.cc = cc = chapterController
     self.name = g.checkUnicode(name)
     self.selectLockout = False  # True: in chapter.select logic.
     # State variables: saved/restored when the chapter is unselected/selected.
     self.p = c.p
     self.root = self.findRootNode()
     if cc.tt:
         cc.tt.createTab(name)
Exemplo n.º 3
0
 def match_prefix(self, ch, i, j, prefix, s):
     """A match helper."""
     i = j - len(prefix)
     word = g.checkUnicode(prefix) + g.checkUnicode(ch)
     tag = 'tree'
     val = self.tree_abbrevs_d.get(word)
     if not val:
         val, tag = self.abbrevs.get(word, (None, None))
     if val:
         # Require a word match if the abbreviation is itself a word.
         if ch in ' \t\n':
             word = word.rstrip()
         if word.isalnum() and word[0].isalpha():
             if i == 0 or s[i - 1] in ' \t\n':
                 pass
             else:
                 i -= 1
                 word, val = None, None  # 2017/03/19.
     else:
         i -= 1
         word, val = None, None
     return i, tag, word, val
Exemplo n.º 4
0
    def findChapterNode(self, name):
        """
        Return the position of the first @chapter node with the given name
        anywhere in the entire outline.

        All @chapter nodes are created as children of the @chapters node,
        but users may move them anywhere.
        """
        cc = self
        name = g.checkUnicode(name)
        for p in cc.c.all_positions():
            chapterName, binding = self.parseHeadline(p)
            if chapterName == name:
                return p
        return None  # Not an error.
Exemplo n.º 5
0
 def init_language(self):
     """Init self.language."""
     c = self.c
     language = g.checkUnicode(c.config.getString('enchant-language'))
     if language:
         try:
             ok = enchant.dict_exists(language)
         except Exception:
             ok = False
         if not ok:
             g.warning('Invalid language code for Enchant', repr(language))
             g.es_print('Using "en_US" instead')
             g.es_print('Use @string enchant_language to specify your language')
             language = 'en_US'
     self.language = language
Exemplo n.º 6
0
 def get_ch(self, event, stroke, w):
     """Get the ch from the stroke."""
     ch = g.checkUnicode(event and event.char or '')
     if self.expanding: return None
     if w.hasSelection(): return None
     assert g.isStrokeOrNone(stroke), stroke
     if stroke in ('BackSpace', 'Delete'):
         return None
     d = {'Return': '\n', 'Tab': '\t', 'space': ' ', 'underscore': '_'}
     if stroke:
         ch = d.get(stroke.s, stroke.s)
         if len(ch) > 1:
             if (stroke.find('Ctrl+') > -1 or stroke.find('Alt+') > -1
                     or stroke.find('Meta+') > -1):
                 ch = ''
             else:
                 ch = event.char if event else ''
     else:
         ch = event.char
     return ch