toolbars.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. "addRast": BaseIcons["addRast"].SetLabel(_("Select raster maps")),
  20. "query": MetaIcon(
  21. img="info",
  22. label=_("Query raster/vector map(s)"),
  23. desc=_("Query selected raster/vector map(s)"),
  24. ),
  25. }
  26. class SwipeMapToolbar(BaseToolbar):
  27. """Map toolbar (to control map zoom and rendering)"""
  28. def __init__(self, parent, toolSwitcher):
  29. """Map toolbar constructor"""
  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(
  44. (
  45. (
  46. ("rendermap", icons["render"].label),
  47. icons["render"],
  48. self.parent.OnRender,
  49. ),
  50. (
  51. ("pointer", icons["pointer"].label),
  52. icons["pointer"],
  53. self.parent.OnPointer,
  54. wx.ITEM_CHECK,
  55. ),
  56. (
  57. ("query", swipeIcons["query"].label),
  58. swipeIcons["query"],
  59. self.parent.OnQuery,
  60. wx.ITEM_CHECK,
  61. ),
  62. (
  63. ("pan", icons["pan"].label),
  64. icons["pan"],
  65. self.parent.OnPan,
  66. wx.ITEM_CHECK,
  67. ), # toggle tool
  68. (
  69. ("zoomIn", icons["zoomIn"].label),
  70. icons["zoomIn"],
  71. self.parent.OnZoomIn,
  72. wx.ITEM_CHECK,
  73. ),
  74. (
  75. ("zoomOut", icons["zoomOut"].label),
  76. icons["zoomOut"],
  77. self.parent.OnZoomOut,
  78. wx.ITEM_CHECK,
  79. ),
  80. (None,),
  81. (
  82. ("zoomBack", icons["zoomBack"].label),
  83. icons["zoomBack"],
  84. self.parent.OnZoomBack,
  85. ),
  86. (
  87. ("zoomToMap", icons["zoomExtent"].label),
  88. icons["zoomExtent"],
  89. self.parent.OnZoomToMap,
  90. ),
  91. (None,),
  92. (
  93. ("saveFile", icons["saveFile"].label),
  94. icons["saveFile"],
  95. self.parent.SaveToFile,
  96. ),
  97. (
  98. ("mapDispSettings", BaseIcons["mapDispSettings"].label),
  99. BaseIcons["mapDispSettings"],
  100. self.parent.OnMapDisplayProperties,
  101. ),
  102. )
  103. )
  104. def SetActiveMap(self, index):
  105. """Set currently selected map.
  106. Unused, needed because of DoubleMapPanel API.
  107. """
  108. pass
  109. class SwipeMainToolbar(BaseToolbar):
  110. """Toolbar with tools related to application functionality"""
  111. def __init__(self, parent):
  112. """Toolbar constructor"""
  113. BaseToolbar.__init__(self, parent)
  114. self.InitToolbar(self._toolbarData())
  115. # add tool to toggle active map window
  116. self.toggleMode = wx.Choice(parent=self)
  117. for label, cdata in zip(
  118. [_("Swipe mode"), _("Mirror mode")], ["swipe", "mirror"]
  119. ):
  120. self.toggleMode.Append(label, cdata)
  121. self.toggleMode.SetSelection(0)
  122. self.toggleMode.SetSize(self.toggleMode.GetBestSize())
  123. self.toggleMode.Bind(
  124. wx.EVT_CHOICE,
  125. lambda event: self.parent.SetViewMode(
  126. self.toggleMode.GetClientData(event.GetSelection())
  127. ),
  128. )
  129. self.InsertControl(3, self.toggleMode)
  130. help = _("Choose view mode")
  131. self.SetToolShortHelp(self.toggleMode.GetId(), help)
  132. # realize the toolbar
  133. self.Realize()
  134. def _toolbarData(self):
  135. """Toolbar data"""
  136. return self._getToolbarData(
  137. (
  138. (
  139. ("addRaster", swipeIcons["addRast"].label),
  140. swipeIcons["addRast"],
  141. self.parent.OnSelectLayers,
  142. ),
  143. (None,),
  144. (
  145. ("tools", swipeIcons["tools"].label),
  146. swipeIcons["tools"],
  147. self.OnToolMenu,
  148. ),
  149. )
  150. )
  151. def SetMode(self, mode):
  152. for i in range(self.toggleMode.GetCount()):
  153. if mode == self.toggleMode.GetClientData(i):
  154. self.toggleMode.SetSelection(i)
  155. def OnToolMenu(self, event):
  156. """Menu for additional tools"""
  157. toolMenu = Menu()
  158. for label, itype, handler, desc in (
  159. (
  160. _("Switch orientation"),
  161. wx.ITEM_NORMAL,
  162. self.parent.OnSwitchOrientation,
  163. "switchOrientation",
  164. ),
  165. (
  166. _("Switch maps"),
  167. wx.ITEM_NORMAL,
  168. self.parent.OnSwitchWindows,
  169. "switchMaps",
  170. ),
  171. ):
  172. # Add items to the menu
  173. item = wx.MenuItem(
  174. parentMenu=toolMenu, id=wx.ID_ANY, text=label, kind=itype
  175. )
  176. toolMenu.AppendItem(item)
  177. self.parent.GetWindow().Bind(wx.EVT_MENU, handler, item)
  178. # Popup the menu. If an item is selected then its handler
  179. # will be called before PopupMenu returns.
  180. self.parent.GetWindow().PopupMenu(toolMenu)
  181. toolMenu.Destroy()
  182. class SwipeMiscToolbar(BaseToolbar):
  183. """Toolbar with miscellaneous tools related to app"""
  184. def __init__(self, parent):
  185. """Toolbar constructor"""
  186. BaseToolbar.__init__(self, parent)
  187. self.InitToolbar(self._toolbarData())
  188. # realize the toolbar
  189. self.Realize()
  190. def _toolbarData(self):
  191. """Toolbar data"""
  192. return self._getToolbarData(
  193. (
  194. (
  195. ("settings", BaseIcons["settings"].label),
  196. BaseIcons["settings"],
  197. self.parent.OnPreferences,
  198. ),
  199. (
  200. ("help", BaseIcons["help"].label),
  201. BaseIcons["help"],
  202. self.parent.OnHelp,
  203. ),
  204. (
  205. ("quit", BaseIcons["quit"].label),
  206. BaseIcons["quit"],
  207. self.parent.OnCloseWindow,
  208. ),
  209. )
  210. )