On Thu, Apr 19, 2018 at 6:12 AM, 'Karsten Wolf' via leo-editor <
[email protected]> wrote:

> ...
>
>> Note that apparently simple tests can be fraught.  There is a bug against
>> ks.isPlainKey.  It ends with:
>>
>>     if s in string.printable:
>>         return True
>>     if len(s) > 1:
>>         return False
>>     return unicodedata.category(s).startswith('C')
>>
>> Why this fails is mysterious.  Perhaps the test should be:
>>
>
> s  could still be a str (string.printable is a subset) and make
> unicodedata.category(s) fail.
>
> The question is: Why is s not unicode?
>

​An excellent question.  Happily, the soon-to-be-pushed version of
ks.isPlainKey bypasses unicodedata entirely:

def isPlainKey(self):
    '''
    Return True if self.s represents a plain key.

    **Note**: The caller is responsible for handling Alt-Ctrl keys.
    '''
    s = self.s
    if s in g.ignoreChars:
        # For unit tests.
        return False
    if self.find_mods(s) or self.isFKey():
        return False
    if s in self.specialChars:
        return False
    return True

Once a few special cases are handled, the interesting assumption is that
all keys without modifiers are "plain" keys, even (especially) Chinese
characters.  It looks like this is working now.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to