RE: displaying a number on screen
Try retreiving the cairo context for the widget you want to draw in and try this: /* Create the default Layout */ layout = pango_cairo_create_layout(cr); /* Atach the font descriptor */ font_description = pango_font_description_new(); /* Setup Fonts and color and other layout attributes*/ pango_font_description_set_family(font_description,"Helvetica"); cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 1.0); pango_font_description_set_absolute_size(font_description, 0.28 * PANGO_SCALE); pango_font_description_set_weight(font_description,PANGO_WEIGHT_BOLD); pango_layout_set_font_description(layout,font_description); gchar * l1 = g_strdup_printf("%s-%d",label->aid,label->nid); cairo_move_to(cr, 0.05 * xmultip, 0.00 * ymultip); pango_layout_set_text(layout,l1,-1); pango_cairo_show_layout(cr,layout); You can also use pango_layout_set_markup(layout,l1,-1); using Pango markup to change text style. EMAILING FOR THE GREATER GOOD Join me > Date: Sat, 27 Mar 2010 23:58:15 +0530 > Subject: displaying a number on screen > From: rao.nisc...@gmail.com > To: gtk-app-devel-list@gnome.org > > Hi, > > I am sorry if this is not the right mailing list. > > For given x and y co-ordinates is it possible to display a particular number > at that position? or in other words, is it possible to "paint" a number or > character on the screen at a given point? > > Thanks in advance. > > -- > regards, > Nischal E Rao > blogs.sun.com/nischal > > Join RVCE OSUM at http://osum.sun.com/group/rvceosum > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_main_context_push_thread_default() & g_ io_*()
In the documentation for g_main_context_push_thread_default(), the following sentence appears: "This will cause certain asynchronous operations (such as most gio-based I/O) which are started in this thread to run under context and deliver their results to its main loop, rather than running under the global default context in the main thread." This makes me think my experiment program below would work, yet on ubuntu 9.10 at least, it does not. Perhaps g_io_channel_unix_new() is not in the "most" group referred to above? Or maybe I'm doing this wrong. Thanks for any input. #include #include #include GMainContext *thread1_context, *thread2_context; GMainLoop *main_loop1, *main_loop2; gboolean idle_callback(gpointer data) { g_print("idle_callback() %d\n", (pid_t) syscall (SYS_gettid)); return FALSE; } gboolean input_callback(GIOChannel *source, GIOCondition condition, gpointer data) { GSource *idle_source; unsigned char buffer[16]; g_print("input_callback() %d\n", (pid_t) syscall (SYS_gettid)); if(read(0, buffer, 16) < 1) return FALSE; idle_source = g_idle_source_new(); g_source_set_callback(idle_source, idle_callback, NULL, NULL); g_source_attach(idle_source, thread1_context); return TRUE; } gpointer thread2_entry(gpointer data) { GIOChannel *channel; g_print("thread2_entry() %d\n", (pid_t) syscall (SYS_gettid)); main_loop2 = g_main_loop_new(thread2_context, FALSE); g_main_context_push_thread_default(thread2_context); channel = g_io_channel_unix_new(0); g_io_add_watch(channel, G_IO_IN, input_callback, NULL); g_main_loop_run(main_loop2); } int main(int argc, char **argv) { g_thread_init(NULL); thread1_context = g_main_context_default(); thread2_context = g_main_context_new(); main_loop1 = g_main_loop_new(thread1_context, FALSE); g_thread_create(thread2_entry, NULL, FALSE, NULL); g_main_loop_run(main_loop1); return 0; } Here is an example session: $ ./a.out thread2_entry() 24928 f input_callback() 24927 idle_callback() 24927 e input_callback() 24927 idle_callback() 24927 k input_callback() 24927 idle_callback() 24927 ^C What I was expecting is for input_callback() to run in thread 24928 instead of 24927. -- www.thomasstover.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: g_main_context_push_thread_default() & g_io_*()
On Mon, Mar 29, 2010 at 6:58 PM, Thomas Stover wrote: > In the documentation for g_main_context_push_thread_default(), the > following sentence appears: > > "This will cause certain asynchronous operations (such as most gio-based > I/O) which are started in this thread to run under context and deliver > their results to its main loop, rather than running under the global > default context in the main thread." > > This makes me think my experiment program below would work, yet on ubuntu > 9.10 at least, it does not. Perhaps g_io_channel_unix_new() is not in the > "most" group referred to above? Or maybe I'm doing this wrong. Thanks for > any input. GIO refers to the GIO library (http://library.gnome.org/devel/gio/stable/), not to the g_io_* family of functions. Probably worth filing a bug to make this clearer in the documentation. -A. Walton > > > #include > #include > #include > > GMainContext *thread1_context, *thread2_context; > GMainLoop *main_loop1, *main_loop2; > > gboolean idle_callback(gpointer data) > { > g_print("idle_callback() %d\n", (pid_t) syscall (SYS_gettid)); > return FALSE; > } > > gboolean input_callback(GIOChannel *source, > GIOCondition condition, > gpointer data) > { > GSource *idle_source; > unsigned char buffer[16]; > g_print("input_callback() %d\n", (pid_t) syscall (SYS_gettid)); > > if(read(0, buffer, 16) < 1) > return FALSE; > > idle_source = g_idle_source_new(); > g_source_set_callback(idle_source, idle_callback, NULL, NULL); > g_source_attach(idle_source, thread1_context); > > return TRUE; > } > > gpointer thread2_entry(gpointer data) > { > GIOChannel *channel; > g_print("thread2_entry() %d\n", (pid_t) syscall (SYS_gettid)); > > main_loop2 = g_main_loop_new(thread2_context, FALSE); > > g_main_context_push_thread_default(thread2_context); > > channel = g_io_channel_unix_new(0); > g_io_add_watch(channel, G_IO_IN, input_callback, NULL); > > g_main_loop_run(main_loop2); > } > > int main(int argc, char **argv) > { > g_thread_init(NULL); > > thread1_context = g_main_context_default(); > thread2_context = g_main_context_new(); > > main_loop1 = g_main_loop_new(thread1_context, FALSE); > > g_thread_create(thread2_entry, NULL, FALSE, NULL); > > g_main_loop_run(main_loop1); > return 0; > } > > > Here is an example session: > > $ ./a.out > thread2_entry() 24928 > f > input_callback() 24927 > idle_callback() 24927 > e > input_callback() 24927 > idle_callback() 24927 > k > input_callback() 24927 > idle_callback() 24927 > ^C > > What I was expecting is for input_callback() to run in thread 24928 > instead of 24927. > > -- > www.thomasstover.com > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list