Re: How to set background/foreground on button, entry, or label?

2004-03-04 Thread Tony Denault
On Thu, 4 Mar 2004, Owen Taylor wrote:

 On Wed, 2004-03-03 at 20:39, Tony Denault wrote:
  Hi All,
 
  After doing some research and hacking, I wrote some code to set the
  foreground / backgroud color of a button, entry,  label. This is still a
  confusing part of GTK 2.x., an internet search on this question resulted
  in lots of partial answers, vague description on how it should work,
  but no clear answer that work across all widgets.

 Have you seen:

  http://ometer.com/gtk-colors.html

Yes, it was one of the references I came acoss while researching this
subject. It indicated using gtk_widget_modify_fg/bg(), but I only
got the fg to change for buttonlabel. Could not get the entry text, or
background colors for label, entry, button to change.

As I stated before, if there is a better technique for gtk 2.0, please
modify the code and post.

Thanks,

Tony

/---\
| Tony Denault | Email: [EMAIL PROTECTED] |
| Institute for Astronomy  |  Phone: (808) 932-2378 |
| 640 North Aohoku Place   |Fax: (808) 933-0737 |
| Hilo, Hawaii 96720   ||
\---/


___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list


How to set background/foreground on button, entry, or label?

2004-03-03 Thread Tony Denault
Hi All,

After doing some research and hacking, I wrote some code to set the
foreground / backgroud color of a button, entry,  label. This is still a
confusing part of GTK 2.x., an internet search on this question resulted
in lots of partial answers, vague description on how it should work,
but no clear answer that work across all widgets.

I am posting this code to:
  1. Provide a working example on how I did it.
  2. Maybe the experts can improve on it, or show better methods.
  3. Maybe it (or an improved version) can be put in the faq.

There are still some problems:

1. The Entry widget's cursor doesn'tt change with the 'Text' color. In
   my example, the bg color  cursor is black = invisible cursor!

2. Different widgets use different properites in the style. I still
   don't understand the numberous style-fd, bg, light, dark, mid, text, base.

3. Tried using gtk_widget_modify_fg()/gtk_widget_modify_bg(), but
   never could get them to work on all widgets. So I used
   MyStyleSetItemColor() - a function from my 1.2x code.

code is below my .signature.

Tony

/---\
| Tony Denault | Email: [EMAIL PROTECTED] |
| Institute for Astronomy  |  Phone: (808) 932-2378 |
| 640 North Aohoku Place   |Fax: (808) 933-0737 |
| Hilo, Hawaii 96720   ||
\---/

#include gtk/gtk.h

void MyStyleSetItemColor( GdkColor color, char item, GtkStyle * style);

int main (int argc, char *argv[])
{
   GtkWidget * base,
 * table,
 * entry,
 * button,
 * label,
 * ebox;

   GtkStyle * style_default,
* style_entry_YB,
* style_button_YB;
   GdkColor black = { 0, 0, 0, 0 } ,   // should use gdk_colormap_alloc_color()
yellow = {0, 65535, 65535, 0 };

   gtk_init(argc, argv);

   /* define some styles to apply to my widgets */
   style_default = gtk_widget_get_default_style();

   /* this style works for entry */
   style_entry_YB  = gtk_style_copy( style_default );
   MyStyleSetItemColor( black,   's', style_entry_YB);  // s=base (entry,bg)
   MyStyleSetItemColor( yellow,  't', style_entry_YB ); // t=Text (entry,fg)

   /* this style works for buttons */
   style_button_YB  = gtk_style_copy( style_default );
   MyStyleSetItemColor( black,  'b', style_button_YB );  // b=bg (button,bg)
   MyStyleSetItemColor( yellow, 'f', style_button_YB ); // f=fg (button,fg)

   base = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   table = gtk_table_new( 1, 5, TRUE );
   gtk_container_add (GTK_CONTAINER (base), table);

   /* button - using style_button_YB */
   button = gtk_button_new_with_label( button);
   gtk_widget_set_style(GTK_BIN (button)-child, style_button_YB);
   gtk_widget_set_style(button, style_button_YB);
   gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 1, 0, 1);
   gtk_widget_show(button);

   /* entry - using style_entry_YB */
   entry = gtk_entry_new( );
   gtk_entry_set_text( GTK_ENTRY(entry), Entry);
   gtk_entry_set_width_chars( GTK_ENTRY(entry), 5);
   gtk_table_attach_defaults (GTK_TABLE(table), entry, 2, 3, 0, 1);
   gtk_widget_set_style(entry, style_entry_YB);
   gtk_widget_show(entry);

   /* label w/ event box for backgroud color */
   ebox = gtk_event_box_new();
   label = gtk_label_new(label );
   gtk_container_add( GTK_CONTAINER(ebox), label );
   gtk_widget_set_style( label, style_button_YB);   // change label fg color
   gtk_widget_set_style( ebox, style_button_YB);// bg color provided by ebox
   gtk_table_attach_defaults (GTK_TABLE(table), ebox, 4, 5, 0, 1);
   gtk_widget_show(label);
   gtk_widget_show(ebox);

   gtk_widget_show(table);
   gtk_widget_show( base );
   gtk_main ();
   return 0;
}

