def testAdd(self): mapper = KeyMapper() o1 = object() o2 = object() o3 = object() # Create new ids key1 = mapper.key(o1) key2 = mapper.key(o2) key3 = mapper.key(o3) self.assertEquals(mapper.get(key1), o1) self.assertEquals(mapper.get(key2), o2) self.assertEquals(mapper.get(key3), o3) self.assertNotEquals(key1, key2) self.assertNotEquals(key1, key3) self.assertNotEquals(key2, key3) self.assertSize(mapper, 3) # Key should not add if there already is a mapping self.assertEquals(mapper.key(o3), key3) self.assertSize(mapper, 3) # Remove -> add should return a new key mapper.remove(o1) newkey1 = mapper.key(o1) self.assertNotEqual(key1, newkey1)
def paintActions(self, actionTarget, paintTarget): self.actionMapper = None actions = set() if self.actionHandlers is not None: for handler in self.actionHandlers: ac = handler.getActions(actionTarget, self.viewer) if ac is not None: for a in ac: actions.add(a) if self.ownActions is not None: actions = actions.union(self.ownActions) # Must repaint whenever there are actions OR if all actions have # been removed but still exist on client side if (len(actions) > 0) or self._clientHasActions: self.actionMapper = KeyMapper() paintTarget.addVariable(self.viewer, "action", "") paintTarget.startTag("actions") for a in actions: paintTarget.startTag("action") akey = self.actionMapper.key(a) paintTarget.addAttribute("key", akey) if a.getCaption() is not None: paintTarget.addAttribute("caption", a.getCaption()) if a.getIcon() is not None: paintTarget.addAttribute("icon", a.getIcon()) if isinstance(a, ShortcutAction): sa = a paintTarget.addAttribute("kc", sa.getKeyCode()) modifiers = sa.getModifiers() if modifiers is not None: smodifiers = [None] * len(modifiers) for i in range(len(modifiers)): smodifiers[i] = str(modifiers[i]) paintTarget.addAttribute("mk", smodifiers) paintTarget.endTag("action") paintTarget.endTag("actions") # Update flag for next repaint so we know if we need to paint empty # actions or not (must send actions is client had actions before and # all actions were removed). self._clientHasActions = len(actions) > 0
def addActionHandler(self, actionHandler): """Adds an action handler. @see: L{IContainer.addActionHandler} """ if actionHandler is not None: if self._actionHandlers is None: self._actionHandlers = list() self._actionMapper = KeyMapper() if actionHandler not in self._actionHandlers: self._actionHandlers.append(actionHandler) self.requestRepaint()
def testRemoveAll(self): mapper = KeyMapper() o1 = object() o2 = object() o3 = object() # Create new ids mapper.key(o1) mapper.key(o2) mapper.key(o3) self.assertSize(mapper, 3) mapper.removeAll() self.assertSize(mapper, 0)
def __init__(self): """Constructs a new Tabsheet. Tabsheet is immediate by default, and the default close handler removes the tab being closed. """ super(TabSheet, self).__init__() #: List of component tabs (tab contents). In addition to being on this # list, there is a L{ITab} object in tabs for each tab with # meta-data about the tab. self._components = list() #: Map containing information related to the tabs (caption, icon etc). self._tabs = dict() #: Selected tab content component. self._selected = None #: Mapper between server-side component instances (tab contents) and # keys given to the client that identify tabs. self._keyMapper = KeyMapper() #: When true, the tab selection area is not displayed to the user. self._tabsHidden = None #: Tabs that have been shown to the user (have been painted as # selected). self._paintedTabs = set() #: Handler to be called when a tab is closed. self._closeHandler = None #: expand horizontally by default self.setWidth(100.0, self.UNITS_PERCENTAGE) self.setImmediate(True) self.setCloseHandler(InnerHandler())