|
2 | 2 | #include<pybind11/stl.h> |
3 | 3 | #include<pybind11/iostream.h> |
4 | 4 | #include<pybind11/operators.h> |
| 5 | +#include<pybind11/numpy.h> |
5 | 6 |
|
6 | 7 | #include<MimeType.h> |
| 8 | +#include<Mime.h> |
7 | 9 | #include<Bitmap.h> |
8 | 10 |
|
9 | 11 | namespacepy= pybind11; |
@@ -68,8 +70,37 @@ py::class_<BMimeType>(m, "BMimeType") |
68 | 70 | .def("Install", &BMimeType::Install,"") |
69 | 71 | .def("Delete", &BMimeType::Delete,"") |
70 | 72 | .def("IsInstalled", &BMimeType::IsInstalled,"") |
71 | | -.def("GetIcon", py::overload_cast<BBitmap *, icon_size>(&BMimeType::GetIcon, py::const_),"",py::arg("icon"),py::arg("size")) |
| 73 | +//.def("GetIcon_toBitmap", py::overload_cast<BBitmap *, icon_size>(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) //changed names to GetIcon |
| 74 | +.def("GetIcon_toBitmap", [](const BMimeType &self, icon_size size) { |
| 75 | + BBitmap *icon; |
| 76 | +// Chiamata alla funzione C++ |
| 77 | +if(size==B_LARGE_ICON){ |
| 78 | + icon =newBBitmap(BRect(0,0,31,31), B_RGBA32); |
| 79 | + }else { |
| 80 | + icon =newBBitmap(BRect(0,0,15,15), B_RGBA32); |
| 81 | + } |
| 82 | +status_t result = self.GetIcon(icon, size); |
| 83 | + |
| 84 | +// Restituisci una tupla contenente il risultato e l'oggetto BBitmap |
| 85 | +returnstd::make_tuple(result, icon); |
| 86 | + },"",py::arg("size")=B_LARGE_ICON) |
72 | 87 | //.def("GetIcon", py::overload_cast<unsigned char, size_t *>(&BMimeType::GetIcon, py::const_), "", py::arg("_data"), py::arg("_size")) |
| 88 | +.def("GetIcon_toVector", [](const BMimeType &self) { |
| 89 | + uint8 *data =nullptr; |
| 90 | +size_t size =0; |
| 91 | + |
| 92 | +// Chiamata alla funzione C++ |
| 93 | +status_t result = self.GetIcon(&data, &size); |
| 94 | + |
| 95 | +// Creazione di un array NumPy dalla memoria ottenuta |
| 96 | +auto capsule =py::capsule(data, [](void *d) { |
| 97 | +// Implementa la logica per deallocare la memoria |
| 98 | +// In questo esempio, si presume che la memoria sia stata allocata con new[] |
| 99 | +delete[]static_cast<uint8 *>(d); |
| 100 | + }); |
| 101 | + |
| 102 | +returnstd::make_tuple(result, py::array_t<uint8>({static_cast<ssize_t>(size)}, {sizeof(uint8)}, data, capsule)); |
| 103 | +},"") |
73 | 104 | .def("GetPreferredApp", &BMimeType::GetPreferredApp,"",py::arg("signature"),py::arg("verb")=B_OPEN) |
74 | 105 | .def("GetAttrInfo", &BMimeType::GetAttrInfo,"",py::arg("info")) |
75 | 106 | .def("GetFileExtensions", &BMimeType::GetFileExtensions,"",py::arg("extensions")) |
|