024 colorsel.py :  » Ajax » pyjamas » src » pygtkweb » demos » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » pygtkweb » demos » 024-colorsel.py
#!/usr/bin/env python

# example colorsel.py

import pygtk
pygtk.require('2.0')
import gtk

class ColorSelectionExample:
    # Color changed handler
    def color_changed_cb(self, widget):
        # Get drawingarea colormap
        colormap = self.drawingarea.get_colormap()

        # Get current color
        color = self.colorseldlg.colorsel.get_current_color()

        # Set window background color
        self.drawingarea.modify_bg(gtk.STATE_NORMAL, color)

    # Drawingarea event handler
    def area_event(self, widget, event):
        handled = False

        # Check if we've received a button pressed event
        if event.type == gtk.gdk.BUTTON_PRESS:
            handled = True

            # Create color selection dialog
            if self.colorseldlg is None:
                self.colorseldlg = gtk.ColorSelectionDialog(
                    "Select background color")

            # Get the ColorSelection widget
            colorsel = self.colorseldlg.colorsel

            colorsel.set_previous_color(self.color)
            colorsel.set_current_color(self.color)
            colorsel.set_has_palette(True)

            # Connect to the "color_changed" signal
            colorsel.connect("color_changed", self.color_changed_cb)
            # Show the dialog
            response = self.colorseldlg.run()

            if response -- gtk.RESPONSE_OK:
                self.color = colorsel.get_current_color()
            else:
                self.drawingarea.modify_bg(gtk.STATE_NORMAL, self.color)

            self.colorseldlg.hide()

        return handled

    # Close down and exit handler
    def destroy_window(self, widget, event):
        gtk.main_quit()
        return True

    def __init__(self):
        self.colorseldlg = None
        # Create toplevel window, set title and policies
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.set_title("Color selection test")
        window.set_resizable(True)

        # Attach to the "delete" and "destroy" events so we can exit
        window.connect("delete_event", self.destroy_window)
  
        # Create drawingarea, set size and catch button events
        self.drawingarea = gtk.DrawingArea()

        self.color = self.drawingarea.get_colormap().alloc_color(0, 65535, 0)

        self.drawingarea.set_size_request(200, 200)
        self.drawingarea.set_events(gtk.gdk.BUTTON_PRESS_MASK)
        self.drawingarea.connect("event",  self.area_event)
  
        # Add drawingarea to window, then show them both
        window.add(self.drawingarea)
        self.drawingarea.show()
        window.show()
  
def main():
    gtk.main()
    return 0

if __name__ == "__main__":
    ColorSelectionExample()
    main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.