Exemple #1
0
   def evt_change_priority( self, id, parent ):
      # Stop the replotting of data when the template editor is in use.
      if (parent.vcs[ parent.vcs_id ].SCREEN_MODE() == "TEDITOR"):
          gui_message.error("You must cancel the 'Template Editor' GUI before changing the plot priority.")
          return "break"

      self.form[ id ].priority.configure( entry_background = 'white' )
      try:
         p_val = string.atoi(self.form[id].priority.get())
      except:
          gui_message.error( "The 'P' priority value must be an integer." )
          return

      if ((self.form[id].__dict__.has_key('display')) and (self.form[id].display is not None)):
         if isinstance(self.form[id].display,list):
            displays = self.form[id].display
         else:
            displays = [self.form[id].display,]
      do_plot = False
      for display in displays:
         if ((isinstance(p_val, types.IntType)) and (display is not None)):
             try:
                display.priority = p_val
                vcs = self.eself.vcs[self.eself.vcs_id].update()
             except:
                do_plot = True

      if do_plot:
         self.do_plot( id )
         if isinstance(self.form[id].display,list):
            for display in self.form[id].display:
               display.priority = p_val
         else:
            self.form[id].display.priority = p_val
Exemple #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
Exemple #3
0
   def evt_status_button( self, id, parent, event ):
      # Stop the replotting of data when the template editor is in use.
      if (parent.vcs[ parent.vcs_id ].SCREEN_MODE() == "TEDITOR"):
          gui_message.error("You must cancel the 'Template Editor' GUI before removing the plot.")
          return "break"

      if ((self.form[id].__dict__.has_key('display')) and (self.form[id].display is not None)):
         if isinstance(self.form[id].display,list):
            displays = self.form[id].display
         else:
            displays = [self.form[id].display,]

         did_error = False
         for display in displays:
            if hasattr(display,'off') and display.off == 0:
               try:
                  display.off = 1
                  #parent.vcs[ parent.vcs_id ].remove_display_name( display.name )
               except Exception,err:
                  if parent.show_debug: print 'error in crap',display.name,err
                  pass
               self.form[id].off_btn.create_image(0,0, anchor=Tkinter.NW, image=self.form[id].off_btnimage )
               self.form[id].lbl.configure( label_text = 'Off' )
            else:
               parent.template_skip=1   # step over the set_template function in vcs_function.py
               try:
                  display.off = 0
               except Exception,err:
                  did_error = True
               self.form[id].off_btn.create_image(0,0, anchor=Tkinter.NW, image=self.form[id].on_btnimage )
               self.form[id].lbl.configure( label_text = 'On' )
               parent.template_skip=0
Exemple #4
0
 def evt_select_opendap_server(self, result):
     self.trb1.clear()
     
     self.auth_realm = None
     self.auth_host = None
     self.auth_url = None
     self.auth_callback = None
     self.auth_callback_handler = None
     
     if (self.gui_parent.auth_realm is not None):
         self.auth_realm = self.gui_parent.auth_realm
     if (self.gui_parent.auth_host is not None):
         self.auth_host = self.gui_parent.auth_host
     
     try:
         thredds_url = self.servers[result]['thredds_url']
         thredds_xml = http_thredds.get(thredds_url)
         thredds_obj = http_thredds.parse(thredds_xml)
         
         root_node = self.trb1.root
         root_node.id = thredds_url
         
         root_node.set_label(thredds_obj.dataset_name)
         self.trb1.move_cursor(self.trb1.root)
         
     except Exception, e:
         self.trb1.root.set_label('Select a THREDDS Catalog.')
         self.trb1.root.id = 0
         self.trb1.first()
         gui_message.error(e)
Exemple #5
0
 def evt_btn_select_file(self, exit):
     cur_server = self.ptls.get()
     cur_node = self.trb1.cursor_node()
     
     try:
         thredds_url = cur_node.parent_node.id
         thredds_xml = http_thredds.get(thredds_url)
         thredds_obj = http_thredds.parse(thredds_xml)
         opendap_url_base = [cur_service['base'] for cur_service in thredds_obj.services if cur_service['serviceType'] == 'DODS'][0]
         
         if (opendap_url_base[:7] == 'http://'):
         
             url = opendap_url_base + str(cur_node.id)
             
             if (self.auth_realm and self.auth_host):
                 username, password = self.passwordMgr.find_user_password(self.auth_realm, self.auth_host)
                 
                 if (username is not None and password is not None):
                     url = url.replace('http://', 'http://' + str(username) + ':' + str(password) + '@')
             
             if (exit == "exit"): self.dialog.withdraw()
                     
             self.gui_parent.panelSV.tin3.setentry(url)
             gui_select_variable.evt_enter_file(self.gui_parent, None)
             
         else:
             raise Exception('Unknown protocol for DODS/OPeNDAP access.')
     
     except Exception, e:
         gui_message.error(e)
