source: SHX/trunk/SeismicHandler/modules/screen_x.py @ 1224

Revision 1224, 4.7 KB checked in by klaus, 3 years ago (diff)

first test with fastx

Line 
1# -*- coding: utf-8 -*-
2
3#    This file is part of Seismic Handler eXtended (SHX). For terms of use and
4#    license information please see license.txt and visit
5#    http://www.seismic-handler.org/portal/wiki/Shx/LicenseTerms
6
7"""
8This class handles all "screen" related information, like length, etc.
9"""
10
11from SeismicHandler.basics import Singleton
12from SeismicHandler.basics.messages import subscribe_event, log_message #, \
13from SeismicHandler.config import get_runtime, set_runtime
14from SeismicHandler.core import Traces
15from SeismicHandler.basics.error import ShxError
16from SeismicHandler.basics.threads import ShxThread
17import fastx
18
19class Screen(object):
20    __metaclass__ = Singleton
21    __init = False
22
23    def __init__(self):
24        if not self.__init:
25            self.setup()
26
27    def setup(self):
28        subscribe_event(self.redraw, 'redraw')
29        log_message("debug.screen", "init")
30        self.__init = True
31
32    @staticmethod
33    def redraw(payload=None):
34        """
35        Called on each redraw event. Calculate extend of traces.
36        """
37        print "xscreen.redraw called"
38        pass
39        #if len(Traces) == 0:
40        #    return
41        #
42        #t = Traces[0]
43        #lo = t.get_info("t-origin")
44        #length = t.get_info("endtime") - t.get_info("starttime")
45        #hi = lo + length
46        #
47        #for t in Traces[1:]:
48        #    tlo = t.get_info("t-origin")
49        #    if tlo < lo:
50        #        lo = tlo
51        #
52        #    length = t.get_info("endtime") - t.get_info("starttime")
53        #    thi = tlo + length
54        #    if thi > hi:
55        #        hi = thi
56        #
57        #set_runtime("extend", (lo, hi))
58
59    @staticmethod
60    def timewdw():
61        """
62        Returns current display extend with respect to time window setting.
63        """
64        s, e = get_runtime("extend")
65        s1, e1 = get_runtime("timewindow", (0., None))
66
67        if e1 == None:
68            s1 = s
69            e1 = e
70
71        return (s1, e1)
72
73
74class WindowManager(object):
75    """
76    Holds list of windows.
77    """
78    __metaclass__ = Singleton
79    wlist = {}
80
81    def create(self, wid, x, y, width, height, traces=False, pixelunits=False):
82        if wid in self.wlist:
83            log_message(
84                "warning.WindowManager",
85                ("Attempt to open window twice, cancelled.\n"
86                 "\t Maybe you want to run 'wdw delete %s'\n"
87                 "\t (this information is only shown once.)") % wid
88            )
89            return
90
91        if not traces:
92            raise ShxError("SHX supports only trace windows.")
93
94        w = TracePlotter( [x, y, width, height], pixelunits=pixelunits )
95
96        # remember instance
97        self.wlist[wid] = w
98
99        # start thread
100        w.start()
101
102    def delete(self, wid):
103        try:
104            window = self.wlist.pop(wid)
105        except:
106            return
107
108        window.stop()
109
110    def top(self, wid):
111        """Documentation"""
112        pass
113
114    def size(self, wid):
115        """Documentation"""
116        pass
117
118
119class TracePlotter(ShxThread):
120    """
121    Encapsulates traces plotting on display. Bound to "redraw" event so that
122    any changes will be reflected instantly.
123    """
124
125    def __init__(self, dimension, auto_redraw=True, pixelunits=False ):
126        ShxThread.__init__(self)
127
128        self.name = "TracePlotter"
129        self.redraw = False
130        self.dimensions = dimension
131        self.pixelunits = pixelunits
132
133        if auto_redraw:
134            subscribe_event(self.trigger_redraw, 'redraw')
135
136        log_message("debug.traceplotter", "init")
137
138    def trigger_redraw(self, payload=None):
139        if not self.isAlive():
140            return
141
142        if get_runtime("rdnr", 0) > 0:
143            return
144
145        # this will fire the redraw event
146        #wx.CallAfter(self.plotter.redraw)
147        print "should trigger redraw"
148
149    #@anythread
150    def stop(self):
151        """
152        Exit main loop of wx.
153        """
154        if self.isAlive():
155            self.fastx.close_window( 1 )
156        super(TracePlotter, self).stop()
157
158    def setup(self):
159        log_message("debug.traceplotter", "init x app")
160
161        self.fastx = fastx.FastX()
162
163        # original SH calculates uses always 75 dpi
164        # now using true DPI values
165        if self.pixelunits:
166            width = int( self.dimensions[2] )
167            height = int( self.dimensions[3] )
168            posx = int( self.dimensions[0] )
169            posy = int( self.dimensions[1] )
170        else:
171            print "not supported"
172            exit()
173
174        self.fastx.open_window( 1, posx, posy, width, height )
175
176    def run(self):
177        # override, no standard ShxThread behaviour
178        log_message("debug.traceplotter", "start x main loop")
179        self.fastx.event_loop()
180
181Screen()
Note: See TracBrowser for help on using the repository browser.