Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/interface/MenuField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PyBMenuField : public BMenuField{
PYBIND11_OVERLOAD(void, BMenuField, DetachedFromWindow);
}
void AllDetached() override {
PYBIND11_OVERLOAD(void, BMenuField, AllAttached);
PYBIND11_OVERLOAD(void, BMenuField, AllDetached);
}
void FrameMoved(BPoint where) override {
PYBIND11_OVERLOAD(void, BMenuField, FrameMoved, where);
Expand Down
63 changes: 63 additions & 0 deletions tests/menuFieldDetachCallbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from Be import BApplication, BMenu, BMenuField


EXPECTED_CALLBACKS = [
"DetachedFromWindow",
"AllDetached",
]


class CallbackProbe(BMenuField):
def __init__(self):
self.menu = BMenu("callback-probe-menu")

BMenuField.__init__(
self,
"callback-probe",
"Callback probe",
self.menu,
)

self.calls = []

def AllAttached(self):
self.calls.append("AllAttached")

def DetachedFromWindow(self):
self.calls.append("DetachedFromWindow")

def AllDetached(self):
self.calls.append("AllDetached")


def main():
application = BApplication(
"application/x-vnd.haiku-pyapi-"
"menufield-detach-callback-test"
)

field = CallbackProbe()

# Enter the C++ virtual trampolines through the bound
# base methods instead of calling Python overrides directly.
BMenuField.DetachedFromWindow(field)
BMenuField.AllDetached(field)

if field.calls != EXPECTED_CALLBACKS:
raise SystemExit(
"FAIL: incorrect BMenuField detach callback "
f"dispatch: {field.calls!r}"
)

print("callbacks =", field.calls)
print(
"BMENUFIELD DETACH CALLBACK "
"REGRESSION TEST: PASS"
)

del field
del application


if __name__ == "__main__":
main()