📄 gui_gtk.c
字号:
// This file is part of MANTIS OS, Operating System// See http://mantis.cs.colorado.edu///// Copyright (C) 2003-2005 University of Colorado, Boulder//// This program is free software; you can redistribute it and/or// modify it under the terms of the mos license (see file LICENSE)#include <time.h>#include <stdbool.h>#include "cortex.h"#include "bionet-interface.h"#include "gui_gtk.h"#include "gui_topo.h"#include "gui_xml.h"#include "model_gtk.h"//for widgets/windows#include "generic_view.h"#include "nodelist_view.h"#include "hablist_view.h"#include "commanding_view.h"gchar *global_filename = NULL;GtkWidget *system_status_label;gui_topo_t *topo;GtkWidget *statusbar;GtkWidget *window_data;GtkWidget *dialog_about;//GtkWidget *dialog_quit;// here are the conds we broadcast when the ui has been initedextern GCond *widget_cond;extern GMutex *widget_mutex;gint num_nodes;gint current_node;GladeXML *xml;void dialog_quit_handler(GtkWidget *w, gpointer p){ //gtk_widget_show(dialog_quit); gtk_main_quit(); gtk_exit(0);}void rate_button_handler(GtkButton *b, gpointer p){ MSG_WIN("Rate setting not yet implemented");}void build_filter_handler(GtkWidget *w, gpointer p){ debug("Got build filter callback");}void gui_gtk_new_node_handler(gint id){ if(g_hash_table_lookup(topo->unconf_nodes, GINT_TO_POINTER(id))) return; if(g_hash_table_lookup(topo->nodes, GINT_TO_POINTER (id))) return; // We just create a new node with zero values here, and then // when the update event comes it will get the correct data debug("need to add node to something"); gui_topo_node_new(topo, id, -1, -1); num_nodes++;}void gtk_sounder_send(GtkButton *button, gpointer data){ debug("WOULD HAVE CLICKED: current node is %d", current_node); //net_event_send_command(current_node, CLICK);}GtkWidget *get_widget(GladeXML *xml, char *name){ GtkWidget *ret = glade_xml_get_widget(xml, name); if(!ret) { debug("Couldn't get widget %s", name); exit(-1); } return ret;}void gui_add_node(bionet_node_t *node){ gint light, temp; light = temp = 0; GSList *i; for (i = node->resources; i != NULL; i = i->next) { bionet_resource_t *resource = i->data; model_update_resource(resource); if(strcmp(resource->id, "Light") == 0) { light = atoi(bionet_resource_value_to_string(resource)); } else if(strcmp(resource->id, "Temperature") == 0) { temp = atoi(bionet_resource_value_to_string(resource)); } } g_slist_free(i); gui_topo_node_new(topo, atoi(node->id), light, temp); }/* Start running the gtk gui. */void gui_gtk_run(int *argcp, const char ***argvp){ current_node = 255;//GUI_SELECT_NONE; num_nodes = 0; // standard gtk+ init, followed by a glade init // cast the argvp because gtk_init doesn't want a const // and everything else does */ gtk_init(argcp, (char ***)argvp); glade_init(); // Load the gui from a glade file xml = glade_xml_new(GLADE_FILE, NULL, NULL); if(!xml) { debug("An error occurred while creating the interface."); return; } // define our own quit event handler to properly exit // TODO: do we really want quit confirmation?? (i don't) //dialog_quit = get_widget(xml, "dialog_quit"); //gtk_widget_hide (dialog_quit); system_status_label = get_widget(xml, "system_status_label"); window_data = get_widget(xml, "window_data"); dialog_about = get_widget(xml, "dialog_about"); gtk_widget_hide(dialog_about); statusbar = get_widget(xml, "statusbar_visual"); // make the pane resize properly //GtkWidget *pane = get_widget (xml, "data_pane"); //gtk_paned_set_position(GTK_PANED(pane), 120); //Get the parent widget from glade and set the scroll bars to show up // automatically if necessary. */ GtkWidget *topo_viewport = get_widget(xml, "topo_viewport"); // Now create the topology object topo = gui_topo_new(topo_viewport); gtk_container_add(GTK_CONTAINER(topo_viewport), topo->widget); gtk_widget_show_all(window_data); // connect all the glade signals now that we have created our widgets glade_xml_signal_autoconnect(xml); nodelist_view_init(); hablist_view_init(); //notify the bionet thread that the gui stuff is all setup g_mutex_lock(widget_mutex); g_cond_broadcast(widget_cond); g_mutex_unlock(widget_mutex); //initialize the generic view, model, and callbacks generic_view_init(); //initialize the commanding view window, models and callbacks commanding_view_init(); model_add_node_register_func(gui_add_node); // then just run gtk_main() as per usual gtk_main();}/* Set the currently selected node. */void gui_gtk_set_current_node(gint id, gboolean isTopo){ gchar *str; current_node = id; // Since the tree emits this signal again we can just call it // and then run when it calls us back // TODO: look into a cleaner mechanism for this stuff. if(isTopo) { if(id == GUI_SELECT_NONE) gui_topo_set_current_node(topo, current_node); debug("need to select node in tree!"); return; } gui_topo_set_current_node(topo, current_node); if (current_node == -1) current_node = 255; str = g_strdup_printf("Selected Node: %d", id); gui_gtk_set_status(str); g_free(str); debug("Selected a new node: %d", id); // Force a gui update while(gtk_events_pending()) gtk_main_iteration();}/* Set the content of the statusbar. */// NOTE: You must allocate the passed string, it will be freed with// the status changes...void gui_gtk_set_status(gchar *status){ static guint context_id = 0; static gchar *current = NULL; // If there is already a status message we need to cleanup first if(context_id && current) { gtk_statusbar_pop(GTK_STATUSBAR(statusbar), context_id); g_free(current); } // Now get this random context id and then push the status context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "b.s. context"); gtk_statusbar_push(GTK_STATUSBAR(statusbar), context_id, status); current = status;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -