idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
24,900 | def key_press_event ( self , widget , event ) : keyname = '' self . logger . debug ( "key press event, key=%s" % ( keyname ) ) return self . make_ui_callback ( 'key-press' , keyname ) | Called when a key is pressed and the window has the focus . Adjust method signature as appropriate for callback . |
24,901 | def key_release_event ( self , widget , event ) : keyname = '' self . logger . debug ( "key release event, key=%s" % ( keyname ) ) return self . make_ui_callback ( 'key-release' , keyname ) | Called when a key is released after being pressed . Adjust method signature as appropriate for callback . |
24,902 | def resizeEvent ( self , event ) : vp = self . viewport ( ) rect = vp . geometry ( ) x1 , y1 , x2 , y2 = rect . getCoords ( ) width = x2 - x1 + 1 height = y2 - y1 + 1 self . v_w . resize ( width , height ) | Override from QAbstractScrollArea . Resize the viewer widget when the viewport is resized . |
24,903 | def scrollContentsBy ( self , dx , dy ) : if self . _adjusting : return self . _scrolling = True try : bd = self . viewer . get_bindings ( ) res = bd . calc_pan_pct ( self . viewer , pad = self . pad ) if res is None : return pct_x , pct_y = res . pan_pct_x , res . pan_pct_y if dx != 0 : hsb = self . horizontalScrollBar ( ) pos_x = float ( hsb . value ( ) ) pct_x = pos_x / float ( self . upper_h ) if dy != 0 : vsb = self . verticalScrollBar ( ) pos_y = float ( vsb . value ( ) ) pct_y = 1.0 - ( pos_y / float ( self . upper_v ) ) bd = self . viewer . get_bindings ( ) bd . pan_by_pct ( self . viewer , pct_x , pct_y , pad = self . pad ) self . viewer . redraw ( whence = 0 ) finally : self . _scrolling = False | Override from QAbstractScrollArea . Called when the scroll bars are adjusted by the user . |
24,904 | def get_catalog ( ) : tforms = { } for name , value in list ( globals ( ) . items ( ) ) : if name . endswith ( 'Transform' ) : tforms [ name ] = value return Bunch . Bunch ( tforms , caseless = True ) | Returns a catalog of available transforms . These are used to build chains for rendering with different back ends . |
24,905 | def masktorgb ( mask , color = 'lightgreen' , alpha = 1.0 ) : mask = np . asarray ( mask ) if mask . ndim != 2 : raise ValueError ( 'ndim={0} is not supported' . format ( mask . ndim ) ) ht , wd = mask . shape r , g , b = colors . lookup_color ( color ) rgbobj = RGBImage ( data_np = np . zeros ( ( ht , wd , 4 ) , dtype = np . uint8 ) ) rc = rgbobj . get_slice ( 'R' ) gc = rgbobj . get_slice ( 'G' ) bc = rgbobj . get_slice ( 'B' ) ac = rgbobj . get_slice ( 'A' ) ac [ : ] = 0 rc [ mask ] = int ( r * 255 ) gc [ mask ] = int ( g * 255 ) bc [ mask ] = int ( b * 255 ) ac [ mask ] = int ( alpha * 255 ) return rgbobj | Convert boolean mask to RGB image object for canvas overlay . |
24,906 | def _find_rtd_version ( ) : vstr = 'latest' try : import ginga from bs4 import BeautifulSoup except ImportError : return vstr if not minversion ( ginga , '2.6.0' ) : return vstr url = 'https://readthedocs.org/projects/ginga/downloads/' with urllib . request . urlopen ( url ) as r : soup = BeautifulSoup ( r , 'html.parser' ) all_rtd_vernums = [ ] for link in soup . find_all ( 'a' ) : href = link . get ( 'href' ) if 'htmlzip' not in href : continue s = href . split ( '/' ) [ - 2 ] if s . startswith ( 'v' ) : all_rtd_vernums . append ( s ) all_rtd_vernums . sort ( reverse = True ) ginga_ver = ginga . __version__ for rtd_ver in all_rtd_vernums : if ginga_ver > rtd_ver [ 1 : ] : break else : vstr = rtd_ver return vstr | Find closest RTD doc version . |
24,907 | def _download_rtd_zip ( rtd_version = None , ** kwargs ) : if not toolkit . family . startswith ( 'qt' ) : raise ValueError ( 'Downloaded documentation not compatible with {} ' 'UI toolkit browser' . format ( toolkit . family ) ) if rtd_version is None : rtd_version = _find_rtd_version ( ) data_path = os . path . dirname ( _find_pkg_data_path ( 'help.html' , package = 'ginga.doc' ) ) index_html = os . path . join ( data_path , 'index.html' ) if os . path . isfile ( index_html ) : return index_html url = ( 'https://readthedocs.org/projects/ginga/downloads/htmlzip/' '{}/' . format ( rtd_version ) ) local_path = urllib . request . urlretrieve ( url , ** kwargs ) [ 0 ] with zipfile . ZipFile ( local_path , 'r' ) as zf : zf . extractall ( data_path ) subdir = os . path . join ( data_path , 'ginga-{}' . format ( rtd_version ) ) for s in os . listdir ( subdir ) : src = os . path . join ( subdir , s ) if os . path . isfile ( src ) : shutil . copy ( src , data_path ) else : shutil . copytree ( src , os . path . join ( data_path , s ) ) shutil . rmtree ( subdir ) if not os . path . isfile ( index_html ) : raise OSError ( '{} is missing; Ginga doc download failed' . format ( index_html ) ) return index_html | Download and extract HTML ZIP from RTD to installed doc data path . Download is skipped if content already exists . |
24,908 | def get_doc ( logger = None , plugin = None , reporthook = None ) : from ginga . GingaPlugin import GlobalPlugin , LocalPlugin if isinstance ( plugin , GlobalPlugin ) : plugin_page = 'plugins_global' plugin_name = str ( plugin ) elif isinstance ( plugin , LocalPlugin ) : plugin_page = 'plugins_local' plugin_name = str ( plugin ) else : plugin_page = None plugin_name = None try : index_html = _download_rtd_zip ( reporthook = reporthook ) except Exception as e : url = 'https://ginga.readthedocs.io/en/latest/' if plugin_name is not None : if toolkit . family . startswith ( 'qt' ) : url = None else : url += 'manual/{}/{}.html' . format ( plugin_page , plugin_name ) if logger is not None : logger . error ( str ( e ) ) else : pfx = 'file:' url = '{}{}' . format ( pfx , index_html ) if plugin_name is not None : url += '#{}' . format ( plugin_name ) return url | Return URL to documentation . Attempt download if does not exist . |
24,909 | def redo ( self , * args ) : if not self . gui_up : return mod_only = self . w . modified_only . get_state ( ) treedict = Bunch . caselessDict ( ) self . treeview . clear ( ) self . w . status . set_text ( '' ) channel = self . fv . get_channel ( self . chname ) if channel is None : return if mod_only : all_keys = channel . datasrc . keys ( sort = 'alpha' ) else : all_keys = channel . get_image_names ( ) for key in all_keys : iminfo = channel . get_image_info ( key ) path = iminfo . get ( 'path' ) idx = iminfo . get ( 'idx' ) t = iminfo . get ( 'time_modified' ) if path is None : infile = key is_fits = True else : infile = os . path . basename ( path ) infile_ext = os . path . splitext ( path ) [ 1 ] infile_ext = infile_ext . lower ( ) is_fits = False if 'fit' in infile_ext : is_fits = True if not is_fits : continue if mod_only and t is None : continue if infile in treedict : if t is not None : treedict [ infile ] . extlist . add ( idx ) elist = sorted ( treedict [ infile ] . extlist ) treedict [ infile ] . MODEXT = ';' . join ( map ( self . _format_extname , elist ) ) else : if t is None : s = '' extlist = set ( ) else : s = self . _format_extname ( idx ) extlist = set ( [ idx ] ) treedict [ infile ] = Bunch . Bunch ( IMAGE = infile , MODEXT = s , extlist = extlist , path = path ) self . treeview . set_tree ( treedict ) n_rows = len ( treedict ) if n_rows == 0 : self . w . status . set_text ( 'Nothing available for saving' ) elif n_rows < self . settings . get ( 'max_rows_for_col_resize' , 5000 ) : self . treeview . set_optimal_column_widths ( ) self . logger . debug ( 'Resized columns for {0} row(s)' . format ( n_rows ) ) | Generate listing of images that user can save . |
24,910 | def update_channels ( self ) : if not self . gui_up : return self . logger . debug ( "channel configuration has changed--updating gui" ) try : channel = self . fv . get_channel ( self . chname ) except KeyError : channel = self . fv . get_channel_info ( ) if channel is None : raise ValueError ( 'No channel available' ) self . chname = channel . name w = self . w . channel_name w . clear ( ) self . chnames = list ( self . fv . get_channel_names ( ) ) for chname in self . chnames : w . append_text ( chname ) try : i = self . chnames . index ( channel . name ) except IndexError : i = 0 self . w . channel_name . set_index ( i ) self . redo ( ) | Update the GUI to reflect channels and image listing . |
24,911 | def _format_extname ( self , ext ) : if ext is None : outs = ext else : outs = '{0},{1}' . format ( ext [ 0 ] , ext [ 1 ] ) return outs | Pretty print given extension name and number tuple . |
24,912 | def browse_outdir ( self ) : self . dirsel . popup ( 'Select directory' , self . w . outdir . set_text , initialdir = self . outdir ) self . set_outdir ( ) | Browse for output directory . |
24,913 | def set_outdir ( self ) : dirname = self . w . outdir . get_text ( ) if os . path . isdir ( dirname ) : self . outdir = dirname self . logger . debug ( 'Output directory set to {0}' . format ( self . outdir ) ) else : self . w . outdir . set_text ( self . outdir ) self . logger . error ( '{0} is not a directory' . format ( dirname ) ) | Set output directory . |
24,914 | def set_suffix ( self ) : self . suffix = self . w . suffix . get_text ( ) self . logger . debug ( 'Output suffix set to {0}' . format ( self . suffix ) ) | Set output suffix . |
24,915 | def _write_history ( self , pfx , hdu , linechar = 60 , indentchar = 2 ) : channel = self . fv . get_channel ( self . chname ) if channel is None : return history_plgname = 'ChangeHistory' try : history_obj = self . fv . gpmon . getPlugin ( history_plgname ) except Exception : self . logger . error ( '{0} plugin is not loaded. No HISTORY will be written to ' '{1}.' . format ( history_plgname , pfx ) ) return if channel . name not in history_obj . name_dict : self . logger . error ( '{0} channel not found in {1}. No HISTORY will be written to ' '{2}.' . format ( channel . name , history_plgname , pfx ) ) return file_dict = history_obj . name_dict [ channel . name ] chistory = [ ] ind = ' ' * indentchar for key in file_dict : if not key . startswith ( pfx ) : continue for bnch in file_dict [ key ] . values ( ) : chistory . append ( '{0} {1}' . format ( bnch . MODIFIED , bnch . DESCRIP ) ) for s in sorted ( chistory ) : for i in range ( 0 , len ( s ) , linechar ) : subs = s [ i : i + linechar ] if i > 0 : subs = ind + subs . lstrip ( ) hdu . header . add_history ( subs ) | Write change history to given HDU header . Limit each HISTORY line to given number of characters . Subsequent lines of the same history will be indented . |
24,916 | def _write_header ( self , image , hdu ) : hduhdr = hdu . header ghdr = image . metadata [ 'header' ] for key in ghdr : if key . upper ( ) == 'COMMENT' : continue bnch = ghdr . get_card ( key ) if key not in hduhdr : hduhdr [ key ] = ( bnch . value , bnch . comment ) elif hduhdr [ key ] != bnch . value : hduhdr [ key ] = bnch . value | Write header from image object to given HDU . |
24,917 | def _write_mef ( self , key , extlist , outfile ) : channel = self . fv . get_channel ( self . chname ) with fits . open ( outfile , mode = 'update' ) as pf : for idx in extlist : k = '{0}[{1}]' . format ( key , self . _format_extname ( idx ) ) image = channel . datasrc [ k ] pf [ idx ] . data = image . get_data ( ) self . _write_header ( image , pf [ idx ] ) self . _write_history ( key , pf [ 'PRIMARY' ] ) | Write out regular multi - extension FITS data . |
24,918 | def toggle_save_cb ( self , w , res_dict ) : if len ( res_dict ) > 0 : self . w . save . set_enabled ( True ) else : self . w . save . set_enabled ( False ) | Only enable saving if something is selected . |
24,919 | def save_images ( self ) : res_dict = self . treeview . get_selected ( ) clobber = self . settings . get ( 'clobber' , False ) self . treeview . clear_selection ( ) if self . suffix : sfx = '_' + self . suffix else : sfx = '' if self . settings . get ( 'include_chname' , True ) : sfx += '_' + self . chname for infile in res_dict : f_pfx = os . path . splitext ( infile ) [ 0 ] f_ext = '.fits' oname = f_pfx + sfx + f_ext outfile = os . path . join ( self . outdir , oname ) self . w . status . set_text ( 'Writing out {0} to {1} ...' . format ( shorten_name ( infile , 10 ) , shorten_name ( oname , 10 ) ) ) self . logger . debug ( 'Writing out {0} to {1} ...' . format ( infile , oname ) ) if os . path . exists ( outfile ) and not clobber : self . logger . error ( '{0} already exists' . format ( outfile ) ) continue bnch = res_dict [ infile ] if bnch . path is None or not os . path . isfile ( bnch . path ) : self . _write_mosaic ( f_pfx , outfile ) else : shutil . copyfile ( bnch . path , outfile ) self . _write_mef ( f_pfx , bnch . extlist , outfile ) self . logger . info ( '{0} written' . format ( outfile ) ) self . w . status . set_text ( 'Saving done, see log' ) | Save selected images . |
24,920 | def font_info ( font_str ) : vals = font_str . split ( ';' ) point_size , style , weight = 8 , 'normal' , 'normal' family = vals [ 0 ] if len ( vals ) > 1 : style = vals [ 1 ] if len ( vals ) > 2 : weight = vals [ 2 ] match = font_regex . match ( family ) if match : family , point_size = match . groups ( ) point_size = int ( point_size ) return Bunch . Bunch ( family = family , point_size = point_size , style = style , weight = weight ) | Extract font information from a font string such as supplied to the font argument to a widget . |
24,921 | def get_points ( self ) : if hasattr ( self , 'points' ) : points = self . crdmap . to_data ( self . points ) else : points = [ ] return points | Get the set of points that is used to draw the object . |
24,922 | def get_data_points ( self , points = None ) : if points is None : points = self . points points = self . crdmap . to_data ( points ) return points | Points returned are in data coordinates . |
24,923 | def set_data_points ( self , points ) : self . points = np . asarray ( self . crdmap . data_to ( points ) ) | Input points must be in data coordinates will be converted to the coordinate space of the object and stored . |
24,924 | def convert_mapper ( self , tomap ) : frommap = self . crdmap if frommap == tomap : return if hasattr ( self , 'radius' ) : x0 , y0 = frommap . offset_pt ( ( self . x , self . y ) , ( self . radius , 0 ) ) pts = frommap . to_data ( ( ( self . x , self . y ) , ( x0 , y0 ) ) ) pts = tomap . data_to ( pts ) self . radius = np . fabs ( pts [ 1 ] [ 0 ] - pts [ 0 ] [ 0 ] ) elif hasattr ( self , 'xradius' ) : x0 , y0 = frommap . offset_pt ( ( self . x , self . y ) , ( self . xradius , self . yradius ) ) pts = frommap . to_data ( ( ( self . x , self . y ) , ( x0 , y0 ) ) ) pts = tomap . data_to ( pts ) self . xradius = np . fabs ( pts [ 1 ] [ 0 ] - pts [ 0 ] [ 0 ] ) self . yradius = np . fabs ( pts [ 1 ] [ 1 ] - pts [ 0 ] [ 1 ] ) data_pts = self . get_data_points ( ) self . crdmap = tomap self . set_data_points ( data_pts ) | Converts our object from using one coordinate map to another . |
24,925 | def point_within_radius ( self , points , pt , canvas_radius , scales = ( 1.0 , 1.0 ) ) : scale_x , scale_y = scales x , y = pt a_arr , b_arr = np . asarray ( points ) . T dx = np . fabs ( x - a_arr ) * scale_x dy = np . fabs ( y - b_arr ) * scale_y new_radius = np . sqrt ( dx ** 2 + dy ** 2 ) res = ( new_radius <= canvas_radius ) return res | Points points and point pt are in data coordinates . Return True for points within the circle defined by a center at point pt and within canvas_radius . |
24,926 | def within_radius ( self , viewer , points , pt , canvas_radius ) : scales = viewer . get_scale_xy ( ) return self . point_within_radius ( points , pt , canvas_radius , scales ) | Points points and point pt are in data coordinates . Return True for points within the circle defined by a center at point pt and within canvas_radius . The distance between points is scaled by the canvas scale . |
24,927 | def get_pt ( self , viewer , points , pt , canvas_radius = None ) : if canvas_radius is None : canvas_radius = self . cap_radius if hasattr ( self , 'rot_deg' ) : ctr_pt = self . get_center_pt ( ) pt = trcalc . rotate_coord ( pt , [ - self . rot_deg ] , ctr_pt ) res = self . within_radius ( viewer , points , pt , canvas_radius ) return np . flatnonzero ( res ) | Takes an array of points points and a target point pt . Returns the first index of the point that is within the radius of the target point . If none of the points are within the radius returns None . |
24,928 | def within_line ( self , viewer , points , p_start , p_stop , canvas_radius ) : scale_x , scale_y = viewer . get_scale_xy ( ) new_radius = canvas_radius * 1.0 / min ( scale_x , scale_y ) return self . point_within_line ( points , p_start , p_stop , new_radius ) | Points points and line endpoints p_start p_stop are in data coordinates . Return True for points within the line defined by a line from p_start to p_end and within canvas_radius . The distance between points is scaled by the viewer s canvas scale . |
24,929 | def get_bbox ( self , points = None ) : if points is None : x1 , y1 , x2 , y2 = self . get_llur ( ) return ( ( x1 , y1 ) , ( x1 , y2 ) , ( x2 , y2 ) , ( x2 , y1 ) ) else : return trcalc . strip_z ( trcalc . get_bounds ( points ) ) | Get bounding box of this object . |
24,930 | def set ( self , time_sec , callback_fn , * args , ** kwdargs ) : timer = self . timer ( ) timer . set_callback ( 'expired' , callback_fn , * args , ** kwdargs ) timer . set ( time_sec ) return timer | Convenience function to create and set a timer . |
24,931 | def set_window_size ( self , width , height ) : self . _imgwin_wd = int ( width ) self . _imgwin_ht = int ( height ) self . _ctr_x = width // 2 self . _ctr_y = height // 2 self . logger . debug ( "widget resized to %dx%d" % ( width , height ) ) self . make_callback ( 'configure' , width , height ) self . redraw ( whence = 0 ) | Report the size of the window to display the image . |
24,932 | def set_renderer ( self , renderer ) : self . renderer = renderer width , height = self . get_window_size ( ) if width > 0 and height > 0 : renderer . resize ( ( width , height ) ) | Set and initialize the renderer used by this instance . |
24,933 | def set_canvas ( self , canvas , private_canvas = None ) : self . canvas = canvas canvas . initialize ( None , self , self . logger ) canvas . add_callback ( 'modified' , self . canvas_changed_cb ) canvas . set_surface ( self ) canvas . ui_set_active ( True ) self . _imgobj = None if private_canvas is not None : self . private_canvas = private_canvas if private_canvas != canvas : private_canvas . set_surface ( self ) private_canvas . ui_set_active ( True ) private_canvas . add_callback ( 'modified' , self . canvas_changed_cb ) if self . private_canvas is None : self . private_canvas = canvas if ( self . private_canvas != self . canvas ) and ( not self . private_canvas . has_object ( canvas ) ) : self . private_canvas . add ( canvas ) self . initialize_private_canvas ( self . private_canvas ) | Set the canvas object . |
24,934 | def initialize_private_canvas ( self , private_canvas ) : if self . t_ . get ( 'show_pan_position' , False ) : self . show_pan_mark ( True ) if self . t_ . get ( 'show_focus_indicator' , False ) : self . show_focus_indicator ( True ) | Initialize the private canvas used by this instance . |
24,935 | def set_rgbmap ( self , rgbmap ) : self . rgbmap = rgbmap t_ = rgbmap . get_settings ( ) t_ . share_settings ( self . t_ , keylist = rgbmap . settings_keys ) rgbmap . add_callback ( 'changed' , self . rgbmap_cb ) self . redraw ( whence = 2 ) | Set RGB map object used by this instance . It controls how the values in the image are mapped to color . |
24,936 | def get_image ( self ) : if self . _imgobj is not None : return self . _imgobj . get_image ( ) canvas_img = self . get_canvas_image ( ) return canvas_img . get_image ( ) | Get the image currently being displayed . |
24,937 | def get_canvas_image ( self ) : if self . _imgobj is not None : return self . _imgobj try : self . _imgobj = self . canvas . get_object_by_tag ( self . _canvas_img_tag ) self . _imgobj . add_callback ( 'image-set' , self . _image_set_cb ) except KeyError : NormImage = self . canvas . getDrawClass ( 'normimage' ) interp = self . t_ . get ( 'interpolation' , 'basic' ) if interp not in trcalc . interpolation_methods : interp = 'basic' self . _imgobj = NormImage ( 0 , 0 , None , alpha = 1.0 , interpolation = interp ) self . _imgobj . add_callback ( 'image-set' , self . _image_set_cb ) return self . _imgobj | Get canvas image object . |
24,938 | def set_image ( self , image , add_to_canvas = True ) : if not isinstance ( image , BaseImage . BaseImage ) : raise ValueError ( "Wrong type of object to load: %s" % ( str ( type ( image ) ) ) ) canvas_img = self . get_canvas_image ( ) old_image = canvas_img . get_image ( ) self . make_callback ( 'image-unset' , old_image ) with self . suppress_redraw : canvas_img . set_image ( image ) if add_to_canvas : try : self . canvas . get_object_by_tag ( self . _canvas_img_tag ) except KeyError : self . canvas . add ( canvas_img , tag = self . _canvas_img_tag ) self . canvas . lower_object ( canvas_img ) | Set an image to be displayed . |
24,939 | def save_profile ( self , ** params ) : image = self . get_image ( ) if ( image is None ) : return profile = image . get ( 'profile' , None ) if profile is None : profile = Settings . SettingGroup ( ) image . set ( profile = profile ) self . logger . debug ( "saving to image profile: params=%s" % ( str ( params ) ) ) profile . set ( ** params ) return profile | Save the given parameters into profile settings . |
24,940 | def set_data ( self , data , metadata = None ) : image = AstroImage . AstroImage ( data , metadata = metadata , logger = self . logger ) self . set_image ( image ) | Set an image to be displayed by providing raw data . |
24,941 | def clear ( self ) : self . _imgobj = None try : self . canvas . delete_object_by_tag ( self . _canvas_img_tag ) self . redraw ( ) except KeyError : pass | Clear the displayed image . |
24,942 | def redraw ( self , whence = 0 ) : with self . _defer_lock : whence = min ( self . _defer_whence , whence ) if not self . defer_redraw : if self . _hold_redraw_cnt == 0 : self . _defer_whence = self . _defer_whence_reset self . redraw_now ( whence = whence ) else : self . _defer_whence = whence return elapsed = time . time ( ) - self . time_last_redraw if ( not self . _defer_flag ) or ( elapsed > self . defer_lagtime ) : if elapsed > self . defer_lagtime : if self . _hold_redraw_cnt > 0 : self . _defer_whence = whence return self . _defer_whence = self . _defer_whence_reset self . logger . debug ( "lagtime expired--forced redraw" ) self . redraw_now ( whence = whence ) return self . _defer_flag = True self . _defer_whence = whence secs = self . defer_lagtime - elapsed self . logger . debug ( "defer redraw (whence=%.2f) in %.f sec" % ( whence , secs ) ) self . reschedule_redraw ( secs ) else : self . _defer_whence = whence self . logger . debug ( "update whence=%.2f" % ( whence ) ) | Redraw the canvas . |
24,943 | def canvas_changed_cb ( self , canvas , whence ) : self . logger . debug ( "root canvas changed, whence=%d" % ( whence ) ) try : canvas_img = self . canvas . get_object_by_tag ( self . _canvas_img_tag ) if self . _imgobj is not canvas_img : self . _imgobj = canvas_img self . _imgobj . add_callback ( 'image-set' , self . _image_set_cb ) self . _image_set_cb ( canvas_img , canvas_img . get_image ( ) ) except KeyError : self . _imgobj = None self . redraw ( whence = whence ) | Handle callback for when canvas has changed . |
24,944 | def delayed_redraw ( self ) : with self . _defer_lock : whence = self . _defer_whence self . _defer_whence = self . _defer_whence_reset flag = self . _defer_flag self . _defer_flag = False if flag : self . redraw_now ( whence = whence ) | Handle delayed redrawing of the canvas . |
24,945 | def set_redraw_lag ( self , lag_sec ) : self . defer_redraw = ( lag_sec > 0.0 ) if self . defer_redraw : self . defer_lagtime = lag_sec | Set lag time for redrawing the canvas . |
24,946 | def set_refresh_rate ( self , fps ) : self . rf_fps = fps self . rf_rate = 1.0 / self . rf_fps self . logger . info ( "set a refresh rate of %.2f fps" % ( self . rf_fps ) ) | Set the refresh rate for redrawing the canvas at a timed interval . |
24,947 | def start_refresh ( self ) : self . logger . debug ( "starting timed refresh interval" ) self . rf_flags [ 'done' ] = False self . rf_draw_count = 0 self . rf_timer_count = 0 self . rf_late_count = 0 self . rf_late_total = 0.0 self . rf_early_count = 0 self . rf_early_total = 0.0 self . rf_delta_total = 0.0 self . rf_skip_total = 0.0 self . rf_start_time = time . time ( ) self . rf_deadline = self . rf_start_time self . refresh_timer_cb ( self . rf_timer , self . rf_flags ) | Start redrawing the canvas at the previously set timed interval . |
24,948 | def stop_refresh ( self ) : self . logger . debug ( "stopping timed refresh" ) self . rf_flags [ 'done' ] = True self . rf_timer . clear ( ) | Stop redrawing the canvas at the previously set timed interval . |
24,949 | def get_refresh_stats ( self ) : if self . rf_draw_count == 0 : fps = 0.0 else : interval = time . time ( ) - self . rf_start_time fps = self . rf_draw_count / interval jitter = self . rf_delta_total / max ( 1 , self . rf_timer_count ) late_avg = self . rf_late_total / max ( 1 , self . rf_late_count ) late_pct = self . rf_late_count / max ( 1.0 , float ( self . rf_timer_count ) ) * 100 early_avg = self . rf_early_total / max ( 1 , self . rf_early_count ) early_pct = self . rf_early_count / max ( 1.0 , float ( self . rf_timer_count ) ) * 100 balance = self . rf_late_total - self . rf_early_total stats = dict ( fps = fps , jitter = jitter , early_avg = early_avg , early_pct = early_pct , late_avg = late_avg , late_pct = late_pct , balance = balance ) return stats | Return the measured statistics for timed refresh intervals . |
24,950 | def refresh_timer_cb ( self , timer , flags ) : start_time = time . time ( ) if flags . get ( 'done' , False ) : return deadline = self . rf_deadline self . rf_deadline += self . rf_rate self . rf_timer_count += 1 delta = abs ( start_time - deadline ) self . rf_delta_total += delta adjust = 0.0 if start_time > deadline : self . rf_late_total += delta self . rf_late_count += 1 late_avg = self . rf_late_total / self . rf_late_count adjust = - ( late_avg / 2.0 ) self . rf_skip_total += delta if self . rf_skip_total < self . rf_rate : self . rf_draw_count += 1 self . redraw_now ( whence = 0 ) else : self . rf_skip_total = 0 else : if start_time < deadline : self . rf_early_total += delta self . rf_early_count += 1 self . rf_skip_total = max ( 0.0 , self . rf_skip_total - delta ) early_avg = self . rf_early_total / self . rf_early_count adjust = early_avg / 4.0 self . rf_draw_count += 1 self . redraw_now ( whence = 0 ) delay = max ( 0.0 , self . rf_deadline - time . time ( ) + adjust ) timer . start ( delay ) | Refresh timer callback . This callback will normally only be called internally . |
24,951 | def redraw_now ( self , whence = 0 ) : try : time_start = time . time ( ) self . redraw_data ( whence = whence ) self . update_image ( ) time_done = time . time ( ) time_delta = time_start - self . time_last_redraw time_elapsed = time_done - time_start self . time_last_redraw = time_done self . logger . debug ( "widget '%s' redraw (whence=%d) delta=%.4f elapsed=%.4f sec" % ( self . name , whence , time_delta , time_elapsed ) ) except Exception as e : self . logger . error ( "Error redrawing image: %s" % ( str ( e ) ) ) try : ( type , value , tb ) = sys . exc_info ( ) tb_str = "" . join ( traceback . format_tb ( tb ) ) self . logger . error ( "Traceback:\n%s" % ( tb_str ) ) except Exception : tb_str = "Traceback information unavailable." self . logger . error ( tb_str ) | Redraw the displayed image . |
24,952 | def redraw_data ( self , whence = 0 ) : if not self . _imgwin_set : return if not self . _self_scaling : rgbobj = self . get_rgb_object ( whence = whence ) self . renderer . render_image ( rgbobj , self . _dst_x , self . _dst_y ) self . private_canvas . draw ( self ) self . make_callback ( 'redraw' , whence ) if whence < 2 : self . check_cursor_location ( ) | Render image from RGB map and redraw private canvas . |
24,953 | def check_cursor_location ( self ) : data_x , data_y = self . get_data_xy ( self . last_win_x , self . last_win_y ) if ( data_x != self . last_data_x or data_y != self . last_data_y ) : self . last_data_x , self . last_data_y = data_x , data_y self . logger . debug ( "cursor location changed %.4f,%.4f => %.4f,%.4f" % ( self . last_data_x , self . last_data_y , data_x , data_y ) ) button = 0 self . make_ui_callback ( 'cursor-changed' , button , data_x , data_y ) return data_x , data_y | Check whether the data location of the last known position of the cursor has changed . If so issue a callback . |
24,954 | def getwin_array ( self , order = 'RGB' , alpha = 1.0 , dtype = None ) : order = order . upper ( ) depth = len ( order ) if dtype is None : rgbmap = self . get_rgbmap ( ) dtype = rgbmap . dtype data = self . _rgbobj . get_array ( order , dtype = dtype ) height , width , depth = data . shape imgwin_wd , imgwin_ht = self . get_window_size ( ) r , g , b = self . img_bg outarr = trcalc . make_filled_array ( ( imgwin_ht , imgwin_wd , len ( order ) ) , dtype , order , r , g , b , alpha ) trcalc . overlay_image ( outarr , ( self . _dst_x , self . _dst_y ) , data , dst_order = order , src_order = order , flipy = False , fill = False , copy = False ) return outarr | Get Numpy data array for display window . |
24,955 | def get_datarect ( self ) : x1 , y1 , x2 , y2 = self . _org_x1 , self . _org_y1 , self . _org_x2 , self . _org_y2 return ( x1 , y1 , x2 , y2 ) | Get the approximate bounding box of the displayed image . |
24,956 | def get_limits ( self , coord = 'data' ) : limits = self . t_ [ 'limits' ] if limits is None : image = self . get_image ( ) if image is not None : wd , ht = image . get_size ( ) limits = ( ( self . data_off , self . data_off ) , ( float ( wd - 1 + self . data_off ) , float ( ht - 1 + self . data_off ) ) ) else : canvas = self . get_canvas ( ) pts = canvas . get_points ( ) if len ( pts ) > 0 : limits = trcalc . get_bounds ( pts ) else : limits = ( ( 0.0 , 0.0 ) , ( 0.0 , 0.0 ) ) crdmap = self . get_coordmap ( coord ) limits = crdmap . data_to ( limits ) return limits | Get the bounding box of the viewer extents . |
24,957 | def set_limits ( self , limits , coord = 'data' ) : if limits is not None : if len ( limits ) != 2 : raise ValueError ( "limits takes a 2 tuple, or None" ) crdmap = self . get_coordmap ( coord ) limits = crdmap . to_data ( limits ) self . t_ . set ( limits = limits ) | Set the bounding box of the viewer extents . |
24,958 | def get_rgb_object ( self , whence = 0 ) : time_start = t2 = t3 = time . time ( ) win_wd , win_ht = self . get_window_size ( ) order = self . get_rgb_order ( ) if ( whence <= 0.0 ) or ( self . _rgbarr is None ) : pan_x , pan_y = self . get_pan ( coord = 'data' ) [ : 2 ] scale_x , scale_y = self . get_scale_xy ( ) wd , ht = self . _calc_bg_dimensions ( scale_x , scale_y , pan_x , pan_y , win_wd , win_ht ) depth = len ( order ) rgbmap = self . get_rgbmap ( ) r , g , b = self . img_bg rgba = trcalc . make_filled_array ( ( ht , wd , depth ) , rgbmap . dtype , order , r , g , b , 1.0 ) self . _rgbarr = rgba t2 = time . time ( ) if ( whence <= 2.0 ) or ( self . _rgbarr2 is None ) : self . _rgbarr2 = np . copy ( self . _rgbarr ) self . overlay_images ( self . private_canvas , self . _rgbarr2 , whence = whence ) output_profile = self . t_ . get ( 'icc_output_profile' , None ) working_profile = rgb_cms . working_profile if ( working_profile is not None ) and ( output_profile is not None ) : self . convert_via_profile ( self . _rgbarr2 , order , working_profile , output_profile ) t3 = time . time ( ) if ( whence <= 2.5 ) or ( self . _rgbobj is None ) : rotimg = self . _rgbarr2 rotimg = self . apply_transforms ( rotimg , self . t_ [ 'rot_deg' ] ) rotimg = np . ascontiguousarray ( rotimg ) self . _rgbobj = RGBMap . RGBPlanes ( rotimg , order ) time_end = time . time ( ) self . logger . debug ( "times: t1=%.4f t2=%.4f t3=%.4f total=%.4f" % ( t2 - time_start , t3 - t2 , time_end - t3 , ( time_end - time_start ) ) ) return self . _rgbobj | Create and return RGB slices representing the data that should be rendered at the current zoom level and pan settings . |
24,959 | def _reset_bbox ( self ) : scale_x , scale_y = self . get_scale_xy ( ) pan_x , pan_y = self . get_pan ( coord = 'data' ) [ : 2 ] win_wd , win_ht = self . get_window_size ( ) win_wd , win_ht = max ( 1 , win_wd ) , max ( 1 , win_ht ) self . _calc_bg_dimensions ( scale_x , scale_y , pan_x , pan_y , win_wd , win_ht ) | This function should only be called internally . It resets the viewers bounding box based on changes to pan or scale . |
24,960 | def overlay_images ( self , canvas , data , whence = 0.0 ) : if not hasattr ( canvas , 'objects' ) : return for obj in canvas . get_objects ( ) : if hasattr ( obj , 'draw_image' ) : obj . draw_image ( self , data , whence = whence ) elif obj . is_compound ( ) and ( obj != canvas ) : self . overlay_images ( obj , data , whence = whence ) | Overlay data from any canvas image objects . |
24,961 | def convert_via_profile ( self , data_np , order , inprof_name , outprof_name ) : to_intent = self . t_ . get ( 'icc_output_intent' , 'perceptual' ) proofprof_name = self . t_ . get ( 'icc_proof_profile' , None ) proof_intent = self . t_ . get ( 'icc_proof_intent' , 'perceptual' ) use_black_pt = self . t_ . get ( 'icc_black_point_compensation' , False ) try : rgbobj = RGBMap . RGBPlanes ( data_np , order ) arr_np = rgbobj . get_array ( 'RGB' ) arr = rgb_cms . convert_profile_fromto ( arr_np , inprof_name , outprof_name , to_intent = to_intent , proof_name = proofprof_name , proof_intent = proof_intent , use_black_pt = use_black_pt , logger = self . logger ) ri , gi , bi = rgbobj . get_order_indexes ( 'RGB' ) out = data_np out [ ... , ri ] = arr [ ... , 0 ] out [ ... , gi ] = arr [ ... , 1 ] out [ ... , bi ] = arr [ ... , 2 ] self . logger . debug ( "Converted from '%s' to '%s' profile" % ( inprof_name , outprof_name ) ) except Exception as e : self . logger . warning ( "Error converting output from working profile: %s" % ( str ( e ) ) ) self . logger . info ( "Output left unprofiled" ) | Convert the given RGB data from the working ICC profile to the output profile in - place . |
24,962 | def get_data_xy ( self , win_x , win_y , center = None ) : if center is not None : self . logger . warning ( "`center` keyword is ignored and will be deprecated" ) arr_pts = np . asarray ( ( win_x , win_y ) ) . T return self . tform [ 'data_to_native' ] . from_ ( arr_pts ) . T [ : 2 ] | Get the closest coordinates in the data array to those reported on the window . |
24,963 | def offset_to_window ( self , off_x , off_y ) : arr_pts = np . asarray ( ( off_x , off_y ) ) . T return self . tform [ 'cartesian_to_native' ] . to_ ( arr_pts ) . T [ : 2 ] | Convert data offset to window coordinates . |
24,964 | def get_pan_rect ( self ) : wd , ht = self . get_window_size ( ) win_pts = np . asarray ( [ ( 0 , 0 ) , ( wd , 0 ) , ( wd , ht ) , ( 0 , ht ) ] ) arr_pts = self . tform [ 'data_to_window' ] . from_ ( win_pts ) return arr_pts | Get the coordinates in the actual data corresponding to the area shown in the display for the current zoom level and pan . |
24,965 | def get_data ( self , data_x , data_y ) : image = self . get_image ( ) if image is not None : return image . get_data_xy ( data_x , data_y ) raise ImageViewNoDataError ( "No image found" ) | Get the data value at the given position . Indices are zero - based as in Numpy . |
24,966 | def get_pixel_distance ( self , x1 , y1 , x2 , y2 ) : dx = abs ( x2 - x1 ) dy = abs ( y2 - y1 ) dist = np . sqrt ( dx * dx + dy * dy ) dist = np . round ( dist ) return dist | Calculate distance between the given pixel positions . |
24,967 | def _sanity_check_scale ( self , scale_x , scale_y ) : win_wd , win_ht = self . get_window_size ( ) if ( win_wd <= 0 ) or ( win_ht <= 0 ) : raise ImageViewError ( "window size undefined" ) if ( win_wd * scale_x < 1 ) or ( win_ht * scale_y < 1 ) : raise ValueError ( "resulting scale (%f, %f) would result in image size of " "<1 in width or height" % ( scale_x , scale_y ) ) sx = float ( win_wd ) / scale_x sy = float ( win_ht ) / scale_y if ( sx < 1.0 ) or ( sy < 1.0 ) : raise ValueError ( "resulting scale (%f, %f) would result in pixel size " "approaching window size" % ( scale_x , scale_y ) ) | Do a sanity check on the proposed scale vs . window size . Raises an exception if there will be a problem . |
24,968 | def scale_cb ( self , setting , value ) : zoomlevel = self . zoom . calc_level ( value ) self . t_ . set ( zoomlevel = zoomlevel ) self . redraw ( whence = 0 ) | Handle callback related to image scaling . |
24,969 | def set_scale_base_xy ( self , scale_x_base , scale_y_base ) : self . t_ . set ( scale_x_base = scale_x_base , scale_y_base = scale_y_base ) | Set stretch factors . |
24,970 | def get_scale_text ( self ) : scalefactor = self . get_scale_max ( ) if scalefactor >= 1.0 : text = '%.2fx' % ( scalefactor ) else : text = '1/%.2fx' % ( 1.0 / scalefactor ) return text | Report current scaling in human - readable format . |
24,971 | def set_zoom_algorithm ( self , name ) : name = name . lower ( ) alg_names = list ( zoom . get_zoom_alg_names ( ) ) if name not in alg_names : raise ImageViewError ( "Alg '%s' must be one of: %s" % ( name , ', ' . join ( alg_names ) ) ) self . t_ . set ( zoom_algorithm = name ) | Set zoom algorithm . |
24,972 | def zoomsetting_change_cb ( self , setting , value ) : alg_name = self . t_ [ 'zoom_algorithm' ] self . zoom = zoom . get_zoom_alg ( alg_name ) ( self ) self . zoom_to ( self . get_zoom ( ) ) | Handle callback related to changes in zoom . |
24,973 | def interpolation_change_cb ( self , setting , value ) : canvas_img = self . get_canvas_image ( ) canvas_img . interpolation = value canvas_img . reset_optimize ( ) self . redraw ( whence = 0 ) | Handle callback related to changes in interpolation . |
24,974 | def set_scale_limits ( self , scale_min , scale_max ) : self . t_ . set ( scale_min = scale_min , scale_max = scale_max ) | Set scale limits . |
24,975 | def enable_autozoom ( self , option ) : option = option . lower ( ) assert ( option in self . autozoom_options ) , ImageViewError ( "Bad autozoom option '%s': must be one of %s" % ( str ( self . autozoom_options ) ) ) self . t_ . set ( autozoom = option ) | Set autozoom behavior . |
24,976 | def set_pan ( self , pan_x , pan_y , coord = 'data' , no_reset = False ) : pan_pos = ( pan_x , pan_y ) with self . suppress_redraw : self . t_ . set ( pan = pan_pos , pan_coord = coord ) self . _reset_bbox ( ) if ( not no_reset ) and ( self . t_ [ 'autocenter' ] in ( 'override' , 'once' ) ) : self . t_ . set ( autocenter = 'off' ) | Set pan position . |
24,977 | def pan_cb ( self , setting , value ) : pan_x , pan_y = value [ : 2 ] self . logger . debug ( "pan set to %.2f,%.2f" % ( pan_x , pan_y ) ) self . redraw ( whence = 0 ) | Handle callback related to changes in pan . |
24,978 | def get_pan ( self , coord = 'data' ) : pan_x , pan_y = self . t_ [ 'pan' ] [ : 2 ] if coord == 'wcs' : if self . t_ [ 'pan_coord' ] == 'data' : image = self . get_image ( ) if image is not None : try : return image . pixtoradec ( pan_x , pan_y ) except Exception as e : pass return ( pan_x , pan_y ) if self . t_ [ 'pan_coord' ] == 'data' : return ( pan_x , pan_y ) image = self . get_image ( ) if image is not None : try : return image . radectopix ( pan_x , pan_y ) except Exception as e : pass return ( pan_x , pan_y ) | Get pan positions . |
24,979 | def center_image ( self , no_reset = True ) : try : xy_mn , xy_mx = self . get_limits ( ) data_x = float ( xy_mn [ 0 ] + xy_mx [ 0 ] ) / 2.0 data_y = float ( xy_mn [ 1 ] + xy_mx [ 1 ] ) / 2.0 except ImageViewNoDataError : canvas = self . get_canvas ( ) try : data_x , data_y = canvas . get_center_pt ( ) [ : 2 ] except Exception as e : self . logger . error ( "Can't compute center point: %s" % ( str ( e ) ) ) return self . panset_xy ( data_x , data_y , no_reset = no_reset ) if self . t_ [ 'autocenter' ] == 'once' : self . t_ . set ( autocenter = 'off' ) | Pan to the center of the image . |
24,980 | def enable_autocenter ( self , option ) : option = option . lower ( ) assert ( option in self . autocenter_options ) , ImageViewError ( "Bad autocenter option '%s': must be one of %s" % ( str ( self . autocenter_options ) ) ) self . t_ . set ( autocenter = option ) | Set autocenter behavior . |
24,981 | def cut_levels ( self , loval , hival , no_reset = False ) : self . t_ . set ( cuts = ( loval , hival ) ) if ( not no_reset ) and ( self . t_ [ 'autocuts' ] in ( 'once' , 'override' ) ) : self . t_ . set ( autocuts = 'off' ) | Apply cut levels on the image view . |
24,982 | def auto_levels ( self , autocuts = None ) : if autocuts is None : autocuts = self . autocuts image = self . get_image ( ) if image is None : return loval , hival = autocuts . calc_cut_levels ( image ) self . t_ . set ( cuts = ( loval , hival ) ) if self . t_ [ 'autocuts' ] == 'once' : self . t_ . set ( autocuts = 'off' ) | Apply auto - cut levels on the image view . |
24,983 | def auto_levels_cb ( self , setting , value ) : method = self . t_ [ 'autocut_method' ] params = self . t_ . get ( 'autocut_params' , [ ] ) params = dict ( params ) if method != str ( self . autocuts ) : ac_class = AutoCuts . get_autocuts ( method ) self . autocuts = ac_class ( self . logger , ** params ) else : self . autocuts . update_params ( ** params ) self . auto_levels ( ) | Handle callback related to changes in auto - cut levels . |
24,984 | def enable_autocuts ( self , option ) : option = option . lower ( ) assert ( option in self . autocuts_options ) , ImageViewError ( "Bad autocuts option '%s': must be one of %s" % ( str ( self . autocuts_options ) ) ) self . t_ . set ( autocuts = option ) | Set autocuts behavior . |
24,985 | def set_autocut_params ( self , method , ** params ) : self . logger . debug ( "Setting autocut params method=%s params=%s" % ( method , str ( params ) ) ) params = list ( params . items ( ) ) self . t_ . set ( autocut_method = method , autocut_params = params ) | Set auto - cut parameters . |
24,986 | def transform ( self , flip_x , flip_y , swap_xy ) : self . logger . debug ( "flip_x=%s flip_y=%s swap_xy=%s" % ( flip_x , flip_y , swap_xy ) ) with self . suppress_redraw : self . t_ . set ( flip_x = flip_x , flip_y = flip_y , swap_xy = swap_xy ) | Transform view of the image . |
24,987 | def transform_cb ( self , setting , value ) : self . make_callback ( 'transform' ) whence = 0 self . redraw ( whence = whence ) | Handle callback related to changes in transformations . |
24,988 | def copy_attributes ( self , dst_fi , attrlist , share = False ) : keylist = [ ] if 'transforms' in attrlist : keylist . extend ( [ 'flip_x' , 'flip_y' , 'swap_xy' ] ) if 'rotation' in attrlist : keylist . extend ( [ 'rot_deg' ] ) if 'autocuts' in attrlist : keylist . extend ( [ 'autocut_method' , 'autocut_params' ] ) if 'cutlevels' in attrlist : keylist . extend ( [ 'cuts' ] ) if 'rgbmap' in attrlist : keylist . extend ( [ 'color_algorithm' , 'color_hashsize' , 'color_map' , 'intensity_map' , 'color_array' , 'shift_array' ] ) if 'zoom' in attrlist : keylist . extend ( [ 'scale' ] ) if 'pan' in attrlist : keylist . extend ( [ 'pan' ] ) with dst_fi . suppress_redraw : if share : self . t_ . share_settings ( dst_fi . get_settings ( ) , keylist = keylist ) else : self . t_ . copy_settings ( dst_fi . get_settings ( ) , keylist = keylist ) dst_fi . redraw ( whence = 0 ) | Copy interesting attributes of our configuration to another image view . |
24,989 | def auto_orient ( self ) : image = self . get_image ( ) if image is None : return invert_y = not isinstance ( image , AstroImage . AstroImage ) header = image . get_header ( ) if header : orient = header . get ( 'Orientation' , None ) if orient is None : orient = header . get ( 'Image Orientation' , None ) if orient is not None : self . logger . debug ( "orientation [%s]" % orient ) try : orient = int ( str ( orient ) ) self . logger . info ( "setting orientation from metadata [%d]" % ( orient ) ) flip_x , flip_y , swap_xy = self . orient_map [ orient ] self . transform ( flip_x , flip_y , swap_xy ) invert_y = False except Exception as e : self . logger . error ( "orientation error: %s" % str ( e ) ) if invert_y : flip_x , flip_y , swap_xy = self . get_transforms ( ) flip_y = True self . transform ( flip_x , flip_y , swap_xy ) | Set the orientation for the image to a reasonable default . |
24,990 | def get_image_as_buffer ( self , output = None ) : obuf = output if obuf is None : obuf = BytesIO ( ) arr8 = self . get_image_as_array ( ) if not hasattr ( arr8 , 'tobytes' ) : obuf . write ( arr8 . tostring ( order = 'C' ) ) else : obuf . write ( arr8 . tobytes ( order = 'C' ) ) return obuf | Get the current image shown in the viewer with any overlaid graphics in a IO buffer with channels as needed and ordered by the back end widget . |
24,991 | def get_rgb_image_as_bytes ( self , format = 'png' , quality = 90 ) : obuf = self . get_rgb_image_as_buffer ( format = format , quality = quality ) return bytes ( obuf . getvalue ( ) ) | Get the current image shown in the viewer with any overlaid graphics in the form of a buffer in the form of bytes . |
24,992 | def save_rgb_image_as_file ( self , filepath , format = 'png' , quality = 90 ) : with open ( filepath , 'wb' ) as out_f : self . get_rgb_image_as_buffer ( output = out_f , format = format , quality = quality ) self . logger . debug ( "wrote %s file '%s'" % ( format , filepath ) ) | Save the current image shown in the viewer with any overlaid graphics in a file with the specified format and quality . This can be overridden by subclasses . |
24,993 | def set_onscreen_message ( self , text , redraw = True ) : width , height = self . get_window_size ( ) font = self . t_ . get ( 'onscreen_font' , 'sans serif' ) font_size = self . t_ . get ( 'onscreen_font_size' , None ) if font_size is None : font_size = self . _calc_font_size ( width ) ht , wd = font_size , font_size if text is not None : wd = len ( text ) * font_size * 1.1 x = ( width // 2 ) - ( wd // 2 ) y = ( ( height // 3 ) * 2 ) - ( ht // 2 ) tag = '_$onscreen_msg' canvas = self . get_private_canvas ( ) try : message = canvas . get_object_by_tag ( tag ) if text is None : message . text = '' else : message . x = x message . y = y message . text = text message . fontsize = font_size except KeyError : if text is None : text = '' Text = canvas . get_draw_class ( 'text' ) canvas . add ( Text ( x , y , text = text , font = font , fontsize = font_size , color = self . img_fg , coord = 'window' ) , tag = tag , redraw = False ) if redraw : canvas . update_canvas ( whence = 3 ) | Called by a subclass to update the onscreen message . |
24,994 | def _calc_font_size ( self , win_wd ) : font_size = 4 if win_wd >= 1600 : font_size = 24 elif win_wd >= 1000 : font_size = 18 elif win_wd >= 800 : font_size = 16 elif win_wd >= 600 : font_size = 14 elif win_wd >= 500 : font_size = 12 elif win_wd >= 400 : font_size = 11 elif win_wd >= 300 : font_size = 10 elif win_wd >= 250 : font_size = 8 elif win_wd >= 200 : font_size = 6 return font_size | Heuristic to calculate an appropriate font size based on the width of the viewer window . |
24,995 | def popup ( self , title , callfn , initialdir = None , filename = None ) : self . cb = callfn self . filew . set_title ( title ) if initialdir : self . filew . set_current_folder ( initialdir ) if filename : self . filew . set_current_name ( filename ) self . filew . show ( ) | Let user select and load file . |
24,996 | def get_fileinfo ( self , filespec , dldir = None ) : if dldir is None : dldir = self . tmpdir info = iohelper . get_fileinfo ( filespec , cache_dir = dldir ) | Break down a file specification into its components . |
24,997 | def zoomset_cb ( self , setting , zoomlevel , fitsimage ) : if not self . gui_up : return fac_x , fac_y = fitsimage . get_scale_base_xy ( ) fac_x_me , fac_y_me = self . zoomimage . get_scale_base_xy ( ) if ( fac_x != fac_x_me ) or ( fac_y != fac_y_me ) : alg = fitsimage . get_zoom_algorithm ( ) self . zoomimage . set_zoom_algorithm ( alg ) self . zoomimage . set_scale_base_xy ( fac_x , fac_y ) return self . _zoomset ( self . fitsimage_focus , zoomlevel ) | This method is called when a main FITS widget changes zoom level . |
24,998 | def set_amount_cb ( self , widget , val ) : self . zoom_amount = val zoomlevel = self . fitsimage_focus . get_zoom ( ) self . _zoomset ( self . fitsimage_focus , zoomlevel ) | This method is called when Zoom Amount control is adjusted . |
24,999 | def _slice ( self , view ) : if self . _data is not None : return self . _data [ view ] return self . _proxy . get_view ( self . id , view ) | Send view to remote server and do slicing there . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.