Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93554 > unrolled thread

pygtk2 and colors

Started bynickgeovanis@gmail.com
First post2015-07-07 06:57 -0700
Last post2015-07-10 16:06 -0700
Articles 8 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  pygtk2 and colors nickgeovanis@gmail.com - 2015-07-07 06:57 -0700
    Re: pygtk2 and colors bkimstunnaboss@gmail.com - 2015-07-07 07:47 -0700
      Re: pygtk2 and colors Chris Angelico <rosuav@gmail.com> - 2015-07-08 00:54 +1000
    Re: pygtk2 and colors Cousin Stanley <cousinstanley@gmail.com> - 2015-07-07 09:54 -0700
      Re: pygtk2 and colors nickgeovanis@gmail.com - 2015-07-07 10:25 -0700
        Re: pygtk2 and colors Chris Angelico <rosuav@gmail.com> - 2015-07-08 03:57 +1000
          Re: pygtk2 and colors nickgeovanis@gmail.com - 2015-07-07 12:37 -0700
            Re: pygtk2 and colors nickgeovanis@gmail.com - 2015-07-10 16:06 -0700

#93554 — pygtk2 and colors

Fromnickgeovanis@gmail.com
Date2015-07-07 06:57 -0700
Subjectpygtk2 and colors
Message-ID<3b7fcd33-8ba6-44f7-abf8-ad55458eb96a@googlegroups.com>
Morning-
With python 2.7.5, pygtk 2.24, gtk 2.24:
The following snippet successfully sets the line_width but not the foreground color, and I can't figure-out why. The color human-name and the result returned by gtk.gdk.color_parse are correct. Clues? Thanks.

self.gc.set_line_attributes(myclass.board_line_width, gtk.gdk.LINE_SOLID,
                                      gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_BEVEL)
fg = gtk.gdk.color_parse(myclass.board_foreground)
self.gc.set_foreground(fg)

[toc] | [next] | [standalone]


#93556

Frombkimstunnaboss@gmail.com
Date2015-07-07 07:47 -0700
Message-ID<106c414d-0c57-42b2-98be-caa90e8f223d@googlegroups.com>
In reply to#93554
Hi Nick,
Doing colors with pygtk2 is a real pain...
But to change the foreground, what you wanna do is to get a copy of the style of the widget, set the color values on it, and then set it back as the style.
Like so...

    color = gtk.gdk.color_parse('#ac0102')
    style = self.get_style().copy()
    style.fg[gtk.STATE_NORMAL] = color
    style.fg[gtk.STATE_PRELIGHT] = color
    self.set_style(style)

Very unpythonic imo...

[toc] | [prev] | [next] | [standalone]


#93557

FromChris Angelico <rosuav@gmail.com>
Date2015-07-08 00:54 +1000
Message-ID<mailman.343.1436280878.3674.python-list@python.org>
In reply to#93556
On Wed, Jul 8, 2015 at 12:47 AM,  <bkimstunnaboss@gmail.com> wrote:
> Hi Nick,
> Doing colors with pygtk2 is a real pain...

I understand there's a different set of GTK bindings, pygobject. But
I've not used it, so I don't know if it's more pythonic in style.
Might be worth considering.

ChrisA

[toc] | [prev] | [next] | [standalone]


#93561

FromCousin Stanley <cousinstanley@gmail.com>
Date2015-07-07 09:54 -0700
Message-ID<mnh04p$k28$1@dont-email.me>
In reply to#93554
> With python 2.7.5, pygtk 2.24, gtk 2.24:
> The following snippet successfully sets the line_width 
> but not the foreground color, and I can't figure-out why. 
> 
> The color human-name and the result returned 
> by gtk.gdk.color_parse are correct. Clues? Thanks.
> 
> self.gc.set_line_attributes(myclass.board_line_width, gtk.gdk.LINE_SOLID,
>
> gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_BEVEL)
>
> fg = gtk.gdk.color_parse(myclass.board_foreground)
>
> self.gc.set_foreground(fg)
>

  You might try .... 

    self.set_rgb_fg_color( fg ) 


  Example from ... 

    http://www.linuxplanet.com/linuxplanet/tutorials/6750/2/

 

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

[toc] | [prev] | [next] | [standalone]


#93562

Fromnickgeovanis@gmail.com
Date2015-07-07 10:25 -0700
Message-ID<97288ef7-1d9e-4afc-b4e3-534582ccd059@googlegroups.com>
In reply to#93561
On Tuesday, July 7, 2015 at 11:54:21 AM UTC-5, Cousin Stanley wrote:
>   You might try .... 
> 
>     self.set_rgb_fg_color( fg ) 

Well thanks, that works. Yet set_rgb_bg_color() does not. And I notice that the example at the link you sent doesn't set the background color either. Do I have a color overlay or masking issue?

I guess what bothers me is that this is such a basic thing, the reference doc is almost useless on the subject, the usual response is "look at this example", and each example does it differently than every other example.

[toc] | [prev] | [next] | [standalone]


#93564

FromChris Angelico <rosuav@gmail.com>
Date2015-07-08 03:57 +1000
Message-ID<mailman.347.1436291880.3674.python-list@python.org>
In reply to#93562
On Wed, Jul 8, 2015 at 3:25 AM,  <nickgeovanis@gmail.com> wrote:
> On Tuesday, July 7, 2015 at 11:54:21 AM UTC-5, Cousin Stanley wrote:
>>   You might try ....
>>
>>     self.set_rgb_fg_color( fg )
>
> Well thanks, that works. Yet set_rgb_bg_color() does not. And I notice that the example at the link you sent doesn't set the background color either. Do I have a color overlay or masking issue?

Part of your confusion may be because "background" isn't necessarily
what you think it is. In GTK, there are several different ways styles
can be set, and probably you _are_ setting the background color, but
it's not having any visible change. Try playing around with some of
the other settable colors, and see if one of them helps you.

ChrisA

[toc] | [prev] | [next] | [standalone]


#93565

Fromnickgeovanis@gmail.com
Date2015-07-07 12:37 -0700
Message-ID<654cbc5a-9142-4276-9b53-4e2d3a685c12@googlegroups.com>
In reply to#93564
On Tuesday, July 7, 2015 at 12:58:12 PM UTC-5, Chris Angelico wrote:
> 
> Part of your confusion may be because "background" isn't necessarily
> what you think it is. 

Indeed. Yet "foreground" _is_ what I think it is :-) I would argue that we have here a clumsy intrusion of OO inheritance into a context which doesn't consistently support it. I don't mind inheritance; I do mind clumsiness and inconsistency.

[toc] | [prev] | [next] | [standalone]


#93657

Fromnickgeovanis@gmail.com
Date2015-07-10 16:06 -0700
Message-ID<ae7d8d4b-fd38-4f58-9049-c566296b4c23@googlegroups.com>
In reply to#93565
I may be phrasing this question improperly, but...If I need a canvas or canvas-like object, does GTK3/pygobject provide one? Or only GTK2/PyGTK? The answer seems to be "only GTK2/PyGTK" but the discussion I find online doesn't seem to have a clear answer.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web