Skip to content

Commit 9d541f5

Browse files
bind a few things
1 parent 2c25aee commit 9d541f5

File tree

10 files changed

+36
-130
lines changed

10 files changed

+36
-130
lines changed

Jamfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ local sourceFiles =
120120
Menu.cpp
121121
MenuItem.cpp
122122
MenuField.cpp
123-
GridLayout.cpp ;
123+
LayoutItem.cpp
124+
Layout.cpp
125+
AbstractLayout.cpp
126+
TwoDimensionalLayout.cpp
127+
GridLayout.cpp
128+
PopUpMenu.cpp ;
124129

125130
# The shared library Be.so can be built from the sourceFiles
126131
SharedLibrary Be.so : $(sourceFiles) ;

bindings/__init__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,34 @@
2626
from .StringView import *
2727
from .InterfaceDefs import *
2828
from .Alert import *
29+
from .TextView import *
30+
from .Menu import *
31+
from .MenuItem import *
32+
from .MenuField import *
33+
from .LayoutItem import *
34+
from .Layout import *
35+
from .AbstractLayout import *
36+
from .TwoDimensionalLayout import *
37+
from .GridLayout import *
38+
from .PopUpMenu import *
2939

3040
_BWindow=BWindow
3141
_BApplication=BApplication
32-
def MessageReceived(self, msg):
42+
def MessageReceived(self, msg, parent):
3343
if msg.what in self.events:
3444
self.events[msg.what](msg)
45+
elif msg in self.events:
46+
self.events[msg](msg)
3547
else:
36-
super(type(self)).MessageReceived(msg)
48+
parent.MessageReceived(msg)
3749

3850
class BWindow(_BWindow):
3951
events={}
40-
MessageReceived=MessageReceived
52+
MessageReceived=lambda msg, parent=_BWindow: MessageReceived(msg,parent)
4153

4254
class BApplication(_BApplication):
4355
events={}
44-
MessageReceived=MessageReceived
56+
MessageReceived=lambda msg, parent=_BApplication: MessageReceived(msg,parent)
4557

4658

4759
def int32(bytestr):

bindings/interface/AbstractLayout.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,5 @@ namespace py = pybind11;
1313

1414
PYBIND11_MODULE(AbstractLayout,m)
1515
{
16-
py::class_<BAbstractLayout, BLayout>(m, "BAbstractLayout")
17-
.def(py::init(), "")
18-
.def(py::init<BMessage *>(), "", py::arg("from"))
19-
.def("MinSize", &BAbstractLayout::MinSize, "")
20-
.def("MaxSize", &BAbstractLayout::MaxSize, "")
21-
.def("PreferredSize", &BAbstractLayout::PreferredSize, "")
22-
.def("Alignment", &BAbstractLayout::Alignment, "")
23-
.def("SetExplicitMinSize", &BAbstractLayout::SetExplicitMinSize, "", py::arg("size"))
24-
.def("SetExplicitMaxSize", &BAbstractLayout::SetExplicitMaxSize, "", py::arg("size"))
25-
.def("SetExplicitPreferredSize", &BAbstractLayout::SetExplicitPreferredSize, "", py::arg("size"))
26-
.def("SetExplicitAlignment", &BAbstractLayout::SetExplicitAlignment, "", py::arg("alignment"))
27-
.def("BaseMinSize", &BAbstractLayout::BaseMinSize, "")
28-
.def("BaseMaxSize", &BAbstractLayout::BaseMaxSize, "")
29-
.def("BasePreferredSize", &BAbstractLayout::BasePreferredSize, "")
30-
.def("BaseAlignment", &BAbstractLayout::BaseAlignment, "")
31-
.def("Frame", &BAbstractLayout::Frame, "")
32-
.def("SetFrame", &BAbstractLayout::SetFrame, "", py::arg("frame"))
33-
.def("IsVisible", &BAbstractLayout::IsVisible, "")
34-
.def("SetVisible", &BAbstractLayout::SetVisible, "", py::arg("visible"))
35-
.def("Archive", &BAbstractLayout::Archive, "", py::arg("into"), py::arg("deep")=true)
36-
.def("Perform", &BAbstractLayout::Perform, "", py::arg("d"), py::arg("arg"))
37-
;
38-
39-
16+
py::class_<BAbstractLayout, BLayout>(m, "BAbstractLayout");
4017
}

