Is key Free: Adjust character width for East Asian languages #104848

Merged
Pratik Borhade merged 1 commits from jmztn/blender-addons:iskeyfree_i18n into main 2023-09-08 13:26:00 +02:00
Showing only changes of commit cb014a3311 - Show all commits

View File

@ -7,7 +7,7 @@
bl_info = { bl_info = {
"name": "Is key Free", "name": "Is key Free",
"author": "Antonio Vazquez (antonioya)", "author": "Antonio Vazquez (antonioya)",
"version": (1, 1, 2), "version": (1, 1, 3),
"blender": (2, 80, 0), "blender": (2, 80, 0),
"location": "Text Editor > Sidebar > Dev Tab", "location": "Text Editor > Sidebar > Dev Tab",
"description": "Find free shortcuts, inform about used and print a key list", "description": "Find free shortcuts, inform about used and print a key list",
@ -16,6 +16,7 @@ bl_info = {
} }
import bpy import bpy
from bpy.props import ( from bpy.props import (
BoolProperty, BoolProperty,
EnumProperty, EnumProperty,
@ -28,6 +29,7 @@ from bpy.types import (
PropertyGroup, PropertyGroup,
) )
import unicodedata
# ------------------------------------------------------ # ------------------------------------------------------
# Class to find keymaps # Class to find keymaps
@ -498,6 +500,15 @@ class IsKeyFreeRunExportKeys(Operator):
except: except:
return None return None
def unicodelen(self, string):
n = 0
for c in string:
if unicodedata.east_asian_width(c) in 'FWA':
n += 2
else:
n += 1
return n
def execute(self, context): def execute(self, context):
wm = bpy.context.window_manager wm = bpy.context.window_manager
from collections import defaultdict from collections import defaultdict
@ -536,7 +547,7 @@ class IsKeyFreeRunExportKeys(Operator):
textblock.write("\n[%s]\nEntries: %s\n\n" % (ctx, len(mykeys[ctx]))) textblock.write("\n[%s]\nEntries: %s\n\n" % (ctx, len(mykeys[ctx])))
line_k = sorted(mykeys[ctx]) line_k = sorted(mykeys[ctx])
for keys in line_k: for keys in line_k:
add_ticks = "-" * (max_line - (len(keys[0]) + len(keys[1]))) add_ticks = "-" * (max_line - (self.unicodelen(keys[0]) + len(keys[1])))
entries = "{ticks} {entry}".format(ticks=add_ticks, entry=keys[1]) entries = "{ticks} {entry}".format(ticks=add_ticks, entry=keys[1])
textblock.write("{name} {entry}\n".format(name=keys[0], entry=entries)) textblock.write("{name} {entry}\n".format(name=keys[0], entry=entries))