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

from slider import VSlider, HSlider
from knob import Knob
from waveformselector import WaveformSelector
from display import Display
import colors

MASKS = gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK
MASKS2 = gtk.gdk.ENTER_NOTIFY_MASK | gtk.gdk.LEAVE_NOTIFY_MASK
MASKS3 = gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK

class Demo(gtk.Window):

	def destroy(self, widget):
		gtk.main_quit()

	def __init__(self):
		gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
		self.set_flags(gtk.CAN_FOCUS)
		self.grab_focus()
		self.set_title("Demo")
		self.window_x = 800
		self.window_y = 600
		self.set_size_request(self.window_x, self.window_y)
		self.connect("destroy", self.destroy)
				
		layout = gtk.Fixed()
		
		
		
		self.display = Display(colors.black, colors.blue3, colors.blue, 300, 30, 20, 2, 3, 1)
		self.display.show()
		layout.put(self.display, 500, 10)
		#self.display = Display(colors.black, colors.blue3, colors.blue, 300, 30, 20, 2, 3, 0)
		#self.display.show()
		#layout.put(self.display, 300, 200)
		#self.display.setCharacters("Mod Index", 234)
		
		
		
		
		#Button(width, height, default color, color when mouse is within the button, color when the button is pressed)
		self.slider = VSlider("img/vslider_bg.png", "img/vslider_nub.png", 15, 100, 20, "Decay")
		self.slider.setValueCallback(self.printKnob)
		self.slider.setEnterCallback(self.enterKnob)
		self.slider.setLeaveCallback(self.leaveKnob)
		layout.put(self.slider, 400, 300)
		self.slider.show()
		
		self.hslider = HSlider("img/hslider_bg.png", "img/hslider_nub.png", 10, 50, 25, "Attack")
		self.hslider.setValueCallback(self.printKnob)
		self.hslider.setEnterCallback(self.enterKnob)
		self.hslider.setLeaveCallback(self.leaveKnob)
		layout.put(self.hslider, 100, 100)
		self.hslider.show()
		
		self.knob = Knob("img/knob.png", None, 0, 125, 35, 5, "LFO Knob")
		self.knob.setValueCallback(self.printKnob)
		self.knob.setEnterCallback(self.enterKnob)
		self.knob.setLeaveCallback(self.leaveKnob)
		layout.put(self.knob, 50, 50)
		self.knob.show()
		
		self.selector = WaveformSelector(colors.blue3, colors.blue, colors.aqua3, colors.white, 50, 50, 1, "Waveform")
		self.selector.setValueCallback(self.printKnob)
		self.selector.setEnterCallback(self.enterKnob)
		self.selector.setLeaveCallback(self.leaveKnob)
		layout.put(self.selector, 100, 200)
		self.selector.show()
		
		#self.button = gtk.Button("  X  ")
		#self.button.connect("expose-event", self.onExpose)
		#self.button.connect("clicked", self.Click)
		#layout.put(self.button, 400, 400)
		#self.button.show()
		#self.bg = gtk.DrawingArea()
		#self.bg.set_size_request(500, 500)
		#self.bg.show()		
		#layout.put(self.bg, 200, 200)
		
		self.add(layout)
		layout.show()
		self.show()
	
	def changeWaveform(self, value):
		print "changed waveform to waveform #", value
		
	
	def printKnob(self, value):
		#self.display.setCharacters(chars, value)
		print value
		
	def enterKnob(self, chars, value):
		#print chars, value
		self.display.setCharacters(chars, value)
	
	def leaveKnob(self):
		chars = ""
		#print chars, -1
		self.display.setCharacters(chars, -1)
def main():
	gtk.main()
	
if __name__ == "__main__":
	demo = Demo()
	main()