GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 22, 2014 6:14 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: How do you insert gTK in an Even Driven Application
PostPosted: Thu Jun 05, 2008 9:49 am 
Offline

Joined: Thu Jun 05, 2008 9:34 am
Posts: 1
Hi people,

iam from germany and iam writting a GUi application ,who read some Kind of value from a Ondulator which had many variable(like lengh,velosity..)and i have to show all that in the Gui with some Gtkentry.

The Problem is :it work well with a the Console ,but when i built the GUi in GTk ..i can just see the value changed when i move the mouse ,which signal i didntz connect with my Widget.

the one thing too is the application that i write is event driving too,that why i could get the value changed in the console without the GUI

Now with the GUI is little complicated ...Gtk is event driven ..my application too and it has his Callback prpetry too .



/* example-start packbox packbox.c */
#include <stdafx.h>
#include <gtk/gtk.h>
#include "Achsex.h"
#include <stdlib.h>

#include <glib.h>


GtkWidget *window;
GtkWidget *table;
GtkWidget *entry[32];
GtkWidget *colorButton[16];
GtkWidget *layout[4];
GtkWidget *label[4];
GtkWidget * fixed;
gchar value[28][28];//was put here today for test


void entrySix_callback(GtkEditable *widget, void *userdarta);

int main( int argc, char *argv[] )
{



long nErr, nPort;
AmsAddr Addr;
PAmsAddr pAddr = &Addr;
ULONG hNotification, hUser;
AdsNotificationAttrib adsNotificationAttrib;


//int i;
//gchar value[10];





gtk_init (&argc, &argv);

/* Create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

/* Set the window title */
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title (GTK_WINDOW (window), "AchsenX");
gtk_window_set_default_size(GTK_WINDOW(window), 1100, 530);



/* Create a 2x2 table */
table = gtk_table_new (2, 2, TRUE);

/* Put the table in the main window */
gtk_container_add (GTK_CONTAINER (window), table);

layout[0]=gtk_layout_new(NULL,NULL);






/*Anlagenstatus*/
entry[0]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[0])," Anlagenstatus" );
gtk_widget_set_size_request (entry[0],122,24);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[0],6,14);


entry[1]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[1]), " enable" );
gtk_widget_set_size_request (entry[1],68,20);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[1],275,16);


entry[2]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[2])," error" );
gtk_widget_set_size_request (entry[2],68,20);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[2],275,36);


entry[3]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[3])," operative" );
gtk_widget_set_size_request (entry[3],68,20);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[3],275,56);


entry[4]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[4])," Einstellungen" );
gtk_widget_set_size_request (entry[4],337,26);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[4],0,225);

entry[5]=gtk_entry_new( );

gtk_widget_set_size_request (entry[5],122,24);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[5],6,38);





entry[6]=gtk_entry_new( );

gtk_widget_set_size_request (entry[6],63,21);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[6],25,153);


entry[7]=gtk_entry_new( );

gtk_widget_set_size_request (entry[7],63,21);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[7],25,174);

entry[8]=gtk_entry_new( );

gtk_widget_set_size_request (entry[8],63,21);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[8],280,152);


entry[9]=gtk_entry_new( );

gtk_widget_set_size_request (entry[9],63,21);
gtk_layout_put( GTK_LAYOUT(layout[0]),entry[9],280,173);


//struct index lib = { 55, "Einführung in C" };
/*GdkColor s;
s.pixel=0x1cf2e813109c;
s.red=0x1cf2;
s.green=0xe813;
s.blue=0x109c;*/

GdkColor s ={0x1cf2e813109c,0x1cf2,0xe813,0x109c};
colorButton[0]=gtk_color_button_new_with_color (&s);
gtk_widget_set_size_request (colorButton[0],26,23);
gtk_layout_put( GTK_LAYOUT(layout[0]),colorButton[0],243,15);


GdkColor x ={0xe4e40b0b1919,0xe4e4,0x0b0b,0x1919};
colorButton[1]=gtk_color_button_new_with_color (&x);
gtk_widget_set_size_request (colorButton[1],26,23);
gtk_layout_put( GTK_LAYOUT(layout[0]),colorButton[1],243,36);


GdkColor y ={0x40407171c7c7,0x4040,0x7171,0xc7c7};
colorButton[2]=gtk_color_button_new_with_color (&y);
gtk_widget_set_size_request (colorButton[2],26,23);
gtk_layout_put( GTK_LAYOUT(layout[0]),colorButton[2],243,56);


GdkColor l ={0xe4e40b0b1919,0xe4e4,0x0b0b,0x1919};
colorButton[3]=gtk_color_button_new_with_color (&l);
gtk_widget_set_size_request (colorButton[3],26,23);
gtk_layout_put( GTK_LAYOUT(layout[0]),colorButton[3],213,57);

