Re: watching a file descriptor in gtk3

2017-01-23 Thread Eric Cashon via gtk-app-devel-list

 
Hi Roger,

I put together a test example of GSubprocess. It starts Gnuplot, sets up the 
pipes and callbacks, and then when Gnuplot is done it opens the graph in an 
image widget. The GSubprocess will take care of the file descripters for you. 
Also, if I run valgrind with multiple plots being created it doesn't leak 
memory over time. It looks like the subprocess holds everything you need and 
when it is unreferenced everything gets cleaned up. If you want to just run one 
plot, comment out the plot_data() function in the subprocess finish callback. 
Also to get an error back to the program you can do something like changing 
"set ylabel" to "et ylabel" or something of the sort. Change things around to 
get an idea of how they work.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Pipes/gnuplot5.c

This might not be what you are looking for since it is a little higher level 
than using a spawn function but there are a lot of things set up with 
GSubprocess that make it worth consideration. Options. You can do some nice 
plotting with GTK+ and Gnuplot also.

Eric 

 

 



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


Re: Does gtk2 provide a case 'in'-sensitive text search via 'gtk_text_iter_..._search'?

2017-01-26 Thread Eric Cashon via gtk-app-devel-list

 

I worked on this a little more and tried to make it UTF-8 compliant. 
Highlighted the text also. It should still be efficient since it is only doing 
a single pass over each char. I am sure there are things that I haven't 
considered but it does a little more than the first try at it.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Csamples/search_textbuffer1.c

There are a lot of different functions that you can branch off with this. Most 
are supplied by GTK+ but you never know when you will have need for a special 
purpose function for a text buffer.

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


Re: Does gtk2 provide a case 'in'-sensitive text search via 'gtk_text_iter_..._search'?

2017-02-17 Thread Eric Cashon via gtk-app-devel-list

 David,

I asked a question about this on the gtk-devel-list

https://mail.gnome.org/archives/gtk-devel-list/2017-January/msg00018.html

last month. A lot I didn't know about this. For UTF-8 it is a bit complicated 
even for English. For GTK's case in-sensitive search they use a casefold 
function and a normalizing function. This way you can do a case in-sensitive 
search on strings with ligatures and accents. If you are just sticking with 
asci english chars then just converting and comparing case should work. There 
is a bit more to it though for UTF-8 and unicode chars.

I worked on this a little bit so that I could understand it better. My last 
attempt was

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Csamples/search_textbuffer4.c

The GTK developers are working on GTK4. GTK3.22 should be stable for 3. GTK2 or 
3 is fine with me.

Eric


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


Re: Programatically activate menu like a mouse click

2017-02-23 Thread Eric Cashon via gtk-app-devel-list

 

Hi John,

Give this a try. It might be close to what you are after.

Eric

#!/usr/bin/python

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk

class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Menu Popup")
self.set_default_size(200, 100)
self.set_position(Gtk.WindowPosition.CENTER)
  
self.menubar1 = Gtk.MenuBar()  
self.menu1 = Gtk.Menu()
self.menuitem1 = Gtk.MenuItem("Menu") 
self.menuitem1.set_submenu(self.menu1)
self.menuitem2 = Gtk.MenuItem("Save")   
self.menuitem2.connect("activate", self.save_file)  
self.menuitem3 = Gtk.MenuItem("Print")
self.menuitem3.connect("activate", self.print_file)   
self.menu1.append(self.menuitem2)
self.menu1.append(self.menuitem3) 
self.menubar1.append(self.menuitem1)

self.connect("key-press-event", self.key_pressed)   

self.grid = Gtk.Grid()
self.grid.attach(self.menubar1, 0, 0, 1, 1)
self.add(self.grid)

def save_file(self, menuitem2):
print("Save File")

def print_file(self, menuitem3):
print("Print File")

def key_pressed(self, widget, event):
print("Key Pressed")
print(str(event.keyval)) 
self.menu1.popup(None, None, None, None, 0, event.time)
return False

win = MainWindow()
win.connect("delete-event", Gtk.main_quit) 
win.show_all()
Gtk.main()



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


Re: Does gtk2 provide a case 'in'-sensitive text search via 'gtk_text_iter_..._search'?

2017-02-23 Thread Eric Cashon via gtk-app-devel-list

 
Hi David,

I tried out gtkedit and it compiled and worked fine. Did a few searches and 
it found the words. 
When I compiled I got a few warnings like the following.

gtk_common_dlg.c: In function ‘err_dialog’:
gtk_common_dlg.c:8:9: warning: format not a string literal and no format 
arguments [-Wformat-security]
 g_warning (errmsg); /* log to terminal window */

I don't know if they are coming up on your computer but they are easy ones to 
fix.
 Are you going to give finding ligatures and accents a try? I am not very 
good with languages, stuck with English, but it is pretty interesting how 
things are put together with UTF-8 to allow for all different types of 
characters in languages. 

Eric

 


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

Re: Removing entries from EntryCompletion

2017-02-13 Thread Eric Cashon via gtk-app-devel-list
Hi Jeff,

For this you need the private data of the entry completion to get it to work. 
That means looking around the GTK source and seeing how you might put something 
together. Of course, it is not recommended to use something that can be changed 
at anytime by the GTK developers. So... I gave it a try to see if it could be 
done. I got something working but it might very well interfere with other code. 

The list completion gets data for the list store from /usr/bin for testing. You 
can delete the items from the list store with the delete key while the item is 
selected. Your programs will still be safe in /usr/bin.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Csamples/entry_completion2.c

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


Re: GtkPrintOperation; request for assistance

2017-02-10 Thread Eric Cashon via gtk-app-devel-list

 

 
I didn't get to the paper size setup there. Just tried to make sense out of 
getting text to print on multiple pages as simply as possible. I don't have a 
printer that I can test with either so I am no help there.

Printing is difficult. You can draw easy enough on a drawing area but then to 
fit a big drawing with text onto multiple pages of different sizes is tough. I 
have spent a number of hours trying to figure that sort of thing out myself and 
still don't have the best way to do it. All the tools are there with cairo, 
pango along with lots of string functions. Getting everything measured and 
placed correctly is not so easy.

It would be useful to be able to just put text into a layout automatically from 
a text buffer for multiple pages. Emmanuele's code looks like he has it all 
setup to do that but I think you might have to make a change or two in the 
GdictPrintData struct and code depending on where the text is coming from. He 
also uses a struct to hold printing info so you don't have to calculate it more 
than once like I did. A better way to go about it.

Yes, I think there is room for improvement in printing.

Eric


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


Re: GtkPrintOperation; request for assistance

2017-02-09 Thread Eric Cashon via gtk-app-devel-list

 

Hi Norbert,

I hit the reply instead of reply all on the first send. Try again.

There is some information about printing at

https://developer.gnome.org/gtkmm-tutorial/stable/chapter-printing.html.en

It is in C++ but the C++ tutorial is very good. Sometimes I go there to figure 
out how to do something and translate it to C.

For a simple printing example in C this is my try at it. 

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Csamples/print_buffer1.c

Change the font size and see if it fits the numbers on the different pages.

Eric

 

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


Re: Does gtk2 provide a case 'in'-sensitive text search via 'gtk_text_iter_..._search'?

2017-01-19 Thread Eric Cashon via gtk-app-devel-list

 In GTK3 you would have everything that you need. The 
gtk_text_iter_forward_search() function can use 
GTK_TEXT_SEARCH_CASE_INSENSITIVE. I don't see that in GTK2.

Another thought. The GTK Source View can find words and highlight them for you. 
You might want to check that out also. It has some search settings that might 
be what you are trying to do.

https://developer.gnome.org/gtksourceview/stable/GtkSourceSearchSettings.html

For GTK2? I think you might have to test some pointer code out to do this. 
Maybe something like the following for a rough idea. I would strongly recommend 
going with GTK3 though.


//gcc -Wall textview2.c -o textview2 `pkg-config --cflags --libs gtk+-2.0`

#include 

static void button_clicked(GtkWidget *button, gpointer *data)
  {
GtkTextIter start;
gchar *search_string=g_strdup(gtk_entry_get_text(GTK_ENTRY(data[1])));
gchar *p=search_string;
glong count=g_utf8_strlen(search_string, -1);
glong counter=0;
gchar temp_string[count+1];
temp_string[count]='\0';

gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(data[0]), );
do
  {

if(g_unichar_toupper(g_utf8_get_char(p))==gtk_text_iter_get_char()||g_unichar_tolower(g_utf8_get_char(p))==gtk_text_iter_get_char())
  {
temp_string[counter]=gtk_text_iter_get_char();
counter++;
p++;
if(counter>=count)
  {
g_print("%s\n", temp_string);
counter=0;
p=search_string;
  }
  }
else
  {
if(counter>0)
  {
counter=0;
p=search_string;
  }
  }
  }while(gtk_text_iter_forward_char());

g_free(search_string);

  }
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Textview");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 20);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *textview=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_WORD);
gtk_widget_set_size_request(textview, 400, 300);
GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_set_text(buffer, "SEArch Add some words to Search search 
SearCH SEaRch search search Search and a few extra s ss sssr Sea Sear.", -1);

GtkWidget *entry=gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(entry), "search");

GtkWidget *button=gtk_button_new_with_label("Search");
gpointer test[]={buffer, entry};
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), test);

GtkWidget *table=gtk_table_new(3, 1, FALSE);
gtk_table_attach(GTK_TABLE(table), textview, 0, 1, 0, 1, GTK_EXPAND, 
GTK_EXPAND, 0, 0);
gtk_table_attach(GTK_TABLE(table), entry, 0, 1, 1, 2, GTK_EXPAND, 
GTK_SHRINK, 0, 0);
gtk_table_attach(GTK_TABLE(table), button, 0, 1, 2, 3, GTK_EXPAND, 
GTK_SHRINK, 0, 0);

gtk_container_add(GTK_CONTAINER(window), table);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }


 


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


Re: Strange 'regression' in gtk+/gstreamer app

2016-12-09 Thread Eric Cashon via gtk-app-devel-list

It could be a problem with the double buffering.

gtk_widget_set_double_buffered()

Try to set that to false and see if that makes any difference. This is on 
Linux? Usually you don't need this function any more and it is deprecated but 
it can sometimes still be useful. I know to get gnuplot pictures to redraw 
without flickering or a white background, it needs to be false.

I did a little gstreamer experimentation a little while back with the webcam 
video. It works without gtk_widget_set_double_buffered() using Ubuntu 16.04, 
GTK3.18 and gstreamer1.0. No flickering that I can see. I don't have a 
scrollbar in there though. It might be helpful.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Sound/webcam3.c
 

Eric
 

 


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


Re: Ideas of new widgets and critics, only for enhance gtk+.

2016-12-11 Thread Eric Cashon via gtk-app-devel-list

You can create your own widgets to look and work like you want with GTK+. There 
is a good example on the gtkmm tutorial which is worth looking at if you are 
interested in doing this. It also shows a little on how you can use CSS to set 
some properties on your new widget.

https://developer.gnome.org/gtkmm-tutorial/stable/sec-custom-widgets.html.en

Even if C++ isn't your thing the gtkmm tutorial is worth taking a look at. A 
lot more examples there compared to the GTK+ C tutorial and they go over a few 
things before they spring the trivial app on you.

I like C and have been testing out some switches derived from a GTK drawing 
area. Sort of some car things like a rocker "toggle" switch, circuit breaker 
switch and gauges. They are with a few simple test programs to see how they 
work.

https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc

The gtkmm tutorial with the penrose triangle I rewrote in C so that I can get 
an understanding of how the CSS works. It is simpler than the gtkmm tutorial 
since deriving from a drawing area is a little easier than from a widget.

Give making a widget a try. That way you can create what you want and be able 
to use the whole GTK+ framework to build the kind of program you might be 
thinking about.

Eric

 

 


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


Re: Strange 'regression' in gtk+/gstreamer app

2016-12-12 Thread Eric Cashon via gtk-app-devel-list

 

My guess is that it has something to do with how GTK is drawing. Look at the 
double buffered reference.

https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-double-buffered

For drawing transparent backgrounds GTK changed something in the drawing code 
in 3.10. When I was using 3.10 and trying to draw transparent windows they 
would work sometimes and then they wouldn't. I think that got fixed sometime in 
3.10 but then that caused the double buffering set to false not to work 
anymore. I used to be able to send an X window id to gnuplot and it would draw 
directly on the window. That doesn't work in 3.18 but did in 3.10. With 
gstreamer it still needs a X window id but it works with the updates with GTK 
but not with double buffering set to false anymore or it just ignores it. Some 
of the older gstreamer code has the double buffering always set to false. It 
isn't needed anymore. You probably don't want to set it to false if you are 
using GTK after version 3.10 on any of the drawing areas.

I don't know the internals of why this is. Just from testing some code out but 
this is my understanding of it. I will have to test a few more things out.



 



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


Re: gtk3 and fork/exec of non-gtk child

2017-01-14 Thread Eric Cashon via gtk-app-devel-list

 
Hi Roger,

A little while back I was testing something similar with 
g_spawn_async_with_pipes(). It is neither mission-critical or meticulous but 
something I was just testing for the possible use with gnuplot. There is a 
driver.c and a worker.c program. The driver spawns the worker and sets up some 
communication. You just need to set the location path of the worker in 
driver.c. Sort of simple but I had some trouble figuring out how some of this 
worked so... it might be helpful. 

https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/Pipes

I haven't used GSubprocess and don't know of a short starter there.

Eric

 


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


Re: deprecated gtk_cairo_create

2016-12-30 Thread Eric Cashon via gtk-app-devel-list
Hi Roger,

Would this be similar to using a GtkLayout and a GtkDrawingArea? If you add a 
drawing area to a layout you get draw scrolling and the layout can update the 
part of the drawing area shown on the screen even though the drawing might be 
on a larger area.

Eric

 

 

 

-Original Message-
From: rbd 
To: gtk-app-devel-list 
Sent: Fri, Dec 30, 2016 12:24 pm
Subject: Re: deprecated gtk_cairo_create

Hello Sergei,

Unfortunately the use of the gtk3 DrawingArea is a bit obscure and 
difficult to figure out. However, I have been able to make use of it very 
effectively in conjunction with Cairo drawing ops.

For various reasons I have created a GUI toolkit library which lies 
between my app code and gtk3. This library includes an object known as a 
Canvas, which is essentially a toplevel window with scrollbars parenting a 
DrawingArea. The Canvas object includes a private off-screen Cairo drawing 
surface which I create and control completely, and I do all of my 
application drawing onto that surface. Then, I use the gtk3 draw signal 
mechanism to copy whatever recatngular areas I want from my private 
surface onto the DrawingArea. gtk3 passes to my drawing event handler a 
pointer to a Cairo context which addresses the DrawingArea's own Cairo 
surface, so all I need to do in the draw event handler is set a source 
surface on that context (in my case, the source surface is my own private 
Cairo surface), and copy a rectangle. As far as I know there is no safe 
way to access the Cairo surface of a gtk3 DrawingArea other than through 
the Cairo context pointer passed into the drawing event handler.

Following is some incomplete, stripped down code which may help to explain 
the above ideas. I hope this helps!

Roger Davis
Univ. of Hawaii

# code follows ###

/* Here are the relevant parts of the Canvas structure */
typedef struct {
 ...
 GtkWidget *drawarea;/* created by gtk_drawing_area_new() */
 int width, height;  /* size of DrawingArea */
 cairo_surface_t *surface; /* my private Cairo surface */
 ...
} Canvas;

gboolean
canvasdrawevt(GtkWidget *w, cairo_t *cr, gpointer gp)
/*
This internal routine handles draw signals sent by GTK+3 to a Canvas'
GtkDrawingArea widget. These signals will typically be generated by
expose events or by program calls to gtk_widget_queue_draw_area()
generated from within canvasflushregion(). This routine merely copies
the rectangle(s) of interest from the off-screen Cairo drawing surface
of the canvas into the actual GtkDrawingArea widget.
*/
{
 Canvas *c;

 if (gp == (gpointer) 0)
return FALSE;
 c= (Canvas *) gp;
 if (w != c->drawarea)
  return FALSE;

 /* here I set the source to my private
surface which I have already drawn */
 cairo_set_source_surface(cr, c->surface, 0, 0);

 /* note that according to various (and occasionally obscure)
GTK+3 docs, the context cr passed into this routine has
already been clipped to any exposed rectangle(s) of interest
(or whatever canvasflush{reg}() has marked for redraw via
its call to gtk_widget_queue_draw_area()), so the following
   call to copy the whole drawing surface is not as expensive
as it looks! */
 cairo_rectangle(cr, 0, 0, (double) c->width, (double) c->height);
 cairo_fill(cr);

 return TRUE;
}

/* Here is how the important parts of the Canvas are created ... */

Canvas *
canvascreate(gint width, gint height, ... )
{
 Canvas *c;
 int i;
 GtkWidget *win, *lo, *sw;
 GdkGeometry geom;

   if ((c= (Canvas *) calloc((MemSizeType) 1, sizeof(Canvas))) == (Canvas 
*) 0)
   return (Canvas *) 0;

 ...

 /* create the DrawingArea */
  c->width= width;
 c->height= height;
 if ((c->drawarea= gtk_drawing_area_new()) == (GtkWidget *) 0) {
 canvasdestroy(c);
 return (Canvas *) 0;
 }
 gtk_widget_set_size_request(c->drawarea, width, height);
 gtk_widget_set_can_focus(c->drawarea, TRUE);
 ...

 /* attach the drawing event handler */
 g_signal_connect((gpointer) c->drawarea, "draw", 
G_CALLBACK(canvasdrawevt), (gpointer) c);
 ...

 /* create our private Cairo surface on which we will draw
everything */
 if ((c->surface= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int) 
width, (int) height)) == (cairo_surface_t *) 0) {
 canvasdestroy(c);
 return (GITCanvas *) 0;
 }
...

 return c;
}

/* Call this routine to copy our private Cairo surface to the DrawingArea
whenever we want (i.e., after we have done all our drawing into the
former).  A call to this routine will result in our drawing 

Re: gtk_dialog_get_action_area() deprecation

2016-12-31 Thread Eric Cashon via gtk-app-devel-list

 

 I like the gtk_dialog_get_action_area() function. It makes it easy to set 
something like the border width of the container. 

action_area=gtk_dialog_get_action_area(GTK_DIALOG(dialog));
gtk_container_set_border_width(GTK_CONTAINER(action_area), 20);

Maybe no big deal and can be done in a different way but it can be handy for 
dialog design.

Eric

 



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


Re: gtk_dialog_get_action_area() deprecation

2016-12-31 Thread Eric Cashon via gtk-app-devel-list

 

 Hi Emmanuele,

I see the style property "action-area-border" in the documentation for the 
Dialog. Still learning how to use CSS effectively and am using GTK3.18 
currently which has a different CSS syntax than the newer GTK versions. Figure 
I will still use a few deprecated functions so I don't need two different CSS 
strings for the rest of the GTK3 run and start using more of the CSS 
functionality when GTK4 comes out.

Eric

 



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


Re: Seperating Multiple processes

2017-03-17 Thread Eric Cashon via gtk-app-devel-list

 
Some follow up on this. If you are starting a separate process to run your 
transcoding you need to use an async version of your run_cmd(). Otherwise the 
program will wait until the function returns and bind up the main glib thread 
if the function takes a while. This might be the easiest way to do this but may 
not give you very good control of the running process or processes. If you want 
to have more control of the transcoding work you can run the work in a thread 
pool within your program. This is more difficult to put together. In Perl there 
is a reference I found here

http://www.perlmonks.org/?node_id=735923

I don't have experience mixing Glib with Perl threads. Mostly work in C so it 
is a little different than using Perl. 

How are you working with your video files? The GStreamer library has a lot of 
audio/video functionality that is accessible from the command line or in code. 
I have been testing some code playing sounds with several different methods 
from the command line to a thread pool. It is in C but the ideas are going to 
be the same as in Perl. The gstreamer_test1.c has some basic glib spawn from 
the command line type functions and gstreamer_test2.c is putting together a 
pool of sounds to play all at once. Command line easy, thread pools hard. 

https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/Sound

Hope it is of some help.

Eric


 

 



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


Re: drawing GtkDrawingArea surface on motion-notify-event

2017-03-20 Thread Eric Cashon via gtk-app-devel-list

Hi Marcin,

One approach is to use a GtkOverlay. Draw the shape on the top and then save 
the coordinates of the shape if it is what you want. Then you can draw the 
saved shapes on the lower drawing area. 

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/draw_rectangle1.c

Cairo is pretty fast drawing. It take quite a bit to slow it down. 

Eric
 

 

 

-Original Message-
From: Marcin Kolny 
To: gtk-app-devel-list 
Sent: Mon, Mar 20, 2017 1:25 pm
Subject: Re-drawing GtkDrawingArea surface on motion-notify-event

Hi everyone,
I'd like to write very simple application for drawing lines.
 1) User press button - app saves x and y coordinates
 2) User moves the mouse - app dynamically draws potential line on each
mouse move event
 3) User releases button - app "saves" the line on the canvas.

I've tried to modify slightly the GTK example drawing application [1].
 1) On button press event I paint the current state to the "base_surface"
surface.
 2) On each mouse move I paint to the "tmp_surface" surface "base_surface"
and after that the actual line, so I avoid multiple lines on mouse move.
 3) On mouse release event I paint "tmp_surface" surface to "base_surface".

This works, and full code can be found on my gist [2]. However, I don't
think it's the right approach, since I have to re-paint a whole image for
each mouse-move, and latter on, on "draw" event application is doing almost
the same, so I'm doing the re-paint twice per each mouse move. I'm afraid
that for huge surfaces it might be very inefficient.

Do you know what would be the right approach to solve this sort of problems?

Thank you for help,
Marcin

[1] https://developer.gnome.org/gtk3/stable/ch01s05.html
[2] https://gist.github.com/loganek/156b6b9ce2333fd7d389f74c093a92b4
___
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: gtk3 layout background image

2017-03-14 Thread Eric Cashon via gtk-app-devel-list

The layout is similar to a drawing area. Set up your "draw" callback and draw 
what you like. You can put your pictures in there also and be able to scroll 
them easily. 

/*   
gcc -Wall layout1.c -o layout1 `pkg-config --cflags --libs gtk+-3.0`
Tested on Ubuntu16.04 and GTK3.18
*/

#include

static gboolean window_background(GtkWidget *widget, cairo_t *cr, gpointer 
data);
static gboolean layout_drawing(GtkWidget *da, cairo_t *cr, gpointer data);

int main(int argc, char **argv)
 {
   gtk_init(, );

   GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), "Layout");
   gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
   gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
   gtk_container_set_border_width(GTK_CONTAINER(window), 40);
   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
   gtk_widget_set_app_paintable(window, TRUE);
   //Try to set transparency of main window.
   if(gtk_widget_is_composited(window))
 {
   GdkScreen *screen=gtk_widget_get_screen(window);  
   GdkVisual *visual=gdk_screen_get_rgba_visual(screen);
   gtk_widget_set_visual(window, visual);
 }
   else g_print("Can't set window transparency.\n");
   g_signal_connect(window, "draw", G_CALLBACK(window_background), NULL);

   GtkWidget *layout=gtk_layout_new(NULL, NULL);
   gtk_widget_set_hexpand(layout, TRUE);
   gtk_widget_set_vexpand(layout, TRUE);
   g_signal_connect(layout, "draw", G_CALLBACK(layout_drawing), NULL);
   
   GtkWidget *grid=gtk_grid_new();
   gtk_grid_attach(GTK_GRID(grid), layout, 0, 0, 1, 1);
   
   gtk_container_add(GTK_CONTAINER(window), grid);

   gtk_widget_show_all(window);

   gtk_main();

   return 0;  
 }
static gboolean window_background(GtkWidget *widget, cairo_t *cr, gpointer data)
 {
   //Draw background window transparent blue.
   cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 0.3);
   cairo_paint(cr);
   return FALSE;
 }
static gboolean layout_drawing(GtkWidget *da, cairo_t *cr, gpointer data)
 {
   cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
   cairo_paint(cr);
   return FALSE;
 }


 

 

 

-Original Message-
From: Rúben Rodrigues 
To: Emmanuele Bassi 
Cc: gtk-app-devel-list 
Sent: Tue, Mar 14, 2017 8:00 am
Subject: Re: gtk3 layout background image

Thanks again!

So, i will test with gtkbox. thanks for explanation..


Às 14:46 de 14/03/2017, Emmanuele Bassi escreveu:
> On 14 March 2017 at 14:31, Rúben Rodrigues  wrote:
>> Just window can have background?
> I was referring to GdkWindow, not GtkWindow.
>
> GtkBox draws background, for instance; GtkGrid does as well.
>
>> I don't know why is a violation, because in my case my
>> applicationdoesn't make sense without background image..
> I think the issue, here, is that you're not aware that 15 years passed
> in the internals of GTK+.
>
> Changing the background pixmap of a GdkWindow is a layering violation
> because it assumes that you're essentially working on X11 and you
> control the X server as well; on X11, you're telling the X server to
> clear the contents of the native window used by GtkLayout using the
> bytes you're passing. This worked in 1997, but it's not how modern
> toolkits work — and it's not even how different windowing systems
> work. Widgets do not have their own native window for rendering any
> more, for instance.
>
> If your application window has a background image then use the
> background-image CSS property on your GtkWindow widget.
>
> Ciao,
>   Emmanuele.
>
>> On 14-03-2017 14:01, Emmanuele Bassi wrote:
>>> You were not changing the background with your theme: you were
>>> programmatically replacing the base pixmap of the GdkWindow used by
>>> GtkLayout. It was essentially a layering violation, and would actually
>>> break your theme.
>>>
>>> The API reference for each GTK widget should tell you the CSS styling
>>> available; see the "CSS nodes" section, for instance, of GtkBox:
>>> https://developer.gnome.org/gtk3/stable/GtkBox.html
>>>
>>> Ciao,
>>>Emmanuele.
>>>
>>>
>>> On 14 March 2017 at 13:55, Rúben Rodrigues  wrote:
 Thanks!

 But in GTK+2 we could change background in layout with this:

 // Set picture as background.
 //gdk_pixbuf_render_pixmap_and_mask (pixbuf, , NULL, 0);
 //style = gtk_style_new ();
 //style->bg_pixmap[0] = background;
 //homeWindow = GTK_WIDGET(gtk_builder_get_object(builder,
 "layout_Home"));
 //   gtk_widget_set_style (GTK_WIDGET(homeWindow), GTK_STYLE(style));

 How i know witch containers draw background?

 THanks


 On 14-03-2017 12:55, Emmanuele Bassi wrote:
> Not all GTK containers draw a background, mostly for historical
> reasons. This has been true for GTK 1.x, 2.x, and 3.x.
>
> In particular, GtkLayout does not draw any 

Re: How to set initial size of TextView?

2017-03-14 Thread Eric Cashon via gtk-app-devel-list

 
Hi Chris,

Try getting the font height and base the textview height on that. If you use 
the font ascent you might have to pad it a little but it should give you a 
consistent value to size your textviews with based on font size.

Eric


/*
gcc -Wall textview_height1.c -o textview_height1 `pkg-config --cflags 
--libs gtk+-3.0`
Tested on Ubuntu16.04 with GTK3.18.
*/

#include
  
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Textview Height");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 20);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *textview1=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview1), GTK_WRAP_WORD);

//Testing different font sizes.
PangoFontDescription *font=pango_font_description_from_string("Monospace 
20");
G_GNUC_BEGIN_IGNORE_DEPRECATIONS 
gtk_widget_override_font(textview1, font);
G_GNUC_END_IGNORE_DEPRECATIONS

PangoContext *pango_context=gtk_widget_get_pango_context(textview1);
PangoFontDescription 
*desc=pango_context_get_font_description(pango_context);
PangoFontMetrics *metrics=pango_context_get_metrics(pango_context, desc, 
NULL);
gdouble ascent=(gdouble)pango_font_metrics_get_ascent(metrics)/PANGO_SCALE;
pango_font_metrics_unref(metrics);

g_print("Ascent %f\n", ascent);
   
GtkWidget *scroll1=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll1, TRUE);
gtk_widget_set_size_request(scroll1, 360, 3.0*ascent);
gtk_container_add(GTK_CONTAINER(scroll1), textview1);

//Assume the same font size for the second textview.
GtkWidget *textview2=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview2), GTK_WRAP_WORD);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS 
gtk_widget_override_font(textview2, font);
G_GNUC_END_IGNORE_DEPRECATIONS

//Don't need this anymore.
pango_font_description_free(font);

GtkWidget *scroll2=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll2, TRUE);
gtk_widget_set_size_request(scroll2, 360, 5.0*ascent);
gtk_container_add(GTK_CONTAINER(scroll2), textview2);

GtkWidget *grid=gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
gtk_grid_set_row_homogeneous(GTK_GRID(grid), FALSE);
gtk_grid_attach(GTK_GRID(grid), scroll1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), scroll2, 0, 1, 1, 1);

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }


 

 

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


Re: gtk function with argv

2017-04-11 Thread Eric Cashon via gtk-app-devel-list

 
Hi Ruben,

I think what you are looking for is a C variadic function. Something that works 
like g_object_set() with a Null terminated list of arguments.

Using dynamic glib containers might be a better choice. It is simpler to just 
pass a single pointer with your user_data to functions which is how GTK 
callbacks are setup. Also, I have read that variadics have some troubles and 
don't always work well if you call the functions from another language. 

Eric


//gcc -Wall ptr_array1.c -o ptr_array1 `pkg-config --cflags --libs glib-2.0`
 
#include
#include

static void vChart_Init1(gchar *widget, GPtrArray *series)
  {
g_print("Init1\n");
gint i=0;
gint length=series->len;
for(i=0;i

Re: Combobox focus event

2017-04-06 Thread Eric Cashon via gtk-app-devel-list

 Hi Thomas,

You can try getting the private toggle button in the combo box. This isn't a 
solution using the given GTK api but if you want to inspect the how to get the 
"focus-in-event" to work with a combo box, this might be helpful. You are 
working in C right?

Eric


/*
gcc -Wall combo_focus1.c -o combo_focus1 `pkg-config gtk+-3.0 --cflags 
--libs`
Tested on Ubuntu16.04, GTK3.18.
*/

#include

//From gtkcombobox.c
struct _GtkComboBoxPrivate
{
  GtkTreeModel *model;

  GtkCellArea *area;

  gint col_column;
  gint row_column;

  gint wrap_width;

  gint active; /* Only temporary */
  GtkTreeRowReference *active_row;

  GtkWidget *tree_view;

  GtkWidget *cell_view;

  GtkWidget *box;
  GtkWidget *button;
  GtkWidget *arrow;

  GtkWidget *popup_widget;
  GtkWidget *popup_window;
  GtkWidget *scrolled_window;

  //GtkCssGadget *gadget;

  gulong inserted_id;
  gulong deleted_id;
  gulong reordered_id;
  gulong changed_id;
  guint popup_idle_id;
  guint activate_button;
  guint32 activate_time;
  guint scroll_timer;
  guint resize_idle_id;

  /* For "has-entry" specific behavior we track
   * an automated cell renderer and text column
   */
  gint  text_column;
  GtkCellRenderer *text_renderer;

  gint id_column;

  guint popup_in_progress : 1;
  guint popup_shown : 1;
  guint add_tearoffs : 1;
  guint has_frame : 1;
  guint is_cell_renderer : 1;
  guint editing_canceled : 1;
  guint auto_scroll : 1;
  guint button_sensitivity : 2;
  guint has_entry : 1;
  guint popup_fixed_width : 1;

  GtkTreeViewRowSeparatorFunc row_separator_func;
  gpointerrow_separator_data;
  GDestroyNotify  row_separator_destroy;

  GdkDevice *grab_pointer;

  gchar *tearoff_title;
};

static gboolean focus_button(GtkWidget *widget, GdkEvent *event, gpointer 
user_data);
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event, gpointer 
user_data);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Rooster Icon");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *button=gtk_button_new_with_label("Button");
gtk_widget_set_hexpand(button, TRUE);
gtk_widget_set_vexpand(button, TRUE);
g_signal_connect(button, "focus-in-event", G_CALLBACK(focus_button), NULL); 
 

GtkWidget *combo=gtk_combo_box_text_new();
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 0, "1", "Turtle");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 1, "2", "Koala");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 2, "3", "Cheetah");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
gtk_widget_set_hexpand(combo, TRUE);
GtkComboBoxPrivate *priv=G_TYPE_INSTANCE_GET_PRIVATE((combo), 
GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate); 
g_signal_connect(priv->button, "focus-in-event", G_CALLBACK(focus_combo), 
NULL); 
   
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo, 0, 1, 1, 1);
  
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);

gtk_main();

return 0;
  }
static gboolean focus_button(GtkWidget *widget, GdkEvent *event, gpointer 
user_data)
  {
g_print("Button Focus\n");
return FALSE;
  }
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event, gpointer 
user_data)
  {
g_print("Combo Focus\n");
return FALSE;
  }



 


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


Re: Custom GtkHeaderBar

2017-04-17 Thread Eric Cashon via gtk-app-devel-list

 If I use

gtk_style_context_add_class(context, "header");

The background drawn to the event box window is transparent on my computer. I 
just used "menu" to test a different color from the theme but there are many 
that you can test. The style classes are at the bottom of the documentation 
page.

https://developer.gnome.org/gtk3/stable/GtkStyleContext.html

I painted the main window green so that I could see if the event box window 
gets drawn to and also to distinguish widgets that don't have windows like the 
GtkLabel, GtkBox and GtkGrid.

Another option is to have a CSS file for the header widget and use that 
although then you get away from using the users theme. I have tried using the 
deprecated function

gtk_style_context_get_background_color()

to peak at if there is a constant background color set and what it might be but 
that function isn't going to work for a gradient or image so it is only a 
partial solution for checking the style class background.

Still trying to figure out these things myself.

Eric

 


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


Re: Custom GtkHeaderBar

2017-04-13 Thread Eric Cashon via gtk-app-devel-list

Hi Fujiwara,

The GtkBox is going to use the background window for it's color. The box just 
does the layout. If you create a header bar from a box you will have to draw on 
the background where your header bar is going to be. This can get a little 
tricky to get the measurements that you need. A simple case shouldn't be too 
difficult though. If you pass the box to the main window "draw" callback you 
can get something going. You can draw with cairo or get your CSS color. I don't 
have a C# setup to test with so I hope C will do.

By the way, I was just programming something similar looking at cairo meshes. 
Don't know if you like mesh drawing but there is a little program at the 
following that changes some background windows from the UI.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/draw_mesh1.c

Eric

/*
   gcc -Wall box1.c -o box1 `pkg-config --cflags --libs gtk+-3.0`
   Tested with GTK3.18 on Ubuntu16.04
*/
#include

static gboolean draw_box(GtkWidget *widget, cairo_t *cr, gpointer data);

int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Title Bar");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_widget_set_app_paintable(window, TRUE);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *label1=gtk_label_new("Header");
GtkWidget *label2=gtk_label_new("Bar"); 

GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_set_border_width(GTK_CONTAINER(box), 10);
gtk_widget_set_hexpand(box, TRUE);
gtk_box_pack_start(GTK_BOX(box), label1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), label2, TRUE, TRUE, 0);
g_signal_connect(window, "draw", G_CALLBACK(draw_box), box);

GtkWidget *label3=gtk_label_new("Main");
gtk_widget_set_vexpand(label3, TRUE);
gtk_widget_set_hexpand(label3, TRUE);
GtkWidget *label4=gtk_label_new("Window");
gtk_widget_set_vexpand(label4, TRUE);
gtk_widget_set_hexpand(label4, TRUE); 

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), box, 0, 0, 1, 1); 
gtk_grid_attach(GTK_GRID(grid), label3, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), label4, 0, 2, 1, 1);  

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }  
static gboolean draw_box(GtkWidget *widget, cairo_t *cr, gpointer data)
  {
//Paint the main window.
cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
cairo_paint(cr);
//Get the dimensions to draw header bar.
gint width=gtk_widget_get_allocated_width(GTK_WIDGET(widget));
gint height=gtk_widget_get_allocated_height(GTK_WIDGET(data));
cairo_set_source_rgb(cr, 1.0, 0.0, 1.0);
//Add 20 to height for 2 time contain width.
cairo_rectangle(cr, 0.0, 0.0, width, height+20);
cairo_fill(cr);
return FALSE;
  }

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


Re: Custom GtkHeaderBar

2017-04-15 Thread Eric Cashon via gtk-app-devel-list

I gave it another try and "header" gtk_style_context_add_class() is 
transparent. I can use "menu" and that returns a darker color that is used on 
the title bar. 

It is C again. I did get foo.vala output to foo.c. Too much stuff. 

Eric

/*
   gcc -Wall box1.c -o box1 `pkg-config --cflags --libs gtk+-3.0`
   Tested with GTK3.18 on Ubuntu16.04
*/
#include

static gboolean draw_main_window(GtkWidget *widget, cairo_t *cr, gpointer data);
static gboolean draw_event_box(GtkWidget *widget, cairo_t *cr, gpointer data);
static void close_program(GtkWidget *widget, gpointer user_data);

int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Title Bar");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_widget_set_app_paintable(window, TRUE);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window, "draw", G_CALLBACK(draw_main_window), NULL);

GtkWidget *button=gtk_button_new_with_label("Close");
g_signal_connect(button, "clicked", G_CALLBACK(close_program), NULL);

GtkWidget *label1=gtk_label_new("Header");
gtk_label_set_markup(GTK_LABEL(label1), "Header");
GtkWidget *label2=gtk_label_new("Bar");
gtk_label_set_markup(GTK_LABEL(label2), "Bar");   

GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_set_border_width(GTK_CONTAINER(box), 10);
gtk_widget_set_hexpand(box, TRUE);
gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), label1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), label2, TRUE, TRUE, 0);
   
GtkWidget *event=gtk_event_box_new();
GtkStyleContext *context=gtk_widget_get_style_context(event);
//Use the menu background.
gtk_style_context_add_class(context, "menu");
gtk_container_add(GTK_CONTAINER(event), box);
g_signal_connect(event, "draw", G_CALLBACK(draw_event_box), NULL);
gtk_window_set_titlebar(GTK_WINDOW(window), event);

GtkWidget *label3=gtk_label_new("Main");
gtk_widget_set_vexpand(label3, TRUE);
gtk_widget_set_hexpand(label3, TRUE);
GtkWidget *label4=gtk_label_new("Window");
gtk_widget_set_vexpand(label4, TRUE);
gtk_widget_set_hexpand(label4, TRUE); 

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), label3, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), label4, 0, 1, 1, 1);  

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }  
static gboolean draw_main_window(GtkWidget *widget, cairo_t *cr, gpointer data)
  {
//Paint the main window.
cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
cairo_paint(cr);
return FALSE;
  }
static gboolean draw_event_box(GtkWidget *widget, cairo_t *cr, gpointer data)
  {
//Paint the event box header bar.
gint width=gtk_widget_get_allocated_width(widget);
gint height=gtk_widget_get_allocated_height(widget);

GtkStyleContext *context=gtk_widget_get_style_context(widget);
gtk_render_background(context, cr, 0, 0, width, height);

return FALSE;
  }
static void close_program(GtkWidget *widget, gpointer user_data)
  {
gtk_main_quit();
  }




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


Re: Homogeneous table

2017-03-09 Thread Eric Cashon via gtk-app-devel-list

Hi Ruben,

Consider using a drawing area and GTK3. There are more drawing and graphical 
capabilities in GTK3. Going forward to GTK4 I expect even more drawing 
capabilities since every computer sold these days has a gpu and the software 
can take advantage of that. 

With a drawing area you get better control of what you can do with your image. 
It makes it easy to place the image in different places along with, 
transparency, text, animation, transforms,,, and a lot of other things. 

For chicken placement you can use 5 separate drawing areas or merge them into 
one. I have something similar with selecting critters for gauge speed. A png 
picture here.

https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/AdjustableGauge

There is a simple picture in a drawing area with some animated text over it at

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/draw_chars1.c

The code is simple enough but it needs a picture and picture path for it to 
work. I think that it could be ported to GTK2 but haven't done so. I like the 
graphical capabilities of GTK3 so I sort of stick with that for now.

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


Re: Gtk+ progress bar color

2017-03-08 Thread Eric Cashon via gtk-app-devel-list

 
If the default progress bar in GTK isn't what you are looking for then you can 
always make your own. You can design it how you want easy enough with a drawing 
area. With GTK3 you have OpenGL, Cairo, gradients, tensor-product patch meshes, 
etc. to draw with. You even have a frame clock for smooth animation if you 
want. If you figure out a progress bar that you like you can even package it as 
a re-usable object so that you can create many instances of the progress bar at 
once if you so need.

Some simple progress bars.
https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/da_progress1.c

Progress bars as an object.
https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/SteppedProgressBar

Have a little fun programming. The tools are there.

Eric

 

 

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


Re: Seperating Multiple processes

2017-03-10 Thread Eric Cashon via gtk-app-devel-list

 


Hi Mike,

Have you looked at using a thread pool?

https://developer.gnome.org/glib/stable/glib-Thread-Pools.html

If you have a folder full of files that you want to transcode you can set up 
your thread pool to cycle through them.

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


Re: GFileMonitor - g_signal_handler_block "changed" signal doesn't block handler?

2017-04-01 Thread Eric Cashon via gtk-app-devel-list

 
Hi David,

Not sure about this one. I tested some code out to see if I could figure it 
out. Had the same problem that you had with the "changed" signal not being 
blocked. If I change the rate of the file monitor and try to spool out the 
events, I can block the "changed" signal. Not something that I would recommend 
doing outside of testing so I suspect there is a better way to go about it. 
Blocking the "changed" signal isn't going to solve the problem of knowing where 
the change is coming from which can come from another process at any time. 
Maybe if you had a pid in the "changed" callback, then you could compare it 
with your program pid to see if the change is coming from your program or 
someplace else.

The following is what I tried using gedit and the terminal. Hopefully you get 
some better ideas.

Eric


/*
gcc -Wall file_monitor1.c -o file_monitor1 `pkg-config --cflags --libs 
gtk+-3.0`
Tested on Ubuntu16.04, GTK3.18 and gedit.
*/

#include

guint signal_id=0;
GFileMonitor *filemon=NULL;
//The file to append to. Just the .c file that is in the same folder as the 
program.
gchar *path="file_monitor1.c";  

//Check file changes from gedit and the file_monitor1 program.
static void file_changed(GFileMonitor *monitor, GFile *file, GFile *other_file, 
GFileMonitorEvent event_type, gpointer user_data)
  {
g_print("File Changed\n");
  }
static void button_clicked(GtkWidget *button, GFile *gfile)
  {
g_print("Block\n");
g_signal_handler_block(filemon, signal_id);
GError *err=NULL;
GFileOutputStream *stream=g_file_append_to(gfile, G_FILE_CREATE_NONE, NULL, 
);
if(err!=NULL) g_print("%s\n", err->message);
g_output_stream_write((GOutputStream*)stream, "//\n", 3, NULL, );
if(err!=NULL) g_print("%s\n", err->message);
g_output_stream_close((GOutputStream*)stream, NULL, );
if(err!=NULL) g_print("%s\n", err->message);
g_object_unref(stream);

/*
  Give GIO some time to post the event. This is a test. Don't do this 
otherwise.
  From gfilemonitor.c
  #define DEFAULT_RATE_LIMIT_MSECS 800 for filemon.
*/
g_file_monitor_set_rate_limit(filemon, 100);
g_usleep(1);
while(gtk_events_pending()) gtk_main_iteration();
g_file_monitor_set_rate_limit(filemon, 800);

g_signal_handler_unblock(filemon, signal_id);
g_print("Unblock\n");
if(err!=NULL) g_error_free(err);
  }
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "File Monitor");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 20);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GFile *gfile=g_file_new_for_path(path);
filemon=g_file_monitor_file(gfile, G_FILE_MONITOR_NONE, NULL, NULL);
signal_id=g_signal_connect(filemon, "changed", G_CALLBACK(file_changed), 
NULL);

GtkWidget *button=gtk_button_new_with_label("Append to file_monitor1.c");
gtk_widget_set_hexpand(button, TRUE);
gtk_widget_set_vexpand(button, TRUE);
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), gfile);

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button, 0, 0, 1, 1);

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

g_object_unref(gfile);
g_object_unref(filemon);

return 0;
  }


 

 



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


Re: Combobox focus event

2017-04-07 Thread Eric Cashon via gtk-app-devel-list

Hi Nicola,

The "set-focus-child" on the container fires for the "focus-in-event" and 
"focus-out-event". I forgot about those container functions though. You can get 
the toggle button pointer from the container and set up your "focus-in-event". 
That way there is no ugly business of using a private structure.

Eric


/*
gcc -Wall combo_focus2.c -o combo_focus2 `pkg-config gtk+-3.0 --cflags 
--libs`
Tested on Ubuntu16.04, GTK3.18.

https://bugzilla.gnome.org/show_bug.cgi?id=599076
Bugzilla Bug 599076 - GtkComboBox missing focus events 
*/

#include

static void find_toggle_button(GtkWidget *widget, GtkWidget **toggle_button);
static gboolean focus_button1(GtkWidget *widget, GdkEvent *event, gpointer 
user_data);
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event, gpointer 
user_data);
static gboolean focus_button2(GtkWidget *widget, GdkEvent *event, gpointer 
user_data);
static void focus_combo_container(GtkContainer *container, GtkWidget *widget, 
gpointer user_data);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Combo Focus");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *button1=gtk_button_new_with_label("Button1");
gtk_widget_set_hexpand(button1, TRUE);
gtk_widget_set_vexpand(button1, TRUE);
g_signal_connect(button1, "focus-in-event", G_CALLBACK(focus_button1), 
NULL);  

GtkWidget *combo=gtk_combo_box_text_new();
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 0, "1", "Turtle");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 1, "2", "Koala");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 2, "3", "Cheetah");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
gtk_widget_set_hexpand(combo, TRUE);
GtkWidget *toggle_button=NULL;
gtk_container_forall(GTK_CONTAINER(combo), (GtkCallback)find_toggle_button, 
_button);
g_signal_connect(toggle_button, "focus-in-event", G_CALLBACK(focus_combo), 
NULL); 

g_signal_connect(combo, "set-focus-child", 
G_CALLBACK(focus_combo_container), NULL);

GtkWidget *button2=gtk_button_new_with_label("Button2");
gtk_widget_set_hexpand(button2, TRUE);
gtk_widget_set_vexpand(button2, TRUE);
g_signal_connect(button2, "focus-in-event", G_CALLBACK(focus_button2), 
NULL);   
   
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), button2, 0, 2, 1, 1);
  
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);

gtk_main();

return 0;
  }
static void find_toggle_button(GtkWidget *widget, GtkWidget **toggle_button)
  {
if(g_strcmp0(gtk_widget_get_name(widget), "GtkToggleButton")==0)
  {
g_print("Found Toggle Button in Combo\n");
*toggle_button=widget;
  }
  }
static gboolean focus_button1(GtkWidget *widget, GdkEvent *event, gpointer 
user_data)
  {
g_print("Button1 Focus\n");
return FALSE;
  }
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event, gpointer 
user_data)
  {
g_print("Combo Focus In\n");
return FALSE;
  }
static gboolean focus_button2(GtkWidget *widget, GdkEvent *event, gpointer 
user_data)
  {
g_print("Button2 Focus\n");
return FALSE;
  }
static void focus_combo_container(GtkContainer *container, GtkWidget *widget, 
gpointer user_data)
  {
g_print("Combo Container Focus\n");
  }

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


Re: Combobox focus event

2017-04-07 Thread Eric Cashon via gtk-app-devel-list
Thomas, 

Your original question looked easy. Connect the "focus-in-event" to the combo 
box and everything will work fine. The "focus-in-event" works with other 
widgets. So I tried it out. Couldn't get it to work. Tried changing some combo 
box functions around and still couldn't get it to work. So I looked at the GTK 
source code for the combo box to see if I could understand the problem a little 
better. I saw a toggle button in the private structure so I gave that a try. 
That is as far as I got. 

Don't use private variables in your application code. They are private for a 
reason. The toggle button needs to work a certain way for the combo box to 
work. If there is a possible bug that you need to get a better look at, then 
you need to start digging into the private structure to figure out what is 
going on and why something isn't working as expected. Also look at previous bug 
reports. If you get everything figured out and it is a bug then file a bug 
report.

As part of the discussion, if someone knows an easy way to connect the  
"focus-in-event" with the combo box, say so.

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


Re: Combobox focus event

2017-04-08 Thread Eric Cashon via gtk-app-devel-list

Another thing to give a try is just to set a boolean in the "set-focus-child" 
callback. Not sure if this will always work. I think that it should. 

I don't know the best workaround for the "focus-in-event" in a combo box. It 
isn't obvious how to connect that signal for the combobox.

Eric


gboolean combo_focus=FALSE;
g_signal_connect(combo, "set-focus-child", G_CALLBACK(focus_combo_container), 
_focus);
...
static void focus_combo_container(GtkContainer *container, GtkWidget *widget, 
gboolean *combo_focus)
  {
if(*combo_focus) 
  {
g_print("Combo Container Focus Out\n");
*combo_focus=FALSE;
  }
else
  {
g_print("Combo Container Focus In\n");
*combo_focus=TRUE;
  }
  }

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


Re: Custom GtkHeaderBar

2017-04-14 Thread Eric Cashon via gtk-app-devel-list

 

I suspect 

set_titlebar(header);

is causing the problem. If you remove that, then you will have a box that you 
place in the main window. If it is a header bar box it will be below the 
titlebar. The box itself is just doing the layout so it uses the window behind 
it. You can draw on the window with a style context like

GtkStyleContext *context=gtk_widget_get_style_context(GTK_WIDGET(widget));
gtk_render_background(context, cr, 0, 0, width, height+20);

to get a specific widget color instead of setting the color with cairo.

A little limited here since I don't have a C# setup and am using GTK3.18 which 
doesn't have all the 3.22 functions. What OS are you using and how did you 
setup C# for programming with?

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


Re: GdkPixbuf and click events

2017-08-03 Thread Eric Cashon via gtk-app-devel-list

Hi Ferdinand,

You can also try putting the pixbuf in an image widget and that into an event 
box. 

Eric


//gcc -Wall right_click1.c -o right_click1 `pkg-config --cflags --libs gtk+-3.0`

#include

static GdkPixbuf* draw_a_pixbuf()
  {
cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 
20, 20);
cairo_t *cr=cairo_create(surface);

cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
cairo_paint(cr);

GdkPixbuf *pixbuf=gdk_pixbuf_get_from_surface(surface, 0, 0, 20, 20);

cairo_destroy(cr);
cairo_surface_destroy(surface); 
return pixbuf;
  }
static gboolean start_press(GtkWidget *widget, GdkEvent *event, gpointer data)
  {
if(event->button.button==3) g_print("Right Click\n");
return TRUE;
  }
int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Right Click");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GdkPixbuf *pixbuf=draw_a_pixbuf();

GtkWidget *image=gtk_image_new_from_pixbuf(pixbuf);

GtkWidget *event=gtk_event_box_new();
g_signal_connect(event, "button-press-event", G_CALLBACK(start_press), 
NULL);
gtk_container_add(GTK_CONTAINER(event), image);

GtkWidget *textview=gtk_text_view_new();
gtk_text_view_add_child_in_window(GTK_TEXT_VIEW(textview), event, 
GTK_TEXT_WINDOW_TEXT, 40, 40);
gtk_widget_set_hexpand(textview, TRUE);
gtk_widget_set_vexpand(textview, TRUE);

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), textview, 0, 0, 1, 1);  

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

g_object_unref(pixbuf);

return 0;
  }

 

 

 

-Original Message-
From: Ferdinand Ramirez via gtk-app-devel-list 
To: gtk-app-devel-list 
Sent: Thu, Aug 3, 2017 8:13 am
Subject: GdkPixbuf and click events

I have a program that adds a GdkPixbuf to a GtkTextView. I would like to right 
click on the image and capture the mouse click event and execute a callback 
function. Is there any way of achieving this using GdkPixbuf?

Thanks,
Ferdinand
___
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: turn on italics in TextView

2017-08-15 Thread Eric Cashon via gtk-app-devel-list

 


Hi Doug,

I made a bit of a pointer mess there. Not the best of answers or way to go 
about iterating through a list. Looking at some GTK code, this is better done 
with a for loop. As usual, you don't want to move the pointer you get from 
gtk_text_iter_get_tags() and then free it. This will cause you grief later on 
along with buggy code that may not be so easy to debug.

Very glad you got things working well even with a less than good answer. Need 
to be careful of the pointers myself.

Eric


GSList *tlist=NULL;
GSList *p=NULL;
tlist=gtk_text_iter_get_tags();
g_print("List %p p %p\n", tlist, p);
for(p=tlist;p;p=p->next)
  {
gchar *string=NULL;
g_object_get(G_OBJECT(p->data), "name", , NULL);
g_print("p %p %s\n", p, string);
g_free(string);
  }

g_print("List %p\n", tlist);
if(tlist!=NULL) g_slist_free(tlist);
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: turn on italics in TextView

2017-08-15 Thread Eric Cashon via gtk-app-devel-list

Have you tried gtk_text_buffer_insert_with_tags_by_name() to insert text with a 
tag at an iter?

What tag combo do you use to get the cursor to bounce around? If I test having 
two indent tags on the same line, the first one applied wins out. This is what 
I tested with.

Eric


/*
  gcc -Wall move_cursor1.c -o move_cursor1 `pkg-config --cflags --libs gtk+-3.0`
  Tested on GTK3.18 and Ubuntu16.04
*/

#include

static void get_style(GtkTextView *tv, GtkMovementStep step, gint count, 
gboolean extend, gpointer *user_data)
  {
static int i=1;
GtkTextIter start;
GtkTextMark *mark;
GtkTextBuffer *buf;

buf=gtk_text_view_get_buffer(GTK_TEXT_VIEW(tv));

mark=gtk_text_buffer_get_insert(buf);
gtk_text_buffer_get_iter_at_mark (buf, , mark);
g_print("Iter %i\n", gtk_text_iter_get_offset());

GSList *tlist=NULL;
GSList *p=NULL;
tlist=gtk_text_iter_get_tags();
g_print("%i. List %p p %p\n", i, tlist, p);
i++;
for(p=tlist;p;p=p->next)
  {
gchar *string=NULL;
g_object_get(G_OBJECT(p->data), "name", , NULL);
g_print("p %p %s\n", p, string);
g_free(string);
  }

g_print("List %p\n", tlist);
if(tlist!=NULL) g_slist_free(tlist);
  }
int main (int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Move Cursor");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *textview=gtk_text_view_new();
gtk_widget_set_vexpand(textview, TRUE);
gtk_widget_set_hexpand(textview, TRUE);
g_signal_connect(textview, "move-cursor", G_CALLBACK(get_style), NULL);

GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_create_tag(buffer, "ital", "style", PANGO_STYLE_ITALIC, 
NULL);
gtk_text_buffer_create_tag(buffer, "bold", "weight", PANGO_WEIGHT_BOLD, 
NULL);
gtk_text_buffer_create_tag(buffer, "uline", "underline", 
PANGO_UNDERLINE_SINGLE, NULL);
gtk_text_buffer_create_tag(buffer, "indent", "indent", 20, NULL);
gtk_text_buffer_create_tag(buffer, "indent2", "indent", 40, NULL);
gtk_text_buffer_create_tag(buffer, "left-margin", "left-margin", 20, NULL); 
gtk_text_buffer_create_tag(buffer, "left-margin2", "left-margin", 40, 
NULL); 

GtkTextIter iter;
gtk_text_buffer_get_start_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "ital ", -1, 
"ital", NULL);
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "bold ", -1, 
"bold", NULL);
gtk_text_buffer_get_end_iter(buffer, );
//Check a newline for a tag.
gtk_text_buffer_insert_with_tags_by_name(buffer, , "uline \n", -1, 
"uline", NULL);
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "all\n", -1, 
"ital", "bold", "uline", NULL);
//Check indents in the same line.
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "indent ", -1, 
"indent", NULL);
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "indent2\n", -1, 
"indent2", NULL);
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "indent2\n", -1, 
"indent2", NULL);
//Check left-margin in the same line.
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "left-margin ", -1, 
"left-margin", NULL);
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "left-margin2\n", 
-1, "left-margin2", NULL);
gtk_text_buffer_get_end_iter(buffer, );
gtk_text_buffer_insert_with_tags_by_name(buffer, , "left-margin2", -1, 
"left-margin2", NULL);

GtkWidget *grid=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid), 8);
gtk_grid_attach(GTK_GRID(grid), textview, 0, 0, 1, 1);

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

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


Re: Moving/resizing a window in real-time

2017-07-20 Thread Eric Cashon via gtk-app-devel-list

 
Hi Alex,

The OpenCV window_gtk.cpp isn't so simple. A lot of tough concepts there. For 
example the code is written for compiling with both GTK2 and GTK3, makes use of 
threads, creates a custom GTK widget, uses GTK OpenGL if it can, etc. 

The GTK functions can only be called on the "main" thread of the program. This 
means that the OpenCV drawing can happen on a worker thread and you can keep 
track of the worker thread progress with the use of locking. When OpenCV is 
done you can notify the GTK main loop it is done and update the window. The 
following shows how something like this might work in a little simpler program.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/mandelbrot1.c

Have you made custom widgets with GTK? You can incorporate threads and the 
functionality that you are looking for and build it into a widget. There is an 
experimental gauge widget that draws on a separate thread at the following. 
That way the gauge drawing only gets redrawn entirely when the window gets 
resized. Speeds things up when using a frame clock and multiple gauges. Causes 
some screen flicker though on resizes.

https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/AdjustableGauge2

For real-time or smooth window moves you can use a frame clock or a timer to 
check if you need to move your window. A lot of options to build what you want.

Eric

 


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


Re: "click" event on a GtkSpinEntry

2017-08-22 Thread Eric Cashon via gtk-app-devel-list

 
Hi Nicola,

This isn't pretty but it works.

There is a good read about the spin button at

https://blog.gtk.org/author/ebassi/

with Tim Bader on April 25, 2017. I don't know if you have seen that. My first 
try was just to get the GdkWindow of the spin button but that gave me the main 
window. No help there. Noticed that the cursor changed with the mouse movement 
so I went with that. Probably even more hackish than your solution. 

Eric


/*
gcc -Wall click1.c -o click1 `pkg-config --cflags --libs gtk+-3.0`
Tested with Ubuntu16.04 and GTK3.18
*/

#include

static gboolean button_press(GtkWidget *spin, GdkEvent *event, gpointer data)
  {
GdkCursor *cursor=gdk_window_get_cursor(event->button.window);
if(cursor!=NULL) g_print("Text Entry Clicked\n");

return FALSE;
  }
int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Click");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 50);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *spin=gtk_spin_button_new_with_range(0, 10, 1);
gtk_widget_set_hexpand(spin, TRUE);
gtk_widget_add_events(spin, GDK_BUTTON_PRESS_MASK);
g_signal_connect(spin, "button-press-event", G_CALLBACK(button_press), 
NULL);

GtkWidget *grid=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid), 10);
gtk_grid_attach(GTK_GRID(grid), spin, 0, 0, 1, 1);  

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }

 


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


Re: turn on italics in TextView

2017-06-20 Thread Eric Cashon via gtk-app-devel-list

 
Another option is to look at the properties of the tags to get the information 
that you need. This might work better than saving globals and matching pointers.

Eric

...
GSList *tlist=NULL;
GSList *next=NULL;
tlist=gtk_text_iter_get_tags();
if(tlist!=NULL)
  {
do
  {
next=tlist->next;
gchar *string=NULL;
g_object_get(G_OBJECT(tlist->data), "name", , NULL);
g_print("%s\n", string);
g_free(string);
tlist=g_slist_next(tlist);
  }while(next!=NULL);
   }
else g_print("No Tags\n");

if(tlist!=NULL) g_slist_free(tlist);
...

 



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


Re: turn on italics in TextView

2017-06-20 Thread Eric Cashon via gtk-app-devel-list

 
On that last post, I think that I have some bad pointer arithmetic. Moving a 
pointer past the end and freeing a moved pointer. Not so good.

Eric

...
GSList *tlist=NULL;
GSList *p=NULL;
GSList *next=NULL;
tlist=gtk_text_iter_get_tags();
p=tlist;
if(tlist!=NULL)
  {
do
  {
next=p->next;
gchar *string=NULL;
g_object_get(G_OBJECT(p->data), "name", , NULL);
g_print("%s\n", string);
g_free(string);
if(next!=NULL)p=g_slist_next(p);
  }while(next!=NULL);
   }
else g_print("No Tag\n");

if(tlist!=NULL) g_slist_free(tlist);
...

 

 

-----Original Message-
From: Eric Cashon via gtk-app-devel-list <gtk-app-devel-list@gnome.org>
To: dougm <do...@bravoecho.net>
Cc: gtk-app-devel-list <gtk-app-devel-list@gnome.org>
Sent: Tue, Jun 20, 2017 4:48 pm
Subject: Re: turn on italics in TextView


 
Another option is to look at the properties of the tags to get the information 
that you need. This might work better than saving globals and matching pointers.

