Table of Contents
This chapter presents the code for the History program in several annotated sections.
The GTK widgets and Gamma functions used here have been discussed in previous sections.
/*-------------------------------------------------------------------- * Function: make_toggle_button * Returns: A GtkToggleButton * Description: Creates toggle buttons. *------------------------------------------------------------------*/ function make_toggle_button(lbl, color) { local button; button = new(GtkToggleButton); button.label = lbl; button.set_color(1, GTK_STATE_NORMAL, color); button.set_color(1, GTK_STATE_PRELIGHT, (color + 0x111111)); button.set_color(1, GTK_STATE_ACTIVE, (color - 0x111111)); button; }
/*-------------------------------------------------------------------- * Function: create_history * Returns: A GtkWindow * Description: Creates the History window. *------------------------------------------------------------------*/ function create_history () { local history_win, title, frame, box1, box2, box3, table; local label, label1, label2, but_int1, but_int2, but_int3, but_int4; local recbut, entry, qubut, dbsbut, text, but_db1, but_db2, but_db3; local spinner, adj, xbut, iset, ent_yhs, ent_str, ent_dur; local ent_xhs, ent_int, ent_max, ent_res, dbmv_set, dbpv_set, db_list; local dbsbut, plbut, swin, buttons; history_win = new (GtkWindow); send_message("6"); history_win.signal ("destroy", #history_win = nil); history_win.title = "Cogent Tools Demo: History"; history_win.set_color(1, GTK_STATE_NORMAL, 0xdddddd); history_win.border_width = 10; history_win.width = 380; /* Title frame. */ box1 = new(GtkVBox); title = new (GtkLabel); title.set_text("Cogent Tools Demo - History"); title.set_color(1, GTK_STATE_NORMAL, 0xff0000); title.height = 25; frame = new(GtkFrame); frame.set_color(1, GTK_STATE_NORMAL, 0xff0000); frame.add(title); frame.border_width = 5; box1.pack_start(frame, TRUE, TRUE, 0); history_win.add (box1); /* Record Values and Exit buttons. */ table = gtk_table_new(5, 1, FALSE); table.border_width = 5; table.set_homogeneous(FALSE); recbut = make_toggle_button("Record", 0xddccee); recbut.signal("clicked", `send_hs_command(@recbut, "enable", nil, nil)); button_messages (recbut, "6.2", "6"); label1 = new(GtkLabel); label1.set_text("data for"); adj = gtk_adjustment_new (0, 1, 200, 1, 5, 0.0); spinner = new(GtkSpinButton); spinner.set_adjustment(adj); spinner.set_value(RECORD_TIME); adj.signal("value_changed", `(RECORD_TIME = (@adj).value)); label2 = new(GtkLabel); label2.set_text("seconds. "); xbut = new(GtkButton); xbut.label = "Exit"; xbut.signal("clicked", `(@history_win).destroy()); iset = new(InterpolatorSettings); table.attach_defaults(recbut, 0, 1, 0, 1); table.attach_defaults(label1, 1, 2, 0, 1); table.attach_defaults(spinner, 2, 3, 0, 1); table.attach_defaults(label2, 3, 4, 0, 1); table.attach_defaults(xbut, 4, 5, 0, 1); box1.pack_start(table, TRUE, TRUE, 5); text = new(GtkText); text.set_editable(FALSE); /* Interpolator options. */ frame = new(GtkFrame); frame.border_width = 5; frame.set_color(1, GTK_STATE_NORMAL, 0xddccee); frame.set_label(" Interpolator options: "); frame.set_label_align(.05, 1); frame.set_shadow_type(GTK_SHADOW_IN); box1.pack_start(frame, TRUE, TRUE, 0); table = gtk_table_new(2, 6, FALSE); table.border_width = 10; table.set_col_spacing(0, 20); table.set_row_spacings(3); frame.add(table); ent_yhs = qry_entry(table, "Y history:", iset.y_history, 0, 1); ent_str = qry_entry(table, "Start:", iset.start, 1, 2); ent_dur = qry_entry(table, "Duration:", iset.duration, 2, 3); ent_xhs = qry_entry(table, "X history:", iset.x_history, 3, 4); ent_int = qry_entry(table, "Time Interval:", iset.interval, 4, 5); ent_max = qry_entry(table, "Max. gap:", iset.max_gap, 5, 6);
but_int1 = qry_radio_but(table, "NoInterpolator", nil, iset, "6.31", 0, 1, ent_xhs, ent_int, ent_max, 0, 0, 0); but_int2 = qry_radio_but(table, "Periodic", list(but_int1), iset, "6.32", 1, 2, ent_xhs, ent_int, ent_max, 0, 1, 1); but_int3 = qry_radio_but(table, "Relative", list(but_int1, but_int2), iset, "6.33", 2, 3, ent_xhs, ent_int, ent_max, 1, 0, 0); but_int4 = qry_radio_but(table, "FixedRelative", list(but_int1, but_int2, but_int3), iset, "6.34", 3, 4, ent_xhs, ent_int, ent_max, 1, 1, 0); ent_res = new(GtkEntry); ent_res.width = 45; qubut = new(GtkButton); qubut.label = "Update display"; qubut.set_color(1, GTK_STATE_NORMAL, 0xddccee); qubut.set_color(1, GTK_STATE_PRELIGHT, 0xeeddff); button_messages (qubut, "6.3", "6"); table.attach_defaults(qubut, 0, 1, 5, 6); /* Deadband options. */ dbmv_set = new(DeadbandSettings); dbmv_set.history = "MV_001"; dbpv_set = new(DeadbandSettings); dbpv_set.history = "PV_001"; db_list = list(dbmv_set, dbpv_set); box2 = new(GtkHBox); box1.pack_start(box2, TRUE, TRUE, 0); frame = new(GtkFrame); frame.border_width = 5; frame.set_color(1, GTK_STATE_NORMAL, 0xddccee); frame.set_label(" Deadband options: "); frame.set_label_align(.05, 1); frame.set_shadow_type(GTK_SHADOW_IN); box2.pack_start(frame, TRUE, TRUE, 0); table = gtk_table_new(1, 4, FALSE); table.border_width = 10; table.set_row_spacings(3); frame.add(table); but_db1 = gtk_check_button_new_with_label ("Full data set (no deadband)"); but_db2 = gtk_check_button_new_with_label ("Deadband on, prior value off"); but_db3 = gtk_check_button_new_with_label ("Deadband on, prior value on"); but_db1.signal("enter", `send_message("6.51")); but_db2.signal("enter", `send_message("6.52")); but_db3.signal("enter", `send_message("6.53")); dbsbut = make_toggle_button("Set up deadband types", 0xddccee); dbsbut.signal("toggled", `create_dbtype_win(@db_list, @dbsbut)); dbsbut.signal("enter", `send_message("6.5")); table.attach_defaults(but_db1, 0, 1, 0, 1); table.attach_defaults(but_db2, 0, 1, 1, 2); table.attach_defaults(but_db3, 0, 1, 2, 3); table.attach_defaults(dbsbut, 0, 1, 3, 4); /* Plot and text display. */ box3 = new(GtkVBox); box2.pack_start(box3, TRUE, TRUE, 30); local button; plbut = new(GtkToggleButton); plbut.height = 20; plbut.label = "Plot Data"; plbut.set_color(1, GTK_STATE_NORMAL, 0xccccb0); plbut.set_color(1, GTK_STATE_PRELIGHT, 0xddddbb); plbut.set_color(1, GTK_STATE_ACTIVE, 0xbbbb99); plbut.signal("toggled", `start_stop(@plbut, "gnuplot", "plothist1", "-background", "gray", "-geometry", "500x400-10-30", "plhist.cfg", nil, nil, nil)); plbut.signal("toggled", `anygui_move_window(@plbut, @history_win, 380, 45, 100, 45)); button_messages (plbut, "6.4", "6"); label = new(GtkLabel); label.set_text("Number\nof points\nfrom last\nquery:"); box3.pack_end(ent_res, FALSE, FALSE, 5); box3.pack_end(label, TRUE, TRUE, 5); box3.pack_end(plbut, TRUE, TRUE, 5); swin = new(GtkScrolledWindow); swin.set_policy(GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); swin.border_width = 5; swin.height = 200; swin.width = 400; swin.add(text); box1.pack_start(swin, TRUE, TRUE, 0); recbut.signal("clicked", `record_data(@recbut, @iset, @but_db1, @but_db2, @but_db3, @text, @ent_yhs, @ent_str, @ent_dur, @ent_xhs, @ent_int, @ent_max, @ent_res, @but_int1, @but_int2, @but_int3, @but_int4, @qubut)); /* Callbacks for non-deadband buttons to send a query. */ buttons = list(but_int1, but_int2, but_int3, but_int4, qubut); with b in buttons do { b.signal("clicked", `reset_deadbands(@b, @iset, @but_db1, @but_db2, @but_db3, @text, @ent_yhs, @ent_str, @ent_dur, @ent_xhs, @ent_int, @ent_max, @ent_res, @but_int1, @but_int2, @but_int3, @but_int4, @recbut, @qubut)); } /* Callbacks for deadband buttons to prepare for and send a query. */ buttons = list(but_db1, but_db2, but_db3); with b in buttons do { b.signal("clicked", `plot_prep(@b, @iset, @but_db1, @but_db2, @but_db3, @text, @ent_yhs, @ent_str, @ent_dur, @ent_xhs, @ent_int, @ent_max, @ent_res, @but_int1, @but_int2, @but_int3, @but_int4, @recbut, @qubut)); } /* Display version info and start-up message.*/ ret = display_hs_info(text); history_win.show_all(); history_win.reposition(380, 45); history_win; }
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.