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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
"""
@package psmap.toolbars
@brief wxPsMap toolbars classes
Classes:
- toolbars::PsMapToolbar
(C) 2007-2011 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 Anna Kratochvilova <kratochanna gmail.com>
"""
import sys
import wx
from gui_core.toolbars import BaseToolbar, BaseIcons
from icons.icon import MetaIcon
class PsMapToolbar(BaseToolbar):
def __init__(self, parent, toolSwitcher):
"""Toolbar Cartographic Composer (psmap.py)
:param parent: parent window
"""
BaseToolbar.__init__(self, parent, toolSwitcher)
# workaround for http://trac.wxwidgets.org/ticket/13888
if sys.platform == "darwin":
parent.SetToolBar(self)
self.InitToolbar(self._toolbarData())
self._default = self.pointer
for tool in (
self.pointer,
self.pan,
self.zoomin,
self.zoomout,
self.drawGraphics,
self.addMap,
):
self.toolSwitcher.AddToolToGroup(group="mouseUse", toolbar=self, tool=tool)
# custom button for graphics mode selection
# TODO: could this be somehow generalized?
self.arrowButton = self.CreateSelectionButton(tooltip=_("Select graphics tool"))
self.arrowButtonId = self.InsertControl(18, self.arrowButton)
self.arrowButton.Bind(wx.EVT_BUTTON, self.OnDrawGraphicsMenu)
self.drawGraphicsAction = None
self.OnAddPoint(event=None)
self.Realize()
from psmap.frame import havePILImage
if not havePILImage:
self.EnableTool(self.preview, False)
def _toolbarData(self):
"""Toolbar data"""
icons = {
"scriptSave": MetaIcon(
img="script-save",
label=_("Generate text file with mapping instructions"),
),
"scriptLoad": MetaIcon(
img="script-load", label=_("Load text file with mapping instructions")
),
"psExport": MetaIcon(
img="ps-export", label=_("Generate PostScript output")
),
"pdfExport": MetaIcon(img="pdf-export", label=_("Generate PDF output")),
"pageSetup": MetaIcon(
img="page-settings",
label=_("Page setup"),
desc=_("Specify paper size, margins and orientation"),
),
"fullExtent": MetaIcon(
img="zoom-extent", label=_("Full extent"), desc=_("Zoom to full extent")
),
"addMap": MetaIcon(
img="layer-add",
label=_("Map frame"),
desc=_("Click and drag to place map frame"),
),
"deleteObj": MetaIcon(
img="layer-remove", label=_("Delete selected object")
),
"preview": MetaIcon(img="execute", label=_("Show preview")),
"addText": MetaIcon(img="text-add", label=_("Text")),
"addMapinfo": MetaIcon(img="map-info", label=_("Map info")),
"addLegend": MetaIcon(img="legend-add", label=_("Legend")),
"addScalebar": MetaIcon(img="scalebar-add", label=_("Scale bar")),
"addImage": MetaIcon(img="image-add", label=_("Image")),
"addNorthArrow": MetaIcon(img="north-arrow-add", label=_("North Arrow")),
"pointAdd": MetaIcon(img="point-add", label=_("Point")),
"lineAdd": MetaIcon(img="line-add", label=_("Line")),
"rectangleAdd": MetaIcon(img="rectangle-add", label=_("Rectangle")),
"overlaysAdd": MetaIcon(img="layer-more", label=_("Add overlays")),
"labelsAdd": MetaIcon(img="layer-label-add", label=_("Add labels")),
}
self.icons = icons
return self._getToolbarData(
(
(
("loadFile", icons["scriptLoad"].label),
icons["scriptLoad"],
self.parent.OnLoadFile,
),
(
("instructionFile", icons["scriptSave"].label),
icons["scriptSave"],
self.parent.OnInstructionFile,
),
(None,),
(
("pagesetup", icons["pageSetup"].label),
icons["pageSetup"],
self.parent.OnPageSetup,
),
(None,),
(
("pointer", BaseIcons["pointer"].label),
BaseIcons["pointer"],
self.parent.OnPointer,
wx.ITEM_CHECK,
),
(
("pan", BaseIcons["pan"].label),
BaseIcons["pan"],
self.parent.OnPan,
wx.ITEM_CHECK,
),
(
("zoomin", BaseIcons["zoomIn"].label),
BaseIcons["zoomIn"],
self.parent.OnZoomIn,
wx.ITEM_CHECK,
),
(
("zoomout", BaseIcons["zoomOut"].label),
BaseIcons["zoomOut"],
self.parent.OnZoomOut,
wx.ITEM_CHECK,
),
(
("zoomAll", icons["fullExtent"].label),
icons["fullExtent"],
self.parent.OnZoomAll,
),
(None,),
(
("addMap", icons["addMap"].label),
icons["addMap"],
self.parent.OnAddMap,
wx.ITEM_CHECK,
),
(
("addRaster", BaseIcons["addRast"].label),
BaseIcons["addRast"],
self.parent.OnAddRaster,
),
(
("addVector", BaseIcons["addVect"].label),
BaseIcons["addVect"],
self.parent.OnAddVect,
),
(
("overlaysAdd", icons["overlaysAdd"].label),
icons["overlaysAdd"],
self.OnAddOverlays,
),
(
("delete", icons["deleteObj"].label),
icons["deleteObj"],
self.parent.OnDelete,
),
(
("dec", BaseIcons["overlay"].label),
BaseIcons["overlay"],
self.OnDecoration,
),
(
("drawGraphics", icons["pointAdd"].label),
icons["pointAdd"],
self.OnDrawGraphics,
wx.ITEM_CHECK,
),
(None,),
(
("preview", icons["preview"].label),
icons["preview"],
self.parent.OnPreview,
),
(
("generatePS", icons["psExport"].label),
icons["psExport"],
self.parent.OnPSFile,
),
(
("generatePDF", icons["pdfExport"].label),
icons["pdfExport"],
self.parent.OnPDFFile,
),
(None,),
(
("help", BaseIcons["help"].label),
BaseIcons["help"],
self.parent.OnHelp,
),
(
("quit", BaseIcons["quit"].label),
BaseIcons["quit"],
self.parent.OnCloseWindow,
),
)
)
def OnDecoration(self, event):
"""Decorations overlay menu"""
self._onMenu(
(
(self.icons["addLegend"], self.parent.OnAddLegend),
(self.icons["addMapinfo"], self.parent.OnAddMapinfo),
(self.icons["addScalebar"], self.parent.OnAddScalebar),
(self.icons["addText"], self.parent.OnAddText),
(self.icons["addImage"], self.parent.OnAddImage),
(self.icons["addNorthArrow"], self.parent.OnAddNorthArrow),
)
)
def OnAddOverlays(self, event):
self._onMenu(((self.icons["labelsAdd"], self.parent.OnAddLabels),))
def OnDrawGraphics(self, event):
"""Graphics tool activated."""
# we need the previous id
if self.drawGraphicsAction == "pointAdd":
self.parent.OnAddPoint(event)
elif self.drawGraphicsAction == "lineAdd":
self.parent.OnAddLine(event)
elif self.drawGraphicsAction == "rectangleAdd":
self.parent.OnAddRectangle(event)
def OnDrawGraphicsMenu(self, event):
"""Simple geometry features (point, line, rectangle) overlay menu"""
self._onMenu(
(
(self.icons["pointAdd"], self.OnAddPoint),
(self.icons["lineAdd"], self.OnAddLine),
(self.icons["rectangleAdd"], self.OnAddRectangle),
)
)
def OnAddPoint(self, event):
"""Point mode selected.
Graphics drawing tool is activated. Tooltip changed.
"""
self.SetToolNormalBitmap(self.drawGraphics, self.icons["pointAdd"].GetBitmap())
self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: points"))
self.drawGraphicsAction = "pointAdd"
if event:
self.ToggleTool(self.drawGraphics, True)
self.parent.OnAddPoint(event)
def OnAddLine(self, event):
"""Line mode selected.
Graphics drawing tool is activated. Tooltip changed.
"""
self.SetToolNormalBitmap(self.drawGraphics, self.icons["lineAdd"].GetBitmap())
self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: lines"))
self.ToggleTool(self.drawGraphics, True)
if event:
self.drawGraphicsAction = "lineAdd"
self.parent.OnAddLine(event)
def OnAddRectangle(self, event):
"""Rectangle mode selected.
Graphics drawing tool is activated. Tooltip changed.
"""
self.SetToolNormalBitmap(
self.drawGraphics, self.icons["rectangleAdd"].GetBitmap()
)
self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: rectangles"))
self.ToggleTool(self.drawGraphics, True)
if event:
self.drawGraphicsAction = "rectangleAdd"
self.parent.OnAddRectangle(event)
|