toolbars.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. """!
  2. @package swipe.toolbars
  3. @brief Map Swipe toolbars and icons.
  4. Classes:
  5. - toolbars::SwipeMapToolbar
  6. - toolbars::SwipeMainToolbar
  7. - toolbars::SwipeMiscToolbar
  8. (C) 2012 by the GRASS Development Team
  9. This program is free software under the GNU General Public License
  10. (>=v2). Read the file COPYING that comes with GRASS for details.
  11. @author Anna Kratochvilova <kratochanna gmail.com>
  12. """
  13. import wx
  14. from gui_core.toolbars import BaseToolbar, BaseIcons
  15. from icons.icon import MetaIcon
  16. from core.utils import _
  17. swipeIcons = {'tools': MetaIcon(img='tools', label=_("Tools")),
  18. 'quit': BaseIcons['quit'].SetLabel(_("Quit Map Swipe")),
  19. 'addRast': BaseIcons['addRast'].SetLabel(_("Select raster maps")),
  20. 'query': MetaIcon(img='info',
  21. label=_('Query raster/vector map(s)'),
  22. desc=_('Query selected raster/vector map(s)')),
  23. }
  24. class SwipeMapToolbar(BaseToolbar):
  25. """!Map toolbar (to control map zoom and rendering)
  26. """
  27. def __init__(self, parent, toolSwitcher):
  28. """!Map toolbar constructor
  29. """
  30. BaseToolbar.__init__(self, parent, toolSwitcher)
  31. self.InitToolbar(self._toolbarData())
  32. self._default = self.pan
  33. # realize the toolbar
  34. self.Realize()
  35. for tool in (self.pointer, self.query, self.pan, self.zoomIn, self.zoomOut):
  36. self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
  37. self.EnableTool(self.zoomBack, False)
  38. def _toolbarData(self):
  39. """!Returns toolbar data (name, icon, handler)"""
  40. # BaseIcons are a set of often used icons. It is possible
  41. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  42. icons = BaseIcons
  43. return self._getToolbarData((("displaymap", icons["display"],
  44. self.parent.OnDraw),
  45. ("rendermap", icons["render"],
  46. self.parent.OnRender),
  47. ("erase", icons["erase"],
  48. self.parent.OnErase),
  49. (None, ), # creates separator
  50. ("pointer", icons["pointer"],
  51. self.parent.OnPointer,
  52. wx.ITEM_CHECK),
  53. ("query", swipeIcons["query"],
  54. self.parent.OnQuery,
  55. wx.ITEM_CHECK),
  56. ("pan", icons["pan"],
  57. self.parent.OnPan,
  58. wx.ITEM_CHECK), # toggle tool
  59. ("zoomIn", icons["zoomIn"],
  60. self.parent.OnZoomIn,
  61. wx.ITEM_CHECK),
  62. ("zoomOut", icons["zoomOut"],
  63. self.parent.OnZoomOut,
  64. wx.ITEM_CHECK),
  65. (None, ),
  66. ("zoomBack", icons["zoomBack"],
  67. self.parent.OnZoomBack),
  68. ("zoomToMap", icons["zoomExtent"],
  69. self.parent.OnZoomToMap),
  70. (None, ),
  71. ('saveFile', icons['saveFile'],
  72. self.parent.SaveToFile),
  73. ))
  74. def SetActiveMap(self, index):
  75. """!Set currently selected map.
  76. Unused, needed because of DoubleMapFrame API.
  77. """
  78. pass
  79. class SwipeMainToolbar(BaseToolbar):
  80. """!Toolbar with tools related to application functionality
  81. """
  82. def __init__(self, parent):
  83. """!Toolbar constructor
  84. """
  85. BaseToolbar.__init__(self, parent)
  86. self.InitToolbar(self._toolbarData())
  87. # add tool to toggle active map window
  88. self.toggleModeId = wx.NewId()
  89. self.toggleMode = wx.Choice(parent=self, id=self.toggleModeId)
  90. for label, cdata in zip([_('Swipe mode'), _('Mirror mode')], ['swipe', 'mirror']):
  91. self.toggleMode.Append(label, cdata)
  92. self.toggleMode.SetSelection(0)
  93. self.toggleMode.SetSize(self.toggleMode.GetBestSize())
  94. self.toggleMode.Bind(wx.EVT_CHOICE,
  95. lambda event:
  96. self.parent.SetViewMode(self.toggleMode.GetClientData(event.GetSelection())))
  97. self.InsertControl(3, self.toggleMode)
  98. help = _("Choose view mode")
  99. self.SetToolShortHelp(self.toggleModeId, help)
  100. # realize the toolbar
  101. self.Realize()
  102. def _toolbarData(self):
  103. """!Toolbar data"""
  104. return self._getToolbarData((("addRaster", swipeIcons['addRast'],
  105. self.parent.OnSelectLayers),
  106. (None, ),
  107. ("tools", swipeIcons['tools'],
  108. self.OnToolMenu)
  109. ))
  110. def SetMode(self, mode):
  111. for i in range(self.toggleMode.GetCount()):
  112. if mode == self.toggleMode.GetClientData(i):
  113. self.toggleMode.SetSelection(i)
  114. def OnToolMenu(self, event):
  115. """!Menu for additional tools"""
  116. toolMenu = wx.Menu()
  117. for label, itype, handler, desc in (
  118. (_("Switch orientation"),
  119. wx.ITEM_NORMAL, self.parent.OnSwitchOrientation, "switchOrientation"),
  120. (_("Switch maps"),
  121. wx.ITEM_NORMAL, self.parent.OnSwitchWindows, "switchMaps")):
  122. # Add items to the menu
  123. item = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  124. text=label,
  125. kind=itype)
  126. toolMenu.AppendItem(item)
  127. self.parent.GetWindow().Bind(wx.EVT_MENU, handler, item)
  128. # Popup the menu. If an item is selected then its handler
  129. # will be called before PopupMenu returns.
  130. self.parent.GetWindow().PopupMenu(toolMenu)
  131. toolMenu.Destroy()
  132. class SwipeMiscToolbar(BaseToolbar):
  133. """!Toolbar with miscellaneous tools related to app
  134. """
  135. def __init__(self, parent):
  136. """!Toolbar constructor
  137. """
  138. BaseToolbar.__init__(self, parent)
  139. self.InitToolbar(self._toolbarData())
  140. # realize the toolbar
  141. self.Realize()
  142. def _toolbarData(self):
  143. """!Toolbar data"""
  144. return self._getToolbarData((("settings", BaseIcons['settings'],
  145. self.parent.OnPreferences),
  146. ("help", BaseIcons['help'],
  147. self.parent.OnHelp),
  148. ("quit", swipeIcons['quit'],
  149. self.parent.OnCloseWindow),
  150. ))