| View previous topic :: View next topic |
| Author |
Message |
thomas-worm
Joined: 12 Jan 2006 Posts: 18 Location: Erlangen, Bavaria, Germany
|
Posted: Sat Feb 18, 2006 10:27 am Post subject: Change background color of a GtkWindow? |
|
|
Hello,
How can I change the background color of a GtkWindow? |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Sat Feb 18, 2006 10:50 am Post subject: |
|
|
Get the style of the window with get_style, make a copy of this and set the background color property. Then set the style of the window to the copied and modified style object.
The Minesweeper game on the gnope channel has an example; it sets the background color of some buttons. |
|
| Back to top |
|
 |
thomas-worm
Joined: 12 Jan 2006 Posts: 18 Location: Erlangen, Bavaria, Germany
|
Posted: Sun Feb 19, 2006 5:54 pm Post subject: |
|
|
Thank you! It works fine!
But the Minesweeper application crashed (after displaying a blanc window for one second) on my PC with this Windows XP error dialog asking if I want to send an error report to Microsoft. |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Sun Feb 19, 2006 6:08 pm Post subject: |
|
|
| thomas-worm wrote: | | But the Minesweeper application crashed |
That's due to the fact that php-gtk2 is evolving, and the current version in cvs has many more methods than the gnope version has.
There will be an updated version for gnope in the near future, so that you can enjoy the game then :) |
|
| Back to top |
|
 |
rgljr
Joined: 10 Apr 2006 Posts: 15 Location: Minnesota, USA
|
Posted: Sat Apr 22, 2006 6:02 pm Post subject: |
|
|
For Those Looking to do this here is code that works for me.
Had to dig this out thought others could use it.
<?php
/* This takes the instance of entry class and grabs what has been entered
* into the textbox and saves it to $gettext. The instance of the label
* class is then set with the text saved from the $entry class */
function set_name($label, $entry)
{
$gettext = $entry->get_text();
$label->set_text($gettext);
}
/* Creation of the window */
$window = &new GtkWindow();
$window->set_name('main window');
$window->set_title('Introduction to PHP-GTK');
$window->set_size_request(400, 300);
$window->connect('destroy', 'destroy');
$window->connect('delete-event', 'delete_event');
$window->set_border_width(10);
$window->set_position(GTK::WIN_POS_CENTER);
// here's the window color change to a red window
$winStyle=$window->get_style();
$winStyle->bg[Gtk::STATE_NORMAL] = GdkColor::parse('#F00');
$window->set_style($winStyle);
//
/* Creates the frame */
$frame = &new GtkFrame('A Simple Update Program');
$window->add($frame);
/* Creates the Vertical box for putting things in. */
$box1 = &new GtkVBox();
$frame->add($box1);
$box1->show();
/* Creates the area where will be updating the information */
$label = &new GtkLabel('');
$box1->pack_start($label);
$label->show();
/* Creates a horizontal line */
$separator = &new GtkHSeparator();
$box1->pack_start($separator);
$separator->show();
/* Creates the textbox for the user to enter in the information */
$entry = &new GtkEntry();
$box1->pack_start($entry);
$entry->show();
/* Creates the horizontal box for across the bottom of the window */
$box2 = &new GtkHButtonBox();
$box2->set_layout(GTK::BUTTONBOX_SPREAD);
$box1->add($box2);
$box1->show();
/* Sets up one button that is in the button box */
$button = &new GtkButton('Click to Update the Label');
$button->connect('clicked', 'set_name', $label, $entry);
$box2->pack_start($button);
$button->show();
/* Sets up the other button in the button box */
$button = &new GtkButton('Close Window');
$button->connect_simple('clicked', 'destroy');
$box2->pack_start($button);
$button->show();
/* Closes off the frame by showing it */
$frame->show();
/* Tells the window to show all elements */
$window->show_all();
/* Finishes off the entire program */
Gtk::main();
?> |
|
| Back to top |
|
 |
syn
Joined: 12 May 2006 Posts: 46 Location: Hamburg
|
Posted: Fri May 12, 2006 7:10 pm Post subject: |
|
|
my app extends GladeXml (final class App extends GladeXml {})
if i try to change the color of wdo_main, the | Code: | | <widget class="GtkWindow" id="wdo_main"> | , my app crash.
after called the parent constructor | Code: | | parent::__construct('eccapp.glade'); |
i add this code:
| Code: |
$winStyle = $this->wdo_main->get_style();
$winStyle->bg[Gtk::STATE_NORMAL] = GdkColor::parse('#F00');
$this->wdo_main->set_style($winStyle);
|
How can i run this colorchange without the crash?
...
Ok, i see, its a problem with
$winStyle->bg[Gtk::STATE_NORMAL] = GdkColor::parse('#F00');
get_style()/set_style() work fine, i think.
Regards,
Andreas |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Fri May 12, 2006 7:43 pm Post subject: |
|
|
Before you can set or modify the style, you need to copy it
$style = $style->copy()
Otherwise it doesn't work at all.
If it still crashes, can you make the a script with no more code than the one needed to cause the crash and post that here? |
|
| Back to top |
|
 |
syn
Joined: 12 May 2006 Posts: 46 Location: Hamburg
|
Posted: Mon May 15, 2006 10:43 am Post subject: |
|
|
Hi,
$style_temp = $style_original->copy(); works fine.
Mmmm, sometimes i think, using GladeXML isnt the best thing. Is GladeXML a part of the PHP-GTK2 developement, or is it done by another group?
First i had problems with set_events()... now using add_events().. and now the get_style problem. GladeXML is cool, but it isnt cool that there are other steps to do for solving problems...
Regards,
andreas |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Mon May 15, 2006 1:24 pm Post subject: |
|
|
| syn wrote: | Mmmm, sometimes i think, using GladeXML isnt the best thing. Is GladeXML a part of the PHP-GTK2 developement, or is it done by another group?
First i had problems with set_events()... now using add_events().. and now the get_style problem. GladeXML is cool, but it isnt cool that there are other steps to do for solving problems... |
Glade is a user interface designer for Gtk that just creates xml files. libglade (which provices the GladeXML class) is an add-on for Gtk. The "only" work we php-gtk people did was making a PHP wrapper to access the C functions, nothing more.
Glade drastically helps you designing user interfaces, and it's really fast in doing this.
The thing with set_events and add_events lies in the roots of Gdk and can't be done different. Widgets need to be realized after creating e.g. to have children. There is no other way.
You can do the interface design by hand and have full control over what methods you call on your classes. Or you use the help of glade and don't have total control. |
|
| Back to top |
|
 |
kksou
Joined: 06 Sep 2006 Posts: 25
|
Posted: Fri Sep 08, 2006 7:20 pm Post subject: |
|
|
php-gtk2 makes things much simpler as compared with php-gtk.
If you are using php-gtk2, here's a one-liner to set the background of a GtkWindow:
| Code: | | $window->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#FFFF00")); |
For a complete sample code with explanation, you can go here. |
|
| Back to top |
|
 |
|