modal dialog implementation / mainloop nested / g_object_notify use

2010-03-18  来源:本站原创  分类:OS  人气:299 

Reprinted from:

modal dialog implementation

gtk in, modal dialog is that the realization of the general nested by g_main_loop achieved. But the recent discovery is not the case.

Whether modal dialog, mainly by whether the call is as follows function control:

1, gtk_window_set_modal (window, TRUE); but this function is mainly to do several things:

(1), the window manager to set the value _NET_WM_STATE atom in _NET_WM_STATE_MODAL

(2), gtk_grab_add (window)

gtk_grab_add (window), the and the window in the window of a group receive the click event so do not be processed

When the modal window is hide or turn off, then call gtk_grab_remove (window) function.

2, gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DIALOG);

When you set this property after, window manager will be in the original window is always displayed in the window click on the under, even if the window has been received before the focus.

nested mainloop

When has a main loop in run situations, in the main loop of the callback function can be new and run the other main loop, then the first block of a main loop is in the implementation of the callback function, and the new generation the main loop and a main loop because using the same context, would replace the first main loop handling the event loop.


shutdown_loop (GtkWidget * widget, GdkEventAny * evt, gpointer user_data)


GMainLoop * loop = (GMainLoop *) user_data;

if (g_main_loop_is_running (loop))

g_main_loop_quit (loop);

return FALSE;



show_modal_window (GtkWidget * widget, GdkEventButton * evt)



GMainLoop * loop = g_main_loop_new (NULL, FALSE); / / NULL ensures that this loop uses default context

g_signal_connect (window, "delete_event", G_CALLBACK (shutdown_loop), loop);

g_main_loop_run (loop);

g_main_loop_unref (loop);

return FALSE;


When a dialog is the modal, not by whether or red part of the code (nested main loop) control, but the two functions by the above mentioned decision.

The existence of the second loop, so even in the absence of the first loop of the case, a separate call show_modal_window, still can handle the message loop.

g_object_notify to use

0 registered some

g_object_class_install_property (gobject_class,


g_param_spec_boolean ("modal", P_ ("Modal"), P_ ("if true, the window is modal (other windows are not usable while this one is up)"), FALSE, GTK_PARAM_READWRITE)


1, emit some

g_object_notify (G_OBJECT (window), "modal");

2. Connect some

g_signal_connect (window, "notify:: modal", G_CALLBACK (notify_modal_received), NULL);

3, the callback function

void notify_modal_received (GtkWidget * window, GParamSpec * pspec)


printf ("notify modal received");


4. Call the sequence and running the results:

1 -> 2 -> 3

notify modal received

5.g_object_notify role Description:

Submit a "notify" signal to the 'window' object 'pspec' property

g_object_notify alternative use

We can use the exo library provides the function to be associated with the properties of multiple objects

Thunar 1.0.0 part of the code

thunar / thunar-preferences-dialog.c:

GtkWidget              *button;

  button = gtk_radio_button_new_with_mnemonic (NULL, _("_Object1"));
  exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-single-click", G_OBJECT (button), "active");//  Two object associated with the  'dialog->preferences' And the ' button ' property
  g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (g_object_notify), "active");//radio button Select send to notify  active
  gtk_table_attach (GTK_TABLE (table), button, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
  gtk_widget_show (button);

  button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (button), _("_Object2"));
  exo_mutual_binding_new_with_negation (G_OBJECT (dialog->preferences), "misc-single-click", G_OBJECT (button), "active");
  g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (g_object_notify), "active");
  gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0);
  gtk_widget_show (button);

Binding on the control can refer to related articles:

