`
deepfuture
  • 浏览: 4425298 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80283
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:70700
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103889
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:287159
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:15108
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:68186
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32456
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:46217
社区版块
存档分类
最新评论

pygtk-colorsel

 
阅读更多

colorsel = colorseldlg.colorsel

colorsel.set_has_opacity_control(has_opacity)

has_opacity是逻辑值True或False

colorsel.set_current_color(color)
colorsel.set_current_alpha(alpha)

 

color = colorsel.get_current_color()
alpha = colorsel.get_current_alpha()

 


 

#!/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 == 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()

 
 

  • 大小: 97.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics