/[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 2734 - (show annotations)
Thu Mar 1 12:42:59 2007 UTC (18 years ago) by bramz
File MIME type: text/x-python
File size: 2409 byte(s)
made a copy
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.
26
27 The label is defined by its coordinate, the text as well
28 as vertical and horizontal alignment concerning
29 the coordinate.
30 """
31
32 def __init__(self, x, y, text, halign, valign):
33 """Initialize the label with the given parameters."""
34 self.x = x
35 self.y = y
36 self.text = text
37 self.halign = halign
38 self.valign = valign
39
40
41 class LabelLayer(TitledObject, Modifiable):
42
43 """This represent a layer holding a number of labels."""
44
45 def __init__(self, title):
46 """Initialize the LabeleLayer.
47
48 Initialization is done with an empty
49 list of labels and set the title to "title".
50 """
51 TitledObject.__init__(self, title)
52 Modifiable.__init__(self)
53 self.labels = []
54
55 def Labels(self):
56 """Return a list of all labels."""
57 return self.labels
58
59 def AddLabel(self, x, y, text, halign = ALIGN_LEFT,
60 valign = ALIGN_CENTER):
61 """Add a label at position (x,y) with contents "text".
62
63 This will emit a CHANGED signal.
64 """
65 self.labels.append(Label(x, y, text, halign, valign))
66 self.changed(CHANGED)
67
68 def RemoveLabel(self, index):
69 """Remove the label specified by index.
70
71 This will emit a CHANGED signal.
72 """
73 del self.labels[index]
74 self.changed(CHANGED)
75
76 def ClearLabels(self):
77 """Remove all labels.
78
79 This will emit a CHANGED signal.
80 """
81 del self.labels[:]
82 self.changed(CHANGED)
83
84 def TreeInfo(self):
85 """Return a description of the object.
86
87 A tuple of (title, tupel) describing the contents
88 of the object in a tree-structure is returned.
89 """
90 items = []
91 items.append(_("Number of labels: %d") % len(self.labels))
92 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