File: event_callback.py

package info (click to toggle)
pivy 0.6.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,216 kB
  • sloc: python: 36,331; cpp: 787; ansic: 733; makefile: 30; sh: 27; objc: 5
file content (44 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
from pivy.qt.QtGui import QColor
from pivy.qt.QtWidgets import QApplication
from pivy import quarter, coin


# testing if a eventcallback can remove itself.

class test(coin.SoSeparator):
    def __init__(self):
        super(test, self).__init__()
        self.events = coin.SoEventCallback()
        self += self.events
        self.cb = self.events.addEventCallback(
            coin.SoLocation2Event.getClassTypeId(), self.my_cb)
        self.cb1 = self.events.addEventCallback(
            coin.SoEvent.getClassTypeId(), self.my_cb_1)

    def my_cb(self, *args):
        self.events.removeEventCallback(
            coin.SoLocation2Event.getClassTypeId(), self.cb)

    def my_cb_1(self, *args):
        self.events.removeEventCallback(
            coin.SoEvent.getClassTypeId(), self.cb1)


def main():
    app = QApplication(sys.argv)
    viewer = quarter.QuarterWidget()

    root = coin.SoSeparator()
    root += coin.SoCone()
    root += test()

    viewer.setSceneGraph(root)
    viewer.setBackgroundColor(QColor(255, 255, 255))
    viewer.setWindowTitle("minimal")
    viewer.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()