[pygobject/pygobject-2-28] [gi-demo] Fix color dialog demo to run with new draw, style and color apis
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-2-28] [gi-demo] Fix color dialog demo to run with new draw, style and color apis
- Date: Mon, 14 Feb 2011 23:18:12 +0000 (UTC)
commit b6c97de9680f3d5d629132415c1f7a9c42e558f8
Author: John (J5) Palmieri <johnp redhat com>
Date: Mon Feb 14 18:17:20 2011 -0500
[gi-demo] Fix color dialog demo to run with new draw, style and color apis
demos/gtk-demo/demos/colorselector.py | 44 ++++++++++++--------------------
1 files changed, 17 insertions(+), 27 deletions(-)
---
diff --git a/demos/gtk-demo/demos/colorselector.py b/demos/gtk-demo/demos/colorselector.py
index 514718b..ed1e330 100644
--- a/demos/gtk-demo/demos/colorselector.py
+++ b/demos/gtk-demo/demos/colorselector.py
@@ -34,7 +34,11 @@ class ColorSelectorApp:
def __init__(self):
# FIXME: we should allow Gdk.Color to be allocated without parameters
# Also color doesn't seem to work
- self.color = Gdk.Color(0, 65535, 0)
+ self.color = Gdk.RGBA()
+ self.color.red = 0
+ self.color.blue = 1
+ self.color.green = 0
+ self.color.alpha = 1
self.window = Gtk.Window()
self.window.set_title('Color Selection')
@@ -52,12 +56,12 @@ class ColorSelectorApp:
vbox.pack_start(frame, True, True, 0)
self.da = Gtk.DrawingArea()
- self.da.connect('expose_event', self.expose_event_cb)
+ self.da.connect('draw', self.draw_cb)
# set a minimum size
self.da.set_size_request(200, 200)
# set the color
- self.da.modify_bg(Gtk.StateType.NORMAL, self.color)
+ self.da.override_background_color(0, self.color)
frame.add(self.da)
alignment = Gtk.Alignment(xalign=1.0,
@@ -74,42 +78,28 @@ class ColorSelectorApp:
self.window.show_all()
- def expose_event_cb(self, widget, event):
- window = widget.get_window()
-
- if window:
-
- style = widget.get_style()
- x = event.expose.area.x
- y = event.expose.area.y
- width = event.expose.area.width
- height = event.expose.area.height
-
- """
- Gdk.draw_rectangle(window,
- # FIXME: accessing style attribute segfaults
- style.bg_gc[Gtk.StateType.NORMAL],
- True,
- event.expose.area.x, event.expose.area.y,
- event.expose.area.width, event.expose.area.height)
- """
- return True
+ def draw_cb(self, widget, cairo_ctx):
+ style = widget.get_style_context()
+ bg_color = style.get_background_color(0)
+ Gdk.cairo_set_source_rgba(cairo_ctx, bg_color)
+ cairo_ctx.paint()
+ return True
def change_color_cb(self, button):
dialog = Gtk.ColorSelectionDialog(title='Changing color')
dialog.set_transient_for(self.window)
colorsel = dialog.get_color_selection()
- colorsel.set_previous_color(self.color)
- colorsel.set_current_color(self.color)
+ colorsel.set_previous_rgba(self.color)
+ colorsel.set_current_rgba(self.color)
colorsel.set_has_palette(True)
response = dialog.run()
if response == Gtk.ResponseType.OK:
- self.color = colorsel.get_current_color()
- self.da.modify_bg(Gtk.StateType.NORMAL, self.color)
+ self.color = colorsel.get_current_rgba()
+ self.da.override_background_color(0, self.color)
dialog.destroy()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]