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

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/Model/scalebar.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 853 - (hide annotations)
Wed May 7 18:23:58 2003 UTC (21 years, 10 months ago) by frank
Original Path: trunk/thuban/Thuban/Model/scalebar.py
File MIME type: text/x-python
File size: 1764 byte(s)
New, scalebar rendering.

1 frank 853 # 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    
12     from wxPython.wx import *
13    
14     class ScaleBar:
15    
16     def __init__(self, map):
17     self.map = map
18    
19     def DrawScalebar(self, scale, dc):
20     """Draw a scalebar on a given DC"""
21    
22     # Get the dimension
23     width, height = dc.GetSizeTuple()
24     l1width, l1height = dc.GetTextExtent("%d"%0)
25    
26     # Make a first guess for the length (to get the size we have to reserve
27     # for the labels)
28     length, unit = self.__deriveLength(width, scale)
29     l2width, l2height = dc.GetTextExtent("%d %s"%(length,unit))
30     width = width - 4.0 - l1width/2.0 -l2width/2.0
31    
32     # Having precised the width now the final length can be calculated
33     length, unit = self.__deriveLength(width, scale)
34    
35     # We draw 2 rectangles with half the width
36     width = int(width/2)
37    
38     brush = wxBrush(wxWHITE, wxSOLID)
39     dc.SetBrush(brush)
40     dc.DrawRectangle(4,2,width,8)
41    
42     brush = wxBrush(wxBLACK, wxSOLID)
43     dc.SetBrush(brush)
44     dc.DrawRectangle(width+4,2,width,8)
45    
46     dc.DrawText("%d"%0, 4 - l1width/2, 12)
47    
48     l2width, l2height = dc.GetTextExtent("%d %s"%(length, unit))
49     dc.DrawText("%d %s"%(length, unit), 2*width+4 - l2width/2, 12)
50    
51     def __deriveLength(self, width, scale):
52    
53     length = width / scale
54    
55     if length / 1000 > 1:
56     length = int(length / 1000)
57     unit = 'km'
58     else:
59     length = int(length)
60     unit = 'm'
61    
62     return length, unit

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26