idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
231,100
def cross_entropy_calc ( TOP , P , POP ) : try : result = 0 for i in TOP . keys ( ) : reference_likelihood = P [ i ] / POP [ i ] response_likelihood = TOP [ i ] / POP [ i ] if response_likelihood != 0 and reference_likelihood != 0 : result += reference_likelihood * math . log ( response_likelihood , 2 ) return - result...
Calculate cross entropy .
231,101
def joint_entropy_calc ( classes , table , POP ) : try : result = 0 for i in classes : for index , j in enumerate ( classes ) : p_prime = table [ i ] [ j ] / POP [ i ] if p_prime != 0 : result += p_prime * math . log ( p_prime , 2 ) return - result except Exception : return "None"
Calculate joint entropy .
231,102
def conditional_entropy_calc ( classes , table , P , POP ) : try : result = 0 for i in classes : temp = 0 for index , j in enumerate ( classes ) : p_prime = 0 if P [ i ] != 0 : p_prime = table [ i ] [ j ] / P [ i ] if p_prime != 0 : temp += p_prime * math . log ( p_prime , 2 ) result += temp * ( P [ i ] / POP [ i ] ) r...
Calculate conditional entropy .
231,103
def lambda_B_calc ( classes , table , TOP , POP ) : try : result = 0 length = POP maxresponse = max ( list ( TOP . values ( ) ) ) for i in classes : result += max ( list ( table [ i ] . values ( ) ) ) result = ( result - maxresponse ) / ( length - maxresponse ) return result except Exception : return "None"
Calculate Goodman and Kruskal s lambda B .
231,104
def lambda_A_calc ( classes , table , P , POP ) : try : result = 0 maxreference = max ( list ( P . values ( ) ) ) length = POP for i in classes : col = [ ] for col_item in table . values ( ) : col . append ( col_item [ i ] ) result += max ( col ) result = ( result - maxreference ) / ( length - maxreference ) return res...
Calculate Goodman and Kruskal s lambda A .
231,105
def chi_square_calc ( classes , table , TOP , P , POP ) : try : result = 0 for i in classes : for index , j in enumerate ( classes ) : expected = ( TOP [ j ] * P [ i ] ) / ( POP [ i ] ) result += ( ( table [ i ] [ j ] - expected ) ** 2 ) / expected return result except Exception : return "None"
Calculate chi - squared .
231,106
def kappa_se_calc ( PA , PE , POP ) : try : result = math . sqrt ( ( PA * ( 1 - PA ) ) / ( POP * ( ( 1 - PE ) ** 2 ) ) ) return result except Exception : return "None"
Calculate kappa standard error .
231,107
def micro_calc ( TP , item ) : try : TP_sum = sum ( TP . values ( ) ) item_sum = sum ( item . values ( ) ) return TP_sum / ( TP_sum + item_sum ) except Exception : return "None"
Calculate PPV_Micro and TPR_Micro .
231,108
def macro_calc ( item ) : try : item_sum = sum ( item . values ( ) ) item_len = len ( item . values ( ) ) return item_sum / item_len except Exception : return "None"
Calculate PPV_Macro and TPR_Macro .
231,109
def PC_PI_calc ( P , TOP , POP ) : try : result = 0 for i in P . keys ( ) : result += ( ( P [ i ] + TOP [ i ] ) / ( 2 * POP [ i ] ) ) ** 2 return result except Exception : return "None"
Calculate percent chance agreement for Scott s Pi .
231,110
def PC_AC1_calc ( P , TOP , POP ) : try : result = 0 classes = list ( P . keys ( ) ) for i in classes : pi = ( ( P [ i ] + TOP [ i ] ) / ( 2 * POP [ i ] ) ) result += pi * ( 1 - pi ) result = result / ( len ( classes ) - 1 ) return result except Exception : return "None"
Calculate percent chance agreement for Gwet s AC1 .
231,111
def overall_jaccard_index_calc ( jaccard_list ) : try : jaccard_sum = sum ( jaccard_list ) jaccard_mean = jaccard_sum / len ( jaccard_list ) return ( jaccard_sum , jaccard_mean ) except Exception : return "None"
Calculate overall jaccard index .
231,112
def overall_accuracy_calc ( TP , POP ) : try : overall_accuracy = sum ( TP . values ( ) ) / POP return overall_accuracy except Exception : return "None"
Calculate overall accuracy .
231,113
def AUC_analysis ( AUC ) : try : if AUC == "None" : return "None" if AUC < 0.6 : return "Poor" if AUC >= 0.6 and AUC < 0.7 : return "Fair" if AUC >= 0.7 and AUC < 0.8 : return "Good" if AUC >= 0.8 and AUC < 0.9 : return "Very Good" return "Excellent" except Exception : return "None"
Analysis AUC with interpretation table .
231,114
def kappa_analysis_cicchetti ( kappa ) : try : if kappa < 0.4 : return "Poor" if kappa >= 0.4 and kappa < 0.59 : return "Fair" if kappa >= 0.59 and kappa < 0.74 : return "Good" if kappa >= 0.74 and kappa <= 1 : return "Excellent" return "None" except Exception : return "None"
Analysis kappa number with Cicchetti benchmark .
231,115
def kappa_analysis_koch ( kappa ) : try : if kappa < 0 : return "Poor" if kappa >= 0 and kappa < 0.2 : return "Slight" if kappa >= 0.20 and kappa < 0.4 : return "Fair" if kappa >= 0.40 and kappa < 0.6 : return "Moderate" if kappa >= 0.60 and kappa < 0.8 : return "Substantial" if kappa >= 0.80 and kappa <= 1 : return "A...
Analysis kappa number with Landis - Koch benchmark .
231,116
def kappa_analysis_altman ( kappa ) : try : if kappa < 0.2 : return "Poor" if kappa >= 0.20 and kappa < 0.4 : return "Fair" if kappa >= 0.40 and kappa < 0.6 : return "Moderate" if kappa >= 0.60 and kappa < 0.8 : return "Good" if kappa >= 0.80 and kappa <= 1 : return "Very Good" return "None" except Exception : return "...
Analysis kappa number with Altman benchmark .
231,117
def get_requires ( ) : requirements = open ( "requirements.txt" , "r" ) . read ( ) return list ( filter ( lambda x : x != "" , requirements . split ( ) ) )
Read requirements . txt .
231,118
def read_description ( ) : try : with open ( "README.md" ) as r : description = "\n" description += r . read ( ) with open ( "CHANGELOG.md" ) as c : description += "\n" description += c . read ( ) return description except Exception : return
Read README . md and CHANGELOG . md .
231,119
def print_matrix ( self , one_vs_all = False , class_name = None ) : classes = self . classes table = self . table if one_vs_all : [ classes , table ] = one_vs_all_func ( classes , table , self . TP , self . TN , self . FP , self . FN , class_name ) print ( table_print ( classes , table ) )
Print confusion matrix .
231,120
def stat ( self , overall_param = None , class_param = None , class_name = None ) : classes = class_filter ( self . classes , class_name ) print ( stat_print ( classes , self . class_stat , self . overall_stat , self . digit , overall_param , class_param ) )
Print statistical measures table .
231,121
def save_html ( self , name , address = True , overall_param = None , class_param = None , class_name = None , color = ( 0 , 0 , 0 ) , normalize = False ) : try : message = None table = self . table if normalize : table = self . normalized_table html_file = open ( name + ".html" , "w" ) html_file . write ( html_init ( ...
Save ConfusionMatrix in HTML file .
231,122
def save_csv ( self , name , address = True , class_param = None , class_name = None , matrix_save = True , normalize = False ) : try : message = None classes = class_filter ( self . classes , class_name ) csv_file = open ( name + ".csv" , "w" ) csv_data = csv_print ( classes , self . class_stat , self . digit , class_...
Save ConfusionMatrix in CSV file .
231,123
def save_obj ( self , name , address = True ) : try : message = None obj_file = open ( name + ".obj" , "w" ) actual_vector_temp = self . actual_vector predict_vector_temp = self . predict_vector matrix_temp = { k : self . table [ k ] . copy ( ) for k in self . classes } matrix_items = [ ] for i in self . classes : matr...
Save ConfusionMatrix in . obj file .
231,124
def F_beta ( self , beta ) : try : F_dict = { } for i in self . TP . keys ( ) : F_dict [ i ] = F_calc ( TP = self . TP [ i ] , FP = self . FP [ i ] , FN = self . FN [ i ] , beta = beta ) return F_dict except Exception : return { }
Calculate FBeta score .
231,125
def IBA_alpha ( self , alpha ) : try : IBA_dict = { } for i in self . classes : IBA_dict [ i ] = IBA_calc ( self . TPR [ i ] , self . TNR [ i ] , alpha = alpha ) return IBA_dict except Exception : return { }
Calculate IBA_alpha score .
231,126
def relabel ( self , mapping ) : if not isinstance ( mapping , dict ) : raise pycmMatrixError ( MAPPING_FORMAT_ERROR ) if self . classes != list ( mapping . keys ( ) ) : raise pycmMatrixError ( MAPPING_CLASS_NAME_ERROR ) for row in self . classes : temp_dict = { } temp_dict_normalized = { } for col in self . classes : ...
Rename ConfusionMatrix classes .
231,127
def add_tools ( self ) : for data in self . toolbardata : if data [ 0 ] == "T" : _ , msg_type , label , tool_tip = data icon = icons [ label ] self . label2id [ label ] = tool_id = wx . NewId ( ) self . AddSimpleTool ( tool_id , label , icon , short_help_string = tool_tip ) self . ids_msgs [ tool_id ] = msg_type self ....
Adds tools from self . toolbardata to self
231,128
def OnTool ( self , event ) : msgtype = self . ids_msgs [ event . GetId ( ) ] post_command_event ( self , msgtype )
Toolbar event handler
231,129
def OnToggleTool ( self , event ) : config [ "check_spelling" ] = str ( event . IsChecked ( ) ) toggle_id = self . parent . menubar . FindMenuItem ( _ ( "View" ) , _ ( "Check spelling" ) ) if toggle_id != - 1 : toggle_item = self . parent . menubar . FindItemById ( toggle_id ) toggle_item . Check ( event . IsChecked ( ...
Tool event handler
231,130
def _get_button_label ( self ) : dlg = wx . TextEntryDialog ( self , _ ( 'Button label:' ) ) if dlg . ShowModal ( ) == wx . ID_OK : label = dlg . GetValue ( ) else : label = "" dlg . Destroy ( ) return label
Gets Button label from user and returns string
231,131
def OnButtonCell ( self , event ) : if self . button_cell_button_id == event . GetId ( ) : if event . IsChecked ( ) : label = self . _get_button_label ( ) post_command_event ( self , self . ButtonCellMsg , text = label ) else : post_command_event ( self , self . ButtonCellMsg , text = False ) event . Skip ( )
Event handler for cell button toggle button
231,132
def OnVideoCell ( self , event ) : if self . video_cell_button_id == event . GetId ( ) : if event . IsChecked ( ) : wildcard = _ ( "Media files" ) + " (*.*)|*.*" videofile , __ = self . get_filepath_findex_from_user ( wildcard , "Choose video or audio file" , wx . OPEN ) post_command_event ( self , self . VideoCellMsg ...
Event handler for video cell toggle button
231,133
def make_menu ( self ) : menu = wx . Menu ( ) item = menu . Append ( - 1 , "Recent Searches" ) item . Enable ( False ) for __id , txt in enumerate ( self . search_history ) : menu . Append ( __id , txt ) return menu
Creates the search menu
231,134
def OnMenu ( self , event ) : __id = event . GetId ( ) try : menuitem = event . GetEventObject ( ) . FindItemById ( __id ) selected_text = menuitem . GetItemLabel ( ) self . search . SetValue ( selected_text ) except AttributeError : event . Skip ( )
Search history has been selected
231,135
def OnSearch ( self , event ) : search_string = self . search . GetValue ( ) if search_string not in self . search_history : self . search_history . append ( search_string ) if len ( self . search_history ) > 10 : self . search_history . pop ( 0 ) self . menu = self . make_menu ( ) self . search . SetMenu ( self . menu...
Event handler for starting the search
231,136
def OnSearchDirectionButton ( self , event ) : if "DOWN" in self . search_options : flag_index = self . search_options . index ( "DOWN" ) self . search_options [ flag_index ] = "UP" elif "UP" in self . search_options : flag_index = self . search_options . index ( "UP" ) self . search_options [ flag_index ] = "DOWN" els...
Event handler for search direction toggle button
231,137
def OnSearchFlag ( self , event ) : for label in self . search_options_buttons : button_id = self . label2id [ label ] if button_id == event . GetId ( ) : if event . IsChecked ( ) : self . search_options . append ( label ) else : flag_index = self . search_options . index ( label ) self . search_options . pop ( flag_in...
Event handler for search flag toggle buttons
231,138
def _create_font_choice_combo ( self ) : self . fonts = get_font_list ( ) self . font_choice_combo = _widgets . FontChoiceCombobox ( self , choices = self . fonts , style = wx . CB_READONLY , size = ( 125 , - 1 ) ) self . font_choice_combo . SetToolTipString ( _ ( u"Text font" ) ) self . AddControl ( self . font_choice...
Creates font choice combo box
231,139
def _create_font_size_combo ( self ) : self . std_font_sizes = config [ "font_default_sizes" ] font_size = str ( get_default_font ( ) . GetPointSize ( ) ) self . font_size_combo = wx . ComboBox ( self , - 1 , value = font_size , size = ( 60 , - 1 ) , choices = map ( unicode , self . std_font_sizes ) , style = wx . CB_D...
Creates font size combo box
231,140
def _create_font_face_buttons ( self ) : font_face_buttons = [ ( wx . FONTFLAG_BOLD , "OnBold" , "FormatTextBold" , _ ( "Bold" ) ) , ( wx . FONTFLAG_ITALIC , "OnItalics" , "FormatTextItalic" , _ ( "Italics" ) ) , ( wx . FONTFLAG_UNDERLINED , "OnUnderline" , "FormatTextUnderline" , _ ( "Underline" ) ) , ( wx . FONTFLAG_...
Creates font face buttons
231,141
def _create_textrotation_button ( self ) : iconnames = [ "TextRotate270" , "TextRotate0" , "TextRotate90" , "TextRotate180" ] bmplist = [ icons [ iconname ] for iconname in iconnames ] self . rotation_tb = _widgets . BitmapToggleButton ( self , bmplist ) self . rotation_tb . SetToolTipString ( _ ( u"Cell text rotation"...
Create text rotation toggle button
231,142
def _create_justification_button ( self ) : iconnames = [ "JustifyLeft" , "JustifyCenter" , "JustifyRight" ] bmplist = [ icons [ iconname ] for iconname in iconnames ] self . justify_tb = _widgets . BitmapToggleButton ( self , bmplist ) self . justify_tb . SetToolTipString ( _ ( u"Justification" ) ) self . Bind ( wx . ...
Creates horizontal justification button
231,143
def _create_alignment_button ( self ) : iconnames = [ "AlignTop" , "AlignCenter" , "AlignBottom" ] bmplist = [ icons [ iconname ] for iconname in iconnames ] self . alignment_tb = _widgets . BitmapToggleButton ( self , bmplist ) self . alignment_tb . SetToolTipString ( _ ( u"Alignment" ) ) self . Bind ( wx . EVT_BUTTON...
Creates vertical alignment button
231,144
def _create_borderchoice_combo ( self ) : choices = [ c [ 0 ] for c in self . border_toggles ] self . borderchoice_combo = _widgets . BorderEditChoice ( self , choices = choices , style = wx . CB_READONLY , size = ( 50 , - 1 ) ) self . borderchoice_combo . SetToolTipString ( _ ( u"Choose borders for which attributes ar...
Create border choice combo box
231,145
def _create_penwidth_combo ( self ) : choices = map ( unicode , xrange ( 12 ) ) self . pen_width_combo = _widgets . PenWidthComboBox ( self , choices = choices , style = wx . CB_READONLY , size = ( 50 , - 1 ) ) self . pen_width_combo . SetToolTipString ( _ ( u"Border width" ) ) self . AddControl ( self . pen_width_comb...
Create pen width combo box
231,146
def _create_color_buttons ( self ) : button_size = ( 30 , 30 ) button_style = wx . NO_BORDER try : self . linecolor_choice = csel . ColourSelect ( self , - 1 , unichr ( 0x2500 ) , ( 0 , 0 , 0 ) , size = button_size , style = button_style ) except UnicodeEncodeError : self . linecolor_choice = csel . ColourSelect ( self...
Create color choice buttons
231,147
def _create_merge_button ( self ) : bmp = icons [ "Merge" ] self . mergetool_id = wx . NewId ( ) self . AddCheckTool ( self . mergetool_id , "Merge" , bmp , bmp , short_help_string = _ ( "Merge cells" ) ) self . Bind ( wx . EVT_TOOL , self . OnMerge , id = self . mergetool_id )
Create merge button
231,148
def _update_font ( self , textfont ) : try : fontface_id = self . fonts . index ( textfont ) except ValueError : fontface_id = 0 self . font_choice_combo . Select ( fontface_id )
Updates text font widget
231,149
def _update_font_weight ( self , font_weight ) : toggle_state = font_weight & wx . FONTWEIGHT_BOLD == wx . FONTWEIGHT_BOLD self . ToggleTool ( wx . FONTFLAG_BOLD , toggle_state )
Updates font weight widget
231,150
def _update_font_style ( self , font_style ) : toggle_state = font_style & wx . FONTSTYLE_ITALIC == wx . FONTSTYLE_ITALIC self . ToggleTool ( wx . FONTFLAG_ITALIC , toggle_state )
Updates font style widget
231,151
def _update_frozencell ( self , frozen ) : toggle_state = frozen is not False self . ToggleTool ( wx . FONTFLAG_MASK , toggle_state )
Updates frozen cell widget
231,152
def _update_textrotation ( self , angle ) : states = { 0 : 0 , - 90 : 1 , 180 : 2 , 90 : 3 } try : self . rotation_tb . state = states [ round ( angle ) ] except KeyError : self . rotation_tb . state = 0 self . rotation_tb . toggle ( None ) self . rotation_tb . Refresh ( )
Updates text rotation toggle button
231,153
def _update_justification ( self , justification ) : states = { "left" : 2 , "center" : 0 , "right" : 1 } self . justify_tb . state = states [ justification ] self . justify_tb . toggle ( None ) self . justify_tb . Refresh ( )
Updates horizontal text justification button
231,154
def _update_alignment ( self , alignment ) : states = { "top" : 2 , "middle" : 0 , "bottom" : 1 } self . alignment_tb . state = states [ alignment ] self . alignment_tb . toggle ( None ) self . alignment_tb . Refresh ( )
Updates vertical text alignment button
231,155
def _update_fontcolor ( self , fontcolor ) : textcolor = wx . SystemSettings_GetColour ( wx . SYS_COLOUR_WINDOWTEXT ) textcolor . SetRGB ( fontcolor ) self . textcolor_choice . SetColour ( textcolor )
Updates text font color button
231,156
def OnBorderChoice ( self , event ) : choicelist = event . GetEventObject ( ) . GetItems ( ) self . borderstate = choicelist [ event . GetInt ( ) ]
Change the borders that are affected by color and width changes
231,157
def OnLineColor ( self , event ) : color = event . GetValue ( ) . GetRGB ( ) borders = self . bordermap [ self . borderstate ] post_command_event ( self , self . BorderColorMsg , color = color , borders = borders )
Line color choice event handler
231,158
def OnLineWidth ( self , event ) : linewidth_combobox = event . GetEventObject ( ) idx = event . GetInt ( ) width = int ( linewidth_combobox . GetString ( idx ) ) borders = self . bordermap [ self . borderstate ] post_command_event ( self , self . BorderWidthMsg , width = width , borders = borders )
Line width choice event handler
231,159
def OnBGColor ( self , event ) : color = event . GetValue ( ) . GetRGB ( ) post_command_event ( self , self . BackgroundColorMsg , color = color )
Background color choice event handler
231,160
def OnTextColor ( self , event ) : color = event . GetValue ( ) . GetRGB ( ) post_command_event ( self , self . TextColorMsg , color = color )
Text color choice event handler
231,161
def OnTextFont ( self , event ) : fontchoice_combobox = event . GetEventObject ( ) idx = event . GetInt ( ) try : font_string = fontchoice_combobox . GetString ( idx ) except AttributeError : font_string = event . GetString ( ) post_command_event ( self , self . FontMsg , font = font_string )
Text font choice event handler
231,162
def OnTextSize ( self , event ) : try : size = int ( event . GetString ( ) ) except Exception : size = get_default_font ( ) . GetPointSize ( ) post_command_event ( self , self . FontSizeMsg , size = size )
Text size combo text event handler
231,163
def set_code ( self , key , code ) : old_code = self . grid . code_array ( key ) try : old_code = unicode ( old_code , encoding = "utf-8" ) except TypeError : pass if code == old_code : return if not ( old_code is None and not code ) and code != old_code : post_command_event ( self . main_window , self . ContentChanged...
Sets code of cell key marks grid as changed
231,164
def quote_code ( self , key ) : code = self . grid . code_array ( key ) quoted_code = quote ( code ) if quoted_code is not None : self . set_code ( key , quoted_code )
Returns string quoted code
231,165
def delete_cell ( self , key ) : try : self . code_array . pop ( key ) except KeyError : pass self . grid . code_array . result_cache . clear ( )
Deletes key cell
231,166
def append_reference_code ( self , key , ref_key , ref_type = "absolute" ) : if ref_type == "absolute" : code = self . _get_absolute_reference ( ref_key ) elif ref_type == "relative" : code = self . _get_relative_reference ( key , ref_key ) else : raise ValueError ( _ ( 'ref_type has to be "absolute" or "relative".' ) ...
Appends reference code to cell code .
231,167
def _set_cell_attr ( self , selection , table , attr ) : post_command_event ( self . main_window , self . ContentChangedMsg ) if selection is not None : self . code_array . cell_attributes . append ( ( selection , table , attr ) )
Sets cell attr for key cell and mark grid content as changed
231,168
def set_attr ( self , attr , value , selection = None ) : if selection is None : selection = self . grid . selection if not selection : selection . cells . append ( self . grid . actions . cursor [ : 2 ] ) attrs = { attr : value } table = self . grid . current_table self . _set_cell_attr ( selection , table , attrs )
Sets attr of current selection to value
231,169
def set_border_attr ( self , attr , value , borders ) : selection = self . grid . selection if not selection : selection . cells . append ( self . grid . actions . cursor [ : 2 ] ) if "inner" in borders : if "top" in borders : adj_selection = selection + ( - 1 , 0 ) self . set_attr ( attr + "_bottom" , value , adj_sele...
Sets border attribute by adjusting selection to borders
231,170
def toggle_attr ( self , attr ) : selection = self . grid . selection if selection : value = self . get_new_selection_attr_state ( selection , attr ) else : value = self . get_new_cell_attr_state ( self . grid . actions . cursor , attr ) self . set_attr ( attr , value )
Toggles an attribute attr for current selection
231,171
def change_frozen_attr ( self ) : if self . grid . selection : statustext = _ ( "Freezing selections is not supported." ) post_command_event ( self . main_window , self . StatusBarMsg , text = statustext ) cursor = self . grid . actions . cursor frozen = self . grid . code_array . cell_attributes [ cursor ] [ "frozen" ...
Changes frozen state of cell if there is no selection
231,172
def unmerge ( self , unmerge_area , tab ) : top , left , bottom , right = unmerge_area selection = Selection ( [ ( top , left ) ] , [ ( bottom , right ) ] , [ ] , [ ] , [ ] ) attr = { "merge_area" : None , "locked" : False } self . _set_cell_attr ( selection , tab , attr )
Unmerges all cells in unmerge_area
231,173
def merge ( self , merge_area , tab ) : top , left , bottom , right = merge_area cursor = self . grid . actions . cursor top_left_code = self . code_array ( ( top , left , cursor [ 2 ] ) ) selection = Selection ( [ ( top , left ) ] , [ ( bottom , right ) ] , [ ] , [ ] , [ ] ) error_msg = _ ( "Overlapping merge area at ...
Merges top left cell with all cells until bottom_right
231,174
def merge_selected_cells ( self , selection ) : tab = self . grid . current_table bbox = selection . get_bbox ( ) if bbox is None : row , col , tab = self . grid . actions . cursor ( bb_top , bb_left ) , ( bb_bottom , bb_right ) = ( row , col ) , ( row , col ) else : ( bb_top , bb_left ) , ( bb_bottom , bb_right ) = bb...
Merges or unmerges cells that are in the selection bounding box
231,175
def get_new_cell_attr_state ( self , key , attr_key ) : cell_attributes = self . grid . code_array . cell_attributes attr_values = self . attr_toggle_values [ attr_key ] attr_map = dict ( zip ( attr_values , attr_values [ 1 : ] + attr_values [ : 1 ] ) ) return attr_map [ cell_attributes [ key ] [ attr_key ] ]
Returns new attr cell state for toggles
231,176
def get_new_selection_attr_state ( self , selection , attr_key ) : cell_attributes = self . grid . code_array . cell_attributes attr_values = self . attr_toggle_values [ attr_key ] attr_map = dict ( zip ( attr_values , attr_values [ 1 : ] + attr_values [ : 1 ] ) ) selection_attrs = ( attr for attr in cell_attributes if...
Toggles new attr selection state and returns it
231,177
def refresh_frozen_cell ( self , key ) : code = self . grid . code_array ( key ) result = self . grid . code_array . _eval_cell ( key , code ) self . grid . code_array . frozen_cache [ repr ( key ) ] = result
Refreshes a frozen cell
231,178
def refresh_selected_frozen_cells ( self , selection = None ) : if selection is None : selection = self . grid . selection if not selection : selection . cells . append ( self . grid . actions . cursor [ : 2 ] ) cell_attributes = self . grid . code_array . cell_attributes refreshed_keys = [ ] for attr_selection , tab ,...
Refreshes content of frozen cells that are currently selected
231,179
def _import_csv ( self , path ) : if not path : return try : dialect , has_header , digest_types , encoding = self . main_window . interfaces . get_csv_import_info ( path ) except IOError : msg = _ ( "Error opening file {filepath}." ) . format ( filepath = path ) post_command_event ( self . main_window , self . StatusB...
CSV import workflow
231,180
def import_file ( self , filepath , filterindex ) : post_command_event ( self . main_window , self . ContentChangedMsg ) if filterindex == 0 : return self . _import_csv ( filepath ) elif filterindex == 1 : return self . _import_txt ( filepath ) else : msg = _ ( "Unknown import choice {choice}." ) msg = msg . format ( c...
Imports external file
231,181
def _export_csv ( self , filepath , data , preview_data ) : csv_info = self . main_window . interfaces . get_csv_export_info ( preview_data ) if csv_info is None : return try : dialect , digest_types , has_header = csv_info except TypeError : return csv_interface = CsvInterface ( self . main_window , filepath , dialect...
CSV export of code_array results
231,182
def _export_figure ( self , filepath , data , format ) : formats = [ "svg" , "eps" , "ps" , "pdf" , "png" ] assert format in formats data = fig2x ( data , format ) try : outfile = open ( filepath , "wb" ) outfile . write ( data ) except IOError , err : msg = _ ( "The file {filepath} could not be fully written\n \n" "Er...
Export of single cell that contains a matplotlib figure
231,183
def export_file ( self , filepath , __filter , data , preview_data = None ) : if __filter . startswith ( "cell_" ) : self . _export_figure ( filepath , data , __filter [ 5 : ] ) elif __filter == "csv" : self . _export_csv ( filepath , data , preview_data = preview_data ) elif __filter in [ "pdf" , "svg" ] : self . expo...
Export data for other applications
231,184
def get_print_rect ( self , grid_rect ) : grid = self . grid rect_x = grid_rect . x - grid . GetScrollPos ( wx . HORIZONTAL ) * grid . GetScrollLineX ( ) rect_y = grid_rect . y - grid . GetScrollPos ( wx . VERTICAL ) * grid . GetScrollLineY ( ) return wx . Rect ( rect_x , rect_y , grid_rect . width , grid_rect . height...
Returns wx . Rect that is correctly positioned on the print canvas
231,185
def export_cairo ( self , filepath , filetype ) : if cairo is None : return export_info = self . main_window . interfaces . get_cairo_export_info ( filetype ) if export_info is None : return top_row = max ( 0 , export_info [ "top_row" ] ) bottom_row = min ( self . grid . code_array . shape [ 0 ] - 1 , export_info [ "bo...
Exports grid to the PDF file filepath
231,186
def print_preview ( self , print_area , print_data ) : if cairo is None : return print_info = self . main_window . interfaces . get_cairo_export_info ( "Print" ) if print_info is None : return printout_preview = Printout ( self . grid , print_data , print_info ) printout_printing = Printout ( self . grid , print_data ,...
Launch print preview
231,187
def printout ( self , print_area , print_data ) : print_info = self . main_window . interfaces . get_cairo_export_info ( "Print" ) if print_info is None : return pdd = wx . PrintDialogData ( print_data ) printer = wx . Printer ( pdd ) printout = Printout ( self . grid , print_data , print_info ) if printer . Print ( se...
Print out print area
231,188
def copy ( self , selection , getter = None , delete = False ) : if getter is None : getter = self . _get_code tab = self . grid . current_table selection_bbox = selection . get_bbox ( ) if not selection_bbox : bb_top , bb_left = self . grid . actions . cursor [ : 2 ] bb_bottom , bb_right = bb_top , bb_left else : repl...
Returns code from selection in a tab separated string
231,189
def img2code ( self , key , img ) : code_template = "wx.ImageFromData({width}, {height}, " + "bz2.decompress(base64.b64decode('{data}'))).ConvertToBitmap()" code_alpha_template = "wx.ImageFromDataWithAlpha({width}, {height}, " + "bz2.decompress(base64.b64decode('{data}')), " + "bz2.decompress(base64.b64decode('{alpha}'...
Pastes wx . Image into single cell
231,190
def _get_paste_data_gen ( self , key , data ) : if type ( data ) is wx . _gdi . Bitmap : code_str = self . bmp2code ( key , data ) return [ [ code_str ] ] else : return ( line . split ( "\t" ) for line in data . split ( "\n" ) )
Generator for paste data
231,191
def paste ( self , key , data ) : data_gen = self . _get_paste_data_gen ( key , data ) self . grid . actions . paste ( key [ : 2 ] , data_gen , freq = 1000 ) self . main_window . grid . ForceRefresh ( )
Pastes data into grid
231,192
def _get_pasteas_data ( self , dim , obj ) : if dim == 0 : return [ [ repr ( obj ) ] ] elif dim == 1 : return [ [ repr ( o ) ] for o in obj ] elif dim == 2 : return [ map ( repr , o ) for o in obj ]
Returns list of lists of obj than has dimensionality dim
231,193
def paste_as ( self , key , data ) : def error_msg ( err ) : msg = _ ( "Error evaluating data: " ) + str ( err ) post_command_event ( self . main_window , self . StatusBarMsg , text = msg ) interfaces = self . main_window . interfaces key = self . main_window . grid . actions . cursor try : obj = ast . literal_eval ( d...
Paste and transform data
231,194
def execute_macros ( self ) : post_command_event ( self . main_window , self . ContentChangedMsg ) ( result , err ) = self . grid . code_array . execute_macros ( ) post_command_event ( self . main_window , self . MacroErrorMsg , msg = result , err = err )
Executes macros and marks grid as changed
231,195
def open_macros ( self , filepath ) : try : wx . BeginBusyCursor ( ) self . main_window . grid . Disable ( ) with open ( filepath ) as macro_infile : self . main_window . grid . actions . enter_safe_mode ( ) post_command_event ( self . main_window , self . SafeModeEntryMsg ) post_command_event ( self . main_window , se...
Loads macros from file and marks grid as changed
231,196
def save_macros ( self , filepath , macros ) : io_error_text = _ ( "Error writing to file {filepath}." ) io_error_text = io_error_text . format ( filepath = filepath ) tmpfile = filepath + "~" try : wx . BeginBusyCursor ( ) self . main_window . grid . Disable ( ) with open ( tmpfile , "w" ) as macro_outfile : macro_out...
Saves macros to file
231,197
def launch_help ( self , helpname , filename ) : position = config [ "help_window_position" ] size = config [ "help_window_size" ] self . help_window = wx . Frame ( self . main_window , - 1 , helpname , position , size ) self . help_htmlwindow = wx . html . HtmlWindow ( self . help_window , - 1 , ( 0 , 0 ) , size ) sel...
Generic help launcher
231,198
def OnHelpMove ( self , event ) : position = event . GetPosition ( ) config [ "help_window_position" ] = repr ( ( position . x , position . y ) ) event . Skip ( )
Help window move event handler stores position in config
231,199
def OnHelpSize ( self , event ) : size = event . GetSize ( ) config [ "help_window_size" ] = repr ( ( size . width , size . height ) ) event . Skip ( )
Help window size event handler stores size in config