toolbars.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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(17, 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. }
  86. self.icons = icons
  87. return self._getToolbarData((('loadFile', icons['scriptLoad'],
  88. self.parent.OnLoadFile),
  89. ('instructionFile', icons['scriptSave'],
  90. self.parent.OnInstructionFile),
  91. (None, ),
  92. ('pagesetup', icons['pageSetup'],
  93. self.parent.OnPageSetup),
  94. (None, ),
  95. ("pointer", BaseIcons["pointer"],
  96. self.parent.OnPointer, wx.ITEM_CHECK),
  97. ('pan', BaseIcons['pan'],
  98. self.parent.OnPan, wx.ITEM_CHECK),
  99. ("zoomin", BaseIcons["zoomIn"],
  100. self.parent.OnZoomIn, wx.ITEM_CHECK),
  101. ("zoomout", BaseIcons["zoomOut"],
  102. self.parent.OnZoomOut, wx.ITEM_CHECK),
  103. ('zoomAll', icons['fullExtent'],
  104. self.parent.OnZoomAll),
  105. (None, ),
  106. ('addMap', icons['addMap'],
  107. self.parent.OnAddMap, wx.ITEM_CHECK),
  108. ('addRaster', BaseIcons['addRast'],
  109. self.parent.OnAddRaster),
  110. ('addVector', BaseIcons['addVect'],
  111. self.parent.OnAddVect),
  112. ("delete", icons["deleteObj"],
  113. self.parent.OnDelete),
  114. ("dec", BaseIcons["overlay"],
  115. self.OnDecoration),
  116. ("drawGraphics", icons['pointAdd'],
  117. self.OnDrawGraphics, wx.ITEM_CHECK),
  118. (None, ),
  119. ("preview", icons["preview"],
  120. self.parent.OnPreview),
  121. ('generatePS', icons['psExport'],
  122. self.parent.OnPSFile),
  123. ('generatePDF', icons['pdfExport'],
  124. self.parent.OnPDFFile),
  125. (None, ),
  126. ("help", BaseIcons['help'],
  127. self.parent.OnHelp),
  128. ('quit', icons['quit'],
  129. self.parent.OnCloseWindow))
  130. )
  131. def OnDecoration(self, event):
  132. """!Decorations overlay menu
  133. """
  134. self._onMenu(((self.icons["addLegend"], self.parent.OnAddLegend),
  135. (self.icons["addMapinfo"], self.parent.OnAddMapinfo),
  136. (self.icons["addScalebar"], self.parent.OnAddScalebar),
  137. (self.icons["addText"], self.parent.OnAddText),
  138. (self.icons["addImage"], self.parent.OnAddImage),
  139. (self.icons["addNorthArrow"], self.parent.OnAddNorthArrow)))
  140. def OnDrawGraphics(self, event):
  141. """!Graphics tool activated."""
  142. self.OnTool(event)
  143. # we need the previous id
  144. if self.drawGraphicsAction == 'pointAdd':
  145. self.parent.OnAddPoint(event)
  146. elif self.drawGraphicsAction == 'lineAdd':
  147. self.parent.OnAddLine(event)
  148. elif self.drawGraphicsAction == 'rectangleAdd':
  149. self.parent.OnAddRectangle(event)
  150. def OnDrawGraphicsMenu(self, event):
  151. """!Simple geometry features (point, line, rectangle) overlay menu
  152. """
  153. self._onMenu(((self.icons["pointAdd"], self.OnAddPoint),
  154. (self.icons["lineAdd"], self.OnAddLine),
  155. (self.icons["rectangleAdd"], self.OnAddRectangle),
  156. ))
  157. def OnAddPoint(self, event):
  158. """!Point mode selected.
  159. Graphics drawing tool is activated. Tooltip changed.
  160. """
  161. self.SetToolNormalBitmap(self.drawGraphics, self.icons["pointAdd"].GetBitmap())
  162. self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: points"))
  163. self.drawGraphicsAction = 'pointAdd'
  164. if event:
  165. self.ToggleTool(self.drawGraphics, True)
  166. self.parent.OnAddPoint(event)
  167. def OnAddLine(self, event):
  168. """!Line mode selected.
  169. Graphics drawing tool is activated. Tooltip changed.
  170. """
  171. self.SetToolNormalBitmap(self.drawGraphics, self.icons["lineAdd"].GetBitmap())
  172. self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: lines"))
  173. self.ToggleTool(self.drawGraphics, True)
  174. if event:
  175. self.drawGraphicsAction = 'lineAdd'
  176. self.parent.OnAddLine(event)
  177. def OnAddRectangle(self, event):
  178. """!Rectangle mode selected.
  179. Graphics drawing tool is activated. Tooltip changed.
  180. """
  181. self.SetToolNormalBitmap(self.drawGraphics, self.icons["rectangleAdd"].GetBitmap())
  182. self.SetToolShortHelp(self.drawGraphics, _("Add simple graphics: rectangles"))
  183. self.ToggleTool(self.drawGraphics, True)
  184. if event:
  185. self.drawGraphicsAction = 'rectangleAdd'
  186. self.parent.OnAddRectangle(event)
  187. def CreateSelectionButton(self):
  188. """!Add button to toolbar for selection of graphics drawing mode.
  189. Button must be custom (not toolbar tool) to set smaller width.
  190. """
  191. arrowPath = os.path.join(ETCIMGDIR, 'small_down_arrow.png')
  192. if os.path.isfile(arrowPath) and os.path.getsize(arrowPath):
  193. bitmap = wx.Bitmap(name = arrowPath)
  194. else:
  195. bitmap = wx.ArtProvider.GetBitmap(id = wx.ART_MISSING_IMAGE, client = wx.ART_TOOLBAR)
  196. button = wx.BitmapButton(parent = self, id = wx.ID_ANY, size = ((-1, self.GetSize()[1])),
  197. bitmap = bitmap, style = wx.NO_BORDER)
  198. button.SetToolTipString(_("Select graphics tool"))
  199. return button