Add function in GUI to determine the current button states to prevent multiple triggers for rendering/reloading the library during rendering

This commit is contained in:
Mario Hüttel 2019-08-21 18:34:40 +02:00
parent 4b238c55ea
commit 08722cd6f9

View File

@ -47,6 +47,11 @@ enum gds_render_gui_signal_sig_ids {SIGNAL_WINDOW_CLOSED = 0, SIGNAL_COUNT};
static guint gds_render_gui_signals[SIGNAL_COUNT]; static guint gds_render_gui_signals[SIGNAL_COUNT];
struct gui_button_states {
gboolean rendering_active;
gboolean valid_cell_selected;
};
struct _GdsRenderGui { struct _GdsRenderGui {
/* Parent GObject */ /* Parent GObject */
GObject parent; GObject parent;
@ -54,6 +59,9 @@ struct _GdsRenderGui {
/* Custom fields */ /* Custom fields */
GtkWindow *main_window; GtkWindow *main_window;
GtkWidget *convert_button; GtkWidget *convert_button;
GtkWidget *open_button;
GtkWidget *load_layer_button;
GtkWidget *save_layer_button;
GtkTreeStore *cell_tree_store; GtkTreeStore *cell_tree_store;
GtkWidget *cell_search_entry; GtkWidget *cell_search_entry;
LayerSelector *layer_selector; LayerSelector *layer_selector;
@ -62,6 +70,7 @@ struct _GdsRenderGui {
ActivityBar *activity_status_bar; ActivityBar *activity_status_bar;
struct render_settings render_dialog_settings; struct render_settings render_dialog_settings;
ColorPalette *palette; ColorPalette *palette;
struct gui_button_states button_state_data;
}; };
G_DEFINE_TYPE(GdsRenderGui, gds_render_gui, G_TYPE_OBJECT) G_DEFINE_TYPE(GdsRenderGui, gds_render_gui, G_TYPE_OBJECT)
@ -283,6 +292,10 @@ static void on_convert_clicked(gpointer button, gpointer user)
if (!self) if (!self)
return; return;
/* Abort if rendering is already active */
if (self->button_state_data.rendering_active == TRUE)
return;
sett = &self->render_dialog_settings; sett = &self->render_dialog_settings;
/* Get selected cell */ /* Get selected cell */
@ -374,10 +387,14 @@ static void on_convert_clicked(gpointer button, gpointer user)
if (render_engine) { if (render_engine) {
gds_output_renderer_set_output_file(render_engine, file_name); gds_output_renderer_set_output_file(render_engine, file_name);
gds_output_renderer_set_layer_settings(render_engine, layer_settings); gds_output_renderer_set_layer_settings(render_engine, layer_settings);
/* Prevent user from overwriting library or triggering additional conversion */
self->button_state_data.rendering_active = TRUE;
/* TODO: Replace this with asynchronous rendering. However, this fixes issue #19 */ /* TODO: Replace this with asynchronous rendering. However, this fixes issue #19 */
gds_output_renderer_render_output(render_engine, cell_to_render, sett->scale); gds_output_renderer_render_output(render_engine, cell_to_render, sett->scale);
self->button_state_data.rendering_active = FALSE;
g_object_unref(render_engine); g_object_unref(render_engine);
} }
@ -407,6 +424,22 @@ static void cell_tree_view_activated(gpointer tree_view, GtkTreePath *path,
on_convert_clicked(NULL, user); on_convert_clicked(NULL, user);
} }
static void process_button_state_changes(GdsRenderGui *self)
{
gboolean convert_button_state = FALSE;
gboolean open_gds_button_state = FALSE;
/* Calculate states */
if (!self->button_state_data.rendering_active) {
open_gds_button_state = TRUE;
if (self->button_state_data.valid_cell_selected)
convert_button_state = TRUE;
}
/* Apply states */
gtk_widget_set_sensitive(self->convert_button, convert_button_state);
gtk_widget_set_sensitive(self->open_button, open_gds_button_state);
}
/** /**
* @brief Callback for cell-selection change event * @brief Callback for cell-selection change event
@ -423,10 +456,12 @@ static void cell_selection_changed(GtkTreeSelection *sel, GdsRenderGui *self)
if (gtk_tree_selection_get_selected(sel, &model, &iter)) { if (gtk_tree_selection_get_selected(sel, &model, &iter)) {
/* Node selected. Show button */ /* Node selected. Show button */
gtk_widget_set_sensitive(self->convert_button, TRUE); self->button_state_data.valid_cell_selected = TRUE;
} else { } else {
gtk_widget_set_sensitive(self->convert_button, FALSE); self->button_state_data.valid_cell_selected = FALSE;
} }
process_button_state_changes(self);
} }
static void sort_up_callback(GtkWidget *widget, gpointer user) static void sort_up_callback(GtkWidget *widget, gpointer user)
@ -466,6 +501,9 @@ static void gds_render_gui_dispose(GObject *gobject)
g_clear_object(&self->cell_search_entry); g_clear_object(&self->cell_search_entry);
g_clear_object(&self->activity_status_bar); g_clear_object(&self->activity_status_bar);
g_clear_object(&self->palette); g_clear_object(&self->palette);
g_clear_object(&self->load_layer_button);
g_clear_object(&self->save_layer_button);
g_clear_object(&self->open_button);
if (self->main_window) { if (self->main_window) {
g_signal_handlers_destroy(self->main_window); g_signal_handlers_destroy(self->main_window);
@ -521,7 +559,8 @@ static void gds_render_gui_init(GdsRenderGui *self)
self->cell_tree_store = cell_selector_stores->base_store; self->cell_tree_store = cell_selector_stores->base_store;
self->main_window = GTK_WINDOW(gtk_builder_get_object(main_builder, "main-window")); self->main_window = GTK_WINDOW(gtk_builder_get_object(main_builder, "main-window"));
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-gds")), self->open_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-gds"));
g_signal_connect(self->open_button,
"clicked", G_CALLBACK(on_load_gds), (gpointer)self); "clicked", G_CALLBACK(on_load_gds), (gpointer)self);
self->convert_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button")); self->convert_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button"));
@ -550,11 +589,10 @@ static void gds_render_gui_init(GdsRenderGui *self)
g_signal_connect(sort_down_button, "clicked", G_CALLBACK(sort_down_callback), self); g_signal_connect(sort_down_button, "clicked", G_CALLBACK(sort_down_callback), self);
/* Set buttons for loading and saving */ /* Set buttons for loading and saving */
layer_selector_set_load_mapping_button(self->layer_selector, self->load_layer_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-mapping"));
GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-mapping")), self->save_layer_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-save-mapping"));
self->main_window); layer_selector_set_load_mapping_button(self->layer_selector, self->load_layer_button, self->main_window);
layer_selector_set_save_mapping_button(self->layer_selector, GTK_WIDGET(gtk_builder_get_object(main_builder, "button-save-mapping")), layer_selector_set_save_mapping_button(self->layer_selector, self->save_layer_button, self->main_window);
self->main_window);
/* Connect delete-event */ /* Connect delete-event */
g_signal_connect(GTK_WIDGET(self->main_window), "delete-event", g_signal_connect(GTK_WIDGET(self->main_window), "delete-event",
@ -579,6 +617,10 @@ static void gds_render_gui_init(GdsRenderGui *self)
g_object_unref(main_builder); g_object_unref(main_builder);
/* Setup default button sensibility data */
self->button_state_data.rendering_active = FALSE;
self->button_state_data.valid_cell_selected = FALSE;
/* Reference all objects referenced by this object */ /* Reference all objects referenced by this object */
g_object_ref(self->activity_status_bar); g_object_ref(self->activity_status_bar);
g_object_ref(self->main_window); g_object_ref(self->main_window);
@ -588,6 +630,9 @@ static void gds_render_gui_init(GdsRenderGui *self)
g_object_ref(self->cell_tree_store); g_object_ref(self->cell_tree_store);
g_object_ref(self->cell_search_entry); g_object_ref(self->cell_search_entry);
g_object_ref(self->palette); g_object_ref(self->palette);
g_object_ref(self->open_button);
g_object_ref(self->load_layer_button);
g_object_ref(self->save_layer_button);
} }
GdsRenderGui *gds_render_gui_new() GdsRenderGui *gds_render_gui_new()