Re: Pause and resume GtkApplication

2018-01-27 Thread Alexander Koeppe
Hi

just FYI: I solved it.

The trick was that within the second g_application_run(), the app menu
must be attached to the application using gtk_application_set_app_menu()
*before* adding the already existing _window_ using
gtk_application_add_window() to the application.

This way the app-menu is properly (or still) shown in the same window
throughout both GtkApplication instances.

Regards
   - Alex

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Pause and resume GtkApplication

2018-01-26 Thread Alexander Koeppe
Thanks to all of you.

I try to incorporate all the advisories and hints as best as I can given
the constraints underlying.


Cheers


 -- Alex

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Pause and resume GtkApplication

2018-01-26 Thread Chris Vine
On Fri, 26 Jan 2018 11:14:36 +0700
"Lucky B.C"  wrote:
> Well, in the case, I will tell something about me, first I've never
> used the GtkApplication just main window maybe sub windows (dialogs)
> too, and my programs did not do as what you are trying to do. Second
> I'm a C programmer, in my opinion, you should redesign your app
> because sometimes we must do that to gain our main target not about
> GUI which we only need for rendering/displaying to the user. Nothing
> is perfect! If we don't want the user see the private data or
> something else, we just don't show it by doing in another thread.
> Yes, the main loop of GTK always runs after we called gtk_main (),
> but we can create another thread before gtk_init () is called and run
> it anytime we need by gdk_threads_enter and gdk_threads_leave, for
> more detail see GThreads
> 
> and IDLES
> . Finally
> just reload/refresh our new data/thing again to the user or show a
> message dialog says somthing else, for example "Your data changed!".
> I wonder is there some programs which have the same what you are
> trying to do? If there's one or more, please send me the link, I
> really want to test them.

gdk_threads_enter and gdk_threads_leave are absolutely not the way to
do it.  They are deprecated in GTK+3 and will be removed in GTK+4.
Furthermore they only work with the X backend (not with windows or
wayland) and are horribly error-prone.

The correct way for a worker thread to pass back a result to the glib
main loop, or to execute code in that loop, is for it to post an event
using g_idle_add() and cognates.  The glib main loop is thread safe.

gdk_threads_add_idle is only necessary if your code interfaces with
ancient third-party library code which uses gdk_threads_enter and
gdk_threads_leave.  The best thing to do with such ancient libraries is
not to use them.

Chris
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Pause and resume GtkApplication

2018-01-25 Thread Lucky B.C
Well, in the case, I will tell something about me, first I've never used
the GtkApplication just main window maybe sub windows (dialogs) too, and my
programs did not do as what you are trying to do. Second I'm a C
programmer, in my opinion, you should redesign your app because sometimes
we must do that to gain our main target not about GUI which we only need
for rendering/displaying to the user. Nothing is perfect! If we don't want
the user see the private data or something else, we just don't show it by
doing in another thread. Yes, the main loop of GTK always runs after we
called gtk_main (), but we can create another thread before gtk_init () is
called and run it anytime we need by gdk_threads_enter and
gdk_threads_leave, for more detail see GThreads

and IDLES .
Finally just reload/refresh our new data/thing again to the user or show a
message dialog says somthing else, for example "Your data changed!". I
wonder is there some programs which have the same what you are trying to
do? If there's one or more, please send me the link, I really want to test
them.

On Fri, Jan 26, 2018 at 5:10 AM, Alexander Koeppe 
wrote:

