def testEnumNew_NoLeak(self): gc.collect() total = sys.gettotalrefcount() for idx in range(1000): ret = Qt.Key(42) gc.collect() delta = sys.gettotalrefcount() - total print("delta total refcount =", delta) if abs(delta) >= 10: all = [(sys.getrefcount(x), x) for x in sys.getobjects(0)] all.sort(key=lambda x: x[0], reverse=True) for ob in all[:10]: print(ob) self.assertTrue(abs(delta) < 10)
def eventFilter(self, obj, qt_event): """ Qt keys events => EMC events """ event_type = qt_event.type() # notify the EmcGui base class of mouse moves if event_type == QtCore.QEvent.MouseMove: self._gui.mouse_move_event() return False # let Qt manage the event if event_type != QtCore.QEvent.KeyPress: return False # not a key event, let Qt manage it if not qt_event.spontaneous(): return False # we generate this event, let it goes to QML # this keyb event comes from the window, forward it to EMC by name key = Qt.Key(qt_event.key()) self._gui.key_down_send(key.name.decode()) return True # stop propagation
def testPickleEnum(self): # Pickling of enums with different depth works. ret = pickle.loads(pickle.dumps(QIODevice.Append)) self.assertEqual(ret, QIODevice.Append) ret = pickle.loads(pickle.dumps(Qt.Key.Key_Asterisk)) self.assertEqual(ret, Qt.Key.Key_Asterisk) self.assertEqual(ret, Qt.Key(42)) # We can also pickle the whole enum class (built in): ret = pickle.loads(pickle.dumps(QIODevice)) # This works also with nested classes for Python 3, after we # introduced the correct __qualname__ attribute. # Note: For Python 2, we would need quite strange patches. func = lambda: pickle.loads(pickle.dumps(Qt.Key)) if sys.version_info[0] < 3: with self.assertRaises(pickle.PicklingError): func() else: func()