gtk_table_attach_defaults( GTK_TABLE(table),layout[0],0,1,0,1 );


//Layout1


layout[1]=gtk_layout_new(NULL,NULL);
gtk_layout_set_size (GTK_LAYOUT(layout[1]),2,2);

entry[10]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[10])," " );
gtk_widget_set_size_request (entry[10],100,27);
gtk_layout_put( GTK_LAYOUT(layout[1]),entry[10],94,12);


entry[11]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[11]),"Soll-TAPER(mm)" );
gtk_widget_set_size_request (entry[11],85,27);
gtk_layout_put( GTK_LAYOUT(layout[1]),entry[11],9,12);


entry[12]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[12]),"Ist-TAPER(mm)" );
gtk_widget_set_size_request (entry[12],86,28);
gtk_layout_put( GTK_LAYOUT(layout[1]),entry[12],9,46);


entry[13]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[13])," " );
gtk_widget_set_size_request (entry[13],100,28);
gtk_layout_put( GTK_LAYOUT(layout[1]),entry[13],95,46);






gtk_table_attach_defaults( GTK_TABLE(table),layout[1],0,1,1,2 );




//layout2

layout[2]=gtk_layout_new(NULL,NULL);


entry[14]=gtk_entry_new( );

gtk_widget_set_size_request (entry[14],100,29);
gtk_layout_put( GTK_LAYOUT(layout[2]),entry[14],175,15);

entry[15]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[15])," Soll-GAP(mm) " );
gtk_widget_set_size_request (entry[15],100,29);
gtk_layout_put( GTK_LAYOUT(layout[2]),entry[15],75,15);



entry[16]=gtk_entry_new( );

gtk_widget_set_size_request (entry[16],100,27);
gtk_layout_put( GTK_LAYOUT(layout[2]),entry[16],177,54);


entry[17]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[17]),"Ist-GAP(mm)" );
gtk_widget_set_size_request (entry[17],100,27);
gtk_layout_put( GTK_LAYOUT(layout[2]),entry[17],77,54);

gtk_table_attach_defaults( GTK_TABLE(table),layout[2],2,3,1,2 );



//layout 3





layout[3]=gtk_layout_new(NULL,NULL);


entry[18]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[18])," Status" );
gtk_widget_set_size_request (entry[18],212,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[18],0,1);



entry[19]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[19])," Position/mm" );
gtk_widget_set_size_request (entry[19],139,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[19],212,1);


entry[20]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[20])," Betriebsbereit" );
gtk_widget_set_size_request (entry[20],133,23);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[20],0,25);


entry[21]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[21]),"Kop" );
gtk_widget_set_size_request (entry[21],50,23);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[21],133,25);


entry[21]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[21]),"Ext" );
gtk_widget_set_size_request (entry[21],30,23);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[21],183,25);



entry[22]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[22]),"Absolut Linear" );
gtk_widget_set_size_request (entry[22],138,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[22],213,25);


entry[23]=gtk_entry_new( );

gtk_widget_set_size_request (entry[23],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[23],214,53);


entry[24]=gtk_entry_new( );

gtk_widget_set_size_request (entry[24],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[24],214,80);


entry[25]=gtk_entry_new( );

gtk_widget_set_size_request (entry[25],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[25],215,107);

entry[26]=gtk_entry_new( );

gtk_widget_set_size_request (entry[26],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[26],216,135);


entry[27]=gtk_entry_new( );
gtk_entry_set_text( GTK_ENTRY(entry[27])," " );
gtk_widget_set_size_request (entry[27],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[27],283,53);

entry[28]=gtk_entry_new( );

gtk_widget_set_size_request (entry[28],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[28],284,80);

entry[29]=gtk_entry_new( );

gtk_widget_set_size_request (entry[29],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[29],284,107);

entry[30]=gtk_entry_new( );

gtk_widget_set_size_request (entry[30],64,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),entry[30],285,135);

//Label

label[0]=gtk_label_new ("Achse 1 (Links Oben)");
gtk_widget_set_size_request (label[0],112,22);
gtk_layout_put( GTK_LAYOUT(layout[3]),label[0],25,54);

label[1]=gtk_label_new ("Achse 2 (Rechts Oben)");
gtk_widget_set_size_request (label[1],112,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),label[1],25,80);



label[2]=gtk_label_new ("Achse 3 (Links Unten)");
gtk_widget_set_size_request (label[2],112,24);
gtk_layout_put( GTK_LAYOUT(layout[3]),label[2],25,107);


