toolbars.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 = {
  18. 'tools': MetaIcon(img = 'tools', label = _("Tools")),
  19. 'quit' : BaseIcons['quit'].SetLabel(_("Quit Map Swipe")),
  20. 'addRast' : BaseIcons['addRast'].SetLabel(_("Select raster maps")),
  21. }
  22. class SwipeMapToolbar(BaseToolbar):
  23. """!Map toolbar (to control map zoom and rendering)
  24. """
  25. def __init__(self, parent):
  26. """!Map toolbar constructor
  27. """
  28. BaseToolbar.__init__(self, parent)
  29. self.InitToolbar(self._toolbarData())
  30. # realize the toolbar
  31. self.Realize()
  32. self.action = { 'id' : self.pan }
  33. self.defaultAction = { 'id' : self.pan,
  34. 'bind' : self.parent.OnPan }
  35. self.EnableTool(self.zoomBack, False)
  36. def _toolbarData(self):
  37. """!Returns toolbar data (name, icon, handler)"""
  38. # BaseIcons are a set of often used icons. It is possible
  39. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  40. icons = BaseIcons
  41. return self._getToolbarData((("displaymap", icons["display"],
  42. self.parent.OnDraw),
  43. ("rendermap", icons["render"],
  44. self.parent.OnRender),
  45. ("erase", icons["erase"],
  46. self.parent.OnErase),
  47. (None, ), # creates separator
  48. ("pointer", icons["pointer"],
  49. self.parent.OnPointer,
  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.OnSelectRasters),
  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((("help", BaseIcons['help'],
  140. self.parent.OnHelp),
  141. ("quit", swipeIcons['quit'],
  142. self.parent.OnCloseWindow),
  143. ))