GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Jul 30, 2014 5:11 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: How to Enable a button and show a window for few minutes??
PostPosted: Wed Nov 25, 2009 7:03 am 
Offline
Familiar Face

Joined: Mon Nov 23, 2009 7:52 am
Posts: 47
hi... I am creating a GUI using Glade.. I have few questions.. How to enable a button after several steps. The button is disabled at first. After all the wanted task has been done then only the button is enabled.. How to do that?
second, can we just show a window for few minutes and then proceed to next window.. I have a main window. That one has no button, only to display about my project.. So how can I proceed to the next window..?
Thank you in advance..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 25, 2009 6:47 pm 
Offline
Familiar Face

Joined: Sun Dec 07, 2008 5:26 pm
Posts: 26
question 1 - disable buttons:

[code=] gtk_widget_set_sensitive (widgetButton, FALSE);[/code]

Question 2 - Show windows after a delay

use a timer, in intialization

[code=] UpdateTimer = g_timeout_add (TIME_IN_MS, HandleTimer, gpointer)0 );[/code]

In the time callback

[code=]gboolean HandleTimer( gpointer user_data )
{
my_window = create_my_window();
gtk_widget_show (my_window);
return(FALSE);
}[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 26, 2009 7:51 am 
Offline
Familiar Face

Joined: Mon Nov 23, 2009 7:52 am
Posts: 47
Thankz mate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 26, 2009 7:51 am 
Offline
Familiar Face

Joined: Mon Nov 23, 2009 7:52 am
Posts: 47
Now problem lies how to enable the button..

Image

As in this image,i want to enable the main menu button after both threshold button and eer button has been clicked..

Please guide me...Thankz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 26, 2009 9:00 am 
Offline
Familiar Face

Joined: Mon Nov 23, 2009 7:52 am
Posts: 47
can i know what is meant by UpdateTimer, HandleTimer, please?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 27, 2009 12:17 am 
Offline
Familiar Face

Joined: Sun Dec 07, 2008 5:26 pm
Posts: 26
enable button:

[code=]gtk_widget_set_sensitive (widgetButton, TRUE); [/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 17, 2009 5:56 pm 
Offline
Familiar Face

Joined: Mon Nov 23, 2009 7:52 am
Posts: 47
can anyone show some example how to make the window visible for few minutes before transit to next window, please.. I tried but could not make it work..
And thanks for d advice on how to disable a button. It works. Thankz..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 18, 2009 5:01 am 
Offline
GTK+ Geek

Joined: Mon Jul 27, 2009 6:38 am
Posts: 91
moganesh,

To display anything for a while we need to set a timer and call back for that timer.. so to display a popup window for few seconds you need to do this .

1. Display your window gtk_widget_show( window );
2. set timer and a call back function (handler) for timer.
g_timeout_add( 1, (GSourceFunc)destroy_window_call_back, NULL );
3. in destroy_window_call_back function destroy your window.
gtk_widget_destroy(window);

hope this help you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 21, 2009 2:25 am 
Offline
Familiar Face

Joined: Mon Nov 23, 2009 7:52 am
Posts: 47
Thankz pradeep. The code realy worked. But i found some problem. for this case, the windowmain disappaer when time comes and windowmainmenu appears.. But the problem is windowmainmenu reappears every 10500ms. So any advice, please on how make in not appear every 10500ms..
Below will be the code.. I use glade to create the gui. If u want xml file i can upload to.

Code:
#include <gtk/gtk.h>
#include <stdio.h>


// GLOBAL GTK WIDGETS DECLARATION
GtkWidget       *windowmainmenu;   
GtkWidget       *windowadduser;
GtkWidget       *windowmain;
GtkWidget       *windowdeleteuser;
GtkWidget       *windowcalculate;
GtkWidget       *windowauthenticate;
GtkWidget       *windowcomparing;

//text entry
         
GtkWidget      *teName;
GtkWidget      *teIC;

//button
         
GtkWidget      *btnAddUser;
GtkWidget      *btnSave;
GtkWidget      *btnMainMenu;
GtkWidget      *btnDeleteUser;
GtkWidget      *btnDelete;
GtkWidget      *btnMainMenu2;
GtkWidget      *btnThreshold;
GtkWidget      *btnEER;
GtkWidget      *btnMainMenu3;
GtkWidget      *btnMainMenu4;
GtkWidget      *btnVerify;

GtkWidget             *pgb1;


//dialog box
GtkWidget      *dialogusersaved;
GtkWidget      *dialogdeletinguser;
GtkWidget      *dialoguserdeleted;
GtkWidget      *dialogthreshold;
GtkWidget      *dialogEER;
GtkWidget      *dialogverifed;
GtkWidget      *dialogfailed;

//====================================================================
//Your SIGNAL HANDLER FUNCTION...




void pgb_10 (GtkObject *object, gpointer user_data)
{
         gdouble new_val;
   
   
   new_val = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (pgb1)) + 0.01;
     
      if (new_val > 1.0)
   new_val = 1.0;

   gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pgb1), new_val);

   
}



