idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
231,600
def common_start ( strings ) : def gen_start_strings ( string ) : for i in xrange ( 1 , len ( string ) + 1 ) : yield string [ : i ] if not strings : return "" start_string = "" for start_string in gen_start_strings ( max ( strings ) ) : if not all ( string . startswith ( start_string ) for string in strings ) : return ...
Returns start sub - string that is common for all given strings
231,601
def is_svg ( code ) : if rsvg is None : return try : rsvg . Handle ( data = code ) except glib . GError : return False if "http://www.w3.org/2000/svg" in code [ : 1000 ] : return True return False
Checks if code is an svg image
231,602
def _get_dialog_title ( self ) : title_filetype = self . filetype [ 0 ] . upper ( ) + self . filetype [ 1 : ] if self . filetype == "print" : title_export = "" else : title_export = " export" return _ ( "{filetype}{export} options" ) . format ( filetype = title_filetype , export = title_export )
Returns title string
231,603
def on_page_layout_choice ( self , event ) : width , height = self . paper_sizes_points [ event . GetString ( ) ] self . page_width_text_ctrl . SetValue ( str ( width / 72.0 ) ) self . page_height_text_ctrl . SetValue ( str ( height / 72.0 ) ) event . Skip ( )
Page layout choice event handler
231,604
def get_info ( self ) : info = { } info [ "top_row" ] = self . top_row_text_ctrl . GetValue ( ) info [ "bottom_row" ] = self . bottom_row_text_ctrl . GetValue ( ) info [ "left_col" ] = self . left_col_text_ctrl . GetValue ( ) info [ "right_col" ] = self . right_col_text_ctrl . GetValue ( ) info [ "first_tab" ] = self ....
Returns a dict with the dialog PDF info
231,605
def get_program_path ( ) : src_folder = os . path . dirname ( __file__ ) program_path = os . sep . join ( src_folder . split ( os . sep ) [ : - 1 ] ) + os . sep return program_path
Returns the path in which pyspread is installed
231,606
def get_dpi ( ) : def pxmm_2_dpi ( ( pixels , length_mm ) ) : return pixels * 25.6 / length_mm return map ( pxmm_2_dpi , zip ( wx . GetDisplaySize ( ) , wx . GetDisplaySizeMM ( ) ) )
Returns screen dpi resolution
231,607
def get_font_list ( ) : font_map = pangocairo . cairo_font_map_get_default ( ) font_list = [ f . get_name ( ) for f in font_map . list_families ( ) ] font_list . sort ( ) return font_list
Returns a sorted list of all system font names
231,608
def get_dependencies ( ) : dependencies = [ ] dep_attrs = { "name" : "numpy" , "min_version" : "1.1.0" , "description" : "required" , } try : import numpy dep_attrs [ "version" ] = numpy . version . version except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "w...
Returns list of dicts which indicate installed dependencies
231,609
def get_cell_rect ( self , row , col , tab ) : top_row = self . row_tb [ 0 ] left_col = self . col_rl [ 0 ] pos_x = self . x_offset pos_y = self . y_offset merge_area = self . _get_merge_area ( ( row , col , tab ) ) for __row in xrange ( top_row , row ) : __row_height = self . code_array . get_row_height ( __row , tab ...
Returns rectangle of cell on canvas
231,610
def draw ( self ) : row_start , row_stop = self . row_tb col_start , col_stop = self . col_rl tab_start , tab_stop = self . tab_fl for tab in xrange ( tab_start , tab_stop ) : first_key = row_start , col_start , tab first_rect = self . get_cell_rect ( * first_key ) if first_rect is None : top , left , __ , __ = self . ...
Draws slice to context
231,611
def draw ( self ) : cell_background_renderer = GridCellBackgroundCairoRenderer ( self . context , self . code_array , self . key , self . rect , self . view_frozen ) cell_content_renderer = GridCellContentCairoRenderer ( self . context , self . code_array , self . key , self . rect , self . spell_check ) cell_border_re...
Draws cell to context
231,612
def get_cell_content ( self ) : try : if self . code_array . cell_attributes [ self . key ] [ "button_cell" ] : return except IndexError : return try : return self . code_array [ self . key ] except IndexError : pass
Returns cell content
231,613
def _get_scalexy ( self , ims_width , ims_height ) : cell_attributes = self . code_array . cell_attributes [ self . key ] angle = cell_attributes [ "angle" ] if abs ( angle ) == 90 : scale_x = self . rect [ 3 ] / float ( ims_width ) scale_y = self . rect [ 2 ] / float ( ims_height ) else : scale_x = self . rect [ 2 ] /...
Returns scale_x scale_y for bitmap display
231,614
def _get_translation ( self , ims_width , ims_height ) : cell_attributes = self . code_array . cell_attributes [ self . key ] justification = cell_attributes [ "justification" ] vertical_align = cell_attributes [ "vertical_align" ] angle = cell_attributes [ "angle" ] scale_x , scale_y = self . _get_scalexy ( ims_width ...
Returns x and y for a bitmap translation
231,615
def draw_bitmap ( self , content ) : if content . HasAlpha ( ) : image = wx . ImageFromBitmap ( content ) image . ConvertAlphaToMask ( ) image . SetMask ( False ) content = wx . BitmapFromImage ( image ) ims = wx . lib . wxcairo . ImageSurfaceFromBitmap ( content ) ims_width = ims . get_width ( ) ims_height = ims . get...
Draws bitmap cell content to context
231,616
def draw_svg ( self , svg_str ) : try : import rsvg except ImportError : self . draw_text ( svg_str ) return svg = rsvg . Handle ( data = svg_str ) svg_width , svg_height = svg . get_dimension_data ( ) [ : 2 ] transx , transy = self . _get_translation ( svg_width , svg_height ) scale_x , scale_y = self . _get_scalexy (...
Draws svg string to cell
231,617
def draw_matplotlib_figure ( self , figure ) : class CustomRendererCairo ( RendererCairo ) : if sys . byteorder == 'little' : BYTE_FORMAT = 0 else : BYTE_FORMAT = 1 def draw_path ( self , gc , path , transform , rgbFace = None ) : ctx = gc . ctx transform = transform + Affine2D ( ) . scale ( 1.0 , - 1.0 ) . translate (...
Draws matplotlib figure to context
231,618
def _get_text_color ( self ) : color = self . code_array . cell_attributes [ self . key ] [ "textcolor" ] return tuple ( c / 255.0 for c in color_pack2rgb ( color ) )
Returns text color rgb tuple of right line
231,619
def set_font ( self , pango_layout ) : wx2pango_weights = { wx . FONTWEIGHT_BOLD : pango . WEIGHT_BOLD , wx . FONTWEIGHT_LIGHT : pango . WEIGHT_LIGHT , wx . FONTWEIGHT_NORMAL : None , } wx2pango_styles = { wx . FONTSTYLE_NORMAL : None , wx . FONTSTYLE_SLANT : pango . STYLE_OBLIQUE , wx . FONTSTYLE_ITALIC : pango . STYL...
Sets the font for draw_text
231,620
def _draw_error_underline ( self , ptx , pango_layout , start , stop ) : self . context . save ( ) self . context . set_source_rgb ( 1.0 , 0.0 , 0.0 ) pit = pango_layout . get_iter ( ) for i in xrange ( start ) : pit . next_char ( ) extents_list = [ ] for char_no in xrange ( start , stop ) : char_extents = pit . get_ch...
Draws an error underline
231,621
def _check_spelling ( self , text , lang = "en_US" ) : chkr = SpellChecker ( lang ) chkr . set_text ( text ) word_starts_ends = [ ] for err in chkr : start = err . wordpos stop = err . wordpos + len ( err . word ) + 1 word_starts_ends . append ( ( start , stop ) ) return word_starts_ends
Returns a list of start stop tuples that have spelling errors
231,622
def draw_text ( self , content ) : wx2pango_alignment = { "left" : pango . ALIGN_LEFT , "center" : pango . ALIGN_CENTER , "right" : pango . ALIGN_RIGHT , } cell_attributes = self . code_array . cell_attributes [ self . key ] angle = cell_attributes [ "angle" ] if angle in [ - 90 , 90 ] : rect = self . rect [ 1 ] , self...
Draws text cell content to context
231,623
def draw_roundedrect ( self , x , y , w , h , r = 10 ) : context = self . context context . save context . move_to ( x + r , y ) context . line_to ( x + w - r , y ) context . curve_to ( x + w , y , x + w , y , x + w , y + r ) context . line_to ( x + w , y + h - r ) context . curve_to ( x + w , y + h , x + w , y + h , x...
Draws a rounded rectangle
231,624
def draw_button ( self , x , y , w , h , label ) : context = self . context self . draw_roundedrect ( x , y , w , h ) context . clip ( ) gradient = cairo . LinearGradient ( 0 , 0 , 0 , 1 ) gradient . add_color_stop_rgba ( 0 , 0.5 , 0.5 , 0.5 , 0.1 ) gradient . add_color_stop_rgba ( 1 , 0.8 , 0.8 , 0.8 , 0.9 ) context ....
Draws a button
231,625
def draw ( self ) : self . context . save ( ) self . context . rectangle ( * self . rect ) self . context . clip ( ) content = self . get_cell_content ( ) pos_x , pos_y = self . rect [ : 2 ] self . context . translate ( pos_x + 2 , pos_y + 2 ) cell_attributes = self . code_array . cell_attributes if self . rect [ 2 ] <...
Draws cell content to context
231,626
def _get_background_color ( self ) : color = self . cell_attributes [ self . key ] [ "bgcolor" ] return tuple ( c / 255.0 for c in color_pack2rgb ( color ) )
Returns background color rgb tuple of right line
231,627
def _draw_frozen_pattern ( self ) : self . context . save ( ) x , y , w , h = self . rect self . context . set_source_rgb ( 0 , 0 , 1 ) self . context . set_line_width ( 0.25 ) self . context . rectangle ( * self . rect ) self . context . clip ( ) for __x in numpy . arange ( x - h , x + w , 5 ) : self . context . move_...
Draws frozen pattern i . e . diagonal lines
231,628
def draw ( self ) : self . context . set_source_rgb ( * self . _get_background_color ( ) ) self . context . rectangle ( * self . rect ) self . context . fill ( ) if self . view_frozen and self . cell_attributes [ self . key ] [ "frozen" ] : self . _draw_frozen_pattern ( )
Draws cell background to context
231,629
def draw ( self , context ) : context . set_line_width ( self . width ) context . set_source_rgb ( * self . color ) context . move_to ( * self . start_point ) context . line_to ( * self . end_point ) context . stroke ( )
Draws self to Cairo context
231,630
def get_above_key_rect ( self ) : key_above = self . row - 1 , self . col , self . tab border_width_bottom = float ( self . cell_attributes [ key_above ] [ "borderwidth_bottom" ] ) / 2.0 rect_above = ( self . x , self . y - border_width_bottom , self . width , border_width_bottom ) return key_above , rect_above
Returns tuple key rect of above cell
231,631
def get_below_key_rect ( self ) : key_below = self . row + 1 , self . col , self . tab border_width_bottom = float ( self . cell_attributes [ self . key ] [ "borderwidth_bottom" ] ) / 2.0 rect_below = ( self . x , self . y + self . height , self . width , border_width_bottom ) return key_below , rect_below
Returns tuple key rect of below cell
231,632
def get_left_key_rect ( self ) : key_left = self . row , self . col - 1 , self . tab border_width_right = float ( self . cell_attributes [ key_left ] [ "borderwidth_right" ] ) / 2.0 rect_left = ( self . x - border_width_right , self . y , border_width_right , self . height ) return key_left , rect_left
Returns tuple key rect of left cell
231,633
def get_right_key_rect ( self ) : key_right = self . row , self . col + 1 , self . tab border_width_right = float ( self . cell_attributes [ self . key ] [ "borderwidth_right" ] ) / 2.0 rect_right = ( self . x + self . width , self . y , border_width_right , self . height ) return key_right , rect_right
Returns tuple key rect of right cell
231,634
def get_above_left_key_rect ( self ) : key_above_left = self . row - 1 , self . col - 1 , self . tab border_width_right = float ( self . cell_attributes [ key_above_left ] [ "borderwidth_right" ] ) / 2.0 border_width_bottom = float ( self . cell_attributes [ key_above_left ] [ "borderwidth_bottom" ] ) / 2.0 rect_above_...
Returns tuple key rect of above left cell
231,635
def get_above_right_key_rect ( self ) : key_above = self . row - 1 , self . col , self . tab key_above_right = self . row - 1 , self . col + 1 , self . tab border_width_right = float ( self . cell_attributes [ key_above ] [ "borderwidth_right" ] ) / 2.0 border_width_bottom = float ( self . cell_attributes [ key_above_r...
Returns tuple key rect of above right cell
231,636
def get_below_left_key_rect ( self ) : key_left = self . row , self . col - 1 , self . tab key_below_left = self . row + 1 , self . col - 1 , self . tab border_width_right = float ( self . cell_attributes [ key_below_left ] [ "borderwidth_right" ] ) / 2.0 border_width_bottom = float ( self . cell_attributes [ key_left ...
Returns tuple key rect of below left cell
231,637
def get_below_right_key_rect ( self ) : key_below_right = self . row + 1 , self . col + 1 , self . tab border_width_right = float ( self . cell_attributes [ self . key ] [ "borderwidth_right" ] ) / 2.0 border_width_bottom = float ( self . cell_attributes [ self . key ] [ "borderwidth_bottom" ] ) / 2.0 rect_below_right ...
Returns tuple key rect of below right cell
231,638
def _get_bottom_line_coordinates ( self ) : rect_x , rect_y , rect_width , rect_height = self . rect start_point = rect_x , rect_y + rect_height end_point = rect_x + rect_width , rect_y + rect_height return start_point , end_point
Returns start and stop coordinates of bottom line
231,639
def _get_bottom_line_color ( self ) : color = self . cell_attributes [ self . key ] [ "bordercolor_bottom" ] return tuple ( c / 255.0 for c in color_pack2rgb ( color ) )
Returns color rgb tuple of bottom line
231,640
def _get_right_line_color ( self ) : color = self . cell_attributes [ self . key ] [ "bordercolor_right" ] return tuple ( c / 255.0 for c in color_pack2rgb ( color ) )
Returns color rgb tuple of right line
231,641
def get_b ( self ) : start_point , end_point = self . _get_bottom_line_coordinates ( ) width = self . _get_bottom_line_width ( ) color = self . _get_bottom_line_color ( ) return CellBorder ( start_point , end_point , width , color )
Returns the bottom border of the cell
231,642
def get_r ( self ) : start_point , end_point = self . _get_right_line_coordinates ( ) width = self . _get_right_line_width ( ) color = self . _get_right_line_color ( ) return CellBorder ( start_point , end_point , width , color )
Returns the right border of the cell
231,643
def get_t ( self ) : cell_above = CellBorders ( self . cell_attributes , * self . cell . get_above_key_rect ( ) ) return cell_above . get_b ( )
Returns the top border of the cell
231,644
def get_l ( self ) : cell_left = CellBorders ( self . cell_attributes , * self . cell . get_left_key_rect ( ) ) return cell_left . get_r ( )
Returns the left border of the cell
231,645
def get_tl ( self ) : cell_above_left = CellBorders ( self . cell_attributes , * self . cell . get_above_left_key_rect ( ) ) return cell_above_left . get_r ( )
Returns the top left border of the cell
231,646
def get_tr ( self ) : cell_above = CellBorders ( self . cell_attributes , * self . cell . get_above_key_rect ( ) ) return cell_above . get_r ( )
Returns the top right border of the cell
231,647
def get_rt ( self ) : cell_above_right = CellBorders ( self . cell_attributes , * self . cell . get_above_right_key_rect ( ) ) return cell_above_right . get_b ( )
Returns the right top border of the cell
231,648
def get_rb ( self ) : cell_right = CellBorders ( self . cell_attributes , * self . cell . get_right_key_rect ( ) ) return cell_right . get_b ( )
Returns the right bottom border of the cell
231,649
def get_br ( self ) : cell_below = CellBorders ( self . cell_attributes , * self . cell . get_below_key_rect ( ) ) return cell_below . get_r ( )
Returns the bottom right border of the cell
231,650
def get_bl ( self ) : cell_below_left = CellBorders ( self . cell_attributes , * self . cell . get_below_left_key_rect ( ) ) return cell_below_left . get_r ( )
Returns the bottom left border of the cell
231,651
def get_lb ( self ) : cell_left = CellBorders ( self . cell_attributes , * self . cell . get_left_key_rect ( ) ) return cell_left . get_b ( )
Returns the left bottom border of the cell
231,652
def get_lt ( self ) : cell_above_left = CellBorders ( self . cell_attributes , * self . cell . get_above_left_key_rect ( ) ) return cell_above_left . get_b ( )
Returns the left top border of the cell
231,653
def gen_all ( self ) : borderfuncs = [ self . get_b , self . get_r , self . get_t , self . get_l , self . get_tl , self . get_tr , self . get_rt , self . get_rb , self . get_br , self . get_bl , self . get_lb , self . get_lt , ] for borderfunc in borderfuncs : yield borderfunc ( )
Generator of all borders
231,654
def draw ( self ) : self . context . set_line_cap ( cairo . LINE_CAP_SQUARE ) self . context . save ( ) self . context . rectangle ( * self . rect ) self . context . clip ( ) cell_borders = CellBorders ( self . cell_attributes , self . key , self . rect ) borders = list ( cell_borders . gen_all ( ) ) borders . sort ( k...
Draws cell border to context
231,655
def _draw_cursor ( self , dc , grid , row , col , pen = None , brush = None ) : if grid . main_window . IsFullScreen ( ) : return key = row , col , grid . current_table rect = grid . CellToRect ( row , col ) rect = self . get_merged_rect ( grid , key , rect ) if rect is None : return size = self . get_zoomed_size ( 1.0...
Draws cursor as Rectangle in lower right corner
231,656
def update_cursor ( self , dc , grid , row , col ) : old_row , old_col = self . old_cursor_row_col bgcolor = get_color ( config [ "background_color" ] ) self . _draw_cursor ( dc , grid , old_row , old_col , pen = wx . Pen ( bgcolor ) , brush = wx . Brush ( bgcolor ) ) self . _draw_cursor ( dc , grid , row , col )
Whites out the old cursor and draws the new one
231,657
def get_merged_rect ( self , grid , key , rect ) : row , col , tab = key cell_attributes = grid . code_array . cell_attributes merge_area = cell_attributes [ ( row , col , tab ) ] [ "merge_area" ] if merge_area is None : return rect else : top , left , bottom , right = merge_area if top == row and left == col : ul_rect...
Returns cell rect for normal or merged cells and None for merged
231,658
def _get_drawn_rect ( self , grid , key , rect ) : rect = self . get_merged_rect ( grid , key , rect ) if rect is None : if grid . is_merged_cell_drawn ( key ) : row , col , __ = key = self . get_merging_cell ( grid , key ) rect = grid . CellToRect ( row , col ) rect = self . get_merged_rect ( grid , key , rect ) else ...
Replaces drawn rect if the one provided by wx is incorrect
231,659
def _get_draw_cache_key ( self , grid , key , drawn_rect , is_selected ) : row , col , tab = key cell_attributes = grid . code_array . cell_attributes zoomed_width = drawn_rect . width / self . zoom zoomed_height = drawn_rect . height / self . zoom if grid . code_array . cell_attributes [ key ] [ "button_cell" ] : cell...
Returns key for the screen draw cache
231,660
def _get_cairo_bmp ( self , mdc , key , rect , is_selected , view_frozen ) : bmp = wx . EmptyBitmap ( rect . width , rect . height ) mdc . SelectObject ( bmp ) mdc . SetBackgroundMode ( wx . SOLID ) mdc . SetBackground ( wx . WHITE_BRUSH ) mdc . Clear ( ) mdc . SetDeviceOrigin ( 0 , 0 ) context = wx . lib . wxcairo . C...
Returns a wx . Bitmap of cell key in size rect
231,661
def Draw ( self , grid , attr , dc , rect , row , col , isSelected ) : key = row , col , grid . current_table if grid . code_array . cell_attributes [ key ] [ "merge_area" ] : key = self . get_merging_cell ( grid , key ) drawn_rect = self . _get_drawn_rect ( grid , key , rect ) if drawn_rect is None : return cell_cache...
Draws the cell border and content using pycairo
231,662
def choose_key ( gpg_private_keys ) : uid_strings_fp = [ ] uid_string_fp2key = { } current_key_index = None for i , key in enumerate ( gpg_private_keys ) : fingerprint = key [ 'fingerprint' ] if fingerprint == config [ "gpg_key_fingerprint" ] : current_key_index = i for uid_string in key [ 'uids' ] : uid_string_fp = '"...
Displays gpg key choice and returns key
231,663
def _register_key ( fingerprint , gpg ) : for private_key in gpg . list_keys ( True ) : try : if str ( fingerprint ) == private_key [ 'fingerprint' ] : config [ "gpg_key_fingerprint" ] = repr ( private_key [ 'fingerprint' ] ) except KeyError : pass
Registers key in config
231,664
def has_no_password ( gpg_secret_keyid ) : if gnupg is None : return False gpg = gnupg . GPG ( ) s = gpg . sign ( "" , keyid = gpg_secret_keyid , passphrase = "" ) try : return s . status == "signature created" except AttributeError : if hasattr ( s , "stderr" ) : return "GOOD_PASSPHRASE" in s . stderr
Returns True iif gpg_secret_key has a password
231,665
def genkey ( key_name = None ) : if gnupg is None : return gpg_key_param_list = [ ( 'key_type' , 'DSA' ) , ( 'key_length' , '2048' ) , ( 'subkey_type' , 'ELG-E' ) , ( 'subkey_length' , '2048' ) , ( 'expire_date' , '0' ) , ] gpg = gnupg . GPG ( ) gpg . encoding = 'utf-8' pyspread_key_fingerprint = config [ "gpg_key_fing...
Creates a new standard GPG key
231,666
def fingerprint2keyid ( fingerprint ) : if gnupg is None : return gpg = gnupg . GPG ( ) private_keys = gpg . list_keys ( True ) keyid = None for private_key in private_keys : if private_key [ 'fingerprint' ] == config [ "gpg_key_fingerprint" ] : keyid = private_key [ 'keyid' ] break return keyid
Returns keyid from fingerprint for private keys
231,667
def sign ( filename ) : if gnupg is None : return gpg = gnupg . GPG ( ) with open ( filename , "rb" ) as signfile : keyid = fingerprint2keyid ( config [ "gpg_key_fingerprint" ] ) if keyid is None : msg = "No private key for GPG fingerprint '{}'." raise ValueError ( msg . format ( config [ "gpg_key_fingerprint" ] ) ) si...
Returns detached signature for file
231,668
def verify ( sigfilename , filefilename = None ) : if gnupg is None : return False gpg = gnupg . GPG ( ) with open ( sigfilename , "rb" ) as sigfile : verified = gpg . verify_file ( sigfile , filefilename ) pyspread_keyid = fingerprint2keyid ( config [ "gpg_key_fingerprint" ] ) if verified . valid and verified . key_id...
Verifies a signature returns True if successful else False .
231,669
def _len_table_cache ( self ) : length = 0 for table in self . _table_cache : length += len ( self . _table_cache [ table ] ) return length
Returns the length of the table cache
231,670
def _update_table_cache ( self ) : self . _table_cache . clear ( ) for sel , tab , val in self : try : self . _table_cache [ tab ] . append ( ( sel , val ) ) except KeyError : self . _table_cache [ tab ] = [ ( sel , val ) ] assert len ( self ) == self . _len_table_cache ( )
Clears and updates the table cache to be in sync with self
231,671
def get_merging_cell ( self , key ) : row , col , tab = key merge_area = self [ key ] [ "merge_area" ] if merge_area : return merge_area [ 0 ] , merge_area [ 1 ] , tab
Returns key of cell that merges the cell key
231,672
def _get_data ( self ) : data = { } data [ "shape" ] = self . shape data [ "grid" ] = { } . update ( self . dict_grid ) data [ "attributes" ] = [ ca for ca in self . cell_attributes ] data [ "row_heights" ] = self . row_heights data [ "col_widths" ] = self . col_widths data [ "macros" ] = self . macros return data
Returns dict of data content .
231,673
def _set_data ( self , ** kwargs ) : if "shape" in kwargs : self . shape = kwargs [ "shape" ] if "grid" in kwargs : self . dict_grid . clear ( ) self . dict_grid . update ( kwargs [ "grid" ] ) if "attributes" in kwargs : self . attributes [ : ] = kwargs [ "attributes" ] if "row_heights" in kwargs : self . row_heights =...
Sets data from given parameters
231,674
def get_row_height ( self , row , tab ) : try : return self . row_heights [ ( row , tab ) ] except KeyError : return config [ "default_row_height" ]
Returns row height
231,675
def get_col_width ( self , col , tab ) : try : return self . col_widths [ ( col , tab ) ] except KeyError : return config [ "default_col_width" ]
Returns column width
231,676
def _set_shape ( self , shape ) : old_shape = self . shape deleted_cells = { } if any ( new_axis < old_axis for new_axis , old_axis in zip ( shape , old_shape ) ) : for key in self . dict_grid . keys ( ) : if any ( key_ele >= new_axis for key_ele , new_axis in zip ( key , shape ) ) : deleted_cells [ key ] = self . pop ...
Deletes all cells beyond new shape and sets dict_grid shape
231,677
def get_last_filled_cell ( self , table = None ) : maxrow = 0 maxcol = 0 for row , col , tab in self . dict_grid : if table is None or tab == table : maxrow = max ( row , maxrow ) maxcol = max ( col , maxcol ) return maxrow , maxcol , table
Returns key for the bottommost rightmost cell with content
231,678
def cell_array_generator ( self , key ) : for i , key_ele in enumerate ( key ) : if type ( key_ele ) is SliceType : slc_keys = xrange ( * key_ele . indices ( self . dict_grid . shape [ i ] ) ) key_list = list ( key ) key_list [ i ] = None has_subslice = any ( type ( ele ) is SliceType for ele in key_list ) for slc_key ...
Generator traversing cells specified in key
231,679
def _shift_rowcol ( self , insertion_point , no_to_insert ) : new_row_heights = { } del_row_heights = [ ] for row , tab in self . row_heights : if tab > insertion_point : new_row_heights [ ( row , tab + no_to_insert ) ] = self . row_heights [ ( row , tab ) ] del_row_heights . append ( ( row , tab ) ) for row , tab in n...
Shifts row and column sizes when a table is inserted or deleted
231,680
def _get_adjusted_merge_area ( self , attrs , insertion_point , no_to_insert , axis ) : assert axis in range ( 2 ) if "merge_area" not in attrs or attrs [ "merge_area" ] is None : return top , left , bottom , right = attrs [ "merge_area" ] selection = Selection ( [ ( top , left ) ] , [ ( bottom , right ) ] , [ ] , [ ] ...
Returns updated merge area
231,681
def set_row_height ( self , row , tab , height ) : try : old_height = self . row_heights . pop ( ( row , tab ) ) except KeyError : old_height = None if height is not None : self . row_heights [ ( row , tab ) ] = float ( height )
Sets row height
231,682
def set_col_width ( self , col , tab , width ) : try : old_width = self . col_widths . pop ( ( col , tab ) ) except KeyError : old_width = None if width is not None : self . col_widths [ ( col , tab ) ] = float ( width )
Sets column width
231,683
def _make_nested_list ( self , gen ) : res = [ ] for ele in gen : if ele is None : res . append ( None ) elif not is_string_like ( ele ) and is_generator_like ( ele ) : res . append ( self . _make_nested_list ( ele ) ) else : res . append ( ele ) return res
Makes nested list from generator for creating numpy . array
231,684
def _get_assignment_target_end ( self , ast_module ) : if len ( ast_module . body ) > 1 : raise ValueError ( "More than one expression or assignment." ) elif len ( ast_module . body ) > 0 and type ( ast_module . body [ 0 ] ) is ast . Assign : if len ( ast_module . body [ 0 ] . targets ) != 1 : raise ValueError ( "More ...
Returns position of 1st char after assignment traget .
231,685
def _get_updated_environment ( self , env_dict = None ) : if env_dict is None : env_dict = { 'S' : self } env = globals ( ) . copy ( ) env . update ( env_dict ) return env
Returns globals environment with magic variable
231,686
def _eval_cell ( self , key , code ) : def nn ( val ) : try : return numpy . array ( filter ( None , val . flat ) ) except AttributeError : return numpy . array ( filter ( None , val ) ) env_dict = { 'X' : key [ 0 ] , 'Y' : key [ 1 ] , 'Z' : key [ 2 ] , 'bz2' : bz2 , 'base64' : base64 , 'charts' : charts , 'nn' : nn , ...
Evaluates one cell and returns its result
231,687
def pop ( self , key ) : try : self . result_cache . pop ( repr ( key ) ) except KeyError : pass return DataArray . pop ( self , key )
Pops dict_grid with undo and redo support
231,688
def reload_modules ( self ) : import src . lib . charts as charts from src . gui . grid_panels import vlcpanel_factory modules = [ charts , bz2 , base64 , re , ast , sys , wx , numpy , datetime ] for module in modules : reload ( module )
Reloads modules that are available in cells
231,689
def clear_globals ( self ) : base_keys = [ 'cStringIO' , 'IntType' , 'KeyValueStore' , 'undoable' , 'is_generator_like' , 'is_string_like' , 'bz2' , 'base64' , '__package__' , 're' , 'config' , '__doc__' , 'SliceType' , 'CellAttributes' , 'product' , 'ast' , '__builtins__' , '__file__' , 'charts' , 'sys' , 'is_slice_li...
Clears all newly assigned globals
231,690
def execute_macros ( self ) : if self . safe_mode : return '' , "Safe mode activated. Code not executed." self . macros = self . macros . replace ( '\r\n' , '\n' ) globals ( ) . update ( self . _get_updated_environment ( ) ) code_out = cStringIO . StringIO ( ) code_err = cStringIO . StringIO ( ) err_msg = cStringIO . S...
Executes all macros and returns result string
231,691
def _sorted_keys ( self , keys , startkey , reverse = False ) : tuple_key = lambda t : t [ : : - 1 ] if reverse : tuple_cmp = lambda t : t [ : : - 1 ] > startkey [ : : - 1 ] else : tuple_cmp = lambda t : t [ : : - 1 ] < startkey [ : : - 1 ] searchkeys = sorted ( keys , key = tuple_key , reverse = reverse ) searchpos = ...
Generator that yields sorted keys starting with startkey
231,692
def findnextmatch ( self , startkey , find_string , flags , search_result = True ) : assert "UP" in flags or "DOWN" in flags assert not ( "UP" in flags and "DOWN" in flags ) if search_result : def is_matching ( key , find_string , flags ) : code = self ( key ) if self . string_match ( code , find_string , flags ) is no...
Returns a tuple with the position of the next match of find_string
231,693
def Validate ( self , win ) : val = self . GetWindow ( ) . GetValue ( ) for x in val : if x not in string . digits : return False return True
Returns True if Value in digits False otherwise
231,694
def OnChar ( self , event ) : key = event . GetKeyCode ( ) if key < wx . WXK_SPACE or key == wx . WXK_DELETE or key > 255 or chr ( key ) in string . digits : event . Skip ( )
Eats event if key not in digits
231,695
def Draw ( self , grid , attr , dc , rect , row , col , is_selected ) : render = wx . RendererNative . Get ( ) dc . SetBackgroundMode ( wx . SOLID ) if is_selected : dc . SetBrush ( wx . Brush ( wx . BLUE , wx . SOLID ) ) dc . SetPen ( wx . Pen ( wx . BLUE , 1 , wx . SOLID ) ) else : dc . SetBrush ( wx . Brush ( wx . W...
Draws the text and the combobox icon
231,696
def _setup_param_widgets ( self ) : for parameter in self . csv_params : pname , ptype , plabel , phelp = parameter label = wx . StaticText ( self . parent , - 1 , plabel ) widget = self . type2widget [ ptype ] ( self . parent ) if pname in self . choices : widget . AppendItems ( self . choices [ pname ] ) widget . Set...
Creates the parameter entry widgets and binds them to methods
231,697
def _do_layout ( self ) : sizer_csvoptions = wx . FlexGridSizer ( 5 , 4 , 5 , 5 ) leftpos = wx . LEFT | wx . ADJUST_MINSIZE rightpos = wx . RIGHT | wx . EXPAND current_label_margin = 0 other_label_margin = 15 for label , widget in zip ( self . param_labels , self . param_widgets ) : sizer_csvoptions . Add ( label , 0 ,...
Sizer hell returns a sizer that contains all widgets
231,698
def _update_settings ( self , dialect ) : for parameter in self . csv_params [ 2 : ] : pname , ptype , plabel , phelp = parameter widget = self . _widget_from_p ( pname , ptype ) if ptype is types . TupleType : ptype = types . ObjectType digest = Digest ( acceptable_types = [ ptype ] ) if pname == 'self.has_header' : i...
Sets the widget settings to those of the chosen dialect
231,699
def _widget_from_p ( self , pname , ptype ) : widget_name = self . type2widget [ ptype ] . __name__ . lower ( ) widget_name = "_" . join ( [ widget_name , pname ] ) return getattr ( self , widget_name )
Returns a widget from its ptype and pname