Re: setting border width



On Mon, 5 Jan 2009 16:17:22 +0200
"Dafna Hirschfeld" <dafna3 gmail com> wrote:

I couldn't find how to set a border of a widget. I don't mean the space
around the widget but the border line itself.
The entry widget and the check-button come with a border line by default
(the entry widget even have a little shadow).
But the TextView  has no border by default , How can I add a border?
I fond the function paint_shadow of Style, and a struct GtkBorder but I
couldn't understand if this is what I need and how to use it.

In addition to what Emmanuel said, there is a style setting that may help
on the ScrolledWindow that you put the TextView in.

Also I toyed around with trying make a sub-classed widget, like muppet's
package Mup::ColorButton;   but it gets so messy trying to override default
styles, I gave up. So many installations now, have default pixmap based color
schemes that it's hard to cleanly change anything.

The second script below may give you an idea on how to do it at a low level on the gdk
window. It's very clunky, and uncommenting the xor function gives an interesting
flashing effect. You might need to get the gdk window of the vbox the textview is in,
and instead of drawing to the textview, draw to it's container. 

# don't take these scripts too seriously.....I'm still in a partying mode from the holidays. :-)

#  setting a style on the scrolled window and the window bg
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

Gtk2::Rc->parse_string(<<__);

pixmap_path  '.'   

style "my_text" {
font_name ="sans 24"
text[NORMAL] = "#FFAA00"
base[NORMAL] = "#000000"   
GtkTextView::cursor-color = "red"
}

style "my_cursor"{
fg[NORMAL] = "#FF0000"
}

widget "*Text*" style "my_text"


style "my-scrolledwindow"
{
    xthickness = 10
    ythickness = 10
    GtkScrolledWindow ::scrollbars-within-bevel = 1
    GtkScrolledWindow ::scrollbar-spacing = 10
    engine "pixmap"
    {
          image
          {
                function = SHADOW
                file = "./background.png"
                border = {10, 10, 10, 10}
                detail = "scrolled_window"
          }
    }
}
 
class "GtkScrolledWindow" style "my-scrolledwindow"
__

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(300,300);

my $back_pixbuf =  Gtk2::Gdk::Pixbuf->new_from_file('background.png');
my ($pixmap,$mask) = $back_pixbuf->render_pixmap_and_mask(255);
my $style = $window->get_style();
$style=$style->copy();
$style->bg_pixmap("normal",$pixmap);
$window->set_style($style);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(5);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);

my $ebutton = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $ebutton, FALSE, FALSE, 0 );
$ebutton->signal_connect( clicked => \&delete_event );

my $str;
my $file = shift || $0;
open( TEST, "< $file" ) or die "Cannot open test.txt\n";
while (<TEST>) {
    $str .= $_;
}
close TEST;

# Create a textbuffer to contain that string 
my $textbuffer = Gtk2::TextBuffer->new();
$textbuffer->set_text($str);

# Create a textview using that textbuffer 
my $textview = Gtk2::TextView->new_with_buffer($textbuffer);

# Add the textview to a scrolledwindow 
my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef );
$scrolledwindow->add($textview);

$scrolledwindow->set_shadow_type ('etched-out');
$scrolledwindow->set_policy ('automatic', 'automatic');

$vbox->pack_start($scrolledwindow, 1, 1, 0 );

$window->show_all();
Gtk2->main;

#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
#######################################

__END__


A wild example writing to the lowlevel window.

#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

Gtk2::Rc->parse_string(<<__);

pixmap_path  '.'   

style "my_text" {
font_name ="sans 24"
text[NORMAL] = "#FFAA00"
base[NORMAL] = "#000000"   
GtkTextView::cursor-color = "red"
}

style "my_cursor"{
fg[NORMAL] = "#FF0000"
}

widget "*Text*" style "my_text"
__

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(400,400);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);

my $ebutton = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $ebutton, FALSE, FALSE, 0 );
$ebutton->signal_connect( clicked => \&delete_event );

# Create a textbuffer to contain that string 
my $textbuffer = Gtk2::TextBuffer->new();
$textbuffer->set_text('yadda yadda yadda');

# Create a textview using that textbuffer 
my $textview = Gtk2::TextView->new_with_buffer($textbuffer);

# Add the textview to a scrolledwindow 
my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef );
$scrolledwindow->add($textview);
$vbox->pack_start($scrolledwindow, 1, 1, 0 );

$textview->signal_connect('expose-event' => \&on_expose);  

$window->show_all();

Gtk2->main;

#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
#######################################
sub on_expose{

  my $root = Gtk2::Gdk->get_default_root_window;
  my $disp = Gtk2::Gdk::Display->get_default;
  my $white = Gtk2::Gdk::Color->new( 65535, 65535, 65535 );

   my $gc = Gtk2::Gdk::GC->new( $root, undef );
   $gc->set_line_attributes( 6, 'solid', 'round', 'round' );
   $gc->set_rgb_bg_color( $white );
   $gc->set_rgb_fg_color( $white );
   $gc->set_subwindow( 'include-inferiors' );
# the xor line gives an interesting effect
   $gc->set_function( 'xor' );

my ($x, $y, $width, $height, $depth) = $textview->window->get_geometry;
print  "($x, $y, $width, $height, $depth)\n";

$textview->window->draw_rectangle( $gc, 0, 0,0, $width, $height);

}
__END__


zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]