コード例 #1
0
 def execute(self,parent,type,button):
     if button=='OK':
         if type=='Xhourly':
             entry=self.entry.getvalue()
             if entry!='':
                 entry=eval(self.entry.getvalue())
             else:
                 gui_message.error('Please Fill the Entry Field')
                 return
             
             gui_busy.busyStart( self, parent )
             fqcy=24./int(entry)
             try:
                 var=parent.panelDV.lst1[ parent.panelDV.selected]
             except Exception,err:
                 var=None
             if var is None: 
                 gui_busy.busyEnd( self, parent )
                 gui_message.error( "The 'Set Bounds Time Tool' could not complete its function, because a variable was not selected.\nError:\n"+str(err) )
                 return
             cdutil.setTimeBoundsDaily(var,frequency=fqcy)
             gui_control.record_command( parent, "\n# X-Daily Data Bounds Set Function" , 1 )
             gui_control.record_command( parent, "cdutil.times.setTimeBoundsDaily( %s, frequency=%s )" % (var.id,str(fqcy)), 1 )            
             
         gui_busy.busyEnd( self, parent )
         self.dialog.destroy()
コード例 #2
0
 def execute(self, parent, result):
     if result == 'Apply':
         try:
             v_name = self.name.get()
             expression = self.expression.get()
             if not __main__.__dict__.has_key('MV'):
                 exec "from cdms2 import MV" in __main__.__dict__
             __main__.__dict__[v_name] = eval(expression, __main__.__dict__)
             if type(__main__.__dict__[v_name]) in [
                     types.IntType, types.FloatType
             ]:
                 __main__.__dict__[v_name] = cdms.asVariable(
                     __main__.__dict__[v_name])
             __main__.__dict__[v_name].id = __main__.__dict__[
                 v_name].name = v_name
             gui_defined_variables.update_defined()
             gui_control.record_command(parent, "\n# Record the expression",
                                        1)
             gui_control.record_command(parent,
                                        "%s = %s" % (v_name, expression), 1)
         except:
             gui_message.error(
                 "Bad expression! Check expression and try again.")
     elif result == 'Clear':
         self.expression.clear()
         self.fself.doing_calculation_type = ''
         self.fself.saved_expression = ''
         self.fself.build_expression = 'no'
     else:
         self.dialog.destroy()
         self.fself.gui_expression = None
コード例 #3
0
    def remove_apply(self, parent):
        text_3 = self.eny3.get()
        try:
            delattr(parent.slab, text_3)
            #
            slab_list = parent.slab.listall()
            parent.panelVI.scl1.configure(text_state='normal')
            parent.panelVI.scl1.settext('')
            first_time = 1
            for x in slab_list:
                if string.find(x, " Dimension ") != -1:
                    if first_time:
                        ln = len(
                            parent.panelDV.lst1[parent.panelDV.selected].shape)
                        num_dim = 'Number of dimensions: %d' % ln
                        parent.panelVI.scl1.insert('end', (num_dim + '\n'))
                        first_time = 0
                    parent.panelVI.scl1.insert('end', '\n')
                parent.panelVI.scl1.insert('end', (x + '\n'))
            parent.panelVI.scl1.configure(text_state='disabled')
            #
#         for x in slab_list:
#            parent.panelVI.scl1.insert( 'end', (x + '\n') )
        except:
            gui_message.error('The attribute %s was not found.' % text_3)

        # record as a new variable
        gui_control.record_command(
            parent, "\n# Record the deletion of attribute '%s' on %s " %
            (text_3, parent.slab.id), 1)
        gui_control.record_command(parent,
                                   "del(%s.%s)" % (parent.slab.id, text_3), 1)
コード例 #4
0
 def dimension_apply(self, parent):
     text_4 = self.eny4.get()
     parent.slab.setdimattribute((string.atoi(self.ctr.get()) - 1), 'units',
                                 text_4)
     #
     slab_list = parent.slab.listall()
     parent.panelVI.scl1.configure(text_state='normal')
     parent.panelVI.scl1.settext('')
     first_time = 1
     for x in slab_list:
         if string.find(x, " Dimension ") != -1:
             if first_time:
                 ln = len(
                     parent.panelDV.lst1[parent.panelDV.selected].shape)
                 num_dim = 'Number of dimensions: %d' % ln
                 parent.panelVI.scl1.insert('end', (num_dim + '\n'))
                 first_time = 0
             parent.panelVI.scl1.insert('end', '\n')
         parent.panelVI.scl1.insert('end', (x + '\n'))
     parent.panelVI.scl1.configure(text_state='disabled')
     #
     #      for x in slab_list:
     #         parent.panelVI.scl1.insert( 'end', (x + '\n') )
     # record as a new variable
     gui_control.record_command(
         parent,
         "\n# Record the change of units on dimension %i for %s to %s " %
         (string.atoi(self.ctr.get()) - 1, parent.slab.id, text_4), 1)
     gui_control.record_command(
         parent, "%s.setdimattribute(%i,'units','%s')" %
         (parent.slab.id, string.atoi(self.ctr.get()) - 1, text_4), 1)