Thunar of control binding

  • modal dialog implementation / mainloop nested / g_object_notify use 2010-03-18

    Reprinted from: modal dialog implementation gtk in, modal dialog is that the realization of the general nested by g_main_loop achieved. But the recent discovery is not the case. Whether mod

  • div / layer, to achieve modal windows / modal window / modal dialog box 2011-01-13

    <! - First need to explain, this is a pseudo-mode window, style, good-looking, is displayed on the same page the div only. If necessary, up to: the real modal dialog box -> <html> <head> <title> Compact mode window </ title>

  • Selenium test using modal dialog showModalDialog 2009-07-27

    Selenium does not currently offer the IE modal dialog (that is, through the showModalDialog method open pop-up dialog box) processing. The reason is that modal dialog will be the parent page JS hang until the dialog box will be disposed to continue t

  • With the modal dialog to achieve "message prompt box" and "Operation Tips Box" 2008-09-11

    With the modal dialog to achieve "message prompt box" and "Operation Tips Box" With the alert () and confirm () message box and operation of the confirmation dialog box, the interface is not friendly, Here are achieved using a modal di

  • window.showModalDialog the difference between a modal dialog box and 2008-08-14

    1. Modal dialog parent window pops up a modal dialog box code is as follows window.showModalDialog(url,window, "help:no;scroll:no;resizable:no;status:0;dialogWidth:420px;dialogHeight:200px;center:yes" ); 1. Parameter 1 url, url behind you can ac

  • window.showModalDialog modal dialog and 2009-05-23

    Java code window.showModalDialog (url, window, "help: no; scroll: no; resizable: no; status: 0; dialogWidth: 420px; dialogHeight: 200px; center: yes"); 1. Parameter 1 url, url behind you can access "? Name = user" Parameter 2 is passed

  • WTL modal dialog box in how to respond to the message keydown 2010-09-16

    WTL modal dialog box, if the dialog box there is no control, or control is not the focus (such as Static text control), the window can receive WM_KEYDOWN messages. However, if the control dialog has focus, such as Button or Edit control, then the dia

  • WTL modal dialog in the news of how to respond to keydown 2010-10-27

    WTL modal dialog box, if there is no control on the dialog box or control is not the focus (such as Static text control), the window can receive WM_KEYDOWN messages. But if there is focus on the dialog box controls, such as Button or Edit control, th

  • Since the submission of the screen after a modal dialog box, dialogArguments loss problem 2010-11-11

    Main screen pop-up modal dialog box, modal dialog box requires the screen to the dynamic operation of a single main screen content can be achieved by window.returnValue Scene: the main screen pop-up modal dialog box, modal dialog box requires the dyn

  • JavaScript Modal Dialog Class 2010-12-06

    Modal dialog class / ** * JavaScript DodelDialog v0.1 * * * New DodelDialog ({ * Caption title 'dialog box title' (default) * Template body content''(default) * DialogCls dialog className 'md-dialog' (default) * HeadCls head className 'md-head' (defa

  • 2.3 15 ajax effects, and Modal Dialog for Lightbox 2010-12-10

    1. Facebox facebox is a jquery based Lightbox, can display images, divs, or a remote page. It is easy to use. Download: 2. Colorbox ColorBox is a lightweight, customizable Lightbox plug-in, you can use jQuery 1.3 and

  • jQuery对话框 jQuery Modal Dialog 2008-09-19

    jQuery Modal Dialog 网站 : jQuery Modal Dialog 是一个用来显示错误提示.警告信息.操作成功提示等等对话框的 jQuery 插件. 示例代码: $.modaldialog.error('你好,开源中国社区'); 对话框选项包括有: AutoClose Timeout Show/Hide Close Button Dialog Title Dialog Width 演示地址:http://tautologistics.c

  • Modal dialog close the parent form 2010-05-14

    Yesterday had been looking for such a view there is no answer. Results in a find some information The solution of this problem are as follows: Entitled: A.html in a modal popup to allow the B.html

  • [ShowModalDialog] modal dialog box to open the link, but not to open a new window 2010-11-11

    In the model window to open a new window does not open the connection in <head> </ head> to add Add the following code: <base target="_self">

  • Windows window. Controls and dialog boxes 2010-05-12

    from: Windows window, controls, and dialog boxes windows application through the window (window), control (control) and the dialog box (dialog box) to and user interaction, windows system, a lot of

  • Based on. Net development platform windows modal form (change) 2010-08-10

    Overview What is modal form? Simple can be understood as a form dialog box, users must complete the form after the operation or close the form to return the form to open this form. This form is not modal definitions, characteristics, functions make a

  • JScript.VBScript use the message box. Dialog - scripting language 2010-08-28

    The use of JScript message box ------------------------------------- Use warnings, tips and warnings can be used to confirm, confirm and prompt a message box to get user input. The message box is a window object's interface methods. As the window obj

  • With regard to the modal javascript. Non-modal windows, the mainstream browser support 2010-02-14

    To briefly explain the basic knowledge: 1, () support environment: JavaScript1.0 + / JScript1.0 + / Nav2 + / IE3 + / Opera3 + 2, the basic syntax: (pageURL, name, parameters) Of which: pageURL path for the child window name fo

  • Modal pop-up window, refresh the parent form 2010-03-29

    Q: I was doing a system when faced with this problem. Modal pop-up window does not refresh the parent form. For example, I added the data is added in the modal window, which was successful only after the closure of manually refresh the parent form. T

  • Ask: modal window dTree solution 2010-03-30

    Functional Requirements Description: In the modal window to display a tree structure, and select the node back to the parent form. Is currently experiencing problems: In the modal window, you can load the tree, but in the selection of nodes when the