VisionEgg.PyroApps.SphereGratingGUI

Package VisionEgg :: Package PyroApps :: Module SphereGratingGUI |
[frames] | no frames]

# Source Code for Module VisionEgg.PyroApps.SphereGratingGUI

      1  #!/usr/bin/env python
      2  """Handle perspective-distorted sinusoidal gratings (client-side)"""
      3
      4  # Copyright (c) 2002-2003 Andrew Straw.  Distributed under the terms
      5  # of the GNU Lesser General Public License (LGPL).
      6
      7  import VisionEgg, string
      8  __version__ = VisionEgg.release_name
      9  __cvs__ = string.split('$Revision$')[1]
     10  __date__ = string.join(string.split('$Date$')[1:3], ' ')
     11  __author__ = 'Andrew Straw <astraw@users.sourceforge.net>'
     12
     13  import sys, os
     14  import Tkinter
     15  import VisionEgg.PyroApps.EPhysGUIUtils as client_utils
     16
     17 -def get_control_list():
     18      return [("sphere_grating_server",SphereGratingControlFrame,SphereGratingControlFrame.title)]
     19
     20 -class SphereGratingMetaParameters:
     21 -    def __init__(self):
     22          self.contrast = 1.0
     23          self.orient = 0.0
     24          self.sf = 0.1 # cycles per degree
     25          self.tf = 1.0
     26          self.pre_stim_sec = 1.0
     27          self.stim_sec = 2.0
     28          self.post_stim_sec = 1.0
     29          self.window_func = 'gaussian'
     30          self.window_radius = 10.0
     31          self.window_az = 0.0
     32          self.window_el = 0.0
     33
     34 -class SphereGratingControlFrame(client_utils.StimulusControlFrame):
     35      title = "Grating (Perspective-distorted) Experiment"
     36 -    def __init__(self, master=None, suppress_go_buttons=0,**kw):
     37          client_utils.StimulusControlFrame.__init__(self,
     38                                                     master,
     39                                                     suppress_go_buttons,
     40                                                     SphereGratingControlFrame.title,
     41                                                     SphereGratingMetaParameters,
     42                                                     **kw)
     43
     44          param_frame = self.param_frame # shorthand for self.param_frame created in base class
     45
     46          # Allow columns to expand
     47          param_frame.columnconfigure(0,weight=1)
     48          param_frame.columnconfigure(1,weight=1)
     49
     50          pf_row = 0
     51          Tkinter.Label(param_frame,text="Contrast:").grid(row=pf_row,column=0)
     52          self.contrast_tk_var = Tkinter.DoubleVar()
     53          self.contrast_tk_var.set(self.meta_params.contrast)
     54          self.make_callback_entry(textvariable=self.contrast_tk_var).grid(row=pf_row,column=1)
     55          self.loopable_variables["Contrast"] = ("contrast",self.contrast_tk_var)
     56
     57          pf_row += 1
     58          Tkinter.Label(param_frame,text="Orientation (deg):").grid(row=pf_row,column=0)
     59          self.orient_tk_var = Tkinter.DoubleVar()
     60          self.orient_tk_var.set(self.meta_params.orient)
     61          self.make_callback_entry(textvariable=self.orient_tk_var).grid(row=pf_row,column=1)
     62          self.loopable_variables["Orientation"] = ("orient",self.orient_tk_var)
     63
     64          pf_row += 1
     65          Tkinter.Label(param_frame,text="Spatial frequency (Cpd):").grid(row=pf_row,column=0)
     66          self.sf_tk_var = Tkinter.DoubleVar()
     67          self.sf_tk_var.set(self.meta_params.sf)
     68          self.make_callback_entry(textvariable=self.sf_tk_var).grid(row=pf_row,column=1)
     69          self.loopable_variables["Spatial frequency"] = ("sf",self.sf_tk_var)
     70
     71          pf_row += 1
     72          Tkinter.Label(param_frame,text="Temporal frequency (Hz):").grid(row=pf_row,column=0)
     73          self.tf_tk_var = Tkinter.DoubleVar()
     74          self.tf_tk_var.set(self.meta_params.tf)
     75          self.make_callback_entry(textvariable=self.tf_tk_var).grid(row=pf_row,column=1)
     76          self.loopable_variables["Temporal frequency"] = ("tf",self.tf_tk_var)
     77
     78          pf_row += 1
     79          Tkinter.Label(param_frame,text="Pre stimulus duration (sec):").grid(row=pf_row,column=0)
     80          self.prestim_dur_tk_var = Tkinter.DoubleVar()
     81          self.prestim_dur_tk_var.set(self.meta_params.pre_stim_sec)
     82          self.make_callback_entry(textvariable=self.prestim_dur_tk_var).grid(row=pf_row,column=1)
     83
     84          pf_row += 1
     85          Tkinter.Label(param_frame,text="Stimulus duration (sec):").grid(row=pf_row,column=0)
     86          self.stim_dur_tk_var = Tkinter.DoubleVar()
     87          self.stim_dur_tk_var.set(self.meta_params.stim_sec)
     88          self.make_callback_entry(textvariable=self.stim_dur_tk_var).grid(row=pf_row,column=1)
     89
     90          pf_row += 1
     91          Tkinter.Label(param_frame,text="Post stimulus duration (sec):").grid(row=pf_row,column=0)
     92          self.poststim_dur_tk_var = Tkinter.DoubleVar()
     93          self.poststim_dur_tk_var.set(self.meta_params.post_stim_sec)
     94          self.make_callback_entry(textvariable=self.poststim_dur_tk_var).grid(row=pf_row,column=1)
     95
     96          pf_row += 1
     97          Tkinter.Label(param_frame,text="Window function:").grid(row=pf_row,column=0)
     98          self.window_func_tk_var = Tkinter.StringVar()
     99          self.window_func_tk_var.set(self.meta_params.window_func)
    100          bar = Tkinter.Menubutton(param_frame, textvariable=self.window_func_tk_var, relief=Tkinter.RAISED)
    101          bar.grid(row=pf_row, column=1, sticky=Tkinter.W+Tkinter.E, pady=2, padx=2)
    102          bar.menu = Tkinter.Menu(bar,tearoff=0)
    103          bar.menu.add_radiobutton(label='circle',
    104                                   value='circle',
    105                                   variable=self.window_func_tk_var,
    106                                   command=self.send_values)
    107          bar.menu.add_radiobutton(label='gaussian',
    108                                   value='gaussian',
    109                                   variable=self.window_func_tk_var,
    110                                   command=self.send_values)
    111          bar['menu'] = bar.menu
    112
    113          pf_row += 1
    114          Tkinter.Label(param_frame,text="Window radius/sigma (deg):").grid(row=pf_row,column=0)
    115          self.window_radius_tk_var = Tkinter.DoubleVar()
    116          self.window_radius_tk_var.set(self.meta_params.window_radius)
    117          self.make_callback_entry(textvariable=self.window_radius_tk_var).grid(row=pf_row,column=1)
    118
    119          pf_row += 1
    120          Tkinter.Label(param_frame,text="Window azimuth (deg):").grid(row=pf_row,column=0)
    121          self.window_az_tk_var = Tkinter.DoubleVar()
    122          self.window_az_tk_var.set(self.meta_params.window_az)
    123          self.make_callback_entry(textvariable=self.window_az_tk_var).grid(row=pf_row,column=1)
    124          self.loopable_variables["Window azimuth"] = ("window_az",self.window_az_tk_var)
    125
    126          pf_row += 1
    127          Tkinter.Label(param_frame,text="Window elevation (deg):").grid(row=pf_row,column=0)
    128          self.window_el_tk_var = Tkinter.DoubleVar()
    129          self.window_el_tk_var.set(self.meta_params.window_el)
    130          self.make_callback_entry(textvariable=self.window_el_tk_var).grid(row=pf_row,column=1)
    131          self.loopable_variables["Window elevation"] = ("window_el",self.window_el_tk_var)
    132
    133 -    def get_shortname(self):
    134          return "sphere_grating"
    135
    136 -    def update_tk_vars(self):
    137          self.contrast_tk_var.set( self.meta_params.contrast )
    138          self.orient_tk_var.set( self.meta_params.orient )
    139          self.sf_tk_var.set( self.meta_params.sf )
    140          self.tf_tk_var.set( self.meta_params.tf )
    141          self.prestim_dur_tk_var.set( self.meta_params.pre_stim_sec )
    142          self.stim_dur_tk_var.set( self.meta_params.stim_sec )
    143          self.poststim_dur_tk_var.set( self.meta_params.post_stim_sec )
    144          self.window_func_tk_var.set( self.meta_params.window_func )
    145          self.window_radius_tk_var.set( self.meta_params.window_radius )
    146          self.window_az_tk_var.set( self.meta_params.window_az )
    147          self.window_el_tk_var.set( self.meta_params.window_el )
    148
    149 -    def send_values(self,dummy_arg=None):
    150          self.meta_params.contrast = self.contrast_tk_var.get()
    151          self.meta_params.orient = self.orient_tk_var.get()
    152          self.meta_params.sf = self.sf_tk_var.get()
    153          self.meta_params.tf = self.tf_tk_var.get()
    154          self.meta_params.pre_stim_sec = self.prestim_dur_tk_var.get()
    155          self.meta_params.stim_sec = self.stim_dur_tk_var.get()
    156          self.meta_params.post_stim_sec = self.poststim_dur_tk_var.get()
    157          self.meta_params.window_func = self.window_func_tk_var.get()
    158          self.meta_params.window_radius = self.window_radius_tk_var.get()
    159          self.meta_params.window_az = self.window_az_tk_var.get()
    160          self.meta_params.window_el = self.window_el_tk_var.get()
    161          if self.connected:
    162              self.meta_controller.set_parameters( self.meta_params )
    163
    164 -    def get_duration_sec(self):
    165          self.meta_params.pre_stim_sec = self.prestim_dur_tk_var.get()
    166          self.meta_params.stim_sec = self.stim_dur_tk_var.get()
    167          self.meta_params.post_stim_sec = self.poststim_dur_tk_var.get()
    168          return self.meta_params.pre_stim_sec + self.meta_params.stim_sec + self.meta_params.post_stim_sec
    169
    170  if __name__=='__main__':
    171      frame = SphereGratingControlFrame()
    172      frame.pack(expand=1,fill=Tkinter.BOTH)
    173      frame.winfo_toplevel().title("%s"%(os.path.basename(os.path.splitext(sys.argv[0])[0]),))
    174      frame.mainloop()
    175