/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/scalebar.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/scalebar.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 866 by frank, Thu May 8 13:40:32 2003 UTC revision 912 by frank, Fri May 16 16:24:44 2003 UTC
# Line 8  Line 8 
8  __version__ = "$Revision$"  __version__ = "$Revision$"
9    
10  from Thuban import _  from Thuban import _
11  from Thuban.Model.scalebar import *  from Thuban.Model.scalebar import deriveInterval, roundInterval
12    
13  from wxPython.wx import *  from wxPython.wx import *
14    
# Line 17  class ScaleBar: Line 17  class ScaleBar:
17      def __init__(self, map):      def __init__(self, map):
18          self.map = map          self.map = map
19    
20      def DrawScalebar(self, scale, dc):      def DrawScaleBar(self, scale, dc, position, size):
21          """Draw a scalebar on a given DC"""          """Draw a scalebar on a given DC"""
22    
23          # Only draw a legend if the corresponding map has a layer          # Only draw a legend if the corresponding map has a layer
# Line 35  class ScaleBar: Line 35  class ScaleBar:
35                  BlackText = wxBLACK                  BlackText = wxBLACK
36                                    
37              # Get the dimension              # Get the dimension
38              width, height = dc.GetSizeTuple()              width, height = size
39                posx, posy    = position
40              l1width, l1height = dc.GetTextExtent("%d"%0)              l1width, l1height = dc.GetTextExtent("%d"%0)
41    
42              # Make a first guess for the interval (to get the size we have              # Make a first guess for the interval (to get the size we have
# Line 48  class ScaleBar: Line 49  class ScaleBar:
49              interval, unit  = deriveInterval(width, scale)              interval, unit  = deriveInterval(width, scale)
50              interval, label = roundInterval(interval)              interval, label = roundInterval(interval)
51                            
52              # We draw 2 rectangles with half the width              if interval > 0.0:
53              if unit == 'km':                  # We draw 2 rectangles with half the width
54                  width = int(interval*1000.0*scale/2)                  if unit == 'km':
55              else:                      width = int(interval*1000.0*scale/2)
56                  width = int(interval*scale/2)                  else:
57                        width = int(interval*scale/2)
58                            
59              dc.SetPen(BlackPen)                  dc.SetPen(BlackPen)
60    
61              brush = wxBrush(wxWHITE, wxSOLID)                  brush = wxBrush(wxWHITE, wxSOLID)
62              dc.SetBrush(brush)                  dc.SetBrush(brush)
63              dc.DrawRectangle(4,2,width,8)                  dc.DrawRectangle(posx+4,posy+2,width,8)
64    
65              dc.SetBrush(BlackBrush)                  dc.SetBrush(BlackBrush)
66              dc.DrawRectangle(width+4,2,width,8)                  dc.DrawRectangle(posx+width+4,posy+2,width,8)
67    
68              dc.SetTextForeground(BlackText)                  dc.SetTextForeground(BlackText)
69              dc.DrawText("%d"%0, 4 - l1width/2, 12)                  dc.DrawText("%d"%0, posx+ 4 - l1width/2, posy+12)
70    
71              l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit))                  l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit))
72              dc.DrawText("%s %s"%(interval, unit), 2*width+4 - l2width/2, 12)                  dc.DrawText("%s %s"%(interval, unit), posx+ 2*width+4 - l2width/2, posy + 12)
73    

Legend:
Removed from v.866  
changed lines
  Added in v.912

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26