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

# Source Code for Module VisionEgg.PyroApps.DropinGUI

      1  # The Vision Egg: DropinGUI
      2  #
      3  # Copyright (C) 2004 Imran S. Ali, Lachlan Dowd, Andrew Straw
      4  # Copyright (C) 2004 California Institute of Technology
      5  #
      6  # Authors: Imran S. Ali, Lachlan Dowd, Andrew Straw
      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  import VisionEgg, string
     15  import sys, os
     16  import Tkinter
     17  import tkMessageBox
     18  import VisionEgg.PyroApps.VarTypes as VarTypes
     19  import VisionEgg.PyroApps.EPhysGUIUtils as client_utils
     20
     21 -def get_control_list():
     22     return [("dropin_server",DropinControlFrame,DropinControlFrame.title)]
     23
     24 -class DropinMetaParameters:
     25 -   def __init__(self):
     26        self.vars_list = []
     27
     28 -class DropinControlFrame(client_utils.StimulusControlFrame):
     29     title = "Vision Egg Script"
     30
     31 -   def __init__(self, master=None, suppress_go_buttons=0,**kw):
     32        client_utils.StimulusControlFrame.__init__(self,
     33                                                   master,
     34                                                   suppress_go_buttons,
     35                                                   DropinControlFrame.title,
     36                                                   DropinMetaParameters,
     37                                                   **kw)
     38
     39        param_frame = self.param_frame # shorthand for self.param_frame created in base class
     40        param_frame.columnconfigure(0,weight=1)
     41        param_frame.columnconfigure(1,weight=1)
     42        self.vars_list = []
     43        self.error_names = []
     44
     45 -   def get_shortname(self):
     46        return "dropin"
     47
     48 -   def update_tk_vars(self):
     49        pass
     50
     51
     52 -   def send_values(self,dummy_arg=None):
     53
     54        self.meta_params.vars_list = []
     55        self.error_names = []
     56
     57        if self.vars_list is None:
     58           return 0
     59
     60        for var in self.vars_list:
     61           if len(var) == 3:
     62              var_type = var[0]
     63              var_name = var[1]
     64              var_val_holder = var[2]
     65              var_val = var_val_holder.get()
     66              try:
     67                 if var_val == "compound":
     68                    pass
     69                 else:
     70                    if VarTypes.getType(var_type) == "float":
     71                       var_typed_val = float(var_val)
     72                    elif VarTypes.getType(var_type) == "integer":
     73                       var_typed_val = int(float(var_val))
     74                    elif VarTypes.getType(var_type) == "string":
     75                       var_typed_val = var_val
     76                    else:
     77                       raise ValueError()
     78                    self.meta_params.vars_list.append([var_name, var_typed_val])
     79              except ValueError:
     80                 self.error_names.append(var_name)
     81
     82
     83
     84        if len(self.error_names) == 0:
     85           self.meta_controller.set_parameters( self.meta_params )
     86           return 1
     87        else:
     88           all_error_names = "Invalid value(s) for the following variable(s):\n"
     89           for error_name in self.error_names:
     90              all_error_names = all_error_names + error_name + "\n"
     91           tkMessageBox.showerror("Invalid value(s)", all_error_names)
     92           return 0
     93
     94 -   def get_duration_sec(self):
     95        # XXX not implemented yet
     96        return -1
     97
     98     # Creates the variable Entry and Label widgets:
     99 -   def gen_var_widgets(self, demoscript_filename, vars_list):
    100        self.vars_list = vars_list
    101        param_frame = self.param_frame # shorthand for self.param_frame created in base class
    102        if demoscript_filename is None:
    103           label = "No demo file loaded"
    104        else:
    105           label = demoscript_filename
    106        Tkinter.Label(param_frame,
    107                      text=label,
    108                      font=("Helvetica",8,"bold")).grid(row=0,columnspan=2)
    109        row_num = 1
    110
    111        if self.vars_list is None:
    112           return
    113        for var in self.vars_list:
    114           var_label = Tkinter.Label(param_frame,text=var[1]).grid(row=row_num,column=0)
    115           # Create a Tkinter string variable holder:
    116           var_val_holder = Tkinter.StringVar()
    117           # Set to its value:
    118           var_val_holder.set(var[2])
    119           # Create (indirectly) Entry widgets:
    120           # Render variables which were "not found" as non-modifiable for user:
    121           if var[2] == "not found":
    122              self.make_callback_entry(textvariable=var_val_holder, state="disabled").grid(row=row_num,column=1)
    123              del var[2]
    124           else:
    125              self.make_callback_entry(textvariable=var_val_holder).grid(row=row_num,column=1)
    126              var[2] = var_val_holder
    127           row_num = row_num + 1
    128
    129  if __name__=='__main__':
    130     frame = DropinControlFrame()
    131     frame.pack(expand=1,fill=Tkinter.BOTH)
    132     frame.winfo_toplevel().title("%s"%(os.path.basename(os.path.splitext(sys.argv[0])[0]),))
    133     frame.mainloop()
    134