VisionEgg.PyroApps.TargetGUI

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

# Source Code for Module VisionEgg.PyroApps.TargetGUI

      1  #!/usr/bin/env python
      2  #
      3  # The Vision Egg: TargetGUI
      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 small target stimulus (client-side)"""
     15
     16  import VisionEgg
     17  __version__ = VisionEgg.release_name
     18  __cvs__ = '$Revision$'.split()[1]
     19  __date__ = ' '.join('$Date$'.split()[1:3])
     20  __author__ = 'Andrew Straw <astraw@users.sourceforge.net>'
     21
     22  import sys, os, math
     23  import Tkinter
     24  import VisionEgg.PyroApps.EPhysGUIUtils as client_utils
     25
     26 -def get_control_list():
     27      return [("target_server",TargetControlFrame,TargetControlFrame.title)]
     28
     29 -class TargetMetaParameters:
     30 -    def __init__(self):
     31          # colors
     32          self.color = (0.0, 0.0, 0.0, 1.0)
     33          self.bgcolor = (1.0, 1.0, 1.0, 0.0)
     34
     35          # motion parameters
     36          self.start_x = 10.0
     37          self.start_y = 50.0
     38          self.velocity_pps = 100.0 # pixels per second
     39          self.direction_deg = 0.0
     40
     41          # size and orientation
     42          self.width = 10.0
     43          self.height = 30.0
     44          self.orientation_deg = 0.0
     45
     46          self.pre_stim_sec = 1.0
     47          self.stim_sec = 2.0
     48          self.post_stim_sec = 1.0
     49
     50 -class TargetControlFrame(client_utils.StimulusControlFrame):
     51      title = "Moving Target Experiment"
     52 -    def __init__(self, master=None, suppress_go_buttons=0,**kw):
     53          client_utils.StimulusControlFrame.__init__(self,
     54                                                     master,
     55                                                     suppress_go_buttons,
     56                                                     TargetControlFrame.title,
     57                                                     TargetMetaParameters,
     58                                                     **kw)
     59
     60          param_frame = self.param_frame # shorthand for self.param_frame created in base class
     61
     62          pf_row = 0
     63          Tkinter.Label(param_frame,text="Start X (pixels):").grid(row=pf_row,column=0,sticky=Tkinter.E)
     64          self.start_x_tk_var = Tkinter.DoubleVar()
     65          self.start_x_tk_var.set(self.meta_params.start_x)
     66          self.make_callback_entry(textvariable=self.start_x_tk_var).grid(row=pf_row,column=2)
     67          self.loopable_variables["Start X"] = ("start_x",self.start_x_tk_var)
     68
     69          pf_row += 1
     70          Tkinter.Label(param_frame,text="Start Y (pixels):").grid(row=pf_row,column=0,sticky=Tkinter.E)
     71          self.start_y_tk_var = Tkinter.DoubleVar()
     72          self.start_y_tk_var.set(self.meta_params.start_y)
     73          self.make_callback_entry(textvariable=self.start_y_tk_var).grid(row=pf_row,column=2)
     74          self.loopable_variables["Start Y"] = ("start_y",self.start_y_tk_var)
     75
     76          pf_row += 1
     77          Tkinter.Label(param_frame,text="Velocity (pixels/sec):").grid(row=pf_row,column=0,sticky=Tkinter.E)
     78          self.velocity_tk_var = Tkinter.DoubleVar()
     79          self.velocity_tk_var.set(self.meta_params.velocity_pps)
     80          self.make_callback_entry(textvariable=self.velocity_tk_var).grid(row=pf_row,column=2)
     81          self.loopable_variables["Velocity"] = ("velocity_pps",self.velocity_tk_var)
     82
     83          pf_row += 1
     84          Tkinter.Label(param_frame,text="Direction (degrees):").grid(row=pf_row,column=0,sticky=Tkinter.E)
     85          self.direction_tk_var = Tkinter.DoubleVar()
     86          self.direction_tk_var.set(self.meta_params.direction_deg)
     87          self.make_callback_entry(textvariable=self.direction_tk_var).grid(row=pf_row,column=2)
     88          self.loopable_variables["Direction"] = ("direction_deg",self.direction_tk_var)
     89
     90          pf_row += 1
     91          Tkinter.Label(param_frame,text="Color:").grid(row=pf_row,column=0,sticky=Tkinter.E)
     92          self.color_tk_var = Tkinter.StringVar()
     93          self.color_tk_var.set("black on white")
     94          bar = Tkinter.Menubutton(param_frame, textvariable=self.color_tk_var, relief=Tkinter.RAISED)
     95          bar.grid(row=pf_row, column=2, sticky=Tkinter.W+Tkinter.E, pady=2, padx=2)
     96          bar.menu = Tkinter.Menu(bar,tearoff=0)
     97          bar.menu.add_radiobutton(label="white on black",
     98                                   value="white on black",
     99                                   variable=self.color_tk_var,
    100                                   command=self.send_values)
    101          bar.menu.add_radiobutton(label="black on white",
    102                                   value="black on white",
    103                                   variable=self.color_tk_var,
    104                                   command=self.send_values)
    105          bar['menu'] = bar.menu
    106
    107          pf_row += 1
    108          Tkinter.Label(param_frame,text="Orientation (degrees):").grid(row=pf_row,column=0,sticky=Tkinter.E)
    109          self.ortho_tk_var = Tkinter.StringVar()
    110          self.ortho_tk_var.set("ortho")
    111
    112          manual = Tkinter.Radiobutton( param_frame, text="Manual",
    113                                        variable=self.ortho_tk_var, value="manual")
    114          manual.grid(row=pf_row,column=1)
    115
    116          self.orient_tk_var = Tkinter.DoubleVar()
    117          self.orient_tk_var.set(self.meta_params.orientation_deg)
    118
    119          manual_entry = Tkinter.Entry( param_frame,
    120                                        textvariable=self.orient_tk_var,
    121                                        width=self.entry_width )
    122          manual_entry.grid(row=pf_row,column=2)
    123
    124          ortho = Tkinter.Radiobutton( param_frame, text="Orthogonal to motion",
    125                                       variable=self.ortho_tk_var, value="ortho")
    126          ortho.grid(row=pf_row,column=3)
    127          self.loopable_variables["Orientation"] = ("orientation_deg",self.orient_tk_var)
    128
    129          pf_row += 1
    130          Tkinter.Label(param_frame,text="Width (pixels):").grid(row=pf_row,column=0,sticky=Tkinter.E)
    131          self.width_tk_var = Tkinter.DoubleVar()
    132          self.width_tk_var.set(self.meta_params.width)
    133          self.make_callback_entry(textvariable=self.width_tk_var).grid(row=pf_row,column=2)
    134          self.loopable_variables["Width"] = ("width",self.width_tk_var)
    135
    136          pf_row += 1
    137          Tkinter.Label(param_frame,text="Height (pixels):").grid(row=pf_row,column=0,sticky=Tkinter.E)
    138          self.height_tk_var = Tkinter.DoubleVar()
    139          self.height_tk_var.set(self.meta_params.height)
    140          self.make_callback_entry(textvariable=self.height_tk_var).grid(row=pf_row,column=2)
    141          self.loopable_variables["Height"] = ("height",self.height_tk_var)
    142
    143          pf_row += 1
    144          Tkinter.Label(param_frame,text="Pre stimulus duration (sec):").grid(row=pf_row,column=0,sticky=Tkinter.E)
    145          self.prestim_dur_tk_var = Tkinter.DoubleVar()
    146          self.prestim_dur_tk_var.set(self.meta_params.pre_stim_sec)
    147          self.make_callback_entry(textvariable=self.prestim_dur_tk_var).grid(row=pf_row,column=2)
    148
    149          pf_row += 1
    150          Tkinter.Label(param_frame,text="Stimulus duration (sec):").grid(row=pf_row,column=0,sticky=Tkinter.E)
    151          self.stim_dur_tk_var = Tkinter.DoubleVar()
    152          self.stim_dur_tk_var.set(self.meta_params.stim_sec)
    153          self.make_callback_entry(textvariable=self.stim_dur_tk_var).grid(row=pf_row,column=2)
    154          self.loopable_variables["Duration"] = ("stim_sec",self.stim_dur_tk_var)
    155
    156          pf_row += 1
    157          Tkinter.Label(param_frame,text="Post stimulus duration (sec):").grid(row=pf_row,column=0,sticky=Tkinter.E)
    158          self.poststim_dur_tk_var = Tkinter.DoubleVar()
    159          self.poststim_dur_tk_var.set(self.meta_params.post_stim_sec)
    160          self.make_callback_entry(textvariable=self.poststim_dur_tk_var).grid(row=pf_row,column=2)
    161
    162 -    def get_shortname(self):
    163          return "target"
    164
    165 -    def update_tk_vars(self):
    166          self.start_x_tk_var.set( self.meta_params.start_x )
    167          self.start_y_tk_var.set( self.meta_params.start_y )
    168          self.velocity_tk_var.set( self.meta_params.velocity_pps )
    169          self.direction_tk_var.set( self.meta_params.direction_deg )
    170          self.orient_tk_var.set( self.meta_params.orientation_deg )
    171          self.width_tk_var.set( self.meta_params.width )
    172          self.height_tk_var.set( self.meta_params.height )
    173          self.prestim_dur_tk_var.set( self.meta_params.pre_stim_sec )
    174          self.stim_dur_tk_var.set( self.meta_params.stim_sec )
    175          self.poststim_dur_tk_var.set( self.meta_params.post_stim_sec )
    176
    177          if self.meta_params.color == (0.0,0.0,0.0,1.0) and self.meta_params.bgcolor == (1.0,1.0,1.0,0.0):
    178              self.color_tk_var.set( "black on white" )
    179          elif self.meta_params.color == (1.0,1.0,1.0,1.0) and self.meta_params.bgcolor == (0.0,0.0,0.0,0.0):
    180              self.color_tk_var.set( "white on black" )
    181          else:
    182              raise RuntimeError("Cannot set tk variable for color")
    183
    184 -    def send_values(self,dummy_arg=None):
    185          self.meta_params.start_x = self.start_x_tk_var.get()
    186          self.meta_params.start_y = self.start_y_tk_var.get()
    187          self.meta_params.velocity_pps = self.velocity_tk_var.get()
    188          self.meta_params.direction_deg = self.direction_tk_var.get()
    189          if self.color_tk_var.get() == "black on white":
    190              self.meta_params.color = (0.0,0.0,0.0,1.0)
    191              self.meta_params.bgcolor = (1.0,1.0,1.0,0.0)
    192          elif self.color_tk_var.get() == "white on black":
    193              self.meta_params.color = (1.0,1.0,1.0,1.0)
    194              self.meta_params.bgcolor = (0.0,0.0,0.0,0.0)
    195
    196          if self.ortho_tk_var.get() == "ortho":
    197              self.meta_params.orientation_deg = math.fmod(self.meta_params.direction_deg,360.0)
    198          else: # it's "manual"
    199              self.meta_params.orientation_deg = self.orient_tk_var.get()
    200          self.meta_params.width = self.width_tk_var.get()
    201          self.meta_params.height = self.height_tk_var.get()
    202          self.meta_params.pre_stim_sec = self.prestim_dur_tk_var.get()
    203          self.meta_params.stim_sec = self.stim_dur_tk_var.get()
    204          self.meta_params.post_stim_sec = self.poststim_dur_tk_var.get()
    205          if self.connected:
    206              self.meta_controller.set_parameters( self.meta_params )
    207
    208 -    def get_duration_sec(self):
    209          self.meta_params.pre_stim_sec = self.prestim_dur_tk_var.get()
    210          self.meta_params.stim_sec = self.stim_dur_tk_var.get()
    211          self.meta_params.post_stim_sec = self.poststim_dur_tk_var.get()
    212          return self.meta_params.pre_stim_sec + self.meta_params.stim_sec + self.meta_params.post_stim_sec
    213
    214  if __name__=='__main__':
    215      frame = TargetControlFrame()
    216      frame.pack(expand=Tkinter.YES,fill=Tkinter.BOTH)
    217      frame.winfo_toplevel().title("%s"%(os.path.basename(os.path.splitext(sys.argv[0])[0]),))
    218      frame.mainloop()
    219