label[3]=gtk_label_new ("Achse 4(Rechts Unten)");
gtk_widget_set_size_request (label[3],112,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),label[3],25,133);


GdkColor m ={0x1cf2e813109c,0x1cf2,0xe813,0x109c};
colorButton[4]=gtk_color_button_new_with_color (&m);
gtk_widget_set_size_request (colorButton[4],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[4],0,53);

GdkColor m1 ={0x1cf2e813109c,0x1cf2,0xe813,0x109c};
colorButton[5]=gtk_color_button_new_with_color (&m1);
gtk_widget_set_size_request (colorButton[5],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[5],1,80);


GdkColor m2 ={0x1cf2e813109c,0x1cf2,0xe813,0x109c};
colorButton[6]=gtk_color_button_new_with_color (&m2);
gtk_widget_set_size_request (colorButton[6],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[6],1,106);

GdkColor m3 ={0x1cf2e813109c,0x1cf2,0xe813,0x109c};
colorButton[6]=gtk_color_button_new_with_color (&m3);
gtk_widget_set_size_request (colorButton[6],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[6],1,133);

//bleu
GdkColor l1 ={0x40407171c7c7,0x4040,0x7171,0xc7c7};
colorButton[7]=gtk_color_button_new_with_color (&l1);
gtk_widget_set_size_request (colorButton[7],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[7],137,52);


GdkColor l2 ={0x40407171c7c7,0x4040,0x7171,0xc7c7};
colorButton[8]=gtk_color_button_new_with_color (&l2);
gtk_widget_set_size_request (colorButton[8],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[8],137,80);


GdkColor l3 ={0x40407171c7c7,0x4040,0x7171,0xc7c7};
colorButton[9]=gtk_color_button_new_with_color (&l3);
gtk_widget_set_size_request (colorButton[9],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[9],137,107);


GdkColor l4 ={0x40407171c7c7,0x4040,0x7171,0xc7c7};
colorButton[10]=gtk_color_button_new_with_color (&l4);
gtk_widget_set_size_request (colorButton[10],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[10],137,135);

//wrot

GdkColor w ={0x7c7c00000000,0x7c7c,0x0000,0x0000};
colorButton[11]=gtk_color_button_new_with_color (&w);
gtk_widget_set_size_request (colorButton[11],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[11],184,53);


GdkColor w1 ={0x7c7c00000000,0x7c7c,0x0000,0x0000};
colorButton[12]=gtk_color_button_new_with_color (&w1);
gtk_widget_set_size_request (colorButton[12],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[12],184,80);


GdkColor w2 ={0x7c7c00000000,0x7c7c,0x0000,0x0000};
colorButton[13]=gtk_color_button_new_with_color (&w2);
gtk_widget_set_size_request (colorButton[13],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[13],184,107);


GdkColor w3 ={0x7c7c00000000,0x7c7c,0x0000,0x0000};
colorButton[14]=gtk_color_button_new_with_color (&w3);
gtk_widget_set_size_request (colorButton[14],24,26);
gtk_layout_put( GTK_LAYOUT(layout[3]),colorButton[14],184,134);


g_signal_connect (G_OBJECT (GTK_EDITABLE(entry[6])),"changed",G_CALLBACK (entrySix_callback), NULL);
























gtk_table_attach_defaults( GTK_TABLE(table),layout[3],2,3,0,1 );













gtk_widget_show_all(window);



//--------------------------------------------------------------------------------------------------------------------------




// Open communication port for local PLC (Run-time system 1)
nPort = AdsPortOpen();
nErr = AdsGetLocalAddress(pAddr);

pAddr->port = AMSPORT_R0_PLC_RTS1;

// Specify attributes of the notification
adsNotificationAttrib.cbLength = 109;
adsNotificationAttrib.nTransMode = ADSTRANS_SERVERONCHA;
adsNotificationAttrib.nMaxDelay =0; // 20000000; // 2sec
adsNotificationAttrib.nCycleTime = 1000000;// 10000000; // 1sec

// 32-bit variable (including pointers) that are passed to the callback function
hUser = 3474573467;

// Start transmission of the PLC variables

nErr = AdsSyncAddDeviceNotificationReq(pAddr, 0x4020, 0x64, &adsNotificationAttrib, Callback, hUser, &hNotification);


// Wait for a key-press from the user
//_getch();

gtk_main ();

// Wait for a key-press from the user
//_getch();



// Finish transmission of the PLC variables
nErr = AdsSyncDelDeviceNotificationReq(pAddr, hNotification);


// Close communication port
nErr = AdsPortClose();

/*for(i=0;i<5;i++)
{ int j;
for(j=0;j<100;j++);
sprintf_s(value,"%d",i);
gtk_entry_set_text(GTK_ENTRY(entry[7]),value);
}*/