Eric

...
GSList *tlist=NULL;
GSList *next=NULL;
tlist=gtk_text_iter_get_tags();
if(tlist!=NULL)
{
do
  {
next=tlist->next;
gchar *string=NULL;
g_object_get(G_OBJECT(tlist->data), "name", , NULL);
g_print("%s\n", string);
g_free(string);
  tlist=g_slist_next(tlist);
  }while(next!=NULL);
   }
else g_print("No Tags\n");

if(tlist!=NULL) g_slist_free(tlist);
...

 



___
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: GtkDrawingArea size request

2017-06-22 Thread Eric Cashon via gtk-app-devel-list

 
Hi Ruben, 

You might consider allowing the gauge to expand with the window size. This 
makes the gauge a lot more flexible. When drawing a gauge it is useful to get a 
general coordinate drawing on screen that you can check your gauge drawing 
with. Both cartesian coordinates and radial coordinates are useful to check 
your drawing. There is a general layout drawing in the following.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/gears2.c

You can use set sizes if you want to also. To keep your drawing area window 
size a set size check your vexpand and hexpand properties. Make sure they are 
false. Try using a GtkGrid instead of a GtkBox. Put the drawing area in a 
scrolled window and put that in the grid.

I have done some work drawing gauges and have a couple packaged as widgets. 
There are also some drawings of clocks, gauges, gems and gears in the above 
github cairo_drawings folder. Some resize as circles and some as ellipses. They 
might be helpful getting something that you can test a gauge drawing with.

Eric

 


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


Re: Combobox disable item

2017-06-22 Thread Eric Cashon via gtk-app-devel-list

 

 
Hi Mike,

What part of the combo box are you trying to disable? If you want to filter 
rows or columns you can set up a tree model filter to do so. Maybe something 
like the following?

Eric


/*
gcc -Wall combo_filter1.c -o combo_filter1 `pkg-config --cflags --libs 
gtk+-3.0`
Tested on GTK3.18 and Ubuntu16.04
*/
#include
#include

static gint combo_row=0;

static void change_combo(GtkComboBox *combo2, gpointer *data)
  {
combo_row=gtk_combo_box_get_active(combo2);
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(data[1]));
gtk_combo_box_set_active(GTK_COMBO_BOX(data[0]), 0);
  }
static gboolean show_rgb(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
  {
gchar *string=gtk_tree_model_get_string_from_iter(model, iter);
gint row=atoi(string);
g_free(string);

if(combo_row==1&<3)
  {
g_print("Combo1 Don't Show %i\n", row);
return FALSE;
  }
else
  { 
g_print("Combo1 Show %i\n", row);
return TRUE;
  }
  }
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Combo Filter");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeIter iter;
GtkListStore *store=gtk_list_store_new(1, G_TYPE_STRING);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Yellow", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Purple", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Cyan", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Red", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Green", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Blue", -1);

GtkTreeModel *model=gtk_tree_model_filter_new(GTK_TREE_MODEL(store), NULL);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model), 
(GtkTreeModelFilterVisibleFunc)show_rgb, NULL, NULL);  

GtkCellRenderer *renderer=gtk_cell_renderer_text_new();

GtkWidget *combo1=gtk_combo_box_new_with_model(model);
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo1), renderer, TRUE);
gtk_widget_set_hexpand(combo1, TRUE);
gtk_widget_set_vexpand(combo1, TRUE);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo1), 0);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo1), 
GTK_CELL_RENDERER(renderer), "text", 0, NULL);

GtkWidget *combo2=gtk_combo_box_text_new();
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 0, "1", "Show All");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 1, "2", "Show RGB");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo2), 0);
gtk_widget_set_hexpand(combo2, TRUE);
gtk_widget_set_vexpand(combo2, TRUE);
gpointer data[]={combo1, model};
g_signal_connect(combo2, "changed", G_CALLBACK(change_combo), data);

g_object_unref(G_OBJECT(store));

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), combo1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo2, 0, 1, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }



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


Re: Combobox disable item

2017-06-23 Thread Eric Cashon via gtk-app-devel-list

 
Add an extra column to your list and use that to set your "sensitive" property 
for the row. 

Eric


/*
gcc -Wall combo_filter2.c -o combo_filter2 `pkg-config --cflags --libs 
gtk+-3.0`
Tested on GTK3.18 and Ubuntu16.04
*/
#include

static void combo2_changed(GtkComboBox *combo2, gpointer data)
  {
gint combo_row=gtk_combo_box_get_active(combo2);
if(combo_row==1)
  {
GtkTreeIter iter;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(data), , "1");
gtk_list_store_set(GTK_LIST_STORE(data), , 1, FALSE, -1);
  }
else
  {
GtkTreeIter iter;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(data), , "1");
gtk_list_store_set(GTK_LIST_STORE(data), , 1, TRUE, -1);
  }
  }
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Combo Filter2");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeIter iter;
GtkListStore *store=gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Scandvb", 1, TRUE, -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "DVB module", 1, TRUE, -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "DVDb5-Scan", 1, TRUE, -1);
gtk_list_store_append(store, );

GtkCellRenderer *renderer=gtk_cell_renderer_text_new();

GtkWidget *combo1=gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo1), renderer, TRUE);
gtk_widget_set_hexpand(combo1, TRUE);
gtk_widget_set_vexpand(combo1, TRUE);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo1), 0);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo1), 
GTK_CELL_RENDERER(renderer), "text", 0, "sensitive", 1, NULL);

GtkWidget *combo2=gtk_combo_box_text_new();
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 0, "1", "Show All");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 1, "2", "Disable DVB 
module");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo2), 0);
gtk_widget_set_hexpand(combo2, TRUE);
gtk_widget_set_vexpand(combo2, TRUE);
g_signal_connect(combo2, "changed", G_CALLBACK(combo2_changed), store);

g_object_unref(G_OBJECT(store));

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), combo1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo2, 0, 1, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }



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


Re: Can I make GtkPlug transparent?

2017-06-26 Thread Eric Cashon via gtk-app-devel-list

 
Hi Lihao,

If you set the socket color you will be OK. You won't have to worry about the 
transparency of the plug, in that case.

For setting the transparency for the different windows you can try setting the 
window, socket and plug widgets with the following. It worked on GTK3.18. 
Couldn't get the transparency to work with CSS though. I don't know why that is.

Eric

...
static gboolean draw_background(GtkWidget *widget, cairo_t *cr, gpointer data)
  {
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.5);
cairo_paint(cr);
return FALSE;
  } 
...
gtk_widget_set_app_paintable("widget", TRUE);
if(gtk_widget_is_composited("widget"))
  {
GdkScreen *screen=gtk_widget_get_screen("widget");  
GdkVisual *visual=gdk_screen_get_rgba_visual(screen);
gtk_widget_set_visual("widget", visual);
  }
else g_print("Can't set window transparency.\n");
g_signal_connect("widget", "draw", G_CALLBACK(draw_background), NULL);
... 

 


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


Re: Can I make GtkPlug transparent?

2017-06-26 Thread Eric Cashon via gtk-app-devel-list

 
It looks like both the plug and socket draw to the same window. That would mean 
that you would have to draw your window background in both the plug and socket 
"draw" callback functions. There is a plug2.c and socket2.c in the following 
folder that sets the transparency on the different windows to try to figure out 
how it could work. With cairo you can draw or load an image. You would just 
have to do it twice in this case.

Might be stretching GTK a little here. Should work.

https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/Csamples

Eric

 


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


Re: gtktree: combination filter and using gtk_tree_model_foreach

2017-05-24 Thread Eric Cashon via gtk-app-devel-list

 
Hi Rob,

The trick here is to use gtk_tree_model_filter_convert_iter_to_child_iter(). 
That will get the iter that you need. It will work the same on both GTK2 and 
GTK3. You have to be a little careful with gtk_tree_model_foreach(). It is easy 
to add nodes and then the function will check everyone of the additional nodes. 

Eric

gboolean func(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, 
gpointer data) 
{ 
  //Test counter for nodes.
  static gint i=0;
  GtkTreeIter parent;
  GtkTreeIter child_iter;
  GtkTreeIter node;
  
  if(!gtk_tree_model_iter_parent(model, , iter))
{
  if(!gtk_tree_model_iter_has_child(model, iter))
{
  g_print("Child %i\n", i);
  
gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), 
_iter, iter); 
  gtk_tree_store_append(store, , _iter);
  gtk_tree_store_set(store, , 0, "child", -1);
}
}
  i++;
   
  return FALSE; 
} 

 

 

-Original Message-
From: Rob Alblas 
To: gtk-app-devel-list 
Sent: Wed, May 24, 2017 5:57 am
Subject: gtktree: combination filter and using gtk_tree_model_foreach

In a GtkTree I want to use a filter, and also extend the tree using 
gtk_tree_model_foreach. The combination of the 2 gives problems. 
In the function connected to gtk_tree_model_foreach I use the GtkTreeIter *iter 
argument, which gives an error message: 

