diff options
Diffstat (limited to 'src/person.py')
-rw-r--r-- | src/person.py | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/src/person.py b/src/person.py index a318266..094eeb8 100644 --- a/src/person.py +++ b/src/person.py @@ -5,13 +5,14 @@ import const # Constants -const._person_width = 80 -const._person_height = 30 -const._person_wmargin = 6 -const._person_hmargin = 16 +const._person_width = 120 +const._person_height = 48 +const._person_wmargin_ratio = 12 +const._person_hmargin_ratio = 2 const._male_color = (0, 0, 255) const._female_color = (255, 0, 0) -const._person_font = pango.FontDescription('Arial 8') +const._person_font = 'Arial' +const._person_fontsize = 8 # Set of person @@ -35,7 +36,7 @@ class Person: self.sex = 'F' self.parents = None self.unions = [] - (self.x, self.y) = (-1, -1) + (self.x0, self.y0, self.x1, self.y1, self.fontsize) = (-1, -1, -1, -1, const._person_fontsize) persons.append(self) @@ -73,7 +74,7 @@ class Person: def point_inside(self, x, y): "Test if point is inside the drawing" - return x >= self.x and x <= self.x+const._person_width and y >= self.y and y <= self.y+const._person_height + return x >= self.x0 and x <= self.x1 and y >= self.y0 and y <= self.y1 def draw_node(self, gc, pc): @@ -84,17 +85,17 @@ class Person: gc.set_source_rgb(*const._male_color) else: gc.set_source_rgb(*const._female_color) - gc.rectangle(self.x, self.y, const._person_width, const._person_height) + gc.rectangle(self.x0, self.y0, self.x1-self.x0, self.y1-self.y0) gc.stroke() # draw text layout = pango.Layout(pc) - layout.set_width(const._person_width*pango.SCALE) + layout.set_width(int(self.x1-self.x0)*pango.SCALE) layout.set_text(self.name) layout.set_alignment(pango.ALIGN_CENTER) layout.set_wrap(pango.WRAP_WORD) - layout.set_font_description(const._person_font) - gc.move_to(self.x, self.y) + layout.set_font_description(pango.FontDescription(const._person_font + " " + str(self.fontsize))) + gc.move_to(self.x0, self.y0) gc.show_layout(layout) @@ -102,35 +103,50 @@ class Person: "Compute person and its subtree draw starting at origin" # Set person position - (self.x, self.y) = (x, y) + (self.x0, self.y0) = (x, y) + (self.x1, self.y1) = (x+const._person_width, y+const._person_height) if self.unions != []: # Set union position + wmargin = const._person_width / const._person_wmargin_ratio + hmargin = const._person_height / const._person_hmargin_ratio for i, u in enumerate(self.unions): # Next union if i != 0: size = u.size_to_draw() - x = x + (size*const._person_width+size*const._person_wmargin)/2 + x = x + (size*const._person_width+size*wmargin)/2 # Set conjoint position if self.sex == 'M': opposite = u.mum else: opposite = u.dad - (opposite.x, opposite.y) = (x + const._person_width+const._person_wmargin, y) + (opposite.x0, opposite.y0) = (x + const._person_width+wmargin, y) + (opposite.x1, opposite.y1) = (opposite.x0 + const._person_width, opposite.y0 + const._person_height) # Set the union and childs of this union - u.compute_draw(x+const._person_width+(const._person_wmargin/2), y+const._person_height+const._person_hmargin) + u.compute_draw(x+const._person_width+(wmargin/2), y+const._person_height+hmargin) # Shift right size = u.size_to_draw() - x = x + (size*const._person_width+size*const._person_wmargin)/2 + x = x + (size*const._person_width+size*wmargin)/2 def translate(self, dx, dy): "Translate coordinate" - self.x = self.x + dx - self.y = self.y + dy + self.x0 = self.x0 + dx + self.y0 = self.y0 + dy + self.x1 = self.x1 + dx + self.y1 = self.y1 + dy + + def scale(self, scalerate): + "Scale coordinate and font" + self.x0 = self.x0 + ((self.x0 * scalerate) / 100) + self.y0 = self.y0 + ((self.y0 * scalerate) / 100) + self.x1 = self.x1 + ((self.x1 * scalerate) / 100) + self.y1 = self.y1 + ((self.y1 * scalerate) / 100) + self.fontsize = const._person_fontsize + (scalerate / 10) + def draw(self, gc, pc): "Draw person and its subtree in the graphical context" @@ -149,8 +165,3 @@ class Person: # Draw the union and childs of this union u.draw(gc, pc, i) - - - - - |