From 0ba048c092aa9b90aaffa87edba0dda721cfb1e1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 18 Nov 2023 19:02:16 +0100 Subject: [PATCH 001/155] enable GraphicDefs and parts of View --- Jamfile | 2 + bindings/__init__.py | 3 +- bindings/interface/GraphicsDefs.cpp | 88 ++++++++++++++++-------- bindings/interface/View.cpp | 57 +++++++++++++++- tmtest.py | 100 +++++++++++++++++----------- 5 files changed, 184 insertions(+), 66 deletions(-) diff --git a/Jamfile b/Jamfile index 0d733c9..aa08352 100644 --- a/Jamfile +++ b/Jamfile @@ -145,6 +145,8 @@ local sourceFiles = Picture.cpp StringItem.cpp TabView.cpp + ScrollBar.cpp + GraphicsDefs.cpp #SupportKit SupportDefs.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index efb48f8..10c97c2 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -18,6 +18,7 @@ from .Roster import * from .Window import * from .Rect import * +from .GraphicsDefs import * from .View import * from .Control import * from .Button import * @@ -54,7 +55,7 @@ from .Picture import * from .StringItem import * from .TabView import * - +from .ScrollBar import * diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 150c068..20f646e 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -8,6 +8,20 @@ namespace py = pybind11; +struct Pattern { + std::vector data; + pattern toPattern() const { + // Assicurati che il vettore abbia la dimensione corretta + if (data.size() != 8) { + throw std::runtime_error("Invalid vector size"); + } + + // Crea una struttura pattern e copia i dati + pattern result; + std::memcpy(&result, data.data(), sizeof(pattern)); + return result; + } +}; PYBIND11_MODULE(GraphicsDefs,m) { @@ -78,9 +92,6 @@ py::enum_(m, "color_space", "") .value("B_BIG_RGB_16_BIT", color_space::B_BIG_RGB_16_BIT, "") .export_values(); -m.attr("B_VIEWS_SUPPORT_DRAW_BITMAP") = 1; -m.attr("B_BITMAPS_SUPPORT_ATTACHED_VIEWS") = 2; -m.attr("B_BITMAPS_SUPPORT_OVERLAY") = 4; py::enum_(m, "buffer_orientation", "") .value("B_BUFFER_TOP_TO_BOTTOM", buffer_orientation::B_BUFFER_TOP_TO_BOTTOM, "") @@ -154,34 +165,53 @@ m.attr("B_15_BIT_1600x1200") = 4194304; m.attr("B_15_BIT_1152x900") = 8388608; m.attr("B_8_BIT_640x400") = 2147483648; -m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; - -m.attr("B_MIXED_COLORS") = B_MIXED_COLORS; - -m.attr("B_SOLID_LOW") = B_SOLID_LOW; - -m.attr("B_TRANSPARENT_COLOR") = B_TRANSPARENT_COLOR; - m.attr("B_TRANSPARENT_MAGIC_CMAP8") = B_TRANSPARENT_MAGIC_CMAP8; - m.attr("B_TRANSPARENT_MAGIC_RGBA15") = B_TRANSPARENT_MAGIC_RGBA15; - m.attr("B_TRANSPARENT_MAGIC_RGBA15_BIG") = B_TRANSPARENT_MAGIC_RGBA15_BIG; - m.attr("B_TRANSPARENT_MAGIC_RGBA32") = B_TRANSPARENT_MAGIC_RGBA32; - m.attr("B_TRANSPARENT_MAGIC_RGBA32_BIG") = B_TRANSPARENT_MAGIC_RGBA32_BIG; - m.attr("B_TRANSPARENT_8_BIT") = B_TRANSPARENT_8_BIT; -m.attr("B_TRANSPARENT_32_BIT") = B_TRANSPARENT_32_BIT; - -m.attr("B_MAIN_SCREEN_ID") = B_MAIN_SCREEN_ID; - +/* py::class_(m, "pattern") .def_readwrite("data", &pattern::data, "") ; - +*/ +py::class_(m, "Pattern") +.def(py::init<>()) +.def_property("data", [](const Pattern &p) -> std::vector { + return p.data; + }, [](Pattern &p, const std::vector& vec) { + // Assicurati che il vettore abbia la dimensione corretta + if (vec.size() != 8) { + throw std::runtime_error("Invalid vector size"); + } + // Copia i dati dal vettore Python a Pattern + p.data = vec; + }) +.def("toPattern", &Pattern::toPattern); +; +//m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; +/* +std::vector solid_high_vector(B_SOLID_HIGH.data, B_SOLID_HIGH.data + sizeof(B_SOLID_HIGH.data)); +m.attr("B_SOLID_HIGH") = solid_high_vector; +*/ +//const pattern B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +//m.attr("B_SOLID_HIGH") = pattern{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +/* +const pattern solido = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +m.attr("B_SOLID_HIGH") = solido; +*/ +//m.attr("B_MIXED_COLORS") = B_MIXED_COLORS; +/* +std::vector mixed_colors_vector(B_MIXED_COLORS.data, B_MIXED_COLORS.data + sizeof(B_MIXED_COLORS.data)); +m.attr("B_MIXED_COLORS") = mixed_colors_vector; +*/ +//m.attr("B_SOLID_LOW") = B_SOLID_LOW; +/* +std::vector solid_low_vector(B_SOLID_LOW.data, B_SOLID_LOW.data + sizeof(B_SOLID_LOW.data)); +m.attr("B_SOLID_LOW") = solid_low_vector; +*/ py::class_(m, "rgb_color") .def("set_to", &rgb_color::set_to, "", py::arg("r"), py::arg("g"), py::arg("b"), py::arg("a")=255) .def("Brightness", &rgb_color::Brightness, "") @@ -196,9 +226,9 @@ py::class_(m, "rgb_color") py::class_(m, "color_map") .def_readwrite("id", &color_map::id, "") -.def_readwrite("color_list", &color_map::color_list, "") -.def_readwrite("inversion_map", &color_map::inversion_map, "") -.def_readwrite("index_map", &color_map::index_map, "") +//.def_readwrite("color_list", &color_map::color_list, "") +//.def_readwrite("inversion_map", &color_map::inversion_map, "") +//.def_readwrite("index_map", &color_map::index_map, "") ; py::class_(m, "overlay_rect_limits") @@ -210,7 +240,7 @@ py::class_(m, "overlay_rect_limits") .def_readwrite("max_width", &overlay_rect_limits::max_width, "") .def_readwrite("min_height", &overlay_rect_limits::min_height, "") .def_readwrite("max_height", &overlay_rect_limits::max_height, "") -.def_readwrite("reserved", &overlay_rect_limits::reserved, "") +//.def_readwrite("reserved", &overlay_rect_limits::reserved, "") ; py::class_(m, "overlay_restrictions") @@ -220,7 +250,7 @@ py::class_(m, "overlay_restrictions") .def_readwrite("max_width_scale", &overlay_restrictions::max_width_scale, "") .def_readwrite("min_height_scale", &overlay_restrictions::min_height_scale, "") .def_readwrite("max_height_scale", &overlay_restrictions::max_height_scale, "") -.def_readwrite("reserved", &overlay_restrictions::reserved, "") +//.def_readwrite("reserved", &overlay_restrictions::reserved, "") ; py::class_(m, "screen_id") @@ -243,4 +273,10 @@ m.def("bitmaps_support_space", &bitmaps_support_space, "", py::arg("space"), py: m.def("get_pixel_size_for", &get_pixel_size_for, "", py::arg("space"), py::arg("_pixelChunk"), py::arg("_rowAlignment"), py::arg("_pixelsPerChunk")); +//m.attr("B_SOLID_LOW") = const B_SOLID_LOW; +//m.attr("B_MIXED_COLORS") = const B_MIXED_COLORS; +//m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; +m.attr("B_TRANSPARENT_COLOR") = B_TRANSPARENT_COLOR; +m.attr("B_TRANSPARENT_32_BIT") = B_TRANSPARENT_32_BIT; +m.attr("B_MAIN_SCREEN_ID") = B_MAIN_SCREEN_ID; } diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index a7c31f7..2ad1e64 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -232,10 +233,55 @@ py::class_>(m, "BView") .def("MovePenBy", &BView::MovePenBy, "", py::arg("x"), py::arg("y")) .def("PenLocation", &BView::PenLocation, "") //.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("toPoint"), py::arg("pattern")=B_SOLID_HIGH) -//.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("start"), py::arg("end"), py::arg("pattern")=B_SOLID_HIGH) +//.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("toPoint"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("start"), py::arg("end"), py::arg("pattern"))//=pattern{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})//=pattern{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) //B_SOLID_HIGH) +.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("toPoint"), py::arg("pattern")) .def("BeginLineArray", &BView::BeginLineArray, "", py::arg("count")) .def("AddLine", &BView::AddLine, "", py::arg("start"), py::arg("end"), py::arg("color")) .def("EndLineArray", &BView::EndLineArray, "") + +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern"))//=B_SOLID_HIGH) +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern"))//=B_SOLID_HIGH) +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("gradient")) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("gradient")) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("gradient")) +.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("gradient")) +.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("gradient")) +.def("StrokeRect", &BView::StrokeRect, "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("gradient")) +.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("gradient")) +.def("InvertRect", &BView::InvertRect, "", py::arg("rect")) +.def("StrokeRoundRect", &BView::StrokeRoundRect, "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) +.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) +.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("gradient")) +.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) +.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) +.def("StrokeBezier", &BView::StrokeBezier, "", py::arg("controlPoints"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("gradient")) +.def("StrokeShape", &BView::StrokeShape, "", py::arg("shape"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern"))//=B_SOLID_HIGH) +.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) /* .def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) .def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) @@ -279,6 +325,7 @@ py::class_>(m, "BView") .def("StrokeShape", &BView::StrokeShape, "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) + */ .def("CopyBits", &BView::CopyBits, "", py::arg("src"), py::arg("dst")) /* @@ -303,6 +350,14 @@ py::class_>(m, "BView") .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount")) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount")) */ +.def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar")) +.def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar"), py::arg("location")) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("delta")=NULL) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("location"), py::arg("delta")=NULL) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("delta")=NULL) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("location"), py::arg("delta")=0) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount")) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount")) .def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=py::int_(0x000001FF)) .def("GetFont", &BView::GetFont, "", py::arg("font")) diff --git a/tmtest.py b/tmtest.py index 05e2588..8ef8683 100644 --- a/tmtest.py +++ b/tmtest.py @@ -1,6 +1,6 @@ -from Be import BApplication, BWindow, BListItem, BPicture, BStringItem, BAlert, BPoint, BBox, BListView, BScrollView, BRadioButton, BColorControl, BCheckBox, BRect, BTextControl, BView,BMenu,BStatusBar, BMenuBar, BMenuItem,BSeparatorItem,BStringView,BMessage,window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE +from Be import BApplication, BWindow, BListItem, BTabView, BTab, BFont, BPicture, BStringItem, BAlert, BPoint, BBox, BListView, BScrollView, BRadioButton, BColorControl, BCheckBox, BRect, BTextControl, BView,BMenu,BStatusBar, BMenuBar, BMenuItem,BSeparatorItem,BStringView,BMessage,window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE #from Be import BListItem #BStringItem -from Be import BTabView, BTab, BFont +from Be.GraphicsDefs import *#rgb_color from Be.ListView import list_view_type from Be.Alert import alert_type from Be.ColorControl import color_control_layout @@ -10,21 +10,28 @@ class StrangeItem(BStringItem): nocolor = (0, 0, 0, 0) + gcolor = (0, 200, 0, 0) def __init__(self, testo,colore): self.testo = testo self.color = colore BStringItem.__init__(self,testo) + def Text(self): + return self.testo + def Color(self): + return self.color def DrawItem(self,owner,frame,complete): + print("dissegno StrangeItem") if self.IsSelected() or complete: color = (50,50,50,255) - owner.SetHighColor(color) - owner.SetLowColor(color) - owner.FillRect(frame) + owner.SetHighColor(50,50,50,255) + owner.SetLowColor(50,50,50,255) + #owner.FillRect(frame) self.color=self.nocolor - owner.SetHighColor(self.color) - owner.MovePenTo(0,frame.Height()-2) - owner.DrawString(self.testo) - owner.SetLowColor((255,255,255,255)) + owner.SetHighColor(0, 200, 0, 0) + #owner.MovePenTo(0,frame.Height()-2) + #owner.DrawString(self.testo) + owner.SetLowColor(255,255,255,255) + BStringItem.DrawItem(self,owner,frame,complete) class NewsItem(BListItem): nocolor = (0, 0, 0, 0) @@ -37,21 +44,26 @@ def __init__(self, name,color): def DrawItem(self, owner, frame, complete): if self.IsSelected() or complete: color = (200,200,200,255) - #owner.SetHighColor(color) - #owner.SetLowColor(color) + owner.SetHighColor(200,200,200,255) + owner.SetLowColor(200,200,200,255) + paternale=Pattern() + paternale.data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] + #paternale = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] + BView.FillRect(frame,paternale.toPattern()) #owner.FillRect(frame) self.color=self.nocolor - #owner.SetHighColor(self.color) - #if self.color == (200,0,0,0): - # self.font = be_bold_font - # owner.SetFont(self.font) - #else: - # self.font = be_plain_font - # owner.SetFont(self.font) +# #owner.SetHighColor(self.color) +# #if self.color == (200,0,0,0): +# # self.font = be_bold_font +# # owner.SetFont(self.font) +# #else: +# # self.font = be_plain_font +# # owner.SetFont(self.font) frame.PrintToStream() - #owner.MovePenTo(frame[0],frame[3]-2) - #owner.DrawString(self.name) - #owner.SetLowColor((255,255,255,255)) + owner.MovePenTo(0,frame.Height()-2) + owner.DrawString("->"+self.name,None) +# #owner.SetLowColor((255,255,255,255)) + #BListItem.DrawItem(self,owner,frame,complete) def Text(self): return self.name @@ -84,6 +96,10 @@ def __init__(self): print(bounds.LeftTop()) self.panel = BView(self.Bounds(), "panel", 8, 20000000) self.box = BBox(BRect(10,26,90,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) + #self.box.SetHighColor(0, 200, 0, 0) + #paternale=Pattern() + #paternale.data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] + #self.box.FillRect(self.box.Bounds(),paternale.toPattern()) self.bar = BMenuBar(self.box.Bounds(), 'Bar') self.testo = BStringView(BRect(5,5,75,20), 'Test','prova') self.box.AddChild(self.testo,None) @@ -98,6 +114,12 @@ def __init__(self): self.sevenradio = BRadioButton(BRect(8,236,24,252),'tepidradio', 'tepid', BMessage(7)) self.nineradio = BRadioButton(BRect(8,252,24,268),'coolradio', 'cool', BMessage(9)) self.list = ScrollView(BRect(18 , 300, bounds.Width() - 18 , bounds.Height() - 40 ), 'ScrollView') + colore=self.list.lv.HighColor() + print("colore è:",colore.red,colore.green,colore.blue,colore.alpha) + colore.set_to(10,200,100,255) + print("colore modificato è:",colore.red,colore.green,colore.blue,colore.alpha) + self.list.lv.SetHighColor(colore) + self.list.lv.SetLowColor(colore) lollo=BPicture() self.list.sv.Hide() global newsitem @@ -109,16 +131,19 @@ def __init__(self): # reference to NewsItem and so cannot free it until Haiku-PyAPI # is finished with it newsitem = NewsItem("Nuova",(255,0,0,0)) - strano = StrangeItem("Prova",(0,200,0,0)) + self.elementolista=BStringItem("Questo è un BStringItem") + #global strano + strano = StrangeItem("Questo è un StrangeItem",(0,200,0,0)) print(type(self.list.lv)) print(self.list.lv.Items()) print(self.list.lv.CountItems()) self.list.lv.AddItem(newsitem) + self.list.lv.AddItem(self.elementolista) self.list.lv.AddItem(strano) print(self.list.lv.Items()) - print(self.list.lv.IndexOf(newsitem)) + print(self.list.lv.IndexOf(self.elementolista)) self.list.sv.Show() - self.panel.AddChild(self.list.topview(),None) + #self.panel.AddChild(self.list.topview(),None) self.panel.AddChild(self.sixradio,None) self.panel.AddChild(self.sevenradio,None) self.panel.AddChild(self.nineradio,None) @@ -127,6 +152,14 @@ def __init__(self): self.panel.AddChild(self.tachetest,None) self.panel.AddChild(self.statbar,None) self.panel.AddChild(self.bar,None) + for menu, items in self.Menus: + menu = BMenu(menu) + for k, name in items: + if k is None: + menu.AddItem(BSeparatorItem()) + else: + menu.AddItem(BMenuItem(name, BMessage(k),name[1],0)) + self.bar.AddItem(menu) self.tabslabels=[] self.tabsviews=[] self.tabsviews.append(self.panel) @@ -137,24 +170,15 @@ def __init__(self): #BFont.GetStringWidths(testotab,len(testotab),1,outarray)#StringWidth(chr(ord("P"))) #print(outarray) tabrect=BRect(3.0, 3.0, 30.0, self.maintabview.TabHeight()-3.0) - bviewtab=BStringView(tabrect,"scheda1","Princpiale") - scheda=BTab(bviewtab)#self.maintabview) + #bviewtab=BStringView(tabrect,"scheda1","Princpiale") + scheda=BTab(None)#bviewtab)#self.maintabview) scheda.SetLabel("Principale") self.tabslabels.append(scheda) - - print(self.tabslabels[0]) - print(self.tabsviews[0]) - self.maintabview.AddTab(self.panel,scheda)#self.tabsviews[0],self.tabslabels[0]) + self.maintabview.AddTab(self.tabsviews[0],scheda)#self.tabsviews[0],self.tabslabels[0]) self.bckgnd.AddChild(self.maintabview,None) - for menu, items in self.Menus: - menu = BMenu(menu) - for k, name in items: - if k is None: - menu.AddItem(BSeparatorItem()) - else: - menu.AddItem(BMenuItem(name, BMessage(k),name[1],0)) - self.bar.AddItem(menu) + scheda.SetLabel("Principale") self.AddChild(self.bckgnd,None) + self.panel.AddChild(self.list.topview(),None) def MessageReceived(self, msg): if msg.what == 1: From 2a4b5ba14b6788631e12694accacd73422ccc8bb Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 18 Nov 2023 21:17:38 +0100 Subject: [PATCH 002/155] missing elements GraphicsDefs.cpp, revert StringItem no derivated classes allowed --- bindings/interface/GraphicsDefs.cpp | 8 ++++++-- bindings/interface/StringItem.cpp | 8 +++++--- tmtest.py | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 20f646e..bbcf7ab 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -273,9 +273,13 @@ m.def("bitmaps_support_space", &bitmaps_support_space, "", py::arg("space"), py: m.def("get_pixel_size_for", &get_pixel_size_for, "", py::arg("space"), py::arg("_pixelChunk"), py::arg("_rowAlignment"), py::arg("_pixelsPerChunk")); -//m.attr("B_SOLID_LOW") = const B_SOLID_LOW; -//m.attr("B_MIXED_COLORS") = const B_MIXED_COLORS; +//m.attr("B_SOLID_LOW") = B_SOLID_LOW; +//m.attr("B_MIXED_COLORS") = B_MIXED_COLORS; //m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; + +m.attr("B_VIEWS_SUPPORT_DRAW_BITMAP") = 1; +m.attr("B_BITMAPS_SUPPORT_ATTACHED_VIEWS") = 2; +m.attr("B_BITMAPS_SUPPORT_OVERLAY") = 4; m.attr("B_TRANSPARENT_COLOR") = B_TRANSPARENT_COLOR; m.attr("B_TRANSPARENT_32_BIT") = B_TRANSPARENT_32_BIT; m.attr("B_MAIN_SCREEN_ID") = B_MAIN_SCREEN_ID; diff --git a/bindings/interface/StringItem.cpp b/bindings/interface/StringItem.cpp index d80f7bd..4636a2e 100644 --- a/bindings/interface/StringItem.cpp +++ b/bindings/interface/StringItem.cpp @@ -9,7 +9,7 @@ #include namespace py = pybind11; - +/* class PyStringItem : public BStringItem{ public: using BStringItem::BStringItem; @@ -17,11 +17,13 @@ class PyStringItem : public BStringItem{ PYBIND11_OVERLOAD(void, BStringItem, DrawItem, owner, frame, complete); } // TODO: there may be more methods that we should allow overloading +private: + BStringItem* item_; }; - +*/ PYBIND11_MODULE(StringItem,m) { -py::class_(m, "BStringItem") +py::class_>(m, "BStringItem") .def(py::init(), "", py::arg("text"), py::arg("outlineLevel")=0, py::arg("expanded")=true) .def(py::init(), "", py::arg("archive")) .def_static("Instantiate", &BStringItem::Instantiate, "", py::arg("archive")) diff --git a/tmtest.py b/tmtest.py index 8ef8683..20297d4 100644 --- a/tmtest.py +++ b/tmtest.py @@ -21,17 +21,17 @@ def Color(self): return self.color def DrawItem(self,owner,frame,complete): print("dissegno StrangeItem") - if self.IsSelected() or complete: - color = (50,50,50,255) - owner.SetHighColor(50,50,50,255) - owner.SetLowColor(50,50,50,255) - #owner.FillRect(frame) - self.color=self.nocolor +# if self.IsSelected() or complete: +# color = (50,50,50,255) +# owner.SetHighColor(50,50,50,255) +# owner.SetLowColor(50,50,50,255) +# #owner.FillRect(frame) +# self.color=self.nocolor owner.SetHighColor(0, 200, 0, 0) - #owner.MovePenTo(0,frame.Height()-2) - #owner.DrawString(self.testo) - owner.SetLowColor(255,255,255,255) - BStringItem.DrawItem(self,owner,frame,complete) + owner.MovePenTo(0,frame.Height()-2) + owner.DrawString(self.testo) +# owner.SetLowColor(255,255,255,255) + #BStringItem.DrawItem(self,owner,frame,complete) class NewsItem(BListItem): nocolor = (0, 0, 0, 0) From 3bcf5f6e34953a073718f0630fc8280cc37fbfe6 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 18 Nov 2023 21:38:09 +0100 Subject: [PATCH 003/155] recommenting the functions which need a pattern value --- bindings/interface/View.cpp | 107 +++++++++--------------------------- 1 file changed, 27 insertions(+), 80 deletions(-) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 2ad1e64..30702cb 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -240,93 +240,48 @@ py::class_>(m, "BView") .def("AddLine", &BView::AddLine, "", py::arg("start"), py::arg("end"), py::arg("color")) .def("EndLineArray", &BView::EndLineArray, "") -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern"))//=B_SOLID_HIGH) -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern"))//=B_SOLID_HIGH) -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +//.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +//.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +//.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("gradient")) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("gradient")) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("gradient")) -.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) +//.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) .def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("gradient")) .def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("gradient")) -.def("StrokeRect", &BView::StrokeRect, "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokeRect", &BView::StrokeRect, "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("gradient")) -.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("gradient")) .def("InvertRect", &BView::InvertRect, "", py::arg("rect")) -.def("StrokeRoundRect", &BView::StrokeRoundRect, "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokeRoundRect", &BView::StrokeRoundRect, "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) -.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) +//.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) .def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) .def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("gradient")) -.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) +//.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) .def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) .def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) -.def("StrokeBezier", &BView::StrokeBezier, "", py::arg("controlPoints"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokeBezier", &BView::StrokeBezier, "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) .def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("gradient")) -.def("StrokeShape", &BView::StrokeShape, "", py::arg("shape"), py::arg("pattern"))//=B_SOLID_HIGH) -.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern"))//=B_SOLID_HIGH) +//.def("StrokeShape", &BView::StrokeShape, "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) +//.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) -/* -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("gradient")) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("gradient")) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("gradient")) -.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) -.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("gradient")) -.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("gradient")) -.def("StrokeRect", &BView::StrokeRect, "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("gradient")) -.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("gradient")) -.def("InvertRect", &BView::InvertRect, "", py::arg("rect")) -.def("StrokeRoundRect", &BView::StrokeRoundRect, "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) -.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) -.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) -.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("gradient")) -.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) -.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) -.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) -.def("StrokeBezier", &BView::StrokeBezier, "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("gradient")) -.def("StrokeShape", &BView::StrokeShape, "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) - -*/ .def("CopyBits", &BView::CopyBits, "", py::arg("src"), py::arg("dst")) /* .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) @@ -341,14 +296,6 @@ py::class_>(m, "BView") .def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap")) .def("DrawTiledBitmapAsync", &BView::DrawTiledBitmapAsync, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) .def("DrawTiledBitmap", &BView::DrawTiledBitmap, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) -.def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar")) -.def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar"), py::arg("location")) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("delta")=NULL) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("location"), py::arg("delta")=NULL) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("delta")=NULL) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("location"), py::arg("delta")=0) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount")) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount")) */ .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar")) .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar"), py::arg("location")) From bf7a22fae1a5bfe679f81d3b4ba59d043bcc7482 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 18 Nov 2023 21:51:04 +0100 Subject: [PATCH 004/155] load Point before View in __init__.py, enable ClipToPicture ClipToInversePicture in View --- bindings/__init__.py | 3 ++- bindings/interface/View.cpp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bindings/__init__.py b/bindings/__init__.py index 10c97c2..a3b3cea 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -19,6 +19,7 @@ from .Window import * from .Rect import * from .GraphicsDefs import * +from .Point import * from .View import * from .Control import * from .Button import * @@ -42,7 +43,7 @@ from .MenuBar import * from .StatusBar import * from .CheckBox import * -from .Point import * + from .ColorControl import * from .RadioButton import * from .ListView import * diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 30702cb..d7115a1 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace py = pybind11; using namespace BPrivate; @@ -172,8 +173,16 @@ py::class_>(m, "BView") .def("LeftTop", &BView::LeftTop, "") .def("GetClippingRegion", &BView::GetClippingRegion, "", py::arg("region")) .def("ConstrainClippingRegion", &BView::ConstrainClippingRegion, "", py::arg("region")) -//.def("ClipToPicture", &BView::ClipToPicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) -//.def("ClipToInversePicture", &BView::ClipToInversePicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) +/* +.def("ClipToPicture",py::overload_cast(&BView::ClipToPicture), "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) +.def("ClipToInversePicture", &BView::ClipToInversePicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) +*/ + +//from here +.def("ClipToPicture", &BView::ClipToPicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) +.def("ClipToInversePicture", &BView::ClipToInversePicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) +//to here + .def("ClipToRect", &BView::ClipToRect, "", py::arg("rect")) .def("ClipToInverseRect", &BView::ClipToInverseRect, "", py::arg("rect")) .def("ClipToShape", &BView::ClipToShape, "", py::arg("shape")) From 77e8980811fce77bd447536a1d93e33ec877c27b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 19 Nov 2023 00:16:22 +0100 Subject: [PATCH 005/155] enable pattern in GraphicsDefs w/o readwrite data --- bindings/interface/GraphicsDefs.cpp | 18 +++++++++------- bindings/interface/View.cpp | 14 +++--------- tmtest.py | 33 +++++++++++++---------------- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index bbcf7ab..827521c 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -7,7 +7,7 @@ #include namespace py = pybind11; - +/* struct Pattern { std::vector data; pattern toPattern() const { @@ -21,7 +21,7 @@ struct Pattern { std::memcpy(&result, data.data(), sizeof(pattern)); return result; } -}; +};*/ PYBIND11_MODULE(GraphicsDefs,m) { @@ -172,11 +172,12 @@ m.attr("B_TRANSPARENT_MAGIC_RGBA32") = B_TRANSPARENT_MAGIC_RGBA32; m.attr("B_TRANSPARENT_MAGIC_RGBA32_BIG") = B_TRANSPARENT_MAGIC_RGBA32_BIG; m.attr("B_TRANSPARENT_8_BIT") = B_TRANSPARENT_8_BIT; -/* + py::class_(m, "pattern") -.def_readwrite("data", &pattern::data, "") +//.def_readwrite("data", &pattern::data, "") ; -*/ + +/* py::class_(m, "Pattern") .def(py::init<>()) .def_property("data", [](const Pattern &p) -> std::vector { @@ -191,6 +192,7 @@ py::class_(m, "Pattern") }) .def("toPattern", &Pattern::toPattern); ; +*/ //m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; /* std::vector solid_high_vector(B_SOLID_HIGH.data, B_SOLID_HIGH.data + sizeof(B_SOLID_HIGH.data)); @@ -273,9 +275,9 @@ m.def("bitmaps_support_space", &bitmaps_support_space, "", py::arg("space"), py: m.def("get_pixel_size_for", &get_pixel_size_for, "", py::arg("space"), py::arg("_pixelChunk"), py::arg("_rowAlignment"), py::arg("_pixelsPerChunk")); -//m.attr("B_SOLID_LOW") = B_SOLID_LOW; -//m.attr("B_MIXED_COLORS") = B_MIXED_COLORS; -//m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; +m.attr("B_SOLID_LOW") = B_SOLID_LOW; +m.attr("B_MIXED_COLORS") = B_MIXED_COLORS; +m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; m.attr("B_VIEWS_SUPPORT_DRAW_BITMAP") = 1; m.attr("B_BITMAPS_SUPPORT_ATTACHED_VIEWS") = 2; diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index d7115a1..44a5751 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -173,16 +173,8 @@ py::class_>(m, "BView") .def("LeftTop", &BView::LeftTop, "") .def("GetClippingRegion", &BView::GetClippingRegion, "", py::arg("region")) .def("ConstrainClippingRegion", &BView::ConstrainClippingRegion, "", py::arg("region")) -/* -.def("ClipToPicture",py::overload_cast(&BView::ClipToPicture), "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) -.def("ClipToInversePicture", &BView::ClipToInversePicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) -*/ - -//from here .def("ClipToPicture", &BView::ClipToPicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) .def("ClipToInversePicture", &BView::ClipToInversePicture, "", py::arg("picture"), py::arg("where")=B_ORIGIN, py::arg("sync")=true) -//to here - .def("ClipToRect", &BView::ClipToRect, "", py::arg("rect")) .def("ClipToInverseRect", &BView::ClipToInverseRect, "", py::arg("rect")) .def("ClipToShape", &BView::ClipToShape, "", py::arg("shape")) @@ -265,7 +257,7 @@ py::class_>(m, "BView") .def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("gradient")) .def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("gradient")) //.def("StrokeRect", &BView::StrokeRect, "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("gradient")) //.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("gradient")) @@ -292,7 +284,7 @@ py::class_>(m, "BView") //.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) .def("CopyBits", &BView::CopyBits, "", py::arg("src"), py::arg("dst")) -/* +//from here check if they work as BBitmap is not implemented .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("viewRect")) @@ -305,7 +297,7 @@ py::class_>(m, "BView") .def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap")) .def("DrawTiledBitmapAsync", &BView::DrawTiledBitmapAsync, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) .def("DrawTiledBitmap", &BView::DrawTiledBitmap, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) -*/ +//to here .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar")) .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar"), py::arg("location")) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("delta")=NULL) diff --git a/tmtest.py b/tmtest.py index 20297d4..cb0b138 100644 --- a/tmtest.py +++ b/tmtest.py @@ -44,25 +44,21 @@ def __init__(self, name,color): def DrawItem(self, owner, frame, complete): if self.IsSelected() or complete: color = (200,200,200,255) - owner.SetHighColor(200,200,200,255) + owner.SetHighColor(150,0,0,0) owner.SetLowColor(200,200,200,255) - paternale=Pattern() - paternale.data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] - #paternale = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] - BView.FillRect(frame,paternale.toPattern()) - #owner.FillRect(frame) + owner.FillRect(frame) self.color=self.nocolor -# #owner.SetHighColor(self.color) -# #if self.color == (200,0,0,0): -# # self.font = be_bold_font -# # owner.SetFont(self.font) -# #else: -# # self.font = be_plain_font -# # owner.SetFont(self.font) + #owner.SetHighColor(self.color) + #if self.color == (200,0,0,0): + # self.font = be_bold_font + # owner.SetFont(self.font) + #else: + # self.font = be_plain_font + # owner.SetFont(self.font) frame.PrintToStream() - owner.MovePenTo(0,frame.Height()-2) + owner.MovePenTo(5,frame.Height()-2) owner.DrawString("->"+self.name,None) -# #owner.SetLowColor((255,255,255,255)) + owner.SetLowColor(255,255,255,255) #BListItem.DrawItem(self,owner,frame,complete) def Text(self): @@ -134,9 +130,10 @@ def __init__(self): self.elementolista=BStringItem("Questo è un BStringItem") #global strano strano = StrangeItem("Questo è un StrangeItem",(0,200,0,0)) - print(type(self.list.lv)) - print(self.list.lv.Items()) - print(self.list.lv.CountItems()) + print("strano gcolor è:",strano.gcolor) + #print(type(self.list.lv)) + #print(self.list.lv.Items()) + #print(self.list.lv.CountItems()) self.list.lv.AddItem(newsitem) self.list.lv.AddItem(self.elementolista) self.list.lv.AddItem(strano) From 19e3149b27241fb60f153a8a56e6582ea02b9c39 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 19 Nov 2023 00:20:35 +0100 Subject: [PATCH 006/155] enable readonly pattern.data --- bindings/interface/GraphicsDefs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 827521c..2fa0af5 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -175,6 +175,7 @@ m.attr("B_TRANSPARENT_8_BIT") = B_TRANSPARENT_8_BIT; py::class_(m, "pattern") //.def_readwrite("data", &pattern::data, "") +.def_readonly("data", &pattern::data, "") ; /* From a554349a2cc583cec215b4302bea2b83150baa2b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 19 Nov 2023 01:03:37 +0100 Subject: [PATCH 007/155] enable in readonly mode color_map definitions --- bindings/interface/GraphicsDefs.cpp | 38 ++++++++--------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 2fa0af5..4b56b2a 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -7,6 +7,7 @@ #include namespace py = pybind11; + /* struct Pattern { std::vector data; @@ -172,12 +173,6 @@ m.attr("B_TRANSPARENT_MAGIC_RGBA32") = B_TRANSPARENT_MAGIC_RGBA32; m.attr("B_TRANSPARENT_MAGIC_RGBA32_BIG") = B_TRANSPARENT_MAGIC_RGBA32_BIG; m.attr("B_TRANSPARENT_8_BIT") = B_TRANSPARENT_8_BIT; - -py::class_(m, "pattern") -//.def_readwrite("data", &pattern::data, "") -.def_readonly("data", &pattern::data, "") -; - /* py::class_(m, "Pattern") .def(py::init<>()) @@ -192,29 +187,13 @@ py::class_(m, "Pattern") p.data = vec; }) .def("toPattern", &Pattern::toPattern); +;*/ + +py::class_(m, "pattern") +//.def_readwrite("data", &pattern::data, "") +.def_readonly("data", &pattern::data, "") ; -*/ -//m.attr("B_SOLID_HIGH") = B_SOLID_HIGH; -/* -std::vector solid_high_vector(B_SOLID_HIGH.data, B_SOLID_HIGH.data + sizeof(B_SOLID_HIGH.data)); -m.attr("B_SOLID_HIGH") = solid_high_vector; -*/ -//const pattern B_SOLID_HIGH = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -//m.attr("B_SOLID_HIGH") = pattern{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -/* -const pattern solido = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -m.attr("B_SOLID_HIGH") = solido; -*/ -//m.attr("B_MIXED_COLORS") = B_MIXED_COLORS; -/* -std::vector mixed_colors_vector(B_MIXED_COLORS.data, B_MIXED_COLORS.data + sizeof(B_MIXED_COLORS.data)); -m.attr("B_MIXED_COLORS") = mixed_colors_vector; -*/ -//m.attr("B_SOLID_LOW") = B_SOLID_LOW; -/* -std::vector solid_low_vector(B_SOLID_LOW.data, B_SOLID_LOW.data + sizeof(B_SOLID_LOW.data)); -m.attr("B_SOLID_LOW") = solid_low_vector; -*/ + py::class_(m, "rgb_color") .def("set_to", &rgb_color::set_to, "", py::arg("r"), py::arg("g"), py::arg("b"), py::arg("a")=255) .def("Brightness", &rgb_color::Brightness, "") @@ -230,8 +209,11 @@ py::class_(m, "rgb_color") py::class_(m, "color_map") .def_readwrite("id", &color_map::id, "") //.def_readwrite("color_list", &color_map::color_list, "") +.def_readonly("color_list", &color_map::color_list, "") //.def_readwrite("inversion_map", &color_map::inversion_map, "") +.def_readonly("inversion_map", &color_map::inversion_map, "") //.def_readwrite("index_map", &color_map::index_map, "") +.def_readonly("index_map", &color_map::index_map, "") ; py::class_(m, "overlay_rect_limits") From dcc20d3e7f17385233d10e3b91a34451212d0775 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 19 Nov 2023 02:56:31 +0100 Subject: [PATCH 008/155] Enable PictureButton --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/interface/PictureButton.cpp | 11 +++++-- tmtest.py | 44 ++++++++++++++-------------- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/Jamfile b/Jamfile index aa08352..3ddf41d 100644 --- a/Jamfile +++ b/Jamfile @@ -143,6 +143,7 @@ local sourceFiles = #Bitmap.cpp #Slider.cpp Picture.cpp + PictureButton.cpp StringItem.cpp TabView.cpp ScrollBar.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index a3b3cea..6b308a7 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -54,6 +54,7 @@ #from .Bitmap import * #from .Slider import * from .Picture import * +from .PictureButton import * from .StringItem import * from .TabView import * from .ScrollBar import * diff --git a/bindings/interface/PictureButton.cpp b/bindings/interface/PictureButton.cpp index a005d9c..f3af4e7 100644 --- a/bindings/interface/PictureButton.cpp +++ b/bindings/interface/PictureButton.cpp @@ -6,16 +6,21 @@ #include #include #include +#include namespace py = pybind11; PYBIND11_MODULE(PictureButton,m) { -m.attr("B_ONE_STATE_BUTTON") = 0; -m.attr("B_TWO_STATE_BUTTON") = 1; +//m.attr("B_ONE_STATE_BUTTON") = 0; +//m.attr("B_TWO_STATE_BUTTON") = 1; +py::enum_(m, "picture_button_behavior", "") +.value("B_ONE_STATE_BUTTON", picture_button_behavior::B_ONE_STATE_BUTTON, "") +.value("B_TWO_STATE_BUTTON", picture_button_behavior::B_TWO_STATE_BUTTON, "") +.export_values(); -py::class_(m, "BPictureButton") +py::class_>(m, "BPictureButton") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("off"), py::arg("on"), py::arg("message"), py::arg("behavior")=B_ONE_STATE_BUTTON, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flgs")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("archive")) .def_static("Instantiate", &BPictureButton::Instantiate, "", py::arg("archive")) diff --git a/tmtest.py b/tmtest.py index cb0b138..4be0604 100644 --- a/tmtest.py +++ b/tmtest.py @@ -1,6 +1,7 @@ from Be import BApplication, BWindow, BListItem, BTabView, BTab, BFont, BPicture, BStringItem, BAlert, BPoint, BBox, BListView, BScrollView, BRadioButton, BColorControl, BCheckBox, BRect, BTextControl, BView,BMenu,BStatusBar, BMenuBar, BMenuItem,BSeparatorItem,BStringView,BMessage,window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE -#from Be import BListItem #BStringItem -from Be.GraphicsDefs import *#rgb_color +from Be import BPictureButton +from Be.PictureButton import picture_button_behavior +from Be.GraphicsDefs import * from Be.ListView import list_view_type from Be.Alert import alert_type from Be.ColorControl import color_control_layout @@ -19,35 +20,29 @@ def Text(self): return self.testo def Color(self): return self.color - def DrawItem(self,owner,frame,complete): - print("dissegno StrangeItem") -# if self.IsSelected() or complete: -# color = (50,50,50,255) -# owner.SetHighColor(50,50,50,255) -# owner.SetLowColor(50,50,50,255) -# #owner.FillRect(frame) -# self.color=self.nocolor - owner.SetHighColor(0, 200, 0, 0) - owner.MovePenTo(0,frame.Height()-2) - owner.DrawString(self.testo) -# owner.SetLowColor(255,255,255,255) - #BStringItem.DrawItem(self,owner,frame,complete) class NewsItem(BListItem): nocolor = (0, 0, 0, 0) def __init__(self, name,color): self.name = name + print("inizializzato con color:"+str(color)) self.color=color BListItem.__init__(self) def DrawItem(self, owner, frame, complete): if self.IsSelected() or complete: color = (200,200,200,255) - owner.SetHighColor(150,0,0,0) + #print("HighColor era:",str(owner.HighColor().red),str(owner.HighColor().green),str(owner.HighColor().blue),str(owner.HighColor().alpha)) + #print("LowColor era:",str(owner.LowColor().red),str(owner.LowColor().green),str(owner.LowColor().blue),str(owner.LowColor().alpha)) + owner.SetHighColor(180,0,0,255) owner.SetLowColor(200,200,200,255) + #print("HighColor ora è:",str(owner.HighColor().red),str(owner.HighColor().green),str(owner.HighColor().blue),str(owner.HighColor().alpha)) + #print("LowColor ora è:",str(owner.LowColor().red),str(owner.LowColor().green),str(owner.LowColor().blue),str(owner.LowColor().alpha)) owner.FillRect(frame) - self.color=self.nocolor + owner.SetHighColor(0,0,0,255) + owner.SetLowColor(255,255,255,255) + #self.color=self.nocolor #owner.SetHighColor(self.color) #if self.color == (200,0,0,0): # self.font = be_bold_font @@ -55,11 +50,9 @@ def DrawItem(self, owner, frame, complete): #else: # self.font = be_plain_font # owner.SetFont(self.font) - frame.PrintToStream() + #frame.PrintToStream() owner.MovePenTo(5,frame.Height()-2) - owner.DrawString("->"+self.name,None) - owner.SetLowColor(255,255,255,255) - #BListItem.DrawItem(self,owner,frame,complete) + owner.DrawString("▶ "+self.name,None) def Text(self): return self.name @@ -116,7 +109,13 @@ def __init__(self): print("colore modificato è:",colore.red,colore.green,colore.blue,colore.alpha) self.list.lv.SetHighColor(colore) self.list.lv.SetLowColor(colore) - lollo=BPicture() + bup=BPicture() + arrgh=[] + arrgh.append(BView.MovePenTo(BPoint(3.0,16.0))) + arrgh.append(BView.DrawString("On",None)) + bup.Play(arrgh,len(arrgh),None) + bdown=BPicture() + butupdown=BPictureButton(BRect(bounds.Width()-32,220,bounds.Width()-16,236),"TwoStateButt",bup,bdown,BMessage(333),picture_button_behavior.B_TWO_STATE_BUTTON) self.list.sv.Hide() global newsitem # TODO: newsitem (defined below) seems to be freed by Python as soon @@ -144,6 +143,7 @@ def __init__(self): self.panel.AddChild(self.sixradio,None) self.panel.AddChild(self.sevenradio,None) self.panel.AddChild(self.nineradio,None) + self.panel.AddChild(butupdown,None) self.panel.AddChild(self.cc,None) self.panel.AddChild(self.startimer,None) self.panel.AddChild(self.tachetest,None) From 2d2fee70dbe283e0ed05683880a1786e39aee442 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 19 Nov 2023 03:00:24 +0100 Subject: [PATCH 009/155] enable remaining drawing functions --- bindings/interface/View.cpp | 59 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 44a5751..1845d3e 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -233,55 +233,52 @@ py::class_>(m, "BView") .def("MovePenTo", py::overload_cast(&BView::MovePenTo), "", py::arg("x"), py::arg("y")) .def("MovePenBy", &BView::MovePenBy, "", py::arg("x"), py::arg("y")) .def("PenLocation", &BView::PenLocation, "") -//.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("toPoint"), py::arg("pattern")=B_SOLID_HIGH) -//.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("toPoint"), py::arg("pattern")=B_SOLID_HIGH) -.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("start"), py::arg("end"), py::arg("pattern"))//=pattern{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})//=pattern{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) //B_SOLID_HIGH) -.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("toPoint"), py::arg("pattern")) +.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("toPoint"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeLine", py::overload_cast(&BView::StrokeLine), "", py::arg("start"), py::arg("end"), py::arg("pattern")=B_SOLID_HIGH) .def("BeginLineArray", &BView::BeginLineArray, "", py::arg("count")) .def("AddLine", &BView::AddLine, "", py::arg("start"), py::arg("end"), py::arg("color")) .def("EndLineArray", &BView::EndLineArray, "") - -//.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -//.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -//.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -//.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("gradient")) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("gradient")) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("gradient")) -//.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) -//.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) .def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("gradient")) .def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("gradient")) -//.def("StrokeRect", &BView::StrokeRect, "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeRect", &BView::StrokeRect, "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRect", py::overload_cast(&BView::FillRect), "", py::arg("rect"), py::arg("gradient")) -//.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRegion", py::overload_cast(&BView::FillRegion), "", py::arg("rectegion"), py::arg("gradient")) .def("InvertRect", &BView::InvertRect, "", py::arg("rect")) -//.def("StrokeRoundRect", &BView::StrokeRoundRect, "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeRoundRect", &BView::StrokeRoundRect, "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) .def("FillRoundRect", py::overload_cast(&BView::FillRoundRect), "", py::arg("rect"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) -//.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) -//.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeEllipse", py::overload_cast(&BView::StrokeEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("pattern")=B_SOLID_HIGH) .def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("gradient")) .def("FillEllipse", py::overload_cast(&BView::FillEllipse), "", py::arg("rect"), py::arg("gradient")) -//.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) -//.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeArc", py::overload_cast(&BView::StrokeArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("pattern")=B_SOLID_HIGH) .def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("center"), py::arg("xRadius"), py::arg("yRadius"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) .def("FillArc", py::overload_cast(&BView::FillArc), "", py::arg("rect"), py::arg("startAngle"), py::arg("arcAngle"), py::arg("gradient")) -//.def("StrokeBezier", &BView::StrokeBezier, "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeBezier", &BView::StrokeBezier, "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("pattern")=B_SOLID_HIGH) .def("FillBezier", py::overload_cast(&BView::FillBezier), "", py::arg("controlPoints"), py::arg("gradient")) -//.def("StrokeShape", &BView::StrokeShape, "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) -//.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) +.def("StrokeShape", &BView::StrokeShape, "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) .def("CopyBits", &BView::CopyBits, "", py::arg("src"), py::arg("dst")) //from here check if they work as BBitmap is not implemented From 273ee72d0b72885caff2abf965e106e264919bfa Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 19 Nov 2023 03:33:57 +0100 Subject: [PATCH 010/155] check BBox crash on exit --- tmtest.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/tmtest.py b/tmtest.py index 4be0604..dd72aef 100644 --- a/tmtest.py +++ b/tmtest.py @@ -1,5 +1,5 @@ from Be import BApplication, BWindow, BListItem, BTabView, BTab, BFont, BPicture, BStringItem, BAlert, BPoint, BBox, BListView, BScrollView, BRadioButton, BColorControl, BCheckBox, BRect, BTextControl, BView,BMenu,BStatusBar, BMenuBar, BMenuItem,BSeparatorItem,BStringView,BMessage,window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE -from Be import BPictureButton +from Be import BPictureButton, BTextView from Be.PictureButton import picture_button_behavior from Be.GraphicsDefs import * from Be.ListView import list_view_type @@ -84,12 +84,15 @@ def __init__(self): self.maintabview = BTabView(BRect(2.0, 2.0, bounds.Width()-2.0, bounds.Height()-2.0), 'tabview') print(bounds.LeftTop()) self.panel = BView(self.Bounds(), "panel", 8, 20000000) - self.box = BBox(BRect(10,26,90,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) + self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) + self.box = BBox(BRect(200,26,280,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) + self.box2 = BBox(BRect(10,26,90,51),"MYBox2",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) + self.panel2.AddChild(self.box2,None) #self.box.SetHighColor(0, 200, 0, 0) #paternale=Pattern() #paternale.data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] #self.box.FillRect(self.box.Bounds(),paternale.toPattern()) - self.bar = BMenuBar(self.box.Bounds(), 'Bar') + self.bar = BMenuBar(self.panel.Bounds(), 'Bar') self.testo = BStringView(BRect(5,5,75,20), 'Test','prova') self.box.AddChild(self.testo,None) self.statbar = BStatusBar(BRect(10,70,bounds.Width()/3-15,144), 'progress','0%', '100%') @@ -110,12 +113,12 @@ def __init__(self): self.list.lv.SetHighColor(colore) self.list.lv.SetLowColor(colore) bup=BPicture() - arrgh=[] - arrgh.append(BView.MovePenTo(BPoint(3.0,16.0))) - arrgh.append(BView.DrawString("On",None)) - bup.Play(arrgh,len(arrgh),None) + #arrgh=[] + #arrgh.append(BView.MovePenTo(BPoint(3.0,16.0))) + #arrgh.append(BView.DrawString("On",None)) + #bup.Play(arrgh,len(arrgh),None) bdown=BPicture() - butupdown=BPictureButton(BRect(bounds.Width()-32,220,bounds.Width()-16,236),"TwoStateButt",bup,bdown,BMessage(333),picture_button_behavior.B_TWO_STATE_BUTTON) + butupdown=BPictureButton(BRect(bounds.Width()-32,180,bounds.Width()-16,196),"TwoStateButt",bup,bdown,BMessage(333),picture_button_behavior.B_TWO_STATE_BUTTON) self.list.sv.Hide() global newsitem # TODO: newsitem (defined below) seems to be freed by Python as soon @@ -128,7 +131,7 @@ def __init__(self): newsitem = NewsItem("Nuova",(255,0,0,0)) self.elementolista=BStringItem("Questo è un BStringItem") #global strano - strano = StrangeItem("Questo è un StrangeItem",(0,200,0,0)) + strano = StrangeItem("Questo è uno StrangeItem",(0,200,0,0)) print("strano gcolor è:",strano.gcolor) #print(type(self.list.lv)) #print(self.list.lv.Items()) @@ -140,6 +143,7 @@ def __init__(self): print(self.list.lv.IndexOf(self.elementolista)) self.list.sv.Show() #self.panel.AddChild(self.list.topview(),None) + self.panel.AddChild(self.box,None) self.panel.AddChild(self.sixradio,None) self.panel.AddChild(self.sevenradio,None) self.panel.AddChild(self.nineradio,None) @@ -160,20 +164,21 @@ def __init__(self): self.tabslabels=[] self.tabsviews=[] self.tabsviews.append(self.panel) - #testotab=[] - #for char in "Principale": - # testotab.append(char) - #outarray=[] - #BFont.GetStringWidths(testotab,len(testotab),1,outarray)#StringWidth(chr(ord("P"))) - #print(outarray) + self.tabsviews.append(self.panel2) + + tabrect=BRect(3.0, 3.0, 30.0, self.maintabview.TabHeight()-3.0) - #bviewtab=BStringView(tabrect,"scheda1","Princpiale") - scheda=BTab(None)#bviewtab)#self.maintabview) - scheda.SetLabel("Principale") + scheda=BTab(None) + #scheda.SetLabel("Principale") <--- works after maintabview.AddTab + scheda2=BTab(None) self.tabslabels.append(scheda) - self.maintabview.AddTab(self.tabsviews[0],scheda)#self.tabsviews[0],self.tabslabels[0]) + self.tabslabels.append(scheda2) + + self.maintabview.AddTab(self.tabsviews[0],self.tabslabels[0])#self.tabsviews[0],self.tabslabels[0]) + self.maintabview.AddTab(self.tabsviews[1],self.tabslabels[1]) self.bckgnd.AddChild(self.maintabview,None) scheda.SetLabel("Principale") + scheda2.SetLabel("Scrittura") self.AddChild(self.bckgnd,None) self.panel.AddChild(self.list.topview(),None) From 95e068a145efab8f8f7a9df56beeb87618bdb19a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 19 Nov 2023 06:18:18 +0100 Subject: [PATCH 011/155] a SetFontAndColor in TextView, cleanups in GraphicsDefs --- bindings/interface/GraphicsDefs.cpp | 32 --------------------- bindings/interface/TextView.cpp | 1 + tmtest.py | 43 +++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 4b56b2a..3e7fd1a 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -8,22 +8,6 @@ namespace py = pybind11; -/* -struct Pattern { - std::vector data; - pattern toPattern() const { - // Assicurati che il vettore abbia la dimensione corretta - if (data.size() != 8) { - throw std::runtime_error("Invalid vector size"); - } - - // Crea una struttura pattern e copia i dati - pattern result; - std::memcpy(&result, data.data(), sizeof(pattern)); - return result; - } -};*/ - PYBIND11_MODULE(GraphicsDefs,m) { py::enum_(m, "color_space", "") @@ -173,22 +157,6 @@ m.attr("B_TRANSPARENT_MAGIC_RGBA32") = B_TRANSPARENT_MAGIC_RGBA32; m.attr("B_TRANSPARENT_MAGIC_RGBA32_BIG") = B_TRANSPARENT_MAGIC_RGBA32_BIG; m.attr("B_TRANSPARENT_8_BIT") = B_TRANSPARENT_8_BIT; -/* -py::class_(m, "Pattern") -.def(py::init<>()) -.def_property("data", [](const Pattern &p) -> std::vector { - return p.data; - }, [](Pattern &p, const std::vector& vec) { - // Assicurati che il vettore abbia la dimensione corretta - if (vec.size() != 8) { - throw std::runtime_error("Invalid vector size"); - } - // Copia i dati dal vettore Python a Pattern - p.data = vec; - }) -.def("toPattern", &Pattern::toPattern); -;*/ - py::class_(m, "pattern") //.def_readwrite("data", &pattern::data, "") .def_readonly("data", &pattern::data, "") diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 6c4afcf..095b1c6 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -85,6 +85,7 @@ py::class_>(m, "BTextV .def("Select", &BTextView::Select, "", py::arg("startOffset"), py::arg("endOffset")) .def("SelectAll", &BTextView::SelectAll, "") .def("GetSelection", &BTextView::GetSelection, "", py::arg("_start"), py::arg("_end")) +.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("font"), py::arg("mode")=511, py::arg("color")=NULL) //nullptr) //.def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) //.def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) //.def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("offset"), py::arg("_font"), py::arg("_color")=NULL) diff --git a/tmtest.py b/tmtest.py index dd72aef..a61e6e8 100644 --- a/tmtest.py +++ b/tmtest.py @@ -86,7 +86,7 @@ def __init__(self): self.panel = BView(self.Bounds(), "panel", 8, 20000000) self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) self.box = BBox(BRect(200,26,280,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) - self.box2 = BBox(BRect(10,26,90,51),"MYBox2",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) + self.box2 = BBox(BRect(10,10,self.panel2.Bounds().Width()-20,40),"MYBox2",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.panel2.AddChild(self.box2,None) #self.box.SetHighColor(0, 200, 0, 0) #paternale=Pattern() @@ -97,7 +97,7 @@ def __init__(self): self.box.AddChild(self.testo,None) self.statbar = BStatusBar(BRect(10,70,bounds.Width()/3-15,144), 'progress','0%', '100%') self.statbar.SetMaxValue(100.0) - self.tachetest=BTextControl(BRect(57,bounds.Height()-30,bounds.Width()-57,bounds.Height()-12),'TxTView', "prova:",None,BMessage(1),0x0202|0x0404) + self.tachetest=BTextControl(BRect(57,bounds.Height()-30,bounds.Width()-57,bounds.Height()-12),'TxTCtrl', "prova:",None,BMessage(1),0x0202|0x0404) self.tachetest.SetDivider(55.0) self.startimer= BCheckBox(BRect(10,30,290,50),'Testbox','Test Checkbox',BMessage(612)) self.point=BPoint() @@ -105,13 +105,15 @@ def __init__(self): self.sixradio = BRadioButton(BRect(8,220,24,236),'hotradio', 'hot', BMessage(6)) self.sevenradio = BRadioButton(BRect(8,236,24,252),'tepidradio', 'tepid', BMessage(7)) self.nineradio = BRadioButton(BRect(8,252,24,268),'coolradio', 'cool', BMessage(9)) - self.list = ScrollView(BRect(18 , 300, bounds.Width() - 18 , bounds.Height() - 40 ), 'ScrollView') - colore=self.list.lv.HighColor() - print("colore è:",colore.red,colore.green,colore.blue,colore.alpha) - colore.set_to(10,200,100,255) - print("colore modificato è:",colore.red,colore.green,colore.blue,colore.alpha) - self.list.lv.SetHighColor(colore) - self.list.lv.SetLowColor(colore) + + # Handling colors################## + #colore=self.list.lv.HighColor() + #print("colore è:",colore.red,colore.green,colore.blue,colore.alpha) + #colore.set_to(10,200,100,255) + #print("colore modificato è:",colore.red,colore.green,colore.blue,colore.alpha) + #self.list.lv.SetHighColor(colore) + #self.list.lv.SetLowColor(colore) + #################################### bup=BPicture() #arrgh=[] #arrgh.append(BView.MovePenTo(BPoint(3.0,16.0))) @@ -119,7 +121,10 @@ def __init__(self): #bup.Play(arrgh,len(arrgh),None) bdown=BPicture() butupdown=BPictureButton(BRect(bounds.Width()-32,180,bounds.Width()-16,196),"TwoStateButt",bup,bdown,BMessage(333),picture_button_behavior.B_TWO_STATE_BUTTON) - self.list.sv.Hide() + + + self.list = ScrollView(BRect(8 , 300, bounds.Width() - 18 , bounds.Height() - 42 ), 'ScrollView') + #self.list.sv.Hide() global newsitem # TODO: newsitem (defined below) seems to be freed by Python as soon # as Python is finished with the __init__ function. But we still @@ -174,11 +179,27 @@ def __init__(self): self.tabslabels.append(scheda) self.tabslabels.append(scheda2) - self.maintabview.AddTab(self.tabsviews[0],self.tabslabels[0])#self.tabsviews[0],self.tabslabels[0]) + self.maintabview.AddTab(self.tabsviews[0],self.tabslabels[0]) self.maintabview.AddTab(self.tabsviews[1],self.tabslabels[1]) + self.bckgnd.AddChild(self.maintabview,None) scheda.SetLabel("Principale") scheda2.SetLabel("Scrittura") + + from Be.Font import be_plain_font + from Be.Font import be_bold_font + #from Be.View import set_font_mask + self.typtap=BTextView(BRect(10,45,self.panel2.Bounds().Width()-20,self.panel2.Bounds().Height()-20-self.maintabview.TabHeight()), 'TxTView', BRect(5,5,self.panel2.Bounds().Width()-35,self.panel2.Bounds().Height()-30-self.maintabview.TabHeight()), 0x1234, 20000000) + self.typtap.SetStylable(1) + self.panel2.AddChild(self.typtap,None) + colore=self.panel.HighColor() + print(colore.red,colore.green,colore.blue,colore.alpha) + colore.red=180 + self.typtap.SetFontAndColor(be_plain_font,511,colore)#B_FONT_ALL = 511 + stuff = '\n\t\t\t\t\t\t\tHello Haiku!\n\n\t\t\t\t\t\t\t\t\t\t\tA simple test program\n\t\t\t\t\t\t\t\t\t\t\tfor Haiku, version 1.0\n\t\t\t\t\t\t\t\t\t\t\tsample code included!\n\n\t\t\t\t\t\t\t\t\t\t\tby Fabio Tomat aka TmTFx\n\t\t\t\t\t\t\t\t\t\t\tand others\n\t\t\t\t\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\t\t\t\t\tspecial thanks to:\n\t\t\t\t\t\t\t\t\t\t\tZardshard and coolcoder613' + #n = stuff.find('Bulletin Gator') + #m = stuff.find('This') + self.typtap.SetText(stuff,None)#, [(0, be_plain_font, (0, 0, 0, 0)), (n, be_bold_font, (0, 150, 0, 0)), (n + 14, be_plain_font, (0, 0, 0, 0)),(m,be_plain_font,(100,150,0,0))]) self.AddChild(self.bckgnd,None) self.panel.AddChild(self.list.topview(),None) From 34751a4d02c0817953d1385dd8a1736bcbdcf7d1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 21 Nov 2023 18:32:17 +0100 Subject: [PATCH 012/155] enable SetFontAndColor/GetFontAndColor in TextView --- bindings/interface/TextView.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 095b1c6..983e493 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -85,11 +85,12 @@ py::class_>(m, "BTextV .def("Select", &BTextView::Select, "", py::arg("startOffset"), py::arg("endOffset")) .def("SelectAll", &BTextView::SelectAll, "") .def("GetSelection", &BTextView::GetSelection, "", py::arg("_start"), py::arg("_end")) -.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("font"), py::arg("mode")=511, py::arg("color")=NULL) //nullptr) +.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("font"), py::arg("mode")=511, py::arg("color")=NULL) //hadcoded B_FONT_ALL 511 //.def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) +.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=511, py::arg("color")=NULL) //.def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) -//.def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("offset"), py::arg("_font"), py::arg("_color")=NULL) -//.def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("_font"), py::arg("_mode"), py::arg("_color")=NULL, py::arg("_sameColor")=NULL) +.def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("offset"), py::arg("_font"), py::arg("_color")=NULL) +.def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("_font"), py::arg("_mode"), py::arg("_color")=NULL, py::arg("_sameColor")=NULL) .def("SetRunArray", &BTextView::SetRunArray, "", py::arg("startOffset"), py::arg("endOffset"), py::arg("runs")) .def("RunArray", &BTextView::RunArray, "", py::arg("startOffset"), py::arg("endOffset"), py::arg("_size")=NULL) .def("LineAt", py::overload_cast(&BTextView::LineAt,py::const_), "", py::arg("offset")) From 189c2cb8e415fdebfbc4a09684671602961425ce Mon Sep 17 00:00:00 2001 From: coolcoder613eb Date: Wed, 22 Nov 2023 10:02:53 +1100 Subject: [PATCH 013/155] Fix for 32-bit --- bindings/interface/ListView.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/interface/ListView.cpp b/bindings/interface/ListView.cpp index 76b559f..e527926 100644 --- a/bindings/interface/ListView.cpp +++ b/bindings/interface/ListView.cpp @@ -78,9 +78,9 @@ py::class_>( .def("AddItem", py::overload_cast(&BListView::AddItem), "", py::arg("item")) .def("AddItem", py::overload_cast(&BListView::AddItem), "", py::arg("item"), py::arg("atIndex")) .def("AddList", py::overload_cast(&BListView::AddList), "", py::arg("newItems")) -.def("AddList", py::overload_cast(&BListView::AddList), "", py::arg("newItems"), py::arg("atIndex")) +.def("AddList", py::overload_cast(&BListView::AddList), "", py::arg("newItems"), py::arg("atIndex")) .def("RemoveItem", py::overload_cast(&BListView::RemoveItem), "", py::arg("item")) -.def("RemoveItem", py::overload_cast(&BListView::RemoveItem), "", py::arg("index")) +.def("RemoveItem", py::overload_cast(&BListView::RemoveItem), "", py::arg("index")) .def("RemoveItems", &BListView::RemoveItems, "", py::arg("index"), py::arg("count")) .def("SetSelectionMessage", &BListView::SetSelectionMessage, "", py::arg("message")) .def("SetInvocationMessage", &BListView::SetInvocationMessage, "", py::arg("message")) @@ -127,8 +127,8 @@ py::class_>( }, "") .def("InvalidateItem", &BListView::InvalidateItem, "", py::arg("index")) .def("ScrollToSelection", &BListView::ScrollToSelection, "") -.def("Select", py::overload_cast(&BListView::Select), "", py::arg("index"), py::arg("extend")=false) -.def("Select", py::overload_cast(&BListView::Select), "", py::arg("from"), py::arg("to"), py::arg("extend")=false) +.def("Select", py::overload_cast(&BListView::Select), "", py::arg("index"), py::arg("extend")=false) +.def("Select", py::overload_cast(&BListView::Select), "", py::arg("from"), py::arg("to"), py::arg("extend")=false) .def("IsItemSelected", &BListView::IsItemSelected, "", py::arg("index")) .def("CurrentSelection", &BListView::CurrentSelection, "", py::arg("index")=0) .def("Invoke", &BListView::Invoke, "", py::arg("message")=NULL) From 4e5df5d1ac62640bcd33c0515d68c441578f0c11 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 14:10:48 +0100 Subject: [PATCH 014/155] initial support for BEntry --- Jamfile | 6 +++- bindings/__init__.py | 3 +- bindings/storage/Entry.cpp | 67 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 bindings/storage/Entry.cpp diff --git a/Jamfile b/Jamfile index 3ddf41d..63a3c55 100644 --- a/Jamfile +++ b/Jamfile @@ -72,7 +72,7 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support ; +SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage ; # Where to look for header files SubDirHdrs /system/lib/python$(python_version)/vendor-packages/pybind11/include/ ; @@ -152,6 +152,10 @@ local sourceFiles = #SupportKit SupportDefs.cpp Archivable.cpp + + #StorageKit + Statable.cpp + Entry.cpp ; # The shared library Be.so can be built from the sourceFiles diff --git a/bindings/__init__.py b/bindings/__init__.py index 6b308a7..64e931c 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -59,7 +59,8 @@ from .TabView import * from .ScrollBar import * - +from .Statable import * +from .Entry import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/storage/Entry.cpp b/bindings/storage/Entry.cpp new file mode 100644 index 0000000..e9c3803 --- /dev/null +++ b/bindings/storage/Entry.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +#include +//#include +//#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Entry,m) +{ +py::class_(m, "entry_ref") +.def(py::init(), "") +.def(py::init(), "", py::arg("device"), py::arg("dir"), py::arg("name")) +.def(py::init(), "", py::arg("ref")) +.def("set_name", &entry_ref::set_name, "", py::arg("name")) +.def("__ne__", &entry_ref::operator!=, "", py::arg("ref")) +.def("__eq__", &entry_ref::operator==, "", py::arg("ref")) +.def("operator=", &entry_ref::operator=, "", py::arg("ref")) +.def_readwrite("device", &entry_ref::device, "") +.def_readwrite("directory", &entry_ref::directory, "") +.def_readwrite("name", &entry_ref::name, "") +; + +py::class_(m, "BEntry")//, BStatable +.def(py::init(), "") +.def(py::init(), "", py::arg("dir"), py::arg("path"), py::arg("traverse")=false) +.def(py::init(), "", py::arg("ref"), py::arg("traverse")=false) +.def(py::init(), "", py::arg("path"),py::arg("traverse")=false) +.def(py::init(), "", py::arg("entry")) +//vecchio.def_static("Instantiate", &BBox::Instantiate, "", py::arg("archive")) +.def("InitCheck", &BEntry::InitCheck, "") +.def("Exists", &BEntry::Exists, "") +.def("Name", &BEntry::Name, "") +.def("GetStat", &BEntry::GetStat, "", py::arg("stat")) +//vecchio.def("SetLabel", py::overload_cast(&BBox::SetLabel), "", py::arg("string")) +//vecchio.def("SetLabel", py::overload_cast(&BBox::SetLabel), "", py::arg("viewLabel")) +//.def("SetTo", &BEntry::SetTo, "",py::arg("dir"),py::arg("path"),py::arg("traverse")=false) +//.def("SetTo", &BEntry::SetTo, "",py::arg("ref"),py::arg("traverse")=false) +//.def("SetTo", &BEntry::SetTo, "",py::arg("path"),py::arg("traverse")=false) +.def("Unset", &BEntry::Unset, "") +.def("GetRef", &BEntry::GetRef, "",py::arg("ref")) +.def("GetPath", &BEntry::GetPath, "",py::arg("path")) +//.def("GetParent", &BEntry::GetParent, "",py::arg("entry")) +//.def("GetParent", &BEntry::GetParent, "",py::arg("dir")) +.def("GetName", &BEntry::GetName, "", py::arg("buffer")) +.def("Rename", &BEntry::Rename, "", py::arg("path"),py::arg("clobber")=false) +.def("MoveTo", &BEntry::MoveTo, "", py::arg("dir"),py::arg("path"),py::arg("clobber")=false) +.def("Remove", &BEntry::Remove, "") +.def("operator=", &BEntry::operator=, "", py::arg("item")) +.def("__eq__", &BEntry::operator==, "", py::arg("item")) +.def("__ne__", &BEntry::operator!=, "", py::arg("item")) +; + +m.def("get_ref_for_path",&get_ref_for_path, "", py::arg("path"), py::arg("ref")); +m.def("operator<", &operator<, "", py::arg("a"),py::arg("b")); + + +} From 641361ae0782a9f5ee5d92cacc6ab9f6b15fc6a9 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 15:35:52 +0100 Subject: [PATCH 015/155] removing Statable from compilation --- Jamfile | 1 - bindings/__init__.py | 1 - 2 files changed, 2 deletions(-) diff --git a/Jamfile b/Jamfile index 63a3c55..319a5a1 100644 --- a/Jamfile +++ b/Jamfile @@ -154,7 +154,6 @@ local sourceFiles = Archivable.cpp #StorageKit - Statable.cpp Entry.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 64e931c..c733fa5 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -59,7 +59,6 @@ from .TabView import * from .ScrollBar import * -from .Statable import * from .Entry import * _BWindow=BWindow From 3eda1cc57e42cf5a73b41bc593634d5abb4c0191 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 15:08:10 +0000 Subject: [PATCH 016/155] fix int32 for x86, recomment DrawBitmap defs --- bindings/interface/View.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 1845d3e..2ecc06e 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -239,14 +239,14 @@ py::class_>(m, "BView") .def("AddLine", &BView::AddLine, "", py::arg("start"), py::arg("end"), py::arg("color")) .def("EndLineArray", &BView::EndLineArray, "") .def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("polygon"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) -.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) +.def("StrokePolygon", py::overload_cast(&BView::StrokePolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("closed")=true, py::arg("pattern")=B_SOLID_HIGH) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern")=B_SOLID_HIGH) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("pattern")=B_SOLID_HIGH) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) .def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("polygon"), py::arg("gradient")) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("gradient")) -.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("gradient")) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("gradient")) +.def("FillPolygon", py::overload_cast(&BView::FillPolygon), "", py::arg("pointArray"), py::arg("numPoints"), py::arg("bounds"), py::arg("gradient")) .def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("bounds"), py::arg("pattern")=B_SOLID_HIGH) .def("StrokeTriangle", py::overload_cast(&BView::StrokeTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) .def("FillTriangle", py::overload_cast(&BView::FillTriangle), "", py::arg("point1"), py::arg("point2"), py::arg("point3"), py::arg("pattern")=B_SOLID_HIGH) @@ -281,6 +281,7 @@ py::class_>(m, "BView") .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) .def("CopyBits", &BView::CopyBits, "", py::arg("src"), py::arg("dst")) +/* //from here check if they work as BBitmap is not implemented .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect")) @@ -295,14 +296,15 @@ py::class_>(m, "BView") .def("DrawTiledBitmapAsync", &BView::DrawTiledBitmapAsync, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) .def("DrawTiledBitmap", &BView::DrawTiledBitmap, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) //to here +*/ .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar")) .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar"), py::arg("location")) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("delta")=NULL) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("location"), py::arg("delta")=NULL) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("delta")=NULL) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("location"), py::arg("delta")=0) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount")) -.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount")) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("delta")=NULL) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("location"), py::arg("delta")=0) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount")) +.def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount")) .def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=py::int_(0x000001FF)) .def("GetFont", &BView::GetFont, "", py::arg("font")) From c62ad852cf8503052eec5326a08547059f35ea40 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 17:01:38 +0100 Subject: [PATCH 017/155] uncomment rest of Entry.cpp --- bindings/storage/Entry.cpp | 15 ++++++--------- tmtest.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bindings/storage/Entry.cpp b/bindings/storage/Entry.cpp index e9c3803..2a5ff39 100644 --- a/bindings/storage/Entry.cpp +++ b/bindings/storage/Entry.cpp @@ -30,27 +30,24 @@ py::class_(m, "entry_ref") .def_readwrite("name", &entry_ref::name, "") ; -py::class_(m, "BEntry")//, BStatable +py::class_(m, "BEntry") .def(py::init(), "") .def(py::init(), "", py::arg("dir"), py::arg("path"), py::arg("traverse")=false) .def(py::init(), "", py::arg("ref"), py::arg("traverse")=false) .def(py::init(), "", py::arg("path"),py::arg("traverse")=false) .def(py::init(), "", py::arg("entry")) -//vecchio.def_static("Instantiate", &BBox::Instantiate, "", py::arg("archive")) .def("InitCheck", &BEntry::InitCheck, "") .def("Exists", &BEntry::Exists, "") .def("Name", &BEntry::Name, "") .def("GetStat", &BEntry::GetStat, "", py::arg("stat")) -//vecchio.def("SetLabel", py::overload_cast(&BBox::SetLabel), "", py::arg("string")) -//vecchio.def("SetLabel", py::overload_cast(&BBox::SetLabel), "", py::arg("viewLabel")) -//.def("SetTo", &BEntry::SetTo, "",py::arg("dir"),py::arg("path"),py::arg("traverse")=false) -//.def("SetTo", &BEntry::SetTo, "",py::arg("ref"),py::arg("traverse")=false) -//.def("SetTo", &BEntry::SetTo, "",py::arg("path"),py::arg("traverse")=false) +.def("SetTo", py::overload_cast(&BEntry::SetTo), "",py::arg("dir"),py::arg("path"),py::arg("traverse")=false) +.def("SetTo", py::overload_cast(&BEntry::SetTo), "",py::arg("ref"),py::arg("traverse")=false) +.def("SetTo", py::overload_cast(&BEntry::SetTo), "",py::arg("path"),py::arg("traverse")=false) .def("Unset", &BEntry::Unset, "") .def("GetRef", &BEntry::GetRef, "",py::arg("ref")) .def("GetPath", &BEntry::GetPath, "",py::arg("path")) -//.def("GetParent", &BEntry::GetParent, "",py::arg("entry")) -//.def("GetParent", &BEntry::GetParent, "",py::arg("dir")) +.def("GetParent", py::overload_cast(&BEntry::GetParent, py::const_), "",py::arg("entry")) +.def("GetParent", py::overload_cast(&BEntry::GetParent, py::const_), "",py::arg("dir")) .def("GetName", &BEntry::GetName, "", py::arg("buffer")) .def("Rename", &BEntry::Rename, "", py::arg("path"),py::arg("clobber")=false) .def("MoveTo", &BEntry::MoveTo, "", py::arg("dir"),py::arg("path"),py::arg("clobber")=false) diff --git a/tmtest.py b/tmtest.py index a61e6e8..e4ce5f5 100644 --- a/tmtest.py +++ b/tmtest.py @@ -9,6 +9,10 @@ from Be.InterfaceDefs import border_style from Be import AppDefs +from Be import BEntry +from Be.Entry import entry_ref +from Be.Entry import get_ref_for_path + class StrangeItem(BStringItem): nocolor = (0, 0, 0, 0) gcolor = (0, 200, 0, 0) @@ -106,6 +110,7 @@ def __init__(self): self.sevenradio = BRadioButton(BRect(8,236,24,252),'tepidradio', 'tepid', BMessage(7)) self.nineradio = BRadioButton(BRect(8,252,24,268),'coolradio', 'cool', BMessage(9)) + # Handling colors################## #colore=self.list.lv.HighColor() #print("colore è:",colore.red,colore.green,colore.blue,colore.alpha) @@ -202,6 +207,13 @@ def __init__(self): self.typtap.SetText(stuff,None)#, [(0, be_plain_font, (0, 0, 0, 0)), (n, be_bold_font, (0, 150, 0, 0)), (n + 14, be_plain_font, (0, 0, 0, 0)),(m,be_plain_font,(100,150,0,0))]) self.AddChild(self.bckgnd,None) self.panel.AddChild(self.list.topview(),None) + ###### Example handling refs / BEntry ##### + a=entry_ref() + get_ref_for_path("/boot/home",a) + b=BEntry("/boot/home") + b.Exists() + #to complete + ########################################### def MessageReceived(self, msg): if msg.what == 1: From 7900d594c37afcf709aa214b0c87bb20947a6f59 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 18:07:42 +0100 Subject: [PATCH 018/155] add Node.cpp and StorageDefs.cpp --- Jamfile | 2 ++ bindings/__init__.py | 2 ++ bindings/storage/Node.cpp | 62 ++++++++++++++++++++++++++++++++ bindings/storage/StorageDefs.cpp | 22 ++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 bindings/storage/Node.cpp create mode 100644 bindings/storage/StorageDefs.cpp diff --git a/Jamfile b/Jamfile index 319a5a1..3e3c719 100644 --- a/Jamfile +++ b/Jamfile @@ -154,7 +154,9 @@ local sourceFiles = Archivable.cpp #StorageKit + StorageDefs.cpp Entry.cpp + Node.cpp ; # The shared library Be.so can be built from the sourceFiles diff --git a/bindings/__init__.py b/bindings/__init__.py index c733fa5..87c3bb4 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -59,7 +59,9 @@ from .TabView import * from .ScrollBar import * +from .StorageDefs import * from .Entry import * +from .Node import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp new file mode 100644 index 0000000..3f5d232 --- /dev/null +++ b/bindings/storage/Node.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +namespace py = pybind11; + + +PYBIND11_MODULE(Node,m) +{ +py::class_(m, "node_ref") +.def(py::init(), "") +.def(py::init(), "", py::arg("device"), py::arg("node")) +.def(py::init(), "", py::arg("other")) +.def("__eq__", &node_ref::operator==, "", py::arg("other")) +.def("__ne__", &node_ref::operator!=, "", py::arg("other")) +.def("operator<", &node_ref::operator<, "", py::arg("other")) +.def("operator=", &node_ref::operator=, "", py::arg("other")) +.def_readwrite("device", &node_ref::device, "") +.def_readwrite("node", &node_ref::node, "") +; + +py::class_(m, "BNode") +.def(py::init(), "") +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("entry")) +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("dir"), py::arg("path")) +.def(py::init(), "", py::arg("node")) +.def("InitCheck", &BNode::InitCheck, "") +.def("GetStat", &BNode::GetStat, "", py::arg("stat")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "",py::arg("ref")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "",py::arg("entry")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "",py::arg("path")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "",py::arg("dir"),py::arg("path")) +.def("Unset", &BNode::Unset, "") +.def("Lock", &BNode::Lock, "") +.def("Unlock", &BNode::Unlock, "") +.def("Sync", &BNode::Sync, "") +.def("WriteAttr", &BNode::WriteAttr, "",py::arg("name"),py::arg("type"),py::arg("offset"),py::arg("buffer"),py::arg("length")) +.def("ReadAttr", &BNode::ReadAttr, "",py::arg("name"),py::arg("type"),py::arg("offset"),py::arg("buffer"),py::arg("length")) +.def("RemoveAttr", &BNode::RemoveAttr, "",py::arg("name")) +.def("RenameAttr", &BNode::RenameAttr, "",py::arg("oldName"),py::arg("newName")) +.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "",py::arg("name"),py::arg("info")) +.def("GetNextAttrName", &BNode::GetNextAttrName, "",py::arg("buffer")) +.def("RewindAttrs", &BNode::RewindAttrs, "") +.def("WriteAttrString", &BNode::WriteAttrString, "",py::arg("name"),py::arg("data")) +.def("ReadAttrString", &BNode::ReadAttrString, "",py::arg("name"),py::arg("result")) +.def("operator=", &BNode::operator=, "", py::arg("node")) +.def("__eq__", &BNode::operator==, "", py::arg("node")) +.def("__ne__", &BNode::operator!=, "", py::arg("node")) +.def("Dup", &BNode::Dup, "") +; +} diff --git a/bindings/storage/StorageDefs.cpp b/bindings/storage/StorageDefs.cpp new file mode 100644 index 0000000..8362b5a --- /dev/null +++ b/bindings/storage/StorageDefs.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; +//Check the StorageDefs.h as a lot of define values are not here + +PYBIND11_MODULE(StorageDefs,m) +{ +py::enum_(m, "node_flavor", "") +.value("B_FILE_NODE", node_flavor::B_FILE_NODE, "") +.value("B_SYMLINK_NODE", node_flavor::B_SYMLINK_NODE, "") +.value("B_DIRECTORY_NODE", node_flavor::B_DIRECTORY_NODE, "") +.value("B_ANY_NODE", node_flavor::B_ANY_NODE, "") +.export_values(); +} From 9492a5b783d72fc39eb0ff2efb072b5a969e2260 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 18:24:48 +0100 Subject: [PATCH 019/155] comment out GetAttrInfo --- bindings/storage/Node.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 3f5d232..509e994 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -49,7 +49,7 @@ py::class_(m, "BNode") .def("ReadAttr", &BNode::ReadAttr, "",py::arg("name"),py::arg("type"),py::arg("offset"),py::arg("buffer"),py::arg("length")) .def("RemoveAttr", &BNode::RemoveAttr, "",py::arg("name")) .def("RenameAttr", &BNode::RenameAttr, "",py::arg("oldName"),py::arg("newName")) -.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "",py::arg("name"),py::arg("info")) +//.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "",py::arg("name"),py::arg("info")) //should I define attr_info or get from kernel/fs_attr.h? For now I cannot use this command .def("GetNextAttrName", &BNode::GetNextAttrName, "",py::arg("buffer")) .def("RewindAttrs", &BNode::RewindAttrs, "") .def("WriteAttrString", &BNode::WriteAttrString, "",py::arg("name"),py::arg("data")) From 614f7506c9e0e5791c6b72dd7656ec20e6a6fea6 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 20:22:57 +0100 Subject: [PATCH 020/155] Add Directory --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/storage/Directory.cpp | 56 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 bindings/storage/Directory.cpp diff --git a/Jamfile b/Jamfile index 3e3c719..a41bd30 100644 --- a/Jamfile +++ b/Jamfile @@ -157,6 +157,7 @@ local sourceFiles = StorageDefs.cpp Entry.cpp Node.cpp + Directory.cpp ; # The shared library Be.so can be built from the sourceFiles diff --git a/bindings/__init__.py b/bindings/__init__.py index 87c3bb4..efdc0c8 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -62,6 +62,7 @@ from .StorageDefs import * from .Entry import * from .Node import * +from .Directory import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/storage/Directory.cpp b/bindings/storage/Directory.cpp new file mode 100644 index 0000000..b0ecd62 --- /dev/null +++ b/bindings/storage/Directory.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include +//#include +//#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Directory,m) +{ +py::class_(m, "BDirectory")//, BEntryList +.def(py::init(), "") +.def(py::init(), "", py::arg("dir")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("nref")) +.def(py::init(), "", py::arg("entry")) +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("dir"), py::arg("path")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("nref")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("entry")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("path")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("dir"), py::arg("path")) + +// works also as +//.def("GetEntry", &BDirectory::GetEntry, "", py::arg("entry")) +.def("GetEntry", py::overload_cast(&BDirectory::GetEntry, py::const_), "",py::arg("entry")) // verificare +.def("IsRootDirectory", &BDirectory::IsRootDirectory, "") +.def("FindEntry", &BDirectory::FindEntry, "", py::arg("path"), py::arg("entry"), py::arg("traverse")=false) +.def("Contains", py::overload_cast(&BDirectory::Contains, py::const_), "",py::arg("path"),py::arg("nodeFlags")=B_ANY_NODE) +.def("Contains", py::overload_cast(&BDirectory::Contains, py::const_), "",py::arg("entry"),py::arg("nodeFlags")=B_ANY_NODE) +.def("GetStatFor", &BDirectory::GetStatFor, "",py::arg("path"),py::arg("st")) +.def("GetNextEntry", &BDirectory::GetNextEntry, "",py::arg("entry"),py::arg("traverse")=false) +.def("GetNextRef", &BDirectory::GetNextRef, "",py::arg("ref")) +.def("GetNextDirents", &BDirectory::GetNextDirents, "", py::arg("buf"),py::arg("bufSize"),py::arg("count")=INT_MAX) +.def("Rewind", &BDirectory::Rewind, "") +.def("CountEntries", &BDirectory::CountEntries, "") +.def("CreateDirectory", &BDirectory::CreateDirectory, "",py::arg("path"),py::arg("dir")) +.def("CreateFile", &BDirectory::CreateFile, "", py::arg("path"),py::arg("file"),py::arg("failIfExists")=false) +.def("CreateSymLink", &BDirectory::CreateSymLink, "", py::arg("path"),py::arg("linkToPath"),py::arg("link")) +.def("operator=", &BDirectory::operator=, "", py::arg("dir")) +; + +m.def("create_directory",&create_directory, "", py::arg("path"), py::arg("mode")); + +} From fc6aeed600f75f3c0be618ff4711d10bc67a6bf3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 23 Nov 2023 18:20:59 +0100 Subject: [PATCH 021/155] add kernel/fs_attr.cpp, fix Node.GetNextAttrName --- Jamfile | 5 ++++- bindings/__init__.py | 2 ++ bindings/kernel/fs_attr.cpp | 39 +++++++++++++++++++++++++++++++++++++ bindings/storage/Node.cpp | 19 ++++++++++++++++-- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 bindings/kernel/fs_attr.cpp diff --git a/Jamfile b/Jamfile index a41bd30..978d719 100644 --- a/Jamfile +++ b/Jamfile @@ -72,7 +72,7 @@ install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage ; +SEARCH_SOURCE += bindings/interface bindings/app bindings/support bindings/storage bindings/kernel ; # Where to look for header files SubDirHdrs /system/lib/python$(python_version)/vendor-packages/pybind11/include/ ; @@ -152,6 +152,9 @@ local sourceFiles = #SupportKit SupportDefs.cpp Archivable.cpp + + #Kernel + fs_attr.cpp #StorageKit StorageDefs.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index efdc0c8..b225201 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -59,6 +59,8 @@ from .TabView import * from .ScrollBar import * +from .fs_attr import * + from .StorageDefs import * from .Entry import * from .Node import * diff --git a/bindings/kernel/fs_attr.cpp b/bindings/kernel/fs_attr.cpp new file mode 100644 index 0000000..e7858a3 --- /dev/null +++ b/bindings/kernel/fs_attr.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(fs_attr,m) +{ +py::class_(m, "attr_info") +.def(py::init(), "") +.def_readwrite("type", &attr_info::type, "") +.def_readwrite("size", &attr_info::size, "") +//.export_values(); +; + + +m.def("fs_read_attr", &fs_read_attr, "", py::arg("fd"), py::arg("attribute"), py::arg("type"), py::arg("pos"), py::arg("buffer"), py::arg("readBytes")); +m.def("fs_write_attr", &fs_write_attr, "", py::arg("fd"), py::arg("attribute"), py::arg("type"), py::arg("pos"), py::arg("buffer"), py::arg("readBytes")); +m.def("fs_remove_attr", &fs_remove_attr, "", py::arg("fd"), py::arg("attribute")); +m.def("fs_stat_attr", &fs_stat_attr, "", py::arg("fd"), py::arg("attribute"), py::arg("attrInfo")); +m.def("fs_open_attr", &fs_open_attr, "", py::arg("path"), py::arg("attribute"), py::arg("type"), py::arg("openMode")); +m.def("fs_fopen_attr", &fs_fopen_attr, "", py::arg("fd"), py::arg("attribute"), py::arg("type"), py::arg("openMode")); +m.def("fs_close_attr", &fs_close_attr, "", py::arg("fd")); +/* +m.def("fs_open_attr_dir", &fs_open_attr_dir, "", py::arg("path")); +m.def("fs_lopen_attr_dir", &fs_lopen_attr_dir, "", py::arg("path")); +m.def("fs_fopen_attr_dir", &fs_fopen_attr_dir, "", py::arg("fd")); +m.def("fs_close_attr_dir", &fs_close_attr_dir, "", py::arg("dir")); +m.def("fs_read_attr_dir", &fs_read_attr_dir, "", py::arg("dir")); +m.def("fs_rewind_attr_dir", &fs_rewind_attr_dir, "", py::arg("dir")); +*/ + +} diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 509e994..cdfebd2 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -16,6 +16,12 @@ namespace py = pybind11; PYBIND11_MODULE(Node,m) { +/*py::class_(m, "attr_info") +.def_readwrite("type", &attr_info::type, "") +.def_readwrite("size", &attr_info::size, "") +.export_values(); +*/ + py::class_(m, "node_ref") .def(py::init(), "") .def(py::init(), "", py::arg("device"), py::arg("node")) @@ -49,8 +55,17 @@ py::class_(m, "BNode") .def("ReadAttr", &BNode::ReadAttr, "",py::arg("name"),py::arg("type"),py::arg("offset"),py::arg("buffer"),py::arg("length")) .def("RemoveAttr", &BNode::RemoveAttr, "",py::arg("name")) .def("RenameAttr", &BNode::RenameAttr, "",py::arg("oldName"),py::arg("newName")) -//.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "",py::arg("name"),py::arg("info")) //should I define attr_info or get from kernel/fs_attr.h? For now I cannot use this command -.def("GetNextAttrName", &BNode::GetNextAttrName, "",py::arg("buffer")) +.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "",py::arg("name"),py::arg("info")) //should I define attr_info or get from kernel/fs_attr.h? For now I cannot use this command +//.def("GetNextAttrName", &BNode::GetNextAttrName, "",py::arg("buffer")) +//.def("GetNextAttrName", py::overload_cast(&BNode::GetNextAttrName), "",py::arg("buffer")) +.def("GetNextAttrName", [](BNode& self, char* buffer){ + status_t result = self.GetNextAttrName(buffer); + if (result == 0) { + return std::string(buffer); + } else { + throw std::runtime_error("Errore durante la chiamata a GetNextAttrName"); + } +}, py::arg("buffer"))//, py::return_value_policy::reference_internal .def("RewindAttrs", &BNode::RewindAttrs, "") .def("WriteAttrString", &BNode::WriteAttrString, "",py::arg("name"),py::arg("data")) .def("ReadAttrString", &BNode::ReadAttrString, "",py::arg("name"),py::arg("result")) From d1846e2d7eee6f24fb493465a7e45e5a158b2ec6 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 23 Nov 2023 19:08:39 +0100 Subject: [PATCH 022/155] BNode test app --- fstest.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 fstest.py diff --git a/fstest.py b/fstest.py new file mode 100644 index 0000000..c590f36 --- /dev/null +++ b/fstest.py @@ -0,0 +1,58 @@ +import os +from Be import BNode +from Be.fs_attr import attr_info +#from structuple import Structuple + +#class Battr_info(Structuple): +# _members = ('type', 'size') +# def typegen(self): +# return (None, None) + +class card: + def __init__(self,path): + self.path = path + self.attribs = [] + def addattrib(self,n,v): + att=(n,v) + self.attribs.append(att) + def retattrib(self): + return self.attribs + +def attr(node): + al = [] + while 1: + #if True: + try: + atri=str("") + a = node.GetNextAttrName(str("")) + #info=attr_info() + #size = node.GetAttrInfo(a,info) + #print(a,atri,size) + #b+=1 + #if b==5: + # break + except: + #print("no next attr name") + a = None + if a is None: + node.RewindAttrs() + break + else: + #info = Battr_info(node.GetAttrInfo(a)) + #info = node.GetAttrInfo(a) + al.append((a))#, info, node.ReadAttr(atri, 0, 0, 1024))) + return al + +f=os.path.abspath("fstest.py") +carta=card(f) +#print(f) +nf = BNode(f) +print(attr(nf)) +#for n, i, v in attr(nf): +# carta.addattrib(n,v) +# #if n[:5]=="META:": +# # z = v.find('\000') +# # if z >= 0: +# # v = v[:z] +# # carta.addattrib(n[5:],v) +#print(carta.attribs) From b910c68e7ccc35616311c4a2b00d697b64ca614a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 20:45:47 +0100 Subject: [PATCH 023/155] No parameter needed to GetNextAttrName --- bindings/storage/Node.cpp | 2 +- fstest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index cdfebd2..16e0842 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -65,7 +65,7 @@ py::class_(m, "BNode") } else { throw std::runtime_error("Errore durante la chiamata a GetNextAttrName"); } -}, py::arg("buffer"))//, py::return_value_policy::reference_internal +}, py::arg("buffer")="")//, py::return_value_policy::reference_internal .def("RewindAttrs", &BNode::RewindAttrs, "") .def("WriteAttrString", &BNode::WriteAttrString, "",py::arg("name"),py::arg("data")) .def("ReadAttrString", &BNode::ReadAttrString, "",py::arg("name"),py::arg("result")) diff --git a/fstest.py b/fstest.py index c590f36..cf64304 100644 --- a/fstest.py +++ b/fstest.py @@ -24,7 +24,7 @@ def attr(node): #if True: try: atri=str("") - a = node.GetNextAttrName(str("")) + a = node.GetNextAttrName() #info=attr_info() #size = node.GetAttrInfo(a,info) #print(a,atri,size) From 5a640ea9ae9763a5b4aefffb058d3ee232c89478 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 22 Nov 2023 22:25:41 +0100 Subject: [PATCH 024/155] comment out BPrivate namespaces --- bindings/storage/Node.cpp | 6 +++--- bindings/storage/StorageDefs.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 8ddd6df..966005e 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -12,9 +12,9 @@ namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; PYBIND11_MODULE(Node,m) diff --git a/bindings/storage/StorageDefs.cpp b/bindings/storage/StorageDefs.cpp index cb0f999..60785f3 100644 --- a/bindings/storage/StorageDefs.cpp +++ b/bindings/storage/StorageDefs.cpp @@ -9,10 +9,10 @@ #include namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; PYBIND11_MODULE(StorageDefs,m) From 60b5447afc04eda911bad0e7dae36d6781b7ae3c Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 24 Nov 2023 21:36:18 +0100 Subject: [PATCH 025/155] update fstest.py --- fstest.py | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/fstest.py b/fstest.py index cf64304..aafdab2 100644 --- a/fstest.py +++ b/fstest.py @@ -1,12 +1,6 @@ -import os +import os, struct from Be import BNode from Be.fs_attr import attr_info -#from structuple import Structuple - -#class Battr_info(Structuple): -# _members = ('type', 'size') -# def typegen(self): -# return (None, None) class card: def __init__(self,path): @@ -21,29 +15,32 @@ def retattrib(self): def attr(node): al = [] while 1: - #if True: try: atri=str("") a = node.GetNextAttrName() - #info=attr_info() - #size = node.GetAttrInfo(a,info) - #print(a,atri,size) - #b+=1 - #if b==5: - # break except: - #print("no next attr name") - a = None + a = None #no more attributes if a is None: node.RewindAttrs() break else: - #info = Battr_info(node.GetAttrInfo(a)) - #info = node.GetAttrInfo(a) - al.append((a))#, info, node.ReadAttr(atri, 0, 0, 1024))) + # you can do this way: + #tmp = attr_info() + #nfo = node.GetAttrInfo(a,tmp) + #al.append((a,(tmp.type,tmp.size))) + # or this way: + nfo = node.GetAttrInfo(a) + type_string = get_type_string(nfo.type) + al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, 0, 0, None, 1024))) + return al -f=os.path.abspath("fstest.py") + +def get_type_string(value): + type_string = struct.pack('>I', value).decode('utf-8') + return type_string + +f=os.path.abspath("WPLaura.pdf")#Haiku-friûl.png")#fstest.py") carta=card(f) #print(f) nf = BNode(f) From ae6f72422f472cc1a590c3e30b406d3ae42819bf Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 24 Nov 2023 21:45:46 +0100 Subject: [PATCH 026/155] modify return value GetAttrInfo and ReadAttr --- bindings/storage/Node.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 966005e..9f796e1 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -49,11 +49,35 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed .def("Unlock", &BNode::Unlock, "") .def("Sync", &BNode::Sync, "") .def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) +//.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length){ + if (buffer == NULL){ + void* tmp; + ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + return tmp;//std::string(buffer); + } else { + ssize_t result = self.ReadAttr(name, type, offset, buffer, length); + return buffer; + } +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) .def("RenameAttr", &BNode::RenameAttr, "", py::arg("oldName"), py::arg("newName")) //.def("GetAttrInfo", &BNode::GetAttrInfo, "", py::arg("name"), py::arg("info")) -.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "", py::arg("name"), py::arg("info")) +//.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "", py::arg("name"), py::arg("info")) +/*.def("GetAttrInfo", [](BNode& self, const char* attr) -> std::pair { + attr_info info; + status_t result = self.GetAttrInfo(attr, &info); + return {result, info}; +}, "", py::arg("name")) +*/ +.def("GetAttrInfo", [](BNode& self, const char* attr, struct attr_info* info){ + status_t result = self.GetAttrInfo(attr, info); + if (result == 0) { + return *info; + } else { + throw std::runtime_error("Errore durante la chiamata a GetAttrInfo"); + } +}, py::arg("attr"), py::arg("info")=attr_info()) //.def("GetNextAttrName", &BNode::GetNextAttrName, "",py::arg("buffer")) //.def("GetNextAttrName", py::overload_cast(&BNode::GetNextAttrName), "",py::arg("buffer")) .def("GetNextAttrName", [](BNode& self, char* buffer){ From c84c377148576e6fc43344f9eb037d44c0fafb08 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 24 Nov 2023 22:25:15 +0100 Subject: [PATCH 027/155] Allocate tmp buffer and free it --- bindings/storage/Node.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 9f796e1..e7a0938 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -50,14 +50,23 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed .def("Sync", &BNode::Sync, "") .def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length){ +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)-> std::pair{ if (buffer == NULL){ - void* tmp; + void* tmp = malloc(length);; ssize_t result = self.ReadAttr(name, type, offset, tmp, length); - return tmp;//std::string(buffer); + if (result > 0) { + return {result,tmp};//std::string(buffer); + } else { + free(tmp); + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } } else { ssize_t result = self.ReadAttr(name, type, offset, buffer, length); - return buffer; + if (result > 0) { + return {result,buffer}; + } else { + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } } }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) From 227610b6ef014e334b4296f338ba1e79920fcc5d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 25 Nov 2023 19:05:54 +0100 Subject: [PATCH 028/155] Add TypeConstants.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/interface/View.cpp | 4 ++ bindings/support/TypeConstants.cpp | 64 ++++++++++++++++++++++++++++++ fstest.py | 7 ++++ 5 files changed, 77 insertions(+) create mode 100644 bindings/support/TypeConstants.cpp diff --git a/Jamfile b/Jamfile index 978d719..a71ebd0 100644 --- a/Jamfile +++ b/Jamfile @@ -152,6 +152,7 @@ local sourceFiles = #SupportKit SupportDefs.cpp Archivable.cpp + TypeConstants.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index b225201..2658a5e 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -49,6 +49,7 @@ from .ListView import * from .ScrollView import * from .SupportDefs import * +from .TypeConstants import * from .Archivable import * from .ListItem import * #from .Bitmap import * diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 2ecc06e..40c868a 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -148,8 +148,10 @@ py::class_>(m, "BView") .def("EndRectTracking", &BView::EndRectTracking, "") .def("GetMouse", &BView::GetMouse, "", py::arg("location"), py::arg("buttons"), py::arg("checkMessageQueue")=true) .def("DragMessage", py::overload_cast(&BView::DragMessage), "", py::arg("message"), py::arg("dragRect"), py::arg("replyTo")=NULL) +// check as soon as BBitmap works .def("DragMessage", py::overload_cast(&BView::DragMessage), "", py::arg("message"), py::arg("bitmap"), py::arg("offset"), py::arg("replyTo")=NULL) .def("DragMessage", py::overload_cast(&BView::DragMessage), "", py::arg("message"), py::arg("bitmap"), py::arg("dragMode"), py::arg("offset"), py::arg("replyTo")=NULL) +// ends here .def("FindView", &BView::FindView, "", py::arg("name")) .def("Parent", &BView::Parent, "") .def("Bounds", &BView::Bounds, "") @@ -199,8 +201,10 @@ py::class_>(m, "BView") //.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("srcRect"), py::arg("dstRect"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) //.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) .def("ClearViewBitmap", &BView::ClearViewBitmap, "") +// check as soon as BBitmap module works .def("SetViewOverlay", py::overload_cast(&BView::SetViewOverlay), "", py::arg("overlay"), py::arg("srcRect"), py::arg("dstRect"), py::arg("colorKey"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=0) .def("SetViewOverlay", py::overload_cast(&BView::SetViewOverlay), "", py::arg("overlay"), py::arg("colorKey"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=0) +// ends here .def("ClearViewOverlay", &BView::ClearViewOverlay, "") .def("SetHighColor", py::overload_cast(&BView::SetHighColor), "", py::arg("color")) .def("SetHighColor", py::overload_cast(&BView::SetHighColor), "", py::arg("red"), py::arg("green"), py::arg("blue"), py::arg("alpha")=255) diff --git a/bindings/support/TypeConstants.cpp b/bindings/support/TypeConstants.cpp new file mode 100644 index 0000000..7f2fb92 --- /dev/null +++ b/bindings/support/TypeConstants.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; + +PYBIND11_MODULE(TypeConstants, m) { + m.attr("B_AFFINE_TRANSFORM_TYPE") = 'AMTX'; + m.attr("B_ALIGNMENT_TYPE") = 'ALGN'; + m.attr("B_ANY_TYPE") = 'ANYT'; + m.attr("B_ATOM_TYPE") = 'ATOM'; + m.attr("B_ATOMREF_TYPE") = 'ATMR'; + m.attr("B_BOOL_TYPE") = 'BOOL'; + m.attr("B_CHAR_TYPE") = 'CHAR'; + m.attr("B_COLOR_8_BIT_TYPE") = 'CLRB'; + m.attr("B_DOUBLE_TYPE") = 'DBLE'; + m.attr("B_FLOAT_TYPE") = 'FLOT'; + m.attr("B_GRAYSCALE_8_BIT_TYPE") = 'GRYB'; + m.attr("B_INT16_TYPE") = 'SHRT'; + m.attr("B_INT32_TYPE") = 'LONG'; + m.attr("B_INT64_TYPE") = 'LLNG'; + m.attr("B_INT8_TYPE") = 'BYTE'; + m.attr("B_LARGE_ICON_TYPE") = 'ICON'; + m.attr("B_MEDIA_PARAMETER_GROUP_TYPE") = 'BMCG'; + m.attr("B_MEDIA_PARAMETER_TYPE") = 'BMCT'; + m.attr("B_MEDIA_PARAMETER_WEB_TYPE") = 'BMCW'; + m.attr("B_MESSAGE_TYPE") = 'MSGG'; + m.attr("B_MESSENGER_TYPE") = 'MSNG'; + m.attr("B_MIME_TYPE") = 'MIME'; + m.attr("B_MINI_ICON_TYPE") = 'MICN'; + m.attr("B_MONOCHROME_1_BIT_TYPE") = 'MNOB'; + m.attr("B_OBJECT_TYPE") = 'OPTR'; + m.attr("B_OFF_T_TYPE") = 'OFFT'; + m.attr("B_PATTERN_TYPE") = 'PATN'; + m.attr("B_POINTER_TYPE") = 'PNTR'; + m.attr("B_POINT_TYPE") = 'BPNT'; + m.attr("B_PROPERTY_INFO_TYPE") = 'SCTD'; + m.attr("B_RAW_TYPE") = 'RAWT'; + m.attr("B_RECT_TYPE") = 'RECT'; + m.attr("B_REF_TYPE") = 'RREF'; + m.attr("B_NODE_REF_TYPE") = 'NREF'; + m.attr("B_RGB_32_BIT_TYPE") = 'RGBB'; + m.attr("B_RGB_COLOR_TYPE") = 'RGBC'; + m.attr("B_SIZE_TYPE") = 'SIZE'; + m.attr("B_SIZE_T_TYPE") = 'SIZT'; + m.attr("B_SSIZE_T_TYPE") = 'SSZT'; + m.attr("B_STRING_TYPE") = 'CSTR'; + m.attr("B_STRING_LIST_TYPE") = 'STRL'; + m.attr("B_TIME_TYPE") = 'TIME'; + m.attr("B_UINT16_TYPE") = 'USHT'; + m.attr("B_UINT32_TYPE") = 'ULNG'; + m.attr("B_UINT64_TYPE") = 'ULLG'; + m.attr("B_UINT8_TYPE") = 'UBYT'; + m.attr("B_VECTOR_ICON_TYPE") = 'VICN'; + m.attr("B_XATTR_TYPE") = 'XATR'; + m.attr("B_NETWORK_ADDRESS_TYPE") = 'NWAD'; + m.attr("B_MIME_STRING_TYPE") = 'MIMS'; + m.attr("B_ASCII_TYPE") = 'TEXT'; + +} + diff --git a/fstest.py b/fstest.py index aafdab2..1f1bb03 100644 --- a/fstest.py +++ b/fstest.py @@ -31,12 +31,19 @@ def attr(node): # or this way: nfo = node.GetAttrInfo(a) type_string = get_type_string(nfo.type) + print(get_type_int(type_string),nfo.type) al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, 0, 0, None, 1024))) return al +def get_type_int(stringa): + value=0 + for i in range(4): + value |= ord(stringa[i]) << (8*(3-i)) + return value def get_type_string(value): + #type_string = ''.join([chr((value >> (8*i)) & 0xFF) for i in range(4)]) #<--- this works better if the binary representation of the integer contains bytes that are not valid for UTF-8 encoding type_string = struct.pack('>I', value).decode('utf-8') return type_string From f8a14c6d436540f1d96b596dd2c7e1f18c7e1401 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 25 Nov 2023 22:15:39 +0100 Subject: [PATCH 029/155] attempts to ReadAttr void*buffer --- bindings/storage/Node.cpp | 53 +++++++++++++++++++++++++++++++++++++-- fstest.py | 9 ++++--- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index e7a0938..ae4f067 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -16,7 +17,6 @@ namespace py = pybind11; //using namespace BPrivate::Storage; //using namespace BPrivate::Storage::Mime; - PYBIND11_MODULE(Node,m) { py::class_(m, "node_ref") @@ -50,7 +50,7 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed .def("Sync", &BNode::Sync, "") .def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)-> std::pair{ +/*.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)-> std::pair{ if (buffer == NULL){ void* tmp = malloc(length);; ssize_t result = self.ReadAttr(name, type, offset, tmp, length); @@ -69,6 +69,55 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed } } }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) +*/ +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, PyObject* data, size_t length){ + if (data == NULL){ + void* tmp = malloc(length);; + ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + if (result > 0) { + PyObject* ret; + switch (type){ + case B_INT32_TYPE: { + // Turn the void* into an int* and put it into the PyObject + ret = PyLong_FromLong(*reinterpret_cast(tmp)); + free(tmp); + break; + // and so on for each type_code... + } + return ret; + } + + //return result;//tmp;//std::string(buffer); + } else { + free(tmp); + return Py_None; + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } + } else { + ssize_t result = self.ReadAttr(name, type, offset, data, length); + if (result > 0) { + switch (type){ + case B_INT32_TYPE: { + PyObject* pyInt = PyLong_FromLong(*reinterpret_cast(data)); + Py_XINCREF(pyInt); // Incrementa il riferimento all'oggetto Python + data = pyInt; // Assegna direttamente il risultato di PyLong_FromLong a data + // Turn the void* into an int* and put it into the PyObject + // *data = PyLong_FromLong(*reinterpret_cast(data));//*(int32*)tmp; + // free(tmp); + break; + } + // and so on for each type_code... + } + //return PyLong_FromLong(result); //tmp;//std::string(buffer); + } else { + + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + + } + return PyLong_FromLong(result); + } +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) + .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) .def("RenameAttr", &BNode::RenameAttr, "", py::arg("oldName"), py::arg("newName")) //.def("GetAttrInfo", &BNode::GetAttrInfo, "", py::arg("name"), py::arg("info")) diff --git a/fstest.py b/fstest.py index 1f1bb03..088078f 100644 --- a/fstest.py +++ b/fstest.py @@ -1,4 +1,4 @@ -import os, struct +import os, struct, ctypes from Be import BNode from Be.fs_attr import attr_info @@ -31,8 +31,11 @@ def attr(node): # or this way: nfo = node.GetAttrInfo(a) type_string = get_type_string(nfo.type) - print(get_type_int(type_string),nfo.type) - al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, 0, 0, None, 1024))) + #print(get_type_int(type_string),nfo.type) + my_obj = ctypes.py_object() + #print(type(my_obj),my_obj) + print(type_string, nfo.size) + al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, 0, 0, my_obj, 1024))) return al From 45369621e004c41472d6a66c8f610f796386732a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 08:14:54 +0100 Subject: [PATCH 030/155] more failing attempts --- bindings/storage/Node.cpp | 49 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index ae4f067..ec08e5d 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -49,7 +49,27 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed .def("Unlock", &BNode::Unlock, "") .def("Sync", &BNode::Sync, "") .def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) +//PyBytes_FromObject //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->PyObject*{ //void* buffer + void* tmp = malloc(length);; + ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + if (result > 0) { + PyObject* ret; + switch (type){ + case B_INT32_TYPE: + ret = PyLong_FromVoidPtr(tmp);//*reinterpret_cast( + break; + default: + ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); + break; + } + return ret; + } else { + free(tmp); + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) /*.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)-> std::pair{ if (buffer == NULL){ void* tmp = malloc(length);; @@ -70,6 +90,33 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed } }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) */ +/*.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length){ +//as buffer being an output variable we use instead the return value of the function diverging from Haiku-Book references + void* tmp = malloc(length); + ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + if (result > 0) { + PyObject* ret; + switch (type){ + case B_INT32_TYPE: { + //ret = PyLong_FromLong(*reinterpret_cast(tmp)); + free(tmp); + + break; + } + /*default: { + ret = PyLong_FromLong(*reinterpret_cast(0)); + break; + }*/ + /* ############################################ + return ret; + } + //std::string(buffer); + } else { + free(tmp); + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length"))*/ +/* .def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, PyObject* data, size_t length){ if (data == NULL){ void* tmp = malloc(length);; @@ -117,7 +164,7 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed return PyLong_FromLong(result); } }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) - +*/ .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) .def("RenameAttr", &BNode::RenameAttr, "", py::arg("oldName"), py::arg("newName")) //.def("GetAttrInfo", &BNode::GetAttrInfo, "", py::arg("name"), py::arg("info")) From 3b3880dc54c32be557c481e90548afab1ee1e4ff Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 10:40:11 +0100 Subject: [PATCH 031/155] working attempts? --- bindings/storage/Node.cpp | 98 ++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 16 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index ec08e5d..1a01db5 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -13,9 +13,28 @@ namespace py = pybind11; -//using namespace BPrivate; -//using namespace BPrivate::Storage; -//using namespace BPrivate::Storage::Mime; +/* +PyObject* ReadAttrWrapper(BNode& self, const char* name, type_code type, off_t offset, PyObject* data, size_t length) { + void* buffer; + ssize_t ret = self.ReadAttr(name, type, offset, buffer, length); + PyObject* rit + switch (type){ + case B_INT32_TYPE: + // Turn the void* into an int* and put it into the PyObject + //*data = *(int*)buffer; + rit = PyLong_FromVoidPtr(buffer); + free(buffer); + break; + // and so on for each type_code... + default: + rit = PyLong_FromSsize_t(ret); + return rit; + break; + } + return rit; + +}*/ + PYBIND11_MODULE(Node,m) { @@ -50,26 +69,73 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed .def("Sync", &BNode::Sync, "") .def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //PyBytes_FromObject +//.def("ReadAttr", py::overload_cast(&ReadAttrWrapper), "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->PyObject*{ //void* buffer +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->int*{ void* tmp = malloc(length);; - ssize_t result = self.ReadAttr(name, type, offset, tmp, length); - if (result > 0) { - PyObject* ret; - switch (type){ +// ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + self.ReadAttr(name, type, offset, tmp, length); + PyObject* ret; + int* intPtr = 0; + switch (type){ case B_INT32_TYPE: - ret = PyLong_FromVoidPtr(tmp);//*reinterpret_cast( + ret = PyLong_FromVoidPtr(tmp); + if (ret == nullptr) { + free(tmp); + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } + // Converte l'oggetto PyObject* in un puntatore a int* + intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); + if (intPtr == nullptr) { + Py_DECREF(ret); + free(tmp); + throw std::runtime_error("Errore durante la conversione dell'oggetto PyLong a int*"); + } + // Ora intPtr punta all'area di memoria a cui puntava tmp + // Puoi utilizzare intPtr come desideri + Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* (non più necessario) + // Restituisci il puntatore a intPtr invece dell'oggetto PyObject* + //return intPtr; + break; + default: + //ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); + //intPtr = 0; + free(tmp); break; + } + return intPtr; +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) + +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->char*{ + void* tmp = malloc(length);; +// ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + self.ReadAttr(name, type, offset, tmp, length); + PyObject* ret; + char* strPtr = strdup(""); + switch (type){ + case B_STRING_TYPE: + PyObject* ret = PyUnicode_FromString(static_cast(tmp)); + free(tmp); // Libera la memoria allocata con malloc + if (ret == nullptr) { + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } + // Converte l'oggetto PyObject* in un puntatore a char* + strPtr = PyUnicode_AsUTF8(ret); + if (strPtr == nullptr) { + Py_DECREF(ret); + throw std::runtime_error("Errore durante la conversione dell'oggetto PyUnicode a char*"); + } + Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* + break; default: - ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); + //ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); + //intPtr = 0; + free(tmp); break; } - return ret; - } else { - free(tmp); - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) + return strPtr; +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) + /*.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)-> std::pair{ if (buffer == NULL){ void* tmp = malloc(length);; From 18c8cc9fa8fa92e41c8fc40eacd998180a0246f8 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 11:36:57 +0100 Subject: [PATCH 032/155] fix ReadAttr --- bindings/storage/Node.cpp | 71 +++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 1a01db5..42debda 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -71,12 +71,14 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed //PyBytes_FromObject //.def("ReadAttr", py::overload_cast(&ReadAttrWrapper), "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->int*{ +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->py::object{ void* tmp = malloc(length);; // ssize_t result = self.ReadAttr(name, type, offset, tmp, length); self.ReadAttr(name, type, offset, tmp, length); PyObject* ret; - int* intPtr = 0; + //int32* intPtr = 0; + long intVal; + char* strPtr = strdup(""); switch (type){ case B_INT32_TYPE: ret = PyLong_FromVoidPtr(tmp); @@ -85,7 +87,63 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed throw std::runtime_error("Errore durante la chiamata a ReadAttr"); } // Converte l'oggetto PyObject* in un puntatore a int* - intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); + //intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); + /*if (intPtr == nullptr) { + Py_DECREF(ret); + free(tmp); + throw std::runtime_error("Errore durante la conversione dell'oggetto PyLong a int*"); + }*/ + intVal = PyLong_AsLong(ret); + // Ora intPtr punta all'area di memoria a cui puntava tmp + // Puoi utilizzare intPtr come desideri + Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* (non più necessario) + // Restituisci il puntatore a intPtr invece dell'oggetto PyObject* + break; + case B_STRING_TYPE: + ret = PyUnicode_FromString(static_cast(tmp)); + free(tmp); // Libera la memoria allocata con malloc + if (ret == nullptr) { + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } + // Converte l'oggetto PyObject* in un puntatore a char* + strPtr = strdup(PyUnicode_AsUTF8(ret)); + if (strPtr == nullptr) { + Py_DECREF(ret); + throw std::runtime_error("Errore durante la conversione dell'oggetto PyUnicode a char*"); + } + Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* + break; + default: + //ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); + //intPtr = 0; + free(tmp); + break; + } + if (type == B_STRING_TYPE){ + return py::str(strPtr); + } else if (type == B_INT32_TYPE){ + return py::int_(intVal); + } + return py::none(); + +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) +//##################################################################################################################### +/* +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->int32*{ + void* tmp = malloc(length);; +// ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + self.ReadAttr(name, type, offset, tmp, length); + PyObject* ret; + int32* intPtr = 0; + switch (type){ + case B_INT32_TYPE: + ret = PyLong_FromVoidPtr(tmp); + if (ret == nullptr) { + free(tmp); + throw std::runtime_error("Errore durante la chiamata a ReadAttr"); + } + // Converte l'oggetto PyObject* in un puntatore a int* + intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); if (intPtr == nullptr) { Py_DECREF(ret); free(tmp); @@ -114,13 +172,13 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed char* strPtr = strdup(""); switch (type){ case B_STRING_TYPE: - PyObject* ret = PyUnicode_FromString(static_cast(tmp)); + ret = PyUnicode_FromString(static_cast(tmp)); free(tmp); // Libera la memoria allocata con malloc if (ret == nullptr) { throw std::runtime_error("Errore durante la chiamata a ReadAttr"); } // Converte l'oggetto PyObject* in un puntatore a char* - strPtr = PyUnicode_AsUTF8(ret); + strPtr = strdup(PyUnicode_AsUTF8(ret)); if (strPtr == nullptr) { Py_DECREF(ret); throw std::runtime_error("Errore durante la conversione dell'oggetto PyUnicode a char*"); @@ -135,7 +193,8 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed } return strPtr; }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) - +*/ +//############################################################################################################ /*.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)-> std::pair{ if (buffer == NULL){ void* tmp = malloc(length);; From 3e17bba2062768d5147b30141d33318c140fc162 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 11:37:45 +0100 Subject: [PATCH 033/155] fix fstest.py --- fstest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fstest.py b/fstest.py index 088078f..eb8df52 100644 --- a/fstest.py +++ b/fstest.py @@ -35,7 +35,8 @@ def attr(node): my_obj = ctypes.py_object() #print(type(my_obj),my_obj) print(type_string, nfo.size) - al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, 0, 0, my_obj, 1024))) + print(node.ReadAttr(a, nfo.type, 0, None,1024)) + al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, nfo.type, 0, None,1024)))#my_obj, return al From 25016bf9fb7da6bc4923aa2129847b3698a35328 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 12:56:21 +0100 Subject: [PATCH 034/155] fix ReadAttr int32 --- bindings/storage/Node.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 42debda..57ad559 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -76,7 +76,6 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed // ssize_t result = self.ReadAttr(name, type, offset, tmp, length); self.ReadAttr(name, type, offset, tmp, length); PyObject* ret; - //int32* intPtr = 0; long intVal; char* strPtr = strdup(""); switch (type){ @@ -87,13 +86,17 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed throw std::runtime_error("Errore durante la chiamata a ReadAttr"); } // Converte l'oggetto PyObject* in un puntatore a int* - //intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); + int32* intPtr; + intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); /*if (intPtr == nullptr) { Py_DECREF(ret); free(tmp); throw std::runtime_error("Errore durante la conversione dell'oggetto PyLong a int*"); }*/ - intVal = PyLong_AsLong(ret); + //intVal = PyLong_AsLong(ret); + intVal = py::int_(*intPtr); + free(intPtr); + //intVal = PyLong_AsLong(ret); // Ora intPtr punta all'area di memoria a cui puntava tmp // Puoi utilizzare intPtr come desideri Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* (non più necessario) From 9bfecf7fecfb9d73f76227e417e375ef04fad2c7 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 14:22:25 +0100 Subject: [PATCH 035/155] optimize code --- bindings/storage/Node.cpp | 231 ++++++-------------------------------- 1 file changed, 37 insertions(+), 194 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 57ad559..b4d2b6d 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -13,27 +13,6 @@ namespace py = pybind11; -/* -PyObject* ReadAttrWrapper(BNode& self, const char* name, type_code type, off_t offset, PyObject* data, size_t length) { - void* buffer; - ssize_t ret = self.ReadAttr(name, type, offset, buffer, length); - PyObject* rit - switch (type){ - case B_INT32_TYPE: - // Turn the void* into an int* and put it into the PyObject - //*data = *(int*)buffer; - rit = PyLong_FromVoidPtr(buffer); - free(buffer); - break; - // and so on for each type_code... - default: - rit = PyLong_FromSsize_t(ret); - return rit; - break; - } - return rit; - -}*/ PYBIND11_MODULE(Node,m) @@ -72,12 +51,38 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed //.def("ReadAttr", py::overload_cast(&ReadAttrWrapper), "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) .def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->py::object{ - void* tmp = malloc(length);; -// ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + void* tmp = malloc(length); + if (tmp == nullptr){ + throw std::runtime_error("Error allocating memory"); + } + ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + if (result < 0) { + free(tmp); + throw std::runtime_error("Error calling ReadAttr"); + } + py::object ret; + switch (type) { + case B_INT32_TYPE: + ret = py::int_(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp)))); + break; + case B_STRING_TYPE: + ret = py::str(static_cast(tmp)); + break; + default: + ret = py::none(); + break; + free(tmp); + } + return ret; +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) +/* +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->py::object{ + void* tmp = malloc(length); self.ReadAttr(name, type, offset, tmp, length); PyObject* ret; long intVal; char* strPtr = strdup(""); + bool boolPtr; switch (type){ case B_INT32_TYPE: ret = PyLong_FromVoidPtr(tmp); @@ -88,17 +93,9 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed // Converte l'oggetto PyObject* in un puntatore a int* int32* intPtr; intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); - /*if (intPtr == nullptr) { - Py_DECREF(ret); - free(tmp); - throw std::runtime_error("Errore durante la conversione dell'oggetto PyLong a int*"); - }*/ - //intVal = PyLong_AsLong(ret); intVal = py::int_(*intPtr); free(intPtr); //intVal = PyLong_AsLong(ret); - // Ora intPtr punta all'area di memoria a cui puntava tmp - // Puoi utilizzare intPtr come desideri Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* (non più necessario) // Restituisci il puntatore a intPtr invece dell'oggetto PyObject* break; @@ -116,6 +113,12 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed } Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* break; + case B_BOOL_TYPE: + ret = PyLong_FromVoidPtr(tmp); + int32* intPtr; + intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); + boolPtr = PyBool_FromLong(*intPtr); + default: //ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); //intPtr = 0; @@ -126,173 +129,13 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed return py::str(strPtr); } else if (type == B_INT32_TYPE){ return py::int_(intVal); + } else if (type == B_BOOL_TYPE){ + return py::bool_(boolPtr); } return py::none(); -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) -//##################################################################################################################### -/* -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->int32*{ - void* tmp = malloc(length);; -// ssize_t result = self.ReadAttr(name, type, offset, tmp, length); - self.ReadAttr(name, type, offset, tmp, length); - PyObject* ret; - int32* intPtr = 0; - switch (type){ - case B_INT32_TYPE: - ret = PyLong_FromVoidPtr(tmp); - if (ret == nullptr) { - free(tmp); - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } - // Converte l'oggetto PyObject* in un puntatore a int* - intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); - if (intPtr == nullptr) { - Py_DECREF(ret); - free(tmp); - throw std::runtime_error("Errore durante la conversione dell'oggetto PyLong a int*"); - } - // Ora intPtr punta all'area di memoria a cui puntava tmp - // Puoi utilizzare intPtr come desideri - Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* (non più necessario) - // Restituisci il puntatore a intPtr invece dell'oggetto PyObject* - //return intPtr; - break; - default: - //ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); - //intPtr = 0; - free(tmp); - break; - } - return intPtr; -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length"))*/ -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->char*{ - void* tmp = malloc(length);; -// ssize_t result = self.ReadAttr(name, type, offset, tmp, length); - self.ReadAttr(name, type, offset, tmp, length); - PyObject* ret; - char* strPtr = strdup(""); - switch (type){ - case B_STRING_TYPE: - ret = PyUnicode_FromString(static_cast(tmp)); - free(tmp); // Libera la memoria allocata con malloc - if (ret == nullptr) { - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } - // Converte l'oggetto PyObject* in un puntatore a char* - strPtr = strdup(PyUnicode_AsUTF8(ret)); - if (strPtr == nullptr) { - Py_DECREF(ret); - throw std::runtime_error("Errore durante la conversione dell'oggetto PyUnicode a char*"); - } - Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* - break; - default: - //ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); - //intPtr = 0; - free(tmp); - break; - } - return strPtr; -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) -*/ -//############################################################################################################ -/*.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)-> std::pair{ - if (buffer == NULL){ - void* tmp = malloc(length);; - ssize_t result = self.ReadAttr(name, type, offset, tmp, length); - if (result > 0) { - return {result,tmp};//std::string(buffer); - } else { - free(tmp); - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } - } else { - ssize_t result = self.ReadAttr(name, type, offset, buffer, length); - if (result > 0) { - return {result,buffer}; - } else { - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } - } -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -*/ -/*.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length){ -//as buffer being an output variable we use instead the return value of the function diverging from Haiku-Book references - void* tmp = malloc(length); - ssize_t result = self.ReadAttr(name, type, offset, tmp, length); - if (result > 0) { - PyObject* ret; - switch (type){ - case B_INT32_TYPE: { - //ret = PyLong_FromLong(*reinterpret_cast(tmp)); - free(tmp); - - break; - } - /*default: { - ret = PyLong_FromLong(*reinterpret_cast(0)); - break; - }*/ - /* ############################################ - return ret; - } - //std::string(buffer); - } else { - free(tmp); - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length"))*/ -/* -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, PyObject* data, size_t length){ - if (data == NULL){ - void* tmp = malloc(length);; - ssize_t result = self.ReadAttr(name, type, offset, tmp, length); - if (result > 0) { - PyObject* ret; - switch (type){ - case B_INT32_TYPE: { - // Turn the void* into an int* and put it into the PyObject - ret = PyLong_FromLong(*reinterpret_cast(tmp)); - free(tmp); - break; - // and so on for each type_code... - } - return ret; - } - - //return result;//tmp;//std::string(buffer); - } else { - free(tmp); - return Py_None; - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } - } else { - ssize_t result = self.ReadAttr(name, type, offset, data, length); - if (result > 0) { - switch (type){ - case B_INT32_TYPE: { - PyObject* pyInt = PyLong_FromLong(*reinterpret_cast(data)); - Py_XINCREF(pyInt); // Incrementa il riferimento all'oggetto Python - data = pyInt; // Assegna direttamente il risultato di PyLong_FromLong a data - // Turn the void* into an int* and put it into the PyObject - // *data = PyLong_FromLong(*reinterpret_cast(data));//*(int32*)tmp; - // free(tmp); - break; - } - // and so on for each type_code... - } - //return PyLong_FromLong(result); //tmp;//std::string(buffer); - } else { - - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - - } - return PyLong_FromLong(result); - } -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -*/ .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) .def("RenameAttr", &BNode::RenameAttr, "", py::arg("oldName"), py::arg("newName")) //.def("GetAttrInfo", &BNode::GetAttrInfo, "", py::arg("name"), py::arg("info")) From c9397c3b9e071ce71fb2819b98c8ef3535143b20 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 15:12:19 +0100 Subject: [PATCH 036/155] ReadAttr Booleans --- bindings/storage/Node.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index b4d2b6d..4930279 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -68,6 +68,16 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed case B_STRING_TYPE: ret = py::str(static_cast(tmp)); break; + case B_BOOL_TYPE: + /*int32* inttmpPtr = reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp))); + if (inttmpPtr == nullptr) { + free(tmp); + throw std::runtime_error("Error converting PyLong object to int32*"); + } + ret = py::bool_(*inttmpPtr != 0); + break;*/ + ret = py::bool_(PyBool_FromLong(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp))))); + break; default: ret = py::none(); break; From 8c97fbb005b1b3fdd10adc7ce611f2c2b21ec575 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 16:50:36 +0100 Subject: [PATCH 037/155] support more ReadAttr types --- bindings/storage/Node.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 4930279..8102427 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -62,11 +63,16 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed } py::object ret; switch (type) { + //test Int64 for reinterpretation in int32* + case B_INT64_TYPE: case B_INT32_TYPE: + case B_INT16_TYPE: + case B_INT8_TYPE: ret = py::int_(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp)))); break; case B_STRING_TYPE: ret = py::str(static_cast(tmp)); + //ret = PyUnicode_FromString(static_cast(tmp)); break; case B_BOOL_TYPE: /*int32* inttmpPtr = reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp))); @@ -78,12 +84,33 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed break;*/ ret = py::bool_(PyBool_FromLong(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp))))); break; + case B_FLOAT_TYPE: + ret = py::float_(*reinterpret_cast(tmp)); + break; + case B_DOUBLE_TYPE: + ret = py::float_(*reinterpret_cast(tmp)); + break; + case B_TIME_TYPE:{ + bigtime_t timeValue = *reinterpret_cast(tmp); + std::chrono::system_clock::time_point timePoint = + std::chrono::system_clock::time_point(std::chrono::seconds(timeValue)); + // Calcola il tempo trascorso dalla mezzanotte del 1 gennaio 1970 in secondi + auto seconds_since_epoch = std::chrono::duration_cast(timePoint.time_since_epoch()).count(); + ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(seconds_since_epoch); + break; + /* + bigtime_t timeValue=*reinterpret_cast(tmp); + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::from_time_t(timeValue / 1000000); + ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(std::chrono::system_clock::to_time_t(timePoint)); + break;*/ + } default: ret = py::none(); break; - free(tmp); } + free(tmp); return ret; + //return py::reinterpret_steal(ret); }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) /* .def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->py::object{ From ba6a240ed63bd2c50d8158fb55e2f6c4d1fd13d9 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 27 Nov 2023 17:27:36 +0100 Subject: [PATCH 038/155] test ASCII and INT64 --- bindings/storage/Node.cpp | 2 ++ fstest.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 8102427..e1b20b7 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -71,6 +71,8 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed ret = py::int_(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp)))); break; case B_STRING_TYPE: + case B_MIME_STRING_TYPE: + case B_ASCII_TYPE: ret = py::str(static_cast(tmp)); //ret = PyUnicode_FromString(static_cast(tmp)); break; diff --git a/fstest.py b/fstest.py index eb8df52..3dcd95c 100644 --- a/fstest.py +++ b/fstest.py @@ -35,9 +35,8 @@ def attr(node): my_obj = ctypes.py_object() #print(type(my_obj),my_obj) print(type_string, nfo.size) - print(node.ReadAttr(a, nfo.type, 0, None,1024)) - al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, nfo.type, 0, None,1024)))#my_obj, - + print(node.ReadAttr(a, nfo.type, 0, None,nfo.size)) + al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, nfo.type, 0, None,nfo.size)))#my_obj, return al def get_type_int(stringa): @@ -51,7 +50,8 @@ def get_type_string(value): type_string = struct.pack('>I', value).decode('utf-8') return type_string -f=os.path.abspath("WPLaura.pdf")#Haiku-friûl.png")#fstest.py") +f=os.path.abspath("WPLaura.pdf") +#f=os.path.abspath("/boot/system/Tracker")#Haiku-friûl.png")#fstest.py") carta=card(f) #print(f) nf = BNode(f) From ad99ae96cb229d3ab65f4e2992795db0f0761a3d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 28 Nov 2023 23:24:07 +0100 Subject: [PATCH 039/155] fix decode time,test for ReadAttr fstest.py --- bindings/storage/Node.cpp | 7 ++++--- fstest.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index e1b20b7..d5a4355 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -93,9 +93,10 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed ret = py::float_(*reinterpret_cast(tmp)); break; case B_TIME_TYPE:{ - bigtime_t timeValue = *reinterpret_cast(tmp); + //bigtime_t timeValue = *reinterpret_cast(tmp); + time_t timeValue = *reinterpret_cast(tmp); std::chrono::system_clock::time_point timePoint = - std::chrono::system_clock::time_point(std::chrono::seconds(timeValue)); + std::chrono::system_clock::time_point(std::chrono::seconds(timeValue)); //this was microseconds // Calcola il tempo trascorso dalla mezzanotte del 1 gennaio 1970 in secondi auto seconds_since_epoch = std::chrono::duration_cast(timePoint.time_since_epoch()).count(); ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(seconds_since_epoch); @@ -176,7 +177,7 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length"))*/ .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) -.def("RenameAttr", &BNode::RenameAttr, "", py::arg("oldName"), py::arg("newName")) +.def("RenameAttr", py::overload_cast(&BNode::RenameAttr), "", py::arg("oldName"), py::arg("newName")) //.def("GetAttrInfo", &BNode::GetAttrInfo, "", py::arg("name"), py::arg("info")) //.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "", py::arg("name"), py::arg("info")) /*.def("GetAttrInfo", [](BNode& self, const char* attr) -> std::pair { diff --git a/fstest.py b/fstest.py index 3dcd95c..023b99b 100644 --- a/fstest.py +++ b/fstest.py @@ -1,5 +1,5 @@ -import os, struct, ctypes -from Be import BNode +import os, sys, struct, ctypes +from Be import BNode#,BString from Be.fs_attr import attr_info class card: @@ -36,6 +36,11 @@ def attr(node): #print(type(my_obj),my_obj) print(type_string, nfo.size) print(node.ReadAttr(a, nfo.type, 0, None,nfo.size)) + print(a) + if a == "Media:Width": + print("passo di qui") + node.RenameAttr("Media:Width", "media:width") + print(a) al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, nfo.type, 0, None,nfo.size)))#my_obj, return al @@ -50,7 +55,8 @@ def get_type_string(value): type_string = struct.pack('>I', value).decode('utf-8') return type_string -f=os.path.abspath("WPLaura.pdf") +f=os.path.abspath(sys.argv[1]) +#f=os.path.abspath("WPLaura.pdf") #f=os.path.abspath("/boot/system/Tracker")#Haiku-friûl.png")#fstest.py") carta=card(f) #print(f) From 37626af2599fd372dee9d2da648780fa486f3b1f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 28 Nov 2023 23:50:03 +0100 Subject: [PATCH 040/155] tested removeAttr, faulty RenameAttr --- bindings/storage/Node.cpp | 3 ++- fstest.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index d5a4355..539a6f6 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -177,7 +177,8 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length"))*/ .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) -.def("RenameAttr", py::overload_cast(&BNode::RenameAttr), "", py::arg("oldName"), py::arg("newName")) +//.def("RenameAttr", py::overload_cast(&BNode::RenameAttr), "", py::arg("oldName"), py::arg("newName")) +.def("RenameAttr", &BNode::RenameAttr, "", py::arg("oldName"), py::arg("newName")) //.def("GetAttrInfo", &BNode::GetAttrInfo, "", py::arg("name"), py::arg("info")) //.def("GetAttrInfo", py::overload_cast(&BNode::GetAttrInfo, py::const_), "", py::arg("name"), py::arg("info")) /*.def("GetAttrInfo", [](BNode& self, const char* attr) -> std::pair { diff --git a/fstest.py b/fstest.py index 023b99b..4a99bb0 100644 --- a/fstest.py +++ b/fstest.py @@ -39,9 +39,11 @@ def attr(node): print(a) if a == "Media:Width": print("passo di qui") - node.RenameAttr("Media:Width", "media:width") + node.RenameAttr("Media:Width", "media:width")# <- not working print(a) + al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, nfo.type, 0, None,nfo.size)))#my_obj, + #node.RemoveAttr("Media:Width") <- works return al def get_type_int(stringa): From 40a780e2856ceea68803bdcc6a1db1163d48c4b2 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 29 Nov 2023 03:35:15 +0100 Subject: [PATCH 041/155] make compatible to main --- bindings/support/Archivable.cpp | 30 -------- bindings/support/SupportDefs.cpp | 115 ------------------------------- 2 files changed, 145 deletions(-) delete mode 100644 bindings/support/Archivable.cpp delete mode 100644 bindings/support/SupportDefs.cpp diff --git a/bindings/support/Archivable.cpp b/bindings/support/Archivable.cpp deleted file mode 100644 index c9a445b..0000000 --- a/bindings/support/Archivable.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include "support/Archivable.h" // Assicurati che il nome del tuo file header sia corretto - -namespace py = pybind11; - -class PyBArchivable : public BArchivable { -public: - // Costruttori - using BArchivable::BArchivable; // Eredità dei costruttori base - - // Metodo per l'archiviazione - status_t Archive(BMessage* into, bool deep = true) const override { - PYBIND11_OVERLOAD_PURE(status_t, BArchivable, Archive, into, deep); - } - - // Altri metodi da esporre a Python, se necessario -}; - -PYBIND11_MODULE(Archivable, m) { - py::class_(m, "BArchivable") - .def(py::init()) - .def(py::init<>()) - .def("Archive", &BArchivable::Archive); - - // Aggiungi altri metodi e costruttori se necessario - - // Aggiungi altre classi wrapper se necessario -} - diff --git a/bindings/support/SupportDefs.cpp b/bindings/support/SupportDefs.cpp deleted file mode 100644 index ef6ebbc..0000000 --- a/bindings/support/SupportDefs.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include -#include -#include -#include "support/SupportDefs.h" -#include - -namespace py = pybind11; - -PYBIND11_MODULE(SupportDefs, m) { - m.attr("B_EMPTY_STRING") = B_EMPTY_STRING; - - // Definizione dei tipi di dati - py::class_(m, "status_t"); - py::class_(m, "bigtime_t"); - py::class_(m, "type_code"); - - py::class_(m, "phys_addr_t"); - - // ... Aggiungi altri tipi di dati secondo necessità ... - - // Aggiungi costanti o macro se necessario - m.attr("B_PRId8") = B_PRId8; - m.attr("B_PRIi8") = B_PRIi8; - m.attr("B_PRId16") = B_PRId16; - m.attr("B_PRIi16") = B_PRIi16; - m.attr("B_PRId32") = B_PRId32; - m.attr("B_PRIi32") = B_PRIi32; - m.attr("B_PRId64") = B_PRId64; - m.attr("B_PRIi64") = B_PRIi64; - - m.attr("B_PRIu8") = B_PRIu8; - m.attr("B_PRIo8") = B_PRIo8; - m.attr("B_PRIx8") = B_PRIx8; - m.attr("B_PRIX8") = B_PRIX8; - m.attr("B_PRIu16") = B_PRIu16; - m.attr("B_PRIo16") = B_PRIo16; - m.attr("B_PRIx16") = B_PRIx16; - m.attr("B_PRIX16") = B_PRIX16; - m.attr("B_PRIu32") = B_PRIu32; - m.attr("B_PRIo32") = B_PRIo32; - m.attr("B_PRIx32") = B_PRIx32; - m.attr("B_PRIX32") = B_PRIX32; - m.attr("B_PRIu64") = B_PRIu64; - m.attr("B_PRIo64") = B_PRIo64; - m.attr("B_PRIx64") = B_PRIx64; - m.attr("B_PRIX64") = B_PRIX64; - - m.attr("B_SCNd8") = B_SCNd8; - m.attr("B_SCNi8") = B_SCNi8; - m.attr("B_SCNd16") = B_SCNd16; - m.attr("B_SCNi16") = B_SCNi16; - m.attr("B_SCNd32") = B_SCNd32; - m.attr("B_SCNi32") = B_SCNi32; - m.attr("B_SCNd64") = B_SCNd64; - m.attr("B_SCNi64") = B_SCNi64; - - m.attr("B_SCNu8") = B_SCNu8; - m.attr("B_SCNo8") = B_SCNo8; - m.attr("B_SCNx8") = B_SCNx8; - m.attr("B_SCNu16") = B_SCNu16; - m.attr("B_SCNo16") = B_SCNo16; - m.attr("B_SCNx16") = B_SCNx16; - m.attr("B_SCNu32") = B_SCNu32; - m.attr("B_SCNo32") = B_SCNo32; - m.attr("B_SCNx32") = B_SCNx32; - m.attr("B_SCNu64") = B_SCNu64; - m.attr("B_SCNo64") = B_SCNo64; - m.attr("B_SCNx64") = B_SCNx64; - // ... Aggiungi altre costanti o macro secondo necessità ... - m.attr("B_PRIuSIZE") = B_PRIuSIZE; - m.attr("B_PRIoSIZE") = B_PRIoSIZE; - m.attr("B_PRIxSIZE") = B_PRIxSIZE; - m.attr("B_PRIXSIZE") = B_PRIXSIZE; - m.attr("B_SCNuSIZE") = B_SCNuSIZE; - m.attr("B_SCNoSIZE") = B_SCNoSIZE; - m.attr("B_SCNxSIZE") = B_SCNxSIZE; - m.attr("B_PRIdSSIZE") = B_PRIdSSIZE; - m.attr("B_PRIiSSIZE") = B_PRIiSSIZE; - m.attr("B_SCNdSSIZE") = B_SCNdSSIZE; - m.attr("B_SCNiSSIZE") = B_SCNiSSIZE; - m.attr("B_PRIuADDR") = B_PRIuADDR; - m.attr("B_PRIoADDR") = B_PRIoADDR; - m.attr("B_PRIxADDR") = B_PRIxADDR; - m.attr("B_PRIXADDR") = B_PRIXADDR; - m.attr("B_SCNuADDR") = B_SCNuADDR; - m.attr("B_SCNoADDR") = B_SCNoADDR; - m.attr("B_PRIuPHYSADDR") = B_PRIuPHYSADDR; - m.attr("B_PRIoPHYSADDR") = B_PRIoPHYSADDR; - m.attr("B_PRIxPHYSADDR") = B_PRIxPHYSADDR; - m.attr("B_PRIXPHYSADDR") = B_PRIXPHYSADDR; - m.attr("B_SCNuPHYSADDR") = B_SCNuPHYSADDR; - m.attr("B_SCNoPHYSADDR") = B_SCNoPHYSADDR; - m.attr("B_SCNxPHYSADDR") = B_SCNxPHYSADDR; - m.attr("B_PRIuGENADDR") = B_PRIuGENADDR; - m.attr("B_PRIoGENADDR") = B_PRIoGENADDR; - m.attr("B_PRIxGENADDR") = B_PRIxGENADDR; - m.attr("B_PRIXGENADDR") = B_PRIXGENADDR; - m.attr("B_SCNuGENADDR") = B_SCNuGENADDR; - m.attr("B_SCNoGENADDR") = B_SCNoGENADDR; - m.attr("B_SCNxGENADDR") = B_SCNxGENADDR; - m.attr("B_PRIdOFF") = B_PRIdOFF; - m.attr("B_PRIiOFF") = B_PRIiOFF; - m.attr("B_PRIxOFF") = B_PRIxOFF; - m.attr("B_SCNdOFF") = B_SCNdOFF; - m.attr("B_SCNiOFF") = B_SCNiOFF; - m.attr("B_SCNxOFF") = B_SCNxOFF; - m.attr("B_PRIdDEV") = B_PRIdDEV; - m.attr("B_PRIiDEV") = B_PRIiDEV; - m.attr("B_PRIdINO") = B_PRIdINO; - m.attr("B_PRIiINO") = B_PRIiINO; - m.attr("B_PRIdBIGTIME") = B_PRIdBIGTIME; - m.attr("B_PRIiBIGTIME") = B_PRIiBIGTIME; -} - From 4d7f6db6e4dee713dfc12a6b6f3e00893cabcb40 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 29 Nov 2023 10:47:13 +0100 Subject: [PATCH 042/155] Fix SupportDefs.cpp --- bindings/support/SupportDefs.cpp | 177 +++++++++++++++++++++---------- 1 file changed, 120 insertions(+), 57 deletions(-) diff --git a/bindings/support/SupportDefs.cpp b/bindings/support/SupportDefs.cpp index 6abbfc4..0f0827b 100644 --- a/bindings/support/SupportDefs.cpp +++ b/bindings/support/SupportDefs.cpp @@ -8,66 +8,129 @@ namespace py = pybind11; -void define_SupportDefs(py::module_& m) +PYBIND11_MODULE(SupportDefs, m) { m.attr("B_EMPTY_STRING") = py::cast(B_EMPTY_STRING); m.def("get_stack_frame", &get_stack_frame, "", py::arg("")); -m.def_static("atomic_set", py::overload_cast(&atomic_set), "", py::arg("value"), py::arg("newValue")); - -m.def_static("atomic_get_and_set", py::overload_cast(&atomic_get_and_set), "", py::arg("value"), py::arg("newValue")); - -m.def_static("atomic_test_and_set", py::overload_cast(&atomic_test_and_set), "", py::arg("value"), py::arg("newValue"), py::arg("testAgainst")); - -m.def_static("atomic_add", py::overload_cast(&atomic_add), "", py::arg("value"), py::arg("addValue")); - -m.def_static("atomic_and", py::overload_cast(&atomic_and), "", py::arg("value"), py::arg("andValue")); - -m.def_static("atomic_or", py::overload_cast(&atomic_or), "", py::arg("value"), py::arg("orValue")); - -m.def_static("atomic_get", py::overload_cast(&atomic_get), "", py::arg("value")); - -m.def_static("atomic_set64", py::overload_cast(&atomic_set64), "", py::arg("value"), py::arg("newValue")); - -m.def_static("atomic_get_and_set64", py::overload_cast(&atomic_get_and_set64), "", py::arg("value"), py::arg("newValue")); - -m.def_static("atomic_test_and_set64", py::overload_cast(&atomic_test_and_set64), "", py::arg("value"), py::arg("newValue"), py::arg("testAgainst")); - -m.def_static("atomic_add64", py::overload_cast(&atomic_add64), "", py::arg("value"), py::arg("addValue")); - -m.def_static("atomic_and64", py::overload_cast(&atomic_and64), "", py::arg("value"), py::arg("andValue")); - -m.def_static("atomic_or64", py::overload_cast(&atomic_or64), "", py::arg("value"), py::arg("orValue")); - -m.def_static("atomic_get64", py::overload_cast(&atomic_get64), "", py::arg("value")); - -m.def("atomic_set", py::overload_cast(&atomic_set), "", py::arg("value"), py::arg("newValue")); - -m.def("atomic_get_and_set", py::overload_cast(&atomic_get_and_set), "", py::arg("value"), py::arg("newValue")); - -m.def("atomic_test_and_set", py::overload_cast(&atomic_test_and_set), "", py::arg("value"), py::arg("newValue"), py::arg("testAgainst")); - -m.def("atomic_add", py::overload_cast(&atomic_add), "", py::arg("value"), py::arg("addValue")); - -m.def("atomic_and", py::overload_cast(&atomic_and), "", py::arg("value"), py::arg("andValue")); - -m.def("atomic_or", py::overload_cast(&atomic_or), "", py::arg("value"), py::arg("orValue")); - -m.def("atomic_get", py::overload_cast(&atomic_get), "", py::arg("value")); - -m.def("atomic_set64", py::overload_cast(&atomic_set64), "", py::arg("value"), py::arg("newValue")); - -m.def("atomic_get_and_set64", py::overload_cast(&atomic_get_and_set64), "", py::arg("value"), py::arg("newValue")); - -m.def("atomic_test_and_set64", py::overload_cast(&atomic_test_and_set64), "", py::arg("value"), py::arg("newValue"), py::arg("testAgainst")); - -m.def("atomic_add64", py::overload_cast(&atomic_add64), "", py::arg("value"), py::arg("addValue")); - -m.def("atomic_and64", py::overload_cast(&atomic_and64), "", py::arg("value"), py::arg("andValue")); - -m.def("atomic_or64", py::overload_cast(&atomic_or64), "", py::arg("value"), py::arg("orValue")); - -m.def("atomic_get64", py::overload_cast(&atomic_get64), "", py::arg("value")); - +m.def("atomic_set", py::overload_cast(&atomic_set), "", py::arg("value"), py::arg("newValue")); + +m.def("atomic_get_and_set", py::overload_cast(&atomic_get_and_set), "", py::arg("value"), py::arg("newValue")); + +m.def("atomic_test_and_set", py::overload_cast(&atomic_test_and_set), "", py::arg("value"), py::arg("newValue"), py::arg("testAgainst")); + +m.def("atomic_add", py::overload_cast(&atomic_add), "", py::arg("value"), py::arg("addValue")); + +m.def("atomic_and", py::overload_cast(&atomic_and), "", py::arg("value"), py::arg("andValue")); + +m.def("atomic_or", py::overload_cast(&atomic_or), "", py::arg("value"), py::arg("orValue")); + +m.def("atomic_get", py::overload_cast(&atomic_get), "", py::arg("value")); + +m.def("atomic_set64", py::overload_cast(&atomic_set64), "", py::arg("value"), py::arg("newValue")); + +m.def("atomic_get_and_set64", py::overload_cast(&atomic_get_and_set64), "", py::arg("value"), py::arg("newValue")); + +m.def("atomic_test_and_set64", py::overload_cast(&atomic_test_and_set64), "", py::arg("value"), py::arg("newValue"), py::arg("testAgainst")); + +m.def("atomic_add64", py::overload_cast(&atomic_add64), "", py::arg("value"), py::arg("addValue")); + +m.def("atomic_and64", py::overload_cast(&atomic_and64), "", py::arg("value"), py::arg("andValue")); + +m.def("atomic_or64", py::overload_cast(&atomic_or64), "", py::arg("value"), py::arg("orValue")); + +m.def("atomic_get64", py::overload_cast(&atomic_get64), "", py::arg("value")); + +m.attr("B_PRId8") = B_PRId8; + m.attr("B_PRIi8") = B_PRIi8; + m.attr("B_PRId16") = B_PRId16; + m.attr("B_PRIi16") = B_PRIi16; + m.attr("B_PRId32") = B_PRId32; + m.attr("B_PRIi32") = B_PRIi32; + m.attr("B_PRId64") = B_PRId64; + m.attr("B_PRIi64") = B_PRIi64; + + m.attr("B_PRIu8") = B_PRIu8; + m.attr("B_PRIo8") = B_PRIo8; + m.attr("B_PRIx8") = B_PRIx8; + m.attr("B_PRIX8") = B_PRIX8; + m.attr("B_PRIu16") = B_PRIu16; + m.attr("B_PRIo16") = B_PRIo16; + m.attr("B_PRIx16") = B_PRIx16; + m.attr("B_PRIX16") = B_PRIX16; + m.attr("B_PRIu32") = B_PRIu32; + m.attr("B_PRIo32") = B_PRIo32; + m.attr("B_PRIx32") = B_PRIx32; + m.attr("B_PRIX32") = B_PRIX32; + m.attr("B_PRIu64") = B_PRIu64; + m.attr("B_PRIo64") = B_PRIo64; + m.attr("B_PRIx64") = B_PRIx64; + m.attr("B_PRIX64") = B_PRIX64; + + m.attr("B_SCNd8") = B_SCNd8; + m.attr("B_SCNi8") = B_SCNi8; + m.attr("B_SCNd16") = B_SCNd16; + m.attr("B_SCNi16") = B_SCNi16; + m.attr("B_SCNd32") = B_SCNd32; + m.attr("B_SCNi32") = B_SCNi32; + m.attr("B_SCNd64") = B_SCNd64; + m.attr("B_SCNi64") = B_SCNi64; + + m.attr("B_SCNu8") = B_SCNu8; + m.attr("B_SCNo8") = B_SCNo8; + m.attr("B_SCNx8") = B_SCNx8; + m.attr("B_SCNu16") = B_SCNu16; + m.attr("B_SCNo16") = B_SCNo16; + m.attr("B_SCNx16") = B_SCNx16; + m.attr("B_SCNu32") = B_SCNu32; + m.attr("B_SCNo32") = B_SCNo32; + m.attr("B_SCNx32") = B_SCNx32; + m.attr("B_SCNu64") = B_SCNu64; + m.attr("B_SCNo64") = B_SCNo64; + m.attr("B_SCNx64") = B_SCNx64; + // ... Aggiungi altre costanti o macro secondo necessità ... + m.attr("B_PRIuSIZE") = B_PRIuSIZE; + m.attr("B_PRIoSIZE") = B_PRIoSIZE; + m.attr("B_PRIxSIZE") = B_PRIxSIZE; + m.attr("B_PRIXSIZE") = B_PRIXSIZE; + m.attr("B_SCNuSIZE") = B_SCNuSIZE; + m.attr("B_SCNoSIZE") = B_SCNoSIZE; + m.attr("B_SCNxSIZE") = B_SCNxSIZE; + m.attr("B_PRIdSSIZE") = B_PRIdSSIZE; + m.attr("B_PRIiSSIZE") = B_PRIiSSIZE; + m.attr("B_SCNdSSIZE") = B_SCNdSSIZE; + m.attr("B_SCNiSSIZE") = B_SCNiSSIZE; + m.attr("B_PRIuADDR") = B_PRIuADDR; + m.attr("B_PRIoADDR") = B_PRIoADDR; + m.attr("B_PRIxADDR") = B_PRIxADDR; + m.attr("B_PRIXADDR") = B_PRIXADDR; + m.attr("B_SCNuADDR") = B_SCNuADDR; + m.attr("B_SCNoADDR") = B_SCNoADDR; + m.attr("B_PRIuPHYSADDR") = B_PRIuPHYSADDR; + m.attr("B_PRIoPHYSADDR") = B_PRIoPHYSADDR; + m.attr("B_PRIxPHYSADDR") = B_PRIxPHYSADDR; + m.attr("B_PRIXPHYSADDR") = B_PRIXPHYSADDR; + m.attr("B_SCNuPHYSADDR") = B_SCNuPHYSADDR; + m.attr("B_SCNoPHYSADDR") = B_SCNoPHYSADDR; + m.attr("B_SCNxPHYSADDR") = B_SCNxPHYSADDR; + m.attr("B_PRIuGENADDR") = B_PRIuGENADDR; + m.attr("B_PRIoGENADDR") = B_PRIoGENADDR; + m.attr("B_PRIxGENADDR") = B_PRIxGENADDR; + m.attr("B_PRIXGENADDR") = B_PRIXGENADDR; + m.attr("B_SCNuGENADDR") = B_SCNuGENADDR; + m.attr("B_SCNoGENADDR") = B_SCNoGENADDR; + m.attr("B_SCNxGENADDR") = B_SCNxGENADDR; + m.attr("B_PRIdOFF") = B_PRIdOFF; + m.attr("B_PRIiOFF") = B_PRIiOFF; + m.attr("B_PRIxOFF") = B_PRIxOFF; + m.attr("B_SCNdOFF") = B_SCNdOFF; + m.attr("B_SCNiOFF") = B_SCNiOFF; + m.attr("B_SCNxOFF") = B_SCNxOFF; + m.attr("B_PRIdDEV") = B_PRIdDEV; + m.attr("B_PRIiDEV") = B_PRIiDEV; + m.attr("B_PRIdINO") = B_PRIdINO; + m.attr("B_PRIiINO") = B_PRIiINO; + m.attr("B_PRIdBIGTIME") = B_PRIdBIGTIME; + m.attr("B_PRIiBIGTIME") = B_PRIiBIGTIME; } From 3b990ea38be919a982dedb61a816d427946b15fd Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 29 Nov 2023 12:11:44 +0100 Subject: [PATCH 043/155] Fix SupportDefs, Archivable --- bindings/support/Archivable.cpp | 98 ++++++++++++++++++-------------- bindings/support/SupportDefs.cpp | 2 +- 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/bindings/support/Archivable.cpp b/bindings/support/Archivable.cpp index 13fc8e6..e8efd50 100644 --- a/bindings/support/Archivable.cpp +++ b/bindings/support/Archivable.cpp @@ -4,21 +4,17 @@ #include #include +//#include +//#include +//#include namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::Archiving; -void define_Archivable(py::module_& m) -{ -m.attr("BArchiveManager") = py::cast(BArchiveManager); - -m.attr("BUnarchiveManager") = py::cast(BUnarchiveManager); - -m.attr("BArchiveManager") = py::cast(BArchiveManager); - -m.attr("BUnarchiveManager") = py::cast(BUnarchiveManager); +PYBIND11_MODULE(Archivable, m) +{ py::class_(m, "BArchivable") .def(py::init(), "", py::arg("from")) .def(py::init(), "") @@ -32,55 +28,61 @@ py::class_(m, "BArchivable") py::class_(m, "BArchiver") .def(py::init(), "", py::arg("archive")) .def("AddArchivable", &BArchiver::AddArchivable, "", py::arg("name"), py::arg("archivable"), py::arg("deep")=true) -.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("_token")) -.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("deep"), py::arg("_token")) +//.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("_token")) +//.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("deep"), py::arg("_token")) .def("IsArchived", &BArchiver::IsArchived, "", py::arg("archivable")) .def("Finish", &BArchiver::Finish, "", py::arg("err")=B_OK) .def("ArchiveMessage", &BArchiver::ArchiveMessage, "") ; +/* my attempt to import ownership_policy +py::enum_(m, "ownership_policy") +.value("B_ASSUME_OWNERSHIP", BUnarchiver::ownership_policy::B_ASSUME_OWNERSHIP, "") +.value("B_DONT_ASSUME_OWNERSHIP", BUnarchiver::ownership_policy::B_DONT_ASSUME_OWNERSHIP, "") +.export_values(); +*/ py::class_(m, "BUnarchiver") .def(py::init(), "", py::arg("archive")) -.def("GetObject", [](BUnarchiver& self,int token) { +/* +.def("ownership_policy", py::enum_(m,"ownership_policy") + .value("B_ASSUME_OWNERSHIP",BUnarchiver::ownership_policy::B_ASSUME_OWNERSHIP) + .value("B_DONT_ASSUME_OWNERSHIP", BUnarchiver::ownership_policy::B_DONT_ASSUME_OWNERSHIP) +) +*/ +/*.def("GetObject", [](BUnarchiver& self,int token) { T * object; inline status_t r = self.GetObject(token, object); return std::make_tuple(r,object); -} -, "", py::arg("token")) -.def("GetObject", [](BUnarchiver& self,int token,ownership_policy owning) { +}, "", py::arg("token"))*/ +/*.def("GetObject", [](BUnarchiver& self,int token,ownership_policy owning) { T * object; status_t r = self.GetObject(token, owning, object); return std::make_tuple(r,object); -} -, "", py::arg("token"), py::arg("owning")) -.def("FindObject", [](BUnarchiver& self,const char * name) { +}, "", py::arg("token"), py::arg("owning"))*/ +/*.def("FindObject", [](BUnarchiver& self,const char * name) { T * object; inline status_t r = self.FindObject(name, object); return std::make_tuple(r,object); -} -, "", py::arg("name")) -.def("FindObject", [](BUnarchiver& self,const char * name,ownership_policy owning) { +}, "", py::arg("name"))*/ +/*.def("FindObject", [](BUnarchiver& self,const char * name,ownership_policy owning) { T * object; inline status_t r = self.FindObject(name, owning, object); return std::make_tuple(r,object); -} -, "", py::arg("name"), py::arg("owning")) -.def("FindObject", [](BUnarchiver& self,const char * name,int index) { +}, "", py::arg("name"), py::arg("owning"))*/ +/*.def("FindObject", [](BUnarchiver& self,const char * name,int index) { T * object; inline status_t r = self.FindObject(name, index, object); return std::make_tuple(r,object); -} -, "", py::arg("name"), py::arg("index")) -.def("FindObject", [](BUnarchiver& self,const char * name,int index,ownership_policy owning) { +}, "", py::arg("name"), py::arg("index"))*/ +/*.def("FindObject", [](BUnarchiver& self,const char * name,int index,ownership_policy owning) { T * object; status_t r = self.FindObject(name, index, owning, object); return std::make_tuple(r,object); -} -, "", py::arg("name"), py::arg("index"), py::arg("owning")) -.def("EnsureUnarchived", py::overload_cast(&BUnarchiver::EnsureUnarchived), "", py::arg("name"), py::arg("index")=0) -.def("EnsureUnarchived", py::overload_cast(&BUnarchiver::EnsureUnarchived), "", py::arg("token")) -.def("IsInstantiated", py::overload_cast(&BUnarchiver::IsInstantiated), "", py::arg("token")) -.def("IsInstantiated", py::overload_cast(&BUnarchiver::IsInstantiated), "", py::arg("name"), py::arg("index")=0) +}, "", py::arg("name"), py::arg("index"), py::arg("owning"))*/ +.def("EnsureUnarchived", py::overload_cast(&BUnarchiver::EnsureUnarchived), "", py::arg("name"), py::arg("index")=0) +.def("EnsureUnarchived", py::overload_cast(&BUnarchiver::EnsureUnarchived), "", py::arg("token")) +.def("IsInstantiated", py::overload_cast(&BUnarchiver::IsInstantiated), "", py::arg("token")) +.def("IsInstantiated", py::overload_cast(&BUnarchiver::IsInstantiated), "", py::arg("name"), py::arg("index")=0) .def("Finish", &BUnarchiver::Finish, "", py::arg("err")=B_OK) .def("ArchiveMessage", &BUnarchiver::ArchiveMessage, "") .def("AssumeOwnership", &BUnarchiver::AssumeOwnership, "", py::arg("archivable")) @@ -92,45 +94,57 @@ py::class_(m, "BUnarchiver") return std::make_tuple(r,archive); } , "") -.def_static("InstantiateObject", [](BUnarchiver& self,BMessage * archive) { +/*.def_static("InstantiateObject", [](BUnarchiver& self,BMessage * archive) { T * object; static status_t r = self.InstantiateObject(archive, object); return std::make_tuple(r,object); -} -, "", py::arg("archive")) +}, "", py::arg("archive"))*/ ; +/* these do not generate errors on compile-time + m.def("instantiate_object", py::overload_cast(&instantiate_object), "", py::arg("from"), py::arg("id")); m.def("instantiate_object", py::overload_cast(&instantiate_object), "", py::arg("from")); m.def("validate_instantiation", &validate_instantiation, "", py::arg("from"), py::arg("className")); +*/ -m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("className"), py::arg("signature")); +//m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("className"), py::arg("signature")); -m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("className")); - -m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("archive")); +//m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("className")); +//m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("archive")); +/* m.def(">", [](const char * name,int index,ownership_policy owning) { BArchivable * archivable; status_t BUnarchiver::FindObject(name, index, owning, archivable); return std::make_tuple(r,archivable); } , "", py::arg("name"), py::arg("index"), py::arg("owning")); - +*/ +/* m.def(">", [](int token,ownership_policy owning) { BArchivable * object; status_t BUnarchiver::GetObject(token, owning, object); return std::make_tuple(r,object); } , "", py::arg("token"), py::arg("owning")); - +*/ +/* m.def(">", [](BMessage * from) { BArchivable * object; status_t BUnarchiver::InstantiateObject(from, object); return std::make_tuple(r,object); } , "", py::arg("from")); +*/ + +//m.attr("BArchiveManager") = py::cast(BArchiveManager); + +//m.attr("BUnarchiveManager") = py::cast(BUnarchiveManager); + +//m.attr("BArchiveManager") = py::cast(BArchiveManager); +//m.attr("BUnarchiveManager") = py::cast(BUnarchiveManager); } diff --git a/bindings/support/SupportDefs.cpp b/bindings/support/SupportDefs.cpp index 0f0827b..d27868c 100644 --- a/bindings/support/SupportDefs.cpp +++ b/bindings/support/SupportDefs.cpp @@ -12,7 +12,7 @@ PYBIND11_MODULE(SupportDefs, m) { m.attr("B_EMPTY_STRING") = py::cast(B_EMPTY_STRING); -m.def("get_stack_frame", &get_stack_frame, "", py::arg("")); +m.def("get_stack_frame", &get_stack_frame, "");//, py::arg("")); m.def("atomic_set", py::overload_cast(&atomic_set), "", py::arg("value"), py::arg("newValue")); From 248fe685e61c915539fdd6363b98e6bc47562a97 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 29 Nov 2023 12:27:46 +0100 Subject: [PATCH 044/155] Temporary Fix TypeConstants --- bindings/support/TypeConstants.cpp | 37 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/bindings/support/TypeConstants.cpp b/bindings/support/TypeConstants.cpp index 574384e..d4d41ed 100644 --- a/bindings/support/TypeConstants.cpp +++ b/bindings/support/TypeConstants.cpp @@ -2,14 +2,13 @@ #include #include #include -<<<<<<< HEAD +//<<<<<<< HEAD #include - +/* namespace py = pybind11; - -void define_TypeConstants(py::module_& m) +PYBIND11_MODULE(TypeConstants, m) { m.attr("B_AFFINE_TRANSFORM_TYPE") = py::cast(B_AFFINE_TRANSFORM_TYPE); m.attr("B_ALIGNMENT_TYPE") = py::cast(B_ALIGNMENT_TYPE); @@ -89,9 +88,7 @@ m.attr("B_URL_FILE") = py::cast(B_URL_FILE); } -======= -#include -#include +*/ namespace py = pybind11; @@ -147,7 +144,27 @@ PYBIND11_MODULE(TypeConstants, m) { m.attr("B_NETWORK_ADDRESS_TYPE") = 'NWAD'; m.attr("B_MIME_STRING_TYPE") = 'MIMS'; m.attr("B_ASCII_TYPE") = 'TEXT'; - -} + m.attr("B_URL_HTTP") = py::cast(B_URL_HTTP); + +m.attr("B_URL_HTTPS") = py::cast(B_URL_HTTPS); + +m.attr("B_URL_FTP") = py::cast(B_URL_FTP); + +m.attr("B_URL_GOPHER") = py::cast(B_URL_GOPHER); + +m.attr("B_URL_MAILTO") = py::cast(B_URL_MAILTO); + +m.attr("B_URL_NEWS") = py::cast(B_URL_NEWS); ->>>>>>> tmtfx-testing +m.attr("B_URL_NNTP") = py::cast(B_URL_NNTP); + +m.attr("B_URL_TELNET") = py::cast(B_URL_TELNET); + +m.attr("B_URL_RLOGIN") = py::cast(B_URL_RLOGIN); + +m.attr("B_URL_TN3270") = py::cast(B_URL_TN3270); + +m.attr("B_URL_WAIS") = py::cast(B_URL_WAIS); + +m.attr("B_URL_FILE") = py::cast(B_URL_FILE); +} From aadaba4c689c3b8d4014608efa84dd5755eab5aa Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 29 Nov 2023 13:25:34 +0100 Subject: [PATCH 045/155] update fstest.py --- fstest.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fstest.py b/fstest.py index 4a99bb0..e9ab376 100644 --- a/fstest.py +++ b/fstest.py @@ -34,13 +34,11 @@ def attr(node): #print(get_type_int(type_string),nfo.type) my_obj = ctypes.py_object() #print(type(my_obj),my_obj) - print(type_string, nfo.size) - print(node.ReadAttr(a, nfo.type, 0, None,nfo.size)) - print(a) + print("Attr_name:",a,"Type:",type_string,"Size:", nfo.size,"Value:",node.ReadAttr(a, nfo.type, 0, None,nfo.size)) if a == "Media:Width": - print("passo di qui") + print("Attempt to change AttribName") node.RenameAttr("Media:Width", "media:width")# <- not working - print(a) + print("Name after RenameAttr:",a) al.append((a,("Type:",type_string,"Size:",nfo.size),node.ReadAttr(a, nfo.type, 0, None,nfo.size)))#my_obj, #node.RemoveAttr("Media:Width") <- works From 17b8f4229a4f3cc175a0d27a3d544037ec7b1898 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 29 Nov 2023 19:49:41 +0100 Subject: [PATCH 046/155] ReadAttr B_RAW_TYPE, defaults return bytes for not handled types --- bindings/storage/Node.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 539a6f6..07f882d 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -107,8 +107,14 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(std::chrono::system_clock::to_time_t(timePoint)); break;*/ } + case B_RAW_TYPE:{ + ret = py::bytes(reinterpret_cast(tmp), length); + break; + } default: - ret = py::none(); + ret = py::bytes(reinterpret_cast(tmp), length); + //ret = py::bytes(static_cast(tmp)); + //py::none(); break; } free(tmp); From dc114b613a034daba638a52d1aab44ab5cf510d0 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 09:22:48 +0100 Subject: [PATCH 047/155] Add Bitmap --- Jamfile | 2 +- bindings/__init__.py | 2 +- bindings/interface/Bitmap.cpp | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Jamfile b/Jamfile index a71ebd0..f471aa0 100644 --- a/Jamfile +++ b/Jamfile @@ -140,7 +140,7 @@ local sourceFiles = ListView.cpp ScrollView.cpp ListItem.cpp - #Bitmap.cpp + Bitmap.cpp #Slider.cpp Picture.cpp PictureButton.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 2658a5e..9dec670 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -52,7 +52,7 @@ from .TypeConstants import * from .Archivable import * from .ListItem import * -#from .Bitmap import * +from .Bitmap import * #from .Slider import * from .Picture import * from .PictureButton import * diff --git a/bindings/interface/Bitmap.cpp b/bindings/interface/Bitmap.cpp index 8b27717..d64bd36 100644 --- a/bindings/interface/Bitmap.cpp +++ b/bindings/interface/Bitmap.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace py = pybind11; using namespace BPrivate; @@ -23,7 +24,7 @@ m.attr("B_BITMAP_WILL_OVERLAY") = "0x00000040 | B_BITMAP_IS_OFFSCREEN"; m.attr("B_BITMAP_RESERVE_OVERLAY_CHANNEL") = 128; m.attr("B_BITMAP_NO_SERVER_LINK") = 256; -m.attr("BPrivateScreen") = BPrivateScreen; +//m.attr("BPrivateScreen") = BPrivateScreen; py::class_(m, "BBitmap") .def(py::init(), "", py::arg("bounds"), py::arg("flags"), py::arg("colorSpace"), py::arg("bytesPerRow")=B_ANY_BYTES_PER_ROW, py::arg("screenID")=B_MAIN_SCREEN_ID) @@ -46,8 +47,8 @@ py::class_(m, "BBitmap") .def("Bounds", &BBitmap::Bounds, "") .def("SetDrawingFlags", &BBitmap::SetDrawingFlags, "", py::arg("flags")) .def("Flags", &BBitmap::Flags, "") -.def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("data"), py::arg("length"), py::arg("bpr"), py::arg("offset"), py::arg("colorSpace")) -.def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("data"), py::arg("length"), py::arg("bpr"), py::arg("colorSpace"), py::arg("from"), py::arg("to"), py::arg("size")) +.def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("data"), py::arg("length"), py::arg("bpr"), py::arg("offset"), py::arg("colorSpace")) +.def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("data"), py::arg("length"), py::arg("bpr"), py::arg("colorSpace"), py::arg("from"), py::arg("to"), py::arg("size")) .def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("bitmap")) .def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("bitmap"), py::arg("from"), py::arg("to"), py::arg("size")) .def("GetOverlayRestrictions", &BBitmap::GetOverlayRestrictions, "", py::arg("restrictions")) @@ -55,14 +56,14 @@ py::class_(m, "BBitmap") .def("RemoveChild", &BBitmap::RemoveChild, "", py::arg("view")) .def("CountChildren", &BBitmap::CountChildren, "") .def("ChildAt", &BBitmap::ChildAt, "", py::arg("index")) -.def("FindView", py::overload_cast(&BBitmap::FindView), "", py::arg("viewName")) -.def("FindView", py::overload_cast(&BBitmap::FindView), "", py::arg("point")) +.def("FindView", py::overload_cast(&BBitmap::FindView, py::const_), "", py::arg("viewName")) +.def("FindView", py::overload_cast(&BBitmap::FindView, py::const_), "", py::arg("point")) .def("Lock", &BBitmap::Lock, "") .def("Unlock", &BBitmap::Unlock, "") .def("IsLocked", &BBitmap::IsLocked, "") .def("operator=", &BBitmap::operator=, "", py::arg("source")) .def("SetBits", &BBitmap::SetBits, "", py::arg("data"), py::arg("length"), py::arg("offset"), py::arg("colorSpace")) -.def_readwrite("Private", &BBitmap::Private, "") +//.def_readwrite("Private", &BBitmap::Private, "") ; From bd11bff5ff091ae007ff1ebccba4569a899a20d0 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 13:15:32 +0100 Subject: [PATCH 048/155] SetDrawingFlags broken --- bindings/interface/Bitmap.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/interface/Bitmap.cpp b/bindings/interface/Bitmap.cpp index d64bd36..4780dc4 100644 --- a/bindings/interface/Bitmap.cpp +++ b/bindings/interface/Bitmap.cpp @@ -27,9 +27,9 @@ m.attr("B_BITMAP_NO_SERVER_LINK") = 256; //m.attr("BPrivateScreen") = BPrivateScreen; py::class_(m, "BBitmap") -.def(py::init(), "", py::arg("bounds"), py::arg("flags"), py::arg("colorSpace"), py::arg("bytesPerRow")=B_ANY_BYTES_PER_ROW, py::arg("screenID")=B_MAIN_SCREEN_ID) +.def(py::init(), "", py::arg("bounds"), py::arg("flags"), py::arg("colorSpace"), py::arg("bytesPerRow")=B_ANY_BYTES_PER_ROW, py::arg("screenID")=B_MAIN_SCREEN_ID) .def(py::init(), "", py::arg("bounds"), py::arg("colorSpace"), py::arg("acceptsViews")=false, py::arg("needsContiguous")=false) -.def(py::init(), "", py::arg("source"), py::arg("flags")) +.def(py::init(), "", py::arg("source"), py::arg("flags")) .def(py::init(), "", py::arg("source")) .def(py::init(), "", py::arg("source"), py::arg("acceptsViews")=false, py::arg("needsContiguous")=false) .def(py::init(), "", py::arg("data")) @@ -45,7 +45,7 @@ py::class_(m, "BBitmap") .def("BytesPerRow", &BBitmap::BytesPerRow, "") .def("ColorSpace", &BBitmap::ColorSpace, "") .def("Bounds", &BBitmap::Bounds, "") -.def("SetDrawingFlags", &BBitmap::SetDrawingFlags, "", py::arg("flags")) +//.def("SetDrawingFlags", py::overload_cast(&BBitmap::SetDrawingFlags), "", py::arg("flags")) .def("Flags", &BBitmap::Flags, "") .def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("data"), py::arg("length"), py::arg("bpr"), py::arg("offset"), py::arg("colorSpace")) .def("ImportBits", py::overload_cast(&BBitmap::ImportBits), "", py::arg("data"), py::arg("length"), py::arg("bpr"), py::arg("colorSpace"), py::arg("from"), py::arg("to"), py::arg("size")) From 079c5cd11cdb0f5b96f97c0a398c7d2491f775a0 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 12:39:54 +0100 Subject: [PATCH 049/155] fix Drawbitmap funcs for 32-bit --- bindings/interface/View.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 40c868a..dd83aee 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -285,14 +285,14 @@ py::class_>(m, "BView") .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) .def("CopyBits", &BView::CopyBits, "", py::arg("src"), py::arg("dst")) -/* + //from here check if they work as BBitmap is not implemented -.def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) +.def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("viewRect")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("where")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap")) -.def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) +.def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) .def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect")) .def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap"), py::arg("viewRect")) .def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap"), py::arg("where")) @@ -300,7 +300,6 @@ py::class_>(m, "BView") .def("DrawTiledBitmapAsync", &BView::DrawTiledBitmapAsync, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) .def("DrawTiledBitmap", &BView::DrawTiledBitmap, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) //to here -*/ .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar")) .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar"), py::arg("location")) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("delta")=NULL) From d15585c98c867dbb1596cb88a178bab45b8f43bc Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 21:02:30 +0100 Subject: [PATCH 050/155] initial Screen support --- bindings/interface/Screen.cpp | 44 ++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index c3e08f8..52093a8 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -8,13 +8,15 @@ #include #include #include +#include +#include namespace py = pybind11; using namespace BPrivate; PYBIND11_MODULE(Screen,m) { -m.attr("BPrivateScreen") = BPrivateScreen; +//m.attr("BPrivateScreen") = BPrivateScreen; py::class_(m, "BScreen") .def(py::init(), "", py::arg("id")=B_MAIN_SCREEN_ID) @@ -31,14 +33,50 @@ py::class_(m, "BScreen") .def("ColorForIndex", &BScreen::ColorForIndex, "", py::arg("index")) .def("InvertIndex", &BScreen::InvertIndex, "", py::arg("index")) .def("ColorMap", &BScreen::ColorMap, "") -.def("GetBitmap", &BScreen::GetBitmap, "", py::arg("_bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) +//.def("GetBitmap", &BScreen::GetBitmap, "", py::arg("_bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) +.def("GetBitmap", [](BScreen& self) -> py::object { + // Chiamare la funzione originale + BBitmap* buffer; + status_t result = self.GetBitmap(&buffer); + + // Gestire gli errori + if (result != B_OK) { + throw std::runtime_error("Errore durante la chiamata a GetBitmap"); + } + + // Creare un oggetto PyCapsule per incapsulare il puntatore BBitmap + py::capsule capsule(buffer, [](void* p) { delete reinterpret_cast(p); }); + + // Restituire l'oggetto PyCapsule + return py::reinterpret_steal(capsule); + }) .def("ReadBitmap", &BScreen::ReadBitmap, "", py::arg("bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("DesktopColor", py::overload_cast<>(&BScreen::DesktopColor), "") .def("DesktopColor", py::overload_cast(&BScreen::DesktopColor), "", py::arg("workspace")) .def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("stick")=true) .def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("workspace"), py::arg("stick")=true) .def("ProposeMode", &BScreen::ProposeMode, "", py::arg("target"), py::arg("low"), py::arg("high")) -.def("GetModeList", &BScreen::GetModeList, "", py::arg("_modeList"), py::arg("_count")) +//.def("GetModeList", &BScreen::GetModeList, "", py::arg("_modeList"), py::arg("_count")) +.def("GetModeList", [](BScreen& self) -> std::vector { + // Chiamare la funzione originale + uint32 _count; + display_mode* _modeList; + status_t result = self.GetModeList(&_modeList, &_count); + + // Gestire gli errori + if (result != B_OK) { + throw std::runtime_error("Errore durante la chiamata a GetModeList"); + } + + // Convertire il risultato in un vettore di display_mode + std::vector resultVector(_modeList, _modeList + _count); + + // Liberare la memoria allocata da GetModeList + free(_modeList); + + return resultVector; + } +) .def("GetMode", py::overload_cast(&BScreen::GetMode), "", py::arg("mode")) .def("GetMode", py::overload_cast(&BScreen::GetMode), "", py::arg("workspace"), py::arg("mode")) .def("SetMode", py::overload_cast(&BScreen::SetMode), "", py::arg("mode"), py::arg("makeDefault")=false) From 15c474d5a4773b2ba225b7759e209603071ced0b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 21:19:00 +0100 Subject: [PATCH 051/155] node cleanups --- bindings/storage/Node.cpp | 62 --------------------------------------- 1 file changed, 62 deletions(-) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 07f882d..0733e29 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -48,8 +48,6 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed .def("Unlock", &BNode::Unlock, "") .def("Sync", &BNode::Sync, "") .def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) -//PyBytes_FromObject -//.def("ReadAttr", py::overload_cast(&ReadAttrWrapper), "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) .def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->py::object{ void* tmp = malloc(length); @@ -121,66 +119,6 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed return ret; //return py::reinterpret_steal(ret); }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) -/* -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->py::object{ - void* tmp = malloc(length); - self.ReadAttr(name, type, offset, tmp, length); - PyObject* ret; - long intVal; - char* strPtr = strdup(""); - bool boolPtr; - switch (type){ - case B_INT32_TYPE: - ret = PyLong_FromVoidPtr(tmp); - if (ret == nullptr) { - free(tmp); - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } - // Converte l'oggetto PyObject* in un puntatore a int* - int32* intPtr; - intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); - intVal = py::int_(*intPtr); - free(intPtr); - //intVal = PyLong_AsLong(ret); - Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* (non più necessario) - // Restituisci il puntatore a intPtr invece dell'oggetto PyObject* - break; - case B_STRING_TYPE: - ret = PyUnicode_FromString(static_cast(tmp)); - free(tmp); // Libera la memoria allocata con malloc - if (ret == nullptr) { - throw std::runtime_error("Errore durante la chiamata a ReadAttr"); - } - // Converte l'oggetto PyObject* in un puntatore a char* - strPtr = strdup(PyUnicode_AsUTF8(ret)); - if (strPtr == nullptr) { - Py_DECREF(ret); - throw std::runtime_error("Errore durante la conversione dell'oggetto PyUnicode a char*"); - } - Py_DECREF(ret); // Decrementa il riferimento all'oggetto PyObject* - break; - case B_BOOL_TYPE: - ret = PyLong_FromVoidPtr(tmp); - int32* intPtr; - intPtr = reinterpret_cast(PyLong_AsVoidPtr(ret)); - boolPtr = PyBool_FromLong(*intPtr); - - default: - //ret = PyLong_FromSsize_t(result);//*reinterpret_cast(result)); - //intPtr = 0; - free(tmp); - break; - } - if (type == B_STRING_TYPE){ - return py::str(strPtr); - } else if (type == B_INT32_TYPE){ - return py::int_(intVal); - } else if (type == B_BOOL_TYPE){ - return py::bool_(boolPtr); - } - return py::none(); - -}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length"))*/ .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) //.def("RenameAttr", py::overload_cast(&BNode::RenameAttr), "", py::arg("oldName"), py::arg("newName")) From 23cf4135d8257bc4985cc8742c77f5dce21cd63f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 21:37:47 +0100 Subject: [PATCH 052/155] Fix&Add Screen --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/interface/Screen.cpp | 8 ++++---- tmtest.py | 31 +++++++++++++++++++++++++------ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Jamfile b/Jamfile index f471aa0..74b6dd1 100644 --- a/Jamfile +++ b/Jamfile @@ -148,6 +148,7 @@ local sourceFiles = TabView.cpp ScrollBar.cpp GraphicsDefs.cpp + Screen.cpp #SupportKit SupportDefs.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 9dec670..537bfb0 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -19,6 +19,7 @@ from .Window import * from .Rect import * from .GraphicsDefs import * +from .Screen import * from .Point import * from .View import * from .Control import * diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index 52093a8..517ced3 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -52,9 +52,9 @@ py::class_(m, "BScreen") }) .def("ReadBitmap", &BScreen::ReadBitmap, "", py::arg("bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("DesktopColor", py::overload_cast<>(&BScreen::DesktopColor), "") -.def("DesktopColor", py::overload_cast(&BScreen::DesktopColor), "", py::arg("workspace")) +.def("DesktopColor", py::overload_cast(&BScreen::DesktopColor), "", py::arg("workspace")) .def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("stick")=true) -.def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("workspace"), py::arg("stick")=true) +.def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("workspace"), py::arg("stick")=true) .def("ProposeMode", &BScreen::ProposeMode, "", py::arg("target"), py::arg("low"), py::arg("high")) //.def("GetModeList", &BScreen::GetModeList, "", py::arg("_modeList"), py::arg("_count")) .def("GetModeList", [](BScreen& self) -> std::vector { @@ -78,9 +78,9 @@ py::class_(m, "BScreen") } ) .def("GetMode", py::overload_cast(&BScreen::GetMode), "", py::arg("mode")) -.def("GetMode", py::overload_cast(&BScreen::GetMode), "", py::arg("workspace"), py::arg("mode")) +.def("GetMode", py::overload_cast(&BScreen::GetMode), "", py::arg("workspace"), py::arg("mode")) .def("SetMode", py::overload_cast(&BScreen::SetMode), "", py::arg("mode"), py::arg("makeDefault")=false) -.def("SetMode", py::overload_cast(&BScreen::SetMode), "", py::arg("workspace"), py::arg("mode"), py::arg("makeDefault")=false) +.def("SetMode", py::overload_cast(&BScreen::SetMode), "", py::arg("workspace"), py::arg("mode"), py::arg("makeDefault")=false) .def("GetDeviceInfo", &BScreen::GetDeviceInfo, "", py::arg("info")) .def("GetMonitorInfo", &BScreen::GetMonitorInfo, "", py::arg("info")) .def("GetPixelClockLimits", &BScreen::GetPixelClockLimits, "", py::arg("mode"), py::arg("_low"), py::arg("_high")) diff --git a/tmtest.py b/tmtest.py index e4ce5f5..193e665 100644 --- a/tmtest.py +++ b/tmtest.py @@ -1,5 +1,5 @@ from Be import BApplication, BWindow, BListItem, BTabView, BTab, BFont, BPicture, BStringItem, BAlert, BPoint, BBox, BListView, BScrollView, BRadioButton, BColorControl, BCheckBox, BRect, BTextControl, BView,BMenu,BStatusBar, BMenuBar, BMenuItem,BSeparatorItem,BStringView,BMessage,window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE -from Be import BPictureButton, BTextView +from Be import BPictureButton, BTextView, BButton from Be.PictureButton import picture_button_behavior from Be.GraphicsDefs import * from Be.ListView import list_view_type @@ -13,6 +13,21 @@ from Be.Entry import entry_ref from Be.Entry import get_ref_for_path +class PBut(BButton): + def __init__(self,frame,name,caption,msg,immagine,immaginedown): + self.immagine=immagine + self.imgdown=immaginedown + self.frame=frame + BButton.__init__(self, frame, name, caption, msg) + + def Draw(self,rect): + BButton.Draw(self, rect) + inset = (4, 4, self.frame.Width()-4, self.frame.Heigth()-4) + if self.Value(): + self.DrawBitmap(self.immagine, inset) + else: + self.DrawBitmap(self.imgdown, inset) + class StrangeItem(BStringItem): nocolor = (0, 0, 0, 0) gcolor = (0, 200, 0, 0) @@ -106,10 +121,15 @@ def __init__(self): self.startimer= BCheckBox(BRect(10,30,290,50),'Testbox','Test Checkbox',BMessage(612)) self.point=BPoint() self.cc= BColorControl(BPoint(8, 128), color_control_layout.B_CELLS_32x8, 8.0,'colors', BMessage(self.CLRCTL), 0) - self.sixradio = BRadioButton(BRect(8,220,24,236),'hotradio', 'hot', BMessage(6)) - self.sevenradio = BRadioButton(BRect(8,236,24,252),'tepidradio', 'tepid', BMessage(7)) - self.nineradio = BRadioButton(BRect(8,252,24,268),'coolradio', 'cool', BMessage(9)) - + self.sixradio = BRadioButton(BRect(8,220,28,240),'hotradio', 'hot', BMessage(6)) + self.sevenradio = BRadioButton(BRect(8,240,28,260),'tepidradio', 'tepid', BMessage(7)) + self.nineradio = BRadioButton(BRect(8,260,28,280),'coolradio', 'cool', BMessage(9)) + + #link=sys.path[0]+"/help/minusmine.bmp" + #img=BTranslationUtils.GetBitmap(link) + #link2=sys.path[0]+"/help/minusmined.bmp" + #img2=BTranslationUtils.GetBitmap(link2) + #self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(AppDefs.B_QUIT_REQUESTED),img2,img) # Handling colors################## #colore=self.list.lv.HighColor() @@ -129,7 +149,6 @@ def __init__(self): self.list = ScrollView(BRect(8 , 300, bounds.Width() - 18 , bounds.Height() - 42 ), 'ScrollView') - #self.list.sv.Hide() global newsitem # TODO: newsitem (defined below) seems to be freed by Python as soon # as Python is finished with the __init__ function. But we still From f269239c93a162a13e9f9261f9a91611e1a6b587 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 22:11:12 +0100 Subject: [PATCH 053/155] adjust GetBitmap --- bindings/interface/Screen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index 517ced3..d9a570f 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -34,10 +34,10 @@ py::class_(m, "BScreen") .def("InvertIndex", &BScreen::InvertIndex, "", py::arg("index")) .def("ColorMap", &BScreen::ColorMap, "") //.def("GetBitmap", &BScreen::GetBitmap, "", py::arg("_bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) -.def("GetBitmap", [](BScreen& self) -> py::object { +.def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> py::object { // Chiamare la funzione originale BBitmap* buffer; - status_t result = self.GetBitmap(&buffer); + status_t result = self.GetBitmap(&buffer,drawCursor,frame); // Gestire gli errori if (result != B_OK) { @@ -49,7 +49,7 @@ py::class_(m, "BScreen") // Restituire l'oggetto PyCapsule return py::reinterpret_steal(capsule); - }) + }, py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("ReadBitmap", &BScreen::ReadBitmap, "", py::arg("bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("DesktopColor", py::overload_cast<>(&BScreen::DesktopColor), "") .def("DesktopColor", py::overload_cast(&BScreen::DesktopColor), "", py::arg("workspace")) From 5460a690da07ef5a15091d75368de84b7c937cd8 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 30 Nov 2023 22:54:38 +0100 Subject: [PATCH 054/155] Return BBitmap on GetBitmap --- bindings/interface/Screen.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index d9a570f..aa32d25 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -34,7 +34,7 @@ py::class_(m, "BScreen") .def("InvertIndex", &BScreen::InvertIndex, "", py::arg("index")) .def("ColorMap", &BScreen::ColorMap, "") //.def("GetBitmap", &BScreen::GetBitmap, "", py::arg("_bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) -.def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> py::object { +.def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> BBitmap* { // Chiamare la funzione originale BBitmap* buffer; status_t result = self.GetBitmap(&buffer,drawCursor,frame); @@ -45,10 +45,11 @@ py::class_(m, "BScreen") } // Creare un oggetto PyCapsule per incapsulare il puntatore BBitmap - py::capsule capsule(buffer, [](void* p) { delete reinterpret_cast(p); }); + //py::capsule capsule(buffer, [](void* p) { delete reinterpret_cast(p); }); // Restituire l'oggetto PyCapsule - return py::reinterpret_steal(capsule); + //return py::reinterpret_steal(capsule); + return buffer; }, py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("ReadBitmap", &BScreen::ReadBitmap, "", py::arg("bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("DesktopColor", py::overload_cast<>(&BScreen::DesktopColor), "") From f85447648a29671af9a1ead70a5b30fddf5fdcf7 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 1 Dec 2023 11:41:39 +0100 Subject: [PATCH 055/155] Fix Bitmap.Bits, to refine workaround Screen.GetBitmap --- bindings/interface/Bitmap.cpp | 15 ++++++++++++++- bindings/interface/Screen.cpp | 4 +++- tmtest.py | 29 +++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/bindings/interface/Bitmap.cpp b/bindings/interface/Bitmap.cpp index 4780dc4..d5105cb 100644 --- a/bindings/interface/Bitmap.cpp +++ b/bindings/interface/Bitmap.cpp @@ -40,7 +40,20 @@ py::class_(m, "BBitmap") .def("LockBits", &BBitmap::LockBits, "", py::arg("state")=NULL) .def("UnlockBits", &BBitmap::UnlockBits, "") .def("Area", &BBitmap::Area, "") -.def("Bits", &BBitmap::Bits, "") +//.def("Bits", &BBitmap::Bits, "") +//.def("Bits", py::overload_cast<>(&BBitmap::Bits, py::const_),"") + +.def("Bits", [](BBitmap& self)->py::bytes{ + size_t dataSize = self.BitsLength(); + const uint8_t* data = static_cast(self.Bits()); + //int32* lung = self.BitsLength(); + //void* tmp = malloc(lung); + //if (tmp == nullptr){ + // throw std::runtime_error("Error allocating memory"); + //} + return py::bytes(reinterpret_cast(data), dataSize); + } +) .def("BitsLength", &BBitmap::BitsLength, "") .def("BytesPerRow", &BBitmap::BytesPerRow, "") .def("ColorSpace", &BBitmap::ColorSpace, "") diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index aa32d25..9f50c79 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -36,7 +36,8 @@ py::class_(m, "BScreen") //.def("GetBitmap", &BScreen::GetBitmap, "", py::arg("_bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> BBitmap* { // Chiamare la funzione originale - BBitmap* buffer; + //BBitmap* buffer; + BBitmap* buffer = new BBitmap(*frame,B_RGBA32); status_t result = self.GetBitmap(&buffer,drawCursor,frame); // Gestire gli errori @@ -50,6 +51,7 @@ py::class_(m, "BScreen") // Restituire l'oggetto PyCapsule //return py::reinterpret_steal(capsule); return buffer; + //return py::capsule(buffer,""BBitmap", &deleteBBitmap); }, py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("ReadBitmap", &BScreen::ReadBitmap, "", py::arg("bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("DesktopColor", py::overload_cast<>(&BScreen::DesktopColor), "") diff --git a/tmtest.py b/tmtest.py index 193e665..5b7b8f4 100644 --- a/tmtest.py +++ b/tmtest.py @@ -1,5 +1,5 @@ from Be import BApplication, BWindow, BListItem, BTabView, BTab, BFont, BPicture, BStringItem, BAlert, BPoint, BBox, BListView, BScrollView, BRadioButton, BColorControl, BCheckBox, BRect, BTextControl, BView,BMenu,BStatusBar, BMenuBar, BMenuItem,BSeparatorItem,BStringView,BMessage,window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE -from Be import BPictureButton, BTextView, BButton +from Be import BPictureButton, BTextView, BButton, BScreen, BBitmap from Be.PictureButton import picture_button_behavior from Be.GraphicsDefs import * from Be.ListView import list_view_type @@ -21,12 +21,14 @@ def __init__(self,frame,name,caption,msg,immagine,immaginedown): BButton.__init__(self, frame, name, caption, msg) def Draw(self,rect): - BButton.Draw(self, rect) - inset = (4, 4, self.frame.Width()-4, self.frame.Heigth()-4) + inset = BRect(4, 4, self.frame.Width()-4, self.frame.Heigth()-4) if self.Value(): + print("disegno su") self.DrawBitmap(self.immagine, inset) else: + print("disegno GIù") self.DrawBitmap(self.imgdown, inset) + BButton.Draw(self, rect) class StrangeItem(BStringItem): nocolor = (0, 0, 0, 0) @@ -104,6 +106,7 @@ def __init__(self): print(bounds.LeftTop()) self.panel = BView(self.Bounds(), "panel", 8, 20000000) self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) + self.panel3 = BView(self.Bounds(), "panel3", 8, 20000000) self.box = BBox(BRect(200,26,280,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.box2 = BBox(BRect(10,10,self.panel2.Bounds().Width()-20,40),"MYBox2",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.panel2.AddChild(self.box2,None) @@ -124,13 +127,17 @@ def __init__(self): self.sixradio = BRadioButton(BRect(8,220,28,240),'hotradio', 'hot', BMessage(6)) self.sevenradio = BRadioButton(BRect(8,240,28,260),'tepidradio', 'tepid', BMessage(7)) self.nineradio = BRadioButton(BRect(8,260,28,280),'coolradio', 'cool', BMessage(9)) - + scrn = BScreen(self) + img1 = scrn.GetBitmap(True,BRect(0,0,200,200)) + print(img1) + print(img1.BitsLength()) + print(img1.Bits()) #link=sys.path[0]+"/help/minusmine.bmp" #img=BTranslationUtils.GetBitmap(link) #link2=sys.path[0]+"/help/minusmined.bmp" #img2=BTranslationUtils.GetBitmap(link2) - #self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(AppDefs.B_QUIT_REQUESTED),img2,img) - + self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(2),img1,img1)#img2,img)AppDefs.B_QUIT_REQUESTED + # Handling colors################## #colore=self.list.lv.HighColor() #print("colore è:",colore.red,colore.green,colore.blue,colore.alpha) @@ -176,6 +183,7 @@ def __init__(self): self.panel.AddChild(self.sixradio,None) self.panel.AddChild(self.sevenradio,None) self.panel.AddChild(self.nineradio,None) + self.panel.AddChild(self.fadBtn,None) self.panel.AddChild(butupdown,None) self.panel.AddChild(self.cc,None) self.panel.AddChild(self.startimer,None) @@ -194,22 +202,27 @@ def __init__(self): self.tabsviews=[] self.tabsviews.append(self.panel) self.tabsviews.append(self.panel2) - + self.tabsviews.append(self.panel3) tabrect=BRect(3.0, 3.0, 30.0, self.maintabview.TabHeight()-3.0) scheda=BTab(None) #scheda.SetLabel("Principale") <--- works after maintabview.AddTab scheda2=BTab(None) + scheda3=BTab(None) self.tabslabels.append(scheda) self.tabslabels.append(scheda2) + self.tabslabels.append(scheda3) self.maintabview.AddTab(self.tabsviews[0],self.tabslabels[0]) self.maintabview.AddTab(self.tabsviews[1],self.tabslabels[1]) + self.maintabview.AddTab(self.tabsviews[2],self.tabslabels[2]) self.bckgnd.AddChild(self.maintabview,None) scheda.SetLabel("Principale") scheda2.SetLabel("Scrittura") - + scheda3.SetLabel("Draw Bitmap") + + self.panel3.DrawBitmap(img1) from Be.Font import be_plain_font from Be.Font import be_bold_font #from Be.View import set_font_mask From 8acca61e768a1ed32ea283ff2965eef8b68f9f06 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 1 Dec 2023 14:37:32 +0100 Subject: [PATCH 056/155] test BView.DrawBitmap --- tmtest.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tmtest.py b/tmtest.py index 5b7b8f4..e3fc24a 100644 --- a/tmtest.py +++ b/tmtest.py @@ -13,6 +13,22 @@ from Be.Entry import entry_ref from Be.Entry import get_ref_for_path +class PView(BView): + def __init__(self,frame,name,immagine): + self.immagine=immagine + self.frame=frame + BView.__init__(self,self.frame,name,8, 20000000) + + def UpdateImg(self,immagine): + self.immagine=immagine + rect=BRect(0,0,self.frame.Width(),self.frame.Height()) + self.DrawBitmap(self.immagine,rect) + + def Draw(self,rect): + BView.Draw(self,rect) + rect=BRect(0,0,self.frame.Width(),self.frame.Height()) + self.DrawBitmap(self.immagine,rect) + class PBut(BButton): def __init__(self,frame,name,caption,msg,immagine,immaginedown): self.immagine=immagine @@ -106,7 +122,6 @@ def __init__(self): print(bounds.LeftTop()) self.panel = BView(self.Bounds(), "panel", 8, 20000000) self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) - self.panel3 = BView(self.Bounds(), "panel3", 8, 20000000) self.box = BBox(BRect(200,26,280,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.box2 = BBox(BRect(10,10,self.panel2.Bounds().Width()-20,40),"MYBox2",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.panel2.AddChild(self.box2,None) @@ -129,6 +144,8 @@ def __init__(self): self.nineradio = BRadioButton(BRect(8,260,28,280),'coolradio', 'cool', BMessage(9)) scrn = BScreen(self) img1 = scrn.GetBitmap(True,BRect(0,0,200,200)) + self.panel3 = PView(self.Bounds(), "panel3",img1) + print(img1) print(img1.BitsLength()) print(img1.Bits()) @@ -222,7 +239,9 @@ def __init__(self): scheda2.SetLabel("Scrittura") scheda3.SetLabel("Draw Bitmap") - self.panel3.DrawBitmap(img1) + #self.panel3.DrawBitmap(img1) + self.panel3.UpdateImg(img1) + from Be.Font import be_plain_font from Be.Font import be_bold_font #from Be.View import set_font_mask From af59d3207663677e21dfa66998ac8862dbcf63c6 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 1 Dec 2023 20:28:01 +0100 Subject: [PATCH 057/155] can override BButton.Draw, update Screen.cpp --- bindings/interface/Button.cpp | 10 +++++++++- bindings/interface/Screen.cpp | 4 ++-- tmtest.py | 15 ++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bindings/interface/Button.cpp b/bindings/interface/Button.cpp index d29cdc4..a51cd15 100644 --- a/bindings/interface/Button.cpp +++ b/bindings/interface/Button.cpp @@ -9,10 +9,18 @@ namespace py = pybind11; +class PyBButton : public BButton{ + public: + using BButton::BButton; + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BButton, Draw, updateRect); + } +}; + PYBIND11_MODULE(Button,m) { -py::class_>(m, "BButton") +py::class_>(m, "BButton") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE) .def(py::init(), "", py::arg("label"), py::arg("message")=NULL) diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index 9f50c79..ad1a901 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -60,9 +60,9 @@ py::class_(m, "BScreen") .def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("workspace"), py::arg("stick")=true) .def("ProposeMode", &BScreen::ProposeMode, "", py::arg("target"), py::arg("low"), py::arg("high")) //.def("GetModeList", &BScreen::GetModeList, "", py::arg("_modeList"), py::arg("_count")) -.def("GetModeList", [](BScreen& self) -> std::vector { +.def("GetModeList", [](BScreen& self, uint32 _count) -> std::vector { // Chiamare la funzione originale - uint32 _count; + // uint32 _count; <- removed as passed by argument display_mode* _modeList; status_t result = self.GetModeList(&_modeList, &_count); diff --git a/tmtest.py b/tmtest.py index e3fc24a..9820492 100644 --- a/tmtest.py +++ b/tmtest.py @@ -37,7 +37,7 @@ def __init__(self,frame,name,caption,msg,immagine,immaginedown): BButton.__init__(self, frame, name, caption, msg) def Draw(self,rect): - inset = BRect(4, 4, self.frame.Width()-4, self.frame.Heigth()-4) + inset = BRect(4, 4, self.frame.Width()-4, self.frame.Height()-4) if self.Value(): print("disegno su") self.DrawBitmap(self.immagine, inset) @@ -63,19 +63,14 @@ class NewsItem(BListItem): def __init__(self, name,color): self.name = name - print("inizializzato con color:"+str(color)) self.color=color BListItem.__init__(self) def DrawItem(self, owner, frame, complete): if self.IsSelected() or complete: color = (200,200,200,255) - #print("HighColor era:",str(owner.HighColor().red),str(owner.HighColor().green),str(owner.HighColor().blue),str(owner.HighColor().alpha)) - #print("LowColor era:",str(owner.LowColor().red),str(owner.LowColor().green),str(owner.LowColor().blue),str(owner.LowColor().alpha)) owner.SetHighColor(180,0,0,255) owner.SetLowColor(200,200,200,255) - #print("HighColor ora è:",str(owner.HighColor().red),str(owner.HighColor().green),str(owner.HighColor().blue),str(owner.HighColor().alpha)) - #print("LowColor ora è:",str(owner.LowColor().red),str(owner.LowColor().green),str(owner.LowColor().blue),str(owner.LowColor().alpha)) owner.FillRect(frame) owner.SetHighColor(0,0,0,255) owner.SetLowColor(255,255,255,255) @@ -119,7 +114,6 @@ def __init__(self): bounds=self.Bounds() self.bckgnd = BView(self.Bounds(), "background", 8, 20000000) self.maintabview = BTabView(BRect(2.0, 2.0, bounds.Width()-2.0, bounds.Height()-2.0), 'tabview') - print(bounds.LeftTop()) self.panel = BView(self.Bounds(), "panel", 8, 20000000) self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) self.box = BBox(BRect(200,26,280,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) @@ -146,9 +140,12 @@ def __init__(self): img1 = scrn.GetBitmap(True,BRect(0,0,200,200)) self.panel3 = PView(self.Bounds(), "panel3",img1) - print(img1) - print(img1.BitsLength()) print(img1.Bits()) + print(img1.Flags()) + print(img1.BitsLength()) + img2=BBitmap(img1.Bounds(),color_space.B_RGBA32) + img2.ImportBits(img1) + #link=sys.path[0]+"/help/minusmine.bmp" #img=BTranslationUtils.GetBitmap(link) #link2=sys.path[0]+"/help/minusmined.bmp" From 590e9ecab2033c5c01faf74c9baa2f6d7af0e92b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 1 Dec 2023 12:37:53 +0100 Subject: [PATCH 058/155] Fix PBut class --- tmtest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tmtest.py b/tmtest.py index 9820492..5db56f1 100644 --- a/tmtest.py +++ b/tmtest.py @@ -37,6 +37,7 @@ def __init__(self,frame,name,caption,msg,immagine,immaginedown): BButton.__init__(self, frame, name, caption, msg) def Draw(self,rect): + BButton.Draw(self, rect) inset = BRect(4, 4, self.frame.Width()-4, self.frame.Height()-4) if self.Value(): print("disegno su") @@ -44,7 +45,7 @@ def Draw(self,rect): else: print("disegno GIù") self.DrawBitmap(self.imgdown, inset) - BButton.Draw(self, rect) + class StrangeItem(BStringItem): nocolor = (0, 0, 0, 0) From 5c7d7698607eabc4a3b68e66bf25402121e32764 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 1 Dec 2023 13:45:22 +0100 Subject: [PATCH 059/155] Override Draw --- bindings/interface/Box.cpp | 10 +++++++++- bindings/interface/View.cpp | 11 ++++++++++- tmtest.py | 34 ++++++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/bindings/interface/Box.cpp b/bindings/interface/Box.cpp index ff2871e..44bd2b6 100644 --- a/bindings/interface/Box.cpp +++ b/bindings/interface/Box.cpp @@ -8,10 +8,18 @@ namespace py = pybind11; +class PyBBox : public BBox{ + public: + using BBox::BBox; + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BBox, Draw, updateRect); + } +}; + PYBIND11_MODULE(Box,m) { -py::class_>(m, "BBox") +py::class_>(m, "BBox") .def(py::init(), "", py::arg("frame"), py::arg("name")=NULL, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, py::arg("border")=B_FANCY_BORDER) .def(py::init(), "", py::arg("name"), py::arg("flags")=B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, py::arg("border")=B_FANCY_BORDER, py::arg("child")=NULL) .def(py::init(), "", py::arg("border"), py::arg("child")) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index dd83aee..eb68676 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -28,6 +28,15 @@ namespace py = pybind11; using namespace BPrivate; +class PyBView : public BView{ + public: + using BView::BView; + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BView, Draw, updateRect); + } +}; + + PYBIND11_MODULE(View,m) { m.attr("B_PRIMARY_MOUSE_BUTTON") = "B_MOUSE_BUTTON ( 1 )"; @@ -111,7 +120,7 @@ m.attr("_VIEW_CENTER_") = _VIEW_CENTER_; //m.attr("ViewState") = ViewState; -py::class_>(m, "BView") +py::class_>(m, "BView") .def(py::init(), "", py::arg("name"), py::arg("flags"), py::arg("layout")=NULL) .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("resizingMode"), py::arg("flags")) .def(py::init(), "", py::arg("archive")) diff --git a/tmtest.py b/tmtest.py index 5db56f1..7ecbe6b 100644 --- a/tmtest.py +++ b/tmtest.py @@ -13,6 +13,18 @@ from Be.Entry import entry_ref from Be.Entry import get_ref_for_path + +class PBox(BBox): + def __init__(self,frame,name,immagine): + self.immagine = immagine + self.frame = frame + BBox.__init__(self,frame,name,0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) + + def Draw(self,rect): + BBox.Draw(self, rect) + inset = BRect(4, 4, self.frame.Width()-4, self.frame.Height()-4) + self.DrawBitmap(self.immagine, inset) + class PView(BView): def __init__(self,frame,name,immagine): self.immagine=immagine @@ -20,12 +32,14 @@ def __init__(self,frame,name,immagine): BView.__init__(self,self.frame,name,8, 20000000) def UpdateImg(self,immagine): + self.Draw(self.frame) self.immagine=immagine rect=BRect(0,0,self.frame.Width(),self.frame.Height()) self.DrawBitmap(self.immagine,rect) def Draw(self,rect): BView.Draw(self,rect) + print("Disegno PView") rect=BRect(0,0,self.frame.Width(),self.frame.Height()) self.DrawBitmap(self.immagine,rect) @@ -117,6 +131,7 @@ def __init__(self): self.maintabview = BTabView(BRect(2.0, 2.0, bounds.Width()-2.0, bounds.Height()-2.0), 'tabview') self.panel = BView(self.Bounds(), "panel", 8, 20000000) self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) + self.panel3 = BView(self.Bounds(), "panel2", 8, 20000000) self.box = BBox(BRect(200,26,280,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.box2 = BBox(BRect(10,10,self.panel2.Bounds().Width()-20,40),"MYBox2",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.panel2.AddChild(self.box2,None) @@ -139,20 +154,21 @@ def __init__(self): self.nineradio = BRadioButton(BRect(8,260,28,280),'coolradio', 'cool', BMessage(9)) scrn = BScreen(self) img1 = scrn.GetBitmap(True,BRect(0,0,200,200)) - self.panel3 = PView(self.Bounds(), "panel3",img1) + print(img1.Bits()) print(img1.Flags()) print(img1.BitsLength()) - img2=BBitmap(img1.Bounds(),color_space.B_RGBA32) - img2.ImportBits(img1) - + img2=BBitmap(self.panel2.Bounds(),color_space.B_RGBA32) + #img2.ImportBits(img1) + img2 = scrn.GetBitmap(True,self.panel3.Bounds()) + #self.panel3 = PView(self.Bounds(), "panel3",img2) #link=sys.path[0]+"/help/minusmine.bmp" #img=BTranslationUtils.GetBitmap(link) #link2=sys.path[0]+"/help/minusmined.bmp" #img2=BTranslationUtils.GetBitmap(link2) - self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(2),img1,img1)#img2,img)AppDefs.B_QUIT_REQUESTED - + self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(2),img1,img2)#img2,img)AppDefs.B_QUIT_REQUESTED + self.PicBox = PBox(self.panel3.Bounds(),"PictureBox",img2) # Handling colors################## #colore=self.list.lv.HighColor() #print("colore è:",colore.red,colore.green,colore.blue,colore.alpha) @@ -238,7 +254,8 @@ def __init__(self): scheda3.SetLabel("Draw Bitmap") #self.panel3.DrawBitmap(img1) - self.panel3.UpdateImg(img1) + #self.panel3.UpdateImg(img1) + #self.panel3.Draw(self.panel3.Bounds()) from Be.Font import be_plain_font from Be.Font import be_bold_font @@ -247,7 +264,8 @@ def __init__(self): self.typtap.SetStylable(1) self.panel2.AddChild(self.typtap,None) colore=self.panel.HighColor() - print(colore.red,colore.green,colore.blue,colore.alpha) + #print(colore.red,colore.green,colore.blue,colore.alpha) + self.panel3.AddChild(self.PicBox,None) colore.red=180 self.typtap.SetFontAndColor(be_plain_font,511,colore)#B_FONT_ALL = 511 stuff = '\n\t\t\t\t\t\t\tHello Haiku!\n\n\t\t\t\t\t\t\t\t\t\t\tA simple test program\n\t\t\t\t\t\t\t\t\t\t\tfor Haiku, version 1.0\n\t\t\t\t\t\t\t\t\t\t\tsample code included!\n\n\t\t\t\t\t\t\t\t\t\t\tby Fabio Tomat aka TmTFx\n\t\t\t\t\t\t\t\t\t\t\tand others\n\t\t\t\t\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\t\t\t\t\tspecial thanks to:\n\t\t\t\t\t\t\t\t\t\t\tZardshard and coolcoder613' From 7eac54895b3aeb55a7f60bdc5dac9df51b6ace95 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 1 Dec 2023 23:09:18 +0100 Subject: [PATCH 060/155] Return pair not only one value --- bindings/interface/Screen.cpp | 38 +++++++++++--- bindings/storage/Node.cpp | 94 ++++++++++++++++++++++++++++++----- fstest.py | 5 +- tmtest.py | 6 ++- 4 files changed, 121 insertions(+), 22 deletions(-) diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index ad1a901..839f737 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -34,6 +34,15 @@ py::class_(m, "BScreen") .def("InvertIndex", &BScreen::InvertIndex, "", py::arg("index")) .def("ColorMap", &BScreen::ColorMap, "") //.def("GetBitmap", &BScreen::GetBitmap, "", py::arg("_bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) +.def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> std::pair { + BBitmap* buffer = new BBitmap(*frame,B_RGBA32); + status_t result = self.GetBitmap(&buffer,drawCursor,frame); + //if (result != B_OK) { + // throw std::runtime_error("Errore durante la chiamata a GetBitmap"); + //} + return std::make_pair(buffer,result); + }, py::arg("drawCursor")=true, py::arg("frame")=NULL) +/* .def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> BBitmap* { // Chiamare la funzione originale //BBitmap* buffer; @@ -44,15 +53,10 @@ py::class_(m, "BScreen") if (result != B_OK) { throw std::runtime_error("Errore durante la chiamata a GetBitmap"); } - - // Creare un oggetto PyCapsule per incapsulare il puntatore BBitmap - //py::capsule capsule(buffer, [](void* p) { delete reinterpret_cast(p); }); - - // Restituire l'oggetto PyCapsule - //return py::reinterpret_steal(capsule); return buffer; //return py::capsule(buffer,""BBitmap", &deleteBBitmap); }, py::arg("drawCursor")=true, py::arg("frame")=NULL) +*/ .def("ReadBitmap", &BScreen::ReadBitmap, "", py::arg("bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) .def("DesktopColor", py::overload_cast<>(&BScreen::DesktopColor), "") .def("DesktopColor", py::overload_cast(&BScreen::DesktopColor), "", py::arg("workspace")) @@ -60,6 +64,27 @@ py::class_(m, "BScreen") .def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("workspace"), py::arg("stick")=true) .def("ProposeMode", &BScreen::ProposeMode, "", py::arg("target"), py::arg("low"), py::arg("high")) //.def("GetModeList", &BScreen::GetModeList, "", py::arg("_modeList"), py::arg("_count")) +.def("GetModeList", [](BScreen& self, uint32 _count) -> std::pair, status_t>{ + // Chiamare la funzione originale + // uint32 _count; <- removed as passed by argument + display_mode* _modeList; + status_t result = self.GetModeList(&_modeList, &_count); + + // Gestire gli errori + //if (result != B_OK) { + // throw std::runtime_error("Errore durante la chiamata a GetModeList"); + //} + + // Convertire il risultato in un vettore di display_mode + std::vector resultVector(_modeList, _modeList + _count); + + // Liberare la memoria allocata da GetModeList + free(_modeList); + + return std::make_pair(resultVector,result); + } +) +/* .def("GetModeList", [](BScreen& self, uint32 _count) -> std::vector { // Chiamare la funzione originale // uint32 _count; <- removed as passed by argument @@ -80,6 +105,7 @@ py::class_(m, "BScreen") return resultVector; } ) +*/ .def("GetMode", py::overload_cast(&BScreen::GetMode), "", py::arg("mode")) .def("GetMode", py::overload_cast(&BScreen::GetMode), "", py::arg("workspace"), py::arg("mode")) .def("SetMode", py::overload_cast(&BScreen::SetMode), "", py::arg("mode"), py::arg("makeDefault")=false) diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index 0733e29..ba72a33 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -49,6 +49,7 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed .def("Sync", &BNode::Sync, "") .def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) //.def("ReadAttr", &BNode::ReadAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) +/* .def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->py::object{ void* tmp = malloc(length); if (tmp == nullptr){ @@ -75,13 +76,6 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed //ret = PyUnicode_FromString(static_cast(tmp)); break; case B_BOOL_TYPE: - /*int32* inttmpPtr = reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp))); - if (inttmpPtr == nullptr) { - free(tmp); - throw std::runtime_error("Error converting PyLong object to int32*"); - } - ret = py::bool_(*inttmpPtr != 0); - break;*/ ret = py::bool_(PyBool_FromLong(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp))))); break; case B_FLOAT_TYPE: @@ -99,11 +93,11 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed auto seconds_since_epoch = std::chrono::duration_cast(timePoint.time_since_epoch()).count(); ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(seconds_since_epoch); break; - /* - bigtime_t timeValue=*reinterpret_cast(tmp); - std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::from_time_t(timeValue / 1000000); - ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(std::chrono::system_clock::to_time_t(timePoint)); - break;*/ + + //bigtime_t timeValue=*reinterpret_cast(tmp); + //std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::from_time_t(timeValue / 1000000); + //ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(std::chrono::system_clock::to_time_t(timePoint)); + //break; } case B_RAW_TYPE:{ ret = py::bytes(reinterpret_cast(tmp), length); @@ -119,7 +113,70 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed return ret; //return py::reinterpret_steal(ret); }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) - +*/ +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->std::pair{ + void* tmp = malloc(length); + if (tmp == nullptr){ + throw std::runtime_error("Error allocating memory"); + } + ssize_t result = self.ReadAttr(name, type, offset, tmp, length); + //if (result < 0) { + // free(tmp); + // throw std::runtime_error("Error calling ReadAttr"); + //} + py::object ret; + switch (type) { + //test Int64 for reinterpretation in int32* + case B_INT64_TYPE: + case B_INT32_TYPE: + case B_INT16_TYPE: + case B_INT8_TYPE: + ret = py::int_(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp)))); + break; + case B_STRING_TYPE: + case B_MIME_STRING_TYPE: + case B_ASCII_TYPE: + ret = py::str(static_cast(tmp)); + //ret = PyUnicode_FromString(static_cast(tmp)); + break; + case B_BOOL_TYPE: + ret = py::bool_(PyBool_FromLong(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp))))); + break; + case B_FLOAT_TYPE: + ret = py::float_(*reinterpret_cast(tmp)); + break; + case B_DOUBLE_TYPE: + ret = py::float_(*reinterpret_cast(tmp)); + break; + case B_TIME_TYPE:{ + //bigtime_t timeValue = *reinterpret_cast(tmp); + time_t timeValue = *reinterpret_cast(tmp); + std::chrono::system_clock::time_point timePoint = + std::chrono::system_clock::time_point(std::chrono::seconds(timeValue)); //this was microseconds + // Calcola il tempo trascorso dalla mezzanotte del 1 gennaio 1970 in secondi + auto seconds_since_epoch = std::chrono::duration_cast(timePoint.time_since_epoch()).count(); + ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(seconds_since_epoch); + break; + + //bigtime_t timeValue=*reinterpret_cast(tmp); + //std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::from_time_t(timeValue / 1000000); + //ret = py::module::import("datetime").attr("datetime").attr("fromtimestamp")(std::chrono::system_clock::to_time_t(timePoint)); + //break; + } + case B_RAW_TYPE:{ + ret = py::bytes(reinterpret_cast(tmp), length); + break; + } + default: + ret = py::bytes(reinterpret_cast(tmp), length); + //ret = py::bytes(static_cast(tmp)); + //py::none(); + break; + } + free(tmp); + return std::make_pair(ret,result); + //return py::reinterpret_steal(ret); +}, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) //.def("RenameAttr", py::overload_cast(&BNode::RenameAttr), "", py::arg("oldName"), py::arg("newName")) .def("RenameAttr", &BNode::RenameAttr, "", py::arg("oldName"), py::arg("newName")) @@ -131,6 +188,7 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed return {result, info}; }, "", py::arg("name")) */ +/* .def("GetAttrInfo", [](BNode& self, const char* attr, struct attr_info* info){ status_t result = self.GetAttrInfo(attr, info); if (result == 0) { @@ -139,6 +197,16 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed throw std::runtime_error("Errore durante la chiamata a GetAttrInfo"); } }, py::arg("attr"), py::arg("info")=attr_info()) +*/ +.def("GetAttrInfo", [](BNode& self, const char* attr, struct attr_info* info)->std::pair{ + status_t result = self.GetAttrInfo(attr, info); + //if (result == 0) { + // return *info; + //} else { + // throw std::runtime_error("Errore durante la chiamata a GetAttrInfo"); + //} + return std::make_pair(info,result); +}, py::arg("attr"), py::arg("info")=attr_info()) //.def("GetNextAttrName", &BNode::GetNextAttrName, "",py::arg("buffer")) //.def("GetNextAttrName", py::overload_cast(&BNode::GetNextAttrName), "",py::arg("buffer")) .def("GetNextAttrName", [](BNode& self, char* buffer){ diff --git a/fstest.py b/fstest.py index e9ab376..eaa4687 100644 --- a/fstest.py +++ b/fstest.py @@ -29,7 +29,10 @@ def attr(node): #nfo = node.GetAttrInfo(a,tmp) #al.append((a,(tmp.type,tmp.size))) # or this way: - nfo = node.GetAttrInfo(a) + pnfo = node.GetAttrInfo(a) + if not pnfo[1]: + nfo = node.GetAttrInfo(a)[0] + type_string = get_type_string(nfo.type) #print(get_type_int(type_string),nfo.type) my_obj = ctypes.py_object() diff --git a/tmtest.py b/tmtest.py index 7ecbe6b..5f4be16 100644 --- a/tmtest.py +++ b/tmtest.py @@ -153,7 +153,9 @@ def __init__(self): self.sevenradio = BRadioButton(BRect(8,240,28,260),'tepidradio', 'tepid', BMessage(7)) self.nineradio = BRadioButton(BRect(8,260,28,280),'coolradio', 'cool', BMessage(9)) scrn = BScreen(self) - img1 = scrn.GetBitmap(True,BRect(0,0,200,200)) + outimg = scrn.GetBitmap(True,BRect(0,0,200,200)) + if not outimg[1]: + img1 = outimg[0] print(img1.Bits()) @@ -161,7 +163,7 @@ def __init__(self): print(img1.BitsLength()) img2=BBitmap(self.panel2.Bounds(),color_space.B_RGBA32) #img2.ImportBits(img1) - img2 = scrn.GetBitmap(True,self.panel3.Bounds()) + img2 = scrn.GetBitmap(True,self.panel3.Bounds())[0] #self.panel3 = PView(self.Bounds(), "panel3",img2) #link=sys.path[0]+"/help/minusmine.bmp" #img=BTranslationUtils.GetBitmap(link) From 4ae34a5966654d66f00c7c4dfdcf7f5269a5d16a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 10:00:25 +0100 Subject: [PATCH 061/155] Return tuple instead pair --- bindings/interface/Screen.cpp | 8 ++++---- bindings/storage/Node.cpp | 26 +++++++++++++++----------- fstest.py | 16 ++++++++++------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index 839f737..fb1fa87 100644 --- a/bindings/interface/Screen.cpp +++ b/bindings/interface/Screen.cpp @@ -34,13 +34,13 @@ py::class_(m, "BScreen") .def("InvertIndex", &BScreen::InvertIndex, "", py::arg("index")) .def("ColorMap", &BScreen::ColorMap, "") //.def("GetBitmap", &BScreen::GetBitmap, "", py::arg("_bitmap"), py::arg("drawCursor")=true, py::arg("frame")=NULL) -.def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> std::pair { +.def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> std::tuple { BBitmap* buffer = new BBitmap(*frame,B_RGBA32); status_t result = self.GetBitmap(&buffer,drawCursor,frame); //if (result != B_OK) { // throw std::runtime_error("Errore durante la chiamata a GetBitmap"); //} - return std::make_pair(buffer,result); + return std::make_tuple(buffer,result); }, py::arg("drawCursor")=true, py::arg("frame")=NULL) /* .def("GetBitmap", [](BScreen& self, bool drawCursor, BRect* frame) -> BBitmap* { @@ -64,7 +64,7 @@ py::class_(m, "BScreen") .def("SetDesktopColor", py::overload_cast(&BScreen::SetDesktopColor), "", py::arg("color"), py::arg("workspace"), py::arg("stick")=true) .def("ProposeMode", &BScreen::ProposeMode, "", py::arg("target"), py::arg("low"), py::arg("high")) //.def("GetModeList", &BScreen::GetModeList, "", py::arg("_modeList"), py::arg("_count")) -.def("GetModeList", [](BScreen& self, uint32 _count) -> std::pair, status_t>{ +.def("GetModeList", [](BScreen& self, uint32 _count) -> std::tuple, status_t>{ // Chiamare la funzione originale // uint32 _count; <- removed as passed by argument display_mode* _modeList; @@ -81,7 +81,7 @@ py::class_(m, "BScreen") // Liberare la memoria allocata da GetModeList free(_modeList); - return std::make_pair(resultVector,result); + return std::make_tuple(resultVector,result); } ) /* diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp index ba72a33..38cc981 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -114,7 +114,7 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed //return py::reinterpret_steal(ret); }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) */ -.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->std::pair{ +.def("ReadAttr", [](BNode& self, const char* name, type_code type, off_t offset, void* buffer, size_t length)->std::tuple{ void* tmp = malloc(length); if (tmp == nullptr){ throw std::runtime_error("Error allocating memory"); @@ -174,7 +174,7 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed break; } free(tmp); - return std::make_pair(ret,result); + return std::make_tuple(ret,result); //return py::reinterpret_steal(ret); }, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer")=NULL, py::arg("length")) .def("RemoveAttr", &BNode::RemoveAttr, "", py::arg("name")) @@ -198,25 +198,29 @@ py::class_(m, "BNode") //Commented out BStatable verify if needed } }, py::arg("attr"), py::arg("info")=attr_info()) */ -.def("GetAttrInfo", [](BNode& self, const char* attr, struct attr_info* info)->std::pair{ +.def("GetAttrInfo", [](BNode& self, const char* attr, struct attr_info* info){ status_t result = self.GetAttrInfo(attr, info); - //if (result == 0) { - // return *info; - //} else { - // throw std::runtime_error("Errore durante la chiamata a GetAttrInfo"); - //} - return std::make_pair(info,result); + return std::make_tuple(*info, result); }, py::arg("attr"), py::arg("info")=attr_info()) //.def("GetNextAttrName", &BNode::GetNextAttrName, "",py::arg("buffer")) //.def("GetNextAttrName", py::overload_cast(&BNode::GetNextAttrName), "",py::arg("buffer")) -.def("GetNextAttrName", [](BNode& self, char* buffer){ +/*.def("GetNextAttrName", [](BNode& self, char* buffer){ status_t result = self.GetNextAttrName(buffer); if (result == 0) { return std::string(buffer); } else { throw std::runtime_error("Errore durante la chiamata a GetNextAttrName"); } -}, py::arg("buffer")="")//, py::return_value_policy::reference_internal +}, py::arg("buffer")="")//, py::return_value_policy::reference_internal*/ +.def("GetNextAttrName", [](BNode& self, char* buffer){ + status_t result = self.GetNextAttrName(buffer); + //if (result == 0) { + // return std::string(buffer); + //} else { + // throw std::runtime_error("Errore durante la chiamata a GetNextAttrName"); + //} + return std::make_tuple(std::string(buffer),result); +}, py::arg("buffer")="") .def("RewindAttrs", &BNode::RewindAttrs, "") .def("WriteAttrString", &BNode::WriteAttrString, "", py::arg("name"), py::arg("data")) .def("ReadAttrString", &BNode::ReadAttrString, "", py::arg("name"), py::arg("result")) diff --git a/fstest.py b/fstest.py index eaa4687..a0f4581 100644 --- a/fstest.py +++ b/fstest.py @@ -15,11 +15,16 @@ def retattrib(self): def attr(node): al = [] while 1: - try: - atri=str("") - a = node.GetNextAttrName() - except: - a = None #no more attributes + #try: + #atri=str("") + #a = node.GetNextAttrName() + #except: + # a = None #no more attributes + an = node.GetNextAttrName() + if not an[1]: + a = an[0] + else: + a = None if a is None: node.RewindAttrs() break @@ -27,7 +32,6 @@ def attr(node): # you can do this way: #tmp = attr_info() #nfo = node.GetAttrInfo(a,tmp) - #al.append((a,(tmp.type,tmp.size))) # or this way: pnfo = node.GetAttrInfo(a) if not pnfo[1]: From b82f4a8154ad29f4f91cc90a7df04d84d4d0c172 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 10:15:52 +0100 Subject: [PATCH 062/155] Add overrides --- bindings/interface/Alert.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bindings/interface/Alert.cpp b/bindings/interface/Alert.cpp index ae4a740..7aec309 100644 --- a/bindings/interface/Alert.cpp +++ b/bindings/interface/Alert.cpp @@ -13,6 +13,28 @@ namespace py = pybind11; +class PyBAlert : public BAlert{ + public: + using BAlert::BAlert; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BAlert, Archive, data, deep); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BAlert, MessageReceived, message); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BAlert, FrameResized, newWidth, newHeight); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, + BMessage* specifier, int32 form, + const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BAlert, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BAlert, GetSupportedSuites, data); + } +}; + PYBIND11_MODULE(Alert,m) { From e25e4e844a9f6f14a4b41dafdca6cfa474847e15 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 10:30:28 +0100 Subject: [PATCH 063/155] Update Alert overrides --- bindings/interface/Alert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/interface/Alert.cpp b/bindings/interface/Alert.cpp index 7aec309..21e4d25 100644 --- a/bindings/interface/Alert.cpp +++ b/bindings/interface/Alert.cpp @@ -51,7 +51,7 @@ py::enum_(m, "button_spacing", "") .value("B_OFFSET_SPACING", button_spacing::B_OFFSET_SPACING, "") .export_values(); -py::class_>(m, "BAlert") +py::class_>(m, "BAlert") .def(py::init(), "") .def(py::init(), "", py::arg("title"), py::arg("text"), py::arg("button1"), py::arg("button2")=NULL, py::arg("button3")=NULL, py::arg("width")=B_WIDTH_AS_USUAL, py::arg("type")=B_INFO_ALERT) .def(py::init(), "", py::arg("title"), py::arg("text"), py::arg("button1"), py::arg("button2"), py::arg("button3"), py::arg("width"), py::arg("spacing"), py::arg("type")=B_INFO_ALERT) From 377abda6b1ab22e07a3a81c35b03d524d7b05d32 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 10:49:39 +0100 Subject: [PATCH 064/155] Comment out overrides in Bitmap.cpp --- bindings/interface/Bitmap.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bindings/interface/Bitmap.cpp b/bindings/interface/Bitmap.cpp index d5105cb..6e5088f 100644 --- a/bindings/interface/Bitmap.cpp +++ b/bindings/interface/Bitmap.cpp @@ -10,6 +10,22 @@ #include namespace py = pybind11; +/* +class PyBitmap : public BBitmap{ + public: + using BBitmap::BBitmap; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BBitmap, Archive, data, deep); + } + void AddChild(BView* view) override { + PYBIND11_OVERLOAD(void, BBitmap, AddChild, view); + } + bool RemoveChild(BView* view) override { + PYBIND11_OVERLOAD(bool, BBitmap, RemoveChild, view); + } +}; +*/ + using namespace BPrivate; PYBIND11_MODULE(Bitmap,m) From 416df53040e7eae39dc16e3905d206f34a2dc778 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 11:02:50 +0100 Subject: [PATCH 065/155] Add Box.cpp overrides --- bindings/interface/Box.cpp | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/bindings/interface/Box.cpp b/bindings/interface/Box.cpp index 44bd2b6..ff37704 100644 --- a/bindings/interface/Box.cpp +++ b/bindings/interface/Box.cpp @@ -11,9 +11,78 @@ namespace py = pybind11; class PyBBox : public BBox{ public: using BBox::BBox; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BBox, Archive, archive, deep); + } + void SetBorder(border_style border) override { + PYBIND11_OVERLOAD(void, BBox, SetBorder, border); + } void Draw(BRect updateRect) override { PYBIND11_OVERLOAD(void, BBox, Draw, updateRect); } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BBox, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BBox, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BBox, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BBox, AllDetached); + } + void FrameResized(float width, float height) override { + PYBIND11_OVERLOAD(void, BBox, FrameResized, width, height); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BBox, MessageReceived, message); + } + void MouseDown(BPoint point) override { + PYBIND11_OVERLOAD(void, BBox, MouseDown, point); + } + void MouseUp(BPoint point) override { + PYBIND11_OVERLOAD(void, BBox, MouseUp, point); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BBox, WindowActivated, active); + } + void MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BBox, MouseMoved, point, transit, dragMessage); + } + void FrameMoved(BPoint newLocation) override { + PYBIND11_OVERLOAD(void, BBox, FrameMoved, newLocation); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BBox, ResolveSpecifier, message, index, specifier, what, property); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BBox, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BBox, GetPreferredSize, _width, _height); + } + void MakeFocus(bool focused = true) override { + PYBIND11_OVERLOAD(void, BBox, MakeFocus, focused); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BBox, GetSupportedSuites, message); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BBox, Perform, d, arg); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BBox, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BBox, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BBox, PreferredSize); + } + BAlignment LayoutAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BBox, LayoutAlignment); + } }; From 75a5d74b43ba6f0efc5dfb8bbca9e7a892c359f4 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 11:27:21 +0100 Subject: [PATCH 066/155] Add Button.cpp overrides --- bindings/interface/Button.cpp | 83 ++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/bindings/interface/Button.cpp b/bindings/interface/Button.cpp index a51cd15..2f143ae 100644 --- a/bindings/interface/Button.cpp +++ b/bindings/interface/Button.cpp @@ -12,9 +12,90 @@ namespace py = pybind11; class PyBButton : public BButton{ public: using BButton::BButton; - void Draw(BRect updateRect) override { + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BButton, Archive, data, deep); + } + void Draw(BRect updateRect) override { PYBIND11_OVERLOAD(void, BButton, Draw, updateRect); } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BButton, MouseDown, where); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BButton, AttachedToWindow); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BButton, KeyDown, bytes, numBytes); + } + void MakeDefault(bool flag) override { + PYBIND11_OVERLOAD(void, BButton, MakeDefault, flag); + } + void SetLabel(const char* string) override { + PYBIND11_OVERLOAD(void, BButton, SetLabel, string); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BButton, MessageReceived, message); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BButton, WindowActivated, active); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BButton, MouseMoved, where, code, dragMessage); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BButton, MouseUp, where); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BButton, DetachedFromWindow); + } + void SetValue(int32 value) override { + PYBIND11_OVERLOAD(void, BButton, SetValue, value); + } + void GetPreferredSize (float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BButton, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BButton, ResizeToPreferred); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BButton, Invoke, message); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BButton, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BButton, FrameResized, newWidth, newHeight); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BButton, MakeFocus, focus); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BButton, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BButton, AllDetached); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BButton, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BButton, GetSupportedSuites, message); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BButton, Perform, d, arg); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BButton, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BButton, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BButton, PreferredSize); + } + status_t SetIcon(const BBitmap* icon, uint32 flags = 0) override { + PYBIND11_OVERLOAD(status_t, BButton, SetIcon, icon, flags); + } }; From 7db8799303fa9b17abd51d3a7f5871b2af8a8c65 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 13:29:24 +0100 Subject: [PATCH 067/155] Add CheckBox.cpp overrides --- bindings/interface/CheckBox.cpp | 86 +++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/bindings/interface/CheckBox.cpp b/bindings/interface/CheckBox.cpp index 1f89c24..7ed06de 100644 --- a/bindings/interface/CheckBox.cpp +++ b/bindings/interface/CheckBox.cpp @@ -10,6 +10,92 @@ namespace py = pybind11; +class PyBCheckBox : public BCheckBox{ + public: + using BCheckBox::BCheckBox; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BCheckBox, Archive, data, deep); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BCheckBox, Draw, updateRect); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BCheckBox, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BCheckBox, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BCheckBox, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BCheckBox, AllDetached); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BCheckBox, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BCheckBox, FrameResized, newWidth, newHeight); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BCheckBox, WindowActivated, active); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BCheckBox, MessageReceived, message); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BCheckBox, KeyDown, bytes, numBytes); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BCheckBox, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BCheckBox, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BCheckBox, MouseMoved, where, code, dragMessage); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BCheckBox, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BCheckBox, ResizeToPreferred); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BCheckBox, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BCheckBox, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BCheckBox, PreferredSize); + } + BAlignment LayoutAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BCheckBox, LayoutAlignment); + } + void MakeFocus(bool focused = true) override { + PYBIND11_OVERLOAD(void, BCheckBox, MakeFocus, focused); + } + void SetValue(int32 value) override { + PYBIND11_OVERLOAD(void, BCheckBox, SetValue, value); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BCheckBox, Invoke, message); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BCheckBox, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BCheckBox, GetSupportedSuites, message); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BCheckBox, Perform, code, data); + } + status_t SetIcon(const BBitmap* icon, uint32 flags = 0) override { + PYBIND11_OVERLOAD(status_t, BCheckBox, SetIcon, icon, flags); + } +}; + PYBIND11_MODULE(CheckBox,m) { py::class_>(m, "BCheckBox") From e2b50ec4914266883e0a83ac3a344227c258b3d7 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 13:52:32 +0100 Subject: [PATCH 068/155] Add ColorControl.cpp overrides --- bindings/interface/ColorControl.cpp | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/bindings/interface/ColorControl.cpp b/bindings/interface/ColorControl.cpp index fee6624..8faf443 100644 --- a/bindings/interface/ColorControl.cpp +++ b/bindings/interface/ColorControl.cpp @@ -10,6 +10,88 @@ namespace py = pybind11; +class PyBColorControl : public BColorControl{ + public: + using BColorControl::BColorControl; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BColorControl, Archive, data, deep); + } + void SetLayout(BLayout* layout) override { + PYBIND11_OVERLOAD(void, BColorControl, SetLayout, layout); + } + void SetValue(int32 color_value) override { + PYBIND11_OVERLOAD(void, BColorControl, SetValue, color_value); + } + void SetEnabled(bool state) override { + PYBIND11_OVERLOAD(void, BColorControl, SetEnabled, state); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BColorControl, AttachedToWindow); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BColorControl, MessageReceived, message); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BColorControl, Draw, updateRect); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BColorControl, MouseDown, where); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BColorControl, KeyDown, bytes, numBytes); + } + void SetCellSize(float size) override { + PYBIND11_OVERLOAD(void, BColorControl, SetCellSize, size); + } + void SetLayout(color_control_layout layout) override { + PYBIND11_OVERLOAD(void, BColorControl, SetLayout, layout); + } + void WindowActivated(bool state) override { + PYBIND11_OVERLOAD(void, BColorControl, WindowActivated, state); + } + void MouseUp(BPoint point) override { + PYBIND11_OVERLOAD(void, BColorControl, MouseUp, point); + } + void MouseMoved(BPoint point, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BColorControl, MouseMoved, point, code, dragMessage); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BColorControl, DetachedFromWindow); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BColorControl, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BColorControl, ResizeToPreferred); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BColorControl, Invoke, message); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BColorControl, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BColorControl, FrameResized, newWidth, newHeight); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BColorControl, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BColorControl, GetSupportedSuites, data); + } + void MakeFocus(bool focused = true) override { + PYBIND11_OVERLOAD(void, BColorControl, MakeFocus, focused); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BColorControl, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BColorControl, AllDetached); + } + status_t SetIcon(const BBitmap* icon, uint32 flags = 0) override { + PYBIND11_OVERLOAD(status_t, BColorControl, SetIcon, icon, flags); + } +}; PYBIND11_MODULE(ColorControl,m) { From ad69963f2f007cbd324c7c9ad73788b987059233 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 13:54:49 +0100 Subject: [PATCH 069/155] Fix Checkbox & ColorControl overrides --- bindings/interface/CheckBox.cpp | 2 +- bindings/interface/ColorControl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/interface/CheckBox.cpp b/bindings/interface/CheckBox.cpp index 7ed06de..8f7f81b 100644 --- a/bindings/interface/CheckBox.cpp +++ b/bindings/interface/CheckBox.cpp @@ -98,7 +98,7 @@ class PyBCheckBox : public BCheckBox{ PYBIND11_MODULE(CheckBox,m) { -py::class_>(m, "BCheckBox") +py::class_>(m, "BCheckBox") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("label"), py::arg("message")=NULL) diff --git a/bindings/interface/ColorControl.cpp b/bindings/interface/ColorControl.cpp index 8faf443..694f6f4 100644 --- a/bindings/interface/ColorControl.cpp +++ b/bindings/interface/ColorControl.cpp @@ -103,7 +103,7 @@ py::enum_(m, "color_control_layout", "") .value("B_CELLS_64x4", color_control_layout::B_CELLS_64x4, "") .export_values(); -py::class_>(m, "BColorControl") +py::class_>(m, "BColorControl") .def(py::init(), "", py::arg("start"), py::arg("layout"), py::arg("cellSize"), py::arg("name"), py::arg("message")=NULL, py::arg("useOffscreen")=false) .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BColorControl::Instantiate, "", py::arg("data")) From 8062f1575a17c1fa0335550116751aa4cd24137d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 14:07:01 +0100 Subject: [PATCH 070/155] Add Control.cpp overrides --- bindings/interface/Control.cpp | 74 +++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/bindings/interface/Control.cpp b/bindings/interface/Control.cpp index 02a9e71..31f559b 100644 --- a/bindings/interface/Control.cpp +++ b/bindings/interface/Control.cpp @@ -12,6 +12,78 @@ namespace py = pybind11; using namespace BPrivate; +class PyBControl : public BControl{ + public: + using BControl::BControl; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BControl, Archive, data, deep); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BControl, WindowActivated, active); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BControl, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BControl, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BControl, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BControl, AllDetached); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BControl, MessageReceived, message); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BControl, MakeFocus, focus); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BControl, KeyDown, bytes, numBytes); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BControl, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BControl, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BControl, MouseMoved, where, code, dragMessage); + } + void SetLabel(const char* string) override { + PYBIND11_OVERLOAD(void, BControl, SetLabel, string); + } + void SetValue(int32 value) override { + PYBIND11_OVERLOAD(void, BControl, SetValue, value); + } + void SetEnabled(bool enabled) override { + PYBIND11_OVERLOAD(void, BControl, SetEnabled, enabled); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BControl, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BControl, ResizeToPreferred); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BControl, Invoke, message); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BControl, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BControl, GetSupportedSuites, message); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BControl, Perform, d, arg); + } + status_t SetIcon(const BBitmap* bitmap, uint32 flags = 0) override { + PYBIND11_OVERLOAD(status_t, BControl, SetIcon, bitmap, flags); + } +}; + + PYBIND11_MODULE(Control,m) { m.attr("B_CONTROL_OFF") = 0; @@ -20,7 +92,7 @@ m.attr("B_CONTROL_PARTIALLY_ON") = 2; //m.attr("BIcon") = BIcon; -py::class_(m, "BControl") +py::class_(m, "BControl") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("resizingMode"), py::arg("flags")) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("flags")) .def(py::init(), "", py::arg("data")) From 79247a3d50f3ece2953ad61101f4f32ff526c47d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 14:30:00 +0100 Subject: [PATCH 071/155] Add GridLayout.cpp overrides --- bindings/interface/GridLayout.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/bindings/interface/GridLayout.cpp b/bindings/interface/GridLayout.cpp index d69b015..60453f9 100644 --- a/bindings/interface/GridLayout.cpp +++ b/bindings/interface/GridLayout.cpp @@ -11,10 +11,38 @@ namespace py = pybind11; +class PyBGridLayout : public BGridLayout{ + public: + using BGridLayout::BGridLayout; + BLayoutItem* AddView(BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BGridLayout, AddView, child); + } + BLayoutItem* AddView(int32 index, BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BGridLayout, AddView, index, child); + } + BLayoutItem* AddView(BView* child, int32 column, int32 row, int32 columnCount = 1, int32 rowCount = 1) override { + PYBIND11_OVERLOAD(BLayoutItem*, BGridLayout, AddView, child, column, row, columnCount, rowCount); + } + bool AddItem(BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BGridLayout, AddItem, item); + } + bool AddItem(int32 index, BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BGridLayout, AddItem, index, item); + } + bool AddItem(BLayoutItem* item, int32 column, int32 row, int32 columnCount = 1, int32 rowCount = 1) override { + PYBIND11_OVERLOAD(bool, BGridLayout, AddItem, item, column, row, columnCount, rowCount); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BGridLayout, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BGridLayout, Perform, d, arg); + } +}; PYBIND11_MODULE(GridLayout,m) { -py::class_>(m, "BGridLayout") +py::class_>(m, "BGridLayout") // ImportError: arg(): could not convert default argument 'horizontal: ._anon_253' in method '.__init__' into a Python object (type not registered yet?) .def(py::init(), "", py::arg("horizontal")=py::int_(-1002), py::arg("vertical")=py::int_(-1002)) .def(py::init(), "", py::arg("from")) From af1ae90db9d234217f107563730a0d06e0c3c711 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 14:38:02 +0100 Subject: [PATCH 072/155] Add ListItem.cpp overrides --- bindings/interface/ListItem.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bindings/interface/ListItem.cpp b/bindings/interface/ListItem.cpp index c43e348..bcc26b6 100644 --- a/bindings/interface/ListItem.cpp +++ b/bindings/interface/ListItem.cpp @@ -18,11 +18,22 @@ namespace py = pybind11; class PyBListItem : public BListItem { public: using BListItem::BListItem; - - void DrawItem(BView* owner, BRect itemRect, bool drawEverything) override { + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BListItem, Archive, archive, deep); + } + void SetEnabled(bool enabled) override { + PYBIND11_OVERLOAD(void, BListItem, SetEnabled, enabled); + } + void DrawItem(BView* owner, BRect itemRect, bool drawEverything) override { PYBIND11_OVERLOAD_PURE(void, BListItem, DrawItem, owner, itemRect, drawEverything); } - + void Update(BView* owner, const BFont* font) override { + PYBIND11_OVERLOAD(void, BListItem, Update, owner, font); + } + status_t Perform(perform_code code, void* arg) override { + PYBIND11_OVERLOAD(status_t, BListItem, Perform, code, arg); + } + private: BListItem* item_; }; From 4eb73ba363ad806790a0c1bb06dc51a84c42231c Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 17:10:17 +0100 Subject: [PATCH 073/155] Add ListView.cpp overrides --- bindings/interface/ListView.cpp | 116 +++++++++++++++++++++++++++++++- tmtest.py | 2 - 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/bindings/interface/ListView.cpp b/bindings/interface/ListView.cpp index e527926..cb10603 100644 --- a/bindings/interface/ListView.cpp +++ b/bindings/interface/ListView.cpp @@ -12,8 +12,120 @@ #include namespace py = pybind11; -//py::list convertBListItemsToPythonList(BListItem** items); -//py::list convertBListItemsToPythonList(const BListItem* const* items); + +class PyBListView : public BListView{ + public: + using BListView::BListView; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BListView, Archive, data, deep); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BListView, WindowActivated, active); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BListView, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BListView, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BListView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BListView, AllDetached); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BListView, MessageReceived, message); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BListView, KeyDown, bytes, numBytes); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BListView, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BListView, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BListView, MouseMoved, where, code, dragMessage); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BListView, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BListView, GetPreferredSize, _width, _height); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BListView, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BListView, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BListView, PreferredSize); + } + void MakeFocus(bool state = true) override { + PYBIND11_OVERLOAD(void, BListView, MakeFocus, state); + } + void SetFont(const BFont* font, uint32 mask = B_FONT_ALL) override { + PYBIND11_OVERLOAD(void, BListView, SetFont, font, mask); + } + void ScrollTo(BPoint where) override { + PYBIND11_OVERLOAD(void, BListView, ScrollTo, where); + } + bool AddItem(BListItem* item) override { + PYBIND11_OVERLOAD(bool, BListView, AddItem, item); + } + bool AddItem(BListItem* item, int32 atIndex) override { + PYBIND11_OVERLOAD(bool, BListView, AddItem, item, atIndex); + } + bool AddList(BList* newItems) override { + PYBIND11_OVERLOAD(bool, BListView, AddList, newItems); + } + bool AddList(BList* newItems, int32 atIndex) override { + PYBIND11_OVERLOAD(bool, BListView, AddList, newItems, atIndex); + } + bool RemoveItem(BListItem* item) override { + PYBIND11_OVERLOAD(bool, BListView, RemoveItem, item); + } + BListItem* RemoveItem(int32 index) override { + PYBIND11_OVERLOAD(BListItem*, BListView, RemoveItem, index); + } + bool RemoveItems(int32 index, int32 count) override { + PYBIND11_OVERLOAD(bool, BListView, RemoveItems, index, count); + } + void SetSelectionMessage(BMessage* message) override { + PYBIND11_OVERLOAD(void, BListView, SetSelectionMessage, message); + } + void SetInvocationMessage(BMessage* message) override { + PYBIND11_OVERLOAD(void, BListView, SetInvocationMessage, message); + } + void SetListType(list_view_type type) override { + PYBIND11_OVERLOAD(void, BListView, SetListType, type); + } + void MakeEmpty() override { + PYBIND11_OVERLOAD(void, BListView, MakeEmpty); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BListView, Invoke, message); + } + void SelectionChanged() override { + PYBIND11_OVERLOAD(void, BListView, SelectionChanged); + } + bool InitiateDrag(BPoint where, int32 index, bool wasSelected) override { + PYBIND11_OVERLOAD(bool, BListView, InitiateDrag, where, index, wasSelected); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BListView, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BListView, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* arg) override { + PYBIND11_OVERLOAD(status_t, BListView, Perform, code, arg); + } +}; + py::list convertBListItemsToPythonList(const BListItem* const* items, long count) { py::list result; diff --git a/tmtest.py b/tmtest.py index 5f4be16..29f5b5a 100644 --- a/tmtest.py +++ b/tmtest.py @@ -54,10 +54,8 @@ def Draw(self,rect): BButton.Draw(self, rect) inset = BRect(4, 4, self.frame.Width()-4, self.frame.Height()-4) if self.Value(): - print("disegno su") self.DrawBitmap(self.immagine, inset) else: - print("disegno GIù") self.DrawBitmap(self.imgdown, inset) From 593af902c524f7e6a27cdfbd094c92969b7da433 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 17:28:07 +0100 Subject: [PATCH 074/155] Add ListView.cpp overrides, Fix ListView override --- bindings/interface/ListView.cpp | 2 +- bindings/interface/Menu.cpp | 85 ++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/bindings/interface/ListView.cpp b/bindings/interface/ListView.cpp index cb10603..1f7615f 100644 --- a/bindings/interface/ListView.cpp +++ b/bindings/interface/ListView.cpp @@ -156,7 +156,7 @@ py::enum_(m, "list_view_type", "") .value("B_MULTIPLE_SELECTION_LIST", list_view_type::B_MULTIPLE_SELECTION_LIST, "") .export_values(); -py::class_>(m, "BListView") +py::class_>(m, "BListView") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("type")=B_SINGLE_SELECTION_LIST, py::arg("resizeMask")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE) .def(py::init(), "", py::arg("name"), py::arg("type")=B_SINGLE_SELECTION_LIST, py::arg("flags")=B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE) .def(py::init(), "", py::arg("type")=B_SINGLE_SELECTION_LIST) diff --git a/bindings/interface/Menu.cpp b/bindings/interface/Menu.cpp index c798c79..2850d34 100644 --- a/bindings/interface/Menu.cpp +++ b/bindings/interface/Menu.cpp @@ -12,6 +12,89 @@ namespace py = pybind11; using namespace BPrivate; +class PyBMenu : public BMenu{ + public: + using BMenu::BMenu; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BMenu, Archive, archive, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BMenu, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BMenu, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BMenu, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BMenu, AllDetached); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BMenu, Draw, updateRect); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BMenu, MessageReceived, message); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BMenu, KeyDown, bytes, numBytes); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BMenu, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BMenu, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BMenu, PreferredSize); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BMenu, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BMenu, ResizeToPreferred); + } + void DoLayout() override { + PYBIND11_OVERLOAD(void, BMenu, DoLayout); + } + void FrameMoved(BPoint where) override { + PYBIND11_OVERLOAD(void, BMenu, FrameMoved, where); + } + void FrameResized(float width, float height) override { + PYBIND11_OVERLOAD(void, BMenu, FrameResized, width, height); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BMenu, MakeFocus, focus); + } + status_t SetTargetForItems(BHandler* target) override { + PYBIND11_OVERLOAD(status_t, BMenu, SetTargetForItems, target); + } + status_t SetTargetForItems(BMessenger messenger) override { + PYBIND11_OVERLOAD(status_t, BMenu, SetTargetForItems, messenger); + } + void SetEnabled(bool enable) override { + PYBIND11_OVERLOAD(void, BMenu, SetEnabled, enable); + } + void SetRadioMode(bool on) override { + PYBIND11_OVERLOAD(void, BMenu, SetRadioMode, on); + } + void SetTriggersEnabled(bool enable) override { + PYBIND11_OVERLOAD(void, BMenu, SetTriggersEnabled, enable); + } + void SetMaxContentWidth(float maxWidth) override { + PYBIND11_OVERLOAD(void, BMenu, SetMaxContentWidth, maxWidth); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BMenu, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BMenu, GetSupportedSuites, data); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BMenu, Perform, d, arg); + } +}; + PYBIND11_MODULE(Menu,m) { py::enum_(m, "menu_layout", "") @@ -38,7 +121,7 @@ py::class_(m, "menu_info") .def_readwrite("triggers_always_shown", &menu_info::triggers_always_shown, "") ; -py::class_>(m, "BMenu") +py::class_>(m, "BMenu") .def(py::init(), "", py::arg("name"), py::arg("layout")=B_ITEMS_IN_COLUMN) .def(py::init(), "", py::arg("name"), py::arg("width"), py::arg("height")) .def(py::init(), "", py::arg("archive")) From d479c7a374fac3d6a9a383af59987806acff5830 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 18:00:21 +0100 Subject: [PATCH 075/155] Add MenuBar.cpp overrides --- bindings/interface/MenuBar.cpp | 79 +++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/bindings/interface/MenuBar.cpp b/bindings/interface/MenuBar.cpp index 4ce22ef..1c877ee 100644 --- a/bindings/interface/MenuBar.cpp +++ b/bindings/interface/MenuBar.cpp @@ -9,7 +9,82 @@ #include namespace py = pybind11; - +class PyBMenuBar : public BMenuBar{ + public: + using BMenuBar::BMenuBar; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BMenuBar, Archive, archive, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BMenuBar, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BMenuBar, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BMenuBar, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BMenuBar, AllDetached); + } + void WindowActivated(bool state) override { + PYBIND11_OVERLOAD(void, BMenuBar, WindowActivated, state); + } + void MakeFocus(bool state = true) override { + PYBIND11_OVERLOAD(void, BMenuBar, MakeFocus, state); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BMenuBar, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BMenuBar, GetPreferredSize, _width, _height); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BMenuBar, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BMenuBar, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BMenuBar, PreferredSize); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BMenuBar, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BMenuBar, FrameResized, newWidth, newHeight); + } + void Show() override { + PYBIND11_OVERLOAD(void, BMenuBar, Show); + } + void Hide() override { + PYBIND11_OVERLOAD(void, BMenuBar, Hide); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BMenuBar, Draw, updateRect); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BMenuBar, MessageReceived, message); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BMenuBar, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BMenuBar, MouseUp, where); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BMenuBar, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BMenuBar, GetSupportedSuites, data); + } + void SetBorder(menu_bar_border border) override { + PYBIND11_OVERLOAD(void, BMenuBar, SetBorder, border); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BMenuBar, Perform, code, data); + } +}; PYBIND11_MODULE(MenuBar,m) { @@ -19,7 +94,7 @@ py::enum_(m, "menu_bar_border", "") .value("B_BORDER_EACH_ITEM", menu_bar_border::B_BORDER_EACH_ITEM, "") .export_values(); -py::class_>(m, "BMenuBar") +py::class_>(m, "BMenuBar") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("resizingMode")=B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, py::arg("layout")=B_ITEMS_IN_ROW, py::arg("resizeToFit")=true) .def(py::init(), "", py::arg("name"), py::arg("layout")=B_ITEMS_IN_ROW, py::arg("flags")=B_WILL_DRAW | B_FRAME_EVENTS) .def(py::init(), "", py::arg("archive")) From bc0db896451da7fa4fe7a5360ade798b97c968b1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 18:14:56 +0100 Subject: [PATCH 076/155] Add MenuField.cpp overrides --- bindings/interface/MenuField.cpp | 87 +++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/bindings/interface/MenuField.cpp b/bindings/interface/MenuField.cpp index 108a2cd..b96f0d8 100644 --- a/bindings/interface/MenuField.cpp +++ b/bindings/interface/MenuField.cpp @@ -11,10 +11,95 @@ namespace py = pybind11; +class PyBMenuField : public BMenuField{ + public: + using BMenuField::BMenuField; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BMenuField, Archive, archive, deep); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BMenuField, Draw, updateRect); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BMenuField, AttachedToWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BMenuField, AllAttached); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BMenuField, MouseDown, where); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BMenuField, KeyDown, bytes, numBytes); + } + void MakeFocus(bool focused) override { + PYBIND11_OVERLOAD(void, BMenuField, MakeFocus, focused); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BMenuField, MessageReceived, message); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BMenuField, WindowActivated, active); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BMenuField, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BMenuField, MouseMoved, where, transit, dragMessage); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BMenuField, DetachedFromWindow); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BMenuField, AllAttached); + } + void FrameMoved(BPoint where) override { + PYBIND11_OVERLOAD(void, BMenuField, FrameMoved, where); + } + void FrameResized(float width, float height) override { + PYBIND11_OVERLOAD(void, BMenuField, FrameResized, width, height); + } + void SetLabel(const char* label) override { + PYBIND11_OVERLOAD(void, BMenuField, SetLabel, label); + } + void SetEnabled(bool on) override { + PYBIND11_OVERLOAD(void, BMenuField, SetEnabled, on); + } + void SetAlignment(alignment label) override { + PYBIND11_OVERLOAD(void, BMenuField, SetAlignment, label); + } + void SetDivider(float position) override { + PYBIND11_OVERLOAD(void, BMenuField, SetDivider, position); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BMenuField, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BMenuField, GetSupportedSuites, data); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BMenuField, ResizeToPreferred); + } + void GetPreferredSize(float* width, float* height) override { + PYBIND11_OVERLOAD(void, BMenuField, GetPreferredSize, width, height); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BMenuField, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BMenuField, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BMenuField, PreferredSize); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BMenuField, Perform, d, arg); + } +}; PYBIND11_MODULE(MenuField,m) { -py::class_>(m, "BMenuField") +py::class_>(m, "BMenuField") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("menu"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("menu"), py::arg("fixed_size"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("menu"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) From b6956764eff250a2f62cbdbdd4ea0a7aa539b6ea Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 18:21:36 +0100 Subject: [PATCH 077/155] Add MenuItem.cpp overrides --- bindings/interface/MenuItem.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/bindings/interface/MenuItem.cpp b/bindings/interface/MenuItem.cpp index 5c5bed2..2f2fe32 100644 --- a/bindings/interface/MenuItem.cpp +++ b/bindings/interface/MenuItem.cpp @@ -13,11 +13,34 @@ namespace py = pybind11; using namespace BPrivate; +class PyBMenuItem : public BMenuItem{ + public: + using BMenuItem::BMenuItem; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BMenuItem, Archive, archive, deep); + } + void SetLabel(const char* name) override { + PYBIND11_OVERLOAD(void, BMenuItem, SetLabel, name); + } + void SetEnabled(bool enable) override { + PYBIND11_OVERLOAD(void, BMenuItem, SetEnabled, enable); + } + void SetMarked(bool mark) override { + PYBIND11_OVERLOAD(void, BMenuItem, SetMarked, mark); + } + void SetTrigger(char trigger) override { + PYBIND11_OVERLOAD(void, BMenuItem, SetTrigger, trigger); + } + void SetShortcut(char shortcut, uint32 modifiers) override { + PYBIND11_OVERLOAD(void, BMenuItem, SetShortcut, shortcut, modifiers); + } +}; + PYBIND11_MODULE(MenuItem,m) { //m.attr("MenuItemPrivate") = MenuItemPrivate; -py::class_>(m, "BMenuItem") +py::class_>(m, "BMenuItem") .def(py::init(), "", py::arg("label"), py::arg("message"), py::arg("shortcut")=0, py::arg("modifiers")=0) .def(py::init(), "", py::arg("menu"), py::arg("message")=NULL) .def(py::init(), "", py::arg("data")) @@ -38,5 +61,4 @@ py::class_>(m, "BM .def("Frame", &BMenuItem::Frame, "") ; - } From bc3f094f86c5d4e554a408a40c01991eb03d5a02 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 18:40:22 +0100 Subject: [PATCH 078/155] Add PictureButton.cpp overrides --- bindings/interface/PictureButton.cpp | 90 +++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/bindings/interface/PictureButton.cpp b/bindings/interface/PictureButton.cpp index f3af4e7..3297b77 100644 --- a/bindings/interface/PictureButton.cpp +++ b/bindings/interface/PictureButton.cpp @@ -10,6 +10,94 @@ namespace py = pybind11; +class PyBPictureButton : public BPictureButton{ + public: + using BPictureButton::BPictureButton; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BPictureButton, Archive, archive, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BPictureButton, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BPictureButton, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BPictureButton, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BPictureButton, AllDetached); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BPictureButton, ResizeToPreferred); + } + void GetPreferredSize(float* _width,float* _height) override { + PYBIND11_OVERLOAD(void, BPictureButton, GetPreferredSize, _width, _height); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BPictureButton, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BPictureButton, FrameResized, newWidth, newHeight); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BPictureButton, WindowActivated, active); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BPictureButton, MakeFocus, focus); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BPictureButton, Draw, updateRect); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BPictureButton, MessageReceived, message); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BPictureButton, KeyDown, bytes, numBytes); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BPictureButton, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BPictureButton, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BPictureButton, MouseMoved, where, code, dragMessage); + } + void SetEnabledOn(BPicture* picture) override { + PYBIND11_OVERLOAD(void, BPictureButton, SetEnabledOn, picture); + } + void SetEnabledOff(BPicture* picture) override { + PYBIND11_OVERLOAD(void, BPictureButton, SetEnabledOff, picture); + } + void SetDisabledOn(BPicture* picture) override { + PYBIND11_OVERLOAD(void, BPictureButton, SetDisabledOn, picture); + } + void SetDisabledOff(BPicture* picture) override { + PYBIND11_OVERLOAD(void, BPictureButton, SetDisabledOff, picture); + } + void SetBehavior(uint32 behavior) override { + PYBIND11_OVERLOAD(void, BPictureButton, SetBehavior, behavior); + } + void SetValue(int32 value) override { + PYBIND11_OVERLOAD(void, BPictureButton, SetValue, value); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BPictureButton, Invoke, message); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BPictureButton, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BPictureButton, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BPictureButton, Perform, code, data); + } + status_t SetIcon(const BBitmap* icon, uint32 flags = 0) override { + PYBIND11_OVERLOAD(status_t, BPictureButton, SetIcon, icon, flags); + } +}; PYBIND11_MODULE(PictureButton,m) { @@ -20,7 +108,7 @@ py::enum_(m, "picture_button_behavior", "") .value("B_TWO_STATE_BUTTON", picture_button_behavior::B_TWO_STATE_BUTTON, "") .export_values(); -py::class_>(m, "BPictureButton") +py::class_>(m, "BPictureButton") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("off"), py::arg("on"), py::arg("message"), py::arg("behavior")=B_ONE_STATE_BUTTON, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flgs")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("archive")) .def_static("Instantiate", &BPictureButton::Instantiate, "", py::arg("archive")) From e72e01c001fc956f1ff85a6f119599b4e2ea8bee Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 08:12:05 +0100 Subject: [PATCH 079/155] Add RadioButton.cpp overrides --- bindings/interface/RadioButton.cpp | 81 +++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/bindings/interface/RadioButton.cpp b/bindings/interface/RadioButton.cpp index e282300..df8de77 100644 --- a/bindings/interface/RadioButton.cpp +++ b/bindings/interface/RadioButton.cpp @@ -9,10 +9,89 @@ namespace py = pybind11; +class PyBRadioButton : public BRadioButton{ + public: + using BRadioButton::BRadioButton; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BRadioButton, Archive, data, deep); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BRadioButton, Draw, updateRect); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BRadioButton, MouseDown, where); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BRadioButton, AttachedToWindow); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BRadioButton, KeyDown, bytes, numBytes); + } + void SetValue(int32 value) override { + PYBIND11_OVERLOAD(void, BRadioButton, SetValue, value); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BRadioButton, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BRadioButton, ResizeToPreferred); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BRadioButton, Invoke, message); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BRadioButton, MessageReceived, message); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BRadioButton, WindowActivated, active); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BRadioButton, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BRadioButton, MouseMoved, where, code, dragMessage); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BRadioButton, DetachedFromWindow); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BRadioButton, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BRadioButton, FrameResized, newWidth, newHeight); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BRadioButton, ResolveSpecifier, message, index, specifier, what, property); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BRadioButton, MakeFocus, focus); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BRadioButton, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BRadioButton, AllDetached); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BRadioButton, GetSupportedSuites, message); + } + status_t Perform(perform_code d, void* argument) override { + PYBIND11_OVERLOAD(status_t, BRadioButton, Perform, d, argument); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BRadioButton, MaxSize); + } + BAlignment LayoutAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BRadioButton, LayoutAlignment); + } + status_t SetIcon(const BBitmap* icon, uint32 flags = 0) override { + PYBIND11_OVERLOAD(status_t, BRadioButton, SetIcon, icon, flags); + } +}; PYBIND11_MODULE(RadioButton,m) { -py::class_>(m, "BRadioButton") +py::class_>(m, "BRadioButton") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("label"), py::arg("message")) From b52baf53cf219ffe674902db587c932823e5d9e8 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 19:08:46 +0100 Subject: [PATCH 080/155] Add PopUpMenu.cpp overrides --- bindings/interface/PopUpMenu.cpp | 57 +++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/bindings/interface/PopUpMenu.cpp b/bindings/interface/PopUpMenu.cpp index a937ff5..ad6758e 100644 --- a/bindings/interface/PopUpMenu.cpp +++ b/bindings/interface/PopUpMenu.cpp @@ -9,10 +9,65 @@ namespace py = pybind11; +class PyBPopUpMenu : public BPopUpMenu{ + public: + using BPopUpMenu::BPopUpMenu; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BPopUpMenu, Archive, archive, deep); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, MessageReceived, message); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, MouseMoved, where, transit, dragMessage); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BPopUpMenu, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BPopUpMenu, DetachedFromWindow); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, FrameResized, newWidth, newHeight); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BPopUpMenu, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BPopUpMenu, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* _data) override { + PYBIND11_OVERLOAD(status_t, BPopUpMenu, Perform, code, _data); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BPopUpMenu, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, GetPreferredSize, _width, _height); + } + void MakeFocus(bool state = true) override { + PYBIND11_OVERLOAD(void, BPopUpMenu, MakeFocus, state); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BPopUpMenu, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BPopUpMenu, AllDetached); + } +}; PYBIND11_MODULE(PopUpMenu,m) { -py::class_>(m, "BPopUpMenu") +py::class_>(m, "BPopUpMenu") .def(py::init(), "", py::arg("name"), py::arg("radioMode")=true, py::arg("labelFromMarked")=true, py::arg("layout")=B_ITEMS_IN_COLUMN) .def(py::init(), "", py::arg("data")) .def("Archive", &BPopUpMenu::Archive, "", py::arg("archive"), py::arg("deep")=true) From 1bd9c1dbf2e06e0d2bef23c537f94d103e5569ca Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 2 Dec 2023 19:18:07 +0100 Subject: [PATCH 081/155] Update tmtest.py --- tmtest.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tmtest.py b/tmtest.py index 29f5b5a..d408674 100644 --- a/tmtest.py +++ b/tmtest.py @@ -154,21 +154,23 @@ def __init__(self): outimg = scrn.GetBitmap(True,BRect(0,0,200,200)) if not outimg[1]: img1 = outimg[0] - - - print(img1.Bits()) - print(img1.Flags()) - print(img1.BitsLength()) + print(img1.Bits()) + print(img1.Flags()) + print(img1.BitsLength()) img2=BBitmap(self.panel2.Bounds(),color_space.B_RGBA32) #img2.ImportBits(img1) - img2 = scrn.GetBitmap(True,self.panel3.Bounds())[0] + img2, reto = scrn.GetBitmap(True,self.panel3.Bounds()) + if not reto: + self.PicBox = PBox(self.panel3.Bounds(),"PictureBox",img2) + self.panel3.AddChild(self.PicBox,None) #self.panel3 = PView(self.Bounds(), "panel3",img2) #link=sys.path[0]+"/help/minusmine.bmp" #img=BTranslationUtils.GetBitmap(link) #link2=sys.path[0]+"/help/minusmined.bmp" #img2=BTranslationUtils.GetBitmap(link2) - self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(2),img1,img2)#img2,img)AppDefs.B_QUIT_REQUESTED - self.PicBox = PBox(self.panel3.Bounds(),"PictureBox",img2) + if outimg[1]+reto == 0: + self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(2),img1,img2)#img2,img)AppDefs.B_QUIT_REQUESTED + self.panel.AddChild(self.fadBtn,None) # Handling colors################## #colore=self.list.lv.HighColor() #print("colore è:",colore.red,colore.green,colore.blue,colore.alpha) @@ -214,7 +216,6 @@ def __init__(self): self.panel.AddChild(self.sixradio,None) self.panel.AddChild(self.sevenradio,None) self.panel.AddChild(self.nineradio,None) - self.panel.AddChild(self.fadBtn,None) self.panel.AddChild(butupdown,None) self.panel.AddChild(self.cc,None) self.panel.AddChild(self.startimer,None) @@ -265,7 +266,7 @@ def __init__(self): self.panel2.AddChild(self.typtap,None) colore=self.panel.HighColor() #print(colore.red,colore.green,colore.blue,colore.alpha) - self.panel3.AddChild(self.PicBox,None) + colore.red=180 self.typtap.SetFontAndColor(be_plain_font,511,colore)#B_FONT_ALL = 511 stuff = '\n\t\t\t\t\t\t\tHello Haiku!\n\n\t\t\t\t\t\t\t\t\t\t\tA simple test program\n\t\t\t\t\t\t\t\t\t\t\tfor Haiku, version 1.0\n\t\t\t\t\t\t\t\t\t\t\tsample code included!\n\n\t\t\t\t\t\t\t\t\t\t\tby Fabio Tomat aka TmTFx\n\t\t\t\t\t\t\t\t\t\t\tand others\n\t\t\t\t\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\t\t\t\t\tspecial thanks to:\n\t\t\t\t\t\t\t\t\t\t\tZardshard and coolcoder613' From 556d168fba854c49eeb2818a038ab2643a5d327c Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 11:54:07 +0100 Subject: [PATCH 082/155] Add ScrollBar.cpp overrides --- bindings/interface/ScrollBar.cpp | 75 +++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/bindings/interface/ScrollBar.cpp b/bindings/interface/ScrollBar.cpp index c2341a3..6c055d5 100644 --- a/bindings/interface/ScrollBar.cpp +++ b/bindings/interface/ScrollBar.cpp @@ -8,10 +8,83 @@ namespace py = pybind11; +class PyBScrollBar : public BScrollBar{ + public: + using BScrollBar::BScrollBar; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BScrollBar, Archive, archive, deep); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BScrollBar, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BScrollBar, AllDetached); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BScrollBar, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BScrollBar, DetachedFromWindow); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BScrollBar, Draw, updateRect); + } + void FrameMoved(BPoint new_position) override { + PYBIND11_OVERLOAD(void, BScrollBar, FrameMoved, new_position); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BScrollBar, FrameResized, newWidth, newWidth); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BScrollBar, MessageReceived, message); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BScrollBar, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BScrollBar, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BScrollBar, MouseMoved, where, code, dragMessage); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BScrollBar, WindowActivated, active); + } + void ValueChanged(float newValue) override { + PYBIND11_OVERLOAD(void, BScrollBar, ValueChanged, newValue); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BScrollBar, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BScrollBar, ResizeToPreferred); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BScrollBar, MakeFocus, focus); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BScrollBar, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BScrollBar, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BScrollBar, PreferredSize); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BScrollBar, GetSupportedSuites, message); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BScrollBar, ResolveSpecifier, message, index, specifier, what, property); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BScrollBar, Perform, d, arg); + } +}; PYBIND11_MODULE(ScrollBar,m) { -py::class_(m, "BScrollBar") +py::class_(m, "BScrollBar") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("target"), py::arg("min"), py::arg("max"), py::arg("direction")) .def(py::init(), "", py::arg("name"), py::arg("target"), py::arg("min"), py::arg("max"), py::arg("orientation")) .def(py::init(), "", py::arg("archive")) From e7ea47aad199c30d5efa02f84595fb1cf29f8a69 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 16:01:01 +0100 Subject: [PATCH 083/155] Add ScrollView.cpp overrides --- bindings/interface/ScrollView.cpp | 82 ++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/bindings/interface/ScrollView.cpp b/bindings/interface/ScrollView.cpp index d19762c..6cf34f6 100644 --- a/bindings/interface/ScrollView.cpp +++ b/bindings/interface/ScrollView.cpp @@ -8,10 +8,90 @@ namespace py = pybind11; +class PyBScrollView : public BScrollView{ + public: + using BScrollView::BScrollView; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BScrollView, Archive, archive, deep); + } + status_t AllUnarchived(const BMessage* archive) override { + PYBIND11_OVERLOAD(status_t, BScrollView, AllUnarchived, archive); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BScrollView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BScrollView, AllDetached); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BScrollView, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BScrollView, DetachedFromWindow); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BScrollView, Draw, updateRect); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BScrollView, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BScrollView, FrameResized, newWidth, newHeight); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BScrollView, MessageReceived, message); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BScrollView, MouseDown, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BScrollView, MouseMoved, where, code, dragMessage); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BScrollView, MouseUp, where); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BScrollView, WindowActivated, active); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BScrollView, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BScrollView, ResizeToPreferred); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BScrollView, MakeFocus, focus); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BScrollView, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BScrollView, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BScrollView, PreferredSize); + } + void SetBorder(border_style border) override { + PYBIND11_OVERLOAD(void, BScrollView, SetBorder, border); + } + status_t SetBorderHighlighted(bool highlight) override { + PYBIND11_OVERLOAD(status_t, BScrollView, SetBorderHighlighted, highlight); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BScrollView, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BScrollView, GetSupportedSuites, message); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BScrollView, Perform, d, arg); + } +}; + PYBIND11_MODULE(ScrollView,m) { -py::class_>(m, "BScrollView") +py::class_>(m, "BScrollView") .def(py::init(), "", py::arg("name"), py::arg("target"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=0, py::arg("horizontal")=false, py::arg("vertical")=false, py::arg("border")=B_FANCY_BORDER) .def(py::init(), "", py::arg("name"), py::arg("target"), py::arg("flags"), py::arg("horizontal"), py::arg("vertical"), py::arg("border")=B_FANCY_BORDER) .def(py::init(), "", py::arg("archive")) From 96e0cddabae7ddf807d450405d649530f4342a76 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 16:04:09 +0100 Subject: [PATCH 084/155] Add SeparatorItem.cpp overrides --- bindings/interface/SeparatorItem.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bindings/interface/SeparatorItem.cpp b/bindings/interface/SeparatorItem.cpp index 0c317ae..d34382a 100644 --- a/bindings/interface/SeparatorItem.cpp +++ b/bindings/interface/SeparatorItem.cpp @@ -8,10 +8,20 @@ namespace py = pybind11; +class PyBSeparatorItem : public BSeparatorItem{ + public: + using BSeparatorItem::BSeparatorItem; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BSeparatorItem, Archive, data, deep); + } + void SetEnabled(bool enable) override { + PYBIND11_OVERLOAD(void, BSeparatorItem, SetEnabled, enable); + } +}; PYBIND11_MODULE(SeparatorItem,m) { -py::class_>(m, "BSeparatorItem") +py::class_>(m, "BSeparatorItem") .def(py::init(), "") .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BSeparatorItem::Instantiate, "", py::arg("data")) From c79c5c0704a16372aba0da99f73ec9f5c6643a91 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 16:12:56 +0100 Subject: [PATCH 085/155] Add SeparatorView.cpp and overrides --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/interface/SeparatorView.cpp | 27 ++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index 74b6dd1..e969b47 100644 --- a/Jamfile +++ b/Jamfile @@ -131,6 +131,7 @@ local sourceFiles = PopUpMenu.cpp Box.cpp SeparatorItem.cpp + SeparatorView.cpp MenuBar.cpp StatusBar.cpp CheckBox.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 537bfb0..8a6b8e5 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -41,6 +41,7 @@ from .PopUpMenu import * from .Box import * from .SeparatorItem import * +from .SeparatorView import * from .MenuBar import * from .StatusBar import * from .CheckBox import * diff --git a/bindings/interface/SeparatorView.cpp b/bindings/interface/SeparatorView.cpp index 29e264e..c75e7ce 100644 --- a/bindings/interface/SeparatorView.cpp +++ b/bindings/interface/SeparatorView.cpp @@ -10,10 +10,35 @@ namespace py = pybind11; +class PyBSeparatorView : public BSeparatorView{ + public: + using BSeparatorView::BSeparatorView; + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BSeparatorView, Archive, into, deep); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BSeparatorView, Draw, updateRect); + } + void GetPreferredSize(float* width, float* height) override { + PYBIND11_OVERLOAD(void, BSeparatorView, GetPreferredSize, width, height); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BSeparatorView, MinSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BSeparatorView, PreferredSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BSeparatorView, MaxSize); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BSeparatorView, Perform, code, data); + } +}; PYBIND11_MODULE(SeparatorView,m) { -py::class_(m, "BSeparatorView") +py::class_(m, "BSeparatorView") .def(py::init(), "", py::arg("orientation"), py::arg("border")=B_PLAIN_BORDER) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("orientation")=B_HORIZONTAL, py::arg("border")=B_FANCY_BORDER, py::arg("alignment")=BAlignment(B_ALIGN_HORIZONTAL_CENTER,B_ALIGN_VERTICAL_CENTER)) .def(py::init(), "", py::arg("name"), py::arg("labelView"), py::arg("orientation")=B_HORIZONTAL, py::arg("border")=B_FANCY_BORDER, py::arg("alignment")=BAlignment(B_ALIGN_HORIZONTAL_CENTER,B_ALIGN_VERTICAL_CENTER)) From 021ac2fcce3c8551331471a45143b6f8f5c2ade6 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 16:25:54 +0100 Subject: [PATCH 086/155] Add Alignment.cpp, Fix BSeparatorView module loading --- Jamfile | 2 ++ bindings/__init__.py | 2 ++ bindings/interface/Alignment.cpp | 6 +++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index e969b47..2148a26 100644 --- a/Jamfile +++ b/Jamfile @@ -131,6 +131,7 @@ local sourceFiles = PopUpMenu.cpp Box.cpp SeparatorItem.cpp + Alignment.cpp SeparatorView.cpp MenuBar.cpp StatusBar.cpp @@ -150,6 +151,7 @@ local sourceFiles = ScrollBar.cpp GraphicsDefs.cpp Screen.cpp + #Shape.cpp #SupportKit SupportDefs.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 8a6b8e5..ce755bc 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -41,6 +41,7 @@ from .PopUpMenu import * from .Box import * from .SeparatorItem import * +from .Alignment import * from .SeparatorView import * from .MenuBar import * from .StatusBar import * @@ -61,6 +62,7 @@ from .StringItem import * from .TabView import * from .ScrollBar import * +#from .Shape import * from .fs_attr import * diff --git a/bindings/interface/Alignment.cpp b/bindings/interface/Alignment.cpp index 2c3af56..c940fc0 100644 --- a/bindings/interface/Alignment.cpp +++ b/bindings/interface/Alignment.cpp @@ -30,10 +30,10 @@ py::class_(m, "BAlignment") .def_readwrite("vertical", &BAlignment::vertical, "") ; -m.def("__eq__", &operator==, "", py::arg("other")); +//m.def("__eq__", &operator==, "", py::arg("other")); -m.def("__ne__", &operator!=, "", py::arg("other")); +//m.def("__ne__", &operator!=, "", py::arg("other")); -m.def("operator=", &operator=, "", py::arg("other")); +//m.def("operator=", &operator=, "", py::arg("other")); } From 664587a18fd1a55f2c5d64b4c3070776da7cb7c8 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 16:49:39 +0100 Subject: [PATCH 087/155] Add Shape.cpp --- Jamfile | 2 +- bindings/__init__.py | 2 +- bindings/interface/Shape.cpp | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Jamfile b/Jamfile index 2148a26..8badf31 100644 --- a/Jamfile +++ b/Jamfile @@ -151,7 +151,7 @@ local sourceFiles = ScrollBar.cpp GraphicsDefs.cpp Screen.cpp - #Shape.cpp + Shape.cpp #SupportKit SupportDefs.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index ce755bc..9d5cab1 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -62,7 +62,7 @@ from .StringItem import * from .TabView import * from .ScrollBar import * -#from .Shape import * +from .Shape import * from .fs_attr import * diff --git a/bindings/interface/Shape.cpp b/bindings/interface/Shape.cpp index 7972ade..d82c849 100644 --- a/bindings/interface/Shape.cpp +++ b/bindings/interface/Shape.cpp @@ -5,16 +5,13 @@ #include #include +#include namespace py = pybind11; using namespace BPrivate; PYBIND11_MODULE(Shape,m) { -m.attr("ServerLink") = ServerLink; - -m.attr("PicturePlayer") = PicturePlayer; - py::class_(m, "BShapeIterator") .def(py::init(), "") .def("IterateMoveTo", &BShapeIterator::IterateMoveTo, "", py::arg("point")) @@ -48,11 +45,14 @@ py::class_(m, "BShape") .def("AddShape", &BShape::AddShape, "", py::arg("other")) .def("MoveTo", &BShape::MoveTo, "", py::arg("point")) .def("LineTo", &BShape::LineTo, "", py::arg("linePoint")) -.def("BezierTo", py::overload_cast(&BShape::BezierTo), "", py::arg("controlPoints")) +.def("BezierTo", py::overload_cast(&BShape::BezierTo), "", py::arg("controlPoints")) .def("BezierTo", py::overload_cast(&BShape::BezierTo), "", py::arg("control1"), py::arg("control2"), py::arg("endPoint")) .def("ArcTo", &BShape::ArcTo, "", py::arg("rx"), py::arg("ry"), py::arg("angle"), py::arg("largeArc"), py::arg("counterClockWise"), py::arg("point")) .def("Close", &BShape::Close, "") ; +//m.attr("ServerLink") = ServerLink; + +//m.attr("PicturePlayer") = PicturePlayer; } From 463604af828c09e731e3f4fb20fea54cf3db0514 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 17:07:22 +0100 Subject: [PATCH 088/155] Add partial Shape.cpp overrides --- bindings/interface/Shape.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bindings/interface/Shape.cpp b/bindings/interface/Shape.cpp index d82c849..c3cbbf0 100644 --- a/bindings/interface/Shape.cpp +++ b/bindings/interface/Shape.cpp @@ -10,9 +10,29 @@ namespace py = pybind11; using namespace BPrivate; +class PyBShapeIterator : public BShapeIterator{ + public: + using BShapeIterator::BShapeIterator; + status_t IterateMoveTo(BPoint* point) override { + PYBIND11_OVERLOAD(status_t, BShapeIterator, IterateMoveTo, point); + } + status_t IterateLineTo(int32 lineCount, BPoint* linePoints) override { + PYBIND11_OVERLOAD(status_t, BShapeIterator, IterateLineTo, lineCount, linePoints); + } + status_t IterateBezierTo(int32 bezierCount, BPoint* bezierPoints) override { + PYBIND11_OVERLOAD(status_t, BShapeIterator, IterateBezierTo, bezierCount, bezierPoints); + } + status_t IterateClose() override { + PYBIND11_OVERLOAD(status_t, BShapeIterator, IterateClose); + } + status_t IterateArcTo(float& rx, float& ry, float& angle, bool largeArc, bool counterClockWise, BPoint& point) override { + PYBIND11_OVERLOAD(status_t, BShapeIterator, IterateArcTo, rx, ry, angle, largeArc, counterClockWise, point); + } +}; + PYBIND11_MODULE(Shape,m) { -py::class_(m, "BShapeIterator") +py::class_(m, "BShapeIterator") .def(py::init(), "") .def("IterateMoveTo", &BShapeIterator::IterateMoveTo, "", py::arg("point")) .def("IterateLineTo", &BShapeIterator::IterateLineTo, "", py::arg("lineCount"), py::arg("linePoints")) From 6a99894338dce3d84cad786f5a4615cacf491c71 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 17:11:01 +0100 Subject: [PATCH 089/155] Add Size.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/interface/Size.cpp | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index 8badf31..18606b2 100644 --- a/Jamfile +++ b/Jamfile @@ -152,6 +152,7 @@ local sourceFiles = GraphicsDefs.cpp Screen.cpp Shape.cpp + Size.cpp #SupportKit SupportDefs.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 9d5cab1..af64a70 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -63,6 +63,7 @@ from .TabView import * from .ScrollBar import * from .Shape import * +from .Size import * from .fs_attr import * diff --git a/bindings/interface/Size.cpp b/bindings/interface/Size.cpp index 9a7e5da..00a89e0 100644 --- a/bindings/interface/Size.cpp +++ b/bindings/interface/Size.cpp @@ -35,10 +35,10 @@ py::class_(m, "BSize") .def_readwrite("height", &BSize::height, "") ; -m.def("__eq__", &operator==, "", py::arg("other")); +//m.def("__eq__", &operator==, "", py::arg("other")); -m.def("__ne__", &operator!=, "", py::arg("other")); +//m.def("__ne__", &operator!=, "", py::arg("other")); -m.def("operator=", &operator=, "", py::arg("other")); +//m.def("operator=", &operator=, "", py::arg("other")); } From 1929555b12ea10764100801f65e5582d6e6c4fb4 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 17:32:21 +0100 Subject: [PATCH 090/155] Fix enum set_font_mask --- bindings/interface/View.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index eb68676..b1592da 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -58,7 +58,19 @@ m.attr("B_FULL_POINTER_HISTORY") = 8; m.attr("B_TRACK_WHOLE_RECT") = 0; m.attr("B_TRACK_RECT_CORNER") = 1; - +py::enum_ (m, "set_font_mask", "") +.value("B_FONT_FAMILY_AND_STYLE", set_font_mask::B_FONT_FAMILY_AND_STYLE, "") +.value("B_FONT_SIZE", set_font_mask::B_FONT_SIZE, "") +.value("B_FONT_SHEAR", set_font_mask::B_FONT_SHEAR, "") +.value("B_FONT_ROTATION", set_font_mask::B_FONT_ROTATION, "") +.value("B_FONT_SPACING", set_font_mask::B_FONT_SPACING, "") +.value("B_FONT_ENCODING", set_font_mask::B_FONT_ENCODING, "") +.value("B_FONT_FACE", set_font_mask::B_FONT_FACE, "") +.value("B_FONT_FLAGS", set_font_mask::B_FONT_FLAGS, "") +.value("B_FONT_FALSE_BOLD_WIDTH", set_font_mask::B_FONT_FALSE_BOLD_WIDTH, "") +.value("B_FONT_ALL", set_font_mask::B_FONT_ALL, "") +.export_values(); +/* m.attr("B_FONT_FAMILY_AND_STYLE") = 1; m.attr("B_FONT_SIZE") = 2; m.attr("B_FONT_SHEAR") = 4; @@ -69,6 +81,7 @@ m.attr("B_FONT_FACE") = 64; m.attr("B_FONT_FLAGS") = 128; m.attr("B_FONT_FALSE_BOLD_WIDTH") = 256; m.attr("B_FONT_ALL") = 511; +*/ py::enum_(m, "coordinate_space", "") .value("B_CURRENT_STATE_COORDINATES", coordinate_space::B_CURRENT_STATE_COORDINATES, "") From 82337989d0296a6a627532d4107d93b7dd3b2786 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 17:37:05 +0100 Subject: [PATCH 091/155] Fix set_font_mask B_FONT_ALL --- bindings/interface/ListView.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/interface/ListView.cpp b/bindings/interface/ListView.cpp index 1f7615f..6a22183 100644 --- a/bindings/interface/ListView.cpp +++ b/bindings/interface/ListView.cpp @@ -183,8 +183,7 @@ py::class_(&BListView::ScrollTo), "", py::arg("where")) .def("ScrollTo", py::overload_cast(&BListView::ScrollTo), "", py::arg("x"), py::arg("y")) .def("AddItem", py::overload_cast(&BListView::AddItem), "", py::arg("item")) From 28aa8aa1b5d747efc0cc81facdf6d5bbf5ac58f1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 17:51:33 +0100 Subject: [PATCH 092/155] Fix set_font_mask B_FONT_ALL --- bindings/interface/TextView.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 983e493..e54845e 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include namespace py = pybind11; using namespace BPrivate; @@ -85,9 +87,9 @@ py::class_>(m, "BTextV .def("Select", &BTextView::Select, "", py::arg("startOffset"), py::arg("endOffset")) .def("SelectAll", &BTextView::SelectAll, "") .def("GetSelection", &BTextView::GetSelection, "", py::arg("_start"), py::arg("_end")) -.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("font"), py::arg("mode")=511, py::arg("color")=NULL) //hadcoded B_FONT_ALL 511 +.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) //.def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) -.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=511, py::arg("color")=NULL) +.def("SetFontAndColor", static_cast(&BTextView::SetFontAndColor), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) //.def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) .def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("offset"), py::arg("_font"), py::arg("_color")=NULL) .def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("_font"), py::arg("_mode"), py::arg("_color")=NULL, py::arg("_sameColor")=NULL) From ee0d85c7ce29b2bd2571e1c6cb42e8aaba45348b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 17:52:22 +0100 Subject: [PATCH 093/155] Remove unused includes --- bindings/interface/TextView.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index e54845e..842e46c 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include namespace py = pybind11; using namespace BPrivate; From 98c932590b4c142c0d4e4e52fba9ba89cf3d73e4 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 18:27:36 +0100 Subject: [PATCH 094/155] Add StatusBar.cpp overrides --- bindings/interface/StatusBar.cpp | 96 +++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/bindings/interface/StatusBar.cpp b/bindings/interface/StatusBar.cpp index 1a5340d..3cb11e2 100644 --- a/bindings/interface/StatusBar.cpp +++ b/bindings/interface/StatusBar.cpp @@ -9,10 +9,104 @@ namespace py = pybind11; +class PyBStatusBar : public BStatusBar{ + public: + using BStatusBar::BStatusBar; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BStatusBar, Archive, archive, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BStatusBar, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BStatusBar, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BStatusBar, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BStatusBar, AllDetached); + } + void WindowActivated(bool state) override { + PYBIND11_OVERLOAD(void, BStatusBar, WindowActivated, state); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BStatusBar, MakeFocus, focus); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BStatusBar, GetPreferredSize, _width, _height); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BStatusBar, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BStatusBar, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BStatusBar, PreferredSize); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BStatusBar, ResizeToPreferred); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BStatusBar, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BStatusBar, FrameResized, newWidth, newHeight); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BStatusBar, Draw, updateRect); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BStatusBar, MessageReceived, message); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BStatusBar, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BStatusBar, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BStatusBar, MouseMoved, where, transit, dragMessage); + } + void SetBarColor(rgb_color color) override { + PYBIND11_OVERLOAD(void, BStatusBar, SetBarColor, color); + } + void SetBarHeight(float height) override { + PYBIND11_OVERLOAD(void, BStatusBar, SetBarHeight, height); + } + void SetText(const char* string) override { + PYBIND11_OVERLOAD(void, BStatusBar, SetText, string); + } + void SetTrailingText(const char* string) override { + PYBIND11_OVERLOAD(void, BStatusBar, SetTrailingText, string); + } + void SetMaxValue(float max) override { + PYBIND11_OVERLOAD(void, BStatusBar, SetMaxValue, max); + } + void Update(float delta, const char* text = NULL, const char* trailingText = NULL) override { + PYBIND11_OVERLOAD(void, BStatusBar, Update, delta, text, trailingText); + } + void Reset(const char* label = NULL, const char* trailingLabel = NULL) override { + PYBIND11_OVERLOAD(void, BStatusBar, Reset, label, trailingLabel); + } + void SetTo(float value, const char* text = NULL, const char* trailingText = NULL) override { + PYBIND11_OVERLOAD(void, BStatusBar, SetTo, value, text, trailingText); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BStatusBar, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BStatusBar, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BStatusBar, Perform, code, data); + } +}; PYBIND11_MODULE(StatusBar,m) { -py::class_>(m, "BStatusBar") +py::class_>(m, "BStatusBar") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label")=NULL, py::arg("trailingLabel")=NULL) .def(py::init(), "", py::arg("name"), py::arg("label")=NULL, py::arg("trailingLabel")=NULL) .def(py::init(), "", py::arg("archive")) From 88642f824b438fc8d634dcd510171b973fadf574 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 18:29:30 +0100 Subject: [PATCH 095/155] Add Slider.cpp --- Jamfile | 2 +- bindings/__init__.py | 2 +- bindings/interface/Slider.cpp | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Jamfile b/Jamfile index 18606b2..2966dcb 100644 --- a/Jamfile +++ b/Jamfile @@ -143,7 +143,6 @@ local sourceFiles = ScrollView.cpp ListItem.cpp Bitmap.cpp - #Slider.cpp Picture.cpp PictureButton.cpp StringItem.cpp @@ -153,6 +152,7 @@ local sourceFiles = Screen.cpp Shape.cpp Size.cpp + Slider.cpp #SupportKit SupportDefs.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index af64a70..d25e7cb 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -56,7 +56,6 @@ from .Archivable import * from .ListItem import * from .Bitmap import * -#from .Slider import * from .Picture import * from .PictureButton import * from .StringItem import * @@ -64,6 +63,7 @@ from .ScrollBar import * from .Shape import * from .Size import * +from .Slider import * from .fs_attr import * diff --git a/bindings/interface/Slider.cpp b/bindings/interface/Slider.cpp index 4c30a1d..445b1d7 100644 --- a/bindings/interface/Slider.cpp +++ b/bindings/interface/Slider.cpp @@ -4,7 +4,9 @@ #include #include +#include #include +#include namespace py = pybind11; From d3c40b1a1ff88783b3c1074b98a6286963ae34fb Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 19:09:14 +0100 Subject: [PATCH 096/155] Add partial Slider.cpp overrides --- bindings/interface/Slider.cpp | 175 +++++++++++++++++++++++++++++++++- 1 file changed, 174 insertions(+), 1 deletion(-) diff --git a/bindings/interface/Slider.cpp b/bindings/interface/Slider.cpp index 445b1d7..b63d9a1 100644 --- a/bindings/interface/Slider.cpp +++ b/bindings/interface/Slider.cpp @@ -10,6 +10,179 @@ namespace py = pybind11; +class PyBSlider : public BSlider{ + public: + using BSlider::BSlider; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BSlider, Archive, archive, deep); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BSlider, Perform, code, data); + } + void WindowActivated(bool state) override { + PYBIND11_OVERLOAD(void, BSlider, WindowActivated, state); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BSlider, AttachedToWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BSlider, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BSlider, AllDetached); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BSlider, DetachedFromWindow); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BSlider, MessageReceived, message); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BSlider, FrameMoved, newPosition); + } + void FrameResized(float width, float height) override { + PYBIND11_OVERLOAD(void, BSlider, FrameResized, width, height); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BSlider, KeyDown, bytes, numBytes); + } + void KeyUp(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BSlider, KeyUp, bytes, numBytes); + } + void MouseDown(BPoint point) override { + PYBIND11_OVERLOAD(void, BSlider, MouseDown, point); + } + void MouseUp(BPoint point) override { + PYBIND11_OVERLOAD(void, BSlider, MouseUp, point); + } + void MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BSlider, MouseMoved, point, transit, dragMessage); + } + void Pulse() override { + PYBIND11_OVERLOAD(void, BSlider, Pulse); + } + void SetLabel(const char* label) override { + PYBIND11_OVERLOAD(void, BSlider, SetLabel, label); + } + void SetLimitLabels(const char* minLabel, const char* maxLabel) override { + PYBIND11_OVERLOAD(void, BSlider, SetLimitLabels, minLabel, maxLabel); + } + void SetValue(int32 value) override { + PYBIND11_OVERLOAD(void, BSlider, SetValue, value); + } + int32 ValueForPoint(BPoint point) const override { + PYBIND11_OVERLOAD(int32, BSlider, ValueForPoint, point); + } + //void SetPosition(float) + void SetEnabled(bool on) override { + PYBIND11_OVERLOAD(void, BSlider, SetEnabled, on); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BSlider, Draw, updateRect); + } + void DrawSlider() override { + PYBIND11_OVERLOAD(void, BSlider, DrawSlider); + } + void DrawBar() override { + PYBIND11_OVERLOAD(void, BSlider, DrawBar); + } + void DrawHashMarks() override { + PYBIND11_OVERLOAD(void, BSlider, DrawHashMarks); + } + void DrawThumb() override { + PYBIND11_OVERLOAD(void, BSlider, DrawThumb); + } + void DrawFocusMark() override { + PYBIND11_OVERLOAD(void, BSlider, DrawFocusMark); + } + void DrawText() override { + PYBIND11_OVERLOAD(void, BSlider, DrawText); + } + const char* UpdateText() const override { + PYBIND11_OVERLOAD(const char*, BSlider, UpdateText); + } + BRect BarFrame() const override { + PYBIND11_OVERLOAD(BRect, BSlider, BarFrame); + } + BRect HashMarksFrame() const override { + PYBIND11_OVERLOAD(BRect, BSlider, HashMarksFrame); + } + BRect ThumbFrame() const override { + PYBIND11_OVERLOAD(BRect, BSlider, ThumbFrame); + } + void SetFlags(uint32 flags) override { + PYBIND11_OVERLOAD(void, BSlider, SetFlags, flags); + } + void SetResizingMode(uint32 mode) override { + PYBIND11_OVERLOAD(void, BSlider, SetResizingMode, mode); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BSlider, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BSlider, ResizeToPreferred); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BSlider, Invoke, message); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BSlider, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BSlider, GetSupportedSuites, data); + } + void SetModificationMessage(BMessage* message) override { + PYBIND11_OVERLOAD(void, BSlider, SetModificationMessage, message); + } + void SetSnoozeAmount(int32 microSeconds) override { + PYBIND11_OVERLOAD(void, BSlider, SetSnoozeAmount, microSeconds); + } + void SetKeyIncrementValue(int32 value) override { + PYBIND11_OVERLOAD(void, BSlider, SetKeyIncrementValue, value); + } + void SetHashMarkCount(int32 count) override { + PYBIND11_OVERLOAD(void, BSlider, SetHashMarkCount, count); + } + void SetHashMarks(hash_mark_location where) override { + PYBIND11_OVERLOAD(void, BSlider, SetHashMarks, where); + } + void SetStyle(thumb_style style) override { + PYBIND11_OVERLOAD(void, BSlider, SetStyle, style); + } + void SetBarColor(rgb_color color) override { + PYBIND11_OVERLOAD(void, BSlider, SetBarColor, color); + } + void UseFillColor(bool useFill, const rgb_color* color = NULL) override { + PYBIND11_OVERLOAD(void, BSlider, UseFillColor, useFill, color); + } + //void SetOrientation(orientation) override { + // PYBIND11_OVERLOAD(void, BSlider, SetOrientation); + //} + void SetBarThickness(float thickness) override { + PYBIND11_OVERLOAD(void, BSlider, SetBarThickness, thickness); + } + void SetFont(const BFont* font, uint32 properties = B_FONT_ALL) override { + PYBIND11_OVERLOAD(void, BSlider, SetFont, font, properties); + } + void SetLimits(int32 minimum, int32 maximum) override { + PYBIND11_OVERLOAD(void, BSlider, SetLimits, minimum, maximum); + } + float MaxUpdateTextWidth() override { + PYBIND11_OVERLOAD(float, BSlider, MaxUpdateTextWidth); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BSlider, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BSlider, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BSlider, PreferredSize); + } + status_t SetIcon(const BBitmap* icon, uint32 flags = 0) override { + PYBIND11_OVERLOAD(status_t, BSlider, SetIcon, icon, flags); + } +}; PYBIND11_MODULE(Slider,m) { @@ -27,7 +200,7 @@ py::enum_(m, "thumb_style", "") .value("B_TRIANGLE_THUMB", thumb_style::B_TRIANGLE_THUMB, "") .export_values(); -py::class_(m, "BSlider") +py::class_(m, "BSlider") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("minValue"), py::arg("maxValue"), py::arg("thumbType")=B_BLOCK_THUMB, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS) .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("minValue"), py::arg("maxValue"), py::arg("posture"), py::arg("thumbType")=B_BLOCK_THUMB, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("minValue"), py::arg("maxValue"), py::arg("posture"), py::arg("thumbType")=B_BLOCK_THUMB, py::arg("flags")=B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS) From 53606ba6eadf7a075e200dd0ea0ec9bf19943b48 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 19:19:37 +0100 Subject: [PATCH 097/155] Add StringItem.cpp overrides --- bindings/interface/StringItem.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bindings/interface/StringItem.cpp b/bindings/interface/StringItem.cpp index 4636a2e..b9ccf7a 100644 --- a/bindings/interface/StringItem.cpp +++ b/bindings/interface/StringItem.cpp @@ -9,18 +9,30 @@ #include namespace py = pybind11; -/* + class PyStringItem : public BStringItem{ public: using BStringItem::BStringItem; - void DrawItem(BView* owner, BRect frame, bool complete = false) override { + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BStringItem, Archive, archive, deep); + } + void DrawItem(BView* owner, BRect frame, bool complete = false) override { PYBIND11_OVERLOAD(void, BStringItem, DrawItem, owner, frame, complete); } + void SetText(const char* text) override { + PYBIND11_OVERLOAD(void, BStringItem, SetText, text); + } + void Update(BView* owner, const BFont* font) override { + PYBIND11_OVERLOAD(void, BStringItem, Update, owner, font); + } + status_t Perform(perform_code code, void* arg) override { + PYBIND11_OVERLOAD(status_t, BStringItem, Perform, code, arg); + } // TODO: there may be more methods that we should allow overloading private: BStringItem* item_; }; -*/ + PYBIND11_MODULE(StringItem,m) { py::class_>(m, "BStringItem") From ec608d7db14b257008e13b80933f83bd57403598 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 20:26:30 +0100 Subject: [PATCH 098/155] Add StringView.cpp overrides --- bindings/interface/StringView.cpp | 74 ++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/bindings/interface/StringView.cpp b/bindings/interface/StringView.cpp index 53e2631..62ce618 100644 --- a/bindings/interface/StringView.cpp +++ b/bindings/interface/StringView.cpp @@ -8,9 +8,81 @@ namespace py = pybind11; +class PyBStringView : public BStringView{ + public: + using BStringView::BStringView; + + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BStringView, Archive, archive, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BStringView, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BStringView, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BStringView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BStringView, AllDetached); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BStringView, MakeFocus, focus); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BStringView, GetPreferredSize, _width, _height); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BStringView, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BStringView, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BStringView, PreferredSize); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BStringView, ResizeToPreferred); + } + BAlignment LayoutAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BStringView, LayoutAlignment); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BStringView, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BStringView, FrameResized, newWidth, newHeight); + } + void Draw(BRect bounds) override { + PYBIND11_OVERLOAD(void, BStringView, Draw, bounds); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BStringView, MessageReceived, message); + } + void MouseDown(BPoint point) override { + PYBIND11_OVERLOAD(void, BStringView, MouseDown, point); + } + void MouseUp(BPoint point) override { + PYBIND11_OVERLOAD(void, BStringView, MouseUp, point); + } + void MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BStringView, MouseMoved, point, transit, dragMessage); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BStringView, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BStringView, GetSupportedSuites, data); + } + void SetFont(const BFont* font, uint32 mask = B_FONT_ALL) override { + PYBIND11_OVERLOAD(void, BStringView, SetFont, font, mask); + } +}; + PYBIND11_MODULE(StringView,m) { -py::class_>(m, "BStringView") +py::class_>(m, "BStringView") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("text"), py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW) .def(py::init(), "", py::arg("name"), py::arg("text"), py::arg("flags")=B_WILL_DRAW) .def(py::init(), "", py::arg("archive")) From 0dfcaac825b87c4a0bd3c5f8134f62d08eb87185 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 08:42:51 +0100 Subject: [PATCH 099/155] Update tmtest.py --- tmtest.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tmtest.py b/tmtest.py index d408674..3fcb07c 100644 --- a/tmtest.py +++ b/tmtest.py @@ -130,7 +130,7 @@ def __init__(self): self.panel = BView(self.Bounds(), "panel", 8, 20000000) self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) self.panel3 = BView(self.Bounds(), "panel2", 8, 20000000) - self.box = BBox(BRect(200,26,280,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) + self.box = BBox(BRect(200,30,280,55),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.box2 = BBox(BRect(10,10,self.panel2.Bounds().Width()-20,40),"MYBox2",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) self.panel2.AddChild(self.box2,None) #self.box.SetHighColor(0, 200, 0, 0) @@ -138,9 +138,9 @@ def __init__(self): #paternale.data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] #self.box.FillRect(self.box.Bounds(),paternale.toPattern()) self.bar = BMenuBar(self.panel.Bounds(), 'Bar') - self.testo = BStringView(BRect(5,5,75,20), 'Test','prova') + self.testo = BStringView(BRect(6,8,75,22), 'Test','prova') self.box.AddChild(self.testo,None) - self.statbar = BStatusBar(BRect(10,70,bounds.Width()/3-15,144), 'progress','0%', '100%') + self.statbar = BStatusBar(BRect(10,70,bounds.Width()/2-15,144), 'progress','Progress: ', '') self.statbar.SetMaxValue(100.0) self.tachetest=BTextControl(BRect(57,bounds.Height()-30,bounds.Width()-57,bounds.Height()-12),'TxTCtrl', "prova:",None,BMessage(1),0x0202|0x0404) self.tachetest.SetDivider(55.0) @@ -151,15 +151,14 @@ def __init__(self): self.sevenradio = BRadioButton(BRect(8,240,28,260),'tepidradio', 'tepid', BMessage(7)) self.nineradio = BRadioButton(BRect(8,260,28,280),'coolradio', 'cool', BMessage(9)) scrn = BScreen(self) - outimg = scrn.GetBitmap(True,BRect(0,0,200,200)) - if not outimg[1]: - img1 = outimg[0] - print(img1.Bits()) + img1,retu = scrn.GetBitmap(True,BRect(0,0,200,200)) + if not retu: + #print(img1.Bits()) print(img1.Flags()) print(img1.BitsLength()) img2=BBitmap(self.panel2.Bounds(),color_space.B_RGBA32) #img2.ImportBits(img1) - img2, reto = scrn.GetBitmap(True,self.panel3.Bounds()) + img2,reto = scrn.GetBitmap(True,self.panel3.Bounds()) if not reto: self.PicBox = PBox(self.panel3.Bounds(),"PictureBox",img2) self.panel3.AddChild(self.PicBox,None) @@ -168,7 +167,7 @@ def __init__(self): #img=BTranslationUtils.GetBitmap(link) #link2=sys.path[0]+"/help/minusmined.bmp" #img2=BTranslationUtils.GetBitmap(link2) - if outimg[1]+reto == 0: + if retu+reto == 0: self.fadBtn = PBut(BRect(50, 220, 86, 256), "Quit","⎆", BMessage(2),img1,img2)#img2,img)AppDefs.B_QUIT_REQUESTED self.panel.AddChild(self.fadBtn,None) # Handling colors################## @@ -186,8 +185,7 @@ def __init__(self): #bup.Play(arrgh,len(arrgh),None) bdown=BPicture() butupdown=BPictureButton(BRect(bounds.Width()-32,180,bounds.Width()-16,196),"TwoStateButt",bup,bdown,BMessage(333),picture_button_behavior.B_TWO_STATE_BUTTON) - - + self.list = ScrollView(BRect(8 , 300, bounds.Width() - 18 , bounds.Height() - 42 ), 'ScrollView') global newsitem # TODO: newsitem (defined below) seems to be freed by Python as soon From 0faa10f9aaabef072591a9b7108b812bca124921 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 09:19:00 +0100 Subject: [PATCH 100/155] Add TabView.cpp overrides --- bindings/interface/TabView.cpp | 161 ++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 2 deletions(-) diff --git a/bindings/interface/TabView.cpp b/bindings/interface/TabView.cpp index f7680c5..5771e59 100644 --- a/bindings/interface/TabView.cpp +++ b/bindings/interface/TabView.cpp @@ -8,6 +8,163 @@ namespace py = pybind11; +class PyBTab : public BTab{ + public: + using BTab::BTab; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BTab, Archive, data, deep); + } + status_t Perform(uint32 d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BTab, Perform, d, arg); + } + void SetLabel(const char* label) override { + PYBIND11_OVERLOAD(void, BTab, SetLabel, label); + } + void Select(BView* owner) override { + PYBIND11_OVERLOAD(void, BTab, Select, owner); + } + void Deselect() override { + PYBIND11_OVERLOAD(void, BTab, Deselect); + } + void SetEnabled(bool enable) override { + PYBIND11_OVERLOAD(void, BTab, SetEnabled, enable); + } + void SetView(BView* view) override { + PYBIND11_OVERLOAD(void, BTab, SetView, view); + } + void DrawFocusMark(BView* owner, BRect frame) override { + PYBIND11_OVERLOAD(void, BTab, DrawFocusMark, owner, frame); + } + void DrawLabel(BView* owner, BRect frame) override { + PYBIND11_OVERLOAD(void, BTab, DrawLabel, owner, frame); + } + void DrawTab(BView* owner, BRect frame, tab_position position, bool full = true) override { + PYBIND11_OVERLOAD(void, BTab, DrawTab, owner, frame, position, full); + } +}; + +class PyBTabView : public BTabView{ + public: + using BTabView::BTabView; + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BTabView, Archive, into, deep); + } + status_t AllUnarchived(const BMessage* from) override { + PYBIND11_OVERLOAD(status_t, BTabView, AllUnarchived, from); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BTabView, Perform, d, arg); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BTabView, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BTabView, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BTabView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BTabView, AllDetached); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BTabView, MessageReceived, message); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BTabView, KeyDown, bytes, numBytes); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BTabView, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BTabView, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BTabView, MouseMoved, where, transit, dragMessage); + } + void Pulse() override { + PYBIND11_OVERLOAD(void, BTabView, Pulse); + } + void Select(int32 index) override { + PYBIND11_OVERLOAD(void, BTabView, Select, index); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BTabView, WindowActivated, active); + } + void MakeFocus(bool focused = true) override { + PYBIND11_OVERLOAD(void, BTabView, MakeFocus, focused); + } + void SetFocusTab(int32 tab, bool focused) override { + PYBIND11_OVERLOAD(void, BTabView, SetFocusTab, tab, focused); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BTabView, Draw, updateRect); + } + BRect DrawTabs() override { + PYBIND11_OVERLOAD(BRect, BTabView, DrawTabs); + } + void DrawBox(BRect selectedTabRect) override { + PYBIND11_OVERLOAD(void, BTabView, DrawBox, selectedTabRect); + } + BRect TabFrame(int32 index) const override { + PYBIND11_OVERLOAD(BRect, BTabView, TabFrame, index); + } + void SetFlags(uint32 flags) override { + PYBIND11_OVERLOAD(void, BTabView, SetFlags, flags); + } + void SetResizingMode(uint32 mode) override { + PYBIND11_OVERLOAD(void, BTabView, SetResizingMode, mode); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BTabView, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BTabView, GetPreferredSize, _width, _height); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BTabView, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BTabView, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BTabView, PreferredSize); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BTabView, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BTabView, FrameResized, newWidth, newHeight); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BTabView, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BTabView, GetSupportedSuites, message); + } + void AddTab(BView* target, BTab* tab = NULL) override { + PYBIND11_OVERLOAD(void, BTabView, AddTab, target, tab); + } + BTab* RemoveTab(int32 tabIndex) override { + PYBIND11_OVERLOAD(BTab*, BTabView, RemoveTab, tabIndex); + } + BTab* TabAt(int32 index) const override { + PYBIND11_OVERLOAD(BTab*, BTabView, TabAt, index); + } + void SetTabWidth(button_width width) override { + PYBIND11_OVERLOAD(void, BTabView, SetTabWidth, width); + } + void SetTabHeight(float height) override { + PYBIND11_OVERLOAD(void, BTabView, SetTabHeight, height); + } + void SetBorder(border_style borderStyle) override { + PYBIND11_OVERLOAD(void, BTabView, SetBorder, borderStyle); + } + void SetTabSide(tab_side tabSide) override { + PYBIND11_OVERLOAD(void, BTabView, SetTabSide, tabSide); + } +}; + PYBIND11_MODULE(TabView,m) { @@ -17,7 +174,7 @@ py::enum_(m, "tab_position", "") .value("B_TAB_ANY", tab_position::B_TAB_ANY, "") .export_values(); -py::class_>(m, "BTab") +py::class_>(m, "BTab") .def(py::init(), "", py::arg("contentsView")=NULL) .def(py::init(), "", py::arg("archive")) .def_static("Instantiate", &BTab::Instantiate, "", py::arg("archive")) @@ -40,7 +197,7 @@ py::class_>(m, "BTab") //.def_readwrite("Private", &BTab::Private, "") ; -py::class_>(m, "BTabView") +py::class_>(m, "BTabView") .def(py::init(), "", py::arg("name"), py::arg("width")=B_WIDTH_FROM_WIDEST, py::arg("flags")=B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW | B_NAVIGABLE_JUMP | B_FRAME_EVENTS | B_NAVIGABLE) .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("width")=B_WIDTH_AS_USUAL, py::arg("resizeMask")=B_FOLLOW_ALL, py::arg("flags")=B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW | B_NAVIGABLE_JUMP | B_FRAME_EVENTS | B_NAVIGABLE) .def(py::init(), "", py::arg("archive")) From e96c8fd308fcd7f5e595c7e04d2720cad048410d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 22:03:46 +0100 Subject: [PATCH 101/155] Add TextControl.cpp overrides --- bindings/interface/TextControl.cpp | 99 +++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/bindings/interface/TextControl.cpp b/bindings/interface/TextControl.cpp index 514de1a..dfdcda4 100644 --- a/bindings/interface/TextControl.cpp +++ b/bindings/interface/TextControl.cpp @@ -11,11 +11,104 @@ namespace py = pybind11; using namespace BPrivate; +class PyBTextControl : public BTextControl{ + public: + using BTextControl::BTextControl; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BTextControl, Archive, archive, deep); + } + void SetText(const char* text) override { + PYBIND11_OVERLOAD(void, BTextControl, SetText, text); + } + void SetValue(int32 value) override { + PYBIND11_OVERLOAD(void, BTextControl, SetValue, value); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BTextControl, Invoke, message); + } + void SetModificationMessage(BMessage* message) override { + PYBIND11_OVERLOAD(void, BTextControl, SetModificationMessage, message); + } + void SetAlignment(alignment label, alignment text) override { + PYBIND11_OVERLOAD(void, BTextControl, SetAlignment, label, text); + } + void SetDivider(float position) override { + PYBIND11_OVERLOAD(void, BTextControl, SetDivider, position); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BTextControl, Draw, updateRect); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BTextControl, MouseDown, where); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BTextControl, AttachedToWindow); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BTextControl, MakeFocus, focus); + } + void SetEnabled(bool enable) override { + PYBIND11_OVERLOAD(void, BTextControl, SetEnabled, enable); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BTextControl, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BTextControl, FrameResized, newWidth, newHeight); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BTextControl, WindowActivated, active); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BTextControl, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BTextControl, ResizeToPreferred); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BTextControl, MessageReceived, message); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BTextControl, ResolveSpecifier, message, index, specifier, what, property); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BTextControl, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BTextControl, MouseMoved, where, transit, dragMessage); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BTextControl, DetachedFromWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BTextControl, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BTextControl, AllDetached); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BTextControl, GetSupportedSuites, data); + } + void SetFlags(uint32 flags) override { + PYBIND11_OVERLOAD(void, BTextControl, SetFlags, flags); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BTextControl, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BTextControl, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BTextControl, PreferredSize); + } + BAlignment LayoutAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BTextControl, LayoutAlignment); + } +}; + PYBIND11_MODULE(TextControl,m) { - - -py::class_>(m, "BTextControl") +py::class_>(m, "BTextControl") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("initialText"), py::arg("message"), py::arg("resizeMask")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("initialText"), py::arg("message"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("label"), py::arg("initialText"), py::arg("message")) From b1381d23c6142adaa7d913a9cc0b5488a8283500 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 22:22:54 +0100 Subject: [PATCH 102/155] Add TextView.cpp overrides --- bindings/interface/TextView.cpp | 94 ++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 842e46c..c464fa3 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -14,6 +14,98 @@ namespace py = pybind11; using namespace BPrivate; +class PyBTextView : public BTextView{ + public: + using BTextView::BTextView; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BTextView, Archive, archive, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BTextView, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BTextView, DetachedFromWindow); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BTextView, Draw, updateRect); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BTextView, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BTextView, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BTextView, MouseMoved, where, code, dragMessage); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BTextView, WindowActivated, active); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BTextView, KeyDown, bytes, numBytes); + } + void Pulse() override { + PYBIND11_OVERLOAD(void, BTextView, Pulse); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BTextView, FrameResized, newWidth, newHeight); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BTextView, MakeFocus, focus); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BTextView, MessageReceived, message); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BTextView, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BTextView, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BTextView, Perform, code, data); + } + void Cut(BClipboard* clipboard) override { + PYBIND11_OVERLOAD(void, BTextView, Cut, clipboard); + } + void Copy(BClipboard* clipboard) override { + PYBIND11_OVERLOAD(void, BTextView, Copy, clipboard); + } + void Paste(BClipboard* clipboard) override { + PYBIND11_OVERLOAD(void, BTextView, Paste, clipboard); + } + bool AcceptsPaste(BClipboard* clipboard) override { + PYBIND11_OVERLOAD(bool, BTextView, AcceptsPaste, clipboard); + } + bool AcceptsDrop(const BMessage* message) override { + PYBIND11_OVERLOAD(bool, BTextView, AcceptsDrop, message); + } + void Select(int32 startOffset, int32 endOffset) override { + PYBIND11_OVERLOAD(void, BTextView, Select, startOffset, endOffset); + } + void FindWord(int32 offset, int32* _fromOffset, int32* _toOffset) override { + PYBIND11_OVERLOAD(void, BTextView, FindWord, offset, _fromOffset, _toOffset); + } + bool CanEndLine(int32 offset) override { + PYBIND11_OVERLOAD(bool, BTextView, CanEndLine, offset); + } + void ScrollToOffset(int32 offset) override { + PYBIND11_OVERLOAD(void, BTextView, ScrollToOffset, offset); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BTextView, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BTextView, GetPreferredSize, _width, _height); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BTextView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BTextView, AllDetached); + } +}; + PYBIND11_MODULE(TextView,m) { py::enum_(m, "undo_state", "") @@ -38,7 +130,7 @@ py::class_(m, "text_run_array") .def_readonly("runs", &text_run_array::runs, "") ; -py::class_>(m, "BTextView") +py::class_>(m, "BTextView") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("textRect"), py::arg("resizeMask"), py::arg("flags")=B_WILL_DRAW | B_PULSE_NEEDED) .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("textRect"), py::arg("initialFont"), py::arg("initialColor"), py::arg("resizeMask"), py::arg("flags")) .def(py::init(), "", py::arg("name"), py::arg("flags")=B_WILL_DRAW | B_PULSE_NEEDED) From 1fb82c73c19535646d1037b55f0ff422138ae830 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 22:33:53 +0100 Subject: [PATCH 103/155] Complete Slider.cpp overrides --- bindings/interface/Slider.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bindings/interface/Slider.cpp b/bindings/interface/Slider.cpp index b63d9a1..0afbe18 100644 --- a/bindings/interface/Slider.cpp +++ b/bindings/interface/Slider.cpp @@ -73,7 +73,9 @@ class PyBSlider : public BSlider{ int32 ValueForPoint(BPoint point) const override { PYBIND11_OVERLOAD(int32, BSlider, ValueForPoint, point); } - //void SetPosition(float) + void SetPosition(float position) override { + PYBIND11_OVERLOAD(void, BSlider, SetPosition, position); + } void SetEnabled(bool on) override { PYBIND11_OVERLOAD(void, BSlider, SetEnabled, on); } @@ -155,9 +157,9 @@ class PyBSlider : public BSlider{ void UseFillColor(bool useFill, const rgb_color* color = NULL) override { PYBIND11_OVERLOAD(void, BSlider, UseFillColor, useFill, color); } - //void SetOrientation(orientation) override { - // PYBIND11_OVERLOAD(void, BSlider, SetOrientation); - //} + void SetOrientation(orientation orient) override { + PYBIND11_OVERLOAD(void, BSlider, SetOrientation, orient); + } void SetBarThickness(float thickness) override { PYBIND11_OVERLOAD(void, BSlider, SetBarThickness, thickness); } From 4cc3cdfa6e769532748434d7cb3a3eac9ffee3b1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 22:47:08 +0100 Subject: [PATCH 104/155] Fix rect_tracking_style enum values, Enable BeginRectTracking --- bindings/interface/View.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index b1592da..9f4e59f 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -56,8 +56,13 @@ m.attr("B_SUSPEND_VIEW_FOCUS") = 2; m.attr("B_NO_POINTER_HISTORY") = 4; m.attr("B_FULL_POINTER_HISTORY") = 8; -m.attr("B_TRACK_WHOLE_RECT") = 0; -m.attr("B_TRACK_RECT_CORNER") = 1; + +py::enum_ (m, "rect_tracking_style", "") +.value("B_TRACK_WHOLE_RECT", rect_tracking_style::B_TRACK_WHOLE_RECT, "") +.value("B_TRACK_RECT_CORNER", rect_tracking_style::B_TRACK_RECT_CORNER, "") +.export_values(); +//m.attr("B_TRACK_WHOLE_RECT") = 0; +//m.attr("B_TRACK_RECT_CORNER") = 1; py::enum_ (m, "set_font_mask", "") .value("B_FONT_FAMILY_AND_STYLE", set_font_mask::B_FONT_FAMILY_AND_STYLE, "") .value("B_FONT_SIZE", set_font_mask::B_FONT_SIZE, "") @@ -166,7 +171,7 @@ py::class_>(m, "BView") .def("FrameMoved", &BView::FrameMoved, "", py::arg("newPosition")) .def("FrameResized", &BView::FrameResized, "", py::arg("newWidth"), py::arg("newHeight")) .def("TargetedByScrollView", &BView::TargetedByScrollView, "", py::arg("scrollView")) -//.def("BeginRectTracking", &BView::BeginRectTracking, "", py::arg("startRect"), py::arg("style")=B_TRACK_WHOLE_RECT) +.def("BeginRectTracking", &BView::BeginRectTracking, "", py::arg("startRect"), py::arg("style")=B_TRACK_WHOLE_RECT) .def("EndRectTracking", &BView::EndRectTracking, "") .def("GetMouse", &BView::GetMouse, "", py::arg("location"), py::arg("buttons"), py::arg("checkMessageQueue")=true) .def("DragMessage", py::overload_cast(&BView::DragMessage), "", py::arg("message"), py::arg("dragRect"), py::arg("replyTo")=NULL) @@ -307,8 +312,6 @@ py::class_>(m, "BView") .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("pattern")=B_SOLID_HIGH) .def("FillShape", py::overload_cast(&BView::FillShape), "", py::arg("shape"), py::arg("gradient")) .def("CopyBits", &BView::CopyBits, "", py::arg("src"), py::arg("dst")) - -//from here check if they work as BBitmap is not implemented .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect"), py::arg("options")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("bitmapRect"), py::arg("viewRect")) .def("DrawBitmapAsync", py::overload_cast(&BView::DrawBitmapAsync), "", py::arg("aBitmap"), py::arg("viewRect")) @@ -321,7 +324,6 @@ py::class_>(m, "BView") .def("DrawBitmap", py::overload_cast(&BView::DrawBitmap), "", py::arg("aBitmap")) .def("DrawTiledBitmapAsync", &BView::DrawTiledBitmapAsync, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) .def("DrawTiledBitmap", &BView::DrawTiledBitmap, "", py::arg("aBitmap"), py::arg("viewRect"), py::arg("phase")=B_ORIGIN) -//to here .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar")) .def("DrawChar", py::overload_cast(&BView::DrawChar), "", py::arg("aChar"), py::arg("location")) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("delta")=NULL) From ef4adfed49d59564647a1ddada56b255dd39e3a3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 23:05:30 +0100 Subject: [PATCH 105/155] Fix module loading order, uncommnt View.cpp functions --- bindings/__init__.py | 3 ++- bindings/interface/View.cpp | 12 ++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/bindings/__init__.py b/bindings/__init__.py index d25e7cb..eec43b3 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -21,13 +21,14 @@ from .GraphicsDefs import * from .Screen import * from .Point import * +from .InterfaceDefs import * from .View import * from .Control import * from .Button import * from .TextControl import * from .Font import * from .StringView import * -from .InterfaceDefs import * + from .Alert import * from .TextView import * from .Menu import * diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 9f4e59f..5b88f48 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -175,10 +175,8 @@ py::class_>(m, "BView") .def("EndRectTracking", &BView::EndRectTracking, "") .def("GetMouse", &BView::GetMouse, "", py::arg("location"), py::arg("buttons"), py::arg("checkMessageQueue")=true) .def("DragMessage", py::overload_cast(&BView::DragMessage), "", py::arg("message"), py::arg("dragRect"), py::arg("replyTo")=NULL) -// check as soon as BBitmap works .def("DragMessage", py::overload_cast(&BView::DragMessage), "", py::arg("message"), py::arg("bitmap"), py::arg("offset"), py::arg("replyTo")=NULL) .def("DragMessage", py::overload_cast(&BView::DragMessage), "", py::arg("message"), py::arg("bitmap"), py::arg("dragMode"), py::arg("offset"), py::arg("replyTo")=NULL) -// ends here .def("FindView", &BView::FindView, "", py::arg("name")) .def("Parent", &BView::Parent, "") .def("Bounds", &BView::Bounds, "") @@ -225,13 +223,11 @@ py::class_>(m, "BView") .def("ViewColor", &BView::ViewColor, "") .def("SetViewUIColor", &BView::SetViewUIColor, "", py::arg("which"), py::arg("tint")=B_NO_TINT) .def("ViewUIColor", &BView::ViewUIColor, "", py::arg("tint")=NULL) -//.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("srcRect"), py::arg("dstRect"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) -//.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) +.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("srcRect"), py::arg("dstRect"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) +.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) .def("ClearViewBitmap", &BView::ClearViewBitmap, "") -// check as soon as BBitmap module works .def("SetViewOverlay", py::overload_cast(&BView::SetViewOverlay), "", py::arg("overlay"), py::arg("srcRect"), py::arg("dstRect"), py::arg("colorKey"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=0) .def("SetViewOverlay", py::overload_cast(&BView::SetViewOverlay), "", py::arg("overlay"), py::arg("colorKey"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=0) -// ends here .def("ClearViewOverlay", &BView::ClearViewOverlay, "") .def("SetHighColor", py::overload_cast(&BView::SetHighColor), "", py::arg("color")) .def("SetHighColor", py::overload_cast(&BView::SetHighColor), "", py::arg("red"), py::arg("green"), py::arg("blue"), py::arg("alpha")=255) @@ -332,9 +328,9 @@ py::class_>(m, "BView") .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("location"), py::arg("delta")=0) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount")) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount")) -.def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=py::int_(0x000001FF)) +//.def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=py::int_(0x000001FF)) +.def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=B_FONT_ALL) .def("GetFont", &BView::GetFont, "", py::arg("font")) - .def("TruncateString", &BView::TruncateString, "", py::arg("in_out"), py::arg("mode"), py::arg("width")) .def("StringWidth", py::overload_cast(&BView::StringWidth, py::const_), "", py::arg("string")) .def("StringWidth", py::overload_cast(&BView::StringWidth, py::const_), "", py::arg("string"), py::arg("length")) From 433e039927e3f23d2c86323acbcfe1b0f303a374 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sun, 3 Dec 2023 23:38:28 +0100 Subject: [PATCH 106/155] Add View.cpp remaining overrides --- bindings/__init__.py | 2 - bindings/interface/View.cpp | 136 +++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 4 deletions(-) diff --git a/bindings/__init__.py b/bindings/__init__.py index eec43b3..076fd94 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -28,7 +28,6 @@ from .TextControl import * from .Font import * from .StringView import * - from .Alert import * from .TextView import * from .Menu import * @@ -47,7 +46,6 @@ from .MenuBar import * from .StatusBar import * from .CheckBox import * - from .ColorControl import * from .RadioButton import * from .ListView import * diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 5b88f48..dcc0c38 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -31,9 +31,142 @@ using namespace BPrivate; class PyBView : public BView{ public: using BView::BView; - void Draw(BRect updateRect) override { + + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BView, Archive, archive, deep); + } + status_t AllUnarchived(const BMessage* archive) override { + PYBIND11_OVERLOAD(status_t, BView, AllUnarchived, archive); + } + status_t AllArchived(BMessage* archive) const override { + PYBIND11_OVERLOAD(status_t, BView, AllArchived, archive); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BView, AttachedToWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BView, AllAttached); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BView, AllAttached); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BView, MessageReceived, message); + } + void Draw(BRect updateRect) override { PYBIND11_OVERLOAD(void, BView, Draw, updateRect); } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BView, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BView, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BView, MouseMoved, where, code, dragMessage); + } + void WindowActivated(bool active) override { + PYBIND11_OVERLOAD(void, BView, WindowActivated, active); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BView, KeyDown, bytes, numBytes); + } + void KeyUp(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BView, KeyUp, bytes, numBytes); + } + void Pulse() override { + PYBIND11_OVERLOAD(void, BView, Pulse); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BView, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BView, FrameResized, newWidth, newHeight); + } + void TargetedByScrollView(BScrollView* scrollView) override { + PYBIND11_OVERLOAD(void, BView, TargetedByScrollView, scrollView); + } + void ConstrainClippingRegion(BRegion* region) override { + PYBIND11_OVERLOAD(void, BView, ConstrainClippingRegion, region); + } + void SetDrawingMode(drawing_mode mode) override { + PYBIND11_OVERLOAD(void, BView, SetDrawingMode, mode); + } + void SetPenSize(float size) override { + PYBIND11_OVERLOAD(void, BView, SetPenSize, size); + } + void SetViewColor(rgb_color color) override { + PYBIND11_OVERLOAD(void, BView, SetViewColor, color); + } + void SetHighColor(rgb_color color) override { + PYBIND11_OVERLOAD(void, BView, SetHighColor, color); + } + void SetLowColor(rgb_color color) override { + PYBIND11_OVERLOAD(void, BView, SetLowColor, color); + } + void SetFont(const BFont* font, uint32 mask = B_FONT_ALL) override { + PYBIND11_OVERLOAD(void, BView, SetFont, font, mask); + } + void SetFlags(uint32 flags) override { + PYBIND11_OVERLOAD(void, BView, SetFlags, flags); + } + void SetResizingMode(uint32 mode) override { + PYBIND11_OVERLOAD(void, BView, SetResizingMode, mode); + } + void ScrollTo(BPoint where) override { + PYBIND11_OVERLOAD(void, BView, ScrollTo, where); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BView, MakeFocus, focus); + } + void Show() override { + PYBIND11_OVERLOAD(void, BView, Show); + } + void Hide() override { + PYBIND11_OVERLOAD(void, BView, Hide); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BView, GetPreferredSize, _width, _height); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BView, ResizeToPreferred); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BView, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BView, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BView, Perform, code, data); + } + void DrawAfterChildren(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BView, DrawAfterChildren, updateRect); + } + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BView, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BView, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BView, PreferredSize); + } + BAlignment LayoutAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BView, LayoutAlignment); + } + bool HasHeightForWidth() override { + PYBIND11_OVERLOAD(bool, BView, HasHeightForWidth); + } + void GetHeightForWidth(float width, float* min, float* max, float* preferred) override { + PYBIND11_OVERLOAD(void, BView, GetHeightForWidth, width, min, max, preferred); + } + void SetLayout(BLayout* layout) override { + PYBIND11_OVERLOAD(void, BView, SetLayout, layout); + } }; @@ -328,7 +461,6 @@ py::class_>(m, "BView") .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("location"), py::arg("delta")=0) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount")) .def("DrawString", py::overload_cast(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount")) -//.def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=py::int_(0x000001FF)) .def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=B_FONT_ALL) .def("GetFont", &BView::GetFont, "", py::arg("font")) .def("TruncateString", &BView::TruncateString, "", py::arg("in_out"), py::arg("mode"), py::arg("width")) From 6236a5e5019af4fe239c9ddd2123e80f28069a50 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 08:12:27 +0100 Subject: [PATCH 107/155] Add Window.cpp remaining overrides --- bindings/interface/Window.cpp | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/bindings/interface/Window.cpp b/bindings/interface/Window.cpp index a8fb3cf..890942e 100644 --- a/bindings/interface/Window.cpp +++ b/bindings/interface/Window.cpp @@ -35,6 +35,66 @@ class PyBWindow : public BWindow{ QuitRequested, ); } + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BWindow, Archive, archive, deep); + } + void Quit() override { + PYBIND11_OVERLOAD(void, BWindow, Quit); + } + void DispatchMessage(BMessage* message, BHandler* handler) override { + PYBIND11_OVERLOAD(void, BWindow, Quit); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BWindow, FrameMoved, newPosition); + } + void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces) override { + PYBIND11_OVERLOAD(void, BWindow, WorkspacesChanged, oldWorkspaces, newWorkspaces); + } + void WorkspaceActivated(int32 workspace, bool state) override { + PYBIND11_OVERLOAD(void, BWindow, WorkspaceActivated, workspace, state); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BWindow, FrameResized, newWidth, newHeight); + } + void Minimize(bool minimize) override { + PYBIND11_OVERLOAD(void, BWindow, Minimize, minimize); + } + void Zoom(BPoint origin, float width, float height) override { + PYBIND11_OVERLOAD(void, BWindow, Zoom, origin, width, height); + } + void ScreenChanged(BRect screenSize, color_space depth) override { + PYBIND11_OVERLOAD(void, BWindow, ScreenChanged, screenSize, depth); + } + void MenusBeginning() override { + PYBIND11_OVERLOAD(void, BWindow, MenusBeginning); + } + void MenusEnded() override { + PYBIND11_OVERLOAD(void, BWindow, MenusEnded); + } + void WindowActivated(bool focus) override { + PYBIND11_OVERLOAD(void, BWindow, WindowActivated, focus); + } + void Show() override { + PYBIND11_OVERLOAD(void, BWindow, Show); + } + void Hide() override { + PYBIND11_OVERLOAD(void, BWindow, Hide); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BWindow, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BWindow, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BWindow, Perform, code, data); + } + thread_id Run() override { + PYBIND11_OVERLOAD(thread_id, BWindow, Run); + } + void SetLayout(BLayout* layout) override { + PYBIND11_OVERLOAD(void, BWindow, SetLayout, layout); + } }; void QuitWrapper(BWindow& self) { From e5cf86bf8fb5281f6b95e4bff311b9eac3a692a3 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 09:53:32 +0100 Subject: [PATCH 108/155] Fix wrong DispatchMessage override --- bindings/interface/Window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/interface/Window.cpp b/bindings/interface/Window.cpp index 890942e..f6a9472 100644 --- a/bindings/interface/Window.cpp +++ b/bindings/interface/Window.cpp @@ -42,7 +42,7 @@ class PyBWindow : public BWindow{ PYBIND11_OVERLOAD(void, BWindow, Quit); } void DispatchMessage(BMessage* message, BHandler* handler) override { - PYBIND11_OVERLOAD(void, BWindow, Quit); + PYBIND11_OVERLOAD(void, BWindow, DispatchMessage, message, handler); } void FrameMoved(BPoint newPosition) override { PYBIND11_OVERLOAD(void, BWindow, FrameMoved, newPosition); From ff4c371b7bd0ce8c93bae696f715e35fa5c7dd91 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 10:18:55 +0100 Subject: [PATCH 109/155] Add inital Application.cpp overrides --- bindings/app/Application.cpp | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index bc668e7..4707368 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -27,6 +27,46 @@ class PyBApplication : public BApplication{ bool QuitRequested() override { PYBIND11_OVERLOAD(bool, BApplication, QuitRequested); } + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BApplication, Archive, data, deep); + } + thread_id Run() override { + PYBIND11_OVERLOAD(thread_id, BApplication, Run); + } + void Quit() override { + PYBIND11_OVERLOAD(void, BApplication, Quit); + } + void Pulse() override { + PYBIND11_OVERLOAD(void, BApplication, Pulse); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BApplication, MessageReceived, message); + } + //void ArgvReceived(int32 argc, char** argv) override { + //ArgvReceivedWrapper(argc, argv); + //PYBIND11_OVERLOAD(void, BApplication, ArgvReceived, argc, argv); //look at this + //} + void AppActivated(bool active) override { + PYBIND11_OVERLOAD(void, BApplication, AppActivated, active); + } + void RefsReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BApplication, RefsReceived, message); + } + void AboutRequested() override { + PYBIND11_OVERLOAD(void, BApplication, AboutRequested); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BApplication, ResolveSpecifier, message, index, specifier, form, property); + } + void DispatchMessage(BMessage* message, BHandler* handler) override { + PYBIND11_OVERLOAD(void, BApplication, DispatchMessage, message, handler); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BApplication, GetSupportedSuites, data); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BApplication, Perform, d, arg); + } }; void RunWrapper(BApplication& self) { From 55bf2562c49700bfa358423c233898e1a32827da Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 12:30:46 +0100 Subject: [PATCH 110/155] Add Cursor.cpp overrides --- bindings/app/Cursor.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bindings/app/Cursor.cpp b/bindings/app/Cursor.cpp index fa2cd73..86ef4b1 100644 --- a/bindings/app/Cursor.cpp +++ b/bindings/app/Cursor.cpp @@ -11,6 +11,13 @@ namespace py = pybind11; +class PyBCursor : public BCursor{ + public: + using BCursor::BCursor; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BCursor, Archive, archive, deep); + } +}; PYBIND11_MODULE(Cursor,m) { @@ -46,7 +53,7 @@ py::enum_(m, "BCursorID", "") .value("B_CURSOR_ID_ZOOM_OUT", BCursorID::B_CURSOR_ID_ZOOM_OUT, "") .export_values(); -py::class_(m, "BCursor") +py::class_(m, "BCursor") .def(py::init(), "", py::arg("cursorData")) .def(py::init(), "", py::arg("other")) .def(py::init(), "", py::arg("id")) From 19eeb5b180a9404055dfbd3b1c19029de1551ba9 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 12:41:55 +0100 Subject: [PATCH 111/155] Add Handler.cpp overrides --- bindings/app/Handler.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/bindings/app/Handler.cpp b/bindings/app/Handler.cpp index c0f4034..a2cef55 100644 --- a/bindings/app/Handler.cpp +++ b/bindings/app/Handler.cpp @@ -13,11 +13,47 @@ namespace py = pybind11; using namespace BPrivate; + +class PyBHandler : public BHandler{ + public: + using BHandler::BHandler; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BHandler, Archive, data, deep); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BHandler, MessageReceived, message); + } + void SetNextHandler(BHandler* handler) override { + PYBIND11_OVERLOAD(void, BHandler, SetNextHandler, handler); + } + void AddFilter(BMessageFilter* filter) override { + PYBIND11_OVERLOAD(void, BHandler, AddFilter, filter); + } + bool RemoveFilter(BMessageFilter* filter) override { + PYBIND11_OVERLOAD(bool, BHandler, RemoveFilter, filter); + } + void SetFilterList(BList* filters) override { + PYBIND11_OVERLOAD(void, BHandler, SetFilterList, filters); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BHandler, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BHandler, GetSupportedSuites, data); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BHandler, Perform, d, arg); + } + void SendNotices(uint32 what, const BMessage* notice = NULL) override { + PYBIND11_OVERLOAD(void, BHandler, SendNotices, what, notice); + } +}; + PYBIND11_MODULE(Handler,m) { m.attr("B_OBSERVER_OBSERVE_ALL") = B_OBSERVER_OBSERVE_ALL; -py::class_(m, "BHandler") +py::class_(m, "BHandler") .def(py::init(), "", py::arg("name")=NULL) .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BHandler::Instantiate, "", py::arg("data")) From f3d8c8992f793fb3da93b9f642f2aeeb3281ab5b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 12:51:35 +0100 Subject: [PATCH 112/155] Add Invoker.cpp overrides --- bindings/app/Invoker.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bindings/app/Invoker.cpp b/bindings/app/Invoker.cpp index b518edd..29fb5a0 100644 --- a/bindings/app/Invoker.cpp +++ b/bindings/app/Invoker.cpp @@ -12,6 +12,25 @@ namespace py = pybind11; +class PyBInvoker : public BInvoker{ + public: + using BInvoker::BInvoker; + status_t SetMessage(BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BInvoker, SetMessage, message); + } + status_t SetTarget(const BHandler* handler, const BLooper* looper = NULL) override { + PYBIND11_OVERLOAD(status_t, BInvoker, SetTarget, handler, looper); + } + status_t SetTarget(BMessenger messenger) override { + PYBIND11_OVERLOAD(status_t, BInvoker, SetTarget, messenger); + } + status_t SetHandlerForReply(BHandler* handler) override { + PYBIND11_OVERLOAD(status_t, BInvoker, SetHandlerForReply, handler); + } + status_t Invoke(BMessage* message = NULL) override { + PYBIND11_OVERLOAD(status_t, BInvoker, Invoke, message); + } +}; py::tuple TargetWrapper(BInvoker& self) { BHandler* handler; @@ -24,7 +43,7 @@ py::tuple TargetWrapper(BInvoker& self) { PYBIND11_MODULE(Invoker,m) { -py::class_(m, "BInvoker") +py::class_(m, "BInvoker") .def(py::init(), "") .def(py::init(), "", py::arg("message"), py::arg("handler"), py::arg("looper")=NULL) .def(py::init(), "", py::arg("message"), py::arg("target")) From e9d5ffafff5f37d0b0895ce9d8c06a9c017f3da4 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 12:54:59 +0100 Subject: [PATCH 113/155] Revert "Add Cursor.cpp overrides" This reverts commit 55bf2562c49700bfa358423c233898e1a32827da. --- bindings/app/Cursor.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/bindings/app/Cursor.cpp b/bindings/app/Cursor.cpp index 86ef4b1..fa2cd73 100644 --- a/bindings/app/Cursor.cpp +++ b/bindings/app/Cursor.cpp @@ -11,13 +11,6 @@ namespace py = pybind11; -class PyBCursor : public BCursor{ - public: - using BCursor::BCursor; - status_t Archive(BMessage* archive, bool deep = true) const override { - PYBIND11_OVERLOAD(status_t, BCursor, Archive, archive, deep); - } -}; PYBIND11_MODULE(Cursor,m) { @@ -53,7 +46,7 @@ py::enum_(m, "BCursorID", "") .value("B_CURSOR_ID_ZOOM_OUT", BCursorID::B_CURSOR_ID_ZOOM_OUT, "") .export_values(); -py::class_(m, "BCursor") +py::class_(m, "BCursor") .def(py::init(), "", py::arg("cursorData")) .def(py::init(), "", py::arg("other")) .def(py::init(), "", py::arg("id")) From 6fc24725503135b217054c8feaec3a2c0bdfa243 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 13:19:28 +0100 Subject: [PATCH 114/155] Add Key.cpp overrides --- bindings/app/Key.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bindings/app/Key.cpp b/bindings/app/Key.cpp index fd07a3f..ad2c8bd 100644 --- a/bindings/app/Key.cpp +++ b/bindings/app/Key.cpp @@ -11,6 +11,20 @@ namespace py = pybind11; +class PyBKey : public BKey{ + public: + using BKey::BKey; + //BKeyType Type() const { return B_KEY_TYPE_GENERIC; } + status_t Flatten(BMessage& message) const override { + PYBIND11_OVERLOAD(status_t, BKey, Flatten, message); + } + status_t Unflatten(const BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BKey, Unflatten, message); + } + void PrintToStream() override { + PYBIND11_OVERLOAD(void, BKey, PrintToStream); + } +}; PYBIND11_MODULE(Key,m) { @@ -30,7 +44,7 @@ py::enum_(m, "BKeyType", "") .value("B_KEY_TYPE_CERTIFICATE", BKeyType::B_KEY_TYPE_CERTIFICATE, "") .export_values(); -py::class_(m, "BKey") +py::class_(m, "BKey") .def(py::init(), "") .def(py::init(), "", py::arg("purpose"), py::arg("identifier"), py::arg("secondaryIdentifier")=NULL, py::arg("data")=NULL, py::arg("length")=0) .def(py::init(), "") From 4ad38019fac45bf39b8ad2f339199b69c749ec88 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 15:21:35 +0100 Subject: [PATCH 115/155] Complete Key.cpp overrides --- bindings/app/Key.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bindings/app/Key.cpp b/bindings/app/Key.cpp index ad2c8bd..872bad3 100644 --- a/bindings/app/Key.cpp +++ b/bindings/app/Key.cpp @@ -14,7 +14,9 @@ namespace py = pybind11; class PyBKey : public BKey{ public: using BKey::BKey; - //BKeyType Type() const { return B_KEY_TYPE_GENERIC; } + BKeyType Type() const override { + PYBIND11_OVERLOAD(BKeyType, BKey, Type); + } status_t Flatten(BMessage& message) const override { PYBIND11_OVERLOAD(status_t, BKey, Flatten, message); } From 3f6e268246013aa1a698d5211a767d110cffd3ff Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 12:32:27 +0100 Subject: [PATCH 116/155] Assign watching_request_flags values to their enum --- bindings/app/Roster.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/app/Roster.cpp b/bindings/app/Roster.cpp index 7d60669..1643a21 100644 --- a/bindings/app/Roster.cpp +++ b/bindings/app/Roster.cpp @@ -30,10 +30,11 @@ void GetRecentDocumentsWrapper(BRoster& self, BMessage* refList, int32 maxCount, PYBIND11_MODULE(Roster,m) { +/* m.attr("B_REQUEST_LAUNCHED") = 1; m.attr("B_REQUEST_QUIT") = 2; m.attr("B_REQUEST_ACTIVATED") = 4; - +*/ m.attr("B_SOME_APP_LAUNCHED") = py::int_('BRAS'); m.attr("B_SOME_APP_QUIT") = py::int_('BRAQ'); m.attr("B_SOME_APP_ACTIVATED") = py::int_('BRAW'); @@ -47,6 +48,11 @@ py::class_(m, "app_info") .def_readwrite("ref", &app_info::ref) .def_readonly("signature", &app_info::signature) ; +py::enum_(m, "watching_request_flags", "") +.value("B_REQUEST_LAUNCHED", watching_request_flags::B_REQUEST_LAUNCHED, "") +.value("B_REQUEST_QUIT", watching_request_flags::B_REQUEST_QUIT, "") +.value("B_REQUEST_ACTIVATED", watching_request_flags::B_REQUEST_ACTIVATED, "") +.export_values(); py::class_(m, "BRoster") .def(py::init(), "") From 4991551317d5a8854fe4d8c1d1958a37b94c2e28 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Mon, 4 Dec 2023 12:35:10 +0100 Subject: [PATCH 117/155] Add Looper.cpp overrides --- bindings/app/Looper.cpp | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/bindings/app/Looper.cpp b/bindings/app/Looper.cpp index f18e89b..38b23ad 100644 --- a/bindings/app/Looper.cpp +++ b/bindings/app/Looper.cpp @@ -14,6 +14,47 @@ namespace py = pybind11; using namespace BPrivate; +class PyBLooper : public BLooper{ + public: + using BLooper::BLooper; + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BLooper, Archive, data, deep); + } + void DispatchMessage(BMessage* message, BHandler* handler) override { + PYBIND11_OVERLOAD(void, BLooper, DispatchMessage, message, handler); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BLooper, MessageReceived, message); + } + thread_id Run() override { + PYBIND11_OVERLOAD(thread_id, BLooper, Run); + } + void Quit() override { + PYBIND11_OVERLOAD(void, BLooper, Quit); + } + bool QuitRequested() override { + PYBIND11_OVERLOAD(bool, BLooper, QuitRequested); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BLooper, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BLooper, GetSupportedSuites, data); + } + void AddCommonFilter(BMessageFilter* filter) override { + PYBIND11_OVERLOAD(void, BLooper, AddCommonFilter, filter); + } + bool RemoveCommonFilter(BMessageFilter* filter) override { + PYBIND11_OVERLOAD(bool, BLooper, RemoveCommonFilter, filter); + } + void SetCommonFilterList(BList* filters) override { + PYBIND11_OVERLOAD(void, BLooper, SetCommonFilterList, filters); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BLooper, Perform, d, arg); + } +}; + void QuitWrapper(BLooper& self) { // When quit is called from the BWindow's thread, it never returns. The // thread is destroyed inside of this function. That means we need to @@ -28,7 +69,7 @@ void QuitWrapper(BLooper& self) { PYBIND11_MODULE(Looper,m) { -py::class_(m, "BLooper") +py::class_(m, "BLooper") .def(py::init(), "", py::arg("name")=NULL, py::arg("priority")=B_NORMAL_PRIORITY, py::arg("portCapacity")=B_LOOPER_PORT_DEFAULT_CAPACITY) .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BLooper::Instantiate, "", py::arg("data")) From 8ed46204ebf78c20e3634ef507948d573c0fd734 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 08:46:41 +0100 Subject: [PATCH 118/155] Add ProppertyInfo.cpp overrides --- bindings/app/PropertyInfo.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bindings/app/PropertyInfo.cpp b/bindings/app/PropertyInfo.cpp index 5063908..a07f690 100644 --- a/bindings/app/PropertyInfo.cpp +++ b/bindings/app/PropertyInfo.cpp @@ -12,6 +12,31 @@ namespace py = pybind11; +class PyBPropertyInfo : public BPropertyInfo{ + public: + using BPropertyInfo::BPropertyInfo; + int32 FindMatch(BMessage* msg, int32 index, BMessage* specifier, int32 form, const char* prop, void* data = NULL) const override { + PYBIND11_OVERLOAD(int32, BPropertyInfo, FindMatch, msg, index, specifier, form, prop, data); + } + bool IsFixedSize() const override { + PYBIND11_OVERLOAD(bool, BPropertyInfo, IsFixedSize); + } + type_code TypeCode() const override { + PYBIND11_OVERLOAD(type_code, BPropertyInfo, TypeCode); + } + ssize_t FlattenedSize() const override { + PYBIND11_OVERLOAD(ssize_t, BPropertyInfo, FlattenedSize); + } + status_t Flatten(void* buffer, ssize_t size) const override { + PYBIND11_OVERLOAD(status_t, BPropertyInfo, Flatten, buffer, size); + } + bool AllowsTypeCode(type_code code) const override { + PYBIND11_OVERLOAD(bool, BPropertyInfo, AllowsTypeCode, code); + } + status_t Unflatten(type_code code, const void* buffer, ssize_t size) override { + PYBIND11_OVERLOAD(status_t, BPropertyInfo, Unflatten, code, buffer, size); + } +}; PYBIND11_MODULE(PropertyInfo,m) { @@ -49,7 +74,7 @@ py::class_(m, "value_info") .def_readonly("_reserved", &value_info::_reserved, "") ; -py::class_(m, "BPropertyInfo") +py::class_(m, "BPropertyInfo") .def(py::init(), "", py::arg("prop")=NULL, py::arg("value")=NULL, py::arg("freeOnDelete")=false) .def("FindMatch", &BPropertyInfo::FindMatch, "", py::arg("msg"), py::arg("index"), py::arg("specifier"), py::arg("form"), py::arg("prop"), py::arg("data")=NULL) .def("IsFixedSize", &BPropertyInfo::IsFixedSize, "") From af44be5cd99125da5a16cde2cd21d6007cba4013 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 10:43:14 +0100 Subject: [PATCH 119/155] Add Architecture.cpp --- bindings/support/Architecture.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bindings/support/Architecture.cpp b/bindings/support/Architecture.cpp index 557abac..f53ca60 100644 --- a/bindings/support/Architecture.cpp +++ b/bindings/support/Architecture.cpp @@ -7,16 +7,15 @@ namespace py = pybind11; - -void define_Architecture(py::module_& m) +PYBIND11_MODULE(Architecture,m) { m.def("get_architecture", &get_architecture, ""); m.def("get_primary_architecture", &get_primary_architecture, ""); -m.def("get_secondary_architectures", py::overload_cast(&get_secondary_architectures), "", py::arg("architectures"), py::arg("count")); +//m.def("get_secondary_architectures", py::overload_cast(&get_secondary_architectures), "", py::arg("architectures"), py::arg("count")); -m.def("get_architectures", py::overload_cast(&get_architectures), "", py::arg("architectures"), py::arg("count")); +//m.def("get_architectures", py::overload_cast(&get_architectures), "", py::arg("architectures"), py::arg("count")); m.def("guess_architecture_for_path", &guess_architecture_for_path, "", py::arg("path")); From 0474cac7764dc31fb7ab17d485ccd12672c97e8f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 10:55:49 +0100 Subject: [PATCH 120/155] Add Autolock.cpp & Locker.cpp --- Jamfile | 3 +++ bindings/__init__.py | 3 +++ bindings/support/Autolock.cpp | 4 ++-- bindings/support/Locker.cpp | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index 2966dcb..ae52668 100644 --- a/Jamfile +++ b/Jamfile @@ -155,9 +155,12 @@ local sourceFiles = Slider.cpp #SupportKit + Locker.cpp + Autolock.cpp SupportDefs.cpp Archivable.cpp TypeConstants.cpp + Architecture.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 076fd94..7b13a69 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -63,6 +63,9 @@ from .Shape import * from .Size import * from .Slider import * +from .Architecture import * +from .Locker import * +#from .Autolock import * from .fs_attr import * diff --git a/bindings/support/Autolock.cpp b/bindings/support/Autolock.cpp index bfe32f7..7bd4360 100644 --- a/bindings/support/Autolock.cpp +++ b/bindings/support/Autolock.cpp @@ -8,12 +8,12 @@ namespace py = pybind11; -void define_Autolock(py::module_& m) +PYBIND11_MODULE(Autolock, m) { py::class_(m, "BAutolock") .def(py::init(), "", py::arg("looper")) .def(py::init(), "", py::arg("locker")) -.def(py::init(), "") +.def(py::init(), "", py::arg("locker")) .def("IsLocked", &BAutolock::IsLocked, "") .def("Lock", &BAutolock::Lock, "") .def("Unlock", &BAutolock::Unlock, "") diff --git a/bindings/support/Locker.cpp b/bindings/support/Locker.cpp index f5989a3..091a4d4 100644 --- a/bindings/support/Locker.cpp +++ b/bindings/support/Locker.cpp @@ -8,7 +8,7 @@ namespace py = pybind11; -void define_Locker(py::module_& m) +PYBIND11_MODULE(Locker, m) { py::class_(m, "BLocker") .def(py::init(), "") From 132b9bf1105d55729ba05e0df43d9910766281f2 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 12:27:34 +0100 Subject: [PATCH 121/155] Add DateTime.cpp --- Jamfile | 2 ++ bindings/__init__.py | 4 ++- bindings/support/DateTime.cpp | 67 ++++++++++++++++++----------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/Jamfile b/Jamfile index ae52668..10bd33f 100644 --- a/Jamfile +++ b/Jamfile @@ -155,12 +155,14 @@ local sourceFiles = Slider.cpp #SupportKit + Beep.cpp Locker.cpp Autolock.cpp SupportDefs.cpp Archivable.cpp TypeConstants.cpp Architecture.cpp + DateTime.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 7b13a69..98ff470 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -63,9 +63,11 @@ from .Shape import * from .Size import * from .Slider import * +from .Beep import * from .Architecture import * from .Locker import * -#from .Autolock import * +from .Autolock import * +from .DateTime import * from .fs_attr import * diff --git a/bindings/support/DateTime.cpp b/bindings/support/DateTime.cpp index 65489d0..c291706 100644 --- a/bindings/support/DateTime.cpp +++ b/bindings/support/DateTime.cpp @@ -4,11 +4,12 @@ #include #include +#include namespace py = pybind11; using namespace BPrivate; -void define_DateTime(py::module_& m) +PYBIND11_MODULE(DateTime, m) { py::enum_(m, "time_type", "") .value("B_GMT_TIME", time_type::B_GMT_TIME, "") @@ -23,37 +24,13 @@ py::enum_(m, "diff_type", "") .value("B_MICROSECONDS_DIFF", diff_type::B_MICROSECONDS_DIFF, "") .export_values(); -m.attr("time_type") = py::cast(time_type); - -m.attr("B_GMT_TIME") = py::cast(B_GMT_TIME); - -m.attr("B_LOCAL_TIME") = py::cast(B_LOCAL_TIME); - -m.attr("diff_type") = py::cast(diff_type); - -m.attr("B_HOURS_DIFF") = py::cast(B_HOURS_DIFF); - -m.attr("B_MINUTES_DIFF") = py::cast(B_MINUTES_DIFF); - -m.attr("B_SECONDS_DIFF") = py::cast(B_SECONDS_DIFF); - -m.attr("B_MILLISECONDS_DIFF") = py::cast(B_MILLISECONDS_DIFF); - -m.attr("B_MICROSECONDS_DIFF") = py::cast(B_MICROSECONDS_DIFF); - -m.attr("BTime") = py::cast(BTime); - -m.attr("BDate") = py::cast(BDate); - -m.attr("BDateTime") = py::cast(BDateTime); - py::class_(m, "BTime") .def(py::init(), "") .def(py::init(), "", py::arg("other")) .def(py::init(), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) .def(py::init(), "", py::arg("archive")) .def("Archive", &BTime::Archive, "", py::arg("into")) -.def("IsValid", py::overload_cast<>(&BTime::IsValid), "") +//.def("IsValid", py::overload_cast<>(&BTime::IsValid, py::const_), "") // overloading a method with both static and instance methods is not supported; .def_static("IsValid", py::overload_cast(&BTime::IsValid), "", py::arg("time")) .def_static("IsValid", py::overload_cast(&BTime::IsValid), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) .def_static("CurrentTime", &BTime::CurrentTime, "", py::arg("type")) @@ -86,7 +63,7 @@ py::class_(m, "BDate") .def(py::init(), "", py::arg("time"), py::arg("type")=B_LOCAL_TIME) .def(py::init(), "", py::arg("archive")) .def("Archive", &BDate::Archive, "", py::arg("into")) -.def("IsValid", py::overload_cast<>(&BDate::IsValid), "") +//.def("IsValid", py::overload_cast<>(&BDate::IsValid, py::const_), "") // overloading a method with both static and instance methods is not supported; .def_static("IsValid", py::overload_cast(&BDate::IsValid), "", py::arg("date")) .def_static("IsValid", py::overload_cast(&BDate::IsValid), "", py::arg("year"), py::arg("month"), py::arg("day")) .def_static("CurrentDate", &BDate::CurrentDate, "", py::arg("type")) @@ -107,19 +84,19 @@ py::class_(m, "BDate") .def("DayOfWeek", &BDate::DayOfWeek, "") .def("DayOfYear", &BDate::DayOfYear, "") .def("WeekNumber", &BDate::WeekNumber, "") -.def("IsLeapYear", py::overload_cast<>(&BDate::IsLeapYear), "") +//.def("IsLeapYear", py::overload_cast<>(&BDate::IsLeapYear, py::const_), "") .def_static("IsLeapYear", py::overload_cast(&BDate::IsLeapYear), "", py::arg("year")) .def("DaysInYear", &BDate::DaysInYear, "") .def("DaysInMonth", &BDate::DaysInMonth, "") -.def("ShortDayName", py::overload_cast<>(&BDate::ShortDayName), "") +//.def("ShortDayName", py::overload_cast<>(&BDate::ShortDayName, py::const_), "") .def_static("ShortDayName", py::overload_cast(&BDate::ShortDayName), "", py::arg("day")) -.def("ShortMonthName", py::overload_cast<>(&BDate::ShortMonthName), "") +//.def("ShortMonthName", py::overload_cast<>(&BDate::ShortMonthName, py::const_), "") .def_static("ShortMonthName", py::overload_cast(&BDate::ShortMonthName), "", py::arg("month")) -.def("LongDayName", py::overload_cast<>(&BDate::LongDayName), "") +//.def("LongDayName", py::overload_cast<>(&BDate::LongDayName, py::const_), "") .def_static("LongDayName", py::overload_cast(&BDate::LongDayName), "", py::arg("day")) -.def("LongMonthName", py::overload_cast<>(&BDate::LongMonthName), "") +//.def("LongMonthName", py::overload_cast<>(&BDate::LongMonthName, py::const_), "") .def_static("LongMonthName", py::overload_cast(&BDate::LongMonthName), "", py::arg("month")) -.def("DateToJulianDay", &BDate::DateToJulianDay, "") +//.def("DateToJulianDay", &BDate::DateToJulianDay, "") .def_static("JulianDayToDate", &BDate::JulianDayToDate, "", py::arg("julianDay")) .def("__ne__", &BDate::operator!=, "", py::arg("date")) .def("__eq__", &BDate::operator==, "", py::arg("date")) @@ -153,5 +130,29 @@ py::class_(m, "BDateTime") .def("__ge__", &BDateTime::operator>=, "", py::arg("dateTime")) ; +/* +m.attr("time_type") = py::cast(time_type); + +m.attr("B_GMT_TIME") = py::cast(B_GMT_TIME); + +m.attr("B_LOCAL_TIME") = py::cast(B_LOCAL_TIME); + +m.attr("diff_type") = py::cast(diff_type); + +m.attr("B_HOURS_DIFF") = py::cast(B_HOURS_DIFF); + +m.attr("B_MINUTES_DIFF") = py::cast(B_MINUTES_DIFF); +m.attr("B_SECONDS_DIFF") = py::cast(B_SECONDS_DIFF); + +m.attr("B_MILLISECONDS_DIFF") = py::cast(B_MILLISECONDS_DIFF); + +m.attr("B_MICROSECONDS_DIFF") = py::cast(B_MICROSECONDS_DIFF); + +m.attr("BTime") = py::cast(BTime); + +m.attr("BDate") = py::cast(BDate); + +m.attr("BDateTime") = py::cast(BDateTime); +*/ } From 7cb33862de2325b318c5c7f31f2093c25ff94557 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 12:29:16 +0100 Subject: [PATCH 122/155] Add Beep.cpp --- bindings/support/Beep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/support/Beep.cpp b/bindings/support/Beep.cpp index 6944ada..822de37 100644 --- a/bindings/support/Beep.cpp +++ b/bindings/support/Beep.cpp @@ -8,7 +8,7 @@ namespace py = pybind11; -void define_Beep(py::module_& m) +PYBIND11_MODULE(Beep, m) { m.def("beep", &beep, ""); From e660e0a2a206758cc3bc5db21b8ae476a69e78d1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 13:52:10 +0100 Subject: [PATCH 123/155] Add List.cpp --- Jamfile | 3 ++- bindings/__init__.py | 1 + bindings/support/List.cpp | 31 ++++++++++++++++++++++--------- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Jamfile b/Jamfile index 10bd33f..fd79a16 100644 --- a/Jamfile +++ b/Jamfile @@ -163,7 +163,8 @@ local sourceFiles = TypeConstants.cpp Architecture.cpp DateTime.cpp - + List.cpp + #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 98ff470..b7be631 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -68,6 +68,7 @@ from .Locker import * from .Autolock import * from .DateTime import * +from .List import * from .fs_attr import * diff --git a/bindings/support/List.cpp b/bindings/support/List.cpp index 8fb70a1..b166399 100644 --- a/bindings/support/List.cpp +++ b/bindings/support/List.cpp @@ -7,8 +7,12 @@ namespace py = pybind11; +bool CallPythonFunction(void* item, py::function& func) { + py::object result = func(item); + return py::cast(result); +} -void define_List(py::module_& m) +PYBIND11_MODULE(List, m) { py::class_(m, "BList") .def(py::init(), "", py::arg("count")=20) @@ -33,15 +37,24 @@ py::class_(m, "BList") .def("ItemAtFast", &BList::ItemAtFast, "", py::arg("index")) .def("LastItem", &BList::LastItem, "") .def("Items", &BList::Items, "") -.def("HasItem", py::overload_cast(&BList::HasItem), "", py::arg("item")) -.def("HasItem", py::overload_cast(&BList::HasItem), "", py::arg("item")) -.def("IndexOf", py::overload_cast(&BList::IndexOf), "", py::arg("item")) -.def("IndexOf", py::overload_cast(&BList::IndexOf), "", py::arg("item")) +.def("HasItem", py::overload_cast(&BList::HasItem, py::const_), "", py::arg("item")) +.def("HasItem", py::overload_cast(&BList::HasItem, py::const_), "", py::arg("item")) +.def("IndexOf", py::overload_cast(&BList::IndexOf, py::const_), "", py::arg("item")) +.def("IndexOf", py::overload_cast(&BList::IndexOf, py::const_), "", py::arg("item")) .def("CountItems", &BList::CountItems, "") .def("IsEmpty", &BList::IsEmpty, "") -.def("DoForEach", py::overload_cast(&BList::DoForEach), "", py::arg("")) -.def("DoForEach", py::overload_cast(&BList::DoForEach), "", py::arg(""), py::arg("arg2")) -; - +//.def("DoForEach", py::overload_cast(&BList::DoForEach), "", py::arg("")) +.def("DoForEach", [](BList& self,py::function& func, void* item) -> void { + self.DoForEach(static_cast(+[](void* item, void* userData) -> bool { + return CallPythonFunction(item, *static_cast(userData)); + }), item); +}, "", py::arg("func"), py::arg("item")) +//.def("DoForEach", py::overload_cast(&BList::DoForEach), "", py::arg(""), py::arg("arg2")) +.def("DoForEach", [](BList& self, py::function& func, void* arg2) -> void { + self.DoForEach(static_cast(+[](void* item, void* userData) -> bool { + return CallPythonFunction(item, *static_cast(userData)); + }), arg2); + }, "", py::arg("func"), py::arg("arg2")) +; } From 83cecaa0f2e448597ded5711aa1762a59f921e07 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 14:13:45 +0100 Subject: [PATCH 124/155] Add parsedate.cpp --- Jamfile | 1 + bindings/support/parsedate.cpp | 36 +++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Jamfile b/Jamfile index fd79a16..e900cb2 100644 --- a/Jamfile +++ b/Jamfile @@ -163,6 +163,7 @@ local sourceFiles = TypeConstants.cpp Architecture.cpp DateTime.cpp + parsedate.cpp List.cpp #Kernel diff --git a/bindings/support/parsedate.cpp b/bindings/support/parsedate.cpp index 325e590..b40e388 100644 --- a/bindings/support/parsedate.cpp +++ b/bindings/support/parsedate.cpp @@ -8,14 +8,44 @@ namespace py = pybind11; -void define_parsedate(py::module_& m) +// Funzione di esempio che accetta un array di stringhe in stile C +extern void set_dateformats(const char **table); + +// Converte uno std::vector in un array di stringhe in stile C +void set_dateformats_wrapper(const std::vector& formats) { + std::vector c_formats; + for (const auto& format : formats) { + c_formats.push_back(format.c_str()); + } + c_formats.push_back(nullptr); // Aggiunge un terminatore nullo + + set_dateformats(c_formats.data()); +} + +// Funzione di esempio che restituisce un array di stringhe in stile C +extern const char **get_dateformats(void); + +// Converte l'array di stringhe in stile C in uno std::vector +std::vector get_dateformats_wrapper() { + const char **dateformats = get_dateformats(); + std::vector result; + + // Assume che la fine dell'array sia segnata da un puntatore nullo + for (size_t i = 0; dateformats[i] != nullptr; ++i) { + result.push_back(const_cast(dateformats[i])); + } + + return result; +} + +PYBIND11_MODULE(parsedate, m) { m.def("parsedate", &parsedate, "", py::arg("dateString"), py::arg("now")); m.def("parsedate_etc", &parsedate_etc, "", py::arg("dateString"), py::arg("now"), py::arg("_storedFlags")); -m.def("set_dateformats", &set_dateformats, "", py::arg("table")); +m.def("set_dateformats", &set_dateformats_wrapper, "", py::arg("table")); -m.def("get_dateformats", &get_dateformats, "", py::arg("")); +m.def("get_dateformats", &get_dateformats_wrapper, "", py::return_value_policy::take_ownership); } From dedf7859b3c9184244a71954305055118c28ac62 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 14:53:05 +0100 Subject: [PATCH 125/155] Add String.cpp --- Jamfile | 1 + bindings/__init__.py | 2 + bindings/support/String.cpp | 160 ++++++++++++++++++------------------ 3 files changed, 85 insertions(+), 78 deletions(-) diff --git a/Jamfile b/Jamfile index e900cb2..b80e81b 100644 --- a/Jamfile +++ b/Jamfile @@ -165,6 +165,7 @@ local sourceFiles = DateTime.cpp parsedate.cpp List.cpp + String.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index b7be631..dbbeb1f 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -68,7 +68,9 @@ from .Locker import * from .Autolock import * from .DateTime import * +from .parsedate import * from .List import * +from .String import * from .fs_attr import * diff --git a/bindings/support/String.cpp b/bindings/support/String.cpp index da1e660..86c3626 100644 --- a/bindings/support/String.cpp +++ b/bindings/support/String.cpp @@ -4,11 +4,15 @@ #include #include +#include +#include +#include +#include namespace py = pybind11; -void define_String(py::module_& m) +PYBIND11_MODULE(String, m) { py::class_(m, "BString") .def(py::init(), "") @@ -21,17 +25,17 @@ py::class_(m, "BString") .def("CountChars", &BString::CountChars, "") .def("CountBytes", &BString::CountBytes, "", py::arg("fromCharOffset"), py::arg("charCount")) .def("IsEmpty", &BString::IsEmpty, "") -.def("HashValue", py::overload_cast<>(&BString::HashValue), "") -.def_static("HashValue", py::overload_cast(&BString::HashValue), "", py::arg("string")) +.def("HashValue", py::overload_cast<>(&BString::HashValue, py::const_), "") +.def_static("HashValueString", py::overload_cast(&BString::HashValue), "", py::arg("string"))// BEWARE! Name changed due to: overloading a method with both static and instance methods is not supported .def("operator=", py::overload_cast(&BString::operator=), "", py::arg("string")) .def("operator=", py::overload_cast(&BString::operator=), "", py::arg("string")) .def("operator=", py::overload_cast(&BString::operator=), "", py::arg("c")) -.def("operator=", [](BString& self) { +/*.def("operator=", [](BString& self) { BString & string; BString & r = self.operator=(string); return std::make_tuple(r,string); } -, "") +, "")*/ .def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string")) .def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string"), py::arg("maxLength")) .def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string")) @@ -57,24 +61,24 @@ py::class_(m, "BString") return std::make_tuple(r,from); } , "", py::arg("charCount")) -.def("SetToFormat", &BString::SetToFormat, "", py::arg("format")) -.def("SetToFormatVarArgs", &BString::SetToFormatVarArgs, "", py::arg("format"), py::arg("args")) -.def("ScanWithFormat", &BString::ScanWithFormat, "", py::arg("format")) -.def("ScanWithFormatVarArgs", &BString::ScanWithFormatVarArgs, "", py::arg("format"), py::arg("args")) +//.def("SetToFormat", &BString::SetToFormat, "", py::arg("format")) +//.def("SetToFormatVarArgs", &BString::SetToFormatVarArgs, "", py::arg("format"), py::arg("args")) +//.def("ScanWithFormat", &BString::ScanWithFormat, "", py::arg("format")) +//.def("ScanWithFormatVarArgs", &BString::ScanWithFormatVarArgs, "", py::arg("format"), py::arg("args")) .def("CopyInto", [](BString& self,int fromOffset,int length) { BString into; BString & r = self.CopyInto(into, fromOffset, length); return std::make_tuple(r,into); } , "", py::arg("fromOffset"), py::arg("length")) -.def("CopyInto", py::overload_cast(&BString::CopyInto), "", py::arg("into"), py::arg("fromOffset"), py::arg("length")) +.def("CopyInto", py::overload_cast(&BString::CopyInto, py::const_), "", py::arg("into"), py::arg("fromOffset"), py::arg("length")) .def("CopyCharsInto", [](BString& self,int fromCharOffset,int charCount) { BString into; BString & r = self.CopyCharsInto(into, fromCharOffset, charCount); return std::make_tuple(r,into); } , "", py::arg("fromCharOffset"), py::arg("charCount")) -.def("CopyCharsInto", py::overload_cast(&BString::CopyCharsInto), "", py::arg("into"), py::arg("intoLength"), py::arg("fromCharOffset"), py::arg("charCount")) +.def("CopyCharsInto", py::overload_cast(&BString::CopyCharsInto, py::const_), "", py::arg("into"), py::arg("intoLength"), py::arg("fromCharOffset"), py::arg("charCount")) .def("Split", [](BString& self,const char * separator,bool noEmptyStrings) { BStringList _list; bool r = self.Split(separator, noEmptyStrings, _list); @@ -136,67 +140,67 @@ py::class_(m, "BString") return std::make_tuple(r,into); } , "", py::arg("fromCharOffset"), py::arg("charCount")) -.def("MoveCharsInto", py::overload_cast(&BString::MoveCharsInto), "", py::arg("into"), py::arg("intoLength"), py::arg("fromCharOffset"), py::arg("charCount")) -.def("__lt__", py::overload_cast(&BString::operator<), "", py::arg("string")) -.def("__le__", py::overload_cast(&BString::operator<=), "", py::arg("string")) -.def("__eq__", py::overload_cast(&BString::operator==), "", py::arg("string")) -.def("__ge__", py::overload_cast(&BString::operator>=), "", py::arg("string")) -.def("__gt__", py::overload_cast(&BString::operator>), "", py::arg("string")) -.def("__ne__", py::overload_cast(&BString::operator!=), "", py::arg("string")) -.def("__lt__", py::overload_cast(&BString::operator<), "", py::arg("string")) -.def("__le__", py::overload_cast(&BString::operator<=), "", py::arg("string")) -.def("__eq__", py::overload_cast(&BString::operator==), "", py::arg("string")) -.def("__ge__", py::overload_cast(&BString::operator>=), "", py::arg("string")) -.def("__gt__", py::overload_cast(&BString::operator>), "", py::arg("string")) -.def("__ne__", py::overload_cast(&BString::operator!=), "", py::arg("string")) -.def("operatorconstchar*", &BString::operatorconstchar*, "") -.def("Compare", py::overload_cast(&BString::Compare), "", py::arg("string")) -.def("Compare", py::overload_cast(&BString::Compare), "", py::arg("string")) -.def("Compare", py::overload_cast(&BString::Compare), "", py::arg("string"), py::arg("length")) -.def("Compare", py::overload_cast(&BString::Compare), "", py::arg("string"), py::arg("length")) +.def("MoveCharsInto", py::overload_cast(&BString::MoveCharsInto), "", py::arg("into"), py::arg("intoLength"), py::arg("fromCharOffset"), py::arg("charCount")) +.def("__lt__", py::overload_cast(&BString::operator<, py::const_), "", py::arg("string")) +.def("__le__", py::overload_cast(&BString::operator<=, py::const_), "", py::arg("string")) +.def("__eq__", py::overload_cast(&BString::operator==, py::const_), "", py::arg("string")) +.def("__ge__", py::overload_cast(&BString::operator>=, py::const_), "", py::arg("string")) +.def("__gt__", py::overload_cast(&BString::operator>, py::const_), "", py::arg("string")) +.def("__ne__", py::overload_cast(&BString::operator!=, py::const_), "", py::arg("string")) +.def("__lt__", py::overload_cast(&BString::operator<, py::const_), "", py::arg("string")) +.def("__le__", py::overload_cast(&BString::operator<=, py::const_), "", py::arg("string")) +.def("__eq__", py::overload_cast(&BString::operator==, py::const_), "", py::arg("string")) +.def("__ge__", py::overload_cast(&BString::operator>=, py::const_), "", py::arg("string")) +.def("__gt__", py::overload_cast(&BString::operator>, py::const_), "", py::arg("string")) +.def("__ne__", py::overload_cast(&BString::operator!=, py::const_), "", py::arg("string")) +//.def("operatorconstchar*", &BString::operatorconstchar*, "") +.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string")) +.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string")) +.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string"), py::arg("length")) +.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string"), py::arg("length")) .def("CompareAt", &BString::CompareAt, "", py::arg("offset"), py::arg("string"), py::arg("length")) -.def("CompareChars", py::overload_cast(&BString::CompareChars), "", py::arg("string"), py::arg("charCount")) -.def("CompareChars", py::overload_cast(&BString::CompareChars), "", py::arg("string"), py::arg("charCount")) -.def("ICompare", py::overload_cast(&BString::ICompare), "", py::arg("string")) -.def("ICompare", py::overload_cast(&BString::ICompare), "", py::arg("string")) -.def("ICompare", py::overload_cast(&BString::ICompare), "", py::arg("string"), py::arg("length")) -.def("ICompare", py::overload_cast(&BString::ICompare), "", py::arg("string"), py::arg("length")) -.def("FindFirst", py::overload_cast(&BString::FindFirst), "", py::arg("string")) -.def("FindFirst", py::overload_cast(&BString::FindFirst), "", py::arg("string")) -.def("FindFirst", py::overload_cast(&BString::FindFirst), "", py::arg("string"), py::arg("fromOffset")) -.def("FindFirst", py::overload_cast(&BString::FindFirst), "", py::arg("string"), py::arg("fromOffset")) -.def("FindFirst", py::overload_cast(&BString::FindFirst), "", py::arg("c")) -.def("FindFirst", py::overload_cast(&BString::FindFirst), "", py::arg("c"), py::arg("fromOffset")) -.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars), "", py::arg("string"), py::arg("fromCharOffset")) -.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars), "", py::arg("string"), py::arg("fromCharOffset")) -.def("FindLast", py::overload_cast(&BString::FindLast), "", py::arg("string")) -.def("FindLast", py::overload_cast(&BString::FindLast), "", py::arg("string")) -.def("FindLast", py::overload_cast(&BString::FindLast), "", py::arg("string"), py::arg("beforeOffset")) -.def("FindLast", py::overload_cast(&BString::FindLast), "", py::arg("string"), py::arg("beforeOffset")) -.def("FindLast", py::overload_cast(&BString::FindLast), "", py::arg("c")) -.def("FindLast", py::overload_cast(&BString::FindLast), "", py::arg("c"), py::arg("beforeOffset")) -.def("FindLastChars", py::overload_cast(&BString::FindLastChars), "", py::arg("string"), py::arg("beforeCharOffset")) -.def("FindLastChars", py::overload_cast(&BString::FindLastChars), "", py::arg("string"), py::arg("beforeCharOffset")) -.def("IFindFirst", py::overload_cast(&BString::IFindFirst), "", py::arg("string")) -.def("IFindFirst", py::overload_cast(&BString::IFindFirst), "", py::arg("string")) -.def("IFindFirst", py::overload_cast(&BString::IFindFirst), "", py::arg("string"), py::arg("fromOffset")) -.def("IFindFirst", py::overload_cast(&BString::IFindFirst), "", py::arg("string"), py::arg("fromOffset")) -.def("IFindLast", py::overload_cast(&BString::IFindLast), "", py::arg("string")) -.def("IFindLast", py::overload_cast(&BString::IFindLast), "", py::arg("string")) -.def("IFindLast", py::overload_cast(&BString::IFindLast), "", py::arg("string"), py::arg("beforeOffset")) -.def("IFindLast", py::overload_cast(&BString::IFindLast), "", py::arg("string"), py::arg("beforeOffset")) -.def("StartsWith", py::overload_cast(&BString::StartsWith), "", py::arg("string")) -.def("StartsWith", py::overload_cast(&BString::StartsWith), "", py::arg("string")) -.def("StartsWith", py::overload_cast(&BString::StartsWith), "", py::arg("string"), py::arg("length")) -.def("IStartsWith", py::overload_cast(&BString::IStartsWith), "", py::arg("string")) -.def("IStartsWith", py::overload_cast(&BString::IStartsWith), "", py::arg("string")) -.def("IStartsWith", py::overload_cast(&BString::IStartsWith), "", py::arg("string"), py::arg("length")) -.def("EndsWith", py::overload_cast(&BString::EndsWith), "", py::arg("string")) -.def("EndsWith", py::overload_cast(&BString::EndsWith), "", py::arg("string")) -.def("EndsWith", py::overload_cast(&BString::EndsWith), "", py::arg("string"), py::arg("length")) -.def("IEndsWith", py::overload_cast(&BString::IEndsWith), "", py::arg("string")) -.def("IEndsWith", py::overload_cast(&BString::IEndsWith), "", py::arg("string")) -.def("IEndsWith", py::overload_cast(&BString::IEndsWith), "", py::arg("string"), py::arg("length")) +.def("CompareChars", py::overload_cast(&BString::CompareChars, py::const_), "", py::arg("string"), py::arg("charCount")) +.def("CompareChars", py::overload_cast(&BString::CompareChars, py::const_), "", py::arg("string"), py::arg("charCount")) +.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string")) +.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string")) +.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string"), py::arg("length")) +.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string"), py::arg("length")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("c")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("c"), py::arg("fromOffset")) +.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars, py::const_), "", py::arg("string"), py::arg("fromCharOffset")) +.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars, py::const_), "", py::arg("string"), py::arg("fromCharOffset")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("c")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("c"), py::arg("beforeOffset")) +.def("FindLastChars", py::overload_cast(&BString::FindLastChars, py::const_), "", py::arg("string"), py::arg("beforeCharOffset")) +.def("FindLastChars", py::overload_cast(&BString::FindLastChars, py::const_), "", py::arg("string"), py::arg("beforeCharOffset")) +.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string")) +.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string")) +.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string")) +.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string")) +.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("StartsWith", py::overload_cast(&BString::StartsWith, py::const_), "", py::arg("string")) +.def("StartsWith", py::overload_cast(&BString::StartsWith, py::const_), "", py::arg("string")) +.def("StartsWith", py::overload_cast(&BString::StartsWith, py::const_), "", py::arg("string"), py::arg("length")) +.def("IStartsWith", py::overload_cast(&BString::IStartsWith, py::const_), "", py::arg("string")) +.def("IStartsWith", py::overload_cast(&BString::IStartsWith, py::const_), "", py::arg("string")) +.def("IStartsWith", py::overload_cast(&BString::IStartsWith, py::const_), "", py::arg("string"), py::arg("length")) +.def("EndsWith", py::overload_cast(&BString::EndsWith, py::const_), "", py::arg("string")) +.def("EndsWith", py::overload_cast(&BString::EndsWith, py::const_), "", py::arg("string")) +.def("EndsWith", py::overload_cast(&BString::EndsWith, py::const_), "", py::arg("string"), py::arg("length")) +.def("IEndsWith", py::overload_cast(&BString::IEndsWith, py::const_), "", py::arg("string")) +.def("IEndsWith", py::overload_cast(&BString::IEndsWith, py::const_), "", py::arg("string")) +.def("IEndsWith", py::overload_cast(&BString::IEndsWith, py::const_), "", py::arg("string"), py::arg("length")) .def("ReplaceFirst", py::overload_cast(&BString::ReplaceFirst), "", py::arg("replaceThis"), py::arg("withThis")) .def("ReplaceLast", py::overload_cast(&BString::ReplaceLast), "", py::arg("replaceThis"), py::arg("withThis")) .def("ReplaceAll", py::overload_cast(&BString::ReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) @@ -218,11 +222,11 @@ py::class_(m, "BString") .def("ReplaceSet", py::overload_cast(&BString::ReplaceSet), "", py::arg("setOfBytes"), py::arg("with")) .def("ReplaceSet", py::overload_cast(&BString::ReplaceSet), "", py::arg("setOfBytes"), py::arg("with")) .def("ReplaceCharsSet", &BString::ReplaceCharsSet, "", py::arg("setOfChars"), py::arg("with")) -.def("__getitem__", py::overload_cast(&BString::operator[]), "", py::arg("index")) -.def("__getitem__", py::overload_cast(&BString::operator[]), "", py::arg("index")) +.def("__getitem__", py::overload_cast(&BString::operator[], py::const_), "", py::arg("index")) +//.def("__getitem__", py::overload_cast(&BString::operator[]), "", py::arg("index")) .def("ByteAt", &BString::ByteAt, "", py::arg("index")) -.def("CharAt", py::overload_cast(&BString::CharAt), "", py::arg("charIndex"), py::arg("bytes")=NULL) -.def("CharAt", py::overload_cast(&BString::CharAt), "", py::arg("charIndex"), py::arg("buffer"), py::arg("bytes")) +.def("CharAt", py::overload_cast(&BString::CharAt, py::const_), "", py::arg("charIndex"), py::arg("bytes")=NULL) +.def("CharAt", py::overload_cast(&BString::CharAt, py::const_), "", py::arg("charIndex"), py::arg("buffer"), py::arg("bytes")) .def("LockBuffer", &BString::LockBuffer, "", py::arg("maxLength")) .def("UnlockBuffer", &BString::UnlockBuffer, "", py::arg("length")=- 1) .def("SetByteAt", &BString::SetByteAt, "", py::arg("pos"), py::arg("to")) @@ -247,9 +251,9 @@ py::class_(m, "BString") .def("__lshift__", py::overload_cast(&BString::operator<<), "", py::arg("value")) .def("__lshift__", py::overload_cast(&BString::operator<<), "", py::arg("value")) .def("__lshift__", py::overload_cast(&BString::operator<<), "", py::arg("value")) -.def_readwrite("Private", &BString::Private, "") +//.def_readwrite("Private", &BString::Private, "") ; - +/* m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); m.def("__le__", py::overload_cast(&operator<=), "", py::arg("a"), py::arg("b")); @@ -301,5 +305,5 @@ m.def("__gt__", py::overload_cast(&operator>), "" m.def("__ge__", py::overload_cast(&operator>=), "", py::arg("str"), py::arg("string")); m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("str"), py::arg("string")); - +*/ } From c66d1dd0408440e6c7262a1c9f015835df19df87 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 15:44:57 +0100 Subject: [PATCH 126/155] Add Flattenable.cpp & StringList.cpp --- Jamfile | 2 ++ bindings/__init__.py | 2 ++ bindings/support/Flattenable.cpp | 2 +- bindings/support/StringList.cpp | 58 +++++++++++++++++++++++++++++--- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index b80e81b..1cea32b 100644 --- a/Jamfile +++ b/Jamfile @@ -166,6 +166,8 @@ local sourceFiles = parsedate.cpp List.cpp String.cpp + Flattenable.cpp + StringList.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index dbbeb1f..aebcd96 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -71,6 +71,8 @@ from .parsedate import * from .List import * from .String import * +from .Flattenable import * +from .StringList import * from .fs_attr import * diff --git a/bindings/support/Flattenable.cpp b/bindings/support/Flattenable.cpp index 16ddfe7..6f35893 100644 --- a/bindings/support/Flattenable.cpp +++ b/bindings/support/Flattenable.cpp @@ -8,7 +8,7 @@ namespace py = pybind11; -void define_Flattenable(py::module_& m) +PYBIND11_MODULE(Flattenable, m) { py::class_(m, "BFlattenable") .def("IsFixedSize", &BFlattenable::IsFixedSize, "") diff --git a/bindings/support/StringList.cpp b/bindings/support/StringList.cpp index 454dcf0..599cfd8 100644 --- a/bindings/support/StringList.cpp +++ b/bindings/support/StringList.cpp @@ -2,13 +2,53 @@ #include #include #include +#include #include namespace py = pybind11; +class PyBStringList : public BStringList{ + public: + using BStringList::BStringList; + bool IsFixedSize() const override { + PYBIND11_OVERLOAD(bool, BStringList, IsFixedSize); + } + type_code TypeCode() const override { + PYBIND11_OVERLOAD(type_code, BStringList, TypeCode); + } + bool AllowsTypeCode(type_code code) const override { + PYBIND11_OVERLOAD(bool, BStringList, AllowsTypeCode, code); + } + ssize_t FlattenedSize() const override { + PYBIND11_OVERLOAD(ssize_t, BStringList, FlattenedSize); + } + status_t Flatten(void* buffer, ssize_t size) const override { + PYBIND11_OVERLOAD(status_t, BStringList, Flatten, buffer, size); + } + status_t Unflatten(type_code code, const void* buffer, ssize_t size) override { + PYBIND11_OVERLOAD(status_t, BStringList, Unflatten, code, buffer, size); + } +}; -void define_StringList(py::module_& m) +bool CallPythonFunction(const BString& item, py::function& func) { + // Chiamare la funzione Python passando l'elemento + // Questo richiede la conversione tra tipi C++ e Python + // Includere eventuali conversioni necessarie qui + // Esempio di chiamata della funzione Python + py::object result = func(item); + + // Convertire il risultato della funzione Python in un booleano + return py::cast(result); +} +/* or this way +bool CallPythonFunction(const BString& str, const py::function& func) { + // Chiamare la funzione Python + return func(str).template cast(); +}*/ + + +PYBIND11_MODULE(StringList, m) { py::class_(m, "BStringList") .def(py::init(), "", py::arg("count")=20) @@ -34,8 +74,18 @@ py::class_(m, "BStringList") .def("CountStrings", &BStringList::CountStrings, "") .def("IsEmpty", &BStringList::IsEmpty, "") .def("Join", &BStringList::Join, "", py::arg("separator"), py::arg("length")=- 1) -.def("DoForEach", py::overload_cast(&BStringList::DoForEach), "", py::arg("")) -.def("DoForEach", py::overload_cast(&BStringList::DoForEach), "", py::arg(""), py::arg("arg2")) +//.def("DoForEach", py::overload_cast(&BStringList::DoForEach), "", py::arg("")) +.def("DoForEach", [](BStringList& self, py::function& func) -> void { + self.DoForEach(static_cast(+[](const BString& item, void* userData) -> bool { + return CallPythonFunction(item, *static_cast(userData)); + }), &func); +}, "", py::arg("func")) +//.def("DoForEach", py::overload_cast(&BStringList::DoForEach), "", py::arg(""), py::arg("arg2")) +.def("DoForEach", [](BStringList& self, py::function& func, void* arg2) -> void { + self.DoForEach(static_cast(+[](const BString& item, void* userData) -> bool { + return CallPythonFunction(item, *static_cast(userData)); + }), arg2); +}, "", py::arg("func"), py::arg("arg2")) .def("operator=", &BStringList::operator=, "", py::arg("other")) .def("__eq__", &BStringList::operator==, "", py::arg("other")) .def("__ne__", &BStringList::operator!=, "", py::arg("other")) @@ -47,6 +97,6 @@ py::class_(m, "BStringList") .def("Unflatten", &BStringList::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) ; -m.def("__ne__", &operator!=, "", py::arg("other")); +//m.def("__ne__", &operator!=, "", py::arg("other")); } From 4cfc66581fd8e506f5233233d75187a640beaef1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 01:02:34 +0100 Subject: [PATCH 127/155] Add File.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/storage/File.cpp | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Jamfile b/Jamfile index 1cea32b..f45ccf2 100644 --- a/Jamfile +++ b/Jamfile @@ -177,6 +177,7 @@ local sourceFiles = Entry.cpp Node.cpp Directory.cpp + File.cpp ; # The shared library Be.so can be built from the sourceFiles diff --git a/bindings/__init__.py b/bindings/__init__.py index aebcd96..1a8abda 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -80,6 +80,7 @@ from .Entry import * from .Node import * from .Directory import * +from .File import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/storage/File.cpp b/bindings/storage/File.cpp index 79c3f4a..a43698b 100644 --- a/bindings/storage/File.cpp +++ b/bindings/storage/File.cpp @@ -4,23 +4,28 @@ #include #include +#include +#include +#include +#include +#include namespace py = pybind11; -void define_File(py::module_& m) +PYBIND11_MODULE(File, m) { py::class_(m, "BFile") .def(py::init(), "") .def(py::init(), "", py::arg("file")) -.def(py::init(), "", py::arg("ref"), py::arg("openMode")) -.def(py::init(), "", py::arg("entry"), py::arg("openMode")) -.def(py::init(), "", py::arg("path"), py::arg("openMode")) -.def(py::init(), "", py::arg("dir"), py::arg("path"), py::arg("openMode")) -.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("ref"), py::arg("openMode")) -.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("entry"), py::arg("openMode")) -.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("path"), py::arg("openMode")) -.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("dir"), py::arg("path"), py::arg("openMode")) +.def(py::init(), "", py::arg("ref"), py::arg("openMode")) +.def(py::init(), "", py::arg("entry"), py::arg("openMode")) +.def(py::init(), "", py::arg("path"), py::arg("openMode")) +.def(py::init(), "", py::arg("dir"), py::arg("path"), py::arg("openMode")) +.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("ref"), py::arg("openMode")) +.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("entry"), py::arg("openMode")) +.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("path"), py::arg("openMode")) +.def("SetTo", py::overload_cast(&BFile::SetTo), "", py::arg("dir"), py::arg("path"), py::arg("openMode")) .def("IsReadable", &BFile::IsReadable, "") .def("IsWritable", &BFile::IsWritable, "") .def("Read", &BFile::Read, "", py::arg("buffer"), py::arg("size")) From ade40fc0914f65ba6d12002fb1fc70525cd74585 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 01:03:41 +0100 Subject: [PATCH 128/155] Fix 32bit --- bindings/support/DateTime.cpp | 24 +++--- bindings/support/List.cpp | 8 +- bindings/support/String.cpp | 138 ++++++++++++++++---------------- bindings/support/StringList.cpp | 10 +-- 4 files changed, 90 insertions(+), 90 deletions(-) diff --git a/bindings/support/DateTime.cpp b/bindings/support/DateTime.cpp index c291706..945d4dd 100644 --- a/bindings/support/DateTime.cpp +++ b/bindings/support/DateTime.cpp @@ -27,16 +27,16 @@ py::enum_(m, "diff_type", "") py::class_(m, "BTime") .def(py::init(), "") .def(py::init(), "", py::arg("other")) -.def(py::init(), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) +.def(py::init(), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) .def(py::init(), "", py::arg("archive")) .def("Archive", &BTime::Archive, "", py::arg("into")) //.def("IsValid", py::overload_cast<>(&BTime::IsValid, py::const_), "") // overloading a method with both static and instance methods is not supported; .def_static("IsValid", py::overload_cast(&BTime::IsValid), "", py::arg("time")) -.def_static("IsValid", py::overload_cast(&BTime::IsValid), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) +.def_static("IsValid", py::overload_cast(&BTime::IsValid), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) .def_static("CurrentTime", &BTime::CurrentTime, "", py::arg("type")) .def("Time", &BTime::Time, "") .def("SetTime", py::overload_cast(&BTime::SetTime), "", py::arg("time")) -.def("SetTime", py::overload_cast(&BTime::SetTime), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) +.def("SetTime", py::overload_cast(&BTime::SetTime), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) .def("AddHours", &BTime::AddHours, "", py::arg("hours")) .def("AddMinutes", &BTime::AddMinutes, "", py::arg("minutes")) .def("AddSeconds", &BTime::AddSeconds, "", py::arg("seconds")) @@ -59,17 +59,17 @@ py::class_(m, "BTime") py::class_(m, "BDate") .def(py::init(), "") .def(py::init(), "", py::arg("other")) -.def(py::init(), "", py::arg("year"), py::arg("month"), py::arg("day")) +.def(py::init(), "", py::arg("year"), py::arg("month"), py::arg("day")) .def(py::init(), "", py::arg("time"), py::arg("type")=B_LOCAL_TIME) .def(py::init(), "", py::arg("archive")) -.def("Archive", &BDate::Archive, "", py::arg("into")) +.def("Archive", &BDate::Archive, "", py::arg("int32o")) //.def("IsValid", py::overload_cast<>(&BDate::IsValid, py::const_), "") // overloading a method with both static and instance methods is not supported; .def_static("IsValid", py::overload_cast(&BDate::IsValid), "", py::arg("date")) -.def_static("IsValid", py::overload_cast(&BDate::IsValid), "", py::arg("year"), py::arg("month"), py::arg("day")) +.def_static("IsValid", py::overload_cast(&BDate::IsValid), "", py::arg("year"), py::arg("month"), py::arg("day")) .def_static("CurrentDate", &BDate::CurrentDate, "", py::arg("type")) .def("Date", &BDate::Date, "") .def("SetDate", py::overload_cast(&BDate::SetDate), "", py::arg("date")) -.def("SetDate", py::overload_cast(&BDate::SetDate), "", py::arg("year"), py::arg("month"), py::arg("day")) +.def("SetDate", py::overload_cast(&BDate::SetDate), "", py::arg("year"), py::arg("month"), py::arg("day")) .def("GetDate", &BDate::GetDate, "", py::arg("year"), py::arg("month"), py::arg("day")) .def("AddDays", &BDate::AddDays, "", py::arg("days")) .def("AddYears", &BDate::AddYears, "", py::arg("years")) @@ -85,17 +85,17 @@ py::class_(m, "BDate") .def("DayOfYear", &BDate::DayOfYear, "") .def("WeekNumber", &BDate::WeekNumber, "") //.def("IsLeapYear", py::overload_cast<>(&BDate::IsLeapYear, py::const_), "") -.def_static("IsLeapYear", py::overload_cast(&BDate::IsLeapYear), "", py::arg("year")) +.def_static("IsLeapYear", py::overload_cast(&BDate::IsLeapYear), "", py::arg("year")) .def("DaysInYear", &BDate::DaysInYear, "") .def("DaysInMonth", &BDate::DaysInMonth, "") //.def("ShortDayName", py::overload_cast<>(&BDate::ShortDayName, py::const_), "") -.def_static("ShortDayName", py::overload_cast(&BDate::ShortDayName), "", py::arg("day")) +.def_static("ShortDayName", py::overload_cast(&BDate::ShortDayName), "", py::arg("day")) //.def("ShortMonthName", py::overload_cast<>(&BDate::ShortMonthName, py::const_), "") -.def_static("ShortMonthName", py::overload_cast(&BDate::ShortMonthName), "", py::arg("month")) +.def_static("ShortMonthName", py::overload_cast(&BDate::ShortMonthName), "", py::arg("month")) //.def("LongDayName", py::overload_cast<>(&BDate::LongDayName, py::const_), "") -.def_static("LongDayName", py::overload_cast(&BDate::LongDayName), "", py::arg("day")) +.def_static("LongDayName", py::overload_cast(&BDate::LongDayName), "", py::arg("day")) //.def("LongMonthName", py::overload_cast<>(&BDate::LongMonthName, py::const_), "") -.def_static("LongMonthName", py::overload_cast(&BDate::LongMonthName), "", py::arg("month")) +.def_static("LongMonthName", py::overload_cast(&BDate::LongMonthName), "", py::arg("month")) //.def("DateToJulianDay", &BDate::DateToJulianDay, "") .def_static("JulianDayToDate", &BDate::JulianDayToDate, "", py::arg("julianDay")) .def("__ne__", &BDate::operator!=, "", py::arg("date")) diff --git a/bindings/support/List.cpp b/bindings/support/List.cpp index b166399..82a55b8 100644 --- a/bindings/support/List.cpp +++ b/bindings/support/List.cpp @@ -15,17 +15,17 @@ bool CallPythonFunction(void* item, py::function& func) { PYBIND11_MODULE(List, m) { py::class_(m, "BList") -.def(py::init(), "", py::arg("count")=20) +.def(py::init(), "", py::arg("count")=20) .def(py::init(), "", py::arg("other")) .def("operator=", &BList::operator=, "", py::arg("other")) .def("__eq__", &BList::operator==, "", py::arg("other")) .def("__ne__", &BList::operator!=, "", py::arg("other")) -.def("AddItem", py::overload_cast(&BList::AddItem), "", py::arg("item"), py::arg("index")) +.def("AddItem", py::overload_cast(&BList::AddItem), "", py::arg("item"), py::arg("index")) .def("AddItem", py::overload_cast(&BList::AddItem), "", py::arg("item")) -.def("AddList", py::overload_cast(&BList::AddList), "", py::arg("list"), py::arg("index")) +.def("AddList", py::overload_cast(&BList::AddList), "", py::arg("list"), py::arg("index")) .def("AddList", py::overload_cast(&BList::AddList), "", py::arg("list")) .def("RemoveItem", py::overload_cast(&BList::RemoveItem), "", py::arg("item")) -.def("RemoveItem", py::overload_cast(&BList::RemoveItem), "", py::arg("index")) +.def("RemoveItem", py::overload_cast(&BList::RemoveItem), "", py::arg("index")) .def("RemoveItems", &BList::RemoveItems, "", py::arg("index"), py::arg("count")) .def("ReplaceItem", &BList::ReplaceItem, "", py::arg("index"), py::arg("item")) .def("MakeEmpty", &BList::MakeEmpty, "") diff --git a/bindings/support/String.cpp b/bindings/support/String.cpp index 86c3626..f4174cd 100644 --- a/bindings/support/String.cpp +++ b/bindings/support/String.cpp @@ -18,7 +18,7 @@ py::class_(m, "BString") .def(py::init(), "") .def(py::init(), "", py::arg("string")) .def(py::init(), "", py::arg("string")) -.def(py::init(), "", py::arg("string"), py::arg("maxLength")) +.def(py::init(), "", py::arg("string"), py::arg("maxLength")) .def(py::init(), "") .def("String", &BString::String, "") .def("Length", &BString::Length, "") @@ -37,7 +37,7 @@ py::class_(m, "BString") } , "")*/ .def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string")) -.def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string"), py::arg("maxLength")) +.def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string"), py::arg("maxLength")) .def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string")) .def("Adopt", [](BString& self) { BString from; @@ -45,17 +45,17 @@ py::class_(m, "BString") return std::make_tuple(r,from); } , "") -.def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string"), py::arg("maxLength")) -.def("Adopt", [](BString& self,int maxLength) { +.def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string"), py::arg("maxLength")) +.def("Adopt", [](BString& self,int32 maxLength) { BString from; BString & r = self.Adopt(from, maxLength); return std::make_tuple(r,from); } , "", py::arg("maxLength")) -.def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("c"), py::arg("count")) -.def("SetToChars", py::overload_cast(&BString::SetToChars), "", py::arg("string"), py::arg("charCount")) -.def("SetToChars", py::overload_cast(&BString::SetToChars), "", py::arg("string"), py::arg("charCount")) -.def("AdoptChars", [](BString& self,int charCount) { +.def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("c"), py::arg("count")) +.def("SetToChars", py::overload_cast(&BString::SetToChars), "", py::arg("string"), py::arg("charCount")) +.def("SetToChars", py::overload_cast(&BString::SetToChars), "", py::arg("string"), py::arg("charCount")) +.def("AdoptChars", [](BString& self,int32 charCount) { BString from; BString & r = self.AdoptChars(from, charCount); return std::make_tuple(r,from); @@ -65,14 +65,14 @@ py::class_(m, "BString") //.def("SetToFormatVarArgs", &BString::SetToFormatVarArgs, "", py::arg("format"), py::arg("args")) //.def("ScanWithFormat", &BString::ScanWithFormat, "", py::arg("format")) //.def("ScanWithFormatVarArgs", &BString::ScanWithFormatVarArgs, "", py::arg("format"), py::arg("args")) -.def("CopyInto", [](BString& self,int fromOffset,int length) { +.def("CopyInto", [](BString& self,int32 fromOffset,int32 length) { BString into; BString & r = self.CopyInto(into, fromOffset, length); return std::make_tuple(r,into); } , "", py::arg("fromOffset"), py::arg("length")) -.def("CopyInto", py::overload_cast(&BString::CopyInto, py::const_), "", py::arg("into"), py::arg("fromOffset"), py::arg("length")) -.def("CopyCharsInto", [](BString& self,int fromCharOffset,int charCount) { +.def("CopyInto", py::overload_cast(&BString::CopyInto, py::const_), "", py::arg("into"), py::arg("fromOffset"), py::arg("length")) +.def("CopyCharsInto", [](BString& self,int32 fromCharOffset,int charCount) { BString into; BString & r = self.CopyCharsInto(into, fromCharOffset, charCount); return std::make_tuple(r,into); @@ -90,31 +90,31 @@ py::class_(m, "BString") .def("__iadd__", py::overload_cast(&BString::operator+=), "", py::arg("c")) .def("Append", py::overload_cast(&BString::Append), "", py::arg("string")) .def("Append", py::overload_cast(&BString::Append), "", py::arg("string")) -.def("Append", py::overload_cast(&BString::Append), "", py::arg("string"), py::arg("length")) -.def("Append", py::overload_cast(&BString::Append), "", py::arg("string"), py::arg("length")) -.def("Append", py::overload_cast(&BString::Append), "", py::arg("c"), py::arg("count")) -.def("AppendChars", py::overload_cast(&BString::AppendChars), "", py::arg("string"), py::arg("charCount")) -.def("AppendChars", py::overload_cast(&BString::AppendChars), "", py::arg("string"), py::arg("charCount")) +.def("Append", py::overload_cast(&BString::Append), "", py::arg("string"), py::arg("length")) +.def("Append", py::overload_cast(&BString::Append), "", py::arg("string"), py::arg("length")) +.def("Append", py::overload_cast(&BString::Append), "", py::arg("c"), py::arg("count")) +.def("AppendChars", py::overload_cast(&BString::AppendChars), "", py::arg("string"), py::arg("charCount")) +.def("AppendChars", py::overload_cast(&BString::AppendChars), "", py::arg("string"), py::arg("charCount")) .def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("string")) .def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("string")) -.def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("string"), py::arg("length")) -.def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("string"), py::arg("length")) -.def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("c"), py::arg("count")) -.def("PrependChars", py::overload_cast(&BString::PrependChars), "", py::arg("string"), py::arg("charCount")) -.def("PrependChars", py::overload_cast(&BString::PrependChars), "", py::arg("string"), py::arg("charCount")) -.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("position")) -.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("length"), py::arg("position")) -.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("fromOffset"), py::arg("length"), py::arg("position")) -.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("position")) -.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("length"), py::arg("position")) -.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("fromOffset"), py::arg("length"), py::arg("position")) -.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("c"), py::arg("count"), py::arg("position")) -.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charPosition")) -.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charCount"), py::arg("charPosition")) -.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("fromCharOffset"), py::arg("charCount"), py::arg("charPosition")) -.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charPosition")) -.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charCount"), py::arg("charPosition")) -.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("fromCharOffset"), py::arg("charCount"), py::arg("charPosition")) +.def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("string"), py::arg("length")) +.def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("string"), py::arg("length")) +.def("Prepend", py::overload_cast(&BString::Prepend), "", py::arg("c"), py::arg("count")) +.def("PrependChars", py::overload_cast(&BString::PrependChars), "", py::arg("string"), py::arg("charCount")) +.def("PrependChars", py::overload_cast(&BString::PrependChars), "", py::arg("string"), py::arg("charCount")) +.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("position")) +.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("length"), py::arg("position")) +.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("fromOffset"), py::arg("length"), py::arg("position")) +.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("position")) +.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("length"), py::arg("position")) +.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("string"), py::arg("fromOffset"), py::arg("length"), py::arg("position")) +.def("Insert", py::overload_cast(&BString::Insert), "", py::arg("c"), py::arg("count"), py::arg("position")) +.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charPosition")) +.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charCount"), py::arg("charPosition")) +.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("fromCharOffset"), py::arg("charCount"), py::arg("charPosition")) +.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charPosition")) +.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("charCount"), py::arg("charPosition")) +.def("InsertChars", py::overload_cast(&BString::InsertChars), "", py::arg("string"), py::arg("fromCharOffset"), py::arg("charCount"), py::arg("charPosition")) .def("Truncate", &BString::Truncate, "", py::arg("newLength"), py::arg("lazy")=true) .def("TruncateChars", &BString::TruncateChars, "", py::arg("newCharCount"), py::arg("lazy")=true) .def("Remove", &BString::Remove, "", py::arg("from"), py::arg("length")) @@ -127,14 +127,14 @@ py::class_(m, "BString") .def("RemoveAll", py::overload_cast(&BString::RemoveAll), "", py::arg("string")) .def("RemoveSet", &BString::RemoveSet, "", py::arg("setOfBytesToRemove")) .def("RemoveCharsSet", &BString::RemoveCharsSet, "", py::arg("setOfCharsToRemove")) -.def("MoveInto", [](BString& self,int from,int length) { +.def("MoveInto", [](BString& self,int32 from,int32 length) { BString into; BString & r = self.MoveInto(into, from, length); return std::make_tuple(r,into); } , "", py::arg("from"), py::arg("length")) -.def("MoveInto", py::overload_cast(&BString::MoveInto), "", py::arg("into"), py::arg("from"), py::arg("length")) -.def("MoveCharsInto", [](BString& self,int fromCharOffset,int charCount) { +.def("MoveInto", py::overload_cast(&BString::MoveInto), "", py::arg("into"), py::arg("from"), py::arg("length")) +.def("MoveCharsInto", [](BString& self,int32 fromCharOffset,int32 charCount) { BString into; BString & r = self.MoveCharsInto(into, fromCharOffset, charCount); return std::make_tuple(r,into); @@ -156,69 +156,69 @@ py::class_(m, "BString") //.def("operatorconstchar*", &BString::operatorconstchar*, "") .def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string")) .def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string")) -.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string"), py::arg("length")) -.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string"), py::arg("length")) +.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string"), py::arg("length")) +.def("Compare", py::overload_cast(&BString::Compare, py::const_), "", py::arg("string"), py::arg("length")) .def("CompareAt", &BString::CompareAt, "", py::arg("offset"), py::arg("string"), py::arg("length")) -.def("CompareChars", py::overload_cast(&BString::CompareChars, py::const_), "", py::arg("string"), py::arg("charCount")) -.def("CompareChars", py::overload_cast(&BString::CompareChars, py::const_), "", py::arg("string"), py::arg("charCount")) +.def("CompareChars", py::overload_cast(&BString::CompareChars, py::const_), "", py::arg("string"), py::arg("charCount")) +.def("CompareChars", py::overload_cast(&BString::CompareChars, py::const_), "", py::arg("string"), py::arg("charCount")) .def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string")) .def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string")) -.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string"), py::arg("length")) -.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string"), py::arg("length")) +.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string"), py::arg("length")) +.def("ICompare", py::overload_cast(&BString::ICompare, py::const_), "", py::arg("string"), py::arg("length")) .def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string")) .def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string")) -.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) -.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) .def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("c")) -.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("c"), py::arg("fromOffset")) -.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars, py::const_), "", py::arg("string"), py::arg("fromCharOffset")) -.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars, py::const_), "", py::arg("string"), py::arg("fromCharOffset")) +.def("FindFirst", py::overload_cast(&BString::FindFirst, py::const_), "", py::arg("c"), py::arg("fromOffset")) +.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars, py::const_), "", py::arg("string"), py::arg("fromCharOffset")) +.def("FindFirstChars", py::overload_cast(&BString::FindFirstChars, py::const_), "", py::arg("string"), py::arg("fromCharOffset")) .def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string")) .def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string")) -.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) -.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) .def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("c")) -.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("c"), py::arg("beforeOffset")) -.def("FindLastChars", py::overload_cast(&BString::FindLastChars, py::const_), "", py::arg("string"), py::arg("beforeCharOffset")) -.def("FindLastChars", py::overload_cast(&BString::FindLastChars, py::const_), "", py::arg("string"), py::arg("beforeCharOffset")) +.def("FindLast", py::overload_cast(&BString::FindLast, py::const_), "", py::arg("c"), py::arg("beforeOffset")) +.def("FindLastChars", py::overload_cast(&BString::FindLastChars, py::const_), "", py::arg("string"), py::arg("beforeCharOffset")) +.def("FindLastChars", py::overload_cast(&BString::FindLastChars, py::const_), "", py::arg("string"), py::arg("beforeCharOffset")) .def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string")) .def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string")) -.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) -.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) +.def("IFindFirst", py::overload_cast(&BString::IFindFirst, py::const_), "", py::arg("string"), py::arg("fromOffset")) .def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string")) .def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string")) -.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) -.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) +.def("IFindLast", py::overload_cast(&BString::IFindLast, py::const_), "", py::arg("string"), py::arg("beforeOffset")) .def("StartsWith", py::overload_cast(&BString::StartsWith, py::const_), "", py::arg("string")) .def("StartsWith", py::overload_cast(&BString::StartsWith, py::const_), "", py::arg("string")) -.def("StartsWith", py::overload_cast(&BString::StartsWith, py::const_), "", py::arg("string"), py::arg("length")) +.def("StartsWith", py::overload_cast(&BString::StartsWith, py::const_), "", py::arg("string"), py::arg("length")) .def("IStartsWith", py::overload_cast(&BString::IStartsWith, py::const_), "", py::arg("string")) .def("IStartsWith", py::overload_cast(&BString::IStartsWith, py::const_), "", py::arg("string")) -.def("IStartsWith", py::overload_cast(&BString::IStartsWith, py::const_), "", py::arg("string"), py::arg("length")) +.def("IStartsWith", py::overload_cast(&BString::IStartsWith, py::const_), "", py::arg("string"), py::arg("length")) .def("EndsWith", py::overload_cast(&BString::EndsWith, py::const_), "", py::arg("string")) .def("EndsWith", py::overload_cast(&BString::EndsWith, py::const_), "", py::arg("string")) -.def("EndsWith", py::overload_cast(&BString::EndsWith, py::const_), "", py::arg("string"), py::arg("length")) +.def("EndsWith", py::overload_cast(&BString::EndsWith, py::const_), "", py::arg("string"), py::arg("length")) .def("IEndsWith", py::overload_cast(&BString::IEndsWith, py::const_), "", py::arg("string")) .def("IEndsWith", py::overload_cast(&BString::IEndsWith, py::const_), "", py::arg("string")) -.def("IEndsWith", py::overload_cast(&BString::IEndsWith, py::const_), "", py::arg("string"), py::arg("length")) +.def("IEndsWith", py::overload_cast(&BString::IEndsWith, py::const_), "", py::arg("string"), py::arg("length")) .def("ReplaceFirst", py::overload_cast(&BString::ReplaceFirst), "", py::arg("replaceThis"), py::arg("withThis")) .def("ReplaceLast", py::overload_cast(&BString::ReplaceLast), "", py::arg("replaceThis"), py::arg("withThis")) -.def("ReplaceAll", py::overload_cast(&BString::ReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) -.def("Replace", py::overload_cast(&BString::Replace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) +.def("ReplaceAll", py::overload_cast(&BString::ReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) +.def("Replace", py::overload_cast(&BString::Replace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) .def("ReplaceFirst", py::overload_cast(&BString::ReplaceFirst), "", py::arg("replaceThis"), py::arg("withThis")) .def("ReplaceLast", py::overload_cast(&BString::ReplaceLast), "", py::arg("replaceThis"), py::arg("withThis")) -.def("ReplaceAll", py::overload_cast(&BString::ReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) -.def("Replace", py::overload_cast(&BString::Replace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) +.def("ReplaceAll", py::overload_cast(&BString::ReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) +.def("Replace", py::overload_cast(&BString::Replace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) .def("ReplaceAllChars", &BString::ReplaceAllChars, "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromCharOffset")) .def("ReplaceChars", &BString::ReplaceChars, "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromCharOffset")) .def("IReplaceFirst", py::overload_cast(&BString::IReplaceFirst), "", py::arg("replaceThis"), py::arg("withThis")) .def("IReplaceLast", py::overload_cast(&BString::IReplaceLast), "", py::arg("replaceThis"), py::arg("withThis")) -.def("IReplaceAll", py::overload_cast(&BString::IReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) -.def("IReplace", py::overload_cast(&BString::IReplace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) +.def("IReplaceAll", py::overload_cast(&BString::IReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) +.def("IReplace", py::overload_cast(&BString::IReplace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) .def("IReplaceFirst", py::overload_cast(&BString::IReplaceFirst), "", py::arg("replaceThis"), py::arg("withThis")) .def("IReplaceLast", py::overload_cast(&BString::IReplaceLast), "", py::arg("replaceThis"), py::arg("withThis")) -.def("IReplaceAll", py::overload_cast(&BString::IReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) -.def("IReplace", py::overload_cast(&BString::IReplace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) +.def("IReplaceAll", py::overload_cast(&BString::IReplaceAll), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("fromOffset")=0) +.def("IReplace", py::overload_cast(&BString::IReplace), "", py::arg("replaceThis"), py::arg("withThis"), py::arg("maxReplaceCount"), py::arg("fromOffset")=0) .def("ReplaceSet", py::overload_cast(&BString::ReplaceSet), "", py::arg("setOfBytes"), py::arg("with")) .def("ReplaceSet", py::overload_cast(&BString::ReplaceSet), "", py::arg("setOfBytes"), py::arg("with")) .def("ReplaceCharsSet", &BString::ReplaceCharsSet, "", py::arg("setOfChars"), py::arg("with")) diff --git a/bindings/support/StringList.cpp b/bindings/support/StringList.cpp index 599cfd8..7b93d0e 100644 --- a/bindings/support/StringList.cpp +++ b/bindings/support/StringList.cpp @@ -51,16 +51,16 @@ bool CallPythonFunction(const BString& str, const py::function& func) { PYBIND11_MODULE(StringList, m) { py::class_(m, "BStringList") -.def(py::init(), "", py::arg("count")=20) +.def(py::init(), "", py::arg("count")=20) .def(py::init(), "", py::arg("other")) -.def("Add", py::overload_cast(&BStringList::Add), "", py::arg("string"), py::arg("index")) +.def("Add", py::overload_cast(&BStringList::Add), "", py::arg("string"), py::arg("index")) .def("Add", py::overload_cast(&BStringList::Add), "", py::arg("string")) -.def("Add", py::overload_cast(&BStringList::Add), "", py::arg("list"), py::arg("index")) +.def("Add", py::overload_cast(&BStringList::Add), "", py::arg("list"), py::arg("index")) .def("Add", py::overload_cast(&BStringList::Add), "", py::arg("list")) .def("Remove", py::overload_cast(&BStringList::Remove), "", py::arg("string"), py::arg("ignoreCase")=false) .def("Remove", py::overload_cast(&BStringList::Remove), "", py::arg("list"), py::arg("ignoreCase")=false) -.def("Remove", py::overload_cast(&BStringList::Remove), "", py::arg("index")) -.def("Remove", py::overload_cast(&BStringList::Remove), "", py::arg("index"), py::arg("count")) +.def("Remove", py::overload_cast(&BStringList::Remove), "", py::arg("index")) +.def("Remove", py::overload_cast(&BStringList::Remove), "", py::arg("index"), py::arg("count")) .def("Replace", &BStringList::Replace, "", py::arg("index"), py::arg("string")) .def("MakeEmpty", &BStringList::MakeEmpty, "") .def("Sort", &BStringList::Sort, "", py::arg("ignoreCase")=false) From 2b7b0d1be406c873738c72473e991138da4cb9bd Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Tue, 5 Dec 2023 18:09:07 +0100 Subject: [PATCH 129/155] Add partial DataIO.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/support/DataIO.cpp | 112 ++++++++++++++++++++++++++++++++---- 3 files changed, 103 insertions(+), 11 deletions(-) diff --git a/Jamfile b/Jamfile index f45ccf2..da1cb56 100644 --- a/Jamfile +++ b/Jamfile @@ -168,6 +168,7 @@ local sourceFiles = String.cpp Flattenable.cpp StringList.cpp + DataIO.cpp #Kernel fs_attr.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 1a8abda..23cecc2 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -73,6 +73,7 @@ from .String import * from .Flattenable import * from .StringList import * +from .DataIO import * from .fs_attr import * diff --git a/bindings/support/DataIO.cpp b/bindings/support/DataIO.cpp index 2fdced8..17e212e 100644 --- a/bindings/support/DataIO.cpp +++ b/bindings/support/DataIO.cpp @@ -7,10 +7,93 @@ namespace py = pybind11; +class PyBDataIO : public BDataIO { +public: + ssize_t Read(void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BDataIO, Read, buffer, size); + } + ssize_t Write(const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BDataIO, Write, buffer, size); + } + status_t Flush() override { + PYBIND11_OVERLOAD(status_t, BDataIO, Flush); + } +}; -void define_DataIO(py::module_& m) +/* +class PyBPositionIO : public BPositionIO { +public: + using BPositionIO::Seek; + using BPositionIO::Position; + using BPositionIO::BPositionIO; + ssize_t Read(void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BPositionIO, Read, buffer, size); + } + ssize_t Write(const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BPositionIO, Write, buffer, size); + } + ssize_t ReadAt(off_t position, void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BPositionIO, ReadAt, position, buffer, size); + } + ssize_t WriteAt(off_t position, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BPositionIO, WriteAt, position, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BPositionIO, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BPositionIO, Position); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BPositionIO, SetSize, size); + } + status_t GetSize(off_t* size) const override { + PYBIND11_OVERLOAD(status_t, BPositionIO, GetSize, size); + } +}; + +class PyBMemoryIO : public BMemoryIO { +public: + ssize_t ReadAt(off_t position, void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BMemoryIO, ReadAt, position, buffer, size); + } + ssize_t WriteAt(off_t position, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BMemoryIO, WriteAt, position, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BMemoryIO, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BMemoryIO, Position); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BMemoryIO, SetSize, size); + } +}; + +class PyBMallocIO : public BMallocIO { +public: + ssize_t ReadAt(off_t position, void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BMallocIO, ReadAt, position, buffer, size); + } + ssize_t WriteAt(off_t position, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BMallocIO, WriteAt, position, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BMallocIO, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BMallocIO, Position); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BMallocIO, SetSize, size); + } +};*/ + + +PYBIND11_MODULE(DataIO, m) { -py::class_(m, "BDataIO") +py::class_(m, "BDataIO") .def(py::init(), "") .def("Read", &BDataIO::Read, "", py::arg("buffer"), py::arg("size")) .def("Write", &BDataIO::Write, "", py::arg("buffer"), py::arg("size")) @@ -19,12 +102,18 @@ py::class_(m, "BDataIO") .def("WriteExactly", &BDataIO::WriteExactly, "", py::arg("buffer"), py::arg("size"), py::arg("_bytesWritten")=NULL) ; -py::class_(m, "BPositionIO") + +py::class_(m, "BLayout"); +py::class_(m, "BMemoryIO"); +py::class_(m, "BMallocIO"); +/* +//py::class_(m, "BPositionIO") +py::class_>(m, "BPositionIO") .def(py::init(), "") .def("Read", &BPositionIO::Read, "", py::arg("buffer"), py::arg("size")) .def("Write", &BPositionIO::Write, "", py::arg("buffer"), py::arg("size")) -.def("ReadAt", &BPositionIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) -.def("WriteAt", &BPositionIO::WriteAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) +//.def("ReadAt", &BPositionIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) +//.def("WriteAt", &BPositionIO::WriteAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("ReadAtExactly", &BPositionIO::ReadAtExactly, "", py::arg("position"), py::arg("buffer"), py::arg("size"), py::arg("_bytesRead")=NULL) .def("WriteAtExactly", &BPositionIO::WriteAtExactly, "", py::arg("position"), py::arg("buffer"), py::arg("size"), py::arg("_bytesWritten")=NULL) .def("Seek", &BPositionIO::Seek, "", py::arg("position"), py::arg("seekMode")) @@ -33,9 +122,10 @@ py::class_(m, "BPositionIO") .def("GetSize", &BPositionIO::GetSize, "", py::arg("size")) ; -py::class_(m, "BMemoryIO") -.def(py::init(), "", py::arg("data"), py::arg("length")) -.def(py::init(), "", py::arg("data"), py::arg("length")) +//py::class_(m, "BMemoryIO") +py::class_>(m, "BMemoryIO") +//.def(py::init(), "", py::arg("data"), py::arg("length")) +//.def(py::init(), "", py::arg("data"), py::arg("length")) .def("ReadAt", &BMemoryIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("WriteAt", &BMemoryIO::WriteAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("Seek", &BMemoryIO::Seek, "", py::arg("position"), py::arg("seekMode")) @@ -43,8 +133,8 @@ py::class_(m, "BMemoryIO") .def("SetSize", &BMemoryIO::SetSize, "", py::arg("size")) ; -py::class_(m, "BMallocIO") -.def(py::init(), "") +py::class_(m, "BMallocIO") +//.def(py::init(), "") .def("ReadAt", &BMallocIO::ReadAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("WriteAt", &BMallocIO::WriteAt, "", py::arg("position"), py::arg("buffer"), py::arg("size")) .def("Seek", &BMallocIO::Seek, "", py::arg("position"), py::arg("seekMode")) @@ -54,6 +144,6 @@ py::class_(m, "BMallocIO") .def("Buffer", &BMallocIO::Buffer, "") .def("BufferLength", &BMallocIO::BufferLength, "") ; - +*/ } From 5717c2d40e1dd3f1d7e9ce0d8460d2db714aa796 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 02:12:10 +0100 Subject: [PATCH 130/155] Add Path.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/storage/Path.cpp | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Jamfile b/Jamfile index da1cb56..7db5460 100644 --- a/Jamfile +++ b/Jamfile @@ -179,6 +179,7 @@ local sourceFiles = Node.cpp Directory.cpp File.cpp + Path.cpp ; # The shared library Be.so can be built from the sourceFiles diff --git a/bindings/__init__.py b/bindings/__init__.py index 23cecc2..0bc05ce 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -82,6 +82,7 @@ from .Node import * from .Directory import * from .File import * +from .Path import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/storage/Path.cpp b/bindings/storage/Path.cpp index 398a835..2b73aaa 100644 --- a/bindings/storage/Path.cpp +++ b/bindings/storage/Path.cpp @@ -4,13 +4,37 @@ #include #include +#include namespace py = pybind11; -using namespace BPrivate; +/*using namespace BPrivate; using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; +using namespace BPrivate::Storage::Mime;*/ -void define_Path(py::module_& m) +class PyBPath : public BPath{ + public: + using BPath::BPath; + bool IsFixedSize() const override { + PYBIND11_OVERLOAD(bool, BPath, IsFixedSize); + } + type_code TypeCode() const override { + PYBIND11_OVERLOAD(type_code, BPath, TypeCode); + } + ssize_t FlattenedSize() const override { + PYBIND11_OVERLOAD(ssize_t, BPath, FlattenedSize); + } + status_t Flatten(void* buffer, ssize_t size) const override { + PYBIND11_OVERLOAD(status_t, BPath, Flatten, buffer, size); + } + bool AllowsTypeCode(type_code code) const override { + PYBIND11_OVERLOAD(bool, BPath, AllowsTypeCode, code); + } + status_t Unflatten(type_code code, const void* buffer, ssize_t size) override { + PYBIND11_OVERLOAD(status_t, BPath, Unflatten, code, buffer, size); + } +}; + +PYBIND11_MODULE(Path, m) { py::class_(m, "BPath") .def(py::init(), "") @@ -30,10 +54,10 @@ py::class_(m, "BPath") .def("Leaf", &BPath::Leaf, "") .def("GetParent", &BPath::GetParent, "", py::arg("path")) .def("IsAbsolute", &BPath::IsAbsolute, "") -.def("__eq__", py::overload_cast(&BPath::operator==), "", py::arg("item")) -.def("__eq__", py::overload_cast(&BPath::operator==), "", py::arg("path")) -.def("__ne__", py::overload_cast(&BPath::operator!=), "", py::arg("item")) -.def("__ne__", py::overload_cast(&BPath::operator!=), "", py::arg("path")) +.def("__eq__", py::overload_cast(&BPath::operator==, py::const_), "", py::arg("item")) +.def("__eq__", py::overload_cast(&BPath::operator==, py::const_), "", py::arg("path")) +.def("__ne__", py::overload_cast(&BPath::operator!=, py::const_), "", py::arg("item")) +.def("__ne__", py::overload_cast(&BPath::operator!=, py::const_), "", py::arg("path")) .def("operator=", py::overload_cast(&BPath::operator=), "", py::arg("item")) .def("operator=", py::overload_cast(&BPath::operator=), "", py::arg("path")) .def("IsFixedSize", &BPath::IsFixedSize, "") From fb70673cc2fd2230cc0cd691367a82e4c1d53d2a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 01:09:09 +0100 Subject: [PATCH 131/155] Add Statable.cpp --- Jamfile | 2 ++ bindings/__init__.py | 2 ++ bindings/storage/Statable.cpp | 10 ++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Jamfile b/Jamfile index 7db5460..51b6387 100644 --- a/Jamfile +++ b/Jamfile @@ -180,6 +180,8 @@ local sourceFiles = Directory.cpp File.cpp Path.cpp + Statable.cpp + #FilePanel.cpp ; # The shared library Be.so can be built from the sourceFiles diff --git a/bindings/__init__.py b/bindings/__init__.py index 0bc05ce..3fa3b30 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -83,6 +83,8 @@ from .Directory import * from .File import * from .Path import * +from .Statable import * +#from .FilePanel import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/storage/Statable.cpp b/bindings/storage/Statable.cpp index 3438e40..ad34e4e 100644 --- a/bindings/storage/Statable.cpp +++ b/bindings/storage/Statable.cpp @@ -4,14 +4,16 @@ #include #include +#include +#include namespace py = pybind11; -using namespace BPrivate; +/*using namespace BPrivate; using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +using namespace BPackageKit;*/ -void define_Statable(py::module_& m) +PYBIND11_MODULE(Statable, m) { py::class_(m, "BStatable") .def("GetStat", &BStatable::GetStat, "", py::arg("stat")) @@ -33,7 +35,7 @@ py::class_(m, "BStatable") .def("GetAccessTime", &BStatable::GetAccessTime, "", py::arg("atime")) .def("SetAccessTime", &BStatable::SetAccessTime, "", py::arg("atime")) .def("GetVolume", &BStatable::GetVolume, "", py::arg("volume")) -.def_readwrite("Private", &BStatable::Private, "") +//.def_readwrite("Private", &BStatable::Private, "") ; From 1c25d38ba39adc1a7db0ab192cd51afb40121edd Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 23:12:19 +0100 Subject: [PATCH 132/155] Add Volume.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/storage/Volume.cpp | 23 ++++++++++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Jamfile b/Jamfile index 51b6387..b232352 100644 --- a/Jamfile +++ b/Jamfile @@ -179,6 +179,7 @@ local sourceFiles = Node.cpp Directory.cpp File.cpp + Volume.cpp Path.cpp Statable.cpp #FilePanel.cpp diff --git a/bindings/__init__.py b/bindings/__init__.py index 3fa3b30..73c2c30 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -82,6 +82,7 @@ from .Node import * from .Directory import * from .File import * +from .Volume import * from .Path import * from .Statable import * #from .FilePanel import * diff --git a/bindings/storage/Volume.cpp b/bindings/storage/Volume.cpp index 9d1704c..24d768e 100644 --- a/bindings/storage/Volume.cpp +++ b/bindings/storage/Volume.cpp @@ -2,16 +2,19 @@ #include #include #include +#include #include +#include +#include namespace py = pybind11; -using namespace BPrivate; +/*using namespace BPrivate; using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +using namespace BPackageKit;*/ -void define_Volume(py::module_& m) +PYBIND11_MODULE(Volume, m) { py::class_(m, "BVolume") .def(py::init(), "") @@ -27,8 +30,18 @@ py::class_(m, "BVolume") .def("BlockSize", &BVolume::BlockSize, "") .def("GetName", &BVolume::GetName, "", py::arg("name")) .def("SetName", &BVolume::SetName, "", py::arg("name")) -.def("GetIcon", py::overload_cast(&BVolume::GetIcon), "", py::arg("icon"), py::arg("which")) -.def("GetIcon", py::overload_cast(&BVolume::GetIcon), "", py::arg("_data"), py::arg("_size"), py::arg("_type")) +.def("GetIcon", py::overload_cast(&BVolume::GetIcon, py::const_), "", py::arg("icon"), py::arg("which")) +//.def("GetIcon", py::overload_cast(&BVolume::GetIcon, py::const_), "", py::arg("_data"), py::arg("_size"), py::arg("_type")) +.def("GetIcon", [](BVolume& self, size_t size, type_code type){ + uint8_t* data; + status_t result = self.GetIcon(&data, &size, &type); + py::array_t array = py::array_t( + {static_cast(size)}, + {sizeof(uint8_t)}, + data + ); + return py::make_tuple(array, result); +}, "", py::arg("size"), py::arg("type")) .def("IsRemovable", &BVolume::IsRemovable, "") .def("IsReadOnly", &BVolume::IsReadOnly, "") .def("IsPersistent", &BVolume::IsPersistent, "") From b62115501289a58a6e881a37a43baae4f1a72594 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 23:30:27 +0100 Subject: [PATCH 133/155] Add Volume.cpp VolumeRoster.cpp SymLink.cpp --- Jamfile | 3 +++ bindings/__init__.py | 2 ++ bindings/storage/SymLink.cpp | 14 +++++++++----- bindings/storage/Volume.cpp | 4 ++-- bindings/storage/VolumeRoster.cpp | 4 ++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Jamfile b/Jamfile index b232352..18b4113 100644 --- a/Jamfile +++ b/Jamfile @@ -177,10 +177,13 @@ local sourceFiles = StorageDefs.cpp Entry.cpp Node.cpp + Directory.cpp File.cpp Volume.cpp + VolumeRoster.cpp Path.cpp + SymLink.cpp Statable.cpp #FilePanel.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 73c2c30..8fa4e03 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -80,9 +80,11 @@ from .StorageDefs import * from .Entry import * from .Node import * +from .SymLink import * from .Directory import * from .File import * from .Volume import * +from .VolumeRoster import * from .Path import * from .Statable import * #from .FilePanel import * diff --git a/bindings/storage/SymLink.cpp b/bindings/storage/SymLink.cpp index 17014e8..59ab885 100644 --- a/bindings/storage/SymLink.cpp +++ b/bindings/storage/SymLink.cpp @@ -4,14 +4,18 @@ #include #include +#include +#include +#include +#include namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; -void define_SymLink(py::module_& m) +PYBIND11_MODULE(SymLink, m) { py::class_(m, "BSymLink") .def(py::init(), "") diff --git a/bindings/storage/Volume.cpp b/bindings/storage/Volume.cpp index 24d768e..37f4e69 100644 --- a/bindings/storage/Volume.cpp +++ b/bindings/storage/Volume.cpp @@ -9,10 +9,10 @@ #include namespace py = pybind11; -/*using namespace BPrivate; +using namespace BPrivate; using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; -using namespace BPackageKit;*/ +//using namespace BPackageKit; PYBIND11_MODULE(Volume, m) { diff --git a/bindings/storage/VolumeRoster.cpp b/bindings/storage/VolumeRoster.cpp index 6ee6d14..b86280a 100644 --- a/bindings/storage/VolumeRoster.cpp +++ b/bindings/storage/VolumeRoster.cpp @@ -9,9 +9,9 @@ namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +//using namespace BPackageKit; -void define_VolumeRoster(py::module_& m) +PYBIND11_MODULE(VolumeRoster, m) { py::class_(m, "BVolumeRoster") .def(py::init(), "") From 0cc49761d8714ae0053c9e0d68eab32a6755f82a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 7 Dec 2023 02:04:51 +0100 Subject: [PATCH 134/155] Add Resources.cpp ResourceString.cpp PathFinder.cpp --- Jamfile | 3 +++ bindings/__init__.py | 2 ++ bindings/storage/PathFinder.cpp | 25 +++++++++++----------- bindings/storage/ResourceStrings.cpp | 29 +++++++++++++++++++------ bindings/storage/Resources.cpp | 32 ++++++++++++++-------------- 5 files changed, 56 insertions(+), 35 deletions(-) diff --git a/Jamfile b/Jamfile index 18b4113..771800c 100644 --- a/Jamfile +++ b/Jamfile @@ -183,8 +183,11 @@ local sourceFiles = Volume.cpp VolumeRoster.cpp Path.cpp + PathFinder.cpp SymLink.cpp Statable.cpp + Resources.cpp + ResourceStrings.cpp #FilePanel.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 8fa4e03..677b6ab 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -87,6 +87,8 @@ from .VolumeRoster import * from .Path import * from .Statable import * +from .Resources import * +from .ResourceStrings import * #from .FilePanel import * _BWindow=BWindow diff --git a/bindings/storage/PathFinder.cpp b/bindings/storage/PathFinder.cpp index 9a9c0ca..70a900c 100644 --- a/bindings/storage/PathFinder.cpp +++ b/bindings/storage/PathFinder.cpp @@ -4,26 +4,27 @@ #include #include +#include namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; -void define_PathFinder(py::module_& m) +PYBIND11_MODULE(PathFinder, m) { -m.attr("BPackageResolvableExpression") = py::cast(BPackageResolvableExpression); +//m.attr("BPackageResolvableExpression") = py::cast(BPackageResolvableExpression); py::class_(m, "BPathFinder") .def(py::init(), "", py::arg("codePointer")=NULL, py::arg("dependency")=NULL) .def(py::init(), "", py::arg("path"), py::arg("dependency")=NULL) .def(py::init(), "", py::arg("ref"), py::arg("dependency")=NULL) -.def(py::init(), "", py::arg("expression"), py::arg("dependency")=NULL) +//.def(py::init(), "", py::arg("expression"), py::arg("dependency")=NULL) .def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("codePointer")=NULL, py::arg("dependency")=NULL) .def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("path"), py::arg("dependency")=NULL) .def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("ref"), py::arg("dependency")=NULL) -.def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("expression"), py::arg("dependency")=NULL) +//.def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("expression"), py::arg("dependency")=NULL) .def("FindPath", [](BPathFinder& self,const char * architecture,path_base_directory baseDirectory,const char * subPath,unsigned int flags) { BPath _path; status_t r = self.FindPath(architecture, baseDirectory, subPath, flags, _path); @@ -48,25 +49,25 @@ py::class_(m, "BPathFinder") return std::make_tuple(r,_path); } , "", py::arg("baseDirectory")) -.def_static("FindPaths", [](BPathFinder& self,const char * architecture,path_base_directory baseDirectory,const char * subPath,unsigned int flags) { +.def("FindPaths", [](BPathFinder& self,const char * architecture,path_base_directory baseDirectory,const char * subPath,uint32 flags) { BStringList _paths; static status_t r = self.FindPaths(architecture, baseDirectory, subPath, flags, _paths); return std::make_tuple(r,_paths); } , "", py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) -.def_static("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath,unsigned int flags) { +.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath,uint32 flags) { BStringList _paths; static status_t r = self.FindPaths(baseDirectory, subPath, flags, _paths); return std::make_tuple(r,_paths); } , "", py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) -.def_static("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath) { +.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath) { BStringList _paths; static status_t r = self.FindPaths(baseDirectory, subPath, _paths); return std::make_tuple(r,_paths); } , "", py::arg("baseDirectory"), py::arg("subPath")) -.def_static("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory) { +.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory) { BStringList _paths; static status_t r = self.FindPaths(baseDirectory, _paths); return std::make_tuple(r,_paths); diff --git a/bindings/storage/ResourceStrings.cpp b/bindings/storage/ResourceStrings.cpp index 2578fd0..9107362 100644 --- a/bindings/storage/ResourceStrings.cpp +++ b/bindings/storage/ResourceStrings.cpp @@ -4,14 +4,29 @@ #include #include +#include namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; -void define_ResourceStrings(py::module_& m) +class PyBResourceStrings : public BResourceStrings{ + public: + using BResourceStrings::BResourceStrings; + BString* NewString(int32 id) override { + PYBIND11_OVERLOAD(BString*, BResourceStrings, NewString, id); + } + const char* FindString(int32 id) override { + PYBIND11_OVERLOAD(const char*, BResourceStrings, FindString, id); + } + status_t SetStringFile(const entry_ref* ref) override { + PYBIND11_OVERLOAD(status_t, BResourceStrings, SetStringFile, ref); + } +}; + +PYBIND11_MODULE(ResourceStrings, m) { py::class_(m, "BResourceStrings") .def(py::init(), "") @@ -22,7 +37,7 @@ py::class_(m, "BResourceStrings") .def("SetStringFile", &BResourceStrings::SetStringFile, "", py::arg("ref")) .def("GetStringFile", &BResourceStrings::GetStringFile, "", py::arg("outRef")) ; - +/* it's protected(?) py::class_<_string_id_hash>(m, "_string_id_hash") .def(py::init(), "") .def("assign_string", &_string_id_hash::assign_string, "", py::arg("str"), py::arg("makeCopy")) @@ -33,6 +48,6 @@ py::class_<_string_id_hash>(m, "_string_id_hash") .def_readwrite("_reserved1", &_string_id_hash::_reserved1, "") .def_readwrite("_reserved2", &_string_id_hash::_reserved2, "") ; - +*/ } diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index 4b7a9df..a917490 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -6,16 +6,16 @@ #include namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; -void define_Resources(py::module_& m) +PYBIND11_MODULE(Resources, m) { -m.attr("ResourcesContainer") = py::cast(ResourcesContainer); +//m.attr("ResourcesContainer") = py::cast(ResourcesContainer); -m.attr("ResourceFile") = py::cast(ResourceFile); +//m.attr("ResourceFile") = py::cast(ResourceFile); py::class_(m, "BResources") .def(py::init(), "") @@ -30,25 +30,25 @@ py::class_(m, "BResources") .def("Unset", &BResources::Unset, "") .def("InitCheck", &BResources::InitCheck, "") .def("File", &BResources::File, "") -.def("LoadResource", py::overload_cast(&BResources::LoadResource), "", py::arg("type"), py::arg("id"), py::arg("_size")) +.def("LoadResource", py::overload_cast(&BResources::LoadResource), "", py::arg("type"), py::arg("id"), py::arg("_size")) .def("LoadResource", py::overload_cast(&BResources::LoadResource), "", py::arg("type"), py::arg("name"), py::arg("_size")) .def("PreloadResourceType", &BResources::PreloadResourceType, "", py::arg("type")=0) .def("Sync", &BResources::Sync, "") .def("MergeFrom", &BResources::MergeFrom, "", py::arg("fromFile")) .def("WriteTo", &BResources::WriteTo, "", py::arg("file")) .def("AddResource", &BResources::AddResource, "", py::arg("type"), py::arg("id"), py::arg("data"), py::arg("length"), py::arg("name")=NULL) -.def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) +.def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("name")) -.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byIndex"), py::arg("typeFound"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) -.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) -.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andID"), py::arg("nameFound"), py::arg("lengthFound")) -.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andName"), py::arg("idFound"), py::arg("lengthFound")) -.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byPointer"), py::arg("typeFound"), py::arg("idFound"), py::arg("lengthFound"), py::arg("nameFound")) +//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byIndex"), py::arg("typeFound"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) +//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) +//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andID"), py::arg("nameFound"), py::arg("lengthFound")) +.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andName"), py::arg("idFound"), py::arg("lengthFound")) +//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byPointer"), py::arg("typeFound"), py::arg("idFound"), py::arg("lengthFound"), py::arg("nameFound")) .def("RemoveResource", py::overload_cast(&BResources::RemoveResource), "", py::arg("resource")) -.def("RemoveResource", py::overload_cast(&BResources::RemoveResource), "", py::arg("type"), py::arg("id")) +.def("RemoveResource", py::overload_cast(&BResources::RemoveResource), "", py::arg("type"), py::arg("id")) .def("WriteResource", &BResources::WriteResource, "", py::arg("type"), py::arg("id"), py::arg("data"), py::arg("offset"), py::arg("length")) .def("ReadResource", &BResources::ReadResource, "", py::arg("type"), py::arg("id"), py::arg("data"), py::arg("offset"), py::arg("length")) -.def("FindResource", py::overload_cast(&BResources::FindResource), "", py::arg("type"), py::arg("id"), py::arg("lengthFound")) +.def("FindResource", py::overload_cast(&BResources::FindResource), "", py::arg("type"), py::arg("id"), py::arg("lengthFound")) .def("FindResource", py::overload_cast(&BResources::FindResource), "", py::arg("type"), py::arg("name"), py::arg("lengthFound")) ; From 3523aae5caecd30a636fb3f0f4b7d19fd538f0ee Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 06:30:15 +0100 Subject: [PATCH 135/155] Add Query.cpp attempt-Fix PathFinder.cpp --- Jamfile | 1 + bindings/__init__.py | 1 + bindings/storage/PathFinder.cpp | 6 ++++-- bindings/storage/Query.cpp | 14 ++++++++------ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Jamfile b/Jamfile index 771800c..d33c1b9 100644 --- a/Jamfile +++ b/Jamfile @@ -188,6 +188,7 @@ local sourceFiles = Statable.cpp Resources.cpp ResourceStrings.cpp + Query.cpp #FilePanel.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 677b6ab..7073381 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -89,6 +89,7 @@ from .Statable import * from .Resources import * from .ResourceStrings import * +from .Query import * #from .FilePanel import * _BWindow=BWindow diff --git a/bindings/storage/PathFinder.cpp b/bindings/storage/PathFinder.cpp index 70a900c..4bbbc37 100644 --- a/bindings/storage/PathFinder.cpp +++ b/bindings/storage/PathFinder.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include namespace py = pybind11; @@ -20,11 +22,11 @@ py::class_(m, "BPathFinder") .def(py::init(), "", py::arg("codePointer")=NULL, py::arg("dependency")=NULL) .def(py::init(), "", py::arg("path"), py::arg("dependency")=NULL) .def(py::init(), "", py::arg("ref"), py::arg("dependency")=NULL) -//.def(py::init(), "", py::arg("expression"), py::arg("dependency")=NULL) +//.def(py::init(), "", py::arg("expression"), py::arg("dependency")=NULL) //BResolvableExpression .def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("codePointer")=NULL, py::arg("dependency")=NULL) .def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("path"), py::arg("dependency")=NULL) .def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("ref"), py::arg("dependency")=NULL) -//.def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("expression"), py::arg("dependency")=NULL) +//.def("SetTo", py::overload_cast(&BPathFinder::SetTo), "", py::arg("expression"), py::arg("dependency")=NULL) //BResolvableExpression .def("FindPath", [](BPathFinder& self,const char * architecture,path_base_directory baseDirectory,const char * subPath,unsigned int flags) { BPath _path; status_t r = self.FindPath(architecture, baseDirectory, subPath, flags, _path); diff --git a/bindings/storage/Query.cpp b/bindings/storage/Query.cpp index d9152c0..4a11050 100644 --- a/bindings/storage/Query.cpp +++ b/bindings/storage/Query.cpp @@ -4,14 +4,16 @@ #include #include +#include +#include namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; -using namespace BPackageKit; +//using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; -void define_Query(py::module_& m) +PYBIND11_MODULE(Query, m) { py::enum_(m, "query_op", "") .value("B_INVALID_OP", query_op::B_INVALID_OP, "") @@ -30,11 +32,11 @@ py::enum_(m, "query_op", "") .value("_B_RESERVED_OP_", query_op::_B_RESERVED_OP_, "") .export_values(); -m.attr("QueryNode") = py::cast(QueryNode); +//m.attr("QueryNode") = py::cast(QueryNode); -m.attr("QueryStack") = py::cast(QueryStack); +//m.attr("QueryStack") = py::cast(QueryStack); -m.attr("QueryTree") = py::cast(QueryTree); +//m.attr("QueryTree") = py::cast(QueryTree); py::class_(m, "BQuery") .def(py::init(), "") From 1441554a29bc8211a961fe2b7154750074734dea Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 08:09:05 +0100 Subject: [PATCH 136/155] Fix NodeMonitor, Add EntryList.cpp --- Jamfile | 2 + bindings/__init__.py | 3 ++ bindings/storage/EntryList.cpp | 24 +++++++++++- bindings/storage/NodeMonitor.cpp | 64 ++++++++++++++++---------------- bindings/storage/Query.cpp | 2 + bindings/storage/Statable.cpp | 1 + 6 files changed, 63 insertions(+), 33 deletions(-) diff --git a/Jamfile b/Jamfile index d33c1b9..0d8e1aa 100644 --- a/Jamfile +++ b/Jamfile @@ -188,7 +188,9 @@ local sourceFiles = Statable.cpp Resources.cpp ResourceStrings.cpp + EntryList.cpp Query.cpp + NodeMonitor.cpp #FilePanel.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 7073381..38b5be4 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -89,7 +89,10 @@ from .Statable import * from .Resources import * from .ResourceStrings import * +from .EntryList import * from .Query import * +from .NodeMonitor import * + #from .FilePanel import * _BWindow=BWindow diff --git a/bindings/storage/EntryList.cpp b/bindings/storage/EntryList.cpp index 92e6c6f..7434303 100644 --- a/bindings/storage/EntryList.cpp +++ b/bindings/storage/EntryList.cpp @@ -4,13 +4,33 @@ #include #include +#include namespace py = pybind11; +class PyBEntryList : public BEntryList { +public: + using BEntryList::BEntryList; + status_t GetNextEntry(BEntry* entry, bool traverse = false) override { + PYBIND11_OVERLOAD_PURE(status_t, BEntryList, GetNextEntry, entry, traverse); + } + status_t GetNextRef(entry_ref* ref) override { + PYBIND11_OVERLOAD_PURE(status_t, BEntryList, GetNextRef, ref); + } + int32 GetNextDirents(struct dirent* direntBuffer, size_t bufferSize, int32 maxEntries = INT_MAX) override { + PYBIND11_OVERLOAD_PURE(int32, BEntryList, GetNextDirents, direntBuffer, bufferSize, maxEntries); + } + status_t Rewind() override { + PYBIND11_OVERLOAD_PURE(status_t, BEntryList, Rewind); + } + int32 CountEntries() override { + PYBIND11_OVERLOAD_PURE(int32, BEntryList, CountEntries); + } +}; -void define_EntryList(py::module_& m) +PYBIND11_MODULE(EntryList, m) { -py::class_(m, "BEntryList") +py::class_(m, "BEntryList") .def(py::init(), "") .def("GetNextEntry", &BEntryList::GetNextEntry, "", py::arg("entry"), py::arg("traverse")=false) .def("GetNextRef", &BEntryList::GetNextRef, "", py::arg("ref")) diff --git a/bindings/storage/NodeMonitor.cpp b/bindings/storage/NodeMonitor.cpp index cee4d88..929b5ed 100644 --- a/bindings/storage/NodeMonitor.cpp +++ b/bindings/storage/NodeMonitor.cpp @@ -4,44 +4,46 @@ #include #include +#include +#include +#include namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; -void define_NodeMonitor(py::module_& m) +PYBIND11_MODULE(NodeMonitor, m) { -m.attr("B_STOP_WATCHING") = py::cast(B_STOP_WATCHING); -m.attr("B_WATCH_NAME") = py::cast(B_WATCH_NAME); -m.attr("B_WATCH_STAT") = py::cast(B_WATCH_STAT); -m.attr("B_WATCH_ATTR") = py::cast(B_WATCH_ATTR); -m.attr("B_WATCH_DIRECTORY") = py::cast(B_WATCH_DIRECTORY); -m.attr("B_WATCH_ALL") = py::cast(B_WATCH_ALL); -m.attr("B_WATCH_MOUNT") = py::cast(B_WATCH_MOUNT); -m.attr("B_WATCH_INTERIM_STAT") = py::cast(B_WATCH_INTERIM_STAT); -m.attr("B_WATCH_CHILDREN") = py::cast(B_WATCH_CHILDREN); - -m.attr("B_STAT_MODE") = py::cast(B_STAT_MODE); -m.attr("B_STAT_UID") = py::cast(B_STAT_UID); -m.attr("B_STAT_GID") = py::cast(B_STAT_GID); -m.attr("B_STAT_SIZE") = py::cast(B_STAT_SIZE); -m.attr("B_STAT_ACCESS_TIME") = py::cast(B_STAT_ACCESS_TIME); -m.attr("B_STAT_MODIFICATION_TIME") = py::cast(B_STAT_MODIFICATION_TIME); -m.attr("B_STAT_CREATION_TIME") = py::cast(B_STAT_CREATION_TIME); -m.attr("B_STAT_CHANGE_TIME") = py::cast(B_STAT_CHANGE_TIME); -m.attr("B_STAT_INTERIM_UPDATE") = py::cast(B_STAT_INTERIM_UPDATE); - -m.def("watch_volume", py::overload_cast(&watch_volume), "", py::arg("volume"), py::arg("flags"), py::arg("target")); - -m.def("watch_volume", py::overload_cast(&watch_volume), "", py::arg("volume"), py::arg("flags"), py::arg("handler"), py::arg("looper")=NULL); - -m.def("watch_node", py::overload_cast(&watch_node), "", py::arg("node"), py::arg("flags"), py::arg("target")); - -m.def("watch_node", py::overload_cast(&watch_node), "", py::arg("node"), py::arg("flags"), py::arg("handler"), py::arg("looper")=NULL); +m.def("watch_volume", py::overload_cast(&watch_volume), "", py::arg("volume"), py::arg("flags"), py::arg("target")); + +m.def("watch_volume", py::overload_cast(&watch_volume), "", py::arg("volume"), py::arg("flags"), py::arg("handler"), py::arg("looper")=NULL); + +m.def("watch_node", py::overload_cast(&watch_node), "", py::arg("node"), py::arg("flags"), py::arg("target")); + +m.def("watch_node", py::overload_cast(&watch_node), "", py::arg("node"), py::arg("flags"), py::arg("handler"), py::arg("looper")=NULL); m.def("stop_watching", py::overload_cast(&stop_watching), "", py::arg("target")); m.def("stop_watching", py::overload_cast(&stop_watching), "", py::arg("handler"), py::arg("looper")=NULL); +m.attr("B_STOP_WATCHING") = 0x0000; //these have been hardcoded due to fault on loading module +m.attr("B_WATCH_NAME") = 0x0001; +m.attr("B_WATCH_STAT") = 0x0002; +m.attr("B_WATCH_ATTR") = 0x0004; +m.attr("B_WATCH_DIRECTORY") = 0x0008; +m.attr("B_WATCH_ALL") = 0x000f; +m.attr("B_WATCH_MOUNT") = 0x0010; +m.attr("B_WATCH_INTERIM_STAT") = 0x0020; +m.attr("B_WATCH_CHILDREN") = 0x0040; + +m.attr("B_STAT_MODE") = 0x0001; +m.attr("B_STAT_UID") = 0x0002; +m.attr("B_STAT_GID") = 0x0004; +m.attr("B_STAT_SIZE") = 0x0008; +m.attr("B_STAT_ACCESS_TIME") = 0x0010; +m.attr("B_STAT_MODIFICATION_TIME") = 0x0020; +m.attr("B_STAT_CREATION_TIME") = 0x0040; +m.attr("B_STAT_CHANGE_TIME") = 0x0080; +m.attr("B_STAT_INTERIM_UPDATE") = 0x1000; } diff --git a/bindings/storage/Query.cpp b/bindings/storage/Query.cpp index 4a11050..7474ef9 100644 --- a/bindings/storage/Query.cpp +++ b/bindings/storage/Query.cpp @@ -13,6 +13,8 @@ using namespace BPrivate::Storage; //using namespace BPrivate::Storage::Mime; //using namespace BPackageKit; +//Add overrides + PYBIND11_MODULE(Query, m) { py::enum_(m, "query_op", "") diff --git a/bindings/storage/Statable.cpp b/bindings/storage/Statable.cpp index ad34e4e..1b1002f 100644 --- a/bindings/storage/Statable.cpp +++ b/bindings/storage/Statable.cpp @@ -13,6 +13,7 @@ using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; using namespace BPackageKit;*/ +// ADD GetStat overload_pure ? PYBIND11_MODULE(Statable, m) { py::class_(m, "BStatable") From 1394127b1ba3ab8d7760a99737086df104396ea9 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Wed, 6 Dec 2023 08:29:50 +0100 Subject: [PATCH 137/155] Initial NodeInfo.cpp, load Mime first --- bindings/storage/NodeInfo.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bindings/storage/NodeInfo.cpp b/bindings/storage/NodeInfo.cpp index 34e66e3..3deda95 100644 --- a/bindings/storage/NodeInfo.cpp +++ b/bindings/storage/NodeInfo.cpp @@ -4,13 +4,14 @@ #include #include +#include namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; -void define_NodeInfo(py::module_& m) +PYBIND11_MODULE(NodeInfo, m) { py::class_(m, "BNodeInfo") .def(py::init(), "") @@ -19,15 +20,15 @@ py::class_(m, "BNodeInfo") .def("InitCheck", &BNodeInfo::InitCheck, "") .def("GetType", &BNodeInfo::GetType, "", py::arg("type")) .def("SetType", &BNodeInfo::SetType, "", py::arg("type")) -.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) +.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) .def("SetIcon", py::overload_cast(&BNodeInfo::SetIcon), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) -.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon), "", py::arg("data"), py::arg("size"), py::arg("type")) -.def("SetIcon", py::overload_cast(&BNodeInfo::SetIcon), "", py::arg("data"), py::arg("size")) +//.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon, py::const_), "", py::arg("data"), py::arg("size"), py::arg("type")) +.def("SetIcon", py::overload_cast(&BNodeInfo::SetIcon), "", py::arg("data"), py::arg("size")) .def("GetPreferredApp", &BNodeInfo::GetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("SetPreferredApp", &BNodeInfo::SetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("GetAppHint", &BNodeInfo::GetAppHint, "", py::arg("ref")) .def("SetAppHint", &BNodeInfo::SetAppHint, "", py::arg("ref")) -.def("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) +.def("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) .def_static("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon), "", py::arg("ref"), py::arg("icon"), py::arg("which")=B_LARGE_ICON) ; From 9767b26d8b525f684413fc1c538be54722a7d6ca Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Thu, 7 Dec 2023 23:03:37 +0100 Subject: [PATCH 138/155] Add Mime MimeType NodeInfo Resources --- Jamfile | 3 ++ bindings/__init__.py | 3 ++ bindings/storage/Mime.cpp | 21 ++++++------ bindings/storage/MimeType.cpp | 61 +++++++++++++++++----------------- bindings/storage/NodeInfo.cpp | 2 +- bindings/storage/Resources.cpp | 21 ++++++++++++ 6 files changed, 70 insertions(+), 41 deletions(-) diff --git a/Jamfile b/Jamfile index 0d8e1aa..1c65c6d 100644 --- a/Jamfile +++ b/Jamfile @@ -186,11 +186,14 @@ local sourceFiles = PathFinder.cpp SymLink.cpp Statable.cpp + Mime.cpp + MimeType.cpp Resources.cpp ResourceStrings.cpp EntryList.cpp Query.cpp NodeMonitor.cpp + NodeInfo.cpp #FilePanel.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 38b5be4..3093d77 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -87,11 +87,14 @@ from .VolumeRoster import * from .Path import * from .Statable import * +from .Mime import * +from .MimeType import * from .Resources import * from .ResourceStrings import * from .EntryList import * from .Query import * from .NodeMonitor import * +from .NodeInfo import * #from .FilePanel import * diff --git a/bindings/storage/Mime.cpp b/bindings/storage/Mime.cpp index f4fdeda..9423798 100644 --- a/bindings/storage/Mime.cpp +++ b/bindings/storage/Mime.cpp @@ -4,35 +4,36 @@ #include #include +#include namespace py = pybind11; -void define_Mime(py::module_& m) +PYBIND11_MODULE(Mime, m) { py::enum_(m, "icon_size", "") .value("B_LARGE_ICON", icon_size::B_LARGE_ICON, "") .value("B_MINI_ICON", icon_size::B_MINI_ICON, "") .export_values(); -m.attr("B_UPDATE_MIME_INFO_NO_FORCE") = py::cast(B_UPDATE_MIME_INFO_NO_FORCE); -m.attr("B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE") = py::cast(B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE); -m.attr("B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL") = py::cast(B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL); +m.attr("B_UPDATE_MIME_INFO_NO_FORCE") = 0; //hardcoded, not reading enum +m.attr("B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE") = 1; +m.attr("B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL") = 2; -m.attr("BBitmap") = py::cast(BBitmap); +//m.attr("BBitmap") = py::cast(BBitmap); m.def("update_mime_info", &update_mime_info, "", py::arg("path"), py::arg("recursive"), py::arg("synchronous"), py::arg("force")); m.def("create_app_meta_mime", &create_app_meta_mime, "", py::arg("path"), py::arg("recursive"), py::arg("synchronous"), py::arg("force")); -m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("size")); +m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("size")); m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("which")); -m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("_data"), py::arg("_size"), py::arg("_type")); - +//m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("_data"), py::arg("_size"), py::arg("_type")); +// unsigned char ->uint8** m.def("get_named_icon", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("icon"), py::arg("which")); -m.def("get_named_icon", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("_data"), py::arg("_size"), py::arg("_type")); - +//m.def("get_named_icon", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("_data"), py::arg("_size"), py::arg("_type")); +// unsigned char ->uint8** } diff --git a/bindings/storage/MimeType.cpp b/bindings/storage/MimeType.cpp index 982752c..8d56704 100644 --- a/bindings/storage/MimeType.cpp +++ b/bindings/storage/MimeType.cpp @@ -4,40 +4,41 @@ #include #include +#include namespace py = pybind11; using namespace BPrivate; using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; -void define_MimeType(py::module_& m) +PYBIND11_MODULE(MimeType, m) { py::enum_(m, "app_verb", "") .value("B_OPEN", app_verb::B_OPEN, "") .export_values(); -m.attr("B_META_MIME_CHANGED") = py::cast(B_META_MIME_CHANGED); +m.attr("B_META_MIME_CHANGED") = 'MMCH'; -m.attr("B_ICON_CHANGED") = py::cast(B_ICON_CHANGED); -m.attr("B_PREFERRED_APP_CHANGED") = py::cast(B_PREFERRED_APP_CHANGED); -m.attr("B_ATTR_INFO_CHANGED") = py::cast(B_ATTR_INFO_CHANGED); -m.attr("B_FILE_EXTENSIONS_CHANGED") = py::cast(B_FILE_EXTENSIONS_CHANGED); -m.attr("B_SHORT_DESCRIPTION_CHANGED") = py::cast(B_SHORT_DESCRIPTION_CHANGED); -m.attr("B_LONG_DESCRIPTION_CHANGED") = py::cast(B_LONG_DESCRIPTION_CHANGED); -m.attr("B_ICON_FOR_TYPE_CHANGED") = py::cast(B_ICON_FOR_TYPE_CHANGED); -m.attr("B_APP_HINT_CHANGED") = py::cast(B_APP_HINT_CHANGED); -m.attr("B_MIME_TYPE_CREATED") = py::cast(B_MIME_TYPE_CREATED); -m.attr("B_MIME_TYPE_DELETED") = py::cast(B_MIME_TYPE_DELETED); -m.attr("B_SNIFFER_RULE_CHANGED") = py::cast(B_SNIFFER_RULE_CHANGED); -m.attr("B_SUPPORTED_TYPES_CHANGED") = py::cast(B_SUPPORTED_TYPES_CHANGED); -m.attr("B_EVERYTHING_CHANGED") = py::cast(B_EVERYTHING_CHANGED); +m.attr("B_ICON_CHANGED") = 0x00000001; +m.attr("B_PREFERRED_APP_CHANGED") = 0x00000002; +m.attr("B_ATTR_INFO_CHANGED") = 0x00000004; +m.attr("B_FILE_EXTENSIONS_CHANGED") = 0x00000008; +m.attr("B_SHORT_DESCRIPTION_CHANGED") = 0x00000010; +m.attr("B_LONG_DESCRIPTION_CHANGED") = 0x00000020; +m.attr("B_ICON_FOR_TYPE_CHANGED") = 0x00000040; +m.attr("B_APP_HINT_CHANGED") = 0x00000080; +m.attr("B_MIME_TYPE_CREATED") = 0x00000100; +m.attr("B_MIME_TYPE_DELETED") = 0x00000200; +m.attr("B_SNIFFER_RULE_CHANGED") = 0x00000400; +m.attr("B_SUPPORTED_TYPES_CHANGED") = 0x00000800; +m.attr("B_EVERYTHING_CHANGED") = (int)0xFFFFFFFF; -m.attr("B_META_MIME_MODIFIED") = py::cast(B_META_MIME_MODIFIED); -m.attr("B_META_MIME_DELETED") = py::cast(B_META_MIME_DELETED); +m.attr("B_META_MIME_MODIFIED") = 'MMMD'; +m.attr("B_META_MIME_DELETED") = 'MMDL'; -m.attr("MimeDatabase") = py::cast(MimeDatabase); +//m.attr("MimeDatabase") = py::cast(BPrivate::MimeDatabase); -m.attr("CreateAppMetaMimeThread") = py::cast(CreateAppMetaMimeThread); +//m.attr("CreateAppMetaMimeThread") = py::cast(CreateAppMetaMimeThread); m.attr("B_APP_MIME_TYPE") = py::cast(B_APP_MIME_TYPE); @@ -58,17 +59,17 @@ py::class_(m, "BMimeType") .def("Unset", &BMimeType::Unset, "") .def("InitCheck", &BMimeType::InitCheck, "") .def("Type", &BMimeType::Type, "") -.def("IsValid", py::overload_cast<>(&BMimeType::IsValid), "") +.def("IsValid", py::overload_cast<>(&BMimeType::IsValid, py::const_), "") .def("IsSupertypeOnly", &BMimeType::IsSupertypeOnly, "") .def("GetSupertype", &BMimeType::GetSupertype, "", py::arg("supertype")) -.def("__eq__", py::overload_cast(&BMimeType::operator==), "", py::arg("type")) -.def("__eq__", py::overload_cast(&BMimeType::operator==), "", py::arg("type")) +.def("__eq__", py::overload_cast(&BMimeType::operator==, py::const_), "", py::arg("type")) +.def("__eq__", py::overload_cast(&BMimeType::operator==, py::const_), "", py::arg("type")) .def("Contains", &BMimeType::Contains, "", py::arg("type")) .def("Install", &BMimeType::Install, "") .def("Delete", &BMimeType::Delete, "") .def("IsInstalled", &BMimeType::IsInstalled, "") -.def("GetIcon", py::overload_cast(&BMimeType::GetIcon), "", py::arg("icon"), py::arg("size")) -.def("GetIcon", py::overload_cast(&BMimeType::GetIcon), "", py::arg("_data"), py::arg("_size")) +.def("GetIcon", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) +//.def("GetIcon", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("_data"), py::arg("_size")) .def("GetPreferredApp", &BMimeType::GetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("GetAttrInfo", &BMimeType::GetAttrInfo, "", py::arg("info")) .def("GetFileExtensions", &BMimeType::GetFileExtensions, "", py::arg("extensions")) @@ -76,7 +77,7 @@ py::class_(m, "BMimeType") .def("GetLongDescription", &BMimeType::GetLongDescription, "", py::arg("description")) .def("GetSupportingApps", &BMimeType::GetSupportingApps, "", py::arg("signatures")) .def("SetIcon", py::overload_cast(&BMimeType::SetIcon), "", py::arg("icon"), py::arg("size")) -.def("SetIcon", py::overload_cast(&BMimeType::SetIcon), "", py::arg("data"), py::arg("size")) +//.def("SetIcon", py::overload_cast(&BMimeType::SetIcon), "", py::arg("data"), py::arg("size")) .def("SetPreferredApp", &BMimeType::SetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("SetAttrInfo", &BMimeType::SetAttrInfo, "", py::arg("info")) .def("SetFileExtensions", &BMimeType::SetFileExtensions, "", py::arg("extensions")) @@ -86,18 +87,18 @@ py::class_(m, "BMimeType") .def_static("GetInstalledTypes", py::overload_cast(&BMimeType::GetInstalledTypes), "", py::arg("types")) .def_static("GetInstalledTypes", py::overload_cast(&BMimeType::GetInstalledTypes), "", py::arg("supertype"), py::arg("subtypes")) .def_static("GetWildcardApps", &BMimeType::GetWildcardApps, "", py::arg("wildcardApps")) -.def_static("IsValid", py::overload_cast(&BMimeType::IsValid), "", py::arg("mimeType")) +.def_static("IsValid_static", py::overload_cast(&BMimeType::IsValid), "", py::arg("mimeType")) .def("GetAppHint", &BMimeType::GetAppHint, "", py::arg("ref")) .def("SetAppHint", &BMimeType::SetAppHint, "", py::arg("ref")) -.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType), "", py::arg("type"), py::arg("icon"), py::arg("which")) -.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType), "", py::arg("type"), py::arg("_data"), py::arg("_size")) +.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("icon"), py::arg("which")) +//.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("_data"), py::arg("_size")) .def("SetIconForType", py::overload_cast(&BMimeType::SetIconForType), "", py::arg("type"), py::arg("icon"), py::arg("which")) -.def("SetIconForType", py::overload_cast(&BMimeType::SetIconForType), "", py::arg("type"), py::arg("data"), py::arg("size")) +.def("SetIconForType", py::overload_cast(&BMimeType::SetIconForType), "", py::arg("type"), py::arg("data"), py::arg("size")) .def("GetSnifferRule", &BMimeType::GetSnifferRule, "", py::arg("result")) .def("SetSnifferRule", &BMimeType::SetSnifferRule, "", py::arg("")) .def_static("CheckSnifferRule", &BMimeType::CheckSnifferRule, "", py::arg("rule"), py::arg("parseError")) .def_static("GuessMimeType", py::overload_cast(&BMimeType::GuessMimeType), "", py::arg("file"), py::arg("type")) -.def_static("GuessMimeType", py::overload_cast(&BMimeType::GuessMimeType), "", py::arg("buffer"), py::arg("length"), py::arg("type")) +.def_static("GuessMimeType", py::overload_cast(&BMimeType::GuessMimeType), "", py::arg("buffer"), py::arg("length"), py::arg("type")) .def_static("GuessMimeType", py::overload_cast(&BMimeType::GuessMimeType), "", py::arg("filename"), py::arg("type")) .def_static("StartWatching", &BMimeType::StartWatching, "", py::arg("target")) .def_static("StopWatching", &BMimeType::StopWatching, "", py::arg("target")) diff --git a/bindings/storage/NodeInfo.cpp b/bindings/storage/NodeInfo.cpp index 3deda95..8452449 100644 --- a/bindings/storage/NodeInfo.cpp +++ b/bindings/storage/NodeInfo.cpp @@ -29,7 +29,7 @@ py::class_(m, "BNodeInfo") .def("GetAppHint", &BNodeInfo::GetAppHint, "", py::arg("ref")) .def("SetAppHint", &BNodeInfo::SetAppHint, "", py::arg("ref")) .def("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) -.def_static("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon), "", py::arg("ref"), py::arg("icon"), py::arg("which")=B_LARGE_ICON) +.def_static("GetTrackerIcon_static", py::overload_cast(&BNodeInfo::GetTrackerIcon), "", py::arg("ref"), py::arg("icon"), py::arg("which")=B_LARGE_ICON) ; diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index a917490..c19e1d0 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -11,6 +11,17 @@ namespace py = pybind11; //using namespace BPrivate::Storage::Mime; //using namespace BPackageKit; +std::vector convertConstCharPtrArray(const char** constCharPtrArray, std::size_t size) { + std::vector charPtrVector; + + for (std::size_t i = 0; i < size; ++i) { + // Copia ogni stringa di caratteri nel vettore + charPtrVector.push_back(const_cast(constCharPtrArray[i])); + } + + return charPtrVector; +} + PYBIND11_MODULE(Resources, m) { //m.attr("ResourcesContainer") = py::cast(ResourcesContainer); @@ -40,6 +51,16 @@ py::class_(m, "BResources") .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("name")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byIndex"), py::arg("typeFound"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) +.def("GetResourceInfo", [](BResources& self, int32 byIndex){ + type_code typeFound; + int32 idFound; + const char * nameFound; + //std::vector nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); + std::vector charPtrVector = convertConstCharPtrArray(&nameFound, lengthFound); + return py::make_tuple(result, typeFound, idFound, charPtrVector, lengthFound); +}, "", py::arg("byIndex")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andID"), py::arg("nameFound"), py::arg("lengthFound")) .def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andName"), py::arg("idFound"), py::arg("lengthFound")) From 219ef33d10334374dfcb0f183d379c5d14e529e2 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 00:53:27 +0100 Subject: [PATCH 139/155] Fix GetResourceInfo --- Jamfile | 1 + bindings/__init__.py | 2 +- bindings/storage/Resources.cpp | 39 +++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Jamfile b/Jamfile index 1c65c6d..f9491f6 100644 --- a/Jamfile +++ b/Jamfile @@ -194,6 +194,7 @@ local sourceFiles = Query.cpp NodeMonitor.cpp NodeInfo.cpp + #DiskDeviceDefs.cpp #FilePanel.cpp ; diff --git a/bindings/__init__.py b/bindings/__init__.py index 3093d77..554e272 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -95,7 +95,7 @@ from .Query import * from .NodeMonitor import * from .NodeInfo import * - +#from .DiskDeviceDefs import * #from .FilePanel import * _BWindow=BWindow diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index c19e1d0..da9c30d 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -2,6 +2,7 @@ #include #include #include +//#include #include @@ -10,7 +11,7 @@ namespace py = pybind11; //using namespace BPrivate::Storage; //using namespace BPrivate::Storage::Mime; //using namespace BPackageKit; - +/* std::vector convertConstCharPtrArray(const char** constCharPtrArray, std::size_t size) { std::vector charPtrVector; @@ -20,7 +21,7 @@ std::vector convertConstCharPtrArray(const char** constCharPtrArray, std: } return charPtrVector; -} +}*/ PYBIND11_MODULE(Resources, m) { @@ -51,6 +52,32 @@ py::class_(m, "BResources") .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("name")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byIndex"), py::arg("typeFound"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) +.def("GetResourceInfo", [](BResources& self, int32 byIndex){ + type_code typeFound; + int32 idFound; + const char * nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); + + // Utilizza py::bytes per rappresentare la sequenza di byte + py::bytes byteSequence(nameFound, lengthFound); + + return py::make_tuple(result, static_cast(typeFound), idFound, byteSequence, lengthFound); +}, "", py::arg("byIndex")) +/* +.def("GetResourceInfo", [](BResources& self, int32 byIndex){ + type_code typeFound; + int32 idFound; + const char * nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); + + // Utilizza py::str per rappresentare la stringa in Python + py::str pythonString(nameFound, lengthFound); + + return py::make_tuple(result, static_cast(typeFound), idFound, pythonString, lengthFound); +}, "", py::arg("byIndex"))*/ +/* .def("GetResourceInfo", [](BResources& self, int32 byIndex){ type_code typeFound; int32 idFound; @@ -58,9 +85,11 @@ py::class_(m, "BResources") //std::vector nameFound; size_t lengthFound; bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); - std::vector charPtrVector = convertConstCharPtrArray(&nameFound, lengthFound); - return py::make_tuple(result, typeFound, idFound, charPtrVector, lengthFound); -}, "", py::arg("byIndex")) + py::array_t array = py::array_t({static_cast(lengthFound)}, {sizeof(const char)}, nameFound); + return py::make_tuple(result, typeFound, idFound, array, lengthFound); + //std::vector charPtrVector = convertConstCharPtrArray(&nameFound, lengthFound); +// return py::make_tuple(result, typeFound, idFound, charPtrVector, lengthFound); +}, "", py::arg("byIndex"))*/ //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andID"), py::arg("nameFound"), py::arg("lengthFound")) .def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andName"), py::arg("idFound"), py::arg("lengthFound")) From 50dd81d27d0fdefc50ffb158f66c6e1c2bcbc421 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 06:23:31 +0100 Subject: [PATCH 140/155] Fix GetResourceInfo --- bindings/storage/Resources.cpp | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index da9c30d..12fde5b 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -64,32 +64,7 @@ py::class_(m, "BResources") return py::make_tuple(result, static_cast(typeFound), idFound, byteSequence, lengthFound); }, "", py::arg("byIndex")) -/* -.def("GetResourceInfo", [](BResources& self, int32 byIndex){ - type_code typeFound; - int32 idFound; - const char * nameFound; - size_t lengthFound; - bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); - - // Utilizza py::str per rappresentare la stringa in Python - py::str pythonString(nameFound, lengthFound); - return py::make_tuple(result, static_cast(typeFound), idFound, pythonString, lengthFound); -}, "", py::arg("byIndex"))*/ -/* -.def("GetResourceInfo", [](BResources& self, int32 byIndex){ - type_code typeFound; - int32 idFound; - const char * nameFound; - //std::vector nameFound; - size_t lengthFound; - bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); - py::array_t array = py::array_t({static_cast(lengthFound)}, {sizeof(const char)}, nameFound); - return py::make_tuple(result, typeFound, idFound, array, lengthFound); - //std::vector charPtrVector = convertConstCharPtrArray(&nameFound, lengthFound); -// return py::make_tuple(result, typeFound, idFound, charPtrVector, lengthFound); -}, "", py::arg("byIndex"))*/ //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andID"), py::arg("nameFound"), py::arg("lengthFound")) .def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andName"), py::arg("idFound"), py::arg("lengthFound")) From 1c3399c49cb9fdfcd3a9203cd99da5ec7a97141a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 06:49:00 +0100 Subject: [PATCH 141/155] Fix others GetResourceInfo --- bindings/storage/Resources.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index 12fde5b..6b43d85 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -58,17 +58,42 @@ py::class_(m, "BResources") const char * nameFound; size_t lengthFound; bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); - - // Utilizza py::bytes per rappresentare la sequenza di byte + py::bytes byteSequence(nameFound, lengthFound); return py::make_tuple(result, static_cast(typeFound), idFound, byteSequence, lengthFound); }, "", py::arg("byIndex")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) +.def("GetResourceInfo", [](BResources& self, type_code byType, int32 andIndex){ + int32 idFound; + const char * nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byType, andIndex, &idFound, &nameFound, &lengthFound); + + py::bytes byteSequence(nameFound, lengthFound); + + return py::make_tuple(result, idFound, byteSequence, lengthFound); +}, "", py::arg("byType"), py::arg("andIndex")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andID"), py::arg("nameFound"), py::arg("lengthFound")) -.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andName"), py::arg("idFound"), py::arg("lengthFound")) -//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byPointer"), py::arg("typeFound"), py::arg("idFound"), py::arg("lengthFound"), py::arg("nameFound")) +.def("GetResourceInfo", [](BResources& self, type_code byType, int32 andID){ + const char * nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byType, andID, &nameFound, &lengthFound); + + py::bytes byteSequence(nameFound, lengthFound); + + return py::make_tuple(result, byteSequence, lengthFound); +}, "", py::arg("byType"), py::arg("andID")) +//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andName"), py::arg("idFound"), py::arg("lengthFound"))// <- TODO!! +.def("GetResourceInfo", [](BResources& self, type_code byType, const char* andName){ + int32 idFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byType, andName, &idFound, &lengthFound); + + return py::make_tuple(result, idFound, lengthFound); +}, "", py::arg("byType"), py::arg("andID")) +//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byPointer"), py::arg("typeFound"), py::arg("idFound"), py::arg("lengthFound"), py::arg("nameFound")) //<- There's no pointer in Python .def("RemoveResource", py::overload_cast(&BResources::RemoveResource), "", py::arg("resource")) .def("RemoveResource", py::overload_cast(&BResources::RemoveResource), "", py::arg("type"), py::arg("id")) .def("WriteResource", &BResources::WriteResource, "", py::arg("type"), py::arg("id"), py::arg("data"), py::arg("offset"), py::arg("length")) From e1622f54ac71eda2259826036537eb3cb83e639b Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 08:06:31 +0100 Subject: [PATCH 142/155] Distinguish two GetResourceInfo cases --- bindings/storage/Resources.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index 6b43d85..96604b3 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -62,10 +62,10 @@ py::class_(m, "BResources") py::bytes byteSequence(nameFound, lengthFound); return py::make_tuple(result, static_cast(typeFound), idFound, byteSequence, lengthFound); -}, "", py::arg("byIndex")) +}, "", py::arg("byIndex")) //<- this works //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) -.def("GetResourceInfo", [](BResources& self, type_code byType, int32 andIndex){ +.def("GetResourceInfo_byTypeAndIndex", [](BResources& self, type_code byType, int32 andIndex){ int32 idFound; const char * nameFound; size_t lengthFound; @@ -76,7 +76,7 @@ py::class_(m, "BResources") return py::make_tuple(result, idFound, byteSequence, lengthFound); }, "", py::arg("byType"), py::arg("andIndex")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andID"), py::arg("nameFound"), py::arg("lengthFound")) -.def("GetResourceInfo", [](BResources& self, type_code byType, int32 andID){ +.def("GetResourceInfo_byTypeAndID", [](BResources& self, type_code byType, int32 andID){ const char * nameFound; size_t lengthFound; bool result = self.GetResourceInfo(byType, andID, &nameFound, &lengthFound); @@ -92,7 +92,7 @@ py::class_(m, "BResources") bool result = self.GetResourceInfo(byType, andName, &idFound, &lengthFound); return py::make_tuple(result, idFound, lengthFound); -}, "", py::arg("byType"), py::arg("andID")) +}, "", py::arg("byType"), py::arg("andName")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byPointer"), py::arg("typeFound"), py::arg("idFound"), py::arg("lengthFound"), py::arg("nameFound")) //<- There's no pointer in Python .def("RemoveResource", py::overload_cast(&BResources::RemoveResource), "", py::arg("resource")) .def("RemoveResource", py::overload_cast(&BResources::RemoveResource), "", py::arg("type"), py::arg("id")) From 78ada8515768e14a20811523fe31a41e9fb27617 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 20:59:52 +0100 Subject: [PATCH 143/155] comments to evaluate --- bindings/storage/Resources.cpp | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index 96604b3..bca8ef7 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -42,16 +42,44 @@ py::class_(m, "BResources") .def("Unset", &BResources::Unset, "") .def("InitCheck", &BResources::InitCheck, "") .def("File", &BResources::File, "") -.def("LoadResource", py::overload_cast(&BResources::LoadResource), "", py::arg("type"), py::arg("id"), py::arg("_size")) -.def("LoadResource", py::overload_cast(&BResources::LoadResource), "", py::arg("type"), py::arg("name"), py::arg("_size")) +.def("LoadResource", py::overload_cast(&BResources::LoadResource), "", py::arg("type"), py::arg("id"), py::arg("_size")) // should we keep these 2 functions? they return const void * +.def("LoadResource", py::overload_cast(&BResources::LoadResource), "", py::arg("type"), py::arg("name"), py::arg("_size")) // .def("PreloadResourceType", &BResources::PreloadResourceType, "", py::arg("type")=0) .def("Sync", &BResources::Sync, "") .def("MergeFrom", &BResources::MergeFrom, "", py::arg("fromFile")) .def("WriteTo", &BResources::WriteTo, "", py::arg("file")) -.def("AddResource", &BResources::AddResource, "", py::arg("type"), py::arg("id"), py::arg("data"), py::arg("length"), py::arg("name")=NULL) +.def("AddResource", &BResources::AddResource, "", py::arg("type"), py::arg("id"), py::arg("data"), py::arg("length"), py::arg("name")=NULL) // to change <- cannot pass void* data from python .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("name")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byIndex"), py::arg("typeFound"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) +/*.def("GetResourceInfo", [](BResources& self, int32 byIndex) { + type_code typeFound; + int32 idFound; + const char* nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); + + // Creare una lista Python per contenere i risultati + py::list resultList; + + // Iterare attraverso i dati restituiti estrarre ciascun blocco + size_t currentIndex = 0; + while (currentIndex < lengthFound) { + // Trova la lunghezza del blocco corrente + size_t currentBlockLength = strlen(nameFound + currentIndex); + + // Estrai il blocco corrente + std::string currentBlock(nameFound + currentIndex, currentBlockLength); + + // Aggiungi il blocco alla lista Python + resultList.append(py::bytes(currentBlock)); + + // Passa al prossimo blocco + currentIndex += currentBlockLength + 1; // +1 per includere il terminatore nullo + } + + return py::make_tuple(result, static_cast(typeFound), idFound, resultList); +}, "", py::arg("byIndex"))*/ .def("GetResourceInfo", [](BResources& self, int32 byIndex){ type_code typeFound; int32 idFound; @@ -63,7 +91,6 @@ py::class_(m, "BResources") return py::make_tuple(result, static_cast(typeFound), idFound, byteSequence, lengthFound); }, "", py::arg("byIndex")) //<- this works - //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byType"), py::arg("andIndex"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) .def("GetResourceInfo_byTypeAndIndex", [](BResources& self, type_code byType, int32 andIndex){ int32 idFound; From 5447260c0a3a380a80611827a357b84e97841c10 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 21:20:29 +0100 Subject: [PATCH 144/155] reorder __init__ and integrade commented public modules --- bindings/__init__.py | 5 +++-- bindings/storage/Directory.cpp | 2 +- bindings/storage/Entry.cpp | 2 +- bindings/storage/Query.cpp | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bindings/__init__.py b/bindings/__init__.py index 554e272..523907b 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -78,20 +78,21 @@ from .fs_attr import * from .StorageDefs import * +from .Statable import * from .Entry import * from .Node import * from .SymLink import * -from .Directory import * from .File import * from .Volume import * from .VolumeRoster import * from .Path import * -from .Statable import * + from .Mime import * from .MimeType import * from .Resources import * from .ResourceStrings import * from .EntryList import * +from .Directory import * from .Query import * from .NodeMonitor import * from .NodeInfo import * diff --git a/bindings/storage/Directory.cpp b/bindings/storage/Directory.cpp index 31e7bbd..83ebc1c 100644 --- a/bindings/storage/Directory.cpp +++ b/bindings/storage/Directory.cpp @@ -17,7 +17,7 @@ namespace py = pybind11; PYBIND11_MODULE(Directory,m) { -py::class_(m, "BDirectory")//, BEntryList verify if needed +py::class_(m, "BDirectory")// verify if needed .def(py::init(), "") .def(py::init(), "", py::arg("dir")) .def(py::init(), "", py::arg("ref")) diff --git a/bindings/storage/Entry.cpp b/bindings/storage/Entry.cpp index 82bbabd..8788129 100644 --- a/bindings/storage/Entry.cpp +++ b/bindings/storage/Entry.cpp @@ -29,7 +29,7 @@ py::class_(m, "entry_ref") .def_readwrite("name", &entry_ref::name, "") ; -py::class_(m, "BEntry") //Commented out BStatable verify if needed +py::class_(m, "BEntry") .def(py::init(), "") .def(py::init(), "", py::arg("dir"), py::arg("path"), py::arg("traverse")=false) .def(py::init(), "", py::arg("ref"), py::arg("traverse")=false) diff --git a/bindings/storage/Query.cpp b/bindings/storage/Query.cpp index 7474ef9..ec238c8 100644 --- a/bindings/storage/Query.cpp +++ b/bindings/storage/Query.cpp @@ -14,6 +14,26 @@ using namespace BPrivate::Storage; //using namespace BPackageKit; //Add overrides +class PyBQuery : public BQuery { +public: + using BQuery::BQuery; + status_t GetNextEntry(BEntry* entry, bool traverse = false) override { + PYBIND11_OVERLOAD_PURE(status_t, BQuery, GetNextEntry, entry, traverse); + } + status_t GetNextRef(entry_ref* ref) override { + PYBIND11_OVERLOAD_PURE(status_t, BQuery, GetNextRef, ref); + } + int32 GetNextDirents(struct dirent* direntBuffer, size_t length, int32 count = INT_MAX) override { + PYBIND11_OVERLOAD_PURE(int32, BQuery, GetNextDirents, direntBuffer, length, count); + } + status_t Rewind() override { + PYBIND11_OVERLOAD_PURE(status_t, BQuery, Rewind); + } + int32 CountEntries() override { + PYBIND11_OVERLOAD_PURE(int32, BQuery, CountEntries); + } + +}; PYBIND11_MODULE(Query, m) { From 9cb2e978d7fe59157ec8f2eefd5c2c36c0ee27bb Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 21:34:46 +0100 Subject: [PATCH 145/155] Add File.cpp overrides --- bindings/storage/File.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bindings/storage/File.cpp b/bindings/storage/File.cpp index a43698b..3eb59a3 100644 --- a/bindings/storage/File.cpp +++ b/bindings/storage/File.cpp @@ -12,6 +12,34 @@ namespace py = pybind11; +class PyBFile : public BFile { +public: + using BFile::BFile; + ssize_t Read(void *buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BFile, Read, buffer, size); + } + ssize_t ReadAt(off_t location, void *buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BFile, ReadAt, location, buffer, size); + } + ssize_t Write(const void *buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BFile, Write, buffer, size); + } + ssize_t WriteAt(off_t location, const void *buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BFile, WriteAt, location, buffer, size); + } + off_t Seek(off_t offset, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BFile, Seek, offset, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BFile, Position); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BFile, SetSize, size); + } + status_t GetSize(off_t* size) const override { + PYBIND11_OVERLOAD(status_t, BFile, GetSize, size); + } +}; PYBIND11_MODULE(File, m) { From ee626ca7b7d0b3124395fda08022385de1697ccf Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Fri, 8 Dec 2023 23:36:30 +0100 Subject: [PATCH 146/155] Uncomment/Fix Mime functions --- bindings/storage/Mime.cpp | 58 +++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/bindings/storage/Mime.cpp b/bindings/storage/Mime.cpp index 9423798..af43e4a 100644 --- a/bindings/storage/Mime.cpp +++ b/bindings/storage/Mime.cpp @@ -2,12 +2,35 @@ #include #include #include +#include #include #include namespace py = pybind11; +/* +std::tuple> get_device_icon_py(const char *device) { + uint8 *data = nullptr; + size_t size = 0; + type_code type = B_MINI_ICON_TYPE; // default value + // Chiamata alla funzione C++ + status_t result = get_device_icon(device, &data, &size, &type); + + //if (result != B_OK) { + // // Gestisci l'errore in qualche modo + // throw std::runtime_error("Errore nella funzione get_device_icon"); + //} + + // Creazione di un array NumPy dalla memoria ottenuta + auto capsule = py::capsule(data, [](void *d) { + // Implementa la logica per deallocare la memoria + // In questo esempio, si presume che la memoria sia stata allocata con new[] + delete[] static_cast(d); + }); + + return std::make_tuple(result,py::array_t({static_cast(size)}, {sizeof(uint8)}, data, capsule)); +}*/ PYBIND11_MODULE(Mime, m) { @@ -17,8 +40,8 @@ py::enum_(m, "icon_size", "") .export_values(); m.attr("B_UPDATE_MIME_INFO_NO_FORCE") = 0; //hardcoded, not reading enum -m.attr("B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE") = 1; -m.attr("B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL") = 2; +m.attr("B_UPDATE_MIME_INFO_FORCE_KEEP_TYPE") = 1; //hardcoded, not reading enum +m.attr("B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL") = 2; //hardcoded, not reading enum //m.attr("BBitmap") = py::cast(BBitmap); @@ -26,14 +49,39 @@ m.def("update_mime_info", &update_mime_info, "", py::arg("path"), py::arg("recur m.def("create_app_meta_mime", &create_app_meta_mime, "", py::arg("path"), py::arg("recursive"), py::arg("synchronous"), py::arg("force")); -m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("size")); +m.def("get_device_icon_toVoid", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("size")); -m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("which")); +m.def("get_device_icon_toBitmap", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("which")); //m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("_data"), py::arg("_size"), py::arg("_type")); +m.def("get_device_icon_toArray", [](const char * device){ + uint8 *data = nullptr; + size_t size = 0; + type_code type = B_MINI_ICON_TYPE; // default value + status_t result = get_device_icon(device, &data, &size, &type); + auto capsule = py::capsule(data, [](void *d) { + // Implementa la logica per deallocare la memoria + // In questo esempio, si presume che la memoria sia stata allocata con new[] + delete[] static_cast(d); + }); + + return std::make_tuple(result,py::array_t({static_cast(size)}, {sizeof(uint8)}, data, capsule)); + }, "", py::arg("device")); // unsigned char ->uint8** -m.def("get_named_icon", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("icon"), py::arg("which")); +m.def("get_named_icon_toBitmap", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("icon"), py::arg("which")); //m.def("get_named_icon", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("_data"), py::arg("_size"), py::arg("_type")); // unsigned char ->uint8** +m.def("get_named_icon_toArray", [](const char *name, unsigned char iconSize, size_t *size, type_code *iconType) { + uint8 *data = nullptr; + status_t result = get_named_icon(name, &data, size, iconType); + + auto capsule = py::capsule(data, [](void *d) { + // Implementa la logica per deallocare la memoria, se necessario + // In questo esempio, si presume che la memoria sia stata allocata con new[] + delete[] static_cast(d); + }); + + return std::make_tuple(result, py::array_t({static_cast(*size)}, {sizeof(uint8)}, data, capsule)); +}, "", py::arg("name"), py::arg("iconSize"), py::arg("size"), py::arg("iconType")); } From dfbf618225a4c20ff35ba7a7c9d812805cb46c3e Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 08:39:44 +0100 Subject: [PATCH 147/155] Fix and change funcnames for GetIcon --- bindings/storage/MimeType.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/bindings/storage/MimeType.cpp b/bindings/storage/MimeType.cpp index 8d56704..0d15687 100644 --- a/bindings/storage/MimeType.cpp +++ b/bindings/storage/MimeType.cpp @@ -2,8 +2,10 @@ #include #include #include +#include #include +#include #include namespace py = pybind11; @@ -68,8 +70,37 @@ py::class_(m, "BMimeType") .def("Install", &BMimeType::Install, "") .def("Delete", &BMimeType::Delete, "") .def("IsInstalled", &BMimeType::IsInstalled, "") -.def("GetIcon", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) +//.def("GetIcon_toBitmap", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) //changed names to GetIcon +.def("GetIcon_toBitmap", [](const BMimeType &self, icon_size size) { + BBitmap *icon; + // Chiamata alla funzione C++ + if(size==B_LARGE_ICON){ + icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32); + } else { + icon = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32); + } + status_t result = self.GetIcon(icon, size); + + // Restituisci una tupla contenente il risultato e l'oggetto BBitmap + return std::make_tuple(result, icon); + }, "", py::arg("size")=B_LARGE_ICON) //.def("GetIcon", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("_data"), py::arg("_size")) +.def("GetIcon_toVector", [](const BMimeType &self) { + uint8 *data = nullptr; + size_t size = 0; + + // Chiamata alla funzione C++ + status_t result = self.GetIcon(&data, &size); + + // Creazione di un array NumPy dalla memoria ottenuta + auto capsule = py::capsule(data, [](void *d) { + // Implementa la logica per deallocare la memoria + // In questo esempio, si presume che la memoria sia stata allocata con new[] + delete[] static_cast(d); + }); + + return std::make_tuple(result, py::array_t({static_cast(size)}, {sizeof(uint8)}, data, capsule)); +}, "") .def("GetPreferredApp", &BMimeType::GetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("GetAttrInfo", &BMimeType::GetAttrInfo, "", py::arg("info")) .def("GetFileExtensions", &BMimeType::GetFileExtensions, "", py::arg("extensions")) From c90fbe0b53593f3c1be731fb801b1850af3db6f6 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 10:34:57 +0100 Subject: [PATCH 148/155] Enable SetIcon for uint8* data --- bindings/storage/MimeType.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/bindings/storage/MimeType.cpp b/bindings/storage/MimeType.cpp index 0d15687..bbac19e 100644 --- a/bindings/storage/MimeType.cpp +++ b/bindings/storage/MimeType.cpp @@ -108,7 +108,7 @@ py::class_(m, "BMimeType") .def("GetLongDescription", &BMimeType::GetLongDescription, "", py::arg("description")) .def("GetSupportingApps", &BMimeType::GetSupportingApps, "", py::arg("signatures")) .def("SetIcon", py::overload_cast(&BMimeType::SetIcon), "", py::arg("icon"), py::arg("size")) -//.def("SetIcon", py::overload_cast(&BMimeType::SetIcon), "", py::arg("data"), py::arg("size")) +.def("SetIcon", py::overload_cast(&BMimeType::SetIcon), "", py::arg("data"), py::arg("size")) .def("SetPreferredApp", &BMimeType::SetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("SetAttrInfo", &BMimeType::SetAttrInfo, "", py::arg("info")) .def("SetFileExtensions", &BMimeType::SetFileExtensions, "", py::arg("extensions")) @@ -121,8 +121,31 @@ py::class_(m, "BMimeType") .def_static("IsValid_static", py::overload_cast(&BMimeType::IsValid), "", py::arg("mimeType")) .def("GetAppHint", &BMimeType::GetAppHint, "", py::arg("ref")) .def("SetAppHint", &BMimeType::SetAppHint, "", py::arg("ref")) -.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("icon"), py::arg("which")) +//.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("icon"), py::arg("which")) +.def("GetIconForType_toBitmap", [](const BMimeType &self, const char *type, icon_size size) { + BBitmap *icon; + // Chiamata alla funzione C++ + if(size==B_LARGE_ICON){ + icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32); + } else { + icon = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32); + } + status_t result = self.GetIconForType(type, icon, size); + + // Restituisci una tupla contenente il risultato e l'oggetto BBitmap + return std::make_tuple(result, icon); + }, "", py::arg("type"), py::arg("size")=B_LARGE_ICON) //.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("_data"), py::arg("_size")) +.def("GetIconForType_toVector", [](const BMimeType &self, const char *type) { + size_t size; + uint8_t *data; + status_t result = self.GetIconForType(type, &data, &size); + auto capsule = py::capsule(data, [](void *d) { + delete[] static_cast(d); + }); + + return std::make_tuple(result, py::array_t({static_cast(size)}, {sizeof(uint8_t)}, data, capsule)); + }, "",py::arg("type")) .def("SetIconForType", py::overload_cast(&BMimeType::SetIconForType), "", py::arg("type"), py::arg("icon"), py::arg("which")) .def("SetIconForType", py::overload_cast(&BMimeType::SetIconForType), "", py::arg("type"), py::arg("data"), py::arg("size")) .def("GetSnifferRule", &BMimeType::GetSnifferRule, "", py::arg("result")) From 3b2ab61c91f4a24e396f3638239a7967d226b66d Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 11:54:20 +0100 Subject: [PATCH 149/155] Change GetIcon return values and function name --- bindings/storage/NodeInfo.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bindings/storage/NodeInfo.cpp b/bindings/storage/NodeInfo.cpp index 8452449..c10bb9d 100644 --- a/bindings/storage/NodeInfo.cpp +++ b/bindings/storage/NodeInfo.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -20,15 +21,35 @@ py::class_(m, "BNodeInfo") .def("InitCheck", &BNodeInfo::InitCheck, "") .def("GetType", &BNodeInfo::GetType, "", py::arg("type")) .def("SetType", &BNodeInfo::SetType, "", py::arg("type")) -.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) +//.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) +.def("GetIcon_toBitmap", [](const BNodeInfo& self, icon_size which){ + BBitmap *icon; + if(which==B_LARGE_ICON){ + icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32); + } else { + icon = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32); + } + status_t result = self.GetIcon(icon, which); + return std::make_tuple(result, icon); +}, "", py::arg("which")=B_LARGE_ICON) .def("SetIcon", py::overload_cast(&BNodeInfo::SetIcon), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) //.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon, py::const_), "", py::arg("data"), py::arg("size"), py::arg("type")) +.def("GetIcon_toArray", [](const BNodeInfo &self) { + size_t size; + type_code type; + uint8_t *data; + status_t result = self.GetIcon(&data, &size, &type); + auto capsule = py::capsule(data, [](void *d) { + delete[] static_cast(d); + }); + return std::make_tuple(result, py::array_t({static_cast(size)}, {sizeof(uint8_t)}, data, capsule), type); +}, "") .def("SetIcon", py::overload_cast(&BNodeInfo::SetIcon), "", py::arg("data"), py::arg("size")) .def("GetPreferredApp", &BNodeInfo::GetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("SetPreferredApp", &BNodeInfo::SetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) .def("GetAppHint", &BNodeInfo::GetAppHint, "", py::arg("ref")) .def("SetAppHint", &BNodeInfo::SetAppHint, "", py::arg("ref")) -.def("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) +.def("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON)// TODO .def_static("GetTrackerIcon_static", py::overload_cast(&BNodeInfo::GetTrackerIcon), "", py::arg("ref"), py::arg("icon"), py::arg("which")=B_LARGE_ICON) ; From 9068dc1e5409db0617fa367daa72dcf88ece19db Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 16:18:31 +0100 Subject: [PATCH 150/155] changed geticon method of defining function --- bindings/storage/Volume.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bindings/storage/Volume.cpp b/bindings/storage/Volume.cpp index 37f4e69..fc84dd8 100644 --- a/bindings/storage/Volume.cpp +++ b/bindings/storage/Volume.cpp @@ -14,6 +14,17 @@ using namespace BPrivate::Storage; using namespace BPrivate::Storage::Mime; //using namespace BPackageKit; +py::tuple GetIcon_toArray(BVolume& self, size_t size, type_code type){ + uint8_t* data; + status_t result = self.GetIcon(&data, &size, &type); + py::array_t array = py::array_t( + {static_cast(size)}, + {sizeof(uint8_t)}, + data + ); + return py::make_tuple(result, array); +}; + PYBIND11_MODULE(Volume, m) { py::class_(m, "BVolume") @@ -32,6 +43,8 @@ py::class_(m, "BVolume") .def("SetName", &BVolume::SetName, "", py::arg("name")) .def("GetIcon", py::overload_cast(&BVolume::GetIcon, py::const_), "", py::arg("icon"), py::arg("which")) //.def("GetIcon", py::overload_cast(&BVolume::GetIcon, py::const_), "", py::arg("_data"), py::arg("_size"), py::arg("_type")) +.def("GetIcon", &GetIcon_toArray, "", py::arg("_size"), py::arg("_type")) +/* .def("GetIcon", [](BVolume& self, size_t size, type_code type){ uint8_t* data; status_t result = self.GetIcon(&data, &size, &type); @@ -41,7 +54,7 @@ py::class_(m, "BVolume") data ); return py::make_tuple(array, result); -}, "", py::arg("size"), py::arg("type")) +}, "", py::arg("size"), py::arg("type"))*/ .def("IsRemovable", &BVolume::IsRemovable, "") .def("IsReadOnly", &BVolume::IsReadOnly, "") .def("IsPersistent", &BVolume::IsPersistent, "") From 5c2cf77aeca6cda706f6276e6c0b883726874a5c Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 14:23:50 +0100 Subject: [PATCH 151/155] Fix static definition --- bindings/storage/PathFinder.cpp | 51 +++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/bindings/storage/PathFinder.cpp b/bindings/storage/PathFinder.cpp index 4bbbc37..f3a506e 100644 --- a/bindings/storage/PathFinder.cpp +++ b/bindings/storage/PathFinder.cpp @@ -13,6 +13,29 @@ namespace py = pybind11; //using namespace BPrivate::Storage; //using namespace BPrivate::Storage::Mime; //using namespace BPackageKit; +class BPathFinderWrapper { +public: + static std::tuple FindPaths(BPathFinder& self, const char* architecture, path_base_directory baseDirectory, const char* subPath, uint32 flags) { + BStringList _paths; + status_t result = self.FindPaths(architecture, baseDirectory, subPath, flags, _paths); + return std::make_tuple(result, _paths); + } + static std::tuple FindPaths(BPathFinder& self, path_base_directory baseDirectory, const char* subPath, uint32 flags) { + BStringList _paths; + status_t result = self.FindPaths(baseDirectory, subPath, flags, _paths); + return std::make_tuple(result, _paths); + } + static std::tuple FindPaths(BPathFinder& self, path_base_directory baseDirectory, const char* subPath) { + BStringList _paths; + status_t result = self.FindPaths(baseDirectory, subPath, _paths); + return std::make_tuple(result, _paths); + } + static std::tuple FindPaths(BPathFinder& self, path_base_directory baseDirectory) { + BStringList _paths; + status_t result = self.FindPaths(baseDirectory, _paths); + return std::make_tuple(result, _paths); + } +}; PYBIND11_MODULE(PathFinder, m) { @@ -51,30 +74,34 @@ py::class_(m, "BPathFinder") return std::make_tuple(r,_path); } , "", py::arg("baseDirectory")) -.def("FindPaths", [](BPathFinder& self,const char * architecture,path_base_directory baseDirectory,const char * subPath,uint32 flags) { +/*.def_static("FindPaths", [](BPathFinder& self,const char * architecture,path_base_directory baseDirectory,const char * subPath,uint32 flags) { BStringList _paths; - static status_t r = self.FindPaths(architecture, baseDirectory, subPath, flags, _paths); + status_t r = self.FindPaths(architecture, baseDirectory, subPath, flags, _paths); return std::make_tuple(r,_paths); } -, "", py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) -.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath,uint32 flags) { +, "", py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags"))*/ +.def_static("FindPaths", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("self"), py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) +/*.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath,uint32 flags) { BStringList _paths; - static status_t r = self.FindPaths(baseDirectory, subPath, flags, _paths); + status_t r = self.FindPaths(baseDirectory, subPath, flags, _paths); return std::make_tuple(r,_paths); } -, "", py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) -.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath) { +, "", py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags"))*/ +.def_static("FindPaths", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("self"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) +/*.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath) { BStringList _paths; - static status_t r = self.FindPaths(baseDirectory, subPath, _paths); + status_t r = self.FindPaths(baseDirectory, subPath, _paths); return std::make_tuple(r,_paths); } -, "", py::arg("baseDirectory"), py::arg("subPath")) -.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory) { +, "", py::arg("baseDirectory"), py::arg("subPath"))*/ +.def_static("FindPaths", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("self"), py::arg("baseDirectory"), py::arg("subPath")) +/*.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory) { BStringList _paths; - static status_t r = self.FindPaths(baseDirectory, _paths); + status_t r = self.FindPaths(baseDirectory, _paths); return std::make_tuple(r,_paths); } -, "", py::arg("baseDirectory")) +, "", py::arg("baseDirectory"))*/ +.def_static("FindPaths", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("self"), py::arg("baseDirectory")) ; From 2810e5096c9d76ddf6b0136561d9737cb52f0f4a Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 14:26:51 +0100 Subject: [PATCH 152/155] Hardcoded values, to complete --- bindings/storage/DiskDeviceDefs.cpp | 142 +++++++++++++++------------- 1 file changed, 75 insertions(+), 67 deletions(-) diff --git a/bindings/storage/DiskDeviceDefs.cpp b/bindings/storage/DiskDeviceDefs.cpp index bbddcc8..9fe4e06 100644 --- a/bindings/storage/DiskDeviceDefs.cpp +++ b/bindings/storage/DiskDeviceDefs.cpp @@ -7,73 +7,77 @@ namespace py = pybind11; +const char* get_current_task_description(const disk_device_job_progress_info& info) { + return info.current_task_description; +} + -void define_DiskDeviceDefs(py::module_& m) +PYBIND11_MODULE(DiskDeviceDefs, m) { -m.attr("B_PARTITION_IS_DEVICE") = py::cast(B_PARTITION_IS_DEVICE); -m.attr("B_PARTITION_FILE_SYSTEM") = py::cast(B_PARTITION_FILE_SYSTEM); -m.attr("B_PARTITION_PARTITIONING_SYSTEM") = py::cast(B_PARTITION_PARTITIONING_SYSTEM); -m.attr("B_PARTITION_READ_ONLY") = py::cast(B_PARTITION_READ_ONLY); -m.attr("B_PARTITION_MOUNTED") = py::cast(B_PARTITION_MOUNTED); -m.attr("B_PARTITION_BUSY") = py::cast(B_PARTITION_BUSY); +m.attr("B_PARTITION_IS_DEVICE") = 0x01; +m.attr("B_PARTITION_FILE_SYSTEM") = 0x02; +m.attr("B_PARTITION_PARTITIONING_SYSTEM") = 0x04; +m.attr("B_PARTITION_READ_ONLY") = 0x08; +m.attr("B_PARTITION_MOUNTED") = 0x10; +m.attr("B_PARTITION_BUSY") = 0x20; -m.attr("B_PARTITION_VALID") = py::cast(B_PARTITION_VALID); -m.attr("B_PARTITION_CORRUPT") = py::cast(B_PARTITION_CORRUPT); -m.attr("B_PARTITION_UNRECOGNIZED") = py::cast(B_PARTITION_UNRECOGNIZED); -m.attr("B_PARTITION_UNINITIALIZED") = py::cast(B_PARTITION_UNINITIALIZED); +m.attr("B_PARTITION_VALID") = B_PARTITION_VALID; +m.attr("B_PARTITION_CORRUPT") = B_PARTITION_CORRUPT; +m.attr("B_PARTITION_UNRECOGNIZED") = B_PARTITION_UNRECOGNIZED; +m.attr("B_PARTITION_UNINITIALIZED") = B_PARTITION_UNINITIALIZED; -m.attr("B_PARTITION_CHANGED_OFFSET") = py::cast(B_PARTITION_CHANGED_OFFSET); -m.attr("B_PARTITION_CHANGED_SIZE") = py::cast(B_PARTITION_CHANGED_SIZE); -m.attr("B_PARTITION_CHANGED_CONTENT_SIZE") = py::cast(B_PARTITION_CHANGED_CONTENT_SIZE); -m.attr("B_PARTITION_CHANGED_BLOCK_SIZE") = py::cast(B_PARTITION_CHANGED_BLOCK_SIZE); -m.attr("B_PARTITION_CHANGED_STATUS") = py::cast(B_PARTITION_CHANGED_STATUS); -m.attr("B_PARTITION_CHANGED_FLAGS") = py::cast(B_PARTITION_CHANGED_FLAGS); -m.attr("B_PARTITION_CHANGED_VOLUME") = py::cast(B_PARTITION_CHANGED_VOLUME); -m.attr("B_PARTITION_CHANGED_NAME") = py::cast(B_PARTITION_CHANGED_NAME); -m.attr("B_PARTITION_CHANGED_CONTENT_NAME") = py::cast(B_PARTITION_CHANGED_CONTENT_NAME); -m.attr("B_PARTITION_CHANGED_TYPE") = py::cast(B_PARTITION_CHANGED_TYPE); -m.attr("B_PARTITION_CHANGED_CONTENT_TYPE") = py::cast(B_PARTITION_CHANGED_CONTENT_TYPE); -m.attr("B_PARTITION_CHANGED_PARAMETERS") = py::cast(B_PARTITION_CHANGED_PARAMETERS); -m.attr("B_PARTITION_CHANGED_CONTENT_PARAMETERS") = py::cast(B_PARTITION_CHANGED_CONTENT_PARAMETERS); -m.attr("B_PARTITION_CHANGED_CHILDREN") = py::cast(B_PARTITION_CHANGED_CHILDREN); -m.attr("B_PARTITION_CHANGED_DESCENDANTS") = py::cast(B_PARTITION_CHANGED_DESCENDANTS); -m.attr("B_PARTITION_CHANGED_DEFRAGMENTATION") = py::cast(B_PARTITION_CHANGED_DEFRAGMENTATION); -m.attr("B_PARTITION_CHANGED_CHECK") = py::cast(B_PARTITION_CHANGED_CHECK); -m.attr("B_PARTITION_CHANGED_REPAIR") = py::cast(B_PARTITION_CHANGED_REPAIR); -m.attr("B_PARTITION_CHANGED_INITIALIZATION") = py::cast(B_PARTITION_CHANGED_INITIALIZATION); +m.attr("B_PARTITION_CHANGED_OFFSET") = 0x000001; +m.attr("B_PARTITION_CHANGED_SIZE") = 0x000002; +m.attr("B_PARTITION_CHANGED_CONTENT_SIZE") = 0x000004; +m.attr("B_PARTITION_CHANGED_BLOCK_SIZE") = 0x000008; +m.attr("B_PARTITION_CHANGED_STATUS") = 0x000010; +m.attr("B_PARTITION_CHANGED_FLAGS") = 0x000020; +m.attr("B_PARTITION_CHANGED_VOLUME") = 0x000040; +m.attr("B_PARTITION_CHANGED_NAME") = 0x000080; +m.attr("B_PARTITION_CHANGED_CONTENT_NAME") = 0x000100; +m.attr("B_PARTITION_CHANGED_TYPE") = 0x000200; +m.attr("B_PARTITION_CHANGED_CONTENT_TYPE") = 0x000400; +m.attr("B_PARTITION_CHANGED_PARAMETERS") = 0x000800; +m.attr("B_PARTITION_CHANGED_CONTENT_PARAMETERS") = 0x001000; +m.attr("B_PARTITION_CHANGED_CHILDREN") = 0x002000; +m.attr("B_PARTITION_CHANGED_DESCENDANTS") = 0x004000; +m.attr("B_PARTITION_CHANGED_DEFRAGMENTATION") = 0x008000; +m.attr("B_PARTITION_CHANGED_CHECK") = 0x010000; +m.attr("B_PARTITION_CHANGED_REPAIR") = 0x020000; +m.attr("B_PARTITION_CHANGED_INITIALIZATION") = 0x040000; -m.attr("B_DISK_DEVICE_REMOVABLE") = py::cast(B_DISK_DEVICE_REMOVABLE); -m.attr("B_DISK_DEVICE_HAS_MEDIA") = py::cast(B_DISK_DEVICE_HAS_MEDIA); -m.attr("B_DISK_DEVICE_READ_ONLY") = py::cast(B_DISK_DEVICE_READ_ONLY); -m.attr("B_DISK_DEVICE_WRITE_ONCE") = py::cast(B_DISK_DEVICE_WRITE_ONCE); -m.attr("B_DISK_DEVICE_IS_FILE") = py::cast(B_DISK_DEVICE_IS_FILE); +m.attr("B_DISK_DEVICE_REMOVABLE") = 0x01; +m.attr("B_DISK_DEVICE_HAS_MEDIA") = 0x02; +m.attr("B_DISK_DEVICE_READ_ONLY") = 0x04; +m.attr("B_DISK_DEVICE_WRITE_ONCE") = 0x08; +m.attr("B_DISK_DEVICE_IS_FILE") = 0x10; -m.attr("B_DISK_SYSTEM_IS_FILE_SYSTEM") = py::cast(B_DISK_SYSTEM_IS_FILE_SYSTEM); -m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING") = py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING); -m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING") = py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING); -m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING") = py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING); -m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING") = py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS); -m.attr("B_DISK_SYSTEM_SUPPORTS_INITIALIZING") = py::cast(B_DISK_SYSTEM_SUPPORTS_INITIALIZING); -m.attr("B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME); -m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING") = py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING); -m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED); -m.attr("B_DISK_SYSTEM_SUPPORTS_WRITING") = py::cast(B_DISK_SYSTEM_SUPPORTS_WRITING); -m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_NAME); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); -m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS") = py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); -m.attr("B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD") = py::cast(B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD); -m.attr("B_DISK_SYSTEM_SUPPORTS_NAME") = py::cast(B_DISK_SYSTEM_SUPPORTS_NAME); +m.attr("B_DISK_SYSTEM_IS_FILE_SYSTEM") = 0x000001; +m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING") = 0x000002; +m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING") = 0x000004; +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING") = 0x000008; +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING") = 0x000010; +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME") = 0x000020; +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS") = 0x000040; +m.attr("B_DISK_SYSTEM_SUPPORTS_INITIALIZING") = 0x000080; +m.attr("B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME") = 0x000100; +m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING") = 0x001000; +m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED") = 0x002000; +m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED") = 0x004000; +m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED") = 0x008000; +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED") = 0x010000; +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED") = 0x020000; +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED") = 0x040000; +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED") = 0x080000; +m.attr("B_DISK_SYSTEM_SUPPORTS_WRITING") = 0x100000; +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD") = 0x001000; +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD") = 0x002000; +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_NAME") = 0x004000; +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE") = 0x008000; +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS") = 0x010000; +m.attr("B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD") = 0x020000; +m.attr("B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD") = 0x040000; +m.attr("B_DISK_SYSTEM_SUPPORTS_NAME") = 0x080000; m.attr("B_DISK_DEVICE_JOB_BAD_TYPE") = py::cast(B_DISK_DEVICE_JOB_BAD_TYPE); m.attr("B_DISK_DEVICE_JOB_DEFRAGMENT") = py::cast(B_DISK_DEVICE_JOB_DEFRAGMENT); @@ -98,10 +102,10 @@ m.attr("B_DISK_DEVICE_JOB_SUCCEEDED") = py::cast(B_DISK_DEVICE_JOB_SUCCEEDED); m.attr("B_DISK_DEVICE_JOB_FAILED") = py::cast(B_DISK_DEVICE_JOB_FAILED); m.attr("B_DISK_DEVICE_JOB_CANCELED") = py::cast(B_DISK_DEVICE_JOB_CANCELED); -m.attr("B_DISK_DEVICE_JOB_CAN_CANCEL") = py::cast(B_DISK_DEVICE_JOB_CAN_CANCEL); -m.attr("B_DISK_DEVICE_JOB_STOP_ON_CANCEL") = py::cast(B_DISK_DEVICE_JOB_STOP_ON_CANCEL); -m.attr("B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL") = py::cast(B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL); -m.attr("B_DISK_DEVICE_JOB_CAN_PAUSE") = py::cast(B_DISK_DEVICE_JOB_CAN_PAUSE); +m.attr("B_DISK_DEVICE_JOB_CAN_CANCEL") = 0x01; +m.attr("B_DISK_DEVICE_JOB_STOP_ON_CANCEL") = 0x02; +m.attr("B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL") = 0x04; +m.attr("B_DISK_DEVICE_JOB_CAN_PAUSE") = 0x08; py::enum_(m, "B_PARAMETER_EDITOR_TYPE", "") .value("B_CREATE_PARAMETER_EDITOR", B_PARAMETER_EDITOR_TYPE::B_CREATE_PARAMETER_EDITOR, "") @@ -116,8 +120,12 @@ py::class_(m, "disk_device_job_progress_info") .def_readwrite("task_count", &disk_device_job_progress_info::task_count, "") .def_readwrite("completed_tasks", &disk_device_job_progress_info::completed_tasks, "") .def_readwrite("current_task_progress", &disk_device_job_progress_info::current_task_progress, "") -.def_readwrite("current_task_description", &disk_device_job_progress_info::current_task_description, "") +.def_property("current_task_description", + [](const disk_device_job_progress_info& info) -> py::str { + return py::str(get_current_task_description(info)); + }, + nullptr); +//.def_readwrite("current_task_description", &disk_device_job_progress_info::current_task_description, "") ; - } From 5831cd5126f05eecfe2e35ceaa268d2ab22c114f Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 14:28:50 +0100 Subject: [PATCH 153/155] Restore functions name --- bindings/storage/MimeType.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/storage/MimeType.cpp b/bindings/storage/MimeType.cpp index bbac19e..0cdeccf 100644 --- a/bindings/storage/MimeType.cpp +++ b/bindings/storage/MimeType.cpp @@ -71,7 +71,7 @@ py::class_(m, "BMimeType") .def("Delete", &BMimeType::Delete, "") .def("IsInstalled", &BMimeType::IsInstalled, "") //.def("GetIcon_toBitmap", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) //changed names to GetIcon -.def("GetIcon_toBitmap", [](const BMimeType &self, icon_size size) { +.def("GetIcon", [](const BMimeType &self, icon_size size) { BBitmap *icon; // Chiamata alla funzione C++ if(size==B_LARGE_ICON){ @@ -85,7 +85,7 @@ py::class_(m, "BMimeType") return std::make_tuple(result, icon); }, "", py::arg("size")=B_LARGE_ICON) //.def("GetIcon", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("_data"), py::arg("_size")) -.def("GetIcon_toVector", [](const BMimeType &self) { +.def("GetIcon", [](const BMimeType &self) { uint8 *data = nullptr; size_t size = 0; @@ -122,7 +122,7 @@ py::class_(m, "BMimeType") .def("GetAppHint", &BMimeType::GetAppHint, "", py::arg("ref")) .def("SetAppHint", &BMimeType::SetAppHint, "", py::arg("ref")) //.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("icon"), py::arg("which")) -.def("GetIconForType_toBitmap", [](const BMimeType &self, const char *type, icon_size size) { +.def("GetIconForType", [](const BMimeType &self, const char *type, icon_size size) { BBitmap *icon; // Chiamata alla funzione C++ if(size==B_LARGE_ICON){ @@ -136,7 +136,7 @@ py::class_(m, "BMimeType") return std::make_tuple(result, icon); }, "", py::arg("type"), py::arg("size")=B_LARGE_ICON) //.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("_data"), py::arg("_size")) -.def("GetIconForType_toVector", [](const BMimeType &self, const char *type) { +.def("GetIconForType", [](const BMimeType &self, const char *type) { size_t size; uint8_t *data; status_t result = self.GetIconForType(type, &data, &size); From 6259a6363fc74a95009c29b02a579982589d3be1 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 14:31:25 +0100 Subject: [PATCH 154/155] Fix overrides --- bindings/storage/ResourceStrings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/storage/ResourceStrings.cpp b/bindings/storage/ResourceStrings.cpp index 9107362..ac71ef4 100644 --- a/bindings/storage/ResourceStrings.cpp +++ b/bindings/storage/ResourceStrings.cpp @@ -28,7 +28,7 @@ class PyBResourceStrings : public BResourceStrings{ PYBIND11_MODULE(ResourceStrings, m) { -py::class_(m, "BResourceStrings") +py::class_(m, "BResourceStrings") .def(py::init(), "") .def(py::init(), "", py::arg("ref")) .def("InitCheck", &BResourceStrings::InitCheck, "") From f911ee62774bae5aa42e47e182bce80a01ff6ac2 Mon Sep 17 00:00:00 2001 From: Fabio Tomat Date: Sat, 9 Dec 2023 14:31:55 +0100 Subject: [PATCH 155/155] Cleanup --- bindings/storage/Resources.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/bindings/storage/Resources.cpp b/bindings/storage/Resources.cpp index bca8ef7..c3dc4c8 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -52,34 +52,6 @@ py::class_(m, "BResources") .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) .def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("name")) //.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byIndex"), py::arg("typeFound"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) -/*.def("GetResourceInfo", [](BResources& self, int32 byIndex) { - type_code typeFound; - int32 idFound; - const char* nameFound; - size_t lengthFound; - bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); - - // Creare una lista Python per contenere i risultati - py::list resultList; - - // Iterare attraverso i dati restituiti estrarre ciascun blocco - size_t currentIndex = 0; - while (currentIndex < lengthFound) { - // Trova la lunghezza del blocco corrente - size_t currentBlockLength = strlen(nameFound + currentIndex); - - // Estrai il blocco corrente - std::string currentBlock(nameFound + currentIndex, currentBlockLength); - - // Aggiungi il blocco alla lista Python - resultList.append(py::bytes(currentBlock)); - - // Passa al prossimo blocco - currentIndex += currentBlockLength + 1; // +1 per includere il terminatore nullo - } - - return py::make_tuple(result, static_cast(typeFound), idFound, resultList); -}, "", py::arg("byIndex"))*/ .def("GetResourceInfo", [](BResources& self, int32 byIndex){ type_code typeFound; int32 idFound;