classicladder_gtk.c
来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 1,261 行 · 第 1/3 页
C
1,261 行
{ InfosGene->LadderState = STATE_RUN; gtk_label_set_text(GTK_LABEL(GTK_BIN(ButtonRunStop)->child),"Stop"); }}void CheckDispSymbols_toggled( ){ InfosGene->DisplaySymbols = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( CheckDispSymbols ) );}void StoreDirectorySelected( #ifndef GTK2GtkFileSelection *selector, #elseGtkFileChooser *selector, #endifchar cForLoadingProject){ char * TempDir; TempDir = #ifndef GTK2 gtk_file_selection_get_filename (GTK_FILE_SELECTION(FileSelector)); #else gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(FileSelector)); #endif if ( cForLoadingProject ) VerifyDirectorySelected( TempDir ); else strcpy( InfosGene->LadderDirectory, TempDir );}void LoadNewLadder(){ StoreDirectorySelected( #ifndef GTK2 GTK_FILE_SELECTION(FileSelector) #else GTK_FILE_CHOOSER(FileSelector) #endif , TRUE/*cForLoadingProject*/); if (InfosGene->LadderState==STATE_RUN) ButtonRunStop_click(); InfosGene->LadderState = STATE_LOADING;//// LoadAllLadderDatas(LadderDirectory); if ( !LoadProjectFiles( InfosGene->LadderDirectory ) ) ShowMessageBox( "Load Error", "Failed to load the project file...", "Ok" ); UpdateGtkAfterLoading( TRUE/*cCreateTimer*/ ); UpdateWindowTitleWithProjectName();#ifndef RT_SUPPORT OpenHardware( 0 ); ConfigHardware( );#endif InfosGene->LadderState = STATE_STOP;}void ButtonSave_click(){//// SaveAllLadderDatas(LadderDirectory); if ( !SaveProjectFiles( InfosGene->LadderDirectory ) ) ShowMessageBox( "Save Error", "Failed to save the project file...", "Ok" );}void SaveAsLadder(void){ StoreDirectorySelected( #ifndef GTK2 GTK_FILE_SELECTION(FileSelector) #else GTK_FILE_CHOOSER(FileSelector) #endif , FALSE/*cForLoadingProject*/);//// SaveAllLadderDatas(LadderDirectory); if ( !SaveProjectFiles( InfosGene->LadderDirectory ) ) ShowMessageBox( "Save Error", "Failed to save the project file...", "Ok" ); UpdateWindowTitleWithProjectName();}#ifdef GTK2voidon_filechooserdialog_save_response(GtkDialog *dialog,gint response_id,gpointer user_data){ printf("SAVE %s %d\n",gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(FileSelector)),response_id); if(response_id==GTK_RESPONSE_ACCEPT || response_id==GTK_RESPONSE_OK)SaveAsLadder();gtk_widget_destroy(GTK_WIDGET(dialog));}voidon_filechooserdialog_load_response(GtkDialog *dialog,gint response_id,gpointer user_data){printf("LOAD %s %d\n",gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(FileSelector)),response_id); if(response_id==GTK_RESPONSE_ACCEPT || response_id==GTK_RESPONSE_OK)LoadNewLadder();gtk_widget_destroy(GTK_WIDGET(dialog));}#endifvoid CreateFileSelection(char * Prompt,int Save){ /* From the example in gtkfileselection help */ /* Create the selector */ #ifndef GTK2 FileSelector = gtk_file_selection_new(Prompt); if (Save) gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->ok_button), "clicked", GTK_SIGNAL_FUNC (SaveAsLadder), NULL); else gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->ok_button), "clicked", GTK_SIGNAL_FUNC (LoadNewLadder), NULL); /* Ensure that the dialog box is destroyed when the user clicks a button. */ gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->ok_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) FileSelector); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) FileSelector); #else if(Save) { FileSelector = gtk_file_chooser_dialog_new (Prompt, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); } else { FileSelector = gtk_file_chooser_dialog_new (Prompt, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);} gtk_window_set_type_hint (GTK_WINDOW (FileSelector), GDK_WINDOW_TYPE_HINT_DIALOG);/* g_signal_connect ((gpointer) filechooserdialog, "file_activated", G_CALLBACK (on_filechooserdialog_file_activated), NULL); */ if(Save) g_signal_connect ((gpointer) FileSelector, "response", G_CALLBACK (on_filechooserdialog_save_response), NULL); else g_signal_connect ((gpointer) FileSelector, "response", G_CALLBACK (on_filechooserdialog_load_response), NULL); g_signal_connect_swapped ((gpointer) FileSelector, "close", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (FileSelector)); #endif /* Display that dialog */ gtk_widget_show (FileSelector);}void ButtonNew_click(){ ShowConfirmationBox("New","Do you really want to clear all datas ?",InitAllLadderDatas);}void ButtonLoad_click(){ CreateFileSelection("Please select the project to load",FALSE);}void ButtonSaveAs_click(){ CreateFileSelection("Please select the project to save",TRUE);}void ButtonReset_click(){ int StateBefore = InfosGene->LadderState; InfosGene->LadderState = STATE_STOP; // wait, to be sure calcs have ended... usleep( 100000 ); PrepareRungs( ); PrepareTimers( ); PrepareMonostables( ); PrepareCounters( );#ifdef SEQUENTIAL_SUPPORT PrepareSequential( );#endif if ( StateBefore==STATE_RUN ) InfosGene->LadderState = STATE_RUN;}void ButtonConfig_click(){ OpenConfigWindowGtk( );}void ButtonAbout_click(){ /* From the example in gtkdialog help */ GtkWidget *dialog, *label, *okay_button; /* Create the widgets */ dialog = gtk_dialog_new(); label = gtk_label_new (" Classicladder v" RELEASE_VER_STRING "\n" RELEASE_DATE_STRING "\n" "EMC2 Development of Classicladder\n" "Copyright (C) 2001-2006 Marc Le Douarain\nmarc . le - douarain /At\\ laposte \\DoT/ net\n" "http://www.sourceforge.net/projects/classicladder\n" "http://www.multimania.com/mavati/classicladder\n" "Released under the terms of the\nGNU Lesser General Public License v2.1\n" "Updates:\n" "***New to this update ***\n" "-load realtime component only once-with GUI or not\n" "-compare/equate works properly, accepts symbols\n" "-Two variable windows, toggle button to show/hide\n" "-HAL s32 IN and OUT equipt words \n" "-rungs refresh at realtime period\n" "-symbols checkbox in section display controls variable window also\n" "-number of HAL s32 IN / OUT pins configurable when loading classicladder RT module\n" ); gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_CENTER ); okay_button = gtk_button_new_with_label("Okay"); /* Ensure that the dialog box is destroyed when the user clicks ok. */ gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT(dialog)); gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), okay_button); gtk_widget_grab_focus(okay_button); /* Add the label, and show everything we've added to the dialog. */ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label); gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER); gtk_widget_show_all (dialog);}void ShowMessageBox(char * title,char * text,char * button){ /* From the example in gtkdialog help */ GtkWidget *dialog, *label, *okay_button; /* Create the widgets */ dialog = gtk_dialog_new(); label = gtk_label_new (text); okay_button = gtk_button_new_with_label(button); /* Ensure that the dialog box is destroyed when the user clicks ok. */ gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT(dialog)); gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), okay_button); gtk_widget_grab_focus(okay_button); /* Add the label, and show everything we've added to the dialog. */ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label); gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); gtk_window_set_title(GTK_WINDOW(dialog),title); gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER); gtk_widget_show_all (dialog);}void DoFunctionOfConfirmationBox(void * (*function_to_do)(void *)){ gtk_widget_destroy(ConfirmDialog); (function_to_do)(NULL);}void ShowConfirmationBox(char * title,char * text,void * function_if_yes){ /* From the example in gtkdialog help */ GtkWidget *label, *yes_button, *no_button; /* Create the widgets */ ConfirmDialog = gtk_dialog_new(); label = gtk_label_new (text); yes_button = gtk_button_new_with_label("Yes"); no_button = gtk_button_new_with_label("No"); /* Ensure that the dialog box is destroyed when the user clicks ok. */ gtk_signal_connect_object (GTK_OBJECT (no_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT(ConfirmDialog)); gtk_signal_connect_object (GTK_OBJECT (yes_button), "clicked", GTK_SIGNAL_FUNC (DoFunctionOfConfirmationBox), function_if_yes); gtk_container_add (GTK_CONTAINER (GTK_DIALOG(ConfirmDialog)->action_area), yes_button); gtk_container_add (GTK_CONTAINER (GTK_DIALOG(ConfirmDialog)->action_area), no_button); gtk_widget_grab_focus(no_button); /* Add the label, and show everything we've added to the dialog. */ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(ConfirmDialog)->vbox), label); gtk_window_set_modal(GTK_WINDOW(ConfirmDialog),TRUE); gtk_window_set_title(GTK_WINDOW(ConfirmDialog),title); gtk_window_set_position(GTK_WINDOW(ConfirmDialog),GTK_WIN_POS_CENTER); gtk_widget_show_all (ConfirmDialog);}void DoQuit( void ){ gtk_widget_destroy( RungWindow ); //sends signal 'destroy' to end the GUI}void ConfirmQuit( void ){ if ( InfosGene->AskConfirmationToQuit ) ShowConfirmationBox( "Sure?", "Do you really want to quit ?\nIf not saved, all modifications will be lost \n", DoQuit ); else ShowConfirmationBox( "Sure?", "Do you really want to quit ?\n", DoQuit );}gint RungWindowDeleteEvent( GtkWidget * widget, GdkEvent * event, gpointer data ){ ConfirmQuit( ); //If confirm quit returns then // we do not want the window to be destroyed. return TRUE;}void OpenEditWindow( void ){ gtk_widget_show (EditWindow);#ifdef GTK2 gtk_window_present( GTK_WINDOW(EditWindow) );#endif}void RungWindowInitGtk(){ GtkWidget *vbox,*hboxtop,*hboxbottom,*hboxbottom2; GtkWidget *hboxmiddle; GtkWidget *ButtonQuit; GtkWidget *ButtonNew,*ButtonLoad,*ButtonSave,*ButtonSaveAs,*ButtonReset,*ButtonConfig,*ButtonAbout; GtkWidget *ButtonEdit,*ButtonSymbols,*ButtonVars;//,*ButtonRefresh;#ifdef GNOME_PRINT_USE GtkWidget *ButtonPrint,*ButtonPrintPreview;#endif RungWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title ((GtkWindow *)RungWindow, "Section Display"); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (RungWindow), vbox); gtk_widget_show (vbox); gtk_signal_connect (GTK_OBJECT (RungWindow), "destroy", GTK_SIGNAL_FUNC (quit_appli), NULL); hboxtop = gtk_hbox_new (FALSE,0); gtk_container_add (GTK_CONTAINER (vbox), hboxtop); gtk_widget_show(hboxtop); gtk_box_set_child_packing(GTK_BOX(vbox), hboxtop, /*expand*/ FALSE, /*fill*/ FALSE, /*pad*/ 0, GTK_PACK_START); entrylabel = gtk_entry_new(); gtk_widget_set_usize((GtkWidget *)entrylabel,80,0); gtk_entry_set_max_length((GtkEntry *)entrylabel,LGT_LABEL-1); gtk_entry_prepend_text((GtkEntry *)entrylabel,""); gtk_box_pack_start (GTK_BOX (hboxtop), entrylabel, FALSE, FALSE, 0); gtk_widget_show(entrylabel); entrycomment = gtk_entry_new(); gtk_entry_set_max_length((GtkEntry *)entrycomment,LGT_COMMENT-1); gtk_entry_prepend_text((GtkEntry *)entrycomment,""); gtk_box_pack_start (GTK_BOX (hboxtop), entrycomment, TRUE, TRUE, 0); gtk_widget_show(entrycomment); CheckDispSymbols = gtk_check_button_new_with_label("Display symbols"); gtk_box_pack_start( GTK_BOX (hboxtop), CheckDispSymbols, FALSE, FALSE, 0 ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( CheckDispSymbols ), InfosGene->DisplaySymbols ); gtk_signal_connect( GTK_OBJECT(CheckDispSymbols), "toggled", (GtkSignalFunc)CheckDispSymbols_toggled, NULL ); gtk_widget_show( CheckDispSymbols );#if defined( RT_SUPPORT ) || defined( __XENO__ ) DurationOfLastScan = gtk_entry_new(); gtk_widget_set_usize((GtkWidget *)DurationOfLastScan,60,0);// gtk_entry_set_max_length((GtkEntry *)DurationOfLastScan,LGT_COMMENT-1);// gtk_entry_set_max_length((GtkEntry *)DurationOfLastScan,20); gtk_entry_prepend_text((GtkEntry *)DurationOfLastScan,""); gtk_box_pack_start (GTK_BOX (hboxtop), DurationOfLastScan, FALSE, FALSE, 0); gtk_widget_set_sensitive(DurationOfLastScan, FALSE); gtk_widget_show(DurationOfLastScan);#endif hboxmiddle = gtk_hbox_new (FALSE,0); gtk_container_add (GTK_CONTAINER (vbox), hboxmiddle); gtk_widget_show(hboxmiddle); gtk_box_set_child_packing(GTK_BOX(vbox), hboxmiddle, /*expand*/ TRUE, /*fill*/ TRUE, /*pad*/ 0, GTK_PACK_START); /* Create the drawing area */ drawing_area = gtk_drawing_area_new (); gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area) , BLOCK_WIDTH_DEF*RUNG_WIDTH+OFFSET_X+5 , BLOCK_HEIGHT_DEF*RUNG_HEIGHT+OFFSET_Y+30); gtk_box_pack_start (GTK_BOX (hboxmiddle), drawing_area, TRUE, TRUE, 0); gtk_widget_show (drawing_area); AdjustVScrollBar = (GtkAdjustment *)gtk_adjustment_new( 0, 0, 0, 0, 0, 0); VScrollBar = gtk_vscrollbar_new( AdjustVScrollBar ); gtk_box_pack_start (GTK_BOX (hboxmiddle), VScrollBar, FALSE, FALSE, 0); gtk_widget_show (VScrollBar); AdjustHScrollBar = (GtkAdjustment *)gtk_adjustment_new( 0, 0, 0, 0, 0, 0); HScrollBar = gtk_hscrollbar_new( AdjustHScrollBar ); gtk_box_pack_start (GTK_BOX (vbox), HScrollBar, FALSE, FALSE, 0); gtk_widget_show (HScrollBar); UpdateVScrollBar(); gtk_signal_connect(GTK_OBJECT (AdjustVScrollBar), "value-changed", (GtkSignalFunc) VScrollBar_value_changed_event, 0); gtk_signal_connect(GTK_OBJECT (AdjustHScrollBar), "value-changed", (GtkSignalFunc) HScrollBar_value_changed_event, 0); hboxbottom = gtk_hbox_new (FALSE,0); gtk_container_add (GTK_CONTAINER (vbox), hboxbottom); gtk_widget_show(hboxbottom); gtk_box_set_child_packing(GTK_BOX(vbox), hboxbottom, /*expand*/ FALSE, /*fill*/ FALSE, /*pad*/ 0, GTK_PACK_START); hboxbottom2 = gtk_hbox_new (FALSE,0); gtk_container_add (GTK_CONTAINER (vbox), hboxbottom2); gtk_widget_show(hboxbottom2); gtk_box_set_child_packing(GTK_BOX(vbox), hboxbottom2, /*expand*/ FALSE, /*fill*/ FALSE, /*pad*/ 0, GTK_PACK_START);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?