1 |
# Copyright (c) 2001, 2002 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 |
""" |
9 |
Various base classes that didn't fir elsewhere |
10 |
""" |
11 |
|
12 |
__version__ = "$Revision$" |
13 |
|
14 |
from Thuban.Lib.connector import Publisher |
15 |
|
16 |
from messages import TITLE_CHANGED, CHANGED |
17 |
|
18 |
class TitledObject: |
19 |
|
20 |
"""Mix-in class for objects that have titles""" |
21 |
|
22 |
def __init__(self, title): |
23 |
self.title = title |
24 |
|
25 |
def Title(self): |
26 |
return self.title |
27 |
|
28 |
def SetTitle(self, title): |
29 |
self.title = title |
30 |
if hasattr(self, 'issue'): |
31 |
self.issue(TITLE_CHANGED, self) |
32 |
|
33 |
class Modifiable(Publisher): |
34 |
|
35 |
"""Class for objects maintaining a modified flag.""" |
36 |
|
37 |
def __init__(self): |
38 |
self.modified = 0 |
39 |
|
40 |
def WasModified(self): |
41 |
"""Return true if the layer was modified""" |
42 |
return self.modified |
43 |
|
44 |
def UnsetModified(self): |
45 |
"""Unset the modified flag. |
46 |
|
47 |
If the modified flag is changed from set to inset by he call, |
48 |
issue a CHANGED message. |
49 |
|
50 |
The modified flag itself is part of the state of the object so |
51 |
some other objects such as a field in the status bar indication |
52 |
whether e.g. the session has changed might be interested in |
53 |
being notified when this flag has changed. |
54 |
""" |
55 |
was_modified = self.modified |
56 |
self.modified = 0 |
57 |
if was_modified: |
58 |
self.issue(CHANGED) |
59 |
|
60 |
def changed(self, channel = None, *args): |
61 |
"""Set the modified flag and optionally issue a message |
62 |
|
63 |
The message is issued on the channel given by channel with args |
64 |
as the arguments. If channel is None issue no message. |
65 |
|
66 |
Subclasses should call this method whenever anything has |
67 |
changed. |
68 |
""" |
69 |
self.modified = 1 |
70 |
if channel is not None: |
71 |
self.issue(channel, *args) |