static void define_scope_windows(void) { GtkWidget *hbox, *vboxleft, *vboxright, *hboxright; /* create main window, set it's size */ ctrl_usr->main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* set the minimum size */ // gtk_widget_set_usize(GTK_WIDGET(ctrl_usr->main_win), 500, 350); /* allow the user to expand it */ gtk_window_set_policy(GTK_WINDOW(ctrl_usr->main_win), FALSE, TRUE, FALSE); /* set main window title */ gtk_window_set_title(GTK_WINDOW(ctrl_usr->main_win), "HAL Oscilloscope"); /* top level - one big hbox */ hbox = gtk_hbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(hbox), 0); /* add the hbox to the main window */ gtk_container_add(GTK_CONTAINER(ctrl_usr->main_win), hbox); gtk_widget_show(hbox); /* end of top level */ /* second level of windows */ vboxleft = gtk_vbox_new_in_box(FALSE, 0, 0, hbox, TRUE, TRUE, 0); hboxright = gtk_hbox_new_in_box(TRUE, 0, 0, hbox, FALSE, FALSE, 0); /* third level of windows */ /* left side */ ctrl_usr->horiz_info_win = gtk_vbox_framed_new_in_box("Horizontal", FALSE, 0, 0, vboxleft, FALSE, FALSE, 1); /* horizontal row of select buttons */ ctrl_usr->waveform_win = gtk_vbox_new_in_box(FALSE, 0, 0, vboxleft, TRUE, TRUE, 0); ctrl_usr->chan_sel_win = gtk_hbox_new_in_box(TRUE, 0, 0, vboxleft, FALSE, FALSE, 0); ctrl_usr->chan_info_win = gtk_hbox_framed_new_in_box("Selected Channel", FALSE, 0, 0, vboxleft, FALSE, FALSE, 0); /* right side */ vboxleft = gtk_vbox_new_in_box(FALSE, 0, 0, hboxright, FALSE, FALSE, 0); vboxright = gtk_vbox_new_in_box(FALSE, 0, 0, hboxright, FALSE, FALSE, 0); ctrl_usr->run_mode_win = gtk_vbox_framed_new_in_box("Run Mode", TRUE, 0, 0, vboxleft, FALSE, FALSE, 0); ctrl_usr->trig_info_win = gtk_vbox_framed_new_in_box("Trigger", FALSE, 0, 0, vboxright, TRUE, TRUE, 0); ctrl_usr->trig_mode_win = gtk_vbox_new_in_box(TRUE, 0, 0, ctrl_usr->trig_info_win, FALSE, FALSE, 0); ctrl_usr->vert_info_win = gtk_vbox_framed_new_in_box("Vertical", FALSE, 0, 0, vboxleft, TRUE, TRUE, 0); /* all windows are now defined */ }
int main(int argc, gchar * argv[]) { GtkWidget *vbox, *hbox; GtkWidget *button_select, *button_exit; char buf[30]; int initial_type = 0, n, i, height, geometryflag = 0, xposition = 0, yposition = 0, width = 270; char *initial_name = NULL , *win_name; meter_t *meter; bindtextdomain("linuxcnc", EMC2_PO_DIR); setlocale(LC_MESSAGES,""); setlocale(LC_CTYPE,""); textdomain("linuxcnc"); /* process and remove any GTK specific command line args */ gtk_init(&argc, &argv); /* process my own command line args (if any) here */ small = 0; n = 1; while ( argc > n ) { if ( strcmp (argv[n], "-g") == 0 ) { /* This sets up the variables for initial position of window*/ /* The last check is for the optional width request*/ geometryflag = 1; n++; xposition = atoi(argv[n]); n++; yposition = atoi(argv[n]); n++; if ( argc > n ){ strcpy(buf,argv[n]); for (i=0; i< strlen(argv[n]); i++) { if (isdigit(buf[i]) == 0) { break; } } if (strlen(argv[n]) == i){ width = atoi(argv[n]); n++; } } } if ((argc > n) && ( strcmp (argv[n], "-s") == 0 )) { small = 1; n++; } if (argc > n) { /* check for user specified initial probe point */ if (strncmp(argv[n], "pin", 3) == 0) { /* initial probe is a pin */ initial_type = 0; } else if (strncmp(argv[n], "sig", 3) == 0) { /* initial probe is a signal */ initial_type = 1; } else if (strncmp(argv[n], "par", 3) == 0) { /* initial probe is a parameter */ initial_type = 2; } else { printf(_("ERROR: '%s' is not a valid probe type\n"), argv[n]); return -1; } n++; if ( argc > n ) { initial_name = argv[n]; n++; } else { printf(_("ERROR: no pin/signal/parameter name\n")); return -1; } } } if ((initial_name == NULL) && (small == 1)) { printf(_("ERROR: -s option requires a probe type and a pin/signal/parameter name\n")); return -1; } /* create a unique module name */ snprintf(buf, 29, "halmeter-%d", getpid()); /* connect to the HAL */ comp_id = hal_init(buf); if (comp_id < 0) { return -1; } hal_ready(comp_id); /* register an exit function to disconnect from the HAL */ g_atexit(exit_from_hal); /* capture INT (ctrl-C) and TERM signals */ signal(SIGINT, quit); signal(SIGTERM, quit); /* create main window, set it's size, and lock the size */ main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* ideally this wouldn't be fixed size in pixels */ if ( small ) { height = 22; win_name = initial_name; } else { height = 80; win_name = _("Hal Meter"); } gtk_widget_set_usize(GTK_WIDGET(main_window), width, height); gtk_window_set_policy(GTK_WINDOW(main_window), FALSE, FALSE, FALSE); /* set main window title */ gtk_window_set_title(GTK_WINDOW(main_window), win_name); /* this makes the application exit when the window is closed */ gtk_signal_connect(GTK_OBJECT(main_window), "destroy", GTK_SIGNAL_FUNC(gtk_main_quit), NULL); /* a vbox to hold the displayed value and the pin/sig/param name */ vbox = gtk_vbox_new(FALSE, 3); gtk_container_set_border_width(GTK_CONTAINER(vbox), 2); /* add the vbox to the main window */ gtk_container_add(GTK_CONTAINER(main_window), vbox); gtk_widget_show(vbox); /* create a meter object */ meter = meter_new(); if (meter == NULL) { printf("null meter\n"); exit(-1); } /* set up for initial probe, if any */ if (initial_name != NULL) { meter->probe->pickname = initial_name; meter->probe->listnum = initial_type; apply_selection(NULL, meter->probe); } /* add the meter's value label to the vbox */ gtk_box_pack_start(GTK_BOX(vbox), meter->value_label, TRUE, TRUE, 0); gtk_widget_show(meter->value_label); /* add the meter's name label to the vbox */ if ( !small ) { gtk_box_pack_start(GTK_BOX(vbox), meter->name_label, TRUE, TRUE, 0); gtk_widget_show(meter->name_label); } /* arrange for periodic refresh of the value */ gtk_timeout_add(100, refresh_value, meter); /* an hbox to hold the select and exit buttons */ if ( !small ) { hbox = gtk_hbox_new_in_box(FALSE, 0, 0, vbox, FALSE, TRUE, 0); /* create the buttons and add them to the hbox */ button_select = gtk_button_new_with_label(_("_Select")); button_exit = gtk_button_new_with_label(_("E_xit")); gtk_button_set_use_underline((GtkButton *)button_select, TRUE); gtk_button_set_use_underline((GtkButton *)button_exit, TRUE); gtk_box_pack_start(GTK_BOX(hbox), button_select, TRUE, TRUE, 4); gtk_box_pack_start(GTK_BOX(hbox), button_exit, TRUE, TRUE, 4); /* make the application exit when the 'exit' button is clicked */ gtk_signal_connect(GTK_OBJECT(button_exit), "clicked", GTK_SIGNAL_FUNC(gtk_main_quit), NULL); /* activate selection window when the 'select' button is clicked */ gtk_signal_connect(GTK_OBJECT(button_select), "clicked", GTK_SIGNAL_FUNC(popup_probe_window), meter->probe); /* save reference to select button */ meter->button_select = button_select; gtk_widget_show(button_select); gtk_widget_show(button_exit); } /* The interface is now set up so we show the window and enter the gtk_main loop. */ gtk_widget_show(main_window); /* If the -g option was invoked: set position */ if (geometryflag == 1) { gtk_window_move(GTK_WINDOW(main_window),xposition,yposition); } gtk_main(); return (0); }
static void init_vert_info_window(void) { scope_vert_t *vert; GtkWidget *hbox, *vbox; GtkWidget *button; vert = &(ctrl_usr->vert); /* box for the two sliders */ hbox = gtk_hbox_new_in_box(TRUE, 0, 0, ctrl_usr->vert_info_win, TRUE, TRUE, 0); /* box for the scale slider */ vbox = gtk_vbox_new_in_box(FALSE, 0, 0, hbox, TRUE, TRUE, 0); gtk_label_new_in_box(_("Gain"), vbox, FALSE, FALSE, 0); vert->scale_adj = gtk_adjustment_new(0, -5, 5, 1, 1, 0); vert->scale_slider = gtk_vscale_new(GTK_ADJUSTMENT(vert->scale_adj)); gtk_scale_set_digits(GTK_SCALE(vert->scale_slider), 0); gtk_scale_set_draw_value(GTK_SCALE(vert->scale_slider), FALSE); gtk_box_pack_start(GTK_BOX(vbox), vert->scale_slider, TRUE, TRUE, 0); /* connect the slider to a function that re-calcs vertical scale */ gtk_signal_connect(GTK_OBJECT(vert->scale_adj), "value_changed", GTK_SIGNAL_FUNC(scale_changed), NULL); gtk_widget_show(vert->scale_slider); /* box for the position slider */ vbox = gtk_vbox_new_in_box(FALSE, 0, 0, hbox, TRUE, TRUE, 0); gtk_label_new_in_box(_("Pos"), vbox, FALSE, FALSE, 0); vert->pos_adj = gtk_adjustment_new(VERT_POS_RESOLUTION / 2, 0, VERT_POS_RESOLUTION, 1, 1, 0); vert->pos_slider = gtk_vscale_new(GTK_ADJUSTMENT(vert->pos_adj)); gtk_scale_set_digits(GTK_SCALE(vert->pos_slider), 0); gtk_scale_set_draw_value(GTK_SCALE(vert->pos_slider), FALSE); gtk_box_pack_start(GTK_BOX(vbox), vert->pos_slider, TRUE, TRUE, 0); /* connect the slider to a function that re-calcs vertical pos */ gtk_signal_connect(GTK_OBJECT(vert->pos_adj), "value_changed", GTK_SIGNAL_FUNC(pos_changed), NULL); gtk_widget_show(vert->pos_slider); /* Scale display */ gtk_hseparator_new_in_box(ctrl_usr->vert_info_win, 3); gtk_label_new_in_box(_("Scale"), ctrl_usr->vert_info_win, FALSE, FALSE, 0); vert->scale_label = gtk_label_new_in_box(" ---- ", ctrl_usr->vert_info_win, FALSE, FALSE, 0); /* Offset control */ vert->offset_button = gtk_button_new_with_label("Offset\n----"); vert->offset_label = (GTK_BIN(vert->offset_button))->child; gtk_box_pack_start(GTK_BOX(ctrl_usr->vert_info_win), vert->offset_button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(vert->offset_button), "clicked", GTK_SIGNAL_FUNC(offset_button), NULL); gtk_widget_show(vert->offset_button); /* a button to turn off the channel */ button = gtk_button_new_with_label(_("Chan Off")); gtk_box_pack_start(GTK_BOX(ctrl_usr->vert_info_win), button, FALSE, FALSE, 0); /* turn off the channel if button is clicked */ gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(channel_off_button), NULL); gtk_widget_show(button); }