コード例 #5
0
 def attribute_apply(self, parent):
     import string
     text_1 = self.eny1.get()
     text_2 = self.eny2.get()
     opt_1 = self.omu.getcurselection()
     if opt_1 == 'str':
         pass
     elif opt_1 == 'int':
         try:
             text_2 = string.atoi(text_2)
         except:
             gui_message.error(
                 'The attribute value [ %s ] is not an integer.' % text_2)
             return
     elif opt_1 == 'flt':
         try:
             text_2 = string.atof(text_2)
         except:
             gui_message.error(
                 'The attribute value [ %s ] is not a float.' % text_2)
             return
     try:
         parent.slab.createattribute(text_1, text_2)
     except:
         parent.slab.setattribute(text_1, text_2)
     # record as a new variable
     gui_control.record_command(
         parent, "\n# Record the change for attribute '%s' on %s to '%s'" %
         (text_1, parent.slab.id, text_2), 1)
     gui_control.record_command(
         parent, "%s.%s = %s" % (parent.slab.id, text_1, repr(text_2)), 1)
     #
     slab_list = parent.slab.listall()
     parent.panelVI.scl1.configure(text_state='normal')
     parent.panelVI.scl1.settext('')
     first_time = 1
     for x in slab_list:
         if string.find(x, " Dimension ") != -1:
             if first_time:
                 ln = len(
                     parent.panelDV.lst1[parent.panelDV.selected].shape)
                 num_dim = 'Number of dimensions: %d' % ln
                 parent.panelVI.scl1.insert('end', (num_dim + '\n'))
                 first_time = 0
             parent.panelVI.scl1.insert('end', '\n')
         parent.panelVI.scl1.insert('end', (x + '\n'))
     parent.panelVI.scl1.configure(text_state='disabled')
コード例 #6
0
ファイル: gui_expression.py プロジェクト: AZed/uvcdat
 def execute(self, parent, result):
    if result == 'Apply':
       try:
          v_name = self.name.get()
          expression = self.expression.get()
          if not __main__.__dict__.has_key('MV'):
             exec "from cdms2 import MV" in __main__.__dict__
          __main__.__dict__[v_name] = eval( expression, __main__.__dict__ )
          if type(__main__.__dict__[v_name]) in [types.IntType,types.FloatType]:
             __main__.__dict__[v_name] = cdms.asVariable(__main__.__dict__[v_name])
          __main__.__dict__[v_name].id = __main__.__dict__[v_name].name = v_name
          gui_defined_variables.update_defined( )
          gui_control.record_command(parent, "\n# Record the expression", 1 )
          gui_control.record_command(parent, "%s = %s" % (v_name, expression), 1 )
       except:
          gui_message.error("Bad expression! Check expression and try again.")
    elif result == 'Clear':
       self.expression.clear()
       self.fself.doing_calculation_type = ''
       self.fself.saved_expression = ''
       self.fself.build_expression = 'no'
    else:
       self.dialog.destroy()
       self.fself.gui_expression = None
