moo_spin_main_loop
This commit is contained in:
parent
b9a4fd8d69
commit
5450ecc16e
@ -70,6 +70,7 @@ _arg_helpers['gint'] = SimpleArgHelper('int', 'int')
|
||||
_arg_helpers['guint'] = SimpleArgHelper('guint', 'int')
|
||||
_arg_helpers['gboolean'] = SimpleArgHelper('gboolean', 'bool')
|
||||
_arg_helpers['index'] = SimpleArgHelper('int', 'index')
|
||||
_arg_helpers['double'] = SimpleArgHelper('double', 'double')
|
||||
_arg_helpers['const-char*'] = SimpleArgHelper('const char*', 'string')
|
||||
_arg_helpers['char*'] = SimpleArgHelper('char*', 'string')
|
||||
_arg_helpers['strv'] = SimpleArgHelper('char**', 'strv')
|
||||
|
@ -249,6 +249,8 @@ source_files = \
|
||||
../moo/mooutils/mooutils-messages.h\
|
||||
../moo/mooutils/mooutils-misc.c\
|
||||
../moo/mooutils/mooutils-misc.h\
|
||||
../moo/mooutils/mooutils-script.c\
|
||||
../moo/mooutils/mooutils-script.h\
|
||||
../moo/mooutils/mooutils-tests.h\
|
||||
../moo/mooutils/mooutils-thread.c\
|
||||
../moo/mooutils/mooutils-thread.h\
|
||||
|
@ -27,10 +27,10 @@ local function test_active_window()
|
||||
tassert(w1 ~= w2, 'old window != new window')
|
||||
tassert(#editor.get_windows() == 2, 'two window')
|
||||
editor.set_active_window(w2)
|
||||
_moo_utils.spin_main_loop(0.1)
|
||||
medit.spin_main_loop(0.1)
|
||||
tassert(w2 == editor.get_active_window(), 'w2 == editor.get_active_window()')
|
||||
editor.set_active_window(w1)
|
||||
_moo_utils.spin_main_loop(0.1)
|
||||
medit.spin_main_loop(0.1)
|
||||
tassert(w1 == editor.get_active_window(), 'w1 == editor.get_active_window()')
|
||||
editor.close_window(w1)
|
||||
tassert(#editor.get_windows() == 1, 'two window')
|
||||
|
@ -73,39 +73,6 @@ lua_check_utf8string (lua_State *L,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
cfunc_sleep (lua_State *L)
|
||||
{
|
||||
double sec = luaL_checknumber (L, 1);
|
||||
g_usleep (G_USEC_PER_SEC * sec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
quit_main_loop (GMainLoop *main_loop)
|
||||
{
|
||||
g_main_loop_quit (main_loop);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
cfunc_spin_main_loop (lua_State *L)
|
||||
{
|
||||
double sec = luaL_checknumber (L, 1);
|
||||
g_return_val_if_fail (sec >= 0, 0);
|
||||
|
||||
GMainLoop *main_loop = g_main_loop_new (NULL, FALSE);
|
||||
_moo_timeout_add (sec * 1000, (GSourceFunc) quit_main_loop, main_loop);
|
||||
|
||||
gdk_threads_leave ();
|
||||
g_main_loop_run (main_loop);
|
||||
gdk_threads_enter ();
|
||||
|
||||
g_main_loop_unref (main_loop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum {
|
||||
my_F_OK = 0,
|
||||
my_R_OK = 1 << 0,
|
||||
@ -171,8 +138,6 @@ cfunc__execute (lua_State *L)
|
||||
}
|
||||
|
||||
static const luaL_Reg moo_utils_funcs[] = {
|
||||
{ "sleep", cfunc_sleep },
|
||||
{ "spin_main_loop", cfunc_spin_main_loop },
|
||||
{ "_access", cfunc__access },
|
||||
{ "_execute", cfunc__execute },
|
||||
{ NULL, NULL }
|
||||
|
@ -691,6 +691,27 @@ moo_lua_get_arg_int (lua_State *L,
|
||||
return moo_lua_get_arg_int_opt (L, narg, param_name, 0);
|
||||
}
|
||||
|
||||
double
|
||||
moo_lua_get_arg_double_opt (lua_State *L,
|
||||
int narg,
|
||||
G_GNUC_UNUSED const char *param_name,
|
||||
double default_value)
|
||||
{
|
||||
if (lua_isnoneornil (L, narg))
|
||||
return default_value;
|
||||
else
|
||||
return lua_tonumber (L, narg);
|
||||
}
|
||||
|
||||
double
|
||||
moo_lua_get_arg_double (lua_State *L,
|
||||
int narg,
|
||||
const char *param_name)
|
||||
{
|
||||
luaL_checkany (L, narg);
|
||||
return moo_lua_get_arg_double_opt (L, narg, param_name, 0);
|
||||
}
|
||||
|
||||
int
|
||||
moo_lua_get_arg_index_opt (lua_State *L,
|
||||
int narg,
|
||||
|
@ -71,6 +71,13 @@ int moo_lua_get_arg_int_opt (lua_State *L,
|
||||
int moo_lua_get_arg_int (lua_State *L,
|
||||
int narg,
|
||||
const char *param_name);
|
||||
double moo_lua_get_arg_double_opt (lua_State *L,
|
||||
int narg,
|
||||
const char *param_name,
|
||||
double default_value);
|
||||
double moo_lua_get_arg_double (lua_State *L,
|
||||
int narg,
|
||||
const char *param_name);
|
||||
int moo_lua_get_arg_index_opt (lua_State *L,
|
||||
int narg,
|
||||
const char *param_name,
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "mooutils/moomenutoolbutton.h"
|
||||
#include "mooutils/moonotebook.h"
|
||||
#include "mooutils/mooundo.h"
|
||||
#include "mooutils/mooutils-script.h"
|
||||
|
||||
#include "moofileview/moofileview.h"
|
||||
|
||||
|
@ -45,6 +45,7 @@ headers
|
||||
#include "mooutils/moomenutoolbutton.h"
|
||||
#include "mooutils/moonotebook.h"
|
||||
#include "mooutils/mooundo.h"
|
||||
#include "mooutils/mooutils-script.h"
|
||||
|
||||
#include "moofileview/moofileview.h"
|
||||
|
||||
|
@ -119,6 +119,8 @@ moo_sources += \
|
||||
mooutils/mooutils-messages.h \
|
||||
mooutils/mooutils-misc.c \
|
||||
mooutils/mooutils-misc.h \
|
||||
mooutils/mooutils-script.c \
|
||||
mooutils/mooutils-script.h \
|
||||
mooutils/mooutils-tests.h \
|
||||
mooutils/mooutils-treeview.c \
|
||||
mooutils/mooutils-treeview.h \
|
||||
|
45
moo/mooutils/mooutils-script.c
Normal file
45
moo/mooutils/mooutils-script.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* mooutils-script.c
|
||||
*
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
* GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation; either version 2.1 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "mooutils-script.h"
|
||||
#include "mooutils.h"
|
||||
|
||||
static gboolean
|
||||
quit_main_loop (GMainLoop *main_loop)
|
||||
{
|
||||
g_main_loop_quit (main_loop);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_spin_main_loop:
|
||||
**/
|
||||
void
|
||||
moo_spin_main_loop (double sec)
|
||||
{
|
||||
GMainLoop *main_loop;
|
||||
|
||||
moo_return_if_fail (sec > 0);
|
||||
|
||||
main_loop = g_main_loop_new (NULL, FALSE);
|
||||
_moo_timeout_add (sec * 1000, (GSourceFunc) quit_main_loop, main_loop);
|
||||
|
||||
gdk_threads_leave ();
|
||||
g_main_loop_run (main_loop);
|
||||
gdk_threads_enter ();
|
||||
|
||||
g_main_loop_unref (main_loop);
|
||||
}
|
27
moo/mooutils/mooutils-script.h
Normal file
27
moo/mooutils/mooutils-script.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* mooutils-script.h
|
||||
*
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
* GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation; either version 2.1 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOO_UTILS_SCRIPT_H
|
||||
#define MOO_UTILS_SCRIPT_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void moo_spin_main_loop (double sec);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_UTILS_SCRIPT_H */
|
Loading…
x
Reference in New Issue
Block a user