1 |
# Copyright (c) 2001, 2002 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
6 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
8 |
""" |
""" |
9 |
Various base classes that didn't fir elsewhere |
Various base classes that did not fit elsewhere. |
10 |
""" |
""" |
11 |
|
|
12 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
13 |
|
|
14 |
from Thuban.Lib.connector import Publisher |
from Thuban.Lib.connector import Publisher |
15 |
|
|
16 |
from messages import TITLE_CHANGED |
from messages import TITLE_CHANGED, CHANGED |
17 |
|
|
18 |
class TitledObject: |
class TitledObject: |
19 |
|
|
27 |
|
|
28 |
def SetTitle(self, title): |
def SetTitle(self, title): |
29 |
self.title = title |
self.title = title |
|
self.issue(TITLE_CHANGED, self) |
|
30 |
|
|
31 |
|
# FIXME: The TitledObject is almost always used in conjunction |
32 |
|
# with Modifiable (the only exceptions currently are the |
33 |
|
# tables). We should reall derive TitledObject from modifiable |
34 |
|
# (would be good for the tables too) but that's taking things a |
35 |
|
# bit far at the moment. |
36 |
|
if hasattr(self, 'changed'): |
37 |
|
self.changed(TITLE_CHANGED, self) |
38 |
|
|
39 |
class Modifiable(Publisher): |
class Modifiable(Publisher): |
40 |
|
|
48 |
return self.modified |
return self.modified |
49 |
|
|
50 |
def UnsetModified(self): |
def UnsetModified(self): |
51 |
"""Unset the modified flag""" |
"""Unset the modified flag. |
52 |
|
|
53 |
|
If the modified flag is changed from set to unset by the call, |
54 |
|
issue a CHANGED message. |
55 |
|
|
56 |
|
The modified flag itself is part of the state of the object so |
57 |
|
some other objects such as a field in the status bar indication |
58 |
|
whether e.g. the session has changed might be interested in |
59 |
|
being notified when this flag has changed. |
60 |
|
""" |
61 |
|
was_modified = self.modified |
62 |
self.modified = 0 |
self.modified = 0 |
63 |
|
if was_modified: |
64 |
|
self.issue(CHANGED) |
65 |
|
|
66 |
def changed(self, channel = None, *args): |
def changed(self, channel = None, *args): |
67 |
"""Set the modified flag and issue a message |
"""Set the modified flag and optionally issue a message |
68 |
|
|
69 |
The message is issued on the channel given by channel with args |
The message is issued on the channel given by channel with args |
70 |
as the arguments. |
as the arguments. If channel is None issue no message. |
71 |
|
|
72 |
Subclasses should call this method whenever anything has |
Subclasses should call this method whenever anything has |
73 |
changed. |
changed. |