コード例 #7
0
ファイル: gui_select_variable.py プロジェクト: AZed/uvcdat
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.")
コード例 #8
0
    def execute(self, parent, result):
        if result == 'OK':
            if self.eny1.get() == '':
                pass
            else:
                a = self.eny1.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:]

                # Get the page orientation (i.e., either l='landscape', or p=portrait)
                o = 'l'
                if self.parent.panelGC.page_orientation_flg == 0: o = 'p'

                if self.type == 'p':
                    self.parent.vcs[parent.vcs_id].postscript(a, o)
                    gui_control.record_command(
                        parent, "\n# Save VCS Canvas in Postscript File")
                    gui_control.record_command(
                        parent, "vcs.postscript( '%s', 'r' )" % (a, ))
                elif self.type == 'e':
                    self.parent.vcs[parent.vcs_id].eps(a, 'r', o)
                    gui_control.record_command(
                        parent,
                        "\n# Save VCS Canvas in Encapsulated Postscript File")
                    gui_control.record_command(parent,
                                               "vcs.eps( '%s', 'r')" % (a, ))
                elif self.type == 'g':
                    self.parent.vcs[parent.vcs_id].gif(a, 'r')
                    gui_control.record_command(
                        parent, "\n# Save VCS Canvas in GIF File")
                    gui_control.record_command(parent,
                                               "vcs.gif( '%s', 'r' )" % (a, ))
                elif self.type == 'c':
                    self.parent.vcs[parent.vcs_id].cgm(a, 'r')
                    gui_control.record_command(
                        parent, "\n# Save VCS Canvas in CGM File")
                    gui_control.record_command(parent,
                                               "vcs.cgm( '%s', 'r' )" % (a, ))
                elif self.type == 'd':
                    if ((a == '') or (a == ' ') or (a is None)):
                        self.parent.new_defined_var = None
                    else:
                        self.parent.new_defined_var = a
                elif self.type == 'operation':
                    try:
                        parent.ret_val = string.atof(self.eny1.get())
                    except:
                        gui_message.error("Not a floating point value.")
                        parent.ret_val = None
                elif self.type == 't':
                    self.parent.vcs[parent.vcs_id].printer(a, o)
                    gui_control.record_command(
                        parent, "\n# Send VCS Canvas to %s Printer" % a)
                    gui_control.record_command(
                        parent, "vcs.printer( '%s', '%s' )" % (a, o))
                elif self.type == 's':
                    search_pattern = a
                    parent.file_search_pattern = search_pattern
                    #  	re-write the new directory information and save directory list
                    d, f = gui_functions._scn_a_dir(parent)
                    #parent.panelDM.scl1.setlist( d )
                    parent.panelDM.lst1 = d
                    #  	display the data files in the directory
                    #               parent.panelDM.scl2.setlist( f )
                    for i in range(len(f)):
                        parent.panelSV.tin3.insert(i, f[i])
                    parent.panelDM.lst2 = f
                    #
                    parent.panelDM.fid2 = None
                    parent.panelDM.var3 = parent.panelDM.remember_var3 = None
                    #
                    #               parent.panelDM.scl3.setlist( () )
                    #
                    gui_functions._blank_dim1_to_ndim(parent)
                elif self.type == 'ss':
                    parent.swap_size = string.atof(a) * 1000000.
                elif self.type == 'tt':
                    if a not in parent.vcs[parent.vcs_id].listelements(
                            'template'):
                        gui_message.error(
                            'Could not find the template name ( %s ) in the template list. Please check the template list to make sure it exist.'
                            % a)
                        return
                    parent.template_name = a
                elif self.type == 'gm':
                    parent.graphics_method_name = a
                elif self.type in [
                        'template_rename', 'template_copy', 'template_remove',
                        'template_save_as'
                ]:
                    new_t_name = a
                    if ((len(new_t_name) < 1)
                            or (self.entry_str == new_t_name)):
                        self.dialog.destroy()
                        return  # do nothing
                    try:
                        vcs = self.parent.vcs[parent.vcs_id]
                        if self.type == 'template_rename':
                            vcs.canvas.renameP(self.entry_str, new_t_name)
                        elif self.type == 'template_copy':
                            vcs.canvas.copyP(self.entry_str, new_t_name)
                        elif self.type == 'template_remove':
                            vcs.canvas.removeP(self.entry_str)
                        elif self.type == 'template_save_as':
                            if new_t_name[-4:] != ".scr": new_t_name += ".scr"
                            vcs.canvas.scriptP(self.entry_str, new_t_name, 'w')
                        self.update_widget.setlist(
                            vcs.listelements('template'))
                    except:
                        gui_message.error(
                            'Cannot rename template (P_%s). Check to make sure that the old name exist in the template list and that the new name does not.'
                            % self.entry_str)

                elif self.type in [
                        'gm_rename', 'gm_copy', 'gm_remove', 'gm_save_as'
                ]:
                    new_gm_name = a
                    gm_type = string.lower(self.gm_type)
                    if ((len(new_gm_name) < 1)
                            or (self.entry_str == new_gm_name)):
                        self.dialog.destroy()
                        return  # do nothing
                    try:
                        vcs = self.parent.vcs[parent.vcs_id]
                        if self.type == 'gm_rename':
                            if gm_type == 'boxfill':
                                vcs.canvas.renameGfb(self.entry_str,
                                                     new_gm_name)
                            elif gm_type == 'continents':
                                vcs.canvas.renameGcon(self.entry_str,
                                                      new_gm_name)
                            elif gm_type == 'isofill':
                                vcs.canvas.renameGfi(self.entry_str,
                                                     new_gm_name)
                            elif gm_type == 'isoline':
                                vcs.canvas.renameGi(self.entry_str,
                                                    new_gm_name)
                            elif gm_type == 'outfill':
                                vcs.canvas.renameGfo(self.entry_str,
                                                     new_gm_name)
                            elif gm_type == 'outline':
                                vcs.canvas.renameGo(self.entry_str,
                                                    new_gm_name)
                            elif gm_type == 'scatter':
                                vcs.canvas.renameGSp(self.entry_str,
                                                     new_gm_name)
                            elif gm_type == 'taylordiagrams':
                                vcs.canvas.renameGtd(self.entry_str,
                                                     new_gm_name)
                            elif gm_type == 'vector':
                                vcs.canvas.renameGv(self.entry_str,
                                                    new_gm_name)
                            elif gm_type == 'xvsy':
                                vcs.canvas.renameGXY(self.entry_str,
                                                     new_gm_name)
                            elif gm_type == 'xyvsy':
                                vcs.canvas.renameGXy(self.entry_str,
                                                     new_gm_name)
                            elif gm_type == 'yxvsx':
                                vcs.canvas.renameGYx(self.entry_str,
                                                     new_gm_name)
                        elif self.type == 'gm_copy':
                            if gm_type == 'boxfill':
                                vcs.canvas.copyGfb(self.entry_str, new_gm_name)
                            elif gm_type == 'continents':
                                vcs.canvas.copyGcon(self.entry_str,
                                                    new_gm_name)
                            elif gm_type == 'isofill':
                                vcs.canvas.copyGfi(self.entry_str, new_gm_name)
                            elif gm_type == 'isoline':
                                vcs.canvas.copyGfi(self.entry_str, new_gm_name)
                            elif gm_type == 'outfill':
                                vcs.canvas.copyGfo(self.entry_str, new_gm_name)
                            elif gm_type == 'outline':
                                vcs.canvas.copyGo(self.entry_str, new_gm_name)
                            elif gm_type == 'scatter':
                                vcs.canvas.copyGSp(self.entry_str, new_gm_name)
                            elif gm_type == 'taylordiagrams':
                                vcs.canvas.copyGtd(self.entry_str, new_gm_name)
                            elif gm_type == 'vector':
                                vcs.canvas.copyGv(self.entry_str, new_gm_name)
                            elif gm_type == 'xvsy':
                                vcs.canvas.copyGXY(self.entry_str, new_gm_name)
                            elif gm_type == 'xyvsy':
                                vcs.canvas.copyGXy(self.entry_str, new_gm_name)
                            elif gm_type == 'yxvsx':
                                vcs.canvas.copyGYx(self.entry_str, new_gm_name)
                        elif self.type == 'gm_save_as':
                            if new_gm_name[-4:] != ".scr":
                                new_gm_name += ".scr"
                            if gm_type == 'boxfill':
                                vcs.canvas.scriptGfb(self.entry_str,
                                                     new_gm_name, 'w')
                            elif gm_type == 'continents':
                                vcs.canvas.scriptGcon(self.entry_str,
                                                      new_gm_name, 'w')
                            elif gm_type == 'isofill':
                                vcs.canvas.scriptGfi(self.entry_str,
                                                     new_gm_name, 'w')
                            elif gm_type == 'isoline':
                                vcs.canvas.scriptGi(self.entry_str,
                                                    new_gm_name, 'w')
                            elif gm_type == 'outfill':
                                vcs.canvas.scriptGfo(self.entry_str,
                                                     new_gm_name, 'w')
                            elif gm_type == 'outline':
                                vcs.canvas.scriptGo(self.entry_str,
                                                    new_gm_name, 'w')
                            elif gm_type == 'scatter':
                                vcs.canvas.scriptGSp(self.entry_str,
                                                     new_gm_name, 'w')
                            elif gm_type == 'taylordiagrams':
                                vcs.canvas.scriptGtd(self.entry_str,
                                                     new_gm_name, 'w')
                            elif gm_type == 'vector':
                                vcs.canvas.scriptGv(self.entry_str,
                                                    new_gm_name, 'w')
                            elif gm_type == 'xvsy':
                                vcs.canvas.scriptXY(self.entry_str,
                                                    new_gm_name, 'w')
                            elif gm_type == 'xyvsy':
                                vcs.canvas.scriptXy(self.entry_str,
                                                    new_gm_name, 'w')
                            elif gm_type == 'yxvsx':
                                vcs.canvas.scriptYx(self.entry_str,
                                                    new_gm_name, 'w')
                        self.update_widget.setlist(vcs.listelements(gm_type))
                    except:
                        gui_message.error(
                            'Cannot rename %s graphics method (%s). Check to make sure that the old name exist in the %s list and that the new name does not.'
                            % (self.gm_type, self.entry_str, self.gm_type))

        self.dialog.destroy()
