1 |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jonathan Coles <[email protected]> |
4 |
|
# Frank Koormann <[email protected]> |
5 |
# |
# |
6 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
7 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
16 |
|
|
17 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
18 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
|
from Thuban.Model.messages import * |
|
19 |
from Thuban.Model.classification import ClassGroup |
from Thuban.Model.classification import ClassGroup |
20 |
|
|
21 |
from Thuban.UI.messages import * |
from Thuban.Model.messages import \ |
22 |
|
MAP_STACKING_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED, LAYER_CHANGED,\ |
23 |
|
LAYER_VISIBILITY_CHANGED, TITLE_CHANGED |
24 |
|
|
25 |
|
from Thuban.UI.messages import SCALE_CHANGED |
26 |
|
|
27 |
from Thuban.UI.classifier import ClassDataPreviewer |
from Thuban.UI.classifier import ClassDataPreviewer |
28 |
from Thuban.UI.dock import DockPanel |
from Thuban.UI.dock import DockPanel |
29 |
|
from Thuban.UI.scalebar import ScaleBar |
30 |
|
|
31 |
from Thuban.Lib.connector import ConnectorError |
from Thuban.Lib.connector import ConnectorError |
32 |
|
|
95 |
|
|
96 |
panelBox.Add(self.tree, 1, wxGROW, 0) |
panelBox.Add(self.tree, 1, wxGROW, 0) |
97 |
|
|
98 |
|
self.scalebarbitmap = ScaleBarBitmap(self, map, mainWindow) |
99 |
|
panelBox.Add(self.scalebarbitmap, 0, wxGROW, 0) |
100 |
|
|
101 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
102 |
self.SetSizer(panelBox) |
self.SetSizer(panelBox) |
103 |
panelBox.SetSizeHints(self) |
panelBox.SetSizeHints(self) |
117 |
|
|
118 |
def SetMap(self, map): |
def SetMap(self, map): |
119 |
self.tree.SetMap(map) |
self.tree.SetMap(map) |
120 |
|
self.scalebarbitmap.SetCanvas(self.mainWindow.canvas) |
121 |
|
|
122 |
def DoOnSelChanged(self, layer, group): |
def DoOnSelChanged(self, layer, group): |
123 |
|
|
226 |
#self._OnMsgMapsChanged) |
#self._OnMsgMapsChanged) |
227 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
228 |
|
|
|
|
|
229 |
def MoveCurrentItemUp(self): |
def MoveCurrentItemUp(self): |
230 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
231 |
|
|
255 |
else: |
else: |
256 |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
257 |
|
|
|
|
|
258 |
def DoOnShowLayer(self): |
def DoOnShowLayer(self): |
259 |
#self.__ShowHideLayer(True) |
#self.__ShowHideLayer(True) |
260 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
459 |
self.__SetVisibilityStyle(visible, id) |
self.__SetVisibilityStyle(visible, id) |
460 |
id, cookie = self.GetNextChild(parent, cookie) |
id, cookie = self.GetNextChild(parent, cookie) |
461 |
|
|
462 |
|
class ScaleBarBitmap(wxBoxSizer): |
463 |
|
|
464 |
|
def __init__(self, parent, map, mainWindow): |
465 |
|
# While the width is fixed, get the height _now_. |
466 |
|
dc = wxMemoryDC() |
467 |
|
textwidth, textheight = dc.GetTextExtent("%d"%0) |
468 |
|
self.width = 200 |
469 |
|
self.height = textheight + 3*2 + 8 |
470 |
|
|
471 |
|
wxBoxSizer.__init__(self, wxVERTICAL) |
472 |
|
bmp=wxEmptyBitmap(self.width, self.height) |
473 |
|
self.scalebarBitmap = wxStaticBitmap(parent, -1, bmp) |
474 |
|
self.Add(self.scalebarBitmap, 0, wxALIGN_CENTER|wxLEFT|wxTOP|wxRIGHT, 1) |
475 |
|
|
476 |
|
self.mainWindow = mainWindow |
477 |
|
self.parent = parent |
478 |
|
self.canvas = None |
479 |
|
self.SetCanvas(self.mainWindow.canvas) |
480 |
|
|
481 |
|
def SetCanvas(self, canvas): |
482 |
|
sub_list = [(SCALE_CHANGED, self._OnMsgScaleChanged)] |
483 |
|
|
484 |
|
if self.canvas is not None: |
485 |
|
for msg, func in sub_list: self.canvas.Unsubscribe(msg, func) |
486 |
|
|
487 |
|
self.canvas = canvas |
488 |
|
self.scalebar = ScaleBar(canvas.map) |
489 |
|
|
490 |
|
if self.canvas is not None: |
491 |
|
for msg, func in sub_list: self.canvas.Subscribe(msg, func) |
492 |
|
self.__SetScale(self.canvas.scale) |
493 |
|
|
494 |
|
def _OnMsgScaleChanged(self, scale): |
495 |
|
self.__SetScale(scale) |
496 |
|
|
497 |
|
def __SetScale(self, scale): |
498 |
|
bmp = wxEmptyBitmap(self.width, self.height) |
499 |
|
dc = wxMemoryDC() |
500 |
|
dc.SelectObject(bmp) |
501 |
|
dc.Clear() |
502 |
|
|
503 |
|
self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple()) |
504 |
|
|
505 |
|
self.scalebarBitmap.SetBitmap(bmp) |
506 |
|
|