diff --git a/Jamfile b/Jamfile index 0d733c9..f9491f6 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 bindings/kernel ; # Where to look for header files SubDirHdrs /system/lib/python$(python_version)/vendor-packages/pybind11/include/ ; @@ -131,6 +131,8 @@ local sourceFiles = PopUpMenu.cpp Box.cpp SeparatorItem.cpp + Alignment.cpp + SeparatorView.cpp MenuBar.cpp StatusBar.cpp CheckBox.cpp @@ -140,15 +142,60 @@ local sourceFiles = ListView.cpp ScrollView.cpp ListItem.cpp - #Bitmap.cpp - #Slider.cpp + Bitmap.cpp Picture.cpp + PictureButton.cpp StringItem.cpp TabView.cpp + ScrollBar.cpp + GraphicsDefs.cpp + Screen.cpp + Shape.cpp + Size.cpp + Slider.cpp #SupportKit + Beep.cpp + Locker.cpp + Autolock.cpp SupportDefs.cpp Archivable.cpp + TypeConstants.cpp + Architecture.cpp + DateTime.cpp + parsedate.cpp + List.cpp + String.cpp + Flattenable.cpp + StringList.cpp + DataIO.cpp + + #Kernel + fs_attr.cpp + + #StorageKit + StorageDefs.cpp + Entry.cpp + Node.cpp + + Directory.cpp + File.cpp + Volume.cpp + VolumeRoster.cpp + Path.cpp + PathFinder.cpp + SymLink.cpp + Statable.cpp + Mime.cpp + MimeType.cpp + Resources.cpp + ResourceStrings.cpp + EntryList.cpp + Query.cpp + NodeMonitor.cpp + NodeInfo.cpp + #DiskDeviceDefs.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 efb48f8..523907b 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -18,13 +18,16 @@ from .Roster import * from .Window import * from .Rect import * +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 * @@ -38,25 +41,63 @@ from .PopUpMenu import * from .Box import * from .SeparatorItem import * +from .Alignment import * +from .SeparatorView import * from .MenuBar import * from .StatusBar import * from .CheckBox import * -from .Point import * from .ColorControl import * from .RadioButton import * from .ListView import * from .ScrollView import * from .SupportDefs import * +from .TypeConstants import * from .Archivable import * from .ListItem import * -#from .Bitmap import * -#from .Slider import * +from .Bitmap import * from .Picture import * +from .PictureButton import * from .StringItem import * from .TabView import * +from .ScrollBar import * +from .Shape import * +from .Size import * +from .Slider import * +from .Beep import * +from .Architecture import * +from .Locker import * +from .Autolock import * +from .DateTime import * +from .parsedate import * +from .List import * +from .String import * +from .Flattenable import * +from .StringList import * +from .DataIO import * +from .fs_attr import * +from .StorageDefs import * +from .Statable import * +from .Entry import * +from .Node import * +from .SymLink import * +from .File import * +from .Volume import * +from .VolumeRoster import * +from .Path 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 * +#from .DiskDeviceDefs import * +#from .FilePanel import * _BWindow=BWindow _BApplication=BApplication 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) { 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")) 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")) diff --git a/bindings/app/Key.cpp b/bindings/app/Key.cpp index fd07a3f..872bad3 100644 --- a/bindings/app/Key.cpp +++ b/bindings/app/Key.cpp @@ -11,6 +11,22 @@ namespace py = pybind11; +class PyBKey : public BKey{ + public: + using BKey::BKey; + BKeyType Type() const override { + PYBIND11_OVERLOAD(BKeyType, BKey, Type); + } + 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 +46,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(), "") 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")) 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, "") 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(), "") diff --git a/bindings/interface/Alert.cpp b/bindings/interface/Alert.cpp index ae4a740..21e4d25 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) { @@ -29,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) 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")); } diff --git a/bindings/interface/Bitmap.cpp b/bindings/interface/Bitmap.cpp index 8b27717..6e5088f 100644 --- a/bindings/interface/Bitmap.cpp +++ b/bindings/interface/Bitmap.cpp @@ -7,8 +7,25 @@ #include #include #include +#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) @@ -23,12 +40,12 @@ 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) +.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")) @@ -39,15 +56,28 @@ 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, "") .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")) +.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 +85,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, "") ; diff --git a/bindings/interface/Box.cpp b/bindings/interface/Box.cpp index ff2871e..ff37704 100644 --- a/bindings/interface/Box.cpp +++ b/bindings/interface/Box.cpp @@ -8,10 +8,87 @@ 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); + } +}; + 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/Button.cpp b/bindings/interface/Button.cpp index d29cdc4..2f143ae 100644 --- a/bindings/interface/Button.cpp +++ b/bindings/interface/Button.cpp @@ -9,10 +9,99 @@ namespace py = pybind11; +class PyBButton : public BButton{ + public: + using BButton::BButton; + 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); + } +}; + 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/CheckBox.cpp b/bindings/interface/CheckBox.cpp index 1f89c24..8f7f81b 100644 --- a/bindings/interface/CheckBox.cpp +++ b/bindings/interface/CheckBox.cpp @@ -10,9 +10,95 @@ 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") +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 fee6624..694f6f4 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) { @@ -21,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")) 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")) diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 150c068..3e7fd1a 100644 --- a/bindings/interface/GraphicsDefs.cpp +++ b/bindings/interface/GraphicsDefs.cpp @@ -8,7 +8,6 @@ namespace py = pybind11; - PYBIND11_MODULE(GraphicsDefs,m) { py::enum_(m, "color_space", "") @@ -78,9 +77,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,32 +150,16 @@ 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, "") +//.def_readwrite("data", &pattern::data, "") +.def_readonly("data", &pattern::data, "") ; py::class_(m, "rgb_color") @@ -196,9 +176,12 @@ 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_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") @@ -210,7 +193,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 +203,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 +226,14 @@ 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_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/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")) 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_; }; diff --git a/bindings/interface/ListView.cpp b/bindings/interface/ListView.cpp index e527926..6a22183 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; @@ -44,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) @@ -71,8 +183,7 @@ py::class_>( .def("MaxSize", &BListView::MaxSize, "") .def("PreferredSize", &BListView::PreferredSize, "") .def("MakeFocus", &BListView::MakeFocus, "", py::arg("state")=true) -.def("SetFont", &BListView::SetFont, "", py::arg("font"), py::arg("mask")=511) -//B_FONT_ALL) Hardcoded 511 if not on import it gives ImportError: arg(): could not convert default argument 'mask: set_font_mask' +.def("SetFont", &BListView::SetFont, "", py::arg("font"), py::arg("mask")=B_FONT_ALL) .def("ScrollTo", py::overload_cast(&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")) 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")) 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")) 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) 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, "") ; - } diff --git a/bindings/interface/PictureButton.cpp b/bindings/interface/PictureButton.cpp index a005d9c..3297b77 100644 --- a/bindings/interface/PictureButton.cpp +++ b/bindings/interface/PictureButton.cpp @@ -6,16 +6,109 @@ #include #include #include +#include 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) { -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/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) 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")) diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index c3e08f8..fb1fa87 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,18 +33,83 @@ 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, 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_tuple(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; + BBitmap* buffer = new BBitmap(*frame,B_RGBA32); + status_t result = self.GetBitmap(&buffer,drawCursor,frame); + + // Gestire gli errori + if (result != B_OK) { + throw std::runtime_error("Errore durante la chiamata a GetBitmap"); + } + 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")) +.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::GetModeList, "", py::arg("_modeList"), py::arg("_count")) +.def("GetModeList", [](BScreen& self, uint32 _count) -> std::tuple, 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_tuple(resultVector,result); + } +) +/* +.def("GetModeList", [](BScreen& self, uint32 _count) -> std::vector { + // 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 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("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/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")) 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")) 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")) 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)) diff --git a/bindings/interface/Shape.cpp b/bindings/interface/Shape.cpp index 7972ade..c3cbbf0 100644 --- a/bindings/interface/Shape.cpp +++ b/bindings/interface/Shape.cpp @@ -5,17 +5,34 @@ #include #include +#include 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) { -m.attr("ServerLink") = ServerLink; - -m.attr("PicturePlayer") = PicturePlayer; - -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")) @@ -48,11 +65,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; } 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")); } diff --git a/bindings/interface/Slider.cpp b/bindings/interface/Slider.cpp index 4c30a1d..0afbe18 100644 --- a/bindings/interface/Slider.cpp +++ b/bindings/interface/Slider.cpp @@ -4,10 +4,187 @@ #include #include +#include #include +#include 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 position) override { + PYBIND11_OVERLOAD(void, BSlider, SetPosition, position); + } + 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 orient) override { + PYBIND11_OVERLOAD(void, BSlider, SetOrientation, orient); + } + 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) { @@ -25,7 +202,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) 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")) diff --git a/bindings/interface/StringItem.cpp b/bindings/interface/StringItem.cpp index d80f7bd..b9ccf7a 100644 --- a/bindings/interface/StringItem.cpp +++ b/bindings/interface/StringItem.cpp @@ -13,15 +13,29 @@ 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") +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/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")) 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")) 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")) diff --git a/bindings/interface/TextView.cpp b/bindings/interface/TextView.cpp index 6c4afcf..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) @@ -85,10 +177,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")=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")=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) +.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")) diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index a7c31f7..dcc0c38 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -22,10 +23,153 @@ #include #include #include +#include namespace py = pybind11; using namespace BPrivate; +class PyBView : public BView{ + public: + using BView::BView; + + 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); + } +}; + + PYBIND11_MODULE(View,m) { m.attr("B_PRIMARY_MOUSE_BUTTON") = "B_MOUSE_BUTTON ( 1 )"; @@ -45,9 +189,26 @@ 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, "") +.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; @@ -58,6 +219,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, "") @@ -109,7 +271,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")) @@ -142,7 +304,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) @@ -171,8 +333,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", &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", &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("ClipToRect", &BView::ClipToRect, "", py::arg("rect")) .def("ClipToInverseRect", &BView::ClipToInverseRect, "", py::arg("rect")) .def("ClipToShape", &BView::ClipToShape, "", py::arg("shape")) @@ -194,8 +356,8 @@ 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, "") .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) @@ -231,21 +393,20 @@ 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("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")=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("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) @@ -279,15 +440,13 @@ 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")) -/* -.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")) @@ -298,14 +457,12 @@ py::class_>(m, "BView") .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("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")=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")) diff --git a/bindings/interface/Window.cpp b/bindings/interface/Window.cpp index a8fb3cf..f6a9472 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, DispatchMessage, message, handler); + } + 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) { 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/Directory.cpp b/bindings/storage/Directory.cpp index 4e550ee..83ebc1c 100644 --- a/bindings/storage/Directory.cpp +++ b/bindings/storage/Directory.cpp @@ -3,14 +3,21 @@ #include #include + #include +#include +#include +#include +#include +#include +#include namespace py = pybind11; -void define_Directory(py::module_& m) +PYBIND11_MODULE(Directory,m) { -py::class_(m, "BDirectory") +py::class_(m, "BDirectory")// verify if needed .def(py::init(), "") .def(py::init(), "", py::arg("dir")) .def(py::init(), "", py::arg("ref")) @@ -23,11 +30,13 @@ py::class_(m, "BDirectory") .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")) -.def("GetEntry", &BDirectory::GetEntry, "", py::arg("entry")) +// 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::arg("path"), py::arg("nodeFlags")=B_ANY_NODE) -.def("Contains", py::overload_cast(&BDirectory::Contains), "", py::arg("entry"), py::arg("nodeFlags")=B_ANY_NODE) +.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")) 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, "") ; - } diff --git a/bindings/storage/Entry.cpp b/bindings/storage/Entry.cpp index a8fe1a8..8788129 100644 --- a/bindings/storage/Entry.cpp +++ b/bindings/storage/Entry.cpp @@ -5,10 +5,16 @@ #include +#include +#include + +#include +#include + namespace py = pybind11; -void define_Entry(py::module_& m) +PYBIND11_MODULE(Entry,m) { py::class_(m, "entry_ref") .def(py::init(), "") @@ -37,10 +43,10 @@ py::class_(m, "BEntry") .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", py::overload_cast(&BEntry::GetParent), "", py::arg("entry")) -.def("GetParent", py::overload_cast(&BEntry::GetParent), "", py::arg("dir")) +.def("GetRef", &BEntry::GetRef, "",py::arg("ref")) +.def("GetPath", &BEntry::GetPath, "",py::arg("path")) +.def("GetParent", py::overload_cast(&BEntry::GetParent, py::const_), "",py::arg("entry")) //added py::const_ +.def("GetParent", py::overload_cast(&BEntry::GetParent, py::const_), "",py::arg("dir")) //added py::const_ .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")=NULL, py::arg("clobber")=false) 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/File.cpp b/bindings/storage/File.cpp index 79c3f4a..3eb59a3 100644 --- a/bindings/storage/File.cpp +++ b/bindings/storage/File.cpp @@ -4,23 +4,56 @@ #include #include +#include +#include +#include +#include +#include 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); + } +}; -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")) diff --git a/bindings/storage/Mime.cpp b/bindings/storage/Mime.cpp index f4fdeda..af43e4a 100644 --- a/bindings/storage/Mime.cpp +++ b/bindings/storage/Mime.cpp @@ -2,37 +2,86 @@ #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); -void define_Mime(py::module_& m) + //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) { 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; //hardcoded, not reading enum +m.attr("B_UPDATE_MIME_INFO_FORCE_UPDATE_ALL") = 2; //hardcoded, not reading enum -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_toVoid", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("icon"), py::arg("size")); + +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("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); + }); -m.def("get_device_icon", py::overload_cast(&get_device_icon), "", py::arg("device"), py::arg("_data"), py::arg("_size"), py::arg("_type")); + 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_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("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); -m.def("get_named_icon", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("_data"), py::arg("_size"), py::arg("_type")); + 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")); } diff --git a/bindings/storage/MimeType.cpp b/bindings/storage/MimeType.cpp index 982752c..0cdeccf 100644 --- a/bindings/storage/MimeType.cpp +++ b/bindings/storage/MimeType.cpp @@ -2,42 +2,45 @@ #include #include #include +#include #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 +61,46 @@ 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_toBitmap", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) //changed names to GetIcon +.def("GetIcon", [](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", [](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")) @@ -76,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")) @@ -86,18 +118,41 @@ 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", [](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", [](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("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/Node.cpp b/bindings/storage/Node.cpp index f9fe736..38cc981 100644 --- a/bindings/storage/Node.cpp +++ b/bindings/storage/Node.cpp @@ -2,15 +2,21 @@ #include #include #include +#include +#include +#include +#include #include +#include +#include +#include + namespace py = pybind11; -using namespace BPrivate; -using namespace BPrivate::Storage; -using namespace BPrivate::Storage::Mime; -void define_Node(py::module_& m) + +PYBIND11_MODULE(Node,m) { py::class_(m, "node_ref") .def(py::init(), "") @@ -24,7 +30,7 @@ py::class_(m, "node_ref") .def_readwrite("node", &node_ref::node, "") ; -py::class_(m, "BNode") +py::class_(m, "BNode") //Commented out BStatable verify if needed .def(py::init(), "") .def(py::init(), "", py::arg("ref")) .def(py::init(), "", py::arg("entry")) @@ -42,11 +48,179 @@ py::class_(m, "BNode") .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)->py::object{ + 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 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::tuple{ + 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_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")) +//.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("GetNextAttrName", &BNode::GetNextAttrName, "", py::arg("buffer")) +//.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 { + 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("GetAttrInfo", [](BNode& self, const char* attr, struct attr_info* info){ + status_t result = self.GetAttrInfo(attr, info); + 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){ + 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("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")) @@ -56,5 +230,4 @@ py::class_(m, "BNode") .def("Dup", &BNode::Dup, "") ; - } diff --git a/bindings/storage/NodeInfo.cpp b/bindings/storage/NodeInfo.cpp index 34e66e3..c10bb9d 100644 --- a/bindings/storage/NodeInfo.cpp +++ b/bindings/storage/NodeInfo.cpp @@ -2,15 +2,17 @@ #include #include #include +#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,16 +21,36 @@ 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("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::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("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::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("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) ; 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/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, "") diff --git a/bindings/storage/PathFinder.cpp b/bindings/storage/PathFinder.cpp index 9a9c0ca..f3a506e 100644 --- a/bindings/storage/PathFinder.cpp +++ b/bindings/storage/PathFinder.cpp @@ -4,26 +4,52 @@ #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; +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); + } +}; -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) //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); @@ -48,30 +74,34 @@ 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_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_static("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath,unsigned int 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_static("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_static("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")) ; diff --git a/bindings/storage/Query.cpp b/bindings/storage/Query.cpp index d9152c0..ec238c8 100644 --- a/bindings/storage/Query.cpp +++ b/bindings/storage/Query.cpp @@ -4,14 +4,38 @@ #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) +//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) { py::enum_(m, "query_op", "") .value("B_INVALID_OP", query_op::B_INVALID_OP, "") @@ -30,11 +54,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(), "") diff --git a/bindings/storage/ResourceStrings.cpp b/bindings/storage/ResourceStrings.cpp index 2578fd0..ac71ef4 100644 --- a/bindings/storage/ResourceStrings.cpp +++ b/bindings/storage/ResourceStrings.cpp @@ -4,16 +4,31 @@ #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") +py::class_(m, "BResourceStrings") .def(py::init(), "") .def(py::init(), "", py::arg("ref")) .def("InitCheck", &BResourceStrings::InitCheck, "") @@ -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..c3dc4c8 100644 --- a/bindings/storage/Resources.cpp +++ b/bindings/storage/Resources.cpp @@ -2,20 +2,32 @@ #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; +/* +std::vector convertConstCharPtrArray(const char** constCharPtrArray, std::size_t size) { + std::vector charPtrVector; -void define_Resources(py::module_& m) + 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); +//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 +42,62 @@ 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("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) +.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", 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", [](BResources& self, int32 byIndex){ + type_code typeFound; + int32 idFound; + const char * nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); + + py::bytes byteSequence(nameFound, lengthFound); + + 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; + 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_byTypeAndID", [](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("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")) +.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")) ; diff --git a/bindings/storage/Statable.cpp b/bindings/storage/Statable.cpp index 3438e40..1b1002f 100644 --- a/bindings/storage/Statable.cpp +++ b/bindings/storage/Statable.cpp @@ -4,14 +4,17 @@ #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) +// ADD GetStat overload_pure ? +PYBIND11_MODULE(Statable, m) { py::class_(m, "BStatable") .def("GetStat", &BStatable::GetStat, "", py::arg("stat")) @@ -33,7 +36,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, "") ; diff --git a/bindings/storage/StorageDefs.cpp b/bindings/storage/StorageDefs.cpp index 9199e29..60785f3 100644 --- a/bindings/storage/StorageDefs.cpp +++ b/bindings/storage/StorageDefs.cpp @@ -4,14 +4,18 @@ #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_StorageDefs(py::module_& m) + +PYBIND11_MODULE(StorageDefs,m) { py::enum_(m, "node_flavor", "") .value("B_FILE_NODE", node_flavor::B_FILE_NODE, "") @@ -20,5 +24,4 @@ py::enum_(m, "node_flavor", "") .value("B_ANY_NODE", node_flavor::B_ANY_NODE, "") .export_values(); - } 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 9d1704c..fc84dd8 100644 --- a/bindings/storage/Volume.cpp +++ b/bindings/storage/Volume.cpp @@ -2,16 +2,30 @@ #include #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 BPackageKit; -void define_Volume(py::module_& m) +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") .def(py::init(), "") @@ -27,8 +41,20 @@ 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", &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); + 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, "") 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(), "") 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")); 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/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/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, ""); 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, "") ; - +*/ } diff --git a/bindings/support/DateTime.cpp b/bindings/support/DateTime.cpp index 65489d0..945d4dd 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,43 +24,19 @@ 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("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("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")) @@ -82,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("IsValid", py::overload_cast<>(&BDate::IsValid), "") +.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")) @@ -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_static("IsLeapYear", py::overload_cast(&BDate::IsLeapYear), "", py::arg("year")) +//.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_static("ShortDayName", py::overload_cast(&BDate::ShortDayName), "", py::arg("day")) -.def("ShortMonthName", py::overload_cast<>(&BDate::ShortMonthName), "") -.def_static("ShortMonthName", py::overload_cast(&BDate::ShortMonthName), "", py::arg("month")) -.def("LongDayName", py::overload_cast<>(&BDate::LongDayName), "") -.def_static("LongDayName", py::overload_cast(&BDate::LongDayName), "", py::arg("day")) -.def("LongMonthName", py::overload_cast<>(&BDate::LongMonthName), "") -.def_static("LongMonthName", py::overload_cast(&BDate::LongMonthName), "", py::arg("month")) -.def("DateToJulianDay", &BDate::DateToJulianDay, "") +//.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, py::const_), "") +.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("LongMonthName", py::overload_cast<>(&BDate::LongMonthName, py::const_), "") +.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")) .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); +*/ } 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/List.cpp b/bindings/support/List.cpp index 8fb70a1..82a55b8 100644 --- a/bindings/support/List.cpp +++ b/bindings/support/List.cpp @@ -7,21 +7,25 @@ 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) +.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, "") @@ -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")) +; } 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(), "") diff --git a/bindings/support/String.cpp b/bindings/support/String.cpp index da1e660..f4174cd 100644 --- a/bindings/support/String.cpp +++ b/bindings/support/String.cpp @@ -4,36 +4,40 @@ #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(), "") .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, "") .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"), py::arg("maxLength")) .def("SetTo", py::overload_cast(&BString::SetTo), "", py::arg("string")) .def("Adopt", [](BString& self) { BString from; @@ -41,40 +45,40 @@ 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); } , "", 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("CopyInto", [](BString& self,int fromOffset,int length) { +//.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,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::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); } , "", 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); @@ -86,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")) @@ -123,106 +127,106 @@ 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); } , "", 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) -.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")) -.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")); - +*/ } diff --git a/bindings/support/StringList.cpp b/bindings/support/StringList.cpp index 454dcf0..7b93d0e 100644 --- a/bindings/support/StringList.cpp +++ b/bindings/support/StringList.cpp @@ -2,25 +2,65 @@ #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) +.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) @@ -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")); } diff --git a/bindings/support/SupportDefs.cpp b/bindings/support/SupportDefs.cpp index 6abbfc4..d27868c 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("get_stack_frame", &get_stack_frame, "");//, py::arg("")); + +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; } diff --git a/bindings/support/TypeConstants.cpp b/bindings/support/TypeConstants.cpp index e3612fb..d4d41ed 100644 --- a/bindings/support/TypeConstants.cpp +++ b/bindings/support/TypeConstants.cpp @@ -2,13 +2,13 @@ #include #include #include +//<<<<<<< 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); @@ -88,3 +88,83 @@ m.attr("B_URL_FILE") = py::cast(B_URL_FILE); } +*/ + +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'; + 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); + +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); +} 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); } diff --git a/fstest.py b/fstest.py new file mode 100644 index 0000000..a0f4581 --- /dev/null +++ b/fstest.py @@ -0,0 +1,79 @@ +import os, sys, struct, ctypes +from Be import BNode#,BString +from Be.fs_attr import attr_info + +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: + #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 + else: + # you can do this way: + #tmp = attr_info() + #nfo = node.GetAttrInfo(a,tmp) + # or this way: + 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() + #print(type(my_obj),my_obj) + 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("Attempt to change AttribName") + node.RenameAttr("Media:Width", "media:width")# <- not working + 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 + 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 + +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) +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) diff --git a/tmtest.py b/tmtest.py index 05e2588..3fcb07c 100644 --- a/tmtest.py +++ b/tmtest.py @@ -1,6 +1,7 @@ -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 BListItem #BStringItem -from Be import BTabView, BTab, BFont +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, BScreen, BBitmap +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 @@ -8,23 +9,67 @@ 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 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 + self.frame=frame + 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) + +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 = BRect(4, 4, self.frame.Width()-4, self.frame.Height()-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) def __init__(self, testo,colore): self.testo = testo self.color = colore BStringItem.__init__(self,testo) - def DrawItem(self,owner,frame,complete): - if self.IsSelected() or complete: - color = (50,50,50,255) - owner.SetHighColor(color) - owner.SetLowColor(color) - 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)) + def Text(self): + return self.testo + def Color(self): + return self.color class NewsItem(BListItem): nocolor = (0, 0, 0, 0) @@ -37,10 +82,12 @@ 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.FillRect(frame) - self.color=self.nocolor + owner.SetHighColor(180,0,0,255) + owner.SetLowColor(200,200,200,255) + owner.FillRect(frame) + 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 @@ -48,10 +95,9 @@ def DrawItem(self, owner, frame, complete): #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)) + #frame.PrintToStream() + owner.MovePenTo(5,frame.Height()-2) + owner.DrawString("▶ "+self.name,None) def Text(self): return self.name @@ -81,25 +127,66 @@ 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.box = BBox(BRect(10,26,90,51),"MYBox",0x0202|0x0404,InterfaceDefs.border_style.B_FANCY_BORDER) - self.bar = BMenuBar(self.box.Bounds(), 'Bar') - self.testo = BStringView(BRect(5,5,75,20), 'Test','prova') + self.panel2 = BView(self.Bounds(), "panel2", 8, 20000000) + self.panel3 = BView(self.Bounds(), "panel2", 8, 20000000) + 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) + #paternale=Pattern() + #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(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),'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() 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.list = ScrollView(BRect(18 , 300, bounds.Width() - 18 , bounds.Height() - 40 ), 'ScrollView') - lollo=BPicture() - self.list.sv.Hide() + 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,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()) + 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) + 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################## + #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))) + #arrgh.append(BView.DrawString("On",None)) + #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 # as Python is finished with the __init__ function. But we still @@ -109,43 +196,30 @@ 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)) - print(type(self.list.lv)) - print(self.list.lv.Items()) - print(self.list.lv.CountItems()) + self.elementolista=BStringItem("Questo è un BStringItem") + #global strano + strano = StrangeItem("Questo è uno StrangeItem",(0,200,0,0)) + 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) 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.box,None) 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) self.panel.AddChild(self.statbar,None) self.panel.AddChild(self.bar,None) - 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) - tabrect=BRect(3.0, 3.0, 30.0, self.maintabview.TabHeight()-3.0) - bviewtab=BStringView(tabrect,"scheda1","Princpiale") - scheda=BTab(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.bckgnd.AddChild(self.maintabview,None) for menu, items in self.Menus: menu = BMenu(menu) for k, name in items: @@ -154,7 +228,58 @@ def __init__(self): else: menu.AddItem(BMenuItem(name, BMessage(k),name[1],0)) self.bar.AddItem(menu) + self.tabslabels=[] + 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) + #self.panel3.UpdateImg(img1) + #self.panel3.Draw(self.panel3.Bounds()) + + 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) + ###### 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: