toolbars.py 6.8 KB

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