File: label.py

package info (click to toggle)
thuban 1.2.2-14
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,176 kB
  • sloc: python: 30,410; ansic: 6,181; xml: 4,234; cpp: 1,595; makefile: 145
file content (92 lines) | stat: -rw-r--r-- 2,416 bytes parent folder | download | duplicates (6)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Copyright (c) 2001, 2002, 2005 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.

__version__ = "$Revision: 2569 $"

from Thuban import _

from messages import CHANGED

from base import TitledObject, Modifiable

ALIGN_CENTER = "center"
ALIGN_TOP = "top"
ALIGN_BOTTOM = "bottom"
ALIGN_LEFT = "left"
ALIGN_RIGHT = "right"
ALIGN_BASELINE = "baseline"

class Label:

    """This class repesents a single label.

    The label is defined by its coordinate, the text as well
    as vertical and horizontal alignment concerning
    the coordinate.
    """

    def __init__(self, x, y, text, halign, valign):
        """Initialize the label with the given parameters."""
        self.x = x
        self.y = y
        self.text = text
        self.halign = halign
        self.valign = valign


class LabelLayer(TitledObject, Modifiable):

    """This represent a layer holding a number of labels."""

    def __init__(self, title):
        """Initialize the LabeleLayer.

        Initialization is done with an empty
        list of labels and set the title to "title".
        """
        TitledObject.__init__(self, title)
        Modifiable.__init__(self)
        self.labels = []

    def Labels(self):
        """Return a list of all labels."""
        return self.labels

    def AddLabel(self, x, y, text, halign = ALIGN_LEFT,
                 valign = ALIGN_CENTER):
        """Add a label at position (x,y) with contents "text".

        This will emit a CHANGED signal.
        """
        self.labels.append(Label(x, y, text, halign, valign))
        self.changed(CHANGED)

    def RemoveLabel(self, index):
        """Remove the label specified by index.

        This will emit a CHANGED signal.
        """
        del self.labels[index]
        self.changed(CHANGED)

    def ClearLabels(self):
        """Remove all labels.

        This will emit a CHANGED signal.
        """
        del self.labels[:]
        self.changed(CHANGED)

    def TreeInfo(self):
        """Return a description of the object.

        A tuple of (title, tupel) describing the contents
        of the object in a tree-structure is returned.
        """
        items = []
        items.append(_("Number of labels: %d") % len(self.labels))
        return (_("Label Layer: %s") % self.title, items)