toolbars.py 11 KB

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