idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
42,700
def OnKey ( self , event ) : def switch_to_next_table ( ) : newtable = self . grid . current_table + 1 post_command_event ( self . grid , self . GridActionTableSwitchMsg , newtable = newtable ) def switch_to_previous_table ( ) : newtable = self . grid . current_table - 1 post_command_event ( self . grid , self . GridActionTableSwitchMsg , newtable = newtable ) grid = self . grid actions = grid . actions shift , alt , ctrl = 1 , 1 << 1 , 1 << 2 shortcuts = { ( 0 , 27 ) : lambda : setattr ( actions , "need_abort" , True ) , ( 0 , 127 ) : actions . delete , ( 0 , 313 ) : lambda : actions . set_cursor ( ( grid . GetGridCursorRow ( ) , 0 ) ) , ( ctrl , 82 ) : actions . copy_selection_access_string , ( ctrl , 388 ) : actions . zoom_in , ( ctrl , 390 ) : actions . zoom_out , ( shift , 32 ) : lambda : grid . SelectRow ( grid . GetGridCursorRow ( ) ) , ( ctrl , 32 ) : lambda : grid . SelectCol ( grid . GetGridCursorCol ( ) ) , ( shift | ctrl , 32 ) : grid . SelectAll , } if self . main_window . IsFullScreen ( ) : shortcuts [ ( 0 , 315 ) ] = switch_to_previous_table shortcuts [ ( 0 , 317 ) ] = switch_to_next_table shortcuts [ ( 0 , 32 ) ] = switch_to_next_table keycode = event . GetKeyCode ( ) modifier = shift * event . ShiftDown ( ) | alt * event . AltDown ( ) | ctrl * event . ControlDown ( ) if ( modifier , keycode ) in shortcuts : shortcuts [ ( modifier , keycode ) ] ( ) else : event . Skip ( )
Handles non - standard shortcut events
42,701
def OnRangeSelected ( self , event ) : if not self . grid . IsEditable ( ) : selection = self . grid . selection row , col , __ = self . grid . sel_mode_cursor if ( row , col ) in selection : self . grid . ClearSelection ( ) else : self . grid . SetGridCursor ( row , col ) post_command_event ( self . grid , self . grid . SelectionMsg , selection = selection )
Event handler for grid selection
42,702
def OnViewFrozen ( self , event ) : self . grid . _view_frozen = not self . grid . _view_frozen self . grid . grid_renderer . cell_cache . clear ( ) self . grid . ForceRefresh ( ) event . Skip ( )
Show cells as frozen status
42,703
def OnGoToCell ( self , event ) : row , col , tab = event . key try : self . grid . actions . cursor = row , col , tab except ValueError : msg = _ ( "Cell {key} outside grid shape {shape}" ) . format ( key = event . key , shape = self . grid . code_array . shape ) post_command_event ( self . grid . main_window , self . grid . StatusBarMsg , text = msg ) event . Skip ( ) return self . grid . MakeCellVisible ( row , col ) event . Skip ( )
Shift a given cell into view
42,704
def OnEnterSelectionMode ( self , event ) : self . grid . sel_mode_cursor = list ( self . grid . actions . cursor ) self . grid . EnableDragGridSize ( False ) self . grid . EnableEditing ( False )
Event handler for entering selection mode disables cell edits
42,705
def OnExitSelectionMode ( self , event ) : self . grid . sel_mode_cursor = None self . grid . EnableDragGridSize ( True ) self . grid . EnableEditing ( True )
Event handler for leaving selection mode enables cell edits
42,706
def OnRefreshSelectedCells ( self , event ) : self . grid . actions . refresh_selected_frozen_cells ( ) self . grid . ForceRefresh ( ) event . Skip ( )
Event handler for refreshing the selected cells via menu
42,707
def OnTimerToggle ( self , event ) : if self . grid . timer_running : self . grid . timer_running = False self . grid . timer . Stop ( ) del self . grid . timer else : self . grid . timer_running = True self . grid . timer = wx . Timer ( self . grid ) self . grid . timer . Start ( config [ "timer_interval" ] )
Toggles the timer for updating frozen cells
42,708
def OnTimer ( self , event ) : self . timer_updating = True shape = self . grid . code_array . shape [ : 2 ] selection = Selection ( [ ( 0 , 0 ) ] , [ ( shape ) ] , [ ] , [ ] , [ ] ) self . grid . actions . refresh_selected_frozen_cells ( selection ) self . grid . ForceRefresh ( )
Update all frozen cells because of timer call
42,709
def OnZoomStandard ( self , event ) : self . grid . actions . zoom ( zoom = 1.0 ) event . Skip ( )
Event handler for resetting grid zoom
42,710
def OnContextMenu ( self , event ) : self . grid . PopupMenu ( self . grid . contextmenu ) event . Skip ( )
Context menu event handler
42,711
def OnMouseWheel ( self , event ) : if event . ControlDown ( ) : if event . WheelRotation > 0 : post_command_event ( self . grid , self . grid . ZoomInMsg ) else : post_command_event ( self . grid , self . grid . ZoomOutMsg ) elif self . main_window . IsFullScreen ( ) : if event . WheelRotation > 0 : newtable = self . grid . current_table - 1 else : newtable = self . grid . current_table + 1 post_command_event ( self . grid , self . GridActionTableSwitchMsg , newtable = newtable ) return else : wheel_speed = config [ "mouse_wheel_speed_factor" ] x , y = self . grid . GetViewStart ( ) direction = wheel_speed if event . GetWheelRotation ( ) < 0 else - wheel_speed if event . ShiftDown ( ) : self . grid . Scroll ( x + direction , y ) else : self . grid . Scroll ( x , y + direction )
Event handler for mouse wheel actions
42,712
def OnFind ( self , event ) : gridpos = list ( self . grid . actions . cursor ) text , flags = event . text , event . flags findpos = self . grid . actions . find ( gridpos , text , flags ) if findpos is None : statustext = _ ( "'{text}' not found." ) . format ( text = text ) else : self . grid . actions . cursor = findpos statustext = _ ( u"Found '{text}' in cell {key}." ) statustext = statustext . format ( text = text , key = findpos ) post_command_event ( self . grid . main_window , self . grid . StatusBarMsg , text = statustext ) event . Skip ( )
Find functionality called from toolbar returns find position
42,713
def OnShowFindReplace ( self , event ) : data = wx . FindReplaceData ( wx . FR_DOWN ) dlg = wx . FindReplaceDialog ( self . grid , data , "Find & Replace" , wx . FR_REPLACEDIALOG ) dlg . data = data dlg . Show ( True )
Calls the find - replace dialog
42,714
def OnReplaceFind ( self , event ) : event . text = event . GetFindString ( ) event . flags = self . _wxflag2flag ( event . GetFlags ( ) ) self . OnFind ( event )
Called when a find operation is started from F&R dialog
42,715
def OnReplace ( self , event ) : find_string = event . GetFindString ( ) flags = self . _wxflag2flag ( event . GetFlags ( ) ) replace_string = event . GetReplaceString ( ) gridpos = list ( self . grid . actions . cursor ) findpos = self . grid . actions . find ( gridpos , find_string , flags , search_result = False ) if findpos is None : statustext = _ ( u"'{find_string}' not found." ) statustext = statustext . format ( find_string = find_string ) else : with undo . group ( _ ( "Replace" ) ) : self . grid . actions . replace ( findpos , find_string , replace_string ) self . grid . actions . cursor = findpos statustext = _ ( u"Replaced '{find_string}' in cell {key} with " u"{replace_string}." ) statustext = statustext . format ( find_string = find_string , key = findpos , replace_string = replace_string ) post_command_event ( self . grid . main_window , self . grid . StatusBarMsg , text = statustext ) event . Skip ( )
Called when a replace operation is started returns find position
42,716
def OnReplaceAll ( self , event ) : find_string = event . GetFindString ( ) flags = self . _wxflag2flag ( event . GetFlags ( ) ) replace_string = event . GetReplaceString ( ) findpositions = self . grid . actions . find_all ( find_string , flags ) with undo . group ( _ ( "Replace all" ) ) : self . grid . actions . replace_all ( findpositions , find_string , replace_string ) event . Skip ( )
Called when a replace all operation is started
42,717
def _get_no_rowscols ( self , bbox ) : if bbox is None : return 1 , 1 else : ( bb_top , bb_left ) , ( bb_bottom , bb_right ) = bbox if bb_top is None : bb_top = 0 if bb_left is None : bb_left = 0 if bb_bottom is None : bb_bottom = self . grid . code_array . shape [ 0 ] - 1 if bb_right is None : bb_right = self . grid . code_array . shape [ 1 ] - 1 return bb_bottom - bb_top + 1 , bb_right - bb_left + 1
Returns tuple of number of rows and cols from bbox
42,718
def OnInsertRows ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 0 ] is None : ins_point = self . grid . actions . cursor [ 0 ] - 1 no_rows = 1 else : ins_point = bbox [ 0 ] [ 0 ] - 1 no_rows = self . _get_no_rowscols ( bbox ) [ 0 ] with undo . group ( _ ( "Insert rows" ) ) : self . grid . actions . insert_rows ( ins_point , no_rows ) self . grid . GetTable ( ) . ResetView ( ) self . grid . actions . zoom ( ) event . Skip ( )
Insert the maximum of 1 and the number of selected rows
42,719
def OnInsertCols ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 1 ] is None : ins_point = self . grid . actions . cursor [ 1 ] - 1 no_cols = 1 else : ins_point = bbox [ 0 ] [ 1 ] - 1 no_cols = self . _get_no_rowscols ( bbox ) [ 1 ] with undo . group ( _ ( "Insert columns" ) ) : self . grid . actions . insert_cols ( ins_point , no_cols ) self . grid . GetTable ( ) . ResetView ( ) self . grid . actions . zoom ( ) event . Skip ( )
Inserts the maximum of 1 and the number of selected columns
42,720
def OnInsertTabs ( self , event ) : with undo . group ( _ ( "Insert table" ) ) : self . grid . actions . insert_tabs ( self . grid . current_table - 1 , 1 ) self . grid . GetTable ( ) . ResetView ( ) self . grid . actions . zoom ( ) event . Skip ( )
Insert one table into grid
42,721
def OnDeleteRows ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 0 ] is None : del_point = self . grid . actions . cursor [ 0 ] no_rows = 1 else : del_point = bbox [ 0 ] [ 0 ] no_rows = self . _get_no_rowscols ( bbox ) [ 0 ] with undo . group ( _ ( "Delete rows" ) ) : self . grid . actions . delete_rows ( del_point , no_rows ) self . grid . GetTable ( ) . ResetView ( ) self . grid . actions . zoom ( ) event . Skip ( )
Deletes rows from all tables of the grid
42,722
def OnDeleteCols ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 1 ] is None : del_point = self . grid . actions . cursor [ 1 ] no_cols = 1 else : del_point = bbox [ 0 ] [ 1 ] no_cols = self . _get_no_rowscols ( bbox ) [ 1 ] with undo . group ( _ ( "Delete columns" ) ) : self . grid . actions . delete_cols ( del_point , no_cols ) self . grid . GetTable ( ) . ResetView ( ) self . grid . actions . zoom ( ) event . Skip ( )
Deletes columns from all tables of the grid
42,723
def OnQuote ( self , event ) : grid = self . grid grid . DisableCellEditControl ( ) with undo . group ( _ ( "Quote cell(s)" ) ) : if self . grid . IsSelection ( ) : self . grid . actions . quote_selection ( ) self . grid . ForceRefresh ( ) else : row = self . grid . GetGridCursorRow ( ) col = self . grid . GetGridCursorCol ( ) key = row , col , grid . current_table self . grid . actions . quote_code ( key ) grid . MoveCursorDown ( False )
Quotes selection or if none the current cell
42,724
def OnRowSize ( self , event ) : row = event . GetRowOrCol ( ) tab = self . grid . current_table rowsize = self . grid . GetRowSize ( row ) / self . grid . grid_renderer . zoom rows = self . grid . GetSelectedRows ( ) if len ( rows ) == 0 : rows = [ row , ] selection = self . grid . selection num_cols = self . grid . code_array . shape [ 1 ] - 1 for box in zip ( selection . block_tl , selection . block_br ) : leftmost_col = box [ 0 ] [ 1 ] rightmost_col = box [ 1 ] [ 1 ] if leftmost_col == 0 and rightmost_col == num_cols : rows += range ( box [ 0 ] [ 0 ] , box [ 1 ] [ 0 ] + 1 ) with undo . group ( _ ( "Resize Rows" ) ) : for row in rows : self . grid . code_array . set_row_height ( row , tab , rowsize ) zoomed_rowsize = rowsize * self . grid . grid_renderer . zoom self . grid . SetRowSize ( row , zoomed_rowsize ) post_command_event ( self . grid . main_window , self . grid . ContentChangedMsg ) event . Skip ( ) self . grid . ForceRefresh ( )
Row size event handler
42,725
def OnColSize ( self , event ) : col = event . GetRowOrCol ( ) tab = self . grid . current_table colsize = self . grid . GetColSize ( col ) / self . grid . grid_renderer . zoom cols = self . grid . GetSelectedCols ( ) if len ( cols ) == 0 : cols = [ col , ] selection = self . grid . selection num_rows = self . grid . code_array . shape [ 0 ] - 1 for box in zip ( selection . block_tl , selection . block_br ) : top_row = box [ 0 ] [ 0 ] bottom_row = box [ 1 ] [ 0 ] if top_row == 0 and bottom_row == num_rows : cols += range ( box [ 0 ] [ 1 ] , box [ 1 ] [ 1 ] + 1 ) with undo . group ( _ ( "Resize Columns" ) ) : for col in cols : self . grid . code_array . set_col_width ( col , tab , colsize ) zoomed_colsize = colsize * self . grid . grid_renderer . zoom self . grid . SetColSize ( col , zoomed_colsize ) post_command_event ( self . grid . main_window , self . grid . ContentChangedMsg ) event . Skip ( ) self . grid . ForceRefresh ( )
Column size event handler
42,726
def OnSortAscending ( self , event ) : try : with undo . group ( _ ( "Sort ascending" ) ) : self . grid . actions . sort_ascending ( self . grid . actions . cursor ) statustext = _ ( u"Sorting complete." ) except Exception , err : statustext = _ ( u"Sorting failed: {}" ) . format ( err ) post_command_event ( self . grid . main_window , self . grid . StatusBarMsg , text = statustext )
Sort ascending event handler
42,727
def OnUndo ( self , event ) : statustext = undo . stack ( ) . undotext ( ) undo . stack ( ) . undo ( ) try : post_command_event ( self . grid . main_window , self . grid . ContentChangedMsg ) except TypeError : pass self . grid . code_array . result_cache . clear ( ) post_command_event ( self . grid . main_window , self . grid . TableChangedMsg , updated_cell = True ) self . grid . actions . zoom ( ) self . grid . GetTable ( ) . ResetView ( ) shape = self . grid . code_array . shape post_command_event ( self . main_window , self . grid . ResizeGridMsg , shape = shape ) self . grid . update_entry_line ( ) self . grid . update_attribute_toolbar ( ) post_command_event ( self . grid . main_window , self . grid . StatusBarMsg , text = statustext )
Calls the grid undo method
42,728
def rowcol_from_template ( target_tab , template_tab = 0 ) : for row , tab in S . row_heights . keys ( ) : if tab == target_tab : S . row_heights . pop ( ( row , tab ) ) if tab == template_tab : S . row_heights [ ( row , target_tab ) ] = S . row_heights [ ( row , tab ) ] for col , tab in S . col_widths . keys ( ) : if tab == target_tab : S . col_widths . pop ( ( col , tab ) ) if tab == template_tab : S . col_widths [ ( col , target_tab ) ] = S . col_widths [ ( col , tab ) ] return "Table {tab} adjusted." . format ( tab = target_tab )
Adjusts row heights and column widths to match the template
42,729
def cell_attributes_from_template ( target_tab , template_tab = 0 ) : new_cell_attributes = [ ] for attr in S . cell_attributes : if attr [ 1 ] == template_tab : new_attr = ( attr [ 0 ] , target_tab , attr [ 2 ] ) new_cell_attributes . append ( new_attr ) S . cell_attributes . extend ( new_cell_attributes ) return "Table {tab} adjusted." . format ( tab = target_tab )
Adjusts cell paarmeters to match the template
42,730
def get_font_from_data ( fontdata ) : textfont = get_default_font ( ) if fontdata != "" : nativefontinfo = wx . NativeFontInfo ( ) nativefontinfo . FromString ( fontdata ) if not nativefontinfo . GetPointSize ( ) : nativefontinfo . SetPointSize ( get_default_font ( ) . GetPointSize ( ) ) textfont . SetNativeFontInfo ( nativefontinfo ) return textfont
Returns wx . Font from fontdata string
42,731
def get_pen_from_data ( pendata ) : pen_color = wx . Colour ( ) pen_color . SetRGB ( pendata [ 0 ] ) pen = wx . Pen ( pen_color , * pendata [ 1 : ] ) pen . SetJoin ( wx . JOIN_MITER ) return pen
Returns wx . Pen from pendata attribute list
42,732
def color_pack2rgb ( packed ) : r = packed & 255 g = ( packed & ( 255 << 8 ) ) >> 8 b = ( packed & ( 255 << 16 ) ) >> 16 return r , g , b
Returns r g b tuple from packed wx . ColourGetRGB value
42,733
def unquote_string ( code ) : scode = code . strip ( ) assert scode [ - 1 ] in [ "'" , '"' ] assert scode [ 0 ] in [ "'" , '"' ] or scode [ 1 ] in [ "'" , '"' ] return ast . literal_eval ( scode )
Returns a string from code that contains a repr of the string
42,734
def parse_dict_strings ( code ) : i = 0 level = 0 chunk_start = 0 curr_paren = None for i , char in enumerate ( code ) : if char in [ "(" , "[" , "{" ] and curr_paren is None : level += 1 elif char in [ ")" , "]" , "}" ] and curr_paren is None : level -= 1 elif char in [ '"' , "'" ] : if curr_paren == char : curr_paren = None elif curr_paren is None : curr_paren = char if level == 0 and char in [ ':' , ',' ] and curr_paren is None : yield code [ chunk_start : i ] . strip ( ) chunk_start = i + 1 yield code [ chunk_start : i + 1 ] . strip ( )
Generator of elements of a dict that is given in the code string
42,735
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 start_string [ : - 1 ] return start_string
Returns start sub - string that is common for all given strings
42,736
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
42,737
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
42,738
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
42,739
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 . first_tab_text_ctrl . GetValue ( ) info [ "last_tab" ] = self . last_tab_text_ctrl . GetValue ( ) if self . filetype != "print" : info [ "paper_width" ] = float ( self . page_width_text_ctrl . GetValue ( ) ) * 72.0 info [ "paper_height" ] = float ( self . page_height_text_ctrl . GetValue ( ) ) * 72.0 if self . portrait_landscape_radio_box . GetSelection ( ) == 0 : orientation = "portrait" elif self . portrait_landscape_radio_box . GetSelection ( ) == 1 : orientation = "landscape" else : raise ValueError ( "Orientation not in portrait or landscape" ) info [ "orientation" ] = orientation return info
Returns a dict with the dialog PDF info
42,740
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
42,741
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
42,742
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
42,743
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" : "wxPython" , "min_version" : "2.8.10.1" , "description" : "required" , } try : import wx dep_attrs [ "version" ] = wx . version ( ) except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "matplotlib" , "min_version" : "1.1.1" , "description" : "required" , } try : import matplotlib dep_attrs [ "version" ] = matplotlib . _version . get_versions ( ) [ "version" ] except ImportError : dep_attrs [ "version" ] = None except AttributeError : dep_attrs [ "version" ] = matplotlib . __version__ dependencies . append ( dep_attrs ) dep_attrs = { "name" : "pycairo" , "min_version" : "1.8.8" , "description" : "required" , } try : import cairo dep_attrs [ "version" ] = cairo . version except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "python-gnupg" , "min_version" : "0.3.0" , "description" : "for opening own files without approval" , } try : import gnupg dep_attrs [ "version" ] = gnupg . __version__ except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "xlrd" , "min_version" : "0.9.2" , "description" : "for loading Excel files" , } try : import xlrd dep_attrs [ "version" ] = xlrd . __VERSION__ except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "xlwt" , "min_version" : "0.7.2" , "description" : "for saving Excel files" , } try : import xlwt dep_attrs [ "version" ] = xlwt . __VERSION__ except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "jedi" , "min_version" : "0.8.0" , "description" : "for tab completion and context help in the entry line" , } try : import jedi dep_attrs [ "version" ] = jedi . __version__ except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "pyrsvg" , "min_version" : "2.32" , "description" : "for displaying SVG files in cells" , } try : import rsvg dep_attrs [ "version" ] = True except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) dep_attrs = { "name" : "pyenchant" , "min_version" : "1.6.6" , "description" : "for spell checking" , } try : import enchant dep_attrs [ "version" ] = enchant . __version__ except ImportError : dep_attrs [ "version" ] = None dependencies . append ( dep_attrs ) return dependencies
Returns list of dicts which indicate installed dependencies
42,744
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 ) pos_y += __row_height for __col in xrange ( left_col , col ) : __col_width = self . code_array . get_col_width ( __col , tab ) pos_x += __col_width if merge_area is None : height = self . code_array . get_row_height ( row , tab ) width = self . code_array . get_col_width ( col , tab ) else : top , left , bottom , right = merge_area if top == row and left == col : heights = ( self . code_array . get_row_height ( __row , tab ) for __row in xrange ( top , bottom + 1 ) ) widths = ( self . code_array . get_col_width ( __col , tab ) for __col in xrange ( left , right + 1 ) ) height = sum ( heights ) width = sum ( widths ) else : return return pos_x , pos_y , width , height
Returns rectangle of cell on canvas
42,745
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 . _get_merge_area ( first_key ) first_rect = self . get_cell_rect ( top , left , tab ) last_key = row_stop - 1 , col_stop - 1 , tab last_rect = self . get_cell_rect ( * last_key ) if last_rect is None : top , left , __ , __ = self . _get_merge_area ( last_key ) last_rect = self . get_cell_rect ( top , left , tab ) x_extent = last_rect [ 0 ] + last_rect [ 2 ] - first_rect [ 0 ] y_extent = last_rect [ 1 ] + last_rect [ 3 ] - first_rect [ 1 ] scale_x = ( self . width - 2 * self . x_offset ) / float ( x_extent ) scale_y = ( self . height - 2 * self . y_offset ) / float ( y_extent ) self . context . save ( ) self . context . translate ( first_rect [ 0 ] , first_rect [ 1 ] ) scale = min ( scale_x , scale_y ) self . context . scale ( scale , scale ) self . context . translate ( - self . x_offset , - self . y_offset ) for row in xrange ( row_start , row_stop ) : for col in xrange ( col_start , col_stop ) : key = row , col , tab rect = self . get_cell_rect ( row , col , tab ) if rect is not None : cell_renderer = GridCellCairoRenderer ( self . context , self . code_array , key , rect , self . view_frozen ) cell_renderer . draw ( ) self . context . restore ( ) self . context . show_page ( )
Draws slice to context
42,746
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_renderer = GridCellBorderCairoRenderer ( self . context , self . code_array , self . key , self . rect ) cell_background_renderer . draw ( ) cell_content_renderer . draw ( ) cell_border_renderer . draw ( )
Draws cell to context
42,747
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
42,748
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 ] / float ( ims_width ) scale_y = self . rect [ 3 ] / float ( ims_height ) return scale_x , scale_y
Returns scale_x scale_y for bitmap display
42,749
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 , ims_height ) scale = min ( scale_x , scale_y ) if angle not in ( 90 , 180 , - 90 ) : x = - 2 y = - 2 if scale_x > scale_y : if justification == "center" : x += ( self . rect [ 2 ] - ims_width * scale ) / 2 elif justification == "right" : x += self . rect [ 2 ] - ims_width * scale else : if vertical_align == "middle" : y += ( self . rect [ 3 ] - ims_height * scale ) / 2 elif vertical_align == "bottom" : y += self . rect [ 3 ] - ims_height * scale if angle == 90 : x = - ims_width * scale + 2 y = - 2 if scale_y > scale_x : if justification == "center" : y += ( self . rect [ 2 ] - ims_height * scale ) / 2 elif justification == "right" : y += self . rect [ 2 ] - ims_height * scale else : if vertical_align == "middle" : x -= ( self . rect [ 3 ] - ims_width * scale ) / 2 elif vertical_align == "bottom" : x -= self . rect [ 3 ] - ims_width * scale elif angle == 180 : x = - ims_width * scale + 2 y = - ims_height * scale + 2 if scale_x > scale_y : if justification == "center" : x -= ( self . rect [ 2 ] - ims_width * scale ) / 2 elif justification == "right" : x -= self . rect [ 2 ] - ims_width * scale else : if vertical_align == "middle" : y -= ( self . rect [ 3 ] - ims_height * scale ) / 2 elif vertical_align == "bottom" : y -= self . rect [ 3 ] - ims_height * scale elif angle == - 90 : x = - 2 y = - ims_height * scale + 2 if scale_y > scale_x : if justification == "center" : y -= ( self . rect [ 2 ] - ims_height * scale ) / 2 elif justification == "right" : y -= self . rect [ 2 ] - ims_height * scale else : if vertical_align == "middle" : x += ( self . rect [ 3 ] - ims_width * scale ) / 2 elif vertical_align == "bottom" : x += self . rect [ 3 ] - ims_width * scale return x , y
Returns x and y for a bitmap translation
42,750
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_height ( ) transx , transy = self . _get_translation ( ims_width , ims_height ) scale_x , scale_y = self . _get_scalexy ( ims_width , ims_height ) scale = min ( scale_x , scale_y ) angle = float ( self . code_array . cell_attributes [ self . key ] [ "angle" ] ) self . context . save ( ) self . context . rotate ( - angle / 360 * 2 * math . pi ) self . context . translate ( transx , transy ) self . context . scale ( scale , scale ) self . context . set_source_surface ( ims , 0 , 0 ) self . context . paint ( ) self . context . restore ( )
Draws bitmap cell content to context
42,751
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 ( svg_width , svg_height ) scale = min ( scale_x , scale_y ) angle = float ( self . code_array . cell_attributes [ self . key ] [ "angle" ] ) self . context . save ( ) self . context . rotate ( - angle / 360 * 2 * math . pi ) self . context . translate ( transx , transy ) self . context . scale ( scale , scale ) svg . render_cairo ( self . context ) self . context . restore ( )
Draws svg string to cell
42,752
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 ( 0 , self . height ) ctx . new_path ( ) self . convert_path ( ctx , path , transform ) try : self . _fill_and_stroke ( ctx , rgbFace , gc . get_alpha ( ) , gc . get_forced_alpha ( ) ) except AttributeError : self . _fill_and_stroke ( ctx , rgbFace , gc . get_alpha ( ) ) def draw_image ( self , gc , x , y , im ) : rows , cols , buf = im . color_conv ( self . BYTE_FORMAT ) surface = cairo . ImageSurface . create_for_data ( buf , cairo . FORMAT_ARGB32 , cols , rows , cols * 4 ) ctx = gc . ctx y = self . height - y - rows ctx . save ( ) ctx . set_source_surface ( surface , x , y ) if gc . get_alpha ( ) != 1.0 : ctx . paint_with_alpha ( gc . get_alpha ( ) ) else : ctx . paint ( ) ctx . restore ( ) if pyplot is None : return FigureCanvasCairo ( figure ) dpi = float ( figure . dpi ) border_x = 200 / ( self . rect [ 2 ] / dpi ) ** 2 border_y = 200 / ( self . rect [ 3 ] / dpi ) ** 2 width = ( self . rect [ 2 ] - 2 * border_x ) / dpi height = ( self . rect [ 3 ] - 2 * border_y ) / dpi figure . set_figwidth ( width ) figure . set_figheight ( height ) renderer = CustomRendererCairo ( dpi ) renderer . set_width_height ( width , height ) renderer . gc . ctx = self . context renderer . text_ctx = self . context self . context . save ( ) self . context . translate ( border_x , border_y + height * dpi ) figure . draw ( renderer ) self . context . restore ( )
Draws matplotlib figure to context
42,753
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
42,754
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 . STYLE_ITALIC , } cell_attributes = self . code_array . cell_attributes [ self . key ] textfont = cell_attributes [ "textfont" ] pointsize = cell_attributes [ "pointsize" ] fontweight = cell_attributes [ "fontweight" ] fontstyle = cell_attributes [ "fontstyle" ] underline = cell_attributes [ "underline" ] strikethrough = cell_attributes [ "strikethrough" ] font_description = pango . FontDescription ( " " . join ( [ textfont , str ( pointsize ) ] ) ) pango_layout . set_font_description ( font_description ) attrs = pango . AttrList ( ) attrs . insert ( pango . AttrUnderline ( underline , 0 , MAX_RESULT_LENGTH ) ) weight = wx2pango_weights [ fontweight ] if weight is not None : attrs . insert ( pango . AttrWeight ( weight , 0 , MAX_RESULT_LENGTH ) ) style = wx2pango_styles [ fontstyle ] if style is not None : attrs . insert ( pango . AttrStyle ( style , 0 , MAX_RESULT_LENGTH ) ) attrs . insert ( pango . AttrStrikethrough ( strikethrough , 0 , MAX_RESULT_LENGTH ) ) pango_layout . set_attributes ( attrs )
Sets the font for draw_text
42,755
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_char_extents ( ) underline_pixel_extents = [ char_extents [ 0 ] / pango . SCALE , ( char_extents [ 1 ] + char_extents [ 3 ] ) / pango . SCALE - 2 , char_extents [ 2 ] / pango . SCALE , 4 , ] if extents_list : if extents_list [ - 1 ] [ 1 ] == underline_pixel_extents [ 1 ] : extents_list [ - 1 ] [ 2 ] = extents_list [ - 1 ] [ 2 ] + underline_pixel_extents [ 2 ] else : extents_list . append ( underline_pixel_extents ) else : extents_list . append ( underline_pixel_extents ) pit . next_char ( ) for extent in extents_list : pangocairo . show_error_underline ( ptx , * extent ) self . context . restore ( )
Draws an error underline
42,756
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
42,757
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 . rect [ 0 ] , self . rect [ 3 ] , self . rect [ 2 ] else : rect = self . rect self . context . set_source_rgb ( * self . _get_text_color ( ) ) ptx = pangocairo . CairoContext ( self . context ) pango_layout = ptx . create_layout ( ) self . set_font ( pango_layout ) pango_layout . set_wrap ( pango . WRAP_WORD_CHAR ) pango_layout . set_width ( int ( round ( ( rect [ 2 ] - 4.0 ) * pango . SCALE ) ) ) try : markup = cell_attributes [ "markup" ] except KeyError : markup = False if markup : with warnings . catch_warnings ( record = True ) as warning_lines : warnings . resetwarnings ( ) warnings . simplefilter ( "always" ) pango_layout . set_markup ( unicode ( content ) ) if warning_lines : w2unicode = lambda m : unicode ( m . message ) msg = u"\n" . join ( map ( w2unicode , warning_lines ) ) pango_layout . set_text ( msg ) else : pango_layout . set_text ( unicode ( content ) ) alignment = cell_attributes [ "justification" ] pango_layout . set_alignment ( wx2pango_alignment [ alignment ] ) extents = pango_layout . get_pixel_extents ( ) downshift = 0 if cell_attributes [ "vertical_align" ] == "bottom" : downshift = rect [ 3 ] - extents [ 1 ] [ 3 ] - 4 elif cell_attributes [ "vertical_align" ] == "middle" : downshift = int ( ( rect [ 3 ] - extents [ 1 ] [ 3 ] ) / 2 ) - 2 self . context . save ( ) self . _rotate_cell ( angle , rect ) self . context . translate ( 0 , downshift ) if SpellChecker is not None and self . spell_check : text = unicode ( pango_layout . get_text ( ) ) lang = config [ "spell_lang" ] for start , stop in self . _check_spelling ( text , lang = lang ) : self . _draw_error_underline ( ptx , pango_layout , start , stop - 1 ) ptx . update_layout ( pango_layout ) ptx . show_layout ( pango_layout ) self . context . restore ( )
Draws text cell content to context
42,758
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 + w - r , y + h ) context . line_to ( x + r , y + h ) context . curve_to ( x , y + h , x , y + h , x , y + h - r ) context . line_to ( x , y + r ) context . curve_to ( x , y , x , y , x + r , y ) context . restore
Draws a rounded rectangle
42,759
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 . save ( ) context . scale ( w , h ) context . rectangle ( 0 , 0 , 1 , 1 ) context . set_source_rgb ( 0 , 0 , 1 ) context . set_source ( gradient ) context . fill ( ) context . restore ( ) x_bearing , y_bearing , width , height , x_advance , y_advance = context . text_extents ( label ) text_x = ( w / 2.0 ) - ( width / 2.0 + x_bearing ) text_y = ( h / 2.0 ) - ( height / 2.0 + y_bearing ) + 1 context . move_to ( text_x , text_y ) context . set_source_rgba ( 0 , 0 , 0 , 1 ) context . show_text ( label ) context . move_to ( x , y ) context . set_source_rgba ( 0 , 0 , 0 , 1 ) self . draw_roundedrect ( x , y , w , h ) context . stroke ( )
Draws a button
42,760
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 ] < cell_attributes [ self . key ] [ "borderwidth_right" ] or self . rect [ 3 ] < cell_attributes [ self . key ] [ "borderwidth_bottom" ] : self . context . restore ( ) return if self . code_array . cell_attributes [ self . key ] [ "button_cell" ] : label = self . code_array . cell_attributes [ self . key ] [ "button_cell" ] self . draw_button ( 1 , 1 , self . rect [ 2 ] - 5 , self . rect [ 3 ] - 5 , label ) elif isinstance ( content , wx . _gdi . Bitmap ) : self . draw_bitmap ( content ) elif pyplot is not None and isinstance ( content , pyplot . Figure ) : self . draw_matplotlib_figure ( content ) elif isinstance ( content , basestring ) and is_svg ( content ) : self . draw_svg ( content ) elif content is not None : self . draw_text ( content ) self . context . translate ( - pos_x - 2 , - pos_y - 2 ) self . context . restore ( )
Draws cell content to context
42,761
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
42,762
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_to ( __x , y + h ) self . context . line_to ( __x + h , y ) self . context . stroke ( ) self . context . restore ( )
Draws frozen pattern i . e . diagonal lines
42,763
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
42,764
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
42,765
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
42,766
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
42,767
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
42,768
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
42,769
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_left = ( self . x - border_width_right , self . y - border_width_bottom , border_width_right , border_width_bottom ) return key_above_left , rect_above_left
Returns tuple key rect of above left cell
42,770
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_right ] [ "borderwidth_bottom" ] ) / 2.0 rect_above_right = ( self . x + self . width , self . y - border_width_bottom , border_width_right , border_width_bottom ) return key_above_right , rect_above_right
Returns tuple key rect of above right cell
42,771
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 ] [ "borderwidth_bottom" ] ) / 2.0 rect_below_left = ( self . x - border_width_right , self . y - self . height , border_width_right , border_width_bottom ) return key_below_left , rect_below_left
Returns tuple key rect of below left cell
42,772
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 = ( self . x + self . width , self . y - self . height , border_width_right , border_width_bottom ) return key_below_right , rect_below_right
Returns tuple key rect of below right cell
42,773
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
42,774
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
42,775
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
42,776
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
42,777
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
42,778
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
42,779
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
42,780
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
42,781
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
42,782
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
42,783
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
42,784
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
42,785
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
42,786
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
42,787
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
42,788
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
42,789
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 ( key = attrgetter ( 'width' , 'color' ) ) for border in borders : border . draw ( self . context ) self . context . restore ( )
Draws cell border to context
42,790
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 ) caret_length = int ( min ( [ rect . width , rect . height ] ) / 5.0 ) color = get_color ( config [ "text_color" ] ) if pen is None : pen = wx . Pen ( color ) if brush is None : brush = wx . Brush ( color ) pen . SetWidth ( size ) border_left = rect . x + size - 1 border_right = rect . x + rect . width - size - 1 border_upper = rect . y + size - 1 border_lower = rect . y + rect . height - size - 1 points_lr = [ ( border_right , border_lower - caret_length ) , ( border_right , border_lower ) , ( border_right - caret_length , border_lower ) , ( border_right , border_lower ) , ] points_ur = [ ( border_right , border_upper + caret_length ) , ( border_right , border_upper ) , ( border_right - caret_length , border_upper ) , ( border_right , border_upper ) , ] points_ul = [ ( border_left , border_upper + caret_length ) , ( border_left , border_upper ) , ( border_left + caret_length , border_upper ) , ( border_left , border_upper ) , ] points_ll = [ ( border_left , border_lower - caret_length ) , ( border_left , border_lower ) , ( border_left + caret_length , border_lower ) , ( border_left , border_lower ) , ] point_list = [ points_lr , points_ur , points_ul , points_ll ] dc . DrawPolygonList ( point_list , pens = pen , brushes = brush ) self . old_cursor_row_col = row , col
Draws cursor as Rectangle in lower right corner
42,791
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
42,792
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 = grid . CellToRect ( row , col ) br_rect = grid . CellToRect ( bottom , right ) width = br_rect . x - ul_rect . x + br_rect . width height = br_rect . y - ul_rect . y + br_rect . height rect = wx . Rect ( ul_rect . x , ul_rect . y , width , height ) return rect
Returns cell rect for normal or merged cells and None for merged
42,793
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 : return return rect
Replaces drawn rect if the one provided by wx is incorrect
42,794
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_preview = repr ( grid . code_array ( key ) ) [ : 100 ] __id = id ( grid . code_array ( key ) ) else : cell_preview = repr ( grid . code_array [ key ] ) [ : 100 ] __id = id ( grid . code_array [ key ] ) sorted_keys = sorted ( grid . code_array . cell_attributes [ key ] . iteritems ( ) ) key_above_left = row - 1 , col - 1 , tab key_above = row - 1 , col , tab key_above_right = row - 1 , col + 1 , tab key_left = row , col - 1 , tab key_right = row , col + 1 , tab key_below_left = row + 1 , col - 1 , tab key_below = row + 1 , col , tab borders = [ ] for k in [ key , key_above_left , key_above , key_above_right , key_left , key_right , key_below_left , key_below ] : borders . append ( cell_attributes [ k ] [ "borderwidth_bottom" ] ) borders . append ( cell_attributes [ k ] [ "borderwidth_right" ] ) borders . append ( cell_attributes [ k ] [ "bordercolor_bottom" ] ) borders . append ( cell_attributes [ k ] [ "bordercolor_right" ] ) return ( zoomed_width , zoomed_height , is_selected , cell_preview , __id , tuple ( sorted_keys ) , tuple ( borders ) )
Returns key for the screen draw cache
42,795
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 . ContextFromDC ( mdc ) context . save ( ) zoom = self . zoom context . scale ( zoom , zoom ) rect_tuple = - 0.5 , - 0.5 , rect . width / zoom + 0.5 , rect . height / zoom + 0.5 spell_check = config [ "check_spelling" ] cell_renderer = GridCellCairoRenderer ( context , self . data_array , key , rect_tuple , view_frozen , spell_check = spell_check ) cell_renderer . draw ( ) if is_selected : context . set_source_rgba ( * self . selection_color_tuple ) context . rectangle ( * rect_tuple ) context . fill ( ) context . restore ( ) return bmp
Returns a wx . Bitmap of cell key in size rect
42,796
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_key = self . _get_draw_cache_key ( grid , key , drawn_rect , isSelected ) mdc = wx . MemoryDC ( ) if vlc is not None and key in self . video_cells and grid . code_array . cell_attributes [ key ] [ "panel_cell" ] : self . video_cells [ key ] . SetClientRect ( drawn_rect ) elif cell_cache_key in self . cell_cache : mdc . SelectObject ( self . cell_cache [ cell_cache_key ] ) else : code = grid . code_array ( key ) if vlc is not None and code is not None and grid . code_array . cell_attributes [ key ] [ "panel_cell" ] : try : panel_cls = grid . code_array [ key ] assert issubclass ( panel_cls , wx . Panel ) video_panel = panel_cls ( grid ) video_panel . SetClientRect ( drawn_rect ) self . video_cells [ key ] = video_panel return except Exception , err : post_command_event ( grid . main_window , self . StatusBarMsg , text = unicode ( err ) ) bmp = self . _get_cairo_bmp ( mdc , key , drawn_rect , isSelected , grid . _view_frozen ) else : bmp = self . _get_cairo_bmp ( mdc , key , drawn_rect , isSelected , grid . _view_frozen ) self . cell_cache [ cell_cache_key ] = bmp dc . Blit ( drawn_rect . x , drawn_rect . y , drawn_rect . width , drawn_rect . height , mdc , 0 , 0 , wx . COPY ) if grid . actions . cursor [ : 2 ] == ( row , col ) : self . update_cursor ( dc , grid , row , col )
Draws the cell border and content using pycairo
42,797
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 = '"' + uid_string + ' (' + fingerprint + ')' uid_strings_fp . append ( uid_string_fp ) uid_string_fp2key [ uid_string_fp ] = key msg = _ ( 'Choose a GPG key for signing pyspread save files.\n' 'The GPG key must not have a passphrase set.' ) dlg = wx . SingleChoiceDialog ( None , msg , _ ( 'Choose key' ) , uid_strings_fp , wx . CHOICEDLG_STYLE ) childlist = list ( dlg . GetChildren ( ) ) childlist [ - 3 ] . SetLabel ( _ ( "Use chosen key" ) ) childlist [ - 2 ] . SetLabel ( _ ( "Create new key" ) ) if current_key_index is not None : dlg . SetSelection ( current_key_index ) if dlg . ShowModal ( ) == wx . ID_OK : uid_string_fp = dlg . GetStringSelection ( ) key = uid_string_fp2key [ uid_string_fp ] else : key = None dlg . Destroy ( ) return key
Displays gpg key choice and returns key
42,798
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
42,799
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