Extract some other constants (labels and icons placement).
Extract some other constants (labels and icons placement).
diff --git a/qwerty.py b/qwerty.py
index 687ced0..ba38160 100755
--- a/qwerty.py
+++ b/qwerty.py
@@ -18,6 +18,14 @@ SECTION = 1
KEY = 2
PADDING = 4
+ICON_TOP_MARGIN = 40
+LABEL_LEFT, LABEL_TOP = 20,25
+LABEL_FONT_SIZE = 16
+DESC_TOP = 120
+DESC_FONT_SIZE = 14
+KEY_BOTTOM = 45
+KEY_FONT_SIZE = 40
+
LINEHEIGHT = 1.2
KEYS = [ "QWERTYUIOP",
@@ -84,8 +92,7 @@ class SuperButton(gtk.DrawingArea):
s = s + ' ' + word
else:
s = word
- o,n = size(old), size(s)
- if o < self.width and n >= self.width:
+ if size(s) >= self.width - LABEL_LEFT:
lines.append(old)
s = word
else:
@@ -109,9 +116,8 @@ class SuperButton(gtk.DrawingArea):
cr2.paint()
x = (self.width - w)/2
- y = 45
- cr.set_source_surface(IS,x,y)
+ cr.set_source_surface(IS,x,ICON_TOP_MARGIN)
cr.paint()
def draw_button(self,cr):
@@ -128,12 +134,12 @@ class SuperButton(gtk.DrawingArea):
def draw_label(self,cr):
if self.active:
cr.set_source_rgb(*BUTTON_BORDER_ACTIVE)
- cr.move_to(20,30)
- cr.set_font_size(16)
+ cr.move_to(LABEL_LEFT, LABEL_TOP)
+ cr.set_font_size(LABEL_FONT_SIZE)
cr.show_text(self.label)
def draw_desc(self,cr):
- self.show_text_wrap(cr,20,130, 14, self.desc)
+ self.show_text_wrap(cr,LABEL_LEFT,DESC_TOP, DESC_FONT_SIZE, self.desc)
def on_expose(self,widget,event):
x,y,self.width,self.height,b = widget.window.get_geometry()
@@ -145,8 +151,8 @@ class SuperButton(gtk.DrawingArea):
cr.set_source_rgb(*BUTTON_BORDER_ACTIVE)
# Draw key
- cr.move_to(20, self.height-50)
- cr.set_font_size(40)
+ cr.move_to(LABEL_LEFT, self.height-KEY_BOTTOM)
+ cr.set_font_size(KEY_FONT_SIZE)
cr.show_text(self.key)
self.draw_label(cr)