Commit ccaf8486 authored by Pierre Pontier's avatar Pierre Pontier
Browse files

Amélioration du wxCast pour les objet statique wxColour, wxSize, … Dorénavent...

Amélioration du wxCast pour les objet statique wxColour, wxSize, … Dorénavent wxColourVar::Get() en python renvoie bien une wx.Colour qui désalloue «correctement» l'instance correspondante de wxColour en c++. (en dérivant wxColour j'ai bien vue le destructeur être appelé, mais je ne sais pas si à tous les coups ça fonctionne)
parent 89abb5eb
......@@ -35,8 +35,10 @@ La version du projet en est encore au stade d'alpha.
### Second cycle:
- [ ] Mettre en place les tests unitaires python pour le projet API_Py
- [ ] Faire une belle interface
- [ ] Multi-thread
- [ ] Simplifier l'api python ex: root.m_Current.SetItem(item) deviendrait root.m_Current = item
- [ ] …
## Prérequis
......@@ -65,24 +67,29 @@ Vous trouverez la liste des dépendances en fonction de votre système
`atk-1.0`
##### Mageia:
- `su`
- ```
urpmi python3-pip lib64openssl-devel lib64freeglut-devel lib64freeglut3 lib64mesaegl1-devel lib64gstreamer1.0-devel lib64gtk+3_0 lib64gtk+3.0-devel lib64jpeg-devel lib64notify-devel lib64png-devel lib64sdl2.0-devel lib64sm-devel lib64tiff-devel lib64webkit2gtk4.0_37 lib64xtst-devel
```
<!-- - `urpmi sslh` -->
<!-- - `systemctl restart sslh.service` -->
<!-- - `urpmi sslh` -->
<!-- - `systemctl restart sslh.service` -->
- `exit`
- `pip3 install --user wget`
##### Ubuntu:
- `sudo apt install uuid-dev`
- `sudo pip3 install wget`
- `sudo apt install libssl-dev`
- WxPython dependencies
```
```
dpkg-dev
build-essential
python3.7-dev and libpython3.7-dev # use appropriate Python version here
......@@ -99,8 +106,7 @@ Vous trouverez la liste des dépendances en fonction de votre système
libtiff-dev
libwebkit2gtk-4.0-dev
libxtst-dev
```
```
## Installation
......@@ -113,11 +119,15 @@ Dans le répertoire Ma/dependencies/ exécutez :
Lors de la première phase, celle qui consiste à créer l'environnement python3, je recommande de choisir l'option :
- Compiler les sources de python3.x (x >= 7).
- Compiler wxPython depuis le dépôt github.
- Compiler wxPython depuis le dépôt github.
Une fois les dépendances installées:
- Editer/corriger le fichier `M`a/dependencies/dependencies.cfg`.
- Copier la librairie dynamique libpython3.xx.so.x.x dans le dossier `Ma/code/GUI`.
- Vous pouvez ouvrir le projet Codeblocks: `Ma/code/Maçon de l'espace` et le compiler.
## Quelques liens
......@@ -143,11 +153,13 @@ Dans le répertoire Ma/dependencies/ exécutez :
Essayer d'installer libssl ou openssll, sinon installer un environnement virtuel au lieu de recompiler python.
### Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(161, '[SSL: LIBRARY_HAS_NO_CIPHERS] library has no ciphers (_ssl.c:3014)'))': /simple/numpy/
Le système ne possède peut-être pas le service ssl d'activé. Vous pouvez essayer d'installer la librairie manquante et
le recompiler python ou de réienstaller l'environnement python mais cette fois ci au lieu de compiler python générer
un environnement virtuel de python.
### [Errno 2] No such file or directory: 'sip/cpp/_core.sbf'
Lors de la compilation le processus doit placer des fichiers dans le dossier sip. Si les sous dossiers de sip ne
contiennent que des fichiers «lisez-moi» alors sip n'a pas été généré. Peut être cela vient de la compilation de python,
où il aurait fallu le compiler avec l'option --enable-shared, si vous avez compiler python à l'aide du scipt
......@@ -156,5 +168,3 @@ install_py_env.py l'option est activée. Le problème n'est donc pas lié à cet
### Plus d'informations:
[Mastodon](https://mamot.fr/@Suryavarman)
......@@ -713,7 +713,7 @@ vers le dossier:
<AutoVersioning>
<Scheme minor_max="20" build_max="0" rev_max="0" rev_rand_max="10" build_times_to_increment_minor="100" />
<Settings autoincrement="1" date_declarations="1" use_define="1" update_manifest="1" do_auto_increment="0" ask_to_increment="0" language="C++" svn="0" svn_directory="" header_path="include/API/Version.h" />
<Changes_Log show_changes_editor="1" app_title="released version %M.%m.%b of %p" changeslog_path="ChangesLog.txt" />
<Changes_Log show_changes_editor="0" app_title="released version %M.%m.%b of %p" changeslog_path="ChangesLog.txt" />
<Code header_guard="VERSION_H" namespace="API" prefix="MA" />
</AutoVersioning>
<DoxyBlocks>
......
......@@ -72,6 +72,7 @@ namespace API
explicit wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha = wxALPHA_OPAQUE);
explicit wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, int red, int green, int blue, int alpha = wxALPHA_OPAQUE);
explicit wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, unsigned int red, unsigned int green, unsigned int blue, float alpha);
explicit wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, int red, int green, int blue, float alpha);
explicit wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, unsigned long colRGB);
explicit wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, const wxString& color_name);
explicit wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, const std::string& color_name);
......@@ -99,7 +100,10 @@ namespace API
virtual bool IsValidString(const std::string& value) const override;
virtual void Set(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = wxALPHA_OPAQUE);
virtual void Set(unsigned char red, unsigned char green, unsigned char blue, float alpha = 1.f);
virtual void Set(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha = wxALPHA_OPAQUE);
virtual void Set(int red, int green, int blue, int alpha = wxALPHA_OPAQUE);
virtual void Set(unsigned int red, unsigned int green, unsigned int blue, float alpha);
virtual void Set(int red, int green, int blue, float alpha);
virtual void Set(unsigned long colRGB);
virtual void Set(const wxString &color_name);
virtual void Set(const std::string &color_name);
......
......@@ -16,17 +16,17 @@ namespace API{
//Standard Version Type
#define MA_MAJOR 0
#define MA_MINOR 3
#define MA_BUILD 16
#define MA_REVISION 106
#define MA_BUILD 24
#define MA_REVISION 150
//Miscellaneous Version Types
#define MA_BUILDS_COUNT 42
#define MA_RC_FILEVERSION 0,3,16,106
#define MA_RC_FILEVERSION_STRING "0, 3, 16, 106\0"
#define MA_FULLVERSION_STRING "0.3.16.106"
#define MA_BUILDS_COUNT 73
#define MA_RC_FILEVERSION 0,3,24,150
#define MA_RC_FILEVERSION_STRING "0, 3, 24, 150\0"
#define MA_FULLVERSION_STRING "0.3.24.150"
//These values are to keep track of your versioning state, don't modify them.
#define MA_BUILD_HISTORY 16
#define MA_BUILD_HISTORY 24
}
......
......@@ -33,6 +33,10 @@ API::wxColourVar::wxColourVar(const API::Var::key_type& key, bool dynamic, bool
API::wxColourVar::VarColourBase(key, dynamic, read_only, wxColour(red, green, blue, alpha * 255))
{}
API::wxColourVar::wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, int red, int green, int blue, float alpha):
API::wxColourVar::VarColourBase(key, dynamic, read_only, wxColour(red, green, blue, alpha * 255))
{}
API::wxColourVar::wxColourVar(const API::Var::key_type& key, bool dynamic, bool read_only, unsigned long colRGB):
API::wxColourVar::VarColourBase(key, dynamic, read_only, wxColour(colRGB))
{}
......@@ -93,7 +97,22 @@ void API::wxColourVar::Set(unsigned char red, unsigned char green, unsigned char
Set(wxColour(red, green, blue, alpha));
}
void API::wxColourVar::Set(unsigned char red, unsigned char green, unsigned char blue, float alpha)
void API::wxColourVar::Set(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha)
{
Set(wxColour(red, green, blue, alpha));
}
void API::wxColourVar::Set(int red, int green, int blue, int alpha)
{
Set(wxColour(red, green, blue, alpha));
}
void API::wxColourVar::Set(unsigned int red, unsigned int green, unsigned int blue, float alpha)
{
Set(wxColour(red, green, blue, alpha * 255));
}
void API::wxColourVar::Set(int red, int green, int blue, float alpha)
{
Set(wxColour(red, green, blue, alpha * 255));
}
......
......@@ -42,7 +42,7 @@ Test(Colour, colour_constructor_colour_value, .init = colour_setup, .fini = colo
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_constructor_RGB_value, .init = colour_setup, .fini = colour_teardown)
Test(Colour, colour_constructor_RGBi_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
......@@ -78,6 +78,16 @@ Test(Colour, colour_constructor_RGBAf_value, .init = colour_setup, .fini = colou
API::wxColourVarPtr var_colour;
wxColour colour(0, 255, 0, 128);
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour", 0, 255, 0, 128.f/255.f));
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_constructor_RGBAuf_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
wxColour colour(0u, 255u, 0u, 128u);
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour", 0u, 255u, 0u, 128.f/255.f));
cr_assert_eq(var_colour->Get(), colour);
}
......@@ -109,3 +119,115 @@ Test(Colour, colour_constructor_std_string_value, .init = colour_setup, .fini =
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour", std::string("RED")));
cr_assert_eq(var_colour->Get(), *wxRED);
}
Test(Colour, colour_set_colour_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxColour colour(0, 255, 0, 128);
cr_assert_none_throw(var_colour->Set(colour))
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_set_RGBi_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxColour colour(255, 0, 128);
cr_assert_none_throw(var_colour->Set(255, 0, 128));
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_set_RGBu_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxColour colour(0u, 255u, 0u);
cr_assert_none_throw(var_colour->Set(0u, 255u, 0u));
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_set_RGBAu_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxColour colour(0u, 255u, 0u, 128u);
cr_assert_none_throw(var_colour->Set(0u, 255u, 0u, 128u));
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_set_RGBAf_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxColour colour(0, 255, 0, 128);
cr_assert_none_throw(var_colour->Set(0, 255, 0, 128.f/255.f));
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_set_RGBAuf_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxColour colour(0u, 255u, 0u, 128);
cr_assert_none_throw(var_colour->Set(0u, 255u, 0u, 128.f/255.f));
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_set_int32_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxColour colour(0, 255, 0, 128);
cr_assert_none_throw(var_colour->Set(colour.GetRGBA()));
cr_assert_eq(var_colour->Get(), wxColour(colour.GetRGBA()));
}
Test(Colour, colour_set_wxString_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
wxString red_str = "RED";
wxColour colour(red_str);
cr_assert_none_throw(var_colour->Set(red_str));
cr_assert_eq(var_colour->Get(), colour);
}
Test(Colour, colour_set_std_string_value, .init = colour_setup, .fini = colour_teardown)
{
auto item = API::Item::CreateItem<API::Item>();
API::wxColourVarPtr var_colour;
cr_assert_none_throw(var_colour = item->AddVar<API::wxColourVar>("m_Colour"));
std::string red_str = "RED";
wxColour colour(red_str);
cr_assert_none_throw(var_colour->Set(red_str));
cr_assert_eq(var_colour->Get(), colour);
}
......@@ -37,6 +37,8 @@
// https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html#accessing-python-libraries-from-c
// https://www.openflipper.org/media/Documentation/latest/a02744_source.html
// PYBIND11_TYPE_CASTER(M_IN_TYPE, _(M_IN_STR_PY_TYPE_NAME));
// _wxPyAPI : https://github.com/wxWidgets/Phoenix/blob/master/wx/include/wxPython/wxpy_api.h
// https://docs.python.org/3.9/c-api/index.html
# define M_WX_PY_CASTER(M_IN_TYPE, M_IN_STR_PY_TYPE_NAME) \
namespace pybind11 { namespace detail { \
......@@ -93,6 +95,20 @@ namespace pybind11 { namespace detail { \
}} // namespace pybind11::detail
# define M_WX_PY_CASTER_NO_CLASSINFO(M_IN_TYPE, M_IN_STR_PY_TYPE_NAME) \
class M_IN_TYPE##Test : public M_IN_TYPE \
{ \
public: \
using M_IN_TYPE::M_IN_TYPE; \
M_IN_TYPE##Test(const M_IN_TYPE & value): \
M_IN_TYPE(value) \
{} \
\
virtual ~M_IN_TYPE##Test() \
{ \
std::cout << "Destructeur de" << #M_IN_TYPE << "Test appelé" << std::endl; \
} \
}; \
\
namespace pybind11 { namespace detail { \
\
template <> struct type_caster<M_IN_TYPE> \
......@@ -148,6 +164,8 @@ namespace pybind11 { namespace detail { \
*/ \
static handle cast(const M_IN_TYPE& src, return_value_policy /* policy */, handle /* parent */) \
{ \
/* auto* ptr_src = new M_IN_TYPE##Test(src); */ \
/* return API_Py::wxCast(ptr_src, wxString::FromUTF8(#M_IN_TYPE)); */ \
return API_Py::wxCast(&src, wxString::FromUTF8(#M_IN_TYPE)); \
} \
}; \
......@@ -174,6 +192,8 @@ namespace API_Py
template <typename T>
pybind11::handle wxCast(const T* src);
pybind11::handle wxCast(const wxColour* src);
/// \brief Permet de construire l'objet de wxPython qui enrobera l'objet de
/// wxWidget. Cette fonction est à utiliser pour définir les modules
/// que vous souhaitez exportez vers python avec pybind11.
......@@ -187,7 +207,7 @@ namespace API_Py
/// \return L'objet qui décrit l'enrobage de la source en python.
/// \remarks src
/// \see [La documentation de pybind11 qui traite de cette fonctionnalité.](https://pybind11.readthedocs.io/en/stable/advanced/cast/custom.html)
///
/// \see L'implémentation de PyObject* i_wxVariant_out_helper(const wxVariant& value)
template <typename T>
pybind11::handle wxCast(const T* src, const wxString &inTypeName);
......@@ -263,6 +283,10 @@ M_WX_PY_CASTER_NO_CLASSINFO(wxSize, "wx.Size")
M_WX_PY_CASTER_NO_CLASSINFO(wxPoint, "wx.Point")
M_WX_PY_CASTER_NO_CLASSINFO(wxBoxSizer, "wx.BoxSizer")
M_WX_PY_CASTER_NO_CLASSINFO(wxColour, "wx.Colour")
M_WX_PY_CASTER_NO_CLASSINFO(wxDateTime, "wx.DateTime")
M_WX_PY_CASTER_NO_CLASSINFO(wxBitmap, "wx.Bitmap")
M_WX_PY_CASTER_NO_CLASSINFO(wxImage, "wx.Image")
M_WX_PY_CASTER_NO_CLASSINFO(wxIcon, "wx.Icon")
M_WX_PY_CASTER(wxWindow, "wx.Window")
M_WX_PY_CASTER(wxValidator, "wx.Validator")
......
......@@ -8,6 +8,7 @@
template <typename T>
pybind11::handle API_Py::wxCast(const T* src)
{
//py::print("pybind11::handle API_Py::wxCast(const T* src)");
wxASSERT(src);
// As always, first grab the GIL
......@@ -26,12 +27,16 @@ pybind11::handle API_Py::wxCast(const T* src)
template <typename T>
pybind11::handle API_Py::wxCast(const T* src, const wxString &inTypeName)
{
//py::print("pybind11::handle API_Py::wxCast(const T* src, const wxString &inTypeName)");
wxASSERT(src);
// As always, first grab the GIL
wxPyBlock_t blocked = API_Py::wxPyBeginBlockThreads();
PyObject* obj = wxPyConstructObject(const_cast<T*>(src), inTypeName, false);
// La nouvelle instance sera gérée par python. C'est pour ça que le
// paramètre setThisOwn est à vrais.
PyObject* obj = wxPyConstructObject(new T(*src), inTypeName, true);
// Finally, after all Python stuff is done, release the GIL
API_Py::wxPyEndBlockThreads(blocked);
......@@ -42,6 +47,7 @@ pybind11::handle API_Py::wxCast(const T* src, const wxString &inTypeName)
template <typename T>
T* API_Py::wxLoad(pybind11::handle src, const wxString& inTypeName)
{
py::print("T* API_Py::wxLoad(pybind11::handle src, const wxString& inTypeName)");
wxASSERT(src);
// As always, first grab the GIL
......
......@@ -24,9 +24,8 @@ wxString API_Py::wxLoad(pybind11::handle src)
return obj;
}
static const wxValidator g_DefaultValidatior;
const wxValidator& API_Py::GetDefaultValidator()
{
return g_DefaultValidatior;
static const wxValidator default_validatior;
return default_validatior;
}
......@@ -18,6 +18,8 @@
using namespace pybind11::literals;
void API_Py::wxPyColour::SetModule(py::module &inModule, py::module &in_wx_module, API_Py::Item::value_type& inClassItem)
{
auto py_wx_module = py::module::import("wx");
......@@ -53,30 +55,29 @@ void API_Py::wxPyColour::SetModule(py::module &inModule, py::module &in_wx_modul
.def("IsValidString", &API::wxColourVar::IsValidString)
.def("Reset", &API::wxColourVar::Reset)
.def("Set",
[](const API::wxColourVarPtr &self, unsigned char red, unsigned char green, unsigned char blue, float alpha)
[](API::wxColourVarPtr self, unsigned int red, unsigned int green, unsigned int blue, float alpha)
{
self->Set(red, green, blue, alpha);
}, py::arg("red"), py::arg("green"), py::arg("blue"), py::arg("alpha") = 1.f)
.def("Set",
[](const API::wxColourVarPtr &self, unsigned long colRGB)
[](API::wxColourVarPtr self, unsigned long colRGB)
{
self->Set(colRGB);
}, py::arg("colRGB"))
.def("Set",
[](const API::wxColourVarPtr &self, const std::string &color_name)
[](API::wxColourVarPtr self, const std::string &color_name)
{
self->Set(color_name);
}, py::arg("color_name"))
.def("Set",
[](const API::wxColourVarPtr &self, const wxColour& colour)
[](API::wxColourVarPtr self, const wxColour& colour)
{
self->Set(colour);
}, py::arg("colour"))
.def("Get",
[](const API::wxColourVarPtr &self)
[](API::wxColourVarPtr self)
{
auto colour = self->Get();
return colour;
return self->Get();
})
.def("GetTypeInfo", &API::wxColourVar::GetTypeInfo)
.def("__repr__",
......
import wx
import ma
item = ma.Item.fs_CreateItem()
var = item.AddwxColour("m_Colour", wx.RED)
var.Get()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment