/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/label.py
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/Thuban/Model/label.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2563 - (show annotations)
Wed Feb 16 23:13:19 2005 UTC (20 years ago) by jan
Original Path: trunk/thuban/Thuban/Model/label.py
File MIME type: text/x-python
File size: 2314 byte(s)
Added import of _.
(Label, Label.__init__): Improved/added doc string.
LabelLayer, LabelLayer.__init__, LabelLayer.Labels,
LabelLayer.RemoveLabel, LabelLayer.ClearLabels):
Improved/added doc string.
(LabelLayer.AddLabel): Use already defined names for
align strings and improved doc string.
(LabelLayer.TreeInfo): New. Return the object data for
the tree view.

1 # Copyright (c) 2001, 2002, 2005 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 __version__ = "$Revision$"
9
10 from Thuban import _
11
12 from messages import CHANGED
13
14 from base import TitledObject, Modifiable
15
16 ALIGN_CENTER = "center"
17 ALIGN_TOP = "top"
18 ALIGN_BOTTOM = "bottom"
19 ALIGN_LEFT = "left"
20 ALIGN_RIGHT = "right"
21 ALIGN_BASELINE = "baseline"
22
23 class Label:
24
25 """This class repesents a single label that is
26 defined by its coordinate, the text as well
27 as vertical and horizontal alignment concerning
28 the coordinate."""
29
30 def __init__(self, x, y, text, halign, valign):
31 """Initialize the label with the given parameters."""
32 self.x = x
33 self.y = y
34 self.text = text
35 self.halign = halign
36 self.valign = valign
37
38
39 class LabelLayer(TitledObject, Modifiable):
40
41 """This represent a layer holding a number of labels."""
42
43 def __init__(self, title):
44 """Initialize the LabeleLayer with an empty
45 list of labels and set the title to "title".
46 """
47 TitledObject.__init__(self, title)
48 Modifiable.__init__(self)
49 self.labels = []
50
51 def Labels(self):
52 """Return a list of all labels."""
53 return self.labels
54
55 def AddLabel(self, x, y, text, halign = ALIGN_LEFT,
56 valign = ALIGN_CENTER):
57 """Add a label at position (x,y) with contents "text".
58
59 This will emit a CHANGED signal.
60 """
61 self.labels.append(Label(x, y, text, halign, valign))
62 self.changed(CHANGED)
63
64 def RemoveLabel(self, index):
65 """Remove the label specified by index.
66
67 This will emit a CHANGED signal.
68 """
69 del self.labels[index]
70 self.changed(CHANGED)
71
72 def ClearLabels(self):
73 """Remove all labels.
74
75 This will emit a CHANGED signal.
76 """
77 del self.labels[:]
78 self.changed(CHANGED)
79
80 def TreeInfo(self):
81 """Return a tuple of (title, tupel) describing the contents
82 of the object in a tree-structure.
83 """
84 items = []
85 items.append(_("Number of labels: %d") % len(self.labels))
86 return (_("Label Layer: %s") % self.title, items)

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26