def user_event( self, event, fnc ) : # If a "thread_*" computation thread is already running, reset # the text in the text boxes and abort. if ( n_thread( ) != 0 ) : self.make_txt( ) return # If the button for automatic point selection has been pressed # or the user has pressed "Return" from "self.txt_win_???", # read in the values of "win_azm" and "win_cur" from their # respective "self.txt_win_???" text boxes and use those values # to run the point selection. Also, ensure that the moments # analysis has been set for "dyanmic" mode (since the user # presumably wants it this way). if ( fnc == 'win_dir' ) : Thread( target=thread_chng_mom_win_dir, args=( self.core, self.txt_win_dir.text( ) ) ).start( ) elif ( fnc == 'win_bin' ) : Thread( target=thread_chng_mom_win_bin, args=( self.core, self.txt_win_bin.text( ) ) ).start( )
def user_event(self, event, fnc): # If a "thread_*" computation thread is already running, reset # the text in the text boxes and abort. if (n_thread() != 0): self.make_txt() return # If the button for automatic point selection has been pressed # or the user has pressed "Return" from "self.txt_win_???", # read in the values of "win_azm" and "win_cur" from their # respective "self.txt_win_???" text boxes and use those values # to run the point selection. Also, ensure that the moments # analysis has been set for "dyanmic" mode (since the user # presumably wants it this way). if ((fnc == 'win_azm') or (fnc == 'win_cur')): win_azm = self.txt_win_azm.text() win_cur = self.txt_win_cur.text() self.core.chng_dyn('mom', True, rerun=False) Thread(target=thread_auto_mom_sel, args=(self.core, win_azm, win_cur)).start()
def user_event(self, event, fnc): # If a "thread_*" computation thread is already running, reset # the text in the text box and abort. if (n_thread() != 0): self.make_txt() return # Determine which population has been changed by the user. i = int(fnc[1:]) # Determine which parameter has been changed by the user and # what its new value is. if (fnc[0] == 'u'): param = 'use' val = self.arr_use[i].isChecked() elif (fnc[0] == 'i'): param = 'spec' val = self.arr_ion[i].currentIndex() - 1 elif (fnc[0] == 'n'): param = 'name' val = str(self.arr_name[i].text()) elif (fnc[0] == 's'): param = 'sym' val = str(self.arr_sym[i].text()) elif (fnc[0] == 'd'): param = 'drift' val = self.arr_drift[i].isChecked() elif (fnc[0] == 'a'): param = 'aniso' val = self.arr_aniso[i].isChecked() else: return # Instruct the core to update its ion-population parameters # appropriately. Thread(target=thread_chng_nln_pop, args=(self.core, i, param, val)).start()
def user_event( self, event, fnc ) : # If a "thread_*" computation thread is already running, reset # the text in the text box and abort. if ( n_thread( ) != 0 ) : self.make_txt( ) return # Determine which ion species has been changed by the user. i = int( fnc[1:] ) # Determine which parameter has been changed and what its new # value is. if ( fnc[0] == 'n' ) : param = 'name' val = str( self.arr_name[i].text( ) ) elif ( fnc[0] == 's' ) : param = 'sym' val = str( self.arr_sym[i].text( ) ) elif ( fnc[0] == 'm' ) : param = 'm' try : val = float( self.arr_m[i].text( ) ) except : val = None elif ( fnc[0] == 'q' ) : param = 'q' try : val = float( self.arr_q[i].text( ) ) except : val = None else : return # Instruct the core to update its ion-species parameter(s) # appropriately. Thread( target=thread_chng_nln_spc, args=( self.core, i, param, val ) ).start( )
def user_event(self, event, fnc): if ((fnc == 'mfi_l') or (fnc == 'mfi_h')): if (n_thread() == 0): # Start a new thread that makes the change to the option # with core. Thread(target=thread_chng_opt, args=(self.core, fnc, self.box[fnc].isChecked())).start() else: self.make_opt() else: txt = self.arr_txt[fnc].text() try: val = str_to_nni(txt) except: val = None # If no threads are running, make the change to the # option with core. Otherwise, restore the original # options settings. if ((n_thread() == 0) and (val is not None)): # Start a new thread that makes the change to # the option with core. Thread(target=thread_chng_opt, args=(self.core, fnc, val)).start() else: self.make_opt()
def user_event(self, event, fnc): # If no threads are running, make the change to the option with # core. Otherwise, restore the original options settings. if (n_thread() == 0): # Start a new thread that makes the change to the option # with core. Thread(target=thread_chng_opt, args=(self.core, fnc, self.box[fnc].isChecked())).start() else: self.make_opt()
def user_event(self, event, fnc): # Take the appropriate action based on which button was pressed. if (fnc == 'close'): # Close the window. self.close() elif (fnc == 'rstr'): # If no other threads are currently running, start a new # thread to restore the default values for all option. if (n_thread() == 0): Thread(target=thread_rstr_opt, args=(self.core, )).start()
def user_event( self, event, plt_ji ) : # If a "thread_*" computation thread is already running, abort. if ( n_thread( ) != 0 ) : return # If no spectrum has been loaded, abort. if ( ( self.core.fc_spec is None ) or ( self.core.fc_spec['n_bin'] <= 0 ) ) : return # Extract the location of the plot in the grid. tk = where( self.plt == plt_ji ) j = tk[0][0] i = tk[1][0] # Determine the look direction corresponding to this plot. d = self.calc_ind_d( j, i ) # Extract the data shown in this plot. Convert them first to # their adjusted values, and then to their equivalent pixel # positions in the "ViewBox". dat_x = self.core.fc_spec['vel_cen'][self.c] dat_y = self.core.fc_spec['curr'][self.c][d] dat_ax = log10( dat_x ) if ( self.log_x ) else dat_x dat_ay = log10( dat_y ) if ( self.log_y ) else dat_y dat_a = tile( None, self.core.fc_spec['n_bin'] ) for b in range( self.core.fc_spec['n_bin'] ) : dat_a[b] = QPointF( dat_ax[b], dat_ay[b] ) dat_p = array( [ self.plt[j,i].mapFromView( da ) for da in dat_a ] ) dat_px = array( [ dp.x( ) for dp in dat_p ] ) dat_py = array( [ dp.y( ) for dp in dat_p ] ) # Extract the pixel position of the mouse-click event. evt_p = event.pos( ) evt_px = evt_p.x( ) evt_py = evt_p.y( ) # Compute the distance (in pixels) of each datum's location from # the location of the mouse-click event. Then, identify the # closest datum. dst = sqrt( ( dat_px - evt_px )**2 + ( dat_py - evt_py )**2 ) b = where( dst == amin( dst ) )[0][0] # If the distance between the nearest datum and the mouse click # is within a set tolerance, invert the selection of that datum # (i.e., de-select it if its already selected or select it if it # isn't selected). tol = 25. if ( dst[b] <= tol ) : if ( self.core.dsp == 'mom' ) : Thread( target=thread_chng_mom_sel, args=( self.core, self.c, d, b ) ).start() elif ( self.core.dsp == 'gsl' ) : Thread( target=thread_chng_nln_sel, args=( self.core, self.c, d, b ) ).start() elif ( self.core.dsp == 'nln' ) : Thread( target=thread_chng_nln_sel, args=( self.core, self.c, d, b ) ).start()
def user_event(self, event, fnc): # If a "thread_*" computation thread is already running, # regenerate the check boxes and abort. if (n_thread() != 0): self.make_box() return # If one of the "Display" boxes has been (un)checked, update the # value of "self.core.dsp" appropriately. # Note. When one of these boxes is checked, it is not abolutely # necessary to uncheck the other boxes. The call to # "self.core.chng_dsp" will emit a signal that cause # "self.make_box" to be run. However, there tends to be # a bit of lag in this process, so an immediate # unchecking of these boxes is warranted. if (fnc == 'dsp_mom'): if (self.box_dsp_mom.isChecked()): self.box_dsp_gsl.setChecked(False) self.box_dsp_nln.setChecked(False) Thread(target=thread_chng_dsp, args=(self.core, 'mom')).start() else: Thread(target=thread_chng_dsp, args=(self.core, None)).start() if (fnc == 'dsp_gsl'): if (self.box_dsp_gsl.isChecked()): self.box_dsp_mom.setChecked(False) self.box_dsp_nln.setChecked(False) Thread(target=thread_chng_dsp, args=(self.core, 'gsl')).start() else: Thread(target=thread_chng_dsp, args=(self.core, None)).start() if (fnc == 'dsp_nln'): if (self.box_dsp_nln.isChecked()): self.box_dsp_mom.setChecked(False) self.box_dsp_gsl.setChecked(False) Thread(target=thread_chng_dsp, args=(self.core, 'nln')).start() else: Thread(target=thread_chng_dsp, args=(self.core, None)).start() # If one of the "Dynamic" boxes has been (un)checked, update the # value of the corresponding "self.core.dyn_???". if (fnc == 'dyn_mom'): Thread(target=thread_chng_dyn, args=(self.core, 'mom', self.box_dyn_mom.isChecked())).start() if (fnc == 'dyn_gss'): Thread(target=thread_chng_dyn, args=(self.core, 'gss', self.box_dyn_gss.isChecked())).start() if (fnc == 'dyn_sel'): Thread(target=thread_chng_dyn, args=(self.core, 'sel', self.box_dyn_sel.isChecked())).start() if (fnc == 'dyn_nln'): Thread(target=thread_chng_dyn, args=(self.core, 'nln', self.box_dyn_nln.isChecked())).start()
def user_event(self, event, fnc): # If a "thread_*" computation thread is running, abort. if (n_thread() != 0): return # If the "Save" button has been pressed, execute the save of # analysis results. if (fnc == 'save'): # Launch a dialog for the user to select a name and # location for the save file. nm_fl = str( QFileDialog.getSaveFileName(caption='Save', directory=make_name_save( self.core))) # If the user canceled the dialog, abort. if (len(nm_fl) == 0): return # Assuming that there still aren't any janus threads # running, start a new thread to have the core save its # log of analysis results to the user-specified file. if (n_thread() == 0): Thread(target=thread_save_res, args=(self.core, nm_fl)).start() # Return return # If the "Export" button has been pressed, execute the export of # analysis results to a plain text file. if (fnc == 'xprt'): # Launch a dialog for the user to select a name and # location for the save file. nm_fl = str( QFileDialog.getSaveFileName(caption='Export', directory=make_name_xprt( self.core))) # If the user canceled the dialog, abort. if (len(nm_fl) == 0): return # Assuming that there still aren't any janus threads # running, start a new thread to have the core save its # log of analysis results to the user-specified file. if (n_thread() == 0): Thread(target=thread_xprt_res, args=(self.core, nm_fl)).start() # Return return # If the "Restore" button has been pressed, launch a dialog box # to load and restore saved results. if (fnc == 'rstr'): # WARNING! THIS FEATURE IS INCOMPLETE. DURING ITS # DEVELOPMENT, IT IS ONLY AVAILABLE IN # DEBUGGING MODE. # If debugging mode is not active, alert the user and # abort. if (not self.core.debug): dialog_missing().alert() return # Return. return
def user_event(self, event, fnc): # If a "thread_*" computation thread is already running, reset # the text in the text box and abort. if (n_thread() != 0): self.make_txt() return # Note. All of the remaining cases spawn a "thread_load_spec" # thread. I have found that having "core.load_spec" only # emit the "janus_rset" signal for itself (i.e., from # within the thread) causes irregularities in the # display. Emitting this signal immediately before this # thread is spwaned ensures that all the relevent widgets # reset before any new data are loaded. # If the "Go To" button has been pressed or the user has pressed # "Return" from the text area, go to the spectrum with the # timestamp closest to the one specified by the user in the text # area "self.txt_timesto". if (fnc == 'goto'): if (n_thread() == 0): self.core.emit(SIGNAL('janus_rset')) time_req = str(self.txt_timestp.text()) Thread(target=thread_load_spec, args=(self.core, time_req)).start() return # If a spectrum has not already been loaded, abort (since the # remaining buttons all function relative to the timestamp of # "self.core"). if (self.core.time_epc is None): return # Load a Wind/FC ion spectrum based the type of button pressed. if (fnc == '-1hr'): if (n_thread() == 0): self.core.emit(SIGNAL('janus_rset')) Thread(target=thread_load_spec, args=(self.core, self.core.time_val - 3600.)).start() return if (fnc == '-1sp'): if (n_thread() == 0): self.core.emit(SIGNAL('janus_rset')) Thread(target=thread_load_spec, args=(self.core, self.core.time_val, True, False)).start() return if (fnc == '+1sp'): if (n_thread() == 0): self.core.emit(SIGNAL('janus_rset')) Thread(target=thread_load_spec, args=(self.core, self.core.time_val, False, True)).start() return if (fnc == '+1hr'): if (n_thread() == 0): self.core.emit(SIGNAL('janus_rset')) Thread(target=thread_load_spec, args=(self.core, self.core.time_val + 3600.)).start() return
def closeEvent(self, event): # Request that the core stop any automatic analysis that might # be in progress. self.core.stop_auto_run = True # Wait until any running Janus threads have finished. # WARNING! THIS APPROACH IS VERY LIMITED AND HAS SEVERAL FLAWS! # A BETTER SOLUTION WOULD BE TO GLOBALLY BLOCK ANY NEW # JANUS THREADS. A CHECK COULD THEN BE MADE TO SEE IF # ANY SUCH THREADS ARE CURRENTLY RUNNING, IF THEY ARE, # THIS FUNCTION WOULD THEN RETURN AND BE RECALLED IN # RESPONSE TO A SIGNAL INDICATING THAT ALL JANUS # THREADS HAD FINISHED. while (n_thread() > 0): sleep(0.1) # If no results have been generated, simply exit the program # (without launching a dialog). if (len(self.core.series) == 0): self.show_dialog = False event.accept() return # If requested, launch a dialog to ask the user whether or not # the analysis results should be saved. Otherwise, exit this # application immediately (and return). if (self.show_dialog): event.ignore() resp = dialog_save().get_resp() else: event.accept() return # Carry out the action requested by the user (via the save # dialog). if (resp == 'save'): # Launch a dialog for the user to select a name and # location for the save file. nm_fl = str( QFileDialog.getSaveFileName(caption='Save', directory=make_name_save( self.core))) # If the user canceled the dialog, abort the exit of # this application (i.e., return). if (len(nm_fl) == 0): return # Assuming that there still aren't any janus threads # running, start a new thread to have the core save its # log of analysis results to the user-specified file. # If a new thread has somehow been launched, abort the # exit of this application (i.e., return). if (n_thread() == 0): Thread(target=thread_save_res, args=(self.core, nm_fl, True)).start() else: return elif (resp == 'xprt'): # Launch a dialog for the user to select a name and # location for the export text-file. nm_fl = str( QFileDialog.getSaveFileName(caption='Export', directory=make_name_xprt( self.core))) # If the user canceled the dialog, abort the exit of # this application (i.e., return). if (len(nm_fl) == 0): return # Assuming that there still aren't any janus threads # running, start a new thread to have the core export # its log of analysis results to the text file specified # the user. If a new thread has somehow been launched, # abort the exit of this application (i.e., return). if (n_thread() == 0): Thread(target=thread_xprt_res, args=(self.core, nm_fl, True)).start() else: return elif (resp == 'exit'): # Exit this application (without saving the analysis # results). self.show_dialog = False event.accept() return else: # Abort the exit of this application (i.e., return). return
def user_event(self, event, fnc): # If a "thread_*" computation thread is already running, reset # the text in the text box and abort. if (n_thread() != 0): self.make_txt() return # Determine which parameter of which ion has been changed by # the user. prfx = fnc[0:2] if (prfx[0] == 'v'): i = None else: i = int(fnc[2:]) # Depending on the type of parameter, extract its new value. if (prfx == 'nn'): param = 'n' try: val = float(self.arr_n[i].text()) except: val = None elif (prfx == 'dd'): param = 'dv' try: val = float(self.arr_d[i].text()) except: val = None elif (prfx == 'ws'): param = 'w' try: val = float(self.arr_ws[i].text()) except: val = None elif (prfx == 'we'): param = 'w_per' try: val = float(self.arr_we[i].text()) except: val = None elif (prfx == 'wa'): param = 'w_par' try: val = float(self.arr_wa[i].text()) except: val = None elif (prfx[0] == 'vx'): param = 'v_x' try: val = float(self.vel_x.text()) except: val = None elif (prfx[0] == 'vy'): param = 'v_y' try: val = float(self.vel_y.text()) except: val = None elif (prfx[0] == 'vz'): param = 'v_z' try: val = float(self.vel_z.text()) except: val = None else: return # Instruct the core to update its ion parameters # appropriately. Thread(target=thread_chng_nln_gss, args=(self.core, i, param, val)).start()
def user_event(self, event, fnc): # If the stop button has been pressed, inform the core to abort # the automatic analysis. if (fnc == 'stop'): # Set the core's indicator of a premature-stop request # to "True". self.core.stop_auto_run = True # Return. return # If a "thread_*" computation thread is running, abort. if (n_thread() != 0): return # If the "Moments" or "Non-Linear" button has been pressed, # execute the requested analysis and return. if (fnc == 'mom'): if (n_thread() == 0): Thread(target=thread_anls_mom, args=(self.core, )).start() return if (fnc == 'nln'): if (n_thread() == 0): Thread(target=thread_anls_nln, args=(self.core, )).start() return # If the "Options" button has been pressed, launch a dialog box # that will allow the user to alter various settings. if (fnc == 'opt'): # Launch a dialog box to request options from the user. dialog_opt(self.core) # Return. return # If the "Auto" button has been pressed, launch the auto-run # dialog box. If the user-input is valid, start a thread to run # the reqested analyses on the specified spectra, enable the # "stop" button, and return. if (fnc == 'auto'): # WARNING! THIS FEATURE IS INCOMPLETE. DURING # DEVELOPMENT, IT IS ONLY AVAILABLE IN # DEBUGGING MODE. # If debugging mode is not active, alert the user and # abort. if (not self.core.debug): dialog_missing().alert() return # Attempt to find suggested settings for the automated # analysis based on the current spectrum loaded (if any) # and the previous requests of the user. self.req_auto_strt = self.core.time_txt if (self.req_auto_strt == ''): self.req_auto_stop = '' self.req_auto_next = False else: self.req_auto_next = True if (self.req_auto_stop != ''): epc_strt = calc_time_epc(self.req_auto_strt) epc_stop = calc_time_epc(self.req_auto_stop) if ((epc_strt is None) or (epc_stop is None)): self.req_auto_stop = '' elif (epc_strt >= epc_stop): self.req_auto_stop = '' # Launch a dialog box to request a range of times from # the user. time_rang = dialog_auto_ctrl( time_strt=self.req_auto_strt, time_stop=self.req_auto_stop, get_next=self.req_auto_next).get_time_rang() # If the range of times is invalid (which can happen if # the user cancels the dialog), return. if (time_rang is None): return # Store the new requested times from the user. self.req_auto_strt = time_rang[0] self.req_auto_stop = time_rang[1] self.req_auto_next = time_rang[2] self.req_auto_halt = time_rang[3] # Assuming that there still aren't any janus threads # running, start a new thread for the automatic analysis # and make the "stop" button available for the user to # abort that analysis (if so desired). if (n_thread() == 0): # Start a new thread that automatically loads # and processes each spectrum in the time range # specified by the user. Thread(target=thread_auto_run, args=(self.core, self.req_auto_strt, self.req_auto_stop, self.req_auto_next, self.req_auto_halt, 1)).start() # Hide the "auto" button and make the "stop" # button visible (so that the user can abort the # automatic analyis). self.btn_auto.setVisible(False) self.btn_stop.setVisible(True) self.dia_prog = dialog_auto_prog(self.req_auto_strt, self.req_auto_stop) # Return. return
def user_event(self, event, fnc): # If a "thread_*" computation thread is already running, reset # the text in the text box and abort. if (n_thread() != 0): self.make_txt() return # Determine which ion population has been changed by the user. i = int(fnc[2:]) # Determine which parameter has been changed and what its new # value is. if (fnc[0:2] == 'gn'): param = 'gss_n' try: val = float(self.arr_gss_n[i].text()) except: val = None elif (fnc[0:2] == 'gd'): param = 'gss_d' try: val = float(self.arr_gss_d[i].text()) except: val = None elif (fnc[0:2] == 'gw'): param = 'gss_w' try: val = float(self.arr_gss_w[i].text()) except: val = None elif ((fnc[0:2] == 's-') or (fnc[0:2] == 's+')): param = 'sel' try: val_a = float(self.arr_sel_a[i].text()) except: val_a = None try: val_b = float(self.arr_sel_b[i].text()) except: val_b = None val = [val_a, val_b] else: return # Instruct the core to update its ion parameters appropriately. Thread(target=thread_chng_nln_set, args=(self.core, i, param, val)).start()