Skip to content
Draft
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
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ option(
# ============

find_package(xeus-zmq REQUIRED)
find_package(xwidgets REQUIRED)
find_package(xproperty REQUIRED)
find_package(PNG REQUIRED)
find_package(glad REQUIRED)
find_package(glfw3)
Expand Down Expand Up @@ -112,6 +114,7 @@ set(
include/xeus-octave/plotstream.hpp
include/xeus-octave/tex2html.hpp
include/xeus-octave/display.hpp
include/xeus-octave/xwidgets.hpp
)

set(
Expand All @@ -122,6 +125,7 @@ set(
src/xinterpreter.cpp
src/input.cpp
src/output.cpp
src/xwidgets.cpp
)

set(XEUS_OCTAVE_MAIN_SRC src/main.cpp)
Expand Down Expand Up @@ -226,7 +230,7 @@ macro(xeus_octave_create_target target_name linkage output_name)

target_link_libraries(
${target_name}
PUBLIC xtl PkgConfig::octinterp
PUBLIC xtl xwidgets PkgConfig::octinterp
PRIVATE glad::glad glfw PNG::PNG
)
if(XEUS_OCTAVE_USE_SHARED_XEUS)
Expand Down
3 changes: 3 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ channels:
dependencies:
# Build dependencies
- cxx-compiler
- fortran-compiler
- c-compiler
- cmake
- make
Expand All @@ -11,6 +12,7 @@ dependencies:
- libuuid
- xtl
- xeus-zmq =1.*
- xwidgets =0.27.3
- nlohmann_json
- cppzmq
- octave =7.*
Expand All @@ -37,4 +39,5 @@ dependencies:
- cmake-format
- plotly
- ipywidgets
- widgetsnbextension =3.6.1
- jupyter-dash
38 changes: 38 additions & 0 deletions include/xeus-octave/plotstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,27 @@

#include <octave/graphics.h>

#include <xwidgets/ximage.hpp>

namespace xeus_octave
{

template <class T> inline T getPlotStream(octave::graphics_object const& o);

/**
* Retrieve from the graphics object the plot_stream property
*/
template <> inline xw::image* getPlotStream<xw::image*>(octave::graphics_object const& o)
{
octave_value ps =
dynamic_cast<octave::figure::properties const&>(o.get_ancestor("figure").get_properties()).get___plot_stream__();

if (ps.isnumeric() && ps.is_scalar_type())
return reinterpret_cast<xw::image*>(ps.long_value());
else
return nullptr;
}

/**
* Retrieve from the graphics object the plot_stream property
*/
Expand All @@ -41,6 +57,18 @@ template <> inline std::string getPlotStream<std::string>(octave::graphics_objec
return "";
}

/**
* Set in the graphics object the plot_stream propert
*/
inline void setPlotStream(octave::graphics_object& o, xw::image* p)
{
if (o.isa("figure"))
{
auto& fp = dynamic_cast<octave::figure::properties&>(o.get_properties());
fp.set___plot_stream__(reinterpret_cast<intptr_t>(p));
}
}

/**
* Set in the graphics object the plot_stream propert
*/
Expand All @@ -53,6 +81,16 @@ inline void setPlotStream(octave::graphics_object& o, std::string p)
}
}

/**
* Set in the graphics object the plot_stream propert (const version)
*/
inline void setPlotStream(octave::graphics_object const& o, xw::image* p)
{
// deCONSTify the graphics_object
auto _go = o;
setPlotStream(_go, p);
}

/**
* Set in the graphics object the plot_stream propert (const version)
*/
Expand Down
41 changes: 41 additions & 0 deletions include/xeus-octave/tk_notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,47 @@ class notebook_graphics_toolkit : public glfw_graphics_toolkit
void show_figure(octave::graphics_object const&) const override;
};

/**
* Stupidly simple toolkit. On each redraw request just sends a display_data
* call to the frontend. Suitable for cases where update_display_data calls are
* not supported (e.g. using xoutput widget)
*
* Should not be used by users
*/
class interact_graphics_toolkit : public glfw_graphics_toolkit
{
public:

interact_graphics_toolkit() : glfw_graphics_toolkit("__interact") {}

bool is_valid() const override { return true; }

void send_figure(octave::graphics_object const&, std::vector<char> const&, int, int, double) const override;
};

/**
* Toolkit that uses a ximage as output region, updating its contents on each
* redraw. When a figure is added to a widget container (e.g. xvbox or xhbox)
* its toolkit is automatically converted to this one.
* Does not display anything on its own, it MUST be included in a container
* widget.
*
* Should not be used by users
*/
class widget_graphics_toolkit : public glfw_graphics_toolkit
{
public:

widget_graphics_toolkit() : glfw_graphics_toolkit("__widget") {}

bool is_valid() const override { return true; }

bool initialize(octave::graphics_object const&) override;
void send_figure(octave::graphics_object const&, std::vector<char> const&, int, int, double) const override;
void show_figure(octave::graphics_object const&) const override;
void finalize(octave::graphics_object const&) override;
};

void register_all(octave::interpreter& interpreter);

} // namespace xeus_octave::tk::notebook
Expand Down
Loading