//gtk_main ();

return 0;
}
//will be call evry time this value change
void __stdcall Callback(AmsAddr* pAddr, AdsNotificationHeader* pNotification, ULONG hUser)
{



SYSTEMTIME SystemTime, LocalTime;
FILETIME FileTime;
LARGE_INTEGER LargeInteger;
TIME_ZONE_INFORMATION TimeZoneInformation;
//gchar value[10];
//gchar value[28][28]; //where he really was....

struct _plctoVisu * plcVisu =((_plctoVisu*)pNotification->data);


cout << "Notification: " << pNotification->hNotification << '\n';



//fTopPosLeftEdge
sprintf_s(value[0],"%3.4f",plcVisu->fTopPosLeftEdge);
gtk_entry_set_text(GTK_ENTRY(entry[6]),value[0]);



/* Kommentar Zweck Test

//fResolverPosIst

//stAchse1LT
sprintf_s(value[1],"%3.4f",plcVisu->first_LT.fResolverPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[23]),value[1]);

//stAchse2RT
sprintf_s(value[2],"%3.4f",plcVisu->second_RT.fResolverPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[24]),value[2]);

//stAchse3LB
sprintf_s(value[3],"%3.4f",plcVisu->third_LB.fResolverPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[25]),value[3]);

//stAchse4RB
sprintf_s(value[4],"%3.4f",plcVisu->third_LB.fResolverPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[26]),value[4]);


//flinearPosIst

//stAchse1LT
sprintf_s(value[5],"%3.4f",plcVisu->first_LT.flinearPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[27]),value[5]);

//stAchse2RT
sprintf_s(value[6],"%3.4f",plcVisu->second_RT.flinearPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[28]),value[6]);

//stAchse3LB
sprintf_s(value[7],"%3.4f",plcVisu->third_LB.flinearPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[29]),value[7]);

//stAchse4RB

sprintf_s(value[8],"%3.4f",plcVisu->four_RB.flinearPosIst);
gtk_entry_set_text(GTK_ENTRY(entry[30]),value[8]);


//imodeState

sprintf_s(value[9],"%d",(INT32)(plcVisu->iModeState) );
gtk_entry_set_text(GTK_ENTRY(entry[5]),value[9]);


//fBottomPosLeftEdge

sprintf_s(value[10],"%3.4f",plcVisu->fBottomPosLeftEdge);
gtk_entry_set_text(GTK_ENTRY(entry[7]),value[10]);


//fBottomPosRightEdge

sprintf_s(value[11],"%3.4f",plcVisu->fBottomPosRightEdge );
gtk_entry_set_text(GTK_ENTRY(entry[9]),value[11]);

//fTopPosRightEdge
sprintf_s(value[12],"%3.4f",plcVisu->fTopPosRightEdge );
gtk_entry_set_text(GTK_ENTRY(entry[8]),value[12]);




//fTaperValue
sprintf_s(value[13],"%3.4f",plcVisu->fTaperValue );
gtk_entry_set_text(GTK_ENTRY(entry[13]),value[13]);

//fGapValue
sprintf_s(value[14],"%3.4f",plcVisu->fGapValue );
gtk_entry_set_text(GTK_ENTRY(entry[16]),value[14]);






*/





//cout << "Value: "<< sizeof(_plctoVisu)<<'\n';


/* struct _plctoVisu * plcVisu =((_plctoVisu*)pNotification->data);
sprintf_s(value,"%f",plcVisu->fTopPosLeftEdge);

cout << "fTopPosLeftEdge:"<<plcVisu->fTopPosLeftEdge<<"\n";
cout << "Value is:"<<value<<"\n";

gtk_entry_set_text(GTK_ENTRY(entry[7]),value);*/

/*Convert time stamp to SYSTEMTIME*/


LargeInteger.QuadPart = pNotification->nTimeStamp;
FileTime.dwLowDateTime = (DWORD)LargeInteger.LowPart;
FileTime.dwHighDateTime = (DWORD)LargeInteger.HighPart;
FileTimeToSystemTime(&FileTime, &SystemTime);

// Calculate time in local representation
GetTimeZoneInformation(&TimeZoneInformation);
SystemTimeToTzSpecificLocalTime(&TimeZoneInformation, &SystemTime, &LocalTime);

}



void entrySix_callback(GtkEditable *widget, void *userdarta)
{

//gtk_entry_set_text(GTK_ENTRY(entry[6]),value[0]);
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 12:16 pm 
Offline
GTK+ Geek

Joined: Wed May 28, 2008 5:49 pm
Posts: 66
Could you please put the text in C code tags?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group