return self.range == other.range
return False
+class Bitmask(Gst.Bitmask):
+ def __init__(self, v):
+ if not isinstance(v, int):
+ raise TypeError("%s is not an int." % (type(v)))
+
+ self.v = v
+
+ def __str__(self):
+ return hex(self.v)
+
+ def __eq__(self, other):
+ return self.v == other
+
+
+Bitmask = override(Bitmask)
+__all__.append('Bitmask')
+
+
if sys.version_info >= (3, 0):
Int64Range = override(Int64Range)
__all__.append('Int64Range')
}
static PyObject *
+gi_gst_bitmask_from_value (const GValue * value)
+{
+ PyObject *val, *bitmask_type;
+
+ bitmask_type = gi_gst_get_type ("Bitmask");
+ val = PyObject_CallFunction (bitmask_type, "L",
+ gst_value_get_bitmask (value));
+ Py_DECREF (bitmask_type);
+
+ return val;
+}
+
+static int
+gi_gst_bitmask_to_value (GValue * value, PyObject * object)
+{
+ PyObject *v = PyObject_GetAttrString (object, "v");
+ if (v == NULL)
+ goto fail;
+
+ gst_value_set_bitmask (value, PyLong_AsLong (v));
+
+ return 0;
+
+fail:
+ PyErr_SetString (PyExc_KeyError, "Object is not compatible with Gst.Bitmask");
+ return -1;
+}
+
+static PyObject *
gi_gst_list_from_value (const GValue * value)
{
PyObject *list, *value_list_type, *value_list;
gi_gst_date_time_from_value, gi_gst_date_time_to_value);
pyg_register_gtype_custom (GST_TYPE_FLAG_SET,
gi_gst_flag_set_from_value, gi_gst_flag_set_to_value);
+#endif
pyg_register_gtype_custom (GST_TYPE_BITMASK,
gi_gst_bitmask_from_value, gi_gst_bitmask_to_value);
-#endif
}
static int
value = st["range"]
self.assertEqual(value, range(0, 10, 2))
+
+
+class TestBitmask(TestCase):
+ def testConstructor(self):
+ Gst.init(None)
+
+ r = Gst.Bitmask(1 << 5)
+ self.assertEqual(r, 1 << 5)
+
+ def testGetValue(self):
+ Gst.init(None)
+
+ self.assertEqual(Gst.Structure('test,test=(bitmask)0x20')['test'], 1 << 5)
+
+ def testStr(self):
+ Gst.init(None)
+
+ r = Gst.Bitmask(1 << 5)
+ self.assertEqual(str(r), '0x20')