From 8922ca4bf4a0e2f4b081463108920d3613edccff Mon Sep 17 00:00:00 2001 From: kohait Date: Thu, 19 May 2011 07:21:21 +0000 Subject: [PATCH] bazaar: Py: xompile fix without boost; PyConsoleCtrl: some api improvements, BoostPyTest: export PyConsoleCtrl to Py itself, major Callback macrofication; PointCtrl handling fixes git-svn-id: svn://ultimatepp.org/upp/trunk@3435 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/BoostPyTest/BoostPyTest.h | 19 ++ bazaar/BoostPyTest/BoostPyTest.upp | 5 +- bazaar/BoostPyTest/PyConsoleCtrl.cpp | 29 ++ bazaar/BoostPyTest/PyConsoleCtrl.h | 13 + bazaar/BoostPyTest/main.cpp | 25 +- bazaar/BoostPyTest/modules.cppi | 17 + bazaar/BoostPyTest/myupp.py | 5 + bazaar/CoreBoostPy/Callback.cpp | 138 ++------ bazaar/CoreBoostPy/Callback.h | 456 +++++++++++++++++++++++++ bazaar/CoreBoostPy/CoreBoostPy.cpp | 2 + bazaar/PointCtrl/PointCtrl.cpp | 10 +- bazaar/Py/Py.cpp | 2 + bazaar/PyConsoleCtrl/PyConsoleCtrl.cpp | 8 +- bazaar/PyConsoleCtrl/PyConsoleCtrl.h | 3 + 14 files changed, 610 insertions(+), 122 deletions(-) create mode 100644 bazaar/BoostPyTest/PyConsoleCtrl.cpp create mode 100644 bazaar/BoostPyTest/PyConsoleCtrl.h diff --git a/bazaar/BoostPyTest/BoostPyTest.h b/bazaar/BoostPyTest/BoostPyTest.h index 1d0447bcc..335c7d456 100644 --- a/bazaar/BoostPyTest/BoostPyTest.h +++ b/bazaar/BoostPyTest/BoostPyTest.h @@ -5,9 +5,28 @@ using namespace boost::python; #include "world.h" +#include "PyConsoleCtrl.h" #include using namespace Upp; +NAMESPACE_UPP + +decl_export_Callback1(int); +decl_export_Gate1(int); +decl_export_Callback1(Value); +decl_export_Gate1(Value); + +decl_export_Callback2(int, double); +decl_export_Gate2(int, double); + +decl_export_Callback3(int, double, bool); +decl_export_Gate3(int, double, bool); + +decl_export_Callback4(int, double, bool, int64); +decl_export_Gate4(int, double, bool, int64); + +END_UPP_NAMESPACE + #define LAYOUTFILE #include diff --git a/bazaar/BoostPyTest/BoostPyTest.upp b/bazaar/BoostPyTest/BoostPyTest.upp index 1e45cce99..29bfd2d7c 100644 --- a/bazaar/BoostPyTest/BoostPyTest.upp +++ b/bazaar/BoostPyTest/BoostPyTest.upp @@ -5,11 +5,14 @@ uses CtrlLibBoostPy; file + PyConsoleCtrl.h, + PyConsoleCtrl.cpp, world.h, world.cpp, - BoostPyTest.h, + app readonly separator, compile.txt, modules.cppi, + BoostPyTest.h, main.cpp, BoostPyTest.lay; diff --git a/bazaar/BoostPyTest/PyConsoleCtrl.cpp b/bazaar/BoostPyTest/PyConsoleCtrl.cpp new file mode 100644 index 000000000..0d08d5d92 --- /dev/null +++ b/bazaar/BoostPyTest/PyConsoleCtrl.cpp @@ -0,0 +1,29 @@ +#include "PyConsoleCtrl.h" +using namespace boost::python; + +#include +using namespace Upp; + +NAMESPACE_UPP + +void export_PyConsoleCtrl() +{ +ONCELOCK +{ + export_CtrlLib(); + + class_, boost::noncopyable>("PyConsoleCtrl", "Upp PyConsoleCtrl") + .def("clear", &PyConsoleCtrl::Clear) + .def("savedlg", &PyConsoleCtrl::SaveDlg) + .def("save", &PyConsoleCtrl::Save) + .def("loaddlg", &PyConsoleCtrl::LoadDlg) + .def("load", &PyConsoleCtrl::Load) + //.def("exec", &PyConsoleCtrl::Exec) //very dangerous + + .def("clearlog", &PyConsoleCtrl::ClearLog) + .def("savelog", &PyConsoleCtrl::SaveLog) + ; +} +} + +END_UPP_NAMESPACE diff --git a/bazaar/BoostPyTest/PyConsoleCtrl.h b/bazaar/BoostPyTest/PyConsoleCtrl.h new file mode 100644 index 000000000..27d5a5475 --- /dev/null +++ b/bazaar/BoostPyTest/PyConsoleCtrl.h @@ -0,0 +1,13 @@ +#ifndef _BoostPyTest_PyConsoleCtrl_h_ +#define _BoostPyTest_PyConsoleCtrl_h_ + +#include + +NAMESPACE_UPP + +void export_PyConsoleCtrl(); + +END_UPP_NAMESPACE + + +#endif diff --git a/bazaar/BoostPyTest/main.cpp b/bazaar/BoostPyTest/main.cpp index fc5e5aa69..58addd7f2 100644 --- a/bazaar/BoostPyTest/main.cpp +++ b/bazaar/BoostPyTest/main.cpp @@ -1,5 +1,26 @@ #include "BoostPyTest.h" +// CallbackX / GateX definitions need to go before the module include +// it's kinda template instantiation + +NAMESPACE_UPP + +def_export_Callback1(int) +def_export_Gate1(int) +def_export_Callback1(Value) +def_export_Gate1(Value) + +def_export_Callback2(int, double) +def_export_Gate2(int, double) + +def_export_Callback3(int, double, bool) +def_export_Gate3(int, double, bool) + +def_export_Callback4(int, double, bool, int64) +def_export_Gate4(int, double, bool, int64) + +END_UPP_NAMESPACE + //CAUTION special module definitions to reduce compile time #include "modules.cppi" @@ -74,6 +95,8 @@ BoostPyTest::BoostPyTest() scope(upp_module).attr("app") = ptr((TopWindow*)this); + scope(upp_module).attr("con") = ptr(&con); + sl.SetData(50); scope(upp_module).attr("sl") = ptr(&sl); @@ -186,7 +209,7 @@ BoostPyTest::BoostPyTest() "print hello.invworld(mu,7)\n" "import fibo\n" - "fibo.fib(200)\n" + "print fibo.fib(200)\n" "import myupp\n" "myupp.chtitle()\n" diff --git a/bazaar/BoostPyTest/modules.cppi b/bazaar/BoostPyTest/modules.cppi index 7afa9c710..b216d00a2 100644 --- a/bazaar/BoostPyTest/modules.cppi +++ b/bazaar/BoostPyTest/modules.cppi @@ -12,4 +12,21 @@ BOOST_PYTHON_MODULE(upp) export_Core(); export_CtrlCore(); export_CtrlLib(); + + export_PyConsoleCtrl(); + + export_Callback1(int); + export_Gate1(int); + + export_Callback1(Value); + export_Gate1(Value); + + export_Callback2(int, double); + export_Gate2(int, double); + + export_Callback3(int, double, bool); + export_Gate3(int, double, bool); + + export_Callback4(int, double, bool, int64); + export_Gate4(int, double, bool, int64); } diff --git a/bazaar/BoostPyTest/myupp.py b/bazaar/BoostPyTest/myupp.py index d8b76d5be..59139f841 100644 --- a/bazaar/BoostPyTest/myupp.py +++ b/bazaar/BoostPyTest/myupp.py @@ -1,3 +1,8 @@ import upp; + +# some calls directly to embedded python, called when this module is imported +print upp.app.title; + +# some function definitions, can be called from embedded python def chtitle(): upp.app.title = "The title was changed from outside :)" diff --git a/bazaar/CoreBoostPy/Callback.cpp b/bazaar/CoreBoostPy/Callback.cpp index b2c48e66a..c98a62aee 100644 --- a/bazaar/CoreBoostPy/Callback.cpp +++ b/bazaar/CoreBoostPy/Callback.cpp @@ -1,32 +1,29 @@ #include "Callback.h" -using namespace boost::python; NAMESPACE_UPP -//Callback +void* call_convertible(PyObject* po) +{ + if(po == Py_None) return po; + if(PyFunction_Check(po)) return po; + if(PyCallable_Check(po) && PyMethod_Self(po)) return po; + return 0; +} +//Callback struct CallbackActionPy : public CallbackAction { object o; - virtual void Execute() { call(o.ptr()); } + virtual void Execute() + { + tuple args; + invoke(o.ptr(), args.ptr()); + } CallbackActionPy(PyObject *callable) : o(handle<>(borrowed(callable))) {} }; -struct Callback_to_python //FIXME translation of Callback internals to python -{ - static PyObject* convert(const Callback& s) { return incref(object(s).ptr()); } -}; - struct Callback_from_python { - Callback_from_python() { converter::registry::push_back(&convertible, &construct, type_id()); } - - static void* convertible(PyObject* po) - { - if(po == Py_None) return po; - if(PyFunction_Check(po)) return po; - if(PyCallable_Check(po) && PyMethod_Self(po)) return po; - return 0; - } + Callback_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id()); } static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) { @@ -42,24 +39,19 @@ struct Callback_from_python }; //Gate - struct GateActionPy : public GateAction { object o; - virtual bool Execute() { return call(o.ptr()); } + virtual bool Execute() + { + tuple args; + return invoke(o.ptr(), args.ptr()); + } GateActionPy(PyObject *callable) : o(handle<>(borrowed(callable))) {} }; struct Gate_from_python { - Gate_from_python() { converter::registry::push_back(&convertible, &construct, type_id()); } - - static void* convertible(PyObject* po) - { - if(po == Py_None) return po; - if(PyFunction_Check(po)) return po; - if(PyCallable_Check(po) && PyMethod_Self(po)) return po; - return 0; - } + Gate_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id()); } static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) { @@ -74,107 +66,31 @@ struct Gate_from_python } }; -/// - -struct Callback1Action_int_Py : public Callback1Action { - object o; - virtual void Execute(int p1) { call(o.ptr(), "i", p1); } - Callback1Action_int_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} -}; - -struct Callback1_int_from_python -{ - Callback1_int_from_python() { converter::registry::push_back(&convertible, &construct, type_id >()); } - - static void* convertible(PyObject* po) - { - if(po == Py_None) return po; - if(PyFunction_Check(po)) return po; - if(PyCallable_Check(po) && PyMethod_Self(po)) return po; - return 0; - } - - static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) - { - void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; - - if(po == Py_None) { new(d) Callback1(); } - else if(PyFunction_Check(po)) { new(d) Callback1(new Callback1Action_int_Py(po)); } - else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Callback1(new Callback1Action_int_Py(po)); } - else { throw_error_already_set(); } - - data->convertible = d; - } -}; - -//Gate1 - -struct Gate1Action_int_Py : public Gate1Action { - object o; - virtual bool Execute(int p1) { return call(o.ptr(), "i", p1); } - Gate1Action_int_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} -}; - -struct Gate1_int_from_python -{ - Gate1_int_from_python() { converter::registry::push_back(&convertible, &construct, type_id >()); } - - static void* convertible(PyObject* po) - { - if(po == Py_None) return po; - if(PyFunction_Check(po)) return po; - if(PyCallable_Check(po) && PyMethod_Self(po)) return po; - return 0; - } - - static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) - { - void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; - - if(po == Py_None) { new(d) Gate1(); } - else if(PyFunction_Check(po)) { new(d) Gate1(new Gate1Action_int_Py(po)); } - else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Gate1(new Gate1Action_int_Py(po)); } - else { throw_error_already_set(); } - - data->convertible = d; - } -}; - void export_Callback() { ONCELOCK { - //to_python_converter(); Callback_from_python(); - class_("Callback", "Upp Callback") .def(init()) .def("clear", &Callback::Clear) .def("valid", &Callback::operator bool) .def("__call__", &Callback::Execute) ; +} +} +void export_Gate() +{ +ONCELOCK +{ + Callback_from_python(); class_("Gate", "Upp Gate") .def(init()) .def("clear", &Gate::Clear) .def("valid", &Gate::operator bool) .def("__call__", &Gate::Execute) ; - - class_ >("Callback1", "Upp Callback1") - .def(init&>()) - .def("clear", &Callback1::Clear) - .def("valid", &Callback1::operator bool) - .def("__call__", &Callback1::Execute) - ; - - class_ >("Gate1", "Upp Gate1") - .def(init&>()) - .def("clear", &Gate1::Clear) - .def("valid", &Gate1::operator bool) - .def("__call__", &Gate1::Execute) - ; - } } diff --git a/bazaar/CoreBoostPy/Callback.h b/bazaar/CoreBoostPy/Callback.h index f34e707ea..d892ce583 100644 --- a/bazaar/CoreBoostPy/Callback.h +++ b/bazaar/CoreBoostPy/Callback.h @@ -3,9 +3,465 @@ #include "Common.h" +namespace boost { namespace python { + +template < + class R + > +typename detail::returnable::type +invoke(PyObject* callable + , PyObject* args + , boost::type* = 0 + ) +{ + PyObject* const result = + PyObject_CallObject( + callable + , args + ); + + // This conversion *must not* be done in the same expression as + // the call, because, in the special case where the result is a + // reference a Python object which was created by converting a C++ + // argument for passing to PyEval_CallFunction, its reference + // count will be 2 until the end of the full expression containing + // the conversion, and that interferes with dangling + // pointer/reference detection. + converter::return_from_python converter; + return converter(result); +} + +}} //ns + NAMESPACE_UPP +using namespace boost::python; + +void* call_convertible(PyObject* po); + +//1 +#define def_export_Callback1(P1) \ + \ +struct Callback1Action_##P1##_Py : public Callback1Action { \ + object o; \ + virtual void Execute(P1 p1) \ + { \ + tuple args = make_tuple(p1); \ + invoke(o.ptr(), args.ptr()); \ + } \ + Callback1Action_##P1##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Callback1_##P1##_from_python \ +{ \ + Callback1_##P1##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Callback1(); } \ + else if(PyFunction_Check(po)) { new(d) Callback1(new Callback1Action_##P1##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Callback1(new Callback1Action_##P1##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Callback1_##P1() \ +{ \ +ONCELOCK \ +{ \ + Callback1_##P1##_from_python(); \ + class_ >("Callback1_"#P1, "Upp Callback1<"#P1">") \ + .def(init&>()) \ + .def("clear", &Callback1::Clear) \ + .def("valid", &Callback1::operator bool) \ + .def("__call__", &Callback1::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Callback1(P1) \ +void export_Callback1_##P1() \ + + +#define export_Callback1(P1) \ +export_Callback1_##P1() \ + + +#define def_export_Gate1(P1) \ + \ +struct Gate1Action_##P1##_Py : public Gate1Action { \ + object o; \ + virtual bool Execute(P1 p1) \ + { \ + tuple args = make_tuple(p1); \ + return invoke(o.ptr(), args.ptr()); \ + } \ + Gate1Action_##P1##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Gate1_##P1##_from_python \ +{ \ + Gate1_##P1##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Gate1(); } \ + else if(PyFunction_Check(po)) { new(d) Gate1(new Gate1Action_##P1##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Gate1(new Gate1Action_##P1##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Gate1_##P1() \ +{ \ +ONCELOCK \ +{ \ + Gate1_##P1##_from_python(); \ + class_ >("Gate1_"#P1, "Upp Gate1<"#P1">") \ + .def(init&>()) \ + .def("clear", &Gate1::Clear) \ + .def("valid", &Gate1::operator bool) \ + .def("__call__", &Gate1::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Gate1(P1) \ +void export_Gate1_##P1() \ + + +#define export_Gate1(P1) \ +export_Gate1_##P1() \ + + +//2 +#define def_export_Callback2(P1, P2) \ + \ +struct Callback2Action_##P1##_##P2##_Py : public Callback2Action { \ + object o; \ + virtual void Execute(P1 p1, P2 p2) \ + { \ + tuple args = make_tuple(p1, p2); \ + invoke(o.ptr(), args.ptr()); \ + } \ + Callback2Action_##P1##_##P2##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Callback2_##P1##_##P2##_from_python \ +{ \ + Callback2_##P1##_##P2##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Callback2(); } \ + else if(PyFunction_Check(po)) { new(d) Callback2(new Callback2Action_##P1##_##P2##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Callback2(new Callback2Action_##P1##_##P2##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Callback2_##P1##_##P2() \ +{ \ +ONCELOCK \ +{ \ + Callback2_##P1##_##P2##_from_python(); \ + class_ >("Callback2_"#P1"_"#P2, "Upp Callback2<"#P1","#P2">") \ + .def(init&>()) \ + .def("clear", &Callback2::Clear) \ + .def("valid", &Callback2::operator bool) \ + .def("__call__", &Callback2::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Callback2(P1, P2) \ +void export_Callback2_##P1##_##P2() \ + + +#define export_Callback2(P1, P2) \ +export_Callback2_##P1##_##P2() \ + + +#define def_export_Gate2(P1, P2) \ + \ +struct Gate2Action_##P1##_##P2##_Py : public Gate2Action { \ + object o; \ + virtual bool Execute(P1 p1, P2 p2) \ + { \ + tuple args = make_tuple(p1, p2); \ + return invoke(o.ptr(), args.ptr()); \ + } \ + Gate2Action_##P1##_##P2##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Gate2_##P1##_##P2##_from_python \ +{ \ + Gate2_##P1##_##P2##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Gate2(); } \ + else if(PyFunction_Check(po)) { new(d) Gate2(new Gate2Action_##P1##_##P2##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Gate2(new Gate2Action_##P1##_##P2##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Gate2_##P1##_##P2() \ +{ \ +ONCELOCK \ +{ \ + Gate2_##P1##_##P2##_from_python(); \ + class_ >("Gate2_"#P1"_"#P2, "Upp Gate2<"#P1","#P2">") \ + .def(init&>()) \ + .def("clear", &Gate2::Clear) \ + .def("valid", &Gate2::operator bool) \ + .def("__call__", &Gate2::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Gate2(P1, P2) \ +void export_Gate2_##P1##_##P2() \ + + +#define export_Gate2(P1, P2) \ +export_Gate2_##P1##_##P2() \ + + +//3 +#define def_export_Callback3(P1, P2, P3) \ + \ +struct Callback3Action_##P1##_##P2##_##P3##_Py : public Callback3Action { \ + object o; \ + virtual void Execute(P1 p1, P2 p2, P3 p3) \ + { \ + tuple args = make_tuple(p1, p2, p3); \ + invoke(o.ptr(), args.ptr()); \ + } \ + Callback3Action_##P1##_##P2##_##P3##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Callback3_##P1##_##P2##_##P3##_from_python \ +{ \ + Callback3_##P1##_##P2##_##P3##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Callback3(); } \ + else if(PyFunction_Check(po)) { new(d) Callback3(new Callback3Action_##P1##_##P2##_##P3##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Callback3(new Callback3Action_##P1##_##P2##_##P3##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Callback3_##P1##_##P2##_##P3() \ +{ \ +ONCELOCK \ +{ \ + Callback3_##P1##_##P2##_##P3##_from_python(); \ + class_ >("Callback3_"#P1"_"#P2"_"#P3, "Upp Callback3<"#P1","#P2","#P3">") \ + .def(init&>()) \ + .def("clear", &Callback3::Clear) \ + .def("valid", &Callback3::operator bool) \ + .def("__call__", &Callback3::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Callback3(P1, P2, P3) \ +void export_Callback3_##P1##_##P2##_##P3() \ + + +#define export_Callback3(P1, P2, P3) \ +export_Callback3_##P1##_##P2##_##P3() \ + + +#define def_export_Gate3(P1, P2, P3) \ + \ +struct Gate3Action_##P1##_##P2##_##P3##_Py : public Gate3Action { \ + object o; \ + virtual bool Execute(P1 p1, P2 p2, P3 p3) \ + { \ + tuple args = make_tuple(p1, p2, p3); \ + return invoke(o.ptr(), args.ptr()); \ + } \ + Gate3Action_##P1##_##P2##_##P3##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Gate3_##P1##_##P2##_##P3##_from_python \ +{ \ + Gate3_##P1##_##P2##_##P3##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Gate3(); } \ + else if(PyFunction_Check(po)) { new(d) Gate3(new Gate3Action_##P1##_##P2##_##P3##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Gate3(new Gate3Action_##P1##_##P2##_##P3##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Gate3_##P1##_##P2##_##P3() \ +{ \ +ONCELOCK \ +{ \ + Gate3_##P1##_##P2##_##P3##_from_python(); \ + class_ >("Gate3_"#P1"_"#P2"_"#P3, "Upp Gate3<"#P1","#P2","#P3">") \ + .def(init&>()) \ + .def("clear", &Gate3::Clear) \ + .def("valid", &Gate3::operator bool) \ + .def("__call__", &Gate3::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Gate3(P1, P2, P3) \ +void export_Gate3_##P1##_##P2##_##P3() \ + + +#define export_Gate3(P1, P2, P3) \ +export_Gate3_##P1##_##P2##_##P3() \ + + +//4 +#define def_export_Callback4(P1, P2, P3, P4) \ + \ +struct Callback4Action_##P1##_##P2##_##P3##_##P4##_Py : public Callback4Action { \ + object o; \ + virtual void Execute(P1 p1, P2 p2, P3 p3, P4 p4) \ + { \ + tuple args = make_tuple(p1, p2, p3, p4); \ + invoke(o.ptr(), args.ptr()); \ + } \ + Callback4Action_##P1##_##P2##_##P3##_##P4##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Callback4_##P1##_##P2##_##P3##_##P4##_from_python \ +{ \ + Callback4_##P1##_##P2##_##P3##_##P4##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Callback4(); } \ + else if(PyFunction_Check(po)) { new(d) Callback4(new Callback4Action_##P1##_##P2##_##P3##_##P4##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Callback4(new Callback4Action_##P1##_##P2##_##P3##_##P4##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Callback4_##P1##_##P2##_##P3##_##P4() \ +{ \ +ONCELOCK \ +{ \ + Callback4_##P1##_##P2##_##P3##_##P4##_from_python(); \ + class_ >("Callback4_"#P1"_"#P2"_"#P3"_"#P4, "Upp Callback4<"#P1","#P2","#P3","#P4">") \ + .def(init&>()) \ + .def("clear", &Callback4::Clear) \ + .def("valid", &Callback4::operator bool) \ + .def("__call__", &Callback4::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Callback4(P1, P2, P3, P4) \ +void export_Callback4_##P1##_##P2##_##P3##_##P4() \ + + +#define export_Callback4(P1, P2, P3, P4) \ +export_Callback4_##P1##_##P2##_##P3##_##P4() \ + + +#define def_export_Gate4(P1, P2, P3, P4) \ + \ +struct Gate4Action_##P1##_##P2##_##P3##_##P4##_Py : public Gate4Action { \ + object o; \ + virtual bool Execute(P1 p1, P2 p2, P3 p3, P4 p4) \ + { \ + tuple args = make_tuple(p1, p2, p3, p4); \ + return invoke(o.ptr(), args.ptr()); \ + } \ + Gate4Action_##P1##_##P2##_##P3##_##P4##_Py(PyObject *callable) : o(handle<>(borrowed(callable))) {} \ +}; \ + \ +struct Gate4_##P1##_##P2##_##P3##_##P4##_from_python \ +{ \ + Gate4_##P1##_##P2##_##P3##_##P4##_from_python() { converter::registry::push_back(&call_convertible, &construct, type_id >()); } \ + \ + static void construct(PyObject* po, converter::rvalue_from_python_stage1_data* data) \ + { \ + void* d = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; \ + \ + if(po == Py_None) { new(d) Gate4(); } \ + else if(PyFunction_Check(po)) { new(d) Gate4(new Gate4Action_##P1##_##P2##_##P3##_##P4##_Py(po)); } \ + else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Gate4(new Gate4Action_##P1##_##P2##_##P3##_##P4##_Py(po)); } \ + else { throw_error_already_set(); } \ + \ + data->convertible = d; \ + } \ +}; \ + \ +void export_Gate4_##P1##_##P2##_##P3##_##P4() \ +{ \ +ONCELOCK \ +{ \ + Gate4_##P1##_##P2##_##P3##_##P4##_from_python(); \ + class_ >("Gate4_"#P1"_"#P2"_"#P3"_"#P4, "Upp Gate4<"#P1","#P2","#P3","#P4">") \ + .def(init&>()) \ + .def("clear", &Gate4::Clear) \ + .def("valid", &Gate4::operator bool) \ + .def("__call__", &Gate4::Execute) \ + ; \ +} \ +} \ + + +#define decl_export_Gate4(P1, P2, P3, P4) \ +void export_Gate4_##P1##_##P2##_##P3##_##P4() \ + + +#define export_Gate4(P1, P2, P3, P4) \ +export_Gate4_##P1##_##P2##_##P3##_##P4() \ + + +// void export_Callback(); +void export_Gate(); END_UPP_NAMESPACE diff --git a/bazaar/CoreBoostPy/CoreBoostPy.cpp b/bazaar/CoreBoostPy/CoreBoostPy.cpp index 89aae0993..0792c5863 100644 --- a/bazaar/CoreBoostPy/CoreBoostPy.cpp +++ b/bazaar/CoreBoostPy/CoreBoostPy.cpp @@ -7,6 +7,8 @@ void export_Core() ONCELOCK { export_Callback(); + export_Gate(); + export_GTypes(); export_String(); export_Value(); diff --git a/bazaar/PointCtrl/PointCtrl.cpp b/bazaar/PointCtrl/PointCtrl.cpp index 479fff5f7..343b4a6bd 100644 --- a/bazaar/PointCtrl/PointCtrl.cpp +++ b/bazaar/PointCtrl/PointCtrl.cpp @@ -40,7 +40,7 @@ void PointCtrl::Paint(Draw& w) } //cross - if(!xp.IsNullInstance()) + if(!xp.IsNullInstance() && IsEnabled() && IsEditable()) { w.DrawLine(xp.x-3,xp.y, xp.x+3+1,xp.y, style->linesize, style->linecol); w.DrawLine(xp.x,xp.y-3, xp.x,xp.y+3+1, style->linesize, style->linecol); @@ -65,8 +65,9 @@ void PointCtrl::Paint(Draw& w) void PointCtrl::LeftDown(Point p, dword keyflags) { - SetCapture(); moving = false; + if(IsReadOnly() || !IsEnabled()) return; + SetCapture(); pressed = (keyflags & K_MOUSELEFT); xp = p; @@ -87,6 +88,7 @@ void PointCtrl::LeftDown(Point p, dword keyflags) void PointCtrl::LeftRepeat(Point p, dword keyflags) { if(moving) return; + if(IsReadOnly() || !IsEnabled()) return; if(di<0 && !(keyflags & K_CTRL)) { @@ -108,6 +110,7 @@ void PointCtrl::LeftRepeat(Point p, dword keyflags) void PointCtrl::MouseMove(Point p, dword keyflags) { + if(IsReadOnly() || !IsEnabled()) return; moving = true; pressed = (keyflags & K_MOUSELEFT); @@ -131,9 +134,10 @@ void PointCtrl::MouseMove(Point p, dword keyflags) void PointCtrl::LeftUp(Point p, dword keyflags) { - ReleaseCapture(); pressed = false; moving = false; + if(IsReadOnly() || !IsEnabled()) return; + ReleaseCapture(); di = -1; xp.SetNull(); Refresh(); diff --git a/bazaar/Py/Py.cpp b/bazaar/Py/Py.cpp index 6a595e8cd..95c08990b 100644 --- a/bazaar/Py/Py.cpp +++ b/bazaar/Py/Py.cpp @@ -1,5 +1,7 @@ #include "Py.h" +#ifdef flagBOOSTPY using namespace boost::python; +#endif NAMESPACE_UPP diff --git a/bazaar/PyConsoleCtrl/PyConsoleCtrl.cpp b/bazaar/PyConsoleCtrl/PyConsoleCtrl.cpp index c8f5407d7..58b3ea262 100644 --- a/bazaar/PyConsoleCtrl/PyConsoleCtrl.cpp +++ b/bazaar/PyConsoleCtrl/PyConsoleCtrl.cpp @@ -4,18 +4,14 @@ void PyConsoleCtrl::LoadDlg() { fs.Types("Python Files\t*.py\nAll Files\t*.*\n"); if(!fs.ExecuteOpen("Load a Python script")) return; - - FileIn in(fs.Get()); - cmd.Load(in); + Load(fs.Get()); } void PyConsoleCtrl::SaveDlg() { fs.Types("Python Files\t*.py\nAll Files\t*.*\n"); if(!fs.ExecuteSaveAs("Save a Python script")) return; - - FileOut out(fs.Get()); - cmd.Save(out); + Save(fs.Get()); } void PyConsoleCtrl::Clear() diff --git a/bazaar/PyConsoleCtrl/PyConsoleCtrl.h b/bazaar/PyConsoleCtrl/PyConsoleCtrl.h index 7261068c6..be76ca5a8 100644 --- a/bazaar/PyConsoleCtrl/PyConsoleCtrl.h +++ b/bazaar/PyConsoleCtrl/PyConsoleCtrl.h @@ -42,6 +42,9 @@ public: void Inc(); void Dec(); + void Load(const String& filename) { FileIn in(filename); cmd.Load(in); } + void Save(const String& filename) const { FileOut out(filename); cmd.Save(out); } + void ClearLog() { log.Clear(); } void SaveLog() { log.Save(); }