#! /usr/bin/env python
# -*- coding: Utf-8 -*-

##################################################
#                 Curseurs.py        
# A f,phi,a parameterek szabalyozasara szolgalo  #
# kurzorokat tartalmazo widget.                  #
# A parameterek minden modositasakor egy speci.  #
# esemeny generalodik, ami a master widget       #
# ertesitesere valo, ami aztan reagalni tud 
#                                                #
#      Szerzo : G.Swinnen (Liège, Belgium)       #
#           2002/03/16 - Licence GPL             #
##################################################

from Tkinter import *
from math import pi

class ChoiceVibra(Frame):
    """kurzorok egy rezges frekvenciajanak, fazisanak es amplitudojanak kivalasztasahoz"""
    def __init__(self, maitre=None, colo='red'):
        Frame.__init__(self)        # a szuloosztaly constructora
        # nehany peldany-attributum inicializalasa :
        self.freq, self.phase, self.ampl, self.colo = 0, 0, 0, colo
        # A checkbox allapotvaltozoja :
        self.chk = IntVar()                 # Tkinter 'objektum-valtozo
        Checkbutton(self, text='Rajzol', variable=self.chk,
                    fg = self.colo, command=self.setCurve).pack(side=LEFT)
        # A 3 cursor-widget definicioja :
        Scale(self, length=150, orient=HORIZONTAL, sliderlength =25,
              label ='Frekvencia (Hz) :', from_=1., to=9., tickinterval =2,
              resolution =0.25,
              showvalue =0, command = self.setFrequency).pack(side=LEFT, pady =5)
        Scale(self, length=150, orient=HORIZONTAL, sliderlength =15,
              label ='Fázis (fok) :', from_=-180, to=180, tickinterval =90,
              showvalue =0, command = self.setPhase).pack(side=LEFT, pady =5)
        Scale(self, length=150, orient=HORIZONTAL, sliderlength =25,
              label ='Amplitúdó :', from_=2, to=10, tickinterval =2,
              showvalue =0, command = self.setAmplitude).pack(side=LEFT, pady =5)

    def setCurve(self):
        self.event_generate('<Control-Z>')

    def setFrequency(self, f):
        self.freq = float(f)
        self.event_generate('<Control-Z>')

    def setPhase(self, p):
        pp =float(p)
        self.phase = pp*2*pi/360        # fok -> radian atalakitas
        self.event_generate('<Control-Z>')

    def setAmplitude(self, a):
        self.ampl = float(a)
        self.event_generate('<Control-Z>')

#### Kod az osztaly tesztelesehez : ###

if __name__ == '__main__':
    def showAll(event=None):
        lab.configure(text = '%s - %s - %s - %s' %
                         (fra.chk.get(), fra.freq, fra.phase, fra.ampl))
    root = Tk()
    fra = ChoiceVibra(root,'navy')
    fra.pack(side =TOP)
    lab = Label(root, text ='test')
    lab.pack()
    root.bind('<Control-Z>', showAll)
    root.mainloop()