void pgb_100 (GtkObject *object, gpointer user_data)
{   
   
        gtk_widget_show(windowmainmenu);
   gtk_widget_hide(windowmain);

   

}
//when X is clicked on the main window(the one with loading)
//the application is closed
void on_windowmain_destroy (GtkObject *object, gpointer user_data)
{
    gtk_main_quit ();
}

//when X is clicked on the Main Menu window
//the application is closed
void on_windowmainmenu_destroy (GtkObject *object, gpointer user_data)
{
    gtk_main_quit ();
}

////................Exit button.............////////////////
//When exit button is clicked on the main menu window
//the application is closed

void on_buttonExit_clicked (GtkButton *button, gpointer user_data)
{
     gtk_main_quit();
}

///...............Add User Button................../////////
//When add user button is clicked on the main menu window
// add user window is opened

void on_buttonAddUser_clicked (GtkButton *button, gpointer user_data)
{
     gtk_widget_show(windowadduser);
     gtk_widget_hide(windowmainmenu);
}

//when X is clicked on the Add User window
//the application is closed and back to Main Menu

void on_windowadduser_delete_event (GtkWindow *window, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(windowadduser);
}


//When main menu button is clicked on the add user window
//Main Menu windowis showed

void on_buttonMainMenu_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(windowadduser);
   
}


//When Save button is clicked on add user window
//the name and IC is saved in the outFile
//dialog box appeared

void on_buttonSave_clicked (GtkButton *button, gpointer user_data)
{
   //get from text entry 'teName'
      
   const gchar *stringName;
   stringName = gtk_entry_get_text(GTK_ENTRY (teName));

   //get text entered by user in 'teName'

   //get from text entry 'teIC'
   const char *stringIC;
   stringIC = gtk_entry_get_text(GTK_ENTRY(teIC));   //get text entered by user in 'teIC'

      //save as output file
   FILE *outFile;
   outFile   = fopen ("./outFile.txt","w+");
   fprintf(outFile, "Name: %s\nIC: %s",stringName, stringIC);
   fclose (outFile);

   rename("outFile.txt","output.txt");
     
           
   gtk_widget_show(dialogusersaved);
   

}

//when OK is clicked the the dialog box disappeared
//and the main menu window appeared

void on_buttonOK1_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowcalculate);
   gtk_widget_set_sensitive(btnMainMenu3,FALSE);   
   gtk_widget_hide(dialogusersaved);
   
}

///dialog box disappear when ESC is pressed//
void on_dialogusersaved_close (GtkDialog *dialog, gpointer user_data)
{
   gtk_widget_show(windowcalculate);
   gtk_widget_set_sensitive(btnMainMenu3,FALSE);   
   gtk_widget_hide(dialogusersaved);
   
}

////...........Delete User............./////
//When delete user button is clicked on the main menu window
// delete user window is opened

void on_buttonDeleteUser_clicked (GtkButton *button, gpointer user_data)
{
     gtk_widget_show(windowdeleteuser);
     gtk_widget_hide(windowmainmenu);

}

//when X is clicked on the Delete User window
//the application is closed and back to Main Menu

void on_windowdeleteuser_delete_event (GtkWindow *window, gpointer user_data)
{
     
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(windowdeleteuser);
}

//When main menu button is clicked on the delete user window
//Main Menu windowis showed