Exemple #6
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()
Exemple #7
0
    def evt_click_tree(self, event):
        cur_server = self.ptls.get()
        cur_node = self.trb1.cursor_node()
        
        if not cur_node.expandable():
            if (self.add_password_flg == 0):
               if ((self.gui_parent.username is not None) or (self.gui_parent.password is not None) or
                   (self.gui_parent.auth_realm is not None) or (self.gui_parent.auth_host is not None)): 
                    self.passwordMgr.add_password(self.gui_parent.auth_realm, self.gui_parent.auth_host, 
                                            self.gui_parent.username, self.gui_parent.password)
                    self.add_password_flg = 1

            try:
                # get url base from parent node thredds
                thredds_url = cur_node.parent_node.id
                
                thredds_xml = http_thredds.get(thredds_url)
                thredds_obj = http_thredds.parse(thredds_xml)
                
                opendap_url_base = [cur_service['base'] for cur_service in thredds_obj.services if cur_service['serviceType'] == 'DODS'][0]
                
                if (opendap_url_base[:7] == 'http://'):
                    opendap_url = opendap_url_base + str(cur_node.id)
                    opendap_das = http_opendap.get_das(opendap_url, self.passwordMgr, self)
                    if (opendap_das is not None):
                        self.handle_das(opendap_das)
                else:
                    raise Exception('Unknown protocol for DODS/OPeNDAP access.')
            
            except Exception, e:
                gui_message.error(e)
Exemple #8
0
    def evt_select_opendap_server(self, result):
        self.trb1.clear()

        self.auth_realm = None
        self.auth_host = None
        self.auth_url = None
        self.auth_callback = None
        self.auth_callback_handler = None

        if (self.gui_parent.auth_realm is not None):
            self.auth_realm = self.gui_parent.auth_realm
        if (self.gui_parent.auth_host is not None):
            self.auth_host = self.gui_parent.auth_host

        try:
            thredds_url = self.servers[result]['thredds_url']
            thredds_xml = http_thredds.get(thredds_url)
            thredds_obj = http_thredds.parse(thredds_xml)

            root_node = self.trb1.root
            root_node.id = thredds_url

            root_node.set_label(thredds_obj.dataset_name)
            self.trb1.move_cursor(self.trb1.root)

        except Exception, e:
            self.trb1.root.set_label('Select a THREDDS Catalog.')
            self.trb1.root.id = 0
            self.trb1.first()
            gui_message.error(e)
 def evt_orientation_widget(self, parent, event):
     if self.properties_orientation.get()[0:3] == 'def':
         gui_message.error(
             'You cannot modify default text orientation objects!')
     else:
         gui_set_text_orientation.create(self.dialog, parent,
                                         self.properties_orientation.get())
    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)
Exemple #11
0
def dotephigramWind(parent, x, template, *vars):
    if len(vars) != 3:
        gui_message.error('Unable to plot data! You need to pass 3 variables')
        return
    return aThermo(parent=parent,
                   template=template,
                   type="tephigram",
                   vars=vars)
Exemple #12
0
   def evt_form_priority_change_color( self, id, parent, event ):
      # Stop the replotting of data when the template editor is in use.
      if (parent.vcs[ parent.vcs_id ].SCREEN_MODE() == "TEDITOR"):
          gui_message.error("You must cancel the 'Template Editor' GUI before changing the plot priority.")
          return "break"

      # change backgound color to red
      self.form[ id ].priority.configure( entry_background = Pmw.Color.changebrightness(self.eself,'red',0.85) )
Exemple #13
0
    def rename(self, evt=None):
        global l_menu
        menu_name = self.eny3.get()
        function_name = self.eny8.get()
        new_name = self.eny8a.get()
        # If user tried to change the name but did not enter a new name, return
        if len(new_name) == 0:
            return
        else:
            for i in range(len(l_menu)):
                if l_menu[i]['m_nam'] == menu_name:
                    for j in range(len(l_menu[i]['m_items'])):
                        # Check to see if function name already exists
                        if l_menu[i]['m_items'][j]['i_nam'] == new_name:
                            gui_message.error('Function name already exists')
                            return
                        if l_menu[i]['m_items'][j]['i_nam'] == function_name:
                            try:
                                old_filename = '%s/PCMDI_GRAPHICS/%s_%s.py' % (
                                    os.environ['HOME'], l_menu[i]['m_nam'],
                                    function_name)
                                new_filename = '%s/%s_%s.py' % (
                                    os.path.dirname(old_filename),
                                    l_menu[i]['m_nam'], new_name)
                                infile = open(old_filename, 'r')
                                outfile = open(new_filename, 'w')
                                a = infile.read().split('\n')
                                # Change function wrapper to use new name
                                a[0] = 'def %s( item_name, func_dir ):' % new_name
                                for k in range(len(a)):
                                    outfile.write('%s\n' % a[k])
                                outfile.close()
                                # Remove old files
                                try:
                                    os.remove(old_filename)
                                except:
                                    pass

                                try:
                                    os.remove('%so' % old_filename)
                                except:
                                    pass

                                l_menu[i]['m_items'][j]['i_nam'] = new_name
                                index = self.functions.index(function_name)
                                self.functions[index] = new_name
                                # Dean will add code here to rename a function
                                #  and change the command of that function to
                                #  the new wrapped py file
                                self.eny8.setlist(self.functions)
                                self.eny8.setentry(new_name)
                            except os.error, values:
                                gui_message.error('Could not rename file: %s' %
                                                  values[1])
                                return
                            break
                    break
            gui_saved_settings.save_menus()
Exemple #14
0
def dofig3(parent, x, template, *vars):
    if len(vars) != 2:
        gui_message.error('Unable to plot data! You need to pass 2 variables')
        return
    WP = prepWKPlot(parent)
    WP.x.clear()
    WP.x.landscape()

    return WP.plot_figure3(vars[0], vars[1])
Exemple #15
0
def dofig3(parent,x,template, *vars):
    if len(vars)!=2:
        gui_message.error('Unable to plot data! You need to pass 2 variables')
        return
    WP = prepWKPlot(parent)
    WP.x.clear()
    WP.x.landscape()
    
    return WP.plot_figure3(vars[0],vars[1])
def evt_display_file_info(parent, event):
    try:
        g = parent.panelDM.fid2
    except:
        gui_message.error(
            "Must enter file or variable name in the 'File' or 'Variable' entry window."
        )
        return
    try:
        v = parent.panelDM.var3
    except:
        v = parent.panelDM.var3 = None

    if (v is not None) or (g is not None):
        if v is not None:
            info_text = gui_functions._scn_a_var(parent, v)
        else:
            info_text = gui_functions._scn_a_file(parent, v, g)

        dialog = Pmw.Dialog(
            parent,
            buttons=('Dismiss', ),
            defaultbutton='OK',
            title='%s  -  File Variable Information' % v,
            #command = gui_control.Command(evt_dispose_execute, parent)
        )
        dialog.transient(parent)  # draw widget on top of its parent

        # Create the ScrolledText.
        sclt = Pmw.ScrolledText(dialog.interior(),
                                borderframe=1,
                                labelpos='n',
                                usehullsize=1,
                                hull_width=400,
                                hull_height=300,
                                text_background='white',
                                text_foreground='black',
                                text_padx=10,
                                text_pady=10,
                                text_wrap='none')
        sclt.pack(padx=5, pady=5, fill='both', expand=1)
        sclt.settext(info_text)
        sclt.configure(text_state='disabled')

        # Position dialog popup
        parent_geom = parent.geometry()
        geom = string.split(parent_geom, '+')
        geom2 = string.split(geom[0], 'x')
        d1 = string.atoi(geom[1])
        d2 = string.atoi(geom[2])
        d3 = string.atoi(geom2[0])
        d4 = string.atoi(geom2[1]) * 0.88
        dialog.activate(geometry="%dx%d+%d+%d" % (d3, d4, d1, d2))
    else:
        gui_message.error(
            "Must enter file or variable name in the 'File' or 'Variable' entry window."
        )
Exemple #17
0
   def rename(self,evt = None):
      global l_menu
      menu_name = self.eny3.get()
      function_name = self.eny8.get()
      new_name = self.eny8a.get() 
      # If user tried to change the name but did not enter a new name, return
      if len(new_name) == 0:
          return
      else:
          for i in range(len(l_menu)):
              if l_menu[i]['m_nam'] == menu_name:
                  for j in range(len(l_menu[i]['m_items'])):
                      # Check to see if function name already exists
                      if l_menu[i]['m_items'][j]['i_nam'] == new_name:
                          gui_message.error('Function name already exists')
                          return
                      if l_menu[i]['m_items'][j]['i_nam'] == function_name:
                          try:
                              old_filename = '%s/PCMDI_GRAPHICS/%s_%s.py'%(os.environ['HOME'],l_menu[i]['m_nam'],function_name)
                              new_filename = '%s/%s_%s.py'%(os.path.dirname(old_filename),l_menu[i]['m_nam'],new_name)
                              infile = open(old_filename,'r')
                              outfile = open(new_filename,'w')
                              a = infile.read().split('\n')
                              # Change function wrapper to use new name
                              a[0] = 'def %s( item_name, func_dir ):'%new_name
                              for k in range(len(a)):
                                  outfile.write('%s\n'%a[k]) 
                              outfile.close()
                              # Remove old files
                              try:
                                  os.remove(old_filename)
                              except:
                                  pass

                              try:
                                  os.remove('%so'%old_filename)
                              except:
                                  pass

                              l_menu[i]['m_items'][j]['i_nam'] = new_name 
                              index = self.functions.index(function_name)
                              self.functions[index] = new_name 
                              # Dean will add code here to rename a function
                              #  and change the command of that function to
                              #  the new wrapped py file
                              self.eny8.setlist(self.functions)
                              self.eny8.setentry(new_name)
                          except os.error, values:
                              gui_message.error( 'Could not rename file: %s'%values[1])
                              return
                          break
                  break  
          gui_saved_settings.save_menus()
Exemple #18
0
def evt_display_file_info( parent, event ):
   try: g = parent.panelDM.fid2
   except: 
        gui_message.error("Must enter file or variable name in the 'File' or 'Variable' entry window.")
        return
   try:
      v =parent.panelDM.var3
   except:
      v = parent.panelDM.var3 = None

   if (v is not None) or (g is not None):
      if v is not None:
         info_text = gui_functions._scn_a_var( parent, v )
      else:
         info_text = gui_functions._scn_a_file( parent, v, g )

      dialog = Pmw.Dialog(parent,
                buttons = ('Dismiss',),
                defaultbutton = 'OK',
                title = '%s  -  File Variable Information' % v,
                #command = gui_control.Command(evt_dispose_execute, parent)
        )
      dialog.transient( parent ) # draw widget on top of its parent

      # Create the ScrolledText.
      sclt = Pmw.ScrolledText(dialog.interior(),
                borderframe = 1,
                labelpos = 'n',
                usehullsize = 1,
                hull_width = 400,
                hull_height = 300,
                text_background = 'white',
                text_foreground = 'black',
                text_padx = 10,
                text_pady = 10,
                text_wrap='none'
      )
      sclt.pack(padx = 5, pady = 5, fill = 'both', expand = 1)
      sclt.settext( info_text )
      sclt.configure( text_state = 'disabled' )

      # Position dialog popup
      parent_geom = parent.geometry()
      geom = string.split(parent_geom, '+')
      geom2 = string.split(geom[0], 'x')
      d1 = string.atoi( geom[1] )
      d2 = string.atoi( geom[2] )
      d3 = string.atoi( geom2[0] )
      d4 = string.atoi( geom2[1] ) * 0.88
      dialog.activate( geometry="%dx%d+%d+%d" % (d3, d4, d1, d2) )
   else:
      gui_message.error("Must enter file or variable name in the 'File' or 'Variable' entry window.")