bindings/interface/GridLayout.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
#include <interface/GridLayout.h>
77
#include <TwoDimensionalLayout.h>
88
#include <View.h>
9+
#include <InterfaceDefs.h>
10+
911

1012
namespace py = pybind11;
1113

1214

1315
PYBIND11_MODULE(GridLayout,m)
1416
{
15-
py::class_<BGridLayout, BTwoDimensionalLayout>(m, "BGridLayout")
16-
.def(py::init<float, float>(), "", py::arg("horizontal")=B_USE_DEFAULT_SPACING, py::arg("vertical")=B_USE_DEFAULT_SPACING)
17+
py::class_<BGridLayout, BTwoDimensionalLayout, std::unique_ptr<BGridLayout,py::nodelete>>(m, "BGridLayout")
18+
// ImportError: arg(): could not convert default argument 'horizontal: ._anon_253' in method '<class 'Be.GridLayout.BGridLayout'>.__init__' into a Python object (type not registered yet?)
19+
.def(py::init<float, float>(), "", py::arg("horizontal")=py::int_(-1002), py::arg("vertical")=py::int_(-1002))
1720
.def(py::init<BMessage *>(), "", py::arg("from"))
1821
.def("CountColumns", &BGridLayout::CountColumns, "")
1922
.def("CountRows", &BGridLayout::CountRows, "")

bindings/interface/Layout.cpp

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,5 @@ namespace py = pybind11;
1717

1818
PYBIND11_MODULE(Layout,m)
1919
{
20-
py::class_<BLayout, BLayoutItem>(m, "BLayout")
21-
.def(py::init(), "")
22-
.def(py::init<BMessage *>(), "", py::arg("archive"))
23-
.def("Owner", &BLayout::Owner, "")
24-
.def("TargetView", &BLayout::TargetView, "")
25-
.def("View", &BLayout::View, "")
26-
.def("AddView", py::overload_cast<BView *>(&BLayout::AddView), "", py::arg("child"))
27-
.def("AddView", py::overload_cast<int, BView *>(&BLayout::AddView), "", py::arg("index"), py::arg("child"))
28-
.def("AddItem", py::overload_cast<BLayoutItem *>(&BLayout::AddItem), "", py::arg("item"))
29-
.def("AddItem", py::overload_cast<int, BLayoutItem *>(&BLayout::AddItem), "", py::arg("index"), py::arg("item"))
30-
.def("RemoveView", &BLayout::RemoveView, "", py::arg("child"))
31-
.def("RemoveItem", py::overload_cast<BLayoutItem *>(&BLayout::RemoveItem), "", py::arg("item"))
32-
.def("RemoveItem", py::overload_cast<int>(&BLayout::RemoveItem), "", py::arg("index"))
33-
.def("ItemAt", &BLayout::ItemAt, "", py::arg("index"))
34-
.def("CountItems", &BLayout::CountItems, "")
35-
.def("IndexOfItem", &BLayout::IndexOfItem, "", py::arg("item"))
36-
.def("IndexOfView", &BLayout::IndexOfView, "", py::arg("child"))
37-
.def("AncestorsVisible", &BLayout::AncestorsVisible, "")
38-
.def("InvalidateLayout", &BLayout::InvalidateLayout, "", py::arg("children")=false)
39-
.def("Relayout", &BLayout::Relayout, "", py::arg("immediate")=false)
40-
.def("RequireLayout", &BLayout::RequireLayout, "")
41-
.def("IsValid", &BLayout::IsValid, "")
42-
.def("EnableLayoutInvalidation", &BLayout::EnableLayoutInvalidation, "")
43-
.def("DisableLayoutInvalidation", &BLayout::DisableLayoutInvalidation, "")
44-
.def("LayoutItems", &BLayout::LayoutItems, "", py::arg("force")=false)
45-
.def("LayoutArea", &BLayout::LayoutArea, "")
46-
.def("LayoutContext", &BLayout::LayoutContext, "")
47-
.def("Archive", &BLayout::Archive, "", py::arg("into"), py::arg("deep")=true)
48-
.def("Perform", &BLayout::Perform, "", py::arg("d"), py::arg("arg"))
49-
;
50-
51-
20+
py::class_<BLayout, BLayoutItem>(m, "BLayout");
5221
}

bindings/interface/LayoutItem.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,5 @@ namespace py = pybind11;
1616

1717
PYBIND11_MODULE(LayoutItem,m)
1818
{
19-
py::class_<BLayoutItem, BArchivable>(m, "BLayoutItem")
20-
//.def(py::init(), "")
21-
.def(py::init<BMessage *>(), "", py::arg("from"))
22-
.def("Layout", &BLayoutItem::Layout, "")
23-
.def("RemoveSelf", &BLayoutItem::RemoveSelf, "")
24-
.def("MinSize", &BLayoutItem::MinSize, "")
25-
.def("MaxSize", &BLayoutItem::MaxSize, "")
26-
.def("PreferredSize", &BLayoutItem::PreferredSize, "")
27-
.def("Alignment", &BLayoutItem::Alignment, "")
28-
.def("SetExplicitMinSize", &BLayoutItem::SetExplicitMinSize, "", py::arg("size"))
29-
.def("SetExplicitMaxSize", &BLayoutItem::SetExplicitMaxSize, "", py::arg("size"))
30-
.def("SetExplicitPreferredSize", &BLayoutItem::SetExplicitPreferredSize, "", py::arg("size"))
31-
.def("SetExplicitSize", &BLayoutItem::SetExplicitSize, "", py::arg("size"))
32-
.def("SetExplicitAlignment", &BLayoutItem::SetExplicitAlignment, "", py::arg("alignment"))
33-
.def("IsVisible", &BLayoutItem::IsVisible, "")
34-
.def("SetVisible", &BLayoutItem::SetVisible, "", py::arg("visible"))
35-
.def("Frame", &BLayoutItem::Frame, "")
36-
.def("SetFrame", &BLayoutItem::SetFrame, "", py::arg("frame"))
37-
.def("HasHeightForWidth", &BLayoutItem::HasHeightForWidth, "")
38-
.def("GetHeightForWidth", &BLayoutItem::GetHeightForWidth, "", py::arg("width"), py::arg("min"), py::arg("max"), py::arg("preferred"))
39-
.def("View", &BLayoutItem::View, "")
40-
.def("InvalidateLayout", &BLayoutItem::InvalidateLayout, "", py::arg("children")=false)
41-
.def("Relayout", &BLayoutItem::Relayout, "", py::arg("immediate")=false)
42-
.def("LayoutData", &BLayoutItem::LayoutData, "")
43-
.def("SetLayoutData", &BLayoutItem::SetLayoutData, "", py::arg("data"))
44-
.def("AlignInFrame", &BLayoutItem::AlignInFrame, "", py::arg("frame"))
45-
.def("Archive", &BLayoutItem::Archive, "", py::arg("into"), py::arg("deep")=true)
46-
.def("Perform", &BLayoutItem::Perform, "", py::arg("d"), py::arg("arg"))
47-
;
48-
49-
19+
py::class_<BLayoutItem,std::unique_ptr<BLayoutItem, py::nodelete>>(m, "BLayoutItem");
5020
}

bindings/interface/MenuItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PYBIND11_MODULE(MenuItem,m)
1717
{
1818
//m.attr("MenuItemPrivate") = MenuItemPrivate;
1919

20-
py::class_<BMenuItem, BArchivable, BInvoker>(m, "BMenuItem")
20+
py::class_<BMenuItem, BInvoker>(m, "BMenuItem")
2121
.def(py::init<const char *, BMessage *, char, unsigned int>(), "", py::arg("label"), py::arg("message"), py::arg("shortcut")=0, py::arg("modifiers")=0)
2222
.def(py::init<BMenu *, BMessage *>(), "", py::arg("menu"), py::arg("message")=NULL)
2323
.def(py::init<BMessage *>(), "", py::arg("data"))

bindings/interface/PopUpMenu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <interface/PopUpMenu.h>
77
#include <Menu.h>
8+
#include <MenuItem.h>
89

910
namespace py = pybind11;
1011

bindings/interface/TwoDimensionalLayout.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,5 @@ namespace py = pybind11;
1111

1212
PYBIND11_MODULE(TwoDimensionalLayout,m)
1313
{
14-
py::class_<BTwoDimensionalLayout, BAbstractLayout>(m, "BTwoDimensionalLayout")
15-
.def(py::init(), "")
16-
.def(py::init<BMessage *>(), "", py::arg("from"))
17-
.def("SetInsets", py::overload_cast<float, float, float, float>(&BTwoDimensionalLayout::SetInsets), "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom"))
18-
.def("SetInsets", py::overload_cast<float, float>(&BTwoDimensionalLayout::SetInsets), "", py::arg("horizontal"), py::arg("vertical"))
19-
.def("SetInsets", py::overload_cast<float>(&BTwoDimensionalLayout::SetInsets), "", py::arg("insets"))
20-
.def("GetInsets", &BTwoDimensionalLayout::GetInsets, "", py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom"))
21-
.def("AlignLayoutWith", &BTwoDimensionalLayout::AlignLayoutWith, "", py::arg("other"), py::arg("orientation"))
22-
.def("BaseMinSize", &BTwoDimensionalLayout::BaseMinSize, "")
23-
.def("BaseMaxSize", &BTwoDimensionalLayout::BaseMaxSize, "")
24-
.def("BasePreferredSize", &BTwoDimensionalLayout::BasePreferredSize, "")
25-
.def("BaseAlignment", &BTwoDimensionalLayout::BaseAlignment, "")
26-
.def("HasHeightForWidth", &BTwoDimensionalLayout::HasHeightForWidth, "")
27-
.def("GetHeightForWidth", &BTwoDimensionalLayout::GetHeightForWidth, "", py::arg("width"), py::arg("min"), py::arg("max"), py::arg("preferred"))
28-
.def("SetFrame", &BTwoDimensionalLayout::SetFrame, "", py::arg("frame"))
29-
.def("Archive", &BTwoDimensionalLayout::Archive, "", py::arg("into"), py::arg("deep")=true)
30-
.def("Perform", &BTwoDimensionalLayout::Perform, "", py::arg("d"), py::arg("arg"))
31-
;
32-
33-
py::class_<ColumnRowConstraints>(m, "ColumnRowConstraints")
34-
.def_readwrite("weight", &ColumnRowConstraints::weight, "")
35-
.def_readwrite("min", &ColumnRowConstraints::min, "")
36-
.def_readwrite("max", &ColumnRowConstraints::max, "")
37-
;
38-
39-
py::class_<Dimensions>(m, "Dimensions")
40-
.def_readwrite("x", &Dimensions::x, "")
41-
.def_readwrite("y", &Dimensions::y, "")
42-
.def_readwrite("width", &Dimensions::width, "")
43-
.def_readwrite("height", &Dimensions::height, "")
44-
;
45-
46-
14+
py::class_<BTwoDimensionalLayout, BAbstractLayout>(m, "BTwoDimensionalLayout");
4715
}

bindings/interface/View.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ py::class_<BView,std::unique_ptr<BView, py::nodelete>>(m, "BView")
302302
.def("DrawString", py::overload_cast<const char *, int, BPoint, escapement_delta *>(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("location"), py::arg("delta")=0)
303303
.def("DrawString", py::overload_cast<const char *, const BPoint *, int>(&BView::DrawString), "", py::arg("string"), py::arg("locations"), py::arg("locationCount"))
304304
.def("DrawString", py::overload_cast<const char *, int, const BPoint *, int>(&BView::DrawString), "", py::arg("string"), py::arg("length"), py::arg("locations"), py::arg("locationCount"))
305-
.def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=B_FONT_ALL)
306-
.def("GetFont", &BView::GetFont, "", py::arg("font"))
307305
*/
306+
.def("SetFont", &BView::SetFont, "", py::arg("font"), py::arg("mask")=py::int_(0x000001FF))
307+
.def("GetFont", &BView::GetFont, "", py::arg("font"))
308+
308309
.def("TruncateString", &BView::TruncateString, "", py::arg("in_out"), py::arg("mode"), py::arg("width"))
309310
.def("StringWidth", py::overload_cast<const char *>(&BView::StringWidth, py::const_), "", py::arg("string"))
310311
.def("StringWidth", py::overload_cast<const char *, int>(&BView::StringWidth, py::const_), "", py::arg("string"), py::arg("length"))

0 commit comments

Comments
 (0)