source: SHX/trunk/SeismicHandler/modules/traces.py @ 532

Revision 532, 2.5 KB checked in by marcus, 11 years ago (diff)
  • implemented DEL command
  • Property svn:eol-style set to native
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2008-2011 Marcus Walther (walther@szgrf.bgr.de)
4#
5# This file is part of Seismic Handler eXtended (SHX)
6# Full details can be found at project website http://www.seismic-handler.org/
7#
8# SHX is free software; you can redistribute it and/or modify
9# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
10# the Free Software Foundation; either version 3 of the License, or
11# (at your option) any later version.
12#
13# SHX is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
19# along with SHX (see license.txt); if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
21
22from obspy.core.util import AttribDict
23from SeismicHandler.basics import Singleton
24from SeismicHandler.basics.messages import logMessage, msgs
25from obspy.core.stream import Stream
26from SeismicHandler.config import Settings
27
28
29class Traces(object):
30    """
31    Supply access for two streams of traces. One is used for plotting, the other
32    holds hidden traces. This will be enhanced later, but for compatibility
33    reasons to existing command procedures it's done that way first.
34    """
35    __metaclass__ = Singleton
36
37    traces = AttribDict()
38
39    def __init__(self, *args, **kwargs):
40        self.traces.visible = Stream()
41        self.traces.hidden = Stream()
42
43    def __getattr__(self, name):
44        try:
45            return self.__class__.__dict__["traces"][name]
46        except:
47            raise AttributeError(name)
48
49    def addreplace(self, stream):
50        """
51        Adds or replaces visible streams depending on runtime setting.
52        """
53        # this is always a global switch!
54        if not Settings.swKeeptraces:
55            logMessage("debug.traces", "replacing visible traces")
56            self.traces.visible.clear()
57
58        self.traces.visible += stream
59        self.updateCounter()
60
61    def updateCounter(self):
62        dsptrcs = len(self.traces.visible)
63        hidtrcs = len(self.traces.hidden)
64        logMessage("debug.traces", "Now %u visible and %u hidden traces" % (
65                                                             dsptrcs, hidtrcs))
66
67        msgs.sendMessage('runtime', name="dsptrcs", value=dsptrcs)
68        msgs.sendMessage('runtime', name="tottrcs", value=dsptrcs+hidtrcs)
69
70
71if __name__ == "__main__":
72    pass
Note: See TracBrowser for help on using the repository browser.