comparison browser_side/base_widget.py @ 320:a0ded7df30f7

browser_side: based on LiberviaWidget.getWidgetsPanel, add a generic method to retrieve the first ancestor of any class
author souliane <souliane@mailoo.org>
date Fri, 03 Jan 2014 21:48:49 +0100
parents 05e264e96a1c
children 0b7934e75e76
comparison
equal deleted inserted replaced
319:462a0a8894e3 320:a0ded7df30f7
29 from pyjamas.ui.TabPanel import TabPanel 29 from pyjamas.ui.TabPanel import TabPanel
30 from pyjamas.ui.HTMLPanel import HTMLPanel 30 from pyjamas.ui.HTMLPanel import HTMLPanel
31 from pyjamas.ui.Label import Label 31 from pyjamas.ui.Label import Label
32 from pyjamas.ui.Button import Button 32 from pyjamas.ui.Button import Button
33 from pyjamas.ui.Image import Image 33 from pyjamas.ui.Image import Image
34 from pyjamas.ui.Widget import Widget
34 from pyjamas.ui.DropWidget import DropWidget 35 from pyjamas.ui.DropWidget import DropWidget
35 from pyjamas.ui.ClickListener import ClickHandler 36 from pyjamas.ui.ClickListener import ClickHandler
36 from pyjamas.ui import HasAlignment 37 from pyjamas.ui import HasAlignment
37 from pyjamas import DOM 38 from pyjamas import DOM
38 import dialog 39 import dialog
40 import logging
39 from tools import LiberviaDragWidget 41 from tools import LiberviaDragWidget
40 from pyjamas import Window 42 from pyjamas import Window
41 from __pyjamas__ import doc 43 from __pyjamas__ import doc
42 44
43 45
195 197
196 def getDebugName(self): 198 def getDebugName(self):
197 return "%s (%s)" % (self, self.__title.getText()) 199 return "%s (%s)" % (self, self.__title.getText())
198 200
199 def getWidgetsPanel(self, verbose=True): 201 def getWidgetsPanel(self, verbose=True):
200 # current = self was not reassuring for the code analyzer 202 return self.getParent(WidgetsPanel, verbose)
201 current = self.getParent() 203
202 while current is not None and not isinstance(current, WidgetsPanel): 204 def getParent(self, class_=None, verbose=True):
203 current = current.getParent() 205 """
206 Note: this method overrides pyjamas.ui.Widget.getParent
207 @param class_: class of the ancestor to look for or None to return the first parent
208 @param verbose: set to True to log error messages
209 @return: the parent/ancestor or None if it has not been found
210 """
211 current = Widget.getParent(self)
212 if class_ is None:
213 return current # this is the default behavior
214 while current is not None and not isinstance(current, class_):
215 current = Widget.getParent(current)
204 if current is None and verbose: 216 if current is None and verbose:
205 print "Error: can't find WidgetsPanel" 217 logging.error("Can't find parent %s for %s" % (class_, self))
206 return current 218 return current
207 219
208 def onClick(self, sender): 220 def onClick(self, sender):
209 self.host.setSelected(self) 221 self.host.setSelected(self)
210 222