예제 #1
0
def evt_enter_variable( parent, event ):
   a = b = parent.panelSV.tin4.get()
   parent.panelSV.lab1.configure(text = "Select Variable")
   if a.find('- [') != -1:
      a=a[:a.find('- [')]
   if a.find('(') !=-1:
      a = a[:a.rfind('(')-1]
   parent.panelSV.tin4.setentry( a )
   if parent.startusertask == 1: gui_control.track_user( parent, "Variable: %s" % a)
   #
   if ( (a[17:] in ['Variable List *************']) or (a in ['******** Bounds and Weights List ******', '*************** Axes List **************']) ):
     parent.panelSV.tin4.setentry( '' )
     gui_functions._blank_dim1_to_ndim( parent )
     parent.panelDM.var3 = parent.panelDM.remember_var3 = None
     return
   parent.panelDM.var3 = parent.panelDM.remember_var3 = a
   #
   parent.panelSV.tin4.first_time = 0
   #
   var_list = parent.panelSV.tin4._list.get(None)
   found = 0
   for j in range(len(var_list)):
      n = len(a)
      if a+' '==var_list[j][:n+1]:
         found = 1
         break
##          if var_list[j].find('(') == -1:
##             if a == var_list[j]: 
##                found = 1
##                break
##          else:
##             if a == var_list[j][:var_list[j].find('(')-1]: 
##                found = 1
##                break
##          j = j + 1
   if found == 0:
      gui_message.error('Variable [ ++%s++ ] cannot be found in the file.' % a)
      parent.panelSV.tin4.setentry( '' )
      gui_functions._blank_dim1_to_ndim( parent )
      parent.panelDM.var3 = parent.panelDM.remember_var3 = None
      return
   #
   parent.panelVI.lst1 = gui_functions._scn_a_var( parent, a )
   parent.panelVI.scl1.settext( parent.panelVI.lst1 )

   # Blank the dimension's window
   gui_functions._blank_dim1_to_ndim( parent )

   # Reset selection counters back to initial state, (e.g., '00 ')
   if parent.panelDV.lst1 != {}:
      for x in parent.panelDV.lst1.keys():
          parent.panelDV.number_lst1[ x ] = gui_control.dvholder + x
      gui_defined_variables.update_defined_variable_list( parent )

   gui_functions._srl_var_dim1_to_ndim( parent )
   for k in range(parent.panelDM.ndim):
      parent.panelDM.dim[k].comb.component('entry').configure(background = gui_color.dim )
      parent.panelDM.dim[k].first_scl.configure( troughcolor=gui_color.dim )
      parent.panelDM.dim[k].last_scl.configure( troughcolor=gui_color.dim )
   #
   parent.panelDV.scl1.select_clear( 0, 'end' )
   parent.panelDV.selected_list = {}
   #
   parent.panelSV.lab1.configure(text = "Selected Variable -- %s" % b)
예제 #2
0
       root.geometry(pos)

    root.deiconify() 
    root.update()
    root.lift()
    if len(sys.argv)>1:
       pth, f = os.path.split(sys.argv[1])
       if pth == '' : pth='.'
       root.panelSV.tin2.setentry(pth)
       gui_select_variable.evt_enter_directory(root,None)
       root.panelSV.tin3.selectitem(f)
       gui_select_variable.evt_enter_file(root,None)
       if len(sys.argv)>2:
          root.panelSV.tin4.setentry(sys.argv[2])
          gui_select_variable.evt_enter_variable(root,None)

    root.mainloop()
    if root.startusertask == 1:
       gui_control.track_user( root, "#______________________________________________________________________________")
       gui_control.track_user( root, "End Session Time: %s" % time.asctime())
       gui_control.track_user( root, "Total Session Wall-Clock Time in Minutes: %g" % ((int(time.time()-startwalltime))/60.0))
       gui_control.track_user( root, "Total Session Processor Time in Minutes: %g" % ((int(time.clock()-startcputime))/60.0))

if __name__ == "__main__":
    main()

#---------------------------------------------------------------------
# End of File
#---------------------------------------------------------------------

예제 #3
0
def evt_enter_file( parent, event ):
   a = parent.panelSV.tin3.get()

   # Must close some files (like DRS) before you can open it again
   try: parent.panelDM.fid2.close()
   except: pass
   
   if parent.startusertask == 1: gui_control.track_user( parent, "File: %s" % a)
   if gui_control.directory_or_database == 'directory':
      if a[:7]!="http://":
         d,f = gui_functions._scn_a_dir( parent )     # re-write the new directory information and save directory list
         #
         parent.panelSV.tin3.first_time = 0
         #
         found = 0
         for i in range(len(f)):
            if (f[i] == a):
               try:
                  parent.panelDM.fid2 = cdms2.open( a ) 
                  #
                  # record the event: select a file to be opened
                  gui_control.record_command( parent, '\n# Open CDMS File', 1 )
                  command = "fid2 = cdms2.open( '%s/%s' )" % (os.getcwd(), a)
                  gui_control.record_command( parent, command, 1 )
                  found = 1
               except:
                  found = 0
                  gui_message.error('Cannot open data file [%s].' % a)
                  return
               gui_functions._srl_file_var( parent )
               gui_functions._blank_dim1_to_ndim( parent )
               break
         if found == 0:
             gui_message.error("Invalid file name.")
         else:
            if ( (parent.panelSV.tin4.first_time != 1) and
                 (parent.panelDM.lst3 != []) and
                 (len(parent.panelDM.lst3[0]) > 0) ):
               pass
               #parent.panelSV.tin4.setentry( parent.panelDM.lst3[0] )
               #evt_enter_variable( parent, None )
      else:
         try:
            parent.panelDM.fid2 = cdms2.open( a ) 
            #
            # record the event: select a file to be opened
            gui_control.record_command( parent, '\n# Open CDMS File', 1 )
            command = "fid2 = cdms2.open( '%s' )" % (a)
            gui_control.record_command( parent, command, 1 )
         except:
            import cdat_info
            if cdat_info.CDMS_INCLUDE_DAP=='yes':
               gui_message.error('Cannot open data file [%s].' % a)
               return
            else:
               gui_message.error('Your version of CDAT is not built with DAP support !')
               return
         gui_functions._srl_file_var( parent )
         gui_functions._blank_dim1_to_ndim( parent )
            
   else:
      f = parent.panelSV.tin3.ds_list
      found = 0
      for i in range(len(f)):
         if (f[i] == a):
            try:
               parent.panelDM.fid2 = parent.panelDM.lst2 = gui_control.db.open( a ) 
            except:
               gui_message.error('Cannot open database file [%s].' % a)
            #parent.panelDM.lst2 = parent.panelDM.fid2
            gui_functions._srl_file_var( parent )
            gui_functions._blank_dim1_to_ndim( parent )
            found = 1
            break
      if found == 0:
         gui_message.error("Invalid file name.")
예제 #4
0
def evt_enter_directory( parent, event, who_called=0 ):
   # change backgound color to white
   parent.panelSV.tin2.configure( entry_background = 'white' )
   #
   Match_found = None
   if gui_control.directory_or_database == 'directory':
      if type(event) == types.StringType:
            if event[0] == '/':
               a = event
            elif event[0:5] == '=====':
               a = os.getcwd()
            else:
               a = os.getcwd() + '/' + event
      else:
         a = parent.panelSV.tin2.get()
         # Add tilde function to entry window
         if a == '~':
           a = os.environ['HOME']
         elif a[0:2] == '~/':
           a = os.environ['HOME'] + '/' + a[2:]
         elif a[0] == '~':
           a = os.environ['HOME'] + '/' + a[1:]
         a = a + '/'
      try:
         os.chdir( a )
      except:
         gui_message.error(('Cannot access directory [ %s ].' % a))
      a=a[0:-1]

      if parent.startusertask == 1: gui_control.track_user( parent, "Directory: %s" % a)

      parent.panelSV.tin2.clear( )		# clear "directory" combo box entry and list
      if parent.panelSV.tin3.first_time == 1:
         parent.panelSV.tin3.delete(0, 'end')	# clear only the "file" combo box list
      else:
         parent.panelSV.tin3.clear( )	        # clear "file" combo box entry and list
      if parent.panelSV.tin4.first_time == 1:
         parent.panelSV.tin4.delete(0, 'end')	# clear only the "variable" combo box list
      else:
         parent.panelSV.tin4.clear( )	        # clear "variable" combo box entry and list
      #
      if who_called != 1:
         t = os.getcwd()
      else:
         t = os.getcwd() + ' '
      parent.panelSV.tin2._entryfield.setentry( t )
      #
      d,f = gui_functions._scn_a_dir( parent )        # re-write the new directory information and save directory list
      gui_functions._scn_dir_history( parent, t )      # store access directory information to the history directory list
      for j in range(len( parent.dir_history )): parent.panelSV.tin2.insert( j, parent.dir_history[j] )
      for i in range(len(d)): parent.panelSV.tin2.insert( j+i+1, d[i] )
      #
      for i in range(len(f)): parent.panelSV.tin3.insert( i, f[i] )
      #
      parent.panelDM.fid2 = None
      parent.panelDM.var3 = parent.panelDM.remember_var3 = None
      #
      gui_functions._blank_dim1_to_ndim( parent )
      #
      if (parent.panelSV.tin3.first_time != 1) and (len(f) > 0):
         parent.panelSV.tin3.setentry( f[0] )
         evt_enter_file( parent, None )
      #
      # record the event: select a directory
      command = "os.chdir( '%s' )" % os.getcwd()
      gui_control.record_command( parent, command )
   elif gui_control.directory_or_database == 'database':
      if event.keysym == 'Return':
         try:
            parent.parent.update()
            g_wait = gui_message.wait(parent.parent,'Please wait while the connection\n to the database is made.')
            gui_control.db=cdms2.connect( parent.parent.tin2.get() )
            parent.parent.update()
            g_wait.progress()
            for x in gui_control.db_connections:
               Match_found = re.match( parent.parent.tin2.get(), x )
               if Match_found: break
            if not Match_found:
               gui_control.db_connections.append( parent.parent.tin2.get() )
            parent.parent.panelC.scl1.setlist( gui_control.db_connections )
            db_list = gui_control.db.listDatasets()
            db_list.sort()
            parent.parent.panelC.scl2.setlist( db_list )
            parent.parent.panelC.scl3.setlist( '' )
            gui_functions._blank_dim1_to_ndim( parent )
            g_wait.execute()
         except:
            g_wait.execute()
            gui_message.error("Invalid database string.\nCould not connect to specified database.")
예제 #5
0
def evt_enter_variable(parent, event):
    a = b = parent.panelSV.tin4.get()
    parent.panelSV.lab1.configure(text="Select Variable")
    if a.find('- [') != -1:
        a = a[:a.find('- [')]
    if a.find('(') != -1:
        a = a[:a.rfind('(') - 1]
    parent.panelSV.tin4.setentry(a)
    if parent.startusertask == 1:
        gui_control.track_user(parent, "Variable: %s" % a)
    #
    if ((a[17:] in ['Variable List *************']) or (a in [
            '******** Bounds and Weights List ******',
            '*************** Axes List **************'
    ])):
        parent.panelSV.tin4.setentry('')
        gui_functions._blank_dim1_to_ndim(parent)
        parent.panelDM.var3 = parent.panelDM.remember_var3 = None
        return
    parent.panelDM.var3 = parent.panelDM.remember_var3 = a
    #
    parent.panelSV.tin4.first_time = 0
    #
    var_list = parent.panelSV.tin4._list.get(None)
    found = 0
    for j in range(len(var_list)):
        n = len(a)
        if a + ' ' == var_list[j][:n + 1]:
            found = 1
            break
##          if var_list[j].find('(') == -1:
##             if a == var_list[j]:
##                found = 1
##                break
##          else:
##             if a == var_list[j][:var_list[j].find('(')-1]:
##                found = 1
##                break
##          j = j + 1
    if found == 0:
        gui_message.error('Variable [ ++%s++ ] cannot be found in the file.' %
                          a)
        parent.panelSV.tin4.setentry('')
        gui_functions._blank_dim1_to_ndim(parent)
        parent.panelDM.var3 = parent.panelDM.remember_var3 = None
        return
    #
    parent.panelVI.lst1 = gui_functions._scn_a_var(parent, a)
    parent.panelVI.scl1.settext(parent.panelVI.lst1)

    # Blank the dimension's window
    gui_functions._blank_dim1_to_ndim(parent)

    # Reset selection counters back to initial state, (e.g., '00 ')
    if parent.panelDV.lst1 != {}:
        for x in parent.panelDV.lst1.keys():
            parent.panelDV.number_lst1[x] = gui_control.dvholder + x
        gui_defined_variables.update_defined_variable_list(parent)

    gui_functions._srl_var_dim1_to_ndim(parent)
    for k in range(parent.panelDM.ndim):
        parent.panelDM.dim[k].comb.component('entry').configure(
            background=gui_color.dim)
        parent.panelDM.dim[k].first_scl.configure(troughcolor=gui_color.dim)
        parent.panelDM.dim[k].last_scl.configure(troughcolor=gui_color.dim)
    #
    parent.panelDV.scl1.select_clear(0, 'end')
    parent.panelDV.selected_list = {}
    #
    parent.panelSV.lab1.configure(text="Selected Variable -- %s" % b)
예제 #6
0
def evt_enter_file(parent, event):
    a = parent.panelSV.tin3.get()

    # Must close some files (like DRS) before you can open it again
    try:
        parent.panelDM.fid2.close()
    except:
        pass

    if parent.startusertask == 1:
        gui_control.track_user(parent, "File: %s" % a)
    if gui_control.directory_or_database == 'directory':
        if a[:7] != "http://":
            d, f = gui_functions._scn_a_dir(
                parent
            )  # re-write the new directory information and save directory list
            #
            parent.panelSV.tin3.first_time = 0
            #
            found = 0
            for i in range(len(f)):
                if (f[i] == a):
                    try:
                        parent.panelDM.fid2 = cdms2.open(a)
                        #
                        # record the event: select a file to be opened
                        gui_control.record_command(parent,
                                                   '\n# Open CDMS File', 1)
                        command = "fid2 = cdms2.open( '%s/%s' )" % (
                            os.getcwd(), a)
                        gui_control.record_command(parent, command, 1)
                        found = 1
                    except:
                        found = 0
                        gui_message.error('Cannot open data file [%s].' % a)
                        return
                    gui_functions._srl_file_var(parent)
                    gui_functions._blank_dim1_to_ndim(parent)
                    break
            if found == 0:
                gui_message.error("Invalid file name.")
            else:
                if ((parent.panelSV.tin4.first_time != 1)
                        and (parent.panelDM.lst3 != [])
                        and (len(parent.panelDM.lst3[0]) > 0)):
                    pass
                    #parent.panelSV.tin4.setentry( parent.panelDM.lst3[0] )
                    #evt_enter_variable( parent, None )
        else:
            try:
                parent.panelDM.fid2 = cdms2.open(a)
                #
                # record the event: select a file to be opened
                gui_control.record_command(parent, '\n# Open CDMS File', 1)
                command = "fid2 = cdms2.open( '%s' )" % (a)
                gui_control.record_command(parent, command, 1)
            except:
                import cdat_info
                if cdat_info.CDMS_INCLUDE_DAP == 'yes':
                    gui_message.error('Cannot open data file [%s].' % a)
                    return
                else:
                    gui_message.error(
                        'Your version of CDAT is not built with DAP support !')
                    return
            gui_functions._srl_file_var(parent)
            gui_functions._blank_dim1_to_ndim(parent)

    else:
        f = parent.panelSV.tin3.ds_list
        found = 0
        for i in range(len(f)):
            if (f[i] == a):
                try:
                    parent.panelDM.fid2 = parent.panelDM.lst2 = gui_control.db.open(
                        a)
                except:
                    gui_message.error('Cannot open database file [%s].' % a)
                #parent.panelDM.lst2 = parent.panelDM.fid2
                gui_functions._srl_file_var(parent)
                gui_functions._blank_dim1_to_ndim(parent)
                found = 1
                break
        if found == 0:
            gui_message.error("Invalid file name.")