void on_buttonMainMenu2_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(windowdeleteuser);
   
}

//When Delete button is clicked on add user window
//dialog box appeared
void on_buttonDelete_clicked (GtkButton *button, gpointer user_data)
{

   gtk_widget_show(dialogdeletinguser);

}


//Dialog box confirming want to delete or not
//Yes..Delete
//No.. Dont Delete

void on_buttonYes_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(dialoguserdeleted);   
   gtk_widget_hide(dialogdeletinguser);
   
}

void on_buttonNo_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowdeleteuser);   
   gtk_widget_hide(dialogdeletinguser);
   
}


///dialog box disappear when ESC is pressed//
void on_dialogdeletinguser_close (GtkDialog *dialog, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);   
   gtk_widget_hide(dialogdeletinguser);
   
}

//when Yes is pressed new dialog box appear confirming that the user
//has been deleted from the database
//when OK is clicked the the dialog box disappeared
//and the main menu window appeared

void on_buttonOK2_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowcalculate);
   gtk_widget_set_sensitive(btnMainMenu3,FALSE);
   gtk_widget_hide(dialoguserdeleted);
   
}

///dialog box disappear when ESC is pressed//

void on_dialoguserdeleted_close (GtkDialog *dialog, gpointer user_data)
{
   gtk_widget_show(windowcalculate);
   
   gtk_widget_hide(dialogusersaved);
   
   
}

void on_buttonThreshold_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(dialogthreshold);
   
   
}

void on_buttonEER_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(dialogEER);
   gtk_widget_set_sensitive(btnMainMenu3,TRUE);
   
   
   
}

void on_buttonOK3_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowcalculate);   
   gtk_widget_hide(dialogthreshold);
   
}

void on_dialogthreshold_close (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowcalculate);   
   gtk_widget_hide(dialogthreshold);
   
}

void on_buttonOK4_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowcalculate);   
   gtk_widget_hide(dialogEER);
   
}

void on_dialogEER_close (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowcalculate);   
   gtk_widget_hide(dialogEER);
   
}


      
   

void on_buttonMainMenu3_clicked (GtkButton *button, gpointer user_data)
{   
   
   //if((on_buttonEER_clicked)==TRUE)
   //if((on_buttonThreshold_clicked)==TRUE)
   
   gtk_widget_show(windowmainmenu);   
   gtk_widget_hide(windowcalculate);
   gtk_widget_hide(windowadduser);
   gtk_widget_hide(windowdeleteuser);
}

///............Authenticate....../////
void on_buttonAuthenticate_clicked (GtkButton *button, gpointer user_data)
{
     gtk_widget_show(windowauthenticate);
     gtk_widget_hide(windowmainmenu);
}

void on_windowauthenticate_delete_event (GtkWindow *window, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(windowauthenticate);
}

void on_buttonMainMenu4_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(windowauthenticate);
   
}

void on_buttonVerify_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowcomparing);
      
}

void on_windowcomparing_delete_event (GtkButton *button, gpointer user_data)
{
   gtk_widget_hide(windowcomparing);
      
}


void on_buttonOK5_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(dialogverifed);   
}

void on_dialogverifed_close (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(dialogverifed);   
}

void on_buttonOK6_clicked (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(dialogfailed);   
}

void on_dialogfailed_close (GtkButton *button, gpointer user_data)
{
   gtk_widget_show(windowmainmenu);
   gtk_widget_hide(dialogfailed);   
}


//...SIGNAL HANDLER FUNCTION end here
//====================================================================


int main(int argc, char *argv[]) //or: main(int argc, char **argv)

   // GTK Builder Declaration
   GtkBuilder      *builder;

   // Initialize GTK+ library
   gtk_init (&argc, &argv);

   // Create a new GtkBuilder object
   builder = gtk_builder_new ();
   // Load the interface
   gtk_builder_add_from_file (builder, "main1.xml", NULL);

   // Create pointer point to object get from 'builder'...
   windowmain= GTK_WIDGET (gtk_builder_get_object (builder, "windowmain"));
   windowmainmenu = GTK_WIDGET (gtk_builder_get_object (builder, "windowmainmenu"));
   windowadduser = GTK_WIDGET (gtk_builder_get_object (builder, "windowadduser"));
   windowdeleteuser = GTK_WIDGET (gtk_builder_get_object (builder, "windowdeleteuser"));
   windowcalculate = GTK_WIDGET (gtk_builder_get_object (builder, "windowcalculate"));
   windowauthenticate = GTK_WIDGET (gtk_builder_get_object (builder, "windowauthenticate"));
   windowcomparing = GTK_WIDGET (gtk_builder_get_object (builder, "windowcomparing"));

   //text entry
   teName = GTK_WIDGET (gtk_builder_get_object (builder, "entryName"));
   teIC = GTK_WIDGET (gtk_builder_get_object (builder, "entryIC"));

   //button
   btnSave = GTK_WIDGET (gtk_builder_get_object (builder, "buttonSave"));   
   btnMainMenu = GTK_WIDGET (gtk_builder_get_object (builder, "buttonMainMenu"));   
   btnAddUser = GTK_WIDGET (gtk_builder_get_object (builder, "buttonAddUser"));
   btnDeleteUser = GTK_WIDGET (gtk_builder_get_object (builder, "buttonDeleteUser"));
   btnDelete = GTK_WIDGET (gtk_builder_get_object (builder, "buttonDelete"));   
   btnMainMenu2 = GTK_WIDGET (gtk_builder_get_object (builder, "buttonMainMenu2"));
   btnThreshold = GTK_WIDGET (gtk_builder_get_object (builder, "buttonThreshold"));
   btnEER = GTK_WIDGET (gtk_builder_get_object (builder, "buttonEER"));
   btnMainMenu3 = GTK_WIDGET (gtk_builder_get_object (builder, "buttonMainMenu3"));
   btnMainMenu4 = GTK_WIDGET (gtk_builder_get_object (builder, "buttonMainMenu4"));
   btnVerify = GTK_WIDGET (gtk_builder_get_object (builder, "buttonVerify"));

   pgb1= GTK_WIDGET (gtk_builder_get_object (builder, "progressbar1"));




   //dialog box
   dialogusersaved = GTK_WIDGET (gtk_builder_get_object (builder, "dialogusersaved"));
   dialogdeletinguser = GTK_WIDGET (gtk_builder_get_object (builder, "dialogdeletinguser"));
   dialoguserdeleted = GTK_WIDGET (gtk_builder_get_object (builder, "dialoguserdeleted"));
   dialogthreshold = GTK_WIDGET (gtk_builder_get_object (builder, "dialogthreshold"));
   dialogEER = GTK_WIDGET (gtk_builder_get_object (builder, "dialogEER"));
   dialogverifed = GTK_WIDGET (gtk_builder_get_object (builder, "dialogverifed"));
   dialogfailed = GTK_WIDGET (gtk_builder_get_object (builder, "dialogfailed"));

   
   
   //...pointer to object end here
   //**************************************************************
   
   
   // Connect the signals to handler in the interface
   gtk_builder_connect_signals (builder, NULL);

   // Free Memory used by object 'builder'
   g_object_unref (G_OBJECT (builder));

   gtk_widget_show (windowmain); 
       
   g_timeout_add( 100,  (GSourceFunc)pgb_10, NULL );
   g_timeout_add( 10500,  (GSourceFunc)pgb_100, NULL );
   gtk_main ();

   return 0;
}
Added CodeBB -dreblen


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 21, 2009 6:18 am 
Offline
GTK+ Geek

Joined: Mon Jul 27, 2009 6:38 am
Posts: 91
hi,

For that you need to save timer ID which you get while creating Timer
and then in call back you need to destroy this time as follows.
Code:
g_source_remove( timer_id );



Change your functions prototype to return gboolean.
Code:
gboolean pgb_10 (GtkObject *object, gpointer user_data)
gboolean pgb_100 (GtkObject *object, gpointer user_data)


Then return FALSE in both the functions, as to tell Gtk that no more need to call this call back.

you can read more documentation on gnome.
http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-timeout-add


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 21, 2009 7:17 am 
Offline
Familiar Face

Joined: Mon Nov 23, 2009 7:52 am
Posts: 47
pradeep,

Thank you very much for your help. It realy worked. Thanks alot. :)


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 5 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