def testUnregister(self): """ test unregistering from manager """ QSettings().clear() s = QgsShortcutsManager(None) shortcut1 = QShortcut(None) shortcut1.setKey('x') shortcut1.setObjectName('shortcut1') shortcut2 = QShortcut(None) shortcut2.setKey('y') shortcut2.setObjectName('shortcut2') action1 = QAction('action1', None) action1.setShortcut('x') action2 = QAction('action2', None) action2.setShortcut('y') # try unregistering objects not registered in manager self.assertFalse(s.unregisterShortcut(shortcut1)) self.assertFalse(s.unregisterAction(action1)) # try unregistering objects from manager s.registerShortcut(shortcut1) s.registerShortcut(shortcut2) s.registerAction(action1) s.registerAction(action2) self.assertEqual(set(s.listActions()), set([action1, action2])) self.assertEqual(set(s.listShortcuts()), set([shortcut1, shortcut2])) self.assertTrue(s.unregisterAction(action1)) self.assertTrue(s.unregisterShortcut(shortcut1)) self.assertEqual(set(s.listActions()), set([action2])) self.assertEqual(set(s.listShortcuts()), set([shortcut2])) self.assertTrue(s.unregisterAction(action2)) self.assertTrue(s.unregisterShortcut(shortcut2))
def testList(self): """ test listing registered objects """ QSettings().clear() s = QgsShortcutsManager(None) self.assertEqual(s.listActions(), []) self.assertEqual(s.listShortcuts(), []) self.assertEqual(s.listAll(), []) shortcut1 = QShortcut(None) shortcut2 = QShortcut(None) action1 = QAction('action1', None) action2 = QAction('action2', None) s.registerShortcut(shortcut1) s.registerShortcut(shortcut2) s.registerAction(action1) s.registerAction(action2) self.assertEqual(set(s.listActions()), set([action1, action2])) self.assertEqual(set(s.listShortcuts()), set([shortcut1, shortcut2])) self.assertEqual(set(s.listAll()), set([action1, action2, shortcut1, shortcut2]))
def testRegisterAll(self): """ test registering all children """ w = QWidget() action1 = QAction('action1', w) shortcut1 = QShortcut(w) shortcut1.setObjectName('shortcut1') w2 = QWidget(w) action2 = QAction('action2', w2) shortcut2 = QShortcut(w2) shortcut2.setObjectName('shortcut2') # recursive s = QgsShortcutsManager() s.registerAllChildActions(w, True) self.assertEqual(set(s.listActions()), set([action1, action2])) s.registerAllChildShortcuts(w, True) self.assertEqual(set(s.listShortcuts()), set([shortcut1, shortcut2])) # non recursive s = QgsShortcutsManager() s.registerAllChildActions(w, False) self.assertEqual(set(s.listActions()), set([action1])) s.registerAllChildShortcuts(w, False) self.assertEqual(set(s.listShortcuts()), set([shortcut1])) # recursive s = QgsShortcutsManager() s.registerAllChildren(w, True) self.assertEqual(set(s.listActions()), set([action1, action2])) self.assertEqual(set(s.listShortcuts()), set([shortcut1, shortcut2])) # non recursive s = QgsShortcutsManager() s.registerAllChildren(w, False) self.assertEqual(set(s.listActions()), set([action1])) self.assertEqual(set(s.listShortcuts()), set([shortcut1]))
def testRegisterAll(self): """ test registering all children """ w = QWidget() action1 = QAction('action1', w) shortcut1 = QShortcut(w) shortcut1.setObjectName('shortcut1') w2 = QWidget(w) action2 = QAction('action2', w2) shortcut2 = QShortcut(w2) shortcut2.setObjectName('shortcut2') # recursive s = QgsShortcutsManager() s.registerAllChildActions(w, True) self.assertEqual(set(s.listActions()), set([action1, action2])) s.registerAllChildShortcuts(w, True) self.assertEqual(set(s.listShortcuts()), set([shortcut1, shortcut2])) # non recursive s = QgsShortcutsManager() s.registerAllChildActions(w, False) self.assertEqual(set(s.listActions()), set([action1])) s.registerAllChildShortcuts(w, False) self.assertEqual(set(s.listShortcuts()), set([shortcut1])) # recursive s = QgsShortcutsManager() s.registerAllChildren(w, True) self.assertEqual(set(s.listActions()), set([action1, action2])) self.assertEqual(set(s.listShortcuts()), set([shortcut1, shortcut2])) # non recursive s = QgsShortcutsManager() s.registerAllChildren(w, False) self.assertEqual(set(s.listActions()), set([action1])) self.assertEqual(set(s.listShortcuts()), set([shortcut1]))
def testList(self): """ test listing registered objects """ QgsSettings().clear() s = QgsShortcutsManager(None) self.assertEqual(s.listActions(), []) self.assertEqual(s.listShortcuts(), []) self.assertEqual(s.listAll(), []) shortcut1 = QShortcut(None) shortcut2 = QShortcut(None) action1 = QAction('action1', None) action2 = QAction('action2', None) s.registerShortcut(shortcut1) s.registerShortcut(shortcut2) s.registerAction(action1) s.registerAction(action2) self.assertEqual(set(s.listActions()), set([action1, action2])) self.assertEqual(set(s.listShortcuts()), set([shortcut1, shortcut2])) self.assertEqual(set(s.listAll()), set([action1, action2, shortcut1, shortcut2]))