Gtk-CRITICAL **: IA__gtk_tree_store_append: assertion `VALID_ITER (parent, 
tree_store)' failed 

I define tree, filter etc. as follows: 
stree = gtk_tree_store_new(1,G_TYPE_STRING); 
ftree = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(stree), 
NULL)); 
tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ftree)); 
model=gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); 

... 
(build a part of the tree) 
... 
gtk_tree_model_foreach(model,func,NULL); 

In func: 
gboolean func(GtkTreeModel *model,GtkTreePath *path,GtkTreeIter *iter,gpointer 
data) 
{ 
gtk_tree_model_get(model,iter, 0, , -1); 
... 
gtk_tree_store_append(stree, , iter); 
... 
} 

gtk_tree_store_append gives the mentioned error. 

If I remove the filter, and define instead: 
tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(stree)); 

then building using gtk_tree_model_foreach works fine. 
How to solve this? 

Attached an example showing the problem. 
(Note: I am using gtk2.0, don't know if the same problem is with gtk3.) 

___
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: Close button in GtkNotebook

2017-05-28 Thread Eric Cashon via gtk-app-devel-list

 
Hi Augusto,

This doesn't use glade but it might help out. You can add a label and button to 
a box and add it to the notebook tab. In the button "clicked" callback you can 
us the notebook pointer if you need that variable. If you want to be able to 
really customize the look and size of the button you could replace it with a 
drawing area and draw your own button. 

Eric

/*
   gcc -Wall notebook1.c -o notebook1 `pkg-config --cflags --libs gtk+-3.0`
   Tested with GTK3.18 on Ubuntu16.04
*/

#include

static void button_clicked(GtkWidget *button, GtkWidget *notebook)
  {
g_print("Clicked\n");
  }
int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Notebook");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *label1=gtk_label_new("page1");
GtkWidget *label2=gtk_label_new("page2");
GtkWidget *nb_label1=gtk_label_new("tab1");
GtkWidget *nb_label2=gtk_label_new("tab2");
 
GtkWidget *x_label=gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(x_label), "x");

GtkWidget *button=gtk_button_new();
gtk_container_add(GTK_CONTAINER(button), x_label); 

GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_pack_start(GTK_BOX(box), nb_label2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
gtk_widget_show_all(box);

GtkWidget *notebook=gtk_notebook_new();
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), label1, nb_label1);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), label2, box);

g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), notebook);
 
gtk_container_add(GTK_CONTAINER(window), notebook);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }  


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


Re: GtkLabel max-width-chars with ellipsize broken?

2017-06-13 Thread Eric Cashon via gtk-app-devel-list

 
What version of GTK are you using?

It does work on my computer. The label expands and shrinks as the window 
expands and shrinks and the label stops expanding at 012345678901234567... I 
take that to be 20 chars if you start at 0 and include the three dots. The 
tooltip shows the full string.

Eric

 



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


Re: GtkLabel max-width-chars with ellipsize broken?

2017-06-10 Thread Eric Cashon via gtk-app-devel-list

 
Hi infirit,

Give the hexpand a try and see if that works. It works for me on Python3.5 and 
GTK3.18

Eric

...
halign=Gtk.Align.CENTER, 
hexpand=True)
..


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


Re: turn on italics in TextView

2017-06-13 Thread Eric Cashon via gtk-app-devel-list

 
Hi Doug,

You can try using the "insert-text" callback to set your italics on the 
inserted text. This is what I came up with to test. The signal is connected 
after so that the update occurs first. Careful about not changing the location 
iter also since there is a warning in the documentation about doing so. Might 
not need to worry about it here but something to be aware of.

https://developer.gnome.org/gtk3/stable/GtkTextBuffer.html#GtkTextBuffer-insert-text

Eric


/*
  gcc -Wall textview2.c -o textview2 `pkg-config --cflags --libs gtk+-3.0`
  Tested on GTK3.18 and Ubuntu16.04
*/

#include

static gboolean italic=FALSE;

static void toggle_italic(GtkToggleButton *toggle1, gpointer data)
  {
GtkWidget *label=gtk_bin_get_child(GTK_BIN(toggle1));
if(gtk_toggle_button_get_active(toggle1))
  {
gtk_label_set_markup(GTK_LABEL(label), "Italics");
italic=TRUE;
  }
else
  {
gtk_label_set_text(GTK_LABEL(label), "Italics");
italic=FALSE;
  }
gtk_widget_grab_focus(GTK_WIDGET(data));
  }
static void new_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar 
*text, gint len, gpointer user_data)
  {
if(italic)
  {
GtkTextIter *start=gtk_text_iter_copy(location);
GtkTextIter *end=gtk_text_iter_copy(location);
gtk_text_iter_backward_chars(start, len);
gtk_text_buffer_apply_tag_by_name(textbuffer, "tag1", start, end);
gtk_text_iter_free(start);
gtk_text_iter_free(end);
  }
  }
int main (int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Textview");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *text_view1=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view1), GTK_WRAP_CHAR);
gtk_widget_set_vexpand(text_view1, TRUE);
gtk_widget_set_hexpand(text_view1, TRUE);

GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view1));
gtk_text_buffer_create_tag(buffer, "tag1", "style", PANGO_STYLE_ITALIC, 
NULL);
g_signal_connect_after(buffer, "insert-text", G_CALLBACK(new_text), NULL);

GtkWidget *toggle1=gtk_toggle_button_new_with_label("Italics");
g_signal_connect(toggle1, "toggled", G_CALLBACK(toggle_italic), text_view1);

GtkWidget *grid=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid), 8);
gtk_grid_set_row_spacing(GTK_GRID(grid), 12);
gtk_grid_attach(GTK_GRID(grid), text_view1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), toggle1, 0, 1, 1, 1);

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }


 


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


Re: turn on italics in TextView

2017-06-14 Thread Eric Cashon via gtk-app-devel-list

 
Here are a few things that might improve the above code a little. Use

gtk_button_set_focus_on_click(GTK_BUTTON(toggle1), FALSE);

instead of a grab. Also the global gboolean can be eliminated if you pass the 
toggle button pointer to the "insert-text" callback. Then you can just use

if(gtk_toggle_button_get_active(user_data))
  
For the sequence of events it is my understanding that the text changes will be 
made during the event cycle before the window gets re-painted.

https://developer.gnome.org/gtk3/stable/chap-drawing-model.html

Eric
 

 

 

-Original Message-
From: Doug McCasland 
To: cecashon 
Sent: Tue, Jun 13, 2017 4:09 pm
Subject: Re: turn on italics in TextView


cecashon, thanks so much for your great reply!


I had tried all those calls, but I hadn't put them together as you did, nor did 
I apply the tag in the way your code does.  And I didn't think of having one 
signal/function for the button-down and another for the apply_tag_by_name.  
Cool!  


So your code gets a signal after the character(s) is entered. Then the style is 
applied to that char, without moving the insert point.  Do you know if the 
un-tagged char is visibly displayed first, and then altered?  Or is all the 
processing somehow finished before the display changes, and then only the 
tagged char is put on the screen.






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


Re: Integrate IP Camera stream in GTK app

2017-06-13 Thread Eric Cashon via gtk-app-devel-list

 
Hi Ruben,

I am sure you can do that with GTK and GStreamer. That way the code would be 
portable across platforms.

I don't have any examples of using GStreamer to get video from an ip camera. I 
have some test code that will show the video from the local webcam.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Sound/webcam3.c

There are a couple of other programs in the Sound folder that uses GStreamer 
with GTK if that is of any help. Also, I have an updated GStreamer 
basic-tutorial5 that will play local video or video from over the web if that 
would be of any help to you.

Eric

 


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


Re: Mouse leave on a row of GtkTreeView

2017-09-19 Thread Eric Cashon via gtk-app-devel-list

 
With a treeview you can try measuring your rows and figure out where your 
cursor is in your treeview. Try the following out and see if it is of any help.

Eric


/*
With Ubuntu16.04 and GTK3.18.
gcc -Wall tree_row1.c -o tree_row1 `pkg-config --cflags --libs gtk+-3.0`
*/
#include

static GtkTreeStore* get_tree_store();
static gboolean tree_motion(GtkWidget *widget, GdkEvent *event, gpointer *data);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Tree View");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeStore *store=get_tree_store();

GtkWidget *tree=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), TRUE);
g_object_unref(G_OBJECT(store));

GtkCellRenderer *renderer1=gtk_cell_renderer_text_new();
gtk_cell_renderer_set_fixed_size(renderer1, -1, 40);
g_object_set(renderer1, "editable", FALSE, NULL);
   
GtkTreeViewColumn 
*column1=gtk_tree_view_column_new_with_attributes("Index", renderer1, "text", 
0, NULL);
GtkTreeViewColumn *column2=gtk_tree_view_column_new_with_attributes("Name", 
renderer1, "text", 1, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column1);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column2);  

GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), tree);  

gpointer ps[]={renderer1, scroll};
g_signal_connect(tree, "motion-notify-event", G_CALLBACK(tree_motion), ps); 

GtkWidget *grid=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }
static GtkTreeStore* get_tree_store()
  {
gint i=0;
GtkTreeStore *store=gtk_tree_store_new(2, G_TYPE_INT, G_TYPE_STRING);

GtkTreeIter iter1;
for(i=0;i<10;i++)
  {
gchar *string1=g_strdup_printf("Name %i", i);
gtk_tree_store_append(store, , NULL);
gtk_tree_store_set(store, , 0, i, 1, string1, -1);
g_free(string1);
  }
  
return store;
  }
static gboolean tree_motion(GtkWidget *widget, GdkEvent *event, gpointer *data)
  {
gint motion_y=event->button.y;
GtkRequisition minimum_size;
GtkRequisition natural_size;
gtk_cell_renderer_get_preferred_size(GTK_CELL_RENDERER(data[0]), widget, 
_size, _size);
GtkAdjustment 
*adjustment=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(data[1]));
gdouble adj_h=gtk_adjustment_get_value(adjustment);

g_print("Row %i\n", (motion_y+(gint)adj_h)/natural_size.height);

return FALSE;
  }

 

 

-Original Message-
From: pspgen 
To: cecashon 
Sent: Tue, Sep 19, 2017 11:36 am
Subject: Re: Mouse leave on a row of GtkTreeView






- Цитат от cecas...@aol.com, на 19.09.2017 в 20:38 -


 
Could you use a GtkListBox? With a list box you can add a widget to the row and 
connect the "enter-notify-event" and "leave-notify-event" signals. There is 
example code for a list box at

https://blog.gtk.org/2017/06/01/drag-and-drop-in-lists-revisited/

It is drag and drop but you could change up widgets and connect different 
signals easy enough.


Eric


Can GtkListBox have columns? With sorting, search, reorder, resize etc 
functionality?
My whole build is based off GtkTreeView would be very hard to switch to another 
widget anyway..
So I rather can't use GtkListBox.











-
Mail.BG: Безплатен e-mail адрес. Най-добрите характеристики на българския пазар 
- 30 GB пощенска кутия, 1 GB прикрепен файл, безплатен POP3, мобилна версия и 
други.

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

Re: Mouse leave on a row of GtkTreeView

2017-09-19 Thread Eric Cashon via gtk-app-devel-list

 
Could you use a GtkListBox? With a list box you can add a widget to the row and 
connect the "enter-notify-event" and "leave-notify-event" signals. There is 
example code for a list box at

https://blog.gtk.org/2017/06/01/drag-and-drop-in-lists-revisited/

It is drag and drop but you could change up widgets and connect different 
signals easy enough.


Eric

 


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


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-14 Thread Eric Cashon via gtk-app-devel-list

 
Here is something else that might help. Try a monospace font to test with. If 
you use a monospace font then your spacing should be kept correct. If I draw a 
grid around the characters, monospace will hold the spacing to the 28x32 grid.

Eric

...
new_font = Pango.FontDescription("Monospace 20")
...
def draw_page(self, operation, gtk_context, page_number):
cr = gtk_context.get_cairo_context()

#Get rectangle for one monospace char for sizing.
self.pango_layout.set_markup("5")
rectangle_ink, rectangle_log = self.pango_layout.get_extents()
   
#Draw rectangles around monospaced text.
cr.set_source_rgb(1.0, 0.0, 1.0)
cr.set_line_width(1)
font_width = rectangle_log.width/Pango.SCALE
font_height = rectangle_log.height/Pango.SCALE
for x in range(28): 
for y in range(32):
cr.rectangle(y * font_width, x * font_height, font_width, 
font_height)
cr.stroke()
  
#Show Text.
cr.set_source_rgb(0.0, 0.0, 0.0)
start = self.textbuffer.get_start_iter()
end = self.textbuffer.get_end_iter()
string = self.textbuffer.get_text(start, end, False)
self.pango_layout.set_markup(string)
PangoCairo.show_layout(cr, self.pango_layout)

 


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


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-14 Thread Eric Cashon via gtk-app-devel-list

 
Hi Attila,

I don't know the internals of how Pango deals with the different fonts for 
putting them on a layout. I have bumped into utf8_casefold() and 
utf8_normalize() before so I know fonts can get complicated. Maybe someone with 
more knowledge than I have about this can help. The first thing that I would 
try out is to change the font that is being drawn to see if that works. Maybe 
you can get a font that Pango will draw correctly so that it can be converted 
from txt to pdf and back again. Have you tested a few different fonts to see if 
they do the same thing? Something like the following. I am doing some guessing 
here.

Eric

...
def begin_print(self, operation, gtk_context):
self.page_width = gtk_context.get_width()
self.page_height = gtk_context.get_height()
pango_context = self.get_pango_context()
description = pango_context.get_font_description()
font = description.to_string()
print(font)
#Test some fonts.
new_font = Pango.FontDescription("Arial 20")
self.pango_layout = gtk_context.create_pango_layout()
self.pango_layout.set_font_description(new_font)
self.pango_layout.set_width(int(self.page_width*Pango.SCALE));
self.pango_layout.set_wrap(Pango.WrapMode.CHAR)
...

 


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


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-15 Thread Eric Cashon via gtk-app-devel-list

 

OK, you got me on the PDF. I don't know about that. I think a monospace font 
will help though because they are easier to keep track of rows and columns 
since all the characters are in the same sized rectangle. The Marburg font is 
also in a constant sized rectangle. I don't know how to put together a layout 
with the two  different fonts sized correctly but I am sure it can be done to 
fit on a A4 page and have everything work correctly. 

This is my latest try at it. It has the A4 page size with a monospace font that 
will fit at 28 rows per page. Maybe it is a step in the right direction.

Eric

#!/usr/bin/env python3

#Needed for cairo context: sudo apt-get install python-gi-cairo
#Tested on Ubuntu16.04 with GTK3.18 and Python3.

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Gtk, GtkSource, PangoCairo, Pango
import math

class TextBox(GtkSource.View):
def __init__(self, win):
GtkSource.View.__init__(self)
self.parent_win = win
self.page_width = 0
self.page_height = 0
self.lines = 0
self.font_width = 0
self.font_height = 0
self.lines_per_page = 0
self.set_wrap_mode(1)
self.set_cursor_visible(True)
self.set_vexpand(True);
self.set_hexpand(True);
self.textbuffer = self.get_buffer() 
self.textbuffer.set_text("1 
alma\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28
 1\n1 
alma2\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28
 1")

def print_dialog(self):
operation = Gtk.PrintOperation()
page_setup = Gtk.PageSetup()
#Try the A4 paper size. 
paper_size = Gtk.PaperSize("iso_a4")
page_setup.set_paper_size(paper_size)
operation.set_default_page_setup(page_setup)
operation.connect("begin_print", self.begin_print)
operation.connect("draw_page", self.draw_page)
result = operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, 
self.parent_win)

def begin_print(self, operation, gtk_context):
self.page_width = gtk_context.get_width()
self.page_height = gtk_context.get_height()
pango_context = self.get_pango_context()
description = pango_context.get_font_description()
#Set a monospace font. Easier for figuring out layouts.
new_font = Pango.FontDescription("Monospace 24")
self.pango_layout = gtk_context.create_pango_layout()
self.pango_layout.set_font_description(new_font)
self.pango_layout.set_width(int(self.page_width*Pango.SCALE));
self.pango_layout.set_wrap(Pango.WrapMode.CHAR)

#Get font width and height for a monospace font.
self.pango_layout.set_markup("5")
rectangle_ink, rectangle_log = self.pango_layout.get_extents()
self.font_width = rectangle_log.width/Pango.SCALE
self.font_height = rectangle_log.height/Pango.SCALE

#Calculate lines per page. 28 lines of monspace 24 font fit on a A4 one 
page. 
self.lines = self.textbuffer.get_line_count() 
self.lines_per_page = int(self.page_height / self.font_height)
operation.set_n_pages(math.ceil(self.lines / self.lines_per_page))

def draw_page(self, operation, gtk_context, page_number):
cr = gtk_context.get_cairo_context()
   
#Draw rectangles around monospaced text.
cr.set_source_rgb(1.0, 0.0, 1.0)
cr.set_line_width(1)
for x in range(28): 
for y in range(32):
cr.rectangle(y * self.font_width, x * self.font_height, 
self.font_width, self.font_height)
cr.stroke()

#Page border rectangle.
cr.set_source_rgb(0.0, 0.0, 1.0)
cr.set_line_width(2)
cr.rectangle(0, 0, self.page_width, self.page_height)
cr.stroke()
  
#Get the lines of text to put on the page.
cr.set_source_rgb(0.0, 0.0, 0.0)
line_offset = page_number * self.lines_per_page
start = self.textbuffer.get_iter_at_line(line_offset)
end = self.textbuffer.get_iter_at_line(line_offset + 
self.lines_per_page - 1)
end.forward_to_line_end()
string = self.textbuffer.get_text(start, end, False)
self.pango_layout.set_markup(string)
PangoCairo.show_layout(cr, self.pango_layout)

class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Print")
self.set_default_size(300,700)
self.TextBox1 = TextBox(self)
self.scrolledwindow = Gtk.ScrolledWindow()
self.scrolledwindow.add(self.TextBox1)
self.button1 = Gtk.Button("Print Dialog")
self.button1.connect("clicked", self.print_dialog)
self.grid = Gtk.Grid()

Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-13 Thread Eric Cashon via gtk-app-devel-list

 
Hi Attila,

You have a print dialog and click on "Print to File" to save the contents to a 
PDF file and that file is not being formatted correctly and isn't the same as 
what is in the print preview? 

I tried a small test program. It prints well to PDF with the extra lines. Does 
this program work OK or does it cause the same problem.

Eric

#!/usr/bin/env python3

#Needed for cairo context: sudo apt-get install python-gi-cairo
#Tested on Ubuntu16.04 with GTK3.18 and Python3.

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Gtk, GtkSource, PangoCairo, Pango
import math

class TextBox(GtkSource.View):
def __init__(self, win):
GtkSource.View.__init__(self)
self.parent_win = win
self.page_width = 0
self.page_height = 0
self.set_wrap_mode(1)
self.set_cursor_visible(True)
self.set_vexpand(True);
self.set_hexpand(True);
self.textbuffer = self.get_buffer() 
self.textbuffer.set_text("  
alma\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
   1")

def print_dialog(self):
operation = Gtk.PrintOperation()
#Just print 1 page.
operation.set_n_pages(1)
operation.connect("begin_print", self.begin_print)
operation.connect("draw_page", self.draw_page)
result = operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, 
self.parent_win)

def begin_print(self, operation, gtk_context):
self.page_width = gtk_context.get_width()
self.page_height = gtk_context.get_height()
pango_context = self.get_pango_context()
description = pango_context.get_font_description()
self.pango_layout = gtk_context.create_pango_layout()
self.pango_layout.set_font_description(description)
self.pango_layout.set_width(int(self.page_width*Pango.SCALE));
self.pango_layout.set_wrap(Pango.WrapMode.CHAR)

def draw_page(self, operation, gtk_context, page_number):
cr = gtk_context.get_cairo_context()

#Draw a rectangle.
cr.set_source_rgb(1.0, 0.0, 1.0)
cr.set_line_width(5)
cr.rectangle(40, 40, self.page_width-80, self.page_height-500)
cr.stroke()

#Show Text.
cr.set_source_rgb(0.0, 0.0, 0.0)
start = self.textbuffer.get_start_iter()
end = self.textbuffer.get_end_iter()
string = self.textbuffer.get_text(start, end, False)
self.pango_layout.set_markup(string)
PangoCairo.show_layout(cr, self.pango_layout)

class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Print")
self.set_default_size(300, 700)
self.TextBox1 = TextBox(self)
self.scrolledwindow = Gtk.ScrolledWindow()
self.scrolledwindow.add(self.TextBox1)
self.button1 = Gtk.Button("Print Dialog")
self.button1.connect("clicked", self.print_dialog)
self.grid = Gtk.Grid()
self.grid.attach(self.scrolledwindow, 0, 0, 4, 4)
self.grid.attach(self.button1, 0, 5, 4, 1)
self.add(self.grid)

def print_dialog(self, button1):
self.TextBox1.print_dialog()

win = MainWindow()
win.connect("delete-event", Gtk.main_quit) 
win.show_all()
Gtk.main()



 


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


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-16 Thread Eric Cashon via gtk-app-devel-list

 Hi Attila,

The text buffer does return the correct number of chars with spaces. If I get a 
char count on the lines with or without numbers it returns the correct number. 
When I export to PDF the layout is the same as the print preview. When I test 
with pdftotext then, as you say, it doesn't maintain the correct layout. 
Looking at pdftotext --help, the website is given.

The Poppler Developers - http://poppler.freedesktop.org  

They do have a mailing list to contact the developers. Have you asked them 
about it? Maybe it is something that they can fix or have a solution for. 

The other option is if the text output is consistent from pdftotext then you 
could parse the text and format it correctly before importing into a new 
program. 

Eric 

Test char count.
...
#Get the lines of text to put on the page.
cr.set_source_rgb(0.0, 0.0, 0.0)
line_offset = page_number * self.lines_per_page
start = self.textbuffer.get_iter_at_line(line_offset)
end = self.textbuffer.get_iter_at_line(line_offset + self.lines_per_page - 
1)
#Test how far end of line is.
print("Line chars " + str(end.get_chars_in_line()))
end.forward_to_line_end()
...

 


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


Re: turn on italics in TextView

2017-08-30 Thread Eric Cashon via gtk-app-devel-list

 
Hi Doug, 

I would consider it a usability bug but not necessarily a textview widget bug. 
If you add text, that doesn't have an indent tag, to the start of the line then 
it doesn't get indented. I suppose you could check the whole line for an indent 
tag but that would go against performance. This one might be up to the 
application developer to deal with.

You could use spaces instead of tags depending on what is needed. To tag the 
inserted text at the start of the line you could check if there is an indent 
tag, and if there is, apply an indent tag to the newly inserted text.

You can check bugzilla to see if there are any bugs reported that are similar. 
There is a link here.

https://www.gtk.org/development.php

Eric

...
g_signal_connect_after(buffer, "insert-text", G_CALLBACK(insert_text), NULL);
...
static void insert_text(GtkTextBuffer *buffer, GtkTextIter *location, gchar 
*text, gint len, gpointer data)
  {
g_print("Text %s len %i offset %i\n", text, len, 
gtk_text_iter_get_offset(location));
GtkTextTagTable *table=gtk_text_buffer_get_tag_table(buffer);
GtkTextTag *indent_tag=gtk_text_tag_table_lookup(table, "indent");
GtkTextIter *start=gtk_text_iter_copy(location);
gtk_text_iter_backward_chars(start, len);
if(gtk_text_iter_has_tag(location, indent_tag))
  {
g_print("Indent Tag\n");
gtk_text_buffer_apply_tag(buffer, indent_tag, start, location);
  }
gtk_text_iter_free(start);
  }
...

 


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


Re: Show dialog after hide another

2017-09-09 Thread Eric Cashon via gtk-app-devel-list

Hi Ruben,

You can give the following a try and see if it helps. Basically you don't want 
to bind up the "main" thread with a long running function and freeze your UI. 

Eric

/* 
  gcc -Wall firmware1.c -o firmware1 `pkg-config --cflags --libs gtk+-3.0`
  Tested on Ubuntu16.04 and GTK3.18
*/

#include

/*
  Set some numbers for work to be done in the worker thread. Might need to 
change
  these for a faster cpu but be careful of guint overflow.
*/
#define SET1 10
#define SET2 1

static guint timeout_id=0;
static gint thread_active=0;
static gint load_progress=0;
static GThread *thread=NULL;

static void start_thread(GtkWidget *widget, GtkWidget **widgets);
static gpointer thread_get_firmware(GtkWidget **widgets);
static gboolean thread_join(GtkWidget **widgets);
static gboolean check_progress(GtkWidget *progress);
static void show_dialog(GtkWidget *widget, GtkWidget *window);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Show Progress");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *progress=gtk_progress_bar_new();
gtk_widget_set_hexpand(progress, TRUE);
gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progress), TRUE);

GtkWidget *button1=gtk_button_new_with_label("Show Firmware Progress");
gtk_widget_set_hexpand(button1, TRUE);
//Some widgets to pass through the thread function to g_idle_add(). 
GtkWidget *widgets[]={progress, button1};
g_signal_connect(button1, "clicked", G_CALLBACK(start_thread), widgets);

GtkWidget *button2=gtk_button_new_with_label("Show a Dialog");
gtk_widget_set_hexpand(button2, TRUE);
g_signal_connect(button2, "clicked", G_CALLBACK(show_dialog), window);

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), progress, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), button2, 0, 2, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);

gtk_main();
return 0;   
  }
static void start_thread(GtkWidget *widget, GtkWidget **widgets)
  {  
gtk_widget_set_sensitive(widget, FALSE); 
g_atomic_int_set(_active, 1);

thread=g_thread_new("TestThread", (GThreadFunc)thread_get_firmware, 
widgets);   
timeout_id=g_timeout_add(500, (GSourceFunc)check_progress, widgets[0]); 
  }
static gpointer thread_get_firmware(GtkWidget **widgets)
  {
//No GTK functions called in thread_get_firmware().
guint32 i=0;
gdouble percent=0;

for(i=0;i

Re: Multi page widgets in Gtk

2017-09-03 Thread Eric Cashon via gtk-app-devel-list

 
Hi Mike,

A GtkAssistant or even a GtkNotebook might work for your program. What database 
are you using? There is an easy example of connecting to and getting data from 
sqlite at

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/simple_sqlite_viewer.c

that might be helpful. You can output the database data to a textview or 
treeview. Lots of possibilities. 

Eric

 


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


Re: How to set the size of a combo box?

2017-10-08 Thread Eric Cashon via gtk-app-devel-list

Hi Lars,

There are a few things that you can try to see if you can get the combo box to 
format how you want it. The first is to create the combo with 
gtk_combo_box_new_with_model(). That way you can setup your cell renderer and 
be able to set properties of how the combo box is going to be rendered. To help 
with the placement of the combo box widget you can use the widget expand and 
align functions. If you put the combo box in a box container then you have a 
few more things you can use for getting the alignment correct.

Eric


//gcc -Wall combo_size1.c -o combo_size1 `pkg-config --cflags --libs gtk+-3.0`

#include

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Combo Size");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeIter iter;
GtkListStore *store=gtk_list_store_new(1, G_TYPE_STRING);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Arial 20", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Arial 20, an extra long line to clip", 
-1);

GtkCellRenderer *renderer=gtk_cell_renderer_text_new();
g_object_set(renderer, "height", 30, "width", 200, "font", "Arial 20", 
NULL);

GtkWidget *combo=gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
gtk_widget_set_hexpand(combo, FALSE);
gtk_widget_set_vexpand(combo, FALSE);
gtk_widget_set_halign(combo, GTK_ALIGN_END);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), 
GTK_CELL_RENDERER(renderer), "text", 0, NULL);

g_object_unref(G_OBJECT(store));

GtkWidget *box=gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), box);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }

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


Re: GTK PageSetupUnixdialog

2017-10-17 Thread Eric Cashon via gtk-app-devel-list

 
Hi Thomas,

What language are you using?

I think that the best tutorial for GTK+ right now is the gtkmm tutorial. They 
have a section on printing.

https://developer.gnome.org/gtkmm-tutorial/stable/chapter-printing.html.en

If you aren't programming in C++ the tutorial still is a good resource to get 
started with printing. I know there is very good documentation for C, C++, 
Python and Perl along with a few others. Once you figure out a languages 
format, it isn't to much trouble to map over the GTK function calls.

Eric

 


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


Re: How would I change the text style in a gedit plugin?

2017-11-26 Thread Eric Cashon via gtk-app-devel-list

 
This is similar but just using GTK. You get the iters for the start and end of 
the range that you want to tag and apply the tag to it.

Eric

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class TextBox(Gtk.TextView):
def __init__(self):
Gtk.TextView.__init__(self)
textbuffer = self.get_buffer() 
textbuffer.set_text("Some text to tag.\nAnother line to tag.")
start = textbuffer.get_start_iter()
end = textbuffer.get_end_iter()
tag = textbuffer.create_tag("blue_tag", background="blue", 
foreground="yellow")
textbuffer.apply_tag(tag, start, end)
   
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Text Tag")
self.set_default_size(300, 100)
self.tb = TextBox()
self.tb.set_hexpand(True)
self.tb.set_vexpand(True)
self.grid = Gtk.Grid()
self.grid.attach(self.tb, 0, 0, 1, 1)
self.add(self.grid)

win = MainWindow()
win.connect("delete-event", Gtk.main_quit) 
win.show_all()
Gtk.main()

 


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


Re: gtk_widget_size_allocate(): attempt to allocate widget with width -19 and height 1

2017-12-04 Thread Eric Cashon via gtk-app-devel-list

 Hi Franco,


I see "margin-left" is deprecated since version 3.12.

This might work. If you set the container margin of the grid and then 
individually place your widgets in the locations that you want them,,, 
hopefully no warnings. I don't get any warnings on GTK3.18. Will something like 
this work?

Eric

/*
   gcc -Wall expander1.c -o expander1 `pkg-config --cflags --libs gtk+-3.0`
   Tested with GTK3.18 on Ubuntu16.04
*/
#include

int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Expander");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *check1=gtk_check_button_new_with_label("Check1");
gtk_widget_set_hexpand(check1, TRUE);
gtk_widget_set_vexpand(check1, TRUE);

GtkWidget *check2=gtk_check_button_new_with_label("Check2");
gtk_widget_set_hexpand(check2, TRUE);
gtk_widget_set_vexpand(check2, TRUE);
gtk_widget_set_halign(check2, GTK_ALIGN_CENTER);

GtkWidget *label=gtk_label_new("Label");
gtk_widget_set_hexpand(label, TRUE); 
gtk_widget_set_vexpand(label, TRUE);  

GtkWidget *grid=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
gtk_grid_attach(GTK_GRID(grid), check1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), check2, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1);

GtkWidget *expander=gtk_expander_new("Expander");
gtk_container_add(GTK_CONTAINER(expander), grid);  

gtk_container_add(GTK_CONTAINER(window), expander);

gtk_widget_show_all(window);

gtk_main();

return 0;
  } 

 


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


Re: GTK3 - GtkExpander problem, bug ?

2017-12-14 Thread Eric Cashon via gtk-app-devel-list

 
Hi Sébastien,

If I try some test code... it should work. The code uses a grid instead of a 
fixed container. Is this similar to what you have tried?

Eric

/*
   gcc -Wall buttons1.c -o buttons1 `pkg-config --cflags --libs gtk+-3.0`
   Tested with GTK3.18 on Ubuntu16.04
*/
#include

static void button_clicked1(GtkWidget *button, gpointer user_data)
  {
g_print("1 %s\n", gtk_button_get_label(GTK_BUTTON(button)));
  }
static void button_clicked2(GtkWidget *button, gpointer user_data)
  {
g_print("2 %s\n", gtk_button_get_label(GTK_BUTTON(button)));
  }
int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Buttons");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

gint i=0;
gint j=0;
GtkWidget *buttons1[100];
GtkWidget *buttons2[100];

//First set of buttons.
for(i=0;i<100;i++)
  {
gchar *string=g_strdup_printf("button%i", i);
buttons1[i]=gtk_button_new_with_label(string);
g_free(string);
  }

GtkWidget *grid1=gtk_grid_new();
for(i=0;i<10;i++)
  {
for(j=0;j<10;j++)
  {
gtk_grid_attach(GTK_GRID(grid1), buttons1[i*10+j], j, i, 1, 1);
g_signal_connect(buttons1[i*10+j], "clicked", 
G_CALLBACK(button_clicked1), NULL);
  }
  } 

//Second set of buttons.
for(i=0;i<100;i++)
  {
gchar *string=g_strdup_printf("button%i", i);
buttons2[i]=gtk_button_new_with_label(string);
g_free(string);
  }

GtkWidget *grid2=gtk_grid_new();
for(i=0;i<10;i++)
  {
for(j=0;j<10;j++)
  {
gtk_grid_attach(GTK_GRID(grid2), buttons2[i*10+j], j, i, 1, 1);
g_signal_connect(buttons2[i*10+j], "clicked", 
G_CALLBACK(button_clicked2), NULL);
  }
  }   

GtkWidget *scroll1=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_vexpand(scroll1, TRUE);
gtk_widget_set_hexpand(scroll1, TRUE);
gtk_container_add(GTK_CONTAINER(scroll1), grid1);

GtkWidget *scroll2=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_vexpand(scroll2, TRUE);
gtk_widget_set_hexpand(scroll2, TRUE);
gtk_container_add(GTK_CONTAINER(scroll2), grid2);

GtkWidget *expander1=gtk_expander_new("buttons1");
gtk_container_add(GTK_CONTAINER(expander1), scroll1);

GtkWidget *expander2=gtk_expander_new("buttons2");
gtk_container_add(GTK_CONTAINER(expander2), scroll2);

GtkWidget *grid3=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid3), expander1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid3), expander2, 0, 1, 1, 1);

gtk_container_add(GTK_CONTAINER(window), grid3);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }   

 


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

Re: g_log_set_fatal_mask() not working for me.

2017-12-18 Thread Eric Cashon via gtk-app-devel-list

 
I found this bug for the scrollbar warning.

https://bugzilla.gnome.org/show_bug.cgi?id=769566

I don't know about the critical warning that you have or have a solution 
figured out. I am not much help there.

Eric 


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


Re: GTK3 - GtkExpander problem, bug ?

2017-12-14 Thread Eric Cashon via gtk-app-devel-list


 
Hi Sébastien,

An out of sync reply. I must have accidently deleted your last response after I 
read it. Also I didn't notice there were two mailing lists referenced. Probably 
just need the app dev list.

It looks like it is a bug that has been recently introduced. If I test, test.c 
with three expanders, on GTK3.18 it works fine. No problems. If I test on 
GTK3.22, after I close any expander the buttons can still be clicked even 
though they aren't showing. This is also the case with only 2 expanders in the 
original test code.



It sounds like the treeview work around is the way to go in this case.


Eric



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

Re: GTK3 - GtkExpander problem, bug ?

2017-12-15 Thread Eric Cashon via gtk-app-devel-list

 
Thanks Matthias. I probably should have checked bugzilla first. Just rebuilt 
GTK to version 3.22.26 and it works fine. There is no click through after 
closing the expander.

Eric

 


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


Re: g_log_set_fatal_mask() not working for me.

2017-12-17 Thread Eric Cashon via gtk-app-devel-list

 
Hi Richard,

This sounds similar to the problem Dino Aljević had in "Scrolled TreeView and 
size allocation warnings" in this list in September?

I can get the warning

"(treeview4:3830): Gtk-WARNING **: Allocating size to GtkWindow 0x843e188 
without calling gtk_widget_get_preferred_width/height(). How does the code know 
the size to allocate?"

with the following code with GTK3.22.26 but I don't see the warning in 
GTK3.18.9. To get the warning expand the treeview until the list extends past 
the window boundry. I looked on Bugzilla but I didn't see it listed there. I am 
not great at finding things on Bugzilla so that doesn't mean it isn't there.

Do you have some test code to produce the GtkScrollbar warning you are seeing?

For the g_log_set_fatal_mask() and a runtime stop, try starting your code with 

G_DEBUG=fatal-warnings

It is a warning though. Something needs to be fixed but your program should run 
fine.

Eric



/*
gcc -Wall treeview4.c -o treeview4 `pkg-config --cflags --libs gtk+-3.0`
Tested on Ubuntu16.04 with GTK3.18.9 and GTK3.22.26

run with

G_DEBUG=fatal-warnings GTK_THEME=Adwaita:dark ./treeview4

this theme doesn't produce any css warnings with GTK3.22.26.

*/
#include

static GtkTreeStore* get_tree_store();

int main(int argc, char *argv[])
  {
gtk_init(, );

g_print("%i.%i.%i\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, 
GTK_MICRO_VERSION);

g_log_set_fatal_mask("Gtk", G_LOG_LEVEL_WARNING);

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Tree View");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeStore *store=get_tree_store();

GtkWidget *tree=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), TRUE);
g_object_unref(G_OBJECT(store));

GtkCellRenderer *renderer1=gtk_cell_renderer_text_new();
g_object_set(renderer1, "editable", TRUE, NULL);
   
GtkTreeViewColumn *column1 = 
gtk_tree_view_column_new_with_attributes("Shape Coordinates", renderer1, 
"text", 0, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column1); 

GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), tree);   

GtkWidget *grid=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }
static GtkTreeStore* get_tree_store()
  {
gint i=0;
gint j=0;
GtkTreeStore *store=gtk_tree_store_new(1, G_TYPE_STRING);

GtkTreeIter iter1;
GtkTreeIter iter2;
gtk_tree_store_append(store, , NULL);
for(i=0;i<3;i++)
  {
gchar *string1=g_strdup_printf("S%i", i);
gtk_tree_store_set(store, , 0, string1, -1);
g_free(string1);
for(j=0;j<5;j++)
  {
gtk_tree_store_append(store, , );   
gchar *string2=g_strdup_printf("C%i", j);
gtk_tree_store_set(store, , 0, string2, -1);
g_free(string2);
  }
gtk_tree_store_append(store, , NULL);
  }
  
return store;
  }

 


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

Re: PyGObject Maybe bug with alternate row colors in a Gt.TreeView

2018-05-16 Thread Eric Cashon via gtk-app-devel-list

 
I took a look at the stackoverflow discussion about this and there is some 
sample code there to change colors of individual records in the treeview list. 
You can no longer do even and odd colors in CSS but being able to connect a 
cell renderer property to a column value can be very useful. 

The following gives an error if I use "cell-background" which is stated in the 
documentation. Maybe just a typo someplace but "cell_background" seems to work 
fine for binding the color column to the cell-background property. You can pass 
some common color names or a rgb hex value for a color string.

Maybe a pretty terrible color combo going here but it might be a useful 
technique to highlight particular records to bring a users attention to them. A 
lot that you can do with a treeview.

Eric

import gi
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk

class MainWindow(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title="Stripes")
self.set_default_size(200, 200)
self.set_position(Gtk.WindowPosition.CENTER)

self.liststore = Gtk.ListStore(str, str)
self.liststore.append(["Apples", "cyan"])
self.liststore.append(["Oranges", "yellow"])
self.liststore.append(["Pears", "cyan"])
self.liststore.append(["Currants", "yellow"])
self.liststore.append(["Gooseberries", "#00"])
self.liststore.append(["Strawberries", "#00"])

self.treeview = Gtk.TreeView(model=self.liststore)
self.treeview.set_vexpand(True)
self.treeview.set_hexpand(True)

self.renderer = Gtk.CellRendererText()
self.renderer.set_property("font", "Arial 16")
self.renderer.set_property("xalign", 0.5)

#Set the column to get the background color from. Need cell_background 
instead of cell-background???
self.column = Gtk.TreeViewColumn("Fruit", self.renderer, text = 0, 
cell_background = 1)
self.column.set_expand(True)

self.treeview.append_column(self.column)

self.add(self.treeview)

win = MainWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

 


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


Re: GtkTextBuffer : Applying tags to newly input text

2018-06-13 Thread Eric Cashon via gtk-app-devel-list


 
Hi Gary,

Test setting up your callback with g_signal_connect_after. Then the location 
iter should be at the end of the insert. Then the tag can be applied to the 
inserted text.

Eric


//gcc -Wall highlight1.c -o highlight1 `pkg-config --cflags --libs gtk+-3.0`

#include 

static gboolean set_tag=FALSE;

static void button_toggled(GtkToggleButton *button, gpointer data)
  {
g_print("Button Toggled\n");
set_tag=gtk_toggle_button_get_active(button);
  }
static void insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar 
*text, gint len, GtkTextTag * cyan_tag)
  {
g_print("Insert %s Offset %i\n", text, gtk_text_iter_get_offset(location));

if(set_tag)
  {
GtkTextIter *start=gtk_text_iter_copy(location);
gtk_text_iter_backward_chars(start, len);
gtk_text_buffer_apply_tag(textbuffer, cyan_tag, start, location);
gtk_text_iter_free(start);
  }
  }
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Highlight");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 20);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *textview=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR);
gtk_widget_set_hexpand(textview, TRUE);
gtk_widget_set_vexpand(textview, TRUE);

GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
GtkTextTag *cyan_tag=gtk_text_buffer_create_tag(buffer, "cyan-tag", 
"background", "cyan", NULL);
g_signal_connect_after(buffer, "insert-text", G_CALLBACK(insert_text), 
cyan_tag); 

GtkWidget *button=gtk_toggle_button_new_with_label("Cyan Highlight");
g_signal_connect(button, "toggled", G_CALLBACK(button_toggled), NULL);

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), textview, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), button, 0, 1, 1, 1);

gtk_container_add(GTK_CONTAINER(window), grid);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }



 


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


Re: This takes 30 secs to render

2018-06-01 Thread Eric Cashon via gtk-app-devel-list


 
The other way to go about it is to just use cairo. I don't think that it will 
give a speed improvement but it might be worth a try. I figure you are trying 
to scale the png first and then draw it in a widget. Once the image is sized it 
shouldn't be a problem to draw quickly.


Eric



//gcc -Wall big_png1.c -o big_png1 `pkg-config gtk+-3.0 --cflags --libs`

#include

static gboolean da_drawing(GtkWidget *da, cairo_t *cr, cairo_surface_t 
*surface);
static void save_png();
static cairo_surface_t *get_and_scale_png();

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Big PNG");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GTimer *timer=g_timer_new();
save_png();
g_print("Save Time %f\n", g_timer_elapsed(timer, NULL));
g_timer_start(timer);
cairo_surface_t *surface=get_and_scale_png();
g_print("Get Time %f\n", g_timer_elapsed(timer, NULL));
g_timer_destroy(timer);

GtkWidget *da=gtk_drawing_area_new();
gtk_widget_set_size_request(da, 1, 1);
gtk_widget_set_hexpand(da, TRUE);
gtk_widget_set_vexpand(da, TRUE);
g_signal_connect(da, "draw", G_CALLBACK(da_drawing), surface);

GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scroll), da);
  
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
  
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);

gtk_main();

cairo_surface_destroy(surface);

return 0;
  }
static gboolean da_drawing(GtkWidget *da, cairo_t *cr, cairo_surface_t *surface)
  {   
GTimer *timer=g_timer_new(); 
cairo_set_source_surface(cr, surface, 0.0, 0.0);
cairo_paint(cr);
g_print("Draw Time %f\n", g_timer_elapsed(timer, NULL));
g_timer_destroy(timer);

return FALSE;
  }
static void save_png()
  {
gdouble width=5000.0;
gdouble height=5000.0;
cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 
width, height);
cairo_t *cr=cairo_create(surface);
   
//Paint the green background.
cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0);
cairo_paint(cr);

cairo_set_source_rgba(cr, 1.0, 0.0, 1.0, 1.0);
cairo_set_line_width(cr, 80.0);
cairo_rectangle(cr, 0.0, 0.0, width, height);
cairo_stroke(cr);

cairo_surface_write_to_png(surface, "big.png");

cairo_destroy(cr);
cairo_surface_destroy(surface);
  }
static cairo_surface_t *get_and_scale_png()
  {
//The 5,000x5,000 surface.
cairo_surface_t *surface=cairo_image_surface_create_from_png("big.png");

//Scale to 1/10 of width and height.
cairo_surface_t *surface2=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 
500.0, 500.0);
cairo_t *cr2=cairo_create(surface2);

cairo_scale(cr2, 1.0/10.0, 1.0/10.0);
cairo_set_source_surface(cr2, surface, 0.0, 0.0);
cairo_pattern_set_filter(cairo_get_source(cr2), CAIRO_FILTER_FAST);
cairo_paint(cr2);

cairo_destroy(cr2);
cairo_surface_destroy(surface);

return surface2;
  }


 


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


Re: Link Gtk.ListStore to the real data

2018-06-02 Thread Eric Cashon via gtk-app-devel-list


Try a relational database. Sqlite is an easy one to use. It can sort and save 
data to multiple tables. Use the list model and treeview to retrieve and view 
the data. That way the columns can be set up dynamically along with the 
renderer. Use SQL to update the database.

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


Re: GtkTextBuffer : Applying tags to newly input text

2018-06-22 Thread Eric Cashon via gtk-app-devel-list


 

 
With the text buffer and tag table you can get the text with pango attributes 
or even rebuild pango markup for print output. This allows the pango markup to 
be parsed into and then to be extracted from the text buffer without 
loss(Easier said than done). You only need one text buffer to manage. I suspect 
that you can't do that with html. I don't think that you can rebuild html after 
parsing it into a text buffer. Maybe a small subset of html? Having more than 
one buffer and trying to synchronize them upon edits,,, doesn't sound very easy 
either but might be the better choice. A bit of a tough problem.

Eric


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


Re: Using Gtk.Builder to create a menubar.

2018-04-26 Thread Eric Cashon via gtk-app-devel-list

 
"1. It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would
prefere this way instead of an XML string. It should be possible
in Python, too? Gtk.Menu or Gio.Menu?"

My understanding of this is that the GMenu is used with the GtkApplication and 
a GtkMenu is used with the "regular" GTK setup. You can use either one in code 
depending on what your program needs and how your program is structured.

Eric

 



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


Re: Need help in GTK3 Draw event

2018-04-28 Thread Eric Cashon via gtk-app-devel-list

 

 
Hi Dhrubajyoti,

The textview widget has text tags built in that you can use to draw rectangles 
around text. If you want to draw a rectangle to block out text you can match 
the background and foreground colors. This code works on Ubuntu16.04, GTK3.18 
and Python2.7. Give it a try and see if something similar will work for what 
you are working on.

Eric

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class TextBox(Gtk.TextView):
def __init__(self):
Gtk.TextView.__init__(self)
textbuffer = self.get_buffer() 
textbuffer.set_text("Some text to tag.\nAnother line to tag.")
start = textbuffer.get_start_iter()
end = textbuffer.get_end_iter()
tag = textbuffer.create_tag("blue_tag", background="blue", 
foreground="yellow")
textbuffer.apply_tag(tag, start, end)
   
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Text Tag")
self.set_default_size(300, 100)
self.tb = TextBox()
self.tb.set_hexpand(True)
self.tb.set_vexpand(True)
self.grid = Gtk.Grid()
self.grid.attach(self.tb, 0, 0, 1, 1)
self.add(self.grid)

win = MainWindow()
win.connect("delete-event", Gtk.main_quit) 
win.show_all()
Gtk.main()

 

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


Re: Scrolling a GtkTreeview cell

2018-01-24 Thread Eric Cashon via gtk-app-devel-list
Hi Kian,

Have you tried a GtkListBox for this? You can probably setup a scrolling window 
in a row in a listbox. 

https://blog.gtk.org/2017/06/01/drag-and-drop-in-lists-revisited/

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


Re: Scrolling a GtkTreeview cell

2018-01-25 Thread Eric Cashon via gtk-app-devel-list

 
Hi Kian,

A list box is more flexible for allowing different widgets but the performance 
might not be so good if you have a lot of rows. Don't have the numbers to show 
that though.

You can put your individual widgets into a scrolled window if you want.  The 
scroll bars will show if the content runs past the border. This is a little 
test code with some textviews in scrolled windows within the list box. You can 
move across rows and columns with the keyboard arrow keys. Might have to do a 
little programming to get the list box to behave how you want for your program.

Eric

/*  
gcc -Wall list_box1.c -o list_box1 `pkg-config --cflags --libs gtk+-3.0`

Tested on Ubuntu16.04 and GTK3.18
*/

#include

static GtkWidget *create_row(const gchar *text)
  {
GtkWidget *row=gtk_list_box_row_new();
gtk_widget_set_size_request(row, 370, 50);
gtk_list_box_row_set_selectable(GTK_LIST_BOX_ROW(row), TRUE);
gtk_list_box_row_set_activatable(GTK_LIST_BOX_ROW(row), TRUE);
GtkWidget *textview=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR);
gtk_widget_set_hexpand(textview, TRUE);
gtk_widget_set_vexpand(textview, TRUE);
GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_set_text(buffer, text, -1);
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), textview);
GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_set_border_width(GTK_CONTAINER(box), 5);
g_object_set (box, "margin-end", 10, NULL);
GtkWidget *label=gtk_label_new(text);  
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);  
gtk_container_add(GTK_CONTAINER(row), box);

return row;
  }
int main(int argc, char **argv)
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "List Box");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *list_box=gtk_list_box_new();
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(list_box), TRUE);
gtk_widget_set_hexpand(list_box, TRUE);
gtk_widget_set_vexpand(list_box, TRUE);

gint i=0;
GtkWidget *row=NULL;
for(i=0;i<10;i++) 
  {
gchar *text=g_strdup_printf("Row %d", i);
row=create_row(text);
gtk_list_box_insert(GTK_LIST_BOX(list_box), row, -1);
g_free(text);
  }

GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), list_box);

GtkWidget *grid1=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
gtk_grid_attach(GTK_GRID(grid1), scroll, 0, 0, 1, 1);
   
gtk_container_add(GTK_CONTAINER(window), grid1);

gtk_widget_show_all(window);

gtk_main();

return 0;  
  }

 


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


Re: GtkTreeViewColumn width

2018-02-18 Thread Eric Cashon via gtk-app-devel-list

 
Hi Phil,

You should be able to resize columns if you want. If you have set sizes of text 
to display in the tree view and want to allocate sizes you can do that.

Eric


/*
Tested with Ubuntu16.04 and GTK3.18.
gcc -Wall tree_column1.c -o tree_column1 `pkg-config --cflags --libs 
gtk+-3.0`
*/

#include

static GtkTreeStore* get_tree_store();
static void set_column2_width(GtkComboBox *combo, GtkTreeViewColumn *column2);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Tree View");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeStore *store=get_tree_store();

GtkWidget *tree=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
g_object_unref(G_OBJECT(store));

GtkCellRenderer *renderer1=gtk_cell_renderer_text_new();
g_object_set(renderer1, "editable", FALSE, NULL);
   
GtkTreeViewColumn 
*column1=gtk_tree_view_column_new_with_attributes("Column1", renderer1, "text", 
0, NULL);
gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column1), 
GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(GTK_TREE_VIEW_COLUMN(column1), 100);

GtkTreeViewColumn 
*column2=gtk_tree_view_column_new_with_attributes("Column2", renderer1, "text", 
1, NULL);
gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column2), 
GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(GTK_TREE_VIEW_COLUMN(column2), 25);

GtkTreeViewColumn 
*column3=gtk_tree_view_column_new_with_attributes("Column3", renderer1, "text", 
2, NULL);

gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column1);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column2); 
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column3); 

GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), tree); 

GtkWidget *combo=gtk_combo_box_text_new();
gtk_widget_set_hexpand(combo, TRUE);
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 0, "1", "Column2 width 
25");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 1, "2", "Column2 width 
50");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 2, "3", "Column2 width 
100");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 3, "4", "Column2 width 
150");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
g_signal_connect(combo, "changed", G_CALLBACK(set_column2_width), column2); 
  

GtkWidget *grid=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo, 0, 1, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }
static GtkTreeStore* get_tree_store()
  {
gint i=0;
GtkTreeStore *store=gtk_tree_store_new(3, G_TYPE_INT, G_TYPE_STRING, 
G_TYPE_STRING);

GtkTreeIter iter1;
for(i=0;i<10;i++)
  {
gchar *string1=g_strdup_printf("Name %i", i);
gtk_tree_store_append(store, , NULL);
gtk_tree_store_set(store, , 0, i, 1, string1, 2, string1, -1);
g_free(string1);
  }
  
return store;
  }
static void set_column2_width(GtkComboBox *combo, GtkTreeViewColumn *column2)
  {
gint combo_id=gtk_combo_box_get_active(combo);
if(combo_id==0) 
gtk_tree_view_column_set_fixed_width(GTK_TREE_VIEW_COLUMN(column2), 25);
else if(combo_id==1) 
gtk_tree_view_column_set_fixed_width(GTK_TREE_VIEW_COLUMN(column2), 50);
else if(combo_id==2) 
gtk_tree_view_column_set_fixed_width(GTK_TREE_VIEW_COLUMN(column2), 100);
else gtk_tree_view_column_set_fixed_width(GTK_TREE_VIEW_COLUMN(column2), 
150);
  }


 


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


Re: GtkTreeViewColumn width

2018-02-18 Thread Eric Cashon via gtk-app-devel-list

Try switching the sizing to what is needed. Something like

...
gint combo_id=gtk_combo_box_get_active(combo);
if(combo_id==0)
  {
g_print("%i\n", gtk_tree_view_column_get_width(column2));
gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column2), 
GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(GTK_TREE_VIEW_COLUMN(column2), 25);
gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(column2), 
GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column2), TRUE);
  }
...

Then when you start the program, get the saved values, set as fixed and then 
switch to autosize.

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


Re: GtkTextBuffer : Applying tags to newly input text

2018-06-21 Thread Eric Cashon via gtk-app-devel-list


 
The textview understands Pango markup. Maybe something to give a try. There are 
a lot of text formats and you might have to do some text parsing depending on 
the format. If it is possible to use gtk_text_buffer_insert_markup(), this can 
save a lot of time dealing with text tags especially if you intend to print the 
text. It is far easier to send a pango markup string to print than to go 
through all the tags and draw them with cairo.

https://developer.gnome.org/pango/stable/PangoMarkupFormat.html

Eric

 


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


Re: Use Xcode to run Gtk code instead of terminal

2018-07-20 Thread Eric Cashon via gtk-app-devel-list

 Hi Evan,

I am unfamiliar with Xcode but if you can compile the code at the command line 
and have pkg-config working then check where the include files are that you 
need and add them to your Xcode development environment. Try

pkg-config --cflags --libs gtk+-3.0

at the command line for your includes and libraries.


Eric

 

 

-Original Message-
From: Evan Wong via gtk-app-devel-list 
To: gtk-app-devel-list 
Sent: Fri, Jul 20, 2018 4:54 am
Subject: Use Xcode to run Gtk code instead of terminal

Hi: I have installed the latest version of whatever gtk+ and gtk+3 on my 
MacBook pro, and I have tried the command line to run the Gtk code 
successfully. However, I want to run this code in the Xcode, but this popped up 
with “ 'gtk/gtk.h' file not found” , and I don’t find any .h file of gtk. 
Therefore, could you give me some solutions or the only way I can run this code 
is using the command line? Thanks!via Newton Mail 
[https://cloudmagic.com/k/d/mailapp?ct=dx=9.8.415=10.14.0=email_footer_2]___gtk-app-devel-list
 mailing 
listgtk-app-devel-list@gnome.orghttps://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: "draw" icon with string

2018-09-10 Thread Eric Cashon via gtk-app-devel-list
 
Give this a try. It creates a surface, draws on it and then returns the surface 
so that it can be put in an image widget. 


import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
import cairo

class MainWindow(Gtk.Window):
    def __init__(self):
    Gtk.Window.__init__(self)
    self.set_title("Surface")
    self.set_default_size(400, 400)
    self.set_position(Gtk.WindowPosition.CENTER)

    surface = self.get_surface()

    image = Gtk.Image()
    image.set_from_surface(surface)
    image.set_vexpand(True)
    image.set_hexpand(True)

    grid = Gtk.Grid()
    grid.attach(image, 0, 0, 1, 1)
    self.add(grid)

    def get_surface(self):
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 200, 200)
    cr = cairo.Context(surface)
    
    cr.set_source_rgb(0.8, 0.8, 0.8)
    cr.paint()

    cr.set_source_rgb(0.0, 1.0, 0.0)
    cr.set_line_width(6)
    cr.rectangle(0, 0, 200.0, 200.0) 
    cr.stroke()
    cr.set_source_rgb(0.0, 0.0, 1.0)
    cr.set_line_width(3)
    cr.move_to(0.0, 100.0)
    cr.line_to(200.0, 100.0)
    cr.stroke()
    cr.move_to(100.0, 0.0)
    cr.line_to(100.0, 200.0)
    cr.stroke()

    cr.set_source_rgb(1.0, 0.0, 1.0)
    cr.select_font_face("Arial", cairo.FONT_SLANT_NORMAL, 
cairo.FONT_WEIGHT_BOLD)
    cr.set_font_size(40)
    (x, y, width, height, dx, dy) = cr.text_extents("Cairo")
    cr.move_to(200/2 - width/2, 200/2 + height/2) 
    cr.show_text("Cairo")

    cr.set_source_rgb(0.0, 0.0, 0.0)
    cr.set_line_width(1)
    cr.rectangle(200/2-width/2, 200/2 - height/2, width, height)
    cr.stroke() 

    return surface

win = MainWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
   
 
 
-Original Message-
From: c.buhtz--- via gtk-app-devel-list 
To: c.buhtz--- via gtk-app-devel-list 
Cc: c.buhtz 
Sent: Sun, Sep 9, 2018 2:14 pm
Subject: Re: "draw" icon with string

On 2018-09-09 23:01 "c.buhtz--- via gtk-app-devel-list"
 wrote:
> It is unclear to me how to create a cairo.Surface instance.
> 

And I can not see any text/string drawing methods in the surface class.
___
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: Lucky B.C.'s reply to GtkDrawingArea "width" and "height"

2018-03-06 Thread Eric Cashon via gtk-app-devel-list

 
Hi Roger,

Not sure about your builder question and setting the width and height of the 
drawing area there. For drawing lines though it looks like you are trying to 
get the width and height of the GtkWindow instead of the drawing area. The 
drawing area widget is passed to your "draw" callback so you can get the width 
and height there. For updating the drawing with the spin buttons you would need 
to send the drawing area to those callbacks and call gtk_widget_queue_draw(da) 
to update your drawing.

Can you put gtk_widget_set_size_request() right after

drawing1 = gtk_builder_get_object (builder1, "drawing1");

in your code? Will that work?

Eric

Some test code.

//gcc -Wall grid_da1.c -o grid_da1 `pkg-config --cflags --libs gtk+-3.0`

#include

static gint rows=4;
static gint columns=5;

static void rows_spin_changed(GtkSpinButton *spin_button, GtkWidget *da);
static void columns_spin_changed(GtkSpinButton *spin_button, GtkWidget *da);
static gboolean draw_lines(GtkWidget *widget, cairo_t *cr, gpointer data);

int main(int argc, char *argv[])
  {
gtk_init(, );
   
GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 600, 400);
gtk_window_set_title(GTK_WINDOW(window), "Draw Grid");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *da=gtk_drawing_area_new();
gtk_widget_set_size_request(da, 600, 600);
g_signal_connect(da, "draw", G_CALLBACK(draw_lines), NULL);

GtkWidget *view=gtk_viewport_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(view), da);
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scroll), view);

GtkAdjustment *adjustment1=gtk_adjustment_new(4, 3, 15, 1, 0, 0);
GtkAdjustment *adjustment2=gtk_adjustment_new(5, 3, 15, 1, 0, 0);

GtkWidget *rows_spin_label=gtk_label_new("Rows");

GtkWidget *rows_spin=gtk_spin_button_new(adjustment1, 1, 0);
g_signal_connect(rows_spin, "value-changed", G_CALLBACK(rows_spin_changed), 
da);

GtkWidget *columns_spin_label=gtk_label_new("Columns");

GtkWidget *columns_spin=gtk_spin_button_new(adjustment2, 1, 0);
g_signal_connect(columns_spin, "value-changed", 
G_CALLBACK(columns_spin_changed), da);

GtkWidget *grid=gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(grid), 8);
gtk_grid_attach(GTK_GRID(grid), rows_spin_label, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), rows_spin, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), columns_spin_label, 0, 2, 1, 1);
gtk_grid_attach(GTK_GRID(grid), columns_spin, 0, 3, 1, 1);

GtkWidget *paned1=gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
gtk_paned_pack1(GTK_PANED(paned1), grid, FALSE, TRUE);
gtk_paned_pack2(GTK_PANED(paned1), scroll, TRUE, TRUE);
gtk_paned_set_position(GTK_PANED(paned1), 200);
   
gtk_container_add(GTK_CONTAINER(window), paned1);

gtk_widget_show_all(window);

gtk_main();

return 0;
  }
static void rows_spin_changed(GtkSpinButton *spin_button, GtkWidget *da)
  {
rows=gtk_spin_button_get_value_as_int(spin_button);
gtk_widget_queue_draw(da);
  }
static void columns_spin_changed(GtkSpinButton *spin_button, GtkWidget *da)
  {
columns=gtk_spin_button_get_value_as_int(spin_button);
gtk_widget_queue_draw(da);
  }
static gboolean draw_lines(GtkWidget *da, cairo_t *cr, gpointer data)
  {
g_print("Drawing Area Width %i, Height %i\n", 
gtk_widget_get_allocated_width(da), gtk_widget_get_allocated_height(da));
gint i=0;
gdouble width=(gdouble)gtk_widget_get_allocated_width(da);
gdouble height=(gdouble)gtk_widget_get_allocated_height(da);
gdouble w1=width/10.0;
gdouble h1=height/10.0;
gdouble w2=8.0*w1/(gdouble)columns;
gdouble h2=8.0*h1/(gdouble)rows;
  
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
cairo_paint(cr);

cairo_set_line_width(cr, 3.0);
cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);
for(i=0;i

Re: Scrolling to a GtkListBoxRow after adding it to a GtkListBox

2018-04-14 Thread Eric Cashon via gtk-app-devel-list

 
Hi Mike,

It looks like the new rows height isn't getting added to the adjustment. If the 
height of the new row gets added to the upper value of the adjustment then the 
last row of the list box can be shown when added. This is what I came up with 
to test it out. Is this similar to what you are seeing?

Eric

/*  
gcc -Wall list_box1.c -o list_box1 `pkg-config --cflags --libs gtk+-3.0`

Tested on Ubuntu16.04 and GTK3.18
*/

#include

static GtkWidget *create_row(const gchar *text)
  {
GtkWidget *row=gtk_list_box_row_new();
gtk_widget_set_size_request(row, 370, 50);
gtk_list_box_row_set_selectable(GTK_LIST_BOX_ROW(row), TRUE);
gtk_list_box_row_set_activatable(GTK_LIST_BOX_ROW(row), TRUE);
GtkWidget *textview=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR);
gtk_widget_set_hexpand(textview, TRUE);
gtk_widget_set_vexpand(textview, TRUE);
GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_set_text(buffer, text, -1);
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), textview);
GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_set_border_width(GTK_CONTAINER(box), 5);
g_object_set (box, "margin-end", 10, NULL);
GtkWidget *label=gtk_label_new(text);  
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);  
gtk_container_add(GTK_CONTAINER(row), box);

return row;
  }
static void add_row(GtkWidget *button, GtkWidget *list_box)
  {
static gint i=10;
gchar *text=g_strdup_printf("Row %d", i);
GtkWidget *row=create_row(text);
gtk_list_box_insert(GTK_LIST_BOX(list_box), row, -1);
gtk_widget_show_all(row);
gtk_list_box_select_row(GTK_LIST_BOX(list_box), GTK_LIST_BOX_ROW(row));

GtkRequisition minimum_size; 
GtkRequisition natural_size;
gtk_widget_get_preferred_size(row, _size, _size);
g_print("min %i nat %i\n", minimum_size.height, natural_size.height);

GtkAdjustment *adj=gtk_list_box_get_adjustment(GTK_LIST_BOX(list_box));
gdouble upper=gtk_adjustment_get_upper(adj);
//Add extra height to adjustment.
gtk_adjustment_set_upper(adj, upper+minimum_size.height);
upper=gtk_adjustment_get_upper(adj);
gtk_adjustment_set_value(adj, upper);

g_free(text);
i++;
  }
int main(int argc, char **argv)
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "List Box");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *list_box=gtk_list_box_new();
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(list_box), TRUE);
gtk_widget_set_hexpand(list_box, TRUE);
gtk_widget_set_vexpand(list_box, TRUE);

gint i=0;
GtkWidget *row=NULL;
for(i=0;i<10;i++) 
  {
gchar *text=g_strdup_printf("Row %d", i);
row=create_row(text);
gtk_list_box_insert(GTK_LIST_BOX(list_box), row, -1);
g_free(text);
  }

GtkWidget *button=gtk_button_new_with_label("Add Row");
gtk_widget_set_hexpand(button, TRUE);
g_signal_connect(button, "clicked", G_CALLBACK(add_row), list_box);

GtkWidget *scroll_win=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll_win, TRUE);
gtk_widget_set_vexpand(scroll_win, TRUE);
gtk_container_add(GTK_CONTAINER(scroll_win), list_box);

GtkWidget *grid1=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
gtk_grid_attach(GTK_GRID(grid1), scroll_win, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid1), button, 0, 1, 1, 1);
   
gtk_container_add(GTK_CONTAINER(window), grid1);

gtk_widget_show_all(window);

gtk_main();

return 0;  
  }


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


Re: Scrolling to a GtkListBoxRow after adding it to a GtkListBox

2018-04-15 Thread Eric Cashon via gtk-app-devel-list

 
"
Is the issue that the widget is not yet drawn, so it size is not settled yet?

Total guesses: What about using g_signal_connect_after on size-allocate? Or 
connecting to map-event signal on that widget? Or spinning on 
gtk_events_pending() until all are done, then scroll down?
"

Hi Matthew

Good ideas. A quick check on the events pending works. The g_signal_connect or 
g_signal_connect_after is probably a better way to go.

Eric

'''
GtkWidget *row=create_row(text);
gtk_list_box_insert(GTK_LIST_BOX(list_box), row, -1);
gtk_widget_show_all(row);
while (gtk_events_pending()) gtk_main_iteration();
gtk_list_box_select_row(GTK_LIST_BOX(list_box), GTK_LIST_BOX_ROW(row));
GtkAdjustment *adj=gtk_list_box_get_adjustment(GTK_LIST_BOX(list_box));
gdouble upper=gtk_adjustment_get_upper(adj); 
gtk_adjustment_set_value(adj, upper); 
''' 

 





 

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


Re: Overriding CSS style

2018-04-19 Thread Eric Cashon via gtk-app-devel-list

 
Hi Yannick,

You have some options here. You can set a priority with

https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-add-provider

with CSS.

If you want to just stick with drawing in C, connect your "draw" handler for 
the window. If you need a pixbuf you can use

https://developer.gnome.org/gdk3/stable/gdk3-Cairo-Interaction.html#gdk-cairo-set-source-pixbuf

to add a pixbuf to the background.

Also, the CSS GTK+ recognizes is a little different between versions. I am 
still using GTK3.18 and it understands a little different CSS string than 
GTK3.22. Something to keep in mind if you are using CSS strings in code.

Eric

/*
   gcc -Wall css1.c -o css1 `pkg-config --cflags --libs gtk+-3.0`
   Tested with GTK3.18 and GTK3.22 on Ubuntu16.04
*/
#include

static gboolean draw_window(GtkWidget *window, cairo_t *cr, gpointer user_data)
  {
//A green window.
cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
cairo_paint(cr);
return FALSE;
  }
int main(int argc, char *argv[])
  {
gtk_init (, );

GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "CSS");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

//Uncomment the following two line for drawing with cairo.
//gtk_widget_set_app_paintable(window, TRUE);
//g_signal_connect(window, "draw", G_CALLBACK(draw_window), NULL);

gtk_widget_show_all(window);

//Setup CSS for the program.
GError *css_error=NULL;
gint minor_version=gtk_get_minor_version();
gchar *css_string1=NULL;
//GTK CSS changed in 3.20.
if(minor_version>20)
  {
css_string1=g_strdup("window{background: blue;}");
  }
else
  {
css_string1=g_strdup("GtkWindow{background: blue;}");
  }
GtkCssProvider *provider=gtk_css_provider_new();
GdkDisplay *display=gdk_display_get_default();
GdkScreen *screen=gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen, 
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_css_provider_load_from_data(provider, css_string1, -1, _error);

if(css_error!=NULL)
  {
g_print("CSS loader error %s\n", css_error->message);
g_error_free(css_error);
  }
g_object_unref(provider);
if(css_string1!=NULL) g_free(css_string1);

gtk_main();

return 0;
  }  

 


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


Re: LuckyB.C.'s reply to GtkDrawingArea "width" and "height"

2018-03-17 Thread Eric Cashon via gtk-app-devel-list

 

 
Hi Roger,

I spend a bit of time drawing with cairo and GTK. If I get a drawing to work 
out then maybe merge it into a widget for reuse. Sort of a bunch of rough 
drafts in 

https://github.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/cairo_drawings

and then one back in Misc is some drawing area widgets. You are welcome to look 
at and use anything there to get started with your own drawings. There is even 
some cairo test drawings in 3d in the spring1.c file. Cairo is 2d but... give 
it a try. It might give you some drawing ideas.

Have fun drawing.

Eric

 



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


Re: A simple GtkSpinner is very costly in CPU cycles

2018-03-22 Thread Eric Cashon via gtk-app-devel-list

 

 
Hi Kian

For effeciency, use one of the default cursors.

https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html

If you want, you can try creating your own cursor with animation and using 
that. I got this working on my netbook which isn't a very high powered computer 
by todays standards and it works fine. I don't see it eating up cpu cycles. 
Give it a try and see if it works.

Eric


//gcc -Wall cursor1.c -o cursor1 `pkg-config gtk+-3.0 --cflags --libs`
//Tested on Ubuntu16.04, GTK3.18.

#include

static guint timeout_id=0;
static GdkCursor *cursors[4];

static void initialize_cursors(GtkWidget *window, GdkPixbuf *pixbufs[]);
static void start_cursor(GtkButton *button1, GtkWidget *da);
static void stop_cursor(GtkButton *button2, GtkWidget *da);
static gboolean update_cursor(GtkWidget *da);
static GdkPixbuf* draw_cursor(gint section);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Cursors");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

//Pixbufs for the different cursors.
GdkPixbuf *pixbuf1=draw_cursor(1);
GdkPixbuf *pixbuf2=draw_cursor(2);
GdkPixbuf *pixbuf3=draw_cursor(3);
GdkPixbuf *pixbuf4=draw_cursor(4);
GdkPixbuf *pixbufs[]={pixbuf1, pixbuf2, pixbuf3, pixbuf4};
g_signal_connect(window, "realize", G_CALLBACK(initialize_cursors), 
pixbufs);

GtkWidget *button1=gtk_button_new_with_label("Start Cursor");
gtk_widget_set_hexpand(button1, TRUE);

GtkWidget *button2=gtk_button_new_with_label("Stop Cursor");
gtk_widget_set_hexpand(button2, TRUE);

//Display the cursor in a drawing area.
GtkWidget *da=gtk_drawing_area_new();
gtk_widget_set_hexpand(da, TRUE);
gtk_widget_set_vexpand(da, TRUE);

g_signal_connect(button1, "clicked", G_CALLBACK(start_cursor), da);
g_signal_connect(button2, "clicked", G_CALLBACK(stop_cursor), da);
  
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), button2, 1, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), da, 0, 1, 2, 1);
  
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);

gtk_main();

g_object_unref(pixbuf1); 
g_object_unref(pixbuf2); 
g_object_unref(pixbuf3); 
g_object_unref(pixbuf4); 
g_object_unref(cursors[0]);
g_object_unref(cursors[1]);
g_object_unref(cursors[2]);
g_object_unref(cursors[3]);

return 0;
  }
static void initialize_cursors(GtkWidget *window, GdkPixbuf *pixbufs[])
  {
GdkWindow *win=gtk_widget_get_window(window);
GdkDisplay *display=gdk_window_get_display(win);
GdkCursor *cursor1=gdk_cursor_new_from_pixbuf(display, pixbufs[0], 1, 32);
GdkCursor *cursor2=gdk_cursor_new_from_pixbuf(display, pixbufs[1], 1, 32);
GdkCursor *cursor3=gdk_cursor_new_from_pixbuf(display, pixbufs[2], 1, 32);
GdkCursor *cursor4=gdk_cursor_new_from_pixbuf(display, pixbufs[3], 1, 32);
cursors[0]=cursor1;
cursors[1]=cursor2;
cursors[2]=cursor3;
cursors[3]=cursor4;
  }
static void start_cursor(GtkButton *button1, GtkWidget *da)
  {
if(timeout_id==0)
  {
timeout_id=g_timeout_add(300, (GSourceFunc)update_cursor, da);
  }
  }
static void stop_cursor(GtkButton *button2, GtkWidget *da)
  {
if(timeout_id!=0)
  {
g_source_remove(timeout_id);
timeout_id=0;
GdkWindow *win=gtk_widget_get_window(da);
gdk_window_set_cursor(win, NULL);
  }
  }
static gboolean update_cursor(GtkWidget *da)
  {
static gint i=0;

GdkWindow *win=gtk_widget_get_window(da);
gdk_window_set_cursor(win, cursors[i]);
if(i>2) i=0;
else i++;
 
return TRUE;
  }
static GdkPixbuf* draw_cursor(gint section)
  { 
//Create a surface to draw on. 
cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 
64, 64);
cairo_t *cr=cairo_create(surface);

//Paint the background transparent.
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.0);
cairo_paint(cr);

cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
cairo_rectangle(cr, 0.0, 0.0, 64.0, 64.0);
cairo_stroke(cr);

//Draw from center
cairo_translate(cr, 64.0/2.0, 64.0/2.0);

cairo_set_source_rgba(cr, 0.0, 1.0, 1.0, 1.0);
cairo_arc(cr, 0.0, 0.0, 20.0, 0.0, 2.0*G_PI);
cairo_fill(cr);

//Some pie wedges.
if(section==1)
  {
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_move_to(cr, 0.0, 0.0);
cairo_line_to(cr, 20.0, 0.0);
cairo_stroke_preserve(cr);
cairo_arc(cr, 0.0, 0.0, 20.0, 0.0, G_PI/2.0);
cairo_stroke_preserve(cr);
cairo_close_path(cr);
cairo_fill(cr);
  }
else if(section==2)
  {
cairo_set_source_rgb(cr, 

Re: Using Gtk.Builder to create a menubar.

2018-04-25 Thread Eric Cashon via gtk-app-devel-list

 

There is a basic setup for the Gtk Application in Python here

https://developer.gnome.org/gnome-devel-demos/stable/hello-world.py.html.en

For C you can check 

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Csamples/gtk_app1.c

which has a menu but doesn't use builder with an application. Maybe partial 
help.

Eric

___
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?

2018-09-27 Thread Eric Cashon via gtk-app-devel-list
 
You might be able to fiddle around with the newlines at the end of the buffer 
to get something to work with the textview.

Eric


//gcc -Wall text_space1.c -o text_space1 `pkg-config --cflags --libs gtk+-3.0`

#include 

static void value_changed(GtkAdjustment *v_adjust, GtkWidget **widgets)
  {
    static gint s_line=0;

    GtkTextIter iter, end_iter;
    GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(widgets[0]));
    GtkTextMark *mark=gtk_text_buffer_get_mark(buffer, "insert");
    gtk_text_buffer_get_iter_at_mark(buffer, , mark);
    gtk_text_buffer_get_end_iter(buffer, _iter);
    gint line=gtk_text_iter_get_line();
    //Check if cursor line is below a certain line in the buffer.
    gint below=gtk_text_buffer_get_line_count(buffer)-6;
    
    if(s_line!=line&>below)
  {
    g_print("Scroll Line\n");
    gint count=0;
    gint i=0;
    //Check for newlines.
    gtk_text_iter_backward_char(_iter);
    for(i=0;i<4;i++)
  {
    if('\n'==gtk_text_iter_get_char(_iter)) count++;
    if(!gtk_text_iter_backward_char(_iter))
  {
    g_print("Break\n");
    break;
  }
  }
    //Add newlines if needed.
    if(count>0)
  {
    GtkTextMark *mark2=gtk_text_buffer_create_mark(buffer, "back", 
, TRUE);
    gint newlines=4-count;
    gtk_text_buffer_get_end_iter(buffer, _iter);
    gchar string[newlines];
    for(i=0;ihttps://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: State actions and Glade

2018-10-05 Thread Eric Cashon via gtk-app-devel-list
 
I don't know if this is of any help. Another try at it. This one uses a 
GtkApplication. Setup an action on the button along with the standard "clicked" 
callback. A menu in there also. 

Eric


//gcc -Wall toolbar2.c -o toolbar2 `pkg-config --cflags --libs gtk+-3.0`

#include

static void quit_program(GSimpleAction *action, GVariant *parameter, gpointer 
user_data)
  {
    g_application_quit(G_APPLICATION(user_data));
  }
static void test1_callback(GSimpleAction *action, GVariant *parameter, gpointer 
user_data)
  {
    g_print("Test1 Callback\n");
  }
static void radio_test1(GtkWidget *button, GtkToolItem **radios)
  {
    gint i=0;

    for(i=0;i<3;i++)
 {
   if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
  {
    g_print("test1 radio%i\n", i+1);
  }
 }
  }
static void radio_test2(GSimpleAction *action, GVariant *parameter, GtkToolItem 
**radios)
  {
    gint i=0;

 for(i=0;i<3;i++)
  {
    if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
   {
 g_print("    test2 radio%i\n", i+1);
   }
  }
  }
static void app_startup(GtkApplication *app, gpointer user_data)
  {
    //Setup menu callbacks.
    GSimpleAction *test1=g_simple_action_new("test1", NULL);
    g_signal_connect(test1, "activate", G_CALLBACK(test1_callback), app);
    g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(test1));
    g_object_unref(test1);
    GSimpleAction *quit=g_simple_action_new("quit", NULL);
    g_signal_connect(quit, "activate", G_CALLBACK(quit_program), app);
    g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(quit));
    g_object_unref(quit);

    //Setup menu.
    GMenu *menu=g_menu_new();
    GMenu *submenu=g_menu_new();
    g_menu_append_submenu(menu, "Application", G_MENU_MODEL(submenu));
    GMenu *section=g_menu_new();
    g_menu_append_section(submenu, NULL, G_MENU_MODEL(section));
    g_menu_append(section, "Test1", "app.test1");
    g_menu_append(section, "Quit", "app.quit");
    g_object_unref(submenu);
    g_object_unref(section);

    gtk_application_set_menubar(GTK_APPLICATION(app), G_MENU_MODEL(menu));
    g_object_unref(menu);
  }
static void app_activate(GtkApplication *app, GtkToolItem **radios)
  {
    GtkWidget *window=gtk_application_window_new(GTK_APPLICATION(app));
    gtk_window_set_title(GTK_WINDOW(window), "Toolbar2");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 20);

    GtkToolItem *radio1=gtk_radio_tool_button_new(NULL);
    gtk_tool_item_set_expand(radio1, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio1), "radio1");
    GtkToolItem 
*radio2=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio2, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio2), "radio2");  
    GtkToolItem 
*radio3=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio3, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio3), "radio3"); 

    radios[0]=radio1;
    radios[1]=radio2;
    radios[2]=radio3;

    GtkWidget *toolbar=gtk_toolbar_new();
    gtk_widget_set_hexpand(toolbar, TRUE);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio1, 0);  
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio2, 1); 
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio3, 2);

    GtkWidget *button=gtk_button_new_with_label("Get Active Radio");
    gtk_widget_set_hexpand(button, TRUE);
    gtk_widget_set_vexpand(button, TRUE);
    g_signal_connect(button, "clicked", G_CALLBACK(radio_test1), radios); 
 
    GSimpleAction *radio_action1=g_simple_action_new("radio_test2", NULL);
    g_action_map_add_action(G_ACTION_MAP(app), (GAction*)radio_action1);
    g_signal_connect(radio_action1, "activate", G_CALLBACK(radio_test2), 
radios);
    gtk_actionable_set_action_name(GTK_ACTIONABLE(button), "app.radio_test2");  
  
    g_object_unref(radio_action1);

    GtkWidget *grid1=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
    gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
    gtk_grid_attach(GTK_GRID(grid1), toolbar, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid1), button, 0, 1, 1, 1);
   
    gtk_container_add(GTK_CONTAINER(window), grid1);

    gtk_widget_show_all(window);

    gtk_widget_grab_focus(button);
  }
int main(int argc, char **argv)
  {
    GtkApplication *app;
    int status;
    GtkToolItem *radios[3];
    app=gtk_application_new("app.example", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "startup", G_CALLBACK(app_startup), NULL);
    g_signal_connect(app, "activate", G_CALLBACK(app_activate), radios);
    status=g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);
    return(status);
  }
 

___
gtk-app-devel-list mailing list

Re: State actions and Glade

2018-10-04 Thread Eric Cashon via gtk-app-devel-list
 
"I am not sure what you mean"

I don't have a good answer for this. I see that GtkRadioToolButton is in the 
list of Known Implementations for GtkActionable but doesn't use the GAction 
interface directly.

https://developer.gnome.org/gtk3/stable/GtkActionable.html#gtk-actionable-set-detailed-action-name

It looks like this allows you to set up your action groups and callbacks with 
GIO but I don't have experience with it. Maybe someone has an example of 
setting up widgets to use action callbacks?

Eric

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


Re: State actions and Glade

2018-10-02 Thread Eric Cashon via gtk-app-devel-list
 
Hi Mitko,

The GtkToolbar doesn't implement the GAction interface so you are out of luck 
there. 

You can use gtk_toggle_tool_button_get_active() to get the state of one of the 
GtkRadioToolButton's in the toolbar.

Eric


//gcc -Wall toolbar1.c -o toolbar1 `pkg-config --cflags --libs gtk+-3.0`

#include

static void get_active_radio(GtkWidget *button, GtkToolItem **radios)
  {
    gint i=0;

    for(i=0;i<3;i++)
 {
   if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
  {
    g_print("radio%i\n", i+1);
  }
 }
  }
int main(int argc, char **argv)
  {
    gtk_init(, );

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Toolbar");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); 

    GtkToolItem *radio1=gtk_radio_tool_button_new(NULL);
    gtk_tool_item_set_expand(radio1, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio1), "radio1");
    GtkToolItem 
*radio2=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio2, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio2), "radio2");  
    GtkToolItem 
*radio3=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio3, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio3), "radio3"); 

    GtkWidget *toolbar=gtk_toolbar_new();
    gtk_widget_set_hexpand(toolbar, TRUE);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio1, 0);  
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio2, 1); 
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio3, 2); 

    GtkWidget *button=gtk_button_new_with_label("Get Active Radio");
    gtk_widget_set_hexpand(button, TRUE);
    gtk_widget_set_vexpand(button, TRUE);
    GtkToolItem *radios[]={radio1, radio2, radio3};
    g_signal_connect(button, "clicked", G_CALLBACK(get_active_radio), radios); 

    GtkWidget *grid1=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
    gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
    gtk_grid_attach(GTK_GRID(grid1), toolbar, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid1), button, 0, 1, 1, 1);

    gtk_container_add(GTK_CONTAINER(window), grid1);
    
    gtk_widget_show_all(window);

    gtk_widget_grab_focus(button);

    gtk_main();

    return 0;  
  }

___
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?

2018-09-25 Thread Eric Cashon via gtk-app-devel-list
 
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 
 
 

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

Re: How can I change the font of a text field using non-deprecated way?

2018-09-23 Thread Eric Cashon via gtk-app-devel-list
 
Hi Radomir,

The function gtk_widget_override_font() is deprecated but as far as I know it 
still works fine in GTK3. 

With the Pango font description and the textview you should be able to set 
everything up without getting any deprecated warnings. It doesn't set the 
textview widget itself to a particular font but you do have the Pango font 
description that you can use elsewhere if needed.

Eric

    
//gcc -Wall font_chooser1.c -o font_chooser1 `pkg-config --cflags --libs 
gtk+-3.0`

#include 

static void show_font_chooser(GtkWidget *button, gpointer **user_data)
  {
    static gint i=1;
    GtkWidget *chooser=gtk_font_chooser_dialog_new("Font Chooser", 
GTK_WINDOW(user_data[0]));
    gint result=gtk_dialog_run(GTK_DIALOG(chooser));

    if(result==GTK_RESPONSE_OK)
  {   
    PangoFontDescription 
*desc=gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(chooser));
    GtkTextBuffer 
*buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(user_data[1]));
    gchar *tag_name=g_strdup_printf("font-tag%i", i);
    GtkTextTag *font_tag=gtk_text_buffer_create_tag(buffer, tag_name, 
"font-desc", desc, NULL);
    g_ptr_array_add((GPtrArray*)user_data[2], (gpointer)font_tag);
    i++;
    g_free(tag_name);
    pango_font_description_free(desc);
  }
    
    gtk_widget_destroy(chooser);
  }
static void insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar 
*text, gint len, GPtrArray *tags)
  {
    GtkTextIter *start=gtk_text_iter_copy(location);
    gtk_text_iter_backward_chars(start, len);
    //Get the last tag added to the tag array.
    GtkTextTag *font_tag=GTK_TEXT_TAG(g_ptr_array_index(tags, ((tags->len)-1)));
    gtk_text_buffer_apply_tag(textbuffer, font_tag, start, location);
    gtk_text_iter_free(start);
  }
int main(int argc, char *argv[])
  {
    gtk_init(, );

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Font Chooser");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 20);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *textview=gtk_text_view_new();
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR);
    gtk_widget_set_hexpand(textview, TRUE);
    gtk_widget_set_vexpand(textview, TRUE);

    PangoContext *context=gtk_widget_get_pango_context(textview);
    PangoFontDescription *desc=pango_context_get_font_description(context);

    //For saving the tag pointers.
    GPtrArray *tags=g_ptr_array_new();

    GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
    GtkTextTag *font_tag=gtk_text_buffer_create_tag(buffer, "font-tag", 
"font-desc", desc, NULL);
    g_ptr_array_add(tags, (gpointer)font_tag);
    g_signal_connect_after(buffer, "insert-text", G_CALLBACK(insert_text), 
tags); 

    GtkWidget *button=gtk_button_new_with_label("FontChooser");
    gtk_widget_set_hexpand(button, TRUE);
    gpointer user_data[]={window, textview, tags};
    g_signal_connect(button, "clicked", G_CALLBACK(show_font_chooser), 
user_data);

    GtkWidget *grid=gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), textview, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), button, 0, 1, 1, 1);

    gtk_container_add(GTK_CONTAINER(window), grid);

    gtk_widget_show_all(window);
    
    gtk_main();

    return 0;
  }

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

Re: Problem with sizes of pixbuf in left gutter

2018-12-26 Thread Eric Cashon via gtk-app-devel-list
 
It looks like the pixbuf sizes rendered are going to be tied to the size of the 
font in the sourceview. If the pixbufs are bigger than the gutter has space for 
then they get clipped. I don't know how the sourceview works very well myself. 
Gave it a try. Maybe it will help.
Eric
//gcc -Wall source_view2.c -o source_view2 `pkg-config --cflags --libs gtk+-3.0 
gtksourceview-3.0`
//Tested with GTK3.18 and Ubuntu16.04

#include
#include

static GdkPixbuf* draw_pixbuf1();
static GdkPixbuf* draw_pixbuf2();
static void redraw_gutter(GtkWidget *button, gpointer renderer);
static void check_renderer1(GtkSourceGutterRenderer *renderer, GtkTextIter 
*start, GtkTextIter *end, GtkSourceGutterRendererState state, GdkPixbuf 
*pixbufs[2]);

int main (int argc, char *argv[])
  {
    gtk_init(, );

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Source View");
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    
    //Highlight for the C language.
    GtkSourceLanguageManager *lm=gtk_source_language_manager_get_default();
    GtkSourceLanguage *language=gtk_source_language_manager_get_language(lm, 
"c");
    GtkSourceBuffer *s_buffer=gtk_source_buffer_new_with_language(language);
    gtk_source_buffer_set_language(s_buffer, language);
    gtk_source_buffer_set_highlight_syntax(s_buffer, TRUE);

    GtkWidget *source_view=gtk_source_view_new_with_buffer(s_buffer);
    gtk_source_view_set_show_line_numbers(GTK_SOURCE_VIEW(source_view), TRUE);
    gtk_source_view_set_show_line_marks(GTK_SOURCE_VIEW(source_view), TRUE);
    gtk_source_view_set_highlight_current_line(GTK_SOURCE_VIEW(source_view), 
TRUE);
    gtk_widget_set_vexpand(source_view, TRUE);
    gtk_widget_set_hexpand(source_view, TRUE);

    //Get some pixbufs to test.
    GdkPixbuf *pixbuf1=draw_pixbuf1();
    GdkPixbuf *pixbuf2=draw_pixbuf2();
    GdkPixbuf *pixbufs[2]={pixbuf1, pixbuf2};

    //Get the left gutter.
    GtkSourceGutter 
*gutter=gtk_source_view_get_gutter(GTK_SOURCE_VIEW(source_view), 
GTK_TEXT_WINDOW_LEFT);

    GtkSourceGutterRenderer *renderer1=gtk_source_gutter_renderer_pixbuf_new();
    g_signal_connect(renderer1, "query-data", G_CALLBACK(check_renderer1), 
pixbufs);
    gtk_source_gutter_renderer_set_alignment_mode(renderer1, 
GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST);
    gtk_source_gutter_renderer_set_size(renderer1, 32);
    gtk_source_gutter_insert(gutter, GTK_SOURCE_GUTTER_RENDERER(renderer1), 0);

    //Create a mark on the first line.
    GtkTextIter start;
    gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(s_buffer), );
    gtk_source_buffer_create_source_mark(s_buffer, "mark_name", 
"mark_category", );
    
    //Color the first line green.
    GdkRGBA bg;
    gdk_rgba_parse(, "#00FF00");
    GtkSourceMarkAttributes *att=gtk_source_mark_attributes_new();
    gtk_source_mark_attributes_set_background(att, );
    gtk_source_view_set_mark_attributes(GTK_SOURCE_VIEW(source_view), 
"mark_category", att, 1);

    gtk_text_buffer_set_text(GTK_TEXT_BUFFER(s_buffer), "//gcc -Wall hello1.c 
-o hello1\n#include\n\nint main()\n  {\n    printf(\"Hello 
World\\n\");\n    return 0;\n  }\n", -1);

    GtkWidget *button=gtk_button_new_with_label("Redraw Gutter");
    gtk_widget_set_hexpand(button, TRUE);
    g_signal_connect(button, "clicked", G_CALLBACK(redraw_gutter), renderer1);

    GtkWidget *grid=gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), source_view, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), button, 0, 1, 1, 1);
    
    gtk_container_add(GTK_CONTAINER(window), grid);

 //Setup CSS for the program.
    GError *css_error=NULL;
    gint minor_version=gtk_get_minor_version();
    gchar *css_string1=NULL;
    //GTK CSS changed in 3.20.
    if(minor_version>20)
  {
    css_string1=g_strdup("textview{background-color: blue; color: yellow; 
font-size: 26px;}");
  }
    else
  {
    //On GTK3.18 background works and background-color doesn't.
    css_string1=g_strdup("GtkTextView{background: blue; color: yellow; 
font-size: 26px;}");
  }
    GtkCssProvider *provider=gtk_css_provider_new();
    GdkDisplay *display=gdk_display_get_default();
    GdkScreen *screen=gdk_display_get_default_screen(display);
    gtk_style_context_add_provider_for_screen(screen, 
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    gtk_css_provider_load_from_data(provider, css_string1, -1, _error);
    //Print out the provider for some help.
    if(css_error==NULL)
  {
    gchar *string=gtk_css_provider_to_string(provider);
    g_print("%s\n", string);
    g_free(string);
  }
    else
  {
    g_print("CSS loader error %s\n", css_error->message);
    g_error_free(css_error);
  }
    g_object_unref(provider);
    g_free(css_string1);

    

Re: PDF page not rendering properly if the page is changed

2018-11-28 Thread Eric Cashon via gtk-app-devel-list
 

Didn't get an attachment either. Try something like the following and see if it 
makes any difference.

...
    GtkWidget *da=gtk_drawing_area_new();
    //Request a large drawing area.
    gtk_widget_set_size_request(da, 1, 1);

    GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
    gtk_widget_set_hexpand(scroll, TRUE);
    gtk_widget_set_vexpand(scroll, TRUE);
    gtk_container_add(GTK_CONTAINER(scroll), da);
...

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

  1   2   >