toolbars.py 6.8 KB

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