def user_menus_put( vnam, var ):
   import gui_message

#   print 'user_menus_put vnam, var = ', vnam, var
   if (type( vnam ) != type( '' )) or (type( var ) == type( '' )):
      gui_message.error( 'user_menu_put must be called with variable name, pointer' )

   import gui_defined_variables
   a = __main__
   b = __main__.__dict__
   c = __main__.__dict__['tk_root']
   b[ vnam ] = var
   gui_defined_variables.selected_updated( )
Exemple #20
0
def background(self,parent):
    vars = get_vars(parent)
    if len(vars)!=2:
        gui_message.error('Background computation requires 2 variables')
        return
    try:
        W,splits,bg = prepW(parent)
        gui_busy.busyStart( self, parent )
        bg = W.background(vars[0],vars[1],wavenumber_smoothing_windows=bg[0],frequencies_smoothing_windows=bg[1])
        gui_user_menus.user_menus_put( bg.id,bg)
    except Exception,err:
        gui_message.error('Error computing background:\n%s' % err)
        gui_busy.busyEnd( self, parent )
        return
Exemple #21
0
def dewpoint(self,parent):
    gui_busy.busyStart( self, parent )
    vars = gui_wk.get_vars(parent)
    doc = thermo.Dewpoint.__doc__
    if len(vars)!=2:
        gui_message.error('This computation requires 2 variables\n%s' % doc)
        gui_busy.busyEnd( self, parent )
        return
    try:
        es = thermo.Dewpoint(vars[0],vars[1])
        gui_user_menus.user_menus_put( "dewpoint_from_%s_%s" % (vars[0].id,vars[1].id),es)
    except Exception,err:
        gui_message.error('Error computing Dewpoint:\n%s\n%s' % (err,doc))
        gui_busy.busyEnd( self, parent )
        return
Exemple #22
0
def power(self,parent):
    vars = get_vars(parent)
    if len(vars)>1:
        gui_message.error('Power computation requires one variable only')
        return
    
    try:
        W,splits,bg = prepW(parent)
        gui_busy.busyStart( self, parent )
        power = W.process(vars[0])
        gui_user_menus.user_menus_put( power.id,power)
    except Exception,err:
        gui_message.error('Error computing power:\n%s' % err)
        gui_busy.busyEnd( self, parent )
        return
Exemple #23
0
def lapse(self,parent):
    gui_busy.busyStart( self, parent )
    vars = gui_wk.get_vars(parent)
    doc = thermo.gammaw.__doc__
    if len(vars)!=3:
        gui_message.error('This computation requires 3 variables\n%s' % doc)
        gui_busy.busyEnd( self, parent )
        return
    try:
        es = thermo.gammaw(vars[0],vars[1],vars[2])
        gui_user_menus.user_menus_put( "moist_adiabatic_lapse_rate_from_%s_%s_%s" % (vars[0].id,vars[1].id,vars[2].id),es)
    except Exception,err:
        gui_message.error('Error computing lapse rate:\n%s\n%s' % (err,doc))
        gui_busy.busyEnd( self, parent )
        return
Exemple #24
0
def ws(self,parent):
    gui_busy.busyStart( self, parent )
    vars = gui_wk.get_vars(parent)
    doc = thermo.Ws.__doc__
    if len(vars)!=2:
        gui_message.error('This computation requires 2 variables\n%s' % doc)
        gui_busy.busyEnd( self, parent )
        return
    try:
        es =thermo.Ws(vars[0],vars[1])
        gui_user_menus.user_menus_put( "saturated_mixing_ratio_from_%s_and_%s" % (vars[0].id,vars[1].id),es)
    except Exception,err:
        gui_message.error('Error computing Ws:\n%s\n%s' % (err,doc))
        gui_busy.busyEnd( self, parent )
        return
Exemple #25
0
def power(self, parent):
    vars = get_vars(parent)
    if len(vars) > 1:
        gui_message.error('Power computation requires one variable only')
        return

    try:
        W, splits, bg = prepW(parent)
        gui_busy.busyStart(self, parent)
        power = W.process(vars[0])
        gui_user_menus.user_menus_put(power.id, power)
    except Exception, err:
        gui_message.error('Error computing power:\n%s' % err)
        gui_busy.busyEnd(self, parent)
        return
Exemple #26
0
def es(self,parent):
    gui_busy.busyStart( self, parent )
    vars = gui_wk.get_vars(parent)
    doc = thermo.Es.__doc__
    if len(vars)!=1:
        gui_message.error('This computation requires one variable only\n%s' % doc)
        gui_busy.busyEnd( self, parent )
        return
    try:
        es =thermo.Es(vars[0])
        gui_user_menus.user_menus_put( "saturated_pressure_from_%s" % vars[0].id,es)
    except Exception,err :
        gui_message.error('Error computing Es:\n%s\n%s' % (err,doc))
        gui_busy.busyEnd( self, parent )
        return
