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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 871 - (show annotations)
Fri May 9 08:33:29 2003 UTC (21 years, 10 months ago) by frank
Original Path: trunk/thuban/Thuban/UI/scalebar.py
File MIME type: text/x-python
File size: 2578 byte(s)
(DrawScaleBar): Draw only if interval > 0.0.

1 # Copyright (c) 2001, 2002 by Intevation GmbH
2 # Authors:
3 # Frank Koormann <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 __version__ = "$Revision$"
9
10 from Thuban import _
11 from Thuban.Model.scalebar import deriveInterval, roundInterval
12
13 from wxPython.wx import *
14
15 class ScaleBar:
16
17 def __init__(self, map):
18 self.map = map
19
20 def DrawScalebar(self, scale, dc):
21 """Draw a scalebar on a given DC"""
22
23 # Only draw a legend if the corresponding map has a layer
24 if self.map is not None and len(self.map.layers) > 0 and scale > 0.0:
25
26 # If no projection is specified, the scale information _might_
27 # be reasonable. So gray out the scalebar in these cases.
28 if self.map.projection is None:
29 BlackPen = wxGREY_PEN
30 BlackBrush = wxGREY_BRUSH
31 BlackText = wxColor(127,127,127)
32 else:
33 BlackPen = wxBLACK_PEN
34 BlackBrush = wxBLACK_BRUSH
35 BlackText = wxBLACK
36
37 # Get the dimension
38 width, height = dc.GetSizeTuple()
39 l1width, l1height = dc.GetTextExtent("%d"%0)
40
41 # Make a first guess for the interval (to get the size we have
42 # to reserve for the labels)
43 interval, unit = deriveInterval(width, scale)
44 l2width, l2height = dc.GetTextExtent("%d %s"%(interval,unit))
45 width = width - 4.0 - l1width/2.0 -l2width/2.0
46
47 # Having precised the width now the final interval can be calculated
48 interval, unit = deriveInterval(width, scale)
49 interval, label = roundInterval(interval)
50
51 if interval > 0.0:
52 # We draw 2 rectangles with half the width
53 if unit == 'km':
54 width = int(interval*1000.0*scale/2)
55 else:
56 width = int(interval*scale/2)
57
58 dc.SetPen(BlackPen)
59
60 brush = wxBrush(wxWHITE, wxSOLID)
61 dc.SetBrush(brush)
62 dc.DrawRectangle(4,2,width,8)
63
64 dc.SetBrush(BlackBrush)
65 dc.DrawRectangle(width+4,2,width,8)
66
67 dc.SetTextForeground(BlackText)
68 dc.DrawText("%d"%0, 4 - l1width/2, 12)
69
70 l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit))
71 dc.DrawText("%s %s"%(interval, unit), 2*width+4 - l2width/2, 12)
72

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26