toolbars.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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((("rendermap", icons["render"],
  44. self.parent.OnRender),
  45. ("pointer", icons["pointer"],
  46. self.parent.OnPointer,
  47. wx.ITEM_CHECK),
  48. ("query", swipeIcons["query"],
  49. self.parent.OnQuery,
  50. wx.ITEM_CHECK),
  51. ("pan", icons["pan"],
  52. self.parent.OnPan,
  53. wx.ITEM_CHECK), # toggle tool
  54. ("zoomIn", icons["zoomIn"],
  55. self.parent.OnZoomIn,
  56. wx.ITEM_CHECK),
  57. ("zoomOut", icons["zoomOut"],
  58. self.parent.OnZoomOut,
  59. wx.ITEM_CHECK),
  60. (None, ),
  61. ("zoomBack", icons["zoomBack"],
  62. self.parent.OnZoomBack),
  63. ("zoomToMap", icons["zoomExtent"],
  64. self.parent.OnZoomToMap),
  65. (None, ),
  66. ('saveFile', icons['saveFile'],
  67. self.parent.SaveToFile),
  68. ))
  69. def SetActiveMap(self, index):
  70. """Set currently selected map.
  71. Unused, needed because of DoubleMapFrame API.
  72. """
  73. pass
  74. class SwipeMainToolbar(BaseToolbar):
  75. """Toolbar with tools related to application functionality
  76. """
  77. def __init__(self, parent):
  78. """Toolbar constructor
  79. """
  80. BaseToolbar.__init__(self, parent)
  81. self.InitToolbar(self._toolbarData())
  82. # add tool to toggle active map window
  83. self.toggleModeId = wx.NewId()
  84. self.toggleMode = wx.Choice(parent=self, id=self.toggleModeId)
  85. for label, cdata in zip([_('Swipe mode'), _('Mirror mode')], ['swipe', 'mirror']):
  86. self.toggleMode.Append(label, cdata)
  87. self.toggleMode.SetSelection(0)
  88. self.toggleMode.SetSize(self.toggleMode.GetBestSize())
  89. self.toggleMode.Bind(wx.EVT_CHOICE,
  90. lambda event:
  91. self.parent.SetViewMode(self.toggleMode.GetClientData(event.GetSelection())))
  92. self.InsertControl(3, self.toggleMode)
  93. help = _("Choose view mode")
  94. self.SetToolShortHelp(self.toggleModeId, help)
  95. # realize the toolbar
  96. self.Realize()
  97. def _toolbarData(self):
  98. """Toolbar data"""
  99. return self._getToolbarData((("addRaster", swipeIcons['addRast'],
  100. self.parent.OnSelectLayers),
  101. (None, ),
  102. ("tools", swipeIcons['tools'],
  103. self.OnToolMenu)
  104. ))
  105. def SetMode(self, mode):
  106. for i in range(self.toggleMode.GetCount()):
  107. if mode == self.toggleMode.GetClientData(i):
  108. self.toggleMode.SetSelection(i)
  109. def OnToolMenu(self, event):
  110. """Menu for additional tools"""
  111. toolMenu = wx.Menu()
  112. for label, itype, handler, desc in (
  113. (_("Switch orientation"),
  114. wx.ITEM_NORMAL, self.parent.OnSwitchOrientation, "switchOrientation"),
  115. (_("Switch maps"),
  116. wx.ITEM_NORMAL, self.parent.OnSwitchWindows, "switchMaps")):
  117. # Add items to the menu
  118. item = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  119. text=label,
  120. kind=itype)
  121. toolMenu.AppendItem(item)
  122. self.parent.GetWindow().Bind(wx.EVT_MENU, handler, item)
  123. # Popup the menu. If an item is selected then its handler
  124. # will be called before PopupMenu returns.
  125. self.parent.GetWindow().PopupMenu(toolMenu)
  126. toolMenu.Destroy()
  127. class SwipeMiscToolbar(BaseToolbar):
  128. """Toolbar with miscellaneous tools related to app
  129. """
  130. def __init__(self, parent):
  131. """Toolbar constructor
  132. """
  133. BaseToolbar.__init__(self, parent)
  134. self.InitToolbar(self._toolbarData())
  135. # realize the toolbar
  136. self.Realize()
  137. def _toolbarData(self):
  138. """Toolbar data"""
  139. return self._getToolbarData((("settings", BaseIcons['settings'],
  140. self.parent.OnPreferences),
  141. ("help", BaseIcons['help'],
  142. self.parent.OnHelp),
  143. ("quit", swipeIcons['quit'],
  144. self.parent.OnCloseWindow),
  145. ))