Exemple #27
0
   def evt_replace_gm( self, pe, id, parent, event ):
      # Stop the replotting of data when the template editor is in use.
      if (parent.vcs[ parent.vcs_id ].SCREEN_MODE() == "TEDITOR"):
          gui_message.error("You must cancel the 'Template Editor' GUI before replacing the graphics method.")
          return "break"

      if pe == 1:
         self.form[id].gm.setentry( self.eself.panelDV.gm_bin_name )
         self.form[id].gm.configure( label_text = self.eself.panelDV.bin_type )
         self.form[id].gm.type = self.eself.panelDV.bin_type
         if self.eself.panelDV.bin_type in [ "Vector", "Scatter", "XvsY","Meshfill"]:
            self.form[id].needed_data = 2
            self.form[id].data1.configure( label_text = 'U(X,Y)' )
            self.form[id].data2.configure( label_text = 'V(X,Y)' )
            self.form[id].data2.pack( side='left', after= self.form[id].data1, padx = 5)
            if (self.form[id].data1.get() != "") and (self.form[id].data2.get() != ""):
               if self.eself.panelDV.template_bin_name != "ASD_dud":
                  self.do_plot( id )
               else:
                  parent.template_skip=1   # step over the set_template function in vcs_function.py
                  parent.template_name = self.eself.panelDV.template_bin_name
                  self.do_plot( id )
                  parent.template_skip=0   # step over the set_template function in vcs_function.py
            elif  (self.form[id].data1.get() != "") and self.eself.panelDV.bin_type=="Meshfill":
               self.do_plot( id )
               
         elif self.eself.panelDV.bin_type == "Continents":
            self.form[id].needed_data = 0
            self.form[id].data1.setentry( "" )
            self.form[id].data2.setentry( "" )
            self.form[id].data1.pack_forget( )
            self.form[id].data2.pack_forget( )
            self.do_plot( id )
         else:
            self.form[id].needed_data = 1
            self.form[id].data1.pack( side='left', after= self.form[id].gm, padx = 5)
            self.form[id].data1.configure( label_text = 'A(X,Y)' )
            self.form[id].data2.pack_forget( )
            if self.form[id].data1.get( ) != '': 
               if self.eself.panelDV.template_bin_name != "ASD_dud":
                  self.do_plot( id )
               else:
                  parent.template_skip=1   # step over the set_template function in vcs_function.py
                  parent.template_name = self.eself.panelDV.template_bin_name
                  self.do_plot( id )
                  parent.template_skip=0   # step over the set_template function in vcs_function.py

      return "break"
Exemple #28
0
def split(self, parent):
    vars = get_vars(parent)
    if len(vars) > 1:
        gui_message.error('Split computation requires one variable only')
        return

    try:
        W, splits, bg = prepW(parent)
        gui_busy.busyStart(self, parent)
        S, A = W.split(vars[0], compresstime=splits[0], smooth=splits[1])
        gui_user_menus.user_menus_put(A.id, A)
        gui_user_menus.user_menus_put(S.id, S)
    except Exception, err:
        gui_message.error('Error computing split:\n%s' % err)
        gui_busy.busyEnd(self, parent)
        return
Exemple #29
0
def lift(self,parent):
    gui_busy.busyStart( self, parent )
    vars = gui_wk.get_vars(parent)
    doc = thermo.gammaw.__doc__
    if len(vars)!=3:
        gui_message.error('This computation requires 3 variables\n%s' % doc)
        gui_busy.busyEnd( self, parent )
        return
    try:
        T,P = thermo.LiftWet(vars[0],vars[1],vars[2])
        gui_user_menus.user_menus_put( "%s_lifted_moist_adiabatically_from_%s_to_%s" % (vars[0].id,vars[1].id,vars[2].id),T)
        gui_user_menus.user_menus_put( "%s_lifted_moist_adiabatically_from_%s_to_%s_pressures" % (vars[0].id,vars[1].id,vars[2].id),P)
    except Exception,err:
        gui_message.error('Error computing lapse rate:\n%s\n%s' % (err,doc))
        gui_busy.busyEnd( self, parent )
        return
Exemple #30
0
def split(self,parent):
    vars = get_vars(parent)
    if len(vars)>1:
        gui_message.error('Split computation requires one variable only')
        return
    
    try:
        W,splits,bg = prepW(parent)
        gui_busy.busyStart( self, parent )
        S,A = W.split(vars[0],compresstime=splits[0],smooth=splits[1])
        gui_user_menus.user_menus_put( A.id,A)
        gui_user_menus.user_menus_put( S.id,S)
    except Exception,err:
        gui_message.error('Error computing split:\n%s' % err)
        gui_busy.busyEnd( self, parent )
        return
Exemple #31
0
def dewpoint(self, parent):
    gui_busy.busyStart(self, parent)
    vars = gui_wk.get_vars(parent)
    doc = thermo.Dewpoint.__doc__
    if len(vars) != 2:
        gui_message.error('This computation requires 2 variables\n%s' % doc)
        gui_busy.busyEnd(self, parent)
        return
    try:
        es = thermo.Dewpoint(vars[0], vars[1])
        gui_user_menus.user_menus_put(
            "dewpoint_from_%s_%s" % (vars[0].id, vars[1].id), es)
    except Exception, err:
        gui_message.error('Error computing Dewpoint:\n%s\n%s' % (err, doc))
        gui_busy.busyEnd(self, parent)
        return
 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')
