Re: Disabling menu And Modal dialog boxes!



On Wed, 23 Mar 2005 11:16:33 +0100, Iago Rubio <iago rubio hispalinux es> wrote:
On Wed, 2005-03-23 at 14:34 +0530, APR Trainees wrote:
Hello,

We're making an application using gnome 2.0 that adds an icon on the
statusbar.We've added a context menu to display the menu when the icon
is clicked using the right mouse button.
tride to do the follwoing in glade too but couldnt!

2 QUERIES
1.   Now we need to disable(i.e. gray the menuitem) a particular menu item
      in this menu when a certain condition occurs.
      We thought probably the following function wud be useful:

     applet_widget_callback_set_sensitive defined in applet-widget.h but
     this is for gnome 1.0
     and when we include the .h in our application,a zillion errors are
     generated!!!!!!!!

     Then we tried applet_object_callback_set_sensitive which is
defined for 2.0
     But again we aren't able to compile it.Says the function used is
     UNREFERENCED.Probably an extra header is required.

Could some1 pls help us with this ..........suggest how to remove the
error....orr disable the context menu's menuitem.

Save the menu item in any sort of structure, or set it as data for any
accesible object and use gtk_widget_set_sensitive(menu_item, FALSE)



hi again,

Thanx for the help...
as u mentioned here id tried using this earlier too.Irwin had
suggested set_sensitive also.
The problem is when i try to use these it says that the 1st argument
if from an incompatible pointer type.
now the function is:-
gtk_widget_set_sensitive(*GTKWIDGET ,FALSE)
so if i pass the name of the menu or the verb associated wth the
context menu to this function it gives an error!
i'm pasting my code here so that u could get a better idea!
as u said about using a structure or data etc for referencing,i cudnt
quite implement it!
the code:-

#include <panel-applet.h>
#include <gtk/gtklabel.h>
#include <gnome.h>
#include <bonobo.h>


GtkWidget* create_dialog (int type, char * message);
static const BonoboUIVerb myexample_menu_verbs [];

static const char Context_menu_un_xml [] =
  "<popup name=\"button3\">\n"
  "   <menuitem name=\"mnuGet\" "
  "             verb=\"pepGet\" "
  "           _label=\"_Get Status\"\n"
  "          pixtype=' "
  "          pixname=' />\n"
  "   <menuitem name=\"mnuStatus\" "
  "             verb=\"pepStatus\" "
  "           _label=\"_Unknown\"\n"
  "          pixtype=' "
  "          sensitive=False "
  "          pixname=' />\n"
  "   <menuitem name=\"mnuAbout\" "
  "             verb=\"pepAbout\" "
  "           _label=\"_About\"\n"
  "          pixtype=' "
  "          pixname=' />\n"
  "</popup>\n";


Now in another function i try to use:

gtk_widget_set_sensitive("pepStatus",FALSE);


//Function called to make dialog and set it modal
//modal not yet working!

GtkWidget* create_dialog (int type, char * message)
{
GtkWidget *dialog;
GtkWidget *dialog_vbox;
GtkWidget *hbox;
GtkWidget *dialog_action_area;
GtkWidget *okbutton;
GtkWidget *image;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *label3;
char about_data[256];
int retVal;

dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW (dialog), _("About"));
gtk_window_set_modal (GTK_WINDOW (dialog), 1);
   
       //gtk_window_set_modal(GTK_WINDOW (dialog),TRUE);       

gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);

dialog_vbox = GTK_DIALOG (dialog)->vbox;
gtk_widget_show (dialog_vbox);
gnome_dialog_run_and_close (GNOME_DIALOG (dialog));

hbox = gtk_hbox_new (TRUE, 0);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (dialog_vbox), hbox, TRUE, TRUE, 0);

image = gtk_image_new_from_file ("icon.ico");
gtk_widget_show (image);
gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);

   sprintf(about_data,"about");
   label1 = gtk_label_new (_(about_data));
   gtk_widget_show (label1);
   gtk_box_pack_start (GTK_BOX (dialog_vbox), label1, FALSE, FALSE, 0);
   gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
    
dialog_action_area = GTK_DIALOG (dialog)->action_area;
gtk_widget_show (dialog_action_area);
gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area),
GTK_BUTTONBOX_SPREAD);

okbutton = gtk_button_new_from_stock ("gtk-ok");
gtk_widget_show (okbutton);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), okbutton, GTK_RESPONSE_OK);
GTK_WIDGET_SET_FLAGS (okbutton, GTK_CAN_DEFAULT);


       g_signal_connect_data ((gpointer) okbutton, "clicked",
                        G_CALLBACK (gtk_widget_destroy),
                        GTK_OBJECT (dialog),
                        NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);

g_object_set_data (G_OBJECT(dialog), "dialog", dialog);
g_object_set_data (G_OBJECT(dialog), "dialog_vbox", dialog_vbox);
       g_object_set_data (G_OBJECT(dialog), "hbox", hbox);
g_object_set_data (G_OBJECT(dialog), "image", image);

     g_object_set_data (G_OBJECT(dialog), "label1", label1);


g_object_set_data (G_OBJECT(dialog), "dialog_action_area", dialog_action_area);
g_object_set_data (G_OBJECT(dialog), "okbutton", okbutton);
       
       return dialog;
}

static const BonoboUIVerb myexample_menu_verbs [] = 
{
       BONOBO_UI_VERB ("pepGet", get_request),
       BONOBO_UI_VERB ("pepAbout", display_about),
       BONOBO_UI_VERB ("pepStatus", set_request),
       BONOBO_UI_VERB_END
};

static gboolean
myexample_applet_fill (PanelApplet *applet,
  const gchar *iid,
  gpointer data)
{
GtkWidget *event_box;
GtkWidget *image;

if (strcmp (iid, "OAFIID:ExampleApplet") != 0)
return FALSE;

image = gtk_image_new_from_file("icon.ico");
//("/usr/share/pixmaps/InmarsatIcon.png");
event_box = gtk_event_box_new();

gtk_container_add (GTK_CONTAINER (event_box), image);

gtk_container_add (GTK_CONTAINER (applet), event_box);

gtk_widget_show_all (GTK_WIDGET (applet));


panel_applet_setup_menu (PANEL_APPLET (applet),
                        Context_menu_un_xml,
                        myexample_menu_verbs,
                        NULL);


return TRUE;
}

PANEL_APPLET_BONOBO_FACTORY ("OAFIID:ExampleApplet_Factory",
                            PANEL_TYPE_APPLET,
                            "The Hello World Applet",
                            "0",
                            myexample_applet_fill,
                            NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]