toolbars.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. """!
  2. @package psmap.toolbars
  3. @brief wxPsMap toolbars classes
  4. Classes:
  5. - toolbars::PsMapToolbar
  6. (C) 2007-2011 by the GRASS Development Team
  7. This program is free software under the GNU General Public License
  8. (>=v2). Read the file COPYING that comes with GRASS for details.
  9. @author Anna Kratochvilova <kratochanna gmail.com>
  10. """
  11. import os
  12. import sys
  13. import wx
  14. from core import globalvar
  15. from core.utils import _
  16. from gui_core.toolbars import BaseToolbar, BaseIcons
  17. from icons.icon import MetaIcon
  18. from core.globalvar import ETCIMGDIR
  19. class PsMapToolbar(BaseToolbar):
  20. def __init__(self, parent):
  21. """!Toolbar Cartographic Composer (psmap.py)
  22. @param parent parent window
  23. """
  24. BaseToolbar.__init__(self, parent)
  25. self.InitToolbar(self._toolbarData())
  26. # custom button for graphics mode selection
  27. # TODO: could this be somehow generalized?
  28. self.arrowButton = self.CreateSelectionButton()
  29. self.arrowButtonId = self.InsertControl(18, self.arrowButton)
  30. self.arrowButton.Bind(wx.EVT_BUTTON, self.OnDrawGraphicsMenu)
  31. self.drawGraphicsAction = None
  32. self.OnAddPoint(event = None)
  33. self.Realize()
  34. self.action = { 'id' : self.pointer }
  35. self.defaultAction = { 'id' : self.pointer,
  36. 'bind' : self.parent.OnPointer }
  37. self.OnTool(None)
  38. from psmap.frame import havePILImage
  39. if not havePILImage:
  40. self.EnableTool(self.preview, False)
  41. def _toolbarData(self):
  42. """!Toolbar data
  43. """
  44. icons = {
  45. 'scriptSave' : MetaIcon(img = 'script-save',
  46. label = _('Generate text file with mapping instructions')),
  47. 'scriptLoad' : MetaIcon(img = 'script-load',
  48. label = _('Load text file with mapping instructions')),
  49. 'psExport' : MetaIcon(img = 'ps-export',
  50. label = _('Generate PostScript output')),
  51. 'pdfExport' : MetaIcon(img = 'pdf-export',
  52. label = _('Generate PDF output')),
  53. 'pageSetup' : MetaIcon(img = 'page-settings',
  54. label = _('Page setup'),
  55. desc = _('Specify paper size, margins and orientation')),
  56. 'fullExtent' : MetaIcon(img = 'zoom-extent',
  57. label = _("Full extent"),
  58. desc = _("Zoom to full extent")),
  59. 'addMap' : MetaIcon(img = 'layer-add',
  60. label = _("Map frame"),
  61. desc = _("Click and drag to place map frame")),
  62. 'deleteObj' : MetaIcon(img = 'layer-remove',
  63. label = _("Delete selected object")),
  64. 'preview' : MetaIcon(img = 'execute',
  65. label = _("Show preview")),
  66. 'quit' : MetaIcon(img = 'quit',
  67. label = _('Quit Cartographic Composer')),
  68. 'addText' : MetaIcon(img = 'text-add',
  69. label = _('Text')),
  70. 'addMapinfo' : MetaIcon(img = 'map-info',
  71. label = _('Map info')),
  72. 'addLegend' : MetaIcon(img = 'legend-add',
  73. label = _('Legend')),
  74. 'addScalebar' : MetaIcon(img = 'scalebar-add',
  75. label = _('Scale bar')),
  76. 'addImage' : MetaIcon(img = 'image-add',
  77. label = _('Image')),
  78. 'addNorthArrow': MetaIcon(img = 'north-arrow-add',
  79. label = _('North Arrow')),
  80. 'pointAdd' : MetaIcon(img = 'point-add',
  81. label = _('Point')),
  82. 'lineAdd' : MetaIcon(img = 'line-add',
  83. label = _('Line')),
  84. 'rectangleAdd': MetaIcon(img = 'rectangle-add',
  85. label = _('Rectangle')),
  86. 'overlaysAdd': MetaIcon(img = 'layer-more',
  87. label = _("Add overlays")),
  88. 'labelsAdd': MetaIcon(img = 'layer-label-add',
  89. label = _("Add labels"))
  90. }
  91. self.icons = icons
  92. return self._getToolbarData((('loadFile', icons['scriptLoad'],
  93. self.parent.OnLoadFile),
  94. ('instructionFile', icons['scriptSave'],
  95. self.parent.OnInstructionFile),
  96. (None, ),
  97. ('pagesetup', icons['pageSetup'],
  98. self.parent.OnPageSetup),
  99. (None, ),
  100. ("pointer", BaseIcons["pointer"],
  101. self.parent.OnPointer, wx.ITEM_CHECK),
  102. ('pan', BaseIcons['pan'],
  103. self.parent.OnPan, wx.ITEM_CHECK),
  104. ("zoomin", BaseIcons["zoomIn"],
  105. self.parent.OnZoomIn, wx.ITEM_CHECK),
  106. ("zoomout", BaseIcons["zoomOut"],
  107. self.parent.OnZoomOut, wx.ITEM_CHECK),
  108. ('zoomAll', icons['fullExtent'],
  109. self.parent.OnZoomAll),
  110. (None, ),
  111. ('addMap', icons['addMap'],
  112. self.parent.OnAddMap, wx.ITEM_CHECK),
  113. ('addRaster', BaseIcons['addRast'],
  114. self.parent.OnAddRaster),
  115. ('addVector', BaseIcons['addVect'],
  116. self.parent.OnAddVect),
  117. ('overlaysAdd', icons['overlaysAdd'],
  118. self.OnAddOverlays),
  119. ("delete", icons["deleteObj"],
  120. self.parent.OnDelete),
  121. ("dec", BaseIcons["overlay"],
  122. self.OnDecoration),
  123. ("drawGraphics", icons['pointAdd'],
  124. self.OnDrawGraphics, wx.ITEM_CHECK),
  125. (None, ),
  126. ("preview", icons["preview"],
  127. self.parent.OnPreview),
  128. ('generatePS', icons['psExport'],
  129. self.parent.OnPSFile),
  130. ('generatePDF', icons['pdfExport'],
  131. self.parent.OnPDFFile),
  132. (None, ),
  133. ("help", BaseIcons['help'],
  134. self.parent.OnHelp),
  135. ('quit', icons['quit'],
  136. self.parent.OnCloseWindow))
  137. )
  138. def OnDecoration(self, event):
  139. """!Decorations overlay menu
  140. """
  141. self._onMenu(((self.icons["addLegend"], self.parent.OnAddLegend),
  142. (self.icons["addMapinfo"], self.parent.OnAddMapinfo),
  143. (self.icons["addScalebar"], self.parent.OnAddScalebar),
  144. (self.icons["addText"], self.parent.OnAddText),
  145. (self.icons["addImage"], self.parent.OnAddImage),
  146. (self.icons["addNorthArrow"], self.parent.OnAddNorthArrow)))
  147. def OnAddOverlays(self, event):
  148. self._onMenu(((self.icons['labelsAdd'], self.parent.OnAddLabels), ))
  149. def OnDrawGraphics(self, event):
  150. """!Graphics tool activated."""
  151. self.OnTool(event)
  152. # we need the previous id
  153. if self.drawGraphicsAction == 'pointAdd':
  154. self.parent.OnAddPoint(event)
  155. elif self.drawGraphicsAction == 'lineAdd':
  156. self.parent.OnAddLine(event)
  157. elif self.drawGraphicsAction == 'rectangleAdd':
  158. self.parent.OnAddRectangle(event)
  159. def OnDrawGraphicsMenu(self, event):
  160. """!Simple geometry features (point, line, rectangle) overlay menu
  161. """
  162. self._onMenu(((self.icons["pointAdd"], self.OnAddPoint),
  163. (self.icons["lineAdd"], self.OnAddLine),
  164. (self.icons["rectangleAdd"], self.OnAddRectangle),
  165. ))
  166. def OnAddPoint(self, event):
  167. """!Point mode selected.
  168. Graphics drawing tool is activated. Tooltip changed.
  169. """
  170. self.SetToolNormalBitmap(self.drawGraphics, self.icons["pointAdd"].GetBitmap())
  171. self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: points"))
  172. self.drawGraphicsAction = 'pointAdd'
  173. if event:
  174. self.ToggleTool(self.drawGraphics, True)
  175. self.parent.OnAddPoint(event)
  176. def OnAddLine(self, event):
  177. """!Line mode selected.
  178. Graphics drawing tool is activated. Tooltip changed.
  179. """
  180. self.SetToolNormalBitmap(self.drawGraphics, self.icons["lineAdd"].GetBitmap())
  181. self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: lines"))
  182. self.ToggleTool(self.drawGraphics, True)
  183. if event:
  184. self.drawGraphicsAction = 'lineAdd'
  185. self.parent.OnAddLine(event)
  186. def OnAddRectangle(self, event):
  187. """!Rectangle mode selected.
  188. Graphics drawing tool is activated. Tooltip changed.
  189. """
  190. self.SetToolNormalBitmap(self.drawGraphics, self.icons["rectangleAdd"].GetBitmap())
  191. self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: rectangles"))
  192. self.ToggleTool(self.drawGraphics, True)
  193. if event:
  194. self.drawGraphicsAction = 'rectangleAdd'
  195. self.parent.OnAddRectangle(event)
  196. def CreateSelectionButton(self):
  197. """!Add button to toolbar for selection of graphics drawing mode.
  198. Button must be custom (not toolbar tool) to set smaller width.
  199. """
  200. arrowPath = os.path.join(ETCIMGDIR, 'small_down_arrow.png')
  201. if os.path.isfile(arrowPath) and os.path.getsize(arrowPath):
  202. bitmap = wx.Bitmap(name = arrowPath)
  203. else:
  204. bitmap = wx.ArtProvider.GetBitmap(id = wx.ART_MISSING_IMAGE, client = wx.ART_TOOLBAR)
  205. button = wx.BitmapButton(parent = self, id = wx.ID_ANY, size = ((-1, self.GetSize()[1])),
  206. bitmap = bitmap, style = wx.NO_BORDER)
  207. button.SetToolTipString(_("Select graphics tool"))
  208. return button