Introduce a flag to create a window without showing it - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年11月09日 14:11:57 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年11月09日 14:11:57 +0100
commit018813c6e5f2b1d7e1809cde0ebae790d57aa3fd (patch)
tree09f2712a8572eeb9de45dc63df5c45d43baa6007
parent096abfe85cc5b961e943fa5970aac4f0dbbda5ab (diff)
downloadgsl-shell-018813c6e5f2b1d7e1809cde0ebae790d57aa3fd.tar.gz
Introduce a flag to create a window without showing it
Diffstat
-rw-r--r--agg-plot/lua-plot.cpp 23
-rw-r--r--agg-plot/window.cpp 31
-rw-r--r--agg-plot/window.h 1
-rw-r--r--agg-plot/window_hooks.h 1
-rw-r--r--doc/user-manual/graphics.rst 10
-rw-r--r--fox-gui/fx_plot_window.cpp 2
-rw-r--r--fox-gui/fx_plot_window.h 17
-rw-r--r--fox-gui/gsl-shell-fox.cpp 2
-rw-r--r--fox-gui/lua_plot_window.cpp 52
-rw-r--r--fox-gui/lua_plot_window.h 3
-rw-r--r--gsl-shell-jit.c 3
-rw-r--r--help/graphics.lua 5
12 files changed, 104 insertions, 46 deletions
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
index 1999f7cc..42961d46 100644
--- a/agg-plot/lua-plot.cpp
+++ b/agg-plot/lua-plot.cpp
@@ -494,11 +494,24 @@ plot_flush (lua_State *L)
int
plot_show (lua_State *L)
{
- lua_pushcfunction (L, app_window_hooks->attach);
- (*app_window_hooks->create)(L);
- lua_pushvalue (L, 1);
- lua_pushstring (L, "");
- lua_call (L, 3, 0);
+ /* create a window without shouwing it */
+ lua_pushcfunction(L, app_window_hooks->create);
+ lua_pushstring(L, ".");
+ lua_pushboolean(L, 1);
+ lua_call(L, 2, 1);
+
+ /* attach the plot to the window */
+ lua_pushcfunction(L, app_window_hooks->attach);
+ lua_pushvalue(L, 2);
+ lua_pushvalue(L, 1);
+ lua_pushstring(L, "");
+ lua_call(L, 3, 0);
+
+ /* show the window */
+ lua_pushcfunction(L, app_window_hooks->show);
+ lua_pushvalue(L, 2);
+ lua_call(L, 1, 0);
+
return 0;
}
diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp
index 3868de85..3114f430 100644
--- a/agg-plot/window.cpp
+++ b/agg-plot/window.cpp
@@ -19,7 +19,6 @@ extern "C" {
__BEGIN_DECLS
-static int window_show (lua_State *L);
static int window_free (lua_State *L);
static int window_split (lua_State *L);
static int window_save_svg (lua_State *L);
@@ -406,17 +405,22 @@ void window::start (lua_State *L, gslshell::ret_status& st)
}
}
-int
-window_new (lua_State *L)
+static void
+show_window(lua_State* L, window* win)
{
- window *win = push_new_object<window>(L, GS_WINDOW, global_state);
- const char *spec = lua_tostring (L, 1);
-
gslshell::ret_status st;
win->start(L, st);
if (st.error_msg())
- return luaL_error (L, "%s (reported during %s)", st.error_msg(), st.context());
+ luaL_error (L, "%s (reported during %s)", st.error_msg(), st.context());
+}
+
+int
+window_new (lua_State *L)
+{
+ window *win = push_new_object<window>(L, GS_WINDOW, global_state);
+ const char *spec = lua_tostring (L, 1);
+ int defer_show = lua_toboolean(L, 2);
if (spec)
{
@@ -424,6 +428,11 @@ window_new (lua_State *L)
return luaL_error(L, "invalid layout specification");
}
+ if (!defer_show)
+ {
+ show_window(L, win);
+ }
+
return 1;
}
@@ -431,13 +440,7 @@ int
window_show (lua_State *L)
{
window *win = object_check<window>(L, 1, GS_WINDOW);
-
- gslshell::ret_status st;
- win->start(L, st);
-
- if (st.error_msg())
- return luaL_error (L, "%s (reported during %s)", st.error_msg(), st.context());
-
+ show_window(L, win);
return 0;
}
diff --git a/agg-plot/window.h b/agg-plot/window.h
index c93d407f..63c26d3e 100644
--- a/agg-plot/window.h
+++ b/agg-plot/window.h
@@ -15,6 +15,7 @@ extern int window_save_slot_image (lua_State *L);
extern int window_restore_slot_image (lua_State *L);
extern int window_update (lua_State *L);
extern int window_new (lua_State *L);
+extern int window_show (lua_State *L);
extern int window_attach (lua_State *L);
extern int window_close (lua_State *L);
extern int window_close_wait (lua_State *L);
diff --git a/agg-plot/window_hooks.h b/agg-plot/window_hooks.h
index 58c6ce33..180c4dcb 100644
--- a/agg-plot/window_hooks.h
+++ b/agg-plot/window_hooks.h
@@ -9,6 +9,7 @@ __BEGIN_DECLS
struct window_hooks {
int (*create)(lua_State* L);
+ int (*show)(lua_State* L);
int (*attach)(lua_State* L);
int (*update)(lua_State* L);
int (*refresh)(lua_State* L);
diff --git a/doc/user-manual/graphics.rst b/doc/user-manual/graphics.rst
index 1a388d0e..fa85d417 100644
--- a/doc/user-manual/graphics.rst
+++ b/doc/user-manual/graphics.rst
@@ -319,12 +319,12 @@ Window class
.. class:: Window
- .. function:: window([layout])
+ .. function:: window([layout, defer_show])
- Create a new empty window with the layout given by the optional
- :ref:`layout string <layout-string>`. If the argument is omitted
- the window will have a single drawing area that will cover the whole
- window.
+ Create a new empty window with the layout given by the optional :ref:`layout string <layout-string>`.
+ If the argument is omitted the window will have a single drawing area that will cover the whole window.
+ If the second argument evaluates to "true" the window will not be shown on the screen.
+ The window can be shown afterward using the method :meth:`~Window.show`.
.. method:: layout(spec)
diff --git a/fox-gui/fx_plot_window.cpp b/fox-gui/fx_plot_window.cpp
index 50f7f820..669067cb 100644
--- a/fox-gui/fx_plot_window.cpp
+++ b/fox-gui/fx_plot_window.cpp
@@ -34,5 +34,5 @@ fx_plot_window::~fx_plot_window()
delete m_plot_menu;
if (m_lua_window)
- lua_window_set_closed(m_lua_window);
+ set_lua_status(closed);
}
diff --git a/fox-gui/fx_plot_window.h b/fox-gui/fx_plot_window.h
index 87465a12..1ed018db 100644
--- a/fox-gui/fx_plot_window.h
+++ b/fox-gui/fx_plot_window.h
@@ -8,7 +8,20 @@
#include "window_surface.h"
-struct lua_fox_window;
+class fx_plot_window;
+
+__BEGIN_DECLS
+
+enum window_status_e { not_ready, running, closed };
+
+struct lua_fox_window
+{
+ fx_plot_window* window;
+ gsl_shell_app* app;
+ enum window_status_e status;
+};
+
+__END_DECLS
class fox_display_window : public display_window {
public:
@@ -42,6 +55,8 @@ public:
void set_lua_window(lua_fox_window* w) { m_lua_window = w; }
+ void set_lua_status(window_status_e s) { m_lua_window->status = s; }
+
int lua_id; // the following is used by Lua to keep trace of the window
protected:
diff --git a/fox-gui/gsl-shell-fox.cpp b/fox-gui/gsl-shell-fox.cpp
index c70abb32..0d50029a 100644
--- a/fox-gui/gsl-shell-fox.cpp
+++ b/fox-gui/gsl-shell-fox.cpp
@@ -5,7 +5,7 @@
#include "lua_plot_window.h"
struct window_hooks app_window_hooks[1] = {{
- fox_window_new, fox_window_attach,
+ fox_window_new, fox_window_show, fox_window_attach,
fox_window_slot_update, fox_window_slot_refresh,
fox_window_close,
fox_window_save_slot_image, fox_window_restore_slot_image,
diff --git a/fox-gui/lua_plot_window.cpp b/fox-gui/lua_plot_window.cpp
index 8024e3d8..257fcc43 100644
--- a/fox-gui/lua_plot_window.cpp
+++ b/fox-gui/lua_plot_window.cpp
@@ -28,6 +28,7 @@ static const struct luaL_Reg fox_window_functions[] =
static const struct luaL_Reg fox_window_methods[] =
{
+ {"show", fox_window_show },
{"layout", fox_window_layout },
{"attach", fox_window_attach },
{"close", fox_window_close },
@@ -37,15 +38,6 @@ static const struct luaL_Reg fox_window_methods[] =
{NULL, NULL}
};
-enum window_status_e { not_ready, running, closed };
-
-struct lua_fox_window
-{
- fx_plot_window* window;
- gsl_shell_app* app;
- enum window_status_e status;
-};
-
__END_DECLS
typedef plot<manage_owner> sg_plot;
@@ -67,6 +59,7 @@ public:
bool is_defined() { return (m_handle != NULL); }
bool is_running() { return (m_handle->status == running); }
+ int window_status() { return m_handle->status; }
gsl_shell_app* app() { return m_handle->app; }
fx_plot_window* window() { return m_handle->window; }
@@ -75,12 +68,23 @@ private:
lua_fox_window* m_handle;
};
+static void
+app_create_window(lua_State* L, gsl_shell_app* app, fx_plot_window* win)
+{
+ app->window_create_request(win);
+ win->lua_id = window_index_add (L, -1);
+ app->wait_action();
+
+ win->set_lua_status(running);
+}
+
int
fox_window_new (lua_State *L)
{
gsl_shell_app* app = global_app;
const char* split_str = lua_tostring(L, 1);
+ int defer_show = lua_toboolean(L, 2);
app->lock();
@@ -105,17 +109,34 @@ fox_window_new (lua_State *L)
win->setTarget(app);
- app->window_create_request(win);
- win->lua_id = window_index_add (L, -1);
- app->wait_action();
-
- bwin->status = running;
+ if (!defer_show)
+ app_create_window(L, app, win);
app->unlock();
return 1;
}
static int
+fox_window_show_try(lua_State* L)
+{
+ window_mutex wm(L, 1);
+ if (!wm.is_defined()) return type_error_return(L, 2, "window");
+ if (wm.window_status() != not_ready) return error_return(L, "window is already running or closed");
+ fx_plot_window* win = wm.window();
+ gsl_shell_app* app = win->get_app();
+ app_create_window(L, app, win);
+ return 0;
+}
+
+int
+fox_window_show(lua_State* L)
+{
+ int nret = fox_window_show_try(L);
+ if (nret < 0) return lua_error(L);
+ return nret;
+}
+
+static int
fox_window_layout_try(lua_State* L)
{
window_mutex wm(L, 1);
@@ -156,7 +177,6 @@ fox_window_attach_try(lua_State *L)
window_mutex wm(L, 1);
if (!wm.is_defined()) return type_error_return(L, 1, "window");
- if (!wm.is_running()) return error_return(L, "window is not running");
sg_plot* p = object_cast<sg_plot>(L, 2, GS_PLOT);
if (!p) return type_error_return(L, 2, "plot");
@@ -334,11 +354,13 @@ fox_window_export_svg(lua_State *L)
return nret;
}
+#if 0
void lua_window_set_closed(void* _win)
{
lua_fox_window *win = (lua_fox_window*) _win;
win->status = closed;
}
+#endif
void
fox_window_register (lua_State *L)
diff --git a/fox-gui/lua_plot_window.h b/fox-gui/lua_plot_window.h
index 7d2577cc..bab79b11 100644
--- a/fox-gui/lua_plot_window.h
+++ b/fox-gui/lua_plot_window.h
@@ -16,8 +16,7 @@ extern int fox_window_slot_refresh (lua_State *L);
extern int fox_window_slot_update (lua_State *L);
extern int fox_window_save_slot_image (lua_State *L);
extern int fox_window_restore_slot_image (lua_State *L);
-
-extern void lua_window_set_closed (void* lua_window);
+extern int fox_window_show (lua_State* L);
__END_DECLS
diff --git a/gsl-shell-jit.c b/gsl-shell-jit.c
index 6b131913..dbce3437 100644
--- a/gsl-shell-jit.c
+++ b/gsl-shell-jit.c
@@ -103,8 +103,9 @@ lua_State *globalL = NULL;
struct gsl_shell_state gsl_shell[1];
static const char *progname = LUA_PROGNAME;
+#warning the window show function should be implemented
struct window_hooks app_window_hooks[1] = {{
- window_new, window_attach,
+ window_new, window_show, window_attach,
window_slot_update, window_slot_refresh,
window_close_wait,
window_save_slot_image, window_restore_slot_image,
diff --git a/help/graphics.lua b/help/graphics.lua
index 7e1b9e52..afdd1985 100644
--- a/help/graphics.lua
+++ b/help/graphics.lua
@@ -101,7 +101,10 @@ graph.window([layout])
Create a new empty window with the layout given by the optional
layout string. If the argument is omitted, the window will have a
- single drawing area that will cover the whole window.
+ single drawing area that will cover the whole window. If the second
+ argument evaluates to "true" the window will not be shown on the
+ screen. The window can be shown afterward using the method
+ <window>:show().
]],
[Window.layout] = [[
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月20日 19:59:53 +0000

AltStyle によって変換されたページ (->オリジナル) /