Exemple #33
0
 def evt_expand_node(self, node):
     cur_server = self.ptls.get()
     if (cur_server != ''):
         try:
             thredds_url = node.id
             thredds_xml = http_thredds.get(thredds_url)
             thredds_obj = http_thredds.parse(thredds_xml)
             
             for cur_catalog_ref in thredds_obj.catalog_refs:
                 self.trb1.add_node(id=cur_catalog_ref['href'], name=cur_catalog_ref['title'], flag=True)
                 
             for cur_file in thredds_obj.files:
                 self.trb1.add_node(id=cur_file['url_suffix'], name=cur_file['name'], flag=False)
         except AttributeError:
             pass
         except Exception, e:
             gui_message.error(e)
Exemple #34
0
def lapse(self, parent):
    gui_busy.busyStart(self, parent)
    vars = gui_wk.get_vars(parent)
    doc = thermo.gammaw.__doc__
    if len(vars) != 3:
        gui_message.error('This computation requires 3 variables\n%s' % doc)
        gui_busy.busyEnd(self, parent)
        return
    try:
        es = thermo.gammaw(vars[0], vars[1], vars[2])
        gui_user_menus.user_menus_put(
            "moist_adiabatic_lapse_rate_from_%s_%s_%s" %
            (vars[0].id, vars[1].id, vars[2].id), es)
    except Exception, err:
        gui_message.error('Error computing lapse rate:\n%s\n%s' % (err, doc))
        gui_busy.busyEnd(self, parent)
        return
Exemple #35
0
def get_vars(parent):
    vars = []
    try:
        if (parent.panelDM.var3 is not None):
            vars.append(gui_formulate.data( parent, d_name = parent.panelDM.var3))
        else:
            from_selected = 1
            if (len(parent.panelDV.selected) == 0):
                gui_message.error('Must first select a variable from the "Select Variable" panel above or from the "Defined Variables" list window below.')
                return vars
            lst = parent.panelDV.selected_list.keys()
            for v in lst:
                vars.append(gui_formulate.data( parent, var = parent.panelDV.lst1[ parent.panelDV.selected_list[ v ] ]))
    except Exception,err:
        gui_message.error( 'Invalid data or no variable selected. Cannot compute field.\nError:\n'+str(err) )
        gui_busy.busyEnd( self, parent )
        return []
Exemple #36
0
def background(self, parent):
    vars = get_vars(parent)
    if len(vars) != 2:
        gui_message.error('Background computation requires 2 variables')
        return
    try:
        W, splits, bg = prepW(parent)
        gui_busy.busyStart(self, parent)
        bg = W.background(vars[0],
                          vars[1],
                          wavenumber_smoothing_windows=bg[0],
                          frequencies_smoothing_windows=bg[1])
        gui_user_menus.user_menus_put(bg.id, bg)
    except Exception, err:
        gui_message.error('Error computing background:\n%s' % err)
        gui_busy.busyEnd(self, parent)
        return
Exemple #37
0
def es(self, parent):
    gui_busy.busyStart(self, parent)
    vars = gui_wk.get_vars(parent)
    doc = thermo.Es.__doc__
    if len(vars) != 1:
        gui_message.error('This computation requires one variable only\n%s' %
                          doc)
        gui_busy.busyEnd(self, parent)
        return
    try:
        es = thermo.Es(vars[0])
        gui_user_menus.user_menus_put(
            "saturated_pressure_from_%s" % vars[0].id, es)
    except Exception, err:
        gui_message.error('Error computing Es:\n%s\n%s' % (err, doc))
        gui_busy.busyEnd(self, parent)
        return
Exemple #38
0
def ws(self, parent):
    gui_busy.busyStart(self, parent)
    vars = gui_wk.get_vars(parent)
    doc = thermo.Ws.__doc__
    if len(vars) != 2:
        gui_message.error('This computation requires 2 variables\n%s' % doc)
        gui_busy.busyEnd(self, parent)
        return
    try:
        es = thermo.Ws(vars[0], vars[1])
        gui_user_menus.user_menus_put(
            "saturated_mixing_ratio_from_%s_and_%s" % (vars[0].id, vars[1].id),
            es)
    except Exception, err:
        gui_message.error('Error computing Ws:\n%s\n%s' % (err, doc))
        gui_busy.busyEnd(self, parent)
        return
Exemple #39
0
   def evt_replace_template( self, pe, id, parent, event ):
      # Stop the replotting of data when the template editor is in use.
      if (parent.vcs[ parent.vcs_id ].SCREEN_MODE() == "TEDITOR"):
          gui_message.error("You must cancel the 'Template Editor' GUI before replacng the template.")
          return "break"

      if pe == 1:
         self.form[id].template.setentry( self.eself.panelDV.template_bin_name )
         if (self.form[id].data1.get( ) != '') or (self.eself.panelDV.bin_type in ["Continents"]):
            if self.eself.panelDV.template_bin_name != "ASD_dud":
               self.do_plot( id )
            else:
               parent.template_skip=1   # step over the set_template function in vcs_function.py
               parent.template_name = self.eself.panelDV.template_bin_name
               self.do_plot( id )
               parent.template_skip=0   # step over the set_template function in vcs_function.py

      return "break"