コード例 #9
0
    def rename_variable_apply(self, parent):
        import __main__
        if parent.panelDV.selected == []:
            gui_message.error(
                "Must select a variable in the 'Defined Variable' window.")
            return
        old_name = var_name = string.split(parent.panelDV.selected)[0]
        new_name = self.eny0.get()
        selected = parent.panelDV.selected
        selected_list = parent.panelDV.selected_list
        __main__.__dict__[new_name] = __main__.__dict__[old_name]
        if old_name != new_name:
            del __main__.__dict__[old_name]

        for x in selected_list.keys():
            if string.split(selected_list[x], ' ')[0] == old_name:
                break
        selected_list[x] = string.replace(selected_list[x], old_name, new_name)
        selected = selected_list[x]

        hold_selected_list = parent.panelDV.selected_list
        hold_selected = parent.panelDV.selected
        gui_defined_variables.update_defined(parent)
        parent.panelDV.selected_list = hold_selected_list
        parent.panelDV.selected = hold_selected

        # Update the selection numbering scheme
        ct = 0
        for x in parent.panelDV.selected_list.values():
            ct += 1
            if ct < 10:
                parent.panelDV.number_lst1[x] = (
                    "%s%d " % (gui_control.dvholder[0], ct)) + x
            elif ct < 100:
                parent.panelDV.number_lst1[x] = ("%d " % ct) + x
            else:
                gui_message.error(
                    'Cannot exceed over 100 selections. See gui_control.py for modification instructions.'
                )

        # Update the defined variable list
        gui_defined_variables.update_defined_variable_list(parent)
        #
        dvlt = parent.panelDV.scl1.get()
        for x in selected_list.values():
            for i in range(len(dvlt)):
                if dvlt[i][gui_control.dvsize:] == x:
                    parent.panelDV.scl1.select_set(i)
        #
        parent.panelDV.selected_list = selected_list
        parent.panelDV.selected = selected
        #
        gui_functions._srl_var_dim1_to_ndim(
            parent, slab=parent.panelDV.lst1[parent.panelDV.selected])
        #
        self.lbl0_text.set(
            ("Change the variable's name from [ %s ] to [ ? ]:" % new_name))
        self.lbl1_text.set(('Add variable attribute to [ %s ]:' % new_name))
        self.lbl2_text.set(
            ('Remove variable attributes from [ %s ]:' % new_name))
        self.lbl3_text.set(('attribute for [ %s ]:' % new_name))
        #
        parent.slab.id = parent.slab.name = new_name  # change the name of the id to new_name
        #
        slab_list = parent.slab.listall()
        parent.panelVI.scl1.configure(text_state='normal')
        parent.panelVI.scl1.settext('')
        first_time = 1
        for x in slab_list:
            if string.find(x, " Dimension ") != -1:
                if first_time:
                    ln = len(
                        parent.panelDV.lst1[parent.panelDV.selected].shape)
                    num_dim = 'Number of dimensions: %d' % ln
                    parent.panelVI.scl1.insert('end', (num_dim + '\n'))
                    first_time = 0
                parent.panelVI.scl1.insert('end', '\n')
            parent.panelVI.scl1.insert('end', (x + '\n'))
        parent.panelVI.scl1.configure(text_state='disabled')

        # record as a new variable
        gui_control.record_command(
            parent,
            "\n# Record the name change of %s to %s" % (old_name, new_name), 1)
        gui_control.record_command(parent, "%s = %s" % (new_name, old_name), 1)
コード例 #10
0
ファイル: gui_select_variable.py プロジェクト: AZed/uvcdat
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.")
コード例 #11
0
ファイル: gui_output.py プロジェクト: AZed/uvcdat
   def execute(self, parent, result):
      if result == 'OK':
         if self.eny1.get( ) == '':
            pass
         else:
            a = self.eny1.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:]

            # Get the page orientation (i.e., either l='landscape', or p=portrait)
            o = 'l'
            if self.parent.panelGC.page_orientation_flg == 0: o = 'p'

            if self.type == 'p':
               self.parent.vcs[ parent.vcs_id ].postscript( a, o )
               gui_control.record_command( parent, "\n# Save VCS Canvas in Postscript File" )
               gui_control.record_command( parent, "vcs.postscript( '%s', 'r' )" % (a,) )
            elif self.type == 'e':
               self.parent.vcs[ parent.vcs_id ].eps( a, 'r', o )
               gui_control.record_command(parent,"\n# Save VCS Canvas in Encapsulated Postscript File")
               gui_control.record_command( parent, "vcs.eps( '%s', 'r')" % (a,) )
            elif self.type == 'g':
               self.parent.vcs[ parent.vcs_id ].gif( a, 'r' )
               gui_control.record_command( parent, "\n# Save VCS Canvas in GIF File" )
               gui_control.record_command( parent, "vcs.gif( '%s', 'r' )" % (a, ) )
            elif self.type == 'c':
               self.parent.vcs[ parent.vcs_id ].cgm( a, 'r' )
               gui_control.record_command( parent, "\n# Save VCS Canvas in CGM File" )
               gui_control.record_command( parent, "vcs.cgm( '%s', 'r' )" % (a,) )
            elif self.type == 'd':
               if ((a == '') or (a == ' ') or
                  (a is None)):
                  self.parent.new_defined_var = None
               else:
                  self.parent.new_defined_var = a
            elif self.type == 'operation':
               try:
                  parent.ret_val = string.atof( self.eny1.get() )
               except:
                  gui_message.error("Not a floating point value.")
                  parent.ret_val = None
            elif self.type == 't':
               self.parent.vcs[ parent.vcs_id ].printer( a, o )
               gui_control.record_command(parent,"\n# Send VCS Canvas to %s Printer" % a )
               gui_control.record_command( parent, "vcs.printer( '%s', '%s' )" % (a, o) )
            elif self.type == 's':
               search_pattern = a
               parent.file_search_pattern =  search_pattern
               #  	re-write the new directory information and save directory list
               d,f = gui_functions._scn_a_dir( parent )
               #parent.panelDM.scl1.setlist( d )
               parent.panelDM.lst1 = d
               #  	display the data files in the directory
#               parent.panelDM.scl2.setlist( f )
               for i in range(len(f)): parent.panelSV.tin3.insert( i, f[i] )
               parent.panelDM.lst2 = f
               #
               parent.panelDM.fid2 = None
               parent.panelDM.var3 = parent.panelDM.remember_var3 = None
               #
#               parent.panelDM.scl3.setlist( () )
               #
               gui_functions._blank_dim1_to_ndim( parent )
            elif self.type == 'ss':
               parent.swap_size = string.atof( a ) * 1000000.
            elif self.type == 'tt':
                 if a not in parent.vcs[ parent.vcs_id ].listelements( 'template' ):
                    gui_message.error( 'Could not find the template name ( %s ) in the template list. Please check the template list to make sure it exist.' % a )
                    return
                 parent.template_name =  a
            elif self.type == 'gm':
                 parent.graphics_method_name = a
            elif self.type in ['template_rename', 'template_copy', 'template_remove', 'template_save_as']:
               new_t_name = a
               if ( (len(new_t_name) < 1) or (self.entry_str == new_t_name) ):
                  self.dialog.destroy()
                  return              			# do nothing
               try:
                  vcs = self.parent.vcs[ parent.vcs_id ]
                  if self.type == 'template_rename':
                     vcs.canvas.renameP(self.entry_str, new_t_name)
                  elif self.type == 'template_copy':
                     vcs.canvas.copyP(self.entry_str, new_t_name)
                  elif self.type == 'template_remove':
                     vcs.canvas.removeP(self.entry_str)
                  elif self.type == 'template_save_as':
                     if new_t_name[-4:] != ".scr": new_t_name += ".scr"
                     vcs.canvas.scriptP( self.entry_str, new_t_name, 'w' )
                  self.update_widget.setlist( vcs.listelements('template') )
               except:
                  gui_message.error( 'Cannot rename template (P_%s). Check to make sure that the old name exist in the template list and that the new name does not.' % self.entry_str )

            elif self.type in ['gm_rename', 'gm_copy', 'gm_remove', 'gm_save_as']:
               new_gm_name = a
               gm_type = string.lower( self.gm_type )
               if ( (len(new_gm_name) < 1) or (self.entry_str == new_gm_name) ):
                  self.dialog.destroy()
                  return              			# do nothing
               try:
                  vcs = self.parent.vcs[ parent.vcs_id ]
                  if self.type == 'gm_rename':
                     if gm_type == 'boxfill': vcs.canvas.renameGfb(self.entry_str, new_gm_name)
                     elif gm_type == 'continents': vcs.canvas.renameGcon(self.entry_str, new_gm_name)
                     elif gm_type == 'isofill': vcs.canvas.renameGfi(self.entry_str, new_gm_name)
                     elif gm_type == 'isoline': vcs.canvas.renameGi(self.entry_str, new_gm_name)
                     elif gm_type == 'outfill': vcs.canvas.renameGfo(self.entry_str, new_gm_name)
                     elif gm_type == 'outline': vcs.canvas.renameGo(self.entry_str, new_gm_name)
                     elif gm_type == 'scatter': vcs.canvas.renameGSp(self.entry_str, new_gm_name)
                     elif gm_type == 'taylordiagrams': vcs.canvas.renameGtd(self.entry_str, new_gm_name)
                     elif gm_type == 'vector': vcs.canvas.renameGv(self.entry_str, new_gm_name)
                     elif gm_type == 'xvsy': vcs.canvas.renameGXY(self.entry_str, new_gm_name)
                     elif gm_type == 'xyvsy': vcs.canvas.renameGXy(self.entry_str, new_gm_name)
                     elif gm_type == 'yxvsx': vcs.canvas.renameGYx(self.entry_str, new_gm_name)
                  elif self.type == 'gm_copy':
                     if gm_type == 'boxfill': vcs.canvas.copyGfb( self.entry_str, new_gm_name)
                     elif gm_type == 'continents': vcs.canvas.copyGcon( self.entry_str, new_gm_name)
                     elif gm_type == 'isofill': vcs.canvas.copyGfi( self.entry_str, new_gm_name)
                     elif gm_type == 'isoline': vcs.canvas.copyGfi( self.entry_str, new_gm_name)
                     elif gm_type == 'outfill': vcs.canvas.copyGfo( self.entry_str, new_gm_name)
                     elif gm_type == 'outline': vcs.canvas.copyGo( self.entry_str, new_gm_name)
                     elif gm_type == 'scatter': vcs.canvas.copyGSp( self.entry_str, new_gm_name)
                     elif gm_type == 'taylordiagrams': vcs.canvas.copyGtd( self.entry_str, new_gm_name)
                     elif gm_type == 'vector': vcs.canvas.copyGv( self.entry_str, new_gm_name)
                     elif gm_type == 'xvsy': vcs.canvas.copyGXY( self.entry_str, new_gm_name)
                     elif gm_type == 'xyvsy': vcs.canvas.copyGXy( self.entry_str, new_gm_name)
                     elif gm_type == 'yxvsx': vcs.canvas.copyGYx( self.entry_str, new_gm_name)
                  elif self.type == 'gm_save_as':
                     if new_gm_name[-4:] != ".scr": new_gm_name += ".scr"
                     if gm_type == 'boxfill': vcs.canvas.scriptGfb( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'continents': vcs.canvas.scriptGcon( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'isofill': vcs.canvas.scriptGfi( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'isoline': vcs.canvas.scriptGi( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'outfill': vcs.canvas.scriptGfo( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'outline': vcs.canvas.scriptGo( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'scatter': vcs.canvas.scriptGSp( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'taylordiagrams': vcs.canvas.scriptGtd( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'vector': vcs.canvas.scriptGv( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'xvsy': vcs.canvas.scriptXY( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'xyvsy': vcs.canvas.scriptXy( self.entry_str, new_gm_name, 'w' )
                     elif gm_type == 'yxvsx': vcs.canvas.scriptYx( self.entry_str, new_gm_name, 'w' )
                  self.update_widget.setlist( vcs.listelements(gm_type) )
               except:
                  gui_message.error( 'Cannot rename %s graphics method (%s). Check to make sure that the old name exist in the %s list and that the new name does not.' % (self.gm_type, self.entry_str, self.gm_type) )
         
      self.dialog.destroy()
コード例 #12
0
        s_coord = "%s=fid2( '%s', " % (var_name, var)
    else:
        var_name = var.id
        if new_var is not None: var_name = new_var
        s_index = "%s=%s( " % (var_name, var.id)
        s_coord = "%s=%s( " % (var_name, var.id)

    for x in dargs:
        s_index = s_index + str(x) + ', '
    for x in dargs2:
        s_coord = s_coord + x + ', '
    for x in rank:
        r += str(x)
    s_index = s_index + "squeeze = 0, order = '%s' )" % r
    s_coord = s_coord + "squeeze = 0, order = '%s' )" % r
    gui_control.record_command(parent, "\n# Get new slab ", 1)
    gui_control.record_command(parent, s_coord, 1)
    ##    gui_control.record_command( parent, "# The equivalent slicing of the slab can be done with longitude\n# and latitude coordinate values, but the 'by' or stride functionality\n# is omitted when using coordinate values. For example: \n#", 1 )
    ##    gui_control.record_command( parent, '# ' + s_coord, 1 )

    slab = MV2.transpose(slab, rank)

    # Return the appropriate slab
    if chk_type_ct == 0:  # return the slab
        if parent.menu.squeeze_dim_flg == 1:
            ##          gui_control.record_command( parent, "\n# Squeeze the slab ", 1 )
            ##          gui_control.record_command( parent, "%s = %s( squeeze=1 )" % (var_name, var_name), 1 )
            try:
                slab = slab(squeeze=1)
            except:  # ok 0d slabs can not be squeezed anymore...
                pass
コード例 #13
0
    def execute(self, parent,button):
        if button=='OK':
##             gui_busy.busyStart( self, parent )
##             try:
                file=self.file.get()
                while file=="":
                    file=self.evt_icon_open_file(self.parent,None)
                    file=self.file.get()
                h=self.header.get()
                if h=='':
                    h=0
                else:
                    h=eval(h)
                sep=self.separators.get()
                if sep=="":
                    sep=[]
                else:
                    sep=sep.split()
                id=self.id.get()
                if id=="":
                    id=None
                else:
                    id=id.replace("'","")
                    id=id.replace('"',"")
                    id=id.split(',')
                    id=' '.join(id)
                    id=id.split()
                sh=self.shape.get()
                print sh
                if sh=="":
                    sh=None
                else:
                    sh=sh.split(',')
                    sh=' '.join(sh)
                    sh=sh.split('(')
                    sh=' '.join(sh)
                    sh2=sh.split(')')
                    sh=[]
                    for s in sh2:
                        if s.strip!='':
                            tmp = eval('(%s)' % ','.join(s.split()))
                            if not isinstance(tmp,tuple):
                                tmp=(tmp,)
                            sh.append(tmp)
                    print 'out:',sh
                vs=self.vs.get()
                if vs=="":
                    vs=None
                vars=read( file ,header=h, ids=id, shape=sh, next=vs,separators=sep)
                gui_control.record_command( parent, "\n# PCMDI's read ASCII Tool\nimport genutil\n", 1 )
                ids=''
                ids_lst=''
                if isinstance(vars,list):
                    for v in vars:
                        v.id = self.Self.return_unique_name( v.id)
                        ids+=v.id+', '
                        ids_lst+=repr(v.id)+', '
                        gui_user_menus.user_menus_put( v.id, v )
                else:
                    v=vars
                    v.id = self.Self.return_unique_name( v.id)
                    ids+=v.id+', '
                    ids_lst+=repr(v.id)+', '
                    gui_user_menus.user_menus_put( v.id, v )

                gui_control.record_command( parent, "%s = genutil.ASCII.readAscii(%s, header=%s, ids= %s, shape=%s, separators=%s, next=%s)" % (ids[:-2], repr(file), repr(h), '[ '+ids_lst[:-2]+' ]', repr(sh), repr(sep),repr(vs)), 1 )
##                 gui_busy.busyEnd( self, parent )
##             except Exception, err: 
##                 gui_busy.busyEnd( self, parent )
##                 gui_message.error( "The 'ASCII Read  Tool' could not complete its function\nError:\n"+str(err))

        self.dialog.destroy()
コード例 #14
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.")
コード例 #15
0
ファイル: gui_formulate.py プロジェクト: AZed/uvcdat
      var_name = var
      if d_name is not None: var_name = d_name
      s_index = "%s=fid2( '%s', " % ( var_name, var )
      s_coord = "%s=fid2( '%s', " % ( var_name, var )
   else:
      var_name = var.id
      if new_var is not None: var_name = new_var
      s_index = "%s=%s( " % ( var_name, var.id )
      s_coord = "%s=%s( " % ( var_name, var.id )

   for x in dargs: s_index = s_index + str(x) + ', '
   for x in dargs2: s_coord = s_coord + x + ', '
   for x in rank: r+=str(x)
   s_index = s_index + "squeeze = 0, order = '%s' )" % r
   s_coord = s_coord + "squeeze = 0, order = '%s' )" % r
   gui_control.record_command( parent, "\n# Get new slab ", 1 )
   gui_control.record_command( parent, s_coord, 1 )
##    gui_control.record_command( parent, "# The equivalent slicing of the slab can be done with longitude\n# and latitude coordinate values, but the 'by' or stride functionality\n# is omitted when using coordinate values. For example: \n#", 1 )
##    gui_control.record_command( parent, '# ' + s_coord, 1 )

   slab=MV2.transpose( slab, rank )

   # Return the appropriate slab
   if chk_type_ct == 0: # return the slab
      if parent.menu.squeeze_dim_flg == 1:
##          gui_control.record_command( parent, "\n# Squeeze the slab ", 1 )
##          gui_control.record_command( parent, "%s = %s( squeeze=1 )" % (var_name, var_name), 1 )
         try:
             slab = slab( squeeze=1 )
         except: # ok 0d slabs can not be squeezed anymore...
             pass
コード例 #16
0
ファイル: gui_ascii_cols.py プロジェクト: AZed/uvcdat
    def execute(self, parent,button):
        if button=='OK':
##             gui_busy.busyStart( self, parent )
##             try:
                
                ## File selection
                file=self.file.get()
                while file=="":
                    file=self.evt_icon_open_file(self.parent,None)
                    file=self.file.get()

                ## header skipping ?
                h=self.header.get()
                if h=='':
                    h=0
                else:
                    h=eval(h)

                ## Characters skip
                cskip=self.cskip.getvalue()
                if cskip=="":
                    cskip=0
                else:
                    cskip=string.atoi(cskip)

                ## Character skip type
                cskip_type=self.cskip_type.getvalue()

                ## values separation
                sep=self.separators.get()
                if sep=="":
                    sep=[]
                else:
                    sep=sep.split()

                ## ids
                id=self.id.get()
                if id=="":
                    id=None
                else:
                    id=id.split(',')
                    id=string.join(id)
                    id=id.split()
                ## stored in first row ?
                idrow=self.idrow.getvalue()
                if len(idrow)>0:
                    idrow=True
                else:
                    idrow=False
                    
                ## Axis values passed ?
                axis=self.axis.getvalue()
                if axis=='Yes':
                    axis=True
                else:
                    axis=False
                
                vars=read( file ,header=h, cskip=cskip, cskip_type=cskip_type, axis=axis, ids=id, idrow=idrow, separators=sep)
                gui_control.record_command( parent, "\n# PCMDI's read ASCII Tool\nimport genutil\n", 1 )
                ids=''
                ids_lst=''
                if isinstance(vars,list):
                    for v in vars:
                        v.id = self.Self.return_unique_name( v.id)
                        ids+=v.id+', '
                        ids_lst+=repr(v.id)+', '
                        gui_user_menus.user_menus_put( v.id, v )
                else:
                    v=vars
                    v.id = self.Self.return_unique_name( v.id)
                    ids+=v.id+', '
                    ids_lst+=repr(v.id)+', '
                    gui_user_menus.user_menus_put( v.id, v )

                gui_control.record_command( parent, "%s = genutil.ASCII.read_col(%s, header=%s, cskip=%s, cskip_type=%s, axis=%s, ids=%s, idrow=%s, separators=%s)" % (ids[:-2], repr(file), repr(h), repr(cskip), repr(cskip_type), str(axis), '[ '+ids_lst[:-2]+' ]', repr(idrow), repr(sep)), 1 )
##                 gui_busy.busyEnd( self, parent )
##             except Exception, err: 
##                 gui_busy.busyEnd( self, parent )
##                 gui_message.error( "The 'ASCII Read  Tool' could not complete its function\nError:\n"+str(err))

        self.dialog.destroy()
コード例 #17
0
    def execute(self, parent,button):
        if button=='OK':
            gui_busy.busyStart( self, parent )
            try:
                file=self.file.get()
                while file=="":
                    file=self.evt_icon_open_file(self.parent,None)
                    file=self.file.get()
                e=self.endian.index(self.endian.getvalue())
                endians=['@','=','<','>']
                e=endians[e]
                f=self.format.get()
                try:
                    struct.calcsize(f)
                except:
                    Pmw.Dialog(self.parent,
                               title = "Wrong Format !",
                               buttons = ('OK',),
                               )
                    gui_busy.busyEnd( self, parent )
                    return
                
                id=self.id.get()
                if id=="":
                    id=[]
                else:
                    id=id.split(',')
                    id=string.join(id)
                    id=id.split()
                sh=self.shape.get()
                if sh=="":
                    sh=[]
                else:
                    sh=sh.strip()
                    if sh[0]=='(':
                        sh=eval(sh)
                    else:
                        sh=sh.split(',')
                        sh=string.join(sh)
                        sh=sh.split('(')
                        sh=string.join(sh)
                        sh=sh.split(')')
                        sh=string.join(sh)
                        sh2=sh.split()
                        sh=[]
                        for s in sh2:
                            sh.append(eval(s))
                        sh=[list(sh),]
                        
                datatype=self.datatype.index(self.datatype.getvalue())
                dtp=['c','b','B','h','H','i','I','l','L','f','d']
                datatype=dtp[datatype]
                
                vs=self.vs.get()
                try:
                    struct.calcsize(vs)
                except:
                    Pmw.Dialog(self.parent,
                               title = "Wrong Format for Variable Separators !",
                               buttons = ('OK',),
                               )
                    gui_busy.busyEnd( self, parent )
                    return
                
                vars=read( file ,format=f, endian=e, datatype=datatype, ids=id, shape=sh,separator=vs)
                gui_control.record_command( parent, "\n# PCMDI's read Binary Tool\nimport browser", 1 )
                ids=''
                ids_lst=''
                if isinstance(vars,list):
                    for v in vars:
                        v.id = self.Self.return_unique_name( v.id)
                        ids+=v.id+', '
                        ids_lst+=repr(v.id)+', '
                        gui_user_menus.user_menus_put( v.id, v )
                else:
                    v=vars
                    v.id = self.Self.return_unique_name( vars.id)
                    ids+=v.id+', '
                    ids_lst+=repr(v.id)+', '
                    gui_user_menus.user_menus_put( v.id, v )

                gui_control.record_command( parent, "%s = browser.gui_read_Struct.read(%s, format=%s, endian=%s, datatype=%s, ids= %s, shape=%s, separator=%s)" % (ids[:-2], repr(file), repr(f), repr(e), repr(datatype), '[ '+ids_lst[:-2]+' ]', str(sh), repr(vs)), 1 )
                
                gui_busy.busyEnd( self, parent )
            except Exception, err: 
                gui_busy.busyEnd( self, parent )
                gui_message.error( "The 'Binary Read Tool' could not complete its function\nError:\n"+str(err))
コード例 #18
0
    def execute(self, parent, button):
        if button == 'OK':
            ##             gui_busy.busyStart( self, parent )
            ##             try:

            ## File selection
            file = self.file.get()
            while file == "":
                file = self.evt_icon_open_file(self.parent, None)
                file = self.file.get()

            ## header skipping ?
            h = self.header.get()
            if h == '':
                h = 0
            else:
                h = eval(h)

            ## Characters skip
            cskip = self.cskip.getvalue()
            if cskip == "":
                cskip = 0
            else:
                cskip = string.atoi(cskip)

            ## Character skip type
            cskip_type = self.cskip_type.getvalue()

            ## values separation
            sep = self.separators.get()
            if sep == "":
                sep = []
            else:
                sep = sep.split()

            ## ids
            id = self.id.get()
            if id == "":
                id = None
            else:
                id = id.split(',')
                id = string.join(id)
                id = id.split()
            ## stored in first row ?
            idrow = self.idrow.getvalue()
            if len(idrow) > 0:
                idrow = True
            else:
                idrow = False

            ## Axis values passed ?
            axis = self.axis.getvalue()
            if axis == 'Yes':
                axis = True
            else:
                axis = False

            vars = read(file,
                        header=h,
                        cskip=cskip,
                        cskip_type=cskip_type,
                        axis=axis,
                        ids=id,
                        idrow=idrow,
                        separators=sep)
            gui_control.record_command(
                parent, "\n# PCMDI's read ASCII Tool\nimport genutil\n", 1)
            ids = ''
            ids_lst = ''
            if isinstance(vars, list):
                for v in vars:
                    v.id = self.Self.return_unique_name(v.id)
                    ids += v.id + ', '
                    ids_lst += repr(v.id) + ', '
                    gui_user_menus.user_menus_put(v.id, v)
            else:
                v = vars
                v.id = self.Self.return_unique_name(v.id)
                ids += v.id + ', '
                ids_lst += repr(v.id) + ', '
                gui_user_menus.user_menus_put(v.id, v)

            gui_control.record_command(
                parent,
                "%s = genutil.ASCII.read_col(%s, header=%s, cskip=%s, cskip_type=%s, axis=%s, ids=%s, idrow=%s, separators=%s)"
                % (ids[:-2], repr(file), repr(h), repr(cskip),
                   repr(cskip_type), str(axis), '[ ' + ids_lst[:-2] + ' ]',
                   repr(idrow), repr(sep)), 1)
##                 gui_busy.busyEnd( self, parent )
##             except Exception, err:
##                 gui_busy.busyEnd( self, parent )
##                 gui_message.error( "The 'ASCII Read  Tool' could not complete its function\nError:\n"+str(err))

        self.dialog.destroy()
コード例 #19
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."
                )