예제 #7
0
def evt_enter_directory(parent, event, who_called=0):
    # change backgound color to white
    parent.panelSV.tin2.configure(entry_background='white')
    #
    Match_found = None
    if gui_control.directory_or_database == 'directory':
        if type(event) == types.StringType:
            if event[0] == '/':
                a = event
            elif event[0:5] == '=====':
                a = os.getcwd()
            else:
                a = os.getcwd() + '/' + event
        else:
            a = parent.panelSV.tin2.get()
            # Add tilde function to entry window
            if a == '~':
                a = os.environ['HOME']
            elif a[0:2] == '~/':
                a = os.environ['HOME'] + '/' + a[2:]
            elif a[0] == '~':
                a = os.environ['HOME'] + '/' + a[1:]
            a = a + '/'
        try:
            os.chdir(a)
        except:
            gui_message.error(('Cannot access directory [ %s ].' % a))
        a = a[0:-1]

        if parent.startusertask == 1:
            gui_control.track_user(parent, "Directory: %s" % a)

        parent.panelSV.tin2.clear(
        )  # clear "directory" combo box entry and list
        if parent.panelSV.tin3.first_time == 1:
            parent.panelSV.tin3.delete(
                0, 'end')  # clear only the "file" combo box list
        else:
            parent.panelSV.tin3.clear(
            )  # clear "file" combo box entry and list
        if parent.panelSV.tin4.first_time == 1:
            parent.panelSV.tin4.delete(
                0, 'end')  # clear only the "variable" combo box list
        else:
            parent.panelSV.tin4.clear(
            )  # clear "variable" combo box entry and list
        #
        if who_called != 1:
            t = os.getcwd()
        else:
            t = os.getcwd() + ' '
        parent.panelSV.tin2._entryfield.setentry(t)
        #
        d, f = gui_functions._scn_a_dir(
            parent
        )  # re-write the new directory information and save directory list
        gui_functions._scn_dir_history(
            parent, t
        )  # store access directory information to the history directory list
        for j in range(len(parent.dir_history)):
            parent.panelSV.tin2.insert(j, parent.dir_history[j])
        for i in range(len(d)):
            parent.panelSV.tin2.insert(j + i + 1, d[i])
        #
        for i in range(len(f)):
            parent.panelSV.tin3.insert(i, f[i])
        #
        parent.panelDM.fid2 = None
        parent.panelDM.var3 = parent.panelDM.remember_var3 = None
        #
        gui_functions._blank_dim1_to_ndim(parent)
        #
        if (parent.panelSV.tin3.first_time != 1) and (len(f) > 0):
            parent.panelSV.tin3.setentry(f[0])
            evt_enter_file(parent, None)
        #
        # record the event: select a directory
        command = "os.chdir( '%s' )" % os.getcwd()
        gui_control.record_command(parent, command)
    elif gui_control.directory_or_database == 'database':
        if event.keysym == 'Return':
            try:
                parent.parent.update()
                g_wait = gui_message.wait(
                    parent.parent,
                    'Please wait while the connection\n to the database is made.'
                )
                gui_control.db = cdms2.connect(parent.parent.tin2.get())
                parent.parent.update()
                g_wait.progress()
                for x in gui_control.db_connections:
                    Match_found = re.match(parent.parent.tin2.get(), x)
                    if Match_found: break
                if not Match_found:
                    gui_control.db_connections.append(parent.parent.tin2.get())
                parent.parent.panelC.scl1.setlist(gui_control.db_connections)
                db_list = gui_control.db.listDatasets()
                db_list.sort()
                parent.parent.panelC.scl2.setlist(db_list)
                parent.parent.panelC.scl3.setlist('')
                gui_functions._blank_dim1_to_ndim(parent)
                g_wait.execute()
            except:
                g_wait.execute()
                gui_message.error(
                    "Invalid database string.\nCould not connect to specified database."
                )