Package horizons :: Package gui :: Package mousetools :: Module navigationtool
[hide private]
[frames] | no frames]

Source Code for Module horizons.gui.mousetools.navigationtool

  1  # ################################################### 
  2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
  3  # team@unknown-horizons.org 
  4  # This file is part of Unknown Horizons. 
  5  # 
  6  # Unknown Horizons is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the 
 18  # Free Software Foundation, Inc., 
 19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 20  # ################################################### 
 21   
 22  from fife import fife 
 23  from fife.extensions.pychan.widgets import Icon 
 24   
 25  import horizons.globals 
 26  from horizons.constants import LAYERS, VIEW 
 27  from horizons.extscheduler import ExtScheduler 
 28  from horizons.gui.mousetools.cursortool import CursorTool 
 29  from horizons.i18n import gettext as T 
 30  from horizons.messaging import HoverInstancesChanged 
 31  from horizons.util.lastactiveplayersettlementmanager import LastActivePlayerSettlementManager 
 32  from horizons.util.python.weaklist import WeakList 
 33  from horizons.util.worldobject import WorldObject 
 80   
 81                          def __init__(self, cursor_tool, **kwargs): 
 82                                  super().__init__(**kwargs) 
 83                                  cursor_tool.session.ingame_gui.coordinates_tooltip = self 
 84                                  self.cursor_tool = cursor_tool 
 85                                  self.enabled = False 
 86   
 87                                  self.icon = Icon(position=(1, 1)) # 0, 0 is currently not supported by tooltips 
 88   
 89                          def toggle(self): 
 90                                  self.enabled = not self.enabled 
 91                                  if not self.enabled and self.icon.tooltip_shown: 
 92                                          self.icon.hide_tooltip() 
 93   
 94                          def show_evt(self, evt): 
 95                                  if self.enabled: 
 96                                          if evt.isConsumedByWidgets(): 
 97                                                  if self.icon.tooltip_shown: 
 98                                                          self.icon.hide_tooltip() 
 99                                                  return 
100                                          x, y = self.cursor_tool.get_world_location(evt).to_tuple() 
101                                          self.icon.helptext = '{:d}, {:d} '.format(x, y) + T("Press H to remove this hint") 
102                                          self.icon.position_tooltip(evt) 
103                                          self.icon.show_tooltip() 
104   
105                  self.tooltip = CoordsTooltip.get_instance(self) 
106   
115   
121   
126   
141   
142          # return new mouse position after moving 
183   
184          # move up mouse wheel = zoom in 
189   
190          # move down mouse wheel = zoom out 
195   
215   
258   
264   
271   
284