Re: gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Rúben Rodrigues
Thanks!
So i could replate enter and leave to g_iddle_add, right?

gdk_threads_enter();
 g_printf("UpdateConfigNow\n");
 iUpdateConfigNow();
gdk_threads_leave();

To

g_idle_add((GCallback)iUpdateConfigNow, NULL);

Why i get this error?

Main.c:1824: undefined reference to `g_iddle_add'

Thanks


Às 11:49 de 28/03/2017, Gabriele Greco escreveu:

In gdk manual i see thath gdk_threads_enter and leave has been
deprecated and alll gdk and gtk+ calls should be made from main thread.
How we do this? Someone have any example?

You have to call g_idle_add (that is thread safe) every time you need to update 
one or more widgets from an external thread.

Let's think about a common situation, for instance you are encoding a video 
file and you want to update a progress bar:

[from encoding thread]
struct progress {
char label[50];
float value;
};

myprg = malloc(sizeof(struct progress));
myprg->value = 75.0;
strncpy(myprg->label, "Second pass", sizeof(myprg->label));
g_idle_add((GCallback)progress_update, myprg);

gboolean progress_update(struct progress *p);
{
 gtk_progress_bar_set_text(p->label);
 gtk_progress_bar_set_fraction(p->value);
 free(p);
 return FALSE; // it means that you want to run this only once
}

--
Bye,
 Gabry


[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
  Sem vírus. 
www.avast.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Howto integrate an inotify watch on editor file in GTK+2 event loop?

2017-03-28 Thread David C. Rankin
On 03/28/2017 10:38 PM, David C. Rankin wrote:
> Emmanuele,
> 
>   I need more help. I have implemented the watch with 'g_file_monitor_file'
> and registered a callback on the "changed" signal for the file, but I cannot
> get it to respond to any changes in the underlying file.

I got it -- it was user error (I was passing a relative rather than an
absolute filename and then monitoring on a relative name)...

-- 
David C. Rankin, J.D.,P.E.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Howto integrate an inotify watch on editor file in GTK+2 event loop?

2017-03-28 Thread David C. Rankin
On 03/28/2017 01:34 PM, David C. Rankin wrote:
> On 03/28/2017 02:06 AM, Emmanuele Bassi wrote:
>> Use GFileMonitor from GIO instead of directly dealing with inotify.
>>
>> Ciao,
>>  Emmanuele.
>>
> 
> Now that is the type of answer I was looking for! Thanks Emmanuele. That
> definitely keeps it much cleaner.
> 

Emmanuele,

  I need more help. I have implemented the watch with 'g_file_monitor_file'
and registered a callback on the "changed" signal for the file, but I cannot
get it to respond to any changes in the underlying file.

  Specifically, I created the GFileMonitor with:

GFileMonitor *file_monitor_add (const gchar *fn)
{
GFile *gfile = g_file_new_for_path (fn);
GCancellable *cancellable = g_cancellable_new();
GError *err=NULL;

GFileMonitor *filemon = g_file_monitor_file (gfile,
G_FILE_MONITOR_NONE,
cancellable, );
if (!filemon) {
err_dialog (err->message);
g_error_free (err);
g_object_unref (gfile);
return NULL;
}

g_print ("added watch for '%s'\n", fn);

// g_signal_connect (G_OBJECT(filemon), "changed",
// G_CALLBACK (file_monitor_on_changed), NULL);

g_object_unref (gfile);

return filemon;
}

NOTE: the first attempt to connect was shown above, but then according to the
documentation "The signal will be emitted in the thread-default main context
of the thread that the monitor was created". That has me confused (in addition
to the fact that the "changed" signal is never caught. I later connect at the
point the file is opened.

  The callback used (for testing purposes) is:

void file_monitor_on_changed (GFileMonitor *mon,
GFile *file, GFile *other,
GFileMonitorEvent evtype,
gpointer data)
{
g_print ("Monitor Event: File = %s\n", g_file_get_parse_name (file));

switch (evtype)
{
case G_FILE_MONITOR_EVENT_CHANGED:
dlg_info ("File Changed.", "changed Event Received");
break;
case G_FILE_MONITOR_EVENT_DELETED:
dlg_info ("File Deleted.", "changed Event Received");
break;
default:;
}

if (mon || other || data) {}
}

In the second attempt to connect, I moved connecting to the callback at the
point of file opening:

else {  /* opening file */
file_get_stats (filename, app); /* save file mode, UID, GID */
gtk_text_buffer_set_modified (buffer , FALSE);/* opened */
app->modified = FALSE;
status = g_strdup_printf ("loaded : '%s'", app->fname);
gtkwrite_window_set_title (NULL, app);  /* set window title */
/* add watch on file */
GFileMonitor *fm = file_monitor_add (app->fname);
g_signal_connect (G_OBJECT(fm), "changed",
G_CALLBACK (file_monitor_on_changed), NULL);

}

I can switch to a terminal and change, delete, move the opened file and the
callback never fires -- what's the trick? At least with the inotify
implementation, there changes were easy to catch. I think I'm stumbling over 
the:

"The signal will be emitted in the thread-default main context of the thread
that the monitor was created"

What do I have to do special to insure I'm looking for the signal in the
"thread-default main context". The editor makes no special use of separate
threads. What am I missing here, if anything.


-- 
David C. Rankin, J.D.,P.E.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Howto integrate an inotify watch on editor file in GTK+2 event loop?

2017-03-28 Thread David C. Rankin
On 03/28/2017 02:06 AM, Emmanuele Bassi wrote:
> Use GFileMonitor from GIO instead of directly dealing with inotify.
> 
> Ciao,
>  Emmanuele.
> 

Now that is the type of answer I was looking for! Thanks Emmanuele. That
definitely keeps it much cleaner.

-- 
David C. Rankin, J.D.,P.E.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


GtkIconView with custom icons

2017-03-28 Thread zahlenmeer
Usually, a GtkIconView uses a GtkTreeModel with a few important
columns. A column of type G_TYPE_STRING for the label or the markup and
a column of type GDK_TYPE_PIXBUF for the icon.
In my application I have a G_TYPE_OBJECT derived object that resembles
such an icon in the few, a row if you wish. It contains the label,
pixbuf and some other data, and also another pixbuf which I use as a
custom tooltip.
I'd like to know if there is a way to create a
GtkTreeModel/GtkListStore for the GtkIconView so I can still use the
gtk_icon_view_set_*_colum functions and have everything shown up
properly.
As an example, I use gtk_list_store_new (1, G_TYPE_OBJECT) but
obviously I have to columns that the icon view object could display,
the relevant data is "hidden" in the first and only column. And the
icon view will not display anything because the text/markup/pixbuf
columns are all set to -1.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Gabriele Greco
> But  now this functions aren't running. This is my main thread
> void *vGtkMain_Thread(gpointer data)
> {
> gdk_threads_enter();
> gtk_main();
> gdk_threads_leave();
> return NULL;
> }
>

You should remove everywhere in your code gtk_threads_ calls.

You cannot call gtk_label_get_text from a thread different from the gtk
main loop one, get the result of the call and pass it to the thread
function as parameter.

You should take care that the functions you call with g_idle_add() return
FALSE otherwise they will be called every time the main loop is idle using
100% of CPU (this can be a desired behaviour in some circumstances).

You should also take care that the global data you access in
iUpdateConfigNow, gbUpdateStatusNow... is not changed while you are
updating the GUI


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


SpinButton size

2017-03-28 Thread Rúben Rodrigues
hi guysm

it's possible to change size of spinbuttons? In touchscreen mode 
spinbutton are still small.. We can change it's size with css provider?

Thanks

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


Re: gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Gabriele Greco
>
>
> In gdk manual i see thath gdk_threads_enter and leave has been
> deprecated and alll gdk and gtk+ calls should be made from main thread.
> How we do this? Someone have any example?
>
> You have to call g_idle_add (that is thread safe) every time you need to
update one or more widgets from an external thread.

Let's think about a common situation, for instance you are encoding a video
file and you want to update a progress bar:

[from encoding thread]
struct progress {
char label[50];
float value;
};

myprg = malloc(sizeof(struct progress));
myprg->value = 75.0;
strncpy(myprg->label, "Second pass", sizeof(myprg->label));
g_idle_add((GCallback)progress_update, myprg);

gboolean progress_update(struct progress *p);
{
 gtk_progress_bar_set_text(p->label);
 gtk_progress_bar_set_fraction(p->value);
 free(p);
 return FALSE; // it means that you want to run this only once
}

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


gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Rúben Rodrigues
Hi guys,

My application sometimes have segmentation fault error. In debug mode 
and using g_print() i see that the applications stops in 
gdk_thread_leave function.

In gdk manual i see thath gdk_threads_enter and leave has been 
deprecated and alll gdk and gtk+ calls should be made from main thread. 
How we do this? Someone have any example?

Thanks!


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


Re: Howto integrate an inotify watch on editor file in GTK+2 event loop?

2017-03-28 Thread Emmanuele Bassi
Use GFileMonitor from GIO instead of directly dealing with inotify.

Ciao,
 Emmanuele.

On Tue, 28 Mar 2017 at 07:58, David C. Rankin <
drankina...@suddenlinkmail.com> wrote:

> All,
>
>   I have a small editor project I've worked on the past several months[1].
> I
> want to add an `inotify` watch on the current filename after each open or
> save
> to detect modification by a foreign process. I have the details of adding
> the
> watch and polling the file descriptor with `pselect`, creating a new
> signal to
> be emitted on the inotify events, and blocking/unblocking the signal for
> normal saves from within the editor, but where I'm stuck is how to
> incorporate
> monitoring `pselect` from the event loop after the `inotify` watchset is
> created?
>
>   Where normally, you would simply call a function that would check whether
> input was available on the file descriptor set monitored by `pselect` in a
> loop, where in the GTK event loop would you incorporate the call to
> `pselect`?
>
>   I may have the answer, but what I'm looking for in an answer is "Yes,
> that's
> a logical approach." or a "No, dummy that's going nowhere."
>
>   From the glib documentation, it appears that one logical vehicle for
> doing
> this is the `g_idle_add()` function which "Adds a function to be called
> whenever there are no higher priority events pending to the default main
> loop." This seems to match exactly what I'm trying to do. I could pass a
> flag
> via the data to control the return of TRUE/FALSE to remove from the list of
> funcitons called when the filename changes, etc.. and within the function
> check the return of `pselect` for any input and emit a signal if any
> changes
> were made to the file by a foreign process between the last check and now.
>
>   Is this the proper vehicle for adding/removing a bit of code to the event
> loop that I could use to monitor `pselect` or is there a better way of
> doing
> this? (the code is GTK+2, using the current glib functions, not the old
> `gtk_idle_add()`, if that makes any difference)
>
>   What say the experts?
>
> footnote 1: https://github.com/drankinatty/gtkwrite
>
> --
> David C. Rankin, J.D.,P.E.
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Howto integrate an inotify watch on editor file in GTK+2 event loop?

2017-03-28 Thread David C. Rankin
All,

  I have a small editor project I've worked on the past several months[1]. I
want to add an `inotify` watch on the current filename after each open or save
to detect modification by a foreign process. I have the details of adding the
watch and polling the file descriptor with `pselect`, creating a new signal to
be emitted on the inotify events, and blocking/unblocking the signal for
normal saves from within the editor, but where I'm stuck is how to incorporate
monitoring `pselect` from the event loop after the `inotify` watchset is 
created?

  Where normally, you would simply call a function that would check whether
input was available on the file descriptor set monitored by `pselect` in a
loop, where in the GTK event loop would you incorporate the call to `pselect`?

  I may have the answer, but what I'm looking for in an answer is "Yes, that's
a logical approach." or a "No, dummy that's going nowhere."

  From the glib documentation, it appears that one logical vehicle for doing
this is the `g_idle_add()` function which "Adds a function to be called
whenever there are no higher priority events pending to the default main
loop." This seems to match exactly what I'm trying to do. I could pass a flag
via the data to control the return of TRUE/FALSE to remove from the list of
funcitons called when the filename changes, etc.. and within the function
check the return of `pselect` for any input and emit a signal if any changes
were made to the file by a foreign process between the last check and now.

  Is this the proper vehicle for adding/removing a bit of code to the event
loop that I could use to monitor `pselect` or is there a better way of doing
this? (the code is GTK+2, using the current glib functions, not the old
`gtk_idle_add()`, if that makes any difference)

  What say the experts?

footnote 1: https://github.com/drankinatty/gtkwrite

-- 
David C. Rankin, J.D.,P.E.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list