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

# Source Code for Module VisionEgg.PyroApps.FlatGratingGUI

      1  #!/usr/bin/env python
      2  #
      3  # The Vision Egg: FlatGratingGUI
      4  #
      5  # Copyright (C) 2001-2003 Andrew Straw.
      6  # Author: Andrew Straw <astraw@users.sourceforge.net>
      7  # URL: <http://www.visionegg.org/>
      8  #
      9  # Distributed under the terms of the GNU Lesser General Public License
     10  # (LGPL). See LICENSE.TXT that came with this file.
     11  #
     12  # $Id$
     13
     14  """Handle sinusoidal gratings (client-side)"""
     15
     16  import VisionEgg, string
     17  __version__ = VisionEgg.release_name
     18  __cvs__ = string.split('$Revision$')[1]
     19  __date__ = string.join(string.split('$Date$')[1:3], ' ')
     20  __author__ = 'Andrew Straw <astraw@users.sourceforge.net>'
     21
     22  import sys, os
     23  import Tkinter
     24  import VisionEgg.PyroApps.EPhysGUIUtils as client_utils
     25
     26 -def get_control_list():
     27      return [("flat_grating_server",FlatGratingControlFrame,FlatGratingControlFrame.title)]
     28
     29 -class FlatGratingMetaParameters:
     30 -    def __init__(self):
     31          self.contrast = 1.0
     32          self.orient = 0.0
     33          self.sf = 0.01 # cycles per pixel
     34          self.tf = 1.0
     35          self.size_x = 200.0
     36          self.size_y = 200.0
     37          self.center_x = 320.0
     38          self.center_y = 240.0
     39          self.pre_stim_sec = 1.0
     40          self.stim_sec = 2.0
     41          self.post_stim_sec = 1.0
     42
     43 -class FlatGratingControlFrame(client_utils.StimulusControlFrame):
     44      title = "Grating (2D) Experiment"
     45 -    def __init__(self, master=None, suppress_go_buttons=0,**kw):
     46          client_utils.StimulusControlFrame.__init__(self,
     47                                                     master,
     48                                                     suppress_go_buttons,
     49                                                     FlatGratingControlFrame.title,
     50                                                     FlatGratingMetaParameters,
     51                                                     **kw)
     52
     53          param_frame = self.param_frame # shorthand for self.param_frame created in base class
     54
     55          # Allow columns to expand
     56          param_frame.columnconfigure(0,weight=1)
     57          param_frame.columnconfigure(1,weight=1)
     58
     59          pf_row = 0
     60          Tkinter.Label(param_frame,text="Contrast:").grid(row=pf_row,column=0)
     61          self.contrast_tk_var = Tkinter.DoubleVar()
     62          self.contrast_tk_var.set(self.meta_params.contrast)
     63          self.make_callback_entry(textvariable=self.contrast_tk_var).grid(row=pf_row,column=1)
     64          self.loopable_variables["Contrast"] = ("contrast",self.contrast_tk_var)
     65
     66          pf_row += 1
     67          Tkinter.Label(param_frame,text="Orientation (deg):").grid(row=pf_row,column=0)
     68          self.orient_tk_var = Tkinter.DoubleVar()
     69          self.orient_tk_var.set(self.meta_params.orient)
     70          self.make_callback_entry(textvariable=self.orient_tk_var).grid(row=pf_row,column=1)
     71          self.loopable_variables["Orientation"] = ("orient",self.orient_tk_var)
     72
     73          pf_row += 1
     74          Tkinter.Label(param_frame,text="Spatial frequency (Cpp):").grid(row=pf_row,column=0)
     75          self.sf_tk_var = Tkinter.DoubleVar()
     76          self.sf_tk_var.set(self.meta_params.sf)
     77          self.make_callback_entry(textvariable=self.sf_tk_var).grid(row=pf_row,column=1)
     78          self.loopable_variables["Spatial frequency"] = ("sf",self.sf_tk_var)
     79
     80          pf_row += 1
     81          Tkinter.Label(param_frame,text="Temporal frequency (Hz):").grid(row=pf_row,column=0)
     82          self.tf_tk_var = Tkinter.DoubleVar()
     83          self.tf_tk_var.set(self.meta_params.tf)
     84          self.make_callback_entry(textvariable=self.tf_tk_var).grid(row=pf_row,column=1)
     85          self.loopable_variables["Temporal frequency"] = ("tf",self.tf_tk_var)
     86
     87          pf_row += 1
     88          Tkinter.Label(param_frame,text="Size X (pixels):").grid(row=pf_row,column=0)
     89          self.size_x_tk_var = Tkinter.DoubleVar()
     90          self.size_x_tk_var.set(self.meta_params.size_x)
     91          self.make_callback_entry(textvariable=self.size_x_tk_var).grid(row=pf_row,column=1)
     92          self.loopable_variables["Size X"] = ("size_x",self.size_x_tk_var)
     93
     94          pf_row += 1
     95          Tkinter.Label(param_frame,text="Size Y (pixels):").grid(row=pf_row,column=0)
     96          self.size_y_tk_var = Tkinter.DoubleVar()
     97          self.size_y_tk_var.set(self.meta_params.size_y)
     98          self.make_callback_entry(textvariable=self.size_y_tk_var).grid(row=pf_row,column=1)
     99          self.loopable_variables["Size Y"] = ("size_y",self.size_y_tk_var)
    100
    101          pf_row += 1
    102          Tkinter.Label(param_frame,text="Center X (pixels):").grid(row=pf_row,column=0)
    103          self.center_x_tk_var = Tkinter.DoubleVar()
    104          self.center_x_tk_var.set(self.meta_params.center_x)
    105          self.make_callback_entry(textvariable=self.center_x_tk_var).grid(row=pf_row,column=1)
    106          self.loopable_variables["Center X"] = ("center_x",self.center_x_tk_var)
    107
    108          pf_row += 1
    109          Tkinter.Label(param_frame,text="Center Y (pixels):").grid(row=pf_row,column=0)
    110          self.center_y_tk_var = Tkinter.DoubleVar()
    111          self.center_y_tk_var.set(self.meta_params.center_y)
    112          self.make_callback_entry(textvariable=self.center_y_tk_var).grid(row=pf_row,column=1)
    113          self.loopable_variables["Center Y"] = ("center_y",self.center_y_tk_var)
    114
    115          pf_row += 1
    116          Tkinter.Label(param_frame,text="Pre stimulus duration (sec):").grid(row=pf_row,column=0)
    117          self.prestim_dur_tk_var = Tkinter.DoubleVar()
    118          self.prestim_dur_tk_var.set(self.meta_params.pre_stim_sec)
    119          self.make_callback_entry(textvariable=self.prestim_dur_tk_var).grid(row=pf_row,column=1)
    120
    121          pf_row += 1
    122          Tkinter.Label(param_frame,text="Stimulus duration (sec):").grid(row=pf_row,column=0)
    123          self.stim_dur_tk_var = Tkinter.DoubleVar()
    124          self.stim_dur_tk_var.set(self.meta_params.stim_sec)
    125          self.make_callback_entry(textvariable=self.stim_dur_tk_var).grid(row=pf_row,column=1)
    126
    127          pf_row += 1
    128          Tkinter.Label(param_frame,text="Post stimulus duration (sec):").grid(row=pf_row,column=0)
    129          self.poststim_dur_tk_var = Tkinter.DoubleVar()
    130          self.poststim_dur_tk_var.set(self.meta_params.post_stim_sec)
    131          self.make_callback_entry(textvariable=self.poststim_dur_tk_var).grid(row=pf_row,column=1)
    132
    133 -    def get_shortname(self):
    134          return "flat_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.size_x_tk_var.set( self.meta_params.size_x )
    142          self.size_y_tk_var.set( self.meta_params.size_y )
    143          self.center_x_tk_var.set( self.meta_params.center_x )
    144          self.center_y_tk_var.set( self.meta_params.center_y )
    145          self.prestim_dur_tk_var.set( self.meta_params.pre_stim_sec )
    146          self.stim_dur_tk_var.set( self.meta_params.stim_sec )
    147          self.poststim_dur_tk_var.set( self.meta_params.post_stim_sec )
    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.size_x = self.size_x_tk_var.get()
    155          self.meta_params.size_y = self.size_y_tk_var.get()
    156          self.meta_params.center_x = self.center_x_tk_var.get()
    157          self.meta_params.center_y = self.center_y_tk_var.get()
    158          self.meta_params.pre_stim_sec = self.prestim_dur_tk_var.get()
    159          self.meta_params.stim_sec = self.stim_dur_tk_var.get()
    160          self.meta_params.post_stim_sec = self.poststim_dur_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 = FlatGratingControlFrame()
    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