Skip to content

Instantly share code, notes, and snippets.

@LettError
Created February 28, 2019 14:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LettError/5b56cf940d962f5d6c6e3caed9cbbee3 to your computer and use it in GitHub Desktop.
Save LettError/5b56cf940d962f5d6c6e3caed9cbbee3 to your computer and use it in GitHub Desktop.
A small converter from normal latin AZ,az to the Unicode math alphabets.
import vanilla
""" Unicode Stylewriter: Use the unicode styles to impress friends and families on the internet. """
class StyleWriter(object):
styles = [
dict(title="𝔸", upper=0x1D538, lower=0x1D552, name='mathdoublestruck'),
dict(title="𝖠", upper=0x1D5A0, lower=0x1D5BA, name='mathsans'),
dict(title="𝗔", upper=0x1D5D4, lower=0x1D5EE, name='mathsansbold'),
dict(title="𝐴", upper=0x1D434, lower=0x1D44E, name='mathitalic'),
dict(title="𝐀", upper=0x1D400, lower=0x1D41A, name='mathbold'),
dict(title="𝑨", upper=0x1D468, lower=0x1D482, name='mathbolditalic'),
dict(title="π’œ", upper=0x1D49C, lower=0x1D4B6, name='mathscript'),
dict(title="𝓐", upper=0x1D4D0, lower=0x1D4EA, name='mathscriptbold'),
dict(title="𝔄", upper=0x1D504, lower=0x1D51E, name='mathfraktur'),
dict(title="𝕬", upper=0x1D56C, lower=0x1D586, name='mathfrakturebold'),
]
def __init__(self):
text = "Unicode StyleWriter"
self.styleIndex = 0
self.w = vanilla.Window((400,300), "Unicode StyleWriter")
self.w.t = vanilla.EditText((0,40,0,120), text, placeholder="Type Text Here", continuous=True, callback=self.newInputCallback)
self.w.o = vanilla.EditText((0,160,0,0), "Output")
self.w.style = vanilla.SegmentedButton((5, 5, -5, 20), segmentDescriptions=self.styles, callback=self.selectStyleCallback )
self.w.style.set(0)
self.newInputCallback()
self.w.open()
def selectStyleCallback(self, sender):
self.styleIndex = sender.get()
self.newInputCallback()
def newInputCallback(self, sender=None):
data = self.w.t.get()
new = ""
for c in data:
if 65 <= ord(c) <= 90:
new += chr(ord(c) + self.styles[self.styleIndex]['upper']-65)
elif 97 <= ord(c) <= 122:
new += chr(ord(c) + self.styles[self.styleIndex]['lower']-97)
else:
new += c
self.w.o.set(new)
OpenWindow(StyleWriter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment