Re: GObject properties and g_value_set_string()
Hi again, Yes, g_value_set_string() does call g_strdup(). bests, Joël On Thu, Feb 7, 2019 at 5:20 AM Joël Krähemann wrote: > > Hi all, > > Currently, I do my properties like following: > > http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/lib/ags_turtle.c?h=2.1.x#n175 > http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/lib/ags_turtle.c?h=2.1.x#n218 > > Is it ok to do g_strdup() and pass it to g_value_set_string()? > Or does g_value_set_string() duplicate the string for me? > > Does the following make any sense? > > g_value_set_string(value, g_strdup(turtle->filename)); > > This sample code is from GLib-2.0 API Reference Manual: > > > > gint intval; > gchar *strval; > GObject *objval; > > g_object_get (my_object, > "int-property", &intval, > "str-property", &strval, > "obj-property", &objval, > NULL); > > // Do something with intval, strval, objval > > g_free (strval); > g_object_unref (objval); > > > > Since I have to free the string, I just wonder if I need to g_strdup() it. > > bests, > Joël ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
GObject properties and g_value_set_string()
Hi all, Currently, I do my properties like following: http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/lib/ags_turtle.c?h=2.1.x#n175 http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/lib/ags_turtle.c?h=2.1.x#n218 Is it ok to do g_strdup() and pass it to g_value_set_string()? Or does g_value_set_string() duplicate the string for me? Does the following make any sense? g_value_set_string(value, g_strdup(turtle->filename)); This sample code is from GLib-2.0 API Reference Manual: gint intval; gchar *strval; GObject *objval; g_object_get (my_object, "int-property", &intval, "str-property", &strval, "obj-property", &objval, NULL); // Do something with intval, strval, objval g_free (strval); g_object_unref (objval); Since I have to free the string, I just wonder if I need to g_strdup() it. bests, Joël ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: string interpolation
Hi, As you set a string property of a Gtk+ widget, the string is usually duplicated. However don't call any Gtk+ function outside the main loop, i.e. from a different thread. Bests, Joël On Fri, Dec 21, 2018 at 9:49 AM Lutz Lümken wrote: > > Hello, > > does GTK have some kind of string interpolation or can I safely display > user input strings in the widgets without anything unexpected (code > injection, formatting etc.) to happen? > > Best regards, > Lutz Lümken > -- > Lutz Lümkenluem...@pre-sense.de > PRESENSE Technologies GmbHSachsenstr. 5, D-20097 HH > Geschäftsführer/Managing Directors AG Hamburg, HRB 107844 > Till Dörges, Jürgen Sander USt-IdNr.: DE263765024 > > ___ > 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
Re: Working with embedded images with GResource, GdkPixbuf and GtkWidget
Hi, First you create a GdkPixbuf: https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Image-Data-in-Memory.html#gdk-pixbuf-new-from-data then set the property of about dialog: https://developer.gnome.org/gtk2/stable/GtkAboutDialog.html#GtkAboutDialog--logo g_object_set(your_about_dialog, "logo", your_pixbuf, NULL); Why don't you use just following? https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-File-Loading.html#gdk-pixbuf-new-from-file Bests, Joël On Sun, Nov 11, 2018 at 6:23 PM Alessandro Francesconi wrote: > > Hello, > > > > I need to show some images inside my GTK+ 2.32 application so I decided to > embed them using GResource compiler. > > I’ve prepared an XML file like this: > > > > > > > > > > logo.png ><…..> > > > > > > > > And after “glib-compile-resources.exe --target=icons.c --generate icons.xml”, > I correctly have a .c file with images encoded inside. > > > > Problem here: i need that images to be shown in About dialog > (gtk_show_about_dialog) and buttons (gtk_button_set_image). As far as I know, > to accomplish this I have to create GdkPixbuf (for gtk_about_dialog_set_logo) > and GtkWidget (for gtk_button_set_image). I tried with this code but got some > issues (see the comments): > > > > --- > > GResource* icons = icons_get_resource(); > > GBytes* data = g_resource_lookup_data(icons, path, > G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); > > gsite size = g_bytes_get_size(data); // <-- this works since I have no > errors and the size is > 0, so I expect data to be ok > > > > // now I need to create a GdkPixbuf, is that the correct way? > > GError* e = NULL; > > GdkPixbuf* pixbuf; > > pixbuf = gdk_pixbuf_new_from_inline(g_bytes_get_size(data), data, FALSE, > &e); > // error here! Message is “Image header corrupt” > > > > // if worked… I’d continue by also getting the GtkWidget image with: > GtkWidget* image; > > image = gtk_image_new_from_pixbuf(pixbuf); > > --- > > > > I can’t really understand how Pixbuf expects from the GResource data… also i > read in the docs that “gdk_pixbuf_new_from_inline has been deprecated since > version 2.32 and should not be used in newly-written code. Use GResource > instead.”… so what’s the correct way to create Pixbuf for About boxes and > GdkWidgets for image button? > > > > Thanks for the support > > Alessandro > > > > ___ > 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
Re: is there a signal for typing at bottom of window?
Hi again, For sure you should probably use: g_signal_connect_after(your_text_buffer, "changed", G_CALLBACK(your_text_buffer_changed_callback), your_data); and YOUR_DATA(your_data) just casts to your pointer to a struct or object containing some information: struct _YourData{ gint last_newline_position; }; Well this is it. Bests, Joël On Wed, Sep 26, 2018 at 7:12 AM Joël Krähemann wrote: > > Hi, > > g_object_get(your_text_view, > "buffer", &your_text_buffer, > NULL); > g_signal_connect(your_text_buffer, "changed", > G_CALLBACK(your_text_buffer_changed_callback), your_data); > > void your_text_buffer_changed_callback(GtkTextBuffer > *your_text_buffer, gpointer your_data) > { > gint line_count; > > line_count = gtk_text_buffer_get_line_count(your_text_buffer); > > if(line_count > YOUR_DATA(your_data)->line_count){ > gchar *your_text; > > g_object_get(your_text_buffer, > "text", &your_text, > NULL); > > if(your_text[strlen(your_text) - 1] == '\n' && > YOUR_DATA(your_data)->last_newline_position < > &(your_text[strlen(your_text) - 1]) - your_text){ > //TODO:DMC: implement me > } > } > } > > by, > Joël > > On Wed, Sep 26, 2018 at 6:49 AM Doug McCasland wrote: > > > > Eric, thanks for the ideas! > > > > I tried a bunch of things to distinguish the callbacks, but it got too > > complicated. Checking for a different line number is a clever idea, but > > PgUp and PgDown also move the cursor which changes the line number. > > Similar problems for tracking the char offset in the line (for simply > > typing at the end of the last visible line, not creating a new line/para). > > > > So, it would be nice if there was a simple signal for this case, where the > > window scrolls because of keyboard input in the last visible line. > > > > The reason I want this is, is so my app can scroll the window > > automatically, so that the cursor insert point becomes centered > > vertically. In other words, when I'm typing a long paragraph, and it's the > > last visible line, I want it to scroll up, so I'm now typing in the middle > > of the window (vs. continuing to type on the last visible line). > > > > I suppose this is a bit esoteric. > > > > I did create a kbd shortcut to do that scroll manually: > > > > gtk_text_view_scroll_to_iter(..., 0.0, TRUE, 1.0, 0.5) > > > > so I have that to use. > > > > > > On Tue, Sep 25, 2018 at 2:34 PM wrote: > > > > > > > > Not sure how to go about this myself. I see the extra callbacks and it > > > would be a good thing to limit them. For filtering maybe check if the > > > cursor has changed lines along with the adjustment value change. Suspect > > > there is a better solution for this. > > > > > > static void value_changed(GtkAdjustment *v_adjust, gpointer textview) > > > { > > > static gint s_line=0; > > > GtkTextIter iter; > > > GtkTextBuffer > > > *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); > > > GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert"); > > > gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); > > > gint line=gtk_text_iter_get_line(&iter); > > > if(s_line!=line) > > > { > > > g_print("Scroll Line\n"); > > > s_line=line; > > > } > > > } > > > > > > Eric > > > > > > > > > -Original Message- > > > From: Doug McCasland > > > To: cecashon > > > Sent: Tue, Sep 25, 2018 2:10 pm > > > Subject: Re: is there a signal for typing at bottom of window? > > > > > > Actually I get 11 signals with a different setting of: > > > gtk_text_view_set_pixels_inside_wrap() > > > > > > So it's one signal per vertical pixel perhaps? I can code for that. > > > > > > But I also I get those signals during any scrolling (scrollbar or > > > mousewheel). How can I distinguish between automatic scrolling at bottom > > > and user-commanded scrolling? > > > > > > thanks > > > > > > > > > > > > > > > > > > On Tue, Sep 25, 2018 at 1:47 PM Doug McCasland > > > wrote: > > > > > > Woo-hoo, that works! > > > > > > BUT, I get 12 signals for each line that is auto-scrolled. I can code for > > > this, but why 12? Will it always be 12? > > > > > > > > > On Tue, Sep 25, 2018 at 11:46 AM wrote: > > > > > > > > > Hi Doug, > > > > > > Try getting the vertical adjustment of the scrolled window and connect to > > > "value-changed". See if that will work. Something like > > > > > > ... > > > static void value_changed(GtkAdjustment *v_adjust, gpointer user_data) > > > { > > > } > > > ... > > > GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL); > > > GtkAdjustment > > > *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll)); > > > g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed), > > > NULL); > > > ... > > > > > > Eric > > > > > > > > > > > > > > > > > > -- > > > Doug McCasland > > > > > > > > > > > > -- > > > Doug McCasland > > > > > > > > > -- > > Doug McCasland > > ___
Re: is there a signal for typing at bottom of window?
Hi, g_object_get(your_text_view, "buffer", &your_text_buffer, NULL); g_signal_connect(your_text_buffer, "changed", G_CALLBACK(your_text_buffer_changed_callback), your_data); void your_text_buffer_changed_callback(GtkTextBuffer *your_text_buffer, gpointer your_data) { gint line_count; line_count = gtk_text_buffer_get_line_count(your_text_buffer); if(line_count > YOUR_DATA(your_data)->line_count){ gchar *your_text; g_object_get(your_text_buffer, "text", &your_text, NULL); if(your_text[strlen(your_text) - 1] == '\n' && YOUR_DATA(your_data)->last_newline_position < &(your_text[strlen(your_text) - 1]) - your_text){ //TODO:DMC: implement me } } } by, Joël On Wed, Sep 26, 2018 at 6:49 AM Doug McCasland wrote: > > Eric, thanks for the ideas! > > I tried a bunch of things to distinguish the callbacks, but it got too > complicated. Checking for a different line number is a clever idea, but > PgUp and PgDown also move the cursor which changes the line number. > Similar problems for tracking the char offset in the line (for simply > typing at the end of the last visible line, not creating a new line/para). > > So, it would be nice if there was a simple signal for this case, where the > window scrolls because of keyboard input in the last visible line. > > The reason I want this is, is so my app can scroll the window > automatically, so that the cursor insert point becomes centered > vertically. In other words, when I'm typing a long paragraph, and it's the > last visible line, I want it to scroll up, so I'm now typing in the middle > of the window (vs. continuing to type on the last visible line). > > I suppose this is a bit esoteric. > > I did create a kbd shortcut to do that scroll manually: > > gtk_text_view_scroll_to_iter(..., 0.0, TRUE, 1.0, 0.5) > > so I have that to use. > > > On Tue, Sep 25, 2018 at 2:34 PM wrote: > > > > > Not sure how to go about this myself. I see the extra callbacks and it > > would be a good thing to limit them. For filtering maybe check if the > > cursor has changed lines along with the adjustment value change. Suspect > > there is a better solution for this. > > > > static void value_changed(GtkAdjustment *v_adjust, gpointer textview) > > { > > static gint s_line=0; > > GtkTextIter iter; > > GtkTextBuffer > > *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); > > GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert"); > > gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); > > gint line=gtk_text_iter_get_line(&iter); > > if(s_line!=line) > > { > > g_print("Scroll Line\n"); > > s_line=line; > > } > > } > > > > Eric > > > > > > -Original Message- > > From: Doug McCasland > > To: cecashon > > Sent: Tue, Sep 25, 2018 2:10 pm > > Subject: Re: is there a signal for typing at bottom of window? > > > > Actually I get 11 signals with a different setting of: > > gtk_text_view_set_pixels_inside_wrap() > > > > So it's one signal per vertical pixel perhaps? I can code for that. > > > > But I also I get those signals during any scrolling (scrollbar or > > mousewheel). How can I distinguish between automatic scrolling at bottom > > and user-commanded scrolling? > > > > thanks > > > > > > > > > > > > On Tue, Sep 25, 2018 at 1:47 PM Doug McCasland > > wrote: > > > > Woo-hoo, that works! > > > > BUT, I get 12 signals for each line that is auto-scrolled. I can code for > > this, but why 12? Will it always be 12? > > > > > > On Tue, Sep 25, 2018 at 11:46 AM wrote: > > > > > > Hi Doug, > > > > Try getting the vertical adjustment of the scrolled window and connect to > > "value-changed". See if that will work. Something like > > > > ... > > static void value_changed(GtkAdjustment *v_adjust, gpointer user_data) > > { > > } > > ... > > GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL); > > GtkAdjustment > > *v_adjust=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scroll)); > > g_signal_connect(v_adjust, "value-changed", G_CALLBACK(value_changed), > > NULL); > > ... > > > > Eric > > > > > > > > > > > > -- > > Doug McCasland > > > > > > > > -- > > Doug McCasland > > > > > -- > Doug McCasland > ___ > 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
Fwd: question about gtk_dialog (gtk2)
-- Forwarded message - From: Joël Krähemann Date: Thu, Jun 21, 2018 at 1:31 PM Subject: Re: question about gtk_dialog (gtk2) To: Wojciech Puchar Hi, Alternatively, you could inherit GTK_TYPE_DIALOG and do your very own object. During ::map() and ::realize() you are able to modify the GdkWindow. Just query parent and child elements for their dimensions. Just implement: GtkWidget::map() GtkWidget::realize() GtkWidget::size-allocate() GtkWidget::size-request() Bests, Joël On Thu, Jun 21, 2018 at 1:21 PM, Joël Krähemann wrote: > Hi, > > FYI some properties are only valid as constructor. > > cheers, > Joël > > > On Thu, Jun 21, 2018 at 1:11 PM, Joël Krähemann wrote: >> Hi Wojciech, >> >> What about: >> >> dialog = g_object_new(GTK_TYPE_DIALOG, >> "window-position", GTK_WIN_POS_CENTER, >> NULL); >> >> bests, >> Joël >> >> >> On Fri, Jun 15, 2018 at 1:43 PM, Wojciech Puchar >> wrote: >>> how to make dialogs appear on center of screen not on left corner. tried >>> multiple things no results. For normal windows gtk_window_set_position works >>> >>> for dialog it doesn't >>> >>> below is example routine to ask a yes/no question from my program. >>> >>> >>> i've tried >>> gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS); >>> >>> but it doesn't work >>> >>> >>> nt pytanie(const char *txt) { >>> GtkWidget *dialog,*lab; >>> int odpowiedz; >>> >>> dialog=gtk_dialog_new_with_buttons(TEXT_QUESTION,NULL,GTK_DIALOG_DESTROY_WITH_PARENT, >>> TEXT_TAK,GTK_RESPONSE_ACCEPT,TEXT_NIE,GTK_RESPONSE_NONE,NULL); >>> lab=new_label(txt); >>> gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG >>> (dialog))), lab); >>> odpowiedz=gtk_dialog_run(GTK_DIALOG(dialog)); >>> gtk_widget_destroy(dialog); >>> return (odpowiedz==GTK_RESPONSE_ACCEPT); >>> } >>> >>> ___ >>> 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
Fwd: question about gtk_dialog (gtk2)
-- Forwarded message - From: Joël Krähemann Date: Thu, Jun 21, 2018 at 1:21 PM Subject: Re: question about gtk_dialog (gtk2) To: Wojciech Puchar Hi, FYI some properties are only valid as constructor. cheers, Joël On Thu, Jun 21, 2018 at 1:11 PM, Joël Krähemann wrote: > Hi Wojciech, > > What about: > > dialog = g_object_new(GTK_TYPE_DIALOG, > "window-position", GTK_WIN_POS_CENTER, > NULL); > > bests, > Joël > > > On Fri, Jun 15, 2018 at 1:43 PM, Wojciech Puchar > wrote: >> how to make dialogs appear on center of screen not on left corner. tried >> multiple things no results. For normal windows gtk_window_set_position works >> >> for dialog it doesn't >> >> below is example routine to ask a yes/no question from my program. >> >> >> i've tried >> gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS); >> >> but it doesn't work >> >> >> nt pytanie(const char *txt) { >> GtkWidget *dialog,*lab; >> int odpowiedz; >> >> dialog=gtk_dialog_new_with_buttons(TEXT_QUESTION,NULL,GTK_DIALOG_DESTROY_WITH_PARENT, >> TEXT_TAK,GTK_RESPONSE_ACCEPT,TEXT_NIE,GTK_RESPONSE_NONE,NULL); >> lab=new_label(txt); >> gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG >> (dialog))), lab); >> odpowiedz=gtk_dialog_run(GTK_DIALOG(dialog)); >> gtk_widget_destroy(dialog); >> return (odpowiedz==GTK_RESPONSE_ACCEPT); >> } >> >> ___ >> 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
Fwd: question about gtk_dialog (gtk2)
-- Forwarded message - From: Joël Krähemann Date: Thu, Jun 21, 2018 at 1:11 PM Subject: Re: question about gtk_dialog (gtk2) To: Wojciech Puchar Hi Wojciech, What about: dialog = g_object_new(GTK_TYPE_DIALOG, "window-position", GTK_WIN_POS_CENTER, NULL); bests, Joël On Fri, Jun 15, 2018 at 1:43 PM, Wojciech Puchar wrote: > how to make dialogs appear on center of screen not on left corner. tried > multiple things no results. For normal windows gtk_window_set_position works > > for dialog it doesn't > > below is example routine to ask a yes/no question from my program. > > > i've tried > gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS); > > but it doesn't work > > > nt pytanie(const char *txt) { > GtkWidget *dialog,*lab; > int odpowiedz; > > dialog=gtk_dialog_new_with_buttons(TEXT_QUESTION,NULL,GTK_DIALOG_DESTROY_WITH_PARENT, > TEXT_TAK,GTK_RESPONSE_ACCEPT,TEXT_NIE,GTK_RESPONSE_NONE,NULL); > lab=new_label(txt); > gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG > (dialog))), lab); > odpowiedz=gtk_dialog_run(GTK_DIALOG(dialog)); > gtk_widget_destroy(dialog); > return (odpowiedz==GTK_RESPONSE_ACCEPT); > } > > ___ > 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