本文整理匯總了Python中qgis.core.QgsAction類的典型用法代碼示例。如果您正苦於以下問題:Python QgsAction類的具體用法?Python QgsAction怎麽用?Python QgsAction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QgsAction類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testDefaultAction
def testDefaultAction(self):
""" test default action for layer"""
self.manager.clearActions()
action1 = QgsAction(QgsAction.GenericPython, 'test_action', '', 'i=1', False, actionScopes={'Feature'})
self.manager.addAction(action1)
action2 = QgsAction(QgsAction.GenericPython, 'test_action2', 'i=2')
self.manager.addAction(action2)
# initially should be not set
self.assertFalse(self.manager.defaultAction('Feature').isValid())
# set bad default action
self.manager.setDefaultAction('Feature', QUuid.createUuid())
self.assertFalse(self.manager.defaultAction('Feature').isValid())
# set good default action
self.manager.setDefaultAction('Feature', action1.id())
self.assertTrue(self.manager.defaultAction('Feature').isValid())
self.assertEqual(self.manager.defaultAction('Feature').id(), action1.id())
self.assertNotEqual(self.manager.defaultAction('Feature').id(), action2.id())
# if default action is removed, should be reset to -1
self.manager.clearActions()
self.assertFalse(self.manager.defaultAction('Feature').isValid())
示例2: testAddAction
def testAddAction(self):
""" Test adding actions """
# should be empty to start with
self.assertEqual(self.manager.actions(), [])
# add an action
action1 = QgsAction(QgsAction.GenericPython, 'Test Action', 'i=1')
self.manager.addAction(action1)
self.assertEqual(len(self.manager.actions()), 1)
self.assertEqual(self.manager.actions()[0].type(), QgsAction.GenericPython)
self.assertEqual(self.manager.actions()[0].name(), 'Test Action')
self.assertEqual(self.manager.actions()[0].command(), 'i=1')
# add another action
action2 = QgsAction(QgsAction.Windows, 'Test Action2', 'i=2')
self.manager.addAction(action2)
self.assertEqual(len(self.manager.actions()), 2)
self.assertEqual(self.manager.action(action2.id()).type(), QgsAction.Windows)
self.assertEqual(self.manager.action(action2.id()).name(), 'Test Action2')
self.assertEqual(self.manager.action(action2.id()).command(), 'i=2')
id3 = self.manager.addAction(QgsAction.Generic, 'Test Action3', 'i=3')
self.assertEqual(len(self.manager.actions()), 3)
self.assertEqual(self.manager.action(id3).type(), QgsAction.Generic)
self.assertEqual(self.manager.action(id3).name(), 'Test Action3')
self.assertEqual(self.manager.action(id3).command(), 'i=3')
示例3: testDefaultAction
def testDefaultAction(self):
""" test default action for layer"""
self.manager.clearActions()
action1 = QgsAction(QgsAction.GenericPython, "test_action", "", "i=1", False, actionScopes={"Feature"})
self.manager.addAction(action1)
action2 = QgsAction(QgsAction.GenericPython, "test_action2", "i=2")
self.manager.addAction(action2)
# initially should be not set
self.assertFalse(self.manager.defaultAction("Feature").isValid())
# set bad default action
self.manager.setDefaultAction("Feature", QUuid.createUuid())
self.assertFalse(self.manager.defaultAction("Feature").isValid())
# set good default action
self.manager.setDefaultAction("Feature", action1.id())
self.assertTrue(self.manager.defaultAction("Feature").isValid())
self.assertEquals(self.manager.defaultAction("Feature").id(), action1.id())
self.assertNotEquals(self.manager.defaultAction("Feature").id(), action2.id())
# if default action is removed, should be reset to -1
self.manager.clearActions()
self.assertFalse(self.manager.defaultAction("Feature").isValid())