Changeset 892


Ignore:
Timestamp:
12/20/2012 06:00:27 PM (11 years ago)
Author:
marcus
Message:
  • support for screen margins
Location:
SHX/trunk/SeismicHandler
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • SHX/trunk/SeismicHandler/basics/messages.py

    r887 r892  
    1313import time 
    1414from SeismicHandler.utils.pubsub import pub 
     15from SeismicHandler.basics.tools import AttributeBlock 
    1516 
    1617# shortcut 
     
    156157    """ 
    157158    styles = get_runtime("styles") 
     159    block = block.upper() 
    158160 
    159     if item is None: 
    160         styles[block.upper()] = value 
     161    if block in styles.keys(): 
     162        if item is None: 
     163            styles[block] = value 
     164        else: 
     165            styles[block.upper()][item.upper()] = value 
     166        set_runtime("styles", styles) 
    161167    else: 
    162         styles[block.upper()][item.upper()] = value 
    163     set_runtime("styles", styles) 
     168        # build attribute block 
     169        attribs = get_runtime("attrib") 
     170        kwargs = {item: value} 
     171        a = attribs.get(block, AttributeBlock(**kwargs)) 
     172        attribs[block.upper()] = a 
     173        set_runtime("attrib", attribs) 
    164174 
    165175def get_style(block, item=None): 
     
    169179    styles = get_runtime("styles") 
    170180 
     181    if block.upper() not in styles.keys(): 
     182        styles = get_runtime("attrib") 
     183 
    171184    if item is None: 
    172185        return styles[block.upper()] 
  • SHX/trunk/SeismicHandler/basics/tools.py

    r891 r892  
    3030 
    3131 
    32 class Attrib(object): 
     32class AttributeBlock(object): 
     33    lstyles = ["Solid", "ShortDash", "LongDash", "DotDash", "Dot"] 
    3334    def __init__(self, **kwargs): 
    3435        """ 
    3536        Style attribute class. Used in command "FCT SETSTYLE" 
    3637        """ 
    37         self.lstyles = ["Solid", "ShortDash", "LongDash", "DotDash", "Dot"] 
    38  
    3938        attrib = AttribDict() 
    4039        # set defaults 
    41         attrib.charheight = 8 
     40        attrib.charsize = 0.012 
    4241        attrib.color = [0, 0, 0] 
    4342        attrib.font = "default" 
     
    4746        # override with new values 
    4847        for k in kwargs: 
    49             k = k.lower() 
    50             if k not in attrib: 
     48            kl = k.lower() 
     49            if kl not in attrib.keys(): 
    5150                raise NameError("invalid style attribute") 
    5251 
    5352            v = kwargs[k] 
    54             if v.is_integer(): 
     53            if v.isdigit(): 
    5554                v = int(v) 
    56             elif v.isnumeric(): 
    57                 v = float(v) 
    58             attrib[k] = v 
     55            else: 
     56                try: 
     57                    v = float(v) 
     58                except: 
     59                    pass 
     60            attrib[kl] = v 
    5961 
    6062        self.style = attrib 
  • SHX/trunk/SeismicHandler/config/runtime.py

    r887 r892  
    105105        # styles 
    106106        "RUNTIME:styles": { 
    107             "TITLE": {}, 
    108             "TRCINFO": {}, 
    109             "TIMEAXIS": {}, 
    110             "MARK": {}, 
    111             "ZEROTRCSTYLE": {}, 
    112             "PM": {}, 
    113             "MARGINS": [0, 0, 0, 0], 
     107            "MARGINS": [0.1, 0.1, 0.4, 0.15], 
    114108        }, 
     109        # attribute blocks 
     110        "RUNTIME:attrib": {} 
    115111    }) 
    116112 
  • SHX/trunk/SeismicHandler/modules/parse.py

    r781 r892  
    639639        "TOTTRCS": "_internalvars", 
    640640        "STATUS": "_internalvars", 
    641         "TITLESTYLE": "TITLE", 
    642         "TRCINFOSTYLE": "TRCINFO", 
    643         "TIMEAXISSTYLE": "TIMEAXIS", 
    644         "MARKSTYLE": "MARK", 
    645         "ZEROTRCSTYLE": "ZEROTRCSTYLE", 
    646         "PMSTYLE": "PM", 
     641        "TITLESTYLE": '8', 
     642        "TRCINFOSTYLE": '9', 
     643        "TIMEAXISSTYLE": '7', 
     644        "MARKSTYLE": '6', 
     645        "ZEROTRCSTYLE": '8', 
     646        "PMSTYLE": '5', 
    647647 
    648648        # XXX todo 
  • SHX/trunk/SeismicHandler/modules/wx_.py

    r890 r892  
    1818# width of station info 
    1919STATION_INFO = 85 
    20 # margin at end of trace 
    21 MARGIN = 15 
     20# margins (top, right, bottom, left) 
     21MARGINS = [10, 10, 10, 10] 
    2222# space for time-scale 
    2323TIMESCALE = 40 
     
    6161        self.phasename = "P" 
    6262        self.space = None 
    63         self.interactive = "time_trace" 
     63        self.interactive = "trace_time" 
    6464 
    6565        self._setup() 
     
    344344        # horizontal 
    345345        if self.traceOrder in [0, 1]: 
    346             pixel_width = self.width - STATION_INFO - MARGIN 
     346            pixel_width = self.width - STATION_INFO - MARGINS[1] - MARGINS[3] 
    347347        # vertical 
    348348        elif self.traceOrder in [2, 3]: 
    349             pixel_width = self.height - STATION_INFO - MARGIN 
     349            pixel_width = self.height - STATION_INFO - MARGINS[0] - MARGINS[2] 
    350350 
    351351        # horizontal plotting 
    352352        if self.traceOrder in [0, 1]: 
     353            timepos -= STATION_INFO + MARGIN[1] 
     354        # vertical plotting 
     355        elif self.traceOrder == 2: 
     356            if self.relativeAxis: 
     357                timepos -= length + MARGINS[0] 
     358            else: 
     359                timepos -= pixel_width + MARGINS[0] 
     360            timepos *= -1 
     361        elif self.traceOrder == 3: 
    353362            timepos -= STATION_INFO 
     363 
     364        if self.timewindow[1] is None: 
     365            duration = self.relend - self.relstart 
     366            start = self.relstart 
     367        else: 
     368            duration = self.timewindow[1] - self.timewindow[0] 
     369            start = self.timewindow[0] 
     370 
     371        t = timepos * duration / pixel_width + start 
     372 
     373        return t 
     374 
     375 
     376    def ScreenToTraceAndTime(self, x, y): 
     377        """ 
     378        Returns trace instance and time code derived from cursor 
     379        position inside graphical panel. 
     380        """ 
     381        x, y = self.CalcUnscrolledPosition((x,y)) 
     382        # horizontal display 
     383        if self.traceOrder in [0, 1]: 
     384            tracepos, timepos = y, x 
     385        # vertical display 
     386        elif self.traceOrder in [2, 3]: 
     387            tracepos, timepos = x, y 
     388 
     389        # get trace under cursor 
     390        trace = None 
     391        theight = self.traceheight // 2 
     392        for t in self.traces: 
     393            if tracepos >= t.shx.midpoint - theight and \ 
     394                                          tracepos <= t.shx.midpoint + theight: 
     395                trace = t 
     396                break 
     397 
     398        # get time code 
     399        if trace and self.relativeAxis: 
     400            start = trace.stats.starttime 
     401            end = trace.stats.endtime 
     402            pixel_width = trace.shx.PlotPixels 
     403            # only needed for vertical plotting 
     404            length = self.height - STATION_INFO - MARGINS[0] - MARGINS[2] 
     405        else: 
     406            # global time axis 
     407            start = self.start 
     408            end = self.end 
     409            # horizontal 
     410            if self.traceOrder in [0, 1]: 
     411                pixel_width = self.width - STATION_INFO - MARGINS[1] - MARGINS[3] 
     412            # vertical 
     413            elif self.traceOrder in [2, 3]: 
     414                pixel_width = self.height - STATION_INFO - MARGINS[0] - MARGINS[2] 
     415 
     416        duration = end - start 
     417        timestamp = None 
     418 
     419        # horizontal plotting 
     420        if self.traceOrder in [0, 1]: 
     421            timepos -= STATION_INFO + MARGINS[3] 
    354422        # vertical plotting 
    355423        elif self.traceOrder == 2: 
     
    362430            timepos -= STATION_INFO 
    363431 
    364         if self.timewindow[1] is None: 
    365             duration = self.relend - self.relstart 
    366             start = self.relstart 
    367         else: 
    368             duration = self.timewindow[1] - self.timewindow[0] 
    369             start = self.timewindow[0] 
    370  
    371         t = timepos * duration / pixel_width + start 
    372  
    373         return t 
    374  
    375  
    376     def ScreenToTraceAndTime(self, x, y): 
    377         """ 
    378         Returns trace instance and time code derived from cursor 
    379         position inside graphical panel. 
    380         """ 
    381         x, y = self.CalcUnscrolledPosition((x,y)) 
    382         # horizontal display 
    383         if self.traceOrder in [0, 1]: 
    384             tracepos, timepos = y, x 
    385         # vertical display 
    386         elif self.traceOrder in [2, 3]: 
    387             tracepos, timepos = x, y 
    388  
    389         # get trace under cursor 
    390         trace = None 
    391         theight = self.traceheight // 2 
    392         for t in self.traces: 
    393             if tracepos >= t.shx.midpoint - theight and \ 
    394                                           tracepos <= t.shx.midpoint + theight: 
    395                 trace = t 
    396                 break 
    397  
    398         # get time code 
    399         if trace and self.relativeAxis: 
    400             start = trace.stats.starttime 
    401             end = trace.stats.endtime 
    402             pixel_width = trace.shx.PlotPixels 
    403             # only needed for vertical plotting 
    404             length = self.height - STATION_INFO - MARGIN 
    405         else: 
    406             # global time axis 
    407             start = self.start 
    408             end = self.end 
    409             # horizontal 
    410             if self.traceOrder in [0, 1]: 
    411                 pixel_width = self.width - STATION_INFO - MARGIN 
    412             # vertical 
    413             elif self.traceOrder in [2, 3]: 
    414                 pixel_width = self.height - STATION_INFO - MARGIN 
    415  
    416         duration = end - start 
    417         timestamp = None 
    418  
    419         # horizontal plotting 
    420         if self.traceOrder in [0, 1]: 
    421             timepos -= STATION_INFO 
    422         # vertical plotting 
    423         elif self.traceOrder == 2: 
    424             if self.relativeAxis: 
    425                 timepos -= length + MARGIN 
    426             else: 
    427                 timepos -= pixel_width + MARGIN 
    428             timepos *= -1 
    429         elif self.traceOrder == 3: 
    430             timepos -= STATION_INFO 
    431  
    432432        t = timepos * duration / pixel_width 
    433433        timestamp = start + t 
     
    459459            # horizontal 
    460460            if self.traceOrder in [0, 1]: 
    461                 pixel_width = self.width - STATION_INFO - MARGIN 
     461                pixel_width = self.width - STATION_INFO - MARGINS[1] - MARGINS[3] 
    462462            # vertical 
    463463            elif self.traceOrder in [2, 3]: 
    464                 pixel_width = self.height - STATION_INFO - MARGIN 
     464                pixel_width = self.height - STATION_INFO - MARGINS[0] - MARGINS[2] 
    465465 
    466466        # relative position inside trace window 
     
    469469        # horizontal 
    470470        if self.traceOrder in [0, 1]: 
    471             x, y = self.CalcScrolledPosition( 
    472                                    (relpos + STATION_INFO, trace.shx.midpoint)) 
     471            x, y = self.CalcScrolledPosition(( 
     472                relpos + STATION_INFO + MARGINS[1] + MARGINS[3], 
     473                trace.shx.midpoint 
     474            )) 
    473475        # vertical 
    474476        elif self.traceOrder == 2: 
     
    636638        if self.traceOrder in [0, 1]: 
    637639            if numTraces: 
    638                 theight = (height - TIMESCALE) // numTraces 
     640                theight = (height - TIMESCALE - MARGINS[0] - MARGINS[2]) // numTraces 
    639641            else: 
    640642                theight = height - TIMESCALE 
    641             pltwidth = width - STATION_INFO - MARGIN 
     643            pltwidth = width - STATION_INFO - MARGINS[1] - MARGINS[3] 
    642644        elif self.traceOrder in [2, 3]: 
    643645            if numTraces: 
    644                 theight = (width - TIMESCALE) // numTraces 
     646                theight = (width - TIMESCALE - MARGINS[1] - MARGINS[3]) // numTraces 
    645647            theight = width - TIMESCALE 
    646             pltwidth = height - STATION_INFO - MARGIN 
     648            pltwidth = height - STATION_INFO - MARGINS[0] - MARGINS[2] 
    647649        else: 
    648650            raise ValueError("unknown trace order %d" % self.traceorder) 
     
    733735            # copy trace picture to canvas 
    734736            if self.traceOrder in [0, 1]: 
    735                 canvas.Blit(plotoffset + STATION_INFO, i * theight, pltwidth, 
    736                                                  theight, buffer, 0, 0, wx.AND) 
     737                canvas.Blit( 
     738                    plotoffset + STATION_INFO + MARGINS[3],  
     739                    i * theight + MARGINS[0],  
     740                    pltwidth, 
     741                    theight, 
     742                    buffer, 
     743                    0, 
     744                    0, 
     745                    wx.AND 
     746                ) 
    737747            elif self.traceOrder == 2: 
    738748                canvas.Blit(i * theight, -plotoffset + MARGIN, theight, 
     
    754764            # helper lines for debugging 
    755765            w, h, _, _ = canvas.GetFullTextExtent(txt) 
    756             t.shx.midpoint = tmp = i * theight + theight//2 
     766            t.shx.midpoint = tmp = i * theight + theight//2 + MARGINS[0] 
    757767            if self.traceOrder in [0, 1]: 
    758                 canvas.DrawText(txt, 5, tmp - h // 2) 
    759                 canvas.DrawLine(STATION_INFO, tmp, width - MARGIN, tmp) 
     768                canvas.DrawText(txt, 5 + MARGINS[3], tmp - h // 2) 
     769                canvas.DrawLine(STATION_INFO + MARGINS[3], tmp, width - MARGINS[1], tmp) 
    760770#                canvas.SetPen(wx.Pen('Red', 1, wx.LONG_DASH)) 
    761771#                canvas.DrawLine(STATION_INFO, tmp + theight // 2, 
     
    790800        if self.traceOrder in [0, 1]: 
    791801            PARTS = 5.  # axis split into X parts 
    792             length = width - MARGIN - STATION_INFO  # pixel length of time axis 
    793             fixpos = height - TIMESCALE + 10  # here: y coordinate 
    794             varpos_start = STATION_INFO # here: x start 
     802            length = width - MARGINS[1] - MARGINS[3] - STATION_INFO  # pixel length of time axis 
     803            fixpos = height - TIMESCALE - MARGINS[2]  # here: y coordinate 
     804            varpos_start = STATION_INFO + MARGINS[3] # here: x start 
    795805        elif self.traceOrder in [2, 3]: 
    796806            PARTS = 4. 
Note: See TracChangeset for help on using the changeset viewer.