/*---
**  MyStyleSetItemColor() - Helper function to change a style.
**---
*/
void MyStyleSetItemColor(
   GdkColor   color,/* The allocated color to be added to the style */
   char   item, /* the item to which the color is to be applied */
/* 'f' = foreground; 'b' = background; */
/* 'l' = light;  'd' = dark; */
/* 'm' = mid;'t' = text; */
/* 's' = base.  */
   GtkStyle * style /* The old style - changes made to a copy */
)
{
   int i;
   switch ( item )
   {
  case 'f':
  case 'F':
 for ( i = 0; i  5; i++ )
style-fg[i] = color;
 break;
  case 'b':
  case 'B':
 for ( i = 0; i  5; i++ )
style-bg[i] = color;
 break;
  case 'l':
  case 'L':
 for ( i = 0; i  5; i++ )
style-light[i] = color;
 break;
  case 'd

RE: Slow Rendering?

2003-11-20 Thread Tony Denault
On Thu, 20 Nov 2003, Dennie, Brooke wrote:

  The answer to your question about speed issues on remote displays is
  that you could try to use X11 core fonts by setting the environment
  variable GDK_ENABLE_XFT to 0. This would disable antialiased fonts
  which are likely causing your speed issues. Does your X-Server
  implement the RENDER extension?
 
 Any other ideas? Thanks again!


You might want to experiment with the types of fonts you used in your GTK
app.

I am also getting into using PANGO, as our new project will use gtk 2.2x.
We initially started using 1.2 API, now converting to pure
2.2 API. I recently switched from using gdk_font_load() to the PANGO
stuff. My app is just using a large drawing area 1200x600 pixels. I am
just filling the area with text display with various colors. I have a GTK
timer that grab data from shared memory and refreshes the drawing area.

When using gdk_font_load (-*-fixed-*-*-*-*-14-*-*-*-*-*-*-*),
my timer function runs in 0.27 ms (fixed is a 8x17 font).
This .27 ms is very steady.

My initial test using pango caused the timer function to
take 270 ms (over 1000x slower). After picking up the maillist thread, I
decide to experiment using different font as I though PANGO might
be rendering everything and sending images to the X11 client windows.
Here is a table of different fonts using Pango;

Font   Pango PangoGDK_ENABLE_XFT=0   size
--
San 8  270   250 7x15
Serif 10   360   362 8x19
miscFixed  9   6.8   6.7 6x14
miscFixed 10   6.9   6.8 9x15
console8x166.9   6.8 8x16
Courier 10 372   372 9x18
Fixed  6.8   6.9 9x15
LucidaTyperwriter 9361   361 8x17

Also note the Pango time varies widely, for example the
360 ms can jump about upto 700ms. I wrote the 'best' time
for the table.

GDK_ENABLE_XFT=0 help a little (sometimes).
For me picking a better font will help. 6.8 ms is OK, but I would
like better - This is still 25x slower that gdk_font_load().

My GTK app runs on a linux box running Fedora Core release 0.94 (Severn).
I am displaying on a XP computer running X-Win32 X11 server.

Running the app directly on the linux console improves things somewhat
(ie: 6.8ms - 4.8ms).

Tony

/---\
| Tony Denault | Email: [EMAIL PROTECTED] |
| Institute for Astronomy  |  Phone: (808) 932-2378 |
| 640 North Aohoku Place   |Fax: (808) 933-0737 |
| Hilo, Hawaii 96720   ||
\---/

___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: theme question

2003-05-29 Thread Tony Denault

On Wed, 28 May 2003, Owen Taylor wrote:

 On Tue, 2003-05-27 at 22:50, Tony Denault wrote:
  I'm using gtk on solaris/sparc, but can't themes to work.
 
 The way that most people would select a theme is, to put in their
 ~/.gtkrc-2.0

  gtk-theme-name = Metal


Tried this - no luck.

 If GTK+ was installed some place other than /usr/local, the
 gtk-engine's README file explains what to do:


I am just using GTK (no gnome) on a sparc/Solaris8 system.
I install everything (atk, glib, pango, gtk, gtk-engines) into their
default locations:
./configure
make
make install

Then I created a ~/.gtkrc-2.0.
Still this didn't work.


After some poking around, I found that my directory /usr/local/lib/gtk-2.0
contain the following:
   /usr/local/lib/gtk-2.0/
|--2.0.0/
 |-engines
 |-immodules
 |-loaders
|--2.2.0/
 |-immodules
 |-loaders

After I did this, gtk found my themes:

   cd /usr/local/lib/gtk-2.0/2.2.0
   ln -s ../2.0.0/engines

So it look like the gtk-engine installed itself in the 2.0.0.

GTK 2.0 and 2.2 confusion. In many instances 2.2 really acts like 2.0.
I ran across a similiar problem in the pkg-config utility too:
   'pkg-config --cflags gtk+-2.2' doesn't work but I can
   use 'pkg-config --cflags gtk+-2.0' to compile my 2.2 apps.

Tony

/---\
| Tony Denault | Email: [EMAIL PROTECTED] |
| Institute for Astronomy  |  Phone: (808) 932-2378 |
| 640 North Aohoku Place   |Fax: (808) 933-0737 |
| Hilo, Hawaii 96720   ||
\---/


___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list


theme question

2003-05-27 Thread Tony Denault

I'm using gtk on solaris/sparc, but can't themes to work.

I installed gtk-engines-2.2.0 using the standard way:
./configure
make
make install

Copy a .gtkrc file:
   cp /usr/local/share/themes/Metal/gtk-2.0/gtkrc  ~/.gtkrc-2.0

When I start a gtk2.2 program I get:
 Gtk-WARNING **: Unable to locate theme engine in module_path: metal,

So I tried adding module_path in my .gtkrc-2.0 file, but I got:
   Gtk-WARNING **: module_path directive is now ignored

Why can't my 2.0 theme load? I can find any instruction to indicate
what I should do. Help..

Thanks,

Tony

/---\
| Tony Denault | Email: [EMAIL PROTECTED] |
| Institute for Astronomy  |  Phone: (808) 932-2378 |
| 640 North Aohoku Place   |Fax: (808) 933-0737 |
| Hilo, Hawaii 96720   ||
\---/

___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: DrawingArea and Text display.

2003-03-11 Thread Tony Denault

On Thu, 6 Mar 2003, Tony Denault wrote:

 Trying to convert some 1.2 gtk code to 2.0. Trying not to use any
 deprecated functions. I used the DrawingArea to display my own
 text using different font  colors. However documentation is very scarce.

Thanks to all who replied. I'll summaried what I learn for the mailing
list:

1. Here is a simple example that illustrates some text rendering in
   a drawing area:

   Note I pre-allocate some colors and GC for my application, ie:

  gdk_colormap_alloc_color( CM.colormap, CM.colors[i], FALSE, TRUE );
  Nor_gc = gdk_gc_new(base_window-window);

/*
**  draw_view_2() - Example showing to render text in drawing area
**
*/
void draw_view_2( GtkWidget *da, int da_wid, int da_hgt )
{
   PangoFontDescription * font;
   PangoContext *context;
   PangoLayout  *layout;

   // obtain pango font object
   font =  pango_font_description_from_string (Courier,Medium 8);

   // obtain pango layout object
   context = gtk_widget_create_pango_context (da);
   layout  = pango_layout_new (context);
   g_object_unref (context);

   // Draw some text
   pango_layout_set_font_description (layout, font);
   pango_layout_set_text (layout, Some UTF-8 text, -1);
   gdk_gc_set_foreground( Nor_gc, CM.colors[CM_YELLOW] );
   gdk_draw_layout (da-window, Nor_gc, 50, 50, layout);

   // Draw 2nd line
   pango_layout_set_text (layout, This is more text, -1);
   gdk_gc_set_foreground( Nor_gc, CM.colors[CM_GREEN] );
   gdk_draw_layout (da-window, Nor_gc, 50, 100, layout);

   // Overwrite part of 2nd line.
   pango_layout_set_text (layout, overwrite, -1);
   gdk_draw_layout_with_colors (da-window, Nor_gc, 50, 100, layout,
  CM.colors[CM_RED], CM.colors[CM_BLACK] );

   // 3rd line - gray back ground, Green Text.
   pango_layout_set_text (layout, overwrite Part II, -1);
   gdk_draw_layout_with_colors (da-window, Nor_gc, 50, 150, layout,
  CM.colors[CM_GREEN], CM.colors[CM_GRAY] );

   pango_layout_set_text (layout, The End, -1);
   gdk_draw_layout (da-window, Nor_gc, 50, 200, layout);

   g_object_unref (layout);
   g_object_unref (font);

}

2. Since my application refreshes my drawing area frequently and I have
   a lot of text, I actually allocate fonts and a layout. Then used
   a printf style function to put text on my drawing area. Here is the
   code:

 2.1. Initialize some colors and a GC for my application:

gdk_colormap_alloc_color( CM.colormap, CM.colors[i], FALSE, TRUE );
Nor_gc = gdk_gc_new(base_window-window);

 2.2. Initalize a font and layout for my application. I save this
  information in a global variable.

   struct app_font_info_t Fixed_font;
   app_font_init( Fixed_font, base_window, Courier,Medium 5)

   where:

 struct app_font_info_t// font, pango layout info to  render
 text to drawing area
 {
PangoFontDescription * font;// font reference
PangoLayout  * layout;  // Pango reference
int  wid;
int  hgt;
int  ascent;
int  descent;
 };



  /*---
  **  app_font_init() - fill af with a pango Font and Layout  reference. Also
  **initializes af with some font information (wid, hgt,etc).
  **---
  */
  int app_font_init(
 struct app_font_info_t *af,  // O: application font  layout  information.
 GtkWidget * gtk_widget,  // I: need to reference a widget.  ie: 
base_window
 char * font_name // I: name of pango font to  allocate.
  )
  {
 PangoContext *context;
 PangoFontMetrics *metrics;

 if( (af-font = pango_font_description_from_string (Courier,Medium 5)) == 
NULL )
 {
   printf(app_font_initialize()-pango_font_description_from_string() 
error!\n);
return ERR_NOT_AVAILABLE;
 }

 if( (context = gtk_widget_create_pango_context (gtk_widget)) == NULL )
 {
printf(app_font_initialize()-gtk_widget_create_pango_context() 
error!\n);
return ERR_NOT_AVAILABLE;
 }

 if( (af-layout = pango_layout_new ( context )) == NULL )
 {
printf(app_font_initialize()-pango_layout_new() error!\n);
return ERR_NOT_AVAILABLE;
 }

 pango_layout_set_font_description (af-layout, af-font);

 // determine width  height of font.
 metrics = pango_context_get_metrics (context, af-font,
pango_context_get_language(context));

 af-wid = PANGO_PIXELS(  
pango_font_metrics_get_approximate_digit_width(metrics) );
 af-ascent = PANGO_PIXELS

DrawingArea and Text display.

2003-03-06 Thread Tony Denault

Hi,

Trying to convert some 1.2 gtk code to 2.0. Trying not to use any
deprecated functions. I used the DrawingArea to display my own
text using different font  colors. However documentation is very scarce.

Could some explain the new way for something like this:

   Fixed_font = gdk_font_load (fixed);
   GC = gdk_gc_new(base_window-window);

   sprintf( buf, Temperature is %6.2f K , temperature_value );
   gdk_draw_text( da-window, Fixed_font, GC, x, y, buf,  strlen(buf) );

So far:

   Fixed_font = pango_font_description_from_string (Fixed);
   GC = gdk_gc_new(base_window-window);

   stuck on how to display string in Drawing area using pango

Thanks,

Tony

/---\
| Tony Denault | Email: [EMAIL PROTECTED] |
| Institute for Astronomy  |  Phone: (808) 932-2378 |
| 640 North Aohoku Place   |Fax: (808) 933-0737 |
| Hilo, Hawaii 96720   ||
\---/

___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list


GTK 2.0 reference

2002-10-22 Thread Tony Denault

Can anyone recommend a good GTK 2.0 book? I have some 1.2 reference, but
will make the move to 2.0 soon.

Thanks,

Tony

/---\
| Tony Denault | Email: [EMAIL PROTECTED] |
| Institute for Astronomy  |  Phone: (808) 932-2378 |
| 640 North Aohoku Place   |Fax: (808) 933-0737 |
| Hilo, Hawaii 96720   ||
\---/

___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list



text widget question.

2002-06-10 Thread Tony Denault

Hello All, Need some text widget advice.

I writing a GUI and would like to include a 'command line window' - A
terminal-like interface to take keyboard input and provide text output
(log style output).

Looking for a simpler text widget that GtkText.

I am currently using a GtkText for output and an GtkEntry for input. And
this almost works, but getting the focus into the Entry is a pain. I would
like it to be a single window. N-1 lines for a scrolling log, and the last
line for keyboard input. And I will add line editing, and history (like
tcsh).

Some question:

1. Easy solution: Can take GtkText input (key_press_event), and just
send these keys to the GtkEntry (as if the user typed them)?

2.Is there a better widget to used. I like to used it in a curses-like fashion ie:

  wmove(wn,11,11); wprintw(wn, %-3d, spl-pr.numarray);
  wmove(wn,12,11); wprintw(wn, %-3d, spl-pr.ndr);
  wmove(wn,13,11); wprintw(wn, %d, spl-pr.cbmode);

With color too. ( I know about drawing_areas, but I would like
the window to support the X mouse copy function (Right mouse key)).

3. Or can I just fork a color-tty task in a GTK window, that act like an
embedded color terminal window. Then I can take my old curses-program have
it part of my GUI.

Would appreciate any advice  thanks,

Tony


/-\
| Tony Denault| Internet: [EMAIL PROTECTED] |
| NASA IRTF, Institute of Astronomy   | Phone: (808) 974-4206 |
| 1175 Manono St., Bldg 393   |   Fax: (808) 974-4207 |
| Hilo, Hawaii 96720  |   |
\-/

___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list



can't install gtk2.0 on solaris 2.8

2002-03-25 Thread Tony Denault


Hello,

Having problems installing on solaris 2.8/gcc2.95.3.
I have gtk 1.2.10 install on my computer, and wanted to start using gtk 2.0.
The installation didn't work.

First, I installed all the dependencies libs: pkg-config, TIFF, libpng,
JPEG. This was OK.

But once I got to the GTK specific stuff I always got the following
error: don't know how to make target 'all-local' . This is the atk output,
but it was the same for pango, glib. But the include and .a files were
installed to I just continued.

rm -fr .libs/libtestrelation.la .libs/libtestrelation.*  .libs/libtestrelation.*
ar cru .libs/libtestrelation.al testrelation.lo
ranlib .libs/libtestrelation.al
creating libtestrelation.la
(cd .libs  rm -f libtestrelation.la  ln -s ../libtestrelation.la
libtestrelation.la)
Making install in docs
make: Fatal error: Don't know how to make target `all-local'
Current working directory /home/denault/gtk_2.0/atk-1.0.0/docs
*** Error code 1
make: Fatal error: Command failed for target `install-recursive'

But then, gtk failed to configure:

checking for pkg-config... /usr/local/bin/pkg-config
checking for glib-2.0 = 2.0.0 atk = 1.0.0 pango = 1.0.0... sh:  gnome-config: not 
found
sh: gnome-config: not found
Package atk was not found in the pkg-config search path.
Perhaps you should add the directory containing `atk.pc'
to the PKG_CONFIG_PATH environment variable
No package 'atk' found

After some poking around, I found atk.pc and pango.pc was not in
/usr/local/lib/pkgconfig. I manually copied the files to get pass this.

Doing another ./configure for gtk:
checking for freetype-config... no
sh: gnome-config: not found
configure: error: pangox Pango backend is required for x11 target

This is where I gave up.

Tony

/-\
| Tony Denault| Internet: [EMAIL PROTECTED] |
| NASA IRTF, Institute of Astronomy   | Phone: (808) 974-4206 |
| 1175 Manono St., Bldg 393   |   Fax: (808) 974-4207 |
| Hilo, Hawaii 96720  |   |
\-/

___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list



Re: Updating a statusbar widget

2000-07-26 Thread Tony Denault



On Sun, 23 Jul 2000, Vlad Harchev wrote:

 
 while (gtk_events_pending())
 gtk_main_iteration();
 


I am doing this, see my print_status function to write text
status to a label:

int print_status( char *fmt, ... )
{
   char buf[256];
   va_list argptr;

   va_start( argptr, fmt);
   vsprintf( buf, fmt, argptr);
   va_end( argptr );

   /* update single line feedback widget on main screen */
   gtk_label_set_text( GTK_LABEL(Feedback_search_w), buf );

   /* force update of widgets */
   while ( gtk_events_pending() ) 
  gtk_main_iteration();
   // while ( gtk_main_iteration());   - this one from the FAQ don't  work!

   return ERR_NONE;
}

Some problems:

1. The suggested code from the FAQ doesn't work:
 "while (gtk_main_iteration(FALSE));"
   I am using GTK 1.2.7. Is the FAQ out of date with the GTK release?

2. Worse, this solution does more than just drawing updates. It also
   processing other events on the queue. If I call print_status(), any
   user input to widget and their call backs are called, expired timers
   call backs get called, etc This make the cure, worse that the problem.

Is there a better method to handle this situation?
I think this is the best gtk 1.2.x can do. Will 1.4.x work better?

Tony
 
/-----\
| Tony Denault| Internet: [EMAIL PROTECTED] |
| NASA IRTF, Institute of Astronomy   | Phone: (808) 974-4206 |
| 1175 Manono St., Bldg 393   |   Fax: (808) 974-4207 |
| Hilo, Hawaii 96720  |   |
\-/





___
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list