static int32_t view_changed_callback_job(dt_job_t *job) { dt_lua_lock(); view_changed_callback_data_t *t = dt_control_job_get_params(job); dt_lua_module_entry_push(darktable.lua_state.state, "view", t->old_view->module_name); dt_lua_module_entry_push(darktable.lua_state.state, "view", t->new_view->module_name); free(t); dt_lua_event_trigger(darktable.lua_state.state, "view-changed", 2); dt_lua_unlock(); return 0; }
static int lua_register_selection(lua_State *L) { lua_settop(L,3); dt_lib_module_t *self = lua_touserdata(L, lua_upvalueindex(1)); dt_lua_module_entry_push(L,"lib",self->plugin_name); lua_getuservalue(L,-1); const char* key = luaL_checkstring(L,1); luaL_checktype(L,2,LUA_TFUNCTION); lua_getfield(L,-1,"callbacks"); lua_pushstring(L,key); lua_pushvalue(L,2); lua_settable(L,-3); GtkWidget* button = gtk_button_new_with_label(key); const char * tooltip = lua_tostring(L,3); if(tooltip) { gtk_widget_set_tooltip_text(button, tooltip); } gtk_grid_attach_next_to(GTK_GRID(self->widget), button, NULL, GTK_POS_BOTTOM, 2, 1); lua_callback_data * data = malloc(sizeof(lua_callback_data)); data->key = strdup(key); data->self = self; g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(lua_button_clicked), data); gtk_widget_show_all(self->widget); return 0; }
static int lua_update_metadata(lua_State*L) { dt_lib_module_t *self = lua_touserdata(L, 1); int32_t imgid = lua_tointeger(L,2); dt_lua_module_entry_push(L,"lib",self->plugin_name); lua_getuservalue(L,-1); lua_getfield(L,4,"callbacks"); lua_getfield(L,4,"values"); lua_pushnil(L); while(lua_next(L, 5) != 0) { lua_pushvalue(L,-1); luaA_push(L,dt_lua_image_t,&imgid); lua_call(L,1,1); lua_pushvalue(L,7); lua_pushvalue(L,9); lua_settable(L,6); lua_pop(L, 2); } lua_pushcfunction(L,lua_update_widgets); dt_lua_gtk_wrap(L); lua_pushlightuserdata(L,self); lua_call(L,1,0); return 0; }
static int new_widget(lua_State *L) { const char *entry_name = luaL_checkstring(L, 1); dt_lua_module_entry_push(L, "widget", entry_name); lua_insert(L,2); lua_call(L, lua_gettop(L)-2, 1); return 1; }
static int views_member(lua_State*L) { dt_lib_module_t * module = *(dt_lib_module_t**)lua_touserdata(L,1); int i; lua_newtable(L); for(i=0; i< darktable.view_manager->num_views ; i++) { if(darktable.view_manager->view[i].view(&darktable.view_manager->view[i]) & module->views()){ dt_lua_module_entry_push(L,"view",(darktable.view_manager->view[i].module_name)); luaL_ref(L,-2); } } return 1; }
static int current_view_cb(lua_State *L) { if(lua_gettop(L) > 0) { luaL_argcheck(L, dt_lua_isa(L, 1, dt_view_t), 1, "dt_view_t expected"); dt_view_t *module = *(dt_view_t **)lua_touserdata(L, 1); int i = 0; while(i < darktable.view_manager->num_views && module != &darktable.view_manager->view[i]) i++; if(i == darktable.view_manager->num_views) return luaL_error(L, "should never happen : %s %d\n", __FILE__, __LINE__); dt_ctl_switch_mode_to(i); } const dt_view_t *current_view = dt_view_manager_get_current_view(darktable.view_manager); dt_lua_module_entry_push(L, "view", current_view->module_name); return 1; }
static int current_view_cb(lua_State *L) { if(lua_gettop(L) > 0) { dt_view_t *module; luaA_to(L,dt_lua_view_t,&module,1); int i = 0; while(i < darktable.view_manager->num_views && module != &darktable.view_manager->view[i]) i++; if(i == darktable.view_manager->num_views) return luaL_error(L, "should never happen : %s %d\n", __FILE__, __LINE__); dt_ctl_switch_mode_to(i); } const dt_view_t *current_view = dt_view_manager_get_current_view(darktable.view_manager); dt_lua_module_entry_push(L, "view", current_view->module_name); return 1; }
void init(struct dt_lib_module_t *self) { lua_State *L = darktable.lua_state.state; int my_type = dt_lua_module_entry_get_type(L, "lib", self->plugin_name); lua_pushlightuserdata(L, self); lua_pushcclosure(L, lua_register_selection ,1); dt_lua_gtk_wrap(L); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, my_type, "register_selection"); dt_lua_module_entry_push(L,"lib",self->plugin_name); lua_getuservalue(L,-1); lua_newtable(L); lua_setfield(L,-2,"callbacks"); lua_pop(L,2); }
static int lua_update_widgets(lua_State*L) { dt_lib_module_t *self = lua_touserdata(L, 1); dt_lua_module_entry_push(L,"lib",self->plugin_name); lua_getuservalue(L,2); lua_getfield(L,3,"values"); lua_getfield(L,3,"widgets"); lua_pushnil(L); while(lua_next(L, 4) != 0) { lua_getfield(L,5,lua_tostring(L,-2)); GtkLabel *widget = lua_touserdata(L,-1); _metadata_update_value_end(widget,luaL_checkstring(L,7)); lua_pop(L,2); } return 0; }
static int lua_register_info(lua_State *L) { dt_lib_module_t *self = lua_touserdata(L, lua_upvalueindex(1)); dt_lua_module_entry_push(L,"lib",self->plugin_name); lua_getuservalue(L,-1); const char* key = luaL_checkstring(L,1); luaL_checktype(L,2,LUA_TFUNCTION); { lua_getfield(L,-1,"callbacks"); lua_pushstring(L,key); lua_pushvalue(L,2); lua_settable(L,5); lua_pop(L,1); } { lua_getfield(L,-1,"values"); lua_pushstring(L,key); lua_pushstring(L,"-"); lua_settable(L,5); lua_pop(L,1); } { GtkWidget *evb = gtk_event_box_new(); gtk_widget_set_name(evb, "brightbg"); GtkLabel *name = GTK_LABEL(gtk_label_new(key)); GtkLabel *value = GTK_LABEL(gtk_label_new("-")); gtk_label_set_selectable(value, TRUE); gtk_container_add(GTK_CONTAINER(evb), GTK_WIDGET(value)); gtk_widget_set_halign(GTK_WIDGET(name), GTK_ALIGN_START); gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START); gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(name), NULL, GTK_POS_BOTTOM, 1, 1); gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(evb), GTK_WIDGET(name), GTK_POS_RIGHT, 1, 1); gtk_widget_show_all(self->widget); { lua_getfield(L,-1,"widgets"); lua_pushstring(L,key); lua_pushlightuserdata(L,value); lua_settable(L,5); lua_pop(L,1); } } return 0; }
static int lua_button_clicked_cb(lua_State* L) { lua_callback_data * data = lua_touserdata(L,1); dt_lua_module_entry_push(L,"lib",data->self->plugin_name); lua_getuservalue(L,-1); lua_getfield(L,-1,"callbacks"); lua_getfield(L,-1,data->key); lua_pushstring(L,data->key); GList *image = dt_collection_get_selected(darktable.collection, -1); lua_newtable(L); while(image) { luaA_push(L, dt_lua_image_t, &image->data); luaL_ref(L, -2); image = g_list_delete_link(image, image); } lua_call(L,2,0); return 0; }
static int lua_button_clicked_cb(lua_State* L) { lua_callback_data * data = lua_touserdata(L,1); dt_lua_module_entry_push(L,"lib",data->self->plugin_name); lua_getuservalue(L,-1); lua_getfield(L,-1,"callbacks"); lua_getfield(L,-1,data->key); lua_pushstring(L,data->key); GList *image = dt_collection_get_all(darktable.collection, -1); lua_newtable(L); while(image) { luaA_push(L, dt_lua_image_t, &image->data); luaL_ref(L, -2); image = g_list_delete_link(image, image); } lua_call(L,2,1); GList *new_selection = NULL; luaL_checktype(L, -1, LUA_TTABLE); lua_pushnil(L); while(lua_next(L, -2) != 0) { /* uses 'key' (at index -2) and 'value' (at index -1) */ int imgid; luaA_to(L, dt_lua_image_t, &imgid, -1); new_selection = g_list_prepend(new_selection, GINT_TO_POINTER(imgid)); lua_pop(L, 1); } new_selection = g_list_reverse(new_selection); dt_selection_clear(darktable.selection); dt_selection_select_list(darktable.selection, new_selection); g_list_free(new_selection); return 0; }