toolbars.py 5.7 KB

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