diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0a6f1a6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "pybind11"] + path = pybind11 + url = https://github.com/pybind/pybind11 + branch = smart_holder diff --git a/Jamfile b/Jamfile index 4ea3533..e8feece 100644 --- a/Jamfile +++ b/Jamfile @@ -1,6 +1,6 @@ # Example usage: # jam -j$(nproc) - build using all cpu cores -# jam clean - remove all build files +# jam clean - remove all build files # jam -sparameter=value - to pass a parameter # # Parameters: @@ -68,24 +68,57 @@ rule Symlink # Set user configurable variables to default value if user did not specify value py ?= 3.10 ; python_version ?= $(py) ; +type ?= release ; +build_location ?= build/python$(python_version)_$(type) ; install_location ?= /boot/system/non-packaged/lib/python$(python_version)/site-packages ; # Where to search for .cpp files -SEARCH_SOURCE += bindings/interface bindings/app ; +SEARCH_SOURCE += + bindings/interface + bindings/app + bindings/support + bindings/storage + bindings/kernel + bindings/translation + bindings/add-ons/screen_saver + bindings/add-ons/registrar + bindings/add-ons/graphics + bindings/add-ons/input_server + bindings/add-ons/mail_daemon + bindings/add-ons/network_settings + bindings/drivers + bindings/device + bindings/mail + bindings/locale + bindings/media ; # Where to look for header files -SubDirHdrs /system/lib/python$(python_version)/vendor-packages/pybind11/include/ ; +SubDirHdrs headers ; +SubDirHdrs headers/app ; +SubDirHdrs headers/interface ; +SubDirHdrs pybind11/include/ ; SubDirHdrs /system/develop/headers/python$(python_version)/ ; # Additional C++ flags to use when compiling -SubDirC++Flags -std=c++14 -pipe -fPIC ; +SubDirC++Flags -std=c++14 -pipe -fPIC -fvisibility=hidden ; +if $(type) = release { + # Optimize for build size when making a release build + SubDirC++Flags -Os ; +} else if $(type) = debug { + # Include debug symbols when making a debug build + # It seems Haiku's debugger still doesn't fully support dwarf-5 (the + # default), so we'll tell it to use dwarf-4. + SubDirC++Flags -gdwarf-4 ; +} else { + Exit "Bad type given. Valid options are \"release\" and \"debug\"" ; +} # Flags to use when linking LINKLIBS = -lbe ; # Where to put the generated build files -LOCATE_TARGET = bin/x86_64/python$(python_version) ; # TODO: hardcoded arch +LOCATE_TARGET = $(build_location) ; # The source files that we want to compile: local sourceFiles = @@ -113,7 +146,10 @@ local sourceFiles = Alert.cpp Button.cpp Control.cpp + #OptionControl.cpp Rect.cpp + Polygon.cpp + Region.cpp StringView.cpp TextControl.cpp View.cpp @@ -126,15 +162,283 @@ local sourceFiles = LayoutItem.cpp Layout.cpp AbstractLayout.cpp + AbstractLayoutItem.cpp TwoDimensionalLayout.cpp GridLayout.cpp - PopUpMenu.cpp ; + GridLayoutBuilder.cpp + GroupLayout.cpp + GroupLayoutBuilder.cpp + LayoutContext.cpp + LayoutUtils.cpp + PopUpMenu.cpp + Box.cpp + SeparatorItem.cpp + Alignment.cpp + SeparatorView.cpp + MenuBar.cpp + StatusBar.cpp + CheckBox.cpp + Point.cpp + ColorControl.cpp + RadioButton.cpp + ListView.cpp + OutlineListView.cpp + ScrollView.cpp + ListItem.cpp + Bitmap.cpp + Picture.cpp + PictureButton.cpp + StringItem.cpp + TabView.cpp + ScrollBar.cpp + GraphicsDefs.cpp + Screen.cpp + Shape.cpp + Size.cpp + Slider.cpp + AffineTransform.cpp + CardLayout.cpp + CardView.cpp + ChannelControl.cpp + ChannelSlider.cpp + ControlLook.cpp + Deskbar.cpp + Gradient.cpp + GradientConic.cpp + GradientDiamond.cpp + GradientLinear.cpp + GradientRadial.cpp + GradientRadialFocus.cpp + GridView.cpp + Dragger.cpp + IconUtils.cpp + Input.cpp + PrintJob.cpp + + #SupportKit + ByteOrder.cpp + StopWatch.cpp + Beep.cpp + Locker.cpp + Autolock.cpp + #BlockCache.cpp + SupportDefs.cpp + Archivable.cpp + TypeConstants.cpp + Architecture.cpp + DateTime.cpp + parsedate.cpp + List.cpp + String.cpp + Flattenable.cpp + StringList.cpp + DataIO.cpp + BufferIO.cpp + BufferedDataIO.cpp + Url.cpp + UTF8.cpp + TLS.cpp + Job.cpp + + #Kernel + fs_attr.cpp + OS.cpp + + #StorageKit + StorageDefs.cpp + Entry.cpp + Node.cpp + + Directory.cpp + File.cpp + Volume.cpp + VolumeRoster.cpp + Path.cpp + FindDirectory.cpp + PathFinder.cpp + SymLink.cpp + Statable.cpp + Mime.cpp + MimeType.cpp + Resources.cpp + ResourceStrings.cpp + EntryList.cpp + Query.cpp + NodeMonitor.cpp + NodeInfo.cpp + AppFileInfo.cpp + DiskDeviceDefs.cpp + FilePanel.cpp + + # TranslationKit + # NOTE: When adding a new file to this list, you will likely also want to + # tell the compiler to link it with libtranslation.so below. + TranslationDefs.cpp + TranslatorRoster.cpp + TranslationUtils.cpp + Translator.cpp + BitmapStream.cpp + TranslatorFormats.cpp + + stat.cpp + + #add-ons + #ScreenSaver.cpp + #MimeSnifferAddon.cpp + Accelerant.cpp + #GraphicsCard.cpp + #InputServerDevice.cpp + #InputServerFilter.cpp + #InputServerMethod.cpp + #MailProtocol.cpp + #MailFilter.cpp + MailSettingsView.cpp + #NetworkProfile.cpp + NetworkSettings.cpp + #NetworkSettingsAddOn.cpp + + #drivers + #bios.cpp + #module.cpp + #bus_manager.cpp + + #device + #SerialPort.cpp + #Joystick.cpp + #USBKit.cpp + #A2D.cpp + #D2A.cpp + #DigitalPort.cpp + + #mail + Email.cpp + mail_encoding.cpp + MailDaemon.cpp + MailComponent.cpp + MailContainer.cpp + MailMessage.cpp + MailAttachment.cpp + MailSettings.cpp + + #locale + Country.cpp + Language.cpp + Format.cpp + FormattingConventions.cpp + DateFormat.cpp + DateTimeFormat.cpp + TimeUnitFormat.cpp + DurationFormat.cpp + TimeFormat.cpp + UnicodeChar.cpp + StringFormat.cpp + TextEncoding.cpp + RelativeDateTimeFormat.cpp + NumberFormat.cpp + LocaleStrings.cpp + LocaleRoster.cpp + Locale.cpp + Collator.cpp + CatalogData.cpp + Catalog.cpp + TimeZone.cpp + + #media + Buffer.cpp + MediaNode.cpp + BufferConsumer.cpp + TimeSource.cpp + BufferGroup.cpp + BufferProducer.cpp + Controllable.cpp + MediaAddOn.cpp + MediaDecoder.cpp + MediaDefs.cpp + MediaEncoder.cpp + ParameterWeb.cpp + MediaTrack.cpp + MediaFile.cpp + MediaFiles.cpp + MediaFormats.cpp + MediaRecorder.cpp + MediaRoster.cpp + MediaTheme.cpp + PlaySound.cpp + Sound.cpp + SoundFile.cpp + SoundPlayer.cpp + TimeCode.cpp + TimedEventQueue.cpp + + ; + +# The .so files can be built from the .cpp files, each .cpp file mapping to +# its own .so file +for sourceFile in $(sourceFiles) { + SharedLibrary $(sourceFile:S=.so) : $(sourceFile) ; +} + +LINKLIBS on UTF8.so = $(LINKLIBS) -ltextencoding ; +# FilePanel.so needs to be linked with libtracker.so +LINKLIBS on FilePanel.so = $(LINKLIBS) -ltracker ; + +# Some/all files in the translation kit need libtranslation.so +LINKLIBS on TranslationDefs.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on TranslatorRoster.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on TranslationUtils.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on Translator.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on TranslatorFormats.so = $(LINKLIBS) -ltranslation ; +LINKLIBS on BitmapStream.so = $(LINKLIBS) -ltranslation ; + +LINKLIBS on LocaleRoster.so = $(LINKLIBS) -llocalestub ; +#LINKLIBS on CatalogData.so = $(LINKLIBS) -llocalestub ; + +#LINKLIBS on TimeFormat.so = $(LINKLIBS) -lsupport ; + +LINKLIBS on Buffer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on BufferGroup.so = $(LINKLIBS) -lmedia ; +LINKLIBS on BufferProducer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on Controllable.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaAddOn.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaDecoder.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaDefs.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaEncoder.so = $(LINKLIBS) -lmedia ; +LINKLIBS on ParameterWeb.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaTrack.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaFile.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaFiles.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaFormats.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaNode.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaRecorder.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaRoster.so = $(LINKLIBS) -lmedia ; +LINKLIBS on MediaTheme.so = $(LINKLIBS) -lmedia ; +LINKLIBS on PlaySound.so = $(LINKLIBS) -lmedia ; +LINKLIBS on Sound.so = $(LINKLIBS) -lmedia ; +LINKLIBS on SoundFile.so = $(LINKLIBS) -lmedia ; +LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ; +LINKLIBS on TimeCode.so = $(LINKLIBS) -lmedia ; +LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ; +LINKLIBS on TimedEventQueue.so = $(LINKLIBS) -lmedia ; +LINKLIBS on BufferConsumer.so = $(LINKLIBS) -lmedia ; -# The shared library Be.so can be built from the sourceFiles -SharedLibrary Be.so : $(sourceFiles) ; +LINKLIBS on ScreenSaver.so = $(LINKLIBS) -lscreensaver ; +#LINKLIBS on MimeSnifferAddon.so = $(LINKLIBS) -lstoragekit ; +#LINKLIBS on InputServerDevice.so = $(LINKLIBS) -linputkit ; +#LINKLIBS on InputServerFilter.so = $(LINKLIBS) -linputkit ; +#LINKLIBS on InputServerMethod.so = $(LINKLIBS) -linputkit ; +LINKLIBS on MailFilter.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailSettingsView.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailProtocol.so = $(LINKLIBS) -lmail ; +LINKLIBS on Email.so = $(LINKLIBS) -lmail ; +LINKLIBS on mail_encoding.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailDaemon.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailComponent.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailAttachment.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailContainer.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailMessage.so = $(LINKLIBS) -lmail ; +LINKLIBS on MailSettings.so = $(LINKLIBS) -lmail ; +LINKLIBS on NetworkSettings.so = $(LINKLIBS) -lbnetapi ; -# The symlinked libraries can be built by linking to Be.so -Symlink $(sourceFiles:S=.so) : Be.so ; # __init__.py can be built by simply copying the file MakeLocate __init__.py : $(LOCATE_TARGET) ; # Put it in the build directory @@ -142,4 +446,4 @@ File __init__.py : bindings/__init__.py ; # As part of `jam install`, copy the following files: InstallLib $(install_location)/Be - : Be.so $(sourceFiles:S=.so) __init__.py ; + : $(sourceFiles:S=.so) __init__.py ; diff --git a/README.md b/README.md index 581932b..5f821c0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,76 @@ # Haiku-PyAPI - Python bindings for the Haiku API + +Python bindings for the Haiku API. + +This lets you build apps for Haiku using the Haiku API directly from Python. + +For the most part, Haiku-PyAPI tries to copy the C++ API. There are some places +where we have had to deviate from the C++ API, however. + +## Current status + +Virtually everything from Haiku's API is available. It is likely that you will +run into some bugs if you try to make an application. Please report them! Also, +there's a good chance we can give you a workaround to use until it is fixed. + +Probably, the biggest bug is memory leaks. Unless memory management for a class +was simple for us to do, it is likely that we opted to never free the memory +so that we could worry about memory management later! + +## Installing + +### From HaikuPorts + +Installation on Haiku is easy, just run + +``` +pkgman install haiku_pyapi_python310 +``` + +If you need the latest widgets and bugfixes, then you should compile from source, see below. + +### From source + +First, clone the source code, with submodules: +``` +git clone https://github.com/coolcder613eb/Haiku-PyAPI --recursive +``` + +The basic build command to build using all CPU cores is +``` +jam -j$(nproc) +``` +Extra build parameters can be specified, as discussed below. + +Finally, to install, simply run +``` +jam install +``` +Haiku-PyAPI should now be installed and ready to use. + + +## Build parameters + +The build parameters can be used to change how the build is done. This can be +used to, for example, specify a different verson of python to build for. To +specify a build parameter, add `-sPARAMETER=VALUE` to the build command line. + +| Parameter | Description | +| ---------------- | --------------------------------------------- | +| python_version | Version of python to build for. Default: 3.10 | +| py | Alias of `python_version` | +| type | Debug or release build. Default: release | +| build_location | Location to put build files. Default: build/python$(python_version)_$(type) | +| install_location | Where to install build files to. Default: /boot/system/non-packaged/lib/python$(python_version)/site-packages | + +## Example projects + +This repository contains `example.py`, which is a simple "Hello world" program. +Other examples: +- https://github.com/coolcoder613eb/Bemini +- https://github.com/coolcoder613eb/BeMatched +- https://github.com/tmtfx/HaiQR +- https://github.com/tmtfx/FeedGator +- https://github.com/tmtfx/HTPBZ2 +- https://github.com/tmtfx/HaikuPO +- https://github.com/robante15/Haiku-PyAPI_Examples diff --git a/bindings/__init__.py b/bindings/__init__.py index eb4c74a..e62d6ff 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -7,7 +7,7 @@ from .Key import * from .KeyStore import * from .Looper import * -from .Application import * # has to be after looper +from .Application import * # should to be loaded after looper from .Message import * from .MessageFilter import * from .MessageQueue import * @@ -18,13 +18,19 @@ from .Roster import * from .Window import * from .Rect import * +from .Polygon import * +from .Region import * +from .GraphicsDefs import * +from .Screen import * +from .Point import * +from .InterfaceDefs import * from .View import * from .Control import * +#from .OptionControl 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 * @@ -33,9 +39,196 @@ from .LayoutItem import * from .Layout import * from .AbstractLayout import * +from .AbstractLayoutItem import * from .TwoDimensionalLayout import * from .GridLayout import * +from .GridLayoutBuilder import * +from .GroupLayout import * +from .GroupLayoutBuilder import * +from .LayoutContext import * +from .LayoutUtils import * 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 .ColorControl import * +from .RadioButton import * +from .ListView import * +from .OutlineListView import * +from .ScrollView import * +from .SupportDefs import * +from .TypeConstants import * +from .Archivable import * +from .ListItem 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 .CardLayout import * +from .CardView import * +from .ChannelControl import * +from .ChannelSlider import * +from .ControlLook import * +from .Deskbar import * +from .Gradient import * +from .GradientConic import * +from .GradientDiamond import * +from .GradientLinear import * +from .GradientRadial import * +from .GradientRadialFocus import * +from .GridView import * +from .Dragger import * +from .IconUtils import * +from .Input import * +from .PrintJob import * + +from .ByteOrder import * +from .StopWatch import * +from .Beep import * +from .Architecture import * +from .Locker import * +#from .BlockCache import * +from .Autolock import * +from .DateTime import * +from .parsedate import * +from .List import * +from .String import * +from .Flattenable import * +from .AffineTransform import * +from .StringList import * +from .DataIO import * +from .BufferIO import * +from .BufferedDataIO import * +from .Url import * +from .UTF8 import * +from .TLS import * +from .Job import * + +from .fs_attr import * +from .OS 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 .FindDirectory import * +from .PathFinder import * + +from .Mime import * +from .MimeType import * +from .NodeInfo import * +from .AppFileInfo 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 * + +from .TranslationDefs import * +from .TranslatorRoster import * +from .TranslationUtils import * +from .Translator import * +from .BitmapStream import * +from .TranslatorFormats import * +from .stat import * + +#from .ScreenSaver import * +#from .MimeSnifferAddon import * +from .Accelerant import * +#from .GraphicsCard import * +#from .InputServerDevice import * +#from .InputServerFilter import * +#from .InputServerMethod import * +#from .MailFilter import * +from .MailSettingsView import * +#from .MailProtocol import * +#from .NetworkProfile import * +from .NetworkSettings import * +#from .NetworkSettingsAddOn import * + +#from .bus_manager import * + +#from .SerialPort import * +#from .Joystick import * +#from .USBKit import * +#from .A2D import * +#from .D2A import * +#from .DigitalPort import * +from .Email import * +from .mail_encoding import * +from .MailComponent import * +from .MailDaemon import * +from .MailContainer import * +from .MailMessage import * +from .MailAttachment import * +from .MailSettings import * + +from .Country import * +from .Language import * +from .Format import * +from .FormattingConventions import * +from .DateFormat import * +from .DateTimeFormat import * +from .TimeUnitFormat import * +from .DurationFormat import * +from .TimeFormat import * +from .UnicodeChar import * +from .StringFormat import * +from .TextEncoding import * +from .RelativeDateTimeFormat import * +from .NumberFormat import * +from .LocaleStrings import * +from .LocaleRoster import * +from .Locale import * +from .Collator import * +from .CatalogData import * +from .Catalog import * +from .TimeZone import * + +#media +from .Buffer import * +from .MediaNode import * +from .BufferConsumer import * +from .TimeSource import * +from .BufferGroup import * +from .BufferProducer import * +from .Controllable import * +from .MediaAddOn import * +from .MediaDecoder import * +from .MediaDefs import * +from .MediaEncoder import * +from .ParameterWeb import * +from .MediaTrack import * +from .MediaFile import * +from .MediaFiles import * +from .MediaFormats import * +from .MediaRecorder import * +from .MediaRoster import * +from .MediaTheme import * +from .PlaySound import * +from .Sound import * +from .SoundFile import * +from .SoundPlayer import * +from .TimeCode import * +from .TimedEventQueue import * _BWindow=BWindow _BApplication=BApplication diff --git a/bindings/add-ons/graphics/Accelerant.cpp b/bindings/add-ons/graphics/Accelerant.cpp new file mode 100644 index 0000000..2800905 --- /dev/null +++ b/bindings/add-ons/graphics/Accelerant.cpp @@ -0,0 +1,310 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class MyClass { +public: +enum production { + week, + year +}; +}; + +PYBIND11_MODULE(Accelerant, m) +{ +m.attr("B_INIT_ACCELERANT") = 0;//py::cast(B_INIT_ACCELERANT); +m.attr("B_ACCELERANT_CLONE_INFO_SIZE") = 1;//py::cast(B_ACCELERANT_CLONE_INFO_SIZE); +m.attr("B_GET_ACCELERANT_CLONE_INFO") = 2;//py::cast(B_GET_ACCELERANT_CLONE_INFO); +m.attr("B_CLONE_ACCELERANT") = 3;//py::cast(B_CLONE_ACCELERANT); +m.attr("B_UNINIT_ACCELERANT") = 4;//py::cast(B_UNINIT_ACCELERANT); +m.attr("B_GET_ACCELERANT_DEVICE_INFO") = 5;//py::cast(B_GET_ACCELERANT_DEVICE_INFO); +m.attr("B_ACCELERANT_RETRACE_SEMAPHORE") = 6;//py::cast(B_ACCELERANT_RETRACE_SEMAPHORE); +m.attr("B_ACCELERANT_MODE_COUNT") = 0x100;//py::cast(B_ACCELERANT_MODE_COUNT); +m.attr("B_GET_MODE_LIST") = 0x101;//py::cast(B_GET_MODE_LIST); +m.attr("B_PROPOSE_DISPLAY_MODE") = 0x102;//py::cast(B_PROPOSE_DISPLAY_MODE); +m.attr("B_SET_DISPLAY_MODE") = 0x103;//py::cast(B_SET_DISPLAY_MODE); +m.attr("B_GET_DISPLAY_MODE") = 0x104;//py::cast(B_GET_DISPLAY_MODE); +m.attr("B_GET_FRAME_BUFFER_CONFIG") = 0x105;//py::cast(B_GET_FRAME_BUFFER_CONFIG); +m.attr("B_GET_PIXEL_CLOCK_LIMITS") = 0x106;//py::cast(B_GET_PIXEL_CLOCK_LIMITS); +m.attr("B_GET_TIMING_CONSTRAINTS") = 0x107;//py::cast(B_GET_TIMING_CONSTRAINTS); +m.attr("B_MOVE_DISPLAY") = 0x108;//py::cast(B_MOVE_DISPLAY); +m.attr("B_SET_INDEXED_COLORS") = 0x109;//py::cast(B_SET_INDEXED_COLORS); +m.attr("B_DPMS_CAPABILITIES") = 0x10A;//py::cast(B_DPMS_CAPABILITIES); +m.attr("B_DPMS_MODE") = 0x10B;//py::cast(B_DPMS_MODE); +m.attr("B_SET_DPMS_MODE") = 0x10C;//py::cast(B_SET_DPMS_MODE); +m.attr("B_GET_PREFERRED_DISPLAY_MODE") = 0x10D;//py::cast(B_GET_PREFERRED_DISPLAY_MODE); +m.attr("B_GET_MONITOR_INFO") = 0x10E;//py::cast(B_GET_MONITOR_INFO); +m.attr("B_GET_EDID_INFO") = 0x10F;//py::cast(B_GET_EDID_INFO); +m.attr("B_SET_BRIGHTNESS") = 0x110;//py::cast(B_SET_BRIGHTNESS); +m.attr("B_GET_BRIGHTNESS") = 0x111;//py::cast(B_GET_BRIGHTNESS); +m.attr("B_MOVE_CURSOR") = 0x200;//py::cast(B_MOVE_CURSOR); +m.attr("B_SET_CURSOR_SHAPE") = 0x201;//py::cast(B_SET_CURSOR_SHAPE); +m.attr("B_SHOW_CURSOR") = 0x202;//py::cast(B_SHOW_CURSOR); +m.attr("B_SET_CURSOR_BITMAP") = 0x203;//py::cast(B_SET_CURSOR_BITMAP); +m.attr("B_ACCELERANT_ENGINE_COUNT") = 0x300;//py::cast(B_ACCELERANT_ENGINE_COUNT); +m.attr("B_ACQUIRE_ENGINE") = 0x301;//py::cast(B_ACQUIRE_ENGINE); +m.attr("B_RELEASE_ENGINE") = 0x302;//py::cast(B_RELEASE_ENGINE); +m.attr("B_WAIT_ENGINE_IDLE") = 0x303;//py::cast(B_WAIT_ENGINE_IDLE); +m.attr("B_GET_SYNC_TOKEN") = 0x304;//py::cast(B_GET_SYNC_TOKEN); +m.attr("B_SYNC_TO_TOKEN") = 0x305;//py::cast(B_SYNC_TO_TOKEN); +m.attr("B_SCREEN_TO_SCREEN_BLIT") = 0x400;//py::cast(B_SCREEN_TO_SCREEN_BLIT); +m.attr("B_FILL_RECTANGLE") = 0x401;//py::cast(B_FILL_RECTANGLE); +m.attr("B_INVERT_RECTANGLE") = 0x402;//py::cast(B_INVERT_RECTANGLE); +m.attr("B_FILL_SPAN") = 0x403;//py::cast(B_FILL_SPAN); +m.attr("B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT") = 0x404;//py::cast(B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT); +m.attr("B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT") = 0x405;//py::cast(B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT); +m.attr("B_ACCELERANT_PRIVATE_START") = (int)0x80000000;//py::cast(B_ACCELERANT_PRIVATE_START); + +m.attr("B_SCROLL") = 1 << 0;//py::cast(B_SCROLL); +m.attr("B_8_BIT_DAC") = 1 << 1;//py::cast(B_8_BIT_DAC); +m.attr("B_HARDWARE_CURSOR") = 1 << 2;//py::cast(B_HARDWARE_CURSOR); +m.attr("B_PARALLEL_ACCESS") = 1 << 3;//py::cast(B_PARALLEL_ACCESS); +m.attr("B_DPMS") = 1 << 4;//py::cast(B_DPMS); +m.attr("B_IO_FB_NA") = 1 << 5;//py::cast(B_IO_FB_NA); + +m.attr("B_DPMS_ON") = 1 << 0;//py::cast(B_DPMS_ON); +m.attr("B_DPMS_STAND_BY") = 1 << 1;//py::cast(B_DPMS_STAND_BY); +m.attr("B_DPMS_SUSPEND") = 1 << 2;//py::cast(B_DPMS_SUSPEND); +m.attr("B_DPMS_OFF") = 1 << 3;//py::cast(B_DPMS_OFF); + +m.attr("B_BLANK_PEDESTAL") = 1 << 27;//py::cast(B_BLANK_PEDESTAL); +m.attr("B_TIMING_INTERLACED") = 1 << 28;//py::cast(B_TIMING_INTERLACED); +m.attr("B_POSITIVE_HSYNC") = 1 << 29;//py::cast(B_POSITIVE_HSYNC); +m.attr("B_POSITIVE_VSYNC") = 1 << 30;//py::cast(B_POSITIVE_VSYNC); +m.attr("B_SYNC_ON_GREEN") = 1 << 31;//py::cast(B_SYNC_ON_GREEN); + +m.attr("B_2D_ACCELERATION") = 1 << 0;//py::cast(B_2D_ACCELERATION); +m.attr("B_3D_ACCELERATION") = 1 << 1;//py::cast(B_3D_ACCELERATION); + +py::class_(m, "accelerant_device_info") +.def(py::init(), "") +.def_readwrite("version", &accelerant_device_info::version, "") +//.def_readwrite("name", &accelerant_device_info::name, "") +//.def_readwrite("chipset", &accelerant_device_info::chipset, "") +//.def_readwrite("serial_no", &accelerant_device_info::serial_no, "") +.def_property( + "name", + [](const accelerant_device_info &acc_info) { + return py::cast(acc_info.name); + }, + [](accelerant_device_info &acc_info, const std::string &value) { + if (value.size()(m, "display_timing") +.def(py::init(), "") +.def_readwrite("pixel_clock", &display_timing::pixel_clock, "") +.def_readwrite("h_display", &display_timing::h_display, "") +.def_readwrite("h_sync_start", &display_timing::h_sync_start, "") +.def_readwrite("h_sync_end", &display_timing::h_sync_end, "") +.def_readwrite("h_total", &display_timing::h_total, "") +.def_readwrite("v_display", &display_timing::v_display, "") +.def_readwrite("v_sync_start", &display_timing::v_sync_start, "") +.def_readwrite("v_sync_end", &display_timing::v_sync_end, "") +.def_readwrite("v_total", &display_timing::v_total, "") +.def_readwrite("flags", &display_timing::flags, "") +; + +py::class_(m, "display_mode") +.def(py::init(), "") +.def_readwrite("timing", &display_mode::timing, "") +.def_readwrite("space", &display_mode::space, "") +.def_readwrite("virtual_width", &display_mode::virtual_width, "") +.def_readwrite("virtual_height", &display_mode::virtual_height, "") +.def_readwrite("h_display_start", &display_mode::h_display_start, "") +.def_readwrite("v_display_start", &display_mode::v_display_start, "") +.def_readwrite("flags", &display_mode::flags, "") +; + +py::class_(m, "frame_buffer_config") +.def(py::init(), "") +.def_readwrite("frame_buffer", &frame_buffer_config::frame_buffer, "") +.def_readwrite("frame_buffer_dma", &frame_buffer_config::frame_buffer_dma, "") +.def_readwrite("bytes_per_row", &frame_buffer_config::bytes_per_row, "") +; + +py::class_(m, "display_timing_constraints") +.def(py::init(), "") +.def_readwrite("h_res", &display_timing_constraints::h_res, "") +.def_readwrite("h_sync_min", &display_timing_constraints::h_sync_min, "") +.def_readwrite("h_sync_max", &display_timing_constraints::h_sync_max, "") +.def_readwrite("h_blank_min", &display_timing_constraints::h_blank_min, "") +.def_readwrite("h_blank_max", &display_timing_constraints::h_blank_max, "") +.def_readwrite("v_res", &display_timing_constraints::v_res, "") +.def_readwrite("v_sync_min", &display_timing_constraints::v_sync_min, "") +.def_readwrite("v_sync_max", &display_timing_constraints::v_sync_max, "") +.def_readwrite("v_blank_min", &display_timing_constraints::v_blank_min, "") +.def_readwrite("v_blank_max", &display_timing_constraints::v_blank_max, "") +; + +py::enum_(m, "production") +.value("week",MyClass::production::week) +.value("year",MyClass::production::year) +.export_values(); +//py::class_(m, "") +//.def_readwrite("week", &::week, "") +//.def_readwrite("year", &::year, "") +//; + +py::class_(m, "monitor_info") +.def(py::init(), "") +.def_readwrite("version", &monitor_info::version, "") +//.def_readwrite("vendor", &monitor_info::vendor, "") +.def_property( + "vendor", + [](const monitor_info &info) { + return py::cast(info.vendor); + }, + [](monitor_info &info, const std::string &value) { + if (value.size()(m, "blit_params") +.def(py::init(), "") +.def_readwrite("src_left", &blit_params::src_left, "") +.def_readwrite("src_top", &blit_params::src_top, "") +.def_readwrite("dest_left", &blit_params::dest_left, "") +.def_readwrite("dest_top", &blit_params::dest_top, "") +.def_readwrite("width", &blit_params::width, "") +.def_readwrite("height", &blit_params::height, "") +; + +py::class_(m, "scaled_blit_params") +.def(py::init(), "") +.def_readwrite("src_left", &scaled_blit_params::src_left, "") +.def_readwrite("src_top", &scaled_blit_params::src_top, "") +.def_readwrite("src_width", &scaled_blit_params::src_width, "") +.def_readwrite("src_height", &scaled_blit_params::src_height, "") +.def_readwrite("dest_left", &scaled_blit_params::dest_left, "") +.def_readwrite("dest_top", &scaled_blit_params::dest_top, "") +.def_readwrite("dest_width", &scaled_blit_params::dest_width, "") +.def_readwrite("dest_height", &scaled_blit_params::dest_height, "") +; + +py::class_(m, "fill_rect_params") +.def(py::init(), "") +.def_readwrite("left", &fill_rect_params::left, "") +.def_readwrite("top", &fill_rect_params::top, "") +.def_readwrite("right", &fill_rect_params::right, "") +.def_readwrite("bottom", &fill_rect_params::bottom, "") +; + +py::class_(m, "engine_token") +.def(py::init(), "") +.def_readwrite("engine_id", &engine_token::engine_id, "") +.def_readwrite("capability_mask", &engine_token::capability_mask, "") +.def_readwrite("opaque", &engine_token::opaque, "") +; + +py::class_(m, "sync_token") +.def(py::init(), "") +.def_readwrite("counter", &sync_token::counter, "") +.def_readwrite("engine_id", &sync_token::engine_id, "") +//.def_readwrite("opaque", &sync_token::opaque, "") +.def_property( + "opaque", + [](const sync_token &token) { + return py::cast(token.opaque); + }, + [](sync_token &token, const std::string &value) { + if (value.size() +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(GraphicsCard, m) +{ +m.attr("B_OPEN_GRAPHICS_CARD") = py::cast(B_OPEN_GRAPHICS_CARD); +m.attr("B_CLOSE_GRAPHICS_CARD") = py::cast(B_CLOSE_GRAPHICS_CARD); +m.attr("B_GET_GRAPHICS_CARD_INFO") = py::cast(B_GET_GRAPHICS_CARD_INFO); +m.attr("B_GET_GRAPHICS_CARD_HOOKS") = py::cast(B_GET_GRAPHICS_CARD_HOOKS); +m.attr("B_SET_INDEXED_COLOR") = py::cast(B_SET_INDEXED_COLOR); +m.attr("B_GET_SCREEN_SPACES") = py::cast(B_GET_SCREEN_SPACES); +m.attr("B_CONFIG_GRAPHICS_CARD") = py::cast(B_CONFIG_GRAPHICS_CARD); +m.attr("B_GET_REFRESH_RATES") = py::cast(B_GET_REFRESH_RATES); +m.attr("B_SET_SCREEN_GAMMA") = py::cast(B_SET_SCREEN_GAMMA); +m.attr("B_GET_INFO_FOR_CLONE_SIZE") = py::cast(B_GET_INFO_FOR_CLONE_SIZE); +m.attr("B_GET_INFO_FOR_CLONE") = py::cast(B_GET_INFO_FOR_CLONE); +m.attr("B_SET_CLONED_GRAPHICS_CARD") = py::cast(B_SET_CLONED_GRAPHICS_CARD); +m.attr("B_CLOSE_CLONED_GRAPHICS_CARD") = py::cast(B_CLOSE_CLONED_GRAPHICS_CARD); +m.attr("B_PROPOSE_FRAME_BUFFER") = py::cast(B_PROPOSE_FRAME_BUFFER); +m.attr("B_SET_FRAME_BUFFER") = py::cast(B_SET_FRAME_BUFFER); +m.attr("B_SET_DISPLAY_AREA") = py::cast(B_SET_DISPLAY_AREA); +m.attr("B_MOVE_DISPLAY_AREA") = py::cast(B_MOVE_DISPLAY_AREA); + +m.attr("B_CRT_CONTROL") = py::cast(B_CRT_CONTROL); +m.attr("B_GAMMA_CONTROL") = py::cast(B_GAMMA_CONTROL); +m.attr("B_FRAME_BUFFER_CONTROL") = py::cast(B_FRAME_BUFFER_CONTROL); +m.attr("B_PARALLEL_BUFFER_ACCESS") = py::cast(B_PARALLEL_BUFFER_ACCESS); +m.attr("B_LAME_ASS_CARD") = py::cast(B_LAME_ASS_CARD); + +py::class_(m, "graphics_card_info") +.def_readwrite("version", &graphics_card_info::version, "") +.def_readwrite("id", &graphics_card_info::id, "") +.def_readwrite("frame_buffer", &graphics_card_info::frame_buffer, "") +//.def_readwrite("rgba_order", &graphics_card_info::rgba_order, "") +.def_property( + "rgba_order", + [](const graphics_card_info &info) { + return py::cast(info.rgba_order); + }, + [](graphics_card_info &info, const std::string &value) { + if (value.size()(m, "indexed_color") +.def_readwrite("index", &indexed_color::index, "") +.def_readwrite("color", &indexed_color::color, "") +; + +py::class_(m, "graphics_card_config") +.def_readwrite("space", &graphics_card_config::space, "") +.def_readwrite("refresh_rate", &graphics_card_config::refresh_rate, "") +.def_readwrite("h_position", &graphics_card_config::h_position, "") +.def_readwrite("v_position", &graphics_card_config::v_position, "") +.def_readwrite("h_size", &graphics_card_config::h_size, "") +.def_readwrite("v_size", &graphics_card_config::v_size, "") +; + +py::class_(m, "refresh_rate_info") +.def_readwrite("min", &refresh_rate_info::min, "") +.def_readwrite("max", &refresh_rate_info::max, "") +.def_readwrite("current", &refresh_rate_info::current, "") +; + +py::class_(m, "graphics_card_spec") +.def_readwrite("screen_base", &graphics_card_spec::screen_base, "") +.def_readwrite("io_base", &graphics_card_spec::io_base, "") +.def_readwrite("vendor_id", &graphics_card_spec::vendor_id, "") +.def_readwrite("device_id", &graphics_card_spec::device_id, "") +.def_readwrite("_reserved1_", &graphics_card_spec::_reserved1_, "") +.def_readwrite("_reserved2_", &graphics_card_spec::_reserved2_, "") +; + +py::class_(m, "rgb_color_line") +.def_readwrite("x1", &rgb_color_line::x1, "") +.def_readwrite("y1", &rgb_color_line::y1, "") +.def_readwrite("x2", &rgb_color_line::x2, "") +.def_readwrite("y2", &rgb_color_line::y2, "") +.def_readwrite("color", &rgb_color_line::color, "") +; + +py::class_(m, "indexed_color_line") +.def_readwrite("x1", &indexed_color_line::x1, "") +.def_readwrite("y1", &indexed_color_line::y1, "") +.def_readwrite("x2", &indexed_color_line::x2, "") +.def_readwrite("y2", &indexed_color_line::y2, "") +.def_readwrite("color", &indexed_color_line::color, "") +; + +py::class_(m, "frame_buffer_info") +.def_readwrite("bits_per_pixel", &frame_buffer_info::bits_per_pixel, "") +.def_readwrite("bytes_per_row", &frame_buffer_info::bytes_per_row, "") +.def_readwrite("width", &frame_buffer_info::width, "") +.def_readwrite("height", &frame_buffer_info::height, "") +.def_readwrite("display_width", &frame_buffer_info::display_width, "") +.def_readwrite("display_height", &frame_buffer_info::display_height, "") +.def_readwrite("display_x", &frame_buffer_info::display_x, "") +.def_readwrite("display_y", &frame_buffer_info::display_y, "") +; + +py::class_(m, "screen_gamma") +//.def_readwrite("red", &screen_gamma::red, "") +.def_property( + "red", + [](const screen_gamma &gamma) { + return py::cast(gamma.red); + }, + [](screen_gamma &gamma, const std::string &value) { + if (value.size() +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +class PyBInputServerDevice : public BInputServerDevice { +public: + using BInputServerDevice::BInputServerDevice; + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, InitCheck); + } + status_t SystemShuttingDown() override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, SystemShuttingDown); + } + status_t Start(const char* device, void* cookie) override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, Start, device, cookie); + } + status_t Stop(const char* device, void* cookie) override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, Stop, device, cookie); + } + status_t Control(const char* device, void* cookie, uint32 code, BMessage* message) override { + PYBIND11_OVERLOAD(status_t, BInputServerDevice, Control, device, cookie, code, message); + } +}; + +PYBIND11_MODULE(InputServerDevice, m) +{ + +py::class_(m, "input_device_ref") +.def(py::init(), "") +.def_readwrite("name", &input_device_ref::name, "") +.def_readwrite("type", &input_device_ref::type, "") +.def_readwrite("cookie", &input_device_ref::cookie, "") +; + +py::class_(m, "BInputServerDevice") +.def(py::init(), "") +.def("InitCheck", &BInputServerDevice::InitCheck, "") +.def("SystemShuttingDown", &BInputServerDevice::SystemShuttingDown, "") +.def("Start", &BInputServerDevice::Start, "", py::arg("device"), py::arg("cookie")) +.def("Stop", &BInputServerDevice::Stop, "", py::arg("device"), py::arg("cookie")) +.def("Control", &BInputServerDevice::Control, "", py::arg("device"), py::arg("cookie"), py::arg("code"), py::arg("message")) +//.def("RegisterDevices", &BInputServerDevice::RegisterDevices, "", py::arg("devices")) +.def("RegisterDevices", [](BInputServerDevice &self, py::list &py_devices) { + std::vector devices; + for (auto item : py_devices) { + devices.push_back(item.cast()); + } + status_t status = self.RegisterDevices(devices.data()); + //for (size_t i = 0; i < devices.size(); ++i) { + // py_devices[i] = py::cast(devices[i]); + //} + return status; + }, py::arg("devices")) +//.def("UnregisterDevices", &BInputServerDevice::UnregisterDevices, "", py::arg("devices")) +.def("UnregisterDevices", [](BInputServerDevice &self, py::list &py_devices) { + std::vector devices; + for (auto item : py_devices) { + devices.push_back(item.cast()); + } + status_t status = self.UnregisterDevices(devices.data()); + //for (size_t i = 0; i < devices.size(); ++i) { + // py_devices[i] = py::cast(devices[i]); + //} + return status; + }, py::arg("devices")) +.def("EnqueueMessage", &BInputServerDevice::EnqueueMessage, "", py::arg("message")) +.def("StartMonitoringDevice", &BInputServerDevice::StartMonitoringDevice, "", py::arg("device")) +.def("StopMonitoringDevice", &BInputServerDevice::StopMonitoringDevice, "", py::arg("device")) +.def("AddDevices", &BInputServerDevice::AddDevices, "", py::arg("path")) +; + +//m.attr("DeviceAddOn") = py::cast(DeviceAddOn); +m.attr("B_KEY_MAP_CHANGED") = py::cast(B_KEY_MAP_CHANGED); +m.attr("B_KEY_LOCKS_CHANGED") = py::cast(B_KEY_LOCKS_CHANGED); +m.attr("B_KEY_REPEAT_DELAY_CHANGED") = py::cast(B_KEY_REPEAT_DELAY_CHANGED); +m.attr("B_KEY_REPEAT_RATE_CHANGED") = py::cast(B_KEY_REPEAT_RATE_CHANGED); +m.attr("B_MOUSE_TYPE_CHANGED") = py::cast(B_MOUSE_TYPE_CHANGED); +m.attr("B_MOUSE_MAP_CHANGED") = py::cast(B_MOUSE_MAP_CHANGED); +m.attr("B_MOUSE_SPEED_CHANGED") = py::cast(B_MOUSE_SPEED_CHANGED); +m.attr("B_CLICK_SPEED_CHANGED") = py::cast(B_CLICK_SPEED_CHANGED); +m.attr("B_MOUSE_ACCELERATION_CHANGED") = py::cast(B_MOUSE_ACCELERATION_CHANGED); +m.attr("B_SET_TOUCHPAD_SETTINGS") = py::cast(B_SET_TOUCHPAD_SETTINGS); +} diff --git a/bindings/add-ons/input_server/InputServerFilter.cpp b/bindings/add-ons/input_server/InputServerFilter.cpp new file mode 100644 index 0000000..421a781 --- /dev/null +++ b/bindings/add-ons/input_server/InputServerFilter.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +class PyBInputServerFilter : public BInputServerFilter { +public: + using BInputServerFilter::BInputServerFilter; + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BInputServerFilter, InitCheck); + } + filter_result Filter(BMessage* message, BList* _list) override { + PYBIND11_OVERLOAD(filter_result, BInputServerFilter, Filter, message, _list); + } +}; + +PYBIND11_MODULE(InputServerFilter, m) +{ +py::class_(m, "BInputServerFilter") +.def(py::init(), "") +.def("InitCheck", &BInputServerFilter::InitCheck, "") +.def("Filter", &BInputServerFilter::Filter, "", py::arg("message"), py::arg("_list")) +.def("GetScreenRegion", &BInputServerFilter::GetScreenRegion, "", py::arg("region")) +; + + +} diff --git a/bindings/add-ons/input_server/InputServerMethod.cpp b/bindings/add-ons/input_server/InputServerMethod.cpp new file mode 100644 index 0000000..0125476 --- /dev/null +++ b/bindings/add-ons/input_server/InputServerMethod.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +class PyBInputServerMethod : public BInputServerMethod { +public: + using BInputServerMethod::BInputServerMethod; + status_t MethodActivated(bool active) override { + PYBIND11_OVERLOAD(status_t, BInputServerMethod, MethodActivated, active); + } +}; + +PYBIND11_MODULE(InputServerMethod, m) +{ +py::class_(m, "BInputServerMethod") +.def(py::init(), "", py::arg("name"), py::arg("icon")) +.def("MethodActivated", &BInputServerMethod::MethodActivated, "", py::arg("active")) +.def("EnqueueMessage", &BInputServerMethod::EnqueueMessage, "", py::arg("message")) +.def("SetName", &BInputServerMethod::SetName, "", py::arg("name")) +.def("SetIcon", &BInputServerMethod::SetIcon, "", py::arg("icon")) +.def("SetMenu", &BInputServerMethod::SetMenu, "", py::arg("menu"), py::arg("target")) +; + + +} diff --git a/bindings/add-ons/mail_daemon/MailFilter.cpp b/bindings/add-ons/mail_daemon/MailFilter.cpp new file mode 100644 index 0000000..8e14b42 --- /dev/null +++ b/bindings/add-ons/mail_daemon/MailFilter.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +#include +#include +#include +namespace py = pybind11; + +class PyBMailFilter : public BMailFilter{ + public: + using BMailFilter::BMailFilter; + BMailFilterAction HeaderFetched(entry_ref& ref, BFile& file, BMessage& attributes) override { + PYBIND11_OVERLOAD(BMailFilterAction, BMailFilter, HeaderFetched, ref, file, attributes); + } + void BodyFetched(const entry_ref& ref, BFile& file, BMessage& attributes) override { + PYBIND11_OVERLOAD(void, BMailFilter, BodyFetched, ref, file, attributes); + } + void MailboxSynchronized(status_t status) override { + PYBIND11_OVERLOAD(void, BMailFilter, MailboxSynchronized, status); + } + void MessageReadyToSend(const entry_ref& ref, BFile& file) override { + PYBIND11_OVERLOAD(void, BMailFilter, MessageReadyToSend, ref, file); + } + void MessageSent(const entry_ref& ref, BFile& file) override { + PYBIND11_OVERLOAD(void, BMailFilter, MessageSent, ref, file); + } +}; + +PYBIND11_MODULE(MailFilter, m) +{ +py::class_(m, "BMailFilter") +.def(py::init(), "", py::arg("protocol"),py::arg("settings")) +.def("HeaderFetched", &BMailFilter::HeaderFetched, "", py::arg("ref"),py::arg("file"), py::arg("attributes")) +/*.def("HeaderFetched", [](BMailFilter& self) { + entry_ref ref; +BFile file; +BMessage attributes; + BMailFilterAction r = self.HeaderFetched(ref, file, attributes); + return std::make_tuple(r,ref,file,attributes); +} +, "")*/ +.def("BodyFetched", &BMailFilter::BodyFetched, "", py::arg("ref"),py::arg("file"), py::arg("attributes")) +/*.def("BodyFetched", [](BMailFilter& self,const entry_ref & ref) { + BFile file; +BMessage attributes; + self.BodyFetched(ref, file, attributes); + return std::make_tuple(file,attributes); +} +, "", py::arg("ref"))*/ +.def("MailboxSynchronized", &BMailFilter::MailboxSynchronized, "", py::arg("status")) +.def("MessageReadyToSend", &BMailFilter::MessageReadyToSend, "", py::arg("ref"), py::arg("file")) +/*.def("MessageReadyToSend", [](BMailFilter& self,const entry_ref & ref) { + BFile file; + self.MessageReadyToSend(ref, file); + return file; +} +, "", py::arg("ref"))*/ +.def("MessageSent", &BMailFilter::MessageSent, "", py::arg("ref"), py::arg("file")) +/*.def("MessageSent", [](BMailFilter& self,const entry_ref & ref) { + BFile file; + self.MessageSent(ref, file); + return file; +} +, "", py::arg("ref"))*/ +; + +m.def("instantiate_filter_settings_view", &instantiate_filter_settings_view, "", py::arg("accountSettings"), py::arg("settings")); + +m.def("filter_name", &filter_name, "", py::arg("accountSettings"), py::arg("settings")); + +m.def("instantiate_filter", [](BMailProtocol& protocol, const BMailAddOnSettings & settings) { + BMailFilter * r = instantiate_filter(protocol, settings); + return r;//std::make_tuple(r,protocol); +} +, "", py::arg("protocol"), py::arg("settings")); + +} diff --git a/bindings/add-ons/mail_daemon/MailProtocol.cpp b/bindings/add-ons/mail_daemon/MailProtocol.cpp new file mode 100644 index 0000000..c16d1a8 --- /dev/null +++ b/bindings/add-ons/mail_daemon/MailProtocol.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; + +class PyBMailNotifier : public BMailNotifier{ + public: + using BMailNotifier::BMailNotifier; + BMailNotifier* Clone() override { + PYBIND11_OVERLOAD_PURE(BMailNotifier*, BMailNotifier, Clone); + } + void ShowError(const char* error) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ShowError, error); + } + void ShowMessage(const char* message) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ShowMessage, message); + } + void SetTotalItems(uint32 items) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, SetTotalItems, items); + } + void SetTotalItemsSize(uint64 size) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, SetTotalItemsSize, size); + } + void ReportProgress(uint32 items, uint64 bytes, const char* message = NULL) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ReportProgress, items, bytes, message); + } + void ResetProgress(const char* message = NULL) override { + PYBIND11_OVERLOAD_PURE(void, BMailNotifier, ResetProgress, message); + } +}; + +class PyBMailProtocol : public BMailProtocol{ + public: + using BMailProtocol::BMailProtocol; + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BMailProtocol, MessageReceived, message); + } +}; + + +PYBIND11_MODULE(MailProtocol, m) +{ +py::class_(m, "BMailNotifier") +.def("Clone", &BMailNotifier::Clone, "") +.def("ShowError", &BMailNotifier::ShowError, "", py::arg("error")) +.def("ShowMessage", &BMailNotifier::ShowMessage, "", py::arg("message")) +.def("SetTotalItems", &BMailNotifier::SetTotalItems, "", py::arg("items")) +.def("SetTotalItemsSize", &BMailNotifier::SetTotalItemsSize, "", py::arg("size")) +.def("ReportProgress", &BMailNotifier::ReportProgress, "", py::arg("items"), py::arg("bytes"), py::arg("message")=NULL) +.def("ResetProgress", &BMailNotifier::ResetProgress, "", py::arg("message")=NULL) +; + +py::class_(m, "BMailProtocol") +.def(py::init(), "", py::arg("name"), py::arg("settings")) +.def("AccountSettings", &BMailProtocol::AccountSettings, "") +.def("SetMailNotifier", &BMailProtocol::SetMailNotifier, "", py::arg("mailNotifier")) +.def("MailNotifier", &BMailProtocol::MailNotifier, "") +.def("AddFilter", py::overload_cast(&BMailProtocol::AddFilter), "", py::arg("filter")) +.def("CountFilter", &BMailProtocol::CountFilter, "") +.def("FilterAt", &BMailProtocol::FilterAt, "", py::arg("index")) +.def("RemoveFilter", py::overload_cast(&BMailProtocol::RemoveFilter), "", py::arg("index")) +.def("RemoveFilter", py::overload_cast(&BMailProtocol::RemoveFilter), "", py::arg("filter")) +.def("MessageReceived", &BMailProtocol::MessageReceived, "", py::arg("message")) +.def("ShowError", &BMailProtocol::ShowError, "", py::arg("error")) +.def("ShowMessage", &BMailProtocol::ShowMessage, "", py::arg("message")) +//.def_readwrite("AddFilter", &BMailProtocol::AddFilter, "") +//.def_readwrite("RemoveFilter", &BMailProtocol::RemoveFilter, "") +; + +/* +py::class_(m, "BInboundMailProtocol") +.def(py::init(), "", py::arg("name"), py::arg("settings")) +.def("MessageReceived", &BInboundMailProtocol::MessageReceived, "", py::arg("message")) +.def("SyncMessages", &BInboundMailProtocol::SyncMessages, "") +.def("FetchBody", &BInboundMailProtocol::FetchBody, "", py::arg("ref"), py::arg("replyTo")) +.def("MarkMessageAsRead", &BInboundMailProtocol::MarkMessageAsRead, "", py::arg("ref"), py::arg("flags")=B_READ) +.def_static("ReplyBodyFetched", &BInboundMailProtocol::ReplyBodyFetched, "", py::arg("replyTo"), py::arg("ref"), py::arg("status")) +; + +py::class_(m, "BOutboundMailProtocol") +.def(py::init(), "", py::arg("name"), py::arg("settings")) +.def("SendMessages", &BOutboundMailProtocol::SendMessages, "", py::arg("message"), py::arg("totalBytes")) +.def("MessageReceived", &BOutboundMailProtocol::MessageReceived, "", py::arg("message")) +;*/ + +m.def("instantiate_inbound_protocol", &instantiate_inbound_protocol, "", py::arg("settings")); + +m.def("instantiate_outbound_protocol", &instantiate_outbound_protocol, "", py::arg("settings")); + +m.def("instantiate_protocol_settings_view", &instantiate_protocol_settings_view, "", py::arg("accountSettings"), py::arg("settings")); + +//#define B_NO_MAIL_ACTION 0 +//#define B_MOVE_MAIL_ACTION 1 +//#define B_DELETE_MAIL_ACTION 2 + +} diff --git a/bindings/add-ons/mail_daemon/MailSettingsView.cpp b/bindings/add-ons/mail_daemon/MailSettingsView.cpp new file mode 100644 index 0000000..d0e6cef --- /dev/null +++ b/bindings/add-ons/mail_daemon/MailSettingsView.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class PyBMailSettingsView : public BMailSettingsView { +public: + using BMailSettingsView::BMailSettingsView; + status_t SaveInto(BMailAddOnSettings& settings) const override { + PYBIND11_OVERLOAD_PURE(status_t, BMailSettingsView, SaveInto, settings); + } +}; + +PYBIND11_MODULE(MailSettingsView, m) +{ +py::class_(m, "BMailSettingsView") +.def(py::init(), "", py::arg("name")) +.def("SaveInto", &BMailSettingsView::SaveInto, "", py::arg("settings")) +/*.def("SaveInto", [](BMailSettingsView& self) { + BMailAddOnSettings settings; + status_t r = self.SaveInto(settings); + return std::make_tuple(r,settings); +} +, "")*/ + +; + + +} diff --git a/bindings/add-ons/network_settings/NetworkProfile.cpp b/bindings/add-ons/network_settings/NetworkProfile.cpp new file mode 100644 index 0000000..62496ae --- /dev/null +++ b/bindings/add-ons/network_settings/NetworkProfile.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BNetworkKit; + +PYBIND11_MODULE(NetworkProfile, m) +{ +py::class_(m, "BNetworkProfile") +.def(py::init(), "") +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("entry")) +.def("SetTo", py::overload_cast(&BNetworkProfile::SetTo), "", py::arg("path")) +.def("SetTo", py::overload_cast(&BNetworkProfile::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BNetworkProfile::SetTo), "", py::arg("entry")) +.def("Exists", &BNetworkProfile::Exists, "") +.def("Name", &BNetworkProfile::Name, "") +.def("SetName", &BNetworkProfile::SetName, "", py::arg("name")) +.def("IsDefault", &BNetworkProfile::IsDefault, "") +.def("IsCurrent", &BNetworkProfile::IsCurrent, "") +.def("MakeCurrent", &BNetworkProfile::MakeCurrent, "") +.def("Delete", &BNetworkProfile::Delete, "") +.def_static("Default", &BNetworkProfile::Default, "") +.def_static("Current", &BNetworkProfile::Current, "") +; + + +} diff --git a/bindings/add-ons/network_settings/NetworkSettings.cpp b/bindings/add-ons/network_settings/NetworkSettings.cpp new file mode 100644 index 0000000..2db9dc8 --- /dev/null +++ b/bindings/add-ons/network_settings/NetworkSettings.cpp @@ -0,0 +1,203 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BNetworkKit; + +class AltBNetworkSettingsRead : public BNetworkSettings { +public: + using BNetworkSettings::BNetworkSettings; + static const uint32 kMsgInterfaceSettingsUpdated() { + return BNetworkSettings::kMsgInterfaceSettingsUpdated; + } + static const uint32 kMsgNetworkSettingsUpdated() { + return BNetworkSettings::kMsgNetworkSettingsUpdated; + } + static const uint32 kMsgServiceSettingsUpdated() { + return BNetworkSettings::kMsgServiceSettingsUpdated; + } +}; + +PYBIND11_MODULE(NetworkSettings, m) +{ +py::class_(m, "BNetworkSettings") +.def(py::init(), "") +.def("GetNextInterface", [](BNetworkSettings& self, uint32 cookie) { + BMessage interface; + status_t r = self.GetNextInterface(cookie, interface); + return std::make_tuple(r,interface); +} +, "", py::arg("cookie")) +.def("GetInterface", [](BNetworkSettings& self,const char * name) { + BMessage interface; + status_t r = self.GetInterface(name, interface); + return std::make_tuple(r,interface); +} +, "", py::arg("name")) +.def("AddInterface", &BNetworkSettings::AddInterface, "", py::arg("interface")) +.def("RemoveInterface", &BNetworkSettings::RemoveInterface, "", py::arg("name")) +.def("Interface", py::overload_cast(&BNetworkSettings::Interface), "", py::arg("name")) +.def("Interface", py::overload_cast(&BNetworkSettings::Interface, py::const_), "", py::arg("name")) +.def("CountNetworks", &BNetworkSettings::CountNetworks, "") +.def("GetNextNetwork", [](BNetworkSettings& self,uint32 cookie) { + BMessage network; + status_t r = self.GetNextNetwork(cookie, network); + return std::make_tuple(r,network); +} +, "", py::arg("cookie")) +.def("GetNetwork", [](BNetworkSettings& self,const char * name) { + BMessage network; + status_t r = self.GetNetwork(name, network); + return std::make_tuple(r,network); +} +, "", py::arg("name")) +.def("AddNetwork", &BNetworkSettings::AddNetwork, "", py::arg("network")) +.def("RemoveNetwork", &BNetworkSettings::RemoveNetwork, "", py::arg("name")) +.def("Services", &BNetworkSettings::Services, "") +.def("GetNextService", [](BNetworkSettings& self,uint32 cookie) { + BMessage service; + status_t r = self.GetNextService(cookie, service); + return std::make_tuple(r,service); +} +, "", py::arg("cookie")) +.def("GetService", [](BNetworkSettings& self,const char * name) { + BMessage service; + status_t r = self.GetService(name, service); + return std::make_tuple(r,service); +} +, "", py::arg("name")) +.def("AddService", &BNetworkSettings::AddService, "", py::arg("service")) +.def("RemoveService", &BNetworkSettings::RemoveService, "", py::arg("name")) +.def("Service", py::overload_cast(&BNetworkSettings::Service), "", py::arg("name")) +.def("Service", py::overload_cast(&BNetworkSettings::Service), "", py::arg("name")) +.def("StartMonitoring", &BNetworkSettings::StartMonitoring, "", py::arg("target")) +.def("StopMonitoring", &BNetworkSettings::StopMonitoring, "", py::arg("target")) +.def("Update", &BNetworkSettings::Update, "", py::arg("message")) +//.def_readwrite("kMsgInterfaceSettingsUpdated", &BNetworkSettings::kMsgInterfaceSettingsUpdated, "") +.def_property_readonly_static("kMsgInterfaceSettingsUpdated", []() { + return AltBNetworkSettingsRead::kMsgInterfaceSettingsUpdated(); + }, "") +//.def_readwrite("kMsgNetworkSettingsUpdated", &BNetworkSettings::kMsgNetworkSettingsUpdated, "") +.def_property_readonly_static("kMsgNetworkSettingsUpdated", []() { + return AltBNetworkSettingsRead::kMsgNetworkSettingsUpdated(); + }, "") +//.def_readwrite("kMsgServiceSettingsUpdated", &BNetworkSettings::kMsgServiceSettingsUpdated, "") +.def_property_readonly_static("kMsgServiceSettingsUpdated", []() { + return AltBNetworkSettingsRead::kMsgServiceSettingsUpdated(); + }, "") +; + +py::class_(m, "BNetworkInterfaceAddressSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("data")) +.def(py::init(), "", py::arg("other")) +.def("Family", &BNetworkInterfaceAddressSettings::Family, "") +.def("SetFamily", &BNetworkInterfaceAddressSettings::SetFamily, "", py::arg("family")) +.def("IsAutoConfigure", &BNetworkInterfaceAddressSettings::IsAutoConfigure, "") +.def("SetAutoConfigure", &BNetworkInterfaceAddressSettings::SetAutoConfigure, "", py::arg("configure")) +.def("Address", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Address), "") +.def("Address", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Address), "") +.def("Mask", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Mask), "") +.def("Mask", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Mask), "") +.def("Peer", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Peer), "") +.def("Peer", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Peer), "") +.def("Broadcast", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Broadcast), "") +.def("Broadcast", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Broadcast), "") +.def("Gateway", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Gateway), "") +.def("Gateway", py::overload_cast<>(&BNetworkInterfaceAddressSettings::Gateway), "") +.def("GetMessage", [](BNetworkInterfaceAddressSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +.def("operator=", &BNetworkInterfaceAddressSettings::operator=, "", py::arg("other")) +; + +py::class_(m, "BNetworkInterfaceSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("message")) +.def("Name", &BNetworkInterfaceSettings::Name, "") +.def("SetName", &BNetworkInterfaceSettings::SetName, "", py::arg("name")) +.def("Flags", &BNetworkInterfaceSettings::Flags, "") +.def("SetFlags", &BNetworkInterfaceSettings::SetFlags, "", py::arg("flags")) +.def("MTU", &BNetworkInterfaceSettings::MTU, "") +.def("SetMTU", &BNetworkInterfaceSettings::SetMTU, "", py::arg("mtu")) +.def("Metric", &BNetworkInterfaceSettings::Metric, "") +.def("SetMetric", &BNetworkInterfaceSettings::SetMetric, "", py::arg("metric")) +.def("CountAddresses", &BNetworkInterfaceSettings::CountAddresses, "") +.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) +.def("AddressAt", py::overload_cast(&BNetworkInterfaceSettings::AddressAt), "", py::arg("index")) +.def("FindFirstAddress", &BNetworkInterfaceSettings::FindFirstAddress, "", py::arg("family")) +.def("AddAddress", &BNetworkInterfaceSettings::AddAddress, "", py::arg("address")) +.def("RemoveAddress", &BNetworkInterfaceSettings::RemoveAddress, "", py::arg("index")) +.def("IsAutoConfigure", &BNetworkInterfaceSettings::IsAutoConfigure, "", py::arg("family")) +.def("GetMessage", [](BNetworkInterfaceSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +; + +py::class_(m, "BNetworkServiceAddressSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("data"), py::arg("family")=- 1, py::arg("type")=- 1, py::arg("protocol")=- 1, py::arg("port")=- 1) +.def("Family", &BNetworkServiceAddressSettings::Family, "") +.def("SetFamily", &BNetworkServiceAddressSettings::SetFamily, "", py::arg("family")) +.def("Protocol", &BNetworkServiceAddressSettings::Protocol, "") +.def("SetProtocol", &BNetworkServiceAddressSettings::SetProtocol, "", py::arg("protocol")) +.def("Type", &BNetworkServiceAddressSettings::Type, "") +.def("SetType", &BNetworkServiceAddressSettings::SetType, "", py::arg("type")) +.def("Address", py::overload_cast<>(&BNetworkServiceAddressSettings::Address), "") +.def("Address", py::overload_cast<>(&BNetworkServiceAddressSettings::Address), "") +.def("GetMessage", [](BNetworkServiceAddressSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +.def("__eq__", &BNetworkServiceAddressSettings::operator==, "", py::arg("other")) +; + +py::class_(m, "BNetworkServiceSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("message")) +.def("InitCheck", &BNetworkServiceSettings::InitCheck, "") +.def("Name", &BNetworkServiceSettings::Name, "") +.def("SetName", &BNetworkServiceSettings::SetName, "", py::arg("name")) +.def("IsStandAlone", &BNetworkServiceSettings::IsStandAlone, "") +.def("SetStandAlone", &BNetworkServiceSettings::SetStandAlone, "", py::arg("alone")) +.def("IsEnabled", &BNetworkServiceSettings::IsEnabled, "") +.def("SetEnabled", &BNetworkServiceSettings::SetEnabled, "", py::arg("enable")) +.def("Family", &BNetworkServiceSettings::Family, "") +.def("SetFamily", &BNetworkServiceSettings::SetFamily, "", py::arg("family")) +.def("Protocol", &BNetworkServiceSettings::Protocol, "") +.def("SetProtocol", &BNetworkServiceSettings::SetProtocol, "", py::arg("protocol")) +.def("Type", &BNetworkServiceSettings::Type, "") +.def("SetType", &BNetworkServiceSettings::SetType, "", py::arg("type")) +.def("Port", &BNetworkServiceSettings::Port, "") +.def("SetPort", &BNetworkServiceSettings::SetPort, "", py::arg("port")) +.def("CountArguments", &BNetworkServiceSettings::CountArguments, "") +.def("ArgumentAt", &BNetworkServiceSettings::ArgumentAt, "", py::arg("index")) +.def("AddArgument", &BNetworkServiceSettings::AddArgument, "", py::arg("argument")) +.def("RemoveArgument", &BNetworkServiceSettings::RemoveArgument, "", py::arg("index")) +.def("CountAddresses", &BNetworkServiceSettings::CountAddresses, "") +.def("AddressAt", &BNetworkServiceSettings::AddressAt, "", py::arg("index")) +.def("AddAddress", &BNetworkServiceSettings::AddAddress, "", py::arg("address")) +.def("RemoveAddress", &BNetworkServiceSettings::RemoveAddress, "", py::arg("index")) +.def("IsRunning", &BNetworkServiceSettings::IsRunning, "") +.def("GetMessage", [](BNetworkServiceSettings& self) { + BMessage data; + status_t r = self.GetMessage(data); + return std::make_tuple(r,data); +} +, "") +; + + +} diff --git a/bindings/add-ons/network_settings/NetworkSettingsAddOn.cpp b/bindings/add-ons/network_settings/NetworkSettingsAddOn.cpp new file mode 100644 index 0000000..6bccd78 --- /dev/null +++ b/bindings/add-ons/network_settings/NetworkSettingsAddOn.cpp @@ -0,0 +1,186 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BNetworkKit; + +class PyBNetworkConfigurationListener : public BNetworkConfigurationListener{ + public: + using BNetworkConfigurationListener::BNetworkConfigurationListener; + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD_PURE(void, BNetworkConfigurationListener, ConfigurationUpdated, message); + } +}; + +class PyBNetworkSettingsListener : public BNetworkSettingsListener{ + public: + using BNetworkSettingsListener::BNetworkSettingsListener; + void SettingsUpdated(uint32 type) override { + PYBIND11_OVERLOAD_PURE(void, BNetworkSettingsListener, SettingsUpdated, type); + } +}; + +class PyBNetworkSettingsItem : public BNetworkSettingsItem{ + public: + using BNetworkSettingsItem::BNetworkSettingsItem; + BNetworkSettingsType Type() const override { + PYBIND11_OVERLOAD_PURE(BNetworkSettingsType, BNetworkSettingsItem, Type); + } + BListItem* ListItem() override { + PYBIND11_OVERLOAD_PURE(BListItem*,BNetworkSettingsItem,ListItem); + } + BView* View() override { + PYBIND11_OVERLOAD_PURE(BView*,BNetworkSettingsItem,View); + } + status_t ProfileChanged(const BNetworkProfile* newProfile) override { + PYBIND11_OVERLOAD(status_t,BNetworkSettingsItem,ProfileChanged,newProfile); + } + status_t Revert() override { + PYBIND11_OVERLOAD_PURE(status_t,BNetworkSettingsItem,Revert); + } + bool IsRevertable() override { + PYBIND11_OVERLOAD_PURE(bool,BNetworkSettingsItem,IsRevertable); + } + void SettingsUpdated(uint32 type) override { + PYBIND11_OVERLOAD(void,BNetworkSettingsItem,SettingsUpdated,type); + } + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD(void,BNetworkSettingsItem,ConfigurationUpdated,message); + } + void NotifySettingsUpdated() override { + PYBIND11_OVERLOAD(void, BNetworkSettingsItem, NotifySettingsUpdated); + } +}; + +class PyBNetworkSettingsInterfaceItem : public BNetworkSettingsInterfaceItem{ + public: + using BNetworkSettingsInterfaceItem::BNetworkSettingsInterfaceItem; + BNetworkSettingsType Type() const override { + PYBIND11_OVERLOAD_PURE(BNetworkSettingsType, BNetworkSettingsInterfaceItem, Type); + } + /* BNetworkSettingsType Type() const override { + PYBIND11_OVERLOAD_PURE(BNetworkSettingsType, BNetworkSettingsInterfaceItem, Type); + }*/ + + BListItem* ListItem() override { + PYBIND11_OVERLOAD_PURE(BListItem*, BNetworkSettingsInterfaceItem, ListItem); + } + + BView* View() override { + PYBIND11_OVERLOAD_PURE(BView*, BNetworkSettingsInterfaceItem, View); + } + + status_t Revert() override { + PYBIND11_OVERLOAD_PURE(status_t, BNetworkSettingsInterfaceItem, Revert); + } + + bool IsRevertable() override { + PYBIND11_OVERLOAD_PURE(bool, BNetworkSettingsInterfaceItem, IsRevertable); + } + void SettingsUpdated(uint32 type) override { + PYBIND11_OVERLOAD(void, BNetworkSettingsInterfaceItem, SettingsUpdated, type); + } + + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD(void, BNetworkSettingsInterfaceItem, ConfigurationUpdated, message); + } + + void NotifySettingsUpdated() override { + PYBIND11_OVERLOAD(void, BNetworkSettingsInterfaceItem, NotifySettingsUpdated); + } +}; + +class PyBNetworkInterfaceListItem : public BNetworkInterfaceListItem{ + public: + using BNetworkInterfaceListItem::BNetworkInterfaceListItem; + void DrawItem(BView* owner,BRect bounds, bool complete) override { + PYBIND11_OVERLOAD(void, BNetworkInterfaceListItem, DrawItem, owner, bounds, complete); + } + void Update(BView* owner, const BFont* font) override { + PYBIND11_OVERLOAD(void, BNetworkInterfaceListItem, Update, owner, font); + } + void ConfigurationUpdated(const BMessage& message) override { + PYBIND11_OVERLOAD(void, BNetworkInterfaceListItem, ConfigurationUpdated, message); + } +}; + +class PyBNetworkSettingsAddOn : public BNetworkSettingsAddOn{ + public: + using BNetworkSettingsAddOn::BNetworkSettingsAddOn; + BNetworkSettingsInterfaceItem* CreateNextInterfaceItem(uint32& cookie, const char* interface) override { + PYBIND11_OVERLOAD(BNetworkSettingsInterfaceItem*, BNetworkSettingsAddOn, CreateNextInterfaceItem, cookie, interface); + } + BNetworkSettingsItem* CreateNextItem(uint32& cookie) override { + PYBIND11_OVERLOAD(BNetworkSettingsItem*, BNetworkSettingsAddOn, CreateNextItem, cookie); + } +}; + +PYBIND11_MODULE(NetworkSettingsAddOn, m) +{ +py::enum_(m, "BNetworkSettingsType", "") +.value("B_NETWORK_SETTINGS_TYPE_INTERFACE", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_INTERFACE, "") +.value("B_NETWORK_SETTINGS_TYPE_SERVICE", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_SERVICE, "") +.value("B_NETWORK_SETTINGS_TYPE_DIAL_UP", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_DIAL_UP, "") +.value("B_NETWORK_SETTINGS_TYPE_VPN", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_VPN, "") +.value("B_NETWORK_SETTINGS_TYPE_OTHER", BNetworkSettingsType::B_NETWORK_SETTINGS_TYPE_OTHER, "") +.export_values(); + +py::class_(m, "BNetworkConfigurationListener") +.def("ConfigurationUpdated", &BNetworkConfigurationListener::ConfigurationUpdated, "", py::arg("message")) +; + +py::class_(m, "BNetworkSettingsListener") +.def("SettingsUpdated", &BNetworkSettingsListener::SettingsUpdated, "", py::arg("type")) +; + +py::class_(m, "BNetworkSettingsItem") +.def(py::init(), "") +.def("Type", &BNetworkSettingsItem::Type, "") +.def("ListItem", &BNetworkSettingsItem::ListItem, "") +.def("View", &BNetworkSettingsItem::View, "") +.def("ProfileChanged", &BNetworkSettingsItem::ProfileChanged, "", py::arg("newProfile")) +.def("Profile", &BNetworkSettingsItem::Profile, "") +.def("Revert", &BNetworkSettingsItem::Revert, "") +.def("IsRevertable", &BNetworkSettingsItem::IsRevertable, "") +.def("SettingsUpdated", &BNetworkSettingsItem::SettingsUpdated, "", py::arg("type")) +.def("ConfigurationUpdated", &BNetworkSettingsItem::ConfigurationUpdated, "", py::arg("message")) +.def("NotifySettingsUpdated", &BNetworkSettingsItem::NotifySettingsUpdated, "") +; + +py::class_(m, "BNetworkSettingsInterfaceItem") +.def(py::init(), "", py::arg("interface")) +.def("Type", &BNetworkSettingsInterfaceItem::Type, "") +.def("Interface", &BNetworkSettingsInterfaceItem::Interface, "") +; + +py::class_(m, "BNetworkInterfaceListItem") +.def(py::init(), "", py::arg("family"), py::arg("interface"), py::arg("label"), py::arg("settings")) +.def("Label", &BNetworkInterfaceListItem::Label, "") +.def("DrawItem", &BNetworkInterfaceListItem::DrawItem, "", py::arg("owner"), py::arg("bounds"), py::arg("complete")) +.def("Update", &BNetworkInterfaceListItem::Update, "", py::arg("owner"), py::arg("font")) +.def("ConfigurationUpdated", &BNetworkInterfaceListItem::ConfigurationUpdated, "", py::arg("message")) +; + +py::class_(m, "BNetworkSettingsAddOn")//, PyBNetworkSettingsAddOn>(m, "BNetworkSettingsAddOn") +.def(py::init(), "", py::arg("image"), py::arg("settings")) +.def("CreateNextInterfaceItem", &BNetworkSettingsAddOn::CreateNextInterfaceItem, "", py::arg("cookie"), py::arg("interface")) +.def("CreateNextItem", &BNetworkSettingsAddOn::CreateNextItem, "", py::arg("cookie")) +.def("Image", &BNetworkSettingsAddOn::Image, "") +.def("Resources", &BNetworkSettingsAddOn::Resources, "") +.def("Settings", &BNetworkSettingsAddOn::Settings, "") +; + +m.def("instantiate_network_settings_add_on", [](image_id image) { + BNetworkSettings settings; + BNetworkSettingsAddOn * r = instantiate_network_settings_add_on(image, settings); + return std::make_tuple(r,settings); +} +, "", py::arg("image")); + +} diff --git a/bindings/add-ons/registrar/MimeSnifferAddon.cpp b/bindings/add-ons/registrar/MimeSnifferAddon.cpp new file mode 100644 index 0000000..2c93e54 --- /dev/null +++ b/bindings/add-ons/registrar/MimeSnifferAddon.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#include +//#include +#include +namespace py = pybind11; + +class PyBMimeSnifferAddon : public BMimeSnifferAddon{ + public: + using BMimeSnifferAddon::BMimeSnifferAddon; + size_t MinimalBufferSize() override { + PYBIND11_OVERLOAD(size_t, BMimeSnifferAddon, MinimalBufferSize); + } + float GuessMimeType(const char* fileName, BMimeType* type) override { + PYBIND11_OVERLOAD(float, BMimeSnifferAddon, GuessMimeType, fileName, type); + } + float GuessMimeType(BFile* file, const void* buffer, int32 length, BMimeType* type) override { + PYBIND11_OVERLOAD(float, BMimeSnifferAddon, GuessMimeType, file, buffer, length, type); + } +}; + +PYBIND11_MODULE(MimeSnifferAddon, m) +{ +py::class_(m, "BMimeSnifferAddon") +.def(py::init(), "") +.def("MinimalBufferSize", &BMimeSnifferAddon::MinimalBufferSize, "") +.def("GuessMimeType", py::overload_cast(&BMimeSnifferAddon::GuessMimeType), "", py::arg("fileName"), py::arg("type")) +.def("GuessMimeType", py::overload_cast(&BMimeSnifferAddon::GuessMimeType), "", py::arg("file"), py::arg("buffer"), py::arg("length"), py::arg("type")) +; + + +} diff --git a/bindings/add-ons/screen_saver/ScreenSaver.cpp b/bindings/add-ons/screen_saver/ScreenSaver.cpp new file mode 100644 index 0000000..883749c --- /dev/null +++ b/bindings/add-ons/screen_saver/ScreenSaver.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class PyBScreenSaver : public BScreenSaver{ + public: + using BScreenSaver::BScreenSaver; + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BScreenSaver, InitCheck); + } + status_t StartSaver(BView* view, bool preview) override { + PYBIND11_OVERLOAD(status_t, BScreenSaver, StartSaver, view, preview); + } + void StopSaver() override { + PYBIND11_OVERLOAD(void, BScreenSaver, StopSaver); + } + void Draw(BView* view, int32 frame) override { + PYBIND11_OVERLOAD(void, BScreenSaver, Draw, view, frame); + } + void DirectConnected(direct_buffer_info* info) override { + PYBIND11_OVERLOAD(void, BScreenSaver, DirectConnected, info); + } + void DirectDraw(int32 frame) override { + PYBIND11_OVERLOAD(void, BScreenSaver, DirectDraw, frame); + } + void StartConfig(BView* configView) override { + PYBIND11_OVERLOAD(void, BScreenSaver, StartConfig, configView); + } + void StopConfig() override { + PYBIND11_OVERLOAD(void, BScreenSaver, StopConfig); + } + void SupplyInfo(BMessage* info) const override { + PYBIND11_OVERLOAD(void, BScreenSaver, SupplyInfo, info); + } + void ModulesChanged(const BMessage* info) override { + PYBIND11_OVERLOAD(void, BScreenSaver, ModulesChanged, info); + } + status_t SaveState(BMessage* into) const override { + PYBIND11_OVERLOAD(status_t, BScreenSaver, SaveState, into); + } +}; + +PYBIND11_MODULE(ScreenSaver, m) +{ +py::class_(m, "BScreenSaver") +.def(py::init(), "", py::arg("archive"), py::arg("thisImage")) +.def("InitCheck", &BScreenSaver::InitCheck, "") +.def("StartSaver", &BScreenSaver::StartSaver, "", py::arg("view"), py::arg("preview")) +.def("StopSaver", &BScreenSaver::StopSaver, "") +.def("Draw", &BScreenSaver::Draw, "", py::arg("view"), py::arg("frame")) +.def("DirectConnected", &BScreenSaver::DirectConnected, "", py::arg("info")) +.def("DirectDraw", &BScreenSaver::DirectDraw, "", py::arg("frame")) +.def("StartConfig", &BScreenSaver::StartConfig, "", py::arg("configView")) +.def("StopConfig", &BScreenSaver::StopConfig, "") +.def("SupplyInfo", &BScreenSaver::SupplyInfo, "", py::arg("info")) +.def("ModulesChanged", &BScreenSaver::ModulesChanged, "", py::arg("info")) +.def("SaveState", &BScreenSaver::SaveState, "", py::arg("into")) +.def("SetTickSize", &BScreenSaver::SetTickSize, "", py::arg("tickSize")) +.def("TickSize", &BScreenSaver::TickSize, "") +.def("SetLoop", &BScreenSaver::SetLoop, "", py::arg("onCount"), py::arg("offCount")) +.def("LoopOnCount", &BScreenSaver::LoopOnCount, "") +.def("LoopOffCount", &BScreenSaver::LoopOffCount, "") +; + +m.def("instantiate_screen_saver", &instantiate_screen_saver, "", py::arg("msg"), py::arg("id")); + +} diff --git a/bindings/app/AppDefs.cpp b/bindings/app/AppDefs.cpp index b5202f2..480a780 100644 --- a/bindings/app/AppDefs.cpp +++ b/bindings/app/AppDefs.cpp @@ -2,126 +2,146 @@ #include #include #include +#include -#include #include +#include #include namespace py = pybind11; +// calculates the size of an old-style cursor array +int cursor_array_size(const unsigned char cursor[]) { + int width = cursor[0]; // width in pixels + int height = cursor[0]; // height in pixels + int depth = cursor[1]; // number of bits per pixel + + // number of bytes in each section of the data structure + int header_size = 4; + int image_mask_size = width * height * depth / 8; + int transparency_mask_size = width * height * depth / 8; + + return header_size + image_mask_size + transparency_mask_size; +} + PYBIND11_MODULE(AppDefs,m) { -m.attr("B_ABOUT_REQUESTED") = py::int_('_ABR'); -m.attr("B_WINDOW_ACTIVATED") = py::int_('_ACT'); -m.attr("B_APP_ACTIVATED") = py::int_('_ACT'); -m.attr("B_ARGV_RECEIVED") = py::int_('_ARG'); -m.attr("B_QUIT_REQUESTED") = py::int_('_QRQ'); -m.attr("B_CLOSE_REQUESTED") = py::int_('_QRQ'); -m.attr("B_CANCEL") = py::int_('_CNC'); -m.attr("B_INVALIDATE") = py::int_('_IVL'); -m.attr("B_KEY_DOWN") = py::int_('_KYD'); -m.attr("B_KEY_UP") = py::int_('_KYU'); -m.attr("B_UNMAPPED_KEY_DOWN") = py::int_('_UKD'); -m.attr("B_UNMAPPED_KEY_UP") = py::int_('_UKU'); -m.attr("B_KEY_MAP_LOADED") = py::int_('_KML'); -m.attr("B_LAYOUT_WINDOW") = py::int_('_LAY'); -m.attr("B_MODIFIERS_CHANGED") = py::int_('_MCH'); -m.attr("B_MINIMIZE") = py::int_('_WMN'); -m.attr("B_MOUSE_DOWN") = py::int_('_MDN'); -m.attr("B_MOUSE_MOVED") = py::int_('_MMV'); -m.attr("B_MOUSE_ENTER_EXIT") = py::int_('_MEX'); -m.attr("B_MOUSE_IDLE") = py::int_('_MSI'); -m.attr("B_MOUSE_UP") = py::int_('_MUP'); -m.attr("B_MOUSE_WHEEL_CHANGED") = py::int_('_MWC'); -m.attr("B_OPEN_IN_WORKSPACE") = py::int_('_OWS'); -m.attr("B_PACKAGE_UPDATE") = py::int_('_PKU'); -m.attr("B_PRINTER_CHANGED") = py::int_('_PCH'); -m.attr("B_PULSE") = py::int_('_PUL'); -m.attr("B_READY_TO_RUN") = py::int_('_RTR'); -m.attr("B_REFS_RECEIVED") = py::int_('_RRC'); -m.attr("B_RELEASE_OVERLAY_LOCK") = py::int_('_ROV'); -m.attr("B_ACQUIRE_OVERLAY_LOCK") = py::int_('_AOV'); -m.attr("B_SCREEN_CHANGED") = py::int_('_SCH'); -m.attr("B_VALUE_CHANGED") = py::int_('_VCH'); -m.attr("B_TRANSLATOR_ADDED") = py::int_('_ART'); -m.attr("B_TRANSLATOR_REMOVED") = py::int_('_RRT'); -m.attr("B_DELETE_TRANSLATOR") = py::int_('_DRT'); -m.attr("B_VIEW_MOVED") = py::int_('_VMV'); -m.attr("B_VIEW_RESIZED") = py::int_('_VRS'); -m.attr("B_WINDOW_MOVED") = py::int_('_WMV'); -m.attr("B_WINDOW_RESIZED") = py::int_('_WRS'); -m.attr("B_WORKSPACES_CHANGED") = py::int_('_WCG'); -m.attr("B_WORKSPACE_ACTIVATED") = py::int_('_WAC'); -m.attr("B_ZOOM") = py::int_('_WZM'); -m.attr("B_COLORS_UPDATED") = py::int_('_CLU'); -m.attr("B_FONTS_UPDATED") = py::int_('_FNU'); -m.attr("B_TRACKER_ADDON_MESSAGE") = py::int_('_TAM'); -m.attr("_APP_MENU_") = py::int_('_AMN'); -m.attr("_BROWSER_MENUS_") = py::int_('_BRM'); -m.attr("_MENU_EVENT_") = py::int_('_MEV'); -m.attr("_PING_") = py::int_('_PBL'); -m.attr("_QUIT_") = py::int_('_QIT'); -m.attr("_VOLUME_MOUNTED_") = py::int_('_NVL'); -m.attr("_VOLUME_UNMOUNTED_") = py::int_('_VRM'); -m.attr("_MESSAGE_DROPPED_") = py::int_('_MDP'); -m.attr("_DISPOSE_DRAG_") = py::int_('_DPD'); -m.attr("_MENUS_DONE_") = py::int_('_MND'); -m.attr("_SHOW_DRAG_HANDLES_") = py::int_('_SDH'); -m.attr("_EVENTS_PENDING_") = py::int_('_EVP'); -m.attr("_UPDATE_") = py::int_('_UPD'); -m.attr("_UPDATE_IF_NEEDED_") = py::int_('_UPN'); -m.attr("_PRINTER_INFO_") = py::int_('_PIN'); -m.attr("_SETUP_PRINTER_") = py::int_('_SUP'); -m.attr("_SELECT_PRINTER_") = py::int_('_PSL'); - -m.attr("B_SET_PROPERTY") = py::int_('PSET'); -m.attr("B_GET_PROPERTY") = py::int_('PGET'); -m.attr("B_CREATE_PROPERTY") = py::int_('PCRT'); -m.attr("B_DELETE_PROPERTY") = py::int_('PDEL'); -m.attr("B_COUNT_PROPERTIES") = py::int_('PCNT'); -m.attr("B_EXECUTE_PROPERTY") = py::int_('PEXE'); -m.attr("B_GET_SUPPORTED_SUITES") = py::int_('SUIT'); -m.attr("B_UNDO") = py::int_('UNDO'); -m.attr("B_REDO") = py::int_('REDO'); -m.attr("B_CUT") = py::int_('CCUT'); -m.attr("B_COPY") = py::int_('COPY'); -m.attr("B_PASTE") = py::int_('PSTE'); -m.attr("B_SELECT_ALL") = py::int_('SALL'); -m.attr("B_SAVE_REQUESTED") = py::int_('SAVE'); -m.attr("B_MESSAGE_NOT_UNDERSTOOD") = py::int_('MNOT'); -m.attr("B_NO_REPLY") = py::int_('NONE'); -m.attr("B_REPLY") = py::int_('RPLY'); -m.attr("B_SIMPLE_DATA") = py::int_('DATA'); -m.attr("B_MIME_DATA") = py::int_('MIME'); -m.attr("B_ARCHIVED_OBJECT") = py::int_('ARCV'); -m.attr("B_UPDATE_STATUS_BAR") = py::int_('SBUP'); -m.attr("B_RESET_STATUS_BAR") = py::int_('SBRS'); -m.attr("B_NODE_MONITOR") = py::int_('NDMN'); -m.attr("B_QUERY_UPDATE") = py::int_('QUPD'); -m.attr("B_ENDORSABLE") = py::int_('ENDO'); -m.attr("B_COPY_TARGET") = py::int_('DDCP'); -m.attr("B_MOVE_TARGET") = py::int_('DDMV'); -m.attr("B_TRASH_TARGET") = py::int_('DDRM'); -m.attr("B_LINK_TARGET") = py::int_('DDLN'); -m.attr("B_INPUT_DEVICES_CHANGED") = py::int_('IDCH'); -m.attr("B_INPUT_METHOD_EVENT") = py::int_('IMEV'); -m.attr("B_WINDOW_MOVE_TO") = py::int_('WDMT'); -m.attr("B_WINDOW_MOVE_BY") = py::int_('WDMB'); -m.attr("B_SILENT_RELAUNCH") = py::int_('AREL'); -m.attr("B_OBSERVER_NOTICE_CHANGE") = py::int_('NTCH'); -m.attr("B_CONTROL_INVOKED") = py::int_('CIVK'); -m.attr("B_CONTROL_MODIFIED") = py::int_('CMOD'); +py::module_::import("Be.Cursor"); -/* -m.attr("B_HAND_CURSOR") = B_HAND_CURSOR; +py::enum_(m, "system_message_code", "") +.value("B_ABOUT_REQUESTED", system_message_code::B_ABOUT_REQUESTED, "") +.value("B_WINDOW_ACTIVATED", system_message_code::B_WINDOW_ACTIVATED, "") +.value("B_APP_ACTIVATED", system_message_code::B_APP_ACTIVATED, "") +.value("B_ARGV_RECEIVED", system_message_code::B_ARGV_RECEIVED, "") +.value("B_QUIT_REQUESTED", system_message_code::B_QUIT_REQUESTED, "") +.value("B_CLOSE_REQUESTED", system_message_code::B_CLOSE_REQUESTED, "") +.value("B_CANCEL", system_message_code::B_CANCEL, "") +.value("B_INVALIDATE", system_message_code::B_INVALIDATE, "") +.value("B_KEY_DOWN", system_message_code::B_KEY_DOWN, "") +.value("B_KEY_UP", system_message_code::B_KEY_UP, "") +.value("B_UNMAPPED_KEY_DOWN", system_message_code::B_UNMAPPED_KEY_DOWN, "") +.value("B_UNMAPPED_KEY_UP", system_message_code::B_UNMAPPED_KEY_UP, "") +.value("B_KEY_MAP_LOADED", system_message_code::B_KEY_MAP_LOADED, "") +.value("B_LAYOUT_WINDOW", system_message_code::B_LAYOUT_WINDOW, "") +.value("B_MODIFIERS_CHANGED", system_message_code::B_MODIFIERS_CHANGED, "") +.value("B_MINIMIZE", system_message_code::B_MINIMIZE, "") +.value("B_MOUSE_DOWN", system_message_code::B_MOUSE_DOWN, "") +.value("B_MOUSE_MOVED", system_message_code::B_MOUSE_MOVED, "") +.value("B_MOUSE_ENTER_EXIT", system_message_code::B_MOUSE_ENTER_EXIT, "") +.value("B_MOUSE_IDLE", system_message_code::B_MOUSE_IDLE, "") +.value("B_MOUSE_UP", system_message_code::B_MOUSE_UP, "") +.value("B_MOUSE_WHEEL_CHANGED", system_message_code::B_MOUSE_WHEEL_CHANGED, "") +.value("B_OPEN_IN_WORKSPACE", system_message_code::B_OPEN_IN_WORKSPACE, "") +.value("B_PACKAGE_UPDATE", system_message_code::B_PACKAGE_UPDATE, "") +.value("B_PRINTER_CHANGED", system_message_code::B_PRINTER_CHANGED, "") +.value("B_PULSE", system_message_code::B_PULSE, "") +.value("B_READY_TO_RUN", system_message_code::B_READY_TO_RUN, "") +.value("B_REFS_RECEIVED", system_message_code::B_REFS_RECEIVED, "") +.value("B_RELEASE_OVERLAY_LOCK", system_message_code::B_RELEASE_OVERLAY_LOCK, "") +.value("B_ACQUIRE_OVERLAY_LOCK", system_message_code::B_ACQUIRE_OVERLAY_LOCK, "") +.value("B_SCREEN_CHANGED", system_message_code::B_SCREEN_CHANGED, "") +.value("B_VALUE_CHANGED", system_message_code::B_VALUE_CHANGED, "") +.value("B_TRANSLATOR_ADDED", system_message_code::B_TRANSLATOR_ADDED, "") +.value("B_TRANSLATOR_REMOVED", system_message_code::B_TRANSLATOR_REMOVED, "") +.value("B_DELETE_TRANSLATOR", system_message_code::B_DELETE_TRANSLATOR, "") +.value("B_VIEW_MOVED", system_message_code::B_VIEW_MOVED, "") +.value("B_VIEW_RESIZED", system_message_code::B_VIEW_RESIZED, "") +.value("B_WINDOW_MOVED", system_message_code::B_WINDOW_MOVED, "") +.value("B_WINDOW_RESIZED", system_message_code::B_WINDOW_RESIZED, "") +.value("B_WORKSPACES_CHANGED", system_message_code::B_WORKSPACES_CHANGED, "") +.value("B_WORKSPACE_ACTIVATED", system_message_code::B_WORKSPACE_ACTIVATED, "") +.value("B_ZOOM", system_message_code::B_ZOOM, "") +.value("B_COLORS_UPDATED", system_message_code::B_COLORS_UPDATED, "") +.value("B_FONTS_UPDATED", system_message_code::B_FONTS_UPDATED, "") +.value("B_TRACKER_ADDON_MESSAGE", system_message_code::B_TRACKER_ADDON_MESSAGE, "") +.value("_APP_MENU_", system_message_code::_APP_MENU_, "") +.value("_BROWSER_MENUS_", system_message_code::_BROWSER_MENUS_, "") +.value("_MENU_EVENT_", system_message_code::_MENU_EVENT_, "") +.value("_PING_", system_message_code::_PING_, "") +.value("_QUIT_", system_message_code::_QUIT_, "") +.value("_VOLUME_MOUNTED_", system_message_code::_VOLUME_MOUNTED_, "") +.value("_VOLUME_UNMOUNTED_", system_message_code::_VOLUME_UNMOUNTED_, "") +.value("_MESSAGE_DROPPED_", system_message_code::_MESSAGE_DROPPED_, "") +.value("_DISPOSE_DRAG_", system_message_code::_DISPOSE_DRAG_, "") +.value("_MENUS_DONE_", system_message_code::_MENUS_DONE_, "") +.value("_SHOW_DRAG_HANDLES_", system_message_code::_SHOW_DRAG_HANDLES_, "") +.value("_EVENTS_PENDING_", system_message_code::_EVENTS_PENDING_, "") +.value("_UPDATE_", system_message_code::_UPDATE_, "") +.value("_UPDATE_IF_NEEDED_", system_message_code::_UPDATE_IF_NEEDED_, "") +.value("_PRINTER_INFO_", system_message_code::_PRINTER_INFO_, "") +.value("_SETUP_PRINTER_", system_message_code::_SETUP_PRINTER_, "") +.value("_SELECT_PRINTER_", system_message_code::_SELECT_PRINTER_, "") +.export_values(); -m.attr("B_I_BEAM_CURSOR") = B_I_BEAM_CURSOR; +py::enum_(m, "command_code", "") +.value("B_SET_PROPERTY", command_code::B_SET_PROPERTY, "") +.value("B_GET_PROPERTY", command_code::B_GET_PROPERTY, "") +.value("B_CREATE_PROPERTY", command_code::B_CREATE_PROPERTY, "") +.value("B_DELETE_PROPERTY", command_code::B_DELETE_PROPERTY, "") +.value("B_COUNT_PROPERTIES", command_code::B_COUNT_PROPERTIES, "") +.value("B_EXECUTE_PROPERTY", command_code::B_EXECUTE_PROPERTY, "") +.value("B_GET_SUPPORTED_SUITES", command_code::B_GET_SUPPORTED_SUITES, "") +.value("B_UNDO", command_code::B_UNDO, "") +.value("B_REDO", command_code::B_REDO, "") +.value("B_CUT", command_code::B_CUT, "") +.value("B_COPY", command_code::B_COPY, "") +.value("B_PASTE", command_code::B_PASTE, "") +.value("B_SELECT_ALL", command_code::B_SELECT_ALL, "") +.value("B_SAVE_REQUESTED", command_code::B_SAVE_REQUESTED, "") +.value("B_MESSAGE_NOT_UNDERSTOOD", command_code::B_MESSAGE_NOT_UNDERSTOOD, "") +.value("B_NO_REPLY", command_code::B_NO_REPLY, "") +.value("B_REPLY", command_code::B_REPLY, "") +.value("B_SIMPLE_DATA", command_code::B_SIMPLE_DATA, "") +.value("B_MIME_DATA", command_code::B_MIME_DATA, "") +.value("B_ARCHIVED_OBJECT", command_code::B_ARCHIVED_OBJECT, "") +.value("B_UPDATE_STATUS_BAR", command_code::B_UPDATE_STATUS_BAR, "") +.value("B_RESET_STATUS_BAR", command_code::B_RESET_STATUS_BAR, "") +.value("B_NODE_MONITOR", command_code::B_NODE_MONITOR, "") +.value("B_QUERY_UPDATE", command_code::B_QUERY_UPDATE, "") +.value("B_ENDORSABLE", command_code::B_ENDORSABLE, "") +.value("B_COPY_TARGET", command_code::B_COPY_TARGET, "") +.value("B_MOVE_TARGET", command_code::B_MOVE_TARGET, "") +.value("B_TRASH_TARGET", command_code::B_TRASH_TARGET, "") +.value("B_LINK_TARGET", command_code::B_LINK_TARGET, "") +.value("B_INPUT_DEVICES_CHANGED", command_code::B_INPUT_DEVICES_CHANGED, "") +.value("B_INPUT_METHOD_EVENT", command_code::B_INPUT_METHOD_EVENT, "") +.value("B_WINDOW_MOVE_TO", command_code::B_WINDOW_MOVE_TO, "") +.value("B_WINDOW_MOVE_BY", command_code::B_WINDOW_MOVE_BY, "") +.value("B_SILENT_RELAUNCH", command_code::B_SILENT_RELAUNCH, "") +.value("B_OBSERVER_NOTICE_CHANGE", command_code::B_OBSERVER_NOTICE_CHANGE, "") +.value("B_CONTROL_INVOKED", command_code::B_CONTROL_INVOKED, "") +.value("B_CONTROL_MODIFIED", command_code::B_CONTROL_MODIFIED, "") +.export_values(); +// old-style cursors +m.attr("B_HAND_CURSOR") = std::vector( + B_HAND_CURSOR, B_HAND_CURSOR + cursor_array_size(B_HAND_CURSOR)); +m.attr("B_I_BEAM_CURSOR") = std::vector( + B_I_BEAM_CURSOR, B_I_BEAM_CURSOR + cursor_array_size(B_I_BEAM_CURSOR)); +// new-style cursors m.attr("B_CURSOR_SYSTEM_DEFAULT") = B_CURSOR_SYSTEM_DEFAULT; - m.attr("B_CURSOR_I_BEAM") = B_CURSOR_I_BEAM; -*/ } diff --git a/bindings/app/Application.cpp b/bindings/app/Application.cpp index 6701bce..1e6eca5 100644 --- a/bindings/app/Application.cpp +++ b/bindings/app/Application.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -18,58 +18,116 @@ namespace py = pybind11; using namespace BPrivate; +void RunWrapper(BApplication& self) { + // Why release the gil (global interpreter lock) here? Because its a long- + // running function (it usually runs for the lifetime of the application). + // See https://pybind11.readthedocs.io/en/stable/advanced/misc.html#global-interpreter-lock-gil + // for more details. + py::gil_scoped_release release; + self.Run(); +} + +void QuitWrapper(BApplication& self) { + // For an explanation, see QuitWrapper in Looper.cpp + py::gil_scoped_release release; + self.Quit(); +} + +void ArgvReceivedWrapper(BApplication& self, int32 argc, std::vector argv) { + self.ArgvReceived(argc, argv.data()); +} + class PyBApplication : public BApplication{ public: using BApplication::BApplication; void ReadyToRun() override { - py::gil_scoped_release release; - { - py::gil_scoped_acquire acquire; - PYBIND11_OVERLOAD(void, BApplication, ReadyToRun); - } + PYBIND11_OVERLOAD(void, BApplication, ReadyToRun); } bool QuitRequested() override { - py::gil_scoped_release release; - { - py::gil_scoped_acquire acquire; - PYBIND11_OVERLOAD( - bool, - BApplication, - QuitRequested, - ); + 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 { + // There is no need to release the GIL here like RunWrapper. Here, + // the GIL starts off unacquired, whereas in RunWrapper, the GIL + // starts off acquired. Here, only if pybind sees that there + // is a Python function overriding Run that needs to be run will + // it acquire the GIL. Otherwise, it stays unacquired. + 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 { + pybind11::gil_scoped_acquire gil; + pybind11::function override = pybind11::get_override(static_cast(this), "ArgvReceived"); + if (override) { + // It exists! Let's call it. + std::vector args; + for (int32 i = 0; i < argc; ++i) { + args.push_back(argv[i]); + } + + override(argc, args); + } else { + // Doesn't exist. Let's call the default ArgvReceived instead + BApplication::ArgvReceived(argc, argv); } } - - - -}; -PYBIND11_MODULE(Application,m) -{ -/* -m.attr("PortLink") = PortLink; + 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); + } +}; -m.attr("ServerMemoryAllocator") = ServerMemoryAllocator; +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BApplication); +PYBIND11_MODULE(Application,m) +{ +py::module_::import("Be.Messenger"); -m.attr("be_app_messenger") = be_app_messenger; -*/ -//m.attr("be_app") = be_app; -py::class_(m, "BApplication") +py::class_(m, "BApplication") .def(py::init(), "", py::arg("signature")) .def(py::init(), "", py::arg("signature"), py::arg("error")) .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BApplication::Instantiate, "", py::arg("data")) .def("Archive", &BApplication::Archive, "", py::arg("data"), py::arg("deep")=true) .def("InitCheck", &BApplication::InitCheck, "") -.def("Run", &BApplication::Run, "") -.def("Quit", &BApplication::Quit, "") +.def("Run", &RunWrapper, "") +.def("Quit", &QuitWrapper, "") .def("QuitRequested", &BApplication::QuitRequested, "") .def("Pulse", &BApplication::Pulse, "") .def("ReadyToRun", &BApplication::ReadyToRun, "") .def("MessageReceived", &BApplication::MessageReceived, "", py::arg("message")) -//.def("ArgvReceived", &BApplication::ArgvReceived, "", py::arg("argc"), py::arg("argv")) +.def("ArgvReceived", &ArgvReceivedWrapper, "", py::arg("argc"), py::arg("argv")) +//.def("ArgvReceivedWrapper", &PyBApplication::ArgvReceivedWrapper, "", py::arg("args")) // Usare il metodo wrapper qui .def("AppActivated", &BApplication::AppActivated, "", py::arg("active")) .def("RefsReceived", &BApplication::RefsReceived, "", py::arg("message")) .def("AboutRequested", &BApplication::AboutRequested, "") @@ -94,10 +152,9 @@ py::class_(m, "BApplication") .def("UnregisterLooper", &BApplication::UnregisterLooper, "", py::arg("looper")) .def("GetSupportedSuites", &BApplication::GetSupportedSuites, "", py::arg("data")) .def("Perform", &BApplication::Perform, "", py::arg("d"), py::arg("arg")) -//.def_readwrite("Private", &BApplication::Private, "") ; -m.attr("be_app")=be_app; -//extern BMessenger be_app_messenger; -//m.attr("be_app_messenger") = be_app_messenger; + +m.attr("be_app") = be_app; +m.attr("be_app_messenger") = be_app_messenger; } diff --git a/bindings/app/Clipboard.cpp b/bindings/app/Clipboard.cpp index 062e1f9..7092933 100644 --- a/bindings/app/Clipboard.cpp +++ b/bindings/app/Clipboard.cpp @@ -15,8 +15,6 @@ PYBIND11_MODULE(Clipboard,m) { m.attr("B_CLIPBOARD_CHANGED") = "CLCH"; -//m.attr("be_clipboard") = be_clipboard; - py::class_(m, "BClipboard") .def(py::init(), "", py::arg("name"), py::arg("transient")=false) .def("Name", &BClipboard::Name, "") @@ -35,5 +33,6 @@ py::class_(m, "BClipboard") .def("Data", &BClipboard::Data, "") ; +m.attr("be_clipboard") = be_clipboard; } diff --git a/bindings/app/Handler.cpp b/bindings/app/Handler.cpp index f4ecd57..e30dbf7 100644 --- a/bindings/app/Handler.cpp +++ b/bindings/app/Handler.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -13,13 +13,49 @@ namespace py = pybind11; using namespace BPrivate; + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BHandler); + +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; -//m.attr("ObserverList") = ObserverList; - -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 6a14ec7..29fb5a0 100644 --- a/bindings/app/Invoker.cpp +++ b/bindings/app/Invoker.cpp @@ -12,10 +12,38 @@ 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; + BLooper* looper; + + handler = self.Target(&looper); + + return py::make_tuple(handler, looper); +} 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")) @@ -25,7 +53,7 @@ py::class_(m, "BInvoker") .def("SetTarget", py::overload_cast(&BInvoker::SetTarget), "", py::arg("handler"), py::arg("looper")=NULL) .def("SetTarget", py::overload_cast(&BInvoker::SetTarget), "", py::arg("messenger")) .def("IsTargetLocal", &BInvoker::IsTargetLocal, "") -//.def("Target", &BInvoker::Target, "", py::arg("_looper")=NULL) +.def("Target", &TargetWrapper, "Returns a tuple containing the handler and looper the Invoker is pointing to.") .def("Messenger", &BInvoker::Messenger, "") .def("SetHandlerForReply", &BInvoker::SetHandlerForReply, "", py::arg("handler")) .def("HandlerForReply", &BInvoker::HandlerForReply, "") 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 95f85e7..475a85f 100644 --- a/bindings/app/Looper.cpp +++ b/bindings/app/Looper.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -14,15 +14,108 @@ namespace py = pybind11; using namespace BPrivate; -PYBIND11_MODULE(Looper,m) -{ -//m.attr("BDirectMessageTarget") = BDirectMessageTarget; +class PyBLooper : public BLooper{ + public: + using BLooper::BLooper; + ~PyBLooper() override { + try { + // Call function overriding the destructor, if any. We can't + // use PYBIND11_OVERLOAD since that attempts to return from the + // destructor. + py::gil_scoped_acquire acquire; + py::function override = py::get_override(this, "__del__"); + if (override) { + override(); + } + } catch (py::error_already_set &e) { + // Return Python exception back to Python. Throwing from a + // destructor would crash the program, but we just want Python + // to print an error message. + e.discard_as_unraisable(__func__); + } + } + 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 { + py::gil_scoped_acquire acquire; + + // Python should not delete the class after run is called + // FIXME: What if the Python overload never actually calls + // BLooper::Run? Then the looper isn't actually running and should + // still be deletable + do_not_delete = py::cast(this); + + PYBIND11_OVERLOAD(thread_id, BLooper, Run); + } + void Quit() override { + { + py::gil_scoped_acquire acquire; + + // Not sure if it's actually necessary to release the reference + // to ourselves, since we will delete ourselves anyway. + // FIXME: What if the Python overload never actually calls + // BLooper::Quit? + do_not_delete.release(); + } + + 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); + } + + private: + // holds a reference to our object in Python to prevent Python from + // deleting us when we're not ready + py::object do_not_delete; +}; -//m.attr("BLooperList") = BLooperList; +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 + // release the global interpreter lock since this thread will no longer be + // running Python code. -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")) + py::gil_scoped_release release; + self.BLooper::Quit(); + // Avoids calling PyBLooper::Quit + + // If the code reaches this point, the global interpreter lock is + // reacquired, otherwise, it isn't. Exactly the behaviour we want. +} + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BLooper); + +PYBIND11_MODULE(Looper,m) +{ +py::class_(m, "BLooper") +.def(py::init_alias(), "", py::arg("name")=NULL, py::arg("priority")=B_NORMAL_PRIORITY, py::arg("portCapacity")=B_LOOPER_PORT_DEFAULT_CAPACITY) +.def(py::init_alias(), "", py::arg("data")) .def_static("Instantiate", &BLooper::Instantiate, "", py::arg("data")) .def("Archive", &BLooper::Archive, "", py::arg("data"), py::arg("deep")=true) .def("PostMessage", py::overload_cast(&BLooper::PostMessage), "", py::arg("command")) @@ -50,7 +143,7 @@ py::class_(m, "BLooper") .def("SetPreferredHandler", &BLooper::SetPreferredHandler, "", py::arg("handler")) .def("Run", &BLooper::Run, "") .def("Loop", &BLooper::Loop, "") -.def("Quit", &BLooper::Quit, "") +.def("Quit", &QuitWrapper, "") .def("QuitRequested", &BLooper::QuitRequested, "") .def("Lock", &BLooper::Lock, "") .def("Unlock", &BLooper::Unlock, "") diff --git a/bindings/app/Message.cpp b/bindings/app/Message.cpp index 2479de5..3733025 100644 --- a/bindings/app/Message.cpp +++ b/bindings/app/Message.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -24,6 +25,36 @@ namespace py = pybind11; +status_t GetInfoWrapper(BMessage& self, type_code typeRequested, int32 index, + std::vector nameFound, type_code* typeFound, int32* countFound) { + return self.GetInfo(typeRequested, index, + nameFound.data(), typeFound, countFound); +} + +status_t GetCurrentSpecifierWrapper(BMessage& self, int32* index, + BMessage* specifier, int32* _what, std::string* property) { + const char* p; + status_t status = self.GetCurrentSpecifier(index, specifier, _what, &p); + *property = p; + return status; +} + +status_t FindStringWrapper(BMessage& self, const char* name, + std::string* string) { + const char* s; + status_t status = self.FindString(name, &s); + *string = s; + return status; +} + +status_t FindStringWrapper(BMessage& self, const char* name, + int32 index, std::string* string) { + const char* s; + status_t status = self.FindString(name, index, &s); + *string = s; + return status; +} + PYBIND11_MODULE(Message,m) { m.attr("B_NO_SPECIFIER") = 0; @@ -41,12 +72,10 @@ py::class_>(m, "BMessage") .def(py::init(), "", py::arg("what")) .def(py::init(), "", py::arg("other")) .def("operator=", &BMessage::operator=, "", py::arg("other")) -/* -.def("GetInfo", py::overload_cast(&BMessage::GetInfo), "", py::arg("typeRequested"), py::arg("index"), py::arg("nameFound"), py::arg("typeFound"), py::arg("countFound")=NULL) -.def("GetInfo", py::overload_cast(&BMessage::GetInfo), "", py::arg("name"), py::arg("typeFound"), py::arg("countFound")=NULL) -.def("GetInfo", py::overload_cast(&BMessage::GetInfo), "", py::arg("name"), py::arg("typeFound"), py::arg("fixedSize")) -.def("GetInfo", py::overload_cast(&BMessage::GetInfo), "", py::arg("name"), py::arg("typeFound"), py::arg("countFound"), py::arg("fixedSize")) -*/ +.def("GetInfo", &GetInfoWrapper, "", py::arg("typeRequested"), py::arg("index"), py::arg("nameFound"), py::arg("typeFound"), py::arg("countFound")=NULL) +.def("GetInfo", py::overload_cast(&BMessage::GetInfo, py::const_), "", py::arg("name"), py::arg("typeFound"), py::arg("countFound")=NULL) +.def("GetInfo", py::overload_cast(&BMessage::GetInfo, py::const_), "", py::arg("name"), py::arg("typeFound"), py::arg("fixedSize")) +.def("GetInfo", py::overload_cast(&BMessage::GetInfo, py::const_), "", py::arg("name"), py::arg("typeFound"), py::arg("countFound"), py::arg("fixedSize")) .def("CountNames", &BMessage::CountNames, "", py::arg("type")) .def("IsEmpty", &BMessage::IsEmpty, "") .def("IsSystem", &BMessage::IsSystem, "") @@ -61,18 +90,17 @@ py::class_>(m, "BMessage") .def("WasDropped", &BMessage::WasDropped, "") .def("DropPoint", &BMessage::DropPoint, "", py::arg("offset")=NULL) -// .def("SendReply", py::overload_cast(&BMessage::SendReply), "", py::arg("command"), py::arg("replyTo")=NULL) .def("SendReply", py::overload_cast(&BMessage::SendReply), "", py::arg("reply"), py::arg("replyTo")=NULL, py::arg("timeout")=B_INFINITE_TIMEOUT) .def("SendReply", py::overload_cast(&BMessage::SendReply), "", py::arg("reply"), py::arg("replyTo"), py::arg("timeout")=B_INFINITE_TIMEOUT) .def("SendReply", py::overload_cast(&BMessage::SendReply), "", py::arg("command"), py::arg("replyToReply")) .def("SendReply", py::overload_cast(&BMessage::SendReply), "", py::arg("reply"), py::arg("replyToReply"), py::arg("sendTimeout")=B_INFINITE_TIMEOUT, py::arg("replyTimeout")=B_INFINITE_TIMEOUT) -// + .def("FlattenedSize", &BMessage::FlattenedSize, "") -// + .def("Flatten", py::overload_cast(&BMessage::Flatten, py::const_), "", py::arg("buffer"), py::arg("size")) .def("Flatten", py::overload_cast(&BMessage::Flatten, py::const_), "", py::arg("stream"), py::arg("size")=NULL) -// + .def("Unflatten", py::overload_cast(&BMessage::Unflatten), "", py::arg("flatBuffer")) .def("Unflatten", py::overload_cast(&BMessage::Unflatten), "", py::arg("stream")) @@ -83,7 +111,7 @@ py::class_>(m, "BMessage") .def("AddSpecifier", py::overload_cast(&BMessage::AddSpecifier), "", py::arg("specifier")) .def("SetCurrentSpecifier", &BMessage::SetCurrentSpecifier, "", py::arg("index")) -//.def("GetCurrentSpecifier", &BMessage::GetCurrentSpecifier, "", py::arg("index"), py::arg("specifier")=NULL, py::arg("what")=NULL, py::arg("property")=NULL) +.def("GetCurrentSpecifier", &GetCurrentSpecifierWrapper, "", py::arg("index"), py::arg("specifier")=NULL, py::arg("what")=NULL, py::arg("property")=NULL) .def("HasSpecifiers", &BMessage::HasSpecifiers, "") .def("PopSpecifier", &BMessage::PopSpecifier, "") .def("AddAlignment", &BMessage::AddAlignment, "", py::arg("name"), py::arg("alignment")) @@ -116,13 +144,17 @@ py::class_>(m, "BMessage") .def("AddMessage", &BMessage::AddMessage, "", py::arg("name"), py::arg("message")) .def("AddFlat", py::overload_cast(&BMessage::AddFlat), "", py::arg("name"), py::arg("object"), py::arg("count")=1) .def("AddFlat", py::overload_cast(&BMessage::AddFlat), "", py::arg("name"), py::arg("object"), py::arg("count")=1) -.def("AddData", &BMessage::AddData, "", py::arg("name"), py::arg("type"), py::arg("data"), py::arg("numBytes"), py::arg("isFixedSize")=true, py::arg("count")=1) +//.def("AddData", &BMessage::AddData, "", py::arg("name"), py::arg("type"), py::arg("data"), py::arg("numBytes"), py::arg("isFixedSize")=true, py::arg("count")=1) +.def("AddData", [](BMessage& self, const char* name, type_code type, py::buffer data, ssize_t numBytes, bool isFixedSize, int32 count) { //const void* data + py::buffer_info info = data.request(); + const void* buffer = info.ptr; + return self.AddData(name,type,buffer,numBytes,isFixedSize,count); +}, "", py::arg("name"), py::arg("type"), py::arg("data"), py::arg("numBytes"), py::arg("isFixedSize")=true, py::arg("count")=1) .def("Append", &BMessage::Append, "", py::arg("message")) .def("RemoveData", &BMessage::RemoveData, "", py::arg("name"), py::arg("index")=0) .def("RemoveName", &BMessage::RemoveName, "", py::arg("name")) .def("MakeEmpty", &BMessage::MakeEmpty, "") -// .def("FindAlignment", py::overload_cast(&BMessage::FindAlignment, py::const_), "", py::arg("name"), py::arg("alignment")) .def("FindAlignment", py::overload_cast(&BMessage::FindAlignment, py::const_), "", py::arg("name"), py::arg("index"), py::arg("alignment")) .def("FindRect", py::overload_cast(&BMessage::FindRect, py::const_), "", py::arg("name"), py::arg("rect")) @@ -131,30 +163,28 @@ py::class_>(m, "BMessage") .def("FindPoint", py::overload_cast(&BMessage::FindPoint, py::const_), "", py::arg("name"), py::arg("index"), py::arg("point")) .def("FindSize", py::overload_cast(&BMessage::FindSize, py::const_), "", py::arg("name"), py::arg("size")) .def("FindSize", py::overload_cast(&BMessage::FindSize, py::const_), "", py::arg("name"), py::arg("index"), py::arg("size")) -//.def("FindString", py::overload_cast(&BMessage::FindString), "", py::arg("name"), py::arg("string")) -//.def("FindString", py::overload_cast(&BMessage::FindString), "", py::arg("name"), py::arg("index"), py::arg("string")) -//.def("FindString", py::overload_cast(&BMessage::FindString), "", py::arg("name"), py::arg("string")) -//.def("FindString", py::overload_cast(&BMessage::FindString), "", py::arg("name"), py::arg("index"), py::arg("string")) -// +.def("FindString", py::overload_cast(&FindStringWrapper), "", py::arg("name"), py::arg("string")) +.def("FindString", py::overload_cast(&FindStringWrapper), "", py::arg("name"), py::arg("index"), py::arg("string")) +.def("FindString", py::overload_cast(&BMessage::FindString, py::const_), "", py::arg("name"), py::arg("string")) +.def("FindString", py::overload_cast(&BMessage::FindString, py::const_), "", py::arg("name"), py::arg("index"), py::arg("string")) + .def("FindStrings", &BMessage::FindStrings, "", py::arg("name"), py::arg("list")) -/* -.def("FindInt8", py::overload_cast(&BMessage::FindInt8, py::const_), "", py::arg("name"), py::arg("value")) -.def("FindInt8", py::overload_cast(&BMessage::FindInt8, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) -.def("FindUInt8", py::overload_cast(&BMessage::FindUInt8, py::const_), "", py::arg("name"), py::arg("value")) -.def("FindUInt8", py::overload_cast(&BMessage::FindUInt8, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) -.def("FindInt16", py::overload_cast(&BMessage::FindInt16, py::const_), "", py::arg("name"), py::arg("value")) -.def("FindInt16", py::overload_cast(&BMessage::FindInt16, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) -.def("FindUInt16", py::overload_cast(&BMessage::FindUInt16, py::const_), "", py::arg("name"), py::arg("value")) -.def("FindUInt16", py::overload_cast(&BMessage::FindUInt16, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) -.def("FindInt32", py::overload_cast(&BMessage::FindInt32, py::const_), "", py::arg("name"), py::arg("value")) -.def("FindInt32", py::overload_cast(&BMessage::FindInt32, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) -.def("FindUInt32", py::overload_cast(&BMessage::FindUInt32, py::const_), "", py::arg("name"), py::arg("value")) -.def("FindUInt32", py::overload_cast(&BMessage::FindUInt32, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) -.def("FindInt64", py::overload_cast(&BMessage::FindInt64, py::const_), "", py::arg("name"), py::arg("value")) -.def("FindInt64", py::overload_cast(&BMessage::FindInt64, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) -.def("FindUInt64", py::overload_cast(&BMessage::FindUInt64), "", py::arg("name"), py::arg("value")) -.def("FindUInt64", py::overload_cast(&BMessage::FindUInt64), "", py::arg("name"), py::arg("index"), py::arg("value")) -*/ +.def("FindInt8", py::overload_cast(&BMessage::FindInt8, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindInt8", py::overload_cast(&BMessage::FindInt8, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) +.def("FindUInt8", py::overload_cast(&BMessage::FindUInt8, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindUInt8", py::overload_cast(&BMessage::FindUInt8, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) +.def("FindInt16", py::overload_cast(&BMessage::FindInt16, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindInt16", py::overload_cast(&BMessage::FindInt16, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) +.def("FindUInt16", py::overload_cast(&BMessage::FindUInt16, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindUInt16", py::overload_cast(&BMessage::FindUInt16, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) +.def("FindInt32", py::overload_cast(&BMessage::FindInt32, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindInt32", py::overload_cast(&BMessage::FindInt32, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) +.def("FindUInt32", py::overload_cast(&BMessage::FindUInt32, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindUInt32", py::overload_cast(&BMessage::FindUInt32, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) +.def("FindInt64", py::overload_cast(&BMessage::FindInt64, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindInt64", py::overload_cast(&BMessage::FindInt64, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) +.def("FindUInt64", py::overload_cast(&BMessage::FindUInt64, py::const_), "", py::arg("name"), py::arg("value")) +.def("FindUInt64", py::overload_cast(&BMessage::FindUInt64, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) .def("FindBool", py::overload_cast(&BMessage::FindBool, py::const_), "", py::arg("name"), py::arg("value")) .def("FindBool", py::overload_cast(&BMessage::FindBool, py::const_), "", py::arg("name"), py::arg("index"), py::arg("value")) @@ -181,8 +211,35 @@ py::class_>(m, "BMessage") .def("FindFlat", py::overload_cast(&BMessage::FindFlat, py::const_), "", py::arg("name"), py::arg("object")) .def("FindFlat", py::overload_cast(&BMessage::FindFlat, py::const_), "", py::arg("name"), py::arg("index"), py::arg("object")) //.def("FindData", py::overload_cast(&BMessage::FindData, py::const_), "", py::arg("name"), py::arg("type"), py::arg("data"), py::arg("numBytes")) +.def("FindData", [](BMessage &self, const char *name, type_code type) -> py::tuple { + const void *vdata = nullptr; + ssize_t numBytes; + status_t ret = self.FindData(name, type, &vdata, &numBytes); + + if (ret == B_OK && vdata != nullptr) { + // Converte i dati in un oggetto py::bytes + const unsigned char *dataPtr = static_cast(vdata); + py::bytes result(reinterpret_cast(dataPtr), numBytes); + return py::make_tuple(ret, result); + } + + return py::make_tuple(ret, py::none()); +}, "", py::arg("name"), py::arg("type")) //.def("FindData", py::overload_cast(&BMessage::FindData, py::const_), "", py::arg("name"), py::arg("type"), py::arg("index"), py::arg("data"), py::arg("numBytes")) - +.def("FindData", [](BMessage &self, const char *name, type_code type, int32 index) -> py::tuple { + const void *vdata = nullptr; + ssize_t numBytes; + status_t ret = self.FindData(name, type, index, &vdata, &numBytes); + + if (ret == B_OK && vdata != nullptr) { + // Converte i dati in un oggetto py::bytes + const unsigned char *dataPtr = static_cast(vdata); + py::bytes result(reinterpret_cast(dataPtr), numBytes); + return py::make_tuple(ret, result); + } + + return py::make_tuple(ret, py::none()); +}, "", py::arg("name"), py::arg("type"), py::arg("index")) .def("ReplaceAlignment", py::overload_cast(&BMessage::ReplaceAlignment), "", py::arg("name"), py::arg("alignment")) .def("ReplaceAlignment", py::overload_cast(&BMessage::ReplaceAlignment), "", py::arg("name"), py::arg("index"), py::arg("alignment")) .def("ReplaceRect", py::overload_cast(&BMessage::ReplaceRect), "", py::arg("name"), py::arg("rect")) @@ -269,7 +326,6 @@ py::class_>(m, "BMessage") .def("HasNodeRef", &BMessage::HasNodeRef, "", py::arg("name"), py::arg("n")=0) .def("HasMessage", &BMessage::HasMessage, "", py::arg("name"), py::arg("n")=0) -// .def("HasFlat", py::overload_cast(&BMessage::HasFlat, py::const_), "", py::arg("name"), py::arg("object")) .def("HasFlat", py::overload_cast(&BMessage::HasFlat, py::const_), "", py::arg("name"), py::arg("n"), py::arg("object")) .def("HasData", &BMessage::HasData, "", py::arg("name"), py::arg(""), py::arg("n")=0) @@ -313,15 +369,22 @@ py::class_>(m, "BMessage") .def("GetPointer", py::overload_cast(&BMessage::GetPointer, py::const_), "", py::arg("name"), py::arg("defaultValue")=NULL) .def("GetString", py::overload_cast(&BMessage::GetString, py::const_), "", py::arg("name"), py::arg("defaultValue")=NULL) .def("GetString", py::overload_cast(&BMessage::GetString, py::const_), "", py::arg("name"), py::arg("index"), py::arg("defaultValue")) -//.def("GetAlignment", py::overload_cast(&BMessage::GetAlignment, py::const_), "", py::arg("name"), py::arg("index"), py::arg("defaultValue")) -//.def("GetAlignment", py::overload_cast(&BMessage::GetAlignment, py::const_), "", py::arg("name"), py::arg("defaultValue")) + +// These two don't seem to be available on Haiku R1B4. Maybe they are, but just +// not in libbe.so? That would be strange... But it's also strange that the +// header files that come with R1B4 mention them. +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +.def("GetAlignment", py::overload_cast(&BMessage::GetAlignment, py::const_), "", py::arg("name"), py::arg("index"), py::arg("defaultValue")) +.def("GetAlignment", py::overload_cast(&BMessage::GetAlignment, py::const_), "", py::arg("name"), py::arg("defaultValue")) +#endif + .def("GetRect", py::overload_cast(&BMessage::GetRect, py::const_), "", py::arg("name"), py::arg("index"), py::arg("defaultValue")) .def("GetRect", py::overload_cast(&BMessage::GetRect, py::const_), "", py::arg("name"), py::arg("defaultValue")) .def("GetPoint", py::overload_cast(&BMessage::GetPoint, py::const_), "", py::arg("name"), py::arg("index"), py::arg("defaultValue")) .def("GetPoint", py::overload_cast(&BMessage::GetPoint, py::const_), "", py::arg("name"), py::arg("defaultValue")) .def("GetSize", py::overload_cast(&BMessage::GetSize, py::const_), "", py::arg("name"), py::arg("index"), py::arg("defaultValue")) .def("GetSize", py::overload_cast(&BMessage::GetSize, py::const_), "", py::arg("name"), py::arg("defaultValue")) -// + .def("SetBool", &BMessage::SetBool, "", py::arg("name"), py::arg("value")) .def("SetInt8", &BMessage::SetInt8, "", py::arg("name"), py::arg("value")) .def("SetUInt8", &BMessage::SetUInt8, "", py::arg("name"), py::arg("value")) @@ -338,16 +401,15 @@ py::class_>(m, "BMessage") .def("SetString", py::overload_cast(&BMessage::SetString), "", py::arg("name"), py::arg("string")) .def("SetFloat", &BMessage::SetFloat, "", py::arg("name"), py::arg("value")) .def("SetDouble", &BMessage::SetDouble, "", py::arg("name"), py::arg("value")) -//.def("SetAlignment", &BMessage::SetAlignment, "", py::arg("name"), py::arg("value")) +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) // see comment for GetAlignment +.def("SetAlignment", &BMessage::SetAlignment, "", py::arg("name"), py::arg("value")) +#endif .def("SetPoint", &BMessage::SetPoint, "", py::arg("name"), py::arg("value")) .def("SetRect", &BMessage::SetRect, "", py::arg("name"), py::arg("value")) .def("SetSize", &BMessage::SetSize, "", py::arg("name"), py::arg("value")) .def("SetData", &BMessage::SetData, "", py::arg("name"), py::arg("type"), py::arg("data"), py::arg("numBytes"), py::arg("fixedSize")=true, py::arg("count")=1) .def_readwrite("what", &BMessage::what, "") -//.def_readwrite("Private", &BMessage::Private, "") -//.def_readonly("message_header", &BMessage::message_header, "") -//.def_readonly("field_header", &BMessage::field_header, "") ; diff --git a/bindings/app/MessageFilter.cpp b/bindings/app/MessageFilter.cpp index 6d605fd..8e06809 100644 --- a/bindings/app/MessageFilter.cpp +++ b/bindings/app/MessageFilter.cpp @@ -11,6 +11,11 @@ namespace py = pybind11; +filter_result FilterWrapper(BMessageFilter& self, + BMessage* message, std::vector _target) { + return self.Filter(message, _target.data()); +} + PYBIND11_MODULE(MessageFilter,m) { py::enum_(m, "filter_result", "") @@ -37,7 +42,7 @@ py::class_(m, "BMessageFilter") .def(py::init(), "", py::arg("filter")) .def(py::init(), "", py::arg("filter")) .def("operator=", &BMessageFilter::operator=, "", py::arg("from")) -//.def("Filter", &BMessageFilter::Filter, "", py::arg("message"), py::arg("_target")) +.def("Filter", &FilterWrapper, "", py::arg("message"), py::arg("_target")) .def("MessageDelivery", &BMessageFilter::MessageDelivery, "") .def("MessageSource", &BMessageFilter::MessageSource, "") .def("Command", &BMessageFilter::Command, "") diff --git a/bindings/app/MessageQueue.cpp b/bindings/app/MessageQueue.cpp index 44ebaea..e0709c7 100644 --- a/bindings/app/MessageQueue.cpp +++ b/bindings/app/MessageQueue.cpp @@ -22,7 +22,7 @@ py::class_(m, "BMessageQueue") .def("FindMessage", py::overload_cast(&BMessageQueue::FindMessage, py::const_), "", py::arg("what"), py::arg("index")=0) .def("Lock", &BMessageQueue::Lock, "") .def("Unlock", &BMessageQueue::Unlock, "") -//.def("IsLocked", &BMessageQueue::IsLocked, "") +.def("IsLocked", static_cast(&BMessageQueue::IsLocked), "") .def("NextMessage", &BMessageQueue::NextMessage, "") .def("IsNextMessage", &BMessageQueue::IsNextMessage, "", py::arg("message")) ; diff --git a/bindings/app/MessageRunner.cpp b/bindings/app/MessageRunner.cpp index 61b00cd..a37ee57 100644 --- a/bindings/app/MessageRunner.cpp +++ b/bindings/app/MessageRunner.cpp @@ -20,8 +20,8 @@ py::class_(m, "BMessageRunner") .def("SetInterval", &BMessageRunner::SetInterval, "", py::arg("interval")) .def("SetCount", &BMessageRunner::SetCount, "", py::arg("count")) .def("GetInfo", &BMessageRunner::GetInfo, "", py::arg("interval"), py::arg("count")) -.def_static("StartSending", py::overload_cast(&BMessageRunner::StartSending), "", py::arg("target"), py::arg("message"), py::arg("interval"), py::arg("count")) -.def_static("StartSending", py::overload_cast(&BMessageRunner::StartSending), "", py::arg("target"), py::arg("message"), py::arg("interval"), py::arg("count"), py::arg("replyTo")) +.def_static("StartSending", py::overload_cast(&BMessageRunner::StartSending), "", py::arg("target"), py::arg("message"), py::arg("interval"), py::arg("count")) +.def_static("StartSending", py::overload_cast(&BMessageRunner::StartSending), "", py::arg("target"), py::arg("message"), py::arg("interval"), py::arg("count"), py::arg("replyTo")) ; diff --git a/bindings/app/Messenger.cpp b/bindings/app/Messenger.cpp index 7330c4a..d3379ac 100644 --- a/bindings/app/Messenger.cpp +++ b/bindings/app/Messenger.cpp @@ -13,6 +13,10 @@ namespace py = pybind11; +BHandler* TargetWrapper(BMessenger& self, std::vector looper) { + return self.Target(looper.data()); +} + PYBIND11_MODULE(Messenger,m) { py::class_(m, "BMessenger") @@ -21,13 +25,13 @@ py::class_(m, "BMessenger") .def(py::init(), "", py::arg("handler"), py::arg("looper")=NULL, py::arg("result")=NULL) .def(py::init(), "", py::arg("other")) .def("IsTargetLocal", &BMessenger::IsTargetLocal, "") -//.def("Target", &BMessenger::Target, "", py::arg("looper")) +.def("Target", &TargetWrapper, "", py::arg("looper")) .def("LockTarget", &BMessenger::LockTarget, "") .def("LockTargetWithTimeout", &BMessenger::LockTargetWithTimeout, "", py::arg("timeout")) -.def("SendMessage", py::overload_cast(&BMessenger::SendMessage, py::const_), "", py::arg("command"), py::arg("replyTo")=NULL) +.def("SendMessage", py::overload_cast(&BMessenger::SendMessage, py::const_), "", py::arg("command"), py::arg("replyTo")=NULL) .def("SendMessage", py::overload_cast(&BMessenger::SendMessage, py::const_), "", py::arg("message"), py::arg("replyTo")=NULL, py::arg("timeout")=B_INFINITE_TIMEOUT) .def("SendMessage", py::overload_cast(&BMessenger::SendMessage, py::const_), "", py::arg("message"), py::arg("replyTo"), py::arg("timeout")=B_INFINITE_TIMEOUT) -.def("SendMessage", py::overload_cast(&BMessenger::SendMessage, py::const_), "", py::arg("command"), py::arg("reply")) +.def("SendMessage", py::overload_cast(&BMessenger::SendMessage, py::const_), "", py::arg("command"), py::arg("reply")) .def("SendMessage", py::overload_cast(&BMessenger::SendMessage, py::const_), "", py::arg("message"), py::arg("reply"), py::arg("deliveryTimeout")=B_INFINITE_TIMEOUT, py::arg("replyTimeout")=B_INFINITE_TIMEOUT) .def("SetTo", py::overload_cast(&BMessenger::SetTo), "", py::arg("signature"), py::arg("team")=- 1) .def("SetTo", py::overload_cast(&BMessenger::SetTo), "", py::arg("handler"), py::arg("looper")=NULL) @@ -36,10 +40,9 @@ py::class_(m, "BMessenger") .def("IsValid", &BMessenger::IsValid, "") .def("Team", &BMessenger::Team, "") .def("HashValue", &BMessenger::HashValue, "") -//.def_readwrite("Private", &BMessenger::Private, "") ; -//m.def("__lt__", &operator<, "", py::arg("a"), py::arg("b")); +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); m.def("__ne__", &operator!=, "", py::arg("a"), py::arg("b")); diff --git a/bindings/app/PropertyInfo.cpp b/bindings/app/PropertyInfo.cpp index 91f69a1..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) { @@ -24,10 +49,10 @@ py::class_(m, "compound_type") .def_readonly("pairs", &compound_type::pairs, "") ; -//py::class_(m, "field_pair") -//.def_readonly("name", &field_pair::name, "") -//.def_readonly("type", &field_pair::type, "") -//; +py::class_(m, "field_pair") +.def_readonly("name", &compound_type::field_pair::name, "") +.def_readonly("type", &compound_type::field_pair::type, "") +; py::class_(m, "property_info") .def_readwrite("name", &property_info::name, "") @@ -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 7f4d8b0..4f114fb 100644 --- a/bindings/app/Roster.cpp +++ b/bindings/app/Roster.cpp @@ -2,7 +2,6 @@ #include #include #include - #include #include #include @@ -11,12 +10,31 @@ namespace py = pybind11; +status_t LaunchWrapper(BRoster& self, const char* mimeType, int argc, + const std::vector& args, team_id* appTeam) { + return self.Launch(mimeType, argc, args.data(), appTeam); +} + +status_t LaunchWrapper(BRoster& self, const entry_ref* ref, int argc, + const std::vector& args, team_id* appTeam) { + return self.Launch(ref, argc, args.data(), appTeam); +} + +void GetRecentDocumentsWrapper(BRoster& self, BMessage* refList, int32 maxCount, + std::vector& fileTypes, int32 fileTypesCount, + const char* signature) { + self.GetRecentDocuments(refList, maxCount, + fileTypes.data(), fileTypesCount, signature); +} PYBIND11_MODULE(Roster,m) { -m.attr("B_REQUEST_LAUNCHED") = 1; -m.attr("B_REQUEST_QUIT") = 2; -m.attr("B_REQUEST_ACTIVATED") = 4; + +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(); m.attr("B_SOME_APP_LAUNCHED") = py::int_('BRAS'); m.attr("B_SOME_APP_QUIT") = py::int_('BRAQ'); @@ -32,6 +50,7 @@ py::class_(m, "app_info") .def_readonly("signature", &app_info::signature) ; + py::class_(m, "BRoster") .def(py::init(), "") .def("IsRunning", py::overload_cast(&BRoster::IsRunning, py::const_), py::arg("signature")) @@ -53,17 +72,16 @@ py::class_(m, "BRoster") .def("ActivateApp", &BRoster::ActivateApp, "", py::arg("team")) .def("Launch", py::overload_cast(&BRoster::Launch, py::const_), "", py::arg("mimeType"), py::arg("initialMessage")=NULL, py::arg("_appTeam")=NULL) .def("Launch", py::overload_cast(&BRoster::Launch, py::const_), "", py::arg("mimeType"), py::arg("messageList"), py::arg("_appTeam")=NULL) -//.def("Launch", py::overload_cast(&BRoster::Launch, py::const_), "", py::arg("mimeType"), py::arg("argc"), py::arg("args"), py::arg("_appTeam")=NULL) +.def("Launch", static_cast&, team_id *)>(&LaunchWrapper), "", py::arg("mimeType"), py::arg("argc"), py::arg("args"), py::arg("_appTeam")=NULL) .def("Launch", py::overload_cast(&BRoster::Launch, py::const_), "", py::arg("ref"), py::arg("initialMessage")=NULL, py::arg("_appTeam")=NULL) .def("Launch", py::overload_cast(&BRoster::Launch, py::const_), "", py::arg("ref"), py::arg("messageList"), py::arg("_appTeam")=NULL) -//.def("Launch", py::overload_cast(&BRoster::Launch, py::const_), "", py::arg("ref"), py::arg("argc"), py::arg("args"), py::arg("_appTeam")=NULL) +.def("Launch", static_cast&, team_id *)>(&LaunchWrapper), "", py::arg("ref"), py::arg("argc"), py::arg("args"), py::arg("_appTeam")=NULL) .def("GetRecentDocuments", py::overload_cast(&BRoster::GetRecentDocuments, py::const_), "", py::arg("refList"), py::arg("maxCount"), py::arg("fileType")=NULL, py::arg("signature")=NULL) -//FIXME: .def("GetRecentDocuments", py::overload_cast(&BRoster::GetRecentDocuments, py::const_), "", py::arg("refList"), py::arg("maxCount"), py::arg("fileTypes"), py::arg("fileTypesCount"), py::arg("signature")=NULL) +.def("GetRecentDocuments", &GetRecentDocumentsWrapper, "", py::arg("refList"), py::arg("maxCount"), py::arg("fileTypes"), py::arg("fileTypesCount"), py::arg("signature")=NULL) .def("GetRecentFolders", &BRoster::GetRecentFolders, "", py::arg("refList"), py::arg("maxCount"), py::arg("signature")=NULL) .def("GetRecentApps", &BRoster::GetRecentApps, "", py::arg("refList"), py::arg("maxCount")) .def("AddToRecentDocuments", &BRoster::AddToRecentDocuments, "", py::arg("document"), py::arg("signature")=NULL) .def("AddToRecentFolders", &BRoster::AddToRecentFolders, "", py::arg("folder"), py::arg("signature")=NULL) -//.def_readonly("Private", &BRoster::Private) ; m.attr("be_roster") = be_roster; diff --git a/bindings/device/A2D.cpp b/bindings/device/A2D.cpp new file mode 100644 index 0000000..2539f96 --- /dev/null +++ b/bindings/device/A2D.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(A2D,m) +{ +py::class_(m, "BA2D") +.def(py::init(), "") +.def("Open", &BA2D::Open, "", py::arg("portName")) +.def("Close", &BA2D::Close, "") +.def("IsOpen", &BA2D::IsOpen, "") +.def("Read", &BA2D::Read, "", py::arg("buf")) +; + + +} diff --git a/bindings/device/D2A.cpp b/bindings/device/D2A.cpp new file mode 100644 index 0000000..b75a18d --- /dev/null +++ b/bindings/device/D2A.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(D2A,m) +{ +py::class_(m, "BD2A") +.def(py::init(), "") +.def("Open", &BD2A::Open, "", py::arg("portName")) +.def("Close", &BD2A::Close, "") +.def("IsOpen", &BD2A::IsOpen, "") +.def("Read", &BD2A::Read, "", py::arg("buf")) +.def("Write", &BD2A::Write, "", py::arg("value")) +; + + +} diff --git a/bindings/device/DigitalPort.cpp b/bindings/device/DigitalPort.cpp new file mode 100644 index 0000000..df3e383 --- /dev/null +++ b/bindings/device/DigitalPort.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(DigitalPort,m) +{ +py::class_(m, "BDigitalPort") +.def(py::init(), "") +.def("Open", &BDigitalPort::Open, "", py::arg("portName")) +.def("Close", &BDigitalPort::Close, "") +.def("IsOpen", &BDigitalPort::IsOpen, "") +.def("Read", &BDigitalPort::Read, "", py::arg("buf")) +.def("Write", &BDigitalPort::Write, "", py::arg("value")) +.def("SetAsOutput", &BDigitalPort::SetAsOutput, "") +.def("IsOutput", &BDigitalPort::IsOutput, "") +.def("SetAsInput", &BDigitalPort::SetAsInput, "") +.def("IsInput", &BDigitalPort::IsInput, "") +; + + +} diff --git a/bindings/device/Joystick.cpp b/bindings/device/Joystick.cpp new file mode 100644 index 0000000..5bb23f5 --- /dev/null +++ b/bindings/device/Joystick.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Joystick,m) +{ +py::class_(m, "BJoystick") +.def(py::init(), "") +.def("Open", py::overload_cast(&BJoystick::Open), "", py::arg("portName")) +.def("Open", py::overload_cast(&BJoystick::Open), "", py::arg("portName"), py::arg("enhanced")) +.def("Close", &BJoystick::Close, "") +.def("Update", &BJoystick::Update, "") +.def("SetMaxLatency", &BJoystick::SetMaxLatency, "", py::arg("maxLatency")) +.def("CountDevices", &BJoystick::CountDevices, "") +.def("GetDeviceName", &BJoystick::GetDeviceName, "", py::arg("index"), py::arg("name"), py::arg("bufSize")=B_OS_NAME_LENGTH) +.def("RescanDevices", &BJoystick::RescanDevices, "") +.def("EnterEnhancedMode", &BJoystick::EnterEnhancedMode, "", py::arg("ref")=NULL) +.def("CountSticks", &BJoystick::CountSticks, "") +.def("CountAxes", &BJoystick::CountAxes, "") +.def("GetAxisValues", &BJoystick::GetAxisValues, "", py::arg("outValues"), py::arg("forStick")=0) +.def("GetAxisNameAt", &BJoystick::GetAxisNameAt, "", py::arg("index"), py::arg("outName")) +.def("CountHats", &BJoystick::CountHats, "") +.def("GetHatValues", &BJoystick::GetHatValues, "", py::arg("outHats"), py::arg("forStick")=0) +.def("GetHatNameAt", &BJoystick::GetHatNameAt, "", py::arg("index"), py::arg("outName")) +.def("CountButtons", &BJoystick::CountButtons, "") +.def("ButtonValues", &BJoystick::ButtonValues, "", py::arg("forStick")=0) +.def("GetButtonValues", &BJoystick::GetButtonValues, "", py::arg("outButtons"), py::arg("forStick")=0) +.def("GetButtonNameAt", &BJoystick::GetButtonNameAt, "", py::arg("index"), py::arg("outName")) +.def("GetControllerModule", &BJoystick::GetControllerModule, "", py::arg("outName")) +.def("GetControllerName", &BJoystick::GetControllerName, "", py::arg("outName")) +.def("IsCalibrationEnabled", &BJoystick::IsCalibrationEnabled, "") +.def("EnableCalibration", &BJoystick::EnableCalibration, "", py::arg("calibrates")=true) +.def_readwrite("timestamp", &BJoystick::timestamp, "") +.def_readwrite("horizontal", &BJoystick::horizontal, "") +.def_readwrite("vertical", &BJoystick::vertical, "") +.def_readwrite("button1", &BJoystick::button1, "") +.def_readwrite("button2", &BJoystick::button2, "") +; + + +} diff --git a/bindings/device/SerialPort.cpp b/bindings/device/SerialPort.cpp new file mode 100644 index 0000000..74ebe3e --- /dev/null +++ b/bindings/device/SerialPort.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(SerialPort,m) +{ +py::enum_(m, "data_rate", "") +.value("B_0_BPS", data_rate::B_0_BPS, "") +.value("B_50_BPS", data_rate::B_50_BPS, "") +.value("B_75_BPS", data_rate::B_75_BPS, "") +.value("B_110_BPS", data_rate::B_110_BPS, "") +.value("B_134_BPS", data_rate::B_134_BPS, "") +.value("B_150_BPS", data_rate::B_150_BPS, "") +.value("B_200_BPS", data_rate::B_200_BPS, "") +.value("B_300_BPS", data_rate::B_300_BPS, "") +.value("B_600_BPS", data_rate::B_600_BPS, "") +.value("B_1200_BPS", data_rate::B_1200_BPS, "") +.value("B_1800_BPS", data_rate::B_1800_BPS, "") +.value("B_2400_BPS", data_rate::B_2400_BPS, "") +.value("B_4800_BPS", data_rate::B_4800_BPS, "") +.value("B_9600_BPS", data_rate::B_9600_BPS, "") +.value("B_19200_BPS", data_rate::B_19200_BPS, "") +.value("B_38400_BPS", data_rate::B_38400_BPS, "") +.value("B_57600_BPS", data_rate::B_57600_BPS, "") +.value("B_115200_BPS", data_rate::B_115200_BPS, "") +.value("B_230400_BPS", data_rate::B_230400_BPS, "") +.value("B_31250_BPS", data_rate::B_31250_BPS, "") +.export_values(); + +py::enum_(m, "data_bits", "") +.value("B_DATA_BITS_7", data_bits::B_DATA_BITS_7, "") +.value("B_DATA_BITS_8", data_bits::B_DATA_BITS_8, "") +.export_values(); + +py::enum_(m, "stop_bits", "") +.value("B_STOP_BITS_1", stop_bits::B_STOP_BITS_1, "") +.value("B_STOP_BITS_2", stop_bits::B_STOP_BITS_2, "") +.export_values(); + +py::enum_(m, "parity_mode", "") +.value("B_NO_PARITY", parity_mode::B_NO_PARITY, "") +.value("B_ODD_PARITY", parity_mode::B_ODD_PARITY, "") +.value("B_EVEN_PARITY", parity_mode::B_EVEN_PARITY, "") +.export_values(); + +m.attr("B_NOFLOW_CONTROL") = py::cast(B_NOFLOW_CONTROL); +m.attr("B_HARDWARE_CONTROL") = py::cast(B_HARDWARE_CONTROL); +m.attr("B_SOFTWARE_CONTROL") = py::cast(B_SOFTWARE_CONTROL); + +py::class_(m, "BSerialPort") +.def(py::init(), "") +.def("Open", &BSerialPort::Open, "", py::arg("portName")) +.def("Close", &BSerialPort::Close, "") +//.def("Read", &BSerialPort::Read, "", py::arg("buf"), py::arg("count")) +.def("Read", [](BSerialPort& self, size_t count) { + std::vector buffer(count); + ssize_t result = self.Read(buffer.data(), count); + if (result > 0) { + return py::bytes(reinterpret_cast(buffer.data()), result); + } + return py::bytes(); + }, "", py::arg("count")) +//.def("Write", &BSerialPort::Write, "", py::arg("buf"), py::arg("count")) +.def("Write", [](BSerialPort& self, py::buffer data){ + /*std::string buffer = data; + const void* buf =buffer.data(); + size_t count = buffer.size();*/ + py::buffer_info info = data.request(); + size_t count = info.size; + const void* buffer = info.ptr; + return self.Write(buffer,count); +},"",py::arg("data")) +.def("SetBlocking", &BSerialPort::SetBlocking, "", py::arg("blocking")) +.def("SetTimeout", &BSerialPort::SetTimeout, "", py::arg("microSeconds")) +.def("SetDataRate", &BSerialPort::SetDataRate, "", py::arg("bitsPerSecond")) +.def("DataRate", &BSerialPort::DataRate, "") +.def("SetDataBits", &BSerialPort::SetDataBits, "", py::arg("numBits")) +.def("DataBits", &BSerialPort::DataBits, "") +.def("SetStopBits", &BSerialPort::SetStopBits, "", py::arg("numBits")) +.def("StopBits", &BSerialPort::StopBits, "") +.def("SetParityMode", &BSerialPort::SetParityMode, "", py::arg("which")) +.def("ParityMode", &BSerialPort::ParityMode, "") +.def("ClearInput", &BSerialPort::ClearInput, "") +.def("ClearOutput", &BSerialPort::ClearOutput, "") +.def("SetFlowControl", &BSerialPort::SetFlowControl, "", py::arg("method")) +.def("FlowControl", &BSerialPort::FlowControl, "") +.def("SetDTR", &BSerialPort::SetDTR, "", py::arg("asserted")) +.def("SetRTS", &BSerialPort::SetRTS, "", py::arg("asserted")) +.def("NumCharsAvailable", &BSerialPort::NumCharsAvailable, "", py::arg("waitThisMany")) +.def("IsCTS", &BSerialPort::IsCTS, "") +.def("IsDSR", &BSerialPort::IsDSR, "") +.def("IsRI", &BSerialPort::IsRI, "") +.def("IsDCD", &BSerialPort::IsDCD, "") +.def("WaitForInput", &BSerialPort::WaitForInput, "") +.def("CountDevices", &BSerialPort::CountDevices, "") +.def("GetDeviceName", &BSerialPort::GetDeviceName, "", py::arg("index"), py::arg("name"), py::arg("bufSize")=B_OS_NAME_LENGTH) +; + + +} diff --git a/bindings/device/USBKit.cpp b/bindings/device/USBKit.cpp new file mode 100644 index 0000000..ea3be3c --- /dev/null +++ b/bindings/device/USBKit.cpp @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include + +#include + +namespace py = pybind11; +class PyBUSBRoster : public BUSBRoster{ + public: + using BUSBRoster::BUSBRoster; + status_t DeviceAdded(BUSBDevice *device) override { + PYBIND11_OVERLOAD_PURE(status_t,BUSBRoster,DeviceAdded,device) + } + void DeviceRemoved(BUSBDevice *device) override { + PYBIND11_OVERLOAD_PURE(void,BUSBRoster,DeviceRemoved,device) + } +}; + +PYBIND11_MODULE(USBKit,m) +{ +py::class_(m, "BUSBRoster") +.def(py::init(), "") +.def("DeviceAdded", &BUSBRoster::DeviceAdded, "", py::arg("device")) +.def("DeviceRemoved", &BUSBRoster::DeviceRemoved, "", py::arg("device")) +.def("Start", &BUSBRoster::Start, "") +.def("Stop", &BUSBRoster::Stop, "") +; + +py::class_(m, "BUSBDevice") +.def(py::init(), "", py::arg("path")=NULL) +.def("InitCheck", &BUSBDevice::InitCheck, "") +.def("SetTo", &BUSBDevice::SetTo, "", py::arg("path")) +.def("Unset", &BUSBDevice::Unset, "") +.def("Location", &BUSBDevice::Location, "") +.def("IsHub", &BUSBDevice::IsHub, "") +.def("USBVersion", &BUSBDevice::USBVersion, "") +.def("Class", &BUSBDevice::Class, "") +.def("Subclass", &BUSBDevice::Subclass, "") +.def("Protocol", &BUSBDevice::Protocol, "") +.def("MaxEndpoint0PacketSize", &BUSBDevice::MaxEndpoint0PacketSize, "") +.def("VendorID", &BUSBDevice::VendorID, "") +.def("ProductID", &BUSBDevice::ProductID, "") +.def("Version", &BUSBDevice::Version, "") +.def("ManufacturerString", &BUSBDevice::ManufacturerString, "") +.def("ProductString", &BUSBDevice::ProductString, "") +.def("SerialNumberString", &BUSBDevice::SerialNumberString, "") +.def("Descriptor", &BUSBDevice::Descriptor, "") +.def("GetStringDescriptor", &BUSBDevice::GetStringDescriptor, "", py::arg("index"), py::arg("descriptor"), py::arg("length")) +.def("DecodeStringDescriptor", &BUSBDevice::DecodeStringDescriptor, "", py::arg("index")) +//.def("GetDescriptor", &BUSBDevice::GetDescriptor, "", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data"), py::arg("length")) //todo: void *data -> in py::bytes +.def("GetDescriptor", [](const BUSBDevice& self, uint8 type, uint8 index, uint16 languageID, py::bytes data) { + size_t length = py::len(data); + std::vector buffer(length); + size_t resultLength = self.GetDescriptor(type, index, languageID, buffer.data(), length); + return py::bytes(reinterpret_cast(buffer.data()), resultLength); +},"", py::arg("type"), py::arg("index"), py::arg("languageID"), py::arg("data")) +.def("CountConfigurations", &BUSBDevice::CountConfigurations, "") +.def("ConfigurationAt", &BUSBDevice::ConfigurationAt, "", py::arg("index")) +.def("ActiveConfiguration", &BUSBDevice::ActiveConfiguration, "") +.def("SetConfiguration", &BUSBDevice::SetConfiguration, "", py::arg("configuration")) +.def("ControlTransfer", &BUSBDevice::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) +; + +py::class_>(m, "BUSBConfiguration") +.def("Index", &BUSBConfiguration::Index, "") +.def("Device", &BUSBConfiguration::Device, "") +.def("ConfigurationString", &BUSBConfiguration::ConfigurationString, "") +.def("Descriptor", &BUSBConfiguration::Descriptor, "") +.def("CountInterfaces", &BUSBConfiguration::CountInterfaces, "") +.def("InterfaceAt", &BUSBConfiguration::InterfaceAt, "", py::arg("index")) +; + +py::class_>(m, "BUSBInterface") +.def("Index", &BUSBInterface::Index, "") +.def("AlternateIndex", &BUSBInterface::AlternateIndex, "") +.def("Configuration", &BUSBInterface::Configuration, py::return_value_policy::reference) +.def("Device", &BUSBInterface::Device, py::return_value_policy::reference) +.def("Class", &BUSBInterface::Class, "") +.def("Subclass", &BUSBInterface::Subclass, "") +.def("Protocol", &BUSBInterface::Protocol, "") +.def("InterfaceString", &BUSBInterface::InterfaceString, "") +.def("Descriptor", &BUSBInterface::Descriptor, "") +.def("OtherDescriptorAt", &BUSBInterface::OtherDescriptorAt, "", py::arg("index"), py::arg("descriptor"), py::arg("length")) +.def("CountEndpoints", &BUSBInterface::CountEndpoints, "") +.def("EndpointAt", &BUSBInterface::EndpointAt, "", py::arg("index")) +.def("CountAlternates", &BUSBInterface::CountAlternates, "") +.def("ActiveAlternateIndex", &BUSBInterface::ActiveAlternateIndex, "") +.def("AlternateAt", &BUSBInterface::AlternateAt, "", py::arg("alternateIndex")) +.def("SetAlternate", &BUSBInterface::SetAlternate, "", py::arg("alternateIndex")) +; + +py::class_>(m, "BUSBEndpoint") +.def("Index", &BUSBEndpoint::Index, "") +.def("Interface", &BUSBEndpoint::Interface, "") +.def("Configuration", &BUSBEndpoint::Configuration, "") +.def("Device", &BUSBEndpoint::Device, "") +.def("IsBulk", &BUSBEndpoint::IsBulk, "") +.def("IsInterrupt", &BUSBEndpoint::IsInterrupt, "") +.def("IsIsochronous", &BUSBEndpoint::IsIsochronous, "") +.def("IsControl", &BUSBEndpoint::IsControl, "") +.def("IsInput", &BUSBEndpoint::IsInput, "") +.def("IsOutput", &BUSBEndpoint::IsOutput, "") +.def("MaxPacketSize", &BUSBEndpoint::MaxPacketSize, "") +.def("Interval", &BUSBEndpoint::Interval, "") +.def("Descriptor", &BUSBEndpoint::Descriptor, "") +//.def("ControlTransfer", &BUSBEndpoint::ControlTransfer, "", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) +.def("ControlTransfer", [](const BUSBEndpoint& self, uint8 requestType, uint8 request, uint16 value, uint16 index, uint16 length, py::bytes data) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.ControlTransfer(requestType, request, value, index, length, buffer.data()); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) +//.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length")) +.def("InterruptTransfer", [](const BUSBEndpoint& self, py::bytes data) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.InterruptTransfer(buffer.data(), dataLength); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("data")) +//.def("BulkTransfer", &BUSBEndpoint::BulkTransfer, "", py::arg("data"), py::arg("length")) +.def("BulkTransfer", [](const BUSBEndpoint& self, py::bytes data) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.BulkTransfer(buffer.data(), dataLength); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("data")) +//.def("IsochronousTransfer", &BUSBEndpoint::IsochronousTransfer, "", py::arg("data"), py::arg("length"), py::arg("packetDescriptors"), py::arg("packetCount")) +.def("IsochronousTransfer", [](const BUSBEndpoint& self, py::bytes data, usb_iso_packet_descriptor *packetDescriptors, uint32 packetCount) { + size_t dataLength = py::len(data); + std::vector buffer(dataLength); + ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength,packetDescriptors,packetCount); + return py::bytes(reinterpret_cast(buffer.data()), result); +},"", py::arg("data"),py::arg("packetDescriptors"),py::arg("packetCount")) +.def("IsStalled", &BUSBEndpoint::IsStalled, "") +.def("ClearStall", &BUSBEndpoint::ClearStall, "") +; + +} diff --git a/bindings/drivers/bios.cpp b/bindings/drivers/bios.cpp new file mode 100644 index 0000000..6fe8d61 --- /dev/null +++ b/bindings/drivers/bios.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include + +#include // Per supportare std::function +#include + +namespace py = pybind11; + +//struct bios_state; +//struct bios_regs; + +// Wrapping class + +class BiosModuleInfo { +public: + struct bios_module_info info; + + //std::function prepare; + std::function interrupt; + std::function finish; + + std::function allocate_mem; + std::function physical_address; + std::function virtual_address; + + BiosModuleInfo() { + // Initialize function pointers with null callbacks by default. + /*info.prepare = [this](bios_state** _state) -> status_t { + return this->prepare(_state); + };*/ + info.interrupt = [this](bios_state* state, uint8 vector, bios_regs* regs) -> status_t { + return this->interrupt(state, vector, regs); + }; + info.finish = [this](bios_state* state) { + this->finish(state); + }; + info.allocate_mem = [this](bios_state* state, size_t size) -> void* { + return this->allocate_mem(state, size); + }; + info.physical_address = [this](bios_state* state, void* virtualAddress) -> uint32 { + return this->physical_address(state, virtualAddress); + }; + info.virtual_address = [this](bios_state* state, uint32 physicalAddress) -> void* { + return this->virtual_address(state, physicalAddress); + }; + } +}; + + +PYBIND11_MODULE(bios, m) +{ +py::class_(m, "bios_regs") +.def_readwrite("eax", &bios_regs::eax, "") +.def_readwrite("ebx", &bios_regs::ebx, "") +.def_readwrite("ecx", &bios_regs::ecx, "") +.def_readwrite("edx", &bios_regs::edx, "") +.def_readwrite("edi", &bios_regs::edi, "") +.def_readwrite("esi", &bios_regs::esi, "") +.def_readwrite("ebp", &bios_regs::ebp, "") +.def_readwrite("eflags", &bios_regs::eflags, "") +.def_readwrite("ds", &bios_regs::ds, "") +.def_readwrite("es", &bios_regs::es, "") +.def_readwrite("fs", &bios_regs::fs, "") +.def_readwrite("gs", &bios_regs::gs, "") +; + +py::class_(m, "bios_module_info") +/* +.def_readwrite("info", &bios_module_info::info, "") +//.def_readwrite("prepare", &bios_module_info::prepare, "") +//.def_readwrite("interrupt", &bios_module_info::interrupt, "") +.def_readwrite("finish", &bios_module_info::finish, "") +.def_readwrite("allocate_mem", &bios_module_info::allocate_mem, "") +.def_readwrite("physical_address", &bios_module_info::physical_address, "") +.def_readwrite("virtual_address", &bios_module_info::virtual_address, "")*/ +; + +.def(py::init<>()) +//.def_readonly("prepare", &BiosModuleInfo::prepare) +.def_readonly("interrupt", &BiosModuleInfo::interrupt) +.def_readonly("finish", &BiosModuleInfo::finish) +.def_readonly("allocate_mem", &BiosModuleInfo::allocate_mem) +.def_readonly("physical_address", &BiosModuleInfo::physical_address) +.def_readonly("virtual_address", &BiosModuleInfo::virtual_address); +; + +} diff --git a/bindings/drivers/bus_manager.cpp b/bindings/drivers/bus_manager.cpp new file mode 100644 index 0000000..78dc0fd --- /dev/null +++ b/bindings/drivers/bus_manager.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include // Per std::function +#include + +namespace py = pybind11; +/* +PYBIND11_MODULE(bus_manager, m) +{ +py::class_(m, "bus_manager_info") +.def_readwrite("minfo", &bus_manager_info::minfo, "") +.def_readwrite("rescan", &bus_manager_info::rescan, "") +; + + +} +*/ + + +// Binding con pybind11 +PYBIND11_MODULE(bus_manager, m) +{ +py::class_(m, "BusManagerInfo") + .def(py::init<>()) + .def_readwrite("minfo", &bus_manager_info::minfo, "") + //.def_readwrite("rescan", &bus_manager_info::rescan) + .def("rescan", [](bus_manager_info& self) { + if (self.rescan) { + return self.rescan(); + } + return static_cast(-1); // Errore se rescan non è impostato + }) +; +} diff --git a/bindings/drivers/module.cpp b/bindings/drivers/module.cpp new file mode 100644 index 0000000..64bc82b --- /dev/null +++ b/bindings/drivers/module.cpp @@ -0,0 +1,187 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +/* +py::object get_module_wrapper(const std::string& path) { + module_info* info = nullptr; + status_t status = get_module(path.c_str(), &info); + + // Crea una lista di module_info da info, se necessario + std::vector info_vector; + if (info) { + // Supponiamo che info sia una lista terminata da nullptr + while (*info) { + info_vector.push_back(*info); + ++info; + } + } + + // Ritorna un tuple (status, info_vector) + return py::make_tuple(status, info_vector); +}*/ +/* +std::tuple> get_module_wrapper(const std::string& path) { + // Alloca un puntatore a module_info + module_info* info = nullptr; + + // Chiama la funzione C + status_t status = get_module(path.c_str(), &info); + + // Crea un vettore per contenere i module_info + std::vector info_vector; + + if (status == B_OK && info != nullptr) { + // Itera attraverso l'array di module_info + // Supponiamo che l'array di module_info termini con un nullptr + module_info* current = info; + while (*current != nullptr) { + info_vector.push_back(*current); + ++current; + } + } else { + throw std::runtime_error("Failed to get module."); + } + + // Ritorna il tuple (status, info_vector) + return std::make_tuple(status, info_vector); +}*/ +#include +#include +#include +std::tuple> get_module_wrapper(const std::string& path) { + // Alloca un puntatore a array di puntatori a module_info + module_info* info = nullptr; + + // Chiama la funzione C + status_t status = get_module(path.c_str(), &info); + + // Crea un vettore per contenere i module_info + std::vector info_vector; + + if (status == B_OK && info != nullptr) { + // Itera attraverso l'array di puntatori a module_info + module_info* current = info; + while (current != nullptr) { + info_vector.push_back(*current); // Aggiunge una copia di module_info al vettore + ++current; + } + } else { + throw std::runtime_error("Failed to get module."); + } + + // Ritorna il tuple (status, info_vector) + return std::make_tuple(status, info_vector); +} + +/*status_t call_std_ops(module_info* info, int32_t operation, const std::vector& args) { + if (info == nullptr || info->std_ops == nullptr) { + return -1; // Ritorna un codice di errore o un valore di default + } + + // Preparazione dei variadic arguments + va_list ap; + va_start(ap, operation); + for (int arg : args) { + va_arg(ap, int) = arg; + } + va_end(ap); + + // Chiama la funzione std_ops + return info->std_ops(operation, ap); +}*/ +#include +/*template +status_t call_with_tuple(module_info* info, int32_t operation, Tuple&& args, std::index_sequence) { + return info->std_ops(operation, std::get(args)...); +} +status_t call_std_ops(module_info* info, int32_t operation, py::args args) { + if (info == nullptr || info->std_ops == nullptr) { + return -1; // Codice di errore o valore di default + } + + // Convert args to a tuple of integers + auto args_tuple = std::make_tuple(args.cast()...); + + // Call the function using the tuple and apply + return call_with_tuple(info, operation, args_tuple, std::make_index_sequence()); +}*/ +template +status_t call_with_tuple(module_info* info, int32_t operation, Tuple&& args, std::index_sequence) { + return info->std_ops(operation, std::get(args)...); +} + +status_t call_std_ops(module_info* info, int32_t operation, py::args args) { + if (info == nullptr || info->std_ops == nullptr) { + return -1; // Codice di errore o valore di default + } + + // Convert py::args to a tuple of integers + auto args_tuple = std::apply([](auto&&... elems) { + return std::make_tuple(elems.cast()...); + }, args); + + // Call the function using the tuple and apply + return std::apply([&](auto&&... unpackedArgs) { + return info->std_ops(operation, unpackedArgs...); + }, args_tuple); +} + +PYBIND11_MODULE(module, m) +{ +py::class_(m, "module_info") +.def_readwrite("name", &module_info::name, "") +.def_readwrite("flags", &module_info::flags, "") +//.def_readwrite("std_ops", &module_info::std_ops, "") + +.def("call_std_ops", &call_std_ops, "Call the std_ops function", py::arg("info"), py::arg("operation"), py::arg("args")); +; + +py::class_(m, "module_dependency") +.def_readwrite("name", &module_dependency::name, "") +//.def_readwrite("info", &module_dependency::info, "") +.def("get_info", [](const module_dependency &self) { + std::vector info_vector; + if (self.info) { + // Converti l'array di puntatori a module_info in un vettore di module_info* + // Supponiamo che il numero di elementi sia conosciuto e sia 'count' + for (int i = 0; self.info[i] != nullptr; ++i) { + info_vector.push_back(self.info[i]); + } + } + return info_vector; + }) +.def("set_info", [](module_dependency &self, const std::vector &info_vector) { + // Funzione per impostare l'array di module_info* dalla lista Python + self.info = new module_info*[info_vector.size() + 1]; // +1 per il terminatore nullptr + for (size_t i = 0; i < info_vector.size(); ++i) { + self.info[i] = info_vector[i]; + } + self.info[info_vector.size()] = nullptr; // Terminatore nullptr + }); + +; + +//m.def("get_module", &get_module, "", py::arg("path"), py::arg("_info")); +//nell'heaader status_t get_module(const char *path, module_info **_info); +//m.def("get_module", [](const char *path, module_info **_info){}, "", py::arg("path"), py::arg("_info")); +m.def("get_module", &get_module_wrapper, "", py::arg("path")); + +m.def("put_module", &put_module, "", py::arg("path")); + +m.def("get_next_loaded_module_name", &get_next_loaded_module_name, "", py::arg("cookie"), py::arg("buffer"), py::arg("_bufferSize")); + +m.def("open_module_list_etc", &open_module_list_etc, "", py::arg("prefix"), py::arg("suffix")); + +m.def("open_module_list", &open_module_list, "", py::arg("prefix")); + +m.def("close_module_list", &close_module_list, "", py::arg("cookie")); + +m.def("read_next_module_name", &read_next_module_name, "", py::arg("cookie"), py::arg("buffer"), py::arg("_bufferSize")); + +} diff --git a/bindings/interface/AbstractLayout.cpp b/bindings/interface/AbstractLayout.cpp index fd2a09b..c95a416 100644 --- a/bindings/interface/AbstractLayout.cpp +++ b/bindings/interface/AbstractLayout.cpp @@ -10,8 +10,89 @@ namespace py = pybind11; +class PyBAbstractLayout : public BAbstractLayout{ + public: + using BAbstractLayout::BAbstractLayout; + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayout, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayout, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayout, PreferredSize); + } + BAlignment Alignment() override { + PYBIND11_OVERLOAD(BAlignment, BAbstractLayout, Alignment); + } + void SetExplicitMinSize(BSize size) override { + PYBIND11_OVERLOAD(void, BAbstractLayout, SetExplicitMinSize, size); + } + void SetExplicitMaxSize(BSize size) override { + PYBIND11_OVERLOAD(void, BAbstractLayout, SetExplicitMaxSize, size); + } + void SetExplicitPreferredSize(BSize size) override { + PYBIND11_OVERLOAD(void, BAbstractLayout, SetExplicitPreferredSize, size); + } + void SetExplicitAlignment(BAlignment alignment) override { + PYBIND11_OVERLOAD(void, BAbstractLayout, SetExplicitAlignment, alignment); + } + BSize BaseMinSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayout, BaseMinSize); + } + BSize BaseMaxSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayout, BaseMaxSize); + } + BSize BasePreferredSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayout, BasePreferredSize); + } + BAlignment BaseAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BAbstractLayout, BaseAlignment); + } + BRect Frame() override { + PYBIND11_OVERLOAD(BRect, BAbstractLayout, Frame); + } + void SetFrame(BRect frame) override { + PYBIND11_OVERLOAD(void, BAbstractLayout, SetFrame, frame); + } + bool IsVisible() override { + PYBIND11_OVERLOAD(bool, BAbstractLayout, IsVisible); + } + void SetVisible(bool visible) override { + PYBIND11_OVERLOAD(void, BAbstractLayout, SetVisible, visible); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BAbstractLayout, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BAbstractLayout, Perform, d, arg); + } + void DoLayout() override { + PYBIND11_OVERLOAD_PURE(void, BAbstractLayout, DoLayout); + } +}; PYBIND11_MODULE(AbstractLayout,m) { -py::class_(m, "BAbstractLayout"); +py::class_(m, "BAbstractLayout") +.def(py::init(), "") +.def(py::init(), "", py::arg("from")) +.def("MinSize", &BAbstractLayout::MinSize, "") +.def("MaxSize", &BAbstractLayout::MaxSize, "") +.def("PreferredSize", &BAbstractLayout::PreferredSize, "") +.def("Alignment", &BAbstractLayout::Alignment, "") +.def("SetExplicitMinSize", &BAbstractLayout::SetExplicitMinSize, "", py::arg("size")) +.def("SetExplicitMaxSize", &BAbstractLayout::SetExplicitMaxSize, "", py::arg("size")) +.def("SetExplicitPreferredSize", &BAbstractLayout::SetExplicitPreferredSize, "", py::arg("size")) +.def("SetExplicitAlignment", &BAbstractLayout::SetExplicitAlignment, "", py::arg("alignment")) +.def("BaseMinSize", &BAbstractLayout::BaseMinSize, "") +.def("BaseMaxSize", &BAbstractLayout::BaseMaxSize, "") +.def("BasePreferredSize", &BAbstractLayout::BasePreferredSize, "") +.def("BaseAlignment", &BAbstractLayout::BaseAlignment, "") +.def("Frame", &BAbstractLayout::Frame, "") +.def("SetFrame", &BAbstractLayout::SetFrame, "", py::arg("frame")) +.def("IsVisible", &BAbstractLayout::IsVisible, "") +.def("SetVisible", &BAbstractLayout::SetVisible, "", py::arg("visible")) +.def("Archive", &BAbstractLayout::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BAbstractLayout::Perform, "", py::arg("d"), py::arg("arg")); } diff --git a/bindings/interface/AbstractLayoutItem.cpp b/bindings/interface/AbstractLayoutItem.cpp index 3a3c848..804135d 100644 --- a/bindings/interface/AbstractLayoutItem.cpp +++ b/bindings/interface/AbstractLayoutItem.cpp @@ -10,27 +10,54 @@ namespace py = pybind11; +class PyBAbstractLayoutItem : public BAbstractLayoutItem{ + public: + using BAbstractLayoutItem::BAbstractLayoutItem; + BSize MinSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayoutItem, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayoutItem, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayoutItem, PreferredSize); + } + BAlignment Alignment() override { + PYBIND11_OVERLOAD(BAlignment, BAbstractLayoutItem, Alignment); + } + void SetExplicitMinSize(BSize size) override { + PYBIND11_OVERLOAD(void, BAbstractLayoutItem, SetExplicitMinSize, size); + } + void SetExplicitMaxSize(BSize size) override { + PYBIND11_OVERLOAD(void, BAbstractLayoutItem, SetExplicitMaxSize, size); + } + void SetExplicitPreferredSize(BSize size) override { + PYBIND11_OVERLOAD(void, BAbstractLayoutItem, SetExplicitPreferredSize, size); + } + void SetExplicitAlignment(BAlignment alignment) override { + PYBIND11_OVERLOAD(void, BAbstractLayoutItem, SetExplicitAlignment, alignment); + } + BSize BaseMinSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayoutItem, BaseMinSize); + } + BSize BaseMaxSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayoutItem, BaseMaxSize); + } + BSize BasePreferredSize() override { + PYBIND11_OVERLOAD(BSize, BAbstractLayoutItem, BasePreferredSize); + } + BAlignment BaseAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BAbstractLayoutItem, BaseAlignment); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BAbstractLayoutItem, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BAbstractLayoutItem, Perform, d, arg); + } +}; PYBIND11_MODULE(AbstractLayoutItem,m) { -py::class_(m, "BAbstractLayoutItem") -.def(py::init(), "") -.def(py::init(), "", py::arg("from")) -.def("MinSize", &BAbstractLayoutItem::MinSize, "") -.def("MaxSize", &BAbstractLayoutItem::MaxSize, "") -.def("PreferredSize", &BAbstractLayoutItem::PreferredSize, "") -.def("Alignment", &BAbstractLayoutItem::Alignment, "") -.def("SetExplicitMinSize", &BAbstractLayoutItem::SetExplicitMinSize, "", py::arg("size")) -.def("SetExplicitMaxSize", &BAbstractLayoutItem::SetExplicitMaxSize, "", py::arg("size")) -.def("SetExplicitPreferredSize", &BAbstractLayoutItem::SetExplicitPreferredSize, "", py::arg("size")) -.def("SetExplicitAlignment", &BAbstractLayoutItem::SetExplicitAlignment, "", py::arg("alignment")) -.def("BaseMinSize", &BAbstractLayoutItem::BaseMinSize, "") -.def("BaseMaxSize", &BAbstractLayoutItem::BaseMaxSize, "") -.def("BasePreferredSize", &BAbstractLayoutItem::BasePreferredSize, "") -.def("BaseAlignment", &BAbstractLayoutItem::BaseAlignment, "") -.def("Archive", &BAbstractLayoutItem::Archive, "", py::arg("into"), py::arg("deep")=true) -.def("Perform", &BAbstractLayoutItem::Perform, "", py::arg("d"), py::arg("arg")) -; - - +py::class_(m, "BAbstractLayoutItem"); } diff --git a/bindings/interface/AffineTransform.cpp b/bindings/interface/AffineTransform.cpp index 672919f..124e5a1 100644 --- a/bindings/interface/AffineTransform.cpp +++ b/bindings/interface/AffineTransform.cpp @@ -9,16 +9,53 @@ #include namespace py = pybind11; +/* +class PyBAffineTransform : public BAffineTransform { +public: + using BAffineTransform::BAffineTransform; + bool IsFixedSize() const override{ + PYBIND11_OVERLOAD(bool, BAffineTransform, IsFixedSize); + } + type_code TypeCode() const override{ + PYBIND11_OVERLOAD(type_code, BAffineTransform, TypeCode); + } + ssize_t FlattenedSize() const override{ + PYBIND11_OVERLOAD(ssize_t, BAffineTransform, FlattenedSize); + } + status_t Flatten(void* buffer, ssize_t size) const override{ + PYBIND11_OVERLOAD(status_t, BAffineTransform, Flatten, buffer, size); + } + status_t Unflatten(type_code code, const void* buffer, ssize_t size) override{ + PYBIND11_OVERLOAD(status_t, BAffineTransform, Unflatten, code, buffer, size); + } +// static double getKDefaultEpsilon() { +// return BAffineTransform::kDefaultEpsilon; +// } +};*/ +class AltBAffineTransform : public BAffineTransform { +public: + using BAffineTransform::BAffineTransform; + static double getKDefaultEpsilon() { + return BAffineTransform::kDefaultEpsilon; + } +}; + +#if __cplusplus < 201103L + static const double kDefaultEpsilon = 1e-14; +#else + static constexpr double kDefaultEpsilon = 1e-14; +#endif PYBIND11_MODULE(AffineTransform,m) { -m.attr("B_AFFINE_IDENTITY_TRANSFORM") = B_AFFINE_IDENTITY_TRANSFORM; - +//m.attr("B_AFFINE_IDENTITY_TRANSFORM") = B_AFFINE_IDENTITY_TRANSFORM; +//m.attr("kDefaultEpsilon") = 1e-14; py::class_(m, "BAffineTransform") .def(py::init(), "") .def(py::init(), "", py::arg("sx"), py::arg("shy"), py::arg("shx"), py::arg("sy"), py::arg("tx"), py::arg("ty")) .def(py::init(), "", py::arg("copyFrom")) +//.def_static("kDefaultEpsilon", &BAffineTransform::kDefaultEpsilon,"") .def("IsFixedSize", &BAffineTransform::IsFixedSize, "") .def("TypeCode", &BAffineTransform::TypeCode, "") .def("FlattenedSize", &BAffineTransform::FlattenedSize, "") @@ -29,24 +66,24 @@ py::class_(m, "BAffineTransform") .def_static("AffineScaling", py::overload_cast(&BAffineTransform::AffineScaling), "", py::arg("x"), py::arg("y")) .def_static("AffineScaling", py::overload_cast(&BAffineTransform::AffineScaling), "", py::arg("scale")) .def_static("AffineShearing", &BAffineTransform::AffineShearing, "", py::arg("x"), py::arg("y")) -.def("Apply", py::overload_cast(&BAffineTransform::Apply), "", py::arg("x"), py::arg("y")) -.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse), "", py::arg("x"), py::arg("y")) -.def("Apply", py::overload_cast(&BAffineTransform::Apply), "", py::arg("point")) -.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse), "", py::arg("point")) -.def("Apply", py::overload_cast(&BAffineTransform::Apply), "", py::arg("point")) -.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse), "", py::arg("point")) -.def("Apply", py::overload_cast(&BAffineTransform::Apply), "", py::arg("points"), py::arg("count")) -.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse), "", py::arg("points"), py::arg("count")) +.def("Apply", py::overload_cast(&BAffineTransform::Apply, py::const_), "", py::arg("x"), py::arg("y")) +.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse, py::const_), "", py::arg("x"), py::arg("y")) +.def("Apply", py::overload_cast(&BAffineTransform::Apply, py::const_), "", py::arg("point")) +.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse, py::const_), "", py::arg("point")) +.def("Apply", py::overload_cast(&BAffineTransform::Apply, py::const_), "", py::arg("point")) +.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse, py::const_), "", py::arg("point")) +.def("Apply", py::overload_cast(&BAffineTransform::Apply, py::const_), "", py::arg("points"), py::arg("count")) +.def("ApplyInverse", py::overload_cast(&BAffineTransform::ApplyInverse, py::const_), "", py::arg("points"), py::arg("count")) .def("TranslateBy", py::overload_cast(&BAffineTransform::TranslateBy), "", py::arg("x"), py::arg("y")) .def("TranslateBy", py::overload_cast(&BAffineTransform::TranslateBy), "", py::arg("delta")) .def("PreTranslateBy", &BAffineTransform::PreTranslateBy, "", py::arg("x"), py::arg("y")) -.def("TranslateByCopy", py::overload_cast(&BAffineTransform::TranslateByCopy), "", py::arg("x"), py::arg("y")) -.def("TranslateByCopy", py::overload_cast(&BAffineTransform::TranslateByCopy), "", py::arg("delta")) +.def("TranslateByCopy", py::overload_cast(&BAffineTransform::TranslateByCopy, py::const_), "", py::arg("x"), py::arg("y")) +.def("TranslateByCopy", py::overload_cast(&BAffineTransform::TranslateByCopy, py::const_), "", py::arg("delta")) .def("RotateBy", py::overload_cast(&BAffineTransform::RotateBy), "", py::arg("angle")) .def("RotateBy", py::overload_cast(&BAffineTransform::RotateBy), "", py::arg("center"), py::arg("angle")) .def("PreRotateBy", &BAffineTransform::PreRotateBy, "", py::arg("angleRadians")) -.def("RotateByCopy", py::overload_cast(&BAffineTransform::RotateByCopy), "", py::arg("angle")) -.def("RotateByCopy", py::overload_cast(&BAffineTransform::RotateByCopy), "", py::arg("center"), py::arg("angle")) +.def("RotateByCopy", py::overload_cast(&BAffineTransform::RotateByCopy, py::const_), "", py::arg("angle")) +.def("RotateByCopy", py::overload_cast(&BAffineTransform::RotateByCopy, py::const_), "", py::arg("center"), py::arg("angle")) .def("ScaleBy", py::overload_cast(&BAffineTransform::ScaleBy), "", py::arg("scale")) .def("ScaleBy", py::overload_cast(&BAffineTransform::ScaleBy), "", py::arg("center"), py::arg("scale")) .def("ScaleBy", py::overload_cast(&BAffineTransform::ScaleBy), "", py::arg("x"), py::arg("y")) @@ -54,22 +91,22 @@ py::class_(m, "BAffineTransform") .def("ScaleBy", py::overload_cast(&BAffineTransform::ScaleBy), "", py::arg("scale")) .def("ScaleBy", py::overload_cast(&BAffineTransform::ScaleBy), "", py::arg("center"), py::arg("scale")) .def("PreScaleBy", &BAffineTransform::PreScaleBy, "", py::arg("x"), py::arg("y")) -.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy), "", py::arg("scale")) -.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy), "", py::arg("center"), py::arg("scale")) -.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy), "", py::arg("x"), py::arg("y")) -.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy), "", py::arg("center"), py::arg("x"), py::arg("y")) -.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy), "", py::arg("scale")) -.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy), "", py::arg("center"), py::arg("scale")) +.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy, py::const_), "", py::arg("scale")) +.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy, py::const_), "", py::arg("center"), py::arg("scale")) +.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy, py::const_), "", py::arg("x"), py::arg("y")) +.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy, py::const_), "", py::arg("center"), py::arg("x"), py::arg("y")) +.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy, py::const_), "", py::arg("scale")) +.def("ScaleByCopy", py::overload_cast(&BAffineTransform::ScaleByCopy, py::const_), "", py::arg("center"), py::arg("scale")) .def("SetScale", py::overload_cast(&BAffineTransform::SetScale), "", py::arg("scale")) .def("SetScale", py::overload_cast(&BAffineTransform::SetScale), "", py::arg("x"), py::arg("y")) .def("ShearBy", py::overload_cast(&BAffineTransform::ShearBy), "", py::arg("x"), py::arg("y")) .def("ShearBy", py::overload_cast(&BAffineTransform::ShearBy), "", py::arg("center"), py::arg("x"), py::arg("y")) .def("ShearBy", py::overload_cast(&BAffineTransform::ShearBy), "", py::arg("shear")) .def("ShearBy", py::overload_cast(&BAffineTransform::ShearBy), "", py::arg("center"), py::arg("shear")) -.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy), "", py::arg("x"), py::arg("y")) -.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy), "", py::arg("center"), py::arg("x"), py::arg("y")) -.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy), "", py::arg("shear")) -.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy), "", py::arg("center"), py::arg("shear")) +.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy, py::const_), "", py::arg("x"), py::arg("y")) +.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy, py::const_), "", py::arg("center"), py::arg("x"), py::arg("y")) +.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy, py::const_), "", py::arg("shear")) +.def("ShearByCopy", py::overload_cast(&BAffineTransform::ShearByCopy, py::const_), "", py::arg("center"), py::arg("shear")) .def("Multiply", &BAffineTransform::Multiply, "", py::arg("other")) .def("PreMultiply", &BAffineTransform::PreMultiply, "", py::arg("other")) .def("MultiplyInverse", &BAffineTransform::MultiplyInverse, "", py::arg("other")) @@ -98,8 +135,11 @@ py::class_(m, "BAffineTransform") .def("GetScale", &BAffineTransform::GetScale, "", py::arg("sx"), py::arg("sy")) .def("GetScaleAbs", &BAffineTransform::GetScaleAbs, "", py::arg("sx"), py::arg("sy")) .def("GetAffineParameters", &BAffineTransform::GetAffineParameters, "", py::arg("translationX"), py::arg("translationY"), py::arg("rotation"), py::arg("scaleX"), py::arg("scaleY"), py::arg("shearX"), py::arg("shearY")) -.def_readwrite("kDefaultEpsilon", &BAffineTransform::kDefaultEpsilon, "") -.def_readwrite("kDefaultEpsilon", &BAffineTransform::kDefaultEpsilon, "") +.def_property_readonly_static("kDefaultEpsilon", []() { + return AltBAffineTransform::getKDefaultEpsilon(); + }, "") +//.def_readwrite("kDefaultEpsilon", &BAffineTransform::kDefaultEpsilon, "") +//.def_readwrite("kDefaultEpsilon", &BAffineTransform::kDefaultEpsilon, "") .def_readwrite("sx", &BAffineTransform::sx, "") .def_readwrite("shy", &BAffineTransform::shy, "") .def_readwrite("shx", &BAffineTransform::shx, "") @@ -107,7 +147,7 @@ py::class_(m, "BAffineTransform") .def_readwrite("tx", &BAffineTransform::tx, "") .def_readwrite("ty", &BAffineTransform::ty, "") ; - +/* m.def("operator=", &operator=, "", py::arg("other")); m.def("__eq__", &operator==, "", py::arg("other")); @@ -122,6 +162,6 @@ m.def("__mul__", &operator*, "", py::arg("other")); m.def("__truediv__", &operator/, "", py::arg("other")); -m.def("__invert__", &operator~, ""); +m.def("__invert__", &operator~, "");*/ } diff --git a/bindings/interface/Alert.cpp b/bindings/interface/Alert.cpp index ae4a740..b14a3eb 100644 --- a/bindings/interface/Alert.cpp +++ b/bindings/interface/Alert.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -13,6 +13,30 @@ namespace py = pybind11; +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BAlert); + +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 +53,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..8d5e90f 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,22 @@ 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("SetBits", &BBitmap::SetBits, "", py::arg("data"), py::arg("length"), py::arg("offset"), py::arg("colorSpace")) +.def("SetBits", [](BBitmap &bitmap, py::bytes pyData, size_t offset, color_space colorSpace) { + // Ottieni il puntatore ai dati e la lunghezza da py::bytes + //const void *data = pyData.data(); + //size_t length = pyData.size(); + const void *data = PyBytes_AsString(pyData.ptr()); + size_t length = static_cast(PyBytes_Size(pyData.ptr())); + bitmap.SetBits(data, length, offset, colorSpace); + }, "", py::arg("data"), py::arg("offset"), py::arg("colorSpace")) +//.def_readwrite("Private", &BBitmap::Private, "") ; diff --git a/bindings/interface/Box.cpp b/bindings/interface/Box.cpp index a55fd3d..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..ea64632 100644 --- a/bindings/interface/Button.cpp +++ b/bindings/interface/Button.cpp @@ -9,10 +9,105 @@ 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::enum_(m, "BBehavior", "") +.value("B_BUTTON_BEHAVIOR", BButton::BBehavior::B_BUTTON_BEHAVIOR, "") +.value("B_TOGGLE_BEHAVIOR", BButton::BBehavior::B_TOGGLE_BEHAVIOR, "") +.value("B_POP_UP_BEHAVIOR", BButton::BBehavior::B_POP_UP_BEHAVIOR, "") +.export_values(); + +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/CardLayout.cpp b/bindings/interface/CardLayout.cpp index 781c59f..b5d1969 100644 --- a/bindings/interface/CardLayout.cpp +++ b/bindings/interface/CardLayout.cpp @@ -16,7 +16,7 @@ py::class_(m, "BCardLayout") .def(py::init(), "", py::arg("from")) .def("VisibleItem", &BCardLayout::VisibleItem, "") .def("VisibleIndex", &BCardLayout::VisibleIndex, "") -.def("SetVisibleItem", py::overload_cast(&BCardLayout::SetVisibleItem), "", py::arg("index")) +.def("SetVisibleItem", py::overload_cast(&BCardLayout::SetVisibleItem), "", py::arg("index")) .def("SetVisibleItem", py::overload_cast(&BCardLayout::SetVisibleItem), "", py::arg("item")) .def("BaseMinSize", &BCardLayout::BaseMinSize, "") .def("BaseMaxSize", &BCardLayout::BaseMaxSize, "") diff --git a/bindings/interface/CardView.cpp b/bindings/interface/CardView.cpp index 1ac9e79..1d406e6 100644 --- a/bindings/interface/CardView.cpp +++ b/bindings/interface/CardView.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include namespace py = pybind11; diff --git a/bindings/interface/ChannelControl.cpp b/bindings/interface/ChannelControl.cpp index 446f3fe..4652b8f 100644 --- a/bindings/interface/ChannelControl.cpp +++ b/bindings/interface/ChannelControl.cpp @@ -4,28 +4,52 @@ #include #include +#include #include #include +#include namespace py = pybind11; +class PyBChannelControl : public BChannelControl{ + public: + using BChannelControl::BChannelControl; + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD_PURE(void, BChannelControl, Draw, updateRect); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD_PURE(void, BChannelControl, MouseDown, where); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD_PURE(void, BChannelControl, KeyDown, bytes, numBytes); + } + void GetPreferredSize(float* width, float* height) override { + PYBIND11_OVERLOAD_PURE(void, BChannelControl, GetPreferredSize, width, height); + } + int32 MaxChannelCount() const override { + PYBIND11_OVERLOAD_PURE(int32, BChannelControl, MaxChannelCount); + } + bool SupportsIndividualLimits() const override { + PYBIND11_OVERLOAD_PURE(bool, BChannelControl, SupportsIndividualLimits); + } +}; PYBIND11_MODULE(ChannelControl,m) { -py::class_(m, "BChannelControl") -.def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("model"), py::arg("channelCount")=1, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW) -.def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("model"), py::arg("channelCount")=1, py::arg("flags")=B_WILL_DRAW) +py::class_(m, "BChannelControl") +.def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("model"), py::arg("channelCount")=1, py::arg("resizingMode")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW) +.def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("model"), py::arg("channelCount")=1, py::arg("flags")=B_WILL_DRAW) .def(py::init(), "", py::arg("archive")) .def("Archive", &BChannelControl::Archive, "", py::arg("data"), py::arg("deep")=true) -.def("Draw", &BChannelControl::Draw, "", py::arg("updateRect")) -.def("MouseDown", &BChannelControl::MouseDown, "", py::arg("where")) -.def("KeyDown", &BChannelControl::KeyDown, "", py::arg("bytes"), py::arg("numBytes")) +//.def("Draw", &BChannelControl::Draw, "", py::arg("updateRect")) +//.def("MouseDown", &BChannelControl::MouseDown, "", py::arg("where")) +//.def("KeyDown", &BChannelControl::KeyDown, "", py::arg("bytes"), py::arg("numBytes")) .def("FrameResized", &BChannelControl::FrameResized, "", py::arg("newWidth"), py::arg("newHeight")) .def("SetFont", &BChannelControl::SetFont, "", py::arg("font"), py::arg("mask")=B_FONT_ALL) .def("AttachedToWindow", &BChannelControl::AttachedToWindow, "") .def("DetachedFromWindow", &BChannelControl::DetachedFromWindow, "") .def("ResizeToPreferred", &BChannelControl::ResizeToPreferred, "") -.def("GetPreferredSize", &BChannelControl::GetPreferredSize, "", py::arg("width"), py::arg("height")) +//.def("GetPreferredSize", &BChannelControl::GetPreferredSize, "", py::arg("width"), py::arg("height")) .def("MessageReceived", &BChannelControl::MessageReceived, "", py::arg("message")) .def("ResolveSpecifier", &BChannelControl::ResolveSpecifier, "", py::arg("message"), py::arg("index"), py::arg("specifier"), py::arg("what"), py::arg("property")) .def("GetSupportedSuites", &BChannelControl::GetSupportedSuites, "", py::arg("data")) @@ -34,29 +58,29 @@ py::class_(m, "BChannelControl") .def("Invoke", &BChannelControl::Invoke, "", py::arg("message")=NULL) .def("InvokeChannel", &BChannelControl::InvokeChannel, "//! These methods are similar to Invoke() Invoke() and InvokeNotify(), but", py::arg("message")=NULL, py::arg("fromChannel")=0, py::arg("channelCount")=- 1, py::arg("_mask")=NULL) .def("InvokeNotifyChannel", &BChannelControl::InvokeNotifyChannel, "", py::arg("message")=NULL, py::arg("kind")=B_CONTROL_INVOKED, py::arg("fromChannel")=0, py::arg("channelCount")=- 1, py::arg("_mask")=NULL) -.def("SetValue", py::overload_cast(&BChannelControl::SetValue), "", py::arg("value")) +.def("SetValue", py::overload_cast(&BChannelControl::SetValue), "", py::arg("value")) .def("SetCurrentChannel", &BChannelControl::SetCurrentChannel, "", py::arg("index")) .def("CurrentChannel", &BChannelControl::CurrentChannel, "") .def("CountChannels", &BChannelControl::CountChannels, "") -.def("MaxChannelCount", &BChannelControl::MaxChannelCount, "") +//.def("MaxChannelCount", &BChannelControl::MaxChannelCount, "") .def("SetChannelCount", &BChannelControl::SetChannelCount, "", py::arg("count")) .def("ValueFor", &BChannelControl::ValueFor, "", py::arg("channel")) .def("GetValue", &BChannelControl::GetValue, "", py::arg("_values"), py::arg("fromChannel"), py::arg("channelCount")) .def("SetValueFor", &BChannelControl::SetValueFor, "", py::arg("channel"), py::arg("value")) -.def("SetValue", py::overload_cast(&BChannelControl::SetValue), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("values")) +.def("SetValue", py::overload_cast(&BChannelControl::SetValue), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("values")) .def("SetAllValue", &BChannelControl::SetAllValue, "", py::arg("values")) -.def("SetLimitsFor", py::overload_cast(&BChannelControl::SetLimitsFor), "", py::arg("channel"), py::arg("minimum"), py::arg("maximum")) -.def("GetLimitsFor", py::overload_cast(&BChannelControl::GetLimitsFor), "", py::arg("channel"), py::arg("_minimum"), py::arg("_maximum")) -.def("SetLimitsFor", py::overload_cast(&BChannelControl::SetLimitsFor), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("minima"), py::arg("maxima")) -.def("GetLimitsFor", py::overload_cast(&BChannelControl::GetLimitsFor), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("minima"), py::arg("maxima")) +.def("SetLimitsFor", py::overload_cast(&BChannelControl::SetLimitsFor), "", py::arg("channel"), py::arg("minimum"), py::arg("maximum")) +.def("GetLimitsFor", py::overload_cast(&BChannelControl::GetLimitsFor, py::const_), "", py::arg("channel"), py::arg("_minimum"), py::arg("_maximum")) +.def("SetLimitsFor", py::overload_cast(&BChannelControl::SetLimitsFor), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("minima"), py::arg("maxima")) +.def("GetLimitsFor", py::overload_cast(&BChannelControl::GetLimitsFor, py::const_), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("minima"), py::arg("maxima")) .def("SetLimits", &BChannelControl::SetLimits, "", py::arg("minimum"), py::arg("maximum")) .def("GetLimits", &BChannelControl::GetLimits, "", py::arg("_minimum"), py::arg("_maximum")) -.def("SupportsIndividualLimits", &BChannelControl::SupportsIndividualLimits, "") +//.def("SupportsIndividualLimits", &BChannelControl::SupportsIndividualLimits, "") .def("SetLimitLabels", &BChannelControl::SetLimitLabels, "", py::arg("minLabel"), py::arg("maxLabel")) .def("MinLimitLabel", &BChannelControl::MinLimitLabel, "") .def("MaxLimitLabel", &BChannelControl::MaxLimitLabel, "") -.def("SetLimitLabelsFor", py::overload_cast(&BChannelControl::SetLimitLabelsFor), "", py::arg("channel"), py::arg("minLabel"), py::arg("maxLabel")) -.def("SetLimitLabelsFor", py::overload_cast(&BChannelControl::SetLimitLabelsFor), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("minLabel"), py::arg("maxLabel")) +.def("SetLimitLabelsFor", py::overload_cast(&BChannelControl::SetLimitLabelsFor), "", py::arg("channel"), py::arg("minLabel"), py::arg("maxLabel")) +.def("SetLimitLabelsFor", py::overload_cast(&BChannelControl::SetLimitLabelsFor), "", py::arg("fromChannel"), py::arg("channelCount"), py::arg("minLabel"), py::arg("maxLabel")) .def("MinLimitLabelFor", &BChannelControl::MinLimitLabelFor, "", py::arg("channel")) .def("MaxLimitLabelFor", &BChannelControl::MaxLimitLabelFor, "", py::arg("channel")) ; diff --git a/bindings/interface/ChannelSlider.cpp b/bindings/interface/ChannelSlider.cpp index 96321e8..6099a96 100644 --- a/bindings/interface/ChannelSlider.cpp +++ b/bindings/interface/ChannelSlider.cpp @@ -4,10 +4,108 @@ #include #include +#include #include +#include namespace py = pybind11; +class PyBChannelSlider : public BChannelSlider{ + public: + using BChannelSlider::BChannelSlider; + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BChannelSlider, Archive, into, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERLOAD(void, BChannelSlider, AttachedToWindow); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BChannelSlider, AllAttached); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BChannelSlider, DetachedFromWindow); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BChannelSlider, AllDetached); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BChannelSlider, MessageReceived, message); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERLOAD(void, BChannelSlider, Draw, updateRect); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BChannelSlider, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BChannelSlider, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERLOAD(void, BChannelSlider, MouseMoved, where, transit, dragMessage); + } + void WindowActivated(bool state) override { + PYBIND11_OVERLOAD(void, BChannelSlider, WindowActivated, state); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BChannelSlider, KeyDown, bytes, numBytes); + } + void KeyUp(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BChannelSlider, KeyUp, bytes, numBytes); + } + void FrameResized(float width, float height) override { + PYBIND11_OVERLOAD(void, BChannelSlider, FrameResized, width, height); + } + void SetFont(const BFont* font, uint32 mask = B_FONT_ALL) override { + PYBIND11_OVERLOAD(void, BChannelSlider, SetFont, font, mask); + } + void MakeFocus(bool focusState = true) override { + PYBIND11_OVERLOAD(void, BChannelSlider, MakeFocus, focusState); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BChannelSlider, GetPreferredSize, _width, _height); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BChannelSlider, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BChannelSlider, GetSupportedSuites, data); + } + void SetEnabled(bool on) override { + PYBIND11_OVERLOAD(void, BChannelSlider, SetEnabled, on); + } + orientation Orientation() const override { + PYBIND11_OVERLOAD(orientation, BChannelSlider, Orientation); + } + int32 MaxChannelCount() const override { + PYBIND11_OVERLOAD(int32, BChannelSlider, MaxChannelCount); + } + bool SupportsIndividualLimits() const override { + PYBIND11_OVERLOAD(bool, BChannelSlider, SupportsIndividualLimits); + } + void DrawChannel(BView* into, int32 channel, BRect area, bool pressed) override { + PYBIND11_OVERLOAD(void, BChannelSlider, DrawChannel, into, channel, area, pressed); + } + void DrawGroove(BView* into, int32 channel, BPoint leftTop, BPoint rightBottom) override { + PYBIND11_OVERLOAD(void, BChannelSlider, DrawGroove, into, channel, leftTop, rightBottom); + } + void DrawThumb(BView* into, int32 channel, BPoint where, bool pressed) override { + PYBIND11_OVERLOAD(void, BChannelSlider, DrawThumb, into, channel, where, pressed); + } + const BBitmap* ThumbFor(int32 channel, bool pressed) override { + PYBIND11_OVERLOAD(const BBitmap*, BChannelSlider, ThumbFor, channel, pressed); + } + BRect ThumbFrameFor(int32 channel) override { + PYBIND11_OVERLOAD(BRect, BChannelSlider, ThumbFrameFor, channel); + } + float ThumbDeltaFor(int32 channel) override { + PYBIND11_OVERLOAD(float, BChannelSlider, ThumbDeltaFor, channel); + } + float ThumbRangeFor(int32 channel) override { + PYBIND11_OVERLOAD(float, BChannelSlider, ThumbRangeFor, channel); + } +}; + + PYBIND11_MODULE(ChannelSlider,m) { diff --git a/bindings/interface/CheckBox.cpp b/bindings/interface/CheckBox.cpp index f508a67..8f7f81b 100644 --- a/bindings/interface/CheckBox.cpp +++ b/bindings/interface/CheckBox.cpp @@ -4,14 +4,101 @@ #include #include +#include #include 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 9bb8491..694f6f4 100644 --- a/bindings/interface/ColorControl.cpp +++ b/bindings/interface/ColorControl.cpp @@ -4,10 +4,94 @@ #include #include +#include +#include #include 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) { @@ -19,13 +103,13 @@ 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")) .def("Archive", &BColorControl::Archive, "", py::arg("data"), py::arg("deep")=true) .def("SetLayout", py::overload_cast(&BColorControl::SetLayout), "", py::arg("layout")) -.def("SetValue", py::overload_cast(&BColorControl::SetValue), "", py::arg("color_value")) +.def("SetValue", py::overload_cast(&BColorControl::SetValue), "", py::arg("color_value")) .def("SetValue", py::overload_cast(&BColorControl::SetValue), "", py::arg("color")) .def("ValueAsColor", &BColorControl::ValueAsColor, "") .def("SetEnabled", &BColorControl::SetEnabled, "", py::arg("state")) 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/ControlLook.cpp b/bindings/interface/ControlLook.cpp index 22de5c1..16344bc 100644 --- a/bindings/interface/ControlLook.cpp +++ b/bindings/interface/ControlLook.cpp @@ -4,23 +4,580 @@ #include #include +#include #include #include #include #include +#include namespace py = pybind11; using namespace BPrivate; + + +class PyBControlLook : public BControlLook { +public: + using BControlLook::BControlLook; + + BAlignment DefaultLabelAlignment() const override { + PYBIND11_OVERRIDE_PURE(BAlignment, BControlLook, DefaultLabelAlignment, ); + } + + float DefaultLabelSpacing() const override { + PYBIND11_OVERRIDE_PURE(float, BControlLook, DefaultLabelSpacing, ); + } + + float DefaultItemSpacing() const override { + PYBIND11_OVERRIDE_PURE(float, BControlLook, DefaultItemSpacing, ); + } + + uint32 Flags(BControl* control) const override { + PYBIND11_OVERRIDE_PURE(uint32, BControlLook, Flags, control); + } + + void DrawButtonFrame(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, const rgb_color& background, + uint32 flags = 0, uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonFrame, view, rect, updateRect, base, background, flags, borders); + } + void DrawButtonFrame(BView* view, BRect& rect, const BRect& updateRect, + float radius, const rgb_color& base, const rgb_color& background, + uint32 flags = 0, uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonFrame, view, rect, updateRect, radius, base, background, flags, borders); + } + void DrawButtonFrame(BView* view, BRect& rect, const BRect& updateRect, + float leftTopRadius, float rightTopRadius, float leftBottomRadius, + float rightBottomRadius, const rgb_color& base, const rgb_color& background, + uint32 flags = 0, uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonFrame, view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, background, flags, borders); + } + void DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, uint32 borders = B_ALL_BORDERS, + orientation orientation = B_HORIZONTAL) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonBackground, view, rect, updateRect, base, flags, borders, orientation); + } + void DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect, + float radius, const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS, orientation orientation = B_HORIZONTAL) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonBackground, view, rect, updateRect, radius, base, flags, borders, orientation); + } + void DrawButtonBackground(BView* view, BRect& rect, + const BRect& updateRect, + float leftTopRadius, + float rightTopRadius, + float leftBottomRadius, + float rightBottomRadius, + const rgb_color& base, + uint32 flags = 0, + uint32 borders = B_ALL_BORDERS, + orientation orientation = B_HORIZONTAL) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonBackground, view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, flags, borders, orientation); + } + void DrawMenuBarBackground(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, + uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuBarBackground, view, rect, updateRect, base, flags, borders); + } + void DrawMenuFieldFrame(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, + const rgb_color& background, + uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuFieldFrame, view, rect, updateRect, base, background, flags, borders); + } + void DrawMenuFieldFrame(BView* view, BRect& rect, + const BRect& updateRect, + float radius, + const rgb_color& base, + const rgb_color& background, + uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuFieldFrame, view, rect, updateRect, radius, base, background, flags, borders); + } + void DrawMenuFieldFrame(BView* view, BRect& rect, + const BRect& updateRect, + float leftTopRadius, + float rightTopRadius, + float leftBottomRadius, + float rightBottomRadius, + const rgb_color& base, + const rgb_color& background, + uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuFieldFrame, view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, background, flags, borders); + } + void DrawMenuFieldBackground(BView* view, + BRect& rect, const BRect& updateRect, + const rgb_color& base, bool popupIndicator, + uint32 flags = 0) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuFieldBackground, view, rect, updateRect, base, popupIndicator, flags); + } + void DrawMenuFieldBackground(BView* view, + BRect& rect, const BRect& updateRect, + float radius, const rgb_color& base, + bool popupIndicator, uint32 flags = 0) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuFieldBackground, view, rect, updateRect, radius, base, popupIndicator, flags); + } + void DrawMenuFieldBackground(BView* view, + BRect& rect, const BRect& updateRect, + float leftTopRadius, + float rightTopRadius, + float leftBottomRadius, + float rightBottomRadius, + const rgb_color& base, + bool popupIndicator, uint32 flags = 0) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuFieldBackground, view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, popupIndicator, flags); + } + void DrawMenuFieldBackground(BView* view, + BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuFieldBackground, view, rect, updateRect, base, flags, borders); + } + void DrawMenuBackground(BView* view, + BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuBackground, view, rect, updateRect, base, flags, borders); + } + void DrawMenuItemBackground(BView* view, + BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawMenuItemBackground, view, rect, updateRect, base, flags, borders); + } + void DrawStatusBar(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, + const rgb_color& barColor, + float progressPosition) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawStatusBar, view, rect, updateRect, base, barColor, progressPosition); + } + void DrawCheckBox(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, + uint32 flags = 0) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawCheckBox, view, rect, updateRect, base, flags); + } + void DrawRadioButton(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, + uint32 flags = 0) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawRadioButton, view, rect, updateRect, base, flags); + } + void DrawScrollBarBackground(BView* view, + BRect& rect1, BRect& rect2, + const BRect& updateRect, + const rgb_color& base, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawScrollBarBackground, view, rect1, rect2, updateRect, base, flags, orientation); + } + void DrawScrollBarBackground(BView* view, + BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawScrollBarBackground, view, rect, updateRect, base, flags, orientation); + } + void DrawScrollViewFrame(BView* view, + BRect& rect, const BRect& updateRect, + BRect verticalScrollBarFrame, + BRect horizontalScrollBarFrame, + const rgb_color& base, + border_style borderStyle, + uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawScrollViewFrame, view, rect, updateRect,verticalScrollBarFrame,horizontalScrollBarFrame, base, borderStyle, flags, borders); + } + void DrawArrowShape(BView* view, + BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 direction, + uint32 flags = 0, + float tint = B_DARKEN_MAX_TINT) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawArrowShape, view, rect, updateRect, base, direction, flags, tint); + } + rgb_color SliderBarColor(const rgb_color& base) override { + PYBIND11_OVERRIDE_PURE(rgb_color, BControlLook, SliderBarColor, base); + } + void DrawSliderBar(BView* view, BRect rect, + const BRect& updateRect, + const rgb_color& base, + rgb_color leftFillColor, + rgb_color rightFillColor, + float sliderScale, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawSliderBar, view, rect, updateRect, base, leftFillColor, rightFillColor, sliderScale, flags, orientation); + } + void DrawSliderBar(BView* view, BRect rect, + const BRect& updateRect, + const rgb_color& base, rgb_color fillColor, + uint32 flags, orientation orientation) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawSliderBar, view, rect, updateRect, base, fillColor, flags, orientation); + } + void DrawSliderThumb(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE( + void, + BControlLook, + DrawSliderThumb, + view, rect, updateRect, base, flags, orientation); + } + void DrawSliderTriangle(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE( + void, + BControlLook, + DrawSliderTriangle, + view, rect, updateRect, base, flags, orientation); + } + void DrawSliderTriangle(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, + const rgb_color& fill, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE( + void, + BControlLook, + DrawSliderTriangle, + view, rect, updateRect, base, fill, flags, orientation); + } + void DrawSliderHashMarks(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, int32 count, + hash_mark_location location, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE( + void, + BControlLook, + DrawSliderHashMarks, + view, rect, updateRect, base, count, location, flags, + orientation); + } + void DrawActiveTab(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS, uint32 side = B_TOP_BORDER, + int32 index = 0, int32 selected = -1, + int32 first = 0, int32 last = 0) override { + PYBIND11_OVERRIDE_PURE( + void, + BControlLook, + DrawActiveTab, + view, rect, updateRect, base, flags, borders, side, index, selected, + first, last); + } + void DrawInactiveTab(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags, + uint32 borders = B_ALL_BORDERS, uint32 side = B_TOP_BORDER, + int32 index = 0, int32 selected = -1, + int32 first = 0, int32 last = 0) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawInactiveTab, view, rect, updateRect, base, + flags, borders, side, index, selected, first, last); +} +void DrawSplitter(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, orientation orientation, + uint32 flags = 0, uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawSplitter, view, rect, updateRect, base, + orientation, flags, borders); +} +void DrawBorder(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, border_style borderStyle, + uint32 flags = 0, uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawBorder, view, rect, updateRect, base, + borderStyle, flags, borders); +} +void DrawRaisedBorder(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawRaisedBorder, view, rect, updateRect, base, + flags, borders); +} +void DrawGroupFrame(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawGroupFrame, view, rect, updateRect, base, + borders); +} +void DrawTextControlBorder(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawTextControlBorder, view, rect, updateRect, + base, flags, borders); +} +void DrawLabel(BView* view, const char* label, BRect rect, + const BRect& updateRect, const rgb_color& base, uint32 flags, + const rgb_color* textColor = nullptr) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawLabel, view, label, rect, updateRect, base, + flags, textColor); +} +void DrawLabel(BView* view, const char* label, BRect rect, + const BRect& updateRect, const rgb_color& base, uint32 flags, + const BAlignment& alignment, + const rgb_color* textColor = nullptr) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawLabel, view, label, rect, updateRect, base, + flags, alignment, textColor); +} +void DrawLabel(BView* view, const char* label, const rgb_color& base, + uint32 flags, const BPoint& where, + const rgb_color* textColor = nullptr) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawLabel, view, label, base, flags, where, + textColor); +} +void DrawLabel(BView* view, const char* label, const BBitmap* icon, BRect rect, + const BRect& updateRect, const rgb_color& base, uint32 flags, + const BAlignment& alignment, + const rgb_color* textColor = nullptr) override { + PYBIND11_OVERRIDE_PURE( + void, BControlLook, DrawLabel, view, label, icon, rect, updateRect, base, + flags, alignment, textColor); +} +void GetFrameInsets(frame_type frameType, uint32 flags, float& _left, + float& _top, float& _right, float& _bottom) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, GetFrameInsets, frameType, flags, + _left, _top, _right, _bottom); +} +void GetBackgroundInsets(background_type backgroundType, uint32 flags, + float& _left, float& _top, float& _right, + float& _bottom) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, GetBackgroundInsets, + backgroundType, flags, _left, _top, _right, _bottom); +} +void DrawButtonWithPopUpBackground(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS, + orientation orientation = B_HORIZONTAL) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonWithPopUpBackground, + view, rect, updateRect, base, flags, borders, + orientation); +} +void DrawButtonWithPopUpBackground(BView* view, BRect& rect, + const BRect& updateRect, float radius, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS, + orientation orientation = B_HORIZONTAL) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonWithPopUpBackground, + view, rect, updateRect, radius, base, flags, borders, + orientation); +} +void DrawButtonWithPopUpBackground(BView* view, BRect& rect, + const BRect& updateRect, + float leftTopRadius, float rightTopRadius, + float leftBottomRadius, + float rightBottomRadius, + const rgb_color& base, uint32 flags = 0, + uint32 borders = B_ALL_BORDERS, + orientation orientation = B_HORIZONTAL) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawButtonWithPopUpBackground, + view, rect, updateRect, leftTopRadius, rightTopRadius, + leftBottomRadius, rightBottomRadius, base, flags, + borders, orientation); +} +void DrawTabFrame(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags = 0, uint32 borders = B_ALL_BORDERS, + border_style borderStyle = B_FANCY_BORDER, uint32 side = B_TOP_BORDER) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawTabFrame, view, rect, + updateRect, base, flags, borders, borderStyle, side); +} +void DrawScrollBarButton(BView* view, BRect rect, const BRect& updateRect, + const rgb_color& base, uint32 flags, int32 direction, + orientation orientation, bool down = false) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawScrollBarButton, view, rect, + updateRect, base, flags, direction, orientation, down); +} +void DrawScrollBarThumb(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags, + orientation orientation, uint32 knobStyle = B_KNOB_NONE) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawScrollBarThumb, view, rect, + updateRect, base, flags, orientation, knobStyle); +} +void DrawScrollBarBorder(BView* view, BRect rect, const BRect& updateRect, + const rgb_color& base, uint32 flags, + orientation orientation) override { + PYBIND11_OVERRIDE_PURE(void, BControlLook, DrawScrollBarBorder, view, rect, + updateRect, base, flags, orientation); +} +float GetScrollBarWidth(orientation orientation = B_VERTICAL) override { + PYBIND11_OVERLOAD(float, BControlLook, GetScrollBarWidth, orientation); +} +}; + +class MyClass { +public: +enum various { + B_LEFT_BORDER = 1 << 0, + B_RIGHT_BORDER = 1 << 1, + B_TOP_BORDER = 1 << 2, + B_BOTTOM_BORDER = 1 << 3, + B_ALL_BORDERS = B_LEFT_BORDER | B_RIGHT_BORDER | B_TOP_BORDER | B_BOTTOM_BORDER, + + B_LEFT_ARROW = 0, + B_RIGHT_ARROW = 1, + B_UP_ARROW = 2, + B_DOWN_ARROW = 3, + B_LEFT_UP_ARROW = 4, + B_RIGHT_UP_ARROW = 5, + B_RIGHT_DOWN_ARROW = 6, + B_LEFT_DOWN_ARROW = 7, + + B_FOCUSED = 1 << 0, + B_CLICKED = 1 << 1, // some controls activate on mouse up + B_ACTIVATED = 1 << 2, + B_HOVER = 1 << 3, + B_DISABLED = 1 << 4, + B_DEFAULT_BUTTON = 1 << 5, + B_IGNORE_OUTLINE = 1 << 6, + B_PARTIALLY_ACTIVATED = 1 << 7, // like B_ACTIVATED, but for tri-state + B_FLAT = 1 << 8, // flat look (e.g. button background) + B_INVALID = 1 << 9, // invalid value, use B_FAILURE_COLOR + B_IS_CONTROL = 1 << 10, // use control colors + B_BLEND_FRAME = 1 << 16, + + B_KNOB_NONE = 0, + B_KNOB_DOTS, + B_KNOB_LINES +}; +// static void exportEnum(py::module& m) { +// m.attr("B_KNOB_NONE") = py::int_(B_KNOB_NONE); +// m.attr("B_KNOB_DOTS") = py::int_(B_KNOB_DOTS); +// m.attr("B_KNOB_LINES") = py::int_(B_KNOB_LINES); +// +// } +}; + + + PYBIND11_MODULE(ControlLook,m) { -m.attr("be_control_look") = be_control_look; + -m.attr("BControlLook") = BControlLook; +/*py::enum_(m, "frame_type", "") +.value("B_BUTTON_FRAME", frame_type::B_BUTTON_FRAME, "") +.value("B_GROUP_FRAME", frame_type::B_GROUP_FRAME, "") +.value("B_MENU_FIELD_FRAME", frame_type::B_MENU_FIELD_FRAME, "") +.value("B_SCROLL_VIEW_FRAME", frame_type::B_SCROLL_VIEW_FRAME, "") +.value("B_TEXT_CONTROL_FRAME", frame_type::B_TEXT_CONTROL_FRAME, "") +.export_values();*/ -m.attr("be_control_look") = be_control_look; +py::enum_(m, "frame_type") + .value("B_BUTTON_FRAME", BControlLook::frame_type::B_BUTTON_FRAME) + .value("B_GROUP_FRAME", BControlLook::frame_type::B_GROUP_FRAME) + .value("B_MENU_FIELD_FRAME", BControlLook::frame_type::B_MENU_FIELD_FRAME) + .value("B_SCROLL_VIEW_FRAME", BControlLook::frame_type::B_SCROLL_VIEW_FRAME) + .value("B_TEXT_CONTROL_FRAME", BControlLook::frame_type::B_TEXT_CONTROL_FRAME); -py::class_(m, "BControlLook") +py::enum_(m, "background_type") + .value("B_BUTTON_BACKGROUND", BControlLook::background_type::B_BUTTON_BACKGROUND) + .value("B_BUTTON_WITH_POP_UP_BACKGROUND", BControlLook::background_type::B_BUTTON_WITH_POP_UP_BACKGROUND) + .value("B_MENU_BACKGROUND", BControlLook::background_type::B_MENU_BACKGROUND) + .value("B_MENU_BAR_BACKGROUND", BControlLook::background_type::B_MENU_BAR_BACKGROUND) + .value("B_MENU_FIELD_BACKGROUND", BControlLook::background_type::B_MENU_FIELD_BACKGROUND) + .value("B_MENU_ITEM_BACKGROUND", BControlLook::background_type::B_MENU_ITEM_BACKGROUND) + .value("B_HORIZONTAL_SCROLL_BAR_BACKGROUND", BControlLook::background_type::B_HORIZONTAL_SCROLL_BAR_BACKGROUND) + .value("B_VERTICAL_SCROLL_BAR_BACKGROUND", BControlLook::background_type::B_VERTICAL_SCROLL_BAR_BACKGROUND); + +py::enum_(m, "BControlLookEnum") +.value("B_LEFT_BORDER", MyClass::various::B_LEFT_BORDER) +.value("B_RIGHT_BORDER", MyClass::various::B_RIGHT_BORDER) +.value("B_TOP_BORDER", MyClass::various::B_TOP_BORDER) +.value("B_BOTTOM_BORDER", MyClass::various::B_BOTTOM_BORDER) +.value("B_ALL_BORDERS", MyClass::various::B_ALL_BORDERS) +.value("B_LEFT_ARROW", MyClass::various::B_LEFT_ARROW) +.value("B_RIGHT_ARROW", MyClass::various::B_RIGHT_ARROW) +.value("B_UP_ARROW", MyClass::various::B_UP_ARROW) +.value("B_DOWN_ARROW", MyClass::various::B_DOWN_ARROW) +.value("B_LEFT_UP_ARROW", MyClass::various::B_LEFT_UP_ARROW) +.value("B_RIGHT_UP_ARROW", MyClass::various::B_RIGHT_UP_ARROW) +.value("B_RIGHT_DOWN_ARROW", MyClass::various::B_RIGHT_DOWN_ARROW) +.value("B_LEFT_DOWN_ARROW", MyClass::various::B_LEFT_DOWN_ARROW) +.value("B_FOCUSED", MyClass::various::B_FOCUSED) +.value("B_CLICKED", MyClass::various::B_CLICKED) +.value("B_ACTIVATED", MyClass::various::B_ACTIVATED) +.value("B_HOVER", MyClass::various::B_HOVER) +.value("B_DISABLED", MyClass::various::B_DISABLED) +.value("B_DEFAULT_BUTTON", MyClass::various::B_DEFAULT_BUTTON) +.value("B_IGNORE_OUTLINE", MyClass::various::B_IGNORE_OUTLINE) +.value("B_PARTIALLY_ACTIVATED", MyClass::various::B_PARTIALLY_ACTIVATED) +.value("B_FLAT", MyClass::various::B_FLAT) +.value("B_INVALID", MyClass::various::B_INVALID) +.value("B_IS_CONTROL", MyClass::various::B_IS_CONTROL) +.value("B_BLEND_FRAME", MyClass::various::B_BLEND_FRAME) +.value("B_KNOB_NONE", MyClass::various::B_KNOB_NONE) +.value("B_KNOB_DOTS", MyClass::various::B_KNOB_DOTS) +.value("B_KNOB_LINES", MyClass::various::B_KNOB_LINES) +.export_values(); +/* +m.attr("B_LEFT_BORDER") = BControlLook::B_LEFT_BORDER; +m.attr("B_RIGHT_BORDER") = BControlLook::B_RIGHT_BORDER; +m.attr("B_TOP_BORDER") = BControlLook::B_TOP_BORDER; +m.attr("B_BOTTOM_BORDER") = BControlLook::B_BOTTOM_BORDER; +m.attr("B_ALL_BORDERS") = BControlLook::B_ALL_BORDERS; +m.attr("B_LEFT_ARROW") = BControlLook::B_LEFT_ARROW; +m.attr("B_RIGHT_ARROW") = BControlLook::B_RIGHT_ARROW; +m.attr("B_UP_ARROW") = BControlLook::B_UP_ARROW; +m.attr("B_DOWN_ARROW") = BControlLook::B_DOWN_ARROW; +m.attr("B_LEFT_UP_ARROW") = BControlLook::B_LEFT_UP_ARROW; +m.attr("B_RIGHT_UP_ARROW") = BControlLook::B_RIGHT_UP_ARROW; +m.attr("B_RIGHT_DOWN_ARROW") = BControlLook::B_RIGHT_DOWN_ARROW; +m.attr("B_LEFT_DOWN_ARROW") = BControlLook::B_LEFT_DOWN_ARROW; +m.attr("B_FOCUSED") = BControlLook::B_FOCUSED; +m.attr("B_CLICKED") = BControlLook::B_CLICKED; +m.attr("B_ACTIVATED") = BControlLook::B_ACTIVATED; +m.attr("B_HOVER") = BControlLook::B_HOVER; +m.attr("B_DISABLED") = BControlLook::B_DISABLED; +m.attr("B_DEFAULT_BUTTON") = BControlLook::B_DEFAULT_BUTTON; +m.attr("B_IGNORE_OUTLINE") = BControlLook::B_IGNORE_OUTLINE; +m.attr("B_PARTIALLY_ACTIVATED") = BControlLook::B_PARTIALLY_ACTIVATED; +m.attr("B_FLAT") = BControlLook::B_FLAT; +m.attr("B_INVALID") = BControlLook::B_INVALID; +m.attr("B_IS_CONTROL") = BControlLook::B_IS_CONTROL; +m.attr("B_BLEND_FRAME") = BControlLook::B_BLEND_FRAME; +m.attr("B_KNOB_NONE") = BControlLook::B_KNOB_NONE; +m.attr("B_KNOB_DOTS") = BControlLook::B_KNOB_DOTS; +m.attr("B_KNOB_LINES") = BControlLook::B_KNOB_LINES;*/ + +m.attr("B_LEFT_BORDER") = 1 << 0; +m.attr("B_RIGHT_BORDER") = 1 << 1; +m.attr("B_TOP_BORDER") = 1 << 2; +m.attr("B_BOTTOM_BORDER") = 1 << 3; +m.attr("B_ALL_BORDERS") = py::int_(BControlLook::B_LEFT_BORDER | BControlLook::B_RIGHT_BORDER | BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER); +m.attr("B_LEFT_ARROW") = 0; +m.attr("B_RIGHT_ARROW") = 1; +m.attr("B_UP_ARROW") = 2; +m.attr("B_DOWN_ARROW") = 3; +m.attr("B_LEFT_UP_ARROW") = 4; +m.attr("B_RIGHT_UP_ARROW") = 5; +m.attr("B_RIGHT_DOWN_ARROW") = 6; +m.attr("B_LEFT_DOWN_ARROW") = 7; +m.attr("B_FOCUSED") = 1 << 0; +m.attr("B_CLICKED") = 1 << 1; +m.attr("B_ACTIVATED") = 1 << 2; +m.attr("B_HOVER") = 1 << 3; +m.attr("B_DISABLED") = 1 << 4; +m.attr("B_DEFAULT_BUTTON") = 1 << 5; +m.attr("B_IGNORE_OUTLINE") = 1 << 6; +m.attr("B_PARTIALLY_ACTIVATED") = 1 << 7; +m.attr("B_FLAT") = 1 << 8; +m.attr("B_INVALID") = 1 << 9; +m.attr("B_IS_CONTROL") = 1 << 10; +m.attr("B_BLEND_FRAME") = 1 << 16; +m.attr("B_KNOB_NONE") = 0; +m.attr("B_KNOB_DOTS") = 1; +m.attr("B_KNOB_LINES") = 2; + + +py::class_(m, "BControlLook") .def(py::init(), "") .def("DefaultLabelAlignment", &BControlLook::DefaultLabelAlignment, "") .def("DefaultLabelSpacing", &BControlLook::DefaultLabelSpacing, "") @@ -28,220 +585,220 @@ py::class_(m, "BControlLook") .def_static("ComposeSpacing", &BControlLook::ComposeSpacing, "", py::arg("spacing")) .def_static("ComposeIconSize", &BControlLook::ComposeIconSize, "", py::arg("size")) .def("Flags", &BControlLook::Flags, "", py::arg("control")) -.def("DrawButtonFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,const rgb_color & background,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +.def("DrawButtonFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,const rgb_color & background,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawButtonFrame(view, rect, updateRect, base, background, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawButtonFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,const rgb_color & background,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawButtonFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,const rgb_color & background,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawButtonFrame(view, rect, updateRect, radius, base, background, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawButtonFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,const rgb_color & background,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawButtonFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,const rgb_color & background,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawButtonFrame(view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, background, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawButtonBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawButtonBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { BRect rect; self.DrawButtonBackground(view, rect, updateRect, base, flags, borders, orientation); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) -.def("DrawButtonBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) +.def("DrawButtonBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { BRect rect; self.DrawButtonBackground(view, rect, updateRect, radius, base, flags, borders, orientation); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) -.def("DrawButtonBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) +.def("DrawButtonBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { BRect rect; self.DrawButtonBackground(view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, flags, borders, orientation); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) -.def("DrawMenuBarBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) +.def("DrawMenuBarBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawMenuBarBackground(view, rect, updateRect, base, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawMenuFieldFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,const rgb_color & background,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawMenuFieldFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,const rgb_color & background,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawMenuFieldFrame(view, rect, updateRect, base, background, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawMenuFieldFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,const rgb_color & background,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawMenuFieldFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,const rgb_color & background,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawMenuFieldFrame(view, rect, updateRect, radius, base, background, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawMenuFieldFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,const rgb_color & background,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawMenuFieldFrame", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,const rgb_color & background,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawMenuFieldFrame(view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, background, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,bool popupIndicator,unsigned int flags=0) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("background"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,bool popupIndicator,uint32 flags=0) { BRect rect; self.DrawMenuFieldBackground(view, rect, updateRect, base, popupIndicator, flags); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("popupIndicator"), py::arg("flags")=0) -.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,bool popupIndicator,unsigned int flags=0) { +.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,bool popupIndicator,uint32 flags=0) { BRect rect; self.DrawMenuFieldBackground(view, rect, updateRect, radius, base, popupIndicator, flags); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("popupIndicator"), py::arg("flags")=0) -.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,bool popupIndicator,unsigned int flags=0) { +.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,bool popupIndicator,uint32 flags=0) { BRect rect; self.DrawMenuFieldBackground(view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, popupIndicator, flags); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("popupIndicator"), py::arg("flags")=0) -.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +.def("DrawMenuFieldBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawMenuFieldBackground(view, rect, updateRect, base, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawMenuBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawMenuBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawMenuBackground(view, rect, updateRect, base, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawMenuItemBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawMenuItemBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawMenuItemBackground(view, rect, updateRect, base, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) .def("DrawStatusBar", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,const rgb_color & barColor,float progressPosition) { BRect rect; self.DrawStatusBar(view, rect, updateRect, base, barColor, progressPosition); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("barColor"), py::arg("progressPosition")) -.def("DrawCheckBox", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0) { +.def("DrawCheckBox", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0) { BRect rect; self.DrawCheckBox(view, rect, updateRect, base, flags); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0) -.def("DrawRadioButton", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0) { +.def("DrawRadioButton", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0) { BRect rect; self.DrawRadioButton(view, rect, updateRect, base, flags); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0) -.def("DrawScrollBarBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags,orientation orientation) { +.def("DrawScrollBarBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags,orientation orientation) { BRect rect1; BRect rect2; self.DrawScrollBarBackground(view, rect1, rect2, updateRect, base, flags, orientation); return std::make_tuple(rect1,rect2); } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("orientation")) -.def("DrawScrollBarBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags,orientation orientation) { +.def("DrawScrollBarBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags,orientation orientation) { BRect rect; self.DrawScrollBarBackground(view, rect, updateRect, base, flags, orientation); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("orientation")) -.def("DrawScrollViewFrame", [](BControlLook& self,BView * view,const BRect & updateRect,BRect verticalScrollBarFrame,BRect horizontalScrollBarFrame,const rgb_color & base,border_style borderStyle,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +.def("DrawScrollViewFrame", [](BControlLook& self,BView * view,const BRect & updateRect,BRect verticalScrollBarFrame,BRect horizontalScrollBarFrame,const rgb_color & base,border_style borderStyle,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawScrollViewFrame(view, rect, updateRect, verticalScrollBarFrame, horizontalScrollBarFrame, base, borderStyle, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("verticalScrollBarFrame"), py::arg("horizontalScrollBarFrame"), py::arg("base"), py::arg("borderStyle"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawArrowShape", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int direction,unsigned int flags=0,float tint=B_DARKEN_MAX_TINT) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("verticalScrollBarFrame"), py::arg("horizontalScrollBarFrame"), py::arg("base"), py::arg("borderStyle"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawArrowShape", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 direction,uint32 flags=0,float tint=B_DARKEN_MAX_TINT) { BRect rect; self.DrawArrowShape(view, rect, updateRect, base, direction, flags, tint); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("direction"), py::arg("flags")=0, py::arg("tint")=B_DARKEN_MAX_TINT) .def("SliderBarColor", &BControlLook::SliderBarColor, "", py::arg("base")) -.def("DrawSliderBar", py::overload_cast(&BControlLook::DrawSliderBar), "", py::arg("view"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("leftFillColor"), py::arg("rightFillColor"), py::arg("sliderScale"), py::arg("flags"), py::arg("orientation")) -.def("DrawSliderBar", py::overload_cast(&BControlLook::DrawSliderBar), "", py::arg("view"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("fillColor"), py::arg("flags"), py::arg("orientation")) -.def("DrawSliderThumb", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags,orientation orientation) { +.def("DrawSliderBar", py::overload_cast(&BControlLook::DrawSliderBar), "", py::arg("view"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("leftFillColor"), py::arg("rightFillColor"), py::arg("sliderScale"), py::arg("flags"), py::arg("orientation")) +.def("DrawSliderBar", py::overload_cast(&BControlLook::DrawSliderBar), "", py::arg("view"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("fillColor"), py::arg("flags"), py::arg("orientation")) +.def("DrawSliderThumb", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags,orientation orientation) { BRect rect; self.DrawSliderThumb(view, rect, updateRect, base, flags, orientation); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("orientation")) -.def("DrawSliderTriangle", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags,orientation orientation) { +.def("DrawSliderTriangle", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags,orientation orientation) { BRect rect; self.DrawSliderTriangle(view, rect, updateRect, base, flags, orientation); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("orientation")) -.def("DrawSliderTriangle", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,const rgb_color & fill,unsigned int flags,orientation orientation) { +.def("DrawSliderTriangle", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,const rgb_color & fill,uint32 flags,orientation orientation) { BRect rect; self.DrawSliderTriangle(view, rect, updateRect, base, fill, flags, orientation); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("fill"), py::arg("flags"), py::arg("orientation")) -.def("DrawSliderHashMarks", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,int count,hash_mark_location location,unsigned int flags,orientation orientation) { +.def("DrawSliderHashMarks", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,int count,hash_mark_location location,uint32 flags,orientation orientation) { BRect rect; self.DrawSliderHashMarks(view, rect, updateRect, base, count, location, flags, orientation); return rect; } , "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("count"), py::arg("location"), py::arg("flags"), py::arg("orientation")) -.def("DrawActiveTab", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,unsigned int side=B_TOP_BORDER,int index=0,int selected=- 1,int first=0,int last=0) { +.def("DrawActiveTab", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,uint32 side=MyClass::various::B_TOP_BORDER,int index=0,int selected=- 1,int first=0,int last=0) { BRect rect; self.DrawActiveTab(view, rect, updateRect, base, flags, borders, side, index, selected, first, last); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("side")=B_TOP_BORDER, py::arg("index")=0, py::arg("selected")=- 1, py::arg("first")=0, py::arg("last")=0) -.def("DrawInactiveTab", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,unsigned int side=B_TOP_BORDER,int index=0,int selected=- 1,int first=0,int last=0) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("side")=MyClass::various::B_TOP_BORDER, py::arg("index")=0, py::arg("selected")=- 1, py::arg("first")=0, py::arg("last")=0) +.def("DrawInactiveTab", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,uint32 side=MyClass::various::B_TOP_BORDER,int index=0,int selected=- 1,int first=0,int last=0) { BRect rect; self.DrawInactiveTab(view, rect, updateRect, base, flags, borders, side, index, selected, first, last); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("side")=B_TOP_BORDER, py::arg("index")=0, py::arg("selected")=- 1, py::arg("first")=0, py::arg("last")=0) -.def("DrawSplitter", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,orientation orientation,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("side")=MyClass::various::B_TOP_BORDER, py::arg("index")=0, py::arg("selected")=- 1, py::arg("first")=0, py::arg("last")=0) +.def("DrawSplitter", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,orientation orientation,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawSplitter(view, rect, updateRect, base, orientation, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("orientation"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawBorder", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,border_style borderStyle,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("orientation"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawBorder", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,border_style borderStyle,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawBorder(view, rect, updateRect, base, borderStyle, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("borderStyle"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawRaisedBorder", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("borderStyle"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawRaisedBorder", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawRaisedBorder(view, rect, updateRect, base, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawGroupFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawGroupFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawGroupFrame(view, rect, updateRect, base, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("borders")=B_ALL_BORDERS) -.def("DrawTextControlBorder", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawTextControlBorder", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS) { BRect rect; self.DrawTextControlBorder(view, rect, updateRect, base, flags, borders); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS) -.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("textColor")=NULL) -.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("alignment"), py::arg("textColor")=NULL) -.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("base"), py::arg("flags"), py::arg("where"), py::arg("textColor")=NULL) -.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("icon"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("textColor")=NULL) -.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("icon"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("alignment"), py::arg("textColor")=NULL) -.def("GetFrameInsets", [](BControlLook& self,frame_type frameType,unsigned int flags) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS) +.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("textColor")=NULL) +.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("alignment"), py::arg("textColor")=NULL) +.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("base"), py::arg("flags"), py::arg("where"), py::arg("textColor")=NULL) +.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("icon"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("textColor")=NULL) +.def("DrawLabel", py::overload_cast(&BControlLook::DrawLabel), "", py::arg("view"), py::arg("label"), py::arg("icon"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("alignment"), py::arg("textColor")=NULL) +.def("GetFrameInsets", [](BControlLook& self,BControlLook::frame_type frameType,uint32 flags) { float _left; float _top; float _right; @@ -250,7 +807,7 @@ float _bottom; return std::make_tuple(_left,_top,_right,_bottom); } , "", py::arg("frameType"), py::arg("flags")) -.def("GetBackgroundInsets", [](BControlLook& self,background_type backgroundType,unsigned int flags) { +.def("GetBackgroundInsets", [](BControlLook& self,BControlLook::background_type backgroundType,uint32 flags) { float _left; float _top; float _right; @@ -259,7 +816,7 @@ float _bottom; return std::make_tuple(_left,_top,_right,_bottom); } , "", py::arg("backgroundType"), py::arg("flags")) -.def("GetInsets", [](BControlLook& self,frame_type frameType,background_type backgroundType,unsigned int flags) { +.def("GetInsets", [](BControlLook& self,BControlLook::frame_type frameType,BControlLook::background_type backgroundType,uint32 flags) { float _left; float _top; float _right; @@ -268,43 +825,47 @@ float _bottom; return std::make_tuple(_left,_top,_right,_bottom); } , "", py::arg("frameType"), py::arg("backgroundType"), py::arg("flags")) -.def("DrawButtonWithPopUpBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { +.def("DrawButtonWithPopUpBackground", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { BRect rect; self.DrawButtonWithPopUpBackground(view, rect, updateRect, base, flags, borders, orientation); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) -.def("DrawButtonWithPopUpBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) +.def("DrawButtonWithPopUpBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float radius,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { BRect rect; self.DrawButtonWithPopUpBackground(view, rect, updateRect, radius, base, flags, borders, orientation); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) -.def("DrawButtonWithPopUpBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { +, "", py::arg("view"), py::arg("updateRect"), py::arg("radius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) +.def("DrawButtonWithPopUpBackground", [](BControlLook& self,BView * view,const BRect & updateRect,float leftTopRadius,float rightTopRadius,float leftBottomRadius,float rightBottomRadius,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,orientation orientation=B_HORIZONTAL) { BRect rect; self.DrawButtonWithPopUpBackground(view, rect, updateRect, leftTopRadius, rightTopRadius, leftBottomRadius, rightBottomRadius, base, flags, borders, orientation); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) +, "", py::arg("view"), py::arg("updateRect"), py::arg("leftTopRadius"), py::arg("rightTopRadius"), py::arg("leftBottomRadius"), py::arg("rightBottomRadius"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("orientation")=B_HORIZONTAL) .def("SetBackgroundInfo", &BControlLook::SetBackgroundInfo, "", py::arg("backgroundInfo")) -.def("DrawTabFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags=0,unsigned int borders=B_ALL_BORDERS,border_style borderStyle=B_FANCY_BORDER,unsigned int side=B_TOP_BORDER) { +.def("DrawTabFrame", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags=0,uint32 borders=MyClass::various::B_ALL_BORDERS,border_style borderStyle=B_FANCY_BORDER,uint32 side=MyClass::various::B_TOP_BORDER) { BRect rect; self.DrawTabFrame(view, rect, updateRect, base, flags, borders, borderStyle, side); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=B_ALL_BORDERS, py::arg("borderStyle")=B_FANCY_BORDER, py::arg("side")=B_TOP_BORDER) +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags")=0, py::arg("borders")=MyClass::various::B_ALL_BORDERS, py::arg("borderStyle")=B_FANCY_BORDER, py::arg("side")=MyClass::various::B_TOP_BORDER) .def("DrawScrollBarButton", &BControlLook::DrawScrollBarButton, "", py::arg("view"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("direction"), py::arg("orientation"), py::arg("down")=false) -.def("DrawScrollBarThumb", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,unsigned int flags,orientation orientation,unsigned int knobStyle=B_KNOB_NONE) { +.def("DrawScrollBarThumb", [](BControlLook& self,BView * view,const BRect & updateRect,const rgb_color & base,uint32 flags,orientation orientation,uint32 knobStyle=MyClass::various::B_KNOB_NONE) { BRect rect; self.DrawScrollBarThumb(view, rect, updateRect, base, flags, orientation, knobStyle); return rect; } -, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("orientation"), py::arg("knobStyle")=B_KNOB_NONE) +, "", py::arg("view"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("orientation"), py::arg("knobStyle")=MyClass::various::B_KNOB_NONE) .def("DrawScrollBarBorder", &BControlLook::DrawScrollBarBorder, "", py::arg("view"), py::arg("rect"), py::arg("updateRect"), py::arg("base"), py::arg("flags"), py::arg("orientation")) .def("GetScrollBarWidth", &BControlLook::GetScrollBarWidth, "", py::arg("orientation")=B_VERTICAL) .def_static("ShouldDraw", &BControlLook::ShouldDraw, "", py::arg("view"), py::arg("rect"), py::arg("updateRect")) ; -m.def("instantiate_control_look", &instantiate_control_look, "", py::arg("id")); +//m.attr("BControlLook") = BControlLook; + +//m.attr("be_control_look") = be_control_look; +//m.attr("be_control_look") = be_control_look; +//m.def("instantiate_control_look", &instantiate_control_look, "", py::arg("id")); //resolve symbol "instantiate_control_look" returned: -2147478780 } diff --git a/bindings/interface/Deskbar.cpp b/bindings/interface/Deskbar.cpp index 13b5fab..3dcc8c7 100644 --- a/bindings/interface/Deskbar.cpp +++ b/bindings/interface/Deskbar.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace py = pybind11; @@ -34,16 +35,16 @@ py::class_(m, "BDeskbar") .def("SetAutoRaise", &BDeskbar::SetAutoRaise, "", py::arg("autoRaise")) .def("IsAutoHide", &BDeskbar::IsAutoHide, "") .def("SetAutoHide", &BDeskbar::SetAutoHide, "", py::arg("autoHide")) -.def("GetItemInfo", py::overload_cast(&BDeskbar::GetItemInfo), "", py::arg("id"), py::arg("_name")) -.def("GetItemInfo", py::overload_cast(&BDeskbar::GetItemInfo), "", py::arg("name"), py::arg("_id")) -.def("HasItem", py::overload_cast(&BDeskbar::HasItem), "", py::arg("id")) -.def("HasItem", py::overload_cast(&BDeskbar::HasItem), "", py::arg("name")) +//.def("GetItemInfo", py::overload_cast(&BDeskbar::GetItemInfo, py::const_), "", py::arg("id"), py::arg("_name")) +.def("GetItemInfo", py::overload_cast(&BDeskbar::GetItemInfo, py::const_), "", py::arg("name"), py::arg("_id")) +.def("HasItem", py::overload_cast(&BDeskbar::HasItem, py::const_), "", py::arg("id")) +.def("HasItem", py::overload_cast(&BDeskbar::HasItem, py::const_), "", py::arg("name")) .def("CountItems", &BDeskbar::CountItems, "") .def("MaxItemWidth", &BDeskbar::MaxItemWidth, "") .def("MaxItemHeight", &BDeskbar::MaxItemHeight, "") -.def("AddItem", py::overload_cast(&BDeskbar::AddItem), "", py::arg("archivableView"), py::arg("_id")=NULL) -.def("AddItem", py::overload_cast(&BDeskbar::AddItem), "", py::arg("addOn"), py::arg("_id")=NULL) -.def("RemoveItem", py::overload_cast(&BDeskbar::RemoveItem), "", py::arg("id")) +.def("AddItem", py::overload_cast(&BDeskbar::AddItem), "", py::arg("archivableView"), py::arg("_id")=NULL) +.def("AddItem", py::overload_cast(&BDeskbar::AddItem), "", py::arg("addOn"), py::arg("_id")=NULL) +.def("RemoveItem", py::overload_cast(&BDeskbar::RemoveItem), "", py::arg("id")) .def("RemoveItem", py::overload_cast(&BDeskbar::RemoveItem), "", py::arg("name")) ; diff --git a/bindings/interface/Dragger.cpp b/bindings/interface/Dragger.cpp index 67811af..6706a80 100644 --- a/bindings/interface/Dragger.cpp +++ b/bindings/interface/Dragger.cpp @@ -7,15 +7,80 @@ #include #include #include +#include +#include namespace py = pybind11; using namespace BPrivate; +class PyBDragger : public BDragger { +public: + using BDragger::BDragger; + + status_t Archive(BMessage* data, bool deep = true) const override { + PYBIND11_OVERRIDE_PURE(status_t, BDragger, Archive, data, deep); + } + void AttachedToWindow() override { + PYBIND11_OVERRIDE_PURE(void, BDragger, AttachedToWindow); + } + void DetachedFromWindow() override { + PYBIND11_OVERRIDE_PURE(void, BDragger, DetachedFromWindow); + } + void Draw(BRect updateRect) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, Draw, updateRect); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, MouseDown, where); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, MouseUp, where); + } + void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, MouseMoved, where, transit, dragMessage); + } + void MessageReceived(BMessage* message) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, MessageReceived, message); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, FrameResized, newWidth, newHeight); + } + BHandler* ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, int32 form, const char* property) override { + PYBIND11_OVERRIDE_PURE(BHandler*, BDragger, ResolveSpecifier, message, index, specifier, form, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERRIDE_PURE(status_t, BDragger, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERRIDE_PURE(status_t, BDragger, Perform, code, data); + } + void ResizeToPreferred() override { + PYBIND11_OVERRIDE_PURE(void, BDragger, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, GetPreferredSize, _width, _height); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERRIDE_PURE(void, BDragger, MakeFocus, focus); + } + void AllAttached() override { + PYBIND11_OVERRIDE_PURE(void, BDragger, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERRIDE_PURE(void, BDragger, AllDetached); + } + BBitmap* DragBitmap(BPoint* offset, drawing_mode* mode) override { + PYBIND11_OVERRIDE_PURE(BBitmap*, BDragger, DragBitmap, offset, mode); + } +}; + PYBIND11_MODULE(Dragger,m) { -m.attr("replicant_data") = replicant_data; +//m.attr("replicant_data") = replicant_data; -m.attr("ShelfContainerViewFilter") = ShelfContainerViewFilter; +//m.attr("ShelfContainerViewFilter") = ShelfContainerViewFilter; py::class_(m, "BDragger") .def(py::init(), "", py::arg("frame"), py::arg("target"), py::arg("resizingMode")=B_FOLLOW_NONE, py::arg("flags")=B_WILL_DRAW) @@ -48,7 +113,7 @@ py::class_(m, "BDragger") .def("InShelf", &BDragger::InShelf, "") .def("Target", &BDragger::Target, "") .def("DragBitmap", &BDragger::DragBitmap, "", py::arg("offset"), py::arg("mode")) -.def_readwrite("Private", &BDragger::Private, "") +//.def_readwrite("Private", &BDragger::Private, "") ; diff --git a/bindings/interface/Font.cpp b/bindings/interface/Font.cpp index a76c0f2..7a82720 100644 --- a/bindings/interface/Font.cpp +++ b/bindings/interface/Font.cpp @@ -2,15 +2,52 @@ #include #include #include +#include #include #include #include +#include #include #include namespace py = pybind11; +/* +py::list GetHasGlyphsWrapper1(BFont& self, std::vector charArray, int32 numChars) { + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get()); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + + return hasArray; +} +py::list GetHasGlyphsWrapper2(BFont& self, std::vector charArray, int32 numChars, bool useFallbacks){ + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get(), useFallbacks); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + + return hasArray; +}*/ PYBIND11_MODULE(Font,m) { @@ -91,22 +128,26 @@ py::class_(m, "unicode_block_range") ; py::class_(m, "edge_info") +.def(py::init(), "") .def_readwrite("left", &edge_info::left, "") .def_readwrite("right", &edge_info::right, "") ; py::class_(m, "font_height") +.def(py::init(), "") .def_readwrite("ascent", &font_height::ascent, "") .def_readwrite("descent", &font_height::descent, "") .def_readwrite("leading", &font_height::leading, "") ; py::class_(m, "escapement_delta") +.def(py::init(), "") .def_readwrite("nonspace", &escapement_delta::nonspace, "") .def_readwrite("space", &escapement_delta::space, "") ; py::class_(m, "font_cache_info") +.def(py::init(), "") .def_readwrite("sheared_font_penalty", &font_cache_info::sheared_font_penalty, "") .def_readwrite("rotated_font_penalty", &font_cache_info::rotated_font_penalty, "") .def_readwrite("oversize_threshold", &font_cache_info::oversize_threshold, "") @@ -116,6 +157,7 @@ py::class_(m, "font_cache_info") ; py::class_(m, "tuned_font_info") +.def(py::init(), "") .def_readwrite("size", &tuned_font_info::size, "") .def_readwrite("shear", &tuned_font_info::shear, "") .def_readwrite("rotation", &tuned_font_info::rotation, "") @@ -128,7 +170,7 @@ py::class_(m, "BFont") .def(py::init(), "", py::arg("font")) .def(py::init(), "", py::arg("font")) .def("SetFamilyAndStyle", py::overload_cast(&BFont::SetFamilyAndStyle), "", py::arg("family"), py::arg("style")) -.def("SetFamilyAndStyle", py::overload_cast(&BFont::SetFamilyAndStyle), "", py::arg("code")) +.def("SetFamilyAndStyle", py::overload_cast(&BFont::SetFamilyAndStyle), "", py::arg("code")) .def("SetFamilyAndFace", &BFont::SetFamilyAndFace, "", py::arg("family"), py::arg("face")) .def("SetSize", &BFont::SetSize, "", py::arg("size")) .def("SetShear", &BFont::SetShear, "", py::arg("shear")) @@ -139,6 +181,34 @@ py::class_(m, "BFont") .def("SetFace", &BFont::SetFace, "", py::arg("face")) .def("SetFlags", &BFont::SetFlags, "", py::arg("flags")) //.def("GetFamilyAndStyle", &BFont::GetFamilyAndStyle, "", py::arg("family"), py::arg("style")) + +.def("GetFamilyAndStyle", [](BFont &self) -> py::tuple { + font_family family; + font_style style; + + // Chiamata alla funzione GetFamilyAndStyle della classe BFont + self.GetFamilyAndStyle(&family, &style); + + // Converte i dati in stringhe Python + //std::string familyStr(family); + //std::string styleStr(style); + + // Restituisci una tupla di stringhe + //return std::make_tuple(familyStr, styleStr); + return py::make_tuple(family, style); +},"") +/* +.def("GetFamilyAndStyle", [](BFont &self, std::string &family, std::string &style) -> py::tuple { + font_family famil; + font_style styl; + + self.GetFamilyAndStyle(&famil, &styl); + + family = std::string(famil, strnlen(famil, B_FONT_FAMILY_LENGTH)); + style = std::string(styl, strnlen(styl, B_FONT_STYLE_LENGTH)); + + return py::make_tuple(family, style); +}, "", py::arg("family"), py::arg("style"))*/ .def("FamilyAndStyle", &BFont::FamilyAndStyle, "") .def("Size", &BFont::Size, "") .def("Shear", &BFont::Shear, "") @@ -159,13 +229,40 @@ py::class_(m, "BFont") .def("GetTunedInfo", &BFont::GetTunedInfo, "", py::arg("index"), py::arg("info")) .def("TruncateString", &BFont::TruncateString, "", py::arg("inOut"), py::arg("mode"), py::arg("width")) //.def("GetTruncatedStrings", py::overload_cast(&BFont::GetTruncatedStrings, py::const_), "", py::arg("stringArray"), py::arg("numStrings"), py::arg("mode"), py::arg("width"), py::arg("resultArray")) +.def("GetTruncatedStrings", [](BFont& self, std::vector stringArray, uint32 mode,float width)->std::vector{ + //BString resArray[stringArray.size()]; + std::vector resArray(stringArray.size()); + self.GetTruncatedStrings(stringArray.data(),stringArray.size(),mode,width,resArray.data()); + return resArray; +},"", py::arg("stringArray"),py::arg("mode"), py::arg("width")) +/*This below compiles but don't returns values we should return as function return value like "return resultArray;" +.def("GetTruncatedStrings", [](BFont& self, std::vector stringArray, uint32 mode, float width, std::vector& resultArray) { + // Chiamata alla funzione GetTruncatedStrings senza creare un array locale + resultArray.resize(stringArray.size()); // Assicurati che resultArray abbia la dimensione corretta + self.GetTruncatedStrings(stringArray.data(), stringArray.size(), mode, width, resultArray.data()); +}, "", py::arg("stringArray"), py::arg("mode"), py::arg("width"), py::arg("resultArray"))*/ //.def("GetTruncatedStrings", py::overload_cast(&BFont::GetTruncatedStrings, py::const_), "", py::arg("stringArray"), py::arg("numStrings"), py::arg("mode"), py::arg("width"), py::arg("resultArray")) .def("StringWidth", py::overload_cast(&BFont::StringWidth, py::const_), "", py::arg("string")) -.def("StringWidth", py::overload_cast(&BFont::StringWidth, py::const_), "", py::arg("string"), py::arg("length")) +.def("StringWidth", py::overload_cast(&BFont::StringWidth, py::const_), "", py::arg("string"), py::arg("length")) //.def("GetStringWidths", &BFont::GetStringWidths, "", py::arg("stringArray"), py::arg("lengthArray"), py::arg("numStrings"), py::arg("widthArray")) -/* -.def("GetEscapements", py::overload_cast(&BFont::GetEscapements,py::const_), "", py::arg("charArray"), py::arg("numChars"), py::arg("escapementArray")) -.def("GetEscapements", py::overload_cast(&BFont::GetEscapements,py::const_), "", py::arg("charArray"), py::arg("numChars"), py::arg("delta"), py::arg("escapementArray")) +.def("GetStringWidths", [](BFont& self, std::vector stringArray, std::vector lengthArray){ + std::vector widthArray; + widthArray.resize(stringArray.size()); + self.GetStringWidths(stringArray.data(),lengthArray.data(),stringArray.size(),widthArray.data()); + return widthArray; +},"", py::arg("stringArray"), py::arg("lengthArray")) +//.def("GetEscapements", py::overload_cast(&BFont::GetEscapements,py::const_), "", py::arg("charArray"), py::arg("numChars"), py::arg("escapementArray")) +/*.def("GetEscapements", [](BFont& self, const std::string& charArray, std::vector& escapementArray) { +// TODO: this function does not return the escapement array, or returns it empty, DON'T WORK + self.GetEscapements(charArray.c_str(), charArray.size(), escapementArray.data()); + //return escapementArray; +}, "", py::arg("charArray"), py::arg("escapementArray"))*/ +.def("GetEscapements", [](BFont& self, const char * charArray, int32 numChars){ + std::vector escapementArray(numChars); + self.GetEscapements(charArray, numChars, escapementArray.data()); + return escapementArray; +}, "", py::arg("charArray"),py::arg("numChars")) +/*.def("GetEscapements", py::overload_cast(&BFont::GetEscapements,py::const_), "", py::arg("charArray"), py::arg("numChars"), py::arg("delta"), py::arg("escapementArray")) .def("GetEscapements", py::overload_cast(&BFont::GetEscapements,py::const_), "", py::arg("charArray"), py::arg("numChars"), py::arg("delta"), py::arg("escapementArray")) .def("GetEscapements", py::overload_cast(&BFont::GetEscapements,py::const_), "", py::arg("charArray"), py::arg("numChars"), py::arg("delta"), py::arg("escapementArray"), py::arg("offsetArray")) */ @@ -174,8 +271,97 @@ py::class_(m, "BFont") .def("GetBoundingBoxesAsGlyphs", &BFont::GetBoundingBoxesAsGlyphs, "", py::arg("charArray"), py::arg("numChars"), py::arg("mode"), py::arg("boundingBoxArray")) .def("GetBoundingBoxesAsString", &BFont::GetBoundingBoxesAsString, "", py::arg("charArray"), py::arg("numChars"), py::arg("mode"), py::arg("delta"), py::arg("boundingBoxArray")) //.def("GetBoundingBoxesForStrings", &BFont::GetBoundingBoxesForStrings, "", py::arg("stringArray"), py::arg("numStrings"), py::arg("mode"), py::arg("deltas"), py::arg("boundingBoxArray")) +// TODO TEST THIS, it returns empty boundingBox array COMPILES BUT DON'T WORK +/*.def("GetBoundingBoxesForStrings", [](const BFont &self, const std::vector &stringArray, + int32 numStrings, font_metric_mode mode, + std::vector &deltas, + std::vector &boundingBoxArray) { + std::vector cStrings; + for (const auto &str : stringArray) { + cStrings.push_back(str.c_str()); + } + + std::vector& constDeltas = deltas; + std::vector& constBoundingBoxArray = boundingBoxArray; + + self.GetBoundingBoxesForStrings(cStrings.data(), numStrings, mode, constDeltas.data(), constBoundingBoxArray.data()); +},"",py::arg("stringArray"),py::arg("numStrings"),py::arg("mode"),py::arg("deltas"),py::arg("boundingBoxArray"))*/ +.def("GetBoundingBoxesForStrings", [](const BFont &self, const std::vector &stringArray, font_metric_mode mode) { + std::vector deltas(stringArray.size()); + std::vector boundingBoxArray(stringArray.size()); + + // Converte i vettori Python in array C + const char** cStringArray = new const char*[stringArray.size()]; + for (size_t i = 0; i < stringArray.size(); ++i) { + cStringArray[i] = stringArray[i].c_str(); + } + + self.GetBoundingBoxesForStrings(cStringArray, stringArray.size(), mode, deltas.data(), boundingBoxArray.data()); + + delete[] cStringArray; + return std::make_tuple(std::move(deltas), std::move(boundingBoxArray)); +},"",py::arg("stringArray"),py::arg("mode")) //.def("GetGlyphShapes", &BFont::GetGlyphShapes, "", py::arg("charArray"), py::arg("numChars"), py::arg("glyphShapeArray")) -.def("GetHasGlyphs", &BFont::GetHasGlyphs, "", py::arg("charArray"), py::arg("numChars"), py::arg("hasArray")) +.def("GetGlyphShapes", [](BFont& self, const std::string& charArray){ + py::list glyphShapeList; + std::vector glyphShapeArray(charArray.size()); + + // Since Each BShape object corresponds to the glyph of one character (this is written in Haiku-Book) + for (size_t i = 0; i < glyphShapeArray.size(); ++i) { + glyphShapeArray[i] = new BShape(); + } + + self.GetGlyphShapes(charArray.data(), charArray.size(), glyphShapeArray.data()); + + for (size_t i = 0; i < glyphShapeArray.size(); ++i) { + glyphShapeList.append(py::cast(*glyphShapeArray[i])); + } + + for (size_t i = 0; i < glyphShapeArray.size(); ++i) { + delete glyphShapeArray[i]; + } + + return glyphShapeList; +},"",py::arg("charArray")) +//.def("GetHasGlyphs", &BFont::GetHasGlyphs, "", py::arg("charArray"), py::arg("numChars"), py::arg("hasArray")) +//.def("GetHasGlyphs",&GetHasGlyphsWrapper1, "", py::arg("charArray"), py::arg("numChars")) //this works +//.def("GetHasGlyphs",&GetHasGlyphsWrapper2, "", py::arg("charArray"), py::arg("numChars"), py::arg("useFallbacks")) //this works +.def("GetHasGlyphs",[](BFont& self,std::vector charArray, int32 numChars){ + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get()); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + + return hasArray; +},"", py::arg("charArray"), py::arg("numChars")) +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +.def("GetHasGlyphs", [](BFont& self,std::vector charArray, int32 numChars, bool useFallbacks){ + py::list hasArray; + std::vector boolArray(numChars); + std::unique_ptr tempArray(new bool[numChars]); + + self.GetHasGlyphs(charArray.data(), numChars, tempArray.get(), useFallbacks); + + for (int32 i = 0; i < numChars; ++i) { + boolArray[i] = tempArray[i]; + } + + for (size_t i = 0; i < boolArray.size(); ++i) { + hasArray.append(boolArray[i]); + } + + return hasArray; +},"", py::arg("charArray"), py::arg("numChars"), py::arg("useFallbacks")) +#endif .def("operator=", &BFont::operator=, "", py::arg("font")) .def("__eq__", &BFont::operator==, "", py::arg("font")) .def("__ne__", &BFont::operator!=, "", py::arg("font")) diff --git a/bindings/interface/Gradient.cpp b/bindings/interface/Gradient.cpp index 49a3d8c..ade07e3 100644 --- a/bindings/interface/Gradient.cpp +++ b/bindings/interface/Gradient.cpp @@ -37,24 +37,39 @@ py::class_(m, "BGradient") .def("GetType", &BGradient::GetType, "") .def("MakeEmpty", &BGradient::MakeEmpty, "") .def("Flatten", &BGradient::Flatten, "", py::arg("stream")) -.def_static("Unflatten", [](BGradient& self,BDataIO * stream) { +/*.def_static("Unflatten", [](BGradient& self,BDataIO * stream) { // TODO BGradient * output; static status_t r = self.Unflatten(output, stream); return std::make_tuple(r,output); } -, "", py::arg("stream")) +, "", py::arg("stream"))*/ + +/*.def_static("Unflatten", [](BGradient& self, BGradient*& output, BDataIO * stream) { + static status_t r = self.Unflatten(output, stream); + return r; +} +, "", py::arg("output"), py::arg("stream"))*/ ; -py::class_(m, "ColorStop") +py::enum_(m, "Type") +.value("TYPE_LINEAR", BGradient::Type::TYPE_LINEAR, "") +.value("TYPE_RADIAL", BGradient::Type::TYPE_RADIAL, "") +.value("TYPE_RADIAL_FOCUS", BGradient::Type::TYPE_RADIAL_FOCUS, "") +.value("TYPE_DIAMOND", BGradient::Type::TYPE_DIAMOND, "") +.value("TYPE_CONIC", BGradient::Type::TYPE_CONIC, "") +.value("TYPE_NONE", BGradient::Type::TYPE_NONE, "") +.export_values(); + +py::class_(m, "ColorStop") .def(py::init(), "", py::arg("c"), py::arg("o")) .def(py::init(), "", py::arg("r"), py::arg("g"), py::arg("b"), py::arg("a"), py::arg("o")) -.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("other")) .def(py::init(), "") -.def("__ne__", &ColorStop::operator!=, "", py::arg("other")) -.def_readwrite("color", &ColorStop::color, "") -.def_readwrite("offset", &ColorStop::offset, "") +.def("__ne__", &BGradient::ColorStop::operator!=, "", py::arg("other")) +.def_readwrite("color", &BGradient::ColorStop::color, "") +.def_readwrite("offset", &BGradient::ColorStop::offset, "") ; - +/* py::class_(m, "union ") .def_readwrite("linear", &union ::linear, "") .def_readwrite("radial", &union ::radial, "") @@ -69,5 +84,5 @@ py::class_<>(m, "") .def_readwrite("angle", &::angle, "") ; - +*/ } diff --git a/bindings/interface/GraphicsDefs.cpp b/bindings/interface/GraphicsDefs.cpp index 150c068..e239444 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,37 +150,24 @@ 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") +.def(py::init<>(), "") .def("set_to", &rgb_color::set_to, "", py::arg("r"), py::arg("g"), py::arg("b"), py::arg("a")=255) .def("Brightness", &rgb_color::Brightness, "") +.def("IsDark", &rgb_color::IsDark, "") +.def("IsLight", &rgb_color::IsLight, "") .def("__eq__", &rgb_color::operator==, "", py::arg("other")) .def("__ne__", &rgb_color::operator!=, "", py::arg("other")) .def("operator=", &rgb_color::operator=, "", py::arg("other")) @@ -194,11 +177,14 @@ py::class_(m, "rgb_color") .def_readwrite("alpha", &rgb_color::alpha, "") ; -py::class_(m, "color_map") +py::class_(m, "color_map")//TODO: color_list,inversion_map,index_map are writable .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 +196,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 +206,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 +229,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 2ecbcac..99208fe 100644 --- a/bindings/interface/GridLayout.cpp +++ b/bindings/interface/GridLayout.cpp @@ -11,12 +11,41 @@ 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("horizontal")=py::int_(-1002), py::arg("vertical")=py::int_(-1002)) +.def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) .def(py::init(), "", py::arg("from")) .def("CountColumns", &BGridLayout::CountColumns, "") .def("CountRows", &BGridLayout::CountRows, "") @@ -39,11 +68,11 @@ py::class_(&BGridLayout::AddView), "", py::arg("child")) -.def("AddView", py::overload_cast(&BGridLayout::AddView), "", py::arg("index"), py::arg("child")) -.def("AddView", py::overload_cast(&BGridLayout::AddView), "", py::arg("child"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) +.def("AddView", py::overload_cast(&BGridLayout::AddView), "", py::arg("index"), py::arg("child")) +.def("AddView", py::overload_cast(&BGridLayout::AddView), "", py::arg("child"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) .def("AddItem", py::overload_cast(&BGridLayout::AddItem), "", py::arg("item")) -.def("AddItem", py::overload_cast(&BGridLayout::AddItem), "", py::arg("index"), py::arg("item")) -.def("AddItem", py::overload_cast(&BGridLayout::AddItem), "", py::arg("item"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) +.def("AddItem", py::overload_cast(&BGridLayout::AddItem), "", py::arg("index"), py::arg("item")) +.def("AddItem", py::overload_cast(&BGridLayout::AddItem), "", py::arg("item"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) .def("Archive", &BGridLayout::Archive, "", py::arg("into"), py::arg("deep")=true) .def_static("Instantiate", &BGridLayout::Instantiate, "", py::arg("from")) .def("Perform", &BGridLayout::Perform, "", py::arg("d"), py::arg("arg")) diff --git a/bindings/interface/GridLayoutBuilder.cpp b/bindings/interface/GridLayoutBuilder.cpp index 31b33e4..413e0b2 100644 --- a/bindings/interface/GridLayoutBuilder.cpp +++ b/bindings/interface/GridLayoutBuilder.cpp @@ -5,26 +5,38 @@ #include #include +#include namespace py = pybind11; - PYBIND11_MODULE(GridLayoutBuilder,m) { py::class_(m, "BGridLayoutBuilder") .def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("horizontal")=-1002, py::arg("vertical")=-1002) .def(py::init(), "", py::arg("layout")) .def(py::init(), "", py::arg("view")) .def("GridLayout", &BGridLayoutBuilder::GridLayout, "") -.def("GetGridLayout", &BGridLayoutBuilder::GetGridLayout, "", py::arg("_layout")) +//.def("GetGridLayout", &BGridLayoutBuilder::GetGridLayout, "", py::arg("_layout")) //TODO check this +.def("GetGridLayout", [](BGridLayoutBuilder &self) { + BGridLayout* layout = nullptr; + self.GetGridLayout(&layout); + return std::make_tuple(std::ref(self), layout); + },"") .def("View", &BGridLayoutBuilder::View, "") -.def("GetView", &BGridLayoutBuilder::GetView, "", py::arg("_view")) -.def("Add", py::overload_cast(&BGridLayoutBuilder::Add), "", py::arg("view"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) -.def("Add", py::overload_cast(&BGridLayoutBuilder::Add), "", py::arg("item"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) +//.def("GetView", &BGridLayoutBuilder::GetView, "", py::arg("_view")) // TODO check this +.def("GetView", [](BGridLayoutBuilder &self) { + BView* view = nullptr; + self.GetView(&view); + return std::make_tuple(std::ref(self), view); + },"") +.def("Add", py::overload_cast(&BGridLayoutBuilder::Add), "", py::arg("view"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) +.def("Add", py::overload_cast(&BGridLayoutBuilder::Add), "", py::arg("item"), py::arg("column"), py::arg("row"), py::arg("columnCount")=1, py::arg("rowCount")=1) .def("SetColumnWeight", &BGridLayoutBuilder::SetColumnWeight, "", py::arg("column"), py::arg("weight")) .def("SetRowWeight", &BGridLayoutBuilder::SetRowWeight, "", py::arg("row"), py::arg("weight")) .def("SetInsets", &BGridLayoutBuilder::SetInsets, "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom")) -.def("operatorBGridLayout*", &BGridLayoutBuilder::operatorBGridLayout*, "") +//.def("operatorBGridLayout*", &BGridLayoutBuilder::operatorBGridLayout*, "") +.def("__call__", &BGridLayoutBuilder::operator BGridLayout *, "") ; diff --git a/bindings/interface/GridView.cpp b/bindings/interface/GridView.cpp index 98a4507..7027f56 100644 --- a/bindings/interface/GridView.cpp +++ b/bindings/interface/GridView.cpp @@ -10,11 +10,24 @@ namespace py = pybind11; +class PyBGridView : public BGridView{ + public: + using BGridView::BGridView; + void SetLayout(BLayout* layout) override { + PYBIND11_OVERLOAD(void, BGridView, SetLayout, layout); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BGridView, Perform, d, arg); + } +}; + PYBIND11_MODULE(GridView,m) { -py::class_(m, "BGridView") +py::class_(m, "BGridView") .def(py::init(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("horizontal")=-1002, py::arg("vertical")=-1002) .def(py::init(), "", py::arg("name"), py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("name"), py::arg("horizontal")=-1002, py::arg("vertical")=-1002) .def(py::init(), "", py::arg("from")) .def("SetLayout", &BGridView::SetLayout, "", py::arg("layout")) .def("GridLayout", &BGridView::GridLayout, "") diff --git a/bindings/interface/GroupLayout.cpp b/bindings/interface/GroupLayout.cpp index 8b84ab9..3cbd3c8 100644 --- a/bindings/interface/GroupLayout.cpp +++ b/bindings/interface/GroupLayout.cpp @@ -5,14 +5,50 @@ #include #include +#include namespace py = pybind11; +class PyBGroupLayout : public BGroupLayout{ + public: + using BGroupLayout::BGroupLayout; + BLayoutItem* AddView(BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BGroupLayout, AddView, child); + } + BLayoutItem* AddView(int32 index, BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BGroupLayout, AddView, index, child); + } + BLayoutItem* AddView(BView* child, float weight) override { + PYBIND11_OVERLOAD(BLayoutItem*, BGroupLayout, AddView, child, weight); + } + BLayoutItem* AddView(int32 index, BView* child, float weight) override { + PYBIND11_OVERLOAD(BLayoutItem*, BGroupLayout, AddView, index, child, weight); + } + bool AddItem(BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BGroupLayout, AddItem, item); + } + bool AddItem(int32 index, BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BGroupLayout, AddItem, index, item); + } + bool AddItem(BLayoutItem* item, float weight) override { + PYBIND11_OVERLOAD(bool, BGroupLayout, AddItem, item, weight); + } + bool AddItem(int32 index, BLayoutItem* item, float weight) override { + PYBIND11_OVERLOAD(bool, BGroupLayout, AddItem, index, item, weight); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BGroupLayout, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BGroupLayout, Perform, d, arg); + } +}; PYBIND11_MODULE(GroupLayout,m) { -py::class_(m, "BGroupLayout") -.def(py::init(), "", py::arg("orientation"), py::arg("spacing")=B_USE_DEFAULT_SPACING) +py::class_(m, "BGroupLayout") +//.def(py::init(), "", py::arg("orientation"), py::arg("spacing")=B_USE_DEFAULT_SPACING) +.def(py::init(), "", py::arg("orientation"), py::arg("spacing")=-1002) .def(py::init(), "", py::arg("from")) .def("Spacing", &BGroupLayout::Spacing, "") .def("SetSpacing", &BGroupLayout::SetSpacing, "", py::arg("spacing")) @@ -21,13 +57,13 @@ py::class_(m, "BGroupLayout") .def("ItemWeight", &BGroupLayout::ItemWeight, "", py::arg("index")) .def("SetItemWeight", &BGroupLayout::SetItemWeight, "", py::arg("index"), py::arg("weight")) .def("AddView", py::overload_cast(&BGroupLayout::AddView), "", py::arg("child")) -.def("AddView", py::overload_cast(&BGroupLayout::AddView), "", py::arg("index"), py::arg("child")) +.def("AddView", py::overload_cast(&BGroupLayout::AddView), "", py::arg("index"), py::arg("child")) .def("AddView", py::overload_cast(&BGroupLayout::AddView), "", py::arg("child"), py::arg("weight")) -.def("AddView", py::overload_cast(&BGroupLayout::AddView), "", py::arg("index"), py::arg("child"), py::arg("weight")) +.def("AddView", py::overload_cast(&BGroupLayout::AddView), "", py::arg("index"), py::arg("child"), py::arg("weight")) .def("AddItem", py::overload_cast(&BGroupLayout::AddItem), "", py::arg("item")) -.def("AddItem", py::overload_cast(&BGroupLayout::AddItem), "", py::arg("index"), py::arg("item")) +.def("AddItem", py::overload_cast(&BGroupLayout::AddItem), "", py::arg("index"), py::arg("item")) .def("AddItem", py::overload_cast(&BGroupLayout::AddItem), "", py::arg("item"), py::arg("weight")) -.def("AddItem", py::overload_cast(&BGroupLayout::AddItem), "", py::arg("index"), py::arg("item"), py::arg("weight")) +.def("AddItem", py::overload_cast(&BGroupLayout::AddItem), "", py::arg("index"), py::arg("item"), py::arg("weight")) .def("Archive", &BGroupLayout::Archive, "", py::arg("into"), py::arg("deep")=true) .def_static("Instantiate", &BGroupLayout::Instantiate, "", py::arg("from")) .def("Perform", &BGroupLayout::Perform, "", py::arg("d"), py::arg("arg")) diff --git a/bindings/interface/GroupLayoutBuilder.cpp b/bindings/interface/GroupLayoutBuilder.cpp index 32edc1f..dbfe39a 100644 --- a/bindings/interface/GroupLayoutBuilder.cpp +++ b/bindings/interface/GroupLayoutBuilder.cpp @@ -15,23 +15,36 @@ PYBIND11_MODULE(GroupLayoutBuilder,m) { py::class_(m, "BGroupLayoutBuilder") .def(py::init(), "", py::arg("orientation")=B_HORIZONTAL, py::arg("spacing")=B_USE_DEFAULT_SPACING) +//.def(py::init(), "", py::arg("orientation")=B_HORIZONTAL, py::arg("spacing")=-1002) .def(py::init(), "", py::arg("layout")) .def(py::init(), "", py::arg("view")) .def("RootLayout", &BGroupLayoutBuilder::RootLayout, "") .def("TopLayout", &BGroupLayoutBuilder::TopLayout, "") -.def("GetTopLayout", &BGroupLayoutBuilder::GetTopLayout, "", py::arg("_layout")) +//.def("GetTopLayout", &BGroupLayoutBuilder::GetTopLayout, "", py::arg("_layout")) //TODO +.def("GetTopLayout", [](BGroupLayoutBuilder &self){ + BGroupLayout* layout = nullptr; + self.GetTopLayout(&layout); + return std::make_tuple(std::ref(self), layout); +},"") .def("TopView", &BGroupLayoutBuilder::TopView, "") -.def("GetTopView", &BGroupLayoutBuilder::GetTopView, "", py::arg("_view")) +//.def("GetTopView", &BGroupLayoutBuilder::GetTopView, "", py::arg("_view")) //TODO +.def("GetTopView", [](BGroupLayoutBuilder &self) { + BView* view = nullptr; + self.GetTopView(&view); + return std::make_tuple(std::ref(self), view); + },"") .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("view")) .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("view"), py::arg("weight")) .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("item")) .def("Add", py::overload_cast(&BGroupLayoutBuilder::Add), "", py::arg("item"), py::arg("weight")) -.def("AddGroup", &BGroupLayoutBuilder::AddGroup, "", py::arg("orientation"), py::arg("spacing")=B_USE_DEFAULT_SPACING, py::arg("weight")=1.0 f) +.def("AddGroup", &BGroupLayoutBuilder::AddGroup, "", py::arg("orientation"), py::arg("spacing")=B_USE_DEFAULT_SPACING, py::arg("weight")=1.0f) +//.def("AddGroup", &BGroupLayoutBuilder::AddGroup, "", py::arg("orientation"), py::arg("spacing")=-1002, py::arg("weight")=1.0f) .def("End", &BGroupLayoutBuilder::End, "") -.def("AddGlue", &BGroupLayoutBuilder::AddGlue, "", py::arg("weight")=1.0 f) +.def("AddGlue", &BGroupLayoutBuilder::AddGlue, "", py::arg("weight")=1.0f) .def("AddStrut", &BGroupLayoutBuilder::AddStrut, "", py::arg("size")) .def("SetInsets", &BGroupLayoutBuilder::SetInsets, "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom")) -.def("operatorBGroupLayout*", &BGroupLayoutBuilder::operatorBGroupLayout*, "") +//.def("operatorBGroupLayout*", &BGroupLayoutBuilder::operatorBGroupLayout*, "") +.def("__call__", &BGroupLayoutBuilder::operator BGroupLayout *, "") ; diff --git a/bindings/interface/IconUtils.cpp b/bindings/interface/IconUtils.cpp index 3f6a224..0cbcf75 100644 --- a/bindings/interface/IconUtils.cpp +++ b/bindings/interface/IconUtils.cpp @@ -5,21 +5,22 @@ #include #include +#include namespace py = pybind11; PYBIND11_MODULE(IconUtils,m) { -py::class_(m, "BIconUtils") +py::class_>(m, "BIconUtils") .def_static("GetIcon", &BIconUtils::GetIcon, "", py::arg("node"), py::arg("vectorIconAttrName"), py::arg("smallIconAttrName"), py::arg("largeIconAttrName"), py::arg("size"), py::arg("result")) .def_static("GetVectorIcon", py::overload_cast(&BIconUtils::GetVectorIcon), "", py::arg("node"), py::arg("attrName"), py::arg("result")) -.def_static("GetVectorIcon", py::overload_cast(&BIconUtils::GetVectorIcon), "", py::arg("buffer"), py::arg("size"), py::arg("result")) +.def_static("GetVectorIcon", py::overload_cast(&BIconUtils::GetVectorIcon), "", py::arg("buffer"), py::arg("size"), py::arg("result")) .def_static("GetCMAP8Icon", &BIconUtils::GetCMAP8Icon, "", py::arg("node"), py::arg("smallIconAttrName"), py::arg("largeIconAttrName"), py::arg("size"), py::arg("icon")) .def_static("ConvertFromCMAP8", py::overload_cast(&BIconUtils::ConvertFromCMAP8), "", py::arg("source"), py::arg("result")) .def_static("ConvertToCMAP8", py::overload_cast(&BIconUtils::ConvertToCMAP8), "", py::arg("source"), py::arg("result")) -.def_static("ConvertFromCMAP8", py::overload_cast(&BIconUtils::ConvertFromCMAP8), "", py::arg("data"), py::arg("width"), py::arg("height"), py::arg("bytesPerRow"), py::arg("result")) -.def_static("ConvertToCMAP8", py::overload_cast(&BIconUtils::ConvertToCMAP8), "", py::arg("data"), py::arg("width"), py::arg("height"), py::arg("bytesPerRow"), py::arg("result")) +.def_static("ConvertFromCMAP8", py::overload_cast(&BIconUtils::ConvertFromCMAP8), "", py::arg("data"), py::arg("width"), py::arg("height"), py::arg("bytesPerRow"), py::arg("result")) +.def_static("ConvertToCMAP8", py::overload_cast(&BIconUtils::ConvertToCMAP8), "", py::arg("data"), py::arg("width"), py::arg("height"), py::arg("bytesPerRow"), py::arg("result")) ; diff --git a/bindings/interface/Input.cpp b/bindings/interface/Input.cpp index f8bbc5d..1ef7808 100644 --- a/bindings/interface/Input.cpp +++ b/bindings/interface/Input.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace py = pybind11; @@ -37,10 +38,10 @@ py::class_(m, "BInputDevice") .def("IsRunning", &BInputDevice::IsRunning, "") .def("Start", py::overload_cast<>(&BInputDevice::Start), "") .def("Stop", py::overload_cast<>(&BInputDevice::Stop), "") -.def("Control", py::overload_cast(&BInputDevice::Control), "", py::arg("code"), py::arg("message")) -.def_static("Start", py::overload_cast(&BInputDevice::Start), "", py::arg("type")) -.def_static("Stop", py::overload_cast(&BInputDevice::Stop), "", py::arg("type")) -.def_static("Control", py::overload_cast(&BInputDevice::Control), "", py::arg("type"), py::arg("code"), py::arg("message")) +.def("Control", py::overload_cast(&BInputDevice::Control), "", py::arg("code"), py::arg("message")) +.def_static("Start_static", py::overload_cast(&BInputDevice::Start), "", py::arg("type")) +.def_static("Stop_static", py::overload_cast(&BInputDevice::Stop), "", py::arg("type")) +.def_static("Control_static", py::overload_cast(&BInputDevice::Control), "", py::arg("type"), py::arg("code"), py::arg("message")) ; m.def("find_input_device", &find_input_device, "", py::arg("name")); diff --git a/bindings/interface/InterfaceDefs.cpp b/bindings/interface/InterfaceDefs.cpp index 8eff5fb..4121527 100644 --- a/bindings/interface/InterfaceDefs.cpp +++ b/bindings/interface/InterfaceDefs.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ namespace py = pybind11; PYBIND11_MODULE(InterfaceDefs,m) { -m.attr("B_BACKSPACE") = 8; +/*m.attr("B_BACKSPACE") = 8; m.attr("B_RETURN") = 10; m.attr("B_ENTER") = 10; m.attr("B_SPACE") = 32; @@ -37,6 +38,28 @@ m.attr("B_FUNCTION_KEY") = 16; m.attr("B_KATAKANA_HIRAGANA") = 242; m.attr("B_HANKAKU_ZENKAKU") = 243; m.attr("B_HANGUL") = 240; +m.attr("B_HANGUL_HANJA") = 241;*/ +m.attr("B_BACKSPACE") = 0x08; +m.attr("B_RETURN") = 0x0a; +m.attr("B_ENTER") = 0x0a; +m.attr("B_SPACE") = 0x20; +m.attr("B_TAB") = 0x09; +m.attr("B_ESCAPE") = 0x1b; +m.attr("B_SUBSTITUTE") = 0x1a; +m.attr("B_LEFT_ARROW") = 0x1c; +m.attr("B_RIGHT_ARROW") = 0x1d; +m.attr("B_UP_ARROW") = 0x1e; +m.attr("B_DOWN_ARROW") = 0x1f; +m.attr("B_INSERT") = 0x05; +m.attr("B_DELETE") = 0x7f; +m.attr("B_HOME") = 0x01; +m.attr("B_END") = 0x04; +m.attr("B_PAGE_UP") = 0x0b; +m.attr("B_PAGE_DOWN") = 0x0c; +m.attr("B_FUNCTION_KEY") = 0x10; +m.attr("B_KATAKANA_HIRAGANA") = 0xf2; +m.attr("B_HANKAKU_ZENKAKU") = 0xf3; +m.attr("B_HANGUL") = 240; m.attr("B_HANGUL_HANJA") = 241; m.attr("B_F1_KEY") = 2; @@ -130,6 +153,8 @@ py::enum_(m, "vertical_alignment", "") .value("B_ALIGN_USE_FULL_HEIGHT", vertical_alignment::B_ALIGN_USE_FULL_HEIGHT, "") .export_values(); +// WHY ARE THESE ASSIGNED AS STRINGS? +/* m.attr("B_USE_DEFAULT_SPACING") = "- 1002"; m.attr("B_USE_ITEM_SPACING") = "- 1003"; m.attr("B_USE_ITEM_INSETS") = "B_USE_ITEM_SPACING"; @@ -145,6 +170,42 @@ m.attr("B_USE_BIG_SPACING") = "- 1008"; m.attr("B_USE_BIG_INSETS") = "B_USE_BIG_SPACING"; m.attr("B_USE_BORDER_SPACING") = "- 1009"; m.attr("B_USE_BORDER_INSETS") = "B_USE_BORDER_SPACING"; +*/ +/* +m.attr("B_USE_DEFAULT_SPACING") = -1002; +m.attr("B_USE_ITEM_SPACING") = -1003; +m.attr("B_USE_ITEM_INSETS") = -1003; +m.attr("B_USE_HALF_ITEM_SPACING") = -1004; +m.attr("B_USE_HALF_ITEM_INSETS") = -1004; +m.attr("B_USE_WINDOW_SPACING") = -1005; +m.attr("B_USE_WINDOW_INSETS") = -1005; +m.attr("B_USE_SMALL_SPACING") = -1006; +m.attr("B_USE_SMALL_INSETS") = -1006; +m.attr("B_USE_CORNER_SPACING") = -1007; +m.attr("B_USE_CORNER_INSETS") = -1007; +m.attr("B_USE_BIG_SPACING") = -1008; +m.attr("B_USE_BIG_INSETS") = -1008; +m.attr("B_USE_BORDER_SPACING") = -1009; +m.attr("B_USE_BORDER_INSETS") = -1009; +*/ +py::enum_(m, "BSpacing", "") +.value("B_USE_DEFAULT_SPACING", BSpacing::B_USE_DEFAULT_SPACING, "") +.value("B_USE_ITEM_SPACING", BSpacing::B_USE_ITEM_SPACING, "") +.value("B_USE_ITEM_INSETS", BSpacing::B_USE_ITEM_INSETS, "") +.value("B_USE_HALF_ITEM_SPACING", BSpacing::B_USE_HALF_ITEM_SPACING, "") +.value("B_USE_HALF_ITEM_INSETS", BSpacing::B_USE_HALF_ITEM_INSETS, "") +.value("B_USE_WINDOW_SPACING", BSpacing::B_USE_WINDOW_SPACING, "") +.value("B_USE_WINDOW_INSETS", BSpacing::B_USE_WINDOW_INSETS, "") +.value("B_USE_SMALL_SPACING", BSpacing::B_USE_SMALL_SPACING, "") +.value("B_USE_SMALL_INSETS", BSpacing::B_USE_SMALL_INSETS, "") +.value("B_USE_CORNER_SPACING", BSpacing::B_USE_CORNER_SPACING, "") +.value("B_USE_CORNER_INSETS", BSpacing::B_USE_CORNER_INSETS, "") +.value("B_USE_BIG_SPACING", BSpacing::B_USE_BIG_SPACING, "") +.value("B_USE_BIG_INSETS", BSpacing::B_USE_BIG_INSETS, "") +.value("B_USE_BORDER_SPACING", BSpacing::B_USE_BORDER_SPACING, "") +.value("B_USE_BORDER_INSETS", BSpacing::B_USE_BORDER_INSETS, "") +.export_values(); + py::enum_(m, "join_mode", "") .value("B_ROUND_JOIN", join_mode::B_ROUND_JOIN, "") @@ -267,7 +328,7 @@ m.attr("B_DISABLED_MARK_TINT") = B_DISABLED_MARK_TINT; py::class_(m, "key_info") .def_readwrite("modifiers", &key_info::modifiers, "") -.def_readonly("key_states", &key_info::key_states, "") +.def_readonly("key_states", &key_info::key_states, "") //TODO is this really Read-Only? ; py::class_(m, "key_map") @@ -285,6 +346,7 @@ py::class_(m, "key_map") .def_readwrite("right_option_key", &key_map::right_option_key, "") .def_readwrite("menu_key", &key_map::menu_key, "") .def_readwrite("lock_settings", &key_map::lock_settings, "") +// TODO are these read-only? //If no, look down at mouse_map and try that .def_readonly("control_map", &key_map::control_map, "") .def_readonly("option_caps_shift_map", &key_map::option_caps_shift_map, "") .def_readonly("option_caps_map", &key_map::option_caps_map, "") @@ -307,7 +369,19 @@ py::class_(m, "key_map") ; py::class_(m, "mouse_map") -.def_readonly("button", &mouse_map::button, "") +//.def_readonly("button", &mouse_map::button, "") +.def_property("button", + [](const mouse_map &mappa) { + py::array_t result(16);//B_MAX_MOUSE_BUTTONS = 16 + std::memcpy(result.mutable_data(), &mappa.button, sizeof(mappa.button)); + return result; + }, + [](mouse_map &mappa, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&mappa.button, value.data(), sizeof(mappa.button)); + },"") ; py::class_(m, "scroll_bar_info") @@ -327,29 +401,49 @@ m.def("get_scroll_bar_info", &get_scroll_bar_info, "", py::arg("info")); m.def("set_scroll_bar_info", &set_scroll_bar_info, "", py::arg("info")); -//m.def("get_mouse_type", py::overload_cast(&get_mouse_type, py::const_), "", py::arg("type")); -//m.def("get_mouse_type", py::overload_cast(&get_mouse_type, py::const_), "", py::arg("mouse_name"), py::arg("type")); +//#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("get_mouse_type", py::overload_cast(&get_mouse_type), "", py::arg("type")); +m.def("get_mouse_type", py::overload_cast(&get_mouse_type), "", py::arg("mouse_name"), py::arg("type")); +//#endif m.def("set_mouse_type", &set_mouse_type, "", py::arg("mouse_name"), py::arg("type")); +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("get_mouse_map", py::overload_cast(&get_mouse_map), "", py::arg("map")); +m.def("get_mouse_map", py::overload_cast(&get_mouse_map), "",py::arg("mouse_name"), py::arg("map")); +#else m.def("get_mouse_map", &get_mouse_map, "", py::arg("map")); +#endif +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("set_mouse_map", py::overload_cast(&set_mouse_map), "", py::arg("map")); +m.def("set_mouse_map", py::overload_cast(&set_mouse_map), "", py::arg("mouse_name"), py::arg("map")); +#else m.def("set_mouse_map", &set_mouse_map, "", py::arg("map")); +#endif +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("get_click_speed", py::overload_cast(&get_click_speed), "", py::arg("speed")); +m.def("get_click_speed", py::overload_cast(&get_click_speed), "", py::arg("mouse_name"), py::arg("speed")); +#else m.def("get_click_speed", &get_click_speed, "", py::arg("speed")); +#endif +#if (B_HAIKU_VERSION > B_HAIKU_VERSION_1_BETA_4) +m.def("set_click_speed", py::overload_cast(&set_click_speed), "", py::arg("speed")); +m.def("set_click_speed", py::overload_cast(&set_click_speed), "", py::arg("mouse_name"), py::arg("speed")); +#else m.def("set_click_speed", &set_click_speed, "", py::arg("speed")); +#endif -//m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed, py::const_), "", py::arg("speed")); - -//m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed, py::const_), "", py::arg("mouse_name"), py::arg("speed")); +m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed), "", py::arg("speed")); +m.def("get_mouse_speed", py::overload_cast(&get_mouse_speed), "", py::arg("mouse_name"), py::arg("speed")); m.def("set_mouse_speed", &set_mouse_speed, "", py::arg("mouse_name"), py::arg("speed")); -//m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration, py::const_), "", py::arg("speed")); - -//m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration, py::const_), "", py::arg("mouse_name"), py::arg("speed")); +m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration), "", py::arg("speed")); +m.def("get_mouse_acceleration", py::overload_cast(&get_mouse_acceleration), "", py::arg("mouse_name"), py::arg("speed")); m.def("set_mouse_acceleration", &set_mouse_acceleration, "", py::arg("mouse_name"), py::arg("speed")); diff --git a/bindings/interface/Layout.cpp b/bindings/interface/Layout.cpp index d32b861..9d67689 100644 --- a/bindings/interface/Layout.cpp +++ b/bindings/interface/Layout.cpp @@ -14,8 +14,115 @@ namespace py = pybind11; +class PyBLayout : public BLayout{ + public: + using BLayout::BLayout; + BView* View() override { + PYBIND11_OVERLOAD(BView*, BLayout, View); + } + BLayoutItem* AddView(BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BLayout, AddView, child); + } + BLayoutItem* AddView(int32 index, BView* child) override { + PYBIND11_OVERLOAD(BLayoutItem*, BLayout, AddView, index, child); + } + bool AddItem(BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BLayout, AddItem, item); + } + bool AddItem(int32 index, BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BLayout, AddItem, index, item); + } + bool RemoveView(BView* child) override { + PYBIND11_OVERLOAD(bool, BLayout, RemoveView, child); + } + bool RemoveItem(BLayoutItem* item) override { + PYBIND11_OVERLOAD(bool, BLayout, RemoveItem, item); + } + BLayoutItem* RemoveItem(int32 index) override { + PYBIND11_OVERLOAD(BLayoutItem*, BLayout, RemoveItem, index); + } + void InvalidateLayout(bool children = false) override { + PYBIND11_OVERLOAD(void, BLayout, InvalidateLayout, children); + } + void Relayout(bool immediate = false) override { + PYBIND11_OVERLOAD(void, BLayout, Relayout, immediate); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BLayout, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BLayout, Perform, d, arg); + } + BSize MinSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayout, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayout, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayout, PreferredSize); + } + BAlignment Alignment() override { + PYBIND11_OVERLOAD_PURE(BAlignment, BLayout, Alignment); + } + void SetExplicitMinSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitMinSize, size); + } + void SetExplicitMaxSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitMaxSize, size); + } + void SetExplicitPreferredSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitPreferredSize, size); + } + void SetExplicitAlignment(BAlignment alignment) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetExplicitAlignment, alignment); + } + bool IsVisible() override { + PYBIND11_OVERLOAD_PURE(bool, BLayout, IsVisible); + } + void SetVisible(bool visible) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetVisible, visible); + } + BRect Frame() override { + PYBIND11_OVERLOAD_PURE(BRect, BLayout, Frame); + } + void SetFrame(BRect frame) override { + PYBIND11_OVERLOAD_PURE(void, BLayout, SetFrame, frame); + } + void DoLayout() override { + PYBIND11_OVERLOAD_PURE(void, BLayout, DoLayout); + } +}; PYBIND11_MODULE(Layout,m) { -py::class_(m, "BLayout"); +py::class_(m, "BLayout") +.def(py::init(), "") +.def(py::init(), "", py::arg("archive")) +.def("Owner", &BLayout::Owner, "") +.def("TargetView", &BLayout::TargetView, "") +.def("View", &BLayout::View, "") +.def("AddView", py::overload_cast(&BLayout::AddView), "", py::arg("child")) +.def("AddView", py::overload_cast(&BLayout::AddView), "", py::arg("index"), py::arg("child")) +.def("AddItem", py::overload_cast(&BLayout::AddItem), "", py::arg("item")) +.def("AddItem", py::overload_cast(&BLayout::AddItem), "", py::arg("index"), py::arg("item")) +.def("RemoveView", &BLayout::RemoveView, "", py::arg("child")) +.def("RemoveItem", py::overload_cast(&BLayout::RemoveItem), "", py::arg("item")) +.def("RemoveItem", py::overload_cast(&BLayout::RemoveItem), "", py::arg("index")) +.def("ItemAt", &BLayout::ItemAt, "", py::arg("index")) +.def("CountItems", &BLayout::CountItems, "") +.def("IndexOfItem", &BLayout::IndexOfItem, "", py::arg("item")) +.def("IndexOfView", &BLayout::IndexOfView, "", py::arg("child")) +.def("AncestorsVisible", &BLayout::AncestorsVisible, "") +.def("InvalidateLayout", &BLayout::InvalidateLayout, "", py::arg("children")=false) +.def("Relayout", &BLayout::Relayout, "", py::arg("immediate")=false) +.def("RequireLayout", &BLayout::RequireLayout, "") +.def("IsValid", &BLayout::IsValid, "") +.def("EnableLayoutInvalidation", &BLayout::EnableLayoutInvalidation, "") +.def("DisableLayoutInvalidation", &BLayout::DisableLayoutInvalidation, "") +.def("LayoutItems", &BLayout::LayoutItems, "", py::arg("force")=false) +.def("LayoutArea", &BLayout::LayoutArea, "") +.def("LayoutContext", &BLayout::LayoutContext, "") +.def("Archive", &BLayout::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BLayout::Perform, "", py::arg("d"), py::arg("arg")); } diff --git a/bindings/interface/LayoutContext.cpp b/bindings/interface/LayoutContext.cpp index f536f13..a46ab28 100644 --- a/bindings/interface/LayoutContext.cpp +++ b/bindings/interface/LayoutContext.cpp @@ -9,9 +9,18 @@ namespace py = pybind11; +class PyBLayoutContextListener : public BLayoutContextListener { +public: + using BLayoutContextListener::BLayoutContextListener; + + void LayoutContextLeft(BLayoutContext* context) override { + PYBIND11_OVERRIDE_PURE(void, BLayoutContextListener, LayoutContextLeft, context); + } +}; + PYBIND11_MODULE(LayoutContext,m) { -py::class_(m, "BLayoutContextListener") +py::class_(m, "BLayoutContextListener") .def(py::init(), "") .def("LayoutContextLeft", &BLayoutContextListener::LayoutContextLeft, "", py::arg("context")) ; diff --git a/bindings/interface/LayoutItem.cpp b/bindings/interface/LayoutItem.cpp index d886c57..83f68c6 100644 --- a/bindings/interface/LayoutItem.cpp +++ b/bindings/interface/LayoutItem.cpp @@ -13,8 +13,97 @@ namespace py = pybind11; +class PyBLayoutItem : public BLayoutItem{ + public: + using BLayoutItem::BLayoutItem; + BSize MinSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayoutItem, MinSize); + } + BSize MaxSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayoutItem, MaxSize); + } + BSize PreferredSize() override { + PYBIND11_OVERLOAD_PURE(BSize, BLayoutItem, PreferredSize); + } + BAlignment Alignment() override { + PYBIND11_OVERLOAD_PURE(BAlignment, BLayoutItem, Alignment); + } + void SetExplicitMinSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitMinSize, size); + } + void SetExplicitMaxSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitMaxSize, size); + } + void SetExplicitPreferredSize(BSize size) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitPreferredSize, size); + } + void SetExplicitAlignment(BAlignment alignment) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetExplicitAlignment, alignment); + } + bool IsVisible() override { + PYBIND11_OVERLOAD_PURE(bool, BLayoutItem, IsVisible); + } + void SetVisible(bool visible) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetVisible, visible); + } + BRect Frame() override { + PYBIND11_OVERLOAD_PURE(BRect, BLayoutItem, Frame); + } + void SetFrame(BRect frame) override { + PYBIND11_OVERLOAD_PURE(void, BLayoutItem, SetFrame, frame); + } + bool HasHeightForWidth() override { + PYBIND11_OVERLOAD(bool, BLayoutItem, HasHeightForWidth); + } + void GetHeightForWidth(float width, float* min, float* max, float* preferred) override { + PYBIND11_OVERLOAD(void, BLayoutItem, GetHeightForWidth, width, min, max, preferred); + } + BView* View() override { + PYBIND11_OVERLOAD(BView*, BLayoutItem, View); + } + void InvalidateLayout(bool children = false) override { + PYBIND11_OVERLOAD(void, BLayoutItem, InvalidateLayout, children); + } + void Relayout(bool immediate = false) override { + PYBIND11_OVERLOAD(void, BLayoutItem, Relayout, immediate); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BLayoutItem, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BLayoutItem, Perform, d, arg); + } +}; PYBIND11_MODULE(LayoutItem,m) { -py::class_>(m, "BLayoutItem"); +py::class_>(m, "BLayoutItem") +.def(py::init(), "") +.def(py::init(), "", py::arg("from")) +.def("Layout", &BLayoutItem::Layout, "") +.def("RemoveSelf", &BLayoutItem::RemoveSelf, "") +.def("MinSize", &BLayoutItem::MinSize, "") +.def("MaxSize", &BLayoutItem::MaxSize, "") +.def("PreferredSize", &BLayoutItem::PreferredSize, "") +.def("Alignment", &BLayoutItem::Alignment, "") +.def("SetExplicitMinSize", &BLayoutItem::SetExplicitMinSize, "", py::arg("size")) +.def("SetExplicitMaxSize", &BLayoutItem::SetExplicitMaxSize, "", py::arg("size")) +.def("SetExplicitPreferredSize", &BLayoutItem::SetExplicitPreferredSize, "", py::arg("size")) +.def("SetExplicitSize", &BLayoutItem::SetExplicitSize, "", py::arg("size")) +.def("SetExplicitAlignment", &BLayoutItem::SetExplicitAlignment, "", py::arg("alignment")) +.def("IsVisible", &BLayoutItem::IsVisible, "") +.def("SetVisible", &BLayoutItem::SetVisible, "", py::arg("visible")) +.def("Frame", &BLayoutItem::Frame, "") +.def("SetFrame", &BLayoutItem::SetFrame, "", py::arg("frame")) +.def("HasHeightForWidth", &BLayoutItem::HasHeightForWidth, "") +.def("GetHeightForWidth", &BLayoutItem::GetHeightForWidth, "", py::arg("width"), py::arg("min"), py::arg("max"), py::arg("preferred")) +.def("View", &BLayoutItem::View, "") +.def("InvalidateLayout", &BLayoutItem::InvalidateLayout, "", py::arg("children")=false) +.def("Relayout", &BLayoutItem::Relayout, "", py::arg("immediate")=false) +.def("LayoutData", &BLayoutItem::LayoutData, "") +.def("SetLayoutData", &BLayoutItem::SetLayoutData, "", py::arg("data")) +.def("AlignInFrame", &BLayoutItem::AlignInFrame, "", py::arg("frame")) +.def("Archive", &BLayoutItem::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BLayoutItem::Perform, "", py::arg("d"), py::arg("arg")) +; } diff --git a/bindings/interface/LayoutUtils.cpp b/bindings/interface/LayoutUtils.cpp index 728af37..bccea2d 100644 --- a/bindings/interface/LayoutUtils.cpp +++ b/bindings/interface/LayoutUtils.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include namespace py = pybind11; @@ -17,24 +19,26 @@ PYBIND11_MODULE(LayoutUtils,m) py::class_(m, "BLayoutUtils") .def_static("AddDistances", py::overload_cast(&BLayoutUtils::AddDistances), "", py::arg("a"), py::arg("b")) .def_static("AddDistances", py::overload_cast(&BLayoutUtils::AddDistances), "", py::arg("a"), py::arg("b"), py::arg("c")) -.def_static("AddSizesInt32", py::overload_cast(&BLayoutUtils::AddSizesInt32), "", py::arg("a"), py::arg("b")) -.def_static("AddSizesInt32", py::overload_cast(&BLayoutUtils::AddSizesInt32), "", py::arg("a"), py::arg("b"), py::arg("c")) +.def_static("AddSizesInt32", py::overload_cast(&BLayoutUtils::AddSizesInt32), "", py::arg("a"), py::arg("b")) +.def_static("AddSizesInt32", py::overload_cast(&BLayoutUtils::AddSizesInt32), "", py::arg("a"), py::arg("b"), py::arg("c")) .def_static("SubtractSizesInt32", &BLayoutUtils::SubtractSizesInt32, "", py::arg("a"), py::arg("b")) .def_static("SubtractDistances", &BLayoutUtils::SubtractDistances, "", py::arg("a"), py::arg("b")) .def_static("FixSizeConstraints", [](BLayoutUtils& self) { float min; float max; float preferred; - static void r = self.FixSizeConstraints(min, max, preferred); - return std::make_tuple(r,min,max,preferred); + //static void r = self.FixSizeConstraints(min, max, preferred); + self.FixSizeConstraints(min, max, preferred); + return std::make_tuple(min,max,preferred); } , "") .def_static("FixSizeConstraints", [](BLayoutUtils& self) { BSize min; BSize max; BSize preferred; - static void r = self.FixSizeConstraints(min, max, preferred); - return std::make_tuple(r,min,max,preferred); + //static void r = self.FixSizeConstraints(min, max, preferred); + self.FixSizeConstraints(min, max, preferred); + return std::make_tuple(min,max,preferred); } , "") .def_static("ComposeSize", &BLayoutUtils::ComposeSize, "", py::arg("size"), py::arg("layoutSize")) diff --git a/bindings/interface/ListItem.cpp b/bindings/interface/ListItem.cpp index b4ec21f..5692c60 100644 --- a/bindings/interface/ListItem.cpp +++ b/bindings/interface/ListItem.cpp @@ -7,14 +7,43 @@ #include #include #include +#include +#include +#include +#include +#include namespace py = pybind11; +class PyBListItem : public BListItem { +public: + using BListItem::BListItem; + 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_; +}; + PYBIND11_MODULE(ListItem,m) { -py::class_(m, "BListItem") -.def(py::init(), "", py::arg("outlineLevel")=0, py::arg("expanded")=true) +//py::class_(m, "BListItem") +py::class_>(m, "BListItem") +.def(py::init(), "", py::arg("outlineLevel")=0, py::arg("expanded")=true) .def(py::init(), "", py::arg("archive")) .def("Archive", &BListItem::Archive, "", py::arg("archive"), py::arg("deep")=true) .def("Height", &BListItem::Height, "") @@ -27,6 +56,8 @@ py::class_(m, "BListItem") .def("SetHeight", &BListItem::SetHeight, "", py::arg("height")) .def("SetWidth", &BListItem::SetWidth, "", py::arg("width")) .def("DrawItem", &BListItem::DrawItem, "", py::arg("owner"), py::arg("frame"), py::arg("complete")=false) +//.def("DrawItem", &PyBListItem::DrawItem, "", py::arg("owner"), py::arg("frame"), py::arg("complete")=false) +//.def("DrawItem", &PyBListItemWrapper::DrawItemWrapper, "", py::arg("owner"), py::arg("itemRect"), py::arg("drawEverything") = false) .def("Update", &BListItem::Update, "", py::arg("owner"), py::arg("font")) .def("IsExpanded", &BListItem::IsExpanded, "") .def("SetExpanded", &BListItem::SetExpanded, "", py::arg("expanded")) diff --git a/bindings/interface/ListView.cpp b/bindings/interface/ListView.cpp index 23a8acf..6a22183 100644 --- a/bindings/interface/ListView.cpp +++ b/bindings/interface/ListView.cpp @@ -8,9 +8,146 @@ #include #include #include +#include +#include namespace py = pybind11; +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; + + for (long i = 0; i < count; ++i) { + // Aggiungi ogni elemento della lista alla lista Python + result.append(items[i]); + } + + return result; +} + +bool CallPythonFunction(BListItem* 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); +} PYBIND11_MODULE(ListView,m) { @@ -19,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) @@ -50,11 +187,11 @@ py::class_(m, "BListView") .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")) -.def("AddItem", py::overload_cast(&BListView::AddItem), "", py::arg("item"), py::arg("atIndex")) +.def("AddItem", py::overload_cast(&BListView::AddItem), "", py::arg("item"), py::arg("atIndex")) .def("AddList", py::overload_cast(&BListView::AddList), "", py::arg("newItems")) -.def("AddList", py::overload_cast(&BListView::AddList), "", py::arg("newItems"), py::arg("atIndex")) +.def("AddList", py::overload_cast(&BListView::AddList), "", py::arg("newItems"), py::arg("atIndex")) .def("RemoveItem", py::overload_cast(&BListView::RemoveItem), "", py::arg("item")) -.def("RemoveItem", py::overload_cast(&BListView::RemoveItem), "", py::arg("index")) +.def("RemoveItem", py::overload_cast(&BListView::RemoveItem), "", py::arg("index")) .def("RemoveItems", &BListView::RemoveItems, "", py::arg("index"), py::arg("count")) .def("SetSelectionMessage", &BListView::SetSelectionMessage, "", py::arg("message")) .def("SetInvocationMessage", &BListView::SetInvocationMessage, "", py::arg("message")) @@ -65,21 +202,44 @@ py::class_(m, "BListView") .def("SetListType", &BListView::SetListType, "", py::arg("type")) .def("ListType", &BListView::ListType, "") .def("ItemAt", &BListView::ItemAt, "", py::arg("index")) -.def("IndexOf", py::overload_cast(&BListView::IndexOf), "", py::arg("point")) -.def("IndexOf", py::overload_cast(&BListView::IndexOf), "", py::arg("item")) +//.def("IndexOf", py::overload_cast(&BListView::IndexOf), "", py::arg("point")) +.def("IndexOf", static_cast(&BListView::IndexOf), "", py::arg("point")) +//.def("IndexOf", py::overload_cast(&BListView::IndexOf), "", py::arg("item")) +.def("IndexOf",static_cast(&BListView::IndexOf), "", py::arg("item")) .def("FirstItem", &BListView::FirstItem, "") .def("LastItem", &BListView::LastItem, "") .def("HasItem", &BListView::HasItem, "", py::arg("item")) .def("CountItems", &BListView::CountItems, "") .def("MakeEmpty", &BListView::MakeEmpty, "") .def("IsEmpty", &BListView::IsEmpty, "") -.def("DoForEach", py::overload_cast(&BListView::DoForEach), "", py::arg("")) -.def("DoForEach", py::overload_cast(&BListView::DoForEach), "", py::arg(""), py::arg("arg")) -.def("Items", &BListView::Items, "") +//.def("DoForEach", py::overload_cast(&BListView::DoForEach), "", py::arg("")) + +.def("DoForEach", [](BListView& self, py::function& func) -> void { + // Utilizzare una lambda expression per chiamare la funzione Python per ogni elemento + self.DoForEach(static_cast(+[](BListItem* item, void* userData) -> bool { + return CallPythonFunction(item, *static_cast(userData)); + }), &func); + }, "", py::arg("func")) + +//.def("DoForEach", py::overload_cast(&BListView::DoForEach), "", py::arg(""), py::arg("arg")) + +.def("DoForEach", [](BListView& self, py::function& func, void* arg) -> void { + // Utilizzare una lambda expression per chiamare la funzione Python per ogni elemento + self.DoForEach(static_cast(+[](BListItem* item, void* userData) -> bool { + return CallPythonFunction(item, *static_cast(userData)); + }), arg); + }, "", py::arg("func"), py::arg("arg")) + +//.def("Items", &BListView::Items, "") +.def("Items", [](BListView& self) { + const BListItem** items = self.Items(); + long count = self.CountItems(); + return convertBListItemsToPythonList(items, count); + }, "") .def("InvalidateItem", &BListView::InvalidateItem, "", py::arg("index")) .def("ScrollToSelection", &BListView::ScrollToSelection, "") -.def("Select", py::overload_cast(&BListView::Select), "", py::arg("index"), py::arg("extend")=false) -.def("Select", py::overload_cast(&BListView::Select), "", py::arg("from"), py::arg("to"), py::arg("extend")=false) +.def("Select", py::overload_cast(&BListView::Select), "", py::arg("index"), py::arg("extend")=false) +.def("Select", py::overload_cast(&BListView::Select), "", py::arg("from"), py::arg("to"), py::arg("extend")=false) .def("IsItemSelected", &BListView::IsItemSelected, "", py::arg("index")) .def("CurrentSelection", &BListView::CurrentSelection, "", py::arg("index")=0) .def("Invoke", &BListView::Invoke, "", py::arg("message")=NULL) @@ -97,7 +257,7 @@ py::class_(m, "BListView") .def("GetSupportedSuites", &BListView::GetSupportedSuites, "", py::arg("data")) .def("Perform", &BListView::Perform, "", py::arg("code"), py::arg("arg")) ; - +/* py::class_(m, "union MiscData") .def_readwrite("replace", &union MiscData::replace, "") .def_readwrite("move", &union MiscData::move, "") @@ -123,5 +283,5 @@ py::class_(m, "Swap") .def_readwrite("b", &Swap::b, "") ; - +*/ } diff --git a/bindings/interface/Menu.cpp b/bindings/interface/Menu.cpp index f208eb9..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")) @@ -62,15 +145,15 @@ py::class_(m, "BMenu") .def("InvalidateLayout", &BMenu::InvalidateLayout, "") .def("MakeFocus", &BMenu::MakeFocus, "", py::arg("focus")=true) .def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("item")) -.def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("item"), py::arg("index")) +.def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("item"), py::arg("index")) .def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("item"), py::arg("frame")) .def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("menu")) -.def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("menu"), py::arg("index")) +.def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("menu"), py::arg("index")) .def("AddItem", py::overload_cast(&BMenu::AddItem), "", py::arg("menu"), py::arg("frame")) .def("AddList", &BMenu::AddList, "", py::arg("list"), py::arg("index")) .def("AddSeparatorItem", &BMenu::AddSeparatorItem, "") .def("RemoveItem", py::overload_cast(&BMenu::RemoveItem), "", py::arg("item")) -.def("RemoveItem", py::overload_cast(&BMenu::RemoveItem), "", py::arg("index")) +.def("RemoveItem", py::overload_cast(&BMenu::RemoveItem), "", py::arg("index")) .def("RemoveItems", &BMenu::RemoveItems, "", py::arg("index"), py::arg("count"), py::arg("deleteItems")=false) .def("RemoveItem", py::overload_cast(&BMenu::RemoveItem), "", py::arg("menu")) .def("ItemAt", &BMenu::ItemAt, "", py::arg("index")) @@ -78,7 +161,7 @@ py::class_(m, "BMenu") .def("CountItems", &BMenu::CountItems, "") .def("IndexOf", py::overload_cast(&BMenu::IndexOf, py::const_), "", py::arg("item")) .def("IndexOf", py::overload_cast(&BMenu::IndexOf, py::const_), "", py::arg("menu")) -.def("FindItem", py::overload_cast(&BMenu::FindItem, py::const_), "", py::arg("command")) +.def("FindItem", py::overload_cast(&BMenu::FindItem, py::const_), "", py::arg("command")) .def("FindItem", py::overload_cast(&BMenu::FindItem, py::const_), "", py::arg("name")) .def("SetTargetForItems", py::overload_cast(&BMenu::SetTargetForItems), "", py::arg("target")) .def("SetTargetForItems", py::overload_cast(&BMenu::SetTargetForItems), "", py::arg("messenger")) diff --git a/bindings/interface/MenuBar.cpp b/bindings/interface/MenuBar.cpp index ed6f5f5..7ace7f4 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")) @@ -32,7 +107,13 @@ py::class_(m, "BMenuBar") .def("WindowActivated", &BMenuBar::WindowActivated, "", py::arg("state")) .def("MakeFocus", &BMenuBar::MakeFocus, "", py::arg("state")=true) .def("ResizeToPreferred", &BMenuBar::ResizeToPreferred, "") -.def("GetPreferredSize", &BMenuBar::GetPreferredSize, "", py::arg("_width"), py::arg("_height")) +//.def("GetPreferredSize", &BMenuBar::GetPreferredSize, "", py::arg("_width"), py::arg("_height")) +.def("GetPreferredSize", [](BMenuBar& self)->py::tuple { + float _width;//=0.0f; + float _height;//=0.0f; + self.GetPreferredSize(&_width,&_height); + return py::make_tuple(_width,_height); +}, "") .def("MinSize", &BMenuBar::MinSize, "") .def("MaxSize", &BMenuBar::MaxSize, "") .def("PreferredSize", &BMenuBar::PreferredSize, "") diff --git a/bindings/interface/MenuField.cpp b/bindings/interface/MenuField.cpp index ceef7ef..b96f0d8 100644 --- a/bindings/interface/MenuField.cpp +++ b/bindings/interface/MenuField.cpp @@ -11,14 +11,99 @@ 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") -.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) -.def(py::init(), "", py::arg("label"), py::arg("menu"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) +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) +.def(py::init(), "", py::arg("label"), py::arg("menu"), py::arg("flags")=B_WILL_DRAW | B_NAVIGABLE) .def(py::init(), "", py::arg("data")) .def_static("Instantiate", &BMenuField::Instantiate, "", py::arg("archive")) .def("Archive", &BMenuField::Archive, "", py::arg("archive"), py::arg("deep")=true) 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/OptionControl.cpp b/bindings/interface/OptionControl.cpp index b0d8989..8443412 100644 --- a/bindings/interface/OptionControl.cpp +++ b/bindings/interface/OptionControl.cpp @@ -8,22 +8,51 @@ namespace py = pybind11; +class PyBOptionControl : public BOptionControl { +public: + using BOptionControl::BOptionControl; + + void MessageReceived(BMessage* message) override { + PYBIND11_OVERLOAD(void, BOptionControl, MessageReceived, message); + } + bool GetOptionAt(int32 index, const char** _name, int32* _value) override { + PYBIND11_OVERRIDE_PURE(bool, BOptionControl, GetOptionAt, index, _name, _value); + } + void RemoveOptionAt(int32 index) override { + PYBIND11_OVERRIDE_PURE(void, BOptionControl, RemoveOptionAt, index); + } + int32 CountOptions() const override { + PYBIND11_OVERRIDE_PURE(int32, BOptionControl, CountOptions); + } + status_t AddOptionAt(const char* name, int32 value, int32 index) override { + PYBIND11_OVERRIDE_PURE(status_t, BOptionControl, AddOptionAt, name, value, index); + } + int32 SelectedOption(const char** name = NULL, int32* outValue = NULL) const override { + PYBIND11_OVERRIDE_PURE(int32, BOptionControl, SelectedOption, name, outValue); + } + status_t SelectOptionFor(int32 value) override { + PYBIND11_OVERLOAD(status_t, BOptionControl, SelectOptionFor, value); + } + status_t SelectOptionFor(const char* name) override { + PYBIND11_OVERLOAD(status_t, BOptionControl, SelectOptionFor, name); + } +}; PYBIND11_MODULE(OptionControl,m) { m.attr("B_OPTION_CONTROL_VALUE") = "_BMV"; -py::class_(m, "BOptionControl") +py::class_(m, "BOptionControl") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("label"), py::arg("message"), py::arg("resizeMask")=B_FOLLOW_LEFT_TOP, py::arg("flags")=B_WILL_DRAW) .def(py::init(), "", py::arg("name"), py::arg("label"), py::arg("message"), py::arg("flags")=B_WILL_DRAW) .def("MessageReceived", &BOptionControl::MessageReceived, "", py::arg("message")) .def("AddOption", &BOptionControl::AddOption, "", py::arg("name"), py::arg("value")) -.def("GetOptionAt", &BOptionControl::GetOptionAt, "", py::arg("index"), py::arg("_name"), py::arg("_value")) -.def("RemoveOptionAt", &BOptionControl::RemoveOptionAt, "", py::arg("index")) -.def("CountOptions", &BOptionControl::CountOptions, "") -.def("AddOptionAt", &BOptionControl::AddOptionAt, "", py::arg("name"), py::arg("value"), py::arg("index")) -.def("SelectedOption", &BOptionControl::SelectedOption, "", py::arg("name")=NULL, py::arg("outValue")=NULL) -.def("SelectOptionFor", py::overload_cast(&BOptionControl::SelectOptionFor), "", py::arg("value")) +//.def("GetOptionAt", &BOptionControl::GetOptionAt, "", py::arg("index"), py::arg("_name"), py::arg("_value")) +//.def("RemoveOptionAt", &BOptionControl::RemoveOptionAt, "", py::arg("index")) +//.def("CountOptions", &BOptionControl::CountOptions, "") +//.def("AddOptionAt", &BOptionControl::AddOptionAt, "", py::arg("name"), py::arg("value"), py::arg("index")) +//.def("SelectedOption", &BOptionControl::SelectedOption, "", py::arg("name")=NULL, py::arg("outValue")=NULL) +.def("SelectOptionFor", py::overload_cast(&BOptionControl::SelectOptionFor), "", py::arg("value")) .def("SelectOptionFor", py::overload_cast(&BOptionControl::SelectOptionFor), "", py::arg("name")) ; diff --git a/bindings/interface/OutlineListView.cpp b/bindings/interface/OutlineListView.cpp index f252035..de5c157 100644 --- a/bindings/interface/OutlineListView.cpp +++ b/bindings/interface/OutlineListView.cpp @@ -8,10 +8,88 @@ namespace py = pybind11; - +class PyBOutlineListView : public BOutlineListView{ + public: + using BOutlineListView::BOutlineListView; + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BOutlineListView, Archive, archive, deep); + } + void MouseDown(BPoint where) override { + PYBIND11_OVERLOAD(void, BOutlineListView, MouseDown, where); + } + void KeyDown(const char* bytes, int32 numBytes) override { + PYBIND11_OVERLOAD(void, BOutlineListView, KeyDown, bytes, numBytes); + } + void MouseUp(BPoint where) override { + PYBIND11_OVERLOAD(void, BOutlineListView, MouseUp, where); + } + bool AddUnder(BListItem* item, BListItem* superItem) override{ + PYBIND11_OVERLOAD(bool, BOutlineListView, AddUnder, item, superItem); + } + bool AddItem(BListItem* item) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddItem, item); + } + bool AddItem(BListItem* item, int32 fullListIndex) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddItem, item, fullListIndex); + } + bool AddList(BList* newItems) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddList, newItems); + } + bool AddList(BList* newItems, int32 fullListIndex) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, AddList, newItems, fullListIndex); + } + bool RemoveItem(BListItem* item) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, RemoveItem, item); + } + BListItem* RemoveItem(int32 fullListIndex) override { + PYBIND11_OVERLOAD(BListItem*, BOutlineListView, RemoveItem, fullListIndex); + } + bool RemoveItems(int32 fullListIndex, int32 count) override { + PYBIND11_OVERLOAD(bool, BOutlineListView, RemoveItems, fullListIndex, count); + } + void FrameMoved(BPoint newPosition) override { + PYBIND11_OVERLOAD(void, BOutlineListView, FrameMoved, newPosition); + } + void FrameResized(float newWidth, float newHeight) override { + PYBIND11_OVERLOAD(void, BOutlineListView, FrameResized, newWidth, newHeight); + } + void MakeEmpty() override { + PYBIND11_OVERLOAD(void, BOutlineListView, MakeEmpty); + } + BHandler* ResolveSpecifier(BMessage* message, + int32 index, BMessage* specifier, + int32 what, const char* property) override { + PYBIND11_OVERLOAD(BHandler*, BOutlineListView, ResolveSpecifier, message, index, specifier, what, property); + } + status_t GetSupportedSuites(BMessage* data) override { + PYBIND11_OVERLOAD(status_t, BOutlineListView, GetSupportedSuites, data); + } + status_t Perform(perform_code code, void* data) override { + PYBIND11_OVERLOAD(status_t, BOutlineListView, Perform, code, data); + } + void ResizeToPreferred() override { + PYBIND11_OVERLOAD(void, BOutlineListView, ResizeToPreferred); + } + void GetPreferredSize(float* _width, float* _height) override { + PYBIND11_OVERLOAD(void, BOutlineListView, GetPreferredSize, _width, _height); + } + void MakeFocus(bool focus = true) override { + PYBIND11_OVERLOAD(void, BOutlineListView, MakeFocus, focus); + } + void AllAttached() override { + PYBIND11_OVERLOAD(void, BOutlineListView, AllAttached); + } + void AllDetached() override { + PYBIND11_OVERLOAD(void, BOutlineListView, AllDetached); + } + void DetachedFromWindow() override { + PYBIND11_OVERLOAD(void, BOutlineListView, DetachedFromWindow); + } +}; + PYBIND11_MODULE(OutlineListView,m) { -py::class_(m, "BOutlineListView") +py::class_(m, "BOutlineListView") .def(py::init(), "", py::arg("frame"), py::arg("name"), py::arg("type")=B_SINGLE_SELECTION_LIST, py::arg("resizingMode")=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("archive")) @@ -24,15 +102,15 @@ py::class_(m, "BOutlineListView") .def("MouseUp", &BOutlineListView::MouseUp, "", py::arg("where")) .def("AddUnder", &BOutlineListView::AddUnder, "", py::arg("item"), py::arg("superItem")) .def("AddItem", py::overload_cast(&BOutlineListView::AddItem), "", py::arg("item")) -.def("AddItem", py::overload_cast(&BOutlineListView::AddItem), "", py::arg("item"), py::arg("fullListIndex")) +.def("AddItem", py::overload_cast(&BOutlineListView::AddItem), "", py::arg("item"), py::arg("fullListIndex")) .def("AddList", py::overload_cast(&BOutlineListView::AddList), "", py::arg("newItems")) -.def("AddList", py::overload_cast(&BOutlineListView::AddList), "", py::arg("newItems"), py::arg("fullListIndex")) +.def("AddList", py::overload_cast(&BOutlineListView::AddList), "", py::arg("newItems"), py::arg("fullListIndex")) .def("RemoveItem", py::overload_cast(&BOutlineListView::RemoveItem), "", py::arg("item")) -.def("RemoveItem", py::overload_cast(&BOutlineListView::RemoveItem), "", py::arg("fullListIndex")) +.def("RemoveItem", py::overload_cast(&BOutlineListView::RemoveItem), "", py::arg("fullListIndex")) .def("RemoveItems", &BOutlineListView::RemoveItems, "", py::arg("fullListIndex"), py::arg("count")) .def("FullListItemAt", &BOutlineListView::FullListItemAt, "", py::arg("fullListIndex")) -.def("FullListIndexOf", py::overload_cast(&BOutlineListView::FullListIndexOf), "", py::arg("where")) -.def("FullListIndexOf", py::overload_cast(&BOutlineListView::FullListIndexOf), "", py::arg("item")) +.def("FullListIndexOf", py::overload_cast(&BOutlineListView::FullListIndexOf, py::const_), "", py::arg("where")) +.def("FullListIndexOf", py::overload_cast(&BOutlineListView::FullListIndexOf, py::const_), "", py::arg("item")) .def("FullListFirstItem", &BOutlineListView::FullListFirstItem, "") .def("FullListLastItem", &BOutlineListView::FullListLastItem, "") .def("FullListHasItem", &BOutlineListView::FullListHasItem, "", py::arg("item")) @@ -40,8 +118,8 @@ py::class_(m, "BOutlineListView") .def("FullListCurrentSelection", &BOutlineListView::FullListCurrentSelection, "", py::arg("index")=0) .def("MakeEmpty", &BOutlineListView::MakeEmpty, "") .def("FullListIsEmpty", &BOutlineListView::FullListIsEmpty, "") -.def("FullListDoForEach", py::overload_cast(&BOutlineListView::FullListDoForEach), "", py::arg("")) -.def("FullListDoForEach", py::overload_cast(&BOutlineListView::FullListDoForEach), "", py::arg(""), py::arg("arg")) +//.def("FullListDoForEach", py::overload_cast(&BOutlineListView::FullListDoForEach), "", py::arg("")) +//.def("FullListDoForEach", py::overload_cast(&BOutlineListView::FullListDoForEach), "", py::arg(""), py::arg("arg")) .def("Superitem", &BOutlineListView::Superitem, "", py::arg("item")) .def("Expand", &BOutlineListView::Expand, "", py::arg("item")) .def("Collapse", &BOutlineListView::Collapse, "", py::arg("item")) diff --git a/bindings/interface/Picture.cpp b/bindings/interface/Picture.cpp index 9375455..e0f0b9c 100644 --- a/bindings/interface/Picture.cpp +++ b/bindings/interface/Picture.cpp @@ -10,6 +10,11 @@ namespace py = pybind11; +int PlayWrapper(BPicture& picture, BMessage* callBackTable, int32 tableEntries, void* userData) { + // Chiamare la funzione Play originale + void* callBackTableVoidPtr = static_cast(callBackTable); + return picture.Play(&callBackTableVoidPtr, tableEntries, userData); +} PYBIND11_MODULE(Picture,m) { @@ -20,10 +25,11 @@ py::class_(m, "BPicture") .def_static("Instantiate", &BPicture::Instantiate, "", py::arg("data")) .def("Archive", &BPicture::Archive, "", py::arg("data"), py::arg("deep")=true) .def("Perform", &BPicture::Perform, "", py::arg("code"), py::arg("arg")) -.def("Play", &BPicture::Play, "", py::arg("callBackTable"), py::arg("tableEntries"), py::arg("userData")) +//.def("Play", &BPicture::Play, "", py::arg("callBackTable"), py::arg("tableEntries"), py::arg("userData")) +.def("Play", &PlayWrapper, "", py::arg("callBackTable"), py::arg("tableEntries"), py::arg("userData")) .def("Flatten", &BPicture::Flatten, "", py::arg("stream")) .def("Unflatten", &BPicture::Unflatten, "", py::arg("stream")) -.def_readwrite("Private", &BPicture::Private, "") +//.def_readwrite("Private", &BPicture::Private, "") ; diff --git a/bindings/interface/PictureButton.cpp b/bindings/interface/PictureButton.cpp index a005d9c..a1b96d4 100644 --- a/bindings/interface/PictureButton.cpp +++ b/bindings/interface/PictureButton.cpp @@ -3,19 +3,111 @@ #include #include +#include #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; +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/Point.cpp b/bindings/interface/Point.cpp index 964e860..0006352 100644 --- a/bindings/interface/Point.cpp +++ b/bindings/interface/Point.cpp @@ -5,13 +5,13 @@ #include #include +#include namespace py = pybind11; PYBIND11_MODULE(Point,m) { -m.attr("B_ORIGIN") = B_ORIGIN; py::class_(m, "BPoint") .def(py::init(), "") @@ -21,9 +21,11 @@ py::class_(m, "BPoint") .def("Set", &BPoint::Set, "", py::arg("x"), py::arg("y")) .def("ConstrainTo", &BPoint::ConstrainTo, "", py::arg("rect")) .def("PrintToStream", &BPoint::PrintToStream, "") -.def("operator-", py::overload_cast<>(&BPoint::operator-), "") +//.def("operator-", py::overload_cast<>(&BPoint::operator-), "") +.def("__neg__", [](const BPoint &self) { return -self; }) .def("__add__", &BPoint::operator+, "", py::arg("other")) -.def("operator-", py::overload_cast(&BPoint::operator-), "", py::arg("other")) +//.def("operator-", py::overload_cast(&BPoint::operator-), "", py::arg("other")) +.def("__sub__", [](const BPoint &self, const BPoint &other) { return self - other; }, py::arg("other")) .def("__iadd__", &BPoint::operator+=, "", py::arg("other")) .def("__isub__", &BPoint::operator-=, "", py::arg("other")) .def("__ne__", &BPoint::operator!=, "", py::arg("other")) @@ -32,6 +34,7 @@ py::class_(m, "BPoint") .def_readwrite("y", &BPoint::y, "") ; -m.def("operator=", &operator=, "", py::arg("other")); +m.attr("B_ORIGIN") = B_ORIGIN; +//m.def("operator=", &operator=, "", py::arg("other")); } 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/PrintJob.cpp b/bindings/interface/PrintJob.cpp index 1bf5fef..44f6b5a 100644 --- a/bindings/interface/PrintJob.cpp +++ b/bindings/interface/PrintJob.cpp @@ -2,22 +2,39 @@ #include #include #include +#include #include #include +#include namespace py = pybind11; PYBIND11_MODULE(PrintJob,m) { -m.attr("") = ; +//m.attr("") = ; py::class_(m, "print_file_header") .def_readwrite("version", &print_file_header::version, "") .def_readwrite("page_count", &print_file_header::page_count, "") .def_readwrite("first_page", &print_file_header::first_page, "") -.def_readwrite("_reserved", &print_file_header::_reserved, "") +//.def_readwrite("_reserved", &print_file_header::_reserved, "") +//.def_readwrite("_reserved", &print_file_header::_reserved, py::size_t(sizeof(print_file_header::_reserved)), "") +.def_property( + "_reserved", + [](const print_file_header &header) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &header._reserved, sizeof(header._reserved)); + return result; + }, + [](print_file_header &header, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&header._reserved, value.data(), sizeof(header._reserved)); + } + ) ; py::class_(m, "BPrintJob") diff --git a/bindings/interface/RadioButton.cpp b/bindings/interface/RadioButton.cpp index 3eadf5e..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/Region.cpp b/bindings/interface/Region.cpp index 3febb75..0a8e044 100644 --- a/bindings/interface/Region.cpp +++ b/bindings/interface/Region.cpp @@ -11,9 +11,9 @@ using namespace BPrivate; PYBIND11_MODULE(Region,m) { -m.attr("ServerLink") = ServerLink; +//m.attr("ServerLink") = ServerLink; -m.attr("LinkReceiver") = LinkReceiver; +//m.attr("LinkReceiver") = LinkReceiver; py::class_(m, "clipping_rect") .def_readwrite("left", &clipping_rect::left, "") @@ -32,20 +32,20 @@ py::class_(m, "BRegion") .def("Set", py::overload_cast(&BRegion::Set), "", py::arg("clipping")) .def("Frame", &BRegion::Frame, "") .def("FrameInt", &BRegion::FrameInt, "") -.def("RectAt", py::overload_cast(&BRegion::RectAt), "", py::arg("index")) -.def("RectAt", py::overload_cast(&BRegion::RectAt), "", py::arg("index")) -.def("RectAtInt", py::overload_cast(&BRegion::RectAtInt), "", py::arg("index")) -.def("RectAtInt", py::overload_cast(&BRegion::RectAtInt), "", py::arg("index")) +.def("RectAt", py::overload_cast(&BRegion::RectAt), "", py::arg("index")) +.def("RectAt", py::overload_cast(&BRegion::RectAt), "", py::arg("index")) +.def("RectAtInt", py::overload_cast(&BRegion::RectAtInt), "", py::arg("index")) +.def("RectAtInt", py::overload_cast(&BRegion::RectAtInt), "", py::arg("index")) .def("CountRects", py::overload_cast<>(&BRegion::CountRects), "") .def("CountRects", py::overload_cast<>(&BRegion::CountRects), "") -.def("Intersects", py::overload_cast(&BRegion::Intersects), "", py::arg("rect")) -.def("Intersects", py::overload_cast(&BRegion::Intersects), "", py::arg("clipping")) -.def("Contains", py::overload_cast(&BRegion::Contains), "", py::arg("point")) -.def("Contains", py::overload_cast(&BRegion::Contains), "", py::arg("x"), py::arg("y")) -.def("Contains", py::overload_cast(&BRegion::Contains), "", py::arg("x"), py::arg("y")) +.def("Intersects", py::overload_cast(&BRegion::Intersects, py::const_), "", py::arg("rect")) +.def("Intersects", py::overload_cast(&BRegion::Intersects, py::const_), "", py::arg("clipping")) +.def("Contains", py::overload_cast(&BRegion::Contains, py::const_), "", py::arg("point")) +.def("Contains", py::overload_cast(&BRegion::Contains), "", py::arg("x"), py::arg("y")) +.def("Contains", py::overload_cast(&BRegion::Contains), "", py::arg("x"), py::arg("y")) .def("PrintToStream", &BRegion::PrintToStream, "") .def("OffsetBy", py::overload_cast(&BRegion::OffsetBy), "", py::arg("point")) -.def("OffsetBy", py::overload_cast(&BRegion::OffsetBy), "", py::arg("x"), py::arg("y")) +.def("OffsetBy", py::overload_cast(&BRegion::OffsetBy), "", py::arg("x"), py::arg("y")) .def("ScaleBy", py::overload_cast(&BRegion::ScaleBy), "", py::arg("scale")) .def("ScaleBy", py::overload_cast(&BRegion::ScaleBy), "", py::arg("x"), py::arg("y")) .def("MakeEmpty", &BRegion::MakeEmpty, "") diff --git a/bindings/interface/Screen.cpp b/bindings/interface/Screen.cpp index c3e08f8..f0fc681 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..26b396e 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 18ba6d6..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 93ca5d8..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")) @@ -19,5 +29,4 @@ py::class_(m, "BSeparatorItem") .def("SetEnabled", &BSeparatorItem::SetEnabled, "", py::arg("enable")) ; - } 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..a94ffe7 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 a3b0621..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 cb79c4e..b8f0f85 100644 --- a/bindings/interface/StringItem.cpp +++ b/bindings/interface/StringItem.cpp @@ -4,15 +4,38 @@ #include #include +#include #include +#include namespace py = pybind11; +class PyStringItem : public BStringItem{ + public: + using BStringItem::BStringItem; + 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); + } +private: + BStringItem* item_; +}; PYBIND11_MODULE(StringItem,m) { -py::class_(m, "BStringItem") -.def(py::init(), "", py::arg("text"), py::arg("outlineLevel")=0, py::arg("expanded")=true) +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")) .def("Archive", &BStringItem::Archive, "", py::arg("archive"), py::arg("deep")=true) diff --git a/bindings/interface/StringView.cpp b/bindings/interface/StringView.cpp index 53e2631..0406f1f 100644 --- a/bindings/interface/StringView.cpp +++ b/bindings/interface/StringView.cpp @@ -8,11 +8,83 @@ 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") -.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) +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")) .def_static("Instantiate", &BStringView::Instantiate, "", py::arg("archive")) .def("Archive", &BStringView::Archive, "", py::arg("archive"), py::arg("deep")=true) diff --git a/bindings/interface/TabView.cpp b/bindings/interface/TabView.cpp index 575d81b..5062c3a 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")) @@ -37,10 +194,10 @@ py::class_(m, "BTab") .def("DrawFocusMark", &BTab::DrawFocusMark, "", py::arg("owner"), py::arg("frame")) .def("DrawLabel", &BTab::DrawLabel, "", py::arg("owner"), py::arg("frame")) .def("DrawTab", &BTab::DrawTab, "", py::arg("owner"), py::arg("frame"), py::arg("position"), py::arg("full")=true) -.def_readwrite("Private", &BTab::Private, "") +//.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")) @@ -95,6 +252,14 @@ py::class_(m, "BTabView") .def("ViewForTab", &BTabView::ViewForTab, "", py::arg("tabIndex")) .def("IndexOf", &BTabView::IndexOf, "", py::arg("tab")) ; - - +py::enum_(m, "tab_side", "") +// kLeftSide = 1 << 0, +// kRightSide = 1 << 1, +// kTopSide = 1 << 2, +// kBottomSide = 1 << 3 +.value("kLeftSide", BTabView::tab_side::kLeftSide, "") +.value("kRightSide", BTabView::tab_side::kRightSide, "") +.value("kTopSide", BTabView::tab_side::kTopSide, "") +.value("kBottomSide", BTabView::tab_side::kBottomSide, "") +.export_values(); } diff --git a/bindings/interface/TextControl.cpp b/bindings/interface/TextControl.cpp index 4a95901..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 86221d5..04e2efa 100644 --- a/bindings/interface/TextView.cpp +++ b/bindings/interface/TextView.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -14,6 +15,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", "") @@ -28,21 +121,54 @@ py::enum_(m, "undo_state", "") //m.attr("TextGapBuffer") = TextGapBuffer; py::class_(m, "text_run") +.def(py::init<>()) .def_readwrite("offset", &text_run::offset, "") .def_readwrite("font", &text_run::font, "") .def_readwrite("color", &text_run::color, "") ; +//tentativo di creare text_run gestito da python, produce lo stesso errori +/*m.def("create_text_run", []() { return new text_run(); // Python prende proprietà +}, py::return_value_policy::take_ownership);*/ py::class_(m, "text_run_array") +//.def(py::init<>()) +/*init has been commented out because it's safer creating a text_run_array with +AllocRunArray static function*/ .def_readwrite("count", &text_run_array::count, "") -.def_readonly("runs", &text_run_array::runs, "") +//.def_readonly("runs", &text_run_array::runs, "") +//this method works but gives error on delete(rewrite draw?) +/*.def_property("runs",[](const text_run_array& self){ + return std::vector(self.runs, self.runs + self.text_run_array::count); + },[](text_run_array& self, const py::list &new_values) { + std::vector newruns; + for (auto item : new_values) { + newruns.push_back(item.cast()); + } + std::memcpy(self.runs, newruns.data(), newruns.size() * sizeof(text_run)); + })*/ +//also this one works but gives errors as above +.def_property("runs", [](const text_run_array& self) -> py::list { + py::list result; for (int i = 0; i < self.count; ++i) { + result.append(self.runs[i]); + } return result; +}, [](text_run_array& self, const py::list& new_values) { + int i = 0; for (auto item : new_values) { + if (i >= self.count) break; // Evita overflow + self.runs[i] = item.cast(); ++i; + } +}) ; +/* +py::class_(m, "text_run_array") +.def_readwrite("count", &text_run_array::count, "") +.def_readonly("runs", &text_run_array::runs, "") +;*/ -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")) +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) -.def(py::init(), "", py::arg("name"), py::arg("initialFont"), py::arg("initialColor"), py::arg("flags")) +.def(py::init(), "", py::arg("name"), py::arg("initialFont"), py::arg("initialColor"), py::arg("flags")) .def(py::init(), "", py::arg("archive")) .def_static("Instantiate", &BTextView::Instantiate, "", py::arg("archive")) .def("Archive", &BTextView::Archive, "", py::arg("archive"), py::arg("deep")=true) @@ -62,16 +188,57 @@ py::class_>(m, "BTextV .def("GetSupportedSuites", &BTextView::GetSupportedSuites, "", py::arg("data")) .def("Perform", &BTextView::Perform, "", py::arg("code"), py::arg("data")) .def("SetText", py::overload_cast(&BTextView::SetText), "", py::arg("text"), py::arg("runs")=NULL) -.def("SetText", py::overload_cast(&BTextView::SetText), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL) -.def("SetText", py::overload_cast(&BTextView::SetText), "", py::arg("file"), py::arg("offset"), py::arg("length"), py::arg("runs")=NULL) +.def("SetText", py::overload_cast(&BTextView::SetText), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL) +.def("SetText", py::overload_cast(&BTextView::SetText), "", py::arg("file"), py::arg("offset"), py::arg("length"), py::arg("runs")=NULL) +.def("SetText", [](BTextView& self, const char* text, const py::list& runs){//&SetTextWrapper, "", py::arg("text"), py::arg("runs")=NULL) + if (!runs.is_none()) { + auto len = runs.size(); + text_run_array* tra = BTextView::AllocRunArray(len); + int i = 0; for (auto item : runs) { + if (i >= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetText(text, tra); + BTextView::FreeRunArray(tra); + } +}, "", py::arg("text"), py::arg("runs")) +.def("SetText", [](BTextView& self, const char* text, int32 length, const py::list& runs){//&SetTextWrapper, "", py::arg("text"), py::arg("runs")=NULL) + if (!runs.is_none()) { + auto len = runs.size(); + text_run_array* tra = BTextView::AllocRunArray(len); + int i = 0; for (auto item : runs) { + if (i >= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetText(text, length, tra); + BTextView::FreeRunArray(tra); + } +}, "", py::arg("text"), py::arg("length"), py::arg("runs")) +.def("SetText", [](BTextView& self, BFile* file, int32 offset, int32 length, const py::list& runs){//&SetTextWrapper, "", py::arg("text"), py::arg("runs")=NULL) + if (!runs.is_none()) { + auto len = runs.size(); + text_run_array* tra = BTextView::AllocRunArray(len); + int i = 0; for (auto item : runs) { + if (i >= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetText(file, offset, length, tra); + BTextView::FreeRunArray(tra); + } +}, "", py::arg("file"), py::arg("offset"), py::arg("length"), py::arg("runs")) .def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("text"), py::arg("runs")=NULL) -.def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL) -.def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("offset"), py::arg("text"), py::arg("length"), py::arg("runs")=NULL) +.def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL) +.def("Insert", py::overload_cast(&BTextView::Insert), "", py::arg("offset"), py::arg("text"), py::arg("length"), py::arg("runs")=NULL) .def("Delete", py::overload_cast<>(&BTextView::Delete), "") -.def("Delete", py::overload_cast(&BTextView::Delete), "", py::arg("startOffset"), py::arg("endOffset")) +.def("Delete", py::overload_cast(&BTextView::Delete), "", py::arg("startOffset"), py::arg("endOffset")) .def("Text", &BTextView::Text, "") .def("TextLength", &BTextView::TextLength, "") -.def("GetText", &BTextView::GetText, "", py::arg("offset"), py::arg("length"), py::arg("buffer")) +//.def("GetText", &BTextView::GetText, "", py::arg("offset"), py::arg("length"), py::arg("buffer")) +.def("GetText", [](BTextView& self,int32 offset,int32 length) { + std::vector buffer(length); + self.GetText(offset, length, buffer.data()); + return std::string(buffer.data(), length); +}, "", py::arg("offset"), py::arg("length")) .def("ByteAt", &BTextView::ByteAt, "", py::arg("offset")) .def("CountLines", &BTextView::CountLines, "") .def("CurrentLine", &BTextView::CurrentLine, "") @@ -84,19 +251,50 @@ py::class_>(m, "BTextV .def("AcceptsDrop", &BTextView::AcceptsDrop, "", py::arg("message")) .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", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) -//.def("SetFontAndColor", py::overload_cast(&BTextView::SetFontAndColor,py::const_), "", py::arg("startOffset"), py::arg("endOffset"), py::arg("font"), py::arg("mode")=B_FONT_ALL, py::arg("color")=NULL) -//.def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("offset"), py::arg("_font"), py::arg("_color")=NULL) -//.def("GetFontAndColor", py::overload_cast(&BTextView::GetFontAndColor,py::const_), "", py::arg("_font"), py::arg("_mode"), py::arg("_color")=NULL, py::arg("_sameColor")=NULL) +//.def("GetSelection", &BTextView::GetSelection, "", py::arg("_start"), py::arg("_end")) +.def("GetSelection", [](BTextView& self)-> std::tuple{ + int32 start; + int32 end; + self.GetSelection(&start,&end); + return std::make_tuple(start,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::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::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("SetRunArray", &BTextView::SetRunArray, "", py::arg("startOffset"), py::arg("endOffset"), py::arg("runs")) +.def("SetRunArray", [](BTextView& self, int32 startOffset, int32 endOffset, const py::list& runs) { + if (!runs.is_none()) { + auto len = runs.size(); + text_run_array* tra = BTextView::AllocRunArray(len); + int i = 0; for (auto item : runs) { + if (i >= len) break; // Evita overflow + tra->runs[i] = item.cast(); ++i; + } + self.SetRunArray(startOffset, endOffset, tra); + BTextView::FreeRunArray(tra); + } +},"",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")) +.def("LineAt", py::overload_cast(&BTextView::LineAt,py::const_), "", py::arg("offset")) .def("LineAt", py::overload_cast(&BTextView::LineAt,py::const_), "", py::arg("point")) -.def("PointAt", &BTextView::PointAt, "", py::arg("offset"), py::arg("_height")=NULL) +//.def("PointAt", &BTextView::PointAt, "", py::arg("offset"), py::arg("_height")=NULL) +.def("PointAt", [](BTextView& self, int32 offset) -> std::tuple { + float height; + BPoint ret = self.PointAt(offset,&height); + return std::make_tuple(ret,height); +},"",py::arg("offset")) .def("OffsetAt", py::overload_cast(&BTextView::OffsetAt,py::const_), "", py::arg("point")) -.def("OffsetAt", py::overload_cast(&BTextView::OffsetAt,py::const_), "", py::arg("line")) -.def("FindWord", &BTextView::FindWord, "", py::arg("offset"), py::arg("_fromOffset"), py::arg("_toOffset")) +.def("OffsetAt", py::overload_cast(&BTextView::OffsetAt,py::const_), "", py::arg("line")) +//.def("FindWord", &BTextView::FindWord, "", py::arg("offset"), py::arg("_fromOffset"), py::arg("_toOffset")) +.def("FindWord", [](BTextView& self, int32 offset) -> std::tuple{ + int32 _fromOffset; + int32 _toOffset; + self.FindWord(offset,&_fromOffset,&_toOffset); + return std::make_tuple(_fromOffset,_toOffset); +},"", py::arg("offset")) .def("CanEndLine", &BTextView::CanEndLine, "", py::arg("offset")) .def("LineWidth", &BTextView::LineWidth, "", py::arg("lineNumber")=0) .def("LineHeight", &BTextView::LineHeight, "", py::arg("lineNumber")=0) @@ -142,8 +340,8 @@ py::class_>(m, "BTextV .def_static("AllocRunArray", &BTextView::AllocRunArray, "", py::arg("entryCount"), py::arg("outSize")=NULL) .def_static("CopyRunArray", &BTextView::CopyRunArray, "", py::arg("orig"), py::arg("countDelta")=0) .def_static("FreeRunArray", &BTextView::FreeRunArray, "", py::arg("array")) -.def_static("FlattenRunArray", &BTextView::FlattenRunArray, "", py::arg("runArray"), py::arg("_size")=NULL) -.def_static("UnflattenRunArray", &BTextView::UnflattenRunArray, "", py::arg("data"), py::arg("_size")=NULL) +.def_static("FlattenRunArray", &BTextView::FlattenRunArray, "", py::arg("runArray"), py::arg("_size")=NULL)// return py::bytes or py::buffer? +.def_static("UnflattenRunArray", &BTextView::UnflattenRunArray, "", py::arg("data"), py::arg("_size")=NULL)// data should be py::bytes or py::buffer? .def("Undo", &BTextView::Undo, "", py::arg("clipboard")) .def("UndoState", &BTextView::UndoState, "", py::arg("isRedo")) .def("MinSize", &BTextView::MinSize, "") diff --git a/bindings/interface/TwoDimensionalLayout.cpp b/bindings/interface/TwoDimensionalLayout.cpp index 7476e90..d99d086 100644 --- a/bindings/interface/TwoDimensionalLayout.cpp +++ b/bindings/interface/TwoDimensionalLayout.cpp @@ -8,8 +8,68 @@ namespace py = pybind11; +class PyBTwoDimensionalLayout : public BTwoDimensionalLayout{ + public: + using BTwoDimensionalLayout::BTwoDimensionalLayout; + BSize BaseMinSize() override { + PYBIND11_OVERLOAD(BSize, BTwoDimensionalLayout, BaseMinSize); + } + BSize BaseMaxSize() override { + PYBIND11_OVERLOAD(BSize, BTwoDimensionalLayout, BaseMaxSize); + } + BSize BasePreferredSize() override { + PYBIND11_OVERLOAD(BSize, BTwoDimensionalLayout, BasePreferredSize); + } + BAlignment BaseAlignment() override { + PYBIND11_OVERLOAD(BAlignment, BTwoDimensionalLayout, BaseAlignment); + } + bool HasHeightForWidth() override { + PYBIND11_OVERLOAD(bool, BTwoDimensionalLayout, HasHeightForWidth); + } + void GetHeightForWidth(float width, float* min, float* max, float* preferred) override { + PYBIND11_OVERLOAD(void, BTwoDimensionalLayout, GetHeightForWidth, width, min, max, preferred); + } + void SetFrame(BRect frame) override { + PYBIND11_OVERLOAD(void, BTwoDimensionalLayout, SetFrame, frame); + } + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BTwoDimensionalLayout, Archive, into, deep); + } + status_t Perform(perform_code d, void* arg) override { + PYBIND11_OVERLOAD(status_t, BTwoDimensionalLayout, Perform, d, arg); + } + int32 InternalCountColumns() override { + PYBIND11_OVERLOAD_PURE(int32, BTwoDimensionalLayout, InternalCountColumns); + } + int32 InternalCountRows() override { + PYBIND11_OVERLOAD_PURE(int32, BTwoDimensionalLayout, InternalCountRows); + } + void GetColumnRowConstraints(orientation orientation, int32 index, ColumnRowConstraints* constraints) override { + PYBIND11_OVERLOAD_PURE(void, BTwoDimensionalLayout, GetColumnRowConstraints, orientation, index, constraints); + } + void GetItemDimensions(BLayoutItem* item, Dimensions* dimensions) override { + PYBIND11_OVERLOAD_PURE(void, BTwoDimensionalLayout, GetItemDimensions, item, dimensions); + } +}; PYBIND11_MODULE(TwoDimensionalLayout,m) { -py::class_(m, "BTwoDimensionalLayout"); +py::class_(m, "BTwoDimensionalLayout") +.def(py::init(), "") +.def(py::init(), "", py::arg("from")) +.def("SetInsets", py::overload_cast(&BTwoDimensionalLayout::SetInsets), "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom")) +.def("SetInsets", py::overload_cast(&BTwoDimensionalLayout::SetInsets), "", py::arg("horizontal"), py::arg("vertical")) +.def("SetInsets", py::overload_cast(&BTwoDimensionalLayout::SetInsets), "", py::arg("insets")) +.def("GetInsets", &BTwoDimensionalLayout::GetInsets, "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom")) +.def("AlignLayoutWith", &BTwoDimensionalLayout::AlignLayoutWith, "", py::arg("other"), py::arg("orientation")) +.def("BaseMinSize", &BTwoDimensionalLayout::BaseMinSize, "") +.def("BaseMaxSize", &BTwoDimensionalLayout::BaseMaxSize, "") +.def("BasePreferredSize", &BTwoDimensionalLayout::BasePreferredSize, "") +.def("BaseAlignment", &BTwoDimensionalLayout::BaseAlignment, "") +.def("HasHeightForWidth", &BTwoDimensionalLayout::HasHeightForWidth, "") +.def("GetHeightForWidth", &BTwoDimensionalLayout::GetHeightForWidth, "", py::arg("width"), py::arg("min"), py::arg("max"), py::arg("preferred")) +.def("SetFrame", &BTwoDimensionalLayout::SetFrame, "", py::arg("frame")) +.def("Archive", &BTwoDimensionalLayout::Archive, "", py::arg("into"), py::arg("deep")=true) +.def("Perform", &BTwoDimensionalLayout::Perform, "", py::arg("d"), py::arg("arg")) +; } diff --git a/bindings/interface/View.cpp b/bindings/interface/View.cpp index 8c9312e..d9bbb46 100644 --- a/bindings/interface/View.cpp +++ b/bindings/interface/View.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -22,10 +24,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,19 +190,23 @@ 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_FONT_FAMILY_AND_STYLE") = 1; -m.attr("B_FONT_SIZE") = 2; -m.attr("B_FONT_SHEAR") = 4; -m.attr("B_FONT_ROTATION") = 8; -m.attr("B_FONT_SPACING") = 16; -m.attr("B_FONT_ENCODING") = 32; -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, "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(); py::enum_(m, "coordinate_space", "") .value("B_CURRENT_STATE_COORDINATES", coordinate_space::B_CURRENT_STATE_COORDINATES, "") @@ -68,50 +217,75 @@ py::enum_(m, "coordinate_space", "") .value("B_WINDOW_COORDINATES", coordinate_space::B_WINDOW_COORDINATES, "") .value("B_SCREEN_COORDINATES", coordinate_space::B_SCREEN_COORDINATES, "") .export_values(); - +/*TODO: it seems that these values are faulted or not read properly*/ m.attr("B_FULL_UPDATE_ON_RESIZE") = B_FULL_UPDATE_ON_RESIZE; - m.attr("_B_RESERVED1_") = _B_RESERVED1_; - m.attr("B_WILL_DRAW") = B_WILL_DRAW; - m.attr("B_PULSE_NEEDED") = B_PULSE_NEEDED; - m.attr("B_NAVIGABLE_JUMP") = B_NAVIGABLE_JUMP; - m.attr("B_FRAME_EVENTS") = B_FRAME_EVENTS; - m.attr("B_NAVIGABLE") = B_NAVIGABLE; - m.attr("B_SUBPIXEL_PRECISE") = B_SUBPIXEL_PRECISE; - m.attr("B_DRAW_ON_CHILDREN") = B_DRAW_ON_CHILDREN; - m.attr("B_INPUT_METHOD_AWARE") = B_INPUT_METHOD_AWARE; - m.attr("B_SCROLL_VIEW_AWARE") = B_SCROLL_VIEW_AWARE; - m.attr("B_SUPPORTS_LAYOUT") = B_SUPPORTS_LAYOUT; - m.attr("B_INVALIDATE_AFTER_LAYOUT") = B_INVALIDATE_AFTER_LAYOUT; - m.attr("B_TRANSPARENT_BACKGROUND") = B_TRANSPARENT_BACKGROUND; - m.attr("_VIEW_TOP_") = _VIEW_TOP_; - m.attr("_VIEW_LEFT_") = _VIEW_LEFT_; - m.attr("_VIEW_BOTTOM_") = _VIEW_BOTTOM_; - m.attr("_VIEW_RIGHT_") = _VIEW_RIGHT_; - m.attr("_VIEW_CENTER_") = _VIEW_CENTER_; //m.attr("ViewState") = ViewState; - -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")) +m.attr("B_FOLLOW_NONE") = B_FOLLOW_NONE; +m.attr("B_FOLLOW_ALL_SIDES") = B_FOLLOW_ALL_SIDES; +m.attr("B_FOLLOW_ALL") = B_FOLLOW_ALL_SIDES; +m.attr("B_FOLLOW_LEFT") = B_FOLLOW_LEFT; +m.attr("B_FOLLOW_RIGHT") = B_FOLLOW_RIGHT; +m.attr("B_FOLLOW_LEFT_RIGHT") = B_FOLLOW_LEFT_RIGHT; +m.attr("B_FOLLOW_H_CENTER") = B_FOLLOW_H_CENTER; +m.attr("B_FOLLOW_TOP") = B_FOLLOW_TOP; +m.attr("B_FOLLOW_BOTTOM") = B_FOLLOW_BOTTOM; +m.attr("B_FOLLOW_TOP_BOTTOM") = B_FOLLOW_TOP_BOTTOM; +m.attr("B_FOLLOW_V_CENTER") = B_FOLLOW_V_CENTER; +/* Hardcoded values +m.attr("B_FULL_UPDATE_ON_RESIZE") = 0x80000000UL; +m.attr("_B_RESERVED1_") = 0x40000000UL; +m.attr("B_WILL_DRAW") = 0x20000000UL; +m.attr("B_PULSE_NEEDED") = 0x10000000UL; +m.attr("B_NAVIGABLE_JUMP") = 0x08000000UL; +m.attr("B_FRAME_EVENTS") = 0x04000000UL; +m.attr("B_NAVIGABLE") = 0x02000000UL; +m.attr("B_SUBPIXEL_PRECISE") = 0x01000000UL; +m.attr("B_DRAW_ON_CHILDREN") = 0x00800000UL; +m.attr("B_INPUT_METHOD_AWARE") = 0x00400000UL; +m.attr("B_SCROLL_VIEW_AWARE") = 0x00200000UL; +m.attr("B_SUPPORTS_LAYOUT") = 0x00100000UL; +m.attr("B_INVALIDATE_AFTER_LAYOUT") = 0x00080000UL; +m.attr("B_TRANSPARENT_BACKGROUND") = 0x00040000UL; +m.attr("_VIEW_TOP_") = 1UL; +m.attr("_VIEW_LEFT_") = 2UL; +m.attr("_VIEW_BOTTOM_") = 3UL; +m.attr("_VIEW_RIGHT_") = 4UL; +m.attr("_VIEW_CENTER_") = 5UL; +#define _rule_(r1, r2, r3, r4) (((r1) << 12) | ((r2) << 8) | ((r3) << 4) | (r4)) +m.attr("B_FOLLOW_NONE") = 0; +m.attr("B_FOLLOW_ALL_SIDES") = _rule_(1UL,2UL,3UL,4UL); +m.attr("B_FOLLOW_ALL") = _rule_(1UL,2UL,3UL,4UL); +m.attr("B_FOLLOW_LEFT") = _rule_(0, 2UL, 0, 2UL); +m.attr("B_FOLLOW_RIGHT") = _rule_(0, 4UL, 0, 4UL); +m.attr("B_FOLLOW_LEFT_RIGHT") = _rule_(0, 2UL, 0, 4UL); +m.attr("B_FOLLOW_H_CENTER") = _rule_(0, 5UL, 0, 5UL); +m.attr("B_FOLLOW_TOP") = _rule_(1UL, 0, 1UL, 0); +m.attr("B_FOLLOW_BOTTOM") = _rule_(3UL, 0, 3UL, 0); +m.attr("B_FOLLOW_TOP_BOTTOM") = _rule_(1UL, 0, 3UL, 0); +m.attr("B_FOLLOW_V_CENTER") = _rule_(5UL, 0, 5UL, 0);*/ + +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")) .def_static("Instantiate", &BView::Instantiate, "", py::arg("archive")) .def("Archive", &BView::Archive, "", py::arg("archive"), py::arg("deep")=true) @@ -142,7 +316,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 +345,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,11 +368,11 @@ py::class_>(m, "BView") .def("ViewColor", &BView::ViewColor, "") .def("SetViewUIColor", &BView::SetViewUIColor, "", py::arg("which"), py::arg("tint")=B_NO_TINT) .def("ViewUIColor", &BView::ViewUIColor, "", py::arg("tint")=NULL) -//.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("srcRect"), py::arg("dstRect"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) -//.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) +.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("srcRect"), py::arg("dstRect"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) +.def("SetViewBitmap", py::overload_cast(&BView::SetViewBitmap), "", py::arg("bitmap"), py::arg("followFlags")=B_FOLLOW_LEFT_TOP, py::arg("options")=B_TILE_BITMAP) .def("ClearViewBitmap", &BView::ClearViewBitmap, "") -.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) +.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) .def("ClearViewOverlay", &BView::ClearViewOverlay, "") .def("SetHighColor", py::overload_cast(&BView::SetHighColor), "", py::arg("color")) .def("SetHighColor", py::overload_cast(&BView::SetHighColor), "", py::arg("red"), py::arg("green"), py::arg("blue"), py::arg("alpha")=255) @@ -231,21 +405,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 +452,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,17 +469,15 @@ 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")) +.def("StringWidth", py::overload_cast(&BView::StringWidth, py::const_), "", py::arg("string"), py::arg("length")) //.def("GetStringWidths", &BView::GetStringWidths, "", py::arg("stringArray"), py::arg("lengthArray"), py::arg("numStrings"), py::arg("widthArray")) .def("SetFontSize", &BView::SetFontSize, "", py::arg("size")) .def("ForceFontAliasing", &BView::ForceFontAliasing, "", py::arg("enable")) diff --git a/bindings/interface/Window.cpp b/bindings/interface/Window.cpp index d3d19e9..2bef299 100644 --- a/bindings/interface/Window.cpp +++ b/bindings/interface/Window.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -20,31 +20,112 @@ class PyBWindow : public BWindow{ using BWindow::BWindow; void MessageReceived(BMessage* msg) override { - py::gil_scoped_release release; - { - py::gil_scoped_acquire acquire; - PYBIND11_OVERLOAD( - void, - BWindow, - MessageReceived, - msg - ); - } + PYBIND11_OVERLOAD( + void, + BWindow, + MessageReceived, + msg + ); } bool QuitRequested() override { - py::gil_scoped_release release; - { - py::gil_scoped_acquire acquire; - PYBIND11_OVERLOAD( - bool, - BWindow, - QuitRequested, - ); - } + PYBIND11_OVERLOAD( + bool, + BWindow, + QuitRequested, + ); } + status_t Archive(BMessage* archive, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BWindow, Archive, archive, deep); + } + void Quit() override { + // limit the scope of py::gil_scoped_acquire, otherwise there may + // be a deadlock, likely due to us holding the lock even after + // the window thread has terminated. + { + py::gil_scoped_acquire acquire; + + // FIXME: What if the Python overload never actually calls + // BWindow::Quit? + do_not_delete.release(); + } + + 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 { + py::gil_scoped_acquire acquire; + + // FIXME: What if the Python overload never actually calls + // BWindow::Run? + do_not_delete = py::cast(this); + + PYBIND11_OVERLOAD(thread_id, BWindow, Run); + } + void SetLayout(BLayout* layout) override { + PYBIND11_OVERLOAD(void, BWindow, SetLayout, layout); + } + + private: + // For an explanation, see do_not_delete in Looper.cpp + py::object do_not_delete; }; +void QuitWrapper(BWindow& self) { + // For an explanation, see QuitWrapper in Looper.cpp + py::gil_scoped_release release; + self.Quit(); +} + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BWindow); + PYBIND11_MODULE(Window,m) { py::enum_(m, "window_type", "") @@ -105,13 +186,13 @@ m.attr("B_MOVE_IF_PARTIALLY_OFFSCREEN") = 2; //m.attr("PortLink") = PortLink; -py::class_>(m, "BWindow") -.def(py::init(), "", py::arg("frame"), py::arg("title"), py::arg("type"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) -.def(py::init(), "", py::arg("frame"), py::arg("title"), py::arg("look"), py::arg("feel"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) -.def(py::init(), "", py::arg("archive")) +py::class_(m, "BWindow") +.def(py::init_alias(), "", py::arg("frame"), py::arg("title"), py::arg("type"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) +.def(py::init_alias(), "", py::arg("frame"), py::arg("title"), py::arg("look"), py::arg("feel"), py::arg("flags"), py::arg("workspace")=B_CURRENT_WORKSPACE) +.def(py::init_alias(), "", py::arg("archive")) .def_static("Instantiate", &BWindow::Instantiate, "", py::arg("archive")) .def("Archive", &BWindow::Archive, "", py::arg("archive"), py::arg("deep")=true) -.def("Quit", &BWindow::Quit, "") +.def("Quit", &QuitWrapper, "") .def("Close", &BWindow::Close, "") .def("AddChild", py::overload_cast(&BWindow::AddChild), "", py::arg("child"), py::arg("before")=NULL) .def("AddChild", py::overload_cast(&BWindow::AddChild), "", py::arg("child")) @@ -131,8 +212,8 @@ py::class_>(m, "BWindow" .def("ScreenChanged", &BWindow::ScreenChanged, "", py::arg("screenSize"), py::arg("depth")) .def("SetPulseRate", &BWindow::SetPulseRate, "", py::arg("rate")) .def("PulseRate", &BWindow::PulseRate, "") -.def("AddShortcut", py::overload_cast(&BWindow::AddShortcut), "", py::arg("key"), py::arg("modifiers"), py::arg("message")) -.def("AddShortcut", py::overload_cast(&BWindow::AddShortcut), "", py::arg("key"), py::arg("modifiers"), py::arg("message"), py::arg("target")) +.def("AddShortcut", py::overload_cast(&BWindow::AddShortcut), "", py::arg("key"), py::arg("modifiers"), py::arg("message")) +.def("AddShortcut", py::overload_cast(&BWindow::AddShortcut), "", py::arg("key"), py::arg("modifiers"), py::arg("message"), py::arg("target")) .def("HasShortcut", &BWindow::HasShortcut, "", py::arg("key"), py::arg("modifiers")) .def("RemoveShortcut", &BWindow::RemoveShortcut, "", py::arg("key"), py::arg("modifiers")) .def("SetDefaultButton", &BWindow::SetDefaultButton, "", py::arg("button")) diff --git a/bindings/kernel/OS.cpp b/bindings/kernel/OS.cpp new file mode 100644 index 0000000..bdb330e --- /dev/null +++ b/bindings/kernel/OS.cpp @@ -0,0 +1,635 @@ +#include +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +unsigned long real_time_clock_wrapper() { + return real_time_clock(); +} + +bigtime_t real_time_clock_usecs_wrapper(){ + return real_time_clock_usecs(); +} + +bigtime_t system_time_wrapper(){ + return system_time(); +} + +nanotime_t system_time_nsecs_wrapper(){ + return system_time_nsecs(); +} + +int32 is_computer_on_wrapper(){ + return is_computer_on(); +} + +double is_computer_on_fire_wrapper(){ + return is_computer_on_fire(); +} + +std::string get_area_info_name(const area_info& self) { + return std::string(self.name); +} + +void set_area_info_name(area_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_OS_NAME_LENGTH - 1); + self.name[B_OS_NAME_LENGTH - 1] = '\0'; +} +// +std::string get_port_info_name(const port_info& self) { + return std::string(self.name); +} + +void set_port_info_name(port_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_OS_NAME_LENGTH - 1); + self.name[B_OS_NAME_LENGTH - 1] = '\0'; +} +// +std::string get_sem_info_name(const sem_info& self) { + return std::string(self.name); +} + +void set_sem_info_name(sem_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_OS_NAME_LENGTH - 1); + self.name[B_OS_NAME_LENGTH - 1] = '\0'; +} +// +std::string get_team_info_args(const team_info& self) { + return std::string(self.args); +} + +void set_team_info_args(team_info& self, const std::string& args) { + std::strncpy(self.args, args.c_str(), 64 - 1); + self.args[64 - 1] = '\0'; +} + +area_id create_area_wrapper(const std::string &name, py::capsule &startAddress, + uint32_t addressSpec, size_t size, uint32_t lock, + uint32_t protection) { + void *startAddressPtr = startAddress; // Converte il py::capsule in void* + return create_area(name.c_str(), &startAddressPtr, addressSpec, size, lock, protection); +} +area_id clone_area_wrapper(const std::string &name, py::capsule &destAddress, + uint32_t addressSpec, uint32_t protection, + area_id source) { + void *destAddressPtr = destAddress.get_pointer(); // Converte il py::capsule in void* + return clone_area(name.c_str(), &destAddressPtr, addressSpec, protection, source); +} + +status_t get_cpu_info_wrapper(uint32 firstCPU, uint32 cpuCount, cpu_info* info) { + return _get_cpu_info_etc((firstCPU), (cpuCount), (info), sizeof(*(info))); +} + +status_t get_thread_info_wrapper(thread_id id, thread_info *info) { + return _get_thread_info((id), (info), sizeof(*(info))); +} + +status_t get_next_thread_info_wrapper(team_id team, int32 *cookie, thread_info *info) { + return _get_next_thread_info((team), (cookie), (info), sizeof(*(info))); +} + +status_t get_team_usage_info_wrapper(team_id team, int32 who, team_usage_info *info) { + return _get_team_usage_info((team), (who), (info), sizeof(*(info))); +} + +status_t get_team_info_wrapper(team_id id, team_info *info) { + return _get_team_info((id), (info), sizeof(*(info))); +} + +status_t get_next_team_info_wrapper(int32 *cookie, team_info *info) { + return _get_next_team_info((cookie), (info), sizeof(*(info))); +} + +status_t get_sem_info_wrapper(sem_id id, struct sem_info *info) { + return _get_sem_info((id), (info), sizeof(*(info))); +} + +status_t get_next_sem_info_wrapper(team_id team, int32 *cookie, struct sem_info *info) { + return _get_next_sem_info((team), (cookie), (info), sizeof(*(info))); +} + +status_t get_port_message_info_etc_wrapper(port_id port, port_message_info *info, uint32 flags, bigtime_t timeout) { + return _get_port_message_info_etc((port), (info), sizeof(*(info)), flags, timeout); +} + +status_t get_next_port_info_wrapper(team_id team, int32 *cookie, port_info *info) { + return _get_next_port_info((team), (cookie), (info), sizeof(*(info))); +} + +status_t get_port_info_wrapper(port_id port, port_info *info) { + return _get_port_info((port), (info), sizeof(*(info))); +} + +status_t get_next_area_info_wrapper(team_id team, ssize_t *cookie, area_info *areaInfo){ + return _get_next_area_info((team), (cookie), (areaInfo), sizeof(*(areaInfo))); +} + +status_t get_area_info_wrapper(area_id id, area_info *areaInfo){ + return _get_area_info((id), (areaInfo),sizeof(*(areaInfo))); +} + +PYBIND11_MODULE(OS,m) +{ +/*m.attr("B_TIMEOUT") = py::cast(B_TIMEOUT); +m.attr("B_RELATIVE_TIMEOUT") = py::cast(B_RELATIVE_TIMEOUT); +m.attr("B_ABSOLUTE_TIMEOUT") = py::cast(B_ABSOLUTE_TIMEOUT); +m.attr("B_TIMEOUT_REAL_TIME_BASE") = py::cast(B_TIMEOUT_REAL_TIME_BASE); +m.attr("B_ABSOLUTE_REAL_TIME_TIMEOUT") = py::cast(B_ABSOLUTE_REAL_TIME_TIMEOUT);*/ +m.attr("B_TIMEOUT") = 0x8; +m.attr("B_RELATIVE_TIMEOUT") = 0x8; +m.attr("B_ABSOLUTE_TIMEOUT") = 0x10; +m.attr("B_TIMEOUT_REAL_TIME_BASE") = 0x40; +m.attr("B_ABSOLUTE_REAL_TIME_TIMEOUT") = 0x10|0x40; +/* +m.attr("B_CAN_INTERRUPT") = py::cast(B_CAN_INTERRUPT); +m.attr("B_CHECK_PERMISSION") = py::cast(B_CHECK_PERMISSION); +m.attr("B_KILL_CAN_INTERRUPT") = py::cast(B_KILL_CAN_INTERRUPT); +m.attr("B_DO_NOT_RESCHEDULE") = py::cast(B_DO_NOT_RESCHEDULE); +m.attr("B_RELEASE_ALL") = py::cast(B_RELEASE_ALL); +m.attr("B_RELEASE_IF_WAITING_ONLY") = py::cast(B_RELEASE_IF_WAITING_ONLY);*/ +m.attr("B_CAN_INTERRUPT") = 0x01; +m.attr("B_CHECK_PERMISSION") = 0x04; +m.attr("B_KILL_CAN_INTERRUPT") = 0x20; +m.attr("B_DO_NOT_RESCHEDULE") = 0x02; +m.attr("B_RELEASE_ALL") = 0x08; +m.attr("B_RELEASE_IF_WAITING_ONLY") = 0x10; + +/*m.attr("B_TEAM_USAGE_SELF") = py::cast(B_TEAM_USAGE_SELF); +m.attr("B_TEAM_USAGE_CHILDREN") = py::cast(B_TEAM_USAGE_CHILDREN);*/ +m.attr("B_TEAM_USAGE_SELF") = 0; +m.attr("B_TEAM_USAGE_CHILDREN") = -1; + +py::enum_(m, "thread_state", "") +.value("B_THREAD_RUNNING", thread_state::B_THREAD_RUNNING, "") +.value("B_THREAD_READY", thread_state::B_THREAD_READY, "") +.value("B_THREAD_RECEIVING", thread_state::B_THREAD_RECEIVING, "") +.value("B_THREAD_ASLEEP", thread_state::B_THREAD_ASLEEP, "") +.value("B_THREAD_SUSPENDED", thread_state::B_THREAD_SUSPENDED, "") +.value("B_THREAD_WAITING", thread_state::B_THREAD_WAITING, "") +.export_values(); +/* +m.attr("B_ONE_SHOT_ABSOLUTE_ALARM") = py::cast(B_ONE_SHOT_ABSOLUTE_ALARM); +m.attr("B_ONE_SHOT_RELATIVE_ALARM") = py::cast(B_ONE_SHOT_RELATIVE_ALARM); +m.attr("B_PERIODIC_ALARM") = py::cast(B_PERIODIC_ALARM);*/ +m.attr("B_ONE_SHOT_ABSOLUTE_ALARM") = 1; +m.attr("B_ONE_SHOT_RELATIVE_ALARM") = 2; +m.attr("B_PERIODIC_ALARM") = 3; + +py::enum_(m, "topology_level_type", "") +.value("B_TOPOLOGY_UNKNOWN", topology_level_type::B_TOPOLOGY_UNKNOWN, "") +.value("B_TOPOLOGY_ROOT", topology_level_type::B_TOPOLOGY_ROOT, "") +.value("B_TOPOLOGY_SMT", topology_level_type::B_TOPOLOGY_SMT, "") +.value("B_TOPOLOGY_CORE", topology_level_type::B_TOPOLOGY_CORE, "") +.value("B_TOPOLOGY_PACKAGE", topology_level_type::B_TOPOLOGY_PACKAGE, "") +.export_values(); + +py::enum_(m, "cpu_platform", "") +.value("B_CPU_UNKNOWN", cpu_platform::B_CPU_UNKNOWN, "") +.value("B_CPU_x86", cpu_platform::B_CPU_x86, "") +.value("B_CPU_x86_64", cpu_platform::B_CPU_x86_64, "") +.value("B_CPU_PPC", cpu_platform::B_CPU_PPC, "") +.value("B_CPU_PPC_64", cpu_platform::B_CPU_PPC_64, "") +.value("B_CPU_M68K", cpu_platform::B_CPU_M68K, "") +.value("B_CPU_ARM", cpu_platform::B_CPU_ARM, "") +.value("B_CPU_ARM_64", cpu_platform::B_CPU_ARM_64, "") +.value("B_CPU_ALPHA", cpu_platform::B_CPU_ALPHA, "") +.value("B_CPU_MIPS", cpu_platform::B_CPU_MIPS, "") +.value("B_CPU_SH", cpu_platform::B_CPU_SH, "") +.value("B_CPU_SPARC", cpu_platform::B_CPU_SPARC, "") +.value("B_CPU_RISC_V", cpu_platform::B_CPU_RISC_V, "") +.export_values(); + +py::enum_(m, "cpu_vendor", "") +.value("B_CPU_VENDOR_UNKNOWN", cpu_vendor::B_CPU_VENDOR_UNKNOWN, "") +.value("B_CPU_VENDOR_AMD", cpu_vendor::B_CPU_VENDOR_AMD, "") +.value("B_CPU_VENDOR_CYRIX", cpu_vendor::B_CPU_VENDOR_CYRIX, "") +.value("B_CPU_VENDOR_IDT", cpu_vendor::B_CPU_VENDOR_IDT, "") +.value("B_CPU_VENDOR_INTEL", cpu_vendor::B_CPU_VENDOR_INTEL, "") +.value("B_CPU_VENDOR_NATIONAL_SEMICONDUCTOR", cpu_vendor::B_CPU_VENDOR_NATIONAL_SEMICONDUCTOR, "") +.value("B_CPU_VENDOR_RISE", cpu_vendor::B_CPU_VENDOR_RISE, "") +.value("B_CPU_VENDOR_TRANSMETA", cpu_vendor::B_CPU_VENDOR_TRANSMETA, "") +.value("B_CPU_VENDOR_VIA", cpu_vendor::B_CPU_VENDOR_VIA, "") +.value("B_CPU_VENDOR_IBM", cpu_vendor::B_CPU_VENDOR_IBM, "") +.value("B_CPU_VENDOR_MOTOROLA", cpu_vendor::B_CPU_VENDOR_MOTOROLA, "") +.value("B_CPU_VENDOR_NEC", cpu_vendor::B_CPU_VENDOR_NEC, "") +.value("B_CPU_VENDOR_HYGON", cpu_vendor::B_CPU_VENDOR_HYGON, "") +.value("B_CPU_VENDOR_SUN", cpu_vendor::B_CPU_VENDOR_SUN, "") +.value("B_CPU_VENDOR_FUJITSU", cpu_vendor::B_CPU_VENDOR_FUJITSU, "") +.export_values(); +/* +m.attr("B_OBJECT_TYPE_FD") = py::cast(B_OBJECT_TYPE_FD); +m.attr("B_OBJECT_TYPE_SEMAPHORE") = py::cast(B_OBJECT_TYPE_SEMAPHORE); +m.attr("B_OBJECT_TYPE_PORT") = py::cast(B_OBJECT_TYPE_PORT); +m.attr("B_OBJECT_TYPE_THREAD") = py::cast(B_OBJECT_TYPE_THREAD);*/ +m.attr("B_OBJECT_TYPE_FD") = 0; +m.attr("B_OBJECT_TYPE_SEMAPHORE") = 1; +m.attr("B_OBJECT_TYPE_PORT") = 2; +m.attr("B_OBJECT_TYPE_THREAD") = 3; + +/* +m.attr("B_EVENT_READ") = py::cast(B_EVENT_READ); +m.attr("B_EVENT_WRITE") = py::cast(B_EVENT_WRITE); +m.attr("B_EVENT_ERROR") = py::cast(B_EVENT_ERROR); +m.attr("B_EVENT_PRIORITY_READ") = py::cast(B_EVENT_PRIORITY_READ); +m.attr("B_EVENT_PRIORITY_WRITE") = py::cast(B_EVENT_PRIORITY_WRITE); +m.attr("B_EVENT_HIGH_PRIORITY_READ") = py::cast(B_EVENT_HIGH_PRIORITY_READ); +m.attr("B_EVENT_HIGH_PRIORITY_WRITE") = py::cast(B_EVENT_HIGH_PRIORITY_WRITE); +m.attr("B_EVENT_DISCONNECTED") = py::cast(B_EVENT_DISCONNECTED); +m.attr("B_EVENT_ACQUIRE_SEMAPHORE") = py::cast(B_EVENT_ACQUIRE_SEMAPHORE); +m.attr("B_EVENT_INVALID") = py::cast(B_EVENT_INVALID);*/ +m.attr("B_EVENT_READ") = 0x0001; +m.attr("B_EVENT_WRITE") = 0x0002; +m.attr("B_EVENT_ERROR") = 0x0004; +m.attr("B_EVENT_PRIORITY_READ") = 0x0008; +m.attr("B_EVENT_PRIORITY_WRITE") = 0x0010; +m.attr("B_EVENT_HIGH_PRIORITY_READ") = 0x0020; +m.attr("B_EVENT_HIGH_PRIORITY_WRITE") = 0x0040; +m.attr("B_EVENT_DISCONNECTED") = 0x0080; +m.attr("B_EVENT_ACQUIRE_SEMAPHORE") = 0x0001; +m.attr("B_EVENT_INVALID") = 0x1000; + + +py::class_(m, "area_info") +.def(py::init(), "") +.def_readwrite("area", &area_info::area, "") +//.def_readwrite("name", &area_info::name, "") +.def_property("name", &get_area_info_name, &set_area_info_name, "") +.def_readwrite("size", &area_info::size, "") +.def_readwrite("lock", &area_info::lock, "") +.def_readwrite("protection", &area_info::protection, "") +.def_readwrite("team", &area_info::team, "") +.def_readwrite("ram_size", &area_info::ram_size, "") +.def_readwrite("copy_count", &area_info::copy_count, "") +.def_readwrite("in_count", &area_info::in_count, "") +.def_readwrite("out_count", &area_info::out_count, "") +.def_readwrite("address", &area_info::address, "") +; + +py::class_(m, "port_info") +.def(py::init(), "") +.def_readwrite("port", &port_info::port, "") +.def_readwrite("team", &port_info::team, "") +//.def_readwrite("name", &port_info::name, "") +.def_property("name", &get_port_info_name, &set_port_info_name, "") +.def_readwrite("capacity", &port_info::capacity, "") +.def_readwrite("queue_count", &port_info::queue_count, "") +.def_readwrite("total_count", &port_info::total_count, "") +; + +py::class_(m, "port_message_info") +.def(py::init(), "") +.def_readwrite("size", &port_message_info::size, "") +.def_readwrite("sender", &port_message_info::sender, "") +.def_readwrite("sender_group", &port_message_info::sender_group, "") +.def_readwrite("sender_team", &port_message_info::sender_team, "") +; + +py::class_(m, "sem_info") +.def(py::init(), "") +.def_readwrite("sem", &sem_info::sem, "") +.def_readwrite("team", &sem_info::team, "") +//.def_readwrite("name", &sem_info::name, "") +.def_property("name", &get_sem_info_name, &set_sem_info_name, "") +.def_readwrite("count", &sem_info::count, "") +.def_readwrite("latest_holder", &sem_info::latest_holder, "") +; + +py::class_(m, "team_info") +.def(py::init(), "") +.def_readwrite("team", &team_info::team, "") +.def_readwrite("thread_count", &team_info::thread_count, "") +.def_readwrite("image_count", &team_info::image_count, "") +.def_readwrite("area_count", &team_info::area_count, "") +.def_readwrite("debugger_nub_thread", &team_info::debugger_nub_thread, "") +.def_readwrite("debugger_nub_port", &team_info::debugger_nub_port, "") +.def_readwrite("argc", &team_info::argc, "") +//.def_readwrite("args", &team_info::args, "") +.def_property("args", &get_team_info_args, &set_team_info_args, "") +.def_readwrite("uid", &team_info::uid, "") +.def_readwrite("gid", &team_info::gid, "") +; + +py::class_(m, "team_usage_info") +.def(py::init(), "") +.def_readwrite("user_time", &team_usage_info::user_time, "") +.def_readwrite("kernel_time", &team_usage_info::kernel_time, "") +; + +py::class_(m, "thread_info") +.def(py::init(), "") +.def_readwrite("thread", &thread_info::thread, "") +.def_readwrite("team", &thread_info::team, "") +.def_readonly("name", &thread_info::name, "") +.def_readwrite("state", &thread_info::state, "") +.def_readwrite("priority", &thread_info::priority, "") +.def_readwrite("sem", &thread_info::sem, "") +.def_readwrite("user_time", &thread_info::user_time, "") +.def_readwrite("kernel_time", &thread_info::kernel_time, "") +.def_readwrite("stack_base", &thread_info::stack_base, "") +.def_readwrite("stack_end", &thread_info::stack_end, "") +; + +py::class_(m, "cpu_info") +.def(py::init(), "") +.def_readwrite("active_time", &cpu_info::active_time, "") +.def_readwrite("enabled", &cpu_info::enabled, "") +.def_readwrite("current_frequency", &cpu_info::current_frequency, "") +; + +py::class_(m, "system_info") +.def(py::init(), "") +.def_readwrite("boot_time", &system_info::boot_time, "") +.def_readwrite("cpu_count", &system_info::cpu_count, "") +.def_readwrite("max_pages", &system_info::max_pages, "") +.def_readwrite("used_pages", &system_info::used_pages, "") +.def_readwrite("cached_pages", &system_info::cached_pages, "") +.def_readwrite("block_cache_pages", &system_info::block_cache_pages, "") +.def_readwrite("ignored_pages", &system_info::ignored_pages, "") +.def_readwrite("needed_memory", &system_info::needed_memory, "") +.def_readwrite("free_memory", &system_info::free_memory, "") +.def_readwrite("max_swap_pages", &system_info::max_swap_pages, "") +.def_readwrite("free_swap_pages", &system_info::free_swap_pages, "") +.def_readwrite("page_faults", &system_info::page_faults, "") +.def_readwrite("max_sems", &system_info::max_sems, "") +.def_readwrite("used_sems", &system_info::used_sems, "") +.def_readwrite("max_ports", &system_info::max_ports, "") +.def_readwrite("used_ports", &system_info::used_ports, "") +.def_readwrite("max_threads", &system_info::max_threads, "") +.def_readwrite("used_threads", &system_info::used_threads, "") +.def_readwrite("max_teams", &system_info::max_teams, "") +.def_readwrite("used_teams", &system_info::used_teams, "") +.def_readonly("kernel_name", &system_info::kernel_name, "") +.def_readonly("kernel_build_date", &system_info::kernel_build_date, "") +.def_readonly("kernel_build_time", &system_info::kernel_build_time, "") +.def_readwrite("kernel_version", &system_info::kernel_version, "") +.def_readwrite("abi", &system_info::abi, "") +; + +py::class_(m, "cpu_topology_root_info") +.def(py::init(), "") +.def_readwrite("platform", &cpu_topology_root_info::platform, "") +; + +py::class_(m, "cpu_topology_package_info") +.def(py::init(), "") +.def_readwrite("vendor", &cpu_topology_package_info::vendor, "") +.def_readwrite("cache_line_size", &cpu_topology_package_info::cache_line_size, "") +; + +py::class_(m, "cpu_topology_core_info") +.def(py::init(), "") +.def_readwrite("model", &cpu_topology_core_info::model, "") +.def_readwrite("default_frequency", &cpu_topology_core_info::default_frequency, "") +; +/* +py::class_(m, "union ") +.def_readwrite("root", &union ::root, "") +.def_readwrite("package", &union ::package, "") +.def_readwrite("core", &union ::core, "") +; +*/ +py::class_(m, "cpu_topology_node_info") +.def(py::init(), "") +.def_readwrite("id", &cpu_topology_node_info::id, "") +.def_readwrite("type", &cpu_topology_node_info::type, "") +.def_readwrite("level", &cpu_topology_node_info::level, "") +//.def_readwrite("data", &cpu_topology_node_info::data, "") +.def("get_root", [](cpu_topology_node_info& self) -> cpu_topology_root_info& { + return self.data.root; + }, py::return_value_policy::reference) +.def("get_package", [](cpu_topology_node_info& self) -> cpu_topology_package_info& { + return self.data.package; + }, py::return_value_policy::reference) +.def("get_core", [](cpu_topology_node_info& self) -> cpu_topology_core_info& { + return self.data.core; + }, py::return_value_policy::reference); +; +/* +py::class_<>(m, "") +.def_readwrite("eax", &::eax, "") +.def_readwrite("ebx", &::ebx, "") +.def_readwrite("edx", &::edx, "") +.def_readwrite("ecx", &::ecx, "") +;*/ + +py::class_(m, "cpuid_info") +.def(py::init(), "") +.def_readwrite("eax_0", &cpuid_info::eax_0, "") +.def_readwrite("eax_1", &cpuid_info::eax_1, "") +.def_readwrite("eax_2", &cpuid_info::eax_2, "") +.def_readwrite("eax_3", &cpuid_info::eax_3, "") +.def_readonly("as_chars", &cpuid_info::as_chars, "") +//def property readonly? +.def("get_reg_eax",[](cpuid_info& self) -> uint32 { + return self.regs.eax; +}, py::return_value_policy::reference) +.def("get_reg_ebx",[](cpuid_info& self) -> uint32 { + return self.regs.ebx; +}, py::return_value_policy::reference) +.def("get_reg_edx",[](cpuid_info& self) -> uint32 { + return self.regs.edx; +}, py::return_value_policy::reference) +.def("get_reg_ecx",[](cpuid_info& self) -> uint32 { + return self.regs.ecx; +}, py::return_value_policy::reference) +//.def_readwrite("regs", &cpuid_info::regs, "") +; + +py::class_(m, "object_wait_info") +.def(py::init(), "") +.def_readwrite("object", &object_wait_info::object, "") +.def_readwrite("type", &object_wait_info::type, "") +.def_readwrite("events", &object_wait_info::events, "") +; + +//m.def("create_area", &create_area, "", py::arg("name"), py::arg("startAddress"), py::arg("addressSpec"), py::arg("size"), py::arg("lock"), py::arg("protection")); +m.def("create_area", &create_area_wrapper, "", py::arg("name"), py::arg("startAddress"), py::arg("addressSpec"), py::arg("size"), py::arg("lock"), py::arg("protection")); //in python declare "start_address = None" + +//m.def("clone_area", &clone_area, "", py::arg("name"), py::arg("destAddress"), py::arg("addressSpec"), py::arg("protection"), py::arg("source")); +m.def("clone_area", &clone_area_wrapper, "", py::arg("name"), py::arg("destAddress"), py::arg("addressSpec"), py::arg("protection"), py::arg("source")); + +m.def("find_area", &find_area, "", py::arg("name")); + +m.def("area_for", &area_for, "", py::arg("address")); + +m.def("delete_area", &delete_area, "", py::arg("id")); + +m.def("resize_area", &resize_area, "", py::arg("id"), py::arg("newSize")); + +m.def("set_area_protection", &set_area_protection, "", py::arg("id"), py::arg("newProtection")); + +m.def("_get_area_info", &_get_area_info, "", py::arg("id"), py::arg("areaInfo"), py::arg("size")); +m.def("get_area_info", &get_area_info_wrapper, "", py::arg("id"), py::arg("areaInfo")); + +m.def("_get_next_area_info", &_get_next_area_info, "", py::arg("team"), py::arg("cookie"), py::arg("areaInfo"), py::arg("size")); +m.def("get_next_area_info", &get_next_area_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("areaInfo")); + +m.def("create_port", &create_port, "", py::arg("capacity"), py::arg("name")); + +m.def("find_port", &find_port, "", py::arg("name")); + +m.def("read_port", &read_port, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("read_port_etc", &read_port_etc, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize"), py::arg("flags"), py::arg("timeout")); + +m.def("write_port", &write_port, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("write_port_etc", &write_port_etc, "", py::arg("port"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize"), py::arg("flags"), py::arg("timeout")); + +m.def("close_port", &close_port, "", py::arg("port")); + +m.def("delete_port", &delete_port, "", py::arg("port")); + +m.def("port_buffer_size", &port_buffer_size, "", py::arg("port")); + +m.def("port_buffer_size_etc", &port_buffer_size_etc, "", py::arg("port"), py::arg("flags"), py::arg("timeout")); + +m.def("port_count", &port_count, "", py::arg("port")); + +m.def("set_port_owner", &set_port_owner, "", py::arg("port"), py::arg("team")); + +m.def("_get_port_info", &_get_port_info, "", py::arg("port"), py::arg("portInfo"), py::arg("portInfoSize")); +m.def("get_port_info", &get_port_info_wrapper, "", py::arg("port"), py::arg("portInfo")); + +m.def("_get_next_port_info", &_get_next_port_info, "", py::arg("team"), py::arg("cookie"), py::arg("portInfo"), py::arg("portInfoSize")); +m.def("get_next_port_info", &get_next_port_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("portInfo")); + +m.def("_get_port_message_info_etc", &_get_port_message_info_etc, "", py::arg("port"), py::arg("info"), py::arg("infoSize"), py::arg("flags"), py::arg("timeout")); +m.def("get_port_message_info_etc", &get_port_message_info_etc_wrapper, "", py::arg("port"), py::arg("info"), py::arg("flags"), py::arg("timeout")); + +m.def("create_sem", &create_sem, "", py::arg("count"), py::arg("name")); + +m.def("delete_sem", &delete_sem, "", py::arg("id")); + +m.def("acquire_sem", &acquire_sem, "", py::arg("id")); + +m.def("acquire_sem_etc", &acquire_sem_etc, "", py::arg("id"), py::arg("count"), py::arg("flags"), py::arg("timeout")); + +m.def("release_sem", &release_sem, "", py::arg("id")); + +m.def("release_sem_etc", &release_sem_etc, "", py::arg("id"), py::arg("count"), py::arg("flags")); + +m.def("switch_sem", &switch_sem, "", py::arg("semToBeReleased"), py::arg("id")); + +m.def("switch_sem_etc", &switch_sem_etc, "", py::arg("semToBeReleased"), py::arg("id"), py::arg("count"), py::arg("flags"), py::arg("timeout")); + +m.def("get_sem_count", &get_sem_count, "", py::arg("id"), py::arg("threadCount")); + +m.def("set_sem_owner", &set_sem_owner, "", py::arg("id"), py::arg("team")); + +m.def("_get_sem_info", &_get_sem_info, "", py::arg("id"), py::arg("info"), py::arg("infoSize")); +m.def("get_sem_info", &get_sem_info_wrapper, "", py::arg("id"), py::arg("info")); + +m.def("_get_next_sem_info", &_get_next_sem_info, "", py::arg("team"), py::arg("cookie"), py::arg("info"), py::arg("infoSize")); +m.def("get_next_sem_info", &get_next_sem_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("info")); + +m.def("kill_team", &kill_team, "", py::arg("team")); + +m.def("_get_team_info", &_get_team_info, "", py::arg("id"), py::arg("info"), py::arg("size")); +m.def("get_team_info", &get_team_info_wrapper, "", py::arg("id"), py::arg("info")); + +m.def("_get_next_team_info", &_get_next_team_info, "", py::arg("cookie"), py::arg("info"), py::arg("size")); +m.def("get_next_team_info", &get_next_team_info_wrapper, "", py::arg("cookie"), py::arg("info")); + +m.def("_get_team_usage_info", &_get_team_usage_info, "", py::arg("team"), py::arg("who"), py::arg("info"), py::arg("size")); +m.def("get_team_usage_info", &get_team_usage_info_wrapper, "", py::arg("team"), py::arg("who"), py::arg("info")); + +m.def("spawn_thread", &spawn_thread, "", py::arg(""), py::arg("name"), py::arg("priority"), py::arg("data")); + +m.def("kill_thread", &kill_thread, "", py::arg("thread")); + +m.def("resume_thread", &resume_thread, "", py::arg("thread")); + +m.def("suspend_thread", &suspend_thread, "", py::arg("thread")); + +m.def("rename_thread", &rename_thread, "", py::arg("thread"), py::arg("newName")); + +m.def("set_thread_priority", &set_thread_priority, "", py::arg("thread"), py::arg("newPriority")); + +m.def("exit_thread", &exit_thread, "", py::arg("status")); + +m.def("wait_for_thread", &wait_for_thread, "", py::arg("thread"), py::arg("returnValue")); + +m.def("wait_for_thread_etc", &wait_for_thread_etc, "", py::arg("id"), py::arg("flags"), py::arg("timeout"), py::arg("_returnCode")); + +m.def("on_exit_thread", &on_exit_thread, "", py::arg(""), py::arg("data")); + +m.def("find_thread", &find_thread, "", py::arg("name")); + +m.def("send_data", &send_data, "", py::arg("thread"), py::arg("code"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("receive_data", &receive_data, "", py::arg("sender"), py::arg("buffer"), py::arg("bufferSize")); + +m.def("has_data", &has_data, "", py::arg("thread")); + +m.def("snooze", &snooze, "", py::arg("amount")); + +m.def("snooze_etc", &snooze_etc, "", py::arg("amount"), py::arg("timeBase"), py::arg("flags")); + +m.def("snooze_until", &snooze_until, "", py::arg("time"), py::arg("timeBase")); + +m.def("_get_thread_info", &_get_thread_info, "", py::arg("id"), py::arg("info"), py::arg("size")); +m.def("get_thread_info", &get_thread_info_wrapper, "",py::arg("id"), py::arg("info")); + +m.def("_get_next_thread_info", &_get_next_thread_info, "", py::arg("team"), py::arg("cookie"), py::arg("info"), py::arg("size")); +m.def("get_next_thread_info", &get_next_thread_info_wrapper, "", py::arg("team"), py::arg("cookie"), py::arg("info")); + +//m.def("get_pthread_thread_id", &get_pthread_thread_id, "", py::arg("thread")); + +//m.def("real_time_clock", &real_time_clock, "", py::arg("")); +m.def("real_time_clock", &real_time_clock_wrapper, ""); + +m.def("set_real_time_clock", &set_real_time_clock, "", py::arg("secsSinceJan1st1970")); + +//m.def("real_time_clock_usecs", &real_time_clock_usecs, "", py::arg("")); +m.def("real_time_clock_usecs", &real_time_clock_usecs_wrapper, ""); + +//m.def("system_time", &system_time, "", py::arg("")); +m.def("system_time", &system_time_wrapper, ""); + +//m.def("system_time_nsecs", &system_time_nsecs, "", py::arg("")); +m.def("system_time_nsecs", &system_time_nsecs_wrapper, ""); + +m.def("set_alarm", &set_alarm, "", py::arg("when"), py::arg("flags")); + +m.def("debugger", &debugger, "", py::arg("message")); + +m.def("disable_debugger", &disable_debugger, "", py::arg("state")); + +//m.def("debug_printf", &debug_printf, "", py::arg("format")); + +m.def("debug_vprintf", &debug_vprintf, "", py::arg("format"), py::arg("args")); + +//m.def("ktrace_printf", &ktrace_printf, "", py::arg("format")); + +m.def("ktrace_vprintf", &ktrace_vprintf, "", py::arg("format"), py::arg("args")); + +m.def("get_system_info", &get_system_info, "", py::arg("info")); + +m.def("_get_cpu_info_etc", &_get_cpu_info_etc, "", py::arg("firstCPU"), py::arg("cpuCount"), py::arg("info"), py::arg("size")); +m.def("get_cpu_info", &get_cpu_info_wrapper, "", py::arg("firstCPU"), py::arg("cpuCount"), py::arg("info")); + +m.def("get_cpu_topology_info", &get_cpu_topology_info, "", py::arg("topologyInfos"), py::arg("topologyInfoCount")); + +m.def("get_cpuid", &get_cpuid, "", py::arg("info"), py::arg("eaxRegister"), py::arg("cpuNum")); + +//m.def("is_computer_on", &is_computer_on, "", py::arg("")); +m.def("is_computer_on", &is_computer_on_wrapper, ""); + +//m.def("is_computer_on_fire", &is_computer_on_fire, "", py::arg("")); +m.def("is_computer_on_fire", &is_computer_on_fire_wrapper, ""); + +m.def("send_signal", &send_signal, "", py::arg("threadID"), py::arg("signal")); + +m.def("set_signal_stack", &set_signal_stack, "", py::arg("base"), py::arg("size")); + +m.def("wait_for_objects", &wait_for_objects, "", py::arg("infos"), py::arg("numInfos")); + +m.def("wait_for_objects_etc", &wait_for_objects_etc, "", py::arg("infos"), py::arg("numInfos"), py::arg("flags"), py::arg("timeout")); + +} 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/locale/Catalog.cpp b/bindings/locale/Catalog.cpp new file mode 100644 index 0000000..7f87240 --- /dev/null +++ b/bindings/locale/Catalog.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +PYBIND11_MODULE(Catalog, m) +{ +py::class_(m, "BCatalog") +.def(py::init(), "") +.def(py::init(), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) +.def(py::init(), "", py::arg("signature"), py::arg("language")=NULL) +.def("GetString", py::overload_cast(&BCatalog::GetString), "", py::arg("string"), py::arg("context")=NULL, py::arg("comment")=NULL) +.def("GetString", py::overload_cast(&BCatalog::GetString), "", py::arg("id")) +.def("GetData", py::overload_cast(&BCatalog::GetData), "", py::arg("name"), py::arg("msg")) +.def("GetData", py::overload_cast(&BCatalog::GetData), "", py::arg("id"), py::arg("msg")) +.def("GetSignature", &BCatalog::GetSignature, "", py::arg("signature")) +.def("GetLanguage", &BCatalog::GetLanguage, "", py::arg("language")) +.def("GetFingerprint", &BCatalog::GetFingerprint, "", py::arg("fingerprint")) +.def("SetTo", py::overload_cast(&BCatalog::SetTo), "", py::arg("catalogOwner"), py::arg("language")=NULL, py::arg("fingerprint")=0) +.def("SetTo", py::overload_cast(&BCatalog::SetTo), "", py::arg("signature"), py::arg("language")=NULL) +.def("InitCheck", &BCatalog::InitCheck, "") +.def("CountItems", &BCatalog::CountItems, "") +; + + +} diff --git a/bindings/locale/CatalogData.cpp b/bindings/locale/CatalogData.cpp new file mode 100644 index 0000000..f9d5425 --- /dev/null +++ b/bindings/locale/CatalogData.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +class PyBCatalogData : public BCatalogData{ + public: + using BCatalogData::BCatalogData; + const char* GetString(const char* string, const char* context = NULL, const char* comment = NULL) override { + PYBIND11_OVERLOAD_PURE(const char*, BCatalogData, GetString, string, context, comment); + } + const char* GetString(uint32 id) override { + PYBIND11_OVERLOAD_PURE(const char*, BCatalogData, GetString, id); + } + bool CanHaveData() const override { + PYBIND11_OVERLOAD(bool, BCatalogData, CanHaveData); + } + status_t GetData(const char* name, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, GetData, name, msg); + } + status_t GetData(uint32 id, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, GetData, id, msg); + } + status_t SetString(const char* string, const char* translated, const char* context = NULL, const char* comment = NULL) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetString, string, translated, context, comment); + } + status_t SetString(int32 id, const char* translated) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetString, id, translated); + } + bool CanWriteData() const override { + PYBIND11_OVERLOAD(bool, BCatalogData, CanWriteData); + } + status_t SetData(const char* name, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetData, name, msg); + } + status_t SetData(uint32 id, BMessage* msg) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, SetData, id, msg); + } + status_t ReadFromFile(const char* path = NULL) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, ReadFromFile, path); + } + status_t ReadFromAttribute(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, ReadFromAttribute, appOrAddOnRef); + } + status_t ReadFromResource(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, ReadFromResource, appOrAddOnRef); + } + status_t WriteToFile(const char* path = NULL) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, WriteToFile, path); + } + status_t WriteToAttribute(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, WriteToAttribute, appOrAddOnRef); + } + status_t WriteToResource(const entry_ref& appOrAddOnRef) override { + PYBIND11_OVERLOAD(status_t, BCatalogData, WriteToResource, appOrAddOnRef); + } + void MakeEmpty() override { + PYBIND11_OVERLOAD(void, BCatalogData, MakeEmpty); + } + int32 CountItems() const override { + PYBIND11_OVERLOAD(int32, BCatalogData, CountItems); + } +}; + +PYBIND11_MODULE(CatalogData, m) +{ +//m.attr("gCatalogAddOnPriority") = py::cast(gCatalogAddOnPriority); +m.attr("gCatalogAddOnPriority") = 99; // from haiku source /add-ons/locale/catalogs/plaintext/Catalog.cpp + +py::class_(m, "BCatalogData") +.def(py::init(), "", py::arg("signature"), py::arg("language"), py::arg("fingerprint")) +.def("GetString", py::overload_cast(&BCatalogData::GetString), "", py::arg("string"), py::arg("context")=NULL, py::arg("comment")=NULL) +.def("GetString", py::overload_cast(&BCatalogData::GetString), "", py::arg("id")) +.def("InitCheck", &BCatalogData::InitCheck, "") +.def("Next", &BCatalogData::Next, "") +.def("CanHaveData", &BCatalogData::CanHaveData, "") +.def("GetData", py::overload_cast(&BCatalogData::GetData), "", py::arg("name"), py::arg("msg")) +.def("GetData", py::overload_cast(&BCatalogData::GetData), "", py::arg("id"), py::arg("msg")) +.def("SetString", py::overload_cast(&BCatalogData::SetString), "", py::arg("string"), py::arg("translated"), py::arg("context")=NULL, py::arg("comment")=NULL) +.def("SetString", py::overload_cast(&BCatalogData::SetString), "", py::arg("id"), py::arg("translated")) +.def("CanWriteData", &BCatalogData::CanWriteData, "") +.def("SetData", py::overload_cast(&BCatalogData::SetData), "", py::arg("name"), py::arg("msg")) +.def("SetData", py::overload_cast(&BCatalogData::SetData), "", py::arg("id"), py::arg("msg")) +.def("ReadFromFile", &BCatalogData::ReadFromFile, "", py::arg("path")=NULL) +.def("ReadFromAttribute", &BCatalogData::ReadFromAttribute, "", py::arg("appOrAddOnRef")) +.def("ReadFromResource", &BCatalogData::ReadFromResource, "", py::arg("appOrAddOnRef")) +.def("WriteToFile", &BCatalogData::WriteToFile, "", py::arg("path")=NULL) +.def("WriteToAttribute", &BCatalogData::WriteToAttribute, "", py::arg("appOrAddOnRef")) +.def("WriteToResource", &BCatalogData::WriteToResource, "", py::arg("appOrAddOnRef")) +.def("MakeEmpty", &BCatalogData::MakeEmpty, "") +.def("CountItems", &BCatalogData::CountItems, "") +.def("SetNext", &BCatalogData::SetNext, "", py::arg("next")) +; + +//m.def("instantiate_catalog", &instantiate_catalog, "", py::arg("signature"), py::arg("language"), py::arg("fingerprint"));// as below + +//m.def("create_catalog", &create_catalog, "", py::arg("signature"), py::arg("language"));// in src/add-ons/locale/catalogs/plaintext/Catalog.cpp or src/tools/locale/PlainTextCatalog.cpp + +} diff --git a/bindings/locale/Collator.cpp b/bindings/locale/Collator.cpp new file mode 100644 index 0000000..24bcd67 --- /dev/null +++ b/bindings/locale/Collator.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(Collator, m) +{ +py::enum_(m, "collator_strengths", "") +.value("B_COLLATE_DEFAULT", collator_strengths::B_COLLATE_DEFAULT, "") +.value("B_COLLATE_PRIMARY", collator_strengths::B_COLLATE_PRIMARY, "") +.value("B_COLLATE_SECONDARY", collator_strengths::B_COLLATE_SECONDARY, "") +.value("B_COLLATE_TERTIARY", collator_strengths::B_COLLATE_TERTIARY, "") +.value("B_COLLATE_QUATERNARY", collator_strengths::B_COLLATE_QUATERNARY, "") +.value("B_COLLATE_IDENTICAL", collator_strengths::B_COLLATE_IDENTICAL, "") +.export_values(); + +//m.attr("Collator") = py::cast(Collator); + +py::class_(m, "BCollator") +.def(py::init(), "") +.def(py::init(), "", py::arg("locale"), py::arg("strength")=B_COLLATE_PRIMARY, py::arg("ignorePunctuation")=false) +.def(py::init(), "", py::arg("archive")) +.def(py::init(), "", py::arg("other")) +.def("operator=", &BCollator::operator=, "", py::arg("source")) +.def("SetStrength", &BCollator::SetStrength, "", py::arg("strength")) +.def("SetIgnorePunctuation", &BCollator::SetIgnorePunctuation, "", py::arg("ignore")) +.def("IgnorePunctuation", &BCollator::IgnorePunctuation, "") +.def("SetNumericSorting", &BCollator::SetNumericSorting, "", py::arg("enable")) +.def("GetSortKey", &BCollator::GetSortKey, "", py::arg("string"), py::arg("key")) +.def("Compare", &BCollator::Compare, "", py::arg("s1"), py::arg("s2")) +.def("Equal", &BCollator::Equal, "", py::arg("s1"), py::arg("s2")) +.def("Greater", &BCollator::Greater, "", py::arg("s1"), py::arg("s2")) +.def("GreaterOrEqual", &BCollator::GreaterOrEqual, "", py::arg("s1"), py::arg("s2")) +.def("Archive", &BCollator::Archive, "", py::arg("archive"), py::arg("deep")) +.def_static("Instantiate", &BCollator::Instantiate, "", py::arg("archive")) +; + + +} diff --git a/bindings/locale/Country.cpp b/bindings/locale/Country.cpp new file mode 100644 index 0000000..9dc5c62 --- /dev/null +++ b/bindings/locale/Country.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(Country, m) +{ + + +py::class_(m, "BCountry") +.def(py::init(), "", py::arg("countryCode")=NULL) +.def(py::init(), "", py::arg("other")) +.def("operator=", &BCountry::operator=, "", py::arg("other")) +.def("SetTo", &BCountry::SetTo, "", py::arg("countryCode")) +.def("InitCheck", &BCountry::InitCheck, "") +.def("GetNativeName", [](BCountry& self) { + BString name; + status_t r = self.GetNativeName(name); + return std::make_tuple(r,name); +} +, "") +.def("GetName", [](BCountry& self,const BLanguage * displayLanguage=NULL) { + BString name; + status_t r = self.GetName(name, displayLanguage); + return std::make_tuple(r,name); +} +, "", py::arg("displayLanguage")=NULL) +.def("GetPreferredLanguage", &BCountry::GetPreferredLanguage, "", py::arg("&")) +.def("Code", &BCountry::Code, "") +.def("GetIcon", &BCountry::GetIcon, "", py::arg("result")) +.def("GetAvailableTimeZones", &BCountry::GetAvailableTimeZones, "", py::arg("timeZones")) +//.def_readwrite("Private", &BCountry::Private, "") +; + +//m.attr("DateFormat") = py::cast(DateFormat); + +//m.attr("Locale") = py::cast(Locale); +} diff --git a/bindings/locale/DateFormat.cpp b/bindings/locale/DateFormat.cpp new file mode 100644 index 0000000..5355bd2 --- /dev/null +++ b/bindings/locale/DateFormat.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(DateFormat, m) +{ +py::enum_(m, "BWeekday", "") +.value("B_WEEKDAY_MONDAY", BWeekday::B_WEEKDAY_MONDAY, "") +.value("B_WEEKDAY_TUESDAY", BWeekday::B_WEEKDAY_TUESDAY, "") +.value("B_WEEKDAY_WEDNESDAY", BWeekday::B_WEEKDAY_WEDNESDAY, "") +.value("B_WEEKDAY_THURSDAY", BWeekday::B_WEEKDAY_THURSDAY, "") +.value("B_WEEKDAY_FRIDAY", BWeekday::B_WEEKDAY_FRIDAY, "") +.value("B_WEEKDAY_SATURDAY", BWeekday::B_WEEKDAY_SATURDAY, "") +.value("B_WEEKDAY_SUNDAY", BWeekday::B_WEEKDAY_SUNDAY, "") +.export_values(); + +//m.attr("DateFormat") = py::cast(DateFormat); + +py::class_(m, "BDateFormat") +.def(py::init(), "", py::arg("locale")=NULL) +.def(py::init(), "", py::arg("language"), py::arg("format")) +.def(py::init(), "", py::arg("other")) +.def("GetDateFormat", [](BDateFormat& self,BDateFormatStyle style) { + BString outFormat; + status_t r = self.GetDateFormat(style, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("style")) +.def("SetDateFormat", &BDateFormat::SetDateFormat, "", py::arg("style"), py::arg("format")) +.def("Format", py::overload_cast(&BDateFormat::Format, py::const_), "", py::arg("string"), py::arg("maxSize"), py::arg("time"), py::arg("style")) +.def("Format", [](BDateFormat& self,const time_t time,const BDateFormatStyle style,const BTimeZone * timeZone=NULL) { + BString string; + status_t r = self.Format(string, time, style, timeZone); + return std::make_tuple(r,string); +} +, "", py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +.def("Format", [](BDateFormat& self,const BDate & time,const BDateFormatStyle style,const BTimeZone * timeZone=NULL) { + BString string; + status_t r = self.Format(string, time, style, timeZone); + return std::make_tuple(r,string); +} +, "", py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +.def("Format", [](BDateFormat& self,const time_t time,const BDateFormatStyle style) { + BString string; +int * fieldPositions; +int fieldCount; + status_t r = self.Format(string, fieldPositions, fieldCount, time, style); + return std::make_tuple(r,string,fieldPositions,fieldCount); +} +, "", py::arg("time"), py::arg("style")) +.def("GetFields", [](BDateFormat& self,BDateFormatStyle style) { + BDateElement * fields; +int fieldCount; + status_t r = self.GetFields(fields, fieldCount, style); + return std::make_tuple(r,fields,fieldCount); +} +, "", py::arg("style")) +.def("GetStartOfWeek", &BDateFormat::GetStartOfWeek, "", py::arg("weekday")) +.def("GetMonthName", [](BDateFormat& self,int month,const BDateFormatStyle style=B_FULL_DATE_FORMAT) { + BString outName; + status_t r = self.GetMonthName(month, outName, style); + return std::make_tuple(r,outName); +} +, "", py::arg("month"), py::arg("style")=B_FULL_DATE_FORMAT) +.def("GetDayName", [](BDateFormat& self,int day,const BDateFormatStyle style=B_FULL_DATE_FORMAT) { + BString outName; + status_t r = self.GetDayName(day, outName, style); + return std::make_tuple(r,outName); +} +, "", py::arg("day"), py::arg("style")=B_FULL_DATE_FORMAT) +.def("Parse", [](BDateFormat& self,BString source,BDateFormatStyle style) { + BDate output; + status_t r = self.Parse(source, style, output); + return std::make_tuple(r,output); +} +, "", py::arg("source"), py::arg("style")) +; + + +} diff --git a/bindings/locale/DateTimeFormat.cpp b/bindings/locale/DateTimeFormat.cpp new file mode 100644 index 0000000..b53d66b --- /dev/null +++ b/bindings/locale/DateTimeFormat.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; + +PYBIND11_MODULE(DateTimeFormat, m) +{ +py::enum_(m, "BDateElement", "") +.value("B_DATE_ELEMENT_INVALID", BDateElement::B_DATE_ELEMENT_INVALID, "") +.value("B_DATE_ELEMENT_YEAR", BDateElement::B_DATE_ELEMENT_YEAR, "") +.value("B_DATE_ELEMENT_MONTH", BDateElement::B_DATE_ELEMENT_MONTH, "") +.value("B_DATE_ELEMENT_WEEKDAY", BDateElement::B_DATE_ELEMENT_WEEKDAY, "") +.value("B_DATE_ELEMENT_DAY", BDateElement::B_DATE_ELEMENT_DAY, "") +.value("B_DATE_ELEMENT_AM_PM", BDateElement::B_DATE_ELEMENT_AM_PM, "") +.value("B_DATE_ELEMENT_HOUR", BDateElement::B_DATE_ELEMENT_HOUR, "") +.value("B_DATE_ELEMENT_MINUTE", BDateElement::B_DATE_ELEMENT_MINUTE, "") +.value("B_DATE_ELEMENT_SECOND", BDateElement::B_DATE_ELEMENT_SECOND, "") +.value("B_DATE_ELEMENT_TIMEZONE", BDateElement::B_DATE_ELEMENT_TIMEZONE, "") +.export_values(); + +py::class_(m, "BDateTimeFormat") +.def(py::init(), "", py::arg("locale")=NULL) +.def(py::init(), "", py::arg("language"), py::arg("conventions")) +.def(py::init(), "", py::arg("other")) +.def("SetDateTimeFormat", &BDateTimeFormat::SetDateTimeFormat, "", py::arg("dateStyle"), py::arg("timeStyle"), py::arg("elements")) +.def("Format", py::overload_cast(&BDateTimeFormat::Format, py::const_), "", py::arg("target"), py::arg("maxSize"), py::arg("time"), py::arg("dateStyle"), py::arg("timeStyle")) +.def("Format", [](BDateTimeFormat& self,const time_t time,BDateFormatStyle dateStyle,BTimeFormatStyle timeStyle,const BTimeZone * timeZone=NULL) { + BString buffer; + status_t r = self.Format(buffer, time, dateStyle, timeStyle, timeZone); + return std::make_tuple(r,buffer); +} +, "", py::arg("time"), py::arg("dateStyle"), py::arg("timeStyle"), py::arg("timeZone")=NULL) +; + + +} diff --git a/bindings/locale/DurationFormat.cpp b/bindings/locale/DurationFormat.cpp new file mode 100644 index 0000000..ffb2e58 --- /dev/null +++ b/bindings/locale/DurationFormat.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(DurationFormat, m) +{ +//m.attr("GregorianCalendar") = py::cast(GregorianCalendar); //TODO try to fix this gregocal.h in icu74 d + +py::class_(m, "BDurationFormat") +.def(py::init(), "", py::arg("language"), py::arg("conventions"), py::arg("separator")=", ", py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("separator")=", ", py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("other")) +.def("SetSeparator", &BDurationFormat::SetSeparator, "", py::arg("separator")) +.def("SetTimeZone", &BDurationFormat::SetTimeZone, "", py::arg("timeZone")) +.def("Format", [](BDurationFormat& self,const bigtime_t startValue,const bigtime_t stopValue) { + BString buffer; + status_t r = self.Format(buffer, startValue, stopValue); + return std::make_tuple(r,buffer); +} +, "", py::arg("startValue"), py::arg("stopValue")) +; + + +} diff --git a/bindings/locale/Format.cpp b/bindings/locale/Format.cpp new file mode 100644 index 0000000..f686be4 --- /dev/null +++ b/bindings/locale/Format.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Format, m) +{ +m.attr("B_CURRENCY_FIELD") = 0;//py::cast(B_CURRENCY_FIELD); +m.attr("B_DECIMAL_SEPARATOR_FIELD") = 1;//py::cast(B_DECIMAL_SEPARATOR_FIELD); +m.attr("B_EXPONENT_FIELD") = 2;//py::cast(B_EXPONENT_FIELD); +m.attr("B_EXPONENT_SIGN_FIELD") = 3;//py::cast(B_EXPONENT_SIGN_FIELD); +m.attr("B_EXPONENT_SYMBOL_FIELD") = 4;//py::cast(B_EXPONENT_SYMBOL_FIELD); +m.attr("B_FRACTION_FIELD") = 5;//py::cast(B_FRACTION_FIELD); +m.attr("B_GROUPING_SEPARATOR_FIELD") = 6;//py::cast(B_GROUPING_SEPARATOR_FIELD); +m.attr("B_INTEGER_FIELD") = 7;//py::cast(B_INTEGER_FIELD); +m.attr("B_PERCENT_FIELD") = 8;//py::cast(B_PERCENT_FIELD); +m.attr("B_PERMILLE_FIELD") = 9;//py::cast(B_PERMILLE_FIELD); +m.attr("B_SIGN_FIELD") = 10;//py::cast(B_SIGN_FIELD); + +py::class_(m, "format_field_position") +.def_readwrite("field_type", &format_field_position::field_type, "") +.def_readwrite("start", &format_field_position::start, "") +.def_readwrite("length", &format_field_position::length, "") +; + +py::class_>(m, "BFormat") +.def("InitCheck", &BFormat::InitCheck, "") +; + + +} diff --git a/bindings/locale/FormattingConventions.cpp b/bindings/locale/FormattingConventions.cpp new file mode 100644 index 0000000..deb5833 --- /dev/null +++ b/bindings/locale/FormattingConventions.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(FormattingConventions, m) +{ +py::enum_(m, "BMeasurementKind", "") +.value("B_METRIC", BMeasurementKind::B_METRIC, "") +.value("B_US", BMeasurementKind::B_US, "") +.export_values(); + +py::enum_(m, "BDateFormatStyle", "") +.value("B_FULL_DATE_FORMAT", BDateFormatStyle::B_FULL_DATE_FORMAT, "") +.value("B_LONG_DATE_FORMAT", BDateFormatStyle::B_LONG_DATE_FORMAT, "") +.value("B_MEDIUM_DATE_FORMAT", BDateFormatStyle::B_MEDIUM_DATE_FORMAT, "") +.value("B_SHORT_DATE_FORMAT", BDateFormatStyle::B_SHORT_DATE_FORMAT, "") +.value("B_DATE_FORMAT_STYLE_COUNT", BDateFormatStyle::B_DATE_FORMAT_STYLE_COUNT, "") +.export_values(); + +py::enum_(m, "BTimeFormatStyle", "") +.value("B_FULL_TIME_FORMAT", BTimeFormatStyle::B_FULL_TIME_FORMAT, "") +.value("B_LONG_TIME_FORMAT", BTimeFormatStyle::B_LONG_TIME_FORMAT, "") +.value("B_MEDIUM_TIME_FORMAT", BTimeFormatStyle::B_MEDIUM_TIME_FORMAT, "") +.value("B_SHORT_TIME_FORMAT", BTimeFormatStyle::B_SHORT_TIME_FORMAT, "") +.value("B_TIME_FORMAT_STYLE_COUNT", BTimeFormatStyle::B_TIME_FORMAT_STYLE_COUNT, "") +.export_values(); + +//m.attr("DateFormat") = py::cast(DateFormat); + +//m.attr("Locale") = py::cast(Locale); + +py::class_(m, "BFormattingConventions") +.def(py::init(), "", py::arg("id")=NULL) +.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("archive")) +.def("operator=", &BFormattingConventions::operator=, "", py::arg("other")) +.def("__eq__", &BFormattingConventions::operator==, "", py::arg("other")) +.def("__ne__", &BFormattingConventions::operator!=, "", py::arg("other")) +.def("ID", &BFormattingConventions::ID, "") +.def("LanguageCode", &BFormattingConventions::LanguageCode, "") +.def("CountryCode", &BFormattingConventions::CountryCode, "") +.def("AreCountrySpecific", &BFormattingConventions::AreCountrySpecific, "") +.def("GetNativeName", [](BFormattingConventions& self) { + BString name; + status_t r = self.GetNativeName(name); + return std::make_tuple(r,name); +} +, "") +.def("GetName", [](BFormattingConventions& self,const BLanguage * displayLanguage=NULL) { + BString name; + status_t r = self.GetName(name, displayLanguage); + return std::make_tuple(r,name); +} +, "", py::arg("displayLanguage")=NULL) +//.def("GetString", &BFormattingConventions::GetString, "", py::arg("id")) +.def("GetDateFormat", [](BFormattingConventions& self,BDateFormatStyle style) { + BString outFormat; + status_t r = self.GetDateFormat(style, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("style")) +.def("GetTimeFormat", [](BFormattingConventions& self,BTimeFormatStyle style) { + BString outFormat; + status_t r = self.GetTimeFormat(style, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("style")) +.def("GetDateTimeFormat", [](BFormattingConventions& self,BDateFormatStyle dateStyle,BTimeFormatStyle timeStyle) { + BString outFormat; + status_t r = self.GetDateTimeFormat(dateStyle, timeStyle, outFormat); + return std::make_tuple(r,outFormat); +} +, "", py::arg("dateStyle"), py::arg("timeStyle")) +.def("GetNumericFormat", [](BFormattingConventions& self) { + BString outFormat; + status_t r = self.GetNumericFormat(outFormat); + return std::make_tuple(r,outFormat); +} +, "") +.def("GetMonetaryFormat", [](BFormattingConventions& self) { + BString outFormat; + status_t r = self.GetMonetaryFormat(outFormat); + return std::make_tuple(r,outFormat); +} +, "") +.def("SetExplicitDateFormat", &BFormattingConventions::SetExplicitDateFormat, "", py::arg("style"), py::arg("format")) +.def("SetExplicitTimeFormat", &BFormattingConventions::SetExplicitTimeFormat, "", py::arg("style"), py::arg("format")) +.def("SetExplicitDateTimeFormat", &BFormattingConventions::SetExplicitDateTimeFormat, "", py::arg("dateStyle"), py::arg("timeStyle"), py::arg("format")) +.def("SetExplicitNumericFormat", &BFormattingConventions::SetExplicitNumericFormat, "", py::arg("format")) +.def("SetExplicitMonetaryFormat", &BFormattingConventions::SetExplicitMonetaryFormat, "", py::arg("format")) +.def("MeasurementKind", &BFormattingConventions::MeasurementKind, "") +.def("UseStringsFromPreferredLanguage", &BFormattingConventions::UseStringsFromPreferredLanguage, "") +.def("SetUseStringsFromPreferredLanguage", &BFormattingConventions::SetUseStringsFromPreferredLanguage, "", py::arg("value")) +.def("Use24HourClock", &BFormattingConventions::Use24HourClock, "") +.def("SetExplicitUse24HourClock", &BFormattingConventions::SetExplicitUse24HourClock, "", py::arg("value")) +.def("UnsetExplicitUse24HourClock", &BFormattingConventions::UnsetExplicitUse24HourClock, "") +.def("Archive", &BFormattingConventions::Archive, "", py::arg("archive"), py::arg("deep")=true) +//.def_readwrite("Private", &BFormattingConventions::Private, "") +; + + +} diff --git a/bindings/locale/Language.cpp b/bindings/locale/Language.cpp new file mode 100644 index 0000000..18cfcc9 --- /dev/null +++ b/bindings/locale/Language.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(Language, m) +{ +py::enum_(m, "script_direction", "") +.value("B_LEFT_TO_RIGHT", script_direction::B_LEFT_TO_RIGHT, "") +.value("B_RIGHT_TO_LEFT", script_direction::B_RIGHT_TO_LEFT, "") +.value("B_TOP_TO_BOTTOM", script_direction::B_TOP_TO_BOTTOM, "") +.export_values(); + +py::class_(m, "BLanguage") +.def(py::init(), "") +.def(py::init(), "", py::arg("language")) +.def(py::init(), "", py::arg("other")) +.def("SetTo", &BLanguage::SetTo, "", py::arg("language")) +.def("GetNativeName", [](BLanguage& self) { + BString name; + status_t r = self.GetNativeName(name); + return std::make_tuple(r,name); +} +, "") +.def("GetName", [](BLanguage& self,const BLanguage * displayLanguage=NULL) { + BString name; + status_t r = self.GetName(name, displayLanguage); + return std::make_tuple(r,name); +} +, "", py::arg("displayLanguage")=NULL) +.def("GetString", &BLanguage::GetString, "", py::arg("id")) +.def("GetIcon", &BLanguage::GetIcon, "", py::arg("result")) +.def("Code", &BLanguage::Code, "") +.def("CountryCode", &BLanguage::CountryCode, "") +.def("ScriptCode", &BLanguage::ScriptCode, "") +.def("Variant", &BLanguage::Variant, "") +.def("ID", &BLanguage::ID, "") +.def("IsCountrySpecific", &BLanguage::IsCountrySpecific, "") +.def("IsVariant", &BLanguage::IsVariant, "") +.def("Direction", &BLanguage::Direction, "") +.def("operator=", &BLanguage::operator=, "", py::arg("source")) +//.def_readwrite("Private", &BLanguage::Private, "") +; +//m.attr("Locale") = py::cast(Locale); + +} diff --git a/bindings/locale/Locale.cpp b/bindings/locale/Locale.cpp new file mode 100644 index 0000000..04b77f7 --- /dev/null +++ b/bindings/locale/Locale.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(Locale, m) +{ +py::class_(m, "BLocale") +.def(py::init(), "", py::arg("language")=NULL, py::arg("conventions")=NULL) +.def(py::init(), "", py::arg("other")) +.def_static("Default", &BLocale::Default, "") +.def("operator=", &BLocale::operator=, "", py::arg("other")) +.def("GetCollator", &BLocale::GetCollator, "", py::arg("collator")) +.def("GetLanguage", &BLocale::GetLanguage, "", py::arg("language")) +.def("GetFormattingConventions", &BLocale::GetFormattingConventions, "", py::arg("conventions")) +.def("SetFormattingConventions", &BLocale::SetFormattingConventions, "", py::arg("conventions")) +.def("SetCollator", &BLocale::SetCollator, "", py::arg("newCollator")) +.def("SetLanguage", &BLocale::SetLanguage, "", py::arg("newLanguage")) +.def("GetString", &BLocale::GetString, "", py::arg("id")) +.def("StringCompare", py::overload_cast(&BLocale::StringCompare, py::const_), "", py::arg("s1"), py::arg("s2")) +.def("StringCompare", py::overload_cast(&BLocale::StringCompare, py::const_), "", py::arg("s1"), py::arg("s2")) +.def("GetSortKey", &BLocale::GetSortKey, "", py::arg("string"), py::arg("sortKey")) +; + + +} diff --git a/bindings/locale/LocaleRoster.cpp b/bindings/locale/LocaleRoster.cpp new file mode 100644 index 0000000..12ac73e --- /dev/null +++ b/bindings/locale/LocaleRoster.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + + +PYBIND11_MODULE(LocaleRoster, m) +{ +//m.attr("LocaleRosterData") = py::cast(LocaleRosterData); + +py::class_(m, "BLocaleRoster") +.def_static("Default", &BLocaleRoster::Default, "") +.def("GetDefaultTimeZone", &BLocaleRoster::GetDefaultTimeZone, "", py::arg("timezone")) +//.def("GetLanguage", &BLocaleRoster::GetLanguage, "", py::arg("languageCode"), py::arg("_language")) +//.def("GetLanguage", &GetLanguage_wrapper, "", py::arg("languageCode"), py::arg("_language")) +.def("GetLanguage", [](BLocaleRoster& self,const char* languageCode)-> py::tuple { + std::vector _language; + status_t r = self.GetLanguage(languageCode,_language.data()); + /* if you want to return a py::list uncomment this and try it + py::list language; + for (size_t i = 0; i < _language.size(); ++i) { + language.append(py::cast(*_language[i]); + } + for (size_t i = 0; i < _language.size(); ++i) { + delete _language[i]; + } + */ + return py::make_tuple(r,_language); +},"",py::arg("languageCode")) // TODO make a test, try this (returning a std::vector or better a py::list??) +.def("GetPreferredLanguages", &BLocaleRoster::GetPreferredLanguages, "", py::arg("message")) +.def("GetAvailableLanguages", &BLocaleRoster::GetAvailableLanguages, "", py::arg("message")) +.def("GetAvailableCountries", &BLocaleRoster::GetAvailableCountries, "", py::arg("timeZones")) +.def("GetAvailableTimeZones", &BLocaleRoster::GetAvailableTimeZones, "", py::arg("timeZones")) +.def("GetAvailableTimeZonesWithRegionInfo", &BLocaleRoster::GetAvailableTimeZonesWithRegionInfo, "", py::arg("timeZonesWithRegonInfo")) +.def("GetAvailableTimeZonesForCountry", &BLocaleRoster::GetAvailableTimeZonesForCountry, "", py::arg("message"), py::arg("countryCode")) +.def("GetFlagIconForCountry", &BLocaleRoster::GetFlagIconForCountry, "", py::arg("flagIcon"), py::arg("countryCode")) +.def("GetFlagIconForLanguage", &BLocaleRoster::GetFlagIconForLanguage, "", py::arg("flagIcon"), py::arg("languageCode")) +.def("GetAvailableCatalogs", &BLocaleRoster::GetAvailableCatalogs, "", py::arg("message"), py::arg("sigPattern")=NULL, py::arg("langPattern")=NULL, py::arg("fingerprint")=0) +.def("Refresh", &BLocaleRoster::Refresh, "") +.def("GetCatalog", &BLocaleRoster::GetCatalog, "") +.def("GetDefaultLocale", &BLocaleRoster::GetDefaultLocale, "") +.def("IsFilesystemTranslationPreferred", &BLocaleRoster::IsFilesystemTranslationPreferred, "") +.def("GetLocalizedFileName", [](BLocaleRoster& self,const entry_ref & ref,bool traverse=false) { + BString localizedFileName; + status_t r = self.GetLocalizedFileName(localizedFileName, ref, traverse); + return std::make_tuple(r,localizedFileName); +} +, "", py::arg("ref"), py::arg("traverse")=false) +//.def_readwrite("kCatLangAttr", &BLocaleRoster::kCatLangAttr, "") +//.def_readwrite("kCatSigAttr", &BLocaleRoster::kCatSigAttr, "") +//.def_readwrite("kCatFingerprintAttr", &BLocaleRoster::kCatFingerprintAttr, "") +//.def_readwrite("kEmbeddedCatAttr", &BLocaleRoster::kEmbeddedCatAttr, "") +//.def_readwrite("kEmbeddedCatResId", &BLocaleRoster::kEmbeddedCatResId, "") +; + +m.attr("B_LOCALE_CHANGED") = '_LCC';//py::cast(B_LOCALE_CHANGED); +} diff --git a/bindings/locale/LocaleStrings.cpp b/bindings/locale/LocaleStrings.cpp new file mode 100644 index 0000000..832c3de --- /dev/null +++ b/bindings/locale/LocaleStrings.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(LocaleStrings, m) +{ +py::enum_(m, "country_strings", "") +.value("B_COUNTRY_STRINGS_BASE", country_strings::B_COUNTRY_STRINGS_BASE, "") +.value("B_DATE_TIME_FORMAT", country_strings::B_DATE_TIME_FORMAT, "") +.value("B_TIME_AM_PM_FORMAT", country_strings::B_TIME_AM_PM_FORMAT, "") +.value("B_SHORT_DATE_TIME_FORMAT", country_strings::B_SHORT_DATE_TIME_FORMAT, "") +.value("B_SHORT_TIME_AM_PM_FORMAT", country_strings::B_SHORT_TIME_AM_PM_FORMAT, "") +.value("B_AM_STRING", country_strings::B_AM_STRING, "") +.value("B_PM_STRING", country_strings::B_PM_STRING, "") +.value("B_DATE_SEPARATOR", country_strings::B_DATE_SEPARATOR, "") +.value("B_TIME_SEPARATOR", country_strings::B_TIME_SEPARATOR, "") +.value("B_NUM_COUNTRY_STRINGS", country_strings::B_NUM_COUNTRY_STRINGS, "") +.export_values(); + +py::enum_(m, "language_strings", "") +.value("B_LANGUAGE_STRINGS_BASE", language_strings::B_LANGUAGE_STRINGS_BASE, "") +.value("B_YESTERDAY_STRING", language_strings::B_YESTERDAY_STRING, "") +.value("B_TODAY_STRING", language_strings::B_TODAY_STRING, "") +.value("B_TOMORROW_STRING", language_strings::B_TOMORROW_STRING, "") +.value("B_FUTURE_STRING", language_strings::B_FUTURE_STRING, "") +.value("B_DAY_1", language_strings::B_DAY_1, "") +.value("B_DAY_2", language_strings::B_DAY_2, "") +.value("B_DAY_3", language_strings::B_DAY_3, "") +.value("B_DAY_4", language_strings::B_DAY_4, "") +.value("B_DAY_5", language_strings::B_DAY_5, "") +.value("B_DAY_6", language_strings::B_DAY_6, "") +.value("B_DAY_7", language_strings::B_DAY_7, "") +.value("B_AB_DAY_1", language_strings::B_AB_DAY_1, "") +.value("B_AB_DAY_2", language_strings::B_AB_DAY_2, "") +.value("B_AB_DAY_3", language_strings::B_AB_DAY_3, "") +.value("B_AB_DAY_4", language_strings::B_AB_DAY_4, "") +.value("B_AB_DAY_5", language_strings::B_AB_DAY_5, "") +.value("B_AB_DAY_6", language_strings::B_AB_DAY_6, "") +.value("B_AB_DAY_7", language_strings::B_AB_DAY_7, "") +.value("B_MON_1", language_strings::B_MON_1, "") +.value("B_MON_2", language_strings::B_MON_2, "") +.value("B_MON_3", language_strings::B_MON_3, "") +.value("B_MON_4", language_strings::B_MON_4, "") +.value("B_MON_5", language_strings::B_MON_5, "") +.value("B_MON_6", language_strings::B_MON_6, "") +.value("B_MON_7", language_strings::B_MON_7, "") +.value("B_MON_8", language_strings::B_MON_8, "") +.value("B_MON_9", language_strings::B_MON_9, "") +.value("B_MON_10", language_strings::B_MON_10, "") +.value("B_MON_11", language_strings::B_MON_11, "") +.value("B_MON_12", language_strings::B_MON_12, "") +.value("B_AB_MON_1", language_strings::B_AB_MON_1, "") +.value("B_AB_MON_2", language_strings::B_AB_MON_2, "") +.value("B_AB_MON_3", language_strings::B_AB_MON_3, "") +.value("B_AB_MON_4", language_strings::B_AB_MON_4, "") +.value("B_AB_MON_5", language_strings::B_AB_MON_5, "") +.value("B_AB_MON_6", language_strings::B_AB_MON_6, "") +.value("B_AB_MON_7", language_strings::B_AB_MON_7, "") +.value("B_AB_MON_8", language_strings::B_AB_MON_8, "") +.value("B_AB_MON_9", language_strings::B_AB_MON_9, "") +.value("B_AB_MON_10", language_strings::B_AB_MON_10, "") +.value("B_AB_MON_11", language_strings::B_AB_MON_11, "") +.value("B_AB_MON_12", language_strings::B_AB_MON_12, "") +.value("B_YES_EXPRESSION", language_strings::B_YES_EXPRESSION, "") +.value("B_NO_EXPRESSION", language_strings::B_NO_EXPRESSION, "") +.value("B_YES_STRING", language_strings::B_YES_STRING, "") +.value("B_NO_STRING", language_strings::B_NO_STRING, "") +.value("B_NUM_LANGUAGE_STRINGS", language_strings::B_NUM_LANGUAGE_STRINGS, "") +.export_values(); + +py::enum_(m, "other_locale_strings", "") +.value("B_OTHER_STRINGS_BASE", other_locale_strings::B_OTHER_STRINGS_BASE, "") +.value("B_CODESET", other_locale_strings::B_CODESET, "") +.value("B_ERA", other_locale_strings::B_ERA, "") +.value("B_ERA_DATE_FORMAT", other_locale_strings::B_ERA_DATE_FORMAT, "") +.value("B_ERA_DATE_TIME_FORMAT", other_locale_strings::B_ERA_DATE_TIME_FORMAT, "") +.value("B_ERA_TIME_FORMAT", other_locale_strings::B_ERA_TIME_FORMAT, "") +.value("B_ALT_DIGITS", other_locale_strings::B_ALT_DIGITS, "") +.export_values(); + + +} diff --git a/bindings/locale/NumberFormat.cpp b/bindings/locale/NumberFormat.cpp new file mode 100644 index 0000000..c9e1506 --- /dev/null +++ b/bindings/locale/NumberFormat.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(NumberFormat, m) +{ +py::enum_(m, "BNumberElement", "") +.value("B_DECIMAL_SEPARATOR", BNumberElement::B_DECIMAL_SEPARATOR, "") +.value("B_GROUPING_SEPARATOR", BNumberElement::B_GROUPING_SEPARATOR, "") +.export_values(); + +py::class_(m, "BNumberFormat") +.def(py::init(), "") +.def(py::init(), "", py::arg("locale")) +.def("Format", py::overload_cast(&BNumberFormat::Format), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("Format", [](BNumberFormat& self,const double value) { + BString string; + status_t r = self.Format(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("Format", py::overload_cast(&BNumberFormat::Format), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("Format", [](BNumberFormat& self, int32 value) { + BString string; + status_t r = self.Format(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("FormatMonetary", py::overload_cast(&BNumberFormat::FormatMonetary), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("FormatMonetary", [](BNumberFormat& self,const double value) { + BString string; + status_t r = self.FormatMonetary(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("FormatPercent", py::overload_cast(&BNumberFormat::FormatPercent), "", py::arg("string"), py::arg("maxSize"), py::arg("value")) +.def("FormatPercent", [](BNumberFormat& self,const double value) { + BString string; + status_t r = self.FormatPercent(string, value); + return std::make_tuple(r,string); +} +, "", py::arg("value")) +.def("Parse", [](BNumberFormat& self,const BString & string) { + double value; + status_t r = self.Parse(string, value); + return std::make_tuple(r,value); +} +, "", py::arg("string")) +.def("GetSeparator", &BNumberFormat::GetSeparator, "", py::arg("element")) +; + + +} diff --git a/bindings/locale/RelativeDateTimeFormat.cpp b/bindings/locale/RelativeDateTimeFormat.cpp new file mode 100644 index 0000000..28e63cf --- /dev/null +++ b/bindings/locale/RelativeDateTimeFormat.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(RelativeDateTimeFormat, m) +{ +//m.attr("GregorianCalendar") = py::cast(GregorianCalendar); + +//m.attr("RelativeDateTimeFormatter") = py::cast(RelativeDateTimeFormatter); + +py::class_(m, "BRelativeDateTimeFormat") +.def(py::init(), "") +.def(py::init(), "", py::arg("language"), py::arg("conventions")) +.def(py::init(), "", py::arg("other")) +.def("Format", [](BRelativeDateTimeFormat& self,const time_t timeValue) { + BString string; + status_t r = self.Format(string, timeValue); + return std::make_tuple(r,string); +} +, "", py::arg("timeValue")) +; + + +} diff --git a/bindings/locale/StringFormat.cpp b/bindings/locale/StringFormat.cpp new file mode 100644 index 0000000..cb2def6 --- /dev/null +++ b/bindings/locale/StringFormat.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(StringFormat, m) +{ +//m.attr("MessageFormat") = py::cast(MessageFormat); + +//m.attr("UnicodeString") = py::cast(UnicodeString); + +py::class_(m, "BStringFormat") +.def(py::init(), "", py::arg("language"), py::arg("pattern")) +.def(py::init(), "", py::arg("pattern")) +.def("InitCheck", &BStringFormat::InitCheck, "") +.def("Format", [](BStringFormat& self,int64_t arg) { + BString buffer; + status_t r = self.Format(buffer, arg); + return std::make_tuple(r,buffer); +} +, "", py::arg("arg")) +; + + +} diff --git a/bindings/locale/TextEncoding.cpp b/bindings/locale/TextEncoding.cpp new file mode 100644 index 0000000..9c9b36b --- /dev/null +++ b/bindings/locale/TextEncoding.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(TextEncoding, m) +{ +py::class_(m, "BTextEncoding") +.def(py::init(), "", py::arg("name")) +.def(py::init(), "", py::arg("data"), py::arg("length")) +.def("InitCheck", &BTextEncoding::InitCheck, "") +.def("GetName", &BTextEncoding::GetName, "") +.def("Encode", [](BTextEncoding& self,const char * input,char * output) { + size_t inputLength; +size_t outputLength; + status_t r = self.Encode(input, inputLength, output, outputLength); + return std::make_tuple(r,inputLength,outputLength); +} +, "", py::arg("input"), py::arg("output")) +.def("Decode", [](BTextEncoding& self,const char * input,char * output) { + size_t inputLength; +size_t outputLength; + status_t r = self.Decode(input, inputLength, output, outputLength); + return std::make_tuple(r,inputLength,outputLength); +} +, "", py::arg("input"), py::arg("output")) +.def("Flush", [](BTextEncoding& self,char * output) { + size_t outputLength; + status_t r = self.Flush(output, outputLength); + return std::make_tuple(r,outputLength); +} +, "", py::arg("output")) +; + + +} diff --git a/bindings/locale/TimeFormat.cpp b/bindings/locale/TimeFormat.cpp new file mode 100644 index 0000000..ad6a2f4 --- /dev/null +++ b/bindings/locale/TimeFormat.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(TimeFormat, m) +{ +//m.attr("BTime") = py::cast(BTime); +//m.attr("BTime") = py::cast(BPrivate::BTime); + +py::class_(m, "BTimeFormat") +.def(py::init(), "") +.def(py::init(), "", py::arg("language"), py::arg("conventions")) +.def(py::init(), "", py::arg("other")) +.def("SetTimeFormat", &BTimeFormat::SetTimeFormat, "", py::arg("style"), py::arg("format")) +.def("Format", py::overload_cast(&BTimeFormat::Format, py::const_), "", py::arg("string"), py::arg("maxSize"), py::arg("time"), py::arg("style")) +//.def("Format", py::overload_cast(&BTimeFormat::Format, py::const_), "", py::arg("string"), py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +//.def("Format", py::overload_cast(&BTimeFormat::Format, py::const_), "", py::arg("string"), py::arg("fieldPositions"), py::arg("fieldCount"), py::arg("time"), py::arg("style")) +.def("Format", [](BTimeFormat& self,const time_t time,const BTimeFormatStyle style,const BTimeZone * timeZone=NULL) { + BString string; + status_t r = self.Format(string, time, style, timeZone); + return std::make_tuple(r,string); +} +, "", py::arg("time"), py::arg("style"), py::arg("timeZone")=NULL) +.def("Format", [](BTimeFormat& self,time_t time,BTimeFormatStyle style) { + BString string; +int * fieldPositions; +int fieldCount; + status_t r = self.Format(string, fieldPositions, fieldCount, time, style); + return std::make_tuple(r,string,fieldPositions,fieldCount); +} +, "", py::arg("time"), py::arg("style")) +.def("GetTimeFields", [](BTimeFormat& self,BTimeFormatStyle style) { + BDateElement * fields; +int fieldCount; + status_t r = self.GetTimeFields(fields, fieldCount, style); + return std::make_tuple(r,fields,fieldCount); +} +, "", py::arg("style")) +.def("Parse", [](BTimeFormat& self,BString source,BTimeFormatStyle style) { + BPrivate::BTime output; + status_t r = self.Parse(source, style, output); + return std::make_tuple(r,output); +} +, "", py::arg("source"), py::arg("style")) +; + + +} diff --git a/bindings/locale/TimeUnitFormat.cpp b/bindings/locale/TimeUnitFormat.cpp new file mode 100644 index 0000000..63761a8 --- /dev/null +++ b/bindings/locale/TimeUnitFormat.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(TimeUnitFormat, m) +{ +py::enum_(m, "time_unit_style", "") +.value("B_TIME_UNIT_ABBREVIATED", time_unit_style::B_TIME_UNIT_ABBREVIATED, "") +.value("B_TIME_UNIT_FULL", time_unit_style::B_TIME_UNIT_FULL, "") +.export_values(); + +py::enum_(m, "time_unit_element", "") +.value("B_TIME_UNIT_YEAR", time_unit_element::B_TIME_UNIT_YEAR, "") +.value("B_TIME_UNIT_MONTH", time_unit_element::B_TIME_UNIT_MONTH, "") +.value("B_TIME_UNIT_WEEK", time_unit_element::B_TIME_UNIT_WEEK, "") +.value("B_TIME_UNIT_DAY", time_unit_element::B_TIME_UNIT_DAY, "") +.value("B_TIME_UNIT_HOUR", time_unit_element::B_TIME_UNIT_HOUR, "") +.value("B_TIME_UNIT_MINUTE", time_unit_element::B_TIME_UNIT_MINUTE, "") +.value("B_TIME_UNIT_SECOND", time_unit_element::B_TIME_UNIT_SECOND, "") +.value("B_TIME_UNIT_LAST", time_unit_element::B_TIME_UNIT_LAST, "") +.export_values(); + +//m.attr("TimeUnitFormat") = py::cast(TimeUnitFormat); TODO try to fix this, it's in ICU + +py::class_(m, "BTimeUnitFormat") +.def(py::init(), "", py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("language"), py::arg("conventions"), py::arg("style")=B_TIME_UNIT_FULL) +.def(py::init(), "", py::arg("other")) +.def("Format", [](BTimeUnitFormat& self,int value,const time_unit_element unit) { + BString buffer; + status_t r = self.Format(buffer, value, unit); + return std::make_tuple(r,buffer); +} +, "", py::arg("value"), py::arg("unit")) +; + + +} diff --git a/bindings/locale/TimeZone.cpp b/bindings/locale/TimeZone.cpp new file mode 100644 index 0000000..39b4c19 --- /dev/null +++ b/bindings/locale/TimeZone.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace U_ICU_NAMESPACE; + +PYBIND11_MODULE(TimeZone, m) +{ +//m.attr("Locale") = py::cast(Locale); + +//m.attr("TimeZone") = py::cast(TimeZone); + +py::class_(m, "BTimeZone") +.def(py::init(), "", py::arg("zoneID")=NULL, py::arg("language")=NULL) +.def(py::init(), "", py::arg("other")) +.def("operator=", &BTimeZone::operator=, "", py::arg("source")) +.def("ID", &BTimeZone::ID, "") +.def("Name", &BTimeZone::Name, "") +.def("DaylightSavingName", &BTimeZone::DaylightSavingName, "") +.def("ShortName", &BTimeZone::ShortName, "") +.def("ShortDaylightSavingName", &BTimeZone::ShortDaylightSavingName, "") +.def("OffsetFromGMT", &BTimeZone::OffsetFromGMT, "") +.def("SupportsDaylightSaving", &BTimeZone::SupportsDaylightSaving, "") +.def("InitCheck", &BTimeZone::InitCheck, "") +.def("SetTo", &BTimeZone::SetTo, "", py::arg("zoneID"), py::arg("language")=NULL) +.def("SetLanguage", &BTimeZone::SetLanguage, "", py::arg("language")) +//.def_readwrite("kNameOfGmtZone", &BTimeZone::kNameOfGmtZone, "") +//.def_readwrite("Private", &BTimeZone::Private, "") +; +m.attr("kNameOfGmtZone") = "GMT"; + +} diff --git a/bindings/locale/UnicodeChar.cpp b/bindings/locale/UnicodeChar.cpp new file mode 100644 index 0000000..96341d1 --- /dev/null +++ b/bindings/locale/UnicodeChar.cpp @@ -0,0 +1,348 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +py::str ToUTF8(uint32_t c) { + char buffer[5] = {0}; // Un carattere UTF-8 può essere lungo fino a 4 byte + terminatore null + char* out = buffer; + BUnicodeChar::ToUTF8(c, &out); + return py::str(buffer); +} + +uint32_t FromUTF8(py::buffer in) { + py::buffer_info info = in.request(); + if (info.ndim != 1 || info.itemsize != 1) { + throw std::runtime_error("Buffer must be a 1-dimensional array of bytes"); + } + + const char* data = static_cast(info.ptr); + uint32_t result = BUnicodeChar::FromUTF8(&data); + + return result; +} + +PYBIND11_MODULE(UnicodeChar, m) +{ +py::enum_(m, "unicode_char_category", "") +.value("B_UNICODE_UNASSIGNED", unicode_char_category::B_UNICODE_UNASSIGNED, "") +.value("B_UNICODE_GENERAL_OTHER_TYPES", unicode_char_category::B_UNICODE_GENERAL_OTHER_TYPES, "") +.value("B_UNICODE_UPPERCASE_LETTER", unicode_char_category::B_UNICODE_UPPERCASE_LETTER, "") +.value("B_UNICODE_LOWERCASE_LETTER", unicode_char_category::B_UNICODE_LOWERCASE_LETTER, "") +.value("B_UNICODE_TITLECASE_LETTER", unicode_char_category::B_UNICODE_TITLECASE_LETTER, "") +.value("B_UNICODE_MODIFIER_LETTER", unicode_char_category::B_UNICODE_MODIFIER_LETTER, "") +.value("B_UNICODE_OTHER_LETTER", unicode_char_category::B_UNICODE_OTHER_LETTER, "") +.value("B_UNICODE_NON_SPACING_MARK", unicode_char_category::B_UNICODE_NON_SPACING_MARK, "") +.value("B_UNICODE_ENCLOSING_MARK", unicode_char_category::B_UNICODE_ENCLOSING_MARK, "") +.value("B_UNICODE_COMBINING_SPACING_MARK", unicode_char_category::B_UNICODE_COMBINING_SPACING_MARK, "") +.value("B_UNICODE_DECIMAL_DIGIT_NUMBER", unicode_char_category::B_UNICODE_DECIMAL_DIGIT_NUMBER, "") +.value("B_UNICODE_LETTER_NUMBER", unicode_char_category::B_UNICODE_LETTER_NUMBER, "") +.value("B_UNICODE_OTHER_NUMBER", unicode_char_category::B_UNICODE_OTHER_NUMBER, "") +.value("B_UNICODE_SPACE_SEPARATOR", unicode_char_category::B_UNICODE_SPACE_SEPARATOR, "") +.value("B_UNICODE_LINE_SEPARATOR", unicode_char_category::B_UNICODE_LINE_SEPARATOR, "") +.value("B_UNICODE_PARAGRAPH_SEPARATOR", unicode_char_category::B_UNICODE_PARAGRAPH_SEPARATOR, "") +.value("B_UNICODE_CONTROL_CHAR", unicode_char_category::B_UNICODE_CONTROL_CHAR, "") +.value("B_UNICODE_FORMAT_CHAR", unicode_char_category::B_UNICODE_FORMAT_CHAR, "") +.value("B_UNICODE_PRIVATE_USE_CHAR", unicode_char_category::B_UNICODE_PRIVATE_USE_CHAR, "") +.value("B_UNICODE_SURROGATE", unicode_char_category::B_UNICODE_SURROGATE, "") +.value("B_UNICODE_DASH_PUNCTUATION", unicode_char_category::B_UNICODE_DASH_PUNCTUATION, "") +.value("B_UNICODE_START_PUNCTUATION", unicode_char_category::B_UNICODE_START_PUNCTUATION, "") +.value("B_UNICODE_END_PUNCTUATION", unicode_char_category::B_UNICODE_END_PUNCTUATION, "") +.value("B_UNICODE_CONNECTOR_PUNCTUATION", unicode_char_category::B_UNICODE_CONNECTOR_PUNCTUATION, "") +.value("B_UNICODE_OTHER_PUNCTUATION", unicode_char_category::B_UNICODE_OTHER_PUNCTUATION, "") +.value("B_UNICODE_MATH_SYMBOL", unicode_char_category::B_UNICODE_MATH_SYMBOL, "") +.value("B_UNICODE_CURRENCY_SYMBOL", unicode_char_category::B_UNICODE_CURRENCY_SYMBOL, "") +.value("B_UNICODE_MODIFIER_SYMBOL", unicode_char_category::B_UNICODE_MODIFIER_SYMBOL, "") +.value("B_UNICODE_OTHER_SYMBOL", unicode_char_category::B_UNICODE_OTHER_SYMBOL, "") +.value("B_UNICODE_INITIAL_PUNCTUATION", unicode_char_category::B_UNICODE_INITIAL_PUNCTUATION, "") +.value("B_UNICODE_FINAL_PUNCTUATION", unicode_char_category::B_UNICODE_FINAL_PUNCTUATION, "") +.value("B_UNICODE_CATEGORY_COUNT", unicode_char_category::B_UNICODE_CATEGORY_COUNT, "") +.export_values(); + +py::enum_(m, "unicode_char_direction", "") +.value("B_UNICODE_LEFT_TO_RIGHT", unicode_char_direction::B_UNICODE_LEFT_TO_RIGHT, "") +.value("B_UNICODE_RIGHT_TO_LEFT", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT, "") +.value("B_UNICODE_EUROPEAN_NUMBER", unicode_char_direction::B_UNICODE_EUROPEAN_NUMBER, "") +.value("B_UNICODE_EUROPEAN_NUMBER_SEPARATOR", unicode_char_direction::B_UNICODE_EUROPEAN_NUMBER_SEPARATOR, "") +.value("B_UNICODE_EUROPEAN_NUMBER_TERMINATOR", unicode_char_direction::B_UNICODE_EUROPEAN_NUMBER_TERMINATOR, "") +.value("B_UNICODE_ARABIC_NUMBER", unicode_char_direction::B_UNICODE_ARABIC_NUMBER, "") +.value("B_UNICODE_COMMON_NUMBER_SEPARATOR", unicode_char_direction::B_UNICODE_COMMON_NUMBER_SEPARATOR, "") +.value("B_UNICODE_BLOCK_SEPARATOR", unicode_char_direction::B_UNICODE_BLOCK_SEPARATOR, "") +.value("B_UNICODE_SEGMENT_SEPARATOR", unicode_char_direction::B_UNICODE_SEGMENT_SEPARATOR, "") +.value("B_UNICODE_WHITE_SPACE_NEUTRAL", unicode_char_direction::B_UNICODE_WHITE_SPACE_NEUTRAL, "") +.value("B_UNICODE_OTHER_NEUTRAL", unicode_char_direction::B_UNICODE_OTHER_NEUTRAL, "") +.value("B_UNICODE_LEFT_TO_RIGHT_EMBEDDING", unicode_char_direction::B_UNICODE_LEFT_TO_RIGHT_EMBEDDING, "") +.value("B_UNICODE_LEFT_TO_RIGHT_OVERRIDE", unicode_char_direction::B_UNICODE_LEFT_TO_RIGHT_OVERRIDE, "") +.value("B_UNICODE_RIGHT_TO_LEFT_ARABIC", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT_ARABIC, "") +.value("B_UNICODE_RIGHT_TO_LEFT_EMBEDDING", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT_EMBEDDING, "") +.value("B_UNICODE_RIGHT_TO_LEFT_OVERRIDE", unicode_char_direction::B_UNICODE_RIGHT_TO_LEFT_OVERRIDE, "") +.value("B_UNICODE_POP_DIRECTIONAL_FORMAT", unicode_char_direction::B_UNICODE_POP_DIRECTIONAL_FORMAT, "") +.value("B_UNICODE_DIR_NON_SPACING_MARK", unicode_char_direction::B_UNICODE_DIR_NON_SPACING_MARK, "") +.value("B_UNICODE_BOUNDARY_NEUTRAL", unicode_char_direction::B_UNICODE_BOUNDARY_NEUTRAL, "") +.value("B_UNICODE_DIRECTION_COUNT", unicode_char_direction::B_UNICODE_DIRECTION_COUNT, "") +.export_values(); + +py::enum_(m, "unicode_char_script", "") +.value("B_UNICODE_NO_BLOCK", unicode_char_script::B_UNICODE_NO_BLOCK, "") +.value("B_UNICODE_BASIC_LATIN", unicode_char_script::B_UNICODE_BASIC_LATIN, "") +.value("B_UNICODE_LATIN_1_SUPPLEMENT", unicode_char_script::B_UNICODE_LATIN_1_SUPPLEMENT, "") +.value("B_UNICODE_LATIN_EXTENDED_A", unicode_char_script::B_UNICODE_LATIN_EXTENDED_A, "") +.value("B_UNICODE_LATIN_EXTENDED_B", unicode_char_script::B_UNICODE_LATIN_EXTENDED_B, "") +.value("B_UNICODE_IPA_EXTENSIONS", unicode_char_script::B_UNICODE_IPA_EXTENSIONS, "") +.value("B_UNICODE_SPACING_MODIFIER_LETTERS", unicode_char_script::B_UNICODE_SPACING_MODIFIER_LETTERS, "") +.value("B_UNICODE_COMBINING_DIACRITICAL_MARKS", unicode_char_script::B_UNICODE_COMBINING_DIACRITICAL_MARKS, "") +.value("B_UNICODE_GREEK", unicode_char_script::B_UNICODE_GREEK, "") +.value("B_UNICODE_CYRILLIC", unicode_char_script::B_UNICODE_CYRILLIC, "") +.value("B_UNICODE_ARMENIAN", unicode_char_script::B_UNICODE_ARMENIAN, "") +.value("B_UNICODE_HEBREW", unicode_char_script::B_UNICODE_HEBREW, "") +.value("B_UNICODE_ARABIC", unicode_char_script::B_UNICODE_ARABIC, "") +.value("B_UNICODE_SYRIAC", unicode_char_script::B_UNICODE_SYRIAC, "") +.value("B_UNICODE_THAANA", unicode_char_script::B_UNICODE_THAANA, "") +.value("B_UNICODE_DEVANAGARI", unicode_char_script::B_UNICODE_DEVANAGARI, "") +.value("B_UNICODE_BENGALI", unicode_char_script::B_UNICODE_BENGALI, "") +.value("B_UNICODE_GURMUKHI", unicode_char_script::B_UNICODE_GURMUKHI, "") +.value("B_UNICODE_GUJARATI", unicode_char_script::B_UNICODE_GUJARATI, "") +.value("B_UNICODE_ORIYA", unicode_char_script::B_UNICODE_ORIYA, "") +.value("B_UNICODE_TAMIL", unicode_char_script::B_UNICODE_TAMIL, "") +.value("B_UNICODE_TELUGU", unicode_char_script::B_UNICODE_TELUGU, "") +.value("B_UNICODE_KANNADA", unicode_char_script::B_UNICODE_KANNADA, "") +.value("B_UNICODE_MALAYALAM", unicode_char_script::B_UNICODE_MALAYALAM, "") +.value("B_UNICODE_SINHALA", unicode_char_script::B_UNICODE_SINHALA, "") +.value("B_UNICODE_THAI", unicode_char_script::B_UNICODE_THAI, "") +.value("B_UNICODE_LAO", unicode_char_script::B_UNICODE_LAO, "") +.value("B_UNICODE_TIBETAN", unicode_char_script::B_UNICODE_TIBETAN, "") +.value("B_UNICODE_MYANMAR", unicode_char_script::B_UNICODE_MYANMAR, "") +.value("B_UNICODE_GEORGIAN", unicode_char_script::B_UNICODE_GEORGIAN, "") +.value("B_UNICODE_HANGUL_JAMO", unicode_char_script::B_UNICODE_HANGUL_JAMO, "") +.value("B_UNICODE_ETHIOPIC", unicode_char_script::B_UNICODE_ETHIOPIC, "") +.value("B_UNICODE_CHEROKEE", unicode_char_script::B_UNICODE_CHEROKEE, "") +.value("B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS", unicode_char_script::B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, "") +.value("B_UNICODE_OGHAM", unicode_char_script::B_UNICODE_OGHAM, "") +.value("B_UNICODE_RUNIC", unicode_char_script::B_UNICODE_RUNIC, "") +.value("B_UNICODE_KHMER", unicode_char_script::B_UNICODE_KHMER, "") +.value("B_UNICODE_MONGOLIAN", unicode_char_script::B_UNICODE_MONGOLIAN, "") +.value("B_UNICODE_LATIN_EXTENDED_ADDITIONAL", unicode_char_script::B_UNICODE_LATIN_EXTENDED_ADDITIONAL, "") +.value("B_UNICODE_GREEK_EXTENDED", unicode_char_script::B_UNICODE_GREEK_EXTENDED, "") +.value("B_UNICODE_GENERAL_PUNCTUATION", unicode_char_script::B_UNICODE_GENERAL_PUNCTUATION, "") +.value("B_UNICODE_SUPERSCRIPTS_AND_SUBSCRIPTS", unicode_char_script::B_UNICODE_SUPERSCRIPTS_AND_SUBSCRIPTS, "") +.value("B_UNICODE_CURRENCY_SYMBOLS", unicode_char_script::B_UNICODE_CURRENCY_SYMBOLS, "") +.value("B_UNICODE_COMBINING_MARKS_FOR_SYMBOLS", unicode_char_script::B_UNICODE_COMBINING_MARKS_FOR_SYMBOLS, "") +.value("B_UNICODE_LETTERLIKE_SYMBOLS", unicode_char_script::B_UNICODE_LETTERLIKE_SYMBOLS, "") +.value("B_UNICODE_NUMBER_FORMS", unicode_char_script::B_UNICODE_NUMBER_FORMS, "") +.value("B_UNICODE_ARROWS", unicode_char_script::B_UNICODE_ARROWS, "") +.value("B_UNICODE_MATHEMATICAL_OPERATORS", unicode_char_script::B_UNICODE_MATHEMATICAL_OPERATORS, "") +.value("B_UNICODE_MISCELLANEOUS_TECHNICAL", unicode_char_script::B_UNICODE_MISCELLANEOUS_TECHNICAL, "") +.value("B_UNICODE_CONTROL_PICTURES", unicode_char_script::B_UNICODE_CONTROL_PICTURES, "") +.value("B_UNICODE_OPTICAL_CHARACTER_RECOGNITION", unicode_char_script::B_UNICODE_OPTICAL_CHARACTER_RECOGNITION, "") +.value("B_UNICODE_ENCLOSED_ALPHANUMERICS", unicode_char_script::B_UNICODE_ENCLOSED_ALPHANUMERICS, "") +.value("B_UNICODE_BOX_DRAWING", unicode_char_script::B_UNICODE_BOX_DRAWING, "") +.value("B_UNICODE_BLOCK_ELEMENTS", unicode_char_script::B_UNICODE_BLOCK_ELEMENTS, "") +.value("B_UNICODE_GEOMETRIC_SHAPES", unicode_char_script::B_UNICODE_GEOMETRIC_SHAPES, "") +.value("B_UNICODE_MISCELLANEOUS_SYMBOLS", unicode_char_script::B_UNICODE_MISCELLANEOUS_SYMBOLS, "") +.value("B_UNICODE_DINGBATS", unicode_char_script::B_UNICODE_DINGBATS, "") +.value("B_UNICODE_BRAILLE_PATTERNS", unicode_char_script::B_UNICODE_BRAILLE_PATTERNS, "") +.value("B_UNICODE_CJK_RADICALS_SUPPLEMENT", unicode_char_script::B_UNICODE_CJK_RADICALS_SUPPLEMENT, "") +.value("B_UNICODE_KANGXI_RADICALS", unicode_char_script::B_UNICODE_KANGXI_RADICALS, "") +.value("B_UNICODE_IDEOGRAPHIC_DESCRIPTION_CHARACTERS", unicode_char_script::B_UNICODE_IDEOGRAPHIC_DESCRIPTION_CHARACTERS, "") +.value("B_UNICODE_CJK_SYMBOLS_AND_PUNCTUATION", unicode_char_script::B_UNICODE_CJK_SYMBOLS_AND_PUNCTUATION, "") +.value("B_UNICODE_HIRAGANA", unicode_char_script::B_UNICODE_HIRAGANA, "") +.value("B_UNICODE_KATAKANA", unicode_char_script::B_UNICODE_KATAKANA, "") +.value("B_UNICODE_BOPOMOFO", unicode_char_script::B_UNICODE_BOPOMOFO, "") +.value("B_UNICODE_HANGUL_COMPATIBILITY_JAMO", unicode_char_script::B_UNICODE_HANGUL_COMPATIBILITY_JAMO, "") +.value("B_UNICODE_KANBUN", unicode_char_script::B_UNICODE_KANBUN, "") +.value("B_UNICODE_BOPOMOFO_EXTENDED", unicode_char_script::B_UNICODE_BOPOMOFO_EXTENDED, "") +.value("B_UNICODE_ENCLOSED_CJK_LETTERS_AND_MONTHS", unicode_char_script::B_UNICODE_ENCLOSED_CJK_LETTERS_AND_MONTHS, "") +.value("B_UNICODE_CJK_COMPATIBILITY", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS, "") +.value("B_UNICODE_YI_SYLLABLES", unicode_char_script::B_UNICODE_YI_SYLLABLES, "") +.value("B_UNICODE_YI_RADICALS", unicode_char_script::B_UNICODE_YI_RADICALS, "") +.value("B_UNICODE_HANGUL_SYLLABLES", unicode_char_script::B_UNICODE_HANGUL_SYLLABLES, "") +.value("B_UNICODE_HIGH_SURROGATES", unicode_char_script::B_UNICODE_HIGH_SURROGATES, "") +.value("B_UNICODE_HIGH_PRIVATE_USE_SURROGATES", unicode_char_script::B_UNICODE_HIGH_PRIVATE_USE_SURROGATES, "") +.value("B_UNICODE_LOW_SURROGATES", unicode_char_script::B_UNICODE_LOW_SURROGATES, "") +.value("B_UNICODE_PRIVATE_USE", unicode_char_script::B_UNICODE_PRIVATE_USE, "") +.value("B_UNICODE_PRIVATE_USE_AREA", unicode_char_script::B_UNICODE_PRIVATE_USE_AREA, "") +.value("B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS, "") +.value("B_UNICODE_ALPHABETIC_PRESENTATION_FORMS", unicode_char_script::B_UNICODE_ALPHABETIC_PRESENTATION_FORMS, "") +.value("B_UNICODE_ARABIC_PRESENTATION_FORMS_A", unicode_char_script::B_UNICODE_ARABIC_PRESENTATION_FORMS_A, "") +.value("B_UNICODE_COMBINING_HALF_MARKS", unicode_char_script::B_UNICODE_COMBINING_HALF_MARKS, "") +.value("B_UNICODE_CJK_COMPATIBILITY_FORMS", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY_FORMS, "") +.value("B_UNICODE_SMALL_FORM_VARIANTS", unicode_char_script::B_UNICODE_SMALL_FORM_VARIANTS, "") +.value("B_UNICODE_ARABIC_PRESENTATION_FORMS_B", unicode_char_script::B_UNICODE_ARABIC_PRESENTATION_FORMS_B, "") +.value("B_UNICODE_SPECIALS", unicode_char_script::B_UNICODE_SPECIALS, "") +.value("B_UNICODE_HALFWIDTH_AND_FULLWIDTH_FORMS", unicode_char_script::B_UNICODE_HALFWIDTH_AND_FULLWIDTH_FORMS, "") +.value("B_UNICODE_OLD_ITALIC", unicode_char_script::B_UNICODE_OLD_ITALIC, "") +.value("B_UNICODE_GOTHIC", unicode_char_script::B_UNICODE_GOTHIC, "") +.value("B_UNICODE_DESERET", unicode_char_script::B_UNICODE_DESERET, "") +.value("B_UNICODE_BYZANTINE_MUSICAL_SYMBOLS", unicode_char_script::B_UNICODE_BYZANTINE_MUSICAL_SYMBOLS, "") +.value("B_UNICODE_MUSICAL_SYMBOLS", unicode_char_script::B_UNICODE_MUSICAL_SYMBOLS, "") +.value("B_UNICODE_MATHEMATICAL_ALPHANUMERIC_SYMBOLS", unicode_char_script::B_UNICODE_MATHEMATICAL_ALPHANUMERIC_SYMBOLS, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, "") +.value("B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT", unicode_char_script::B_UNICODE_CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, "") +.value("B_UNICODE_TAGS", unicode_char_script::B_UNICODE_TAGS, "") +.value("B_UNICODE_CYRILLIC_SUPPLEMENTARY", unicode_char_script::B_UNICODE_CYRILLIC_SUPPLEMENTARY, "") +.value("B_UNICODE_CYRILLIC_SUPPLEMENT", unicode_char_script::B_UNICODE_CYRILLIC_SUPPLEMENT, "") +.value("B_UNICODE_TAGALOG", unicode_char_script::B_UNICODE_TAGALOG, "") +.value("B_UNICODE_HANUNOO", unicode_char_script::B_UNICODE_HANUNOO, "") +.value("B_UNICODE_BUHID", unicode_char_script::B_UNICODE_BUHID, "") +.value("B_UNICODE_TAGBANWA", unicode_char_script::B_UNICODE_TAGBANWA, "") +.value("B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A", unicode_char_script::B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, "") +.value("B_UNICODE_SUPPLEMENTAL_ARROWS_A", unicode_char_script::B_UNICODE_SUPPLEMENTAL_ARROWS_A, "") +.value("B_UNICODE_SUPPLEMENTAL_ARROWS_B", unicode_char_script::B_UNICODE_SUPPLEMENTAL_ARROWS_B, "") +.value("B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B", unicode_char_script::B_UNICODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, "") +.value("B_UNICODE_SUPPLEMENTAL_MATHEMATICAL_OPERATORS", unicode_char_script::B_UNICODE_SUPPLEMENTAL_MATHEMATICAL_OPERATORS, "") +.value("B_UNICODE_KATAKANA_PHONETIC_EXTENSIONS", unicode_char_script::B_UNICODE_KATAKANA_PHONETIC_EXTENSIONS, "") +.value("B_UNICODE_VARIATION_SELECTORS", unicode_char_script::B_UNICODE_VARIATION_SELECTORS, "") +.value("B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_A", unicode_char_script::B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_A, "") +.value("B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_B", unicode_char_script::B_UNICODE_SUPPLEMENTARY_PRIVATE_USE_AREA_B, "") +.value("B_UNICODE_LIMBU", unicode_char_script::B_UNICODE_LIMBU, "") +.value("B_UNICODE_TAI_LE", unicode_char_script::B_UNICODE_TAI_LE, "") +.value("B_UNICODE_KHMER_SYMBOLS", unicode_char_script::B_UNICODE_KHMER_SYMBOLS, "") +.value("B_UNICODE_PHONETIC_EXTENSIONS", unicode_char_script::B_UNICODE_PHONETIC_EXTENSIONS, "") +.value("B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_ARROWS", unicode_char_script::B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_ARROWS, "") +.value("B_UNICODE_YIJING_HEXAGRAM_SYMBOLS", unicode_char_script::B_UNICODE_YIJING_HEXAGRAM_SYMBOLS, "") +.value("B_UNICODE_LINEAR_B_SYLLABARY", unicode_char_script::B_UNICODE_LINEAR_B_SYLLABARY, "") +.value("B_UNICODE_LINEAR_B_IDEOGRAMS", unicode_char_script::B_UNICODE_LINEAR_B_IDEOGRAMS, "") +.value("B_UNICODE_AEGEAN_NUMBERS", unicode_char_script::B_UNICODE_AEGEAN_NUMBERS, "") +.value("B_UNICODE_UGARITIC", unicode_char_script::B_UNICODE_UGARITIC, "") +.value("B_UNICODE_SHAVIAN", unicode_char_script::B_UNICODE_SHAVIAN, "") +.value("B_UNICODE_OSMANYA", unicode_char_script::B_UNICODE_OSMANYA, "") +.value("B_UNICODE_CYPRIOT_SYLLABARY", unicode_char_script::B_UNICODE_CYPRIOT_SYLLABARY, "") +.value("B_UNICODE_TAI_XUAN_JING_SYMBOLS", unicode_char_script::B_UNICODE_TAI_XUAN_JING_SYMBOLS, "") +.value("B_UNICODE_VARIATION_SELECTORS_SUPPLEMENT", unicode_char_script::B_UNICODE_VARIATION_SELECTORS_SUPPLEMENT, "") +.value("B_UNICODE_ANCIENT_GREEK_MUSICAL_NOTATION", unicode_char_script::B_UNICODE_ANCIENT_GREEK_MUSICAL_NOTATION, "") +.value("B_UNICODE_ANCIENT_GREEK_NUMBERS", unicode_char_script::B_UNICODE_ANCIENT_GREEK_NUMBERS, "") +.value("B_UNICODE_ARABIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ARABIC_SUPPLEMENT, "") +.value("B_UNICODE_BUGINESE", unicode_char_script::B_UNICODE_BUGINESE, "") +.value("B_UNICODE_CJK_STROKES", unicode_char_script::B_UNICODE_CJK_STROKES, "") +.value("B_UNICODE_COMBINING_DIACRITICAL_MARKS_SUPPLEMENT", unicode_char_script::B_UNICODE_COMBINING_DIACRITICAL_MARKS_SUPPLEMENT, "") +.value("B_UNICODE_COPTIC", unicode_char_script::B_UNICODE_COPTIC, "") +.value("B_UNICODE_ETHIOPIC_EXTENDED", unicode_char_script::B_UNICODE_ETHIOPIC_EXTENDED, "") +.value("B_UNICODE_ETHIOPIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ETHIOPIC_SUPPLEMENT, "") +.value("B_UNICODE_GEORGIAN_SUPPLEMENT", unicode_char_script::B_UNICODE_GEORGIAN_SUPPLEMENT, "") +.value("B_UNICODE_GLAGOLITIC", unicode_char_script::B_UNICODE_GLAGOLITIC, "") +.value("B_UNICODE_KHAROSHTHI", unicode_char_script::B_UNICODE_KHAROSHTHI, "") +.value("B_UNICODE_MODIFIER_TONE_LETTERS", unicode_char_script::B_UNICODE_MODIFIER_TONE_LETTERS, "") +.value("B_UNICODE_NEW_TAI_LUE", unicode_char_script::B_UNICODE_NEW_TAI_LUE, "") +.value("B_UNICODE_OLD_PERSIAN", unicode_char_script::B_UNICODE_OLD_PERSIAN, "") +.value("B_UNICODE_PHONETIC_EXTENSIONS_SUPPLEMENT", unicode_char_script::B_UNICODE_PHONETIC_EXTENSIONS_SUPPLEMENT, "") +.value("B_UNICODE_SUPPLEMENTAL_PUNCTUATION", unicode_char_script::B_UNICODE_SUPPLEMENTAL_PUNCTUATION, "") +.value("B_UNICODE_SYLOTI_NAGRI", unicode_char_script::B_UNICODE_SYLOTI_NAGRI, "") +.value("B_UNICODE_TIFINAGH", unicode_char_script::B_UNICODE_TIFINAGH, "") +.value("B_UNICODE_VERTICAL_FORMS", unicode_char_script::B_UNICODE_VERTICAL_FORMS, "") +.value("B_UNICODE_NKO", unicode_char_script::B_UNICODE_NKO, "") +.value("B_UNICODE_BALINESE", unicode_char_script::B_UNICODE_BALINESE, "") +.value("B_UNICODE_LATIN_EXTENDED_C", unicode_char_script::B_UNICODE_LATIN_EXTENDED_C, "") +.value("B_UNICODE_LATIN_EXTENDED_D", unicode_char_script::B_UNICODE_LATIN_EXTENDED_D, "") +.value("B_UNICODE_PHAGS_PA", unicode_char_script::B_UNICODE_PHAGS_PA, "") +.value("B_UNICODE_PHOENICIAN", unicode_char_script::B_UNICODE_PHOENICIAN, "") +.value("B_UNICODE_CUNEIFORM", unicode_char_script::B_UNICODE_CUNEIFORM, "") +.value("B_UNICODE_CUNEIFORM_NUMBERS_AND_PUNCTUATION", unicode_char_script::B_UNICODE_CUNEIFORM_NUMBERS_AND_PUNCTUATION, "") +.value("B_UNICODE_COUNTING_ROD_NUMERALS", unicode_char_script::B_UNICODE_COUNTING_ROD_NUMERALS, "") +.value("B_UNICODE_SUNDANESE", unicode_char_script::B_UNICODE_SUNDANESE, "") +.value("B_UNICODE_LEPCHA", unicode_char_script::B_UNICODE_LEPCHA, "") +.value("B_UNICODE_OL_CHIKI", unicode_char_script::B_UNICODE_OL_CHIKI, "") +.value("B_UNICODE_CYRILLIC_EXTENDED_A", unicode_char_script::B_UNICODE_CYRILLIC_EXTENDED_A, "") +.value("B_UNICODE_VAI", unicode_char_script::B_UNICODE_VAI, "") +.value("B_UNICODE_CYRILLIC_EXTENDED_B", unicode_char_script::B_UNICODE_CYRILLIC_EXTENDED_B, "") +.value("B_UNICODE_SAURASHTRA", unicode_char_script::B_UNICODE_SAURASHTRA, "") +.value("B_UNICODE_KAYAH_LI", unicode_char_script::B_UNICODE_KAYAH_LI, "") +.value("B_UNICODE_REJANG", unicode_char_script::B_UNICODE_REJANG, "") +.value("B_UNICODE_CHAM", unicode_char_script::B_UNICODE_CHAM, "") +.value("B_UNICODE_ANCIENT_SYMBOLS", unicode_char_script::B_UNICODE_ANCIENT_SYMBOLS, "") +.value("B_UNICODE_PHAISTOS_DISC", unicode_char_script::B_UNICODE_PHAISTOS_DISC, "") +.value("B_UNICODE_LYCIAN", unicode_char_script::B_UNICODE_LYCIAN, "") +.value("B_UNICODE_CARIAN", unicode_char_script::B_UNICODE_CARIAN, "") +.value("B_UNICODE_LYDIAN", unicode_char_script::B_UNICODE_LYDIAN, "") +.value("B_UNICODE_MAHJONG_TILES", unicode_char_script::B_UNICODE_MAHJONG_TILES, "") +.value("B_UNICODE_DOMINO_TILES", unicode_char_script::B_UNICODE_DOMINO_TILES, "") +.value("B_UNICODE_SAMARITAN", unicode_char_script::B_UNICODE_SAMARITAN, "") +.value("B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS_EXTENDED", unicode_char_script::B_UNICODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS_EXTENDED, "") +.value("B_UNICODE_TAI_THAM", unicode_char_script::B_UNICODE_TAI_THAM, "") +.value("B_UNICODE_VEDIC_EXTENSIONS", unicode_char_script::B_UNICODE_VEDIC_EXTENSIONS, "") +.value("B_UNICODE_LISU", unicode_char_script::B_UNICODE_LISU, "") +.value("B_UNICODE_BAMUM", unicode_char_script::B_UNICODE_BAMUM, "") +.value("B_UNICODE_COMMON_INDIC_NUMBER_FORMS", unicode_char_script::B_UNICODE_COMMON_INDIC_NUMBER_FORMS, "") +.value("B_UNICODE_DEVANAGARI_EXTENDED", unicode_char_script::B_UNICODE_DEVANAGARI_EXTENDED, "") +.value("B_UNICODE_HANGUL_JAMO_EXTENDED_A", unicode_char_script::B_UNICODE_HANGUL_JAMO_EXTENDED_A, "") +.value("B_UNICODE_JAVANESE", unicode_char_script::B_UNICODE_JAVANESE, "") +.value("B_UNICODE_MYANMAR_EXTENDED_A", unicode_char_script::B_UNICODE_MYANMAR_EXTENDED_A, "") +.value("B_UNICODE_TAI_VIET", unicode_char_script::B_UNICODE_TAI_VIET, "") +.value("B_UNICODE_MEETEI_MAYEK", unicode_char_script::B_UNICODE_MEETEI_MAYEK, "") +.value("B_UNICODE_HANGUL_JAMO_EXTENDED_B", unicode_char_script::B_UNICODE_HANGUL_JAMO_EXTENDED_B, "") +.value("B_UNICODE_IMPERIAL_ARAMAIC", unicode_char_script::B_UNICODE_IMPERIAL_ARAMAIC, "") +.value("B_UNICODE_OLD_SOUTH_ARABIAN", unicode_char_script::B_UNICODE_OLD_SOUTH_ARABIAN, "") +.value("B_UNICODE_AVESTAN", unicode_char_script::B_UNICODE_AVESTAN, "") +.value("B_UNICODE_INSCRIPTIONAL_PARTHIAN", unicode_char_script::B_UNICODE_INSCRIPTIONAL_PARTHIAN, "") +.value("B_UNICODE_INSCRIPTIONAL_PAHLAVI", unicode_char_script::B_UNICODE_INSCRIPTIONAL_PAHLAVI, "") +.value("B_UNICODE_OLD_TURKIC", unicode_char_script::B_UNICODE_OLD_TURKIC, "") +.value("B_UNICODE_RUMI_NUMERAL_SYMBOLS", unicode_char_script::B_UNICODE_RUMI_NUMERAL_SYMBOLS, "") +.value("B_UNICODE_KAITHI", unicode_char_script::B_UNICODE_KAITHI, "") +.value("B_UNICODE_EGYPTIAN_HIEROGLYPHS", unicode_char_script::B_UNICODE_EGYPTIAN_HIEROGLYPHS, "") +.value("B_UNICODE_ENCLOSED_ALPHANUMERIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ENCLOSED_ALPHANUMERIC_SUPPLEMENT, "") +.value("B_UNICODE_ENCLOSED_IDEOGRAPHIC_SUPPLEMENT", unicode_char_script::B_UNICODE_ENCLOSED_IDEOGRAPHIC_SUPPLEMENT, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C, "") +.value("B_UNICODE_MANDAIC", unicode_char_script::B_UNICODE_MANDAIC, "") +.value("B_UNICODE_BATAK", unicode_char_script::B_UNICODE_BATAK, "") +.value("B_UNICODE_ETHIOPIC_EXTENDED_A", unicode_char_script::B_UNICODE_ETHIOPIC_EXTENDED_A, "") +.value("B_UNICODE_BRAHMI", unicode_char_script::B_UNICODE_BRAHMI, "") +.value("B_UNICODE_BAMUM_SUPPLEMENT", unicode_char_script::B_UNICODE_BAMUM_SUPPLEMENT, "") +.value("B_UNICODE_KANA_SUPPLEMENT", unicode_char_script::B_UNICODE_KANA_SUPPLEMENT, "") +.value("B_UNICODE_PLAYING_CARDS", unicode_char_script::B_UNICODE_PLAYING_CARDS, "") +.value("B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_PICTOGRAPHS", unicode_char_script::B_UNICODE_MISCELLANEOUS_SYMBOLS_AND_PICTOGRAPHS, "") +.value("B_UNICODE_EMOTICONS", unicode_char_script::B_UNICODE_EMOTICONS, "") +.value("B_UNICODE_TRANSPORT_AND_MAP_SYMBOLS", unicode_char_script::B_UNICODE_TRANSPORT_AND_MAP_SYMBOLS, "") +.value("B_UNICODE_ALCHEMICAL_SYMBOLS", unicode_char_script::B_UNICODE_ALCHEMICAL_SYMBOLS, "") +.value("B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D", unicode_char_script::B_UNICODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D, "") +.value("B_UNICODE_SCRIPT_COUNT", unicode_char_script::B_UNICODE_SCRIPT_COUNT, "") +.value("B_UNICODE_NO_SCRIPT", unicode_char_script::B_UNICODE_NO_SCRIPT, "") +.value("B_UNICODE_INVALID_CODE", unicode_char_script::B_UNICODE_INVALID_CODE, "") +.export_values(); + +py::enum_(m, "unicode_east_asian_width", "") +.value("B_UNICODE_EA_NEUTRAL", unicode_east_asian_width::B_UNICODE_EA_NEUTRAL, "") +.value("B_UNICODE_EA_AMBIGUOUS", unicode_east_asian_width::B_UNICODE_EA_AMBIGUOUS, "") +.value("B_UNICODE_EA_HALFWIDTH", unicode_east_asian_width::B_UNICODE_EA_HALFWIDTH, "") +.value("B_UNICODE_EA_FULLWIDTH", unicode_east_asian_width::B_UNICODE_EA_FULLWIDTH, "") +.value("B_UNICODE_EA_NARROW", unicode_east_asian_width::B_UNICODE_EA_NARROW, "") +.value("B_UNICODE_EA_WIDE", unicode_east_asian_width::B_UNICODE_EA_WIDE, "") +.value("B_UNICODE_EA_COUNT", unicode_east_asian_width::B_UNICODE_EA_COUNT, "") +.export_values(); + +py::class_(m, "BUnicodeChar") +.def_static("IsAlpha", &BUnicodeChar::IsAlpha, "", py::arg("c")) +.def_static("IsAlNum", &BUnicodeChar::IsAlNum, "", py::arg("c")) +.def_static("IsDigit", &BUnicodeChar::IsDigit, "", py::arg("c")) +.def_static("IsHexDigit", &BUnicodeChar::IsHexDigit, "", py::arg("c")) +.def_static("IsUpper", &BUnicodeChar::IsUpper, "", py::arg("c")) +.def_static("IsLower", &BUnicodeChar::IsLower, "", py::arg("c")) +.def_static("IsSpace", &BUnicodeChar::IsSpace, "", py::arg("c")) +.def_static("IsWhitespace", &BUnicodeChar::IsWhitespace, "", py::arg("c")) +.def_static("IsControl", &BUnicodeChar::IsControl, "", py::arg("c")) +.def_static("IsPunctuation", &BUnicodeChar::IsPunctuation, "", py::arg("c")) +.def_static("IsPrintable", &BUnicodeChar::IsPrintable, "", py::arg("c")) +.def_static("IsTitle", &BUnicodeChar::IsTitle, "", py::arg("c")) +.def_static("IsDefined", &BUnicodeChar::IsDefined, "", py::arg("c")) +.def_static("IsBase", &BUnicodeChar::IsBase, "", py::arg("c")) +.def_static("Type", &BUnicodeChar::Type, "", py::arg("c")) +.def_static("ToLower", &BUnicodeChar::ToLower, "", py::arg("c")) +.def_static("ToUpper", &BUnicodeChar::ToUpper, "", py::arg("c")) +.def_static("ToTitle", &BUnicodeChar::ToTitle, "", py::arg("c")) +.def_static("DigitValue", &BUnicodeChar::DigitValue, "", py::arg("c")) +.def_static("EastAsianWidth", &BUnicodeChar::EastAsianWidth, "", py::arg("c")) +//.def_static("ToUTF8", &BUnicodeChar::ToUTF8, "", py::arg("c"), py::arg("out")) +.def_static("ToUTF8", &ToUTF8, "wrapper to py::str", py::arg("c")) +//.def_static("FromUTF8", py::overload_cast(&BUnicodeChar::FromUTF8), "", py::arg("in")) +.def_static("FromUTF8Buffer", &FromUTF8, "wrapper from py::buffer", py::arg("in")) +.def_static("FromUTF8", py::overload_cast(&BUnicodeChar::FromUTF8), "", py::arg("in")) +.def_static("UTF8StringLength", py::overload_cast(&BUnicodeChar::UTF8StringLength), "", py::arg("string")) +.def_static("UTF8StringLength", py::overload_cast(&BUnicodeChar::UTF8StringLength), "", py::arg("string"), py::arg("maxLength")) +; + + +} diff --git a/bindings/mail/Email.cpp b/bindings/mail/Email.cpp new file mode 100644 index 0000000..44646ae --- /dev/null +++ b/bindings/mail/Email.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; + +std::string get_pop_name(const mail_pop_account& self) { + return std::string(self.pop_name); +} + +void set_pop_name(mail_pop_account& self, const std::string& name) { + std::strncpy(self.pop_name, name.c_str(), B_MAX_USER_NAME_LENGTH - 1); + self.pop_name[B_MAX_USER_NAME_LENGTH - 1] = '\0'; +} + +std::string get_pop_password(const mail_pop_account& self) { + return std::string(self.pop_password); +} + +void set_pop_password(mail_pop_account& self, const std::string& name) { + std::strncpy(self.pop_password, name.c_str(), B_MAX_USER_NAME_LENGTH - 1); + self.pop_password[B_MAX_USER_NAME_LENGTH - 1] = '\0'; +} + +std::string get_pop_host(const mail_pop_account& self) { + return std::string(self.pop_host); +} + +void set_pop_host(mail_pop_account& self, const std::string& name) { + std::strncpy(self.pop_host, name.c_str(), B_MAX_HOST_NAME_LENGTH - 1); + self.pop_host[B_MAX_HOST_NAME_LENGTH - 1] = '\0'; +} + +std::string get_real_name(const mail_pop_account& self) { + return std::string(self.real_name); +} + +void set_real_name(mail_pop_account& self, const std::string& name) { + std::strncpy(self.real_name, name.c_str(), 128 - 1); + self.real_name[128 - 1] = '\0'; +} + +std::string get_reply_to(const mail_pop_account& self) { + return std::string(self.reply_to); +} + +void set_reply_to(mail_pop_account& self, const std::string& name) { + std::strncpy(self.reply_to, name.c_str(), 128 - 1); + self.reply_to[128 - 1] = '\0'; +} + +status_t AddEnclosure_wrapper(BMailMessage& self, const char* MIME_type, py::buffer data, int32 len, bool clobber = false) { + py::buffer_info info = data.request(); + void* buffer = info.ptr; + return self.AddEnclosure(MIME_type, buffer, len, clobber); +} + + +PYBIND11_MODULE(Email, m) +{ +py::enum_(m, "read_flags", "") +.value("B_UNREAD", read_flags::B_UNREAD, "") +.value("B_SEEN", read_flags::B_SEEN, "") +.value("B_READ", read_flags::B_READ, "") +.export_values(); + +py::enum_(m, "mail_flags", "") +.value("B_MAIL_PENDING", mail_flags::B_MAIL_PENDING, "") +.value("B_MAIL_SENT", mail_flags::B_MAIL_SENT, "") +.value("B_MAIL_SAVE", mail_flags::B_MAIL_SAVE, "") +.export_values(); + +py::class_(m, "mail_pop_account") +//.def_readwrite("pop_name", &mail_pop_account::pop_name, "") +.def_property("pop_name", &get_pop_name, &set_pop_name, "") +//.def_readwrite("pop_password", &mail_pop_account::pop_password, "") +.def_property("pop_password", &get_pop_password, &set_pop_password, "") +//.def_readwrite("pop_host", &mail_pop_account::pop_host, "") +.def_property("pop_host", &get_pop_host, &set_pop_host, "") +//.def_readwrite("real_name", &mail_pop_account::real_name, "") +.def_property("real_name", &get_real_name, &set_real_name, "") +//.def_readwrite("reply_to", &mail_pop_account::reply_to, "") +.def_property("reply_to", &get_reply_to, &set_reply_to, "") +.def_readwrite("days", &mail_pop_account::days, "") +.def_readwrite("interval", &mail_pop_account::interval, "") +.def_readwrite("begin_time", &mail_pop_account::begin_time, "") +.def_readwrite("end_time", &mail_pop_account::end_time, "") +; + +py::class_(m, "mail_notification") +.def_readwrite("alert", &mail_notification::alert, "") +.def_readwrite("beep", &mail_notification::beep, "") +; + +py::class_(m, "BMailMessage") +.def(py::init(), "") +.def("AddContent", py::overload_cast(&BMailMessage::AddContent), "", py::arg("text"), py::arg("length"), py::arg("encoding")=0, py::arg("clobber")=false)//hardcoded B_ISO1_CONVERSION to 0 +.def("AddContent", py::overload_cast(&BMailMessage::AddContent), "", py::arg("text"), py::arg("length"), py::arg("encoding"), py::arg("clobber")=false) +.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("ref"), py::arg("clobber")=false) +.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("path"), py::arg("clobber")=false) +//.def("AddEnclosure", py::overload_cast(&BMailMessage::AddEnclosure), "", py::arg("MIME_type"), py::arg("data"), py::arg("len"), py::arg("clobber")=false) +.def("AddEnclosure", &AddEnclosure_wrapper, "", py::arg("MIME_type"), py::arg("data"), py::arg("len"), py::arg("clobber")=false) +.def("AddHeaderField", py::overload_cast(&BMailMessage::AddHeaderField), "", py::arg("encoding"), py::arg("field_name"), py::arg("str"), py::arg("clobber")=false) +.def("AddHeaderField", py::overload_cast(&BMailMessage::AddHeaderField), "", py::arg("field_name"), py::arg("str"), py::arg("clobber")=false) +.def("Send", &BMailMessage::Send, "", py::arg("sendNow")=false, py::arg("removeAfterSending")=false) +; + +m.def("count_pop_accounts", &count_pop_accounts, ""); + +m.def("get_pop_account", &get_pop_account, "", py::arg(""), py::arg("index")=0); + +m.def("set_pop_account", &set_pop_account, "", py::arg(""), py::arg("index")=0, py::arg("save")=true); + +} diff --git a/bindings/mail/MailAttachment.cpp b/bindings/mail/MailAttachment.cpp new file mode 100644 index 0000000..479d225 --- /dev/null +++ b/bindings/mail/MailAttachment.cpp @@ -0,0 +1,138 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; + +class PyBSimpleMailAttachment : public BSimpleMailAttachment{ + public: + using BSimpleMailAttachment::BSimpleMailAttachment; + status_t SetTo(BFile *file, bool delete_file_when_done = false) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetTo, file, delete_file_when_done); + } + status_t SetTo(entry_ref *ref) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetTo, ref); + } + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, InitCheck); + } + void SetFileName(const char *name) override { + PYBIND11_OVERLOAD(void, BSimpleMailAttachment, SetFileName, name); + } + status_t FileName(char *name) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, FileName, name); + } + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetDecodedData, data); + } + BPositionIO *GetDecodedData() override { + PYBIND11_OVERLOAD(BPositionIO*, BSimpleMailAttachment, GetDecodedData); + } + status_t SetDecodedData(const void *data, size_t length /* data to attach */) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetDecodedData, data, length); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BSimpleMailAttachment, RenderToRFC822, render_to); + } +}; + +class PyBAttributedMailAttachment : public BAttributedMailAttachment{ + public: + using BAttributedMailAttachment::BAttributedMailAttachment; + status_t SetTo(BFile *file, bool delete_file_when_done = false) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetTo, file, delete_file_when_done); + } + status_t SetTo(entry_ref *ref) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetTo, ref); + } + status_t InitCheck() override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, InitCheck); + } + void SetFileName(const char *name) override { + PYBIND11_OVERLOAD(void, BAttributedMailAttachment, SetFileName, name); + } + status_t FileName(char *name) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, FileName, name); + } + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, RenderToRFC822, render_to); + } + status_t MIMEType(BMimeType *mime) override { + PYBIND11_OVERLOAD(status_t, BAttributedMailAttachment, MIMEType, mime); + } +}; + +PYBIND11_MODULE(MailAttachment, m) +{ +py::class_(m, "BMailAttachment") +.def("SetFileName", &BMailAttachment::SetFileName, "", py::arg("name")) +.def("FileName", &BMailAttachment::FileName, "", py::arg("name")) +.def("SetTo", py::overload_cast(&BMailAttachment::SetTo), "", py::arg("file"), py::arg("deleteFileWhenDone")=false) +.def("SetTo", py::overload_cast(&BMailAttachment::SetTo), "", py::arg("ref")) +.def("InitCheck", &BMailAttachment::InitCheck, "") +; + +py::class_(m, "BSimpleMailAttachment") +.def(py::init(), "", py::arg("dataToAttach"), py::arg("encoding")=base64) +.def(py::init(), "", py::arg("dataToAttach"), py::arg("lengthOfData"), py::arg("encoding")=base64) +.def(py::init(), "", py::arg("file"), py::arg("delete_when_done")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "") +.def("SetTo", py::overload_cast(&BSimpleMailAttachment::SetTo), "", py::arg("file"), py::arg("delete_file_when_done")=false) +.def("SetTo", py::overload_cast(&BSimpleMailAttachment::SetTo), "", py::arg("ref")) +.def("InitCheck", &BSimpleMailAttachment::InitCheck, "") +.def("SetFileName", &BSimpleMailAttachment::SetFileName, "", py::arg("name")) +.def("FileName", &BSimpleMailAttachment::FileName, "", py::arg("name")) +.def("GetDecodedData", py::overload_cast(&BSimpleMailAttachment::GetDecodedData), "", py::arg("data")) +.def("SetDecodedData", py::overload_cast(&BSimpleMailAttachment::SetDecodedData), "", py::arg("data")) +.def("GetDecodedData", py::overload_cast<>(&BSimpleMailAttachment::GetDecodedData), "") +.def("SetDecodedData", py::overload_cast(&BSimpleMailAttachment::SetDecodedData), "", py::arg("data"), py::arg("length")) +.def("SetDecodedDataAndDeleteWhenDone", &BSimpleMailAttachment::SetDecodedDataAndDeleteWhenDone, "", py::arg("data")) +.def("SetEncoding", &BSimpleMailAttachment::SetEncoding, "", py::arg("encoding")=base64) +.def("Encoding", &BSimpleMailAttachment::Encoding, "") +.def("SetToRFC822", &BSimpleMailAttachment::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BSimpleMailAttachment::RenderToRFC822, "", py::arg("render_to")) +; + +py::class_(m, "BAttributedMailAttachment") +.def(py::init(), "", py::arg("file"), py::arg("delete_when_done")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "") +.def("SetTo", py::overload_cast(&BAttributedMailAttachment::SetTo), "", py::arg("file"), py::arg("delete_file_when_done")=false) +.def("SetTo", py::overload_cast(&BAttributedMailAttachment::SetTo), "", py::arg("ref")) +.def("InitCheck", &BAttributedMailAttachment::InitCheck, "") +.def("SaveToDisk", &BAttributedMailAttachment::SaveToDisk, "", py::arg("entry")) +.def("SetEncoding", &BAttributedMailAttachment::SetEncoding, "", py::arg("encoding")) +.def("Encoding", &BAttributedMailAttachment::Encoding, "") +.def("FileName", &BAttributedMailAttachment::FileName, "", py::arg("name")) +.def("SetFileName", &BAttributedMailAttachment::SetFileName, "", py::arg("name")) +.def("GetDecodedData", &BAttributedMailAttachment::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BAttributedMailAttachment::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BAttributedMailAttachment::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BAttributedMailAttachment::RenderToRFC822, "", py::arg("render_to")) +.def("MIMEType", &BAttributedMailAttachment::MIMEType, "", py::arg("mime")) +; + + +} diff --git a/bindings/mail/MailComponent.cpp b/bindings/mail/MailComponent.cpp new file mode 100644 index 0000000..fa893f2 --- /dev/null +++ b/bindings/mail/MailComponent.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +class PyBMailComponent : public BMailComponent{ + public: + using BMailComponent::BMailComponent; + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, RenderToRFC822, render_to); + } + status_t MIMEType(BMimeType *mime) override { + PYBIND11_OVERLOAD(status_t, BMailComponent, MIMEType, mime); + } +}; + +class PyBTextMailComponent : public BTextMailComponent{ + public: + using BTextMailComponent::BTextMailComponent; + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BTextMailComponent, RenderToRFC822, render_to); + } +}; + +PYBIND11_MODULE(MailComponent, m) +{ +py::enum_(m, "component_type", "") +.value("B_MAIL_PLAIN_TEXT_BODY", component_type::B_MAIL_PLAIN_TEXT_BODY, "") +.value("B_MAIL_SIMPLE_ATTACHMENT", component_type::B_MAIL_SIMPLE_ATTACHMENT, "") +.value("B_MAIL_ATTRIBUTED_ATTACHMENT", component_type::B_MAIL_ATTRIBUTED_ATTACHMENT, "") +.value("B_MAIL_MULTIPART_CONTAINER", component_type::B_MAIL_MULTIPART_CONTAINER, "") +.export_values(); + +m.attr("kHeaderCharsetString") = py::cast(kHeaderCharsetString); + +m.attr("kHeaderEncodingString") = py::cast(kHeaderEncodingString); + +py::class_(m, "BMailComponent") +.def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("ComponentType", &BMailComponent::ComponentType, "") +.def("WhatIsThis", &BMailComponent::WhatIsThis, "") +.def("IsAttachment", &BMailComponent::IsAttachment, "") +.def("SetHeaderField", py::overload_cast(&BMailComponent::SetHeaderField), "", py::arg("key"), py::arg("value"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding, py::arg("replace_existing")=true) +.def("SetHeaderField", py::overload_cast(&BMailComponent::SetHeaderField), "", py::arg("key"), py::arg("structured_header"), py::arg("replace_existing")=true) +.def("HeaderAt", &BMailComponent::HeaderAt, "", py::arg("index")) +.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField, py::const_), "", py::arg("key"), py::arg("index")=0) +.def("HeaderField", py::overload_cast(&BMailComponent::HeaderField, py::const_), "", py::arg("key"), py::arg("structured_header"), py::arg("index")=0) +.def("RemoveHeader", &BMailComponent::RemoveHeader, "", py::arg("key")) +.def("GetDecodedData", &BMailComponent::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BMailComponent::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BMailComponent::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BMailComponent::RenderToRFC822, "", py::arg("render_to")) +.def("MIMEType", &BMailComponent::MIMEType, "", py::arg("mime")) +; + +py::class_(m, "BTextMailComponent") +.def(py::init(), "", py::arg("text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("SetEncoding", &BTextMailComponent::SetEncoding, "", py::arg("encoding"), py::arg("charset")) +.def("SetText", &BTextMailComponent::SetText, "", py::arg("text")) +.def("AppendText", &BTextMailComponent::AppendText, "", py::arg("text")) +.def("Text", &BTextMailComponent::Text, "") +.def("BStringText", &BTextMailComponent::BStringText, "") +.def("Quote", &BTextMailComponent::Quote, "", py::arg("message")=NULL, py::arg("quote_style")="> ") +.def("GetDecodedData", &BTextMailComponent::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BTextMailComponent::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BTextMailComponent::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BTextMailComponent::RenderToRFC822, "", py::arg("render_to")) +; + + +} diff --git a/bindings/mail/MailContainer.cpp b/bindings/mail/MailContainer.cpp new file mode 100644 index 0000000..a30fcf6 --- /dev/null +++ b/bindings/mail/MailContainer.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class PyBMailContainer : public BMailContainer{ + public: + using BMailContainer::BMailContainer; + status_t AddComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD_PURE(status_t, BMailContainer, AddComponent, component); + } + status_t RemoveComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD_PURE(status_t, BMailContainer, RemoveComponent, component); + } + status_t RemoveComponent(int32 index) override { + PYBIND11_OVERLOAD_PURE(status_t, BMailContainer, RemoveComponent, index); + } + BMailComponent *GetComponent(int32 index, bool parse_now = false) override { + PYBIND11_OVERLOAD_PURE(BMailComponent*, BMailContainer, GetComponent, index, parse_now); + } + int32 CountComponents() const override { + PYBIND11_OVERLOAD_PURE(int32, BMailContainer, CountComponents); + } +}; + +class PyBMIMEMultipartMailContainer : public BMIMEMultipartMailContainer{ + public: + using BMIMEMultipartMailContainer::BMIMEMultipartMailContainer; + status_t AddComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, AddComponent, component); + } + status_t RemoveComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, RemoveComponent, component); + } + status_t RemoveComponent(int32 index) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, RemoveComponent, index); + } + BMailComponent *GetComponent(int32 index, bool parse_now = false) override { + PYBIND11_OVERLOAD(BMailComponent* , BMIMEMultipartMailContainer, GetComponent, index, parse_now); + } + int32 CountComponents() const override { + PYBIND11_OVERLOAD(int32, BMIMEMultipartMailContainer, CountComponents); + } + status_t GetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, GetDecodedData, data); + } + status_t SetDecodedData(BPositionIO *data) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, SetDecodedData, data); + } + status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, SetToRFC822, data, length, parse_now); + } + status_t RenderToRFC822(BPositionIO *render_to) override { + PYBIND11_OVERLOAD(status_t, BMIMEMultipartMailContainer, RenderToRFC822, render_to); + } +}; + +PYBIND11_MODULE(MailContainer, m) +{ +py::class_(m, "BMailContainer") +.def(py::init(), "", py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("AddComponent", &BMailContainer::AddComponent, "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMailContainer::RemoveComponent), "", py::arg("index")) +.def("GetComponent", &BMailContainer::GetComponent, "", py::arg("index"), py::arg("parse_now")=false) +.def("CountComponents", &BMailContainer::CountComponents, "") +; + +py::class_(m, "BMIMEMultipartMailContainer") +.def(py::init(), "", py::arg("boundary")=NULL, py::arg("this_is_an_MIME_message_text")=NULL, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def(py::init(), "") +.def("SetBoundary", &BMIMEMultipartMailContainer::SetBoundary, "", py::arg("boundary")) +.def("SetThisIsAnMIMEMessageText", &BMIMEMultipartMailContainer::SetThisIsAnMIMEMessageText, "", py::arg("text")) +.def("AddComponent", &BMIMEMultipartMailContainer::AddComponent, "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMIMEMultipartMailContainer::RemoveComponent), "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BMIMEMultipartMailContainer::RemoveComponent), "", py::arg("index")) +.def("GetComponent", &BMIMEMultipartMailContainer::GetComponent, "", py::arg("index"), py::arg("parse_now")=false) +.def("CountComponents", &BMIMEMultipartMailContainer::CountComponents, "") +.def("GetDecodedData", &BMIMEMultipartMailContainer::GetDecodedData, "", py::arg("data")) +.def("SetDecodedData", &BMIMEMultipartMailContainer::SetDecodedData, "", py::arg("data")) +.def("SetToRFC822", &BMIMEMultipartMailContainer::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parse_now")=false) +.def("RenderToRFC822", &BMIMEMultipartMailContainer::RenderToRFC822, "", py::arg("render_to")) +; + + +} diff --git a/bindings/mail/MailDaemon.cpp b/bindings/mail/MailDaemon.cpp new file mode 100644 index 0000000..170405b --- /dev/null +++ b/bindings/mail/MailDaemon.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(MailDaemon, m) +{ +//m.attr("B_MAIL_BODY_FETCHED") = py::cast(B_MAIL_BODY_FETCHED); // +m.attr("B_MAIL_BODY_FETCHED") = '_Mbf'; + +py::class_(m, "BMailDaemon") +.def(py::init(), "") +.def("IsRunning", &BMailDaemon::IsRunning, "") +.def("CheckMail", &BMailDaemon::CheckMail, "", py::arg("accountID")=- 1) +.def("CheckAndSendQueuedMail", &BMailDaemon::CheckAndSendQueuedMail, "", py::arg("accountID")=- 1) +.def("SendQueuedMail", &BMailDaemon::SendQueuedMail, "") +.def("CountNewMessages", &BMailDaemon::CountNewMessages, "", py::arg("waitForFetchCompletion")=false) +.def("MarkAsRead", &BMailDaemon::MarkAsRead, "", py::arg("account"), py::arg("ref"), py::arg("flag")=B_READ) +.def("FetchBody", &BMailDaemon::FetchBody, "", py::arg("ref"), py::arg("listener")=NULL) +.def("Quit", &BMailDaemon::Quit, "") +.def("Launch", &BMailDaemon::Launch, "") +; + + +} diff --git a/bindings/mail/MailMessage.cpp b/bindings/mail/MailMessage.cpp new file mode 100644 index 0000000..914206d --- /dev/null +++ b/bindings/mail/MailMessage.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +class PyBEmailMessage : public BEmailMessage{ + public: + using BEmailMessage::BEmailMessage; + status_t AddComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, AddComponent, component); + } + status_t RemoveComponent(BMailComponent *component) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, RemoveComponent, component); + } + status_t RemoveComponent(int32 index) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, RemoveComponent, index); + } + BMailComponent* GetComponent(int32 index, bool parseNow = false) override { + PYBIND11_OVERLOAD(BMailComponent*, BEmailMessage, GetComponent, index, parseNow); + } + int32 CountComponents() const override { + PYBIND11_OVERLOAD(int32, BEmailMessage, CountComponents); + } + status_t SetToRFC822(BPositionIO* data, size_t length, bool parseNow = false) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, SetToRFC822, data, length, parseNow); + } + status_t RenderToRFC822(BPositionIO* renderTo) override { + PYBIND11_OVERLOAD(status_t, BEmailMessage, RenderToRFC822, renderTo); + } +}; + +PYBIND11_MODULE(MailMessage, m) +{ +py::enum_(m, "mail_reply_to_mode", "") +.value("B_MAIL_REPLY_TO", mail_reply_to_mode::B_MAIL_REPLY_TO, "") +.value("B_MAIL_REPLY_TO_ALL", mail_reply_to_mode::B_MAIL_REPLY_TO_ALL, "") +.value("B_MAIL_REPLY_TO_SENDER", mail_reply_to_mode::B_MAIL_REPLY_TO_SENDER, "") +.export_values(); + +py::class_(m, "BEmailMessage") +.def(py::init(), "", py::arg("stream")=NULL, py::arg("ownStream")=false, py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def(py::init(), "", py::arg("ref"), py::arg("defaultCharSet")=B_MAIL_NULL_CONVERSION) +.def("InitCheck", &BEmailMessage::InitCheck, "") +.def("Data", &BEmailMessage::Data, "") +.def("ReplyMessage", &BEmailMessage::ReplyMessage, "", py::arg("replyTo"), py::arg("accountFromMail"), py::arg("quoteStyle")="> ") +.def("ForwardMessage", &BEmailMessage::ForwardMessage, "", py::arg("accountFromMail"), py::arg("includeAttachments")=false) +.def("To", &BEmailMessage::To, "") +.def("From", &BEmailMessage::From, "") +.def("ReplyTo", &BEmailMessage::ReplyTo, "") +.def("CC", &BEmailMessage::CC, "") +.def("Subject", &BEmailMessage::Subject, "") +.def("Date", &BEmailMessage::Date, "") +.def("Priority", &BEmailMessage::Priority, "") +.def("SetSubject", &BEmailMessage::SetSubject, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetReplyTo", &BEmailMessage::SetReplyTo, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetFrom", &BEmailMessage::SetFrom, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetTo", &BEmailMessage::SetTo, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetCC", &BEmailMessage::SetCC, "", py::arg("to"), py::arg("charset")=B_MAIL_NULL_CONVERSION, py::arg("encoding")=null_encoding) +.def("SetBCC", &BEmailMessage::SetBCC, "", py::arg("to")) +.def("SetPriority", &BEmailMessage::SetPriority, "", py::arg("to")) +.def("GetName", py::overload_cast(&BEmailMessage::GetName,py::const_), "", py::arg("name"), py::arg("maxLength")) +.def("GetName", py::overload_cast(&BEmailMessage::GetName,py::const_), "", py::arg("name")) +.def("SendViaAccountFrom", &BEmailMessage::SendViaAccountFrom, "", py::arg("message")) +.def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("accountName")) +.def("SendViaAccount", py::overload_cast(&BEmailMessage::SendViaAccount), "", py::arg("account")) +.def("Account", &BEmailMessage::Account, "") +.def("GetAccountName", [](BEmailMessage& self) { + BString accountName; + status_t r = self.GetAccountName(accountName); + return std::make_tuple(r,accountName); +} +, "") +.def("AddComponent", &BEmailMessage::AddComponent, "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BEmailMessage::RemoveComponent), "", py::arg("component")) +.def("RemoveComponent", py::overload_cast(&BEmailMessage::RemoveComponent), "", py::arg("index")) +.def("GetComponent", &BEmailMessage::GetComponent, "", py::arg("index"), py::arg("parseNow")=false) +.def("CountComponents", &BEmailMessage::CountComponents, "") +.def("Attach", &BEmailMessage::Attach, "", py::arg("ref"), py::arg("includeAttributes")=true) +.def("IsComponentAttachment", &BEmailMessage::IsComponentAttachment, "", py::arg("index")) +.def("SetBodyTextTo", &BEmailMessage::SetBodyTextTo, "", py::arg("text")) +.def("BodyText", &BEmailMessage::BodyText, "") +.def("SetBody", &BEmailMessage::SetBody, "", py::arg("body")) +.def("Body", &BEmailMessage::Body, "") +.def("SetToRFC822", &BEmailMessage::SetToRFC822, "", py::arg("data"), py::arg("length"), py::arg("parseNow")=false) +.def("RenderToRFC822", &BEmailMessage::RenderToRFC822, "", py::arg("renderTo")) +.def("RenderTo", &BEmailMessage::RenderTo, "", py::arg("dir"), py::arg("message")=NULL) +.def("Send", &BEmailMessage::Send, "", py::arg("sendNow")) +; + + +} diff --git a/bindings/mail/MailSettings.cpp b/bindings/mail/MailSettings.cpp new file mode 100644 index 0000000..6a2a8c1 --- /dev/null +++ b/bindings/mail/MailSettings.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +class PyBMailAddOnSettings : public BMailAddOnSettings{ + public: + using BMailAddOnSettings::BMailAddOnSettings; + status_t Load(const BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailAddOnSettings, Load, message); + } + status_t Save(BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailAddOnSettings, Save, message); + } + bool HasBeenModified() const override { + PYBIND11_OVERLOAD(bool, BMailAddOnSettings, HasBeenModified); + } +}; + +class PyBMailProtocolSettings : public BMailProtocolSettings{ + public: + using BMailProtocolSettings::BMailProtocolSettings; + status_t Load(const BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailProtocolSettings, Load, message); + } + status_t Save(BMessage& message) override { + PYBIND11_OVERLOAD(status_t, BMailProtocolSettings, Save, message); + } + bool HasBeenModified() const override { + PYBIND11_OVERLOAD(bool, BMailProtocolSettings, HasBeenModified); + } +}; + +PYBIND11_MODULE(MailSettings, m) +{ +py::enum_(m, "b_mail_status_window_option", "") +.value("B_MAIL_SHOW_STATUS_WINDOW_NEVER", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_NEVER, "") +.value("B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING, "") +.value("B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE, "") +.value("B_MAIL_SHOW_STATUS_WINDOW_ALWAYS", b_mail_status_window_option::B_MAIL_SHOW_STATUS_WINDOW_ALWAYS, "") +.export_values(); + +py::class_(m, "BMailSettings") +.def(py::init(), "") +.def("Save", &BMailSettings::Save, "") +.def("Reload", &BMailSettings::Reload, "") +.def("InitCheck", &BMailSettings::InitCheck, "") +.def("WindowFollowsCorner", &BMailSettings::WindowFollowsCorner, "") +.def("SetWindowFollowsCorner", &BMailSettings::SetWindowFollowsCorner, "", py::arg("which_corner")) +.def("ShowStatusWindow", &BMailSettings::ShowStatusWindow, "") +.def("SetShowStatusWindow", &BMailSettings::SetShowStatusWindow, "", py::arg("mode")) +.def("DaemonAutoStarts", &BMailSettings::DaemonAutoStarts, "") +.def("SetDaemonAutoStarts", &BMailSettings::SetDaemonAutoStarts, "", py::arg("does_it")) +.def("SetConfigWindowFrame", &BMailSettings::SetConfigWindowFrame, "", py::arg("frame")) +.def("ConfigWindowFrame", &BMailSettings::ConfigWindowFrame, "") +.def("SetStatusWindowFrame", &BMailSettings::SetStatusWindowFrame, "", py::arg("frame")) +.def("StatusWindowFrame", &BMailSettings::StatusWindowFrame, "") +.def("StatusWindowWorkspaces", &BMailSettings::StatusWindowWorkspaces, "") +.def("SetStatusWindowWorkspaces", &BMailSettings::SetStatusWindowWorkspaces, "", py::arg("workspaces")) +.def("StatusWindowLook", &BMailSettings::StatusWindowLook, "") +.def("SetStatusWindowLook", &BMailSettings::SetStatusWindowLook, "", py::arg("look")) +.def("AutoCheckInterval", &BMailSettings::AutoCheckInterval, "") +.def("SetAutoCheckInterval", &BMailSettings::SetAutoCheckInterval, "", py::arg("")) +.def("CheckOnlyIfPPPUp", &BMailSettings::CheckOnlyIfPPPUp, "") +.def("SetCheckOnlyIfPPPUp", &BMailSettings::SetCheckOnlyIfPPPUp, "", py::arg("yes")) +.def("SendOnlyIfPPPUp", &BMailSettings::SendOnlyIfPPPUp, "") +.def("SetSendOnlyIfPPPUp", &BMailSettings::SetSendOnlyIfPPPUp, "", py::arg("yes")) +.def("DefaultOutboundAccount", &BMailSettings::DefaultOutboundAccount, "") +.def("SetDefaultOutboundAccount", &BMailSettings::SetDefaultOutboundAccount, "", py::arg("to")) +; + +py::class_(m, "BMailAddOnSettings") +.def(py::init(), "") +.def("Load", &BMailAddOnSettings::Load, "", py::arg("message")) +//this below has been autogenerated but why not call save on a previously created BMessage()? +/*.def("Save", [](BMailAddOnSettings& self) { + BMessage message; + status_t r = self.Save(message); + return std::make_tuple(r,message); +} +, "")*/ +.def("Save",&BMailAddOnSettings::Save, "", py::arg("message")) +.def("SetAddOnRef", &BMailAddOnSettings::SetAddOnRef, "", py::arg("ref")) +.def("AddOnRef", &BMailAddOnSettings::AddOnRef, "") +.def("HasBeenModified", &BMailAddOnSettings::HasBeenModified, "") +; + +py::class_(m, "BMailProtocolSettings") +.def(py::init(), "") +.def("Load", &BMailProtocolSettings::Load, "", py::arg("message")) +//same as above, why not use a previously created BMessage()? +/*.def("Save", [](BMailProtocolSettings& self) { + BMessage message; + status_t r = self.Save(message); + return std::make_tuple(r,message); +} +, "")*/ +.def("Save",&BMailProtocolSettings::Save, "", py::arg("message")) +.def("CountFilterSettings", &BMailProtocolSettings::CountFilterSettings, "") +.def("AddFilterSettings", &BMailProtocolSettings::AddFilterSettings, "", py::arg("ref")=NULL) +.def("RemoveFilterSettings", &BMailProtocolSettings::RemoveFilterSettings, "", py::arg("index")) +.def("MoveFilterSettings", &BMailProtocolSettings::MoveFilterSettings, "", py::arg("from"), py::arg("to")) +.def("FilterSettingsAt", &BMailProtocolSettings::FilterSettingsAt, "", py::arg("index")) +.def("HasBeenModified", &BMailProtocolSettings::HasBeenModified, "") +; + +py::class_(m, "BMailAccountSettings") +.def(py::init(), "") +.def(py::init(), "", py::arg("account")) +.def("InitCheck", &BMailAccountSettings::InitCheck, "") +.def("SetAccountID", &BMailAccountSettings::SetAccountID, "", py::arg("id")) +.def("AccountID", &BMailAccountSettings::AccountID, "") +.def("SetName", &BMailAccountSettings::SetName, "", py::arg("name")) +.def("Name", &BMailAccountSettings::Name, "") +.def("SetRealName", &BMailAccountSettings::SetRealName, "", py::arg("realName")) +.def("RealName", &BMailAccountSettings::RealName, "") +.def("SetReturnAddress", &BMailAccountSettings::SetReturnAddress, "", py::arg("returnAddress")) +.def("ReturnAddress", &BMailAccountSettings::ReturnAddress, "") +.def("SetInboundAddOn", &BMailAccountSettings::SetInboundAddOn, "", py::arg("name")) +.def("SetOutboundAddOn", &BMailAccountSettings::SetOutboundAddOn, "", py::arg("name")) +.def("InboundAddOnRef", &BMailAccountSettings::InboundAddOnRef, "") +.def("OutboundAddOnRef", &BMailAccountSettings::OutboundAddOnRef, "") +.def("InboundSettings", py::overload_cast<>(&BMailAccountSettings::InboundSettings), "") +.def("InboundSettings", py::overload_cast<>(&BMailAccountSettings::InboundSettings), "") +.def("OutboundSettings", py::overload_cast<>(&BMailAccountSettings::OutboundSettings), "") +.def("OutboundSettings", py::overload_cast<>(&BMailAccountSettings::OutboundSettings), "") +.def("HasInbound", &BMailAccountSettings::HasInbound, "") +.def("HasOutbound", &BMailAccountSettings::HasOutbound, "") +.def("SetInboundEnabled", &BMailAccountSettings::SetInboundEnabled, "", py::arg("enabled")=true) +.def("IsInboundEnabled", &BMailAccountSettings::IsInboundEnabled, "") +.def("SetOutboundEnabled", &BMailAccountSettings::SetOutboundEnabled, "", py::arg("enabled")=true) +.def("IsOutboundEnabled", &BMailAccountSettings::IsOutboundEnabled, "") +.def("Reload", &BMailAccountSettings::Reload, "") +.def("Save", &BMailAccountSettings::Save, "") +.def("Delete", &BMailAccountSettings::Delete, "") +.def("HasBeenModified", &BMailAccountSettings::HasBeenModified, "") +.def("AccountFile", &BMailAccountSettings::AccountFile, "") +; + +py::class_(m, "BMailAccounts") +.def(py::init(), "") +//same as above, why not use a previously created BPath()? +/*.def_static("AccountsPath", [](BMailAccounts& self) { + BPath path; + static status_t r = self.AccountsPath(path); + return std::make_tuple(r,path); +} +, "")*/ +.def_static("AccountsPath", &BMailAccounts::AccountsPath, "", py::arg("path")) +.def("CountAccounts", &BMailAccounts::CountAccounts, "") +.def("AccountAt", &BMailAccounts::AccountAt, "", py::arg("index")) +.def("AccountByID", &BMailAccounts::AccountByID, "", py::arg("id")) +.def("AccountByName", &BMailAccounts::AccountByName, "", py::arg("name")) +; + + +} diff --git a/bindings/mail/mail_encoding.cpp b/bindings/mail/mail_encoding.cpp new file mode 100644 index 0000000..de13131 --- /dev/null +++ b/bindings/mail/mail_encoding.cpp @@ -0,0 +1,263 @@ +#include +#include +#include +#include +#include +#include +/* +#include +#include +#include */ + +namespace py = pybind11; +/* source mail_encoding.cpp from mail-kit +#define DEC(c) (((c) - ' ') & 077) + +static const char kHexAlphabet[16] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8','9','A','B','C','D','E','F'}; + +ssize_t encode_qp_wrapper(char *out, const char *in, off_t length, int headerMode) +{ + int g = 0, i = 0; + + for (; i < length; i++) { + if (((uint8 *)(in))[i] > 127 || in[i] == '?' || in[i] == '=' + || in[i] == '_' + // Also encode the letter F in "From " at the start of the line, + // which Unix systems use to mark the start of messages in their + // mbox files. + || (in[i] == 'F' && i + 5 <= length && (i == 0 || in[i - 1] == '\n') + && in[i + 1] == 'r' && in[i + 2] == 'o' && in[i + 3] == 'm' + && in[i + 4] == ' ')) { + out[g++] = '='; + out[g++] = kHexAlphabet[(in[i] >> 4) & 0x0f]; + out[g++] = kHexAlphabet[in[i] & 0x0f]; + } else if (headerMode && (in[i] == ' ' || in[i] == '\t')) { + out[g++] = '_'; + } else if (headerMode && in[i] >= 0 && in[i] < 32) { + // Control codes in headers need to be sanitized, otherwise certain + // Japanese ISPs mangle the headers badly. But they don't mangle + // the body. + out[g++] = '='; + out[g++] = kHexAlphabet[(in[i] >> 4) & 0x0f]; + out[g++] = kHexAlphabet[in[i] & 0x0f]; + } else + out[g++] = in[i]; + } + + return g; +} + +ssize_t decode_qp_wrapper(char *out, const char *in, off_t length, int underscoreIsSpace) +{ + // decode Quoted Printable + char *dataout = out; + const char *datain = in, *dataend = in + length; + + while (datain < dataend) { + if (*datain == '=' && dataend - datain > 2) { + int a = toupper(datain[1]); + a -= a >= '0' && a <= '9' ? '0' : (a >= 'A' && a <= 'F' + ? 'A' - 10 : a + 1); + + int b = toupper(datain[2]); + b -= b >= '0' && b <= '9' ? '0' : (b >= 'A' && b <= 'F' + ? 'A' - 10 : b + 1); + + if (a >= 0 && b >= 0) { + *dataout++ = (a << 4) + b; + datain += 3; + continue; + } else if (datain[1] == '\r' && datain[2] == '\n') { + // strip = + datain += 3; + continue; + } + } else if (*datain == '_' && underscoreIsSpace) { + *dataout++ = ' '; + ++datain; + continue; + } + + *dataout++ = *datain++; + } + + *dataout = '\0'; + return dataout - out; +} + +ssize_t encode_wrapper(mail_encoding encoding, char *out, const char *in, off_t length, int headerMode) +{ + switch (encoding) { + case base64: + return encode_base64(out,in,length,headerMode); + case quoted_printable: + return encode_qp(out,in,length,headerMode); + case seven_bit: + case eight_bit: + case no_encoding: + memcpy(out,in,length); + return length; + case uuencode: + default: + return -1; + } + + return -1; +} + +ssize_t decode_wrapper(mail_encoding encoding, char *out, const char *in, off_t length, int underscoreIsSpace) +{ + switch (encoding) { + case base64: + return decode_base64(out, in, length); + case uuencode: + return uu_decode(out, in, length); + case seven_bit: + case eight_bit: + case no_encoding: + memcpy(out, in, length); + return length; + case quoted_printable: + return decode_qp(out, in, length, underscoreIsSpace); + default: + break; + } + + return -1; +} + +mail_encoding encoding_for_cte_wrapper(const char *cte) +{ + if (cte == NULL) + return no_encoding; + + if (strcasecmp(cte,"uuencode") == 0) + return uuencode; + if (strcasecmp(cte,"base64") == 0) + return base64; + if (strcasecmp(cte,"quoted-printable") == 0) + return quoted_printable; + if (strcasecmp(cte,"7bit") == 0) + return seven_bit; + if (strcasecmp(cte,"8bit") == 0) + return eight_bit; + + return no_encoding; +} + +ssize_t max_encoded_length_wrapper(mail_encoding encoding, off_t length) +{ + switch (encoding) { + case base64: + { + double result = length * 1.33333333333333; + result += (result / BASE64_LINELENGTH) * 2 + 20; + return (ssize_t)(result); + } + case quoted_printable: + return length * 3; + case seven_bit: + case eight_bit: + case no_encoding: + return length; + case uuencode: + default: + return -1; + } + + return -1; +} + +ssize_t uu_decode_wrapper(char *out, const char *in, off_t length) +{ + long n; + uint8 *p, *inBuffer = (uint8 *)in; + uint8 *outBuffer = (uint8 *)out; + + inBuffer = (uint8 *)strstr((char *)inBuffer, "begin"); + goto enterLoop; + + while ((inBuffer - (uint8 *)in) <= length + && strncmp((char *)inBuffer, "end", 3)) { + p = inBuffer; + n = DEC(inBuffer[0]); + + for (++inBuffer; n > 0; inBuffer += 4, n -= 3) { + if (n >= 3) { + *outBuffer++ = DEC(inBuffer[0]) << 2 | DEC (inBuffer[1]) >> 4; + *outBuffer++ = DEC(inBuffer[1]) << 4 | DEC (inBuffer[2]) >> 2; + *outBuffer++ = DEC(inBuffer[2]) << 6 | DEC (inBuffer[3]); + } else { + if (n >= 1) { + *outBuffer++ = DEC(inBuffer[0]) << 2 + | DEC (inBuffer[1]) >> 4; + } + if (n >= 2) { + *outBuffer++ = DEC(inBuffer[1]) << 4 + | DEC (inBuffer[2]) >> 2; + } + } + } + inBuffer = p; + + enterLoop: + while (inBuffer[0] != '\n' && inBuffer[0] != '\r' && inBuffer[0] != 0) + inBuffer++; + while (inBuffer[0] == '\n' || inBuffer[0] == '\r') + inBuffer++; + } + + return (ssize_t)(outBuffer - (uint8 *)in); +}*/ + +PYBIND11_MODULE(mail_encoding, m) +{ +py::enum_(m, "mail_encoding", "") +.value("base64", mail_encoding::base64, "") +.value("quoted_printable", mail_encoding::quoted_printable, "") +.value("seven_bit", mail_encoding::seven_bit, "") +.value("eight_bit", mail_encoding::eight_bit, "") +.value("uuencode", mail_encoding::uuencode, "") +.value("null_encoding", mail_encoding::null_encoding, "") +.value("no_encoding", mail_encoding::no_encoding, "") +.export_values(); +/* +m.def("encode", &encode_wrapper, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode", &decode_wrapper, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("max_encoded_length", &max_encoded_length_wrapper, "", py::arg("encoding"), py::arg("cur_length")); + +m.def("encoding_for_cte", &encoding_for_cte_wrapper, "", py::arg("content_transfer_encoding")); + +m.def("encode_base64", &encode_base64, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_base64", &decode_base64, "", py::arg("out"), py::arg("in"), py::arg("length")); + +m.def("encode_qp", &encode_qp_wrapper, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_qp", &decode_qp_wrapper, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("uu_decode", &uu_decode_wrapper, "", py::arg("out"), py::arg("in"), py::arg("length")); +*/ + +m.def("encode", &encode, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode", &decode, "", py::arg("encoding"), py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("max_encoded_length", &max_encoded_length, "", py::arg("encoding"), py::arg("cur_length")); + +m.def("encoding_for_cte", &encoding_for_cte, "", py::arg("content_transfer_encoding")); + +m.def("encode_base64", &encode_base64, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_base64", &decode_base64, "", py::arg("out"), py::arg("in"), py::arg("length")); + +m.def("encode_qp", &encode_qp, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("headerMode")); + +m.def("decode_qp", &decode_qp, "", py::arg("out"), py::arg("in"), py::arg("length"), py::arg("underscore_is_space")); + +m.def("uu_decode", &uu_decode, "", py::arg("out"), py::arg("in"), py::arg("length")); + +} diff --git a/bindings/media/Buffer.cpp b/bindings/media/Buffer.cpp new file mode 100644 index 0000000..9cf69f9 --- /dev/null +++ b/bindings/media/Buffer.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(Buffer, m) +{ +//m.attr("BufferCache") = py::cast(BufferCache); + +//m.attr("SharedBufferList") = py::cast(SharedBufferList); + +py::class_(m, "buffer_clone_info") +.def(py::init(), "") +.def_readwrite("buffer", &buffer_clone_info::buffer, "") +.def_readwrite("area", &buffer_clone_info::area, "") +.def_readwrite("offset", &buffer_clone_info::offset, "") +.def_readwrite("size", &buffer_clone_info::size, "") +.def_readwrite("flags", &buffer_clone_info::flags, "") +; + +py::class_>(m, "BBuffer") +.def("Data", &BBuffer::Data, "") +.def("SizeAvailable", &BBuffer::SizeAvailable, "") +.def("SizeUsed", &BBuffer::SizeUsed, "") +.def("SetSizeUsed", &BBuffer::SetSizeUsed, "", py::arg("used")) +.def("Flags", &BBuffer::Flags, "") +.def("Recycle", &BBuffer::Recycle, "") +.def("CloneInfo", &BBuffer::CloneInfo, "") +.def("ID", &BBuffer::ID, "") +.def("Type", &BBuffer::Type, "") +.def("Header", &BBuffer::Header, "") +.def("AudioHeader", &BBuffer::AudioHeader, "") +.def("VideoHeader", &BBuffer::VideoHeader, "") +.def("Size", &BBuffer::Size, "") +; + +m.attr("B_F1_BUFFER") = 0x1; + +m.attr("B_F2_BUFFER") = 0x2; + +m.attr("B_SMALL_BUFFER") = 0x80000000; + +py::class_(m, "BSmallBuffer") +.def(py::init(), "") +.def_static("SmallBufferSizeLimit", &BSmallBuffer::SmallBufferSizeLimit, "") +; + + +} diff --git a/bindings/media/BufferConsumer.cpp b/bindings/media/BufferConsumer.cpp new file mode 100644 index 0000000..1aa5073 --- /dev/null +++ b/bindings/media/BufferConsumer.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_MODULE(BufferConsumer, m) +{ +//m.attr("BufferCache") = py::cast(BufferCache); + +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_>(m, "BBufferConsumer") +.def("ConsumerType", &BBufferConsumer::ConsumerType, "") +.def_static("RegionToClipData", &BBufferConsumer::RegionToClipData, "", py::arg("region"), py::arg("format"), py::arg("size"), py::arg("data")) +; + + +} diff --git a/bindings/media/BufferGroup.cpp b/bindings/media/BufferGroup.cpp new file mode 100644 index 0000000..7c012c0 --- /dev/null +++ b/bindings/media/BufferGroup.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; +py::tuple add_buffer_wrapper(BBufferGroup& self, const buffer_clone_info& info) { + BBuffer* buffer = nullptr; + status_t status = self.AddBuffer(info, &buffer); + + return py::make_tuple(status, py::cast(buffer, py::return_value_policy::reference)); +}; + +py::tuple get_buffer_list_wrapper(BBufferGroup& self, int32 buffer_count) { + std::vector buffers(buffer_count, nullptr); + status_t status = self.GetBufferList(buffer_count, buffers.data()); + + /*if (status != 0) { + // Handle error (e.g., raise a Python exception) + throw py::error_already_set(); + }*/ + + // Create a Python list of BBuffer objects + py::list py_buffers; + for (BBuffer* buffer : buffers) { + py_buffers.append(py::cast(buffer, py::return_value_policy::reference)); + } + + return py::make_tuple(status, py_buffers); +}; + +PYBIND11_MODULE(BufferGroup, m) +{ +//m.attr("SharedBufferList") = py::cast(SharedBufferList); +py::class_(m, "BBufferGroup") +.def(py::init(), "", py::arg("size"), py::arg("count")=3, py::arg("placement")=B_ANY_ADDRESS, py::arg("lock")=B_FULL_LOCK) +.def(py::init(), "") +.def(py::init(), "", py::arg("count"), py::arg("buffers")) +.def("InitCheck", &BBufferGroup::InitCheck, "") +//.def("AddBuffer", &BBufferGroup::AddBuffer, "", py::arg("info"), py::arg("_buffer")=NULL) +.def("AddBuffer", &add_buffer_wrapper, "", py::arg("info")) +.def("RequestBuffer", py::overload_cast(&BBufferGroup::RequestBuffer), "", py::arg("size"), py::arg("timeout")=B_INFINITE_TIMEOUT) +.def("RequestBuffer", py::overload_cast(&BBufferGroup::RequestBuffer), "", py::arg("buffer"), py::arg("timeout")=B_INFINITE_TIMEOUT) +.def("RequestError", &BBufferGroup::RequestError, "") +.def("CountBuffers", &BBufferGroup::CountBuffers, "", py::arg("_count")) +//.def("GetBufferList", &BBufferGroup::GetBufferList, "", py::arg("bufferCount"), py::arg("_buffers")) +.def("GetBufferList", &get_buffer_list_wrapper, "", py::arg("bufferCount")) +.def("WaitForBuffers", &BBufferGroup::WaitForBuffers, "") +.def("ReclaimAllBuffers", &BBufferGroup::ReclaimAllBuffers, "") +; + + +} diff --git a/bindings/media/BufferProducer.cpp b/bindings/media/BufferProducer.cpp new file mode 100644 index 0000000..c0ba0ce --- /dev/null +++ b/bindings/media/BufferProducer.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_MODULE(BufferProducer, m) +{ +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_>(m, "BBufferProducer") +.def_static("ClipDataToRegion", &BBufferProducer::ClipDataToRegion, "", py::arg("format"), py::arg("size"), py::arg("data"), py::arg("region")) +.def("ProducerType", &BBufferProducer::ProducerType, "") +; + + +} diff --git a/bindings/media/Controllable.cpp b/bindings/media/Controllable.cpp new file mode 100644 index 0000000..54b0272 --- /dev/null +++ b/bindings/media/Controllable.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(Controllable, m) +{ +py::class_>(m, "BControllable") +.def("Web", &BControllable::Web, "") +.def("LockParameterWeb", &BControllable::LockParameterWeb, "") +.def("UnlockParameterWeb", &BControllable::UnlockParameterWeb, "") +; + + +} diff --git a/bindings/media/FileInterface.cpp b/bindings/media/FileInterface.cpp new file mode 100644 index 0000000..35217be --- /dev/null +++ b/bindings/media/FileInterface.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_FileInterface(py::module_& m) +{ +py::class_(m, "BFileInterface") +; + + +} diff --git a/bindings/media/MediaAddOn.cpp b/bindings/media/MediaAddOn.cpp new file mode 100644 index 0000000..d5ffeb0 --- /dev/null +++ b/bindings/media/MediaAddOn.cpp @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +std::string get_dormant_node_info_name(const dormant_node_info& self) { + return std::string(self.name); +} + +void set_dormant_node_info_name(dormant_node_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +//std::pair InitCheck(BMediaAddOn& self){ +//std::pair> InitCheck_wrapper(BMediaAddOn& self){ +py::tuple InitCheck_wrapper(BMediaAddOn& self){ + /* + const std::vector _failureText; + const char** failureText; + //const char* failureText = nullptr; + //status_t status = self.InitCheck(failureText); + status_t status = self.InitCheck(failureText); + + //return {status, failureText ? std::string(failureText) : ""}; + //return {status, _failureText}; + return py::make_tuple(status,_failureText); + */ + + + const char ** failureText; + std::vector _failureText; + status_t status = self.InitCheck(failureText); + // Assume che la fine dell'array sia segnata da un puntatore nullo + for (size_t i = 0; failureText[i] != nullptr; ++i) { + _failureText.push_back(const_cast(failureText[i])); + } + + return py::make_tuple(status,_failureText); +} + +PYBIND11_MODULE(MediaAddOn, m) +{ +m.attr("B_FLAVOR_IS_GLOBAL") = 0x100000L;//py::cast(B_FLAVOR_IS_GLOBAL); +m.attr("B_FLAVOR_IS_LOCAL") = 0x200000L;//py::cast(B_FLAVOR_IS_LOCAL); + +//m.attr("DormantNodeManager") = py::cast(DormantNodeManager); + +py::class_(m, "dormant_node_info") +.def(py::init(), "") +.def_readwrite("addon", &dormant_node_info::addon, "") +.def_readwrite("flavor_id", &dormant_node_info::flavor_id, "") +//.def_readwrite("name", &dormant_node_info::name, "") +.def_property("name", &get_dormant_node_info_name,&set_dormant_node_info_name,"") +; + +py::class_(m, "flavor_info") +.def_readwrite("name", &flavor_info::name, "") +.def_readwrite("info", &flavor_info::info, "") +.def_readwrite("kinds", &flavor_info::kinds, "") +.def_readwrite("flavor_flags", &flavor_info::flavor_flags, "") +.def_readwrite("internal_id", &flavor_info::internal_id, "") +.def_readwrite("possible_count", &flavor_info::possible_count, "") +.def_readwrite("in_format_count", &flavor_info::in_format_count, "") +.def_readwrite("in_format_flags", &flavor_info::in_format_flags, "") +.def_readwrite("in_formats", &flavor_info::in_formats, "") +.def_readwrite("out_format_count", &flavor_info::out_format_count, "") +.def_readwrite("out_format_flags", &flavor_info::out_format_flags, "") +.def_readwrite("out_formats", &flavor_info::out_formats, "") +//.def_readwrite("_reserved_", &flavor_info::_reserved_, "") +.def_property( + "_reserved_", + [](const flavor_info &info) { + py::array_t result(16); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](flavor_info &info, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") +; + +py::class_(m, "dormant_flavor_info") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def("operator=", py::overload_cast(&dormant_flavor_info::operator=), "", py::arg("other")) +.def("operator=", py::overload_cast(&dormant_flavor_info::operator=), "", py::arg("other")) +.def("set_name", &dormant_flavor_info::set_name, "", py::arg("name")) +.def("set_info", &dormant_flavor_info::set_info, "", py::arg("info")) +.def("add_in_format", &dormant_flavor_info::add_in_format, "", py::arg("format")) +.def("add_out_format", &dormant_flavor_info::add_out_format, "", py::arg("format")) +.def("IsFixedSize", &dormant_flavor_info::IsFixedSize, "") +.def("TypeCode", &dormant_flavor_info::TypeCode, "") +.def("FlattenedSize", &dormant_flavor_info::FlattenedSize, "") +.def("Flatten", &dormant_flavor_info::Flatten, "", py::arg("buffer"), py::arg("size")) //TODO: handle buffer +.def("Unflatten", &dormant_flavor_info::Unflatten, "", py::arg("type"), py::arg("buffer"), py::arg("size")) //TODO: handle buffer +.def_readwrite("node_info", &dormant_flavor_info::node_info, "") +; + +py::class_(m, "BMediaAddOn") +.def(py::init(), "", py::arg("image")) +//.def("InitCheck", &BMediaAddOn::InitCheck, "", py::arg("_failureText")) +.def("InitCheck",&InitCheck_wrapper, "") +.def("CountFlavors", &BMediaAddOn::CountFlavors, "") +//.def("GetFlavorAt", &BMediaAddOn::GetFlavorAt, "", py::arg("index"), py::arg("_info")) +.def("GetFlavorAt", [](BMediaAddOn& self, int32 index) { + const flavor_info* _info = nullptr; + status_t result = self.GetFlavorAt(index,&_info); + if (result == B_OK && _info != nullptr) { + return py::make_tuple(result, py::cast(_info, py::return_value_policy::reference)); + } else { + return py::make_tuple(result, py::none()); + } +},"") +.def("InstantiateNodeFor", &BMediaAddOn::InstantiateNodeFor, "", py::arg("info"), py::arg("config"), py::arg("_error")) +.def("GetConfigurationFor", &BMediaAddOn::GetConfigurationFor, "", py::arg("yourNode"), py::arg("intoMessage")) +.def("WantsAutoStart", &BMediaAddOn::WantsAutoStart, "") +//.def("AutoStart", &BMediaAddOn::AutoStart, "", py::arg("index"), py::arg("_node"), py::arg("_internalID"), py::arg("_hasMore")) +.def("AutoStart", [](BMediaAddOn& self, int index) { + BMediaNode* node = nullptr; + int32 internalID = 0; + bool hasMore = false; + status_t result = self.AutoStart(index, &node, &internalID, &hasMore); + return std::make_tuple(result, node, internalID, hasMore); +},"") +.def("SniffRef", &BMediaAddOn::SniffRef, "", py::arg("file"), py::arg("ioMimeType"), py::arg("_quality"), py::arg("_internalID")) +.def("SniffType", &BMediaAddOn::SniffType, "", py::arg("type"), py::arg("_quality"), py::arg("_internalID")) +.def("GetFileFormatList", &BMediaAddOn::GetFileFormatList, "", py::arg("forNodeFlavorID"), py::arg("_writableFormats"), py::arg("writableFormatsCount"), py::arg("_writableFormatsTotalCount"), py::arg("_readableFormats"), py::arg("readableFormatsCount"), py::arg("_readableFormatsTotalCount"), py::arg("_reserved")) +.def("SniffTypeKind", &BMediaAddOn::SniffTypeKind, "", py::arg("type"), py::arg("kinds"), py::arg("_quality"), py::arg("_internalID"), py::arg("_reserved")) +.def("ImageID", &BMediaAddOn::ImageID, "") +.def("AddonID", &BMediaAddOn::AddonID, "") +; + +//m.def("make_media_addon", &make_media_addon, "", py::arg("yourImage")); //TODO: where is this? cannot find it normally it calls return new MediaAddOn(imageid); that returns a BMediaAddOn* + +} diff --git a/bindings/media/MediaDecoder.cpp b/bindings/media/MediaDecoder.cpp new file mode 100644 index 0000000..268a849 --- /dev/null +++ b/bindings/media/MediaDecoder.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +class PyBMediaDecoder : public BMediaDecoder{ + public: + using BMediaDecoder::BMediaDecoder; + status_t GetNextChunk(const void **chunkData, size_t *chunkLen, media_header *mh) override { + PYBIND11_OVERRIDE_PURE( status_t, BMediaDecoder, GetNextChunk, chunkData, chunkLen, mh ); + } +}; + +PYBIND11_MODULE(MediaDecoder, m) +{ + +//m.attr("Decoder") = py::cast(Decoder); + +//m.attr("Decoder") = py::cast(Decoder); + +//m.attr("DecoderPlugin") = py::cast(DecoderPlugin); + +py::class_(m, "BMediaDecoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("in_format"), py::arg("info")=NULL, py::arg("info_size")=0) +.def(py::init(), "", py::arg("mci")) +.def("InitCheck", &BMediaDecoder::InitCheck, "") +.def("SetTo", py::overload_cast(&BMediaDecoder::SetTo), "", py::arg("in_format"), py::arg("info")=NULL, py::arg("info_size")=0) +.def("SetTo", py::overload_cast(&BMediaDecoder::SetTo), "", py::arg("mci")) +.def("SetInputFormat", &BMediaDecoder::SetInputFormat, "", py::arg("in_format"), py::arg("in_info")=NULL, py::arg("in_size")=0) // TODO +.def("SetOutputFormat", &BMediaDecoder::SetOutputFormat, "", py::arg("output_format")) +.def("Decode", &BMediaDecoder::Decode, "", py::arg("out_buffer"), py::arg("out_frameCount"), py::arg("out_mh"), py::arg("info")) // TODO out_buffer +.def("GetDecoderInfo", &BMediaDecoder::GetDecoderInfo, "", py::arg("out_info")) +; + +py::class_(m, "BMediaBufferDecoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("in_format"), py::arg("info")=NULL, py::arg("info_size")=0) +.def(py::init(), "", py::arg("mci")) +.def("DecodeBuffer", &BMediaBufferDecoder::DecodeBuffer, "", py::arg("input_buffer"), py::arg("input_size"), py::arg("out_buffer"), py::arg("out_frameCount"), py::arg("out_mh"), py::arg("info")=NULL) // TODO handle buffers +; + + +} diff --git a/bindings/media/MediaDefs.cpp b/bindings/media/MediaDefs.cpp new file mode 100644 index 0000000..acaf890 --- /dev/null +++ b/bindings/media/MediaDefs.cpp @@ -0,0 +1,931 @@ +#include +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaDefs, m) +{ +/* +m.attr("B_MEDIA_WILDCARD") = py::cast(B_MEDIA_WILDCARD); +m.attr("B_MEDIA_NODE_CREATED") = py::cast(B_MEDIA_NODE_CREATED); +m.attr("B_MEDIA_NODE_DELETED") = py::cast(B_MEDIA_NODE_DELETED); +m.attr("B_MEDIA_CONNECTION_MADE") = py::cast(B_MEDIA_CONNECTION_MADE); +m.attr("B_MEDIA_CONNECTION_BROKEN") = py::cast(B_MEDIA_CONNECTION_BROKEN); +m.attr("B_MEDIA_BUFFER_CREATED") = py::cast(B_MEDIA_BUFFER_CREATED); +m.attr("B_MEDIA_BUFFER_DELETED") = py::cast(B_MEDIA_BUFFER_DELETED); +m.attr("B_MEDIA_TRANSPORT_STATE") = py::cast(B_MEDIA_TRANSPORT_STATE); +m.attr("B_MEDIA_PARAMETER_CHANGED") = py::cast(B_MEDIA_PARAMETER_CHANGED); +m.attr("B_MEDIA_FORMAT_CHANGED") = py::cast(B_MEDIA_FORMAT_CHANGED); +m.attr("B_MEDIA_WEB_CHANGED") = py::cast(B_MEDIA_WEB_CHANGED); +m.attr("B_MEDIA_DEFAULT_CHANGED") = py::cast(B_MEDIA_DEFAULT_CHANGED); +m.attr("B_MEDIA_NEW_PARAMETER_VALUE") = py::cast(B_MEDIA_NEW_PARAMETER_VALUE); +m.attr("B_MEDIA_NODE_STOPPED") = py::cast(B_MEDIA_NODE_STOPPED); +m.attr("B_MEDIA_FLAVORS_CHANGED") = py::cast(B_MEDIA_FLAVORS_CHANGED); +m.attr("B_MEDIA_SERVER_STARTED") = py::cast(B_MEDIA_SERVER_STARTED); +m.attr("B_MEDIA_SERVER_QUIT") = py::cast(B_MEDIA_SERVER_QUIT); +*/ + +m.attr("B_MEDIA_WILDCARD") = 'TRWC'; +m.attr("B_MEDIA_NODE_CREATED") = 'TRIA'; +m.attr("B_MEDIA_NODE_DELETED") = 'TRIB'; +m.attr("B_MEDIA_CONNECTION_MADE") = 'TRIC'; +m.attr("B_MEDIA_CONNECTION_BROKEN") = 'TRID'; +m.attr("B_MEDIA_BUFFER_CREATED") = 'TRIE'; +m.attr("B_MEDIA_BUFFER_DELETED") = 'TRIF'; +m.attr("B_MEDIA_TRANSPORT_STATE") = 'TRIG'; +m.attr("B_MEDIA_PARAMETER_CHANGED") = 'TRIH'; +m.attr("B_MEDIA_FORMAT_CHANGED") = 'TRII'; +m.attr("B_MEDIA_WEB_CHANGED") = 'TRIJ'; +m.attr("B_MEDIA_DEFAULT_CHANGED") = 'TRIK'; +m.attr("B_MEDIA_NEW_PARAMETER_VALUE") = 'TRIL'; +m.attr("B_MEDIA_NODE_STOPPED") = 'TRIM'; +m.attr("B_MEDIA_FLAVORS_CHANGED") = 'TRIN'; +m.attr("B_MEDIA_SERVER_STARTED") = 'TRIO'; +m.attr("B_MEDIA_SERVER_QUIT") = 'TRIP'; + +/* +B_MEDIA_WILDCARD = 'TRWC', // 0x54525743 = 1415073475 +B_MEDIA_NODE_CREATED = 'TRIA', // 0x54524941 = 1415073441 +B_MEDIA_NODE_DELETED = 'TRIA' + 1, // 1415073442 +B_MEDIA_CONNECTION_MADE = 'TRIA' + 2, // 1415073443 +B_MEDIA_CONNECTION_BROKEN = 'TRIA' + 3, // 1415073444 +B_MEDIA_BUFFER_CREATED = 'TRIA' + 4, // 1415073445 +B_MEDIA_BUFFER_DELETED = 'TRIA' + 5, // 1415073446 +B_MEDIA_TRANSPORT_STATE = 'TRIA' + 6, // 1415073447 +B_MEDIA_PARAMETER_CHANGED = 'TRIA' + 7, // 1415073448 +B_MEDIA_FORMAT_CHANGED = 'TRIA' + 8, // 1415073449 +B_MEDIA_WEB_CHANGED = 'TRIA' + 9, // 1415073450 +B_MEDIA_DEFAULT_CHANGED = 'TRIA' + 10, // 1415073451 +B_MEDIA_NEW_PARAMETER_VALUE = 'TRIA' + 11, // 1415073452 +B_MEDIA_NODE_STOPPED = 'TRIA' + 12, // 1415073453 +B_MEDIA_FLAVORS_CHANGED = 'TRIA' + 13, // 1415073454 +B_MEDIA_SERVER_STARTED = 'TRIA' + 14, // 1415073455 +B_MEDIA_SERVER_QUIT = 'TRIA' + 15, // 1415073456 +*/ + +py::enum_(m, "media_type", "") +.value("B_MEDIA_NO_TYPE", media_type::B_MEDIA_NO_TYPE, "") +.value("B_MEDIA_UNKNOWN_TYPE", media_type::B_MEDIA_UNKNOWN_TYPE, "") +.value("B_MEDIA_RAW_AUDIO", media_type::B_MEDIA_RAW_AUDIO, "") +.value("B_MEDIA_RAW_VIDEO", media_type::B_MEDIA_RAW_VIDEO, "") +.value("B_MEDIA_VBL", media_type::B_MEDIA_VBL, "") +.value("B_MEDIA_TIMECODE", media_type::B_MEDIA_TIMECODE, "") +.value("B_MEDIA_MIDI", media_type::B_MEDIA_MIDI, "") +.value("B_MEDIA_TEXT", media_type::B_MEDIA_TEXT, "") +.value("B_MEDIA_HTML", media_type::B_MEDIA_HTML, "") +.value("B_MEDIA_MULTISTREAM", media_type::B_MEDIA_MULTISTREAM, "") +.value("B_MEDIA_PARAMETERS", media_type::B_MEDIA_PARAMETERS, "") +.value("B_MEDIA_ENCODED_AUDIO", media_type::B_MEDIA_ENCODED_AUDIO, "") +.value("B_MEDIA_ENCODED_VIDEO", media_type::B_MEDIA_ENCODED_VIDEO, "") +.value("B_MEDIA_PRIVATE", media_type::B_MEDIA_PRIVATE, "") +.value("B_MEDIA_FIRST_USER_TYPE", media_type::B_MEDIA_FIRST_USER_TYPE, "") +.export_values(); + +py::enum_(m, "node_kind", "") +.value("B_BUFFER_PRODUCER", node_kind::B_BUFFER_PRODUCER, "") +.value("B_BUFFER_CONSUMER", node_kind::B_BUFFER_CONSUMER, "") +.value("B_TIME_SOURCE", node_kind::B_TIME_SOURCE, "") +.value("B_CONTROLLABLE", node_kind::B_CONTROLLABLE, "") +.value("B_FILE_INTERFACE", node_kind::B_FILE_INTERFACE, "") +.value("B_ENTITY_INTERFACE", node_kind::B_ENTITY_INTERFACE, "") +.value("B_PHYSICAL_INPUT", node_kind::B_PHYSICAL_INPUT, "") +.value("B_PHYSICAL_OUTPUT", node_kind::B_PHYSICAL_OUTPUT, "") +.value("B_SYSTEM_MIXER", node_kind::B_SYSTEM_MIXER, "") +.export_values(); + +py::enum_(m, "video_orientation", "") +.value("B_VIDEO_TOP_LEFT_RIGHT", video_orientation::B_VIDEO_TOP_LEFT_RIGHT, "") +.value("B_VIDEO_BOTTOM_LEFT_RIGHT", video_orientation::B_VIDEO_BOTTOM_LEFT_RIGHT, "") +.export_values(); + +py::enum_(m, "media_flags", "") +.value("B_MEDIA_FLAGS_VERSION", media_flags::B_MEDIA_FLAGS_VERSION, "") +.value("B_MEDIA_FLAGS_PRIVATE", media_flags::B_MEDIA_FLAGS_PRIVATE, "") +.export_values(); + +py::enum_(m, "media_producer_status", "") +.value("B_DATA_NOT_AVAILABLE", media_producer_status::B_DATA_NOT_AVAILABLE, "") +.value("B_DATA_AVAILABLE", media_producer_status::B_DATA_AVAILABLE, "") +.value("B_PRODUCER_STOPPED", media_producer_status::B_PRODUCER_STOPPED, "") +.export_values(); + +py::enum_(m, "media_realtime_flags", "") +.value("B_MEDIA_REALTIME_ALLOCATOR", media_realtime_flags::B_MEDIA_REALTIME_ALLOCATOR, "") +.value("B_MEDIA_REALTIME_AUDIO", media_realtime_flags::B_MEDIA_REALTIME_AUDIO, "") +.value("B_MEDIA_REALTIME_VIDEO", media_realtime_flags::B_MEDIA_REALTIME_VIDEO, "") +.value("B_MEDIA_REALTIME_ANYKIND", media_realtime_flags::B_MEDIA_REALTIME_ANYKIND, "") +.export_values(); + +py::enum_(m, "media_frame_flags", "") +.value("B_MEDIA_KEY_FRAME", media_frame_flags::B_MEDIA_KEY_FRAME, "") +.export_values(); + +py::enum_(m, "media_multi_channels", "") +.value("B_CHANNEL_LEFT", media_multi_channels::B_CHANNEL_LEFT, "") +.value("B_CHANNEL_RIGHT", media_multi_channels::B_CHANNEL_RIGHT, "") +.value("B_CHANNEL_CENTER", media_multi_channels::B_CHANNEL_CENTER, "") +.value("B_CHANNEL_SUB", media_multi_channels::B_CHANNEL_SUB, "") +.value("B_CHANNEL_REARLEFT", media_multi_channels::B_CHANNEL_REARLEFT, "") +.value("B_CHANNEL_REARRIGHT", media_multi_channels::B_CHANNEL_REARRIGHT, "") +.value("B_CHANNEL_FRONT_LEFT_CENTER", media_multi_channels::B_CHANNEL_FRONT_LEFT_CENTER, "") +.value("B_CHANNEL_FRONT_RIGHT_CENTER", media_multi_channels::B_CHANNEL_FRONT_RIGHT_CENTER, "") +.value("B_CHANNEL_BACK_CENTER", media_multi_channels::B_CHANNEL_BACK_CENTER, "") +.value("B_CHANNEL_SIDE_LEFT", media_multi_channels::B_CHANNEL_SIDE_LEFT, "") +.value("B_CHANNEL_SIDE_RIGHT", media_multi_channels::B_CHANNEL_SIDE_RIGHT, "") +.value("B_CHANNEL_TOP_CENTER", media_multi_channels::B_CHANNEL_TOP_CENTER, "") +.value("B_CHANNEL_TOP_FRONT_LEFT", media_multi_channels::B_CHANNEL_TOP_FRONT_LEFT, "") +.value("B_CHANNEL_TOP_FRONT_CENTER", media_multi_channels::B_CHANNEL_TOP_FRONT_CENTER, "") +.value("B_CHANNEL_TOP_FRONT_RIGHT", media_multi_channels::B_CHANNEL_TOP_FRONT_RIGHT, "") +.value("B_CHANNEL_TOP_BACK_LEFT", media_multi_channels::B_CHANNEL_TOP_BACK_LEFT, "") +.value("B_CHANNEL_TOP_BACK_CENTER", media_multi_channels::B_CHANNEL_TOP_BACK_CENTER, "") +.value("B_CHANNEL_TOP_BACK_RIGHT", media_multi_channels::B_CHANNEL_TOP_BACK_RIGHT, "") +.export_values(); + +py::enum_(m, "media_multi_matrix", "") +.value("B_MATRIX_PROLOGIC_LR", media_multi_matrix::B_MATRIX_PROLOGIC_LR, "") +.value("B_MATRIX_AMBISONIC_WXYZ", media_multi_matrix::B_MATRIX_AMBISONIC_WXYZ, "") +.export_values(); + +py::enum_(m, "media_display_flags", "") +.value("B_F1_DOMINANT", media_display_flags::B_F1_DOMINANT, "") +.value("B_F2_DOMINANT", media_display_flags::B_F2_DOMINANT, "") +.value("B_TOP_SCANLINE_F1", media_display_flags::B_TOP_SCANLINE_F1, "") +.value("B_TOP_SCANLINE_F2", media_display_flags::B_TOP_SCANLINE_F2, "") +.export_values(); + +py::enum_(m, "media_format_flags", "") +.value("B_MEDIA_RETAINED_DATA", media_format_flags::B_MEDIA_RETAINED_DATA, "") +.value("B_MEDIA_MULTIPLE_BUFFERS", media_format_flags::B_MEDIA_MULTIPLE_BUFFERS, "") +.value("B_MEDIA_CONTIGUOUS_BUFFER", media_format_flags::B_MEDIA_CONTIGUOUS_BUFFER, "") +.value("B_MEDIA_LINEAR_UPDATES", media_format_flags::B_MEDIA_LINEAR_UPDATES, "") +.value("B_MEDIA_MAUI_UNDEFINED_FLAGS", media_format_flags::B_MEDIA_MAUI_UNDEFINED_FLAGS, "") +.export_values(); + +py::enum_(m, "media_format_family", "") +.value("B_ANY_FORMAT_FAMILY", media_format_family::B_ANY_FORMAT_FAMILY, "") +.value("B_BEOS_FORMAT_FAMILY", media_format_family::B_BEOS_FORMAT_FAMILY, "") +.value("B_QUICKTIME_FORMAT_FAMILY", media_format_family::B_QUICKTIME_FORMAT_FAMILY, "") +.value("B_AVI_FORMAT_FAMILY", media_format_family::B_AVI_FORMAT_FAMILY, "") +.value("B_ASF_FORMAT_FAMILY", media_format_family::B_ASF_FORMAT_FAMILY, "") +.value("B_MPEG_FORMAT_FAMILY", media_format_family::B_MPEG_FORMAT_FAMILY, "") +.value("B_WAV_FORMAT_FAMILY", media_format_family::B_WAV_FORMAT_FAMILY, "") +.value("B_AIFF_FORMAT_FAMILY", media_format_family::B_AIFF_FORMAT_FAMILY, "") +.value("B_AVR_FORMAT_FAMILY", media_format_family::B_AVR_FORMAT_FAMILY, "") +.value("B_MISC_FORMAT_FAMILY", media_format_family::B_MISC_FORMAT_FAMILY, "") +.export_values(); + +m.attr("B_BIG_ENDIAN") = 0;//py::cast(B_BIG_ENDIAN); +m.attr("B_LITTLE_ENDIAN") = 1;//py::cast(B_LITTLE_ENDIAN); + +m.attr("B_UNDEFINED_SAMPLES") = 0;//py::cast(B_UNDEFINED_SAMPLES); +m.attr("B_LINEAR_SAMPLES") = 1;//py::cast(B_LINEAR_SAMPLES); +m.attr("B_FLOAT_SAMPLES") = 2;//py::cast(B_FLOAT_SAMPLES); +m.attr("B_MULAW_SAMPLES") = 3;//py::cast(B_MULAW_SAMPLES); + +m.attr("B_CODEC_TYPE_INFO") = 0x040807b2;//py::cast(B_CODEC_TYPE_INFO); from haiku source kits/media/MediaDefs.cpp + +m.attr("B_MEDIA_MESSAGE_SIZE") = 16384;//py::cast(B_MEDIA_MESSAGE_SIZE); + +m.attr("B_MEDIA_SERVER_SIGNATURE") = "application/x-vnd.Be.media-server";//py::cast(B_MEDIA_SERVER_SIGNATURE); + +py::class_(m, "media_destination") +.def(py::init(), "") +.def(py::init(), "", py::arg(""), py::arg("")) +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_destination::operator=, "", py::arg("other")) +.def_readwrite("port", &media_destination::port, "") +.def_readwrite("id", &media_destination::id, "") +//.def_readwrite("null", &media_destination::null, "") +; + +py::class_(m, "media_source") +.def(py::init(), "") +.def(py::init(), "", py::arg(""), py::arg("")) +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_source::operator=, "", py::arg("other")) +.def_readwrite("port", &media_source::port, "") +.def_readwrite("id", &media_source::id, "") +//.def_readwrite("null", &media_source::null, "") +; + +py::class_(m, "media_raw_audio_format") +.def_readwrite("frame_rate", &media_raw_audio_format::frame_rate, "") +.def_readwrite("channel_count", &media_raw_audio_format::channel_count, "") +.def_readwrite("format", &media_raw_audio_format::format, "") +.def_readwrite("byte_order", &media_raw_audio_format::byte_order, "") +.def_readwrite("buffer_size", &media_raw_audio_format::buffer_size, "") +//.def_readwrite("wildcard", &media_raw_audio_format::wildcard, "") +.def_static("wildcard", []() { return media_raw_audio_format::wildcard; }) +; + +py::class_(m, "media_audio_header") +//.def_readwrite("_reserved_", &media_audio_header::_reserved_, "") +.def_property( + "_reserved_", + [](const media_audio_header &header) { + py::array_t result(14); + std::memcpy(result.mutable_data(), &header._reserved_, sizeof(header._reserved_)); + return result; + }, + [](media_audio_header &header, py::array_t value) { + if (value.size() != 14) { + throw std::runtime_error("Array must have size 14"); + } + std::memcpy(&header._reserved_, value.data(), sizeof(header._reserved_)); + },"") +.def_readwrite("frame_rate", &media_audio_header::frame_rate, "") +.def_readwrite("channel_count", &media_audio_header::channel_count, "") +; + +py::class_(m, "media_multi_audio_info") +.def_readwrite("channel_mask", &media_multi_audio_info::channel_mask, "") +.def_readwrite("valid_bits", &media_multi_audio_info::valid_bits, "") +.def_readwrite("matrix_mask", &media_multi_audio_info::matrix_mask, "") +//.def_readwrite("_reserved_b", &media_multi_audio_info::_reserved_b, "") +.def_property( + "_reserved_b", + [](const media_multi_audio_info &info) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &info._reserved_b, sizeof(info._reserved_b)); + return result; + }, + [](media_multi_audio_info &info, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&info._reserved_b, value.data(), sizeof(info._reserved_b)); + },"") +; + +py::class_(m, "media_multi_audio_format") +//.def_readwrite("wildcard", &media_multi_audio_format::wildcard, "") +.def_static("wildcard", []() { return media_multi_audio_format::wildcard; }) +; + +py::class_(m, "media_encoded_audio_format") +.def_readwrite("output", &media_encoded_audio_format::output, "") +.def_readwrite("encoding", &media_encoded_audio_format::encoding, "") +.def_readwrite("bit_rate", &media_encoded_audio_format::bit_rate, "") +.def_readwrite("frame_size", &media_encoded_audio_format::frame_size, "") +.def_readwrite("multi_info", &media_encoded_audio_format::multi_info, "") +//.def_readwrite("_reserved_", &media_encoded_audio_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_encoded_audio_format &format) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_encoded_audio_format &format, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +//.def_readwrite("wildcard", &media_encoded_audio_format::wildcard, "") +.def_static("wildcard", []() { return media_encoded_audio_format::wildcard; }) +; + +py::class_(m, "media_encoded_audio_header") +//.def_readwrite("_reserved_0", &media_encoded_audio_header::_reserved_0, "") +.def_property( + "_reserved_0", + [](const media_encoded_audio_header &header) { + py::array_t result(14); + std::memcpy(result.mutable_data(), &header._reserved_0, sizeof(header._reserved_0)); + return result; + }, + [](media_encoded_audio_header &header, py::array_t value) { + if (value.size() != 14) { + throw std::runtime_error("Array must have size 14"); + } + std::memcpy(&header._reserved_0, value.data(), sizeof(header._reserved_0)); + },"") +.def_readwrite("buffer_flags", &media_encoded_audio_header::buffer_flags, "") +.def_readwrite("unused_mask", &media_encoded_audio_header::unused_mask, "") +//.def_readwrite("_reserved_2", &media_encoded_audio_header::_reserved_2, "") +.def_property( + "_reserved_2", + [](const media_encoded_audio_header &header) { + py::array_t result(2); + std::memcpy(result.mutable_data(), &header._reserved_2, sizeof(header._reserved_2)); + return result; + }, + [](media_encoded_audio_header &header, py::array_t value) { + if (value.size() != 2) { + throw std::runtime_error("Array must have size 2"); + } + std::memcpy(&header._reserved_2, value.data(), sizeof(header._reserved_2)); + },"") +; + +py::class_(m, "media_video_display_info") +.def_readwrite("format", &media_video_display_info::format, "") +.def_readwrite("line_width", &media_video_display_info::line_width, "") +.def_readwrite("line_count", &media_video_display_info::line_count, "") +.def_readwrite("bytes_per_row", &media_video_display_info::bytes_per_row, "") +.def_readwrite("pixel_offset", &media_video_display_info::pixel_offset, "") +.def_readwrite("line_offset", &media_video_display_info::line_offset, "") +.def_readwrite("flags", &media_video_display_info::flags, "") +//.def_readwrite("_reserved_", &media_video_display_info::_reserved_, "") +.def_property( + "_reserved_", + [](const media_video_display_info &info) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](media_video_display_info &info, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") +//.def_readwrite("wildcard", &media_video_display_info::wildcard, "") +.def_static("wildcard", []() { return media_video_display_info::wildcard; }) +; + +py::class_(m, "media_raw_video_format") +.def_readwrite("field_rate", &media_raw_video_format::field_rate, "") +.def_readwrite("interlace", &media_raw_video_format::interlace, "") +.def_readwrite("first_active", &media_raw_video_format::first_active, "") +.def_readwrite("last_active", &media_raw_video_format::last_active, "") +.def_readwrite("orientation", &media_raw_video_format::orientation, "") +.def_readwrite("pixel_width_aspect", &media_raw_video_format::pixel_width_aspect, "") +.def_readwrite("pixel_height_aspect", &media_raw_video_format::pixel_height_aspect, "") +.def_readwrite("display", &media_raw_video_format::display, "") +//.def_readwrite("wildcard", &media_raw_video_format::wildcard, "") +.def_static("wildcard", []() { return media_raw_video_format::wildcard; }) +; + +py::class_(m, "media_video_header") +//.def_readwrite("_reserved_", &media_video_header::_reserved_, "") +.def_property( + "_reserved_", + [](const media_video_header &header) { + py::array_t result(8); + std::memcpy(result.mutable_data(), &header._reserved_, sizeof(header._reserved_)); + return result; + }, + [](media_video_header &header, py::array_t value) { + if (value.size() != 8) { + throw std::runtime_error("Array must have size 8"); + } + std::memcpy(&header._reserved_, value.data(), sizeof(header._reserved_)); + },"") +.def_readwrite("display_line_width", &media_video_header::display_line_width, "") +.def_readwrite("display_line_count", &media_video_header::display_line_count, "") +.def_readwrite("bytes_per_row", &media_video_header::bytes_per_row, "") +.def_readwrite("pixel_width_aspect", &media_video_header::pixel_width_aspect, "") +.def_readwrite("pixel_height_aspect", &media_video_header::pixel_height_aspect, "") +.def_readwrite("field_gamma", &media_video_header::field_gamma, "") +.def_readwrite("field_sequence", &media_video_header::field_sequence, "") +.def_readwrite("field_number", &media_video_header::field_number, "") +.def_readwrite("pulldown_number", &media_video_header::pulldown_number, "") +.def_readwrite("first_active_line", &media_video_header::first_active_line, "") +.def_readwrite("line_count", &media_video_header::line_count, "") +; + +py::class_(m, "media_encoded_video_format") +.def_readwrite("output", &media_encoded_video_format::output, "") +.def_readwrite("avg_bit_rate", &media_encoded_video_format::avg_bit_rate, "") +.def_readwrite("max_bit_rate", &media_encoded_video_format::max_bit_rate, "") +.def_readwrite("encoding", &media_encoded_video_format::encoding, "") +.def_readwrite("frame_size", &media_encoded_video_format::frame_size, "") +.def_readwrite("forward_history", &media_encoded_video_format::forward_history, "") +.def_readwrite("backward_history", &media_encoded_video_format::backward_history, "") +//.def_readwrite("_reserved_", &media_encoded_video_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_encoded_video_format &format) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_encoded_video_format &format, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +//.def_readwrite("wildcard", &media_encoded_video_format::wildcard, "") +.def_static("wildcard", []() { return media_encoded_video_format::wildcard; }) +; + +py::class_(m, "media_encoded_video_header") +//.def_readwrite("_reserved_1", &media_encoded_video_header::_reserved_1, "") +.def_property( + "_reserved_1", + [](const media_encoded_video_header &header) { + py::array_t result(9); + std::memcpy(result.mutable_data(), &header._reserved_1, sizeof(header._reserved_1)); + return result; + }, + [](media_encoded_video_header &header, py::array_t value) { + if (value.size() != 9) { + throw std::runtime_error("Array must have size 9"); + } + std::memcpy(&header._reserved_1, value.data(), sizeof(header._reserved_1)); + },"") +.def_readwrite("field_flags", &media_encoded_video_header::field_flags, "") +.def_readwrite("forward_history", &media_encoded_video_header::forward_history, "") +.def_readwrite("backward_history", &media_encoded_video_header::backward_history, "") +.def_readwrite("unused_mask", &media_encoded_video_header::unused_mask, "") +//.def_readwrite("_reserved_2", &media_encoded_video_header::_reserved_2, "") +.def_property( + "_reserved_2", + [](const media_encoded_video_header &header) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &header._reserved_2, sizeof(header._reserved_2)); + return result; + }, + [](media_encoded_video_header &header, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&header._reserved_2, value.data(), sizeof(header._reserved_2)); + },"") +.def_readwrite("field_gamma", &media_encoded_video_header::field_gamma, "") +.def_readwrite("field_sequence", &media_encoded_video_header::field_sequence, "") +.def_readwrite("field_number", &media_encoded_video_header::field_number, "") +.def_readwrite("pulldown_number", &media_encoded_video_header::pulldown_number, "") +.def_readwrite("first_active_line", &media_encoded_video_header::first_active_line, "") +.def_readwrite("line_count", &media_encoded_video_header::line_count, "") +; + +py::class_(m, "media_multistream_format") +.def_readwrite("avg_bit_rate", &media_multistream_format::avg_bit_rate, "") +.def_readwrite("max_bit_rate", &media_multistream_format::max_bit_rate, "") +.def_readwrite("avg_chunk_size", &media_multistream_format::avg_chunk_size, "") +.def_readwrite("max_chunk_size", &media_multistream_format::max_chunk_size, "") +.def_readwrite("flags", &media_multistream_format::flags, "") +.def_readwrite("format", &media_multistream_format::format, "") +//.def_readwrite("_reserved_", &media_multistream_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_multistream_format &format) { + py::array_t result(2); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_multistream_format &format, py::array_t value) { + if (value.size() != 2) { + throw std::runtime_error("Array must have size 2"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +.def_readwrite("u", &media_multistream_format::u, "") +//.def_readwrite("wildcard", &media_multistream_format::wildcard, "") +.def_static("wildcard", []() { return media_multistream_format::wildcard; }) +; + +py::class_(m, "vid_info") +.def_readwrite("frame_rate", &media_multistream_format::vid_info::frame_rate, "") +.def_readwrite("width", &media_multistream_format::vid_info::width, "") +.def_readwrite("height", &media_multistream_format::vid_info::height, "") +.def_readwrite("space", &media_multistream_format::vid_info::space, "") +.def_readwrite("sampling_rate", &media_multistream_format::vid_info::sampling_rate, "") +.def_readwrite("sample_format", &media_multistream_format::vid_info::sample_format, "") +.def_readwrite("byte_order", &media_multistream_format::vid_info::byte_order, "") +.def_readwrite("channel_count", &media_multistream_format::vid_info::channel_count, "") +; + +py::class_(m, "avi_info") +.def_readwrite("us_per_frame", &media_multistream_format::avi_info::us_per_frame, "") +.def_readwrite("width", &media_multistream_format::avi_info::width, "") +.def_readwrite("height", &media_multistream_format::avi_info::height, "") +.def_readwrite("_reserved_", &media_multistream_format::avi_info::_reserved_, "") +.def_readwrite("type_count", &media_multistream_format::avi_info::type_count, "") +//.def_readwrite("types", &media_multistream_format::avi_info::types, "") +.def_property( + "types", + [](const media_multistream_format::avi_info &format) { + py::array_t result(5); + std::memcpy(result.mutable_data(), &format.types, sizeof(format.types)); + return result; + }, + [](media_multistream_format::avi_info &format, py::array_t value) { + if (value.size() != 5) { + throw std::runtime_error("Array must have size 5"); + } + std::memcpy(&format.types, value.data(), sizeof(format.types)); + },"") +; + +/*py::class_(m, "union ") +.def_readwrite("vid", &union ::vid, "") +.def_readwrite("avi", &union ::avi, "") +;*/ + +py::class_(m, "media_multistream_header") +//.def_readwrite("_reserved_", &media_multistream_header::_reserved_, "") +.def_property( + "_reserved_", + [](const media_multistream_header &header) { + py::array_t result(14); + std::memcpy(result.mutable_data(), &header._reserved_, sizeof(header._reserved_)); + return result; + }, + [](media_multistream_header &header, py::array_t value) { + if (value.size() != 14) { + throw std::runtime_error("Array must have size 14"); + } + std::memcpy(&header._reserved_, value.data(), sizeof(header._reserved_)); + },"") +.def_readwrite("unused_mask", &media_multistream_header::unused_mask, "") +//.def_readwrite("_reserved_2", &media_multistream_header::_reserved_2, "") +.def_property( + "_reserved_2", + [](const media_multistream_header &header) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &header._reserved_2, sizeof(header._reserved_2)); + return result; + }, + [](media_multistream_header &header, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&header._reserved_2, value.data(), sizeof(header._reserved_2)); + },"") +.def_readwrite("flags", &media_multistream_header::flags, "") +; + +py::class_(m, "media_format") +.def("IsVideo", &media_format::IsVideo, "") +.def("Width", py::overload_cast<>(&media_format::Width), "") +.def("Height", py::overload_cast<>(&media_format::Height), "") +.def("ColorSpace", py::overload_cast<>(&media_format::ColorSpace), "") +.def("Width", py::overload_cast<>(&media_format::Width), "") +.def("Height", py::overload_cast<>(&media_format::Height), "") +.def("ColorSpace", py::overload_cast<>(&media_format::ColorSpace), "") +.def("IsAudio", &media_format::IsAudio, "") +.def("AudioFormat", py::overload_cast<>(&media_format::AudioFormat), "") +.def("AudioFormat", py::overload_cast<>(&media_format::AudioFormat), "") +.def("AudioFrameSize", &media_format::AudioFrameSize, "") +.def("Encoding", &media_format::Encoding, "") +.def("Matches", &media_format::Matches, "", py::arg("other")) +.def("SpecializeTo", &media_format::SpecializeTo, "", py::arg("other")) +.def("SetMetaData", &media_format::SetMetaData, "", py::arg("data"), py::arg("size")) +.def("MetaData", &media_format::MetaData, "") +.def("MetaDataSize", &media_format::MetaDataSize, "") +.def("Unflatten", &media_format::Unflatten, "", py::arg("flatBuffer")) +.def("Clear", &media_format::Clear, "") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_format::operator=, "", py::arg("other")) +.def_readwrite("type", &media_format::type, "") +.def_readwrite("user_data_type", &media_format::user_data_type, "") +//.def_readwrite("user_data", &media_format::user_data, "") +.def_property( + "user_data", + [](const media_format &format) { + py::array_t result(48); + std::memcpy(result.mutable_data(), &format.user_data, sizeof(format.user_data)); + return result; + }, + [](media_format &format, py::array_t value) { + if (value.size() != 48) { + throw std::runtime_error("Array must have size 48"); + } + std::memcpy(&format.user_data, value.data(), sizeof(format.user_data)); + },"") +//.def_readwrite("_reserved_", &media_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_format &format) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_format &format, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +.def_readwrite("require_flags", &media_format::require_flags, "") +.def_readwrite("deny_flags", &media_format::deny_flags, "") +.def_readwrite("u", &media_format::u, "") +; +/* +py::class_(m, "union ") +.def_readwrite("raw_audio", &union ::raw_audio, "") +.def_readwrite("raw_video", &union ::raw_video, "") +.def_readwrite("multistream", &union ::multistream, "") +.def_readwrite("encoded_audio", &union ::encoded_audio, "") +.def_readwrite("encoded_video", &union ::encoded_video, "") +.def_readwrite("_reserved_", &union ::_reserved_, "") +;*/ + +py::class_(m, "media_seek_tag") +//.def_readwrite("data", &media_seek_tag::data, "") +.def_property( + "data", + [](const media_seek_tag &tag) { + py::array_t result(16); + std::memcpy(result.mutable_data(), &tag.data, sizeof(tag.data)); + return result; + }, + [](media_seek_tag &tag, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&tag.data, value.data(), sizeof(tag.data)); + },"") +; + +py::class_(m, "media_header_time_code") +.def_readwrite("type", &media_header_time_code::type, "") +.def_readwrite("_reserved", &media_header_time_code::_reserved, "") +.def_readwrite("hours", &media_header_time_code::hours, "") +.def_readwrite("minutes", &media_header_time_code::minutes, "") +.def_readwrite("seconds", &media_header_time_code::seconds, "") +.def_readwrite("frames", &media_header_time_code::frames, "") +.def_readwrite("subframes", &media_header_time_code::subframes, "") +; + +py::class_(m, "media_header") +.def_readwrite("type", &media_header::type, "") +.def_readwrite("buffer", &media_header::buffer, "") +.def_readwrite("destination", &media_header::destination, "") +.def_readwrite("time_source", &media_header::time_source, "") +.def_readwrite("_deprecated_", &media_header::_deprecated_, "") +.def_readwrite("size_used", &media_header::size_used, "") +.def_readwrite("start_time", &media_header::start_time, "") +.def_readwrite("owner", &media_header::owner, "") +.def_readwrite("user_data_type", &media_header::user_data_type, "") +//.def_readwrite("user_data", &media_header::user_data, "") +.def_property( + "user_data", + [](const media_header &header) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &header.user_data, sizeof(header.user_data)); + return result; + }, + [](media_header &header, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&header.user_data, value.data(), sizeof(header.user_data)); + },"") +.def_readwrite("source", &media_header::source, "") +.def_readwrite("source_port", &media_header::source_port, "") +.def_readwrite("file_pos", &media_header::file_pos, "") +.def_readwrite("orig_size", &media_header::orig_size, "") +.def_readwrite("data_offset", &media_header::data_offset, "") +.def_readwrite("u", &media_header::u, "") +; +/* +py::class_(m, "union ") +.def_readwrite("raw_audio", &union ::raw_audio, "") +.def_readwrite("raw_video", &union ::raw_video, "") +.def_readwrite("multistream", &union ::multistream, "") +.def_readwrite("encoded_audio", &union ::encoded_audio, "") +.def_readwrite("encoded_video", &union ::encoded_video, "") +.def_readwrite("_reserved_", &union ::_reserved_, "") +;*/ + +py::class_(m, "media_file_format_id") +.def_readwrite("node", &media_file_format_id::node, "") +.def_readwrite("device", &media_file_format_id::device, "") +.def_readwrite("internal_id", &media_file_format_id::internal_id, "") +; + +py::class_(m, "media_file_format") +/* + B_READABLE = 0x1, + B_WRITABLE = 0x2, + B_PERFECTLY_SEEKABLE = 0x4, + B_IMPERFECTLY_SEEKABLE = 0x8, + B_KNOWS_RAW_VIDEO = 0x10, + B_KNOWS_RAW_AUDIO = 0x20, + B_KNOWS_MIDI = 0x40, + B_KNOWS_ENCODED_VIDEO = 0x80, + B_KNOWS_ENCODED_AUDIO = 0x100, + B_KNOWS_OTHER = 0x1000000, // For example sub-title streams + B_KNOWS_ANYTHING = 0x2000000 + */ +.def_readwrite("capabilities", &media_file_format::capabilities, "") +.def_readwrite("id", &media_file_format::id, "") +.def_readwrite("family", &media_file_format::family, "") +.def_readwrite("version", &media_file_format::version, "") +//.def_readwrite("_reserved_", &media_file_format::_reserved_, "") +.def_property( + "_reserved_", + [](const media_file_format &format) { + py::array_t result(25); + std::memcpy(result.mutable_data(), &format._reserved_, sizeof(format._reserved_)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 25) { + throw std::runtime_error("Array must have size 25"); + } + std::memcpy(&format._reserved_, value.data(), sizeof(format._reserved_)); + },"") +//.def_readwrite("mime_type", &media_file_format::mime_type, "") +.def_property( + "mime_type", + [](const media_file_format &format) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &format.mime_type, sizeof(format.mime_type)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&format.mime_type, value.data(), sizeof(format.mime_type)); + },"") +//.def_readwrite("pretty_name", &media_file_format::pretty_name, "") +.def_property( + "pretty_name", + [](const media_file_format &format) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &format.pretty_name, sizeof(format.pretty_name)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&format.pretty_name, value.data(), sizeof(format.pretty_name)); + },"") +//.def_readwrite("short_name", &media_file_format::short_name, "") +.def_property( + "short_name", + [](const media_file_format &format) { + py::array_t result(32); + std::memcpy(result.mutable_data(), &format.short_name, sizeof(format.short_name)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 32) { + throw std::runtime_error("Array must have size 32"); + } + std::memcpy(&format.short_name, value.data(), sizeof(format.short_name)); + },"") +//.def_readwrite("file_extension", &media_file_format::file_extension, "") +.def_property( + "file_extension", + [](const media_file_format &format) { + py::array_t result(8); + std::memcpy(result.mutable_data(), &format.file_extension, sizeof(format.file_extension)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 8) { + throw std::runtime_error("Array must have size 8"); + } + std::memcpy(&format.file_extension, value.data(), sizeof(format.file_extension)); + },"") +//.def_readwrite("reserved", &media_file_format::reserved, "") +.def_property( + "reserved", + [](const media_file_format &format) { + py::array_t result(88); + std::memcpy(result.mutable_data(), &format.reserved, sizeof(format.reserved)); + return result; + }, + [](media_file_format &format, py::array_t value) { + if (value.size() != 88) { + throw std::runtime_error("Array must have size 88"); + } + std::memcpy(&format.reserved, value.data(), sizeof(format.reserved)); + },"") +; + +py::class_(m, "media_encode_info") +.def(py::init(), "") +.def_readwrite("flags", &media_encode_info::flags, "") +.def_readwrite("used_data_size", &media_encode_info::used_data_size, "") +.def_readwrite("start_time", &media_encode_info::start_time, "") +.def_readwrite("time_to_encode", &media_encode_info::time_to_encode, "") +//.def_readwrite("_pad", &media_encode_info::_pad, "") +.def_property( + "_pad", + [](const media_encode_info &info) { + py::array_t result(22); + std::memcpy(result.mutable_data(), &info._pad, sizeof(info._pad)); + return result; + }, + [](media_encode_info &info, py::array_t value) { + if (value.size() != 22) { + throw std::runtime_error("Array must have size 22"); + } + std::memcpy(&info._pad, value.data(), sizeof(info._pad)); + },"") +.def_readwrite("file_format_data", &media_encode_info::file_format_data, "") +.def_readwrite("file_format_data_size", &media_encode_info::file_format_data_size, "") +.def_readwrite("codec_data", &media_encode_info::codec_data, "") +.def_readwrite("codec_data_size", &media_encode_info::codec_data_size, "") +; + +py::class_(m, "encode_parameters") +.def_readwrite("quality", &encode_parameters::quality, "") +.def_readwrite("avg_field_size", &encode_parameters::avg_field_size, "") +.def_readwrite("max_field_size", &encode_parameters::max_field_size, "") +//.def_readwrite("_pad", &encode_parameters::_pad, "") +.def_property( + "_pad", + [](const encode_parameters ¶meters) { + py::array_t result(27); + std::memcpy(result.mutable_data(), ¶meters._pad, sizeof(parameters._pad)); + return result; + }, + [](encode_parameters ¶meters, py::array_t value) { + if (value.size() != 27) { + throw std::runtime_error("Array must have size 27"); + } + std::memcpy(¶meters._pad, value.data(), sizeof(parameters._pad)); + },"") +.def_readwrite("user_data", &encode_parameters::user_data, "") +.def_readwrite("user_data_size", &encode_parameters::user_data_size, "") +; + +py::class_(m, "media_decode_info") +.def(py::init(), "") +.def_readwrite("time_to_decode", &media_decode_info::time_to_decode, "") +//.def_readwrite("_pad", &media_decode_info::_pad, "") +.def_property( + "_pad", + [](const media_decode_info &info) { + py::array_t result(26); + std::memcpy(result.mutable_data(), &info._pad, sizeof(info._pad)); + return result; + }, + [](media_decode_info &info, py::array_t value) { + if (value.size() != 26) { + throw std::runtime_error("Array must have size 26"); + } + std::memcpy(&info._pad, value.data(), sizeof(info._pad)); + },"") +.def_readwrite("file_format_data", &media_decode_info::file_format_data, "") +.def_readwrite("file_format_data_size", &media_decode_info::file_format_data_size, "") +.def_readwrite("codec_data", &media_decode_info::codec_data, "") +.def_readwrite("codec_data_size", &media_decode_info::codec_data_size, "") +; + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("format_is_compatible", &format_is_compatible, "", py::arg("a"), py::arg("b")); + +m.def("string_for_format", &string_for_format, "", py::arg("f"), py::arg("buf"), py::arg("size")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("get_next_file_format", &get_next_file_format, "", py::arg("cookie"), py::arg("mfi")); + +m.def("launch_media_server", &launch_media_server, "", py::arg("timeout")=B_INFINITE_TIMEOUT, py::arg("bool(*progress)(intstage,constchar*message,void*cookie)")=NULL, py::arg("cookie")=NULL, py::arg("flags")=0); + +m.def("shutdown_media_server", &shutdown_media_server, "", py::arg("timeout")=B_INFINITE_TIMEOUT, py::arg("bool(*progress)(intstage,constchar*message,void*cookie)")=NULL, py::arg("cookie")=NULL); + +} diff --git a/bindings/media/MediaEncoder.cpp b/bindings/media/MediaEncoder.cpp new file mode 100644 index 0000000..974222a --- /dev/null +++ b/bindings/media/MediaEncoder.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +class PyBMediaEncoder : public BMediaEncoder{ + public: + using BMediaEncoder::BMediaEncoder; + status_t WriteChunk(const void* buffer, size_t size, media_encode_info* info) override { + PYBIND11_OVERRIDE_PURE( status_t, BMediaEncoder, WriteChunk, buffer, size, info ); + } + status_t AddTrackInfo(uint32 code, const char* data, size_t size) override { + PYBIND11_OVERRIDE( status_t, BMediaEncoder, AddTrackInfo, code, data, size ); + } +}; + +PYBIND11_MODULE(MediaEncoder, m) +{ +//m.attr("Encoder") = py::cast(Encoder); + +//m.attr("EncoderPlugin") = py::cast(EncoderPlugin); + +py::class_(m, "BMediaEncoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("outputFormat")) +.def(py::init(), "", py::arg("info")) +.def("InitCheck", &BMediaEncoder::InitCheck, "") +.def("SetTo", py::overload_cast(&BMediaEncoder::SetTo), "", py::arg("outputFormat")) +.def("SetTo", py::overload_cast(&BMediaEncoder::SetTo), "", py::arg("info")) +.def("SetFormat", &BMediaEncoder::SetFormat, "", py::arg("inputFormat"), py::arg("outputFormat"), py::arg("fileFormat")=NULL) +.def("Encode", &BMediaEncoder::Encode, "", py::arg("buffer"), py::arg("frameCount"), py::arg("info")) // TODO convert void to py::buffer? py::bytes?? +.def("GetEncodeParameters", &BMediaEncoder::GetEncodeParameters, "", py::arg("parameters")) +.def("SetEncodeParameters", &BMediaEncoder::SetEncodeParameters, "", py::arg("parameters")) +; + +py::class_(m, "BMediaBufferEncoder") +.def(py::init(), "") +.def(py::init(), "", py::arg("outputFormat")) +.def(py::init(), "", py::arg("info")) +.def("EncodeToBuffer", &BMediaBufferEncoder::EncodeToBuffer, "", py::arg("outputBuffer"), py::arg("_size"), py::arg("inputBuffer"), py::arg("frameCount"), py::arg("info")) // TODO void +; + + +} diff --git a/bindings/media/MediaEventLooper.cpp b/bindings/media/MediaEventLooper.cpp new file mode 100644 index 0000000..54443f0 --- /dev/null +++ b/bindings/media/MediaEventLooper.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +void define_MediaEventLooper(py::module_& m) +{ +py::class_(m, "BMediaEventLooper") +; + + +} diff --git a/bindings/media/MediaFile.cpp b/bindings/media/MediaFile.cpp new file mode 100644 index 0000000..637ddaa --- /dev/null +++ b/bindings/media/MediaFile.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaFile, m) +{ +m.attr("B_MEDIA_FILE_REPLACE_MODE") = 0x00000001;//py::cast(B_MEDIA_FILE_REPLACE_MODE); +m.attr("B_MEDIA_FILE_NO_READ_AHEAD") = 0x00000002;//py::cast(B_MEDIA_FILE_NO_READ_AHEAD); +m.attr("B_MEDIA_FILE_UNBUFFERED") = 0x00000006;//py::cast(B_MEDIA_FILE_UNBUFFERED); +m.attr("B_MEDIA_FILE_BIG_BUFFERS") = 0x00000008;//py::cast(B_MEDIA_FILE_BIG_BUFFERS); + +//m.attr("MediaExtractor") = py::cast(MediaExtractor); + +//m.attr("MediaStreamer") = py::cast(MediaStreamer); + +//m.attr("MediaWriter") = py::cast(MediaWriter); + +//m.attr("_AddonManager") = py::cast(_AddonManager); +//TODO gestre dati void +py::class_(m, "BMediaFile") +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("source")) +.def(py::init(), "", py::arg("ref"), py::arg("flags")) +.def(py::init(), "", py::arg("source"), py::arg("flags")) +.def(py::init(), "", py::arg("ref"), py::arg("mfi"), py::arg("flags")=0) +.def(py::init(), "", py::arg("destination"), py::arg("mfi"), py::arg("flags")=0) +.def(py::init(), "", py::arg("mfi"), py::arg("flags")=0) +.def(py::init(), "", py::arg("url")) +.def(py::init(), "", py::arg("url"), py::arg("flags")) +.def(py::init(), "", py::arg("destination"), py::arg("mfi"), py::arg("flags")=0) +.def("SetTo", py::overload_cast(&BMediaFile::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BMediaFile::SetTo), "", py::arg("destination")) +.def("SetTo", py::overload_cast(&BMediaFile::SetTo), "", py::arg("url")) +.def("InitCheck", &BMediaFile::InitCheck, "") +.def("GetFileFormatInfo", &BMediaFile::GetFileFormatInfo, "", py::arg("mfi")) +.def("GetMetaData", &BMediaFile::GetMetaData, "", py::arg("_data")) +.def("Copyright", &BMediaFile::Copyright, "") +.def("CountTracks", &BMediaFile::CountTracks, "") +.def("TrackAt", &BMediaFile::TrackAt, "", py::arg("index")) +.def("ReleaseTrack", &BMediaFile::ReleaseTrack, "", py::arg("track")) +.def("ReleaseAllTracks", &BMediaFile::ReleaseAllTracks, "") +.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("mci"), py::arg("flags")=0) +.def("CreateTrack", py::overload_cast(&BMediaFile::CreateTrack), "", py::arg("mf"), py::arg("flags")=0) +.def("AddCopyright", &BMediaFile::AddCopyright, "", py::arg("data")) +.def("AddChunk", &BMediaFile::AddChunk, "", py::arg("type"), py::arg("data"), py::arg("size")) +.def("CommitHeader", &BMediaFile::CommitHeader, "") +.def("CloseFile", &BMediaFile::CloseFile, "") +//.def("GetParameterWeb", &BMediaFile::GetParameterWeb, "", py::arg("outWeb")) +.def("GetParameterWeb", [](BMediaFile &self) { + BParameterWeb* web = nullptr; + status_t status = self.GetParameterWeb(&web); + return std::make_tuple(status, web); + },"") +.def("GetParameterValue", &BMediaFile::GetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("SetParameterValue", &BMediaFile::SetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("GetParameterView", &BMediaFile::GetParameterView, "") +.def("Perform", &BMediaFile::Perform, "", py::arg("selector"), py::arg("data")) +; + + +} diff --git a/bindings/media/MediaFiles.cpp b/bindings/media/MediaFiles.cpp new file mode 100644 index 0000000..2d77348 --- /dev/null +++ b/bindings/media/MediaFiles.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaFiles, m) +{ +py::class_(m, "BMediaFiles") +.def(py::init(), "") +.def("RewindTypes", &BMediaFiles::RewindTypes, "") +.def("GetNextType", &BMediaFiles::GetNextType, "", py::arg("_type")) +.def("RewindRefs", &BMediaFiles::RewindRefs, "", py::arg("type")) +.def("GetNextRef", &BMediaFiles::GetNextRef, "", py::arg("_type"), py::arg("_ref")=NULL) +.def("GetRefFor", &BMediaFiles::GetRefFor, "", py::arg("type"), py::arg("item"), py::arg("_ref")) +.def("SetRefFor", &BMediaFiles::SetRefFor, "", py::arg("type"), py::arg("item"), py::arg("ref")) +.def("GetAudioGainFor", &BMediaFiles::GetAudioGainFor, "", py::arg("type"), py::arg("item"), py::arg("_gain")) +.def("SetAudioGainFor", &BMediaFiles::SetAudioGainFor, "", py::arg("type"), py::arg("item"), py::arg("gain")) +.def("RemoveRefFor", &BMediaFiles::RemoveRefFor, "", py::arg("type"), py::arg("item"), py::arg("ref")) +.def("RemoveItem", &BMediaFiles::RemoveItem, "", py::arg("type"), py::arg("item")) +//.def_readwrite("B_SOUNDS", &BMediaFiles::B_SOUNDS, "") //from media kit source const char BMediaFiles::B_SOUNDS[] = "Sounds"; +.def_static("B_SOUNDS", [](){return "Sounds";},"") +; + + +} diff --git a/bindings/media/MediaFormats.cpp b/bindings/media/MediaFormats.cpp new file mode 100644 index 0000000..092dc0a --- /dev/null +++ b/bindings/media/MediaFormats.cpp @@ -0,0 +1,321 @@ +#include +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; +media_beos_description& get_beos(media_format_description& desc) { + return desc.u.beos; +} +media_quicktime_description& get_quicktime(media_format_description& desc) { + return desc.u.quicktime; +} +media_avi_description& get_avi(media_format_description& desc) { + return desc.u.avi; +} +media_asf_description& get_asf(media_format_description& desc) { + return desc.u.asf; +} +media_mpeg_description& get_mpeg(media_format_description& desc) { + return desc.u.mpeg; +} +media_wav_description& get_wav(media_format_description& desc) { + return desc.u.wav; +} +media_aiff_description& get_aiff(media_format_description& desc) { + return desc.u.aiff; +} +media_misc_description& get_misc(media_format_description& desc) { + return desc.u.misc; +} +media_avr_description& get_avr(media_format_description& desc) { + return desc.u.avr; +} +//******************* +void set_beos(media_format_description& desc, const media_beos_description& value) { + desc.u.beos = value; +} +void set_quicktime(media_format_description& desc, const media_quicktime_description& value) { + desc.u.quicktime = value; +} +void set_avi(media_format_description& desc, const media_avi_description& value) { + desc.u.avi = value; +} +void set_asf(media_format_description& desc, const media_asf_description& value) { + desc.u.asf = value; +} +void set_mpeg(media_format_description& desc, const media_mpeg_description& value) { + desc.u.mpeg = value; +} +void set_wav(media_format_description& desc, const media_wav_description& value) { + desc.u.wav = value; +} +void set_aiff(media_format_description& desc, const media_aiff_description& value) { + desc.u.aiff = value; +} +void set_misc(media_format_description& desc, const media_misc_description& value) { + desc.u.misc = value; +} +void set_avr(media_format_description& desc, const media_avr_description& value) { + desc.u.avr = value; +} +//******** +std::string get_media_codec_info_pretty_name(const media_codec_info& self) { + return std::string(self.pretty_name); +} + +void set_media_codec_info_pretty_name(media_codec_info& self, const std::string& pretty_name) { + std::strncpy(self.pretty_name, pretty_name.c_str(), 95); + self.pretty_name[95] = '\0'; +} +std::string get_media_codec_info_short_name(const media_codec_info& self) { + return std::string(self.short_name); +} + +void set_media_codec_info_short_name(media_codec_info& self, const std::string& short_name) { + std::strncpy(self.short_name, short_name.c_str(), 31); + self.short_name[31] = '\0'; +} + +PYBIND11_MODULE(MediaFormats, m) +{ +py::enum_(m, "media_file_accept_format_flags", "") +.value("B_MEDIA_REJECT_WILDCARDS", media_file_accept_format_flags::B_MEDIA_REJECT_WILDCARDS, "") +.export_values(); + +py::enum_(m, "beos_format", "") +.value("B_BEOS_FORMAT_RAW_AUDIO", beos_format::B_BEOS_FORMAT_RAW_AUDIO, "") +.value("B_BEOS_FORMAT_RAW_VIDEO", beos_format::B_BEOS_FORMAT_RAW_VIDEO, "") +.export_values(); + +py::enum_(m, "mpeg_id", "") +.value("B_MPEG_ANY", mpeg_id::B_MPEG_ANY, "") +.value("B_MPEG_1_AUDIO_LAYER_1", mpeg_id::B_MPEG_1_AUDIO_LAYER_1, "") +.value("B_MPEG_1_AUDIO_LAYER_2", mpeg_id::B_MPEG_1_AUDIO_LAYER_2, "") +.value("B_MPEG_1_AUDIO_LAYER_3", mpeg_id::B_MPEG_1_AUDIO_LAYER_3, "") +.value("B_MPEG_1_VIDEO", mpeg_id::B_MPEG_1_VIDEO, "") +.value("B_MPEG_2_AUDIO_LAYER_1", mpeg_id::B_MPEG_2_AUDIO_LAYER_1, "") +.value("B_MPEG_2_AUDIO_LAYER_2", mpeg_id::B_MPEG_2_AUDIO_LAYER_2, "") +.value("B_MPEG_2_AUDIO_LAYER_3", mpeg_id::B_MPEG_2_AUDIO_LAYER_3, "") +.value("B_MPEG_2_VIDEO", mpeg_id::B_MPEG_2_VIDEO, "") +.value("B_MPEG_2_5_AUDIO_LAYER_1", mpeg_id::B_MPEG_2_5_AUDIO_LAYER_1, "") +.value("B_MPEG_2_5_AUDIO_LAYER_2", mpeg_id::B_MPEG_2_5_AUDIO_LAYER_2, "") +.value("B_MPEG_2_5_AUDIO_LAYER_3", mpeg_id::B_MPEG_2_5_AUDIO_LAYER_3, "") +.export_values(); + +py::class_(m, "media_codec_info") +//.def_readwrite("pretty_name", &media_codec_info::pretty_name, "") +.def_property("pretty_name", &get_media_codec_info_pretty_name, &set_media_codec_info_pretty_name, "") +//.def_readwrite("short_name", &media_codec_info::short_name, "") +.def_property("short_name", &get_media_codec_info_short_name, &set_media_codec_info_short_name, "") +.def_readwrite("id", &media_codec_info::id, "") +.def_readwrite("sub_id", &media_codec_info::sub_id, "") +//.def_readwrite("pad", &media_codec_info::pad, "") +.def_property("pad", + [](const media_codec_info &info) { + py::array_t result(63); + std::memcpy(result.mutable_data(), &info.pad, sizeof(info.pad)); + return result; + }, + [](media_codec_info &info, py::array_t value) { + if (value.size() != 63) { + throw std::runtime_error("Array must have size 63"); + } + std::memcpy(&info.pad, value.data(), sizeof(info.pad)); + },"") +; + +py::class_(m, "GUID") +//.def_readwrite("data", &GUID::data, "") +.def_property("data", + [](const GUID &guid) { + py::array_t result(16); + std::memcpy(result.mutable_data(), &guid.data, sizeof(guid.data)); + return result; + }, + [](GUID &guid, py::array_t value) { + if (value.size() != 16) { + throw std::runtime_error("Array must have size 16"); + } + std::memcpy(&guid.data, value.data(), sizeof(guid.data)); + },"") +; + +py::class_(m, "media_beos_description") +.def_readwrite("format", &media_beos_description::format, "") +; + +py::class_(m, "media_quicktime_description") +.def_readwrite("codec", &media_quicktime_description::codec, "") +.def_readwrite("vendor", &media_quicktime_description::vendor, "") +; + +py::class_(m, "media_avi_description") +.def_readwrite("codec", &media_avi_description::codec, "") +; + +py::class_(m, "media_avr_description") +.def_readwrite("id", &media_avr_description::id, "") +; + +py::class_(m, "media_asf_description") +.def_readwrite("guid", &media_asf_description::guid, "") +; + +py::class_(m, "media_mpeg_description") +.def_readwrite("id", &media_mpeg_description::id, "") +; + +py::class_(m, "media_wav_description") +.def_readwrite("codec", &media_wav_description::codec, "") +; + +py::class_(m, "media_aiff_description") +.def_readwrite("codec", &media_aiff_description::codec, "") +; + +py::class_(m, "media_misc_description") +.def_readwrite("file_format", &media_misc_description::file_format, "") +.def_readwrite("codec", &media_misc_description::codec, "") +; + + +py::class_(m, "media_format_description") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_format_description::operator=, "", py::arg("other")) +.def_readwrite("family", &media_format_description::family, "") +//.def_readwrite("_reserved_", &media_format_description::_reserved_, "") +.def_property( + "_reserved_", + [](const media_format_description &desc) { + py::array_t result(3); + std::memcpy(result.mutable_data(), &desc._reserved_, sizeof(desc._reserved_)); + return result; + }, + [](media_format_description &desc, py::array_t value) { + if (value.size() != 3) { + throw std::runtime_error("Array must have size 3"); + } + std::memcpy(&desc._reserved_, value.data(), sizeof(desc._reserved_)); + },"") +.def_readwrite("u", &media_format_description::u, "") +.def_property("beos", &get_beos, &set_beos) +.def_property("quicktime", &get_quicktime, &set_quicktime) +.def_property("avi", &get_avi, &set_avi) +.def_property("asf", &get_asf, &set_asf) +.def_property("mpeg", &get_mpeg, &set_mpeg) +.def_property("wav", &get_wav, &set_wav) +.def_property("aiff", &get_aiff, &set_aiff) +.def_property("misc", &get_misc, &set_misc) +.def_property("avr", &get_avr, &set_avr) +.def_property( + "u_reserved_", + [](const media_format_description &desc) { + py::array_t result(12); + std::memcpy(result.mutable_data(), &desc.u._reserved_, sizeof(desc.u._reserved_)); + return result; + }, + [](media_format_description &desc, py::array_t value) { + if (value.size() != 12) { + throw std::runtime_error("Array must have size 12"); + } + std::memcpy(&desc.u._reserved_, value.data(), sizeof(desc.u._reserved_)); + },"") +; + +py::class_(m, "BMediaFormats") +.def(py::init(), "") +.def("InitCheck", &BMediaFormats::InitCheck, "") +.def("MakeFormatFor", py::overload_cast(&BMediaFormats::MakeFormatFor), "", py::arg("descriptions"), py::arg("descriptionCount"), py::arg("_inOutFormat"), py::arg("flags")=0, py::arg("_reserved")=0) +.def("GetFormatFor", &BMediaFormats::GetFormatFor, "", py::arg("description"), py::arg("_outFormat")) +.def("GetCodeFor", &BMediaFormats::GetCodeFor, "", py::arg("format"), py::arg("family"), py::arg("_outDescription")) +.def("RewindFormats", &BMediaFormats::RewindFormats, "") +.def("GetNextFormat", &BMediaFormats::GetNextFormat, "", py::arg("_outFormat"), py::arg("_outDescription")) +.def("Lock", &BMediaFormats::Lock, "") +.def("Unlock", &BMediaFormats::Unlock, "") +.def_static("GetBeOSFormatFor", &BMediaFormats::GetBeOSFormatFor, "", py::arg("fourcc"), py::arg("_outFormat"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def_static("GetAVIFormatFor", &BMediaFormats::GetAVIFormatFor, "", py::arg("fourcc"), py::arg("_outFormat"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def_static("GetQuicktimeFormatFor", &BMediaFormats::GetQuicktimeFormatFor, "", py::arg("vendor"), py::arg("fourcc"), py::arg("_outFormat"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def("MakeFormatFor", py::overload_cast(&BMediaFormats::MakeFormatFor), "", py::arg("description"), py::arg("inFormat"), py::arg("_outFormat")) +; + +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), + R"ipc_Qu8mg5v7( + /*! \brief Use this to iterate through the available encoders for a given file +format. +\param cookie A pointer to a preallocated cookie, which you need +to initialize to \c 0 before calling this function +the first time. +\param fileFormat A pointer to a valid media_file_format structure +as can be obtained through get_next_file_format(). +\param inputFormat This is the type of data given to the encoder. +\param _outputFormat This is the type of data the encoder will output. +\param _codecInfo Pointer to a preallocated media_codec_info structure, +information about the encoder is placed there. +\return +- \c B_OK: Everything went fine. +- \c B_BAD_INDEX: There are no more encoders. +*/ + )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("fileFormat"), py::arg("inputFormat"), py::arg("_outputFormat"), py::arg("_codecInfo")); + +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), + R"ipc_Qu8mg5v7( + /*! \brief Use this to iterate through the available encoders with +restrictions to the input and output media_format while the +encoders can specialize wildcards in the media_formats. +\param cookie A pointer to a preallocated cookie, which you need +to initialize to \c 0 before calling this function +the first time. +\param fileFormat A pointer to a valid media_file_format structure +as can be obtained through get_next_file_format(). +You can pass \c NULL if you don't care. +\param inputFormat This is the type of data given to the encoder, +wildcards are accepted. +\param outputFormat This is the type of data you want the encoder to +output. Wildcards are accepted. +\param _codecInfo Pointer to a preallocated media_codec_info structure, +information about the encoder is placed there. +\param _acceptedInputFormat This is the type of data that the encoder will +accept as input. Wildcards in \a inFormat will be +specialized here. +\param _acceptedOutputFormat This is the type of data that the encoder will +output. Wildcards in \a _outFormat will be specialized +here. +\return +- \c B_OK: Everything went fine. +- \c B_BAD_INDEX: There are no more encoders. +*/ + )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("fileFormat"), py::arg("inputFormat"), py::arg("outputFormat"), py::arg("_codecInfo"), py::arg("_acceptedInputFormat"), py::arg("_acceptedOutputFormat")); + +m.def("get_next_encoder", py::overload_cast(&get_next_encoder), + R"ipc_Qu8mg5v7( + /*! \brief Iterate over the all the available encoders without media_format +restrictions. +\param cookie A pointer to a preallocated cookie, which you need +to initialize to \c 0 before calling this function +the first time. +\param _codecInfo Pointer to a preallocated media_codec_info structure, +information about the encoder is placed there. +\return +- \c B_OK: Everything went fine. +- \c B_BAD_INDEX: There are no more encoders. +*/ + )ipc_Qu8mg5v7", py::arg("cookie"), py::arg("_codecInfo")); + +m.def("does_file_accept_format", &does_file_accept_format, "", py::arg("fileFormat"), py::arg("format"), py::arg("flags")=0); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +} diff --git a/bindings/media/MediaNode.cpp b/bindings/media/MediaNode.cpp new file mode 100644 index 0000000..559c824 --- /dev/null +++ b/bindings/media/MediaNode.cpp @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +std::string get_live_node_info_name(const live_node_info& self) { + return std::string(self.name); +} + +void set_live_node_info_name(live_node_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +std::string get_media_output_name(const media_output& self) { + return std::string(self.name); +} + +void set_media_output_name(media_output& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +std::string get_media_input_name(const media_input& self) { + return std::string(self.name); +} + +void set_media_input_name(media_input& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), B_MEDIA_NAME_LENGTH - 1); + self.name[B_MEDIA_NAME_LENGTH - 1] = '\0'; +} + +PYBIND11_MODULE(MediaNode, m) +{ +//m.attr("TimeSourceObject") = py::cast(TimeSourceObject); + +//m.attr("SystemTimeSourceObject") = py::cast(SystemTimeSourceObject); + +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_(m, "media_node") +.def(py::init(), "") +.def_readwrite("node", &media_node::node, "") +.def_readwrite("port", &media_node::port, "") +.def_readwrite("kind", &media_node::kind, "") +//.def_readwrite("null", &media_node::null, "") +; + +py::class_(m, "media_input") +.def(py::init(), "") +.def_readwrite("node", &media_input::node, "") +.def_readwrite("source", &media_input::source, "") +.def_readwrite("destination", &media_input::destination, "") +.def_readwrite("format", &media_input::format, "") +//.def_readwrite("name", &media_input::name, "") +.def_property("name", &get_media_input_name, &set_media_input_name, "") +; + +py::class_(m, "media_output") +.def(py::init(), "") +.def_readwrite("node", &media_output::node, "") +.def_readwrite("source", &media_output::source, "") +.def_readwrite("destination", &media_output::destination, "") +.def_readwrite("format", &media_output::format, "") +//.def_readwrite("name", &media_output::name, "") +.def_property("name", &get_media_output_name, &set_media_output_name, "") +; + +py::class_(m, "live_node_info") +.def(py::init(), "") +.def_readwrite("node", &live_node_info::node, "") +.def_readwrite("hint_point", &live_node_info::hint_point, "") +//.def_readwrite("name", &live_node_info::name, "") +.def_property("name", &get_live_node_info_name, &set_live_node_info_name, "") +; + +py::class_(m, "media_request_info") +.def_readwrite("what", &media_request_info::what, "") +.def_readwrite("change_tag", &media_request_info::change_tag, "") +.def_readwrite("status", &media_request_info::status, "") +.def_readwrite("cookie", &media_request_info::cookie, "") +.def_readwrite("user_data", &media_request_info::user_data, "") +.def_readwrite("source", &media_request_info::source, "") +.def_readwrite("destination", &media_request_info::destination, "") +.def_readwrite("format", &media_request_info::format, "") +//.def_readwrite("_reserved_", &media_request_info::_reserved_, "") +.def_property( + "_reserved_", + [](const media_request_info &info) { + py::array_t result(32); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](media_request_info &info, py::array_t value) { + if (value.size() != 32) { + throw std::runtime_error("Array must have size 32"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") +; + +py::class_(m, "media_node_attribute") +.def_readwrite("what", &media_node_attribute::what, "") +.def_readwrite("flags", &media_node_attribute::flags, "") +.def_readwrite("data", &media_node_attribute::data, "") +; + +py::enum_(m, "run_mode", "") +.value("B_OFFLINE", BMediaNode::run_mode::B_OFFLINE, "") +.value("B_DECREASE_PRECISION", BMediaNode::run_mode::B_DECREASE_PRECISION, "") +.value("B_INCREASE_LATENCY", BMediaNode::run_mode::B_INCREASE_LATENCY, "") +.value("B_DROP_DATA", BMediaNode::run_mode::B_DROP_DATA, "") +.value("B_RECORDING", BMediaNode::run_mode::B_RECORDING, "") +.export_values(); + +py::class_>(m, "BMediaNode") +.def("Acquire", &BMediaNode::Acquire, "") +.def("Release", &BMediaNode::Release, "") +.def("Name", &BMediaNode::Name, "") +.def("ID", &BMediaNode::ID, "") +.def("Kinds", &BMediaNode::Kinds, "") +.def("Node", &BMediaNode::Node, "") +.def("RunMode", &BMediaNode::RunMode, "") +.def("TimeSource", &BMediaNode::TimeSource, "") +.def("ControlPort", &BMediaNode::ControlPort, "") +.def("AddOn", &BMediaNode::AddOn, "", py::arg("internalID")) +.def("HandleMessage", &BMediaNode::HandleMessage, "", py::arg("message"), py::arg("data"), py::arg("size")) +.def("HandleBadMessage", &BMediaNode::HandleBadMessage, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +.def("AddNodeKind", &BMediaNode::AddNodeKind, "", py::arg("kind")) +//.def("operatornew", py::overload_cast(&BMediaNode::operatornew), "", py::arg("size")) +//.def("operatornew", py::overload_cast(&BMediaNode::operatornew), "", py::arg("size"), py::arg("&")) +//.def("operatordelete", py::overload_cast(&BMediaNode::operatordelete), "", py::arg("ptr")) +//.def("operatordelete", py::overload_cast(&BMediaNode::operatordelete), "", py::arg("ptr"), py::arg("&")) +.def("GetNodeAttributes", &BMediaNode::GetNodeAttributes, "", py::arg("_attributes"), py::arg("inMaxCount")) +.def("AddTimer", &BMediaNode::AddTimer, "", py::arg("atPerformanceTime"), py::arg("cookie")) +; + + +} diff --git a/bindings/media/MediaRecorder.cpp b/bindings/media/MediaRecorder.cpp new file mode 100644 index 0000000..cbc86cc --- /dev/null +++ b/bindings/media/MediaRecorder.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_MODULE(MediaRecorder, m) +{ +py::enum_(m, "notification", "") +.value("B_WILL_START", BMediaRecorder::notification::B_WILL_START, "") +.value("B_WILL_STOP", BMediaRecorder::notification::B_WILL_STOP, "") +.value("B_WILL_SEEK", BMediaRecorder::notification::B_WILL_SEEK, "") +.value("B_WILL_TIMEWARP", BMediaRecorder::notification::B_WILL_TIMEWARP, "") +.export_values(); + +py::class_(m, "BMediaRecorder") +.def(py::init(), "", py::arg("name"), py::arg("type")=B_MEDIA_UNKNOWN_TYPE) +.def("InitCheck", &BMediaRecorder::InitCheck, "") +.def("SetHooks", &BMediaRecorder::SetHooks, "", py::arg("recordFunc")=NULL, py::arg("notifyFunc")=NULL, py::arg("cookie")=NULL) +.def("SetAcceptedFormat", &BMediaRecorder::SetAcceptedFormat, "", py::arg("format")) +.def("AcceptedFormat", &BMediaRecorder::AcceptedFormat, "") +.def("Start", &BMediaRecorder::Start, "", py::arg("force")=false) +.def("Stop", &BMediaRecorder::Stop, "", py::arg("force")=false) +.def("Connect", py::overload_cast(&BMediaRecorder::Connect), "", py::arg("format")) +.def("Connect", py::overload_cast(&BMediaRecorder::Connect), "", py::arg("dormantInfo"), py::arg("format")) +.def("Connect", py::overload_cast(&BMediaRecorder::Connect), "", py::arg("node"), py::arg("output")=NULL, py::arg("format")=NULL) +.def("Disconnect", &BMediaRecorder::Disconnect, "") +.def("IsConnected", &BMediaRecorder::IsConnected, "") +.def("IsRunning", &BMediaRecorder::IsRunning, "") +.def("Format", &BMediaRecorder::Format, "") +; + + +} diff --git a/bindings/media/MediaRoster.cpp b/bindings/media/MediaRoster.cpp new file mode 100644 index 0000000..4ea8b6b --- /dev/null +++ b/bindings/media/MediaRoster.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(BMediaRoster); + +PYBIND11_MODULE(MediaRoster, m) +{ +py::enum_(m, "bus_type", "//! The BMediaRoster is the main API to the Media Kit.") +.value("B_ISA_BUS", bus_type::B_ISA_BUS, "") +.value("B_PCI_BUS", bus_type::B_PCI_BUS, "") +.value("B_PCMCIA_BUS", bus_type::B_PCMCIA_BUS, "") +.value("B_UNKNOWN_BUS", bus_type::B_UNKNOWN_BUS, "") +.export_values(); + +//m.attr("DefaultDeleter") = py::cast(DefaultDeleter); + +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +py::class_(m, "BMediaRoster") +.def_static("Roster", &BMediaRoster::Roster, "", py::arg("_error")=NULL) +.def_static("CurrentRoster", &BMediaRoster::CurrentRoster, "") +.def_static("IsRunning", &BMediaRoster::IsRunning, "") +.def("GetVideoInput", &BMediaRoster::GetVideoInput, "", py::arg("_node")) +.def("GetAudioInput", &BMediaRoster::GetAudioInput, "", py::arg("_node")) +.def("GetVideoOutput", &BMediaRoster::GetVideoOutput, "", py::arg("_node")) +.def("GetAudioMixer", &BMediaRoster::GetAudioMixer, "", py::arg("_node")) +.def("GetAudioOutput", py::overload_cast(&BMediaRoster::GetAudioOutput), "", py::arg("_node")) +.def("GetAudioOutput", py::overload_cast(&BMediaRoster::GetAudioOutput), "", py::arg("_node"), py::arg("_inputId"), py::arg("_inputName")) +.def("GetTimeSource", &BMediaRoster::GetTimeSource, "", py::arg("_node")) +.def("SetVideoInput", py::overload_cast(&BMediaRoster::SetVideoInput), "", py::arg("producer")) +.def("SetVideoInput", py::overload_cast(&BMediaRoster::SetVideoInput), "", py::arg("producer")) +.def("SetAudioInput", py::overload_cast(&BMediaRoster::SetAudioInput), "", py::arg("producer")) +.def("SetAudioInput", py::overload_cast(&BMediaRoster::SetAudioInput), "", py::arg("producer")) +.def("SetVideoOutput", py::overload_cast(&BMediaRoster::SetVideoOutput), "", py::arg("consumer")) +.def("SetVideoOutput", py::overload_cast(&BMediaRoster::SetVideoOutput), "", py::arg("consumer")) +.def("SetAudioOutput", py::overload_cast(&BMediaRoster::SetAudioOutput), "", py::arg("consumer")) +.def("SetAudioOutput", py::overload_cast(&BMediaRoster::SetAudioOutput), "", py::arg("inputToOutput")) +.def("SetAudioOutput", py::overload_cast(&BMediaRoster::SetAudioOutput), "", py::arg("consumer")) +.def("GetNodeFor", &BMediaRoster::GetNodeFor, "", py::arg("node"), py::arg("clone")) +.def("GetSystemTimeSource", &BMediaRoster::GetSystemTimeSource, "", py::arg("clone")) +.def("ReleaseNode", &BMediaRoster::ReleaseNode, "", py::arg("node")) +.def("MakeTimeSourceFor", &BMediaRoster::MakeTimeSourceFor, "", py::arg("for_node")) +.def("Connect", py::overload_cast(&BMediaRoster::Connect), "", py::arg("from"), py::arg("to"), py::arg("_inOutFormat"), py::arg("_output"), py::arg("_input")) +.def("Connect", py::overload_cast(&BMediaRoster::Connect), "", py::arg("from"), py::arg("to"), py::arg("_inOutFormat"), py::arg("_output"), py::arg("_input"), py::arg("flags"), py::arg("_reserved")=NULL) +.def("Disconnect", py::overload_cast(&BMediaRoster::Disconnect), "", py::arg("sourceNode"), py::arg("source"), py::arg("destinationNode"), py::arg("destination")) +.def("Disconnect", py::overload_cast(&BMediaRoster::Disconnect), "", py::arg("output"), py::arg("input")) +.def("StartNode", &BMediaRoster::StartNode, "", py::arg("node"), py::arg("atPerformanceTime")) +.def("StopNode", &BMediaRoster::StopNode, "", py::arg("node"), py::arg("atPerformanceTime"), py::arg("immediate")=false) +.def("SeekNode", &BMediaRoster::SeekNode, "", py::arg("node"), py::arg("toMediaTime"), py::arg("atPerformanceTime")=0) +.def("StartTimeSource", &BMediaRoster::StartTimeSource, "", py::arg("node"), py::arg("atRealTime")) +.def("StopTimeSource", &BMediaRoster::StopTimeSource, "", py::arg("node"), py::arg("atRealTime"), py::arg("immediate")=false) +.def("SeekTimeSource", &BMediaRoster::SeekTimeSource, "", py::arg("node"), py::arg("toPerformanceTime"), py::arg("atRealTime")) +.def("SyncToNode", &BMediaRoster::SyncToNode, "", py::arg("node"), py::arg("atTime"), py::arg("timeout")=B_INFINITE_TIMEOUT) +.def("SetRunModeNode", &BMediaRoster::SetRunModeNode, "", py::arg("node"), py::arg("mode")) +.def("PrerollNode", &BMediaRoster::PrerollNode, "", py::arg("node")) +.def("RollNode", &BMediaRoster::RollNode, "", py::arg("node"), py::arg("startPerformance"), py::arg("stopPerformance"), py::arg("atMediaTime")=- B_INFINITE_TIMEOUT) +.def("SetProducerRunModeDelay", &BMediaRoster::SetProducerRunModeDelay, "", py::arg("node"), py::arg("delay"), py::arg("mode")=BMediaNode::run_mode::B_RECORDING) +.def("SetProducerRate", &BMediaRoster::SetProducerRate, "", py::arg("producer"), py::arg("numer"), py::arg("denom")) +.def("GetLiveNodeInfo", &BMediaRoster::GetLiveNodeInfo, "", py::arg("node"), py::arg("_liveInfo")) +.def("GetLiveNodes", &BMediaRoster::GetLiveNodes, "", py::arg("_liveNodes"), py::arg("inOutTotalCount"), py::arg("hasInput")=NULL, py::arg("hasOutput")=NULL, py::arg("name")=NULL, py::arg("nodeKinds")=0) +.def("GetFreeInputsFor", &BMediaRoster::GetFreeInputsFor, "", py::arg("node"), py::arg("_freeInputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount"), py::arg("filterType")=B_MEDIA_UNKNOWN_TYPE) +.def("GetConnectedInputsFor", &BMediaRoster::GetConnectedInputsFor, "", py::arg("node"), py::arg("_activeInputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetAllInputsFor", &BMediaRoster::GetAllInputsFor, "", py::arg("node"), py::arg("_inputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetFreeOutputsFor", &BMediaRoster::GetFreeOutputsFor, "", py::arg("node"), py::arg("_freeOutputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount"), py::arg("filterType")=B_MEDIA_UNKNOWN_TYPE) +.def("GetConnectedOutputsFor", &BMediaRoster::GetConnectedOutputsFor, "", py::arg("node"), py::arg("_activeOutputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetAllOutputsFor", &BMediaRoster::GetAllOutputsFor, "", py::arg("node"), py::arg("_outputsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("notificationType")) +.def("StartWatching", py::overload_cast(&BMediaRoster::StartWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("notificationType")) +.def("StopWatching", py::overload_cast(&BMediaRoster::StopWatching), "", py::arg("target"), py::arg("node"), py::arg("notificationType")) +.def("RegisterNode", &BMediaRoster::RegisterNode, "", py::arg("node")) +.def("UnregisterNode", &BMediaRoster::UnregisterNode, "", py::arg("node")) +.def("SetTimeSourceFor", &BMediaRoster::SetTimeSourceFor, "", py::arg("node"), py::arg("timeSource")) +//.def("GetParameterWebFor", &BMediaRoster::GetParameterWebFor, "", py::arg("node"), py::arg("_web")) +.def("GetParameterWebFor",[](BMediaRoster& self, const media_node& node) { + BParameterWeb* web = nullptr; + status_t status =self.GetParameterWebFor(node, &web); + return std::make_tuple(status, web); +}, "", py::arg("node")) +.def("StartControlPanel", &BMediaRoster::StartControlPanel, "", py::arg("node"), py::arg("_messenger")=NULL) +.def("GetDormantNodes", &BMediaRoster::GetDormantNodes, "", py::arg("_info"), py::arg("_inOutCount"), py::arg("_hasInput")=NULL, py::arg("_hasOutput")=NULL, py::arg("name")=NULL, py::arg("requireKinds")=0, py::arg("denyKinds")=0) +.def("InstantiateDormantNode", py::overload_cast(&BMediaRoster::InstantiateDormantNode), "", py::arg("info"), py::arg("_node"), py::arg("flags")) +.def("InstantiateDormantNode", py::overload_cast(&BMediaRoster::InstantiateDormantNode), "", py::arg("info"), py::arg("_node")) +.def("GetDormantNodeFor", &BMediaRoster::GetDormantNodeFor, "", py::arg("node"), py::arg("_info")) +.def("GetDormantFlavorInfoFor", &BMediaRoster::GetDormantFlavorInfoFor, "", py::arg("info"), py::arg("_flavor")) +.def("GetLatencyFor", &BMediaRoster::GetLatencyFor, "", py::arg("producer"), py::arg("_latency")) +.def("GetInitialLatencyFor", &BMediaRoster::GetInitialLatencyFor, "", py::arg("producer"), py::arg("_latency"), py::arg("_flags")=NULL) +.def("GetStartLatencyFor", &BMediaRoster::GetStartLatencyFor, "", py::arg("timeSource"), py::arg("_latency")) +.def("GetFileFormatsFor", &BMediaRoster::GetFileFormatsFor, "", py::arg("fileInterface"), py::arg("_formatsBuffer"), py::arg("_inOutNumInfos")) +.def("SetRefFor", &BMediaRoster::SetRefFor, "", py::arg("fileInterface"), py::arg("file"), py::arg("createAndTruncate"), py::arg("_length")) +.def("GetRefFor", &BMediaRoster::GetRefFor, "", py::arg("node"), py::arg("_ref"), py::arg("mimeType")=NULL) +.def("SniffRefFor", &BMediaRoster::SniffRefFor, "", py::arg("fileInterface"), py::arg("ref"), py::arg("_mimeType"), py::arg("_capability")) +.def("SniffRef", &BMediaRoster::SniffRef, "", py::arg("ref"), py::arg("requireNodeKinds"), py::arg("_node"), py::arg("_mimeType")=NULL) +.def("GetDormantNodeForType", &BMediaRoster::GetDormantNodeForType, "", py::arg("type"), py::arg("requireNodeKinds"), py::arg("_info")) +.def("GetReadFileFormatsFor", &BMediaRoster::GetReadFileFormatsFor, "", py::arg("node"), py::arg("_readFormatsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetWriteFileFormatsFor", &BMediaRoster::GetWriteFileFormatsFor, "", py::arg("node"), py::arg("_writeFormatsBuffer"), py::arg("bufferCapacity"), py::arg("_foundCount")) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("output"), py::arg("_inOutFormat"), py::arg("flags")=0) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("input"), py::arg("_inOutFormat"), py::arg("flags")=0) +.def("GetFormatFor", py::overload_cast(&BMediaRoster::GetFormatFor), "", py::arg("node"), py::arg("_inOutFormat"), py::arg("quality")=B_MEDIA_ANY_QUALITY) +.def("GetNodeAttributesFor", &BMediaRoster::GetNodeAttributesFor, "", py::arg("node"), py::arg("outArray"), py::arg("inMaxCount")) +.def("NodeIDFor", &BMediaRoster::NodeIDFor, "", py::arg("sourceOrDestinationPort")) +.def("GetInstancesFor", &BMediaRoster::GetInstancesFor, "", py::arg("addon"), py::arg("flavor"), py::arg("_id"), py::arg("_inOutCount")=NULL) +.def("AudioBufferSizeFor", &BMediaRoster::AudioBufferSizeFor, "", py::arg("channelCount"), py::arg("sampleFormat"), py::arg("frameRate"), py::arg("busType")=B_UNKNOWN_BUS) +.def_static("MediaFlags", &BMediaRoster::MediaFlags, "", py::arg("cap"), py::arg("buffer"), py::arg("maxSize")) +.def("MessageReceived", &BMediaRoster::MessageReceived, "", py::arg("message")) +.def("QuitRequested", &BMediaRoster::QuitRequested, "") +.def("ResolveSpecifier", &BMediaRoster::ResolveSpecifier, "", py::arg("message"), py::arg("index"), py::arg("specifier"), py::arg("form"), py::arg("property")) +.def("GetSupportedSuites", &BMediaRoster::GetSupportedSuites, "", py::arg("data")) +; + + +} diff --git a/bindings/media/MediaTheme.cpp b/bindings/media/MediaTheme.cpp new file mode 100644 index 0000000..9fc15c7 --- /dev/null +++ b/bindings/media/MediaTheme.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaTheme, m) +{ +py::enum_(m, "bg_kind", "") +.value("B_GENERAL_BG", BMediaTheme::bg_kind::B_GENERAL_BG, "") +.value("B_SETTINGS_BG", BMediaTheme::bg_kind::B_SETTINGS_BG, "") +.value("B_PRESENTATION_BG", BMediaTheme::bg_kind::B_PRESENTATION_BG, "") +.value("B_EDIT_BG", BMediaTheme::bg_kind::B_EDIT_BG, "") +.value("B_CONTROL_BG", BMediaTheme::bg_kind::B_CONTROL_BG, "") +.value("B_HILITE_BG", BMediaTheme::bg_kind::B_HILITE_BG, "") +.export_values(); +py::enum_(m, "fg_kind", "") +.value("B_GENERAL_FG", BMediaTheme::fg_kind::B_GENERAL_FG, "") +.value("B_SETTINGS_FG", BMediaTheme::fg_kind::B_SETTINGS_FG, "") +.value("B_PRESENTATION_FG", BMediaTheme::fg_kind::B_PRESENTATION_FG, "") +.value("B_EDIT_FG", BMediaTheme::fg_kind::B_EDIT_FG, "") +.value("B_CONTROL_FG", BMediaTheme::fg_kind::B_CONTROL_FG, "") +.value("B_HILITE_FG", BMediaTheme::fg_kind::B_HILITE_FG, "") +.export_values(); +py::class_(m, "BMediaTheme") +.def("Name", &BMediaTheme::Name, "") +.def("Info", &BMediaTheme::Info, "") +.def("ID", &BMediaTheme::ID, "") +.def("GetRef", &BMediaTheme::GetRef, "", py::arg("ref")) +.def_static("ViewFor", &BMediaTheme::ViewFor, "", py::arg("web"), py::arg("hintRect")=NULL, py::arg("usingTheme")=NULL) +.def_static("SetPreferredTheme", &BMediaTheme::SetPreferredTheme, "", py::arg("defaultTheme")=NULL) +.def_static("PreferredTheme", &BMediaTheme::PreferredTheme, "") +.def("MakeControlFor", &BMediaTheme::MakeControlFor, "", py::arg("control")) +.def("BackgroundBitmapFor", &BMediaTheme::BackgroundBitmapFor, "", py::arg("bg")=BMediaTheme::bg_kind::B_GENERAL_BG) +.def("BackgroundColorFor", &BMediaTheme::BackgroundColorFor, "", py::arg("bg")=BMediaTheme::bg_kind::B_GENERAL_BG) +.def("ForegroundColorFor", &BMediaTheme::ForegroundColorFor, "", py::arg("fg")=BMediaTheme::fg_kind::B_GENERAL_FG) +; + +//m.def("make_theme", &make_theme, "", py::arg("id"), py::arg("you")); //where are these? + +//m.def("get_theme_at", &get_theme_at, "", py::arg("index"), py::arg("_name"), py::arg("_info"), py::arg("_id")); + +} diff --git a/bindings/media/MediaTrack.cpp b/bindings/media/MediaTrack.cpp new file mode 100644 index 0000000..45eb8a1 --- /dev/null +++ b/bindings/media/MediaTrack.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(MediaTrack, m) +{ +py::enum_(m, "media_seek_type", "") +.value("B_MEDIA_SEEK_CLOSEST_FORWARD", media_seek_type::B_MEDIA_SEEK_CLOSEST_FORWARD, "") +.value("B_MEDIA_SEEK_CLOSEST_BACKWARD", media_seek_type::B_MEDIA_SEEK_CLOSEST_BACKWARD, "") +.value("B_MEDIA_SEEK_DIRECTION_MASK", media_seek_type::B_MEDIA_SEEK_DIRECTION_MASK, "") +.export_values(); + +//m.attr("Decoder") = py::cast(Decoder); + +//m.attr("Encoder") = py::cast(Encoder); + +//m.attr("MediaExtractor") = py::cast(MediaExtractor); + +//m.attr("MediaWriter") = py::cast(MediaWriter); + +py::class_>(m, "BMediaTrack") +.def("InitCheck", &BMediaTrack::InitCheck, "") +.def("GetCodecInfo", &BMediaTrack::GetCodecInfo, "", py::arg("_codecInfo")) +.def("EncodedFormat", &BMediaTrack::EncodedFormat, "", py::arg("_format")) +.def("DecodedFormat", &BMediaTrack::DecodedFormat, "", py::arg("_format"), py::arg("flags")=0) +.def("CountFrames", &BMediaTrack::CountFrames, "") +.def("Duration", &BMediaTrack::Duration, "") +.def("GetMetaData", &BMediaTrack::GetMetaData, "", py::arg("_data")) +.def("CurrentFrame", &BMediaTrack::CurrentFrame, "") +.def("CurrentTime", &BMediaTrack::CurrentTime, "") +.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header")=NULL) +.def("ReadFrames", py::overload_cast(&BMediaTrack::ReadFrames), "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header"), py::arg("info")) +.def("ReplaceFrames", &BMediaTrack::ReplaceFrames, "", py::arg("buffer"), py::arg("_frameCount"), py::arg("header")) +.def("SeekToTime", &BMediaTrack::SeekToTime, "", py::arg("_time"), py::arg("flags")=0) +.def("SeekToFrame", &BMediaTrack::SeekToFrame, "", py::arg("_frame"), py::arg("flags")=0) +.def("FindKeyFrameForTime", &BMediaTrack::FindKeyFrameForTime, "", py::arg("_time"), py::arg("flags")=0) +.def("FindKeyFrameForFrame", &BMediaTrack::FindKeyFrameForFrame, "", py::arg("_frame"), py::arg("flags")=0) +//.def("ReadChunk", &BMediaTrack::ReadChunk, "", py::arg("_buffer"), py::arg("_size"), py::arg("_header")=NULL) +.def("ReadChunk", [](BMediaTrack &self) { + char* buffer = nullptr; + int32 size = 0; + status_t status = self.ReadChunk(&buffer, &size, nullptr); + if (status == B_OK) { + return std::make_tuple(status, py::bytes(buffer, size)); + } + else { + return std::make_tuple(status, py::bytes()); + } +},"") +.def("AddCopyright", &BMediaTrack::AddCopyright, "", py::arg("copyright")) +.def("AddTrackInfo", &BMediaTrack::AddTrackInfo, "", py::arg("code"), py::arg("data"), py::arg("size"), py::arg("flags")=0) +.def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("flags")=0) +.def("WriteFrames", py::overload_cast(&BMediaTrack::WriteFrames), "", py::arg("data"), py::arg("frameCount"), py::arg("info")) +.def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("flags")=0) +.def("WriteChunk", py::overload_cast(&BMediaTrack::WriteChunk), "", py::arg("data"), py::arg("size"), py::arg("info")) +.def("Flush", &BMediaTrack::Flush, "") +//.def("GetParameterWeb", &BMediaTrack::GetParameterWeb, "", py::arg("_web")) +.def("GetParameterWeb", [](BMediaTrack &self) { + BParameterWeb* web = nullptr; + status_t status = self.GetParameterWeb(&web); + return std::make_tuple(status, web); +},"") +.def("GetParameterValue", &BMediaTrack::GetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("SetParameterValue", &BMediaTrack::SetParameterValue, "", py::arg("id"), py::arg("value"), py::arg("size")) +.def("GetParameterView", &BMediaTrack::GetParameterView, "") +.def("GetQuality", &BMediaTrack::GetQuality, "", py::arg("_quality")) +.def("SetQuality", &BMediaTrack::SetQuality, "", py::arg("quality")) +.def("GetEncodeParameters", &BMediaTrack::GetEncodeParameters, "", py::arg("parameters")) +.def("SetEncodeParameters", &BMediaTrack::SetEncodeParameters, "", py::arg("parameters")) +.def("Perform", &BMediaTrack::Perform, "", py::arg("code"), py::arg("data")) +; + + +} diff --git a/bindings/media/ParameterWeb.cpp b/bindings/media/ParameterWeb.cpp new file mode 100644 index 0000000..4771948 --- /dev/null +++ b/bindings/media/ParameterWeb.cpp @@ -0,0 +1,238 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + + +PYBIND11_MODULE(ParameterWeb, m) +{ +py::enum_(m, "media_parameter_flags", "") +.value("B_HIDDEN_PARAMETER", media_parameter_flags::B_HIDDEN_PARAMETER, "") +.value("B_ADVANCED_PARAMETER", media_parameter_flags::B_ADVANCED_PARAMETER, "") +.export_values(); +/*from ParameterWeb.cpp media kit source +const char * const B_GENERIC = ""; +const char * const B_MASTER_GAIN = "Master"; +const char * const B_GAIN = "Gain"; +const char * const B_BALANCE = "Balance"; +const char * const B_FREQUENCY = "Frequency"; +const char * const B_LEVEL = "Level"; +const char * const B_SHUTTLE_SPEED = "Speed"; +const char * const B_CROSSFADE = "XFade"; +const char * const B_EQUALIZATION = "EQ"; +const char * const B_COMPRESSION = "Compression"; +const char * const B_QUALITY = "Quality"; +const char * const B_BITRATE = "Bitrate"; +const char * const B_GOP_SIZE = "GOPSize"; +const char * const B_MUTE = "Mute"; +const char * const B_ENABLE = "Enable"; +const char * const B_INPUT_MUX = "Input"; +const char * const B_OUTPUT_MUX = "Output"; +const char * const B_TUNER_CHANNEL = "Channel"; +const char * const B_TRACK = "Track"; +const char * const B_RECSTATE = "RecState"; +const char * const B_SHUTTLE_MODE = "Shuttle"; +const char * const B_RESOLUTION = "Resolution"; +const char * const B_COLOR_SPACE = "Colorspace"; +const char * const B_FRAME_RATE = "FrameRate"; +const char * const B_VIDEO_FORMAT = "VideoFormat"; +const char * const B_WEB_PHYSICAL_INPUT = "PhysInput"; +const char * const B_WEB_PHYSICAL_OUTPUT = "PhysOutput"; +const char * const B_WEB_ADC_CONVERTER = "ADC"; +const char * const B_WEB_DAC_CONVERTER = "DAC"; +const char * const B_WEB_LOGICAL_INPUT = "LogInput"; +const char * const B_WEB_LOGICAL_OUTPUT = "LogOutput"; +const char * const B_WEB_LOGICAL_BUS = "LogBus"; +const char * const B_WEB_BUFFER_INPUT = "DataInput"; +const char * const B_WEB_BUFFER_OUTPUT = "DataOutput"; +const char * const B_SIMPLE_TRANSPORT = "SimpleTransport";*/ +m.attr("B_GENERIC") = "";//py::cast(B_GENERIC); + +m.attr("B_MASTER_GAIN") = "Master";//py::cast(B_MASTER_GAIN); + +m.attr("B_GAIN") = "Gain";//py::cast(B_GAIN); + +m.attr("B_BALANCE") = "Balance";//py::cast(B_BALANCE); + +m.attr("B_FREQUENCY") = "Frequency";//py::cast(B_FREQUENCY); + +m.attr("B_LEVEL") = "Level";//py::cast(B_LEVEL); + +m.attr("B_SHUTTLE_SPEED") = "Speed";//py::cast(B_SHUTTLE_SPEED); + +m.attr("B_CROSSFADE") = "XFade";//py::cast(B_CROSSFADE); + +m.attr("B_EQUALIZATION") = "EQ";//py::cast(B_EQUALIZATION); + +m.attr("B_COMPRESSION") = "Compression";//py::cast(B_COMPRESSION); + +m.attr("B_QUALITY") = "Quality";//py::cast(B_QUALITY); + +m.attr("B_BITRATE") = "Bitrate";//py::cast(B_BITRATE); + +m.attr("B_GOP_SIZE") = "GOPSize";//py::cast(B_GOP_SIZE); + +m.attr("B_MUTE") = "Mute";//py::cast(B_MUTE); + +m.attr("B_ENABLE") = "Enable";//py::cast(B_ENABLE); + +m.attr("B_INPUT_MUX") = "Input";//py::cast(B_INPUT_MUX); + +m.attr("B_OUTPUT_MUX") = "Output";//py::cast(B_OUTPUT_MUX); + +m.attr("B_TUNER_CHANNEL") = "Channel";//py::cast(B_TUNER_CHANNEL); + +m.attr("B_TRACK") = "Track";//py::cast(B_TRACK); + +m.attr("B_RECSTATE") = "RecState";//py::cast(B_RECSTATE); + +m.attr("B_SHUTTLE_MODE") = "Shuttle";//py::cast(B_SHUTTLE_MODE); + +m.attr("B_RESOLUTION") = "Resolution";//py::cast(B_RESOLUTION); + +m.attr("B_COLOR_SPACE") = "Colorspace";//py::cast(B_COLOR_SPACE); + +m.attr("B_FRAME_RATE") = "FrameRate";//py::cast(B_FRAME_RATE); + +m.attr("B_VIDEO_FORMAT") = "VideoFormat";//py::cast(B_VIDEO_FORMAT); + +m.attr("B_WEB_PHYSICAL_INPUT") = "PhysInput";//py::cast(B_WEB_PHYSICAL_INPUT); + +m.attr("B_WEB_PHYSICAL_OUTPUT") = "PhysOutput";//py::cast(B_WEB_PHYSICAL_OUTPUT); + +m.attr("B_WEB_ADC_CONVERTER") = "ADC";//py::cast(B_WEB_ADC_CONVERTER); + +m.attr("B_WEB_DAC_CONVERTER") = "DAC";//py::cast(B_WEB_DAC_CONVERTER); + +m.attr("B_WEB_LOGICAL_INPUT") = "LogInput";//py::cast(B_WEB_LOGICAL_INPUT); + +m.attr("B_WEB_LOGICAL_OUTPUT") = "LogOutput";//py::cast(B_WEB_LOGICAL_OUTPUT); + +m.attr("B_WEB_LOGICAL_BUS") = "LogBus";//py::cast(B_WEB_LOGICAL_BUS); + +m.attr("B_WEB_BUFFER_INPUT") = "DataInput";//py::cast(B_WEB_BUFFER_INPUT); + +m.attr("B_WEB_BUFFER_OUTPUT") = "DataOutput";//py::cast(B_WEB_BUFFER_OUTPUT); + +m.attr("B_SIMPLE_TRANSPORT") = "SimpleTransport";//py::cast(B_SIMPLE_TRANSPORT); + +//m.attr("BContinuousParameter") = py::cast(BContinuousParameter); + +py::class_>(m, "BParameterWeb") +.def(py::init(), "") +.def("Node", &BParameterWeb::Node, "") +.def("MakeGroup", &BParameterWeb::MakeGroup, "", py::arg("name")) +.def("CountGroups", &BParameterWeb::CountGroups, "") +.def("GroupAt", &BParameterWeb::GroupAt, "", py::arg("index")) +.def("CountParameters", &BParameterWeb::CountParameters, "") +.def("ParameterAt", &BParameterWeb::ParameterAt, "", py::arg("index")) +.def("IsFixedSize", &BParameterWeb::IsFixedSize, "") +.def("TypeCode", &BParameterWeb::TypeCode, "") +.def("FlattenedSize", &BParameterWeb::FlattenedSize, "") +.def("Flatten", &BParameterWeb::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("AllowsTypeCode", &BParameterWeb::AllowsTypeCode, "", py::arg("code")) +.def("Unflatten", &BParameterWeb::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_>(m, "BParameterGroup") +.def("Web", &BParameterGroup::Web, "") +.def("Name", &BParameterGroup::Name, "") +.def("SetFlags", &BParameterGroup::SetFlags, "", py::arg("flags")) +.def("Flags", &BParameterGroup::Flags, "") +.def("MakeNullParameter", &BParameterGroup::MakeNullParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind")) +.def("MakeContinuousParameter", &BParameterGroup::MakeContinuousParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind"), py::arg("unit"), py::arg("min"), py::arg("max"), py::arg("step")) +.def("MakeDiscreteParameter", &BParameterGroup::MakeDiscreteParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind")) +.def("MakeTextParameter", &BParameterGroup::MakeTextParameter, "", py::arg("id"), py::arg("type"), py::arg("name"), py::arg("kind"), py::arg("maxBytes")) +.def("MakeGroup", &BParameterGroup::MakeGroup, "", py::arg("name")) +.def("CountParameters", &BParameterGroup::CountParameters, "") +.def("ParameterAt", &BParameterGroup::ParameterAt, "", py::arg("index")) +.def("CountGroups", &BParameterGroup::CountGroups, "") +.def("GroupAt", &BParameterGroup::GroupAt, "", py::arg("index")) +.def("IsFixedSize", &BParameterGroup::IsFixedSize, "") +.def("TypeCode", &BParameterGroup::TypeCode, "") +.def("FlattenedSize", &BParameterGroup::FlattenedSize, "") +.def("Flatten", &BParameterGroup::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("AllowsTypeCode", &BParameterGroup::AllowsTypeCode, "", py::arg("code")) +.def("Unflatten", &BParameterGroup::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_>(m, "BParameter") +.def("Type", &BParameter::Type, "") +.def("Web", &BParameter::Web, "") +.def("Group", &BParameter::Group, "") +.def("Name", &BParameter::Name, "") +.def("Kind", &BParameter::Kind, "") +.def("Unit", &BParameter::Unit, "") +.def("ID", &BParameter::ID, "") +.def("SetFlags", &BParameter::SetFlags, "", py::arg("flags")) +.def("Flags", &BParameter::Flags, "") +.def("ValueType", &BParameter::ValueType, "") +.def("GetValue", &BParameter::GetValue, "", py::arg("buffer"), py::arg("_size"), py::arg("_when")) +.def("SetValue", &BParameter::SetValue, "", py::arg("buffer"), py::arg("size"), py::arg("when")) +.def("CountChannels", &BParameter::CountChannels, "") +.def("SetChannelCount", &BParameter::SetChannelCount, "", py::arg("count")) +.def("MediaType", &BParameter::MediaType, "") +.def("SetMediaType", &BParameter::SetMediaType, "", py::arg("type")) +.def("CountInputs", &BParameter::CountInputs, "") +.def("InputAt", &BParameter::InputAt, "", py::arg("index")) +.def("AddInput", &BParameter::AddInput, "", py::arg("input")) +.def("CountOutputs", &BParameter::CountOutputs, "") +.def("OutputAt", &BParameter::OutputAt, "", py::arg("index")) +.def("AddOutput", &BParameter::AddOutput, "", py::arg("output")) +.def("IsFixedSize", &BParameter::IsFixedSize, "") +.def("TypeCode", &BParameter::TypeCode, "") +.def("FlattenedSize", &BParameter::FlattenedSize, "") +.def("Flatten", &BParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("AllowsTypeCode", &BParameter::AllowsTypeCode, "", py::arg("code")) +.def("Unflatten", &BParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_>(m, "BContinuousParameter") +.def("ValueType", &BContinuousParameter::ValueType, "") +.def("MinValue", &BContinuousParameter::MinValue, "") +.def("MaxValue", &BContinuousParameter::MaxValue, "") +.def("ValueStep", &BContinuousParameter::ValueStep, "") +.def("SetResponse", &BContinuousParameter::SetResponse, "", py::arg("response"), py::arg("factor"), py::arg("offset")) +.def("GetResponse", &BContinuousParameter::GetResponse, "", py::arg("_response"), py::arg("factor"), py::arg("offset")) +.def("FlattenedSize", &BContinuousParameter::FlattenedSize, "") +.def("Flatten", &BContinuousParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BContinuousParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_>(m, "BDiscreteParameter") +.def("ValueType", &BDiscreteParameter::ValueType, "") +.def("CountItems", &BDiscreteParameter::CountItems, "") +.def("ItemNameAt", &BDiscreteParameter::ItemNameAt, "", py::arg("index")) +.def("ItemValueAt", &BDiscreteParameter::ItemValueAt, "", py::arg("index")) +.def("AddItem", &BDiscreteParameter::AddItem, "", py::arg("value"), py::arg("name")) +.def("MakeItemsFromInputs", &BDiscreteParameter::MakeItemsFromInputs, "") +.def("MakeItemsFromOutputs", &BDiscreteParameter::MakeItemsFromOutputs, "") +.def("MakeEmpty", &BDiscreteParameter::MakeEmpty, "") +.def("FlattenedSize", &BDiscreteParameter::FlattenedSize, "") +.def("Flatten", &BDiscreteParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BDiscreteParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_>(m, "BTextParameter") +.def("ValueType", &BTextParameter::ValueType, "") +.def("MaxBytes", &BTextParameter::MaxBytes, "") +.def("FlattenedSize", &BTextParameter::FlattenedSize, "") +.def("Flatten", &BTextParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BTextParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +py::class_>(m, "BNullParameter") +.def("ValueType", &BNullParameter::ValueType, "") +.def("FlattenedSize", &BNullParameter::FlattenedSize, "") +.def("Flatten", &BNullParameter::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BNullParameter::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + + +} diff --git a/bindings/media/PlaySound.cpp b/bindings/media/PlaySound.cpp new file mode 100644 index 0000000..5601c80 --- /dev/null +++ b/bindings/media/PlaySound.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +//using namespace BPrivate; +//using namespace BPrivate::media; + +PYBIND11_MODULE(PlaySound, m) +{ +m.def("play_sound", &play_sound, "", py::arg("soundRef"), py::arg("mix"), py::arg("queue"), py::arg("background")); + +m.def("stop_sound", &stop_sound, "", py::arg("handle")); + +m.def("wait_for_sound", &wait_for_sound, "", py::arg("handle")); + +} diff --git a/bindings/media/Sound.cpp b/bindings/media/Sound.cpp new file mode 100644 index 0000000..93da60d --- /dev/null +++ b/bindings/media/Sound.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#include +#include +//#include +//#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(Sound, m) +{ +//m.attr("BTrackReader") = py::cast(BTrackReader); + +py::class_>(m, "BSound") +.def(py::init(), "", py::arg("data"), py::arg("size"), py::arg("format"), py::arg("freeWhenDone")=false) +.def(py::init(), "", py::arg("soundFile"), py::arg("loadIntoMemory")=false) +.def("InitCheck", &BSound::InitCheck, "") +.def("AcquireRef", &BSound::AcquireRef, "") +.def("ReleaseRef", &BSound::ReleaseRef, "") +.def("RefCount", &BSound::RefCount, "") +.def("Duration", &BSound::Duration, "") +.def("Format", &BSound::Format, "") +.def("Data", &BSound::Data, "") +.def("Size", &BSound::Size, "") +.def("GetDataAt", &BSound::GetDataAt, "", py::arg("offset"), py::arg("intoBuffer"), py::arg("bufferSize"), py::arg("outUsed")) +.def("BindTo", &BSound::BindTo, "", py::arg("player"), py::arg("format")) +.def("UnbindFrom", &BSound::UnbindFrom, "", py::arg("player")) +; + + +} diff --git a/bindings/media/SoundFile.cpp b/bindings/media/SoundFile.cpp new file mode 100644 index 0000000..329b523 --- /dev/null +++ b/bindings/media/SoundFile.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include +//#include +//#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(SoundFile, m) +{ +m.attr("B_UNKNOWN_FILE") = 0;//py::cast(B_UNKNOWN_FILE); +m.attr("B_AIFF_FILE") = 1;//py::cast(B_AIFF_FILE); +m.attr("B_WAVE_FILE") = 2;//py::cast(B_WAVE_FILE); +m.attr("B_UNIX_FILE") = 3;//py::cast(B_UNIX_FILE); + +py::class_(m, "BSoundFile") +.def(py::init(), "") +.def(py::init(), "", py::arg("ref"), py::arg("openMode")) +.def("InitCheck", &BSoundFile::InitCheck, "") +.def("SetTo", &BSoundFile::SetTo, "", py::arg("ref"), py::arg("openMode")) +.def("FileFormat", &BSoundFile::FileFormat, "") +.def("SamplingRate", &BSoundFile::SamplingRate, "") +.def("CountChannels", &BSoundFile::CountChannels, "") +.def("SampleSize", &BSoundFile::SampleSize, "") +.def("ByteOrder", &BSoundFile::ByteOrder, "") +.def("SampleFormat", &BSoundFile::SampleFormat, "") +.def("FrameSize", &BSoundFile::FrameSize, "") +.def("CountFrames", &BSoundFile::CountFrames, "") +.def("IsCompressed", &BSoundFile::IsCompressed, "") +.def("CompressionType", &BSoundFile::CompressionType, "") +.def("CompressionName", &BSoundFile::CompressionName, "") +.def("SetFileFormat", &BSoundFile::SetFileFormat, "", py::arg("format")) +.def("SetSamplingRate", &BSoundFile::SetSamplingRate, "", py::arg("fps")) +.def("SetChannelCount", &BSoundFile::SetChannelCount, "", py::arg("samplesPerFrame")) +.def("SetSampleSize", &BSoundFile::SetSampleSize, "", py::arg("bytesPerSample")) +.def("SetByteOrder", &BSoundFile::SetByteOrder, "", py::arg("byteOrder")) +.def("SetSampleFormat", &BSoundFile::SetSampleFormat, "", py::arg("format")) +.def("SetCompressionType", &BSoundFile::SetCompressionType, "", py::arg("type")) +.def("SetCompressionName", &BSoundFile::SetCompressionName, "", py::arg("name")) +.def("SetIsCompressed", &BSoundFile::SetIsCompressed, "", py::arg("compressed")) +.def("SetDataLocation", &BSoundFile::SetDataLocation, "", py::arg("offset")) +.def("SetFrameCount", &BSoundFile::SetFrameCount, "", py::arg("count")) +.def("ReadFrames", &BSoundFile::ReadFrames, "", py::arg("buffer"), py::arg("count")) +.def("WriteFrames", &BSoundFile::WriteFrames, "", py::arg("buffer"), py::arg("count")) +.def("SeekToFrame", &BSoundFile::SeekToFrame, "", py::arg("index")) +.def("FrameIndex", &BSoundFile::FrameIndex, "") +.def("FramesRemaining", &BSoundFile::FramesRemaining, "") +.def_readwrite("fSoundFile", &BSoundFile::fSoundFile, "") +; + + +} diff --git a/bindings/media/SoundPlayer.cpp b/bindings/media/SoundPlayer.cpp new file mode 100644 index 0000000..1b18885 --- /dev/null +++ b/bindings/media/SoundPlayer.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(SoundPlayer, m) +{ +//m.attr("SoundPlayNode") = py::cast(SoundPlayNode); + +/*py::class_(m, "sound_error") +.def(py::init(), "", py::arg("string")) +.def("what", &sound_error::what, "") +;*/ + +py::register_exception(m, "sound_error"); +class sound_error : public std::exception { + public: + explicit sound_error(const char* msg) : message(msg) {} + const char* what() const noexcept override { + return message; + } + private: const char* message; +}; +/* In python you can write: except sound_player.sound_error as e: print(f"Caught sound_error: {e.what()}")*/ + +py::enum_(m, "sound_player_notification", "") +.value("B_STARTED", BSoundPlayer::sound_player_notification::B_STARTED, "") +.value("B_STOPPED", BSoundPlayer::sound_player_notification::B_STOPPED, "") +.value("B_SOUND_DONE", BSoundPlayer::sound_player_notification::B_SOUND_DONE, "") +.export_values(); + +py::class_(m, "BSoundPlayer") +//.def(py::init(), "", py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +//.def(py::init(), "", py::arg("format"), py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +//.def(py::init(), "", py::arg("toNode"), py::arg("format")=NULL, py::arg("name")=NULL, py::arg("input")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) + +.def(py::init(), py::arg("name") = nullptr, py::arg("playerFunction") = nullptr, py::arg("eventNotifierFunction") = nullptr, py::arg("cookie") = nullptr) +.def(py::init(), py::arg("format"), py::arg("name") = nullptr, py::arg("playerFunction") = nullptr, py::arg("eventNotifierFunction") = nullptr, py::arg("cookie") = nullptr) +.def(py::init(), py::arg("toNode"), py::arg("format") = nullptr, py::arg("name") = nullptr, py::arg("input") = nullptr, py::arg("playerFunction") = nullptr, py::arg("eventNotifierFunction") = nullptr, py::arg("cookie") = nullptr) + +.def("InitCheck", &BSoundPlayer::InitCheck, "") +.def("Format", &BSoundPlayer::Format, "") +.def("Start", &BSoundPlayer::Start, "") +.def("Stop", &BSoundPlayer::Stop, "", py::arg("block")=true, py::arg("flush")=true) +//.def("BufferPlayer", &BSoundPlayer::BufferPlayer, "") +//attempt1 +//.def("BufferPlayer", [](const BSoundPlayer& self) { return self.BufferPlayer(); },"") +//attempt2 +.def("BufferPlayer", [](const BSoundPlayer& self) -> std::function { + BSoundPlayer::BufferPlayerFunc playerFunc = self.BufferPlayer(); + return [playerFunc](void* cookie, void* buffer, size_t size, const media_raw_audio_format& format) { if (playerFunc) { playerFunc(cookie, buffer, size, format); } }; },"") //TODO test this +.def("SetBufferPlayer", &BSoundPlayer::SetBufferPlayer, "", py::arg("")) +//.def("EventNotifier", &BSoundPlayer::EventNotifier, "") +//attempt variadic impossible +/*.def("EventNotifier", [](const BSoundPlayer& self) -> std::function { + BSoundPlayer::EventNotifierFunc notifierFunc = self.EventNotifier(); + return [notifierFunc](void* cookie, BSoundPlayer::sound_player_notification what, ...) { if (notifierFunc) { notifierFunc(cookie, what); } }; },"")*/ +.def("EventNotifier", [](const BSoundPlayer& self) -> std::function { + BSoundPlayer::EventNotifierFunc notifierFunc = self.EventNotifier(); + return [notifierFunc](void* cookie, BSoundPlayer::sound_player_notification what) { if (notifierFunc) { notifierFunc(cookie, what); } }; },"") //TODO test this +.def("SetNotifier", &BSoundPlayer::SetNotifier, "", py::arg("eventNotifierFunction")) +.def("Cookie", &BSoundPlayer::Cookie, "") +.def("SetCookie", &BSoundPlayer::SetCookie, "", py::arg("cookie")) +.def("SetCallbacks", &BSoundPlayer::SetCallbacks, "", py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL) +.def("CurrentTime", &BSoundPlayer::CurrentTime, "") +.def("PerformanceTime", &BSoundPlayer::PerformanceTime, "") +.def("Preroll", &BSoundPlayer::Preroll, "") +.def("StartPlaying", py::overload_cast(&BSoundPlayer::StartPlaying), "", py::arg("sound"), py::arg("atTime")=0) +.def("StartPlaying", py::overload_cast(&BSoundPlayer::StartPlaying), "", py::arg("sound"), py::arg("atTime"), py::arg("withVolume")) +.def("SetSoundVolume", &BSoundPlayer::SetSoundVolume, "", py::arg("sound"), py::arg("newVolume")) +.def("IsPlaying", &BSoundPlayer::IsPlaying, "", py::arg("id")) +.def("StopPlaying", &BSoundPlayer::StopPlaying, "", py::arg("id")) +.def("WaitForSound", &BSoundPlayer::WaitForSound, "", py::arg("id")) +.def("Volume", &BSoundPlayer::Volume, "") +.def("SetVolume", &BSoundPlayer::SetVolume, "", py::arg("volume")) +.def("VolumeDB", &BSoundPlayer::VolumeDB, "", py::arg("forcePoll")=false) +.def("SetVolumeDB", &BSoundPlayer::SetVolumeDB, "", py::arg("dB")) +.def("GetVolumeInfo", &BSoundPlayer::GetVolumeInfo, "", py::arg("_node"), py::arg("_parameterID"), py::arg("_minDB"), py::arg("_maxDB")) +.def("Latency", &BSoundPlayer::Latency, "") +.def("HasData", &BSoundPlayer::HasData, "") +.def("SetHasData", &BSoundPlayer::SetHasData, "", py::arg("hasData")) +; +/* +py::class_(m, "playing_sound") +.def_readwrite("next", &playing_sound::next, "") +.def_readwrite("current_offset", &playing_sound::current_offset, "") +.def_readwrite("sound", &playing_sound::sound, "") +.def_readwrite("id", &playing_sound::id, "") +.def_readwrite("delta", &playing_sound::delta, "") +.def_readwrite("rate", &playing_sound::rate, "") +.def_readwrite("wait_sem", &playing_sound::wait_sem, "") +.def_readwrite("volume", &playing_sound::volume, "") +; + +py::class_(m, "waiting_sound") +.def_readwrite("next", &waiting_sound::next, "") +.def_readwrite("start_time", &waiting_sound::start_time, "") +.def_readwrite("sound", &waiting_sound::sound, "") +.def_readwrite("id", &waiting_sound::id, "") +.def_readwrite("rate", &waiting_sound::rate, "") +.def_readwrite("volume", &waiting_sound::volume, "") +;*/ + + +} diff --git a/bindings/media/TimeCode.cpp b/bindings/media/TimeCode.cpp new file mode 100644 index 0000000..072478d --- /dev/null +++ b/bindings/media/TimeCode.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +std::string get_timecode_info_name(const timecode_info& self) { + return std::string(self.name); +} + +void set_timecode_info_name(timecode_info& self, const std::string& name) { + std::strncpy(self.name, name.c_str(), 32 - 1); + self.name[32 - 1] = '\0'; +} + +std::string get_timecode_info_format(const timecode_info& self) { + return std::string(self.format); +} + +void set_timecode_info_format(timecode_info& self, const std::string& format) { + std::strncpy(self.format, format.c_str(), 32 - 1); + self.name[32 - 1] = '\0'; +} + +PYBIND11_MODULE(TimeCode, m) +{ +py::enum_(m, "timecode_type", "") +.value("B_TIMECODE_DEFAULT", timecode_type::B_TIMECODE_DEFAULT, "") +.value("B_TIMECODE_100", timecode_type::B_TIMECODE_100, "") +.value("B_TIMECODE_75", timecode_type::B_TIMECODE_75, "") +.value("B_TIMECODE_30", timecode_type::B_TIMECODE_30, "") +.value("B_TIMECODE_30_DROP_2", timecode_type::B_TIMECODE_30_DROP_2, "") +.value("B_TIMECODE_30_DROP_4", timecode_type::B_TIMECODE_30_DROP_4, "") +.value("B_TIMECODE_25", timecode_type::B_TIMECODE_25, "") +.value("B_TIMECODE_24", timecode_type::B_TIMECODE_24, "") +.value("B_TIMECODE_18", timecode_type::B_TIMECODE_18, "") +.export_values(); + +py::class_(m, "timecode_info") +.def_readwrite("type", &timecode_info::type, "") +.def_readwrite("drop_frames", &timecode_info::drop_frames, "") +.def_readwrite("every_nth", &timecode_info::every_nth, "") +.def_readwrite("except_nth", &timecode_info::except_nth, "") +.def_readwrite("fps_div", &timecode_info::fps_div, "") +//.def_readwrite("name", &timecode_info::name, "") +.def_property("name", &get_timecode_info_name,&set_timecode_info_name,"") +//.def_readwrite("format", &timecode_info::format, "") +.def_property("format", &get_timecode_info_format,&set_timecode_info_format,"") +//.def_readwrite("_reserved_", &timecode_info::_reserved_, "") +.def_property( + "_reserved_", + [](const timecode_info &info) { + py::array_t result(64); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](timecode_info &info, py::array_t value) { + if (value.size() != 64) { + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + },"") +; + +py::class_(m, "BTimeCode") +.def(py::init(), "") +.def(py::init(), "", py::arg("microSeconds"), py::arg("type")=B_TIMECODE_DEFAULT) +.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("type")=B_TIMECODE_DEFAULT) +.def("SetData", &BTimeCode::SetData, "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames")) +.def("SetType", &BTimeCode::SetType, "", py::arg("type")) +.def("SetMicroseconds", &BTimeCode::SetMicroseconds, "", py::arg("microSeconds")) +.def("SetLinearFrames", &BTimeCode::SetLinearFrames, "", py::arg("linearFrames")) +.def("operator=", &BTimeCode::operator=, "", py::arg("other")) +.def("__eq__", &BTimeCode::operator==, "", py::arg("other")) +.def("__lt__", &BTimeCode::operator<, "", py::arg("other")) +.def("__iadd__", &BTimeCode::operator+=, "", py::arg("other")) +.def("__isub__", &BTimeCode::operator-=, "", py::arg("other")) +.def("__add__", &BTimeCode::operator+, "", py::arg("other")) +.def("operator-", &BTimeCode::operator-, "", py::arg("other")) +.def("Hours", &BTimeCode::Hours, "") +.def("Minutes", &BTimeCode::Minutes, "") +.def("Seconds", &BTimeCode::Seconds, "") +.def("Frames", &BTimeCode::Frames, "") +.def("Type", &BTimeCode::Type, "") +.def("GetData", &BTimeCode::GetData, "", py::arg("_hours"), py::arg("_minutes"), py::arg("_seconds"), py::arg("_frames"), py::arg("_type")=NULL) +.def("Microseconds", &BTimeCode::Microseconds, "") +.def("LinearFrames", &BTimeCode::LinearFrames, "") +.def("GetString", &BTimeCode::GetString, "", py::arg("string")) +; + +m.def("us_to_timecode", &us_to_timecode, "", py::arg("micros"), py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("code")=NULL); + +m.def("timecode_to_us", &timecode_to_us, "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("micros"), py::arg("code")=NULL); + +m.def("frames_to_timecode", &frames_to_timecode, "", py::arg("l_frames"), py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("code")=NULL); + +m.def("timecode_to_frames", &timecode_to_frames, "", py::arg("hours"), py::arg("minutes"), py::arg("seconds"), py::arg("frames"), py::arg("lFrames"), py::arg("code")=NULL); + +m.def("get_timecode_description", &get_timecode_description, "", py::arg("type"), py::arg("_timecode")); + +m.def("count_timecodes", &count_timecodes, ""); + +} diff --git a/bindings/media/TimeSource.cpp b/bindings/media/TimeSource.cpp new file mode 100644 index 0000000..09e33aa --- /dev/null +++ b/bindings/media/TimeSource.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::media; + +PYBIND11_MODULE(TimeSource, m) +{ +//m.attr("BMediaRosterEx") = py::cast(BMediaRosterEx); + +//m.attr("TimeSourceObject") = py::cast(TimeSourceObject); + +//m.attr("SystemTimeSourceObject") = py::cast(SystemTimeSourceObject); + +//m.attr("SlaveNodes") = py::cast(SlaveNodes); + +//m.attr("TimeSourceTransmit") = py::cast(TimeSourceTransmit); + +py::class_>(m, "BTimeSource") +.def("SnoozeUntil", &BTimeSource::SnoozeUntil, "", py::arg("performanceTime"), py::arg("withLatency")=0, py::arg("retrySignals")=false) +.def("Now", &BTimeSource::Now, "") +.def("PerformanceTimeFor", &BTimeSource::PerformanceTimeFor, "", py::arg("realTime")) +.def("RealTimeFor", &BTimeSource::RealTimeFor, "", py::arg("performanceTime"), py::arg("withLatency")) +.def("IsRunning", &BTimeSource::IsRunning, "") +.def("GetTime", &BTimeSource::GetTime, "", py::arg("_performanceTime"), py::arg("_realTime"), py::arg("_drift")) +.def("GetStartLatency", &BTimeSource::GetStartLatency, "", py::arg("_latency")) +.def_static("RealTime", &BTimeSource::RealTime, "") +; +/* +py::class_(m, "time_source_op_info") +.def_readwrite("op", &time_source_op_info::op, "") +.def_readwrite("_reserved1", &time_source_op_info::_reserved1, "") +.def_readwrite("real_time", &time_source_op_info::real_time, "") +.def_readwrite("performance_time", &time_source_op_info::performance_time, "") +//.def_readwrite("_reserved2", &time_source_op_info::_reserved2, "") +.def_property( + "_reserved2", + [](const time_source_op_info &info) { + py::array_t result(6); + std::memcpy(result.mutable_data(), &info._reserved_, sizeof(info._reserved_)); + return result; + }, + [](time_source_op_info &info, py::array_t value) { + if (value.size() != 6) { + throw std::runtime_error("Array must have size 6"); + } + std::memcpy(&info._reserved_, value.data(), sizeof(info._reserved_)); + }, "") +;*/ + + +} diff --git a/bindings/media/TimedEventQueue.cpp b/bindings/media/TimedEventQueue.cpp new file mode 100644 index 0000000..9682a92 --- /dev/null +++ b/bindings/media/TimedEventQueue.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +std::string get_media_timed_event_user_data(const media_timed_event& self) { + return std::string(self.user_data); +} + +void set_media_timed_event_user_data(media_timed_event& self, const std::string& user_data) { + std::strncpy(self.user_data, user_data.c_str(), 64 - 1); + self.user_data[64 - 1] = '\0'; +} + +PYBIND11_MODULE(TimedEventQueue, m) +{ +py::class_(m, "media_timed_event") +.def(py::init(), "") +.def(py::init(), "", py::arg("inTime"), py::arg("inType")) +.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup")) +.def(py::init(), "", py::arg("inTime"), py::arg("inType"), py::arg("inPointer"), py::arg("inCleanup"), py::arg("inData"), py::arg("inBigdata"), py::arg("inUserData"), py::arg("dataSize")=0) +.def(py::init(), "", py::arg("other")) +.def("operator=", &media_timed_event::operator=, "", py::arg("other")) +.def_readwrite("event_time", &media_timed_event::event_time, "") +.def_readwrite("type", &media_timed_event::type, "") +.def_readwrite("pointer", &media_timed_event::pointer, "") +.def_readwrite("cleanup", &media_timed_event::cleanup, "") +.def_readwrite("data", &media_timed_event::data, "") +.def_readwrite("bigdata", &media_timed_event::bigdata, "") +//.def_readwrite("user_data", &media_timed_event::user_data, "") +.def_property("user_data", &get_media_timed_event_user_data,&set_media_timed_event_user_data,"") +//.def_readwrite("_reserved_media_timed_event_", &media_timed_event::_reserved_media_timed_event_, "") +.def_property( + "_reserved_media_timed_event_", + [](const media_timed_event &event) { + py::array_t result(8); + std::memcpy(result.mutable_data(), &event._reserved_media_timed_event_, sizeof(event._reserved_media_timed_event_)); + return result; + }, + [](media_timed_event &event, py::array_t value) { + if (value.size() != 8) { + throw std::runtime_error("Array must have size 8"); + } + std::memcpy(&event._reserved_media_timed_event_, value.data(), sizeof(event._reserved_media_timed_event_)); + },"") +; + +py::enum_(m, "event_type", "") +.value("B_NO_EVENT", BTimedEventQueue::event_type::B_NO_EVENT, "") +.value("B_ANY_EVENT", BTimedEventQueue::event_type::B_ANY_EVENT, "") +.value("B_START", BTimedEventQueue::event_type::B_START, "") +.value("B_STOP", BTimedEventQueue::event_type::B_STOP, "") +.value("B_SEEK", BTimedEventQueue::event_type::B_SEEK, "") +.value("B_WARP", BTimedEventQueue::event_type::B_WARP, "") +.value("B_TIMER", BTimedEventQueue::event_type::B_TIMER, "") +.value("B_HANDLE_BUFFER", BTimedEventQueue::event_type::B_HANDLE_BUFFER, "") +.value("B_DATA_STATUS", BTimedEventQueue::event_type::B_DATA_STATUS, "") +.value("B_HARDWARE", BTimedEventQueue::event_type::B_HARDWARE, "") +.value("B_PARAMETER", BTimedEventQueue::event_type::B_PARAMETER, "") +.value("B_USER_EVENT", BTimedEventQueue::event_type::B_USER_EVENT, "") +.export_values(); + +py::enum_(m, "cleanup_flag", "") +.value("B_NO_CLEANUP", BTimedEventQueue::cleanup_flag::B_NO_CLEANUP, "") +.value("B_RECYCLE_BUFFER", BTimedEventQueue::cleanup_flag::B_RECYCLE_BUFFER, "") +.value("B_EXPIRE_TIMER", BTimedEventQueue::cleanup_flag::B_EXPIRE_TIMER, "") +.value("B_USER_CLEANUP", BTimedEventQueue::cleanup_flag::B_USER_CLEANUP, "") +.export_values(); + +py::enum_(m, "time_direction", "") +.value("B_ALWAYS", BTimedEventQueue::time_direction::B_ALWAYS, "") +.value("B_BEFORE_TIME", BTimedEventQueue::time_direction::B_BEFORE_TIME, "") +.value("B_AT_TIME", BTimedEventQueue::time_direction::B_AT_TIME, "") +.value("B_AFTER_TIME", BTimedEventQueue::time_direction::B_AFTER_TIME, "") +.export_values(); + +py::class_(m, "BTimedEventQueue") +//.def("operatornew", &BTimedEventQueue::operatornew, "", py::arg("size")) +//.def("operatordelete", &BTimedEventQueue::operatordelete, "", py::arg("ptr"), py::arg("size")) +.def(py::init(), "") +.def("AddEvent", &BTimedEventQueue::AddEvent, "", py::arg("event")) +.def("RemoveEvent", &BTimedEventQueue::RemoveEvent, "", py::arg("event")) +.def("RemoveFirstEvent", &BTimedEventQueue::RemoveFirstEvent, "", py::arg("_event")=NULL) +.def("HasEvents", &BTimedEventQueue::HasEvents, "") +.def("EventCount", &BTimedEventQueue::EventCount, "") +.def("FirstEvent", &BTimedEventQueue::FirstEvent, "") +.def("FirstEventTime", &BTimedEventQueue::FirstEventTime, "") +.def("LastEvent", &BTimedEventQueue::LastEvent, "") +.def("LastEventTime", &BTimedEventQueue::LastEventTime, "") +.def("FindFirstMatch", &BTimedEventQueue::FindFirstMatch, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=BTimedEventQueue::event_type::B_ANY_EVENT) +.def("DoForEach", &BTimedEventQueue::DoForEach, "", py::arg("hook"), py::arg("context"), py::arg("eventTime")=0, py::arg("direction")=BTimedEventQueue::time_direction::B_ALWAYS, py::arg("inclusive")=true, py::arg("eventType")=BTimedEventQueue::event_type::B_ANY_EVENT) +.def("SetCleanupHook", &BTimedEventQueue::SetCleanupHook, "", py::arg("hook"), py::arg("context")) +.def("FlushEvents", &BTimedEventQueue::FlushEvents, "", py::arg("eventTime"), py::arg("direction"), py::arg("inclusive")=true, py::arg("eventType")=BTimedEventQueue::event_type::B_ANY_EVENT) +; + +//m.def("__eq__", &operator==, "", py::arg("a"), py::arg("b")); +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +//m.def("__ne__", &operator!=, "", py::arg("a"), py::arg("b")); +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +//m.def("__lt__", &operator<, "", py::arg("a"), py::arg("b")); +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("a"), py::arg("b")); + +//m.def("__gt__", &operator>, "", py::arg("a"), py::arg("b")); +m.def("__gt__", py::overload_cast(&operator>), "", py::arg("a"), py::arg("b")); + +} diff --git a/bindings/storage/AppFileInfo.cpp b/bindings/storage/AppFileInfo.cpp new file mode 100644 index 0000000..8fb2278 --- /dev/null +++ b/bindings/storage/AppFileInfo.cpp @@ -0,0 +1,161 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +/* +// promemoria +struct version_info { + uint32_t major; + uint32_t middle; + uint32_t minor; + uint32_t variety; + uint32_t internal; + char short_info[64]; + char long_info[256]; +};*/ + +PYBIND11_MODULE(AppFileInfo, m) +{ +py::enum_(m, "info_variety", "") +.value("B_DEVELOPMENT_VERSION", info_variety::B_DEVELOPMENT_VERSION, "") +.value("B_ALPHA_VERSION", info_variety::B_ALPHA_VERSION, "") +.value("B_BETA_VERSION", info_variety::B_BETA_VERSION, "") +.value("B_GAMMA_VERSION", info_variety::B_GAMMA_VERSION, "") +.value("B_GOLDEN_MASTER_VERSION", info_variety::B_GOLDEN_MASTER_VERSION, "") +.value("B_FINAL_VERSION", info_variety::B_FINAL_VERSION, "") +.export_values(); + +py::enum_(m, "info_location", "") +.value("B_USE_ATTRIBUTES", info_location::B_USE_ATTRIBUTES, "") +.value("B_USE_RESOURCES", info_location::B_USE_RESOURCES, "") +.value("B_USE_BOTH_LOCATIONS", info_location::B_USE_BOTH_LOCATIONS, "") +.export_values(); + +py::enum_(m, "version_kind", "") +.value("B_APP_VERSION_KIND", version_kind::B_APP_VERSION_KIND, "") +.value("B_SYSTEM_VERSION_KIND", version_kind::B_SYSTEM_VERSION_KIND, "") +.export_values(); + +py::class_(m, "version_info") +.def(py::init<>()) +.def_readwrite("major", &version_info::major, "") +.def_readwrite("middle", &version_info::middle, "") +.def_readwrite("minor", &version_info::minor, "") +.def_readwrite("variety", &version_info::variety, "") +.def_readwrite("internal", &version_info::internal, "") +// TODO Test short_info & long_info +//.def_readwrite("short_info", &version_info::short_info, "") +.def_property( + "short_info", + [](const version_info &info) { + return py::cast(info.short_info); + }, + //tentativo non provato n.1 + /*py::array_t result(){ + char data[64]; + return py::array_t{64},{1},data + }; + }. + std::memcpy(result.mutable_data(), &info.short_info, sizeof(info.short_info)); + return result; + }, + [](version_info &info, py::array_t value) { + if (value.size() != 64) { //check how write minor + throw std::runtime_error("Array must have size 64"); + } + std::memcpy(&info.short_info, value.data(), sizeof(info.short_info)); + }*/ + [](version_info &info, const std::string &value) { + if (value.size()(m, "BAppFileInfo") +.def(py::init(), "") +.def(py::init(), "", py::arg("file")) +.def("SetTo", &BAppFileInfo::SetTo, "", py::arg("file")) +.def("GetType", &BAppFileInfo::GetType, "", py::arg("type")) +.def("SetType", &BAppFileInfo::SetType, "", py::arg("type")) +.def("GetSignature", &BAppFileInfo::GetSignature, "", py::arg("signature")) +.def("SetSignature", &BAppFileInfo::SetSignature, "", py::arg("signature")) +.def("GetCatalogEntry", &BAppFileInfo::GetCatalogEntry, "", py::arg("catalogEntry")) +.def("SetCatalogEntry", &BAppFileInfo::SetCatalogEntry, "", py::arg("catalogEntry")) +.def("GetAppFlags", &BAppFileInfo::GetAppFlags, "", py::arg("flags")) +.def("SetAppFlags", &BAppFileInfo::SetAppFlags, "", py::arg("flags")) +.def("RemoveAppFlags", &BAppFileInfo::RemoveAppFlags, "") +.def("GetSupportedTypes", &BAppFileInfo::GetSupportedTypes, "", py::arg("types")) +.def("SetSupportedTypes", py::overload_cast(&BAppFileInfo::SetSupportedTypes), "", py::arg("types"), py::arg("updateMimeDB"), py::arg("syncAll")) +.def("SetSupportedTypes", py::overload_cast(&BAppFileInfo::SetSupportedTypes), "", py::arg("types"), py::arg("syncAll")) +.def("SetSupportedTypes", py::overload_cast(&BAppFileInfo::SetSupportedTypes), "", py::arg("types")) +.def("IsSupportedType", &BAppFileInfo::IsSupportedType, "", py::arg("type")) +.def("Supports", &BAppFileInfo::Supports, "", py::arg("type")) +.def("GetIcon", py::overload_cast(&BAppFileInfo::GetIcon, py::const_), "", py::arg("icon"), py::arg("which")) +.def("SetIcon", py::overload_cast(&BAppFileInfo::SetIcon), "", py::arg("icon"), py::arg("which"), py::arg("updateMimeDB")) +.def("SetIcon", py::overload_cast(&BAppFileInfo::SetIcon), "", py::arg("icon"), py::arg("which")) +//.def("GetIcon", py::overload_cast(&BAppFileInfo::GetIcon), "", py::arg("data"), py::arg("size")) +.def("GetIcon", [](const BAppFileInfo& self, py::list& _data, size_t& _size) { + uint8* data = nullptr; + size_t size = 0; + status_t result = self.GetIcon(&data, &size); + for (size_t i = 0; i < size; ++i) { + _data.append(data[i]); + } + _size = size; + delete[] data; + return result; +},"", py::arg("_data"), py::arg("_size")) +//.def("SetIcon", py::overload_cast(&BAppFileInfo::SetIcon), "", py::arg("data"), py::arg("size"), py::arg("updateMimeDB")) //TODO +//.def("SetIcon", py::overload_cast(&BAppFileInfo::SetIcon), "", py::arg("data"), py::arg("size")) //TODO +.def("GetVersionInfo", &BAppFileInfo::GetVersionInfo, "", py::arg("info"), py::arg("kind")) +.def("SetVersionInfo", &BAppFileInfo::SetVersionInfo, "", py::arg("info"), py::arg("kind")) +.def("GetIconForType", py::overload_cast(&BAppFileInfo::GetIconForType, py::const_), "", py::arg("type"), py::arg("icon"), py::arg("which")) +//.def("GetIconForType", py::overload_cast(&BAppFileInfo::GetIconForType), "", py::arg("type"), py::arg("data"), py::arg("size")) +.def("GetIconForType", [](const BAppFileInfo &self, const char *type, py::list& _data, size_t& _size) { + uint8* data = nullptr; + size_t size = 0; + status_t result = self.GetIconForType(type, &data, &size); + for (size_t i = 0; i < size; ++i) { + _data.append(data[i]); + } + _size = size; + delete[] data; + return result; +},"", py::arg("type"), py::arg("_data"), py::arg("_size")) +.def("SetIconForType", py::overload_cast(&BAppFileInfo::SetIconForType), "", py::arg("type"), py::arg("icon"), py::arg("which"), py::arg("updateMimeDB")) +.def("SetIconForType", py::overload_cast(&BAppFileInfo::SetIconForType), "", py::arg("type"), py::arg("icon"), py::arg("which")) +//.def("SetIconForType", py::overload_cast(&BAppFileInfo::SetIconForType), "", py::arg("type"), py::arg("data"), py::arg("size"), py::arg("updateMimeDB")) //TODO +//.def("SetIconForType", py::overload_cast(&BAppFileInfo::SetIconForType), "", py::arg("type"), py::arg("data"), py::arg("size")) //TODO +.def("SetInfoLocation", &BAppFileInfo::SetInfoLocation, "", py::arg("location")) +.def("IsUsingAttributes", &BAppFileInfo::IsUsingAttributes, "") +.def("IsUsingResources", &BAppFileInfo::IsUsingResources, "") +; + + +} diff --git a/bindings/storage/Directory.cpp b/bindings/storage/Directory.cpp new file mode 100644 index 0000000..d5d7ea2 --- /dev/null +++ b/bindings/storage/Directory.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Directory,m) +{ +py::class_(m, "BDirectory")// verify if needed +.def(py::init(), "") +.def(py::init(), "", py::arg("dir")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("nref")) +.def(py::init(), "", py::arg("entry")) +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("dir"), py::arg("path")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("nref")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("entry")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("path")) +.def("SetTo", py::overload_cast(&BDirectory::SetTo), "", py::arg("dir"), py::arg("path")) +// works also as +.def("GetEntry", &BDirectory::GetEntry, "", py::arg("entry")) +//.def("GetEntry", py::overload_cast(&BDirectory::GetEntry, py::const_), "",py::arg("entry")) // verificare +.def("IsRootDirectory", &BDirectory::IsRootDirectory, "") +.def("FindEntry", &BDirectory::FindEntry, "", py::arg("path"), py::arg("entry"), py::arg("traverse")=false) +.def("Contains", py::overload_cast(&BDirectory::Contains, py::const_), "",py::arg("path"),py::arg("nodeFlags")=B_ANY_NODE) +.def("Contains", py::overload_cast(&BDirectory::Contains, py::const_), "",py::arg("entry"),py::arg("nodeFlags")=B_ANY_NODE) +.def("GetStatFor", &BDirectory::GetStatFor, "", py::arg("path"), py::arg("st")) +.def("GetNextEntry", &BDirectory::GetNextEntry, "", py::arg("entry"), py::arg("traverse")=false) +.def("GetNextRef", &BDirectory::GetNextRef, "", py::arg("ref")) +.def("GetNextDirents", &BDirectory::GetNextDirents, "", py::arg("buf"), py::arg("bufSize"), py::arg("count")=INT_MAX) +.def("Rewind", &BDirectory::Rewind, "") +.def("CountEntries", &BDirectory::CountEntries, "") +.def("CreateDirectory", &BDirectory::CreateDirectory, "", py::arg("path"), py::arg("dir")) +.def("CreateFile", &BDirectory::CreateFile, "", py::arg("path"), py::arg("file"), py::arg("failIfExists")=false) +.def("CreateSymLink", &BDirectory::CreateSymLink, "", py::arg("path"), py::arg("linkToPath"), py::arg("link")) +.def("operator=", &BDirectory::operator=, "", py::arg("dir")) +; + +m.def("create_directory", &create_directory, "", py::arg("path"), py::arg("mode")); + +} diff --git a/bindings/storage/DiskDeviceDefs.cpp b/bindings/storage/DiskDeviceDefs.cpp new file mode 100644 index 0000000..3d3f51b --- /dev/null +++ b/bindings/storage/DiskDeviceDefs.cpp @@ -0,0 +1,123 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(DiskDeviceDefs,m) +{ +m.attr("B_PARTITION_IS_DEVICE") = 0x01;//py::cast(B_PARTITION_IS_DEVICE); +m.attr("B_PARTITION_FILE_SYSTEM") = 0x02;//py::cast(B_PARTITION_FILE_SYSTEM); +m.attr("B_PARTITION_PARTITIONING_SYSTEM") = 0x04;//py::cast(B_PARTITION_PARTITIONING_SYSTEM); +m.attr("B_PARTITION_READ_ONLY") = 0x08;//py::cast(B_PARTITION_READ_ONLY); +m.attr("B_PARTITION_MOUNTED") = 0x10;//py::cast(B_PARTITION_MOUNTED); +m.attr("B_PARTITION_BUSY") = 0x20;//py::cast(B_PARTITION_BUSY); + +m.attr("B_PARTITION_VALID") = 0;//py::cast(B_PARTITION_VALID); +m.attr("B_PARTITION_CORRUPT") = 1;//py::cast(B_PARTITION_CORRUPT); +m.attr("B_PARTITION_UNRECOGNIZED") = 2;//py::cast(B_PARTITION_UNRECOGNIZED); +m.attr("B_PARTITION_UNINITIALIZED") = 3;//py::cast(B_PARTITION_UNINITIALIZED); + +m.attr("B_PARTITION_CHANGED_OFFSET") = 0x000001;//py::cast(B_PARTITION_CHANGED_OFFSET); +m.attr("B_PARTITION_CHANGED_SIZE") = 0x000002;//py::cast(B_PARTITION_CHANGED_SIZE); +m.attr("B_PARTITION_CHANGED_CONTENT_SIZE") = 0x000004;//py::cast(B_PARTITION_CHANGED_CONTENT_SIZE); +m.attr("B_PARTITION_CHANGED_BLOCK_SIZE") = 0x000008;//py::cast(B_PARTITION_CHANGED_BLOCK_SIZE); +m.attr("B_PARTITION_CHANGED_STATUS") = 0x000010;//py::cast(B_PARTITION_CHANGED_STATUS); +m.attr("B_PARTITION_CHANGED_FLAGS") = 0x000020;//py::cast(B_PARTITION_CHANGED_FLAGS); +m.attr("B_PARTITION_CHANGED_VOLUME") = 0x000040;//py::cast(B_PARTITION_CHANGED_VOLUME); +m.attr("B_PARTITION_CHANGED_NAME") = 0x000080;//py::cast(B_PARTITION_CHANGED_NAME); +m.attr("B_PARTITION_CHANGED_CONTENT_NAME") = 0x000100;//py::cast(B_PARTITION_CHANGED_CONTENT_NAME); +m.attr("B_PARTITION_CHANGED_TYPE") = 0x000200;//py::cast(B_PARTITION_CHANGED_TYPE); +m.attr("B_PARTITION_CHANGED_CONTENT_TYPE") = 0x000400;//py::cast(B_PARTITION_CHANGED_CONTENT_TYPE); +m.attr("B_PARTITION_CHANGED_PARAMETERS") = 0x000800;//py::cast(B_PARTITION_CHANGED_PARAMETERS); +m.attr("B_PARTITION_CHANGED_CONTENT_PARAMETERS") = 0x001000;//py::cast(B_PARTITION_CHANGED_CONTENT_PARAMETERS); +m.attr("B_PARTITION_CHANGED_CHILDREN") = 0x002000;//py::cast(B_PARTITION_CHANGED_CHILDREN); +m.attr("B_PARTITION_CHANGED_DESCENDANTS") = 0x004000;//py::cast(B_PARTITION_CHANGED_DESCENDANTS); +m.attr("B_PARTITION_CHANGED_DEFRAGMENTATION") = 0x008000;//py::cast(B_PARTITION_CHANGED_DEFRAGMENTATION); +m.attr("B_PARTITION_CHANGED_CHECK") = 0x010000;//py::cast(B_PARTITION_CHANGED_CHECK); +m.attr("B_PARTITION_CHANGED_REPAIR") = 0x020000;//py::cast(B_PARTITION_CHANGED_REPAIR); +m.attr("B_PARTITION_CHANGED_INITIALIZATION") = 0x040000;//py::cast(B_PARTITION_CHANGED_INITIALIZATION); + +m.attr("B_DISK_DEVICE_REMOVABLE") = 0x01;//py::cast(B_DISK_DEVICE_REMOVABLE); +m.attr("B_DISK_DEVICE_HAS_MEDIA") = 0x02;//py::cast(B_DISK_DEVICE_HAS_MEDIA); +m.attr("B_DISK_DEVICE_READ_ONLY") = 0x04;//py::cast(B_DISK_DEVICE_READ_ONLY); +m.attr("B_DISK_DEVICE_WRITE_ONCE") = 0x08;//py::cast(B_DISK_DEVICE_WRITE_ONCE); +m.attr("B_DISK_DEVICE_IS_FILE") = 0x10;//py::cast(B_DISK_DEVICE_IS_FILE); + +m.attr("B_DISK_SYSTEM_IS_FILE_SYSTEM") = 0x000001;//py::cast(B_DISK_SYSTEM_IS_FILE_SYSTEM); +m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING") = 0x000002;//py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING); +m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING") = 0x000004;//py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING); +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING") = 0x000008;//py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING); +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING") = 0x000010;//py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME") = 0x000020;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS") = 0x000040;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS); +m.attr("B_DISK_SYSTEM_SUPPORTS_INITIALIZING") = 0x000080;//py::cast(B_DISK_SYSTEM_SUPPORTS_INITIALIZING); +m.attr("B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME") = 0x000100;//py::cast(B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME); +m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING") = 0x001000;//py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING); +m.attr("B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED") = 0x002000;//py::cast(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED") = 0x004000;//py::cast(B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED") = 0x008000;//py::cast(B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED") = 0x010000;//py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED") = 0x020000;//py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED") = 0x040000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED") = 0x080000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED); +m.attr("B_DISK_SYSTEM_SUPPORTS_WRITING") = 0x100000;//py::cast(B_DISK_SYSTEM_SUPPORTS_WRITING); +m.attr("B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD") = 0x001000;//py::cast(B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD") = 0x002000;//py::cast(B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_NAME") = 0x004000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_NAME); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE") = 0x008000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); +m.attr("B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS") = 0x010000;//py::cast(B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); +m.attr("B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD") = 0x020000;//py::cast(B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD") = 0x040000;//py::cast(B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD); +m.attr("B_DISK_SYSTEM_SUPPORTS_NAME") = 0x080000;//py::cast(B_DISK_SYSTEM_SUPPORTS_NAME); + +m.attr("B_DISK_DEVICE_JOB_BAD_TYPE") = 0;//py::cast(B_DISK_DEVICE_JOB_BAD_TYPE); +m.attr("B_DISK_DEVICE_JOB_DEFRAGMENT") = 1;//py::cast(B_DISK_DEVICE_JOB_DEFRAGMENT); +m.attr("B_DISK_DEVICE_JOB_REPAIR") = 2;//py::cast(B_DISK_DEVICE_JOB_REPAIR); +m.attr("B_DISK_DEVICE_JOB_RESIZE") = 3;//py::cast(B_DISK_DEVICE_JOB_RESIZE); +m.attr("B_DISK_DEVICE_JOB_MOVE") = 4;//py::cast(B_DISK_DEVICE_JOB_MOVE); +m.attr("B_DISK_DEVICE_JOB_SET_NAME") = 5;//py::cast(B_DISK_DEVICE_JOB_SET_NAME); +m.attr("B_DISK_DEVICE_JOB_SET_CONTENT_NAME") = 6;//py::cast(B_DISK_DEVICE_JOB_SET_CONTENT_NAME); +m.attr("B_DISK_DEVICE_JOB_SET_TYPE") = 7;//py::cast(B_DISK_DEVICE_JOB_SET_TYPE); +m.attr("B_DISK_DEVICE_JOB_SET_PARAMETERS") = 8;//py::cast(B_DISK_DEVICE_JOB_SET_PARAMETERS); +m.attr("B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS") = 9;//py::cast(B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS); +m.attr("B_DISK_DEVICE_JOB_INITIALIZE") = 10;//py::cast(B_DISK_DEVICE_JOB_INITIALIZE); +m.attr("B_DISK_DEVICE_JOB_UNINITIALIZE") = 11;//py::cast(B_DISK_DEVICE_JOB_UNINITIALIZE); +m.attr("B_DISK_DEVICE_JOB_CREATE") = 12;//py::cast(B_DISK_DEVICE_JOB_CREATE); +m.attr("B_DISK_DEVICE_JOB_DELETE") = 13;//py::cast(B_DISK_DEVICE_JOB_DELETE); +m.attr("B_DISK_DEVICE_JOB_SCAN") = 14;//py::cast(B_DISK_DEVICE_JOB_SCAN); + +m.attr("B_DISK_DEVICE_JOB_UNINITIALIZED") = 0;//py::cast(B_DISK_DEVICE_JOB_UNINITIALIZED); +m.attr("B_DISK_DEVICE_JOB_SCHEDULED") = 1;//py::cast(B_DISK_DEVICE_JOB_SCHEDULED); +m.attr("B_DISK_DEVICE_JOB_IN_PROGRESS") = 2;//py::cast(B_DISK_DEVICE_JOB_IN_PROGRESS); +m.attr("B_DISK_DEVICE_JOB_SUCCEEDED") = 3;//py::cast(B_DISK_DEVICE_JOB_SUCCEEDED); +m.attr("B_DISK_DEVICE_JOB_FAILED") = 4;//py::cast(B_DISK_DEVICE_JOB_FAILED); +m.attr("B_DISK_DEVICE_JOB_CANCELED") = 5;//py::cast(B_DISK_DEVICE_JOB_CANCELED); + +m.attr("B_DISK_DEVICE_JOB_CAN_CANCEL") = 0x01;//py::cast(B_DISK_DEVICE_JOB_CAN_CANCEL); +m.attr("B_DISK_DEVICE_JOB_STOP_ON_CANCEL") = 0x02;//py::cast(B_DISK_DEVICE_JOB_STOP_ON_CANCEL); +m.attr("B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL") = 0x04;//py::cast(B_DISK_DEVICE_JOB_REVERSE_ON_CANCEL); +m.attr("B_DISK_DEVICE_JOB_CAN_PAUSE") = 0x08;//py::cast(B_DISK_DEVICE_JOB_CAN_PAUSE); + +py::enum_(m, "B_PARAMETER_EDITOR_TYPE", "") +.value("B_CREATE_PARAMETER_EDITOR", B_PARAMETER_EDITOR_TYPE::B_CREATE_PARAMETER_EDITOR, "") +.value("B_INITIALIZE_PARAMETER_EDITOR", B_PARAMETER_EDITOR_TYPE::B_INITIALIZE_PARAMETER_EDITOR, "") +.value("B_DELETE_PARAMETER_EDITOR", B_PARAMETER_EDITOR_TYPE::B_DELETE_PARAMETER_EDITOR, "") +.value("B_PROPERTIES_PARAMETER_EDITOR", B_PARAMETER_EDITOR_TYPE::B_PROPERTIES_PARAMETER_EDITOR, "") +.export_values(); + +py::class_(m, "disk_device_job_progress_info") +.def_readwrite("status", &disk_device_job_progress_info::status, "") +.def_readwrite("interrupt_properties", &disk_device_job_progress_info::interrupt_properties, "") +.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_readonly("current_task_description", &disk_device_job_progress_info::current_task_description, "") //todo: should this be writable? +; + + +} diff --git a/bindings/storage/Entry.cpp b/bindings/storage/Entry.cpp new file mode 100644 index 0000000..f563a5e --- /dev/null +++ b/bindings/storage/Entry.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Entry,m) +{ +py::class_(m, "entry_ref") +.def(py::init(), "") +.def(py::init(), "", py::arg("dev"), py::arg("dir"), py::arg("name")) +.def(py::init(), "", py::arg("ref")) +.def("set_name", &entry_ref::set_name, "", py::arg("name")) +.def("__eq__", &entry_ref::operator==, "", py::arg("ref")) +.def("__ne__", &entry_ref::operator!=, "", py::arg("ref")) +.def("operator=", &entry_ref::operator=, "", py::arg("ref")) +.def_readwrite("device", &entry_ref::device, "") +.def_readwrite("directory", &entry_ref::directory, "") +.def_readwrite("name", &entry_ref::name, "") +; + +py::class_(m, "BEntry") +.def(py::init(), "") +.def(py::init(), "", py::arg("dir"), py::arg("path"), py::arg("traverse")=false) +.def(py::init(), "", py::arg("ref"), py::arg("traverse")=false) +.def(py::init(), "", py::arg("path"), py::arg("traverse")=false) +.def(py::init(), "", py::arg("entry")) +.def("InitCheck", &BEntry::InitCheck, "") +.def("Exists", &BEntry::Exists, "") +.def("Name", &BEntry::Name, "") +.def("GetStat", &BEntry::GetStat, "", py::arg("stat")) /* +TODO: GetStat writes the result into stat argument, a struct stat variable we should define before calling this function. +this is a C++ struct and we should provide a way for python to read it. So we wrote stat.cpp. In stat struct we have also some +timespec variables, which type is unknow to python, so we should provide a way to read a timespec. This is actually undone. +*/ +.def("SetTo", py::overload_cast(&BEntry::SetTo), "", py::arg("dir"), py::arg("path"), py::arg("traverse")=false) +.def("SetTo", py::overload_cast(&BEntry::SetTo), "", py::arg("ref"), py::arg("traverse")=false) +.def("SetTo", py::overload_cast(&BEntry::SetTo), "", py::arg("path"), py::arg("traverse")=false) +.def("Unset", &BEntry::Unset, "") +.def("GetRef", &BEntry::GetRef, "",py::arg("ref")) +.def("GetPath", &BEntry::GetPath, "",py::arg("path")) +.def("GetParent", py::overload_cast(&BEntry::GetParent, py::const_), "",py::arg("entry")) +.def("GetParent", py::overload_cast(&BEntry::GetParent, py::const_), "",py::arg("dir")) +//.def("GetName", &BEntry::GetName, "", py::arg("buffer")) +.def("GetName", [](BEntry& self)->py::tuple { + char name[B_FILE_NAME_LENGTH]; + status_t ret=self.GetName(name); + py::str filename(name); + return py::make_tuple(ret,filename); +},"") +.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) +.def("Remove", &BEntry::Remove, "") +.def("__eq__", &BEntry::operator==, "", py::arg("item")) +.def("__ne__", &BEntry::operator!=, "", py::arg("item")) +.def("operator=", &BEntry::operator=, "", py::arg("item")) +; + +m.def("get_ref_for_path", &get_ref_for_path, "", py::arg("path"), py::arg("ref")); + +m.def("__lt__", &operator<, "", py::arg("a"), py::arg("b")); + +} diff --git a/bindings/storage/EntryList.cpp b/bindings/storage/EntryList.cpp new file mode 100644 index 0000000..7434303 --- /dev/null +++ b/bindings/storage/EntryList.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#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); + } +}; + +PYBIND11_MODULE(EntryList, m) +{ +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")) +.def("GetNextDirents", &BEntryList::GetNextDirents, "", py::arg("direntBuffer"), py::arg("bufferSize"), py::arg("maxEntries")=INT_MAX) +.def("Rewind", &BEntryList::Rewind, "") +.def("CountEntries", &BEntryList::CountEntries, "") +; + + +} diff --git a/bindings/storage/File.cpp b/bindings/storage/File.cpp new file mode 100644 index 0000000..143a5d0 --- /dev/null +++ b/bindings/storage/File.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#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); + } +}; + +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("IsReadable", &BFile::IsReadable, "") +.def("IsWritable", &BFile::IsWritable, "") +//.def("Read", &BFile::Read, "", py::arg("buffer"), py::arg("size")) +.def("Read",[](BFile& self, size_t size)->py::tuple{ + std::vectorbuffer(size); + ssize_t bytesRead = self.Read(buffer.data(), size); + py::bytes pyBytes(buffer.data(),bytesRead); + return py::make_tuple(pyBytes, bytesRead); +},"", py::arg("size")) +//.def("ReadAt", &BFile::ReadAt, "", py::arg("location"), py::arg("buffer"), py::arg("size")) +.def("ReadAt", [](BFile& self, off_t location, size_t size)->py::tuple{ + std::vectorbuffer(size); + ssize_t bytesRead = self.ReadAt(location, buffer.data(), size); + py::bytes pyBytes(buffer.data(),bytesRead); + return py::make_tuple(pyBytes, bytesRead); +},"", py::arg("location"),py::arg("size")) +//.def("Write", &BFile::Write, "", py::arg("buffer"), py::arg("size")) +.def("Write", [](BFile& self, py::buffer buffer){ + py::buffer_info info = buffer.request(); + const void* data = info.ptr; + size_t length = info.size; + return self.Write(data,length); +}, "",py::arg("buffer")) +//.def("WriteAt", &BFile::WriteAt, "", py::arg("location"), py::arg("buffer"), py::arg("size")) +.def("WriteAt", [](BFile& self, off_t location, py::buffer buffer){ + py::buffer_info info = buffer.request(); + const void* data = info.ptr; + size_t length = info.size; + return self.WriteAt(location,data,length); +}, "",py::arg("location"),py::arg("buffer")) +.def("Seek", &BFile::Seek, "", py::arg("offset"), py::arg("seekMode")) +.def("Position", &BFile::Position, "") +.def("SetSize", &BFile::SetSize, "", py::arg("size")) +//.def("GetSize", &BFile::GetSize, "", py::arg("size")) +.def("GetSize", [](BFile& self)->py::tuple{ + off_t size; + status_t ret = self.GetSize(&size); + return py::make_tuple(ret,size); +}, "") +.def("operator=", &BFile::operator=, "", py::arg("file")) +; + + +} diff --git a/bindings/storage/FilePanel.cpp b/bindings/storage/FilePanel.cpp new file mode 100644 index 0000000..a9b7ea4 --- /dev/null +++ b/bindings/storage/FilePanel.cpp @@ -0,0 +1,87 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +//#include + +namespace py = pybind11; + + +class PyBRefFilter : public BRefFilter { +public: + using BRefFilter::BRefFilter; + bool Filter(const entry_ref* ref, BNode* node, struct stat_beos* stat, const char* mimeType) override { + PYBIND11_OVERLOAD(bool, BRefFilter, Filter, ref, node, stat, mimeType); + } +}; + +class PyBFilePanel : public BFilePanel { +public: + using BFilePanel::BFilePanel; + void WasHidden() override { + PYBIND11_OVERLOAD(void, BFilePanel, WasHidden); + } + void SelectionChanged() override { + PYBIND11_OVERLOAD(void, BFilePanel, SelectionChanged); + } + void SendMessage(const BMessenger* target, BMessage* message) override { + PYBIND11_OVERLOAD(void, BFilePanel, SendMessage, target, message); + } +}; + +PYBIND11_MODULE(FilePanel, m) +{ +py::enum_(m, "file_panel_mode", "") +.value("B_OPEN_PANEL", file_panel_mode::B_OPEN_PANEL, "") +.value("B_SAVE_PANEL", file_panel_mode::B_SAVE_PANEL, "") +.export_values(); + +py::enum_(m, "file_panel_button", "") +.value("B_CANCEL_BUTTON", file_panel_button::B_CANCEL_BUTTON, "") +.value("B_DEFAULT_BUTTON", file_panel_button::B_DEFAULT_BUTTON, "") +.export_values(); + +py::class_(m, "BRefFilter") +//.def(py::init<>(),"") +.def("Filter", &BRefFilter::Filter, "", py::arg("ref"), py::arg("node"), py::arg("stat"), py::arg("mimeType")) +; + +py::class_(m, "BFilePanel") +.def(py::init(), "", py::arg("mode")=file_panel_mode::B_OPEN_PANEL, py::arg("target")=NULL, py::arg("directory")=NULL, py::arg("nodeFlavors")=0, py::arg("allowMultipleSelection")=true, + py::arg("message")=NULL, py::arg("refFilter")=NULL, py::arg("modal")=false, py::arg("hideWhenDone")=true) +.def("Show", &BFilePanel::Show, "") +.def("Hide", &BFilePanel::Hide, "") +.def("IsShowing", &BFilePanel::IsShowing, "") +.def("WasHidden", &BFilePanel::WasHidden, "") +.def("SelectionChanged", &BFilePanel::SelectionChanged, "") +.def("SendMessage", &BFilePanel::SendMessage, "", py::arg("target"), py::arg("message")) +.def("Window", &BFilePanel::Window, "") +.def("Messenger", &BFilePanel::Messenger, "") +.def("RefFilter", &BFilePanel::RefFilter, "") +.def("PanelMode", &BFilePanel::PanelMode, "") +.def("SetTarget", &BFilePanel::SetTarget, "", py::arg("target")) +.def("SetMessage", &BFilePanel::SetMessage, "", py::arg("message")) +.def("SetRefFilter", &BFilePanel::SetRefFilter, "", py::arg("filter")) +.def("SetSaveText", &BFilePanel::SetSaveText, "", py::arg("text")) +.def("SetButtonLabel", &BFilePanel::SetButtonLabel, "", py::arg("button"), py::arg("label")) +.def("SetNodeFlavors", &BFilePanel::SetNodeFlavors, "", py::arg("flavors")) +.def("SetPanelDirectory", py::overload_cast(&BFilePanel::SetPanelDirectory), "", py::arg("newDirectory")) +.def("SetPanelDirectory", py::overload_cast(&BFilePanel::SetPanelDirectory), "", py::arg("newDirectory")) +.def("SetPanelDirectory", py::overload_cast(&BFilePanel::SetPanelDirectory), "", py::arg("newDirectory")) +.def("SetPanelDirectory", py::overload_cast(&BFilePanel::SetPanelDirectory), "", py::arg("newDirectory")) +.def("GetPanelDirectory", &BFilePanel::GetPanelDirectory, "", py::arg("ref")) +.def("SetHideWhenDone", &BFilePanel::SetHideWhenDone, "", py::arg("hideWhenDone")) +.def("HidesWhenDone", &BFilePanel::HidesWhenDone, "") +.def("Refresh", &BFilePanel::Refresh, "") +.def("Rewind", &BFilePanel::Rewind, "") +.def("GetNextSelectedRef", &BFilePanel::GetNextSelectedRef, "", py::arg("ref")) +; + + +} diff --git a/bindings/storage/FindDirectory.cpp b/bindings/storage/FindDirectory.cpp new file mode 100644 index 0000000..ba30852 --- /dev/null +++ b/bindings/storage/FindDirectory.cpp @@ -0,0 +1,303 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(FindDirectory, m) +{ +/* +py::enum_(m, "directory_which", "") +.value("B_DESKTOP_DIRECTORY",0, "") +.value("B_TRASH_DIRECTORY", 1, "") +.value("B_SYSTEM_DIRECTORY", 1000, "") +.value("B_SYSTEM_ADDONS_DIRECTORY", 1002, "") +.value("B_SYSTEM_BOOT_DIRECTORY", 1003, "") +.value("B_SYSTEM_FONTS_DIRECTORY", 1004, "") +.value("B_SYSTEM_LIB_DIRECTORY", 1005, "") +.value("B_SYSTEM_SERVERS_DIRECTORY", 1006, "") +.value("B_SYSTEM_APPS_DIRECTORY", 1007, "") +.value("B_SYSTEM_BIN_DIRECTORY", 1008, "") +.value("B_SYSTEM_DOCUMENTATION_DIRECTORY", 1010, "") +.value("B_SYSTEM_PREFERENCES_DIRECTORY", 1011, "") +.value("B_SYSTEM_TRANSLATORS_DIRECTORY", 1012, "") +.value("B_SYSTEM_MEDIA_NODES_DIRECTORY", 1013, "") +.value("B_SYSTEM_SOUNDS_DIRECTORY", 1014, "") +.value("B_SYSTEM_DATA_DIRECTORY", 1015, "") +.value("B_SYSTEM_DEVELOP_DIRECTORY", 1016, "") +.value("B_SYSTEM_PACKAGES_DIRECTORY", 1017, "") +.value("B_SYSTEM_HEADERS_DIRECTORY", 1018, "") +.value("B_SYSTEM_ETC_DIRECTORY", 2008, "") +.value("B_SYSTEM_SETTINGS_DIRECTORY", 2010, "") +.value("B_SYSTEM_LOG_DIRECTORY", 2012, "") +.value("B_SYSTEM_SPOOL_DIRECTORY", 2013, "") +.value("B_SYSTEM_TEMP_DIRECTORY", 2014, "") +.value("B_SYSTEM_VAR_DIRECTORY", 2015, "") +.value("B_SYSTEM_CACHE_DIRECTORY", 2020, "") +.value("B_SYSTEM_NONPACKAGED_DIRECTORY", 2023, "") +.value("B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY", 2024, "") +.value("B_SYSTEM_NONPACKAGED_TRANSLATORS_DIRECTORY", 2025, "") +.value("B_SYSTEM_NONPACKAGED_MEDIA_NODES_DIRECTORY", 2026, "") +.value("B_SYSTEM_NONPACKAGED_BIN_DIRECTORY", 2027, "") +.value("B_SYSTEM_NONPACKAGED_DATA_DIRECTORY", 2028, "") +.value("B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY", 2029, "") +.value("B_SYSTEM_NONPACKAGED_SOUNDS_DIRECTORY", 2030, "") +.value("B_SYSTEM_NONPACKAGED_DOCUMENTATION_DIRECTORY", 2031, "") +.value("B_SYSTEM_NONPACKAGED_LIB_DIRECTORY", 2032, "") +.value("B_SYSTEM_NONPACKAGED_HEADERS_DIRECTORY", 2033, "") +.value("B_SYSTEM_NONPACKAGED_DEVELOP_DIRECTORY", 2034, "") +.value("B_USER_DIRECTORY", 3000, "") +.value("B_USER_CONFIG_DIRECTORY", 3001, "") +.value("B_USER_ADDONS_DIRECTORY", 3002, "") +.value("B_USER_BOOT_DIRECTORY", 3003, "") +.value("B_USER_FONTS_DIRECTORY", 3004, "") +.value("B_USER_LIB_DIRECTORY", 3005, "") +.value("B_USER_SETTINGS_DIRECTORY", 3006, "") +.value("B_USER_DESKBAR_DIRECTORY", 3007, "") +.value("B_USER_PRINTERS_DIRECTORY", 3008, "") +.value("B_USER_TRANSLATORS_DIRECTORY", 3009, "") +.value("B_USER_MEDIA_NODES_DIRECTORY", 3010, "") +.value("B_USER_SOUNDS_DIRECTORY", 3011, "") +.value("B_USER_DATA_DIRECTORY", 3012, "") +.value("B_USER_CACHE_DIRECTORY", 3013, "") +.value("B_USER_PACKAGES_DIRECTORY", 3014, "") +.value("B_USER_HEADERS_DIRECTORY", 3015, "") +.value("B_USER_NONPACKAGED_DIRECTORY", 3016, "") +.value("B_USER_NONPACKAGED_ADDONS_DIRECTORY", 3017, "") +.value("B_USER_NONPACKAGED_TRANSLATORS_DIRECTORY", 3018, "") +.value("B_USER_NONPACKAGED_MEDIA_NODES_DIRECTORY", 3019, "") +.value("B_USER_NONPACKAGED_BIN_DIRECTORY", 3020, "") +.value("B_USER_NONPACKAGED_DATA_DIRECTORY", 3021, "") +.value("B_USER_NONPACKAGED_FONTS_DIRECTORY", 3022, "") +.value("B_USER_NONPACKAGED_SOUNDS_DIRECTORY", 3023, "") +.value("B_USER_NONPACKAGED_DOCUMENTATION_DIRECTORY", 3024, "") +.value("B_USER_NONPACKAGED_LIB_DIRECTORY", 3025, "") +.value("B_USER_NONPACKAGED_HEADERS_DIRECTORY", 3026, "") +.value("B_USER_NONPACKAGED_DEVELOP_DIRECTORY", 3027, "") +.value("B_USER_DEVELOP_DIRECTORY", 3028, "") +.value("B_USER_DOCUMENTATION_DIRECTORY", 3029, "") +.value("B_USER_SERVERS_DIRECTORY", 3030, "") +.value("B_USER_APPS_DIRECTORY", 3031, "") +.value("B_USER_BIN_DIRECTORY", 3032, "") +.value("B_USER_PREFERENCES_DIRECTORY", 3033, "") +.value("B_USER_ETC_DIRECTORY", 3034, "") +.value("B_USER_LOG_DIRECTORY", 3035, "") +.value("B_USER_SPOOL_DIRECTORY", 3036, "") +.value("B_USER_VAR_DIRECTORY", 3037, "") +.value("B_APPS_DIRECTORY", 4000, "") +.value("B_PREFERENCES_DIRECTORY", 4001, "") +.value("B_UTILITIES_DIRECTORY", 4002, "") +.value("B_PACKAGE_LINKS_DIRECTORY", 4003, "") +.value("B_BEOS_DIRECTORY", 1000, "") +.value("B_BEOS_SYSTEM_DIRECTORY", 1001, "") +.value("B_BEOS_ADDONS_DIRECTORY", 1002, "") +.value("B_BEOS_BOOT_DIRECTORY", 1003, "") +.value("B_BEOS_FONTS_DIRECTORY", 1004, "") +.value("B_BEOS_LIB_DIRECTORY", 1005, "") +.value("B_BEOS_SERVERS_DIRECTORY", 1006, "") +.value("B_BEOS_APPS_DIRECTORY", 1007, "") +.value("B_BEOS_BIN_DIRECTORY", 1008, "") +.value("B_BEOS_ETC_DIRECTORY", 1009, "") +.value("B_BEOS_DOCUMENTATION_DIRECTORY", 1010, "") +.value("B_BEOS_PREFERENCES_DIRECTORY", 1011, "") +.value("B_BEOS_TRANSLATORS_DIRECTORY", 1012, "") +.value("B_BEOS_MEDIA_NODES_DIRECTORY", 1013, "") +.value("B_BEOS_SOUNDS_DIRECTORY", 1014, "") +.export_values();*/ + + +py::enum_(m, "directory_which", "") +.value("B_DESKTOP_DIRECTORY", directory_which::B_DESKTOP_DIRECTORY, "") +.value("B_TRASH_DIRECTORY", directory_which::B_TRASH_DIRECTORY, "") +.value("B_SYSTEM_DIRECTORY", directory_which::B_SYSTEM_DIRECTORY, "") +.value("B_SYSTEM_ADDONS_DIRECTORY", directory_which::B_SYSTEM_ADDONS_DIRECTORY, "") +.value("B_SYSTEM_BOOT_DIRECTORY", directory_which::B_SYSTEM_BOOT_DIRECTORY, "") +.value("B_SYSTEM_FONTS_DIRECTORY", directory_which::B_SYSTEM_FONTS_DIRECTORY, "") +.value("B_SYSTEM_LIB_DIRECTORY", directory_which::B_SYSTEM_LIB_DIRECTORY, "") +.value("B_SYSTEM_SERVERS_DIRECTORY", directory_which::B_SYSTEM_SERVERS_DIRECTORY, "") +.value("B_SYSTEM_APPS_DIRECTORY", directory_which::B_SYSTEM_APPS_DIRECTORY, "") +.value("B_SYSTEM_BIN_DIRECTORY", directory_which::B_SYSTEM_BIN_DIRECTORY, "") +.value("B_SYSTEM_DOCUMENTATION_DIRECTORY", directory_which::B_SYSTEM_DOCUMENTATION_DIRECTORY, "") +.value("B_SYSTEM_PREFERENCES_DIRECTORY", directory_which::B_SYSTEM_PREFERENCES_DIRECTORY, "") +.value("B_SYSTEM_TRANSLATORS_DIRECTORY", directory_which::B_SYSTEM_TRANSLATORS_DIRECTORY, "") +.value("B_SYSTEM_MEDIA_NODES_DIRECTORY", directory_which::B_SYSTEM_MEDIA_NODES_DIRECTORY, "") +.value("B_SYSTEM_SOUNDS_DIRECTORY", directory_which::B_SYSTEM_SOUNDS_DIRECTORY, "") +.value("B_SYSTEM_DATA_DIRECTORY", directory_which::B_SYSTEM_DATA_DIRECTORY, "") +.value("B_SYSTEM_DEVELOP_DIRECTORY", directory_which::B_SYSTEM_DEVELOP_DIRECTORY, "") +.value("B_SYSTEM_PACKAGES_DIRECTORY", directory_which::B_SYSTEM_PACKAGES_DIRECTORY, "") +.value("B_SYSTEM_HEADERS_DIRECTORY", directory_which::B_SYSTEM_HEADERS_DIRECTORY, "") +.value("B_SYSTEM_ETC_DIRECTORY", directory_which::B_SYSTEM_ETC_DIRECTORY, "") +.value("B_SYSTEM_SETTINGS_DIRECTORY", directory_which::B_SYSTEM_SETTINGS_DIRECTORY, "") +.value("B_SYSTEM_LOG_DIRECTORY", directory_which::B_SYSTEM_LOG_DIRECTORY, "") +.value("B_SYSTEM_SPOOL_DIRECTORY", directory_which::B_SYSTEM_SPOOL_DIRECTORY, "") +.value("B_SYSTEM_TEMP_DIRECTORY", directory_which::B_SYSTEM_TEMP_DIRECTORY, "") +.value("B_SYSTEM_VAR_DIRECTORY", directory_which::B_SYSTEM_VAR_DIRECTORY, "") +.value("B_SYSTEM_CACHE_DIRECTORY", directory_which::B_SYSTEM_CACHE_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_TRANSLATORS_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_TRANSLATORS_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_MEDIA_NODES_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_MEDIA_NODES_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_BIN_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_BIN_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_DATA_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_DATA_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_SOUNDS_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_SOUNDS_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_DOCUMENTATION_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_DOCUMENTATION_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_LIB_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_LIB_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_HEADERS_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_HEADERS_DIRECTORY, "") +.value("B_SYSTEM_NONPACKAGED_DEVELOP_DIRECTORY", directory_which::B_SYSTEM_NONPACKAGED_DEVELOP_DIRECTORY, "") +.value("B_USER_DIRECTORY", directory_which::B_USER_DIRECTORY, "") +.value("B_USER_CONFIG_DIRECTORY", directory_which::B_USER_CONFIG_DIRECTORY, "") +.value("B_USER_ADDONS_DIRECTORY", directory_which::B_USER_ADDONS_DIRECTORY, "") +.value("B_USER_BOOT_DIRECTORY", directory_which::B_USER_BOOT_DIRECTORY, "") +.value("B_USER_FONTS_DIRECTORY", directory_which::B_USER_FONTS_DIRECTORY, "") +.value("B_USER_LIB_DIRECTORY", directory_which::B_USER_LIB_DIRECTORY, "") +.value("B_USER_SETTINGS_DIRECTORY", directory_which::B_USER_SETTINGS_DIRECTORY, "") +.value("B_USER_DESKBAR_DIRECTORY", directory_which::B_USER_DESKBAR_DIRECTORY, "") +.value("B_USER_PRINTERS_DIRECTORY", directory_which::B_USER_PRINTERS_DIRECTORY, "") +.value("B_USER_TRANSLATORS_DIRECTORY", directory_which::B_USER_TRANSLATORS_DIRECTORY, "") +.value("B_USER_MEDIA_NODES_DIRECTORY", directory_which::B_USER_MEDIA_NODES_DIRECTORY, "") +.value("B_USER_SOUNDS_DIRECTORY", directory_which::B_USER_SOUNDS_DIRECTORY, "") +.value("B_USER_DATA_DIRECTORY", directory_which::B_USER_DATA_DIRECTORY, "") +.value("B_USER_CACHE_DIRECTORY", directory_which::B_USER_CACHE_DIRECTORY, "") +.value("B_USER_PACKAGES_DIRECTORY", directory_which::B_USER_PACKAGES_DIRECTORY, "") +.value("B_USER_HEADERS_DIRECTORY", directory_which::B_USER_HEADERS_DIRECTORY, "") +.value("B_USER_NONPACKAGED_DIRECTORY", directory_which::B_USER_NONPACKAGED_DIRECTORY, "") +.value("B_USER_NONPACKAGED_ADDONS_DIRECTORY", directory_which::B_USER_NONPACKAGED_ADDONS_DIRECTORY, "") +.value("B_USER_NONPACKAGED_TRANSLATORS_DIRECTORY", directory_which::B_USER_NONPACKAGED_TRANSLATORS_DIRECTORY, "") +.value("B_USER_NONPACKAGED_MEDIA_NODES_DIRECTORY", directory_which::B_USER_NONPACKAGED_MEDIA_NODES_DIRECTORY, "") +.value("B_USER_NONPACKAGED_BIN_DIRECTORY", directory_which::B_USER_NONPACKAGED_BIN_DIRECTORY, "") +.value("B_USER_NONPACKAGED_DATA_DIRECTORY", directory_which::B_USER_NONPACKAGED_DATA_DIRECTORY, "") +.value("B_USER_NONPACKAGED_FONTS_DIRECTORY", directory_which::B_USER_NONPACKAGED_FONTS_DIRECTORY, "") +.value("B_USER_NONPACKAGED_SOUNDS_DIRECTORY", directory_which::B_USER_NONPACKAGED_SOUNDS_DIRECTORY, "") +.value("B_USER_NONPACKAGED_DOCUMENTATION_DIRECTORY", directory_which::B_USER_NONPACKAGED_DOCUMENTATION_DIRECTORY, "") +.value("B_USER_NONPACKAGED_LIB_DIRECTORY", directory_which::B_USER_NONPACKAGED_LIB_DIRECTORY, "") +.value("B_USER_NONPACKAGED_HEADERS_DIRECTORY", directory_which::B_USER_NONPACKAGED_HEADERS_DIRECTORY, "") +.value("B_USER_NONPACKAGED_DEVELOP_DIRECTORY", directory_which::B_USER_NONPACKAGED_DEVELOP_DIRECTORY, "") +.value("B_USER_DEVELOP_DIRECTORY", directory_which::B_USER_DEVELOP_DIRECTORY, "") +.value("B_USER_DOCUMENTATION_DIRECTORY", directory_which::B_USER_DOCUMENTATION_DIRECTORY, "") +.value("B_USER_SERVERS_DIRECTORY", directory_which::B_USER_SERVERS_DIRECTORY, "") +.value("B_USER_APPS_DIRECTORY", directory_which::B_USER_APPS_DIRECTORY, "") +.value("B_USER_BIN_DIRECTORY", directory_which::B_USER_BIN_DIRECTORY, "") +.value("B_USER_PREFERENCES_DIRECTORY", directory_which::B_USER_PREFERENCES_DIRECTORY, "") +.value("B_USER_ETC_DIRECTORY", directory_which::B_USER_ETC_DIRECTORY, "") +.value("B_USER_LOG_DIRECTORY", directory_which::B_USER_LOG_DIRECTORY, "") +.value("B_USER_SPOOL_DIRECTORY", directory_which::B_USER_SPOOL_DIRECTORY, "") +.value("B_USER_VAR_DIRECTORY", directory_which::B_USER_VAR_DIRECTORY, "") +.value("B_APPS_DIRECTORY", directory_which::B_APPS_DIRECTORY, "") +.value("B_PREFERENCES_DIRECTORY", directory_which::B_PREFERENCES_DIRECTORY, "") +.value("B_UTILITIES_DIRECTORY", directory_which::B_UTILITIES_DIRECTORY, "") +.value("B_PACKAGE_LINKS_DIRECTORY", directory_which::B_PACKAGE_LINKS_DIRECTORY, "") +.value("B_BEOS_DIRECTORY", directory_which::B_BEOS_DIRECTORY, "") +.value("B_BEOS_SYSTEM_DIRECTORY", directory_which::B_BEOS_SYSTEM_DIRECTORY, "") +.value("B_BEOS_ADDONS_DIRECTORY", directory_which::B_BEOS_ADDONS_DIRECTORY, "") +.value("B_BEOS_BOOT_DIRECTORY", directory_which::B_BEOS_BOOT_DIRECTORY, "") +.value("B_BEOS_FONTS_DIRECTORY", directory_which::B_BEOS_FONTS_DIRECTORY, "") +.value("B_BEOS_LIB_DIRECTORY", directory_which::B_BEOS_LIB_DIRECTORY, "") +.value("B_BEOS_SERVERS_DIRECTORY", directory_which::B_BEOS_SERVERS_DIRECTORY, "") +.value("B_BEOS_APPS_DIRECTORY", directory_which::B_BEOS_APPS_DIRECTORY, "") +.value("B_BEOS_BIN_DIRECTORY", directory_which::B_BEOS_BIN_DIRECTORY, "") +.value("B_BEOS_ETC_DIRECTORY", directory_which::B_BEOS_ETC_DIRECTORY, "") +.value("B_BEOS_DOCUMENTATION_DIRECTORY", directory_which::B_BEOS_DOCUMENTATION_DIRECTORY, "") +.value("B_BEOS_PREFERENCES_DIRECTORY", directory_which::B_BEOS_PREFERENCES_DIRECTORY, "") +.value("B_BEOS_TRANSLATORS_DIRECTORY", directory_which::B_BEOS_TRANSLATORS_DIRECTORY, "") +.value("B_BEOS_MEDIA_NODES_DIRECTORY", directory_which::B_BEOS_MEDIA_NODES_DIRECTORY, "") +.value("B_BEOS_SOUNDS_DIRECTORY", directory_which::B_BEOS_SOUNDS_DIRECTORY, "") +.export_values(); + +/* These are hardcoded +m.attr("B_FIND_PATH_CREATE_DIRECTORY") = py::cast(B_FIND_PATH_CREATE_DIRECTORY); +m.attr("B_FIND_PATH_CREATE_PARENT_DIRECTORY") = py::cast(B_FIND_PATH_CREATE_PARENT_DIRECTORY); +m.attr("B_FIND_PATH_EXISTING_ONLY") = py::cast(B_FIND_PATH_EXISTING_ONLY); +m.attr("B_FIND_PATHS_SYSTEM_ONLY") = py::cast(B_FIND_PATHS_SYSTEM_ONLY); +m.attr("B_FIND_PATHS_USER_ONLY") = py::cast(B_FIND_PATHS_USER_ONLY); +*/ +m.attr("B_FIND_PATH_CREATE_DIRECTORY") = 0x0001; +m.attr("B_FIND_PATH_CREATE_PARENT_DIRECTORY") = 0x0002; +m.attr("B_FIND_PATH_EXISTING_ONLY") = 0x0004; +m.attr("B_FIND_PATHS_SYSTEM_ONLY") = 0x0010; +m.attr("B_FIND_PATHS_USER_ONLY") = 0x0020; + + +py::enum_(m, "path_base_directory", "") +.value("B_FIND_PATH_INSTALLATION_LOCATION_DIRECTORY", path_base_directory::B_FIND_PATH_INSTALLATION_LOCATION_DIRECTORY, "") +.value("B_FIND_PATH_ADD_ONS_DIRECTORY", path_base_directory::B_FIND_PATH_ADD_ONS_DIRECTORY, "") +.value("B_FIND_PATH_APPS_DIRECTORY", path_base_directory::B_FIND_PATH_APPS_DIRECTORY, "") +.value("B_FIND_PATH_BIN_DIRECTORY", path_base_directory::B_FIND_PATH_BIN_DIRECTORY, "") +.value("B_FIND_PATH_BOOT_DIRECTORY", path_base_directory::B_FIND_PATH_BOOT_DIRECTORY, "") +.value("B_FIND_PATH_CACHE_DIRECTORY", path_base_directory::B_FIND_PATH_CACHE_DIRECTORY, "") +.value("B_FIND_PATH_DATA_DIRECTORY", path_base_directory::B_FIND_PATH_DATA_DIRECTORY, "") +.value("B_FIND_PATH_DEVELOP_DIRECTORY", path_base_directory::B_FIND_PATH_DEVELOP_DIRECTORY, "") +.value("B_FIND_PATH_DEVELOP_LIB_DIRECTORY", path_base_directory::B_FIND_PATH_DEVELOP_LIB_DIRECTORY, "") +.value("B_FIND_PATH_DOCUMENTATION_DIRECTORY", path_base_directory::B_FIND_PATH_DOCUMENTATION_DIRECTORY, "") +.value("B_FIND_PATH_ETC_DIRECTORY", path_base_directory::B_FIND_PATH_ETC_DIRECTORY, "") +.value("B_FIND_PATH_FONTS_DIRECTORY", path_base_directory::B_FIND_PATH_FONTS_DIRECTORY, "") +.value("B_FIND_PATH_HEADERS_DIRECTORY", path_base_directory::B_FIND_PATH_HEADERS_DIRECTORY, "") +.value("B_FIND_PATH_LIB_DIRECTORY", path_base_directory::B_FIND_PATH_LIB_DIRECTORY, "") +.value("B_FIND_PATH_LOG_DIRECTORY", path_base_directory::B_FIND_PATH_LOG_DIRECTORY, "") +.value("B_FIND_PATH_MEDIA_NODES_DIRECTORY", path_base_directory::B_FIND_PATH_MEDIA_NODES_DIRECTORY, "") +.value("B_FIND_PATH_PACKAGES_DIRECTORY", path_base_directory::B_FIND_PATH_PACKAGES_DIRECTORY, "") +.value("B_FIND_PATH_PREFERENCES_DIRECTORY", path_base_directory::B_FIND_PATH_PREFERENCES_DIRECTORY, "") +.value("B_FIND_PATH_SERVERS_DIRECTORY", path_base_directory::B_FIND_PATH_SERVERS_DIRECTORY, "") +.value("B_FIND_PATH_SETTINGS_DIRECTORY", path_base_directory::B_FIND_PATH_SETTINGS_DIRECTORY, "") +.value("B_FIND_PATH_SOUNDS_DIRECTORY", path_base_directory::B_FIND_PATH_SOUNDS_DIRECTORY, "") +.value("B_FIND_PATH_SPOOL_DIRECTORY", path_base_directory::B_FIND_PATH_SPOOL_DIRECTORY, "") +.value("B_FIND_PATH_TRANSLATORS_DIRECTORY", path_base_directory::B_FIND_PATH_TRANSLATORS_DIRECTORY, "") +.value("B_FIND_PATH_VAR_DIRECTORY", path_base_directory::B_FIND_PATH_VAR_DIRECTORY, "") +.value("B_FIND_PATH_IMAGE_PATH", path_base_directory::B_FIND_PATH_IMAGE_PATH, "") +.value("B_FIND_PATH_PACKAGE_PATH", path_base_directory::B_FIND_PATH_PACKAGE_PATH, "") +.export_values(); +/* +py::enum_(m, "path_base_directory", "") +.value("B_FIND_PATH_INSTALLATION_LOCATION_DIRECTORY", 0, "") +.value("B_FIND_PATH_ADD_ONS_DIRECTORY", 1, "") +.value("B_FIND_PATH_APPS_DIRECTORY", 2, "") +.value("B_FIND_PATH_BIN_DIRECTORY", 3, "") +.value("B_FIND_PATH_BOOT_DIRECTORY", 4, "") +.value("B_FIND_PATH_CACHE_DIRECTORY", 5, "") +.value("B_FIND_PATH_DATA_DIRECTORY", 6, "") +.value("B_FIND_PATH_DEVELOP_DIRECTORY", 7, "") +.value("B_FIND_PATH_DEVELOP_LIB_DIRECTORY", 8, "") +.value("B_FIND_PATH_DOCUMENTATION_DIRECTORY", 9, "") +.value("B_FIND_PATH_ETC_DIRECTORY", 10, "") +.value("B_FIND_PATH_FONTS_DIRECTORY", 11, "") +.value("B_FIND_PATH_HEADERS_DIRECTORY", 12, "") +.value("B_FIND_PATH_LIB_DIRECTORY", 13, "") +.value("B_FIND_PATH_LOG_DIRECTORY", 14, "") +.value("B_FIND_PATH_MEDIA_NODES_DIRECTORY", 15, "") +.value("B_FIND_PATH_PACKAGES_DIRECTORY", 16, "") +.value("B_FIND_PATH_PREFERENCES_DIRECTORY", 17, "") +.value("B_FIND_PATH_SERVERS_DIRECTORY", 18, "") +.value("B_FIND_PATH_SETTINGS_DIRECTORY", 19, "") +.value("B_FIND_PATH_SOUNDS_DIRECTORY", 20, "") +.value("B_FIND_PATH_SPOOL_DIRECTORY", 21, "") +.value("B_FIND_PATH_TRANSLATORS_DIRECTORY", 22, "") +.value("B_FIND_PATH_VAR_DIRECTORY", 23, "") +.value("B_FIND_PATH_IMAGE_PATH", 1000, "") +.value("B_FIND_PATH_PACKAGE_PATH", 1001, "") +.export_values();*/ + +//m.attr("BVolume") = py::cast(BVolume); + +m.def("find_directory", py::overload_cast(&find_directory), "", py::arg("which"), py::arg("volume"), py::arg("createIt"), py::arg("pathString"), py::arg("length")); + +m.def("find_path", &find_path, "", py::arg("codePointer"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("pathBuffer"), py::arg("bufferSize")); + +m.def("find_path_etc", &find_path_etc, "", py::arg("codePointer"), py::arg("dependency"), py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags"), py::arg("pathBuffer"), py::arg("bufferSize")); + +m.def("find_path_for_path", &find_path_for_path, "", py::arg("path"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("pathBuffer"), py::arg("bufferSize")); + +m.def("find_path_for_path_etc", &find_path_for_path_etc, "", py::arg("path"), py::arg("dependency"), py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags"), py::arg("pathBuffer"), py::arg("bufferSize")); + +//m.def("find_paths", &find_paths, "", py::arg("baseDirectory"), py::arg("subPath"), py::arg("_paths"), py::arg("_pathCount")); + +//m.def("find_paths_etc", &find_paths_etc, "", py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags"), py::arg("_paths"), py::arg("_pathCount")); + +m.def("find_directory", py::overload_cast(&find_directory), "", py::arg("which"), py::arg("path"), py::arg("createIt")=false, py::arg("volume")=NULL); + +} diff --git a/bindings/storage/Mime.cpp b/bindings/storage/Mime.cpp new file mode 100644 index 0000000..af43e4a --- /dev/null +++ b/bindings/storage/Mime.cpp @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +/* +std::tuple> get_device_icon_py(const char *device) { + uint8 *data = nullptr; + size_t size = 0; + type_code type = B_MINI_ICON_TYPE; // default value + + // Chiamata alla funzione C++ + status_t result = get_device_icon(device, &data, &size, &type); + + //if (result != B_OK) { + // // Gestisci l'errore in qualche modo + // throw std::runtime_error("Errore nella funzione get_device_icon"); + //} + + // Creazione di un array NumPy dalla memoria ottenuta + auto capsule = py::capsule(data, [](void *d) { + // Implementa la logica per deallocare la memoria + // In questo esempio, si presume che la memoria sia stata allocata con new[] + delete[] static_cast(d); + }); + + return std::make_tuple(result,py::array_t({static_cast(size)}, {sizeof(uint8)}, data, capsule)); +}*/ + +PYBIND11_MODULE(Mime, m) +{ +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") = 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.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_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("_data"), py::arg("_size"), py::arg("_type")); +m.def("get_device_icon_toArray", [](const char * device){ + uint8 *data = nullptr; + size_t size = 0; + type_code type = B_MINI_ICON_TYPE; // default value + status_t result = get_device_icon(device, &data, &size, &type); + auto capsule = py::capsule(data, [](void *d) { + // Implementa la logica per deallocare la memoria + // In questo esempio, si presume che la memoria sia stata allocata con new[] + delete[] static_cast(d); + }); + + return std::make_tuple(result,py::array_t({static_cast(size)}, {sizeof(uint8)}, data, capsule)); + }, "", py::arg("device")); +// unsigned char ->uint8** +m.def("get_named_icon_toBitmap", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("icon"), py::arg("which")); + +//m.def("get_named_icon", py::overload_cast(&get_named_icon), "", py::arg("name"), py::arg("_data"), py::arg("_size"), py::arg("_type")); +// unsigned char ->uint8** +m.def("get_named_icon_toArray", [](const char *name, unsigned char iconSize, size_t *size, type_code *iconType) { + uint8 *data = nullptr; + status_t result = get_named_icon(name, &data, size, iconType); + + auto capsule = py::capsule(data, [](void *d) { + // Implementa la logica per deallocare la memoria, se necessario + // In questo esempio, si presume che la memoria sia stata allocata con new[] + delete[] static_cast(d); + }); + + return std::make_tuple(result, py::array_t({static_cast(*size)}, {sizeof(uint8)}, data, capsule)); +}, "", py::arg("name"), py::arg("iconSize"), py::arg("size"), py::arg("iconType")); +} diff --git a/bindings/storage/MimeType.cpp b/bindings/storage/MimeType.cpp new file mode 100644 index 0000000..0d3b5b7 --- /dev/null +++ b/bindings/storage/MimeType.cpp @@ -0,0 +1,212 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::Storage; +using namespace BPrivate::Storage::Mime; + +PYBIND11_MODULE(MimeType, m) +{ +py::enum_(m, "app_verb", "") +.value("B_OPEN", app_verb::B_OPEN, "") +.export_values(); + +m.attr("B_META_MIME_CHANGED") = 'MMCH'; + +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") = 'MMMD'; +m.attr("B_META_MIME_DELETED") = 'MMDL'; + +//m.attr("MimeDatabase") = py::cast(BPrivate::MimeDatabase); + +//m.attr("CreateAppMetaMimeThread") = py::cast(CreateAppMetaMimeThread); + +m.attr("B_APP_MIME_TYPE") = py::cast(B_APP_MIME_TYPE); + +m.attr("B_PEF_APP_MIME_TYPE") = py::cast(B_PEF_APP_MIME_TYPE); + +m.attr("B_PE_APP_MIME_TYPE") = py::cast(B_PE_APP_MIME_TYPE); + +m.attr("B_ELF_APP_MIME_TYPE") = py::cast(B_ELF_APP_MIME_TYPE); + +m.attr("B_RESOURCE_MIME_TYPE") = py::cast(B_RESOURCE_MIME_TYPE); + +m.attr("B_FILE_MIME_TYPE") = py::cast(B_FILE_MIME_TYPE); + +py::class_(m, "BMimeType") +.def(py::init(), "") +.def(py::init(), "", py::arg("mimeType")) +.def("SetTo", &BMimeType::SetTo, "", py::arg("mimeType")) +.def("Unset", &BMimeType::Unset, "") +.def("InitCheck", &BMimeType::InitCheck, "") +.def("Type", &BMimeType::Type, "") +.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::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_toBitmap", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) //changed names to GetIcon +.def("GetIcon", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("icon"), py::arg("size")) +/* +.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 ToDo return only result and pass BBitmap as argument*/ +//------------------------------------------------------------------------------------------------------------------------------------ +//.def("GetIcon", py::overload_cast(&BMimeType::GetIcon, py::const_), "", py::arg("_data"), py::arg("_size")) +/* This does not accept a "variable = []" from python +.def("GetIcon", [](const BMimeType &self, py::array_t& _data, size_t& _size) { + uint8 *data = nullptr; + size_t size = 0; + + // Chiamata alla funzione C++ + status_t result = self.GetIcon(&data, &size); + + auto buf_info = _data.request(); + if (buf_info.size != size * sizeof(uint8) || buf_info.format != py::format_descriptor::format()) { + throw std::runtime_error("Formato o dimensione dell'array incompatibili"); + } + std::memcpy(buf_info.ptr, data, size * sizeof(uint8)); + _size = size; + + // Deallocazione della memoria ottenuta da GetIcon + delete[] data; + + return result; +}, "", py::arg("_data"), py::arg("_size")) +*/ +.def("GetIcon", [](const BMimeType& self, py::list& _data, size_t& _size) { + uint8* data = nullptr; + size_t size = 0; + status_t result = self.GetIcon(&data, &size); + for (size_t i = 0; i < size; ++i) { + _data.append(data[i]); + } + _size = size; + delete[] data; + return result; +},"", py::arg("_data"), py::arg("_size")) +/* +.def("GetIcon", [](const BMimeType &self) { // <---This works + 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")) +.def("GetShortDescription", &BMimeType::GetShortDescription, "", py::arg("description")) +.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("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")) +.def("SetShortDescription", &BMimeType::SetShortDescription, "", py::arg("description")) +.def("SetLongDescription", &BMimeType::SetLongDescription, "", py::arg("description")) +.def_static("GetInstalledSupertypes", &BMimeType::GetInstalledSupertypes, "", py::arg("supertypes")) +.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_static", py::overload_cast(&BMimeType::IsValid), "", py::arg("mimeType")) +.def("GetAppHint", &BMimeType::GetAppHint, "", py::arg("ref")) +.def("SetAppHint", &BMimeType::SetAppHint, "", py::arg("ref")) +.def("GetIconForType", py::overload_cast(&BMimeType::GetIconForType, py::const_), "", py::arg("type"), py::arg("icon"), py::arg("which")) +/* +.def("GetIconForType", [](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, py::list& _data, size_t& _size) { + uint8* data = nullptr; + size_t size = 0; + status_t result = self.GetIconForType(type, &data, &size); + for (size_t i = 0; i < size; ++i) { + _data.append(data[i]); + } + _size = size; + delete[] data; + return result; +},"", 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("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("filename"), py::arg("type")) +.def_static("StartWatching", &BMimeType::StartWatching, "", py::arg("target")) +.def_static("StopWatching", &BMimeType::StopWatching, "", py::arg("target")) +.def("SetType", &BMimeType::SetType, "", py::arg("mimeType")) +; + + +} diff --git a/bindings/storage/Node.cpp b/bindings/storage/Node.cpp new file mode 100644 index 0000000..05cb976 --- /dev/null +++ b/bindings/storage/Node.cpp @@ -0,0 +1,245 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Node,m) +{ +py::class_(m, "node_ref") +.def(py::init(), "") +.def(py::init(), "", py::arg("device"), py::arg("node")) +.def(py::init(), "", py::arg("other")) +.def("__eq__", &node_ref::operator==, "", py::arg("other")) +.def("__ne__", &node_ref::operator!=, "", py::arg("other")) +.def("__lt__", &node_ref::operator<, "", py::arg("other")) +.def("operator=", &node_ref::operator=, "", py::arg("other")) +.def_readwrite("device", &node_ref::device, "") +.def_readwrite("node", &node_ref::node, "") +; + +py::class_(m, "BNode") //Commented out BStatable verify if needed +.def(py::init(), "") +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("entry")) +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("dir"), py::arg("path")) +.def(py::init(), "", py::arg("node")) +.def("InitCheck", &BNode::InitCheck, "") +.def("GetStat", &BNode::GetStat, "", py::arg("st")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "", py::arg("entry")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "", py::arg("path")) +.def("SetTo", py::overload_cast(&BNode::SetTo), "", py::arg("dir"), py::arg("path")) +.def("Unset", &BNode::Unset, "") +.def("Lock", &BNode::Lock, "") +.def("Unlock", &BNode::Unlock, "") +.def("Sync", &BNode::Sync, "") +//.def("WriteAttr", &BNode::WriteAttr, "", py::arg("name"), py::arg("type"), py::arg("offset"), py::arg("buffer"), py::arg("length")) +.def("WriteAttr", [](BNode& self, const char* name, type_code type, off_t offset, py::buffer buffer) { + // Estrai i dati dal buffer + py::buffer_info info = buffer.request(); //use var = bytearray(b"Hello, World!") + const void* data = info.ptr; + size_t length = info.size; + // Chiamare il metodo WriteAttr con i dati estratti + return self.WriteAttr(name, type, offset, data, length); +}, "",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: + ret = py::int_(*reinterpret_cast(PyLong_AsVoidPtr(PyLong_FromVoidPtr(tmp)))); + break; + 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: + { + //py::bytes bytes_obj(reinterpret_cast(tmp),length); + //ret = py::str(bytes_obj); + BString bstring(reinterpret_cast(tmp),length); + ret = py::str(bstring.String()); + } + //ret = py::str(static_cast(tmp)); + //ret = py::str(reinterpret_cast(tmp)); + //ret = PyUnicode_FromString(reinterpret_cast(tmp)); + break; + case B_BOOL_TYPE: + ret = py::bool_(*reinterpret_cast(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("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); + 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")) +.def("operator=", &BNode::operator=, "", py::arg("node")) +.def("__eq__", &BNode::operator==, "", py::arg("node")) +.def("__ne__", &BNode::operator!=, "", py::arg("node")) +.def("Dup", &BNode::Dup, "") +; + +} diff --git a/bindings/storage/NodeInfo.cpp b/bindings/storage/NodeInfo.cpp new file mode 100644 index 0000000..941392d --- /dev/null +++ b/bindings/storage/NodeInfo.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::Storage; +using namespace BPrivate::Storage::Mime; + +PYBIND11_MODULE(NodeInfo, m) +{ +py::class_(m, "BNodeInfo") +.def(py::init(), "") +.def(py::init(), "", py::arg("node")) +.def("SetTo", &BNodeInfo::SetTo, "", py::arg("node")) +.def("InitCheck", &BNodeInfo::InitCheck, "") +.def("GetType", &BNodeInfo::GetType, "", py::arg("type")) +.def("SetType", &BNodeInfo::SetType, "", py::arg("type")) +.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) +/* +.def("GetIcon_toBitmap", [](const BNodeInfo& self, icon_size which){ + BBitmap *icon; + if(which==B_LARGE_ICON){ + icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32); + } else { + icon = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32); + } + status_t result = self.GetIcon(icon, which); + return std::make_tuple(result, icon); +}, "", py::arg("which")=B_LARGE_ICON)*/ +.def("SetIcon", py::overload_cast(&BNodeInfo::SetIcon), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON) +//.def("GetIcon", py::overload_cast(&BNodeInfo::GetIcon, py::const_), "", py::arg("data"), py::arg("size"), py::arg("type")) +.def("GetIcon", [](const BNodeInfo& self, py::list& _data, size_t& _size, type_code& _type) { + uint8* data = nullptr; + size_t size = 0; + type_code type = 0; + status_t result = self.GetIcon(&data, &size, &type); + for (size_t i = 0; i < size; ++i) { + _data.append(data[i]); + } + _size = size; + _type = type; + delete[] data; + return result; +},"", py::arg("_data"), py::arg("_size"), py::arg("_type")) +/*.def("GetIcon_toArray", [](const BNodeInfo &self) { + size_t size; + type_code type; + uint8_t *data; + status_t result = self.GetIcon(&data, &size, &type); + auto capsule = py::capsule(data, [](void *d) { + delete[] static_cast(d); + }); + return std::make_tuple(result, py::array_t({static_cast(size)}, {sizeof(uint8_t)}, data, capsule), type); +}, "")*/ +.def("SetIcon", py::overload_cast(&BNodeInfo::SetIcon), "", py::arg("data"), py::arg("size")) +.def("GetPreferredApp", &BNodeInfo::GetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) +.def("SetPreferredApp", &BNodeInfo::SetPreferredApp, "", py::arg("signature"), py::arg("verb")=B_OPEN) +.def("GetAppHint", &BNodeInfo::GetAppHint, "", py::arg("ref")) +.def("SetAppHint", &BNodeInfo::SetAppHint, "", py::arg("ref")) +.def("GetTrackerIcon", py::overload_cast(&BNodeInfo::GetTrackerIcon, py::const_), "", py::arg("icon"), py::arg("which")=B_LARGE_ICON)// 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 new file mode 100644 index 0000000..929b5ed --- /dev/null +++ b/bindings/storage/NodeMonitor.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; + +PYBIND11_MODULE(NodeMonitor, m) +{ +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 new file mode 100644 index 0000000..2b73aaa --- /dev/null +++ b/bindings/storage/Path.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +/*using namespace BPrivate; +using namespace BPrivate::Storage; +using namespace BPrivate::Storage::Mime;*/ + +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(), "") +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("entry")) +.def(py::init(), "", py::arg("dir"), py::arg("leaf")=NULL, py::arg("normalize")=false) +.def(py::init(), "", py::arg("dir"), py::arg("leaf")=NULL, py::arg("normalize")=false) +.def("InitCheck", &BPath::InitCheck, "") +.def("SetTo", py::overload_cast(&BPath::SetTo), "", py::arg("ref")) +.def("SetTo", py::overload_cast(&BPath::SetTo), "", py::arg("entry")) +.def("SetTo", py::overload_cast(&BPath::SetTo), "", py::arg("path"), py::arg("leaf")=NULL, py::arg("normalize")=false) +.def("SetTo", py::overload_cast(&BPath::SetTo), "", py::arg("dir"), py::arg("leaf")=NULL, py::arg("normalize")=false) +.def("Unset", &BPath::Unset, "") +.def("Append", &BPath::Append, "", py::arg("path"), py::arg("normalize")=false) +.def("Path", &BPath::Path, "") +.def("Leaf", &BPath::Leaf, "") +.def("GetParent", &BPath::GetParent, "", py::arg("path")) +.def("IsAbsolute", &BPath::IsAbsolute, "") +.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, "") +.def("TypeCode", &BPath::TypeCode, "") +.def("FlattenedSize", &BPath::FlattenedSize, "") +.def("Flatten", &BPath::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("AllowsTypeCode", &BPath::AllowsTypeCode, "", py::arg("code")) +.def("Unflatten", &BPath::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + + +} diff --git a/bindings/storage/PathFinder.cpp b/bindings/storage/PathFinder.cpp new file mode 100644 index 0000000..5fd1fe4 --- /dev/null +++ b/bindings/storage/PathFinder.cpp @@ -0,0 +1,109 @@ +#include +#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; + +class BPathFinderWrapper { +public: + static std::tuple FindPaths(const char* architecture, path_base_directory baseDirectory, const char* subPath, uint32 flags, BStringList& _paths) { + //BStringList _paths; + status_t result = BPathFinder::FindPaths(architecture, baseDirectory, subPath, flags, _paths); + return std::make_tuple(result, _paths); + } + static std::tuple FindPaths(path_base_directory baseDirectory, const char* subPath, uint32 flags, BStringList& _paths) { + //BStringList _paths; + status_t result = BPathFinder::FindPaths(baseDirectory, subPath, flags, _paths); + return std::make_tuple(result, _paths); + } + static std::tuple FindPaths(path_base_directory baseDirectory, const char* subPath, BStringList& _paths) { + //BStringList _paths; + status_t result = BPathFinder::FindPaths(baseDirectory, subPath, _paths); + return std::make_tuple(result, _paths); + } + static std::tuple FindPaths(path_base_directory baseDirectory, BStringList& _paths) { + //BStringList _paths; + status_t result = BPathFinder::FindPaths(baseDirectory, _paths); + return std::make_tuple(result, _paths); + } +}; + + +PYBIND11_MODULE(PathFinder, m) +{ +//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) //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) //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); + return std::make_tuple(r,_path); +} +, "", py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) +.def("FindPath", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath,unsigned int flags) { + BPath _path; + status_t r = self.FindPath(baseDirectory, subPath, flags, _path); + return std::make_tuple(r,_path); +} +, "", py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags")) +.def("FindPath", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath) { + BPath _path; + status_t r = self.FindPath(baseDirectory, subPath, _path); + return std::make_tuple(r,_path); +} +, "", py::arg("baseDirectory"), py::arg("subPath")) +.def("FindPath", [](BPathFinder& self,path_base_directory baseDirectory) { + BPath _path; + status_t r = self.FindPath(baseDirectory, _path); + return std::make_tuple(r,_path); +} +, "", py::arg("baseDirectory")) +/*.def_static("FindPaths", [](BPathFinder& self,const char * architecture,path_base_directory baseDirectory,const char * subPath,uint32 flags) { + BStringList _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", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("architecture"), py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags"), py::arg("_paths")) +/*.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath,uint32 flags) { + BStringList _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", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("baseDirectory"), py::arg("subPath"), py::arg("flags"), py::arg("_paths")) +/*.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory,const char * subPath) { + BStringList _paths; + status_t r = self.FindPaths(baseDirectory, subPath, _paths); + return std::make_tuple(r,_paths); +} +, "", py::arg("baseDirectory"), py::arg("subPath"))*/ +.def_static("FindPaths", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("baseDirectory"), py::arg("subPath"), py::arg("_paths")) +/*.def("FindPaths", [](BPathFinder& self,path_base_directory baseDirectory) { + BStringList _paths; + status_t r = self.FindPaths(baseDirectory, _paths); + return std::make_tuple(r,_paths); +} +, "", py::arg("baseDirectory"))*/ +.def_static("FindPaths", py::overload_cast(&BPathFinderWrapper::FindPaths), "", py::arg("baseDirectory"), py::arg("_paths")) +; + +} diff --git a/bindings/storage/Query.cpp b/bindings/storage/Query.cpp new file mode 100644 index 0000000..ec238c8 --- /dev/null +++ b/bindings/storage/Query.cpp @@ -0,0 +1,93 @@ +#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; + +//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, "") +.value("B_EQ", query_op::B_EQ, "") +.value("B_GT", query_op::B_GT, "") +.value("B_GE", query_op::B_GE, "") +.value("B_LT", query_op::B_LT, "") +.value("B_LE", query_op::B_LE, "") +.value("B_NE", query_op::B_NE, "") +.value("B_CONTAINS", query_op::B_CONTAINS, "") +.value("B_BEGINS_WITH", query_op::B_BEGINS_WITH, "") +.value("B_ENDS_WITH", query_op::B_ENDS_WITH, "") +.value("B_AND", query_op::B_AND, "") +.value("B_OR", query_op::B_OR, "") +.value("B_NOT", query_op::B_NOT, "") +.value("_B_RESERVED_OP_", query_op::_B_RESERVED_OP_, "") +.export_values(); + +//m.attr("QueryNode") = py::cast(QueryNode); + +//m.attr("QueryStack") = py::cast(QueryStack); + +//m.attr("QueryTree") = py::cast(QueryTree); + +py::class_(m, "BQuery") +.def(py::init(), "") +.def("Clear", &BQuery::Clear, "") +.def("PushAttr", &BQuery::PushAttr, "", py::arg("attrName")) +.def("PushOp", &BQuery::PushOp, "", py::arg("op")) +.def("PushUInt32", &BQuery::PushUInt32, "", py::arg("value")) +.def("PushInt32", &BQuery::PushInt32, "", py::arg("value")) +.def("PushUInt64", &BQuery::PushUInt64, "", py::arg("value")) +.def("PushInt64", &BQuery::PushInt64, "", py::arg("value")) +.def("PushFloat", &BQuery::PushFloat, "", py::arg("value")) +.def("PushDouble", &BQuery::PushDouble, "", py::arg("value")) +.def("PushString", &BQuery::PushString, "", py::arg("value"), py::arg("caseInsensitive")=false) +.def("PushDate", &BQuery::PushDate, "", py::arg("date")) +.def("SetVolume", &BQuery::SetVolume, "", py::arg("volume")) +.def("SetPredicate", &BQuery::SetPredicate, "", py::arg("expression")) +.def("SetTarget", &BQuery::SetTarget, "", py::arg("messenger")) +.def("IsLive", &BQuery::IsLive, "") +.def("GetPredicate", py::overload_cast(&BQuery::GetPredicate), "", py::arg("buffer"), py::arg("length")) +.def("GetPredicate", py::overload_cast(&BQuery::GetPredicate), "", py::arg("predicate")) +.def("PredicateLength", &BQuery::PredicateLength, "") +.def("TargetDevice", &BQuery::TargetDevice, "") +.def("Fetch", &BQuery::Fetch, "") +.def("GetNextEntry", &BQuery::GetNextEntry, "", py::arg("entry"), py::arg("traverse")=false) +.def("GetNextRef", &BQuery::GetNextRef, "", py::arg("ref")) +.def("GetNextDirents", &BQuery::GetNextDirents, "", py::arg("buffer"), py::arg("length"), py::arg("count")=INT_MAX) +.def("Rewind", &BQuery::Rewind, "") +.def("CountEntries", &BQuery::CountEntries, "") +; + + +} diff --git a/bindings/storage/ResourceStrings.cpp b/bindings/storage/ResourceStrings.cpp new file mode 100644 index 0000000..ac71ef4 --- /dev/null +++ b/bindings/storage/ResourceStrings.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +//using namespace BPrivate; +//using namespace BPrivate::Storage; +//using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; + +class PyBResourceStrings : public BResourceStrings{ + public: + using BResourceStrings::BResourceStrings; + BString* NewString(int32 id) override { + PYBIND11_OVERLOAD(BString*, BResourceStrings, NewString, id); + } + const char* FindString(int32 id) override { + PYBIND11_OVERLOAD(const char*, BResourceStrings, FindString, id); + } + status_t SetStringFile(const entry_ref* ref) override { + PYBIND11_OVERLOAD(status_t, BResourceStrings, SetStringFile, ref); + } +}; + +PYBIND11_MODULE(ResourceStrings, m) +{ +py::class_(m, "BResourceStrings") +.def(py::init(), "") +.def(py::init(), "", py::arg("ref")) +.def("InitCheck", &BResourceStrings::InitCheck, "") +.def("NewString", &BResourceStrings::NewString, "", py::arg("id")) +.def("FindString", &BResourceStrings::FindString, "", py::arg("id")) +.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")) +.def_readwrite("next", &_string_id_hash::next, "") +.def_readwrite("id", &_string_id_hash::id, "") +.def_readwrite("data", &_string_id_hash::data, "") +.def_readwrite("data_alloced", &_string_id_hash::data_alloced, "") +.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 new file mode 100644 index 0000000..c3dc4c8 --- /dev/null +++ b/bindings/storage/Resources.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +//#include + +#include + +namespace py = pybind11; +//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; + + 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("ResourceFile") = py::cast(ResourceFile); + +py::class_(m, "BResources") +.def(py::init(), "") +.def(py::init(), "", py::arg("file"), py::arg("clobber")=false) +.def(py::init(), "", py::arg("path"), py::arg("clobber")=false) +.def(py::init(), "", py::arg("ref"), py::arg("clobber")=false) +.def("SetTo", py::overload_cast(&BResources::SetTo), "", py::arg("file"), py::arg("clobber")=false) +.def("SetTo", py::overload_cast(&BResources::SetTo), "", py::arg("path"), py::arg("clobber")=false) +.def("SetTo", py::overload_cast(&BResources::SetTo), "", py::arg("ref"), py::arg("clobber")=false) +.def("SetToImage", py::overload_cast(&BResources::SetToImage), "", py::arg("image"), py::arg("clobber")=false) +.def("SetToImage", py::overload_cast(&BResources::SetToImage), "", py::arg("codeOrDataPointer"), py::arg("clobber")=false) +.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")) // 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) // to change <- cannot pass void* data from python +.def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("id")) +.def("HasResource", py::overload_cast(&BResources::HasResource), "", py::arg("type"), py::arg("name")) +//.def("GetResourceInfo", py::overload_cast(&BResources::GetResourceInfo), "", py::arg("byIndex"), py::arg("typeFound"), py::arg("idFound"), py::arg("nameFound"), py::arg("lengthFound")) +.def("GetResourceInfo", [](BResources& self, int32 byIndex){ + type_code typeFound; + int32 idFound; + const char * nameFound; + size_t lengthFound; + bool result = self.GetResourceInfo(byIndex, &typeFound, &idFound, &nameFound, &lengthFound); + + 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("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("name"), py::arg("lengthFound")) +; + + +} diff --git a/bindings/storage/Statable.cpp b/bindings/storage/Statable.cpp new file mode 100644 index 0000000..1b1002f --- /dev/null +++ b/bindings/storage/Statable.cpp @@ -0,0 +1,43 @@ +#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;*/ + +// ADD GetStat overload_pure ? +PYBIND11_MODULE(Statable, m) +{ +py::class_(m, "BStatable") +.def("GetStat", &BStatable::GetStat, "", py::arg("stat")) +.def("IsFile", &BStatable::IsFile, "") +.def("IsDirectory", &BStatable::IsDirectory, "") +.def("IsSymLink", &BStatable::IsSymLink, "") +.def("GetNodeRef", &BStatable::GetNodeRef, "", py::arg("ref")) +.def("GetOwner", &BStatable::GetOwner, "", py::arg("owner")) +.def("SetOwner", &BStatable::SetOwner, "", py::arg("owner")) +.def("GetGroup", &BStatable::GetGroup, "", py::arg("group")) +.def("SetGroup", &BStatable::SetGroup, "", py::arg("group")) +.def("GetPermissions", &BStatable::GetPermissions, "", py::arg("permissions")) +.def("SetPermissions", &BStatable::SetPermissions, "", py::arg("permissions")) +.def("GetSize", &BStatable::GetSize, "", py::arg("size")) +.def("GetModificationTime", &BStatable::GetModificationTime, "", py::arg("mtime")) +.def("SetModificationTime", &BStatable::SetModificationTime, "", py::arg("mtime")) +.def("GetCreationTime", &BStatable::GetCreationTime, "", py::arg("ctime")) +.def("SetCreationTime", &BStatable::SetCreationTime, "", py::arg("ctime")) +.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, "") +; + + +} diff --git a/bindings/storage/StorageDefs.cpp b/bindings/storage/StorageDefs.cpp new file mode 100644 index 0000000..60785f3 --- /dev/null +++ b/bindings/storage/StorageDefs.cpp @@ -0,0 +1,27 @@ +#include +#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; + + +PYBIND11_MODULE(StorageDefs,m) +{ +py::enum_(m, "node_flavor", "") +.value("B_FILE_NODE", node_flavor::B_FILE_NODE, "") +.value("B_SYMLINK_NODE", node_flavor::B_SYMLINK_NODE, "") +.value("B_DIRECTORY_NODE", node_flavor::B_DIRECTORY_NODE, "") +.value("B_ANY_NODE", node_flavor::B_ANY_NODE, "") +.export_values(); + +} diff --git a/bindings/storage/SymLink.cpp b/bindings/storage/SymLink.cpp new file mode 100644 index 0000000..59ab885 --- /dev/null +++ b/bindings/storage/SymLink.cpp @@ -0,0 +1,34 @@ +#include +#include +#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; + +PYBIND11_MODULE(SymLink, m) +{ +py::class_(m, "BSymLink") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("ref")) +.def(py::init(), "", py::arg("entry")) +.def(py::init(), "", py::arg("path")) +.def(py::init(), "", py::arg("dir"), py::arg("path")) +.def("ReadLink", &BSymLink::ReadLink, "", py::arg("buf"), py::arg("size")) +.def("MakeLinkedPath", py::overload_cast(&BSymLink::MakeLinkedPath), "", py::arg("dirPath"), py::arg("path")) +.def("MakeLinkedPath", py::overload_cast(&BSymLink::MakeLinkedPath), "", py::arg("dir"), py::arg("path")) +.def("IsAbsolute", &BSymLink::IsAbsolute, "") +; + + +} diff --git a/bindings/storage/Volume.cpp b/bindings/storage/Volume.cpp new file mode 100644 index 0000000..fc84dd8 --- /dev/null +++ b/bindings/storage/Volume.cpp @@ -0,0 +1,71 @@ +#include +#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; + +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(), "") +.def(py::init(), "", py::arg("device")) +.def(py::init(), "", py::arg("volume")) +.def("InitCheck", &BVolume::InitCheck, "") +.def("SetTo", &BVolume::SetTo, "", py::arg("device")) +.def("Unset", &BVolume::Unset, "") +.def("Device", &BVolume::Device, "") +.def("GetRootDirectory", &BVolume::GetRootDirectory, "", py::arg("directory")) +.def("Capacity", &BVolume::Capacity, "") +.def("FreeBytes", &BVolume::FreeBytes, "") +.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::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, "") +.def("IsShared", &BVolume::IsShared, "") +.def("KnowsMime", &BVolume::KnowsMime, "") +.def("KnowsAttr", &BVolume::KnowsAttr, "") +.def("KnowsQuery", &BVolume::KnowsQuery, "") +.def("__eq__", &BVolume::operator==, "", py::arg("volume")) +.def("__ne__", &BVolume::operator!=, "", py::arg("volume")) +.def("operator=", &BVolume::operator=, "", py::arg("volume")) +; + + +} diff --git a/bindings/storage/VolumeRoster.cpp b/bindings/storage/VolumeRoster.cpp new file mode 100644 index 0000000..b86280a --- /dev/null +++ b/bindings/storage/VolumeRoster.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::Storage; +using namespace BPrivate::Storage::Mime; +//using namespace BPackageKit; + +PYBIND11_MODULE(VolumeRoster, m) +{ +py::class_(m, "BVolumeRoster") +.def(py::init(), "") +.def("GetNextVolume", &BVolumeRoster::GetNextVolume, "", py::arg("volume")) +.def("Rewind", &BVolumeRoster::Rewind, "") +.def("GetBootVolume", &BVolumeRoster::GetBootVolume, "", py::arg("volume")) +.def("StartWatching", &BVolumeRoster::StartWatching, "", py::arg("messenger")=be_app_messenger) +.def("StopWatching", &BVolumeRoster::StopWatching, "") +.def("Messenger", &BVolumeRoster::Messenger, "") +; + + +} diff --git a/bindings/storage/stat.cpp b/bindings/storage/stat.cpp new file mode 100644 index 0000000..0b9bb85 --- /dev/null +++ b/bindings/storage/stat.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2023, Fabio Tomat + * All rights reserved. Distributed under the terms of the MIT license. + */ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +void expose_stat(py::module &m) { + py::class_(m, "stat") + .def(py::init<>()) + .def_readwrite("st_dev", &stat::st_dev) + .def_readwrite("st_ino", &stat::st_ino) + .def_readwrite("st_mode", &stat::st_mode) + .def_readwrite("st_nlink", &stat::st_nlink) + .def_readwrite("st_uid", &stat::st_uid) + .def_readwrite("st_gid", &stat::st_gid) + .def_readwrite("st_size", &stat::st_size) + .def_readwrite("st_rdev", &stat::st_rdev) + .def_readwrite("st_blksize", &stat::st_blksize) + .def_readwrite("st_atim", &stat::st_atim) + .def_readwrite("st_mtim", &stat::st_mtim) + .def_readwrite("st_ctim", &stat::st_ctim) + .def_readwrite("st_crtim", &stat::st_crtim) + .def_readwrite("st_type", &stat::st_type) + .def_readwrite("st_blocks", &stat::st_blocks); +} +PYBIND11_MODULE(stat, m) { + expose_stat(m); +} diff --git a/bindings/support/Architecture.cpp b/bindings/support/Architecture.cpp new file mode 100644 index 0000000..f53ca60 --- /dev/null +++ b/bindings/support/Architecture.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +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_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")); + +m.def("get_secondary_architectures", []() { + BStringList _architectures; + status_t r = get_secondary_architectures(_architectures); + return std::make_tuple(r,_architectures); +} +, ""); + +m.def("get_architectures", []() { + BStringList _architectures; + status_t r = get_architectures(_architectures); + return std::make_tuple(r,_architectures); +} +, ""); + +} diff --git a/bindings/support/Archivable.cpp b/bindings/support/Archivable.cpp new file mode 100644 index 0000000..fcd8f16 --- /dev/null +++ b/bindings/support/Archivable.cpp @@ -0,0 +1,174 @@ +#include +#include +#include +#include + +#include +//#include +//#include +//#include + +namespace py = pybind11; +using namespace BPrivate; +using namespace BPrivate::Archiving; + + +PYBIND11_MODULE(Archivable, m) +{ +py::class_(m, "BArchivable") +.def(py::init(), "", py::arg("from")) +.def(py::init(), "") +.def("Archive", &BArchivable::Archive, "", py::arg("into"), py::arg("deep")=true) +.def_static("Instantiate", &BArchivable::Instantiate, "", py::arg("archive")) +.def("Perform", &BArchivable::Perform, "", py::arg("d"), py::arg("arg")) +.def("AllUnarchived", &BArchivable::AllUnarchived, "", py::arg("archive")) +.def("AllArchived", &BArchivable::AllArchived, "", py::arg("archive")) +; + +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")) //TODO Check this function +.def("GetTokenForArchivable", py::overload_cast(&BArchiver::GetTokenForArchivable), "", py::arg("archivable"), py::arg("deep"), py::arg("_token")) //TODO Check this function +.def("IsArchived", &BArchiver::IsArchived, "", py::arg("archivable")) +.def("Finish", &BArchiver::Finish, "", py::arg("err")=B_OK) +.def("ArchiveMessage", &BArchiver::ArchiveMessage, "") +; + +py::class_(m, "BUnarchiver") +.def(py::init(), "", py::arg("archive")) +/*.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) { + 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) { + 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) { + 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) { + 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) { + 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) +.def("Finish", &BUnarchiver::Finish, "", py::arg("err")=B_OK) +.def("ArchiveMessage", &BUnarchiver::ArchiveMessage, "") +.def("AssumeOwnership", &BUnarchiver::AssumeOwnership, "", py::arg("archivable")) +.def("RelinquishOwnership", &BUnarchiver::RelinquishOwnership, "", py::arg("archivable")) +.def_static("IsArchiveManaged", &BUnarchiver::IsArchiveManaged, "", py::arg("archive")) +.def_static("PrepareArchive", [](BUnarchiver& self) { + BMessage * archive; + static BMessage * r = self.PrepareArchive(archive); + return std::make_tuple(r,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"))*/ +; + +///* 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")); +//TODO: check these 3 functions +m.def("find_instantiation_func", [](const char* className, const char* signature) -> py::object { + instantiation_func func = find_instantiation_func(className, signature); + if (func == nullptr) { + return py::none(); + } + return py::cpp_function([func](BMessage* msg) -> BArchivable* { + return func(msg); + }); +}, 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", [](const char* className) -> py::object { + instantiation_func func = find_instantiation_func(className); + if (func == nullptr) { + return py::none(); + } + + return py::cpp_function([func](BMessage* msg) -> BArchivable* { + return func(msg); + }); +}, py::arg("className")); + +//m.def("find_instantiation_func", py::overload_cast(&find_instantiation_func), "", py::arg("archive")); +m.def("find_instantiation_func", [](BMessage* archive) -> py::object { + instantiation_func func = find_instantiation_func(archive); + if (func == nullptr) { + return py::none(); + } + + return py::cpp_function([func](BMessage* msg) -> BArchivable* { + return func(msg); + }); +}, 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); + +//my attempt to add ownership_policy: +//m.attr("B_ASSUME_OWNERSHIP") = py::cast(BUnarchiver::ownership_policy::B_ASSUME_OWNERSHIP); +m.attr("B_ASSUME_OWNERSHIP") = 0; +//m.attr("B_DONT_ASSUME_OWNERSHIP") = py::cast(BUnarchiver::ownership_policy::B_DONT_ASSUME_OWNERSHIP); +m.attr("B_DONT_ASSUME_OWNERSHIP") = 1; +} diff --git a/bindings/support/Autolock.cpp b/bindings/support/Autolock.cpp new file mode 100644 index 0000000..7bd4360 --- /dev/null +++ b/bindings/support/Autolock.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Autolock, m) +{ +py::class_(m, "BAutolock") +.def(py::init(), "", py::arg("looper")) +.def(py::init(), "", py::arg("locker")) +.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 new file mode 100644 index 0000000..822de37 --- /dev/null +++ b/bindings/support/Beep.cpp @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Beep, m) +{ +m.def("beep", &beep, ""); + +m.def("system_beep", &system_beep, "", py::arg("eventName")); + +m.def("add_system_beep_event", &add_system_beep_event, "", py::arg("eventName"), py::arg("flags")=0); + +} diff --git a/bindings/support/BlockCache.cpp b/bindings/support/BlockCache.cpp new file mode 100644 index 0000000..d569edc --- /dev/null +++ b/bindings/support/BlockCache.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +/* +py::bytes Get_wrapper(size_t blockSize) { + void* data = Get(blockSize); + py::buffer buffer; + + if (data == nullptr) { + throw std::runtime_error("Failed to get data"); + } + return py::bytes(static_cast(data), blockSize); +}*/ +py::bytes Get_wrapper2(BBlockCache& self, size_t blockSize) { + void* data = self.Get(blockSize); + if (data == nullptr) { + throw std::runtime_error("Failed to get data"); + } + py::buffer_info buf_info(static_cast(data), sizeof(char), py::format_descriptor::format(), 1, {blockSize}, {sizeof(char)} ); + //return py::array(buf_info); + return py::bytes(static_cast(buf_info.ptr), buf_info.size * buf_info.itemsize); //convert py::buffer to py::bytes +}; + +PYBIND11_MODULE(BlockCache, m) +{ +m.attr("B_OBJECT_CACHE") = 0;//py::cast(B_OBJECT_CACHE); +m.attr("B_MALLOC_CACHE") = 1;//py::cast(B_MALLOC_CACHE); + +py::class_(m, "BBlockCache") +.def(py::init(), "", py::arg("blockCount"), py::arg("blockSize"), py::arg("allocationType")) +//.def("Get", &BBlockCache::Get, "", py::arg("blockSize"))//TODO this returns a void * -- let's return a py::bytes or a py::buffer +.def("Get", &Get_wrapper2, "", py::arg("blockSize")) +.def("Get2", [](BBlockCache& self, size_t blockSize)->py::tuple{ + std::vectorbuffer(blockSize); + void* data = self.Get(blockSize); + if (data != nullptr) { + std::memcpy(buffer.data(), data, blockSize); + } + py::bytes pyBytes(buffer.data(),blockSize); + return py::make_tuple(pyBytes, blockSize); +},"",py::arg("blockSize")) +//.def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize"))//TODO: pointer is a void * -> python can't use void * +.def("Save", [](BBlockCache& self, py::bytes data) {//if we pass a py::bytes we already pass the size along with data right? +/* std::string byt = py::str(data); + void* pointer = static_cast(const_cast(byt.data())); + self.Save(pointer, byt.size());*/ + char* pointer; + ssize_t size; + PYBIND11_BYTES_AS_STRING_AND_SIZE(data.ptr(), &pointer, &size); + self.Save(static_cast(pointer), static_cast(size)); + },"", py::arg("data")) +.def("Save_from_buffer", [](BBlockCache& self, py::buffer py_buffer){ + py::buffer_info buf_info = py_buffer.request(); + void* pointer = buf_info.ptr; + //size_t blockSize = buf_info.size * buf_info.itemsize; + size_t blockSize = buf_info.size; + self.Save(pointer, blockSize); +},"",py::arg("py_buffer")) +; + + +} diff --git a/bindings/support/BufferIO.cpp b/bindings/support/BufferIO.cpp new file mode 100644 index 0000000..9ee9e41 --- /dev/null +++ b/bindings/support/BufferIO.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class PyBBufferIO : public BBufferIO{ + public: + using BBufferIO::BBufferIO; + ssize_t ReadAt(off_t pos, void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferIO, ReadAt, pos, buffer, size); + } + ssize_t WriteAt(off_t pos, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferIO, WriteAt, pos, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BBufferIO, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BBufferIO, Position); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BBufferIO, SetSize, size); + } + status_t Flush() override { + PYBIND11_OVERLOAD(status_t, BBufferIO, Flush); + } +}; + + +ssize_t ReadAtWrapper(BBufferIO& self, off_t pos, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.ReadAt(pos, info.ptr, info.size); +}; + +ssize_t WriteAtWrapper(BBufferIO& self, off_t pos, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.WriteAt(pos, info.ptr, info.size); +}; + +PYBIND11_MODULE(BufferIO, m) +{ +py::class_(m, "BBufferIO") +.def(py::init(), "", py::arg("stream"), py::arg("bufferSize")=65536L, py::arg("ownsStream")=true) +//.def("ReadAt", &BBufferIO::ReadAt, "", py::arg("pos"), py::arg("buffer"), py::arg("size")) +.def("ReadAt", &ReadAtWrapper, "", py::arg("pos"), py::arg("buffer")) +//.def("WriteAt", &BBufferIO::WriteAt, "", py::arg("pos"), py::arg("buffer"), py::arg("size")) +.def("WriteAt", &WriteAtWrapper, "", py::arg("pos"), py::arg("buffer")) +.def("Seek", &BBufferIO::Seek, "", py::arg("position"), py::arg("seekMode")) +.def("Position", &BBufferIO::Position, "") +.def("SetSize", &BBufferIO::SetSize, "", py::arg("size")) +.def("Flush", &BBufferIO::Flush, "") +.def("Stream", &BBufferIO::Stream, "") +.def("BufferSize", &BBufferIO::BufferSize, "") +.def("OwnsStream", &BBufferIO::OwnsStream, "") +.def("SetOwnsStream", &BBufferIO::SetOwnsStream, "", py::arg("ownsStream")) +.def("PrintToStream", &BBufferIO::PrintToStream, "") +; + + +} diff --git a/bindings/support/BufferedDataIO.cpp b/bindings/support/BufferedDataIO.cpp new file mode 100644 index 0000000..2cfe22a --- /dev/null +++ b/bindings/support/BufferedDataIO.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +class PyBBufferedDataIO : public BBufferedDataIO{ + public: + using BBufferedDataIO::BBufferedDataIO; + ssize_t Read(void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferedDataIO, Read, buffer, size); + } + ssize_t Write(const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBufferedDataIO, Write, buffer, size); + } +}; + +ssize_t ReadWrapper(BBufferedDataIO& self, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.Read(info.ptr, info.size); +}; + +ssize_t WriteWrapper(BBufferedDataIO& self, py::buffer buffer) { + py::buffer_info info = buffer.request(); + + if (info.ndim != 1) { + throw std::runtime_error("Buffer should be one-dimensional"); + } + + if (info.itemsize != 1) { + throw std::runtime_error("Buffer elements should be of size 1 byte"); + } + + return self.Write(info.ptr, info.size); +}; + +PYBIND11_MODULE(BufferedDataIO, m) +{ +py::class_(m, "BBufferedDataIO") +.def(py::init(), "", py::arg("stream") ,py::arg("bufferSize")=65536L, py::arg("ownsStream")=true, py::arg("partialReads")=false) +.def("InitCheck", &BBufferedDataIO::InitCheck, "") +.def("Stream", &BBufferedDataIO::Stream, "") +.def("BufferSize", &BBufferedDataIO::BufferSize, "") +.def("OwnsStream", &BBufferedDataIO::OwnsStream, "") +.def("SetOwnsStream", &BBufferedDataIO::SetOwnsStream, "", py::arg("ownsStream")) +.def("Flush", &BBufferedDataIO::Flush, "") +//.def("Read", &BBufferedDataIO::Read, "", py::arg("buffer"), py::arg("size")) // change to correctly handle void* buffer +.def("Read", &ReadWrapper, "", py::arg("buffer")) //TODO test this +/* in python: +buffered_io = mymodule.BBufferedDataIO() +buffer = bytearray(1024) +read_bytes = buffered_io.Read(buffer)*/ +//.def("Write", &BBufferedDataIO::Write, "", py::arg("buffer"), py::arg("size")) // change to correctly handle void* buffer +.def("Write", &WriteWrapper, "", py::arg("buffer")) //TODO test this +/*in python: +buffered_io = mymodule.BBufferedDataIO() +data = bytearray(b"Hello, world!") +written_bytes = buffered_io.Write(data)*/ +; + + +} diff --git a/bindings/support/ByteOrder.cpp b/bindings/support/ByteOrder.cpp new file mode 100644 index 0000000..4117130 --- /dev/null +++ b/bindings/support/ByteOrder.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +/* +uint64 sw_int64(uint64 arg){ + #if __GNUC__ >= 4 + return __builtin_bswap64(arg); + #else + return __swap_int64(arg); +}*/ + +#if __GNUC__ >= 4 + uint64 swap_int64(uint64 arg) { + return __builtin_bswap64(arg); + } + uint32 swap_int32(uint32 arg) { + return __builtin_bswap32(arg); + } + uint16 swap_int16(uint16 arg) { + return __builtin_bswap16(arg); + } +#else + extern uint64 __swap_int64(uint64 arg); + extern uint32 __swap_int32(uint32 arg); + extern uint16 __swap_int16(uint16 arg); +#endif + + + +PYBIND11_MODULE(ByteOrder, m) +{ +py::enum_(m, "swap_action", "") +.value("B_SWAP_HOST_TO_LENDIAN", swap_action::B_SWAP_HOST_TO_LENDIAN, "") +.value("B_SWAP_HOST_TO_BENDIAN", swap_action::B_SWAP_HOST_TO_BENDIAN, "") +.value("B_SWAP_LENDIAN_TO_HOST", swap_action::B_SWAP_LENDIAN_TO_HOST, "") +.value("B_SWAP_BENDIAN_TO_HOST", swap_action::B_SWAP_BENDIAN_TO_HOST, "") +.value("B_SWAP_ALWAYS", swap_action::B_SWAP_ALWAYS, "") +.export_values(); + +m.def("swap_data", &swap_data, "", py::arg("type"), py::arg("data"), py::arg("length"), py::arg("action")); //todo data is a void* convert to py::buffer or py::bytes + +m.def("is_type_swapped", &is_type_swapped, "", py::arg("type")); + +m.def("__swap_double", &__swap_double, "", py::arg("arg")); + +m.def("__swap_float", &__swap_float, "", py::arg("arg")); +/* +m.def("__swap_int64", &__swap_int64, "", py::arg("arg")); +m.def("__swap_int32", &__swap_int32, "", py::arg("arg")); +m.def("__swap_int16", &__swap_int16, "", py::arg("arg")); +*/ +#if __GNUC__ >= 4 +m.def("__swap_int64", &swap_int64, "Swap bytes of a 64-bit integer"); +m.def("__swap_int32", &swap_int32, "Swap bytes of a 32-bit integer"); +m.def("__swap_int16", &swap_int16, "Swap bytes of a 16-bit integer"); +#else +m.def("__swap_int64", &__swap_int64, "", py::arg("arg")); +m.def("__swap_int32", &__swap_int32, "", py::arg("arg")); +m.def("__swap_int16", &__swap_int16, "", py::arg("arg")); +#endif +} diff --git a/bindings/support/ClassInfo.cpp b/bindings/support/ClassInfo.cpp new file mode 100644 index 0000000..936eae2 --- /dev/null +++ b/bindings/support/ClassInfo.cpp @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_ClassInfo(py::module_& m) +{ + +} diff --git a/bindings/support/DataIO.cpp b/bindings/support/DataIO.cpp new file mode 100644 index 0000000..4af613b --- /dev/null +++ b/bindings/support/DataIO.cpp @@ -0,0 +1,149 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +class PyBDataIO : public BDataIO { +public: + using BDataIO::BDataIO; + 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); + } +}; + + +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_PURE(ssize_t, BPositionIO, ReadAt, position, buffer, size); + } + ssize_t WriteAt(off_t position, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD_PURE(ssize_t, BPositionIO, WriteAt, position, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD_PURE(off_t, BPositionIO, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD_PURE(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: + using BMemoryIO::BMemoryIO; + 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: + using BMallocIO::BMallocIO; + 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") +.def(py::init(), "") +.def("Read", &BDataIO::Read, "", py::arg("buffer"), py::arg("size")) +.def("Write", &BDataIO::Write, "", py::arg("buffer"), py::arg("size")) +.def("Flush", &BDataIO::Flush, "") +.def("ReadExactly", &BDataIO::ReadExactly, "", py::arg("buffer"), py::arg("size"), py::arg("_bytesRead")=NULL) +.def("WriteExactly", &BDataIO::WriteExactly, "", py::arg("buffer"), py::arg("size"), py::arg("_bytesWritten")=NULL) +; + +/* +py::class_(m, "BPositionIO"); +py::class_(m, "BMemoryIO"); +py::class_(m, "BMallocIO"); +*/ +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("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")) +.def("Position", &BPositionIO::Position, "") +.def("SetSize", &BPositionIO::SetSize, "", py::arg("size")) +.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")) +.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")) +.def("Position", &BMemoryIO::Position, "") +.def("SetSize", &BMemoryIO::SetSize, "", py::arg("size")) +; + +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")) +.def("Position", &BMallocIO::Position, "") +.def("SetSize", &BMallocIO::SetSize, "", py::arg("size")) +.def("SetBlockSize", &BMallocIO::SetBlockSize, "", py::arg("blockSize")) +.def("Buffer", &BMallocIO::Buffer, "") +.def("BufferLength", &BMallocIO::BufferLength, "") +; + +} diff --git a/bindings/support/DateTime.cpp b/bindings/support/DateTime.cpp new file mode 100644 index 0000000..945d4dd --- /dev/null +++ b/bindings/support/DateTime.cpp @@ -0,0 +1,158 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace BPrivate; + +PYBIND11_MODULE(DateTime, m) +{ +py::enum_(m, "time_type", "") +.value("B_GMT_TIME", time_type::B_GMT_TIME, "") +.value("B_LOCAL_TIME", time_type::B_LOCAL_TIME, "") +.export_values(); + +py::enum_(m, "diff_type", "") +.value("B_HOURS_DIFF", diff_type::B_HOURS_DIFF, "") +.value("B_MINUTES_DIFF", diff_type::B_MINUTES_DIFF, "") +.value("B_SECONDS_DIFF", diff_type::B_SECONDS_DIFF, "") +.value("B_MILLISECONDS_DIFF", diff_type::B_MILLISECONDS_DIFF, "") +.value("B_MICROSECONDS_DIFF", diff_type::B_MICROSECONDS_DIFF, "") +.export_values(); + +py::class_(m, "BTime") +.def(py::init(), "") +.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) +.def(py::init(), "", py::arg("archive")) +.def("Archive", &BTime::Archive, "", py::arg("into")) +//.def("IsValid", py::overload_cast<>(&BTime::IsValid, py::const_), "") // overloading a method with both static and instance methods is not supported; +.def_static("IsValid", py::overload_cast(&BTime::IsValid), "", py::arg("time")) +.def_static("IsValid", py::overload_cast(&BTime::IsValid), "", py::arg("hour"), py::arg("minute"), py::arg("second"), py::arg("microsecond")=0) +.def_static("CurrentTime", &BTime::CurrentTime, "", py::arg("type")) +.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("AddHours", &BTime::AddHours, "", py::arg("hours")) +.def("AddMinutes", &BTime::AddMinutes, "", py::arg("minutes")) +.def("AddSeconds", &BTime::AddSeconds, "", py::arg("seconds")) +.def("AddMilliseconds", &BTime::AddMilliseconds, "", py::arg("milliseconds")) +.def("AddMicroseconds", &BTime::AddMicroseconds, "", py::arg("microseconds")) +.def("Hour", &BTime::Hour, "") +.def("Minute", &BTime::Minute, "") +.def("Second", &BTime::Second, "") +.def("Millisecond", &BTime::Millisecond, "") +.def("Microsecond", &BTime::Microsecond, "") +.def("Difference", &BTime::Difference, "", py::arg("time"), py::arg("type")) +.def("__ne__", &BTime::operator!=, "", py::arg("time")) +.def("__eq__", &BTime::operator==, "", py::arg("time")) +.def("__lt__", &BTime::operator<, "", py::arg("time")) +.def("__le__", &BTime::operator<=, "", py::arg("time")) +.def("__gt__", &BTime::operator>, "", py::arg("time")) +.def("__ge__", &BTime::operator>=, "", py::arg("time")) +; + +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("time"), py::arg("type")=B_LOCAL_TIME) +.def(py::init(), "", py::arg("archive")) +.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("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("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")) +.def("AddMonths", &BDate::AddMonths, "", py::arg("months")) +.def("Day", &BDate::Day, "") +.def("Year", &BDate::Year, "") +.def("Month", &BDate::Month, "") +.def("Difference", &BDate::Difference, "", py::arg("date")) +.def("SetDay", &BDate::SetDay, "", py::arg("day")) +.def("SetMonth", &BDate::SetMonth, "", py::arg("month")) +.def("SetYear", &BDate::SetYear, "", py::arg("year")) +.def("DayOfWeek", &BDate::DayOfWeek, "") +.def("DayOfYear", &BDate::DayOfYear, "") +.def("WeekNumber", &BDate::WeekNumber, "") +//.def("IsLeapYear", py::overload_cast<>(&BDate::IsLeapYear, py::const_), "") +.def_static("IsLeapYear", py::overload_cast(&BDate::IsLeapYear), "", py::arg("year")) +.def("DaysInYear", &BDate::DaysInYear, "") +.def("DaysInMonth", &BDate::DaysInMonth, "") +//.def("ShortDayName", py::overload_cast<>(&BDate::ShortDayName, py::const_), "") +.def_static("ShortDayName", py::overload_cast(&BDate::ShortDayName), "", py::arg("day")) +//.def("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")) +.def("__lt__", &BDate::operator<, "", py::arg("date")) +.def("__le__", &BDate::operator<=, "", py::arg("date")) +.def("__gt__", &BDate::operator>, "", py::arg("date")) +.def("__ge__", &BDate::operator>=, "", py::arg("date")) +; + +py::class_(m, "BDateTime") +.def(py::init(), "") +.def(py::init(), "", py::arg("date"), py::arg("time")) +.def(py::init(), "", py::arg("archive")) +.def("Archive", &BDateTime::Archive, "", py::arg("into")) +.def("IsValid", &BDateTime::IsValid, "") +.def_static("CurrentDateTime", &BDateTime::CurrentDateTime, "", py::arg("type")) +.def("SetDateTime", &BDateTime::SetDateTime, "", py::arg("date"), py::arg("time")) +.def("Date", py::overload_cast<>(&BDateTime::Date), "") +.def("Date", py::overload_cast<>(&BDateTime::Date), "") +.def("SetDate", &BDateTime::SetDate, "", py::arg("date")) +.def("Time", py::overload_cast<>(&BDateTime::Time), "") +.def("Time", py::overload_cast<>(&BDateTime::Time), "") +.def("SetTime", &BDateTime::SetTime, "", py::arg("time")) +.def("Time_t", &BDateTime::Time_t, "") +.def("SetTime_t", &BDateTime::SetTime_t, "", py::arg("seconds")) +.def("__ne__", &BDateTime::operator!=, "", py::arg("dateTime")) +.def("__eq__", &BDateTime::operator==, "", py::arg("dateTime")) +.def("__lt__", &BDateTime::operator<, "", py::arg("dateTime")) +.def("__le__", &BDateTime::operator<=, "", py::arg("dateTime")) +.def("__gt__", &BDateTime::operator>, "", py::arg("dateTime")) +.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/Debug.cpp b/bindings/support/Debug.cpp new file mode 100644 index 0000000..56026c5 --- /dev/null +++ b/bindings/support/Debug.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_Debug(py::module_& m) +{ +m.attr("_rtDebugFlag") = py::cast(_rtDebugFlag); + +m.def("_debugFlag", &_debugFlag, "", py::arg("")); + +m.def("_setDebugFlag", &_setDebugFlag, "", py::arg("")); + +m.def("_debugPrintf", py::overload_cast(&_debugPrintf), "", py::arg("_PRINTFLIKE(1,2")); + +m.def("_sPrintf", py::overload_cast(&_sPrintf), "", py::arg("_PRINTFLIKE(1,2")); + +m.def("_debugPrintf", py::overload_cast(&_debugPrintf), "", py::arg("")); + +m.def("_sPrintf", py::overload_cast(&_sPrintf), "", py::arg("")); + +m.def("_xdebugPrintf", &_xdebugPrintf, "", py::arg("")); + +m.def("_debuggerAssert", &_debuggerAssert, "", py::arg(""), py::arg(""), py::arg("")); + +} diff --git a/bindings/support/Errors.cpp b/bindings/support/Errors.cpp new file mode 100644 index 0000000..96c3cf3 --- /dev/null +++ b/bindings/support/Errors.cpp @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_Errors(py::module_& m) +{ +m.def("_to_positive_error", &_to_positive_error, "", py::arg("error")); + +m.def("_to_negative_error", &_to_negative_error, "", py::arg("error")); + +} diff --git a/bindings/support/Flattenable.cpp b/bindings/support/Flattenable.cpp new file mode 100644 index 0000000..8920d94 --- /dev/null +++ b/bindings/support/Flattenable.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Flattenable, m) +{ +py::class_(m, "BFlattenable") +.def("IsFixedSize", &BFlattenable::IsFixedSize, "") +.def("TypeCode", &BFlattenable::TypeCode, "") +.def("FlattenedSize", &BFlattenable::FlattenedSize, "") +//.def("Flatten", &BFlattenable::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Flatten", [](const BFlattenable& self) { + ssize_t size = self.FlattenedSize(); + std::vector buffer(size); + status_t status = self.Flatten(buffer.data(), size); + //if (status != B_OK) { throw std::runtime_error("Flatten failed with status: " + std::to_string(status)); } + return std::make_tuple(status,py::bytes(buffer.data(), size)); +},"") +.def("AllowsTypeCode", &BFlattenable::AllowsTypeCode, "", py::arg("code")) +//.def("Unflatten", &BFlattenable::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +.def("Unflatten", [](BFlattenable& self, type_code code, py::bytes data) { + // Convert py::bytes to a void* buffer + std::string buffer = data; // py::bytes can be directly assigned to std::string + ssize_t size = buffer.size(); + status_t status = self.Unflatten(code, buffer.data(), size); + //if (status != B_OK) { throw std::runtime_error("Unflatten failed with status: " + std::to_string(status)); } + return status; },"",py::arg("code"),py::arg("data")) +; + + +} diff --git a/bindings/support/Job.cpp b/bindings/support/Job.cpp new file mode 100644 index 0000000..6a6e58d --- /dev/null +++ b/bindings/support/Job.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +using namespace BSupportKit; + +class PyBJob : public BJob{ + public: + using BJob::BJob; + status_t Run() override { + PYBIND11_OVERLOAD(status_t, BJob, Run); + } + status_t Execute() override { + PYBIND11_OVERLOAD_PURE(status_t, BJob, Execute); + } +}; + + +PYBIND11_MODULE(Job, m) +{ +py::enum_(m, "BJobState", "") +.value("B_JOB_STATE_WAITING_TO_RUN", BJobState::B_JOB_STATE_WAITING_TO_RUN, "") +.value("B_JOB_STATE_STARTED", BJobState::B_JOB_STATE_STARTED, "") +.value("B_JOB_STATE_IN_PROGRESS", BJobState::B_JOB_STATE_IN_PROGRESS, "") +.value("B_JOB_STATE_SUCCEEDED", BJobState::B_JOB_STATE_SUCCEEDED, "") +.value("B_JOB_STATE_FAILED", BJobState::B_JOB_STATE_FAILED, "") +.value("B_JOB_STATE_ABORTED", BJobState::B_JOB_STATE_ABORTED, "") +.export_values(); + +py::class_(m, "BJobStateListener") +.def("JobStarted", &BJobStateListener::JobStarted, "", py::arg("job")) +.def("JobProgress", &BJobStateListener::JobProgress, "", py::arg("job")) +.def("JobSucceeded", &BJobStateListener::JobSucceeded, "", py::arg("job")) +.def("JobFailed", &BJobStateListener::JobFailed, "", py::arg("job")) +.def("JobAborted", &BJobStateListener::JobAborted, "", py::arg("job")) +; + +py::class_(m, "BJob") +.def(py::init(), "", py::arg("title")) +.def("InitCheck", &BJob::InitCheck, "") +.def("Run", &BJob::Run, "") +.def("Title", &BJob::Title, "") +.def("State", &BJob::State, "") +.def("Result", &BJob::Result, "") +.def("ErrorString", &BJob::ErrorString, "") +.def("TicketNumber", &BJob::TicketNumber, "") +.def("AddStateListener", &BJob::AddStateListener, "", py::arg("listener")) +.def("RemoveStateListener", &BJob::RemoveStateListener, "", py::arg("listener")) +.def("IsRunnable", &BJob::IsRunnable, "") +.def("AddDependency", &BJob::AddDependency, "", py::arg("job")) +.def("RemoveDependency", &BJob::RemoveDependency, "", py::arg("job")) +.def("CountDependencies", &BJob::CountDependencies, "") +.def("DependantJobAt", &BJob::DependantJobAt, "", py::arg("index")) +//.def_readwrite("Private", &BJob::Private, "") +; + + +} diff --git a/bindings/support/List.cpp b/bindings/support/List.cpp new file mode 100644 index 0000000..82a55b8 --- /dev/null +++ b/bindings/support/List.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +bool CallPythonFunction(void* item, py::function& func) { + py::object result = func(item); + return py::cast(result); +} + +PYBIND11_MODULE(List, m) +{ +py::class_(m, "BList") +.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")) +.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("RemoveItems", &BList::RemoveItems, "", py::arg("index"), py::arg("count")) +.def("ReplaceItem", &BList::ReplaceItem, "", py::arg("index"), py::arg("item")) +.def("MakeEmpty", &BList::MakeEmpty, "") +.def("SortItems", &BList::SortItems, "", py::arg("")) +.def("SwapItems", &BList::SwapItems, "", py::arg("indexA"), py::arg("indexB")) +.def("MoveItem", &BList::MoveItem, "", py::arg("from"), py::arg("to")) +.def("ItemAt", &BList::ItemAt, "", py::arg("index")) +.def("FirstItem", &BList::FirstItem, "") +.def("ItemAtFast", &BList::ItemAtFast, "", py::arg("index")) +.def("LastItem", &BList::LastItem, "") +.def("Items", &BList::Items, "") +.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", [](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 new file mode 100644 index 0000000..091a4d4 --- /dev/null +++ b/bindings/support/Locker.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Locker, m) +{ +py::class_(m, "BLocker") +.def(py::init(), "") +.def(py::init(), "", py::arg("name")) +.def(py::init(), "", py::arg("benaphoreStyle")) +.def(py::init(), "", py::arg("name"), py::arg("benaphoreStyle")) +.def("InitCheck", &BLocker::InitCheck, "") +.def("Lock", &BLocker::Lock, "") +.def("LockWithTimeout", &BLocker::LockWithTimeout, "", py::arg("timeout")) +.def("Unlock", &BLocker::Unlock, "") +.def("LockingThread", &BLocker::LockingThread, "") +.def("IsLocked", &BLocker::IsLocked, "") +.def("CountLocks", &BLocker::CountLocks, "") +.def("CountLockRequests", &BLocker::CountLockRequests, "") +.def("Sem", &BLocker::Sem, "") +; + + +} diff --git a/bindings/support/Referenceable.cpp b/bindings/support/Referenceable.cpp new file mode 100644 index 0000000..922ce25 --- /dev/null +++ b/bindings/support/Referenceable.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_Referenceable(py::module_& m) +{ +py::class_(m, "BReferenceable") +.def(py::init(), "") +.def("AcquireReference", &BReferenceable::AcquireReference, "") +.def("ReleaseReference", &BReferenceable::ReleaseReference, "") +.def("CountReferences", &BReferenceable::CountReferences, "") +; + +py::class_(m, "BReference") +.def(py::init(), "") +.def(py::init(), "", py::arg("object"), py::arg("alreadyHasReference")=false) +.def(py::init &>(), "", py::arg("other")) +.def(py::init &>(), "", py::arg("other")) +.def("SetTo", &BReference::SetTo, "", py::arg("object"), py::arg("alreadyHasReference")=false) +.def("Unset", &BReference::Unset, "") +.def("IsSet", &BReference::IsSet, "") +.def("Get", &BReference::Get, "") +.def("Detach", &BReference::Detach, "") +.def("__mul__", &BReference::operator*, "") +.def("operator->", &BReference::operator->, "") +.def("operatorType*", &BReference::operatorType*, "") +.def("operator=", py::overload_cast &>(&BReference::operator=), "", py::arg("other")) +.def("operator=", py::overload_cast(&BReference::operator=), "", py::arg("other")) +.def("operator=", py::overload_cast &>(&BReference::operator=), "", py::arg("other")) +.def("__eq__", py::overload_cast &>(&BReference::operator==), "", py::arg("other")) +.def("__eq__", py::overload_cast(&BReference::operator==), "", py::arg("other")) +.def("__ne__", py::overload_cast &>(&BReference::operator!=), "", py::arg("other")) +.def("__ne__", py::overload_cast(&BReference::operator!=), "", py::arg("other")) +; + +py::class_>(m, "BReference") +.def(py::init(), "", py::arg("object"), py::arg("alreadyHasReference")=false) +.def(py::init &>(), "", py::arg("other")) +.def(py::init &>(), "", py::arg("other")) +.def("SetTo", &BReference::SetTo, "", py::arg("object"), py::arg("alreadyHasReference")=false) +.def("Unset", &BReference::Unset, "") +.def("IsSet", &BReference::IsSet, "") +.def("Get", &BReference::Get, "") +.def("Detach", &BReference::Detach, "") +.def("__mul__", &BReference::operator*, "") +.def("operator->", &BReference::operator->, "") +.def("operatorconstType*", &BReference::operatorconstType*, "") +.def("operator=", py::overload_cast &>(&BReference::operator=), "", py::arg("other")) +.def("operator=", py::overload_cast(&BReference::operator=), "", py::arg("other")) +.def("operator=", py::overload_cast &>(&BReference::operator=), "", py::arg("other")) +.def("__eq__", py::overload_cast &>(&BReference::operator==), "", py::arg("other")) +.def("__eq__", py::overload_cast(&BReference::operator==), "", py::arg("other")) +.def("__ne__", py::overload_cast &>(&BReference::operator!=), "", py::arg("other")) +.def("__ne__", py::overload_cast(&BReference::operator!=), "", py::arg("other")) +; + + +} diff --git a/bindings/support/StackOrHeapArray.cpp b/bindings/support/StackOrHeapArray.cpp new file mode 100644 index 0000000..4758141 --- /dev/null +++ b/bindings/support/StackOrHeapArray.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_StackOrHeapArray(py::module_& m) +{ +py::class_(m, "BStackOrHeapArray") +.def(py::init(), "", py::arg("count")) +.def("IsValid", &BStackOrHeapArray::IsValid, "") +.def("operatorType*", &BStackOrHeapArray::operatorType*, "") +; + + +} diff --git a/bindings/support/StopWatch.cpp b/bindings/support/StopWatch.cpp new file mode 100644 index 0000000..9ffcdd0 --- /dev/null +++ b/bindings/support/StopWatch.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(StopWatch, m) +{ +py::class_(m, "BStopWatch") +.def(py::init(), "", py::arg("name"), py::arg("silent")=false) +.def("Suspend", &BStopWatch::Suspend, "") +.def("Resume", &BStopWatch::Resume, "") +.def("Lap", &BStopWatch::Lap, "") +.def("ElapsedTime", &BStopWatch::ElapsedTime, "") +.def("Reset", &BStopWatch::Reset, "") +.def("Name", &BStopWatch::Name, "") +; + + +} diff --git a/bindings/support/String.cpp b/bindings/support/String.cpp new file mode 100644 index 0000000..f4174cd --- /dev/null +++ b/bindings/support/String.cpp @@ -0,0 +1,309 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace py = pybind11; + + +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(), "") +.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, 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) { + 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")) +.def("Adopt", [](BString& self) { + BString from; + BString & r = self.Adopt(from); + return std::make_tuple(r,from); +} +, "") +.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,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,int32 fromOffset,int32 length) { + BString into; + BString & r = self.CopyInto(into, fromOffset, length); + return std::make_tuple(r,into); +} +, "", py::arg("fromOffset"), py::arg("length")) +.def("CopyInto", py::overload_cast(&BString::CopyInto, py::const_), "", py::arg("into"), py::arg("fromOffset"), py::arg("length")) +.def("CopyCharsInto", [](BString& self,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::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); + return std::make_tuple(r,_list); +} +, "", py::arg("separator"), py::arg("noEmptyStrings")) +.def("__iadd__", py::overload_cast(&BString::operator+=), "", py::arg("string")) +.def("__iadd__", py::overload_cast(&BString::operator+=), "", py::arg("string")) +.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("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("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")) +.def("RemoveChars", &BString::RemoveChars, "", py::arg("fromCharOffset"), py::arg("charCount")) +.def("RemoveFirst", py::overload_cast(&BString::RemoveFirst), "", py::arg("string")) +.def("RemoveLast", py::overload_cast(&BString::RemoveLast), "", py::arg("string")) +.def("RemoveAll", py::overload_cast(&BString::RemoveAll), "", py::arg("string")) +.def("RemoveFirst", py::overload_cast(&BString::RemoveFirst), "", py::arg("string")) +.def("RemoveLast", py::overload_cast(&BString::RemoveLast), "", py::arg("string")) +.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,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,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::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::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("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("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("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("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::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::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")) +.def("ToLower", &BString::ToLower, "") +.def("ToUpper", &BString::ToUpper, "") +.def("Capitalize", &BString::Capitalize, "") +.def("CapitalizeEachWord", &BString::CapitalizeEachWord, "") +.def("CharacterEscape", py::overload_cast(&BString::CharacterEscape), "", py::arg("original"), py::arg("setOfCharsToEscape"), py::arg("escapeWith")) +.def("CharacterEscape", py::overload_cast(&BString::CharacterEscape), "", py::arg("setOfCharsToEscape"), py::arg("escapeWith")) +.def("CharacterDeescape", py::overload_cast(&BString::CharacterDeescape), "", py::arg("original"), py::arg("escapeChar")) +.def("CharacterDeescape", py::overload_cast(&BString::CharacterDeescape), "", py::arg("escapeChar")) +.def("Trim", &BString::Trim, "") +.def("__lshift__", py::overload_cast(&BString::operator<<), "", py::arg("string")) +.def("__lshift__", py::overload_cast(&BString::operator<<), "", py::arg("string")) +.def("__lshift__", py::overload_cast(&BString::operator<<), "", py::arg("c")) +.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("__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("__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, "") +; +/* +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")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("a"), py::arg("b")); + +m.def("__gt__", py::overload_cast(&operator>), "", py::arg("a"), py::arg("b")); + +m.def("__ge__", py::overload_cast(&operator>=), "", py::arg("a"), py::arg("b")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("a"), py::arg("b")); + +m.def("Compare", py::overload_cast(&Compare), "", py::arg("a"), py::arg("b")); + +m.def("ICompare", py::overload_cast(&ICompare), "", py::arg("a"), py::arg("b")); + +m.def("Compare", py::overload_cast(&Compare), "", py::arg("a"), py::arg("b")); + +m.def("ICompare", py::overload_cast(&ICompare), "", py::arg("a"), py::arg("b")); + +m.def("__getitem__", &operator[], "", py::arg("index")); + +m.def("__iadd__", &operator+=, "", py::arg("string")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("string")); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("string")); + +m.def("__le__", py::overload_cast(&operator<=), "", py::arg("string")); + +m.def("__ge__", py::overload_cast(&operator>=), "", py::arg("string")); + +m.def("__gt__", py::overload_cast(&operator>), "", py::arg("string")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("string")); + +m.def("__ne__", py::overload_cast(&operator!=), "", py::arg("string")); + +m.def("operatorconstchar*", &operatorconstchar*, ""); + +m.def("__lt__", py::overload_cast(&operator<), "", py::arg("str"), py::arg("string")); + +m.def("__le__", py::overload_cast(&operator<=), "", py::arg("str"), py::arg("string")); + +m.def("__eq__", py::overload_cast(&operator==), "", py::arg("str"), py::arg("string")); + +m.def("__gt__", py::overload_cast(&operator>), "", py::arg("str"), py::arg("string")); + +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 new file mode 100644 index 0000000..7b93d0e --- /dev/null +++ b/bindings/support/StringList.cpp @@ -0,0 +1,102 @@ +#include +#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); + } +}; + +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("other")) +.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")) +.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("Replace", &BStringList::Replace, "", py::arg("index"), py::arg("string")) +.def("MakeEmpty", &BStringList::MakeEmpty, "") +.def("Sort", &BStringList::Sort, "", py::arg("ignoreCase")=false) +.def("Swap", &BStringList::Swap, "", py::arg("indexA"), py::arg("indexB")) +.def("Move", &BStringList::Move, "", py::arg("fromIndex"), py::arg("toIndex")) +.def("StringAt", &BStringList::StringAt, "", py::arg("index")) +.def("First", &BStringList::First, "") +.def("Last", &BStringList::Last, "") +.def("HasString", &BStringList::HasString, "", py::arg("string"), py::arg("ignoreCase")=false) +.def("IndexOf", &BStringList::IndexOf, "", py::arg("string"), py::arg("ignoreCase")=false) +.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", [](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")) +.def("IsFixedSize", &BStringList::IsFixedSize, "") +.def("TypeCode", &BStringList::TypeCode, "") +.def("AllowsTypeCode", &BStringList::AllowsTypeCode, "", py::arg("code")) +.def("FlattenedSize", &BStringList::FlattenedSize, "") +.def("Flatten", &BStringList::Flatten, "", py::arg("buffer"), py::arg("size")) +.def("Unflatten", &BStringList::Unflatten, "", py::arg("code"), py::arg("buffer"), py::arg("size")) +; + +//m.def("__ne__", &operator!=, "", py::arg("other")); + +} diff --git a/bindings/support/SupportDefs.cpp b/bindings/support/SupportDefs.cpp new file mode 100644 index 0000000..d27868c --- /dev/null +++ b/bindings/support/SupportDefs.cpp @@ -0,0 +1,136 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +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("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/TLS.cpp b/bindings/support/TLS.cpp new file mode 100644 index 0000000..23a0852 --- /dev/null +++ b/bindings/support/TLS.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; +//TODO: Please, test this module +PYBIND11_MODULE(TLS, m) +{ +m.def("tls_allocate", &tls_allocate, ""); + +m.def("tls_get", &tls_get, "", py::arg("index")); + +m.def("tls_address", &tls_address, "", py::arg("index")); + +m.def("tls_set", &tls_set, "", py::arg("index"), py::arg("value")); //todo value is a void* + +} diff --git a/bindings/support/TypeConstants.cpp b/bindings/support/TypeConstants.cpp new file mode 100644 index 0000000..d4d41ed --- /dev/null +++ b/bindings/support/TypeConstants.cpp @@ -0,0 +1,170 @@ +#include +#include +#include +#include +//<<<<<<< HEAD + +#include +/* +namespace py = pybind11; + +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); +m.attr("B_ANY_TYPE") = py::cast(B_ANY_TYPE); +m.attr("B_ATOM_TYPE") = py::cast(B_ATOM_TYPE); +m.attr("B_ATOMREF_TYPE") = py::cast(B_ATOMREF_TYPE); +m.attr("B_BOOL_TYPE") = py::cast(B_BOOL_TYPE); +m.attr("B_CHAR_TYPE") = py::cast(B_CHAR_TYPE); +m.attr("B_COLOR_8_BIT_TYPE") = py::cast(B_COLOR_8_BIT_TYPE); +m.attr("B_DOUBLE_TYPE") = py::cast(B_DOUBLE_TYPE); +m.attr("B_FLOAT_TYPE") = py::cast(B_FLOAT_TYPE); +m.attr("B_GRAYSCALE_8_BIT_TYPE") = py::cast(B_GRAYSCALE_8_BIT_TYPE); +m.attr("B_INT16_TYPE") = py::cast(B_INT16_TYPE); +m.attr("B_INT32_TYPE") = py::cast(B_INT32_TYPE); +m.attr("B_INT64_TYPE") = py::cast(B_INT64_TYPE); +m.attr("B_INT8_TYPE") = py::cast(B_INT8_TYPE); +m.attr("B_LARGE_ICON_TYPE") = py::cast(B_LARGE_ICON_TYPE); +m.attr("B_MEDIA_PARAMETER_GROUP_TYPE") = py::cast(B_MEDIA_PARAMETER_GROUP_TYPE); +m.attr("B_MEDIA_PARAMETER_TYPE") = py::cast(B_MEDIA_PARAMETER_TYPE); +m.attr("B_MEDIA_PARAMETER_WEB_TYPE") = py::cast(B_MEDIA_PARAMETER_WEB_TYPE); +m.attr("B_MESSAGE_TYPE") = py::cast(B_MESSAGE_TYPE); +m.attr("B_MESSENGER_TYPE") = py::cast(B_MESSENGER_TYPE); +m.attr("B_MIME_TYPE") = py::cast(B_MIME_TYPE); +m.attr("B_MINI_ICON_TYPE") = py::cast(B_MINI_ICON_TYPE); +m.attr("B_MONOCHROME_1_BIT_TYPE") = py::cast(B_MONOCHROME_1_BIT_TYPE); +m.attr("B_OBJECT_TYPE") = py::cast(B_OBJECT_TYPE); +m.attr("B_OFF_T_TYPE") = py::cast(B_OFF_T_TYPE); +m.attr("B_PATTERN_TYPE") = py::cast(B_PATTERN_TYPE); +m.attr("B_POINTER_TYPE") = py::cast(B_POINTER_TYPE); +m.attr("B_POINT_TYPE") = py::cast(B_POINT_TYPE); +m.attr("B_PROPERTY_INFO_TYPE") = py::cast(B_PROPERTY_INFO_TYPE); +m.attr("B_RAW_TYPE") = py::cast(B_RAW_TYPE); +m.attr("B_RECT_TYPE") = py::cast(B_RECT_TYPE); +m.attr("B_REF_TYPE") = py::cast(B_REF_TYPE); +m.attr("B_NODE_REF_TYPE") = py::cast(B_NODE_REF_TYPE); +m.attr("B_RGB_32_BIT_TYPE") = py::cast(B_RGB_32_BIT_TYPE); +m.attr("B_RGB_COLOR_TYPE") = py::cast(B_RGB_COLOR_TYPE); +m.attr("B_SIZE_TYPE") = py::cast(B_SIZE_TYPE); +m.attr("B_SIZE_T_TYPE") = py::cast(B_SIZE_T_TYPE); +m.attr("B_SSIZE_T_TYPE") = py::cast(B_SSIZE_T_TYPE); +m.attr("B_STRING_TYPE") = py::cast(B_STRING_TYPE); +m.attr("B_STRING_LIST_TYPE") = py::cast(B_STRING_LIST_TYPE); +m.attr("B_TIME_TYPE") = py::cast(B_TIME_TYPE); +m.attr("B_UINT16_TYPE") = py::cast(B_UINT16_TYPE); +m.attr("B_UINT32_TYPE") = py::cast(B_UINT32_TYPE); +m.attr("B_UINT64_TYPE") = py::cast(B_UINT64_TYPE); +m.attr("B_UINT8_TYPE") = py::cast(B_UINT8_TYPE); +m.attr("B_VECTOR_ICON_TYPE") = py::cast(B_VECTOR_ICON_TYPE); +m.attr("B_XATTR_TYPE") = py::cast(B_XATTR_TYPE); +m.attr("B_NETWORK_ADDRESS_TYPE") = py::cast(B_NETWORK_ADDRESS_TYPE); +m.attr("B_MIME_STRING_TYPE") = py::cast(B_MIME_STRING_TYPE); +m.attr("B_ASCII_TYPE") = py::cast(B_ASCII_TYPE); + +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); + + +} +*/ + +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/UTF8.cpp b/bindings/support/UTF8.cpp new file mode 100644 index 0000000..18e1bef --- /dev/null +++ b/bindings/support/UTF8.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(UTF8, m) +{ +m.attr("B_ISO1_CONVERSION") = 0;//py::cast(B_ISO....); +m.attr("B_ISO2_CONVERSION") = 1; +m.attr("B_ISO3_CONVERSION") = 2; +m.attr("B_ISO4_CONVERSION") = 3; +m.attr("B_ISO5_CONVERSION") = 4; +m.attr("B_ISO6_CONVERSION") = 5; +m.attr("B_ISO7_CONVERSION") = 6; +m.attr("B_ISO8_CONVERSION") = 7; +m.attr("B_ISO9_CONVERSION") = 8; +m.attr("B_ISO10_CONVERSION") = 9; +m.attr("B_MAC_ROMAN_CONVERSION") = 10; +m.attr("B_SJIS_CONVERSION") = 11; +m.attr("B_EUC_CONVERSION") = 12; +m.attr("B_JIS_CONVERSION") = 13; +m.attr("B_MS_WINDOWS_CONVERSION") = 14; +m.attr("B_UNICODE_CONVERSION") = 15; +m.attr("B_KOI8R_CONVERSION") = 16; +m.attr("B_MS_WINDOWS_1251_CONVERSION") = 17; +m.attr("B_MS_DOS_866_CONVERSION") = 18; +m.attr("B_MS_DOS_CONVERSION") = 19; +m.attr("B_EUC_KR_CONVERSION") = 20; +m.attr("B_ISO13_CONVERSION") = 21; +m.attr("B_ISO14_CONVERSION") = 22; +m.attr("B_ISO15_CONVERSION") = 23; +m.attr("B_BIG5_CONVERSION") = 24; +m.attr("B_GBK_CONVERSION") = 25; +m.attr("B_UTF16_CONVERSION") = 26; +m.attr("B_MS_WINDOWS_1250_CONVERSION") = 27; + +m.def("convert_to_utf8", &convert_to_utf8, "", py::arg("sourceEncoding"), py::arg("source"), py::arg("sourceLength"), py::arg("dest"), py::arg("destLength"), py::arg("state"), py::arg("substitute")=0x1a);//hardcoded B_SUBSTITUTE + +m.def("convert_from_utf8", &convert_from_utf8, "", py::arg("destEncoding"), py::arg("source"), py::arg("sourceLength"), py::arg("dest"), py::arg("destLength"), py::arg("state"), py::arg("substitute")=0x1a);//hardcoded B_SUBSTITUTE + +} diff --git a/bindings/support/Url.cpp b/bindings/support/Url.cpp new file mode 100644 index 0000000..3828031 --- /dev/null +++ b/bindings/support/Url.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(Url, m) +{ +py::class_(m, "BUrl") +.def(py::init(), "", py::arg("url")) +.def(py::init(), "", py::arg("archive")) +.def(py::init(), "", py::arg("other")) +.def(py::init(), "", py::arg("base"), py::arg("relative")) +.def(py::init(), "", py::arg("path")) +.def(py::init(), "") +.def("SetUrlString", &BUrl::SetUrlString, "", py::arg("url")) +.def("SetProtocol", &BUrl::SetProtocol, "", py::arg("scheme")) +.def("SetUserName", &BUrl::SetUserName, "", py::arg("user")) +.def("SetPassword", &BUrl::SetPassword, "", py::arg("password")) +.def("SetAuthority", &BUrl::SetAuthority, "", py::arg("authority")) +.def("SetHost", &BUrl::SetHost, "", py::arg("host")) +.def("SetPort", &BUrl::SetPort, "", py::arg("port")) +.def("SetPath", &BUrl::SetPath, "", py::arg("path")) +.def("SetRequest", &BUrl::SetRequest, "", py::arg("request")) +.def("SetFragment", &BUrl::SetFragment, "", py::arg("fragment")) +.def("UrlString", &BUrl::UrlString, "") +.def("Protocol", &BUrl::Protocol, "") +.def("UserName", &BUrl::UserName, "") +.def("Password", &BUrl::Password, "") +.def("UserInfo", &BUrl::UserInfo, "") +.def("Host", &BUrl::Host, "") +.def("Port", &BUrl::Port, "") +.def("Authority", &BUrl::Authority, "") +.def("Path", &BUrl::Path, "") +.def("Request", &BUrl::Request, "") +.def("Fragment", &BUrl::Fragment, "") +.def("IsValid", &BUrl::IsValid, "") +.def("HasProtocol", &BUrl::HasProtocol, "") +.def("HasUserName", &BUrl::HasUserName, "") +.def("HasPassword", &BUrl::HasPassword, "") +.def("HasUserInfo", &BUrl::HasUserInfo, "") +.def("HasHost", &BUrl::HasHost, "") +.def("HasPort", &BUrl::HasPort, "") +.def("HasAuthority", &BUrl::HasAuthority, "") +.def("HasPath", &BUrl::HasPath, "") +.def("HasRequest", &BUrl::HasRequest, "") +.def("HasFragment", &BUrl::HasFragment, "") +.def("UrlEncode", py::overload_cast(&BUrl::UrlEncode), "", py::arg("strict")=false) +.def("UrlDecode", py::overload_cast(&BUrl::UrlDecode), "", py::arg("strict")=false) +.def("IDNAToAscii", &BUrl::IDNAToAscii, "") +.def("IDNAToUnicode", &BUrl::IDNAToUnicode, "") +.def_static("UrlEncodeStatic", py::overload_cast(&BUrl::UrlEncode), "", py::arg("url"), py::arg("strict")=false, py::arg("directory")=false) +.def_static("UrlDecodeStatic", py::overload_cast(&BUrl::UrlDecode), "", py::arg("url"), py::arg("strict")=false) +.def("HasPreferredApplication", &BUrl::HasPreferredApplication, "") +.def("PreferredApplication", &BUrl::PreferredApplication, "") +.def("OpenWithPreferredApplication", &BUrl::OpenWithPreferredApplication, "", py::arg("onProblemAskUser")=true) +.def("Archive", &BUrl::Archive, "", py::arg("into"), py::arg("deep")=true) +.def_static("Instantiate", &BUrl::Instantiate, "", py::arg("archive")) +.def("__eq__", [](BUrl& self) { + BUrl other; + bool r = self.operator==(other); + return std::make_tuple(r,other); +} +, "") +.def("__ne__", [](BUrl& self) { + BUrl other; + bool r = self.operator!=(other); + return std::make_tuple(r,other); +} +, "") +.def("operator=", py::overload_cast(&BUrl::operator=), "", py::arg("other")) +.def("operator=", py::overload_cast(&BUrl::operator=), "", py::arg("string")) +.def("operator=", py::overload_cast(&BUrl::operator=), "", py::arg("string")) +//.def("operatorconstchar*", &BUrl::operatorconstchar*, "") +; + + +} diff --git a/bindings/support/old/Archivable.cpp b/bindings/support/old/Archivable.cpp new file mode 100644 index 0000000..c9a445b --- /dev/null +++ b/bindings/support/old/Archivable.cpp @@ -0,0 +1,30 @@ +#include +#include +#include "support/Archivable.h" // Assicurati che il nome del tuo file header sia corretto + +namespace py = pybind11; + +class PyBArchivable : public BArchivable { +public: + // Costruttori + using BArchivable::BArchivable; // Eredità dei costruttori base + + // Metodo per l'archiviazione + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD_PURE(status_t, BArchivable, Archive, into, deep); + } + + // Altri metodi da esporre a Python, se necessario +}; + +PYBIND11_MODULE(Archivable, m) { + py::class_(m, "BArchivable") + .def(py::init()) + .def(py::init<>()) + .def("Archive", &BArchivable::Archive); + + // Aggiungi altri metodi e costruttori se necessario + + // Aggiungi altre classi wrapper se necessario +} + diff --git a/bindings/support/old/SupportDefs.cpp b/bindings/support/old/SupportDefs.cpp new file mode 100644 index 0000000..ef6ebbc --- /dev/null +++ b/bindings/support/old/SupportDefs.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include "support/SupportDefs.h" +#include + +namespace py = pybind11; + +PYBIND11_MODULE(SupportDefs, m) { + m.attr("B_EMPTY_STRING") = B_EMPTY_STRING; + + // Definizione dei tipi di dati + py::class_(m, "status_t"); + py::class_(m, "bigtime_t"); + py::class_(m, "type_code"); + + py::class_(m, "phys_addr_t"); + + // ... Aggiungi altri tipi di dati secondo necessità ... + + // Aggiungi costanti o macro se necessario + m.attr("B_PRId8") = B_PRId8; + m.attr("B_PRIi8") = B_PRIi8; + m.attr("B_PRId16") = B_PRId16; + m.attr("B_PRIi16") = B_PRIi16; + m.attr("B_PRId32") = B_PRId32; + m.attr("B_PRIi32") = B_PRIi32; + m.attr("B_PRId64") = B_PRId64; + m.attr("B_PRIi64") = B_PRIi64; + + m.attr("B_PRIu8") = B_PRIu8; + m.attr("B_PRIo8") = B_PRIo8; + m.attr("B_PRIx8") = B_PRIx8; + m.attr("B_PRIX8") = B_PRIX8; + m.attr("B_PRIu16") = B_PRIu16; + m.attr("B_PRIo16") = B_PRIo16; + m.attr("B_PRIx16") = B_PRIx16; + m.attr("B_PRIX16") = B_PRIX16; + m.attr("B_PRIu32") = B_PRIu32; + m.attr("B_PRIo32") = B_PRIo32; + m.attr("B_PRIx32") = B_PRIx32; + m.attr("B_PRIX32") = B_PRIX32; + m.attr("B_PRIu64") = B_PRIu64; + m.attr("B_PRIo64") = B_PRIo64; + m.attr("B_PRIx64") = B_PRIx64; + m.attr("B_PRIX64") = B_PRIX64; + + m.attr("B_SCNd8") = B_SCNd8; + m.attr("B_SCNi8") = B_SCNi8; + m.attr("B_SCNd16") = B_SCNd16; + m.attr("B_SCNi16") = B_SCNi16; + m.attr("B_SCNd32") = B_SCNd32; + m.attr("B_SCNi32") = B_SCNi32; + m.attr("B_SCNd64") = B_SCNd64; + m.attr("B_SCNi64") = B_SCNi64; + + m.attr("B_SCNu8") = B_SCNu8; + m.attr("B_SCNo8") = B_SCNo8; + m.attr("B_SCNx8") = B_SCNx8; + m.attr("B_SCNu16") = B_SCNu16; + m.attr("B_SCNo16") = B_SCNo16; + m.attr("B_SCNx16") = B_SCNx16; + m.attr("B_SCNu32") = B_SCNu32; + m.attr("B_SCNo32") = B_SCNo32; + m.attr("B_SCNx32") = B_SCNx32; + m.attr("B_SCNu64") = B_SCNu64; + m.attr("B_SCNo64") = B_SCNo64; + m.attr("B_SCNx64") = B_SCNx64; + // ... Aggiungi altre costanti o macro secondo necessità ... + m.attr("B_PRIuSIZE") = B_PRIuSIZE; + m.attr("B_PRIoSIZE") = B_PRIoSIZE; + m.attr("B_PRIxSIZE") = B_PRIxSIZE; + m.attr("B_PRIXSIZE") = B_PRIXSIZE; + m.attr("B_SCNuSIZE") = B_SCNuSIZE; + m.attr("B_SCNoSIZE") = B_SCNoSIZE; + m.attr("B_SCNxSIZE") = B_SCNxSIZE; + m.attr("B_PRIdSSIZE") = B_PRIdSSIZE; + m.attr("B_PRIiSSIZE") = B_PRIiSSIZE; + m.attr("B_SCNdSSIZE") = B_SCNdSSIZE; + m.attr("B_SCNiSSIZE") = B_SCNiSSIZE; + m.attr("B_PRIuADDR") = B_PRIuADDR; + m.attr("B_PRIoADDR") = B_PRIoADDR; + m.attr("B_PRIxADDR") = B_PRIxADDR; + m.attr("B_PRIXADDR") = B_PRIXADDR; + m.attr("B_SCNuADDR") = B_SCNuADDR; + m.attr("B_SCNoADDR") = B_SCNoADDR; + m.attr("B_PRIuPHYSADDR") = B_PRIuPHYSADDR; + m.attr("B_PRIoPHYSADDR") = B_PRIoPHYSADDR; + m.attr("B_PRIxPHYSADDR") = B_PRIxPHYSADDR; + m.attr("B_PRIXPHYSADDR") = B_PRIXPHYSADDR; + m.attr("B_SCNuPHYSADDR") = B_SCNuPHYSADDR; + m.attr("B_SCNoPHYSADDR") = B_SCNoPHYSADDR; + m.attr("B_SCNxPHYSADDR") = B_SCNxPHYSADDR; + m.attr("B_PRIuGENADDR") = B_PRIuGENADDR; + m.attr("B_PRIoGENADDR") = B_PRIoGENADDR; + m.attr("B_PRIxGENADDR") = B_PRIxGENADDR; + m.attr("B_PRIXGENADDR") = B_PRIXGENADDR; + m.attr("B_SCNuGENADDR") = B_SCNuGENADDR; + m.attr("B_SCNoGENADDR") = B_SCNoGENADDR; + m.attr("B_SCNxGENADDR") = B_SCNxGENADDR; + m.attr("B_PRIdOFF") = B_PRIdOFF; + m.attr("B_PRIiOFF") = B_PRIiOFF; + m.attr("B_PRIxOFF") = B_PRIxOFF; + m.attr("B_SCNdOFF") = B_SCNdOFF; + m.attr("B_SCNiOFF") = B_SCNiOFF; + m.attr("B_SCNxOFF") = B_SCNxOFF; + m.attr("B_PRIdDEV") = B_PRIdDEV; + m.attr("B_PRIiDEV") = B_PRIiDEV; + m.attr("B_PRIdINO") = B_PRIdINO; + m.attr("B_PRIiINO") = B_PRIiINO; + m.attr("B_PRIdBIGTIME") = B_PRIdBIGTIME; + m.attr("B_PRIiBIGTIME") = B_PRIiBIGTIME; +} + diff --git a/bindings/support/parsedate.cpp b/bindings/support/parsedate.cpp new file mode 100644 index 0000000..b40e388 --- /dev/null +++ b/bindings/support/parsedate.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +// 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_wrapper, "", py::arg("table")); + +m.def("get_dateformats", &get_dateformats_wrapper, "", py::return_value_policy::take_ownership); + +} diff --git a/bindings/translation/BitmapStream.cpp b/bindings/translation/BitmapStream.cpp new file mode 100644 index 0000000..b7621ff --- /dev/null +++ b/bindings/translation/BitmapStream.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; +/* +status_t DetachBitmap_wrapper(BBitmapStream& self, std::vector _bitmap) { + return self.DetachBitmap(_bitmap.data()); +}*/ + +class PyBBitmapStream : public BBitmapStream{ + public: + using BBitmapStream::BBitmapStream; + ssize_t ReadAt(off_t offset, void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBitmapStream, ReadAt, offset, buffer, size); + } + ssize_t WriteAt(off_t offset, const void* buffer, size_t size) override { + PYBIND11_OVERLOAD(ssize_t, BBitmapStream, WriteAt, offset, buffer, size); + } + off_t Seek(off_t position, uint32 seekMode) override { + PYBIND11_OVERLOAD(off_t, BBitmapStream, Seek, position, seekMode); + } + off_t Position() const override { + PYBIND11_OVERLOAD(off_t, BBitmapStream, Position); + } + off_t Size() const override { + PYBIND11_OVERLOAD(off_t, BBitmapStream, Size); + } + status_t SetSize(off_t size) override { + PYBIND11_OVERLOAD(status_t, BBitmapStream, SetSize, size); + } +}; + +PYBIND11_MODULE(BitmapStream,m) +{ +py::class_(m, "BBitmapStream") +.def(py::init(), "", py::arg("bitmap")=NULL) +//.def("ReadAt", &BBitmapStream::ReadAt, "", py::arg("offset"), py::arg("buffer"), py::arg("size")) //convert buffer +.def("ReadAt", [](BBitmapStream& self, off_t offset, size_t size)->py::tuple{ + std::vectorbuffer(size); + ssize_t bytesRead = self.ReadAt(offset, buffer.data(), size); + py::bytes pyBytes(buffer.data(),bytesRead); + return py::make_tuple(pyBytes, bytesRead); +},"", py::arg("offset"),py::arg("size")) +//.def("WriteAt", &BBitmapStream::WriteAt, "", py::arg("offset"), py::arg("buffer"), py::arg("size")) //convert buffer +.def("WriteAt", [](BBitmapStream& self, off_t offset, py::buffer buffer){ + py::buffer_info info = buffer.request(); + const void* data = info.ptr; + size_t length = info.size; + return self.WriteAt(offset,data,length); +}, "",py::arg("offset"),py::arg("buffer")) +.def("Seek", &BBitmapStream::Seek, "", py::arg("position"), py::arg("seekMode")) +.def("Position", &BBitmapStream::Position, "") +.def("Size", &BBitmapStream::Size, "") +.def("SetSize", &BBitmapStream::SetSize, "", py::arg("size")) +//.def("DetachBitmap", &BBitmapStream::DetachBitmap, "", py::arg("_bitmap")) +//.def("DetachBitmap", &DetachBitmap_wrapper, "", py::arg("_bitmap")) //ok, it compiles, but... How do we pass the std::vector called _bitmap? +.def("DetachBitmap", [](BBitmapStream& self) { + BBitmap* bitmap = nullptr; + status_t status = self.DetachBitmap(&bitmap); + + if (bitmap != nullptr) { + return py::make_tuple(status, py::cast(bitmap)); + } else { + return py::make_tuple(status, py::none()); + } +}) + +; + + +} diff --git a/bindings/translation/TranslationDefs.cpp b/bindings/translation/TranslationDefs.cpp new file mode 100644 index 0000000..f6c0ba9 --- /dev/null +++ b/bindings/translation/TranslationDefs.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(TranslationDefs, m) +{ +//m.attr("B_TRANSLATOR_MIME_TYPE") = py::cast(B_TRANSLATOR_MIME_TYPE); +//m.attr("B_TRANSLATOR_MIME_TYPE") = B_TRANSLATOR_MIME_TYPE; + +py::class_(m, "translation_format") +.def_readwrite("type", &translation_format::type, "") +.def_readwrite("group", &translation_format::group, "") +.def_readwrite("quality", &translation_format::quality, "") +.def_readwrite("capability", &translation_format::capability, "") +//.def_readwrite("MIME", &translation_format::MIME, "") +//.def_readwrite("name", &translation_format::name, "") +.def_property("MIME", + [](const translation_format &t) { + return std::string(t.MIME); + }, + [](translation_format &t, const std::string &value) { + std::strncpy(t.MIME, value.c_str(), sizeof(t.MIME)); + }) +.def_property("name", + [](const translation_format &t) { + return std::string(t.name); + }, + [](translation_format &t, const std::string &value) { + std::strncpy(t.name, value.c_str(), sizeof(t.name)); + }) +; + +py::class_(m, "translator_info") +.def_readwrite("type", &translator_info::type, "") +.def_readwrite("translator", &translator_info::translator, "") +.def_readwrite("group", &translator_info::group, "") +.def_readwrite("quality", &translator_info::quality, "") +.def_readwrite("capability", &translator_info::capability, "") +//.def_readwrite("name", &translator_info::name, "") +//.def_readwrite("MIME", &translator_info::MIME, "") +.def_property("name", + [](const translator_info &t) { + return std::string(t.name); + }, + [](translator_info &t, const std::string &value) { + std::strncpy(t.name, value.c_str(), sizeof(t.name)); + }) +.def_property("MIME", + [](const translator_info &t) { + return std::string(t.MIME); + }, + [](translator_info &t, const std::string &value) { + std::strncpy(t.MIME, value.c_str(), sizeof(t.MIME)); + }) +; + + +} diff --git a/bindings/translation/TranslationErrors.cpp b/bindings/translation/TranslationErrors.cpp new file mode 100644 index 0000000..4d6e393 --- /dev/null +++ b/bindings/translation/TranslationErrors.cpp @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_TranslationErrors(py::module_& m) +{ + +} diff --git a/bindings/translation/TranslationUtils.cpp b/bindings/translation/TranslationUtils.cpp new file mode 100644 index 0000000..c346b1e --- /dev/null +++ b/bindings/translation/TranslationUtils.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; + + +PYBIND11_MODULE(TranslationUtils, m) +{ +py::class_>(m, "BTranslationUtils") +.def_static("GetBitmap", py::overload_cast(&BTranslationUtils::GetBitmap), "", py::arg("name"), py::arg("roster")=NULL) +.def_static("GetBitmap", py::overload_cast(&BTranslationUtils::GetBitmap), "", py::arg("type"), py::arg("id"), py::arg("roster")=NULL) +.def_static("GetBitmap", py::overload_cast(&BTranslationUtils::GetBitmap), "", py::arg("type"), py::arg("name"), py::arg("roster")=NULL) +.def_static("GetBitmapFile", &BTranslationUtils::GetBitmapFile, "", py::arg("name"), py::arg("roster")=NULL) +.def_static("GetBitmap", py::overload_cast(&BTranslationUtils::GetBitmap), "", py::arg("ref"), py::arg("roster")=NULL) +.def_static("GetBitmap", py::overload_cast(&BTranslationUtils::GetBitmap), "", py::arg("stream"), py::arg("roster")=NULL) +//.def_static("SetBitmapColorSpace", &BTranslationUtils::SetBitmapColorSpace, "", py::arg("space")) +//.def_static("BitmapColorSpace", &BTranslationUtils::BitmapColorSpace, "") +.def_static("GetStyledText", py::overload_cast(&BTranslationUtils::GetStyledText), "", py::arg("fromStream"), py::arg("intoView"), py::arg("roster")=NULL) +.def_static("GetStyledText", py::overload_cast(&BTranslationUtils::GetStyledText), "", py::arg("fromStream"), py::arg("intoView"), py::arg("encoding"), py::arg("roster")=NULL) +.def_static("PutStyledText", &BTranslationUtils::PutStyledText, "", py::arg("fromView"), py::arg("intoStream"), py::arg("roster")=NULL) +.def_static("WriteStyledEditFile", py::overload_cast(&BTranslationUtils::WriteStyledEditFile), "", py::arg("fromView"), py::arg("intoFile")) +.def_static("WriteStyledEditFile", py::overload_cast(&BTranslationUtils::WriteStyledEditFile), "", py::arg("fromView"), py::arg("intoFile"), py::arg("encoding")) +.def_static("GetDefaultSettings", py::overload_cast(&BTranslationUtils::GetDefaultSettings), "", py::arg("translator"), py::arg("roster")=NULL) +.def_static("GetDefaultSettings", py::overload_cast(&BTranslationUtils::GetDefaultSettings), "", py::arg("name"), py::arg("version")) +.def_static("AddTranslationItems", &BTranslationUtils::AddTranslationItems, "", py::arg("intoMenu"), py::arg("fromType"), py::arg("model")=NULL, py::arg("idName")=NULL, py::arg("typeName")=NULL, py::arg("roster")=NULL) +; + + +} diff --git a/bindings/translation/Translator.cpp b/bindings/translation/Translator.cpp new file mode 100644 index 0000000..3559a5d --- /dev/null +++ b/bindings/translation/Translator.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#include +#include + +namespace py = pybind11; + +class PyBTranslator : public BTranslator { +public: + using BTranslator::BTranslator; + + const char* TranslatorName() const override { + PYBIND11_OVERRIDE_PURE(const char*, BTranslator, TranslatorName); + } + const char* TranslatorInfo() const override { + PYBIND11_OVERRIDE_PURE(const char*, BTranslator, TranslatorInfo); + } + int32 TranslatorVersion() const override { + PYBIND11_OVERRIDE_PURE(int32, BTranslator, TranslatorVersion); + } + const translation_format* InputFormats(int32* _count) const override { + PYBIND11_OVERRIDE_PURE(translation_format*, BTranslator, InputFormats, _count); + } + const translation_format* OutputFormats(int32* _count) const override { + PYBIND11_OVERRIDE_PURE(translation_format*, BTranslator, OutputFormats, _count); + } + status_t Identify(BPositionIO* source, const translation_format* format, BMessage* extension, translator_info* info, uint32 outType) override { + PYBIND11_OVERRIDE_PURE(status_t, BTranslator, Identify, source, format, extension, info,outType); + } + status_t Translate(BPositionIO* source, const translator_info* info, BMessage* extension, uint32 outType, BPositionIO* destination) override { + PYBIND11_OVERRIDE_PURE(status_t, BTranslator, Translate, source, info, extension, outType, destination); + } +// status_t MakeConfigurationView(BMessage* extension, BView** _view, BRect* _extent) + status_t GetConfigurationMessage(BMessage* extension) override { + PYBIND11_OVERLOAD(status_t, BTranslator, GetConfigurationMessage, extension); + } + + +}; + +PYBIND11_MODULE(Translator, m) +{ +py::class_>(m, "BTranslator") +.def(py::init(), "") +.def("Acquire", &BTranslator::Acquire, "") +.def("Release", &BTranslator::Release, "") +.def("ReferenceCount", &BTranslator::ReferenceCount, "") +.def("TranslatorName", &BTranslator::TranslatorName, "") +.def("TranslatorInfo", &BTranslator::TranslatorInfo, "") +.def("TranslatorVersion", &BTranslator::TranslatorVersion, "") +.def("InputFormats", &BTranslator::InputFormats, "", py::arg("_count")) +.def("OutputFormats", &BTranslator::OutputFormats, "", py::arg("_count")) +.def("Identify", &BTranslator::Identify, "", py::arg("source"), py::arg("format"), py::arg("extension"), py::arg("info"), py::arg("outType")) +.def("Translate", &BTranslator::Translate, "", py::arg("source"), py::arg("info"), py::arg("extension"), py::arg("outType"), py::arg("destination")) +//.def("MakeConfigurationView", &BTranslator::MakeConfigurationView, "", py::arg("extension"), py::arg("_view"), py::arg("_extent")) +.def("GetConfigurationMessage", &BTranslator::GetConfigurationMessage, "", py::arg("extension")) +; + +//m.def("make_nth_translator", &make_nth_translator, "", py::arg("n"), py::arg("you"), py::arg("flags")); + +} diff --git a/bindings/translation/TranslatorAddOn.cpp b/bindings/translation/TranslatorAddOn.cpp new file mode 100644 index 0000000..494ac5d --- /dev/null +++ b/bindings/translation/TranslatorAddOn.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + + +void define_TranslatorAddOn(py::module_& m) +{ +m.attr("translatorName") = py::cast(translatorName); + +m.attr("translatorInfo") = py::cast(translatorInfo); + +m.attr("translatorVersion") = py::cast(translatorVersion); + +m.attr("inputFormats") = py::cast(inputFormats); + +m.attr("outputFormats") = py::cast(outputFormats); + +m.def("Identify", &Identify, "", py::arg("source"), py::arg("format"), py::arg("extension"), py::arg("info"), py::arg("outType")); + +m.def("Translate", &Translate, "", py::arg("source"), py::arg("info"), py::arg("extension"), py::arg("outType"), py::arg("destination")); + +m.def("MakeConfig", &MakeConfig, "", py::arg("extension"), py::arg("_view"), py::arg("_frame")); + +m.def("GetConfigMessage", &GetConfigMessage, "", py::arg("extension")); + +} diff --git a/bindings/translation/TranslatorFormats.cpp b/bindings/translation/TranslatorFormats.cpp new file mode 100644 index 0000000..a231030 --- /dev/null +++ b/bindings/translation/TranslatorFormats.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include + +#include + +namespace py = pybind11; + +PYBIND11_MODULE(TranslatorFormats,m) +{ +py::enum_(m, "TranslatorGroups", "") +.value("B_TRANSLATOR_BITMAP", TranslatorGroups::B_TRANSLATOR_BITMAP, "") +.value("B_TRANSLATOR_PICTURE", TranslatorGroups::B_TRANSLATOR_PICTURE, "") +.value("B_TRANSLATOR_SOUND", TranslatorGroups::B_TRANSLATOR_SOUND, "") +.value("B_TRANSLATOR_TEXT", TranslatorGroups::B_TRANSLATOR_TEXT, "") +.value("B_TRANSLATOR_MIDI", TranslatorGroups::B_TRANSLATOR_MIDI, "") +.value("B_TRANSLATOR_MEDIA", TranslatorGroups::B_TRANSLATOR_MEDIA, "") +.value("B_TRANSLATOR_NONE", TranslatorGroups::B_TRANSLATOR_NONE, "") +.value("B_TRANSLATOR_ANY_TYPE", TranslatorGroups::B_TRANSLATOR_ANY_TYPE, "") +.export_values(); + +m.attr("B_GIF_FORMAT") = 'GIF ';//py::cast(B_GIF_FORMAT); +m.attr("B_JPEG_FORMAT") = 'JPEG';//py::cast(B_JPEG_FORMAT); +m.attr("B_PNG_FORMAT") = 'PNG ';//py::cast(B_PNG_FORMAT); +m.attr("B_PPM_FORMAT") = 'PPM ';//py::cast(B_PPM_FORMAT); +m.attr("B_TGA_FORMAT") = 'TGA ';//py::cast(B_TGA_FORMAT); +m.attr("B_BMP_FORMAT") = 'BMP ';//py::cast(B_BMP_FORMAT); +m.attr("B_TIFF_FORMAT") = 'TIFF';//py::cast(B_TIFF_FORMAT); +m.attr("B_WEBP_FORMAT") = 'WebP';//py::cast(B_WEBP_FORMAT); +m.attr("B_DXF_FORMAT") = 'DXF ';//py::cast(B_DXF_FORMAT); +m.attr("B_EPS_FORMAT") = 'EPS ';//py::cast(B_EPS_FORMAT); +m.attr("B_PICT_FORMAT") = 'PICT';//py::cast(B_PICT_FORMAT); +m.attr("B_WAV_FORMAT") = 'WAV ';//py::cast(B_WAV_FORMAT); +m.attr("B_AIFF_FORMAT") = 'AIFF';//py::cast(B_AIFF_FORMAT); +m.attr("B_CD_FORMAT") = 'CD ';//py::cast(B_CD_FORMAT); +m.attr("B_AU_FORMAT") = 'AU ';//py::cast(B_AU_FORMAT); +m.attr("B_STYLED_TEXT_FORMAT") = 'STXT';//py::cast(B_STYLED_TEXT_FORMAT); + + +/* from TranslatorRoster.cpp in translation kit +char B_TRANSLATOR_EXT_HEADER_ONLY[] = "/headerOnly"; +char B_TRANSLATOR_EXT_DATA_ONLY[] = "/dataOnly"; +char B_TRANSLATOR_EXT_COMMENT[] = "/comment"; +char B_TRANSLATOR_EXT_TIME[] = "/time"; +char B_TRANSLATOR_EXT_FRAME[] = "/frame"; +char B_TRANSLATOR_EXT_BITMAP_RECT[] = "bits/Rect"; +char B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE[] = "bits/space"; +char B_TRANSLATOR_EXT_BITMAP_PALETTE[] = "bits/palette"; +char B_TRANSLATOR_EXT_SOUND_CHANNEL[] = "nois/channel"; +char B_TRANSLATOR_EXT_SOUND_MONO[] = "nois/mono"; +char B_TRANSLATOR_EXT_SOUND_MARKER[] = "nois/marker"; +char B_TRANSLATOR_EXT_SOUND_LOOP[] = "nois/loop";*/ + +m.attr("B_TRANSLATOR_EXT_HEADER_ONLY") = "/headerOnly";//py::cast(B_TRANSLATOR_EXT_HEADER_ONLY); + +m.attr("B_TRANSLATOR_EXT_DATA_ONLY") = "/dataOnly";//py::cast(B_TRANSLATOR_EXT_DATA_ONLY); + +m.attr("B_TRANSLATOR_EXT_COMMENT") = "/comment";//py::cast(B_TRANSLATOR_EXT_COMMENT); + +m.attr("B_TRANSLATOR_EXT_TIME") = "/time";//py::cast(B_TRANSLATOR_EXT_TIME); + +m.attr("B_TRANSLATOR_EXT_FRAME") = "/frame";//py::cast(B_TRANSLATOR_EXT_FRAME); + +m.attr("B_TRANSLATOR_EXT_BITMAP_RECT") = "bits/Rect";//py::cast(B_TRANSLATOR_EXT_BITMAP_RECT); + +m.attr("B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE") = "bits/space";//py::cast(B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE); + +m.attr("B_TRANSLATOR_EXT_BITMAP_PALETTE") = "bits/palette";//py::cast(B_TRANSLATOR_EXT_BITMAP_PALETTE); + +m.attr("B_TRANSLATOR_EXT_SOUND_CHANNEL") = "nois/channel";//py::cast(B_TRANSLATOR_EXT_SOUND_CHANNEL); + +m.attr("B_TRANSLATOR_EXT_SOUND_MONO") = "nois/mono";//py::cast(B_TRANSLATOR_EXT_SOUND_MONO); + +m.attr("B_TRANSLATOR_EXT_SOUND_MARKER") = "nois/marker";//py::cast(B_TRANSLATOR_EXT_SOUND_MARKER); + +m.attr("B_TRANSLATOR_EXT_SOUND_LOOP") = "nois/loop";//py::cast(B_TRANSLATOR_EXT_SOUND_LOOP); + +py::class_(m, "TranslatorBitmap") +.def_readwrite("magic", &TranslatorBitmap::magic, "") +.def_readwrite("bounds", &TranslatorBitmap::bounds, "") +.def_readwrite("rowBytes", &TranslatorBitmap::rowBytes, "") +.def_readwrite("colors", &TranslatorBitmap::colors, "") +.def_readwrite("dataSize", &TranslatorBitmap::dataSize, "") +; + +py::class_(m, "TranslatorSound") +.def_readwrite("magic", &TranslatorSound::magic, "") +.def_readwrite("channels", &TranslatorSound::channels, "") +.def_readwrite("sampleFreq", &TranslatorSound::sampleFreq, "") +.def_readwrite("numFrames", &TranslatorSound::numFrames, "") +; + +py::class_(m, "TranslatorStyledTextRecordHeader") +.def_readwrite("magic", &TranslatorStyledTextRecordHeader::magic, "") +.def_readwrite("header_size", &TranslatorStyledTextRecordHeader::header_size, "") +.def_readwrite("data_size", &TranslatorStyledTextRecordHeader::data_size, "") +; + +py::class_(m, "TranslatorStyledTextStreamHeader") +.def_property_readonly("STREAM_HEADER_MAGIC", []() { + return 'STXT'; +},"") +.def_readwrite("header", &TranslatorStyledTextStreamHeader::header, "") +.def_readwrite("version", &TranslatorStyledTextStreamHeader::version, "") +; + +py::class_(m, "TranslatorStyledTextTextHeader") +.def_property_readonly("TEXT_HEADER_MAGIC", []() { + return 'TEXT'; +},"") +.def_readwrite("header", &TranslatorStyledTextTextHeader::header, "") +.def_readwrite("charset", &TranslatorStyledTextTextHeader::charset, "") +; + +py::class_(m, "TranslatorStyledTextStyleHeader") +.def_property_readonly("STYLE_HEADER_MAGIC", []() { + return 'STYL'; +},"") +.def_readwrite("header", &TranslatorStyledTextStyleHeader::header, "") +.def_readwrite("apply_offset", &TranslatorStyledTextStyleHeader::apply_offset, "") +.def_readwrite("apply_length", &TranslatorStyledTextStyleHeader::apply_length, "") +; + + +} diff --git a/bindings/translation/TranslatorRoster.cpp b/bindings/translation/TranslatorRoster.cpp new file mode 100644 index 0000000..c10c992 --- /dev/null +++ b/bindings/translation/TranslatorRoster.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace py = pybind11; + +class PyBTranslatorRoster : public BTranslatorRoster{ + public: + using BTranslatorRoster::BTranslatorRoster; + status_t Archive(BMessage* into, bool deep = true) const override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, Archive, into, deep); + } + status_t Identify(BPositionIO* source, BMessage* ioExtension, translator_info* _info, uint32 hintType = 0, const char* hintMIME = NULL, uint32 wantType = 0) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, Identify, source, ioExtension, _info, hintType, hintMIME, wantType); + } + /*status_t GetTranslators(BPositionIO* source, BMessage* ioExtension, translator_info** _info, int32* _numInfo, uint32 hintType = 0, const char* hintMIME = NULL, uint32 wantType = 0) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, GetTranslators, source, ioExtension, _info, _numInfo, hintType, hintMIME, wantType); + }*/ + /*status_t GetAllTranslators(translator_id** _list, int32* _count) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, GetAllTranslators, _list, _count); + }*/ + /*status_t GetTranslatorInfo(translator_id translatorID, const char** _name, const char** _info, int32* _version) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, GetTranslatorInfo, translatorID, _name, _info, _version); + }*/ + /*status_t GetInputFormats(translator_id translatorID, const translation_format** _formats, int32* _numFormats) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, GetInputFormats, translatorID, _formats, _numFormats); + }*/ + /*status_t GetOutputFormats(translator_id translatorID, const translation_format** _formats, int32* _numFormats) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, GetOutputFormats, translatorID, _formats, _numFormats); + }*/ + status_t Translate(BPositionIO* source, const translator_info* info, BMessage* ioExtension, BPositionIO* destination, uint32 wantOutType, uint32 hintType = 0, const char* hintMIME = NULL) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, Translate, source, info, ioExtension, destination, wantOutType, hintType, hintMIME); + } + status_t Translate(translator_id translatorID, BPositionIO* source, BMessage* ioExtension, BPositionIO* destination, uint32 wantOutType) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, Translate, translatorID, source, ioExtension, destination, wantOutType); + } + /*status_t MakeConfigurationView(translator_id translatorID, BMessage* ioExtension, BView** _view, BRect* _extent) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, MakeConfigurationView, translatorID, ioExtension, _view, _extent); + }*/ + status_t GetConfigurationMessage(translator_id translatorID, BMessage* ioExtension) override { + PYBIND11_OVERLOAD(status_t, BTranslatorRoster, GetConfigurationMessage, translatorID, ioExtension); + } + +}; + +PYBIND11_MODULE(TranslatorRoster, m) +{ +py::class_(m, "BTranslatorReleaseDelegate") +.def(py::init(), "", py::arg("translator")) +.def("Release", &BTranslatorReleaseDelegate::Release, "") +; + +py::class_(m, "BTranslatorRoster") +.def(py::init(), "") +.def(py::init(), "", py::arg("model")) +.def_static("Default", &BTranslatorRoster::Default, "") +.def("Archive", &BTranslatorRoster::Archive, "", py::arg("into"), py::arg("deep")=true) +.def_static("Instantiate", &BTranslatorRoster::Instantiate, "", py::arg("from")) +.def("AddTranslators", &BTranslatorRoster::AddTranslators, "", py::arg("loadPath")=NULL) +.def("AddTranslator", &BTranslatorRoster::AddTranslator, "", py::arg("translator")) +.def("Identify", &BTranslatorRoster::Identify, "", py::arg("source"), py::arg("ioExtension"), py::arg("_info"), py::arg("hintType")=0, py::arg("hintMIME")=NULL, py::arg("wantType")=0) +//.def("GetTranslators", &BTranslatorRoster::GetTranslators, "", py::arg("source"), py::arg("ioExtension"), py::arg("_info"), py::arg("_numInfo"), py::arg("hintType")=0, py::arg("hintMIME")=NULL, py::arg("wantType")=0) +//.def("GetAllTranslators", &BTranslatorRoster::GetAllTranslators, "", py::arg("_list"), py::arg("_count")) +//.def("GetTranslatorInfo", &BTranslatorRoster::GetTranslatorInfo, "", py::arg("translatorID"), py::arg("_name"), py::arg("_info"), py::arg("_version")) +//.def("GetInputFormats", &BTranslatorRoster::GetInputFormats, "", py::arg("translatorID"), py::arg("_formats"), py::arg("_numFormats")) +//.def("GetOutputFormats", &BTranslatorRoster::GetOutputFormats, "", py::arg("translatorID"), py::arg("_formats"), py::arg("_numFormats")) +.def("Translate", py::overload_cast(&BTranslatorRoster::Translate), "", py::arg("source"), py::arg("info"), py::arg("ioExtension"), py::arg("destination"), py::arg("wantOutType"), py::arg("hintType")=0, py::arg("hintMIME")=NULL) +.def("Translate", py::overload_cast(&BTranslatorRoster::Translate), "", py::arg("translatorID"), py::arg("source"), py::arg("ioExtension"), py::arg("destination"), py::arg("wantOutType")) +//.def("MakeConfigurationView", &BTranslatorRoster::MakeConfigurationView, "", py::arg("translatorID"), py::arg("ioExtension"), py::arg("_view"), py::arg("_extent")) +.def("GetConfigurationMessage", &BTranslatorRoster::GetConfigurationMessage, "", py::arg("translatorID"), py::arg("ioExtension")) +.def("AcquireTranslator", &BTranslatorRoster::AcquireTranslator, "", py::arg("translatorID")) +.def("GetRefFor", &BTranslatorRoster::GetRefFor, "", py::arg("translatorID"), py::arg("ref")) +.def("IsTranslator", &BTranslatorRoster::IsTranslator, "", py::arg("ref")) +.def("StartWatching", &BTranslatorRoster::StartWatching, "", py::arg("target")) +.def("StopWatching", &BTranslatorRoster::StopWatching, "", py::arg("target")) +//.def_readwrite("Private", &BTranslatorRoster::Private, "") +; + + +} diff --git a/example.py b/example.py new file mode 100644 index 0000000..3c109ed --- /dev/null +++ b/example.py @@ -0,0 +1,50 @@ +# There two ways to import Haiku-PyAPI +# First, you can import only the things you need +from Be import BApplication, BWindow, BRect, BMessage, BView, BButton, window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE, int32, B_WILL_DRAW, B_FOLLOW_NONE +# Or import everything! +#from Be import * + +# Usage of the API is extremely similar to how it is used in C++ + +class App(BApplication): + def __init__(self): + BApplication.__init__( + self, # Any call to a constructor requires self as the first parameter + "application/x-vnd.pyapi_test") # Application signature + + def ReadyToRun(self): + # Display the main window + window = MainWindow() + window.Show() + +class MainWindow(BWindow): + def __init__(self): + BWindow.__init__( + self, # Any call to a constructor requires self as the first parameter + BRect(100,100,200,150), # Window size + "Hello Haiku!", # Window title + window_type.B_TITLED_WINDOW, # Window type + B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE) # Flags + + # The "Say Hello!" button's message code + self.MSG_SAY_HI = int32(b"syhi") + + # The "Say Hello!" button + self.button = BButton( + self.Bounds(), # Button size + "hi", # Internal name of button + "Say Hello!", # Button text + BMessage(self.MSG_SAY_HI)) # Message to send when button is pressed + self.AddChild(self.button, None) + + def MessageReceived(self, msg): + if msg.what == self.MSG_SAY_HI: + # The "Say Hello!" button has been pressed! + print("Hello World!") + else: + # We don't know what to do with this message. Pass it on to BWindow + BWindow.MessageReceived(self, msg) + +# Let's launch the application! +app = App() +app.Run() diff --git a/headers/README b/headers/README new file mode 100644 index 0000000..ba280d4 --- /dev/null +++ b/headers/README @@ -0,0 +1,7 @@ +This folder contains copies of some of Haiku's header files from versions of Haiku after +R1B4. + +Currently, we need this so that we can reference some structs that were named +after R1B4 was released. Wes hould be able to delete this folder once R1B5 is +released, as the named structs will be included in the default header files +that come with R1B5. diff --git a/headers/app/AppDefs.h b/headers/app/AppDefs.h new file mode 100644 index 0000000..7787fe2 --- /dev/null +++ b/headers/app/AppDefs.h @@ -0,0 +1,138 @@ +/* + * Copyright 2001-2007, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Erik Jaesler (erik@cgsoftware.com) + */ +#ifndef _APP_DEFS_H +#define _APP_DEFS_H + + +#include + + +// Old-style cursors +extern const unsigned char B_HAND_CURSOR[]; +extern const unsigned char B_I_BEAM_CURSOR[]; + +// New-style cursors +#ifdef __cplusplus +class BCursor; +extern const BCursor *B_CURSOR_SYSTEM_DEFAULT; +extern const BCursor *B_CURSOR_I_BEAM; +#endif + + +// System Message Codes +enum system_message_code { + B_ABOUT_REQUESTED = '_ABR', + B_WINDOW_ACTIVATED = '_ACT', + B_APP_ACTIVATED = '_ACT', // Same as B_WINDOW_ACTIVATED + B_ARGV_RECEIVED = '_ARG', + B_QUIT_REQUESTED = '_QRQ', + B_CLOSE_REQUESTED = '_QRQ', // Obsolete; use B_QUIT_REQUESTED + B_CANCEL = '_CNC', + B_INVALIDATE = '_IVL', + B_KEY_DOWN = '_KYD', + B_KEY_UP = '_KYU', + B_UNMAPPED_KEY_DOWN = '_UKD', + B_UNMAPPED_KEY_UP = '_UKU', + B_KEY_MAP_LOADED = '_KML', + B_LAYOUT_WINDOW = '_LAY', + B_MODIFIERS_CHANGED = '_MCH', + B_MINIMIZE = '_WMN', + B_MOUSE_DOWN = '_MDN', + B_MOUSE_MOVED = '_MMV', + B_MOUSE_ENTER_EXIT = '_MEX', + B_MOUSE_IDLE = '_MSI', + B_MOUSE_UP = '_MUP', + B_MOUSE_WHEEL_CHANGED = '_MWC', + B_OPEN_IN_WORKSPACE = '_OWS', + B_PACKAGE_UPDATE = '_PKU', + B_PRINTER_CHANGED = '_PCH', + B_PULSE = '_PUL', + B_READY_TO_RUN = '_RTR', + B_REFS_RECEIVED = '_RRC', + B_RELEASE_OVERLAY_LOCK = '_ROV', + B_ACQUIRE_OVERLAY_LOCK = '_AOV', + B_SCREEN_CHANGED = '_SCH', + B_VALUE_CHANGED = '_VCH', + B_TRANSLATOR_ADDED = '_ART', + B_TRANSLATOR_REMOVED = '_RRT', + B_DELETE_TRANSLATOR = '_DRT', + B_VIEW_MOVED = '_VMV', + B_VIEW_RESIZED = '_VRS', + B_WINDOW_MOVED = '_WMV', + B_WINDOW_RESIZED = '_WRS', + B_WORKSPACES_CHANGED = '_WCG', + B_WORKSPACE_ACTIVATED = '_WAC', + B_ZOOM = '_WZM', + B_COLORS_UPDATED = '_CLU', + B_FONTS_UPDATED = '_FNU', + B_TRACKER_ADDON_MESSAGE = '_TAM', + _APP_MENU_ = '_AMN', + _BROWSER_MENUS_ = '_BRM', + _MENU_EVENT_ = '_MEV', + _PING_ = '_PBL', + _QUIT_ = '_QIT', + _VOLUME_MOUNTED_ = '_NVL', + _VOLUME_UNMOUNTED_ = '_VRM', + _MESSAGE_DROPPED_ = '_MDP', + _DISPOSE_DRAG_ = '_DPD', + _MENUS_DONE_ = '_MND', + _SHOW_DRAG_HANDLES_ = '_SDH', + _EVENTS_PENDING_ = '_EVP', + _UPDATE_ = '_UPD', + _UPDATE_IF_NEEDED_ = '_UPN', + _PRINTER_INFO_ = '_PIN', + _SETUP_PRINTER_ = '_SUP', + _SELECT_PRINTER_ = '_PSL' + // Media Kit reserves all reserved codes starting in '_TR' +}; + + +// Other Commands +enum command_code { + B_SET_PROPERTY = 'PSET', + B_GET_PROPERTY = 'PGET', + B_CREATE_PROPERTY = 'PCRT', + B_DELETE_PROPERTY = 'PDEL', + B_COUNT_PROPERTIES = 'PCNT', + B_EXECUTE_PROPERTY = 'PEXE', + B_GET_SUPPORTED_SUITES = 'SUIT', + B_UNDO = 'UNDO', + B_REDO = 'REDO', + B_CUT = 'CCUT', + B_COPY = 'COPY', + B_PASTE = 'PSTE', + B_SELECT_ALL = 'SALL', + B_SAVE_REQUESTED = 'SAVE', + B_MESSAGE_NOT_UNDERSTOOD = 'MNOT', + B_NO_REPLY = 'NONE', + B_REPLY = 'RPLY', + B_SIMPLE_DATA = 'DATA', + B_MIME_DATA = 'MIME', + B_ARCHIVED_OBJECT = 'ARCV', + B_UPDATE_STATUS_BAR = 'SBUP', + B_RESET_STATUS_BAR = 'SBRS', + B_NODE_MONITOR = 'NDMN', + B_QUERY_UPDATE = 'QUPD', + B_ENDORSABLE = 'ENDO', + B_COPY_TARGET = 'DDCP', + B_MOVE_TARGET = 'DDMV', + B_TRASH_TARGET = 'DDRM', + B_LINK_TARGET = 'DDLN', + B_INPUT_DEVICES_CHANGED = 'IDCH', + B_INPUT_METHOD_EVENT = 'IMEV', + B_WINDOW_MOVE_TO = 'WDMT', + B_WINDOW_MOVE_BY = 'WDMB', + B_SILENT_RELAUNCH = 'AREL', + B_OBSERVER_NOTICE_CHANGE = 'NTCH', + B_CONTROL_INVOKED = 'CIVK', + B_CONTROL_MODIFIED = 'CMOD' + + // Media Kit reserves all reserved codes starting in 'TRI' +}; + +#endif // _APP_DEFS_H diff --git a/headers/app/Roster.h b/headers/app/Roster.h new file mode 100644 index 0000000..e2e72dc --- /dev/null +++ b/headers/app/Roster.h @@ -0,0 +1,247 @@ +/* + * Copyright 2001-2015 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _ROSTER_H +#define _ROSTER_H + + +#include +#include +#include + +class BFile; +class BMimeType; +class BNodeInfo; + + +struct app_info { + app_info(); + ~app_info(); + + thread_id thread; + team_id team; + port_id port; + uint32 flags; + entry_ref ref; + char signature[B_MIME_TYPE_LENGTH]; +}; + +// app flags +#define B_SINGLE_LAUNCH (0x0) +#define B_MULTIPLE_LAUNCH (0x1) +#define B_EXCLUSIVE_LAUNCH (0x2) +#define B_LAUNCH_MASK (0x3) +#define B_BACKGROUND_APP (0x4) +#define B_ARGV_ONLY (0x8) +#define _B_APP_INFO_RESERVED1_ (0x10000000) + +// watching request flags +enum watching_request_flags { + B_REQUEST_LAUNCHED = 0x00000001, + B_REQUEST_QUIT = 0x00000002, + B_REQUEST_ACTIVATED = 0x00000004, +}; + +// notification message "what" +enum { + B_SOME_APP_LAUNCHED = 'BRAS', + B_SOME_APP_QUIT = 'BRAQ', + B_SOME_APP_ACTIVATED = 'BRAW', +}; + +class BList; + + +class BRoster { +public: + BRoster(); + ~BRoster(); + + // running apps + bool IsRunning(const char* signature) const; + bool IsRunning(entry_ref* ref) const; + + team_id TeamFor(const char* signature) const; + team_id TeamFor(entry_ref* ref) const; + + void GetAppList(BList* teamIDList) const; + void GetAppList(const char* signature, + BList* teamIDList) const; + + // app infos + status_t GetAppInfo(const char* signature, + app_info* info) const; + status_t GetAppInfo(entry_ref* ref, + app_info* info) const; + + status_t GetRunningAppInfo(team_id team, + app_info* info) const; + status_t GetActiveAppInfo(app_info* info) const; + + // find app + status_t FindApp(const char* mimeType, + entry_ref* app) const; + status_t FindApp(entry_ref* ref, entry_ref* app) const; + + // broadcast + status_t Broadcast(BMessage* message) const; + status_t Broadcast(BMessage* message, + BMessenger replyTo) const; + + // watching + status_t StartWatching(BMessenger target, + uint32 eventMask + = B_REQUEST_LAUNCHED + | B_REQUEST_QUIT) const; + status_t StopWatching(BMessenger target) const; + + status_t ActivateApp(team_id team) const; + + // launch app + status_t Launch(const char* mimeType, + BMessage* initialMessage = NULL, + team_id* _appTeam = NULL) const; + status_t Launch(const char* mimeType, BList* messageList, + team_id* _appTeam = NULL) const; + status_t Launch(const char* mimeType, int argc, + const char* const* args, + team_id* _appTeam = NULL) const; + status_t Launch(const entry_ref* ref, + const BMessage* initialMessage = NULL, + team_id* _appTeam = NULL) const; + status_t Launch(const entry_ref* ref, + const BList* messageList, + team_id* _appTeam = NULL) const; + status_t Launch(const entry_ref* ref, int argc, + const char* const* args, + team_id* _appTeam = NULL) const; + + // recent documents, folders, apps + void GetRecentDocuments(BMessage* refList, + int32 maxCount, const char* fileType = NULL, + const char* signature = NULL) const; + void GetRecentDocuments(BMessage* refList, + int32 maxCount, const char* fileTypes[], + int32 fileTypesCount, + const char* signature = NULL) const; + + void GetRecentFolders(BMessage* refList, + int32 maxCount, + const char* signature = NULL) const; + + void GetRecentApps(BMessage* refList, + int32 maxCount) const; + + void AddToRecentDocuments(const entry_ref* document, + const char* signature = NULL) const; + void AddToRecentFolders(const entry_ref* folder, + const char* signature = NULL) const; + + // private/reserved stuff starts here + class Private; + +private: + class ArgVector; + friend class Private; + + status_t _ShutDown(bool reboot, bool confirm, + bool synchronous); + status_t _IsShutDownInProgress(bool* inProgress); + + status_t _AddApplication(const char* signature, + const entry_ref* ref, uint32 flags, + team_id team, thread_id thread, + port_id port, bool fullRegistration, + uint32* pToken, team_id* otherTeam) const; + + status_t _SetSignature(team_id team, + const char* signature) const; + + void _SetThread(team_id team, + thread_id thread) const; + + status_t _SetThreadAndTeam(uint32 entryToken, + thread_id thread, team_id team, + port_id* _port) const; + + status_t _CompleteRegistration(team_id team, + thread_id thread, port_id port) const; + + bool _IsAppPreRegistered(const entry_ref* ref, + team_id team, app_info* info) const; + + status_t _IsAppRegistered(const entry_ref* ref, + team_id team, uint32 token, + bool* preRegistered, app_info* info) const; + + status_t _RemovePreRegApp(uint32 entryToken) const; + status_t _RemoveApp(team_id team) const; + + void _ApplicationCrashed(team_id team); + + status_t _LaunchApp(const char* mimeType, + const entry_ref* ref, + const BList* messageList, int argc, + const char* const* args, + const char** environment, + team_id* _appTeam, thread_id* _appThread, + port_id* _appPort, uint32* _appToken, + bool launchSuspended) const; + + status_t _UpdateActiveApp(team_id team) const; + + void _SetAppFlags(team_id team, uint32 flags) const; + + void _DumpRoster() const; + + status_t _ResolveApp(const char* inType, entry_ref* ref, + entry_ref* appRef, + char* signature, + uint32* appFlags, + bool* wasDocument) const; + + status_t _TranslateRef(entry_ref* ref, + BMimeType* appMeta, entry_ref* appRef, + BFile* appFile, bool* wasDocument) const; + + status_t _TranslateType(const char* mimeType, + BMimeType* appMeta, entry_ref* appRef, + BFile* appFile) const; + + status_t _GetFileType(const entry_ref* file, + BNodeInfo* nodeInfo, char* mimeType) const; + status_t _SendToRunning(team_id team, int argc, + const char* const* args, + const BList* messageList, + const entry_ref* ref, + bool readyToRun) const; + + void _SetWithoutRegistrar(bool noRegistrar); + + void _InitMessenger(); + + static status_t _InitMimeMessenger(void* data); + + BMessenger& _MimeMessenger(); + + void _AddToRecentApps(const char* signature) const; + + void _ClearRecentDocuments() const; + void _ClearRecentFolders() const; + void _ClearRecentApps() const; + void _LoadRecentLists(const char* filename) const; + void _SaveRecentLists(const char* filename) const; + + BMessenger fMessenger; + BMessenger fMimeMessenger; + int32 fMimeMessengerInitOnce; + bool fNoRegistrar; + uint32 _reserved[1]; +}; + +// global BRoster instance +extern const BRoster* be_roster; + + +#endif // _ROSTER_H diff --git a/headers/interface/PictureButton.h b/headers/interface/PictureButton.h new file mode 100644 index 0000000..0f8bda9 --- /dev/null +++ b/headers/interface/PictureButton.h @@ -0,0 +1,104 @@ +/* + * Copyright 2001-2015, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _PICTURE_BUTTON_H +#define _PICTURE_BUTTON_H + + +#include +#include + + +enum picture_button_behavior { + B_ONE_STATE_BUTTON, + B_TWO_STATE_BUTTON +}; + + +class BPictureButton : public BControl { +public: + BPictureButton(BRect frame, const char* name, + BPicture* off, BPicture* on, + BMessage* message, + uint32 behavior = B_ONE_STATE_BUTTON, + uint32 resizingMode = B_FOLLOW_LEFT_TOP, + uint32 flgs = B_WILL_DRAW | B_NAVIGABLE); + BPictureButton(BMessage* archive); + + virtual ~BPictureButton(); + + static BArchivable* Instantiate(BMessage* archive); + virtual status_t Archive(BMessage* archive, + bool deep = true) const; + + virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); + virtual void AllAttached(); + virtual void AllDetached(); + + virtual void ResizeToPreferred(); + virtual void GetPreferredSize(float* _width, + float* _height); + virtual void FrameMoved(BPoint newPosition); + virtual void FrameResized(float newWidth, float newHeight); + + virtual void WindowActivated(bool active); + virtual void MakeFocus(bool focus = true); + + virtual void Draw(BRect updateRect); + + virtual void MessageReceived(BMessage* message); + virtual void KeyDown(const char* bytes, int32 numBytes); + virtual void MouseDown(BPoint where); + virtual void MouseUp(BPoint where); + virtual void MouseMoved(BPoint where, uint32 code, + const BMessage* dragMessage); + + virtual void SetEnabledOn(BPicture* picture); + virtual void SetEnabledOff(BPicture* picture); + virtual void SetDisabledOn(BPicture* picture); + virtual void SetDisabledOff(BPicture* picture); + + BPicture* EnabledOn() const; + BPicture* EnabledOff() const; + BPicture* DisabledOn() const; + BPicture* DisabledOff() const; + + virtual void SetBehavior(uint32 behavior); + uint32 Behavior() const; + + virtual void SetValue(int32 value); + virtual status_t Invoke(BMessage* message = NULL); + + virtual BHandler* ResolveSpecifier(BMessage* message, + int32 index, BMessage* specifier, + int32 what, const char* property); + virtual status_t GetSupportedSuites(BMessage* data); + + virtual status_t Perform(perform_code code, void* data); + + virtual status_t SetIcon(const BBitmap* icon, uint32 flags = 0); + +private: + // FBC padding and forbidden methods + virtual void _ReservedPictureButton1(); + virtual void _ReservedPictureButton2(); + virtual void _ReservedPictureButton3(); + + BPictureButton& operator=(const BPictureButton& other); + +private: + BPicture* fEnabledOff; + BPicture* fEnabledOn; + BPicture* fDisabledOff; + BPicture* fDisabledOn; + + bool unused; + + uint32 fBehavior; + + uint32 _reserved[4]; +}; + +#endif // _PICTURE_BUTTON_H diff --git a/headers/interface/View.h b/headers/interface/View.h new file mode 100644 index 0000000..690c9c8 --- /dev/null +++ b/headers/interface/View.h @@ -0,0 +1,841 @@ +/* + * Copyright 2001-2020 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _VIEW_H +#define _VIEW_H + + +#include +#include +#include +#include +#include +#include +#include + + +// mouse button +#define B_MOUSE_BUTTON(n) (1 << ((n) - 1)) + +// Legacy BeOS R5 mouse button definitions +enum { + B_PRIMARY_MOUSE_BUTTON = B_MOUSE_BUTTON(1), + B_SECONDARY_MOUSE_BUTTON = B_MOUSE_BUTTON(2), + B_TERTIARY_MOUSE_BUTTON = B_MOUSE_BUTTON(3) +}; + +// mouse transit +enum { + B_ENTERED_VIEW = 0, + B_INSIDE_VIEW, + B_EXITED_VIEW, + B_OUTSIDE_VIEW +}; + +// event mask +enum { + B_POINTER_EVENTS = 0x00000001, + B_KEYBOARD_EVENTS = 0x00000002 +}; + +// event mask options +enum { + B_LOCK_WINDOW_FOCUS = 0x00000001, + B_SUSPEND_VIEW_FOCUS = 0x00000002, + B_NO_POINTER_HISTORY = 0x00000004, + // NOTE: This is the default behavior in Haiku, unlike in BeOS + B_FULL_POINTER_HISTORY = 0x00000008 + // NOTE: New in Haiku (unless this flag is + // specified, both BWindow and BView::GetMouse() + // will filter out older mouse moved messages) +}; + +enum rect_tracking_style { + B_TRACK_WHOLE_RECT, + B_TRACK_RECT_CORNER +}; + +// set font mask +enum set_font_mask { + B_FONT_FAMILY_AND_STYLE = 0x00000001, + B_FONT_SIZE = 0x00000002, + B_FONT_SHEAR = 0x00000004, + B_FONT_ROTATION = 0x00000008, + B_FONT_SPACING = 0x00000010, + B_FONT_ENCODING = 0x00000020, + B_FONT_FACE = 0x00000040, + B_FONT_FLAGS = 0x00000080, + B_FONT_FALSE_BOLD_WIDTH = 0x00000100, + B_FONT_ALL = 0x000001FF +}; + +typedef enum { + B_CURRENT_STATE_COORDINATES, + B_PREVIOUS_STATE_COORDINATES, + B_VIEW_COORDINATES, + B_PARENT_VIEW_DRAW_COORDINATES, + B_PARENT_VIEW_COORDINATES, + B_WINDOW_COORDINATES, + B_SCREEN_COORDINATES +} coordinate_space; + +// view flags +const uint32 B_FULL_UPDATE_ON_RESIZE = 0x80000000UL; /* 31 */ +const uint32 _B_RESERVED1_ = 0x40000000UL; /* 30 */ +const uint32 B_WILL_DRAW = 0x20000000UL; /* 29 */ +const uint32 B_PULSE_NEEDED = 0x10000000UL; /* 28 */ +const uint32 B_NAVIGABLE_JUMP = 0x08000000UL; /* 27 */ +const uint32 B_FRAME_EVENTS = 0x04000000UL; /* 26 */ +const uint32 B_NAVIGABLE = 0x02000000UL; /* 25 */ +const uint32 B_SUBPIXEL_PRECISE = 0x01000000UL; /* 24 */ +const uint32 B_DRAW_ON_CHILDREN = 0x00800000UL; /* 23 */ +const uint32 B_INPUT_METHOD_AWARE = 0x00400000UL; /* 22 */ +const uint32 B_SCROLL_VIEW_AWARE = 0x00200000UL; /* 21 */ +const uint32 B_SUPPORTS_LAYOUT = 0x00100000UL; /* 20 */ +const uint32 B_INVALIDATE_AFTER_LAYOUT = 0x00080000UL; /* 19 */ +const uint32 B_TRANSPARENT_BACKGROUND = 0x00040000UL; /* 18 */ + +#define _RESIZE_MASK_ (0xffff) + +const uint32 _VIEW_TOP_ = 1UL; +const uint32 _VIEW_LEFT_ = 2UL; +const uint32 _VIEW_BOTTOM_ = 3UL; +const uint32 _VIEW_RIGHT_ = 4UL; +const uint32 _VIEW_CENTER_ = 5UL; + +#define _rule_(r1, r2, r3, r4) (((r1) << 12) | ((r2) << 8) | ((r3) << 4) | (r4)) + +const uint32 B_FOLLOW_NONE = 0; +const uint32 B_FOLLOW_ALL_SIDES = _rule_(_VIEW_TOP_, _VIEW_LEFT_, + _VIEW_BOTTOM_, _VIEW_RIGHT_); +const uint32 B_FOLLOW_ALL = B_FOLLOW_ALL_SIDES; + +const uint32 B_FOLLOW_LEFT = _rule_(0, _VIEW_LEFT_, 0, _VIEW_LEFT_); +const uint32 B_FOLLOW_RIGHT = _rule_(0, _VIEW_RIGHT_, 0, _VIEW_RIGHT_); +const uint32 B_FOLLOW_LEFT_RIGHT = _rule_(0, _VIEW_LEFT_, 0, _VIEW_RIGHT_); +const uint32 B_FOLLOW_H_CENTER = _rule_(0, _VIEW_CENTER_, 0, _VIEW_CENTER_); + +const uint32 B_FOLLOW_TOP = _rule_(_VIEW_TOP_, 0, _VIEW_TOP_, 0); +const uint32 B_FOLLOW_BOTTOM = _rule_(_VIEW_BOTTOM_, 0, _VIEW_BOTTOM_, 0); +const uint32 B_FOLLOW_TOP_BOTTOM = _rule_(_VIEW_TOP_, 0, _VIEW_BOTTOM_, 0); +const uint32 B_FOLLOW_V_CENTER = _rule_(_VIEW_CENTER_, 0, _VIEW_CENTER_, 0); + +const uint32 B_FOLLOW_LEFT_TOP = B_FOLLOW_TOP | B_FOLLOW_LEFT; + +class BBitmap; +class BCursor; +class BLayout; +class BLayoutContext; +class BLayoutItem; +class BMessage; +class BPicture; +class BPolygon; +class BRegion; +class BScrollBar; +class BScrollView; +class BShape; +class BShelf; +class BString; +class BToolTip; +class BWindow; +struct _array_data_; +struct _array_hdr_; +struct overlay_restrictions; + +namespace BPrivate { + class ViewState; +}; + + +class BView : public BHandler { +public: + BView(const char* name, uint32 flags, + BLayout* layout = NULL); + BView(BRect frame, const char* name, + uint32 resizingMode, uint32 flags); + virtual ~BView(); + + BView(BMessage* archive); + static BArchivable* Instantiate(BMessage* archive); + virtual status_t Archive(BMessage* archive, + bool deep = true) const; + virtual status_t AllUnarchived(const BMessage* archive); + virtual status_t AllArchived(BMessage* archive) const; + + virtual void AttachedToWindow(); + virtual void AllAttached(); + virtual void DetachedFromWindow(); + virtual void AllDetached(); + + virtual void MessageReceived(BMessage* message); + + void AddChild(BView* child, BView* before = NULL); + bool AddChild(BLayoutItem* child); + bool RemoveChild(BView* child); + int32 CountChildren() const; + BView* ChildAt(int32 index) const; + BView* NextSibling() const; + BView* PreviousSibling() const; + bool RemoveSelf(); + + BWindow* Window() const; + + virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); + virtual void MouseUp(BPoint where); + virtual void MouseMoved(BPoint where, uint32 code, + const BMessage* dragMessage); + virtual void WindowActivated(bool active); + virtual void KeyDown(const char* bytes, int32 numBytes); + virtual void KeyUp(const char* bytes, int32 numBytes); + virtual void Pulse(); + virtual void FrameMoved(BPoint newPosition); + virtual void FrameResized(float newWidth, float newHeight); + + virtual void TargetedByScrollView(BScrollView* scrollView); + void BeginRectTracking(BRect startRect, + uint32 style = B_TRACK_WHOLE_RECT); + void EndRectTracking(); + + void GetMouse(BPoint* location, uint32* buttons, + bool checkMessageQueue = true); + + void DragMessage(BMessage* message, BRect dragRect, + BHandler* replyTo = NULL); + void DragMessage(BMessage* message, BBitmap* bitmap, + BPoint offset, BHandler* replyTo = NULL); + void DragMessage(BMessage* message, BBitmap* bitmap, + drawing_mode dragMode, BPoint offset, + BHandler* replyTo = NULL); + + BView* FindView(const char* name) const; + BView* Parent() const; + BRect Bounds() const; + BRect Frame() const; + void ConvertToScreen(BPoint* point) const; + BPoint ConvertToScreen(BPoint point) const; + void ConvertFromScreen(BPoint* point) const; + BPoint ConvertFromScreen(BPoint point) const; + void ConvertToScreen(BRect* rect) const; + BRect ConvertToScreen(BRect rect) const; + void ConvertFromScreen(BRect* rect) const; + BRect ConvertFromScreen(BRect rect) const; + void ConvertToParent(BPoint* point) const; + BPoint ConvertToParent(BPoint point) const; + void ConvertFromParent(BPoint* point) const; + BPoint ConvertFromParent(BPoint point) const; + void ConvertToParent(BRect* rect) const; + BRect ConvertToParent(BRect rect) const; + void ConvertFromParent(BRect* rect) const; + BRect ConvertFromParent(BRect rect) const; + BPoint LeftTop() const; + + void GetClippingRegion(BRegion* region) const; + virtual void ConstrainClippingRegion(BRegion* region); + void ClipToPicture(BPicture* picture, + BPoint where = B_ORIGIN, bool sync = true); + void ClipToInversePicture(BPicture* picture, + BPoint where = B_ORIGIN, bool sync = true); + + void ClipToRect(BRect rect); + void ClipToInverseRect(BRect rect); + void ClipToShape(BShape* shape); + void ClipToInverseShape(BShape* shape); + + virtual void SetDrawingMode(drawing_mode mode); + drawing_mode DrawingMode() const; + + void SetBlendingMode(source_alpha srcAlpha, + alpha_function alphaFunc); + void GetBlendingMode(source_alpha* srcAlpha, + alpha_function* alphaFunc) const; + + virtual void SetPenSize(float size); + float PenSize() const; + + void SetViewCursor(const BCursor* cursor, + bool sync = true); + + bool HasDefaultColors() const; + bool HasSystemColors() const; + void AdoptParentColors(); + void AdoptSystemColors(); + void AdoptViewColors(BView* view); + + virtual void SetViewColor(rgb_color color); + void SetViewColor(uchar red, uchar green, uchar blue, + uchar alpha = 255); + rgb_color ViewColor() const; + + void SetViewUIColor(color_which which, + float tint = B_NO_TINT); + color_which ViewUIColor(float* tint = NULL) const; + + void SetViewBitmap(const BBitmap* bitmap, + BRect srcRect, BRect dstRect, + uint32 followFlags = B_FOLLOW_LEFT_TOP, + uint32 options = B_TILE_BITMAP); + void SetViewBitmap(const BBitmap* bitmap, + uint32 followFlags = B_FOLLOW_LEFT_TOP, + uint32 options = B_TILE_BITMAP); + void ClearViewBitmap(); + + status_t SetViewOverlay(const BBitmap* overlay, + BRect srcRect, BRect dstRect, + rgb_color* colorKey, + uint32 followFlags = B_FOLLOW_LEFT_TOP, + uint32 options = 0); + status_t SetViewOverlay(const BBitmap* overlay, + rgb_color* colorKey, + uint32 followFlags = B_FOLLOW_LEFT_TOP, + uint32 options = 0); + void ClearViewOverlay(); + + virtual void SetHighColor(rgb_color color); + void SetHighColor(uchar red, uchar green, uchar blue, + uchar alpha = 255); + rgb_color HighColor() const; + + void SetHighUIColor(color_which which, + float tint = B_NO_TINT); + color_which HighUIColor(float* tint = NULL) const; + + virtual void SetLowColor(rgb_color color); + void SetLowColor(uchar red, uchar green, uchar blue, + uchar alpha = 255); + rgb_color LowColor() const; + + void SetLowUIColor(color_which which, + float tint = B_NO_TINT); + color_which LowUIColor(float* tint = NULL) const; + + void SetLineMode(cap_mode lineCap, + join_mode lineJoin, + float miterLimit = B_DEFAULT_MITER_LIMIT); + join_mode LineJoinMode() const; + cap_mode LineCapMode() const; + float LineMiterLimit() const; + + void SetFillRule(int32 rule); + int32 FillRule() const; + + void SetOrigin(BPoint where); + void SetOrigin(float x, float y); + BPoint Origin() const; + + // Works in addition to Origin and Scale. + // May be used in parallel or as a much + // more powerful alternative. + void SetTransform(BAffineTransform transform); + BAffineTransform Transform() const; + void TranslateBy(double x, double y); + void ScaleBy(double x, double y); + void RotateBy(double angleRadians); + + BAffineTransform TransformTo(coordinate_space basis) const; + + void PushState(); + void PopState(); + + void MovePenTo(BPoint pt); + void MovePenTo(float x, float y); + void MovePenBy(float x, float y); + BPoint PenLocation() const; + void StrokeLine(BPoint toPoint, + ::pattern pattern = B_SOLID_HIGH); + void StrokeLine(BPoint start, BPoint end, + ::pattern pattern = B_SOLID_HIGH); + void BeginLineArray(int32 count); + void AddLine(BPoint start, BPoint end, + rgb_color color); + void EndLineArray(); + + void StrokePolygon(const BPolygon* polygon, + bool closed = true, + ::pattern pattern = B_SOLID_HIGH); + void StrokePolygon(const BPoint* pointArray, + int32 numPoints, bool closed = true, + ::pattern pattern = B_SOLID_HIGH); + void StrokePolygon(const BPoint* pointArray, + int32 numPoints, BRect bounds, + bool closed = true, + ::pattern pattern = B_SOLID_HIGH); + void FillPolygon(const BPolygon* polygon, + ::pattern pattern = B_SOLID_HIGH); + void FillPolygon(const BPoint* pointArray, + int32 numPoints, + ::pattern pattern = B_SOLID_HIGH); + void FillPolygon(const BPoint* pointArray, + int32 numPoints, BRect bounds, + ::pattern pattern = B_SOLID_HIGH); + void FillPolygon(const BPolygon* polygon, + const BGradient& gradient); + void FillPolygon(const BPoint* pointArray, + int32 numPoints, const BGradient& gradient); + void FillPolygon(const BPoint* pointArray, + int32 numPoints, BRect bounds, + const BGradient& gradient); + + void StrokeTriangle(BPoint point1, BPoint point2, + BPoint point3, BRect bounds, + ::pattern pattern = B_SOLID_HIGH); + void StrokeTriangle(BPoint point1, BPoint point2, + BPoint point3, + ::pattern pattern = B_SOLID_HIGH); + void FillTriangle(BPoint point1, BPoint point2, + BPoint point3, + ::pattern pattern = B_SOLID_HIGH); + void FillTriangle(BPoint point1, BPoint point2, + BPoint point3, BRect bounds, + ::pattern pattern = B_SOLID_HIGH); + void FillTriangle(BPoint point1, BPoint point2, + BPoint point3, const BGradient& gradient); + void FillTriangle(BPoint point1, BPoint point2, + BPoint point3, BRect bounds, + const BGradient& gradient); + + void StrokeRect(BRect rect, + ::pattern pattern = B_SOLID_HIGH); + void FillRect(BRect rect, + ::pattern pattern = B_SOLID_HIGH); + void FillRect(BRect rect, const BGradient& gradient); + void FillRegion(BRegion* rectegion, + ::pattern pattern = B_SOLID_HIGH); + void FillRegion(BRegion* rectegion, + const BGradient& gradient); + void InvertRect(BRect rect); + + void StrokeRoundRect(BRect rect, float xRadius, + float yRadius, + ::pattern pattern = B_SOLID_HIGH); + void FillRoundRect(BRect rect, float xRadius, + float yRadius, + ::pattern pattern = B_SOLID_HIGH); + void FillRoundRect(BRect rect, float xRadius, + float yRadius, const BGradient& gradient); + + void StrokeEllipse(BPoint center, float xRadius, + float yRadius, + ::pattern pattern = B_SOLID_HIGH); + void StrokeEllipse(BRect rect, + ::pattern pattern = B_SOLID_HIGH); + void FillEllipse(BPoint center, float xRadius, + float yRadius, + ::pattern pattern = B_SOLID_HIGH); + void FillEllipse(BRect rect, + ::pattern pattern = B_SOLID_HIGH); + void FillEllipse(BPoint center, float xRadius, + float yRadius, const BGradient& gradient); + void FillEllipse(BRect rect, + const BGradient& gradient); + + void StrokeArc(BPoint center, float xRadius, + float yRadius, float startAngle, + float arcAngle, + ::pattern pattern = B_SOLID_HIGH); + void StrokeArc(BRect rect, float startAngle, + float arcAngle, + ::pattern pattern = B_SOLID_HIGH); + void FillArc(BPoint center, float xRadius, + float yRadius, float startAngle, + float arcAngle, + ::pattern pattern = B_SOLID_HIGH); + void FillArc(BRect rect, float startAngle, + float arcAngle, + ::pattern pattern = B_SOLID_HIGH); + void FillArc(BPoint center, float xRadius, + float yRadius, float startAngle, + float arcAngle, const BGradient& gradient); + void FillArc(BRect rect, float startAngle, + float arcAngle, const BGradient& gradient); + + void StrokeBezier(BPoint* controlPoints, + ::pattern pattern = B_SOLID_HIGH); + void FillBezier(BPoint* controlPoints, + ::pattern pattern = B_SOLID_HIGH); + void FillBezier(BPoint* controlPoints, + const BGradient& gradient); + + void StrokeShape(BShape* shape, + ::pattern pattern = B_SOLID_HIGH); + void FillShape(BShape* shape, + ::pattern pattern = B_SOLID_HIGH); + void FillShape(BShape* shape, + const BGradient& gradient); + + void CopyBits(BRect src, BRect dst); + + void DrawBitmapAsync(const BBitmap* aBitmap, + BRect bitmapRect, BRect viewRect, + uint32 options); + void DrawBitmapAsync(const BBitmap* aBitmap, + BRect bitmapRect, BRect viewRect); + void DrawBitmapAsync(const BBitmap* aBitmap, + BRect viewRect); + void DrawBitmapAsync(const BBitmap* aBitmap, + BPoint where); + void DrawBitmapAsync(const BBitmap* aBitmap); + + void DrawBitmap(const BBitmap* aBitmap, + BRect bitmapRect, BRect viewRect, + uint32 options); + void DrawBitmap(const BBitmap* aBitmap, + BRect bitmapRect, BRect viewRect); + void DrawBitmap(const BBitmap* aBitmap, + BRect viewRect); + void DrawBitmap(const BBitmap* aBitmap, + BPoint where); + void DrawBitmap(const BBitmap* aBitmap); + + void DrawTiledBitmapAsync(const BBitmap* aBitmap, + BRect viewRect, BPoint phase = B_ORIGIN); + + void DrawTiledBitmap(const BBitmap* aBitmap, + BRect viewRect, BPoint phase = B_ORIGIN); + + void DrawChar(char aChar); + void DrawChar(char aChar, BPoint location); + void DrawString(const char* string, + escapement_delta* delta = NULL); + void DrawString(const char* string, + BPoint location, + escapement_delta* delta = NULL); + void DrawString(const char* string, int32 length, + escapement_delta* delta = NULL); + void DrawString(const char* string, int32 length, + BPoint location, + escapement_delta* delta = 0L); + void DrawString(const char* string, + const BPoint* locations, + int32 locationCount); + void DrawString(const char* string, int32 length, + const BPoint* locations, + int32 locationCount); + + virtual void SetFont(const BFont* font, + uint32 mask = B_FONT_ALL); + + void GetFont(BFont* font) const; + void TruncateString(BString* in_out, uint32 mode, + float width) const; + float StringWidth(const char* string) const; + float StringWidth(const char* string, + int32 length) const; + void GetStringWidths(char* stringArray[], + int32 lengthArray[], int32 numStrings, + float widthArray[]) const; + void SetFontSize(float size); + void ForceFontAliasing(bool enable); + void GetFontHeight(font_height* height) const; + + void Invalidate(BRect invalRect); + void Invalidate(const BRegion* invalRegion); + void Invalidate(); + void DelayedInvalidate(bigtime_t delay); + void DelayedInvalidate(bigtime_t delay, + BRect invalRect); + + void SetDiskMode(char* filename, long offset); + + void BeginPicture(BPicture* a_picture); + void AppendToPicture(BPicture* a_picture); + BPicture* EndPicture(); + + void DrawPicture(const BPicture* a_picture); + void DrawPicture(const BPicture* a_picture, + BPoint where); + void DrawPicture(const char* filename, long offset, + BPoint where); + void DrawPictureAsync(const BPicture* a_picture); + void DrawPictureAsync(const BPicture* a_picture, + BPoint where); + void DrawPictureAsync(const char* filename, + long offset, BPoint where); + + void BeginLayer(uint8 opacity); + void EndLayer(); + + status_t SetEventMask(uint32 mask, uint32 options = 0); + uint32 EventMask(); + status_t SetMouseEventMask(uint32 mask, + uint32 options = 0); + + virtual void SetFlags(uint32 flags); + uint32 Flags() const; + virtual void SetResizingMode(uint32 mode); + uint32 ResizingMode() const; + void MoveBy(float dh, float dv); + void MoveTo(BPoint where); + void MoveTo(float x, float y); + void ResizeBy(float dh, float dv); + void ResizeTo(float width, float height); + void ResizeTo(BSize size); + void ScrollBy(float dh, float dv); + void ScrollTo(float x, float y); + virtual void ScrollTo(BPoint where); + virtual void MakeFocus(bool focus = true); + bool IsFocus() const; + + virtual void Show(); + virtual void Hide(); + bool IsHidden() const; + bool IsHidden(const BView* looking_from) const; + + void Flush() const; + void Sync() const; + + virtual void GetPreferredSize(float* _width, float* _height); + virtual void ResizeToPreferred(); + + BScrollBar* ScrollBar(orientation direction) const; + + virtual BHandler* ResolveSpecifier(BMessage* message, int32 index, + BMessage* specifier, int32 form, + const char* property); + virtual status_t GetSupportedSuites(BMessage* data); + + bool IsPrinting() const; + void SetScale(float scale) const; + float Scale() const; + // new for Haiku + + virtual status_t Perform(perform_code code, void* data); + + virtual void DrawAfterChildren(BRect updateRect); + + // layout related + + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); + virtual BAlignment LayoutAlignment(); + + void SetExplicitMinSize(BSize size); + void SetExplicitMaxSize(BSize size); + void SetExplicitPreferredSize(BSize size); + void SetExplicitSize(BSize size); + void SetExplicitAlignment(BAlignment alignment); + + BSize ExplicitMinSize() const; + BSize ExplicitMaxSize() const; + BSize ExplicitPreferredSize() const; + BAlignment ExplicitAlignment() const; + + virtual bool HasHeightForWidth(); + virtual void GetHeightForWidth(float width, float* min, + float* max, float* preferred); + + void InvalidateLayout(bool descendants = false); + virtual void SetLayout(BLayout* layout); + BLayout* GetLayout() const; + + void EnableLayoutInvalidation(); + void DisableLayoutInvalidation(); + bool IsLayoutInvalidationDisabled(); + bool IsLayoutValid() const; + void ResetLayoutInvalidation(); + + BLayoutContext* LayoutContext() const; + + void Layout(bool force); + void Relayout(); + + class Private; + +protected: + virtual void LayoutInvalidated(bool descendants = false); + virtual void DoLayout(); + +public: + // tool tip support + + void SetToolTip(const char* text); + void SetToolTip(BToolTip* tip); + BToolTip* ToolTip() const; + + void ShowToolTip(BToolTip* tip = NULL); + void HideToolTip(); + +protected: + virtual bool GetToolTipAt(BPoint point, BToolTip** _tip); + + virtual void LayoutChanged(); + + status_t ScrollWithMouseWheelDelta(BScrollBar*, float); + +private: + void _Layout(bool force, BLayoutContext* context); + void _LayoutLeft(BLayout* deleted); + void _InvalidateParentLayout(); + +private: + // FBC padding and forbidden methods + virtual void _ReservedView13(); + virtual void _ReservedView14(); + virtual void _ReservedView15(); + virtual void _ReservedView16(); + + BView(const BView&); + BView& operator=(const BView&); + +private: + struct LayoutData; + + friend class Private; + friend class BBitmap; + friend class BLayout; + friend class BPrintJob; + friend class BScrollBar; + friend class BShelf; + friend class BTabView; + friend class BWindow; + + void _InitData(BRect frame, const char* name, + uint32 resizingMode, uint32 flags); + status_t _SetViewBitmap(const BBitmap* bitmap, + BRect srcRect, BRect dstRect, + uint32 followFlags, uint32 options); + void _ClipToPicture(BPicture* picture, BPoint where, + bool invert, bool sync); + + void _ClipToRect(BRect rect, bool inverse); + void _ClipToShape(BShape* shape, bool inverse); + + bool _CheckOwnerLockAndSwitchCurrent() const; + bool _CheckOwnerLock() const; + void _CheckLockAndSwitchCurrent() const; + void _CheckLock() const; + void _SwitchServerCurrentView() const; + + void _SetOwner(BWindow* newOwner); + void _RemoveCommArray(); + + BShelf* _Shelf() const; + void _SetShelf(BShelf* shelf); + + void _MoveTo(int32 x, int32 y); + void _ResizeBy(int32 deltaWidth, int32 deltaHeight); + void _ParentResizedBy(int32 deltaWidth, + int32 deltaHeight); + + void _ConvertToScreen(BPoint* pt, + bool checkLock) const; + void _ConvertFromScreen(BPoint* pt, + bool checkLock) const; + + void _ConvertToParent(BPoint* pt, + bool checkLock) const; + void _ConvertFromParent(BPoint* pt, + bool checkLock) const; + + void _Activate(bool state); + void _Attach(); + void _ColorsUpdated(BMessage* message); + void _Detach(); + void _Draw(BRect screenUpdateRect); + void _DrawAfterChildren(BRect screenUpdateRect); + void _FontsUpdated(BMessage*); + void _Pulse(); + + void _UpdateStateForRemove(); + void _UpdatePattern(::pattern pattern); + + void _FlushIfNotInTransaction(); + + bool _CreateSelf(); + bool _AddChildToList(BView* child, + BView* before = NULL); + bool _RemoveChildFromList(BView* child); + + bool _AddChild(BView *child, BView *before); + bool _RemoveSelf(); + void _RemoveLayoutItemsFromLayout(bool deleteItems); + + // Debugging methods + void _PrintToStream(); + void _PrintTree(); + + int32 _unused_int1; + + uint32 fFlags; + BPoint fParentOffset; + BWindow* fOwner; + BView* fParent; + BView* fNextSibling; + BView* fPreviousSibling; + BView* fFirstChild; + + int16 fShowLevel; + bool fTopLevelView; + bool fNoISInteraction; + BPicture* fCurrentPicture; + _array_data_* fCommArray; + + BScrollBar* fVerScroller; + BScrollBar* fHorScroller; + bool fIsPrinting; + bool fAttached; + bool _unused_bool1; + bool _unused_bool2; + ::BPrivate::ViewState* fState; + BRect fBounds; + BShelf* fShelf; + uint32 fEventMask; + uint32 fEventOptions; + uint32 fMouseEventOptions; + + LayoutData* fLayoutData; + BToolTip* fToolTip; + + uint32 _reserved[6]; +}; + + +// #pragma mark - inline definitions + + +inline void +BView::ScrollTo(float x, float y) +{ + ScrollTo(BPoint(x, y)); +} + + +inline void +BView::SetViewColor(uchar red, uchar green, uchar blue, uchar alpha) +{ + rgb_color color; + color.red = red; + color.green = green; + color.blue = blue; + color.alpha = alpha; + SetViewColor(color); +} + + +inline void +BView::SetHighColor(uchar red, uchar green, uchar blue, uchar alpha) +{ + rgb_color color; + color.red = red; + color.green = green; + color.blue = blue; + color.alpha = alpha; + SetHighColor(color); +} + + +inline void +BView::SetLowColor(uchar red, uchar green, uchar blue, uchar alpha) +{ + rgb_color color; + color.red = red; + color.green = green; + color.blue = blue; + color.alpha = alpha; + SetLowColor(color); +} + + +#endif // _VIEW_H diff --git a/headers/media/SoundFile.h b/headers/media/SoundFile.h new file mode 100644 index 0000000..6195c5b --- /dev/null +++ b/headers/media/SoundFile.h @@ -0,0 +1,101 @@ +/* + * Copyright 2009, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _SOUND_FILE_H +#define _SOUND_FILE_H + + +#include +#include +#include +#include +#include + + +// file formats +enum { + B_UNKNOWN_FILE, + B_AIFF_FILE, + B_WAVE_FILE, + B_UNIX_FILE +}; + + +class BSoundFile { +public: + BSoundFile(); + BSoundFile(const entry_ref* ref, + uint32 openMode); + virtual ~BSoundFile(); + + status_t InitCheck() const; + + status_t SetTo(const entry_ref* ref, uint32 openMode); + + int32 FileFormat() const; + int32 SamplingRate() const; + int32 CountChannels() const; + int32 SampleSize() const; + int32 ByteOrder() const; + int32 SampleFormat() const; + int32 FrameSize() const; + off_t CountFrames() const; + + bool IsCompressed() const; + int32 CompressionType() const; + char* CompressionName() const; + + virtual int32 SetFileFormat(int32 format); + virtual int32 SetSamplingRate(int32 fps); + virtual int32 SetChannelCount(int32 samplesPerFrame); + virtual int32 SetSampleSize(int32 bytesPerSample); + virtual int32 SetByteOrder(int32 byteOrder); + virtual int32 SetSampleFormat(int32 format); + virtual int32 SetCompressionType(int32 type); + virtual char* SetCompressionName(char* name); + virtual bool SetIsCompressed(bool compressed); + virtual off_t SetDataLocation(off_t offset); + virtual off_t SetFrameCount(off_t count); + + size_t ReadFrames(char* buffer, size_t count); + size_t WriteFrames(char* buffer, size_t count); + virtual off_t SeekToFrame(off_t index); + off_t FrameIndex() const; + off_t FramesRemaining() const; + + BFile* fSoundFile; + +private: + + virtual void _ReservedSoundFile1(); + virtual void _ReservedSoundFile2(); + virtual void _ReservedSoundFile3(); + + void _init_raw_stats(); + status_t _ref_to_file(const entry_ref* ref); + + int32 fFileFormat; + int32 fSamplingRate; + int32 fChannelCount; + int32 fSampleSize; + int32 fByteOrder; + int32 fSampleFormat; + + off_t fByteOffset; + // offset to first sample + + off_t fFrameCount; + off_t fFrameIndex; + + bool fIsCompressed; + int32 fCompressionType; + char* fCompressionName; + status_t fCStatus; + BMediaFile* fMediaFile; + BMediaTrack* fMediaTrack; + + uint32 _reserved[2]; +}; + +#endif // _SOUND_FILE_H diff --git a/pybind11 b/pybind11 new file mode 160000 index 0000000..b8cf161 --- /dev/null +++ b/pybind11 @@ -0,0 +1 @@ +Subproject commit b8cf16143e7261a48863e02604546a5a2ef43072 diff --git a/test.py b/test.py deleted file mode 100644 index 22502cf..0000000 --- a/test.py +++ /dev/null @@ -1,36 +0,0 @@ -from Be import BApplication, BWindow, BRect, BMessage, BView, BButton, window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE - -class Window(BWindow): - def __init__(self): - BWindow.__init__(self, BRect(100,100,200,150), "Hello Haiku!", window_type.B_TITLED_WINDOW, B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE) - self.say_hi = BMessage(1) - self.panel = BView(self.Bounds(), "panel", 8, 20000000) - self.button = BButton(self.panel.Bounds(), "hi", "Say Hello!", self.say_hi) #BRect(10,10,100,50) - self.panel.AddChild(self.button, None) - self.AddChild(self.panel, None) - - def MessageReceived(self, msg): - if msg.what == self.say_hi.what: - print("Hello World!") - else: - BWindow.MessageReceived(self, msg) - - def QuitRequested(self): - print("PyQUIT") - return True - -class App(BApplication): - def __init__(self): - BApplication.__init__(self, "application/x-python") - def ReadyToRun(self): - self.window = Window() - self.window.Show() - -def main(): - global be_app - be_app = App() - be_app.Run() - print('Ran') - -if __name__ == "__main__": - main() diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..80421af --- /dev/null +++ b/tests/README @@ -0,0 +1,3 @@ +This directory holds tests for Haiku-PyAPI. Currently, the tests are informal, +since we do not have any testing framework setup yet. (Help would be +appreciated!) diff --git a/tests/filesystem.py b/tests/filesystem.py new file mode 100644 index 0000000..3ac0e22 --- /dev/null +++ b/tests/filesystem.py @@ -0,0 +1,162 @@ +import os, sys, struct#, ctypes +from Be import BApplication,BNode,BEntry,BBitmap,BNodeInfo,BFile,BAppFileInfo +from Be.Entry import entry_ref +from Be import BMimeType,BRect,BPathFinder,BStringList +from Be.AppFileInfo import version_info,version_kind +from Be.Mime import icon_size +from Be.GraphicsDefs import * +from Be.FindDirectory import directory_which,path_base_directory +#from Be.GraphicsDefs import color_space +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 + + + +class App(BApplication): + def __init__(self): + BApplication.__init__(self, "application/x-python") + def ReadyToRun(self): + 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) + bf = BFile(f,0) + vi = version_info() + bafi = BAppFileInfo(bf) + bafi.GetVersionInfo(vi,version_kind.B_APP_VERSION_KIND) + #vi.short_info="File system tests" + #bafi.SetVersionInfo(vi,version_kind.B_APP_VERSION_KIND) + try: + print(vi.short_info) + except: + print("no short_info") + try: + print(vi.long_info) + except: + print("no long_info") + nf = BNode(f) + Ni = BNodeInfo(nf) + icondata=[] + dim = 0 + tipo = 0 + if Ni.GetIcon(icondata,dim,tipo): + print("ottenuto icondata da NodeInfo",icondata) + print(attr(nf)) + en=BEntry(f) + ref=entry_ref() + en_ref=en.GetRef(ref) + static = BMimeType() + mime = BMimeType.GuessMimeType(f,static) + if mime == 0: + print(static.Type()) + #TESTING MIMETYPE GETICON + ## testing geticon with raw data, most similar to c++ func + dataicon = [] + dim = 0 + static.GetIcon(dataicon,dim)# <--- dim is 0 + ############################ + ## testing with BBitmap, most similar to c++ func + icnbrdr = BRect(0.0, 0.0, 15.0, 15.0) + icon=BBitmap(icnbrdr,color_space.B_RGBA32) + bitti= icon.Bits() + static.GetIcon(icon,icon_size.B_MINI_ICON) + ribitti=icon.Bits() + if bitti == ribitti: + print("nothing changed") + else: + print("the new bitmap bits are:",ribitti) + listperc=BStringList() + BPathFinder.FindPaths(path_base_directory.B_FIND_PATH_BIN_DIRECTORY,listperc) + print(listperc.CountStrings()) + print(listperc.First().String()) + ############################# + ## test geticon with BBitmap, return tuple + #vale,icona=static.GetIcon(icon_size.B_MINI_ICON) + #if vale: + # print("icona bitmap ottuenuta") + # print(icona) + ############################# + ## test geticon with raw data, return tuple <--- this works + #vale,iconaraw=static.GetIcon() + #if vale==0: + # print("icona raw ottenuta") + # print(iconaraw) + self.Quit() + + + +#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) +def main(): + global be_app + be_app = App() + be_app.Run() + +if __name__ == "__main__": + main() diff --git a/tests/interfaceKit.py b/tests/interfaceKit.py new file mode 100644 index 0000000..a36a6e8 --- /dev/null +++ b/tests/interfaceKit.py @@ -0,0 +1,473 @@ + +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, TypeConstants,BShape +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 +from Be import InterfaceDefs +from Be.InterfaceDefs import border_style +from Be import AppDefs +from Be.Font import * + +from Be import BEntry +from Be.Entry import entry_ref +from Be.Entry import get_ref_for_path +from Be.TextView import text_run,text_run_array +from Be.View import set_font_mask +B_FONT_ALL = set_font_mask.B_FONT_ALL + +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 ShapeView(BView): + def __init__(self,frame,name,shape): + self.shape=shape + self.frame=frame + #trgb=rgb_color() + #trgb.red=255 + #trgb.blue=0 + #trgb.green=0 + #trgb.alpha=0 + #print(self.HighColor()) + BView.__init__(self,self.frame,name,8, 20000000) + def UpdateGlyph(self,glyph): + self.Draw(self.frame) + self.shape=glyph + self.SetHighColor(255,0,0,0) + self.SetLowColor(0,255,0,0) + self.FillRect(self.frame) + self.StrokeShape(glyph) + self.FillShape(glyph) + def Draw(self,rect): + BView.Draw(self,rect) + self.SetHighColor(255,0,0,0) + self.SetLowColor(0,255,0,0) + self.FillRect(rect) + print("Disegno lo shape") + #rect=BRect(0,0,self.frame.Width(),self.frame.Height()) + + self.StrokeShape(self.shape) + self.FillShape(self.shape) + +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 Text(self): + return self.testo + def Color(self): + return self.color + +class NewsItem(BListItem): + nocolor = (0, 0, 0, 0) + + def __init__(self, name,color): + self.name = name + self.color=color + BListItem.__init__(self) + + def DrawItem(self, owner, frame, complete): + if self.IsSelected() or complete: + color = (200,200,200,255) + 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 + # owner.SetFont(self.font) + #else: + # self.font = be_plain_font + # owner.SetFont(self.font) + #frame.PrintToStream() + owner.MovePenTo(5,frame.Height()-2) + owner.DrawString("▶ "+self.name,None) + + def Text(self): + return self.name + +class MyView(BView): + def __init__(self, rect,name,resizingMode,flags): + BView.__init__(self,rect,name,resizingMode,flags) + + def MouseDown(self, where): + where.PrintToStream() + BView.MouseDown(self,where) + +class ScrollView: + HiWhat = 32 #Doppioclick + def __init__(self, rect, name): + self.lv = BListView(rect, name, list_view_type.B_SINGLE_SELECTION_LIST) + self.sv = BScrollView('ScrollView', self.lv)#, 0x0202,0,False,False, border_style.B_FANCY_BORDER)#|0x1030 + + def topview(self): + return self.sv + + def listview(self): + return self.lv + +class Window(BWindow): + Menus = ( + ('File', ((1, 'asd'),(2, 'lol'),(5, 'bubu'),(None, None),(AppDefs.B_QUIT_REQUESTED, 'Quit'))), + ('Help', ((8, 'Help'),(3, 'About'))) + ) + CLRCTL = 4 + + def __init__(self): + BWindow.__init__(self, BRect(100,100,600,750), "Hello Haiku!", window_type.B_TITLED_WINDOW, B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE) + bounds=self.Bounds() + self.bckgnd = MyView(self.Bounds(), "background", 8, 20000000) + self.maintabview = BTabView(BRect(2.0, 2.0, bounds.Width()-2.0, bounds.Height()-2.0), 'tabview') + self.panel = MyView(self.Bounds(), "panel", 8, 20000000) + self.panel2 = MyView(self.Bounds(), "panel2", 8, 20000000) + self.panel3 = MyView(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()/2-15,144), 'progress','Progress: ', '') + self.statbar.SetMaxValue(100.0) + self.tachetest=BTextControl(BRect(57,bounds.Height()-30,bounds.Width()-57,bounds.Height()-12),'TxTCtrl', "prova:",None,BMessage(1),0x0202|0x0404) + self.tachetest.SetDivider(55.0) + 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,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()) + #bitti = img1.Bits() + #img1.SetBits(bitti,0,color_space.B_RGBA32) + #bitto = img1.Bits() + #if bitti == bitto: + # print("le immagini sono uguali") + #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 + # need to have it around afterwards. The goal of this hack is to + # make it that Python never frees NewsItem. The actual fix would + # involve something like Haiku-PyAPI telling Python that it has a + # reference to NewsItem and so cannot free it until Haiku-PyAPI + # is finished with it + newsitem = NewsItem("Nuova",(255,0,0,0)) + 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(self.elementolista)) + #self.list.sv.Show() + #self.panel.AddChild(self.list.topview(),None) + self.panel.AddChild(self.box,None) + self.panel.AddChild(self.sixradio,None) + self.panel.AddChild(self.sevenradio,None) + self.panel.AddChild(self.nineradio,None) + 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) + for menu, items in self.Menus: + menu = BMenu(menu) + for k, name in items: + if k is None: + menu.AddItem(BSeparatorItem()) + else: + menu.AddItem(BMenuItem(name, BMessage(k),name[1],0)) + self.bar.AddItem(menu) + self.tabslabels=[] + self.tabsviews=[] + self.tabsviews.append(self.panel) + 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) + 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_bold_font,511,colore)#B_FONT_ALL = 511 + stuff = '\n\t\t\t\t\t\tHello Haiku!\n\n\t\t\t\t\t\t\t\tA simple test program\n\t\t\t\t\t\t\t\tfor Haiku, version 1.0\n\t\t\t\t\t\t\t\tsample code included!\n\n\t\t\t\t\t\t\t\tby Fabio Tomat aka TmTFx\n\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\tspecial thanks to:\n\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) + ##self.tra=self.typtap.RunArray(0,len(self.typtap.Text())) + pittura=rgb_color() + pittura.red=255 + pittura.green=0 + pittura.blue=0 + pittura.alpha=255 + pictura=rgb_color() + pictura.red=0 + pictura.green=255 + pictura.blue=0 + pictura.alpha=255 + + tr1=text_run() + tr1.offset=0 + tr1.font=BFont(be_plain_font) + tr1.color=pittura + tr2=text_run() + tr2.offset=20 + tr2.font=BFont(be_bold_font) + tr2.color=pictura + mytralist=[tr1,tr2] + self.typtap.SetText(stuff,mytralist) + ##tra.count=2 #now you have 2 text_runs + ##tra.runs[1] = tr2 #assign the second one + ##print("tra runs modified",tra.runs) + ##self.typtap.SetRunArray(0,len(self.typtap.Text()),tra) #this doesn't work +# self.trb=text_run_array() + #trb=self.typtap.RunArray(0,len(self.typtap.Text()))#this crashes +# self.trb.count=2 +# self.trb.runs=mytralist +# self.typtap.SetText(stuff,self.trb) + #self.typtap.SetRunArray(0,len(self.typtap.Text()),trb) #this works, why error exiting and why does trb need tra (or it won't work) + #print(tra.runs[1].color.green) + #self.typtap.SetText(stuff,trb) + ###################### add other text_runs + ###### Example handling refs / BEntry ##### + a=entry_ref() + get_ref_for_path("/boot/home",a) + b=BEntry("/boot/home") + b.Exists() + #to complete + ########################################### + ### Test Message AddData e FindData #### + message=BMessage(100253) + ads="Tçaded00\nlol0".encode('utf-8') + asd="addizionale".encode("utf-8") + message.AddData("bytes",TypeConstants.B_RAW_TYPE,ads,len(ads),False,1) + message.AddData("bytes",TypeConstants.B_RAW_TYPE,asd,len(asd),False,1) + message.PrintToStream() + tret,tdata=message.FindData("bytes",TypeConstants.B_RAW_TYPE,1) + print(tret) + if tret == 0: + print(tdata.decode('utf-8')) + ## test BFont.GetFamilyAndStyle and SetFamilyAndStyle + fen=BFont(be_plain_font) + a,b=fen.GetFamilyAndStyle() + print(a,b) + fen.SetFamilyAndStyle(a,b) + #### test getboundingboxesforStrings + arstr=["test 1","prova 2","attempt 3"] + #boxarr=[] + esc1=escapement_delta() + esc1.nonspace=0 + esc1.space=0 + #fen.GetBoundingBoxesForStrings(arstr,len(arstr),font_metric_mode.B_SCREEN_METRIC,[esc1],boxarr) + o,u=fen.GetBoundingBoxesForStrings(arstr,font_metric_mode.B_SCREEN_METRIC) + print(o,u) + for kld in o: + print(kld.nonspace,kld.space) + for z in u: + print(z.PrintToStream()) + #print(boxarr) + ### test getescapements + #resesc=[] + #retesc=fen.GetEscapements("gnû gno",3,resesc) + retesc=fen.GetEscapements("gnû gno",5) + print("GetEscapements",retesc) + #print(resesc,retesc) + ### test gettruncatedstrings + #out1 = fen.GetTruncatedStrings(arstr,B_TRUNCATE_MIDDLE,100) + out2=[] + out1 = fen.GetTruncatedStrings(arstr,B_TRUNCATE_MIDDLE,100)#,out2) + print(out1,out2) + for sturinga in out1: + print("Stringa:",sturinga.String()) + larstr=[] + for s in arstr: + larstr.append(len(s)) + sw=fen.GetStringWidths(arstr,larstr) + print(sw) + sh=fen.GetGlyphShapes("çÛiao") + print(sh) + for shapi in sh: + shapi.Bounds().PrintToStream() + #shview=ShapeView(BRect(0,0,480,292),"Shapiro",sh[1]) + #self.panel.AddChild(shview,None) + #shview.UpdateGlyph(sh[2]) + + + def MessageReceived(self, msg): + if msg.what == 1: + self.startimer.SetValue(not(self.startimer.Value())) + + + elif msg.what == 2: + tr1=text_run() + tr1.offset=0 + tr1.font=be_bold_font + tr1.color=rgb_color() + tr2=text_run() + tr2.offset=2 + tr2.font=be_plain_font + tr2.color=rgb_color() + tr2.color.blue=255 + self.typtap.SetText("Ciao",[tr1,tr2]) + x=round(self.statbar.CurrentValue()) + if x<100: + outtxt=str(x+1)+"%" + self.statbar.Update(1.0,outtxt,"100%") + elif msg.what == 8: + ask = BAlert('Whoa!', 'Are you sure you need help?', 'Yes','No', None, InterfaceDefs.B_WIDTH_AS_USUAL, alert_type.B_IDEA_ALERT) + answ=ask.Go() + if answ==0: + risp = BAlert('lol', 'Well there\'s no help manual here', 'Bummer', None,None,InterfaceDefs.B_WIDTH_AS_USUAL,alert_type.B_INFO_ALERT) + risp.Go() + else: + risp = BAlert('lol', 'If you think so...', 'Poor me', None,None,InterfaceDefs.B_WIDTH_AS_USUAL,alert_type.B_WARNING_ALERT) + risp.Go() + BWindow.MessageReceived(self, msg) + + def FrameResized(self,x,y): + self.ResizeToPreferred() + + def QuitRequested(self): + print ("So long and thanks for all the fish") + return BWindow.QuitRequested(self) + +class App(BApplication): + def __init__(self): + BApplication.__init__(self, "application/x-python") + def ReadyToRun(self): + self.window = Window() + self.window.Show() + +def main(): + global be_app + be_app = App() + be_app.Run() + print('so said dolphins...') + +if __name__ == "__main__": + main() diff --git a/tests/looperLifetime.py b/tests/looperLifetime.py new file mode 100644 index 0000000..24867d7 --- /dev/null +++ b/tests/looperLifetime.py @@ -0,0 +1,76 @@ +# Tests that a Python class subclassing BLooper is not "forgotten" as soon as +# Python no longer holds any references to it, even though C++ is still using +# it. +# +# The more complicated, fuller explanation: +# This "forgetting" is caused by Python being unaware that C++ holds a +# reference to the Python subclass. So, once Python no longer holds any +# references, it frees the subclass. This, in effect, removes all of the method +# overrides of the base class and leads to methods of the base class being +# called directly. + +from Be import BLooper, BMessenger, B_QUIT_REQUESTED +import time + +looper_quit_called = False +looper_deleted = False + +# The main character of this test is TestLooper +class TestLooper(BLooper): + def __init__(self): + BLooper.__init__(self, "TestLooper") + + def Quit(self): + global looper_quit_called + looper_quit_called = True + BLooper.Quit(self) + + def __del__(self): + global looper_deleted + looper_deleted = True + # give_me_exception() # FIXME: causes program to crash with ugly error message + +testLooper = TestLooper() +testLooper.Run() + +# Make C++ obtain a reference to testLooper +messenger = BMessenger(None, testLooper) + +# Remove Python's reference to testLooper +# One of two things will now happen: +# 1. Python will know C++ has a reference and not delete testLooper yet +# (correct) +# 2. Python will not realize that C++ still has a reference to testLooper and +# will free it (incorrect) +del testLooper + +# Now tell the looper to quit. In effect, this calls the Quit function +# One of two things will now happen: +# 1. C++ will see that TestLooper exists and that its Quit function overrides +# BLooper.Quit, and will call TestLooper.Quit instead (correct) +# 2. C++ will see that nothing extends BLooper.Quit (since TestLooper.Quit has +# been freed) and call BLooper.Quit directly (incorrect) +messenger.SendMessage(B_QUIT_REQUESTED, None) + +# Free the messenger. Now we have no references to it either directly (through +# testLooper), or indirectly. This means that as soon as testLooper quits it +# should call its destructor. Otherwise, there is likely a memory leak. +del messenger + +# Give the looper a bit time to receive and process the message, quit, and +# clean up +time.sleep(.1) + +if looper_quit_called and looper_deleted: + print("Test passed!") + +if not looper_quit_called: + print("TestLooper.Quit wasn't called. This likely means that TestLooper " + " was freed too early, which probably means that something either" + " did not obtain a reference to it when it should have, or else" + " released it too early.") + +if not looper_deleted: + print("TestLooper.__del__ wasn't called. This likely signifies a memory" + " leak. Something that obtained a reference to TestLooper likely never" + " released it.")