Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdfbf618

Browse files
committed
Fix and change funcnames for GetIcon
1 parentee626ca commitdfbf618

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

‎bindings/storage/MimeType.cpp‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#include<pybind11/stl.h>
33
#include<pybind11/iostream.h>
44
#include<pybind11/operators.h>
5+
#include<pybind11/numpy.h>
56

67
#include<MimeType.h>
8+
#include<Mime.h>
79
#include<Bitmap.h>
810

911
namespacepy= pybind11;
@@ -68,8 +70,37 @@ py::class_<BMimeType>(m, "BMimeType")
6870
.def("Install", &BMimeType::Install,"")
6971
.def("Delete", &BMimeType::Delete,"")
7072
.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)
7287
//.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+
},"")
73104
.def("GetPreferredApp", &BMimeType::GetPreferredApp,"",py::arg("signature"),py::arg("verb")=B_OPEN)
74105
.def("GetAttrInfo", &BMimeType::GetAttrInfo,"",py::arg("info"))
75106
.def("GetFileExtensions", &BMimeType::GetFileExtensions,"",py::arg("extensions"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp