File: base.py

package info (click to toggle)
thuban 1.2.2-14
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 9,176 kB
  • sloc: python: 30,410; ansic: 6,181; xml: 4,234; cpp: 1,595; makefile: 145
file content (77 lines) | stat: -rw-r--r-- 2,282 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
# Copyright (c) 2001, 2002, 2003 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.

"""
Various base classes that did not fit elsewhere.
"""

__version__ = "$Revision: 2413 $"

from Thuban.Lib.connector import Publisher

from messages import TITLE_CHANGED, CHANGED

class TitledObject:

    """Mix-in class for objects that have titles"""

    def __init__(self, title):
        self.title = title

    def Title(self):
        return self.title

    def SetTitle(self, title):
        self.title = title

        # FIXME: The TitledObject is almost always used in conjunction
        # with Modifiable (the only exceptions currently are the
        # tables). We should reall derive TitledObject from modifiable
        # (would be good for the tables too) but that's taking things a
        # bit far at the moment.
        if hasattr(self, 'changed'):
            self.changed(TITLE_CHANGED, self)

class Modifiable(Publisher):

    """Class for objects maintaining a modified flag."""

    def __init__(self):
        self.modified = 0

    def WasModified(self):
        """Return true if the layer was modified"""
        return self.modified

    def UnsetModified(self):
        """Unset the modified flag.

        If the modified flag is changed from set to unset by the call,
        issue a CHANGED message.

        The modified flag itself is part of the state of the object so
        some other objects such as a field in the status bar indication
        whether e.g. the session has changed might be interested in
        being notified when this flag has changed.
        """
        was_modified = self.modified
        self.modified = 0
        if was_modified:
            self.issue(CHANGED)

    def changed(self, channel = None, *args):
        """Set the modified flag and optionally issue a message

        The message is issued on the channel given by channel with args
        as the arguments. If channel is None issue no message.

        Subclasses should call this method whenever anything has
        changed.
        """
        self.modified = 1
        if channel is not None:
            self.issue(channel, *args)