> Thanks Lucky,
>
> Good idea to create the widget right away and hide it until it's time.
>
> However, just by accident, I got back the app-menu in the window.
>
> Try this with the code below:
>
> 1. After I selected "Restart" simulating the pause and resume, the
> app-menu disappeared.
> 2. Then I double-clicked the header-bar to maximise the window and the
> app-menu reappeared.
> 3. Again double-clicked the header-bar to restore the original geometry
> the app-menu is still there.
>
> This is what I want. Question is, what happens when I double click the
> header-bar and can I emulate this event in code?
>
> I feel being just 1 grain off my goal
>
> Thanks
>
>-Alex
>
>
> Am 23.01.2018 um 22:37 schrieb Lucky B.C:
> > Wow, I see your problem is that you did not understand what GtkBuilder
> > and Gtk are doing, Because If I'm not wrong, each choice (entry) is a
> > function to start something you want to do after the user/you clicked
> > to the button called "restart". Here's my solution, it's maybe help
> > you.
> >
> > *) You can use gtk_widget_hide (target) function to hide any widget,
> > in this case it's the main window. Then you can do your low-level
> > functions what the other can see at the time after the signal
> > "clicked" activated.
> >
> > Note: Some programs I saw the program did not exit when it's called to
> > restart, there's only the changed/related data must be reload to
> > buffer/ram, and the program must stop rendering/running at the time,
> > after the reloading's done the program continues to render/display the
> > new data in the screen. The reloading can be done in a new thread too,
> > after used you can delete it too.
> >
> > On Wed, Jan 24, 2018 at 2:52 AM, Alexander Koeppe
> >  wrote:
> >> I know about the possiblity to fire the low-level functions using an
> button
> >> callback. However this would draw an exception for other UI choices the
> >> application has: e.g. text, deamon.
> >>
> >> Therefore I'm looking for a way to keep the application structure for
> all
> >> UIs the same.
> >>
> >> There is the test app I'm playing with:
> >>
> >>
> >> #include 
> >>
> >> GtkApplication *app;
> >> GtkWidget *window;
> >> int initialized = 0;
> >>
> >> void quit_cb(GSimpleAction *action, GVariant *value, gpointer data)
> >> {
> >>g_print("quit!\n");
> >>g_object_unref(app);
> >>exit(0);
> >> }
> >>
> >> void restart_cb(GSimpleAction *action, GVariant *value, gpointer data)
> >> {
> >>g_print("restart!\n");
> >>g_application_quit(G_APPLICATION(app));
> >> }
> >>
> >> void test_cb(GSimpleAction *action, GVariant *value, gpointer data)
> >> {
> >>   GtkWidget *dialog;
> >>   GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
> >>
> >>
> >>   dialog = gtk_message_dialog_new(GTK_WINDOW(window),
> >>   flags,
> >>   GTK_MESSAGE_ERROR,
> >>   GTK_BUTTONS_CLOSE,
> >>   "TEst Message");
> >>   g_signal_connect_swapped(dialog, "response",
> >>G_CALLBACK(gtk_widget_destroy),
> >>dialog);
> >>   gtk_dialog_run(GTK_DIALOG(dialog));
> >> }
> >>
> >> static void shutdown(GtkApplication *app, gpointer data)
> >> {
> >>initialized = 1;
> >> }
> >>
> >> static void
> >> activate (GtkApplication *app,
> >>   gpointeruser_data)
> >> {
> >>   GtkWidget *header, *menubutton, *frame, *overlay, *combo, *box;
> >>   GtkBuilder *builder;
> >>
> >>   GActionEntry actions[] = {
> >>   {"test_action", test_cb, NULL, NULL, NULL,{}},
> >>   {"restart", restart_cb, NULL, NULL, 

Re: Pause and resume GtkApplication

2018-01-25 Thread Joël Krähemann
Well, do a context menu and forget about it. In opensuse it is a
special package you install for Gnome3 :/

On Fri, Jan 26, 2018 at 12:30 AM, Alexander Koeppe
 wrote:
> It's not really because of async execution.
> I just tried various gtk_window functions that trigger the
> "window-state-change" event. But not all of them provide the desired effect.
> e.g.
> gtk_window_maximize() reappears the app-menu.
> gtk_window_iconfify() not
>
> So I wonder what is the default callback function of that signal which
> in case of maximization does a little thing that brings back the
> app-menu to my window.
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Pause and resume GtkApplication

2018-01-25 Thread Alexander Koeppe
It's not really because of async execution.
I just tried various gtk_window functions that trigger the
"window-state-change" event. But not all of them provide the desired effect.
e.g.
gtk_window_maximize() reappears the app-menu.
gtk_window_iconfify() not

So I wonder what is the default callback function of that signal which
in case of maximization does a little thing that brings back the
app-menu to my window.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Pause and resume GtkApplication

2018-01-25 Thread Joël Krähemann
Hi

Just some explanation. Your timeout is is dispatched by gtk_main(). As
doing your call to the backend,
you have to listen on message and then forward the event to the UI.

AgsAudio::set-pads() actually is part of my backend. Sends the message.

Here you need some async non-blocking call to your backend, at your
own taste. E.g. this call
invokes ags_audio_set_pads().

The timeout function polls your messages and forwards the event:

AgsMachine::resize-pads() is part of the UI. You listen to this event within UI.

Connect as usual, note the callback does modify is_available to TRUE:

do_wait = TRUE;
is_available = FALSE;

g_signal_connect_after(machine, "resize-pads",
   G_CALLBACK(pads_resized_callback),
_available);

Meanwhile you pause execution of UI by calling within gtk_main().

while((do_wait && !is_available[0])){
usleep(100 / 30);
g_main_context_iteration(NULL,
FALSE);
}

Your source is dispatched but gtk_main() is still within the loop shown above.

Bests,
Joël

On Thu, Jan 25, 2018 at 11:54 PM, Joël Krähemann  wrote:
> Hi,
>
> Well there was some redundant code. This actually fixes it:
>
> http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/X/file/ags_simple_file.c?h=1.5.x#n1904
>
> Bests,
> Joël
>
>
> On Thu, Jan 25, 2018 at 11:16 PM, Joël Krähemann  
> wrote:
>> Hi,
>> You do some async work? Read about:
>>
>> g_timeout_add_full();
>>
>> and
>>
>> g_main_context_iteration();
>>
>> You, can callback the to the UI forwarded event. I do something similar
>> as reading a file from a different thread:
>>
>> http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/X/file/ags_simple_file.c?h=1.4.x#n1957
>>
>> FYI: the UI thread shall run always by gtk_main().
>>
>> Bests,
>> Joël
>>
>> On Thu, Jan 25, 2018 at 11:10 PM, Alexander Koeppe
>>  wrote:
>>> Thanks Lucky,
>>>
>>> Good idea to create the widget right away and hide it until it's time.
>>>
>>> However, just by accident, I got back the app-menu in the window.
>>>
>>> Try this with the code below:
>>>
>>> 1. After I selected "Restart" simulating the pause and resume, the
>>> app-menu disappeared.
>>> 2. Then I double-clicked the header-bar to maximise the window and the
>>> app-menu reappeared.
>>> 3. Again double-clicked the header-bar to restore the original geometry
>>> the app-menu is still there.
>>>
>>> This is what I want. Question is, what happens when I double click the
>>> header-bar and can I emulate this event in code?
>>>
>>> I feel being just 1 grain off my goal
>>>
>>> Thanks
>>>
>>>-Alex
>>>
>>>
>>> Am 23.01.2018 um 22:37 schrieb Lucky B.C:
 Wow, I see your problem is that you did not understand what GtkBuilder
 and Gtk are doing, Because If I'm not wrong, each choice (entry) is a
 function to start something you want to do after the user/you clicked
 to the button called "restart". Here's my solution, it's maybe help
 you.

 *) You can use gtk_widget_hide (target) function to hide any widget,
 in this case it's the main window. Then you can do your low-level
 functions what the other can see at the time after the signal
 "clicked" activated.

 Note: Some programs I saw the program did not exit when it's called to
 restart, there's only the changed/related data must be reload to
 buffer/ram, and the program must stop rendering/running at the time,
 after the reloading's done the program continues to render/display the
 new data in the screen. The reloading can be done in a new thread too,
 after used you can delete it too.

 On Wed, Jan 24, 2018 at 2:52 AM, Alexander Koeppe
  wrote:
> I know about the possiblity to fire the low-level functions using an 
> button
> callback. However this would draw an exception for other UI choices the
> application has: e.g. text, deamon.
>
> Therefore I'm looking for a way to keep the application structure for all
> UIs the same.
>
> There is the test app I'm playing with:
>
>
> #include 
>
> GtkApplication *app;
> GtkWidget *window;
> int initialized = 0;
>
> void quit_cb(GSimpleAction *action, GVariant *value, gpointer data)
> {
>g_print("quit!\n");
>g_object_unref(app);
>exit(0);
> }
>
> void restart_cb(GSimpleAction *action, GVariant *value, gpointer data)
> {
>g_print("restart!\n");
>g_application_quit(G_APPLICATION(app));
> }
>
> void test_cb(GSimpleAction *action, GVariant *value, gpointer data)
> {
>   GtkWidget *dialog;
>   GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
>
>
>   dialog = gtk_message_dialog_new(GTK_WINDOW(window),
>   flags,
>   GTK_MESSAGE_ERROR,
>   

Re: Pause and resume GtkApplication

2018-01-25 Thread Joël Krähemann
Hi,

Well there was some redundant code. This actually fixes it:

http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/X/file/ags_simple_file.c?h=1.5.x#n1904

Bests,
Joël


On Thu, Jan 25, 2018 at 11:16 PM, Joël Krähemann  wrote:
> Hi,
> You do some async work? Read about:
>
> g_timeout_add_full();
>
> and
>
> g_main_context_iteration();
>
> You, can callback the to the UI forwarded event. I do something similar
> as reading a file from a different thread:
>
> http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/X/file/ags_simple_file.c?h=1.4.x#n1957
>
> FYI: the UI thread shall run always by gtk_main().
>
> Bests,
> Joël
>
> On Thu, Jan 25, 2018 at 11:10 PM, Alexander Koeppe
>  wrote:
>> Thanks Lucky,
>>
>> Good idea to create the widget right away and hide it until it's time.
>>
>> However, just by accident, I got back the app-menu in the window.
>>
>> Try this with the code below:
>>
>> 1. After I selected "Restart" simulating the pause and resume, the
>> app-menu disappeared.
>> 2. Then I double-clicked the header-bar to maximise the window and the
>> app-menu reappeared.
>> 3. Again double-clicked the header-bar to restore the original geometry
>> the app-menu is still there.
>>
>> This is what I want. Question is, what happens when I double click the
>> header-bar and can I emulate this event in code?
>>
>> I feel being just 1 grain off my goal
>>
>> Thanks
>>
>>-Alex
>>
>>
>> Am 23.01.2018 um 22:37 schrieb Lucky B.C:
>>> Wow, I see your problem is that you did not understand what GtkBuilder
>>> and Gtk are doing, Because If I'm not wrong, each choice (entry) is a
>>> function to start something you want to do after the user/you clicked
>>> to the button called "restart". Here's my solution, it's maybe help
>>> you.
>>>
>>> *) You can use gtk_widget_hide (target) function to hide any widget,
>>> in this case it's the main window. Then you can do your low-level
>>> functions what the other can see at the time after the signal
>>> "clicked" activated.
>>>
>>> Note: Some programs I saw the program did not exit when it's called to
>>> restart, there's only the changed/related data must be reload to
>>> buffer/ram, and the program must stop rendering/running at the time,
>>> after the reloading's done the program continues to render/display the
>>> new data in the screen. The reloading can be done in a new thread too,
>>> after used you can delete it too.
>>>
>>> On Wed, Jan 24, 2018 at 2:52 AM, Alexander Koeppe
>>>  wrote:
 I know about the possiblity to fire the low-level functions using an button
 callback. However this would draw an exception for other UI choices the
 application has: e.g. text, deamon.

 Therefore I'm looking for a way to keep the application structure for all
 UIs the same.

 There is the test app I'm playing with:


 #include 

 GtkApplication *app;
 GtkWidget *window;
 int initialized = 0;

 void quit_cb(GSimpleAction *action, GVariant *value, gpointer data)
 {
g_print("quit!\n");
g_object_unref(app);
exit(0);
 }

 void restart_cb(GSimpleAction *action, GVariant *value, gpointer data)
 {
g_print("restart!\n");
g_application_quit(G_APPLICATION(app));
 }

 void test_cb(GSimpleAction *action, GVariant *value, gpointer data)
 {
   GtkWidget *dialog;
   GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;


   dialog = gtk_message_dialog_new(GTK_WINDOW(window),
   flags,
   GTK_MESSAGE_ERROR,
   GTK_BUTTONS_CLOSE,
   "TEst Message");
   g_signal_connect_swapped(dialog, "response",
G_CALLBACK(gtk_widget_destroy),
dialog);
   gtk_dialog_run(GTK_DIALOG(dialog));
 }

 static void shutdown(GtkApplication *app, gpointer data)
 {
initialized = 1;
 }

 static void
 activate (GtkApplication *app,
   gpointeruser_data)
 {
   GtkWidget *header, *menubutton, *frame, *overlay, *combo, *box;
   GtkBuilder *builder;

   GActionEntry actions[] = {
   {"test_action", test_cb, NULL, NULL, NULL,{}},
   {"restart", restart_cb, NULL, NULL, NULL, {}},
   {"quit", quit_cb, NULL, NULL, NULL, {}}
   };


   g_action_map_add_action_entries(G_ACTION_MAP(app), actions,
   G_N_ELEMENTS(actions), app);



   if (initialized == 0) {
  window = gtk_application_window_new (app);
  gtk_window_set_default_size (GTK_WINDOW (window), 500, 300);
   }
   else {
  gtk_application_add_window(app, GTK_WINDOW(window));
   }
   gtk_window_set_title (GTK_WINDOW (window), 

Re: Pause and resume GtkApplication

2018-01-25 Thread Joël Krähemann
Hi,
You do some async work? Read about:

g_timeout_add_full();

and

g_main_context_iteration();

You, can callback the to the UI forwarded event. I do something similar
as reading a file from a different thread:

http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/X/file/ags_simple_file.c?h=1.4.x#n1957

FYI: the UI thread shall run always by gtk_main().

Bests,
Joël

On Thu, Jan 25, 2018 at 11:10 PM, Alexander Koeppe
 wrote:
> Thanks Lucky,
>
> Good idea to create the widget right away and hide it until it's time.
>
> However, just by accident, I got back the app-menu in the window.
>
> Try this with the code below:
>
> 1. After I selected "Restart" simulating the pause and resume, the
> app-menu disappeared.
> 2. Then I double-clicked the header-bar to maximise the window and the
> app-menu reappeared.
> 3. Again double-clicked the header-bar to restore the original geometry
> the app-menu is still there.
>
> This is what I want. Question is, what happens when I double click the
> header-bar and can I emulate this event in code?
>
> I feel being just 1 grain off my goal
>
> Thanks
>
>-Alex
>
>
> Am 23.01.2018 um 22:37 schrieb Lucky B.C:
>> Wow, I see your problem is that you did not understand what GtkBuilder
>> and Gtk are doing, Because If I'm not wrong, each choice (entry) is a
>> function to start something you want to do after the user/you clicked
>> to the button called "restart". Here's my solution, it's maybe help
>> you.
>>
>> *) You can use gtk_widget_hide (target) function to hide any widget,
>> in this case it's the main window. Then you can do your low-level
>> functions what the other can see at the time after the signal
>> "clicked" activated.
>>
>> Note: Some programs I saw the program did not exit when it's called to
>> restart, there's only the changed/related data must be reload to
>> buffer/ram, and the program must stop rendering/running at the time,
>> after the reloading's done the program continues to render/display the
>> new data in the screen. The reloading can be done in a new thread too,
>> after used you can delete it too.
>>
>> On Wed, Jan 24, 2018 at 2:52 AM, Alexander Koeppe
>>  wrote:
>>> I know about the possiblity to fire the low-level functions using an button
>>> callback. However this would draw an exception for other UI choices the
>>> application has: e.g. text, deamon.
>>>
>>> Therefore I'm looking for a way to keep the application structure for all
>>> UIs the same.
>>>
>>> There is the test app I'm playing with:
>>>
>>>
>>> #include 
>>>
>>> GtkApplication *app;
>>> GtkWidget *window;
>>> int initialized = 0;
>>>
>>> void quit_cb(GSimpleAction *action, GVariant *value, gpointer data)
>>> {
>>>g_print("quit!\n");
>>>g_object_unref(app);
>>>exit(0);
>>> }
>>>
>>> void restart_cb(GSimpleAction *action, GVariant *value, gpointer data)
>>> {
>>>g_print("restart!\n");
>>>g_application_quit(G_APPLICATION(app));
>>> }
>>>
>>> void test_cb(GSimpleAction *action, GVariant *value, gpointer data)
>>> {
>>>   GtkWidget *dialog;
>>>   GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
>>>
>>>
>>>   dialog = gtk_message_dialog_new(GTK_WINDOW(window),
>>>   flags,
>>>   GTK_MESSAGE_ERROR,
>>>   GTK_BUTTONS_CLOSE,
>>>   "TEst Message");
>>>   g_signal_connect_swapped(dialog, "response",
>>>G_CALLBACK(gtk_widget_destroy),
>>>dialog);
>>>   gtk_dialog_run(GTK_DIALOG(dialog));
>>> }
>>>
>>> static void shutdown(GtkApplication *app, gpointer data)
>>> {
>>>initialized = 1;
>>> }
>>>
>>> static void
>>> activate (GtkApplication *app,
>>>   gpointeruser_data)
>>> {
>>>   GtkWidget *header, *menubutton, *frame, *overlay, *combo, *box;
>>>   GtkBuilder *builder;
>>>
>>>   GActionEntry actions[] = {
>>>   {"test_action", test_cb, NULL, NULL, NULL,{}},
>>>   {"restart", restart_cb, NULL, NULL, NULL, {}},
>>>   {"quit", quit_cb, NULL, NULL, NULL, {}}
>>>   };
>>>
>>>
>>>   g_action_map_add_action_entries(G_ACTION_MAP(app), actions,
>>>   G_N_ELEMENTS(actions), app);
>>>
>>>
>>>
>>>   if (initialized == 0) {
>>>  window = gtk_application_window_new (app);
>>>  gtk_window_set_default_size (GTK_WINDOW (window), 500, 300);
>>>   }
>>>   else {
>>>  gtk_application_add_window(app, GTK_WINDOW(window));
>>>   }
>>>   gtk_window_set_title (GTK_WINDOW (window), "buildertest");
>>>
>>>   /* Header Bar */
>>>   header = gtk_header_bar_new();
>>>   gtk_header_bar_set_title(GTK_HEADER_BAR(header), "Yeah");
>>>   gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header), TRUE);
>>>   gtk_window_set_titlebar(GTK_WINDOW(window), header);
>>>
>>>   /* Menu Button */
>>>   menubutton = gtk_menu_button_new();
>>>
>>>   /* Menu for Menubutton */
>>>   builder = gtk_builder_new();
>>>   

Re: Pause and resume GtkApplication

2018-01-25 Thread Alexander Koeppe
Thanks Lucky,

Good idea to create the widget right away and hide it until it's time.

However, just by accident, I got back the app-menu in the window.

Try this with the code below:

1. After I selected "Restart" simulating the pause and resume, the
app-menu disappeared.
2. Then I double-clicked the header-bar to maximise the window and the
app-menu reappeared.
3. Again double-clicked the header-bar to restore the original geometry
the app-menu is still there.

This is what I want. Question is, what happens when I double click the
header-bar and can I emulate this event in code?

I feel being just 1 grain off my goal

Thanks

   -Alex


Am 23.01.2018 um 22:37 schrieb Lucky B.C:
> Wow, I see your problem is that you did not understand what GtkBuilder
> and Gtk are doing, Because If I'm not wrong, each choice (entry) is a
> function to start something you want to do after the user/you clicked
> to the button called "restart". Here's my solution, it's maybe help
> you.
>
> *) You can use gtk_widget_hide (target) function to hide any widget,
> in this case it's the main window. Then you can do your low-level
> functions what the other can see at the time after the signal
> "clicked" activated.
>
> Note: Some programs I saw the program did not exit when it's called to
> restart, there's only the changed/related data must be reload to
> buffer/ram, and the program must stop rendering/running at the time,
> after the reloading's done the program continues to render/display the
> new data in the screen. The reloading can be done in a new thread too,
> after used you can delete it too.
>
> On Wed, Jan 24, 2018 at 2:52 AM, Alexander Koeppe
>  wrote:
>> I know about the possiblity to fire the low-level functions using an button
>> callback. However this would draw an exception for other UI choices the
>> application has: e.g. text, deamon.
>>
>> Therefore I'm looking for a way to keep the application structure for all
>> UIs the same.
>>
>> There is the test app I'm playing with:
>>
>>
>> #include 
>>
>> GtkApplication *app;
>> GtkWidget *window;
>> int initialized = 0;
>>
>> void quit_cb(GSimpleAction *action, GVariant *value, gpointer data)
>> {
>>g_print("quit!\n");
>>g_object_unref(app);
>>exit(0);
>> }
>>
>> void restart_cb(GSimpleAction *action, GVariant *value, gpointer data)
>> {
>>g_print("restart!\n");
>>g_application_quit(G_APPLICATION(app));
>> }
>>
>> void test_cb(GSimpleAction *action, GVariant *value, gpointer data)
>> {
>>   GtkWidget *dialog;
>>   GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
>>
>>
>>   dialog = gtk_message_dialog_new(GTK_WINDOW(window),
>>   flags,
>>   GTK_MESSAGE_ERROR,
>>   GTK_BUTTONS_CLOSE,
>>   "TEst Message");
>>   g_signal_connect_swapped(dialog, "response",
>>G_CALLBACK(gtk_widget_destroy),
>>dialog);
>>   gtk_dialog_run(GTK_DIALOG(dialog));
>> }
>>
>> static void shutdown(GtkApplication *app, gpointer data)
>> {
>>initialized = 1;
>> }
>>
>> static void
>> activate (GtkApplication *app,
>>   gpointeruser_data)
>> {
>>   GtkWidget *header, *menubutton, *frame, *overlay, *combo, *box;
>>   GtkBuilder *builder;
>>
>>   GActionEntry actions[] = {
>>   {"test_action", test_cb, NULL, NULL, NULL,{}},
>>   {"restart", restart_cb, NULL, NULL, NULL, {}},
>>   {"quit", quit_cb, NULL, NULL, NULL, {}}
>>   };
>>
>>
>>   g_action_map_add_action_entries(G_ACTION_MAP(app), actions,
>>   G_N_ELEMENTS(actions), app);
>>
>>
>>
>>   if (initialized == 0) {
>>  window = gtk_application_window_new (app);
>>  gtk_window_set_default_size (GTK_WINDOW (window), 500, 300);
>>   }
>>   else {
>>  gtk_application_add_window(app, GTK_WINDOW(window));
>>   }
>>   gtk_window_set_title (GTK_WINDOW (window), "buildertest");
>>
>>   /* Header Bar */
>>   header = gtk_header_bar_new();
>>   gtk_header_bar_set_title(GTK_HEADER_BAR(header), "Yeah");
>>   gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header), TRUE);
>>   gtk_window_set_titlebar(GTK_WINDOW(window), header);
>>
>>   /* Menu Button */
>>   menubutton = gtk_menu_button_new();
>>
>>   /* Menu for Menubutton */
>>   builder = gtk_builder_new();
>>   gtk_builder_add_from_string(builder,
>>  ""
>>  "  "
>>  ""
>>  "  "
>>  "> translatable='yes'>Restart"
>>  "app.restart"
>>  "  "
>>  "  "
>>  "> translatable='yes'>Quit"
>>  "app.quit"
>>  "  "
>>  ""
>>  "  "
>>  "  "
>>  ""
>>  "Test"
>>  "  "
>>  "Test
>> Entry"
>>  "app.test_action"
>>  "t"
>>  "  "
>>  ""
>>  "  "
>>  

Re: Pause and resume GtkApplication

2018-01-23 Thread Lucky B.C
Wow, I see your problem is that you did not understand what GtkBuilder
and Gtk are doing, Because If I'm not wrong, each choice (entry) is a
function to start something you want to do after the user/you clicked
to the button called "restart". Here's my solution, it's maybe help
you.

*) You can use gtk_widget_hide (target) function to hide any widget,
in this case it's the main window. Then you can do your low-level
functions what the other can see at the time after the signal
"clicked" activated.

Note: Some programs I saw the program did not exit when it's called to
restart, there's only the changed/related data must be reload to
buffer/ram, and the program must stop rendering/running at the time,
after the reloading's done the program continues to render/display the
new data in the screen. The reloading can be done in a new thread too,
after used you can delete it too.

On Wed, Jan 24, 2018 at 2:52 AM, Alexander Koeppe
 wrote:
> I know about the possiblity to fire the low-level functions using an button
> callback. However this would draw an exception for other UI choices the
> application has: e.g. text, deamon.
>
> Therefore I'm looking for a way to keep the application structure for all
> UIs the same.
>
> There is the test app I'm playing with:
>
>
> #include 
>
> GtkApplication *app;
> GtkWidget *window;
> int initialized = 0;
>
> void quit_cb(GSimpleAction *action, GVariant *value, gpointer data)
> {
>g_print("quit!\n");
>g_object_unref(app);
>exit(0);
> }
>
> void restart_cb(GSimpleAction *action, GVariant *value, gpointer data)
> {
>g_print("restart!\n");
>g_application_quit(G_APPLICATION(app));
> }
>
> void test_cb(GSimpleAction *action, GVariant *value, gpointer data)
> {
>   GtkWidget *dialog;
>   GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
>
>
>   dialog = gtk_message_dialog_new(GTK_WINDOW(window),
>   flags,
>   GTK_MESSAGE_ERROR,
>   GTK_BUTTONS_CLOSE,
>   "TEst Message");
>   g_signal_connect_swapped(dialog, "response",
>G_CALLBACK(gtk_widget_destroy),
>dialog);
>   gtk_dialog_run(GTK_DIALOG(dialog));
> }
>
> static void shutdown(GtkApplication *app, gpointer data)
> {
>initialized = 1;
> }
>
> static void
> activate (GtkApplication *app,
>   gpointeruser_data)
> {
>   GtkWidget *header, *menubutton, *frame, *overlay, *combo, *box;
>   GtkBuilder *builder;
>
>   GActionEntry actions[] = {
>   {"test_action", test_cb, NULL, NULL, NULL,{}},
>   {"restart", restart_cb, NULL, NULL, NULL, {}},
>   {"quit", quit_cb, NULL, NULL, NULL, {}}
>   };
>
>
>   g_action_map_add_action_entries(G_ACTION_MAP(app), actions,
>   G_N_ELEMENTS(actions), app);
>
>
>
>   if (initialized == 0) {
>  window = gtk_application_window_new (app);
>  gtk_window_set_default_size (GTK_WINDOW (window), 500, 300);
>   }
>   else {
>  gtk_application_add_window(app, GTK_WINDOW(window));
>   }
>   gtk_window_set_title (GTK_WINDOW (window), "buildertest");
>
>   /* Header Bar */
>   header = gtk_header_bar_new();
>   gtk_header_bar_set_title(GTK_HEADER_BAR(header), "Yeah");
>   gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header), TRUE);
>   gtk_window_set_titlebar(GTK_WINDOW(window), header);
>
>   /* Menu Button */
>   menubutton = gtk_menu_button_new();
>
>   /* Menu for Menubutton */
>   builder = gtk_builder_new();
>   gtk_builder_add_from_string(builder,
>  ""
>  "  "
>  ""
>  "  "
>  " translatable='yes'>Restart"
>  "app.restart"
>  "  "
>  "  "
>  " translatable='yes'>Quit"
>  "app.quit"
>  "  "
>  ""
>  "  "
>  "  "
>  ""
>  "Test"
>  "  "
>  "Test
> Entry"
>  "app.test_action"
>  "t"
>  "  "
>  ""
>  "  "
>  "", -1, NULL);
>
>   gtk_application_set_app_menu(GTK_APPLICATION(app),
> G_MENU_MODEL(gtk_builder_get_object(builder, "app-menu")));
>
>   gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menubutton),
>   G_MENU_MODEL(gtk_builder_get_object(builder, "test-menu")));
>
>   gtk_button_set_image(GTK_BUTTON(menubutton),
>gtk_image_new_from_icon_name("open-menu-symbolic",
> GTK_ICON_SIZE_MENU));
>   gtk_header_bar_pack_end(GTK_HEADER_BAR(header), menubutton);
>
>   /* content area */
>   if (initialized) {
>  overlay = gtk_bin_get_child(GTK_BIN(window));
>  gtk_container_remove(GTK_CONTAINER(window), overlay);
>   }
>
>   overlay = gtk_overlay_new();
>   gtk_container_add(GTK_CONTAINER(window), overlay);
>
>   frame = gtk_frame_new("Rahmen");
>   gtk_container_add(GTK_CONTAINER(overlay), frame);
>
>   box = 

Re: Pause and resume GtkApplication

2018-01-23 Thread Alexander Koeppe
I know about the possiblity to fire the low-level functions using an
button callback. However this would draw an exception for other UI
choices the application has: e.g. text, deamon.

Therefore I'm looking for a way to keep the application structure for
all UIs the same.

There is the test app I'm playing with:


#include 

GtkApplication *app;
GtkWidget *window;
int initialized = 0;

void quit_cb(GSimpleAction *action, GVariant *value, gpointer data)
{
   g_print("quit!\n");
   g_object_unref(app);
   exit(0);
}

void restart_cb(GSimpleAction *action, GVariant *value, gpointer data)
{
   g_print("restart!\n");
   g_application_quit(G_APPLICATION(app));
}

void test_cb(GSimpleAction *action, GVariant *value, gpointer data)
{
  GtkWidget *dialog;
  GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;


  dialog = gtk_message_dialog_new(GTK_WINDOW(window),
  flags,
  GTK_MESSAGE_ERROR,
  GTK_BUTTONS_CLOSE,
  "TEst Message");
  g_signal_connect_swapped(dialog, "response",
   G_CALLBACK(gtk_widget_destroy),
   dialog);
  gtk_dialog_run(GTK_DIALOG(dialog));
}

static void shutdown(GtkApplication *app, gpointer data)
{
   initialized = 1;
}

static void
activate (GtkApplication *app,
  gpointer    user_data)
{
  GtkWidget *header, *menubutton, *frame, *overlay, *combo, *box;
  GtkBuilder *builder;

  GActionEntry actions[] = {
  {"test_action", test_cb, NULL, NULL, NULL,{}},
  {"restart", restart_cb, NULL, NULL, NULL, {}},
  {"quit", quit_cb, NULL, NULL, NULL, {}}
  };


  g_action_map_add_action_entries(G_ACTION_MAP(app), actions,
  G_N_ELEMENTS(actions), app);



  if (initialized == 0) {
 window = gtk_application_window_new (app);
 gtk_window_set_default_size (GTK_WINDOW (window), 500, 300);
  }
  else {
 gtk_application_add_window(app, GTK_WINDOW(window));
  }
  gtk_window_set_title (GTK_WINDOW (window), "buildertest");

  /* Header Bar */
  header = gtk_header_bar_new();
  gtk_header_bar_set_title(GTK_HEADER_BAR(header), "Yeah");
  gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header), TRUE);
  gtk_window_set_titlebar(GTK_WINDOW(window), header);

  /* Menu Button */
  menubutton = gtk_menu_button_new();

  /* Menu for Menubutton */
  builder = gtk_builder_new();
  gtk_builder_add_from_string(builder,
 ""
 "  "
 "    "
 "  "
 "    Restart"
 "    app.restart"
 "  "
 "  "
 "    Quit"
 "    app.quit"
 "  "
 "    "
 "  "
 "  "
 "    "
 "    Test"
 "  "
 "    Test
Entry"
 "    app.test_action"
 "    t"
 "  "
 "    "
 "  "
 "", -1, NULL);

  gtk_application_set_app_menu(GTK_APPLICATION(app),
    G_MENU_MODEL(gtk_builder_get_object(builder, "app-menu")));

  gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menubutton),
  G_MENU_MODEL(gtk_builder_get_object(builder, "test-menu")));

  gtk_button_set_image(GTK_BUTTON(menubutton),
   gtk_image_new_from_icon_name("open-menu-symbolic",
GTK_ICON_SIZE_MENU));
  gtk_header_bar_pack_end(GTK_HEADER_BAR(header), menubutton);

  /* content area */
  if (initialized) {
 overlay = gtk_bin_get_child(GTK_BIN(window));
 gtk_container_remove(GTK_CONTAINER(window), overlay);
  }

  overlay = gtk_overlay_new();
  gtk_container_add(GTK_CONTAINER(window), overlay);

  frame = gtk_frame_new("Rahmen");
  gtk_container_add(GTK_CONTAINER(overlay), frame);

  box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
  gtk_container_add(GTK_CONTAINER(frame), box);

  combo = gtk_combo_box_text_new();
  gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo), "id1", "Entry 1");
  gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo), "id2", "Entry 2");
  gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
  gtk_widget_set_hexpand(combo, TRUE);

  gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 0);



  gtk_widget_show_all(window);
}

int main(int   argc,
 char *argv[])
{
  app = NULL;
  int status;

  app = gtk_application_new ("org.gnome.Buildertest",
G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  g_signal_connect (app, "shutdown", G_CALLBACK(shutdown), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);

  g_print("some things happen here\n");

  g_object_unref(G_OBJECT(app));

  app = gtk_application_new ("org.gnome.Buildertest",
G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
 
  return status;
}


Am 22.01.2018 um 22:09 schrieb Lucky B.C:
> Hi, can you show your demo about the way you did? But I think you
> should keep the gtk_main() 

Re: Pause and resume GtkApplication

2018-01-22 Thread Lucky B.C
Hi, can you show your demo about the way you did? But I think you should
keep the gtk_main() runs, because you can run your low-level functions by
"clicked" signal on button.

On Jan 23, 2018 03:44, "Alexander Koeppe"  wrote:

Hi,

I have an application where some things need to be setup in the UI, then
some low-level routines to be executed using the setup values and then
resuming the UI loop for further operation.

Since I'm migrating the GTK code from GTK2/3 compatible to GNOME/GTK3, I
make use of g_application_run().

However, I find no simialar way to interrupt the loop (e.g.
gtk_main_quit()) and resuming the UI later (gtk_main()).

The only way I found yet is to quit the application using
g_application_quit() but keep the window widget, clearing the
application (g_object_unref()) and creating a new application after
executing the low-level routines and finally adding the still existing
window widget to this new application using
gtk_application_add_window(). This way I can reuse the window and avoid
any flickering which is the required effect.

The only caveat is, the added window is not considered being the primary
instance of the second application, hence the app-menu isn't displayed.

Is there any way to define a window added being the primary instance of
the application or to show the app-menu (set using
gtk_application_set_app_menu()) in such an non-primary window, or even a
complete different approach?


Thanks and regards

- Alex


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list