gtdc/gui_control_tab.c

54 lines
1.3 KiB
C
Raw Normal View History

2008-03-18 19:30:21 +01:00
#include <gtk/gtk.h>
#include "tdc_parser.h"
static GtkWidget *button_connect;
static int connect_status = STAT_DISCONNECTED;
static void connect_button_update(int status)
{
connect_status = status;
if (status == STAT_DISCONNECTED)
gtk_button_set_label(GTK_BUTTON(button_connect), "Connect");
else
gtk_button_set_label(GTK_BUTTON(button_connect), "Disconnect");
}
static void connect_button_cb(GtkWidget *widget, gpointer data)
{
switch (connect_status) {
case STAT_DISCONNECTED:
tdcparser_connect("127.0.0.1:5000", connect_button_update);
break;
case STAT_CONNECTING:
case STAT_CONNECTED:
tdcparser_disconnect();
break;
}
}
gint gui_ctrltab_init(GtkNotebook *notebook)
{
GtkWidget *table = gtk_table_new(10, 10, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(table), 10);
button_connect = gtk_button_new_with_label("Connect");
gtk_table_attach(GTK_TABLE(table), button_connect, 0, 1, 0, 1, 0, 0, 10, 10);
g_signal_connect(G_OBJECT(button_connect), "clicked", G_CALLBACK(connect_button_cb), NULL);
/*
* TODO:
* - address field
* - all_variable_refresh_timer
* - graph_variable_refresh_timer
* later:
* - board select
* - connection/protocol details/errors
*/
GtkWidget *label = gtk_label_new(" Control ");
return gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, label);
}