idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
230,600 | def get_pasteas_parameters_from_user ( self , obj ) : dlg = PasteAsDialog ( None , - 1 , obj ) dlg_choice = dlg . ShowModal ( ) if dlg_choice != wx . ID_OK : dlg . Destroy ( ) return None parameters = { } parameters . update ( dlg . parameters ) dlg . Destroy ( ) return parameters | Opens a PasteAsDialog and returns parameters dict | 94 | 10 |
230,601 | def _execute_cell_code ( self , row , col , grid ) : key = row , col , grid . current_table grid . code_array [ key ] grid . ForceRefresh ( ) | Executes cell code | 43 | 4 |
230,602 | def StartingKey ( self , evt ) : key = evt . GetKeyCode ( ) ch = None if key in [ wx . WXK_NUMPAD0 , wx . WXK_NUMPAD1 , wx . WXK_NUMPAD2 , wx . WXK_NUMPAD3 , wx . WXK_NUMPAD4 , wx . WXK_NUMPAD5 , wx . WXK_NUMPAD6 , wx . WXK_NUMPAD7 , wx . WXK_NUMPAD8 , wx . WXK_NUMPAD9 ] : ch = ch = chr ( ord ( '0' ) + key - wx . WXK_NUMPAD0 ) elif key < 256 and key >= 0 and chr ( key ) in string . printable : ch = chr ( key ) if ch is not None and self . _tc . IsEnabled ( ) : # For this example, replace the text. Normally we would append it. #self._tc.AppendText(ch) self . _tc . SetValue ( ch ) self . _tc . SetInsertionPointEnd ( ) else : evt . Skip ( ) | If the editor is enabled by pressing keys on the grid this will be called to let the editor do something about that first key if desired . | 276 | 28 |
230,603 | def GetPageInfo ( self ) : return self . first_tab , self . last_tab , self . first_tab , self . last_tab | Returns page information | 32 | 3 |
230,604 | def quote ( code ) : try : code = code . rstrip ( ) except AttributeError : # code is not a string, may be None --> There is no code to quote return code if code and code [ 0 ] + code [ - 1 ] not in ( '""' , "''" , "u'" , '"' ) and '"' not in code : return 'u"' + code + '"' else : return code | Returns quoted code if not already quoted and if possible | 91 | 10 |
230,605 | def _states ( self ) : # The currently visible table self . current_table = 0 # The cell that has been selected before the latest selection self . _last_selected_cell = 0 , 0 , 0 # If we are viewing cells based on their frozen status or normally # (When true, a cross-hatch is displayed for frozen cells) self . _view_frozen = False # Timer for updating frozen cells self . timer_running = False | Sets grid states | 96 | 4 |
230,606 | def _layout ( self ) : self . EnableGridLines ( False ) # Standard row and col sizes for zooming default_cell_attributes = self . code_array . cell_attributes . default_cell_attributes self . std_row_size = default_cell_attributes [ "row-height" ] self . std_col_size = default_cell_attributes [ "column-width" ] self . SetDefaultRowSize ( self . std_row_size ) self . SetDefaultColSize ( self . std_col_size ) # Standard row and col label sizes for zooming self . col_label_size = self . GetColLabelSize ( ) self . row_label_size = self . GetRowLabelSize ( ) self . SetRowMinimalAcceptableHeight ( 1 ) self . SetColMinimalAcceptableWidth ( 1 ) self . SetCellHighlightPenWidth ( 0 ) | Initial layout of grid | 198 | 4 |
230,607 | def is_merged_cell_drawn ( self , key ) : row , col , tab = key # Is key not merged? --> False cell_attributes = self . code_array . cell_attributes top , left , __ = cell_attributes . get_merging_cell ( key ) # Case 1: Top left cell of merge is visible # --> Only top left cell returns True top_left_drawn = row == top and col == left and self . IsVisible ( row , col , wholeCellVisible = False ) # Case 2: Leftmost column is visible # --> Only top visible leftmost cell returns True left_drawn = col == left and self . IsVisible ( row , col , wholeCellVisible = False ) and not self . IsVisible ( row - 1 , col , wholeCellVisible = False ) # Case 3: Top row is visible # --> Only left visible top cell returns True top_drawn = row == top and self . IsVisible ( row , col , wholeCellVisible = False ) and not self . IsVisible ( row , col - 1 , wholeCellVisible = False ) # Case 4: Top row and leftmost column are invisible # --> Only top left visible cell returns True middle_drawn = self . IsVisible ( row , col , wholeCellVisible = False ) and not self . IsVisible ( row - 1 , col , wholeCellVisible = False ) and not self . IsVisible ( row , col - 1 , wholeCellVisible = False ) return top_left_drawn or left_drawn or top_drawn or middle_drawn | True if key in merged area shall be drawn | 345 | 9 |
230,608 | def update_entry_line ( self , key = None ) : if key is None : key = self . actions . cursor cell_code = self . GetTable ( ) . GetValue ( * key ) post_command_event ( self , self . EntryLineMsg , text = cell_code ) | Updates the entry line | 63 | 5 |
230,609 | def update_attribute_toolbar ( self , key = None ) : if key is None : key = self . actions . cursor post_command_event ( self , self . ToolbarUpdateMsg , key = key , attr = self . code_array . cell_attributes [ key ] ) | Updates the attribute toolbar | 63 | 5 |
230,610 | def _update_video_volume_cell_attributes ( self , key ) : try : video_cell_panel = self . grid_renderer . video_cells [ key ] except KeyError : return old_video_volume = self . code_array . cell_attributes [ key ] [ "video_volume" ] new_video_volume = video_cell_panel . volume if old_video_volume == new_video_volume : return selection = Selection ( [ ] , [ ] , [ ] , [ ] , [ key ] ) self . actions . set_attr ( "video_volume" , new_video_volume , selection ) | Updates the panel cell attrutes of a panel cell | 139 | 12 |
230,611 | def OnCellText ( self , event ) : row , col , _ = self . grid . actions . cursor self . grid . GetTable ( ) . SetValue ( row , col , event . code ) event . Skip ( ) | Text entry event handler | 48 | 4 |
230,612 | def OnInsertBitmap ( self , event ) : key = self . grid . actions . cursor # Get file name wildcard = _ ( "Bitmap file" ) + " (*)|*" if rsvg is not None : wildcard += "|" + _ ( "SVG file" ) + " (*.svg)|*.svg" message = _ ( "Select image for current cell" ) style = wx . OPEN | wx . CHANGE_DIR filepath , index = self . grid . interfaces . get_filepath_findex_from_user ( wildcard , message , style ) if index == 0 : # Bitmap loaded try : img = wx . EmptyImage ( 1 , 1 ) img . LoadFile ( filepath ) except TypeError : return if img . GetSize ( ) == ( - 1 , - 1 ) : # Bitmap could not be read return code = self . grid . main_window . actions . img2code ( key , img ) elif index == 1 and rsvg is not None : # SVG loaded with open ( filepath ) as infile : try : code = infile . read ( ) except IOError : return if is_svg ( code ) : code = 'u"""' + code + '"""' else : # Does not seem to be an svg file return else : code = None if code : self . grid . actions . set_code ( key , code ) | Insert bitmap event handler | 308 | 5 |
230,613 | def OnLinkBitmap ( self , event ) : # Get file name wildcard = "*" message = _ ( "Select bitmap for current cell" ) style = wx . OPEN | wx . CHANGE_DIR filepath , __ = self . grid . interfaces . get_filepath_findex_from_user ( wildcard , message , style ) try : bmp = wx . Bitmap ( filepath ) except TypeError : return if bmp . Size == ( - 1 , - 1 ) : # Bitmap could not be read return code = "wx.Bitmap(r'{filepath}')" . format ( filepath = filepath ) key = self . grid . actions . cursor self . grid . actions . set_code ( key , code ) | Link bitmap event handler | 167 | 5 |
230,614 | def OnLinkVLCVideo ( self , event ) : key = self . grid . actions . cursor if event . videofile : try : video_volume = self . grid . code_array . cell_attributes [ key ] [ "video_volume" ] except KeyError : video_volume = None self . grid . actions . set_attr ( "panel_cell" , True ) if video_volume is not None : code = 'vlcpanel_factory("{}", {})' . format ( event . videofile , video_volume ) else : code = 'vlcpanel_factory("{}")' . format ( event . videofile ) self . grid . actions . set_code ( key , code ) else : try : video_panel = self . grid . grid_renderer . video_cells . pop ( key ) video_panel . player . stop ( ) video_panel . player . release ( ) video_panel . Destroy ( ) except KeyError : pass self . grid . actions . set_code ( key , u"" ) | VLC video code event handler | 225 | 6 |
230,615 | def OnInsertChartDialog ( self , event ) : key = self . grid . actions . cursor cell_code = self . grid . code_array ( key ) if cell_code is None : cell_code = u"" chart_dialog = ChartDialog ( self . grid . main_window , key , cell_code ) if chart_dialog . ShowModal ( ) == wx . ID_OK : code = chart_dialog . get_code ( ) key = self . grid . actions . cursor self . grid . actions . set_code ( key , code ) | Chart dialog event handler | 123 | 4 |
230,616 | def OnPasteFormat ( self , event ) : with undo . group ( _ ( "Paste format" ) ) : self . grid . actions . paste_format ( ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) self . grid . actions . zoom ( ) | Paste format event handler | 67 | 5 |
230,617 | def OnCellFont ( self , event ) : with undo . group ( _ ( "Font" ) ) : self . grid . actions . set_attr ( "textfont" , event . font ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell font event handler | 68 | 4 |
230,618 | def OnCellFontSize ( self , event ) : with undo . group ( _ ( "Font size" ) ) : self . grid . actions . set_attr ( "pointsize" , event . size ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell font size event handler | 69 | 5 |
230,619 | def OnCellFontBold ( self , event ) : with undo . group ( _ ( "Bold" ) ) : try : try : weight = getattr ( wx , event . weight [ 2 : ] ) except AttributeError : msg = _ ( "Weight {weight} unknown" ) . format ( weight = event . weight ) raise ValueError ( msg ) self . grid . actions . set_attr ( "fontweight" , weight ) except AttributeError : self . grid . actions . toggle_attr ( "fontweight" ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell font bold event handler | 141 | 5 |
230,620 | def OnCellFontUnderline ( self , event ) : with undo . group ( _ ( "Underline" ) ) : self . grid . actions . toggle_attr ( "underline" ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell font underline event handler | 67 | 6 |
230,621 | def OnCellFrozen ( self , event ) : with undo . group ( _ ( "Frozen" ) ) : self . grid . actions . change_frozen_attr ( ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell frozen event handler | 65 | 4 |
230,622 | def OnButtonCell ( self , event ) : # The button text text = event . text with undo . group ( _ ( "Button" ) ) : self . grid . actions . set_attr ( "button_cell" , text ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Button cell event handler | 76 | 4 |
230,623 | def OnMerge ( self , event ) : with undo . group ( _ ( "Merge cells" ) ) : self . grid . actions . merge_selected_cells ( self . grid . selection ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) | Merge cells event handler | 64 | 5 |
230,624 | def OnCellBorderWidth ( self , event ) : with undo . group ( _ ( "Border width" ) ) : self . grid . actions . set_border_attr ( "borderwidth" , event . width , event . borders ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell border width event handler | 76 | 5 |
230,625 | def OnCellBorderColor ( self , event ) : with undo . group ( _ ( "Border color" ) ) : self . grid . actions . set_border_attr ( "bordercolor" , event . color , event . borders ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell border color event handler | 78 | 5 |
230,626 | def OnCellBackgroundColor ( self , event ) : with undo . group ( _ ( "Background color" ) ) : self . grid . actions . set_attr ( "bgcolor" , event . color ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) event . Skip ( ) | Cell background color event handler | 70 | 5 |
230,627 | def OnCellTextRotation ( self , event ) : with undo . group ( _ ( "Rotation" ) ) : self . grid . actions . toggle_attr ( "angle" ) self . grid . ForceRefresh ( ) self . grid . update_attribute_toolbar ( ) if is_gtk ( ) : try : wx . Yield ( ) except : pass event . Skip ( ) | Cell text rotation event handler | 86 | 5 |
230,628 | def OnCellSelected ( self , event ) : key = row , col , tab = event . Row , event . Col , self . grid . current_table # Is the cell merged then go to merging cell cell_attributes = self . grid . code_array . cell_attributes merging_cell = cell_attributes . get_merging_cell ( key ) if merging_cell is not None and merging_cell != key : post_command_event ( self . grid , self . grid . GotoCellMsg , key = merging_cell ) # Check if the merging cell is a button cell if cell_attributes [ merging_cell ] [ "button_cell" ] : # Button cells shall be executed on click self . grid . EnableCellEditControl ( ) return # If in selection mode do nothing # This prevents the current cell from changing if not self . grid . IsEditable ( ) : return # Redraw cursor self . grid . ForceRefresh ( ) # Disable entry line if cell is locked self . grid . lock_entry_line ( self . grid . code_array . cell_attributes [ key ] [ "locked" ] ) # Update entry line self . grid . update_entry_line ( key ) # Update attribute toolbar self . grid . update_attribute_toolbar ( key ) self . grid . _last_selected_cell = key event . Skip ( ) | Cell selection event handler | 295 | 4 |
230,629 | def OnMouseMotion ( self , event ) : grid = self . grid pos_x , pos_y = grid . CalcUnscrolledPosition ( event . GetPosition ( ) ) row = grid . YToRow ( pos_y ) col = grid . XToCol ( pos_x ) tab = grid . current_table key = row , col , tab merge_area = self . grid . code_array . cell_attributes [ key ] [ "merge_area" ] if merge_area is not None : top , left , bottom , right = merge_area row , col = top , left grid . actions . on_mouse_over ( ( row , col , tab ) ) event . Skip ( ) | Mouse motion event handler | 153 | 4 |
230,630 | 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 key tuple: (modifier, keycode) # Modifier may be e. g. shift | ctrl shortcuts = { # <Esc> pressed ( 0 , 27 ) : lambda : setattr ( actions , "need_abort" , True ) , # <Del> pressed ( 0 , 127 ) : actions . delete , # <Home> pressed ( 0 , 313 ) : lambda : actions . set_cursor ( ( grid . GetGridCursorRow ( ) , 0 ) ) , # <Ctrl> + R pressed ( ctrl , 82 ) : actions . copy_selection_access_string , # <Ctrl> + + pressed ( ctrl , 388 ) : actions . zoom_in , # <Ctrl> + - pressed ( ctrl , 390 ) : actions . zoom_out , # <Shift> + <Space> pressed ( shift , 32 ) : lambda : grid . SelectRow ( grid . GetGridCursorRow ( ) ) , # <Ctrl> + <Space> pressed ( ctrl , 32 ) : lambda : grid . SelectCol ( grid . GetGridCursorCol ( ) ) , # <Shift> + <Ctrl> + <Space> pressed ( shift | ctrl , 32 ) : grid . SelectAll , } if self . main_window . IsFullScreen ( ) : # <Arrow up> pressed shortcuts [ ( 0 , 315 ) ] = switch_to_previous_table # <Arrow down> pressed shortcuts [ ( 0 , 317 ) ] = switch_to_next_table # <Space> pressed 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 | 544 | 7 |
230,631 | def OnRangeSelected ( self , event ) : # If grid editing is disabled then pyspread is in selection mode 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 | 115 | 5 |
230,632 | 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 | 61 | 5 |
230,633 | 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 | 126 | 6 |
230,634 | 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 | 55 | 10 |
230,635 | 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 | 46 | 9 |
230,636 | 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 | 44 | 9 |
230,637 | def OnTimerToggle ( self , event ) : if self . grid . timer_running : # Stop timer self . grid . timer_running = False self . grid . timer . Stop ( ) del self . grid . timer else : # Start timer 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 | 95 | 8 |
230,638 | 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 | 85 | 8 |
230,639 | def OnZoomStandard ( self , event ) : self . grid . actions . zoom ( zoom = 1.0 ) event . Skip ( ) | Event handler for resetting grid zoom | 30 | 7 |
230,640 | def OnContextMenu ( self , event ) : self . grid . PopupMenu ( self . grid . contextmenu ) event . Skip ( ) | Context menu event handler | 30 | 4 |
230,641 | 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 ( ) : # Scroll sideways if shift is pressed. self . grid . Scroll ( x + direction , y ) else : self . grid . Scroll ( x , y + direction ) | Event handler for mouse wheel actions | 233 | 6 |
230,642 | def OnFind ( self , event ) : # Search starts in next cell after the current one gridpos = list ( self . grid . actions . cursor ) text , flags = event . text , event . flags findpos = self . grid . actions . find ( gridpos , text , flags ) if findpos is None : # If nothing is found mention it in the statusbar and return statustext = _ ( "'{text}' not found." ) . format ( text = text ) else : # Otherwise select cell with next occurrence if successful self . grid . actions . cursor = findpos # Update statusbar 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 | 200 | 8 |
230,643 | def OnShowFindReplace ( self , event ) : data = wx . FindReplaceData ( wx . FR_DOWN ) dlg = wx . FindReplaceDialog ( self . grid , data , "Find & Replace" , wx . FR_REPLACEDIALOG ) dlg . data = data # save a reference to data dlg . Show ( True ) | Calls the find - replace dialog | 86 | 7 |
230,644 | 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 | 48 | 13 |
230,645 | 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 # Update statusbar 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 | 277 | 11 |
230,646 | 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 | 113 | 9 |
230,647 | 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 | 160 | 12 |
230,648 | def OnInsertRows ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 0 ] is None : # Insert rows at cursor ins_point = self . grid . actions . cursor [ 0 ] - 1 no_rows = 1 else : # Insert at lower edge of bounding box 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 ( ) # Update the default sized cell sizes self . grid . actions . zoom ( ) event . Skip ( ) | Insert the maximum of 1 and the number of selected rows | 181 | 11 |
230,649 | def OnInsertCols ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 1 ] is None : # Insert rows at cursor ins_point = self . grid . actions . cursor [ 1 ] - 1 no_cols = 1 else : # Insert at right edge of bounding box 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 ( ) # Update the default sized cell sizes self . grid . actions . zoom ( ) event . Skip ( ) | Inserts the maximum of 1 and the number of selected columns | 185 | 12 |
230,650 | 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 | 75 | 5 |
230,651 | def OnDeleteRows ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 0 ] is None : # Insert rows at cursor del_point = self . grid . actions . cursor [ 0 ] no_rows = 1 else : # Insert at lower edge of bounding box 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 ( ) # Update the default sized cell sizes self . grid . actions . zoom ( ) event . Skip ( ) | Deletes rows from all tables of the grid | 177 | 9 |
230,652 | def OnDeleteCols ( self , event ) : bbox = self . grid . selection . get_bbox ( ) if bbox is None or bbox [ 1 ] [ 1 ] is None : # Insert rows at cursor del_point = self . grid . actions . cursor [ 1 ] no_cols = 1 else : # Insert at right edge of bounding box 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 ( ) # Update the default sized cell sizes self . grid . actions . zoom ( ) event . Skip ( ) | Deletes columns from all tables of the grid | 181 | 9 |
230,653 | def OnQuote ( self , event ) : grid = self . grid grid . DisableCellEditControl ( ) with undo . group ( _ ( "Quote cell(s)" ) ) : # Is a selection present? if self . grid . IsSelection ( ) : # Enclose all selected cells self . grid . actions . quote_selection ( ) # Update grid 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 | 144 | 8 |
230,654 | def OnRowSize ( self , event ) : row = event . GetRowOrCol ( ) tab = self . grid . current_table rowsize = self . grid . GetRowSize ( row ) / self . grid . grid_renderer . zoom # Detect for resizing group of rows rows = self . grid . GetSelectedRows ( ) if len ( rows ) == 0 : rows = [ row , ] # Detect for selection of rows spanning all columns 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 ) # All row resizing is undone in one click 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 ) # Mark content as changed post_command_event ( self . grid . main_window , self . grid . ContentChangedMsg ) event . Skip ( ) self . grid . ForceRefresh ( ) | Row size event handler | 333 | 4 |
230,655 | def OnColSize ( self , event ) : col = event . GetRowOrCol ( ) tab = self . grid . current_table colsize = self . grid . GetColSize ( col ) / self . grid . grid_renderer . zoom # Detect for resizing group of cols cols = self . grid . GetSelectedCols ( ) if len ( cols ) == 0 : cols = [ col , ] # Detect for selection of rows spanning all columns 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 ) # All column resizing is undone in one click 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 ) # Mark content as changed post_command_event ( self . grid . main_window , self . grid . ContentChangedMsg ) event . Skip ( ) self . grid . ForceRefresh ( ) | Column size event handler | 333 | 4 |
230,656 | 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 | 113 | 4 |
230,657 | def OnUndo ( self , event ) : statustext = undo . stack ( ) . undotext ( ) undo . stack ( ) . undo ( ) # Update content changed state try : post_command_event ( self . grid . main_window , self . grid . ContentChangedMsg ) except TypeError : # The main window does not exist any more pass self . grid . code_array . result_cache . clear ( ) post_command_event ( self . grid . main_window , self . grid . TableChangedMsg , updated_cell = True ) # Reset row heights and column widths by zooming self . grid . actions . zoom ( ) # Change grid table dimensions self . grid . GetTable ( ) . ResetView ( ) # Update TableChoiceIntCtrl shape = self . grid . code_array . shape post_command_event ( self . main_window , self . grid . ResizeGridMsg , shape = shape ) # Update toolbars 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 | 255 | 6 |
230,658 | def rowcol_from_template ( target_tab , template_tab = 0 ) : for row , tab in S . row_heights . keys ( ) : # Delete all row heights in target table 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 ( ) : # Delete all column widths in target table 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 | 201 | 12 |
230,659 | 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 | 119 | 10 |
230,660 | def get_font_from_data ( fontdata ) : textfont = get_default_font ( ) if fontdata != "" : nativefontinfo = wx . NativeFontInfo ( ) nativefontinfo . FromString ( fontdata ) # OS X does not like a PointSize of 0 # Therefore, it is explicitly set to the system default font point size if not nativefontinfo . GetPointSize ( ) : nativefontinfo . SetPointSize ( get_default_font ( ) . GetPointSize ( ) ) textfont . SetNativeFontInfo ( nativefontinfo ) return textfont | Returns wx . Font from fontdata string | 125 | 9 |
230,661 | 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 | 71 | 10 |
230,662 | 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 | 48 | 14 |
230,663 | 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 | 70 | 12 |
230,664 | 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 | 185 | 14 |
230,665 | def common_start ( strings ) : def gen_start_strings ( string ) : """Generator that yield start sub-strings of length 1, 2, ...""" for i in xrange ( 1 , len ( string ) + 1 ) : yield string [ : i ] # Empty strings list if not strings : return "" start_string = "" # Get sucessively start string of 1st 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 | 133 | 12 |
230,666 | def is_svg ( code ) : if rsvg is None : return try : rsvg . Handle ( data = code ) except glib . GError : return False # The SVG file has to refer to its xmlns # Hopefully, it does so wiyhin the first 1000 characters if "http://www.w3.org/2000/svg" in code [ : 1000 ] : return True return False | Checks if code is an svg image | 89 | 9 |
230,667 | 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 | 90 | 3 |
230,668 | 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 | 83 | 5 |
230,669 | 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" : # If printing and not exporting then page info is # gathered from printer dialog 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 | 316 | 8 |
230,670 | 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 | 58 | 10 |
230,671 | 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 | 71 | 5 |
230,672 | 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 | 67 | 9 |
230,673 | 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 : # We have a merged cell top , left , bottom , right = merge_area # Are we drawing the top left cell? if top == row and left == col : # Set rect to merge area 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 : # Do not draw the cell because it is hidden return return pos_x , pos_y , width , height | Returns rectangle of cell on canvas | 362 | 6 |
230,674 | 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 ) : # Scale context to page extent # In order to keep the aspect ration intact use the maximum first_key = row_start , col_start , tab first_rect = self . get_cell_rect ( * first_key ) # If we have a merged cell then use the top left cell rect 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 we have a merged cell then use the top left cell rect 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 ( ) # Translate offset to o self . context . translate ( first_rect [ 0 ] , first_rect [ 1 ] ) # Scale to fit page, do not change aspect ratio scale = min ( scale_x , scale_y ) self . context . scale ( scale , scale ) # Translate offset self . context . translate ( - self . x_offset , - self . y_offset ) # TODO: Center the grid on the page # Render cells 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 ) # Rect if rect is not None : cell_renderer = GridCellCairoRenderer ( self . context , self . code_array , key , # (row, col, tab) rect , self . view_frozen ) cell_renderer . draw ( ) # Undo scaling, translation, ... self . context . restore ( ) self . context . show_page ( ) | Draws slice to context | 603 | 5 |
230,675 | 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 | 151 | 5 |
230,676 | 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 | 60 | 3 |
230,677 | def _get_scalexy ( self , ims_width , ims_height ) : # Get cell attributes 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 : # Normal case 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 | 148 | 11 |
230,678 | def _get_translation ( self , ims_width , ims_height ) : # Get cell attributes 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 ) : # Standard direction x = - 2 # Otherwise there is a white border y = - 2 # Otherwise there is a white border 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 | 684 | 9 |
230,679 | 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 | 268 | 8 |
230,680 | 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 | 227 | 7 |
230,681 | def draw_matplotlib_figure ( self , figure ) : class CustomRendererCairo ( RendererCairo ) : """Workaround for older versins with limited draw path length""" if sys . byteorder == 'little' : BYTE_FORMAT = 0 # BGRA else : BYTE_FORMAT = 1 # ARGB 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 : # Workaround for some Windiws version of Cairo self . _fill_and_stroke ( ctx , rgbFace , gc . get_alpha ( ) ) def draw_image ( self , gc , x , y , im ) : # bbox - not currently used 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 : # Matplotlib is not installed return FigureCanvasCairo ( figure ) dpi = float ( figure . dpi ) # Set a border so that the figure is not cut off at the cell border 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 | 626 | 8 |
230,682 | 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 | 55 | 8 |
230,683 | def set_font ( self , pango_layout ) : wx2pango_weights = { wx . FONTWEIGHT_BOLD : pango . WEIGHT_BOLD , wx . FONTWEIGHT_LIGHT : pango . WEIGHT_LIGHT , wx . FONTWEIGHT_NORMAL : None , # Do not set a weight by default } wx2pango_styles = { wx . FONTSTYLE_NORMAL : None , # Do not set a style by default wx . FONTSTYLE_SLANT : pango . STYLE_OBLIQUE , wx . FONTSTYLE_ITALIC : pango . STYLE_ITALIC , } cell_attributes = self . code_array . cell_attributes [ self . key ] # Text font attributes textfont = cell_attributes [ "textfont" ] pointsize = cell_attributes [ "pointsize" ] fontweight = cell_attributes [ "fontweight" ] fontstyle = cell_attributes [ "fontstyle" ] underline = cell_attributes [ "underline" ] strikethrough = cell_attributes [ "strikethrough" ] # Now construct the pango font font_description = pango . FontDescription ( " " . join ( [ textfont , str ( pointsize ) ] ) ) pango_layout . set_font_description ( font_description ) attrs = pango . AttrList ( ) # Underline attrs . insert ( pango . AttrUnderline ( underline , 0 , MAX_RESULT_LENGTH ) ) # Weight weight = wx2pango_weights [ fontweight ] if weight is not None : attrs . insert ( pango . AttrWeight ( weight , 0 , MAX_RESULT_LENGTH ) ) # Style style = wx2pango_styles [ fontstyle ] if style is not None : attrs . insert ( pango . AttrStyle ( style , 0 , MAX_RESULT_LENGTH ) ) # Strikethrough attrs . insert ( pango . AttrStrikethrough ( strikethrough , 0 , MAX_RESULT_LENGTH ) ) pango_layout . set_attributes ( attrs ) | Sets the font for draw_text | 499 | 8 |
230,684 | 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 ( ) # Skip characters until start 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 ] : # Same line extents_list [ - 1 ] [ 2 ] = extents_list [ - 1 ] [ 2 ] + underline_pixel_extents [ 2 ] else : # Line break 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 | 332 | 6 |
230,685 | 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 | 96 | 12 |
230,686 | 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 # Text color attributes 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 : # Old file 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 ] ) # Shift text for vertical 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 ) # Spell check underline drawing 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 | 692 | 7 |
230,687 | def draw_roundedrect ( self , x , y , w , h , r = 10 ) : # A****BQ # H C # * * # G D # F****E context = self . context context . save context . move_to ( x + r , y ) # Move to A context . line_to ( x + w - r , y ) # Straight line to B context . curve_to ( x + w , y , x + w , y , x + w , y + r ) # Curve to C # Control points are both at Q context . line_to ( x + w , y + h - r ) # Move to D context . curve_to ( x + w , y + h , x + w , y + h , x + w - r , y + h ) # Curve to E context . line_to ( x + r , y + h ) # Line to F context . curve_to ( x , y + h , x , y + h , x , y + h - r ) # Curve to G context . line_to ( x , y + r ) # Line to H context . curve_to ( x , y , x , y , x + r , y ) # Curve to A context . restore | Draws a rounded rectangle | 266 | 5 |
230,688 | def draw_button ( self , x , y , w , h , label ) : context = self . context self . draw_roundedrect ( x , y , w , h ) context . clip ( ) # Set up the gradients 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 ) # # Transform the coordinates so the width and height are both 1 # # We save the current settings and restore them afterward 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 ( ) # Draw the button text # Center the text 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 # Draw the button text context . move_to ( text_x , text_y ) context . set_source_rgba ( 0 , 0 , 0 , 1 ) context . show_text ( label ) # Draw the border of the button 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 | 392 | 4 |
230,689 | def draw ( self ) : # Content is only rendered within rect 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 # Do not draw cell content if cell is too small # This allows blending out small cells by reducing height to 0 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" ] : # Render a button instead of the 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 ) : # A bitmap is returned --> Draw it! self . draw_bitmap ( content ) elif pyplot is not None and isinstance ( content , pyplot . Figure ) : # A matplotlib figure is returned --> Draw it! self . draw_matplotlib_figure ( content ) elif isinstance ( content , basestring ) and is_svg ( content ) : # The content is a vaid SVG xml string self . draw_svg ( content ) elif content is not None : self . draw_text ( content ) self . context . translate ( - pos_x - 2 , - pos_y - 2 ) # Remove clipping to rect self . context . restore ( ) | Draws cell content to context | 431 | 6 |
230,690 | 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 | 51 | 8 |
230,691 | 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 | 144 | 10 |
230,692 | def draw ( self ) : self . context . set_source_rgb ( * self . _get_background_color ( ) ) self . context . rectangle ( * self . rect ) self . context . fill ( ) # If show frozen is active, show frozen pattern if self . view_frozen and self . cell_attributes [ self . key ] [ "frozen" ] : self . _draw_frozen_pattern ( ) | Draws cell background to context | 94 | 6 |
230,693 | 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 | 65 | 6 |
230,694 | 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 | 98 | 7 |
230,695 | 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 | 96 | 7 |
230,696 | 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 | 98 | 7 |
230,697 | 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 | 96 | 7 |
230,698 | 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 | 154 | 8 |
230,699 | 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 | 167 | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.