Exemple #40
0
   def execute(self, parent, result):
        import string
        if result == 'OK':
           text_1 = self.eny1.get( )
           name = parent.slab.getattribute('name')
           if string.find( text_1, '.nc' ) == -1: text_1 = text_1 + '.nc' 
           mode = 'w'
           if self.rdo.getcurselection()[1:2] == 'A': mode = 'a'
           for x in parent.panelDV.selected_list.values():
              try:
                 f=cdms2.open( text_1, mode )
                 f.write( parent.panelDV.lst1[ x  ] )
                 f.close()
              except:
                 gui_message.error('Could not save [ %s ] in netCDF file [ %s ].' % (name,text_1))
              mode = 'a'

        self.dialog.destroy()
    def __init__(self, parent, filter_type):
        lst = parent.panelDV.selected_list.keys()
        if len(lst)!=1:
            gui_message.error( "The '"+filter_type+" Filter  Tool' could not complete its function, only one variable at a time please" )
            return
        var=parent.panelDV.lst1[ parent.panelDV.selected_list[ lst[0] ] ]
        self.parent = parent
        self.dialog = Pmw.Dialog( parent,
                                  title = "%s Question to User"%filter_type,
                                  buttons = ('OK', 'Dismiss'),
                                  defaultbutton = 'OK',
                                  command = gui_control.Command(self.execute, parent, filter_type, var) )
        
        if parent.menu.popup_window_settings_flg == 1:
            self.dialog.transient( self.parent ) # Keep widget on top of its parent

        if filter_type=='RunningAverage':
            label="Length"
        elif filter_type=="121":
            label=""
        elif filter_type=='Custom':
            label="Filter (Enter as a list)"
        if label!="":
            self.entry=Pmw.EntryField(self.dialog.interior(),
                                      labelpos='w',
                                      label_text=label)
            self.entry.pack()

        self.radio=Pmw.RadioSelect(self.dialog.interior(),
                                   labelpos='nw',
                                   label_text='Choose which dimension to apply the filter on',
                                   buttontype = 'radiobutton',
                                   orient='vertical',
                                   )
        self.radio.pack()
        for text in var.listdimnames():
            self.radio.add(text)
        self.radio.invoke(0)
        # Position dialog popup
        parent_geom = self.parent.geometry()
        geom = string.split(parent_geom, '+')
        d1 = string.atoi( geom[1] )
        d2 = string.atoi( geom[2] )
	self.dialog.geometry( "+%d+%d" % (d1, d2) )
Exemple #42
0
   def evt_remove_form( self, id, parent, event ):
      # Stop the replotting of data when the template editor is in use.
      if (parent.vcs[ parent.vcs_id ].SCREEN_MODE() == "TEDITOR"):
          gui_message.error("You must cancel the 'Template Editor' GUI before removing the plot.")
          return "break"

      if ((self.form[id].__dict__.has_key('display')) and (self.form[id].display is not None)):
         if isinstance(self.form[id].display,list):
            displays = self.form[id].display
         else:
            displays = [self.form[id].display,]
         for display in displays:
            try:
               display.off = 1
               self.eself.vcs[ self.eself.vcs_id ].remove_display_name( display.name )
            except Exception,err:
               if parent.show_debug: print err
##                print 'failed'
               pass
Exemple #43
0
    def handle_auth_prompt(self, result):
        if (result is None or result == 'Cancel'):
            self.auth_dialog.deactivate(result)
        else:
            try:
                self.gui_parent.username = username = self.txt_username.get()
                self.gui_parent.password = password = self.txt_password.get()

                self.auth_dialog.deactivate(result)
                
                self.passwordMgr.add_password(self.auth_realm, self.auth_host, username, password)
                self.add_password_flg = 1
                
                output = self.auth_callback(self.auth_url, self.passwordMgr, self)
                if (output):
                    self.auth_callback_handler(output)
                    
            except Exception, e:
                gui_message.error(e)
Exemple #44
0
def get_cdms_database_info():
   try:
      uri = os.environ['CDMSROOT']
   except KeyError:
      gui_message.error( 'Database connection error: ' + '\nSet environment variable CDMSROOT to default database location' )
      return None, None, None
      #raise CDMSError, ConnectError + '%s\nSet environment variable CDMSROOT to default database location'%uri
   (scheme,netloc,path,parameters,query,fragment)=cdms2.cdurlparse.urlparse(uri)

   host_port = string.split(netloc,':')
   if len(host_port) > 0:
     host = host_port[0]
   if len(host_port) > 1:
     port = host_port[1]
   else:
     port = '389'

   cpath = (path,)
   return host, port, cpath
Exemple #45
0
    def add_top_menu(self, parent, evt=None):
        global l_menu
        addmenu = 1
        a = parent.menu.main_menu
        nam = self.eny1.get()
        inf = self.eny2.get()

        if len(nam) == 0:
            gui_message.error(('Please enter a new menu name'))
            return

        for i in range(len(l_menu)):
            x = l_menu[i]
            # Add check here to make sure menu is not already defined as
            #   a main menu
            if x['m_nam'] == nam:
                addmenu = 0
                gui_message.error((
                    'Menu name already exists.\nPlease choose another menu name.'
                ))
                break

        # Update main menu and "Menu name" pull down menu. Update
        #  all appropriate fields
        if addmenu:
            men7 = a.addmenu(nam, inf, tearoff=1)
            m_dict = {'m_nam': nam, 'm_info': inf, 'm_items': []}
            l_menu.append(m_dict)
            self.menus.append(nam)
            self.eny3.setlist(self.menus)
            self.eny3.setentry(nam)
            self.eny4.setentry(inf)
            self.eny9.clear()
            self.eny9.setlist(self.menus)
            gui_saved_settings.save_menus()
            self.eny1.clear()
            self.eny2.clear()
            self.eny5_file.clear()
            self.eny5_import.clear()
            self.eny6.clear()
            self.eny7.clear()
            self.eny8.clear()
