Skip to content

Commit

Permalink
Try to detect invalid events from pychan.
Browse files Browse the repository at this point in the history
Sometimes, pychan sends invalid event notifications. It is probably related to changing the gui when the mouse hovers on gui elements. Random tests have given evidence to believe that pychan indicates invalid events by setting the top container's position to 0, 0. Since this position is currently unused, it can serve as invalid flag, and dropping these events seems to lead to the desired placements.

A proper fix would probably be related to this:
http://fife.trac.cvsdude.com/engine/ticket/387

Refs unknown-horizons#1717
  • Loading branch information
totycro committed Apr 19, 2012
1 parent 4c4d68d commit 1ad08aa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions horizons/gui/widgets/tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import textwrap
from fife import fife
from fife.extensions import pychan

import horizons.main

from horizons.extscheduler import ExtScheduler
from horizons.gui.util import load_uh_widget
from horizons.util import Callback

class _Tooltip(object):
"""Base class for pychan widgets overloaded with tooltip functionality"""
Expand Down Expand Up @@ -69,6 +71,18 @@ def position_tooltip(self, event):
if self.gui is None:
self.gui = load_uh_widget('tooltip.xml')
widget_position = self.getAbsolutePos()

# Sometimes, we get invalid events from pychan, it is probably related to changing the
# gui when the mouse hovers on gui elements.
# Random tests have given evidence to believe that pychan indicates invalid events
# by setting the top container's position to 0, 0.
# Since this position is currently unused, it can serve as invalid flag,
# and dropping these events seems to lead to the desired placements
def get_top(w): return get_top(w.parent) if w.parent else w
top_pos = get_top(self).position
if top_pos == (0, 0):
return

screen_width = horizons.main.fife.engine_settings.getScreenWidth()
self.gui.y = widget_position[1] + y + 5
if (widget_position[0] + x + self.gui.size[0] + 10) <= screen_width:
Expand Down

0 comments on commit 1ad08aa

Please sign in to comment.