-
Notifications
You must be signed in to change notification settings - Fork 19
/
em.py
56 lines (36 loc) · 1.02 KB
/
em.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gi
from gi.repository import Pango
from gi.repository import Gtk
gi.require_version("Gtk", "3.0")
import logging
LOG = logging.getLogger(__name__)
def get_em(size=""):
# calc the height of a character, use as 1em
if size:
m = '<%s>M</%s>' % (size, size)
else:
m = 'M'
l = Gtk.Label()
l.set_markup(m)
w, h = l.get_layout().get_size()
return h / Pango.SCALE
def get_small_em():
return get_em("small")
def get_big_em():
return get_em("big")
EM = get_em()
SMALL_EM = get_small_em()
BIG_EM = get_big_em()
LOG.debug("EM's: %s %s %s" % (EM, SMALL_EM, BIG_EM))
def em(multiplier=1, min=1):
return max(int(min), int(round(EM * multiplier, 0)))
def small_em(multiplier=1, min=1):
return max(int(min), int(round(SMALL_EM * multiplier, 0)))
def big_em(multiplier=1, min=1):
return max(int(min), int(round(BIG_EM * multiplier, 0)))
# common values
class StockEms:
XLARGE = em(1.33, 5)
LARGE = em(min=3)
MEDIUM = em(0.666, 2)
SMALL = em(0.333, 1)