Exemple #46
0
def lift(self, parent):
    gui_busy.busyStart(self, parent)
    vars = gui_wk.get_vars(parent)
    doc = thermo.gammaw.__doc__
    if len(vars) != 3:
        gui_message.error('This computation requires 3 variables\n%s' % doc)
        gui_busy.busyEnd(self, parent)
        return
    try:
        T, P = thermo.LiftWet(vars[0], vars[1], vars[2])
        gui_user_menus.user_menus_put(
            "%s_lifted_moist_adiabatically_from_%s_to_%s" %
            (vars[0].id, vars[1].id, vars[2].id), T)
        gui_user_menus.user_menus_put(
            "%s_lifted_moist_adiabatically_from_%s_to_%s_pressures" %
            (vars[0].id, vars[1].id, vars[2].id), P)
    except Exception, err:
        gui_message.error('Error computing lapse rate:\n%s\n%s' % (err, doc))
        gui_busy.busyEnd(self, parent)
        return
Exemple #47
0
def process(self,parent):
    vars = get_vars(parent)
    if len(vars)>1:
        gui_message.error('WK computations requires one variable only')
        return
    
    try:
        W,splits,bg = prepW(parent)
        gui_busy.busyStart( self, parent )
        power = W.process(vars[0])
        S,A = W.split(power,compresstime=splits[0],smooth=splits[1])
        bg = W.background(S,A,wavenumber_smoothing_windows=bg[0],frequencies_smoothing_windows=bg[1])
        gui_user_menus.user_menus_put( power.id,power)
        gui_user_menus.user_menus_put( A.id,A)
        gui_user_menus.user_menus_put( S.id,S)
        gui_user_menus.user_menus_put( bg.id,bg)
    except Exception,err:
        gui_message.error('Error computing power:\n%s' % err)
        gui_busy.busyEnd( self, parent )
        return
Exemple #48
0
    def execute(self, parent, result):
        import string
        if result == 'OK':
            text_1 = self.eny1.get()
            name = parent.slab.getattribute('name')
            if string.find(text_1, '.nc') == -1: text_1 = text_1 + '.nc'
            mode = 'w'
            if self.rdo.getcurselection()[1:2] == 'A': mode = 'a'
            for x in parent.panelDV.selected_list.values():
                try:
                    f = cdms2.open(text_1, mode)
                    f.write(parent.panelDV.lst1[x])
                    f.close()
                except:
                    gui_message.error(
                        'Could not save [ %s ] in netCDF file [ %s ].' %
                        (name, text_1))
                mode = 'a'

        self.dialog.destroy()
Exemple #49
0
   def add_top_menu( self, parent, evt = None ):
      global l_menu
      addmenu = 1
      a = parent.menu.main_menu
      nam = self.eny1.get()
      inf = self.eny2.get()

      if len(nam) == 0:
         gui_message.error( ('Please enter a new menu name') )
         return

      for i in range( len(l_menu) ):
         x = l_menu[i]
         # Add check here to make sure menu is not already defined as 
         #   a main menu
         if x[ 'm_nam' ] == nam:
            addmenu = 0
            gui_message.error( ('Menu name already exists.\nPlease choose another menu name.'))
            break
       
      
      # Update main menu and "Menu name" pull down menu. Update
      #  all appropriate fields
      if addmenu:
              men7 = a.addmenu( nam, inf, tearoff = 1 ) 
              m_dict = { 'm_nam' : nam, 'm_info' : inf, 'm_items' : [] } 
              l_menu.append( m_dict )
              self.menus.append(nam)
              self.eny3.setlist(self.menus)
              self.eny3.setentry(nam)
              self.eny4.setentry(inf)
              self.eny9.clear()
              self.eny9.setlist(self.menus)
              gui_saved_settings.save_menus()  
              self.eny1.clear()
              self.eny2.clear()
              self.eny5_file.clear()
              self.eny5_import.clear()
              self.eny6.clear()
              self.eny7.clear()
              self.eny8.clear()
Exemple #50
0
    def handle_auth_prompt(self, result):
        if (result is None or result == 'Cancel'):
            self.auth_dialog.deactivate(result)
        else:
            try:
                self.gui_parent.username = username = self.txt_username.get()
                self.gui_parent.password = password = self.txt_password.get()

                self.auth_dialog.deactivate(result)

                self.passwordMgr.add_password(self.auth_realm, self.auth_host,
                                              username, password)
                self.add_password_flg = 1

                output = self.auth_callback(self.auth_url, self.passwordMgr,
                                            self)
                if (output):
                    self.auth_callback_handler(output)

            except Exception, e:
                gui_message.error(e)
Exemple #51
0
    def evt_expand_node(self, node):
        cur_server = self.ptls.get()
        if (cur_server != ''):
            try:
                thredds_url = node.id
                thredds_xml = http_thredds.get(thredds_url)
                thredds_obj = http_thredds.parse(thredds_xml)

                for cur_catalog_ref in thredds_obj.catalog_refs:
                    self.trb1.add_node(id=cur_catalog_ref['href'],
                                       name=cur_catalog_ref['title'],
                                       flag=True)

                for cur_file in thredds_obj.files:
                    self.trb1.add_node(id=cur_file['url_suffix'],
                                       name=cur_file['name'],
                                       flag=False)
            except AttributeError:
                pass
            except Exception, e:
                gui_message.error(e)