toolbars.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. 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.toggleMode = wx.Choice(parent=self)
  92. for label, cdata in zip(
  93. [_('Swipe mode'),
  94. _('Mirror mode')],
  95. ['swipe', 'mirror']):
  96. self.toggleMode.Append(label, cdata)
  97. self.toggleMode.SetSelection(0)
  98. self.toggleMode.SetSize(self.toggleMode.GetBestSize())
  99. self.toggleMode.Bind(
  100. wx.EVT_CHOICE,
  101. lambda event: self.parent.SetViewMode(
  102. self.toggleMode.GetClientData(
  103. event.GetSelection())))
  104. self.InsertControl(3, self.toggleMode)
  105. help = _("Choose view mode")
  106. self.SetToolShortHelp(self.toggleMode.GetId(), help)
  107. # realize the toolbar
  108. self.Realize()
  109. def _toolbarData(self):
  110. """Toolbar data"""
  111. return self._getToolbarData((("addRaster", swipeIcons['addRast'],
  112. self.parent.OnSelectLayers),
  113. (None, ),
  114. ("tools", swipeIcons['tools'],
  115. self.OnToolMenu)
  116. ))
  117. def SetMode(self, mode):
  118. for i in range(self.toggleMode.GetCount()):
  119. if mode == self.toggleMode.GetClientData(i):
  120. self.toggleMode.SetSelection(i)
  121. def OnToolMenu(self, event):
  122. """Menu for additional tools"""
  123. toolMenu = Menu()
  124. for label, itype, handler, desc in (
  125. (_("Switch orientation"),
  126. wx.ITEM_NORMAL, self.parent.OnSwitchOrientation,
  127. "switchOrientation"),
  128. (_("Switch maps"),
  129. wx.ITEM_NORMAL, self.parent.OnSwitchWindows, "switchMaps")):
  130. # Add items to the menu
  131. item = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  132. text=label,
  133. kind=itype)
  134. toolMenu.AppendItem(item)
  135. self.parent.GetWindow().Bind(wx.EVT_MENU, handler, item)
  136. # Popup the menu. If an item is selected then its handler
  137. # will be called before PopupMenu returns.
  138. self.parent.GetWindow().PopupMenu(toolMenu)
  139. toolMenu.Destroy()
  140. class SwipeMiscToolbar(BaseToolbar):
  141. """Toolbar with miscellaneous tools related to app
  142. """
  143. def __init__(self, parent):
  144. """Toolbar constructor
  145. """
  146. BaseToolbar.__init__(self, parent)
  147. self.InitToolbar(self._toolbarData())
  148. # realize the toolbar
  149. self.Realize()
  150. def _toolbarData(self):
  151. """Toolbar data"""
  152. return self._getToolbarData((("settings", BaseIcons['settings'],
  153. self.parent.OnPreferences),
  154. ("help", BaseIcons['help'],
  155. self.parent.OnHelp),
  156. ("quit", swipeIcons['quit'],
  157. self.parent.OnCloseWindow),
  158. ))