-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolor_circle.py
More file actions
95 lines (71 loc) · 2.88 KB
/
color_circle.py
File metadata and controls
95 lines (71 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# example colorsel.py
import pygtk
pygtk.require('2.0')
import gtk
class ColorSelectionExample:
def __init__(self):
self.colorseldlg = None
# Create toplevel window, set title and policies
self. window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self. window.set_title("Click Here for Choosing Colors")
self. window.set_resizable(True)
# Attach to the "delete" and "destroy" events so we can exit
self. window.connect("delete_event", self.destroy_window)
# def draw():
# 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
self. window.add(self.drawingarea)
# self.window.connect("key-press-event", self. keyEvent)
self.drawingarea.show()
self. window.show()
# Color changed handler
def color_changed_cb(self, widget):
# Get drawingarea colormap
colormap = self.drawingarea.get_colormap()
# Get current color
self.color = self.colorseldlg.colorsel.get_current_color()
# global selected_color
# selected_color=color
# Set window background color
self.drawingarea.modify_bg(gtk.STATE_NORMAL, self.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 == 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 False
def main():
gtk.main()
return 0
if __name__ == "__main__":
ColorSelectionExample()
main()