Yajushi
Yajushi

Reputation: 1185

PyGtk : Modify Background color/image of gtk FileChooserButton

I have tried following to change background color for Filechooser Button, but nothing changed..

gtkrc file:

style "FilechooserButtonStyle" = "button_style"
{
 base[NORMAL] = '#F5F5F5'
 base[SELECTED] = 'red'
 bg[NORMAL] = 'green'
 bg_pixmap[NORMAL] = "button.jpg"

 xthickness = 10
 ythickness = 10
 GtkFileChooserButton::set_app_paintable = True

}

In py file:

file_chooser.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
file_chooser.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('gray'))

How could I solve the problem ?

Thanks in advance!

Upvotes: 0

Views: 1208

Answers (1)

Louis
Louis

Reputation: 2900

I'm not so familiar with the .rc files, but this works in the code :

#!/usr/bin/env python
# example filechooser.py

import pygtk
pygtk.require('2.0')

import gtk

dialog = gtk.FileChooserDialog("Open..", None,
                           gtk.FILE_CHOOSER_ACTION_OPEN,
                           (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)


##      here it is
##
for child in dialog.get_children():
    for enf in child.get_children():
    if isinstance(enf, gtk.HButtonBox):
        for butt in enf.get_children():
            style = butt.get_style().copy ()
            style.bg[gtk.STATE_NORMAL] = butt.get_colormap().alloc (0xffff, 0x0000, 0x0000)
            butt.set_style (style)
##

response = dialog.run()
if response == gtk.RESPONSE_OK:
    print dialog.get_filename(), 'selected'
elif response == gtk.RESPONSE_CANCEL:
    print 'Closed, no files selected'
dialog.destroy()

It searches in all the dialog's childs to find buttons and change their style to red. Hope it helped you !

Upvotes: 1

Related Questions