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

# Source Code for Module VisionEgg.PyroApps.MouseTargetGUI

     1  #!/usr/bin/env python
     2  #
     3  # The Vision Egg: MouseTargetGUI
     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 mouse controlled small target stimulus (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 [("mouse_target_server",MouseTargetControlFrame,MouseTargetControlFrame.title)]
    28
    29 -class MouseTargetMetaParameters:
    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 -class MouseTargetControlFrame(client_utils.StimulusControlFrame):
    36      title = "Mouse Controlled Moving Target"
    37 -    def __init__(self, master=None, suppress_go_buttons=0,**kw):
    38          client_utils.StimulusControlFrame.__init__(self,
    39                                                     master,
    40                                                     suppress_go_buttons,
    41                                                     MouseTargetControlFrame.title,
    42                                                     MouseTargetMetaParameters,
    43                                                     **kw)
    44
    45          param_frame = self.param_frame # shorthand for self.param_frame created in base class
    46
    47          # Allow columns to expand
    48          param_frame.columnconfigure(0,weight=1)
    49          param_frame.columnconfigure(1,weight=1)
    50
    51          pf_row = 0
    52          Tkinter.Label(param_frame,text="Color:").grid(row=pf_row,column=0)
    53          self.color_tk_var = Tkinter.StringVar()
    54          self.color_tk_var.set("black on white")
    55          bar = Tkinter.Menubutton(param_frame, textvariable=self.color_tk_var, relief=Tkinter.RAISED)
    56          bar.grid(row=pf_row, column=2, sticky=Tkinter.W+Tkinter.E, pady=2, padx=2)
    57          bar.menu = Tkinter.Menu(bar,tearoff=0)
    58          bar.menu.add_radiobutton(label="white on black",
    59                                   value="white on black",
    60                                   variable=self.color_tk_var,
    61                                   command=self.send_values)
    62          bar.menu.add_radiobutton(label="black on white",
    63                                   value="black on white",
    64                                   variable=self.color_tk_var,
    65                                   command=self.send_values)
    66          bar['menu'] = bar.menu
    67
    68 -    def get_shortname(self):
    69          return "mouse_target"
    70
    71 -    def update_tk_vars(self):
    72          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):
    73              self.color_tk_var.set( "black on white" )
    74          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):
    75              self.color_tk_var.set( "white on black" )
    76          else:
    77              raise RuntimeError("Cannot set tk variable for color")
    78
    79 -    def send_values(self,dummy_arg=None):
    80          if self.color_tk_var.get() == "black on white":
    81              self.meta_params.color = (0.0,0.0,0.0,1.0)
    82              self.meta_params.bgcolor = (1.0,1.0,1.0,0.0)
    83          elif self.color_tk_var.get() == "white on black":
    84              self.meta_params.color = (1.0,1.0,1.0,1.0)
    85              self.meta_params.bgcolor = (0.0,0.0,0.0,0.0)
    86
    87          if self.connected:
    88              self.meta_controller.set_parameters( self.meta_params )
    89
    90 -    def get_duration_sec(self):
    91          return 0.0
    92
    93  if __name__=='__main__':
    94      frame = MouseTargetControlFrame()
    95      frame.pack(expand=1,fill=Tkinter.BOTH)
    96      frame.winfo_toplevel().title("%s"%(os.path.basename(os.path.splitext(sys.argv[0])[0]),))
    97      frame.mainloop()
    98