comparison src/browser/sat_browser/base_widget.py @ 635:40c3c6aaafaa frontends_multi_profiles

browser side (LiberviaWidget): an error is raised when expect is True on getParent
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:44:58 +0100
parents c2abadf31afb
children 86ae737da6f3
comparison
equal deleted inserted replaced
634:16a5da120b7f 635:40c3c6aaafaa
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 import pyjd # this is dummy in pyjs 20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from sat.core import exceptions
23 from sat_frontends.quick_frontend import quick_widgets 24 from sat_frontends.quick_frontend import quick_widgets
24 from pyjamas.ui.SimplePanel import SimplePanel 25 from pyjamas.ui.SimplePanel import SimplePanel
25 from pyjamas.ui.AbsolutePanel import AbsolutePanel 26 from pyjamas.ui.AbsolutePanel import AbsolutePanel
26 from pyjamas.ui.VerticalPanel import VerticalPanel 27 from pyjamas.ui.VerticalPanel import VerticalPanel
27 from pyjamas.ui.HorizontalPanel import HorizontalPanel 28 from pyjamas.ui.HorizontalPanel import HorizontalPanel
336 """Return the closest ancestor of the specified class. 337 """Return the closest ancestor of the specified class.
337 338
338 Note: this method overrides pyjamas.ui.Widget.getParent 339 Note: this method overrides pyjamas.ui.Widget.getParent
339 340
340 @param class_: class of the ancestor to look for or None to return the first parent 341 @param class_: class of the ancestor to look for or None to return the first parent
341 @param expect: set to True if the parent is expected (print a message if not found) 342 @param expect: set to True if the parent is expected (raise an error if not found)
342 @return: the parent/ancestor or None if it has not been found 343 @return: the parent/ancestor or None if it has not been found
344 @raise exceptions.InternalError: expect is True and no parent is found
343 """ 345 """
344 current = Widget.getParent(self) 346 current = Widget.getParent(self)
345 if class_ is None: 347 if class_ is None:
346 return current # this is the default behavior 348 return current # this is the default behavior
347 while current is not None and not isinstance(current, class_): 349 while current is not None and not isinstance(current, class_):
348 current = Widget.getParent(current) 350 current = Widget.getParent(current)
349 if current is None and expect: 351 if current is None and expect:
350 log.error("Can't find parent %s for %s" % (class_, self)) 352 raise exceptions.InternalError("Can't find parent %s for %s" % (class_, self))
351 return current 353 return current
352 354
353 def onClick(self, sender): 355 def onClick(self, sender):
354 self.host.setSelected(self) 356 self.host.setSelected(self)
355 357