def fill(target, color, area=None): """Fills a certain rectangular area on the passed target with a color. If no area is provided, the entire target will be filled with the passed color. If an iterable item is provided as area (such as a list or tuple), it will be first checked, if the item denotes a single rectangular area (4 integer values) before assuming it to be a sequence of rectangular areas. """ color = prepare_color(color, target) rtarget = _get_target_surface(target) varea = None if area is not None and isiterable(area): # can be either a single rect or a list of rects) if len(area) == 4: # is it a rect? try: varea = rect.SDL_Rect(int(area[0]), int(area[1]), int(area[2]), int(area[3])) except: # No, not a rect, assume a seq of rects. pass if not varea: # len(area) == 4 AND varea set. varea = [] for r in area: varea.append(rect.SDL_Rect(r[0], r[1], r[2], r[3])) if varea is None or isinstance(varea, rect.SDL_Rect): sdlsurface.fill_rect(rtarget, varea, color) else: sdlsurface.fill_rects(rtarget, varea, color)
def dispatch(self, obj, event): """Passes an event to the given object. If obj is a World object, UI relevant components will receive the event, if they support the event type. If obj is a single object, obj.events MUST be a dictionary consisting of SDL event type identifiers and EventHandler instances bound to the object. obj also must have a 'uitype' attribute referring to the UI type of the object. If obj is an iterable, such as a list or set, every item within obj MUST feature an 'events' and 'uitype' attribute as described above. """ if event is None: return handler = self.handlers.get(event.type, self.passevent) if isinstance(obj, World): for ctype in self.componenttypes: items = obj.get_components(ctype) items = [ (v, e) for v in items for e in (event,) if hasattr(v, "events") and hasattr(v, "uitype") and e.type in v.events ] if len(items) > 0: arg1, arg2 = zip(*items) map(handler, arg1, arg2) elif isiterable(obj): items = [(v, e) for v in obj for e in (event,) if e.type in v.events] if len(items) > 0: for v, e in items: handler(v, e) elif event.type in obj.events: handler(obj, event) if self._nextactive is not None: self.activate(self._nextactive) self._nextactive = None