forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusbar.py
125 lines (93 loc) · 3.61 KB
/
statusbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
@package gcp.statusbar
@brief Classes for statusbar management in GCP Manager
Classes:
- statusbar::SbRMSError
- statusbar::SbGoToGCP
(C) 2012-2013 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@author Vaclav Petras <wenzeslaus gmail.com> (statusbar refactoring)
@author Anna Kratochvilova <kratochanna gmail.com> (statusbar refactoring)
"""
import wx
from core.gcmd import GMessage
from mapdisp.statusbar import SbItem, SbTextItem
from gui_core.wrap import SpinCtrl
class SbGoToGCP(SbItem):
"""SpinCtrl to select GCP to focus on
Requires MapFrame.GetSrcWindow, MapFrame.GetTgtWindow,
MapFrame.GetListCtrl, MapFrame.GetMapCoordList.
"""
def __init__(self, mapframe, statusbar, position=0):
SbItem.__init__(self, mapframe, statusbar, position)
self.name = "gotoGCP"
self.label = _("Pan to GCP by number")
self.widget = SpinCtrl(parent=self.statusbar, id=wx.ID_ANY, value="", min=0)
self.widget.Hide()
self.widget.Bind(wx.EVT_TEXT_ENTER, self.OnGoToGCP)
self.widget.Bind(wx.EVT_SPINCTRL, self.OnGoToGCP)
def OnGoToGCP(self, event):
"""Zooms to given GCP."""
gcpNumber = self.GetValue()
mapCoords = self.mapFrame.GetMapCoordList()
# always false, spin checks it
if gcpNumber < 0 or gcpNumber > len(mapCoords):
GMessage(
parent=self, message="%s 1 - %s." % (_("Valid Range:"), len(mapCoords))
)
return
if gcpNumber == 0:
return
listCtrl = self.mapFrame.GetListCtrl()
listCtrl.selectedkey = gcpNumber
listCtrl.selected = listCtrl.FindItem(-1, gcpNumber)
listCtrl.render = False
listCtrl.SetItemState(
listCtrl.selected, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED
)
listCtrl.render = True
listCtrl.EnsureVisible(listCtrl.selected)
srcWin = self.mapFrame.GetSrcWindow()
tgtWin = self.mapFrame.GetTgtWindow()
# Source MapWindow:
begin = (mapCoords[gcpNumber][1], mapCoords[gcpNumber][2])
begin = srcWin.Cell2Pixel(begin)
end = begin
srcWin.Zoom(begin, end, 0)
# redraw map
srcWin.UpdateMap()
if self.mapFrame.GetShowTarget():
# Target MapWindow:
begin = (mapCoords[gcpNumber][3], mapCoords[gcpNumber][4])
begin = tgtWin.Cell2Pixel(begin)
end = begin
tgtWin.Zoom(begin, end, 0)
# redraw map
tgtWin.UpdateMap()
self.GetWidget().SetFocus()
def Update(self):
"""Checks the number of items in the gcp list
and sets the spin limits accordingly."""
self.statusbar.SetStatusText("")
maximum = self.mapFrame.GetListCtrl().GetItemCount()
maximum = max(maximum, 1)
self.widget.SetRange(0, maximum)
self.Show()
# disable long help
self.mapFrame.StatusbarEnableLongHelp(False)
class SbRMSError(SbTextItem):
"""Shows RMS error.
Requires MapFrame.GetFwdError, MapFrame.GetBkwError.
"""
def __init__(self, mapframe, statusbar, position=0):
SbTextItem.__init__(self, mapframe, statusbar, position)
self.name = "RMSError"
self.label = _("RMS error")
def Show(self):
"""Shows the RMS errors."""
self.SetValue(
_("Forward: %(forw)s, Backward: %(back)s")
% {"forw": self.mapFrame.GetFwdError(), "back": self.mapFrame.GetBkwError()}
)
SbTextItem.Show(self)