toolbars.py 5.9 KB

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