repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnNew
def OnNew(self, event): """New grid event handler""" # If changes have taken place save of old grid if undo.stack().haschanged(): save_choice = self.interfaces.get_save_request_from_user() if save_choice is None: # Cancelled close operation return elif save_choice: # User wants to save content post_command_event(self.main_window, self.main_window.SaveMsg) # Get grid dimensions shape = self.interfaces.get_dimensions_from_user(no_dim=3) if shape is None: return # Set new filepath and post it to the title bar self.main_window.filepath = None post_command_event(self.main_window, self.main_window.TitleMsg, text="pyspread") # Clear globals self.main_window.grid.actions.clear_globals_reload_modules() # Create new grid post_command_event(self.main_window, self.main_window.GridActionNewMsg, shape=shape) # Update TableChoiceIntCtrl post_command_event(self.main_window, self.main_window.ResizeGridMsg, shape=shape) if is_gtk(): try: wx.Yield() except: pass self.main_window.grid.actions.change_grid_shape(shape) self.main_window.grid.GetTable().ResetView() self.main_window.grid.ForceRefresh() # Display grid creation in status bar msg = _("New grid with dimensions {dim} created.").format(dim=shape) post_command_event(self.main_window, self.main_window.StatusBarMsg, text=msg) self.main_window.grid.ForceRefresh() if is_gtk(): try: wx.Yield() except: pass # Update undo stack savepoint and clear undo stack undo.stack().clear() undo.stack().savepoint() # Update content changed state try: post_command_event(self.main_window, self.ContentChangedMsg) except TypeError: # The main window does not exist any more pass
python
def OnNew(self, event): """New grid event handler""" # If changes have taken place save of old grid if undo.stack().haschanged(): save_choice = self.interfaces.get_save_request_from_user() if save_choice is None: # Cancelled close operation return elif save_choice: # User wants to save content post_command_event(self.main_window, self.main_window.SaveMsg) # Get grid dimensions shape = self.interfaces.get_dimensions_from_user(no_dim=3) if shape is None: return # Set new filepath and post it to the title bar self.main_window.filepath = None post_command_event(self.main_window, self.main_window.TitleMsg, text="pyspread") # Clear globals self.main_window.grid.actions.clear_globals_reload_modules() # Create new grid post_command_event(self.main_window, self.main_window.GridActionNewMsg, shape=shape) # Update TableChoiceIntCtrl post_command_event(self.main_window, self.main_window.ResizeGridMsg, shape=shape) if is_gtk(): try: wx.Yield() except: pass self.main_window.grid.actions.change_grid_shape(shape) self.main_window.grid.GetTable().ResetView() self.main_window.grid.ForceRefresh() # Display grid creation in status bar msg = _("New grid with dimensions {dim} created.").format(dim=shape) post_command_event(self.main_window, self.main_window.StatusBarMsg, text=msg) self.main_window.grid.ForceRefresh() if is_gtk(): try: wx.Yield() except: pass # Update undo stack savepoint and clear undo stack undo.stack().clear() undo.stack().savepoint() # Update content changed state try: post_command_event(self.main_window, self.ContentChangedMsg) except TypeError: # The main window does not exist any more pass
[ "def", "OnNew", "(", "self", ",", "event", ")", ":", "# If changes have taken place save of old grid", "if", "undo", ".", "stack", "(", ")", ".", "haschanged", "(", ")", ":", "save_choice", "=", "self", ".", "interfaces", ".", "get_save_request_from_user", "(", ...
New grid event handler
[ "New", "grid", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L757-L830
train
231,400
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnOpen
def OnOpen(self, event): """File open event handler""" # If changes have taken place save of old grid if undo.stack().haschanged(): save_choice = self.interfaces.get_save_request_from_user() if save_choice is None: # Cancelled close operation return elif save_choice: # User wants to save content post_command_event(self.main_window, self.main_window.SaveMsg) # Get filepath from user f2w = get_filetypes2wildcards( ["pys", "pysu", "xls", "xlsx", "ods", "all"]) filetypes = f2w.keys() wildcards = f2w.values() wildcard = "|".join(wildcards) message = _("Choose file to open.") style = wx.OPEN default_filetype = config["default_open_filetype"] try: default_filterindex = filetypes.index(default_filetype) except ValueError: # Be graceful if the user has entered an unkown filetype default_filterindex = 0 get_fp_fidx = self.interfaces.get_filepath_findex_from_user filepath, filterindex = get_fp_fidx(wildcard, message, style, filterindex=default_filterindex) if filepath is None: return filetype = filetypes[filterindex] # Change the main window filepath state self.main_window.filepath = filepath # Load file into grid post_command_event(self.main_window, self.main_window.GridActionOpenMsg, attr={"filepath": filepath, "filetype": filetype}) # Set Window title to new filepath title_text = filepath.split("/")[-1] + " - pyspread" post_command_event(self.main_window, self.main_window.TitleMsg, text=title_text) self.main_window.grid.ForceRefresh() if is_gtk(): try: wx.Yield() except: pass # Update savepoint and clear the undo stack undo.stack().clear() undo.stack().savepoint() # Update content changed state try: post_command_event(self.main_window, self.ContentChangedMsg) except TypeError: # The main window does not exist any more pass
python
def OnOpen(self, event): """File open event handler""" # If changes have taken place save of old grid if undo.stack().haschanged(): save_choice = self.interfaces.get_save_request_from_user() if save_choice is None: # Cancelled close operation return elif save_choice: # User wants to save content post_command_event(self.main_window, self.main_window.SaveMsg) # Get filepath from user f2w = get_filetypes2wildcards( ["pys", "pysu", "xls", "xlsx", "ods", "all"]) filetypes = f2w.keys() wildcards = f2w.values() wildcard = "|".join(wildcards) message = _("Choose file to open.") style = wx.OPEN default_filetype = config["default_open_filetype"] try: default_filterindex = filetypes.index(default_filetype) except ValueError: # Be graceful if the user has entered an unkown filetype default_filterindex = 0 get_fp_fidx = self.interfaces.get_filepath_findex_from_user filepath, filterindex = get_fp_fidx(wildcard, message, style, filterindex=default_filterindex) if filepath is None: return filetype = filetypes[filterindex] # Change the main window filepath state self.main_window.filepath = filepath # Load file into grid post_command_event(self.main_window, self.main_window.GridActionOpenMsg, attr={"filepath": filepath, "filetype": filetype}) # Set Window title to new filepath title_text = filepath.split("/")[-1] + " - pyspread" post_command_event(self.main_window, self.main_window.TitleMsg, text=title_text) self.main_window.grid.ForceRefresh() if is_gtk(): try: wx.Yield() except: pass # Update savepoint and clear the undo stack undo.stack().clear() undo.stack().savepoint() # Update content changed state try: post_command_event(self.main_window, self.ContentChangedMsg) except TypeError: # The main window does not exist any more pass
[ "def", "OnOpen", "(", "self", ",", "event", ")", ":", "# If changes have taken place save of old grid", "if", "undo", ".", "stack", "(", ")", ".", "haschanged", "(", ")", ":", "save_choice", "=", "self", ".", "interfaces", ".", "get_save_request_from_user", "(",...
File open event handler
[ "File", "open", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L832-L905
train
231,401
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnSave
def OnSave(self, event): """File save event handler""" try: filetype = event.attr["filetype"] except (KeyError, AttributeError): filetype = None filepath = self.main_window.filepath if filepath is None: filetype = config["default_save_filetype"] if filetype is None: f2w = get_filetypes2wildcards(["pys", "pysu", "xls", "all"]) __filetypes = f2w.keys() # Check if the file extension matches any valid save filetype for __filetype in __filetypes: if splitext(filepath)[-1][1:] == __filetype: filetype = __filetype break # If there is no filepath or no filetype is found then jump to save as if self.main_window.filepath is None or filetype is None: post_command_event(self.main_window, self.main_window.SaveAsMsg) return # Save the grid post_command_event(self.main_window, self.main_window.GridActionSaveMsg, attr={"filepath": self.main_window.filepath, "filetype": filetype}) # Update undo stack savepoint undo.stack().savepoint() # Display file save in status bar statustext = self.main_window.filepath.split("/")[-1] + " saved." post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext)
python
def OnSave(self, event): """File save event handler""" try: filetype = event.attr["filetype"] except (KeyError, AttributeError): filetype = None filepath = self.main_window.filepath if filepath is None: filetype = config["default_save_filetype"] if filetype is None: f2w = get_filetypes2wildcards(["pys", "pysu", "xls", "all"]) __filetypes = f2w.keys() # Check if the file extension matches any valid save filetype for __filetype in __filetypes: if splitext(filepath)[-1][1:] == __filetype: filetype = __filetype break # If there is no filepath or no filetype is found then jump to save as if self.main_window.filepath is None or filetype is None: post_command_event(self.main_window, self.main_window.SaveAsMsg) return # Save the grid post_command_event(self.main_window, self.main_window.GridActionSaveMsg, attr={"filepath": self.main_window.filepath, "filetype": filetype}) # Update undo stack savepoint undo.stack().savepoint() # Display file save in status bar statustext = self.main_window.filepath.split("/")[-1] + " saved." post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext)
[ "def", "OnSave", "(", "self", ",", "event", ")", ":", "try", ":", "filetype", "=", "event", ".", "attr", "[", "\"filetype\"", "]", "except", "(", "KeyError", ",", "AttributeError", ")", ":", "filetype", "=", "None", "filepath", "=", "self", ".", "main_...
File save event handler
[ "File", "save", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L908-L954
train
231,402
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnSaveAs
def OnSaveAs(self, event): """File save as event handler""" # Get filepath from user f2w = get_filetypes2wildcards(["pys", "pysu", "xls", "all"]) filetypes = f2w.keys() wildcards = f2w.values() wildcard = "|".join(wildcards) message = _("Choose filename for saving.") style = wx.SAVE default_filetype = config["default_save_filetype"] try: default_filterindex = filetypes.index(default_filetype) except ValueError: # Be graceful if the user has entered an unkown filetype default_filterindex = 0 get_fp_fidx = self.interfaces.get_filepath_findex_from_user filepath, filterindex = get_fp_fidx(wildcard, message, style, filterindex=default_filterindex) if filepath is None: return 0 filetype = filetypes[filterindex] # Look if path is already present if os.path.exists(filepath): if not os.path.isfile(filepath): # There is a directory with the same path statustext = _("Directory present. Save aborted.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext) return 0 # There is a file with the same path message = \ _("The file {filepath} is already present.\nOverwrite?")\ .format(filepath=filepath) short_msg = _("File collision") if not self.main_window.interfaces.get_warning_choice(message, short_msg): statustext = _("File present. Save aborted by user.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext) return 0 # Put pys suffix if wildcard choice is 0 if filterindex == 0 and filepath[-4:] != ".pys": filepath += ".pys" # Set the filepath state self.main_window.filepath = filepath # Set Window title to new filepath title_text = filepath.split("/")[-1] + " - pyspread" post_command_event(self.main_window, self.main_window.TitleMsg, text=title_text) # Now jump to save post_command_event(self.main_window, self.main_window.SaveMsg, attr={"filetype": filetype})
python
def OnSaveAs(self, event): """File save as event handler""" # Get filepath from user f2w = get_filetypes2wildcards(["pys", "pysu", "xls", "all"]) filetypes = f2w.keys() wildcards = f2w.values() wildcard = "|".join(wildcards) message = _("Choose filename for saving.") style = wx.SAVE default_filetype = config["default_save_filetype"] try: default_filterindex = filetypes.index(default_filetype) except ValueError: # Be graceful if the user has entered an unkown filetype default_filterindex = 0 get_fp_fidx = self.interfaces.get_filepath_findex_from_user filepath, filterindex = get_fp_fidx(wildcard, message, style, filterindex=default_filterindex) if filepath is None: return 0 filetype = filetypes[filterindex] # Look if path is already present if os.path.exists(filepath): if not os.path.isfile(filepath): # There is a directory with the same path statustext = _("Directory present. Save aborted.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext) return 0 # There is a file with the same path message = \ _("The file {filepath} is already present.\nOverwrite?")\ .format(filepath=filepath) short_msg = _("File collision") if not self.main_window.interfaces.get_warning_choice(message, short_msg): statustext = _("File present. Save aborted by user.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext) return 0 # Put pys suffix if wildcard choice is 0 if filterindex == 0 and filepath[-4:] != ".pys": filepath += ".pys" # Set the filepath state self.main_window.filepath = filepath # Set Window title to new filepath title_text = filepath.split("/")[-1] + " - pyspread" post_command_event(self.main_window, self.main_window.TitleMsg, text=title_text) # Now jump to save post_command_event(self.main_window, self.main_window.SaveMsg, attr={"filetype": filetype})
[ "def", "OnSaveAs", "(", "self", ",", "event", ")", ":", "# Get filepath from user", "f2w", "=", "get_filetypes2wildcards", "(", "[", "\"pys\"", ",", "\"pysu\"", ",", "\"xls\"", ",", "\"all\"", "]", ")", "filetypes", "=", "f2w", ".", "keys", "(", ")", "wild...
File save as event handler
[ "File", "save", "as", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L956-L1025
train
231,403
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnImport
def OnImport(self, event): """File import event handler""" # Get filepath from user wildcards = get_filetypes2wildcards(["csv", "txt"]).values() wildcard = "|".join(wildcards) message = _("Choose file to import.") style = wx.OPEN filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return # Get generator of import data import_data = self.main_window.actions.import_file(filepath, filterindex) if import_data is None: return # Paste import data to grid grid = self.main_window.grid tl_cell = grid.GetGridCursorRow(), grid.GetGridCursorCol() grid.actions.paste(tl_cell, import_data) self.main_window.grid.ForceRefresh()
python
def OnImport(self, event): """File import event handler""" # Get filepath from user wildcards = get_filetypes2wildcards(["csv", "txt"]).values() wildcard = "|".join(wildcards) message = _("Choose file to import.") style = wx.OPEN filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return # Get generator of import data import_data = self.main_window.actions.import_file(filepath, filterindex) if import_data is None: return # Paste import data to grid grid = self.main_window.grid tl_cell = grid.GetGridCursorRow(), grid.GetGridCursorCol() grid.actions.paste(tl_cell, import_data) self.main_window.grid.ForceRefresh()
[ "def", "OnImport", "(", "self", ",", "event", ")", ":", "# Get filepath from user", "wildcards", "=", "get_filetypes2wildcards", "(", "[", "\"csv\"", ",", "\"txt\"", "]", ")", ".", "values", "(", ")", "wildcard", "=", "\"|\"", ".", "join", "(", "wildcards", ...
File import event handler
[ "File", "import", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1027-L1057
train
231,404
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnExport
def OnExport(self, event): """File export event handler Currently, only CSV export is supported """ code_array = self.main_window.grid.code_array tab = self.main_window.grid.current_table selection = self.main_window.grid.selection # Check if no selection is present selection_bbox = selection.get_bbox() f2w = get_filetypes2wildcards(["csv", "pdf", "svg"]) filters = f2w.keys() wildcards = f2w.values() wildcard = "|".join(wildcards) if selection_bbox is None: # No selection --> Use smallest filled area for bottom right edge maxrow, maxcol, __ = code_array.get_last_filled_cell(tab) (top, left), (bottom, right) = (0, 0), (maxrow, maxcol) else: (top, left), (bottom, right) = selection_bbox # Generator of row and column keys in correct order __top = 0 if top is None else top __bottom = code_array.shape[0] if bottom is None else bottom + 1 __left = 0 if left is None else left __right = code_array.shape[1] if right is None else right + 1 def data_gen(top, bottom, left, right): for row in xrange(top, bottom): yield (code_array[row, col, tab] for col in xrange(left, right)) data = data_gen(__top, __bottom, __left, __right) preview_data = data_gen(__top, __bottom, __left, __right) # Get target filepath from user # No selection --> Provide svg export of current cell # if current cell is a matplotlib figure if selection_bbox is None: cursor = self.main_window.grid.actions.cursor figure = code_array[cursor] if Figure is not None and isinstance(figure, Figure): wildcard += \ "|" + _("SVG of current cell") + " (*.svg)|*.svg" + \ "|" + _("EPS of current cell") + " (*.eps)|*.eps" + \ "|" + _("PS of current cell") + " (*.ps)|*.ps" + \ "|" + _("PDF of current cell") + " (*.pdf)|*.pdf" + \ "|" + _("PNG of current cell") + " (*.png)|*.png" filters.append("cell_svg") filters.append("cell_eps") filters.append("cell_ps") filters.append("cell_pdf") filters.append("cell_png") message = _("Choose filename for export.") style = wx.SAVE path, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if path is None: return # If an single cell is exported then the selection bbox # has to be changed to the current cell if filters[filterindex].startswith("cell_"): data = figure # Export file # ----------- self.main_window.actions.export_file(path, filters[filterindex], data, preview_data)
python
def OnExport(self, event): """File export event handler Currently, only CSV export is supported """ code_array = self.main_window.grid.code_array tab = self.main_window.grid.current_table selection = self.main_window.grid.selection # Check if no selection is present selection_bbox = selection.get_bbox() f2w = get_filetypes2wildcards(["csv", "pdf", "svg"]) filters = f2w.keys() wildcards = f2w.values() wildcard = "|".join(wildcards) if selection_bbox is None: # No selection --> Use smallest filled area for bottom right edge maxrow, maxcol, __ = code_array.get_last_filled_cell(tab) (top, left), (bottom, right) = (0, 0), (maxrow, maxcol) else: (top, left), (bottom, right) = selection_bbox # Generator of row and column keys in correct order __top = 0 if top is None else top __bottom = code_array.shape[0] if bottom is None else bottom + 1 __left = 0 if left is None else left __right = code_array.shape[1] if right is None else right + 1 def data_gen(top, bottom, left, right): for row in xrange(top, bottom): yield (code_array[row, col, tab] for col in xrange(left, right)) data = data_gen(__top, __bottom, __left, __right) preview_data = data_gen(__top, __bottom, __left, __right) # Get target filepath from user # No selection --> Provide svg export of current cell # if current cell is a matplotlib figure if selection_bbox is None: cursor = self.main_window.grid.actions.cursor figure = code_array[cursor] if Figure is not None and isinstance(figure, Figure): wildcard += \ "|" + _("SVG of current cell") + " (*.svg)|*.svg" + \ "|" + _("EPS of current cell") + " (*.eps)|*.eps" + \ "|" + _("PS of current cell") + " (*.ps)|*.ps" + \ "|" + _("PDF of current cell") + " (*.pdf)|*.pdf" + \ "|" + _("PNG of current cell") + " (*.png)|*.png" filters.append("cell_svg") filters.append("cell_eps") filters.append("cell_ps") filters.append("cell_pdf") filters.append("cell_png") message = _("Choose filename for export.") style = wx.SAVE path, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if path is None: return # If an single cell is exported then the selection bbox # has to be changed to the current cell if filters[filterindex].startswith("cell_"): data = figure # Export file # ----------- self.main_window.actions.export_file(path, filters[filterindex], data, preview_data)
[ "def", "OnExport", "(", "self", ",", "event", ")", ":", "code_array", "=", "self", ".", "main_window", ".", "grid", ".", "code_array", "tab", "=", "self", ".", "main_window", ".", "grid", ".", "current_table", "selection", "=", "self", ".", "main_window", ...
File export event handler Currently, only CSV export is supported
[ "File", "export", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1059-L1143
train
231,405
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnExportPDF
def OnExportPDF(self, event): """Export PDF event handler""" wildcards = get_filetypes2wildcards(["pdf"]).values() if not wildcards: return wildcard = "|".join(wildcards) # Get filepath from user message = _("Choose file path for PDF export.") style = wx.SAVE filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return self.main_window.actions.export_cairo(filepath, "pdf") event.Skip()
python
def OnExportPDF(self, event): """Export PDF event handler""" wildcards = get_filetypes2wildcards(["pdf"]).values() if not wildcards: return wildcard = "|".join(wildcards) # Get filepath from user message = _("Choose file path for PDF export.") style = wx.SAVE filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return self.main_window.actions.export_cairo(filepath, "pdf") event.Skip()
[ "def", "OnExportPDF", "(", "self", ",", "event", ")", ":", "wildcards", "=", "get_filetypes2wildcards", "(", "[", "\"pdf\"", "]", ")", ".", "values", "(", ")", "if", "not", "wildcards", ":", "return", "wildcard", "=", "\"|\"", ".", "join", "(", "wildcard...
Export PDF event handler
[ "Export", "PDF", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1145-L1168
train
231,406
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnApprove
def OnApprove(self, event): """File approve event handler""" if not self.main_window.safe_mode: return msg = _(u"You are going to approve and trust a file that\n" u"you have not created yourself.\n" u"After proceeding, the file is executed.\n \n" u"It may harm your system as any program can.\n" u"Please check all cells thoroughly before\nproceeding.\n \n" u"Proceed and sign this file as trusted?") short_msg = _("Security warning") if self.main_window.interfaces.get_warning_choice(msg, short_msg): # Leave safe mode self.main_window.grid.actions.leave_safe_mode() # Display safe mode end in status bar statustext = _("Safe mode deactivated.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext)
python
def OnApprove(self, event): """File approve event handler""" if not self.main_window.safe_mode: return msg = _(u"You are going to approve and trust a file that\n" u"you have not created yourself.\n" u"After proceeding, the file is executed.\n \n" u"It may harm your system as any program can.\n" u"Please check all cells thoroughly before\nproceeding.\n \n" u"Proceed and sign this file as trusted?") short_msg = _("Security warning") if self.main_window.interfaces.get_warning_choice(msg, short_msg): # Leave safe mode self.main_window.grid.actions.leave_safe_mode() # Display safe mode end in status bar statustext = _("Safe mode deactivated.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext)
[ "def", "OnApprove", "(", "self", ",", "event", ")", ":", "if", "not", "self", ".", "main_window", ".", "safe_mode", ":", "return", "msg", "=", "_", "(", "u\"You are going to approve and trust a file that\\n\"", "u\"you have not created yourself.\\n\"", "u\"After proceed...
File approve event handler
[ "File", "approve", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1170-L1193
train
231,407
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnClearGlobals
def OnClearGlobals(self, event): """Clear globals event handler""" msg = _("Deleting globals and reloading modules cannot be undone." " Proceed?") short_msg = _("Really delete globals and modules?") choice = self.main_window.interfaces.get_warning_choice(msg, short_msg) if choice: self.main_window.grid.actions.clear_globals_reload_modules() statustext = _("Globals cleared and base modules reloaded.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext)
python
def OnClearGlobals(self, event): """Clear globals event handler""" msg = _("Deleting globals and reloading modules cannot be undone." " Proceed?") short_msg = _("Really delete globals and modules?") choice = self.main_window.interfaces.get_warning_choice(msg, short_msg) if choice: self.main_window.grid.actions.clear_globals_reload_modules() statustext = _("Globals cleared and base modules reloaded.") post_command_event(self.main_window, self.main_window.StatusBarMsg, text=statustext)
[ "def", "OnClearGlobals", "(", "self", ",", "event", ")", ":", "msg", "=", "_", "(", "\"Deleting globals and reloading modules cannot be undone.\"", "\" Proceed?\"", ")", "short_msg", "=", "_", "(", "\"Really delete globals and modules?\"", ")", "choice", "=", "self", ...
Clear globals event handler
[ "Clear", "globals", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1195-L1209
train
231,408
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnPageSetup
def OnPageSetup(self, event): """Page setup handler for printing framework""" print_data = self.main_window.print_data new_print_data = \ self.main_window.interfaces.get_print_setup(print_data) self.main_window.print_data = new_print_data
python
def OnPageSetup(self, event): """Page setup handler for printing framework""" print_data = self.main_window.print_data new_print_data = \ self.main_window.interfaces.get_print_setup(print_data) self.main_window.print_data = new_print_data
[ "def", "OnPageSetup", "(", "self", ",", "event", ")", ":", "print_data", "=", "self", ".", "main_window", ".", "print_data", "new_print_data", "=", "self", ".", "main_window", ".", "interfaces", ".", "get_print_setup", "(", "print_data", ")", "self", ".", "m...
Page setup handler for printing framework
[ "Page", "setup", "handler", "for", "printing", "framework" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1213-L1219
train
231,409
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers._get_print_area
def _get_print_area(self): """Returns selection bounding box or visible area""" # Get print area from current selection selection = self.main_window.grid.selection print_area = selection.get_bbox() # If there is no selection use the visible area on the screen if print_area is None: print_area = self.main_window.grid.actions.get_visible_area() return print_area
python
def _get_print_area(self): """Returns selection bounding box or visible area""" # Get print area from current selection selection = self.main_window.grid.selection print_area = selection.get_bbox() # If there is no selection use the visible area on the screen if print_area is None: print_area = self.main_window.grid.actions.get_visible_area() return print_area
[ "def", "_get_print_area", "(", "self", ")", ":", "# Get print area from current selection", "selection", "=", "self", ".", "main_window", ".", "grid", ".", "selection", "print_area", "=", "selection", ".", "get_bbox", "(", ")", "# If there is no selection use the visibl...
Returns selection bounding box or visible area
[ "Returns", "selection", "bounding", "box", "or", "visible", "area" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1221-L1232
train
231,410
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnPrintPreview
def OnPrintPreview(self, event): """Print preview handler""" print_area = self._get_print_area() print_data = self.main_window.print_data self.main_window.actions.print_preview(print_area, print_data)
python
def OnPrintPreview(self, event): """Print preview handler""" print_area = self._get_print_area() print_data = self.main_window.print_data self.main_window.actions.print_preview(print_area, print_data)
[ "def", "OnPrintPreview", "(", "self", ",", "event", ")", ":", "print_area", "=", "self", ".", "_get_print_area", "(", ")", "print_data", "=", "self", ".", "main_window", ".", "print_data", "self", ".", "main_window", ".", "actions", ".", "print_preview", "("...
Print preview handler
[ "Print", "preview", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1234-L1240
train
231,411
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnPrint
def OnPrint(self, event): """Print event handler""" print_area = self._get_print_area() print_data = self.main_window.print_data self.main_window.actions.printout(print_area, print_data)
python
def OnPrint(self, event): """Print event handler""" print_area = self._get_print_area() print_data = self.main_window.print_data self.main_window.actions.printout(print_area, print_data)
[ "def", "OnPrint", "(", "self", ",", "event", ")", ":", "print_area", "=", "self", ".", "_get_print_area", "(", ")", "print_data", "=", "self", ".", "main_window", ".", "print_data", "self", ".", "main_window", ".", "actions", ".", "printout", "(", "print_a...
Print event handler
[ "Print", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1242-L1248
train
231,412
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnCut
def OnCut(self, event): """Clipboard cut event handler""" entry_line = \ self.main_window.entry_line_panel.entry_line_panel.entry_line if wx.Window.FindFocus() != entry_line: selection = self.main_window.grid.selection with undo.group(_("Cut")): data = self.main_window.actions.cut(selection) self.main_window.clipboard.set_clipboard(data) self.main_window.grid.ForceRefresh() else: entry_line.Cut() event.Skip()
python
def OnCut(self, event): """Clipboard cut event handler""" entry_line = \ self.main_window.entry_line_panel.entry_line_panel.entry_line if wx.Window.FindFocus() != entry_line: selection = self.main_window.grid.selection with undo.group(_("Cut")): data = self.main_window.actions.cut(selection) self.main_window.clipboard.set_clipboard(data) self.main_window.grid.ForceRefresh() else: entry_line.Cut() event.Skip()
[ "def", "OnCut", "(", "self", ",", "event", ")", ":", "entry_line", "=", "self", ".", "main_window", ".", "entry_line_panel", ".", "entry_line_panel", ".", "entry_line", "if", "wx", ".", "Window", ".", "FindFocus", "(", ")", "!=", "entry_line", ":", "select...
Clipboard cut event handler
[ "Clipboard", "cut", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1252-L1271
train
231,413
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnCopy
def OnCopy(self, event): """Clipboard copy event handler""" focus = self.main_window.FindFocus() if isinstance(focus, wx.TextCtrl): # Copy selection from TextCtrl if in focus focus.Copy() else: selection = self.main_window.grid.selection data = self.main_window.actions.copy(selection) self.main_window.clipboard.set_clipboard(data) event.Skip()
python
def OnCopy(self, event): """Clipboard copy event handler""" focus = self.main_window.FindFocus() if isinstance(focus, wx.TextCtrl): # Copy selection from TextCtrl if in focus focus.Copy() else: selection = self.main_window.grid.selection data = self.main_window.actions.copy(selection) self.main_window.clipboard.set_clipboard(data) event.Skip()
[ "def", "OnCopy", "(", "self", ",", "event", ")", ":", "focus", "=", "self", ".", "main_window", ".", "FindFocus", "(", ")", "if", "isinstance", "(", "focus", ",", "wx", ".", "TextCtrl", ")", ":", "# Copy selection from TextCtrl if in focus", "focus", ".", ...
Clipboard copy event handler
[ "Clipboard", "copy", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1273-L1287
train
231,414
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnCopyResult
def OnCopyResult(self, event): """Clipboard copy results event handler""" selection = self.main_window.grid.selection data = self.main_window.actions.copy_result(selection) # Check if result is a bitmap if type(data) is wx._gdi.Bitmap: # Copy bitmap to clipboard self.main_window.clipboard.set_clipboard(data, datatype="bitmap") else: # Copy string representation of result to clipboard self.main_window.clipboard.set_clipboard(data, datatype="text") event.Skip()
python
def OnCopyResult(self, event): """Clipboard copy results event handler""" selection = self.main_window.grid.selection data = self.main_window.actions.copy_result(selection) # Check if result is a bitmap if type(data) is wx._gdi.Bitmap: # Copy bitmap to clipboard self.main_window.clipboard.set_clipboard(data, datatype="bitmap") else: # Copy string representation of result to clipboard self.main_window.clipboard.set_clipboard(data, datatype="text") event.Skip()
[ "def", "OnCopyResult", "(", "self", ",", "event", ")", ":", "selection", "=", "self", ".", "main_window", ".", "grid", ".", "selection", "data", "=", "self", ".", "main_window", ".", "actions", ".", "copy_result", "(", "selection", ")", "# Check if result is...
Clipboard copy results event handler
[ "Clipboard", "copy", "results", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1289-L1305
train
231,415
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnPaste
def OnPaste(self, event): """Clipboard paste event handler""" data = self.main_window.clipboard.get_clipboard() focus = self.main_window.FindFocus() if isinstance(focus, wx.TextCtrl): # Paste into TextCtrl if in focus focus.WriteText(data) else: # We got a grid selection key = self.main_window.grid.actions.cursor with undo.group(_("Paste")): self.main_window.actions.paste(key, data) self.main_window.grid.ForceRefresh() event.Skip()
python
def OnPaste(self, event): """Clipboard paste event handler""" data = self.main_window.clipboard.get_clipboard() focus = self.main_window.FindFocus() if isinstance(focus, wx.TextCtrl): # Paste into TextCtrl if in focus focus.WriteText(data) else: # We got a grid selection key = self.main_window.grid.actions.cursor with undo.group(_("Paste")): self.main_window.actions.paste(key, data) self.main_window.grid.ForceRefresh() event.Skip()
[ "def", "OnPaste", "(", "self", ",", "event", ")", ":", "data", "=", "self", ".", "main_window", ".", "clipboard", ".", "get_clipboard", "(", ")", "focus", "=", "self", ".", "main_window", ".", "FindFocus", "(", ")", "if", "isinstance", "(", "focus", ",...
Clipboard paste event handler
[ "Clipboard", "paste", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1307-L1327
train
231,416
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnPasteAs
def OnPasteAs(self, event): """Clipboard paste as event handler""" data = self.main_window.clipboard.get_clipboard() key = self.main_window.grid.actions.cursor with undo.group(_("Paste As...")): self.main_window.actions.paste_as(key, data) self.main_window.grid.ForceRefresh() event.Skip()
python
def OnPasteAs(self, event): """Clipboard paste as event handler""" data = self.main_window.clipboard.get_clipboard() key = self.main_window.grid.actions.cursor with undo.group(_("Paste As...")): self.main_window.actions.paste_as(key, data) self.main_window.grid.ForceRefresh() event.Skip()
[ "def", "OnPasteAs", "(", "self", ",", "event", ")", ":", "data", "=", "self", ".", "main_window", ".", "clipboard", ".", "get_clipboard", "(", ")", "key", "=", "self", ".", "main_window", ".", "grid", ".", "actions", ".", "cursor", "with", "undo", ".",...
Clipboard paste as event handler
[ "Clipboard", "paste", "as", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1329-L1340
train
231,417
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnSelectAll
def OnSelectAll(self, event): """Select all cells event handler""" entry_line = \ self.main_window.entry_line_panel.entry_line_panel.entry_line if wx.Window.FindFocus() != entry_line: self.main_window.grid.SelectAll() else: entry_line.SelectAll()
python
def OnSelectAll(self, event): """Select all cells event handler""" entry_line = \ self.main_window.entry_line_panel.entry_line_panel.entry_line if wx.Window.FindFocus() != entry_line: self.main_window.grid.SelectAll() else: entry_line.SelectAll()
[ "def", "OnSelectAll", "(", "self", ",", "event", ")", ":", "entry_line", "=", "self", ".", "main_window", ".", "entry_line_panel", ".", "entry_line_panel", ".", "entry_line", "if", "wx", ".", "Window", ".", "FindFocus", "(", ")", "!=", "entry_line", ":", "...
Select all cells event handler
[ "Select", "all", "cells", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1343-L1353
train
231,418
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnFontDialog
def OnFontDialog(self, event): """Event handler for launching font dialog""" # Get current font data from current cell cursor = self.main_window.grid.actions.cursor attr = self.main_window.grid.code_array.cell_attributes[cursor] size, style, weight, font = \ [attr[name] for name in ["pointsize", "fontstyle", "fontweight", "textfont"]] current_font = wx.Font(int(size), -1, style, weight, 0, font) # Get Font from dialog fontdata = wx.FontData() fontdata.EnableEffects(True) fontdata.SetInitialFont(current_font) dlg = wx.FontDialog(self.main_window, fontdata) if dlg.ShowModal() == wx.ID_OK: fontdata = dlg.GetFontData() font = fontdata.GetChosenFont() post_command_event(self.main_window, self.main_window.FontMsg, font=font.FaceName) post_command_event(self.main_window, self.main_window.FontSizeMsg, size=font.GetPointSize()) post_command_event(self.main_window, self.main_window.FontBoldMsg, weight=font.GetWeightString()) post_command_event(self.main_window, self.main_window.FontItalicsMsg, style=font.GetStyleString()) if is_gtk(): try: wx.Yield() except: pass self.main_window.grid.update_attribute_toolbar()
python
def OnFontDialog(self, event): """Event handler for launching font dialog""" # Get current font data from current cell cursor = self.main_window.grid.actions.cursor attr = self.main_window.grid.code_array.cell_attributes[cursor] size, style, weight, font = \ [attr[name] for name in ["pointsize", "fontstyle", "fontweight", "textfont"]] current_font = wx.Font(int(size), -1, style, weight, 0, font) # Get Font from dialog fontdata = wx.FontData() fontdata.EnableEffects(True) fontdata.SetInitialFont(current_font) dlg = wx.FontDialog(self.main_window, fontdata) if dlg.ShowModal() == wx.ID_OK: fontdata = dlg.GetFontData() font = fontdata.GetChosenFont() post_command_event(self.main_window, self.main_window.FontMsg, font=font.FaceName) post_command_event(self.main_window, self.main_window.FontSizeMsg, size=font.GetPointSize()) post_command_event(self.main_window, self.main_window.FontBoldMsg, weight=font.GetWeightString()) post_command_event(self.main_window, self.main_window.FontItalicsMsg, style=font.GetStyleString()) if is_gtk(): try: wx.Yield() except: pass self.main_window.grid.update_attribute_toolbar()
[ "def", "OnFontDialog", "(", "self", ",", "event", ")", ":", "# Get current font data from current cell", "cursor", "=", "self", ".", "main_window", ".", "grid", ".", "actions", ".", "cursor", "attr", "=", "self", ".", "main_window", ".", "grid", ".", "code_arr...
Event handler for launching font dialog
[ "Event", "handler", "for", "launching", "font", "dialog" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1364-L1405
train
231,419
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnTextColorDialog
def OnTextColorDialog(self, event): """Event handler for launching text color dialog""" dlg = wx.ColourDialog(self.main_window) # Ensure the full colour dialog is displayed, # not the abbreviated version. dlg.GetColourData().SetChooseFull(True) if dlg.ShowModal() == wx.ID_OK: # Fetch color data data = dlg.GetColourData() color = data.GetColour().GetRGB() post_command_event(self.main_window, self.main_window.TextColorMsg, color=color) dlg.Destroy()
python
def OnTextColorDialog(self, event): """Event handler for launching text color dialog""" dlg = wx.ColourDialog(self.main_window) # Ensure the full colour dialog is displayed, # not the abbreviated version. dlg.GetColourData().SetChooseFull(True) if dlg.ShowModal() == wx.ID_OK: # Fetch color data data = dlg.GetColourData() color = data.GetColour().GetRGB() post_command_event(self.main_window, self.main_window.TextColorMsg, color=color) dlg.Destroy()
[ "def", "OnTextColorDialog", "(", "self", ",", "event", ")", ":", "dlg", "=", "wx", ".", "ColourDialog", "(", "self", ".", "main_window", ")", "# Ensure the full colour dialog is displayed,", "# not the abbreviated version.", "dlg", ".", "GetColourData", "(", ")", "....
Event handler for launching text color dialog
[ "Event", "handler", "for", "launching", "text", "color", "dialog" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1407-L1425
train
231,420
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnMacroListLoad
def OnMacroListLoad(self, event): """Macro list load event handler""" # Get filepath from user wildcards = get_filetypes2wildcards(["py", "all"]).values() wildcard = "|".join(wildcards) message = _("Choose macro file.") style = wx.OPEN filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return # Enter safe mode because macro file could be harmful post_command_event(self.main_window, self.main_window.SafeModeEntryMsg) # Load macros from file self.main_window.actions.open_macros(filepath) event.Skip()
python
def OnMacroListLoad(self, event): """Macro list load event handler""" # Get filepath from user wildcards = get_filetypes2wildcards(["py", "all"]).values() wildcard = "|".join(wildcards) message = _("Choose macro file.") style = wx.OPEN filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return # Enter safe mode because macro file could be harmful post_command_event(self.main_window, self.main_window.SafeModeEntryMsg) # Load macros from file self.main_window.actions.open_macros(filepath) event.Skip()
[ "def", "OnMacroListLoad", "(", "self", ",", "event", ")", ":", "# Get filepath from user", "wildcards", "=", "get_filetypes2wildcards", "(", "[", "\"py\"", ",", "\"all\"", "]", ")", ".", "values", "(", ")", "wildcard", "=", "\"|\"", ".", "join", "(", "wildca...
Macro list load event handler
[ "Macro", "list", "load", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1460-L1487
train
231,421
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnMacroListSave
def OnMacroListSave(self, event): """Macro list save event handler""" # Get filepath from user wildcards = get_filetypes2wildcards(["py", "all"]).values() wildcard = "|".join(wildcards) message = _("Choose macro file.") style = wx.SAVE filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return # Save macros to file macros = self.main_window.grid.code_array.macros self.main_window.actions.save_macros(filepath, macros) event.Skip()
python
def OnMacroListSave(self, event): """Macro list save event handler""" # Get filepath from user wildcards = get_filetypes2wildcards(["py", "all"]).values() wildcard = "|".join(wildcards) message = _("Choose macro file.") style = wx.SAVE filepath, filterindex = \ self.interfaces.get_filepath_findex_from_user(wildcard, message, style) if filepath is None: return # Save macros to file macros = self.main_window.grid.code_array.macros self.main_window.actions.save_macros(filepath, macros) event.Skip()
[ "def", "OnMacroListSave", "(", "self", ",", "event", ")", ":", "# Get filepath from user", "wildcards", "=", "get_filetypes2wildcards", "(", "[", "\"py\"", ",", "\"all\"", "]", ")", ".", "values", "(", ")", "wildcard", "=", "\"|\"", ".", "join", "(", "wildca...
Macro list save event handler
[ "Macro", "list", "save", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1489-L1513
train
231,422
manns/pyspread
pyspread/src/gui/_main_window.py
MainWindowEventHandlers.OnDependencies
def OnDependencies(self, event): """Display dependency dialog""" dlg = DependencyDialog(self.main_window) dlg.ShowModal() dlg.Destroy()
python
def OnDependencies(self, event): """Display dependency dialog""" dlg = DependencyDialog(self.main_window) dlg.ShowModal() dlg.Destroy()
[ "def", "OnDependencies", "(", "self", ",", "event", ")", ":", "dlg", "=", "DependencyDialog", "(", "self", ".", "main_window", ")", "dlg", ".", "ShowModal", "(", ")", "dlg", ".", "Destroy", "(", ")" ]
Display dependency dialog
[ "Display", "dependency", "dialog" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_main_window.py#L1540-L1545
train
231,423
manns/pyspread
pyspread/src/gui/_menubars.py
_filledMenu._add_submenu
def _add_submenu(self, parent, data): """Adds items in data as a submenu to parent""" for item in data: obj = item[0] if obj == wx.Menu: try: __, menuname, submenu, menu_id = item except ValueError: __, menuname, submenu = item menu_id = -1 menu = obj() self._add_submenu(menu, submenu) if parent == self: self.menubar.Append(menu, menuname) else: parent.AppendMenu(menu_id, menuname, menu) elif obj == wx.MenuItem: try: msgtype, shortcut, helptext, item_id = item[1] except ValueError: msgtype, shortcut, helptext = item[1] item_id = wx.NewId() try: style = item[2] except IndexError: style = wx.ITEM_NORMAL menuitem = obj(parent, item_id, shortcut, helptext, style) self.shortcut2menuitem[shortcut] = menuitem self.id2menuitem[item_id] = menuitem parent.AppendItem(menuitem) self.ids_msgs[item_id] = msgtype self.parent.Bind(wx.EVT_MENU, self.OnMenu, id=item_id) elif obj == "Separator": parent.AppendSeparator() else: raise TypeError(_("Menu item unknown"))
python
def _add_submenu(self, parent, data): """Adds items in data as a submenu to parent""" for item in data: obj = item[0] if obj == wx.Menu: try: __, menuname, submenu, menu_id = item except ValueError: __, menuname, submenu = item menu_id = -1 menu = obj() self._add_submenu(menu, submenu) if parent == self: self.menubar.Append(menu, menuname) else: parent.AppendMenu(menu_id, menuname, menu) elif obj == wx.MenuItem: try: msgtype, shortcut, helptext, item_id = item[1] except ValueError: msgtype, shortcut, helptext = item[1] item_id = wx.NewId() try: style = item[2] except IndexError: style = wx.ITEM_NORMAL menuitem = obj(parent, item_id, shortcut, helptext, style) self.shortcut2menuitem[shortcut] = menuitem self.id2menuitem[item_id] = menuitem parent.AppendItem(menuitem) self.ids_msgs[item_id] = msgtype self.parent.Bind(wx.EVT_MENU, self.OnMenu, id=item_id) elif obj == "Separator": parent.AppendSeparator() else: raise TypeError(_("Menu item unknown"))
[ "def", "_add_submenu", "(", "self", ",", "parent", ",", "data", ")", ":", "for", "item", "in", "data", ":", "obj", "=", "item", "[", "0", "]", "if", "obj", "==", "wx", ".", "Menu", ":", "try", ":", "__", ",", "menuname", ",", "submenu", ",", "m...
Adds items in data as a submenu to parent
[ "Adds", "items", "in", "data", "as", "a", "submenu", "to", "parent" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_menubars.py#L96-L142
train
231,424
manns/pyspread
pyspread/src/gui/_menubars.py
_filledMenu.OnMenu
def OnMenu(self, event): """Menu event handler""" msgtype = self.ids_msgs[event.GetId()] post_command_event(self.parent, msgtype)
python
def OnMenu(self, event): """Menu event handler""" msgtype = self.ids_msgs[event.GetId()] post_command_event(self.parent, msgtype)
[ "def", "OnMenu", "(", "self", ",", "event", ")", ":", "msgtype", "=", "self", ".", "ids_msgs", "[", "event", ".", "GetId", "(", ")", "]", "post_command_event", "(", "self", ".", "parent", ",", "msgtype", ")" ]
Menu event handler
[ "Menu", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_menubars.py#L144-L148
train
231,425
manns/pyspread
pyspread/src/gui/_menubars.py
_filledMenu.OnUpdate
def OnUpdate(self, event): """Menu state update""" if wx.ID_UNDO in self.id2menuitem: undo_item = self.id2menuitem[wx.ID_UNDO] undo_item.Enable(undo.stack().canundo()) if wx.ID_REDO in self.id2menuitem: redo_item = self.id2menuitem[wx.ID_REDO] redo_item.Enable(undo.stack().canredo()) event.Skip()
python
def OnUpdate(self, event): """Menu state update""" if wx.ID_UNDO in self.id2menuitem: undo_item = self.id2menuitem[wx.ID_UNDO] undo_item.Enable(undo.stack().canundo()) if wx.ID_REDO in self.id2menuitem: redo_item = self.id2menuitem[wx.ID_REDO] redo_item.Enable(undo.stack().canredo()) event.Skip()
[ "def", "OnUpdate", "(", "self", ",", "event", ")", ":", "if", "wx", ".", "ID_UNDO", "in", "self", ".", "id2menuitem", ":", "undo_item", "=", "self", ".", "id2menuitem", "[", "wx", ".", "ID_UNDO", "]", "undo_item", ".", "Enable", "(", "undo", ".", "st...
Menu state update
[ "Menu", "state", "update" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_menubars.py#L150-L161
train
231,426
manns/pyspread
pyspread/src/gui/_chart_dialog.py
TextEditor.OnFont
def OnFont(self, event): """Check event handler""" font_data = wx.FontData() # Disable color chooser on Windows font_data.EnableEffects(False) if self.chosen_font: font_data.SetInitialFont(self.chosen_font) dlg = wx.FontDialog(self, font_data) if dlg.ShowModal() == wx.ID_OK: font_data = dlg.GetFontData() font = self.chosen_font = font_data.GetChosenFont() self.font_face = font.GetFaceName() self.font_size = font.GetPointSize() self.font_style = font.GetStyle() self.font_weight = font.GetWeight() dlg.Destroy() post_command_event(self, self.DrawChartMsg)
python
def OnFont(self, event): """Check event handler""" font_data = wx.FontData() # Disable color chooser on Windows font_data.EnableEffects(False) if self.chosen_font: font_data.SetInitialFont(self.chosen_font) dlg = wx.FontDialog(self, font_data) if dlg.ShowModal() == wx.ID_OK: font_data = dlg.GetFontData() font = self.chosen_font = font_data.GetChosenFont() self.font_face = font.GetFaceName() self.font_size = font.GetPointSize() self.font_style = font.GetStyle() self.font_weight = font.GetWeight() dlg.Destroy() post_command_event(self, self.DrawChartMsg)
[ "def", "OnFont", "(", "self", ",", "event", ")", ":", "font_data", "=", "wx", ".", "FontData", "(", ")", "# Disable color chooser on Windows", "font_data", ".", "EnableEffects", "(", "False", ")", "if", "self", ".", "chosen_font", ":", "font_data", ".", "Set...
Check event handler
[ "Check", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L445-L470
train
231,427
manns/pyspread
pyspread/src/gui/_chart_dialog.py
TickParamsEditor.OnDirectionChoice
def OnDirectionChoice(self, event): """Direction choice event handler""" label = self.direction_choicectrl.GetItems()[event.GetSelection()] param = self.choice_label2param[label] self.attrs["direction"] = param post_command_event(self, self.DrawChartMsg)
python
def OnDirectionChoice(self, event): """Direction choice event handler""" label = self.direction_choicectrl.GetItems()[event.GetSelection()] param = self.choice_label2param[label] self.attrs["direction"] = param post_command_event(self, self.DrawChartMsg)
[ "def", "OnDirectionChoice", "(", "self", ",", "event", ")", ":", "label", "=", "self", ".", "direction_choicectrl", ".", "GetItems", "(", ")", "[", "event", ".", "GetSelection", "(", ")", "]", "param", "=", "self", ".", "choice_label2param", "[", "label", ...
Direction choice event handler
[ "Direction", "choice", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L630-L637
train
231,428
manns/pyspread
pyspread/src/gui/_chart_dialog.py
TickParamsEditor.OnSecondaryCheckbox
def OnSecondaryCheckbox(self, event): """Top Checkbox event handler""" self.attrs["top"] = event.IsChecked() self.attrs["right"] = event.IsChecked() post_command_event(self, self.DrawChartMsg)
python
def OnSecondaryCheckbox(self, event): """Top Checkbox event handler""" self.attrs["top"] = event.IsChecked() self.attrs["right"] = event.IsChecked() post_command_event(self, self.DrawChartMsg)
[ "def", "OnSecondaryCheckbox", "(", "self", ",", "event", ")", ":", "self", ".", "attrs", "[", "\"top\"", "]", "=", "event", ".", "IsChecked", "(", ")", "self", ".", "attrs", "[", "\"right\"", "]", "=", "event", ".", "IsChecked", "(", ")", "post_command...
Top Checkbox event handler
[ "Top", "Checkbox", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L639-L645
train
231,429
manns/pyspread
pyspread/src/gui/_chart_dialog.py
TickParamsEditor.OnPadIntCtrl
def OnPadIntCtrl(self, event): """Pad IntCtrl event handler""" self.attrs["pad"] = event.GetValue() post_command_event(self, self.DrawChartMsg)
python
def OnPadIntCtrl(self, event): """Pad IntCtrl event handler""" self.attrs["pad"] = event.GetValue() post_command_event(self, self.DrawChartMsg)
[ "def", "OnPadIntCtrl", "(", "self", ",", "event", ")", ":", "self", ".", "attrs", "[", "\"pad\"", "]", "=", "event", ".", "GetValue", "(", ")", "post_command_event", "(", "self", ",", "self", ".", "DrawChartMsg", ")" ]
Pad IntCtrl event handler
[ "Pad", "IntCtrl", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L647-L652
train
231,430
manns/pyspread
pyspread/src/gui/_chart_dialog.py
TickParamsEditor.OnLabelSizeIntCtrl
def OnLabelSizeIntCtrl(self, event): """Label size IntCtrl event handler""" self.attrs["labelsize"] = event.GetValue() post_command_event(self, self.DrawChartMsg)
python
def OnLabelSizeIntCtrl(self, event): """Label size IntCtrl event handler""" self.attrs["labelsize"] = event.GetValue() post_command_event(self, self.DrawChartMsg)
[ "def", "OnLabelSizeIntCtrl", "(", "self", ",", "event", ")", ":", "self", ".", "attrs", "[", "\"labelsize\"", "]", "=", "event", ".", "GetValue", "(", ")", "post_command_event", "(", "self", ",", "self", ".", "DrawChartMsg", ")" ]
Label size IntCtrl event handler
[ "Label", "size", "IntCtrl", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L654-L659
train
231,431
manns/pyspread
pyspread/src/gui/_chart_dialog.py
StyleEditorMixin.get_code
def get_code(self): """Returns code representation of value of widget""" selection = self.GetSelection() if selection == wx.NOT_FOUND: selection = 0 # Return code string return self.styles[selection][1]
python
def get_code(self): """Returns code representation of value of widget""" selection = self.GetSelection() if selection == wx.NOT_FOUND: selection = 0 # Return code string return self.styles[selection][1]
[ "def", "get_code", "(", "self", ")", ":", "selection", "=", "self", ".", "GetSelection", "(", ")", "if", "selection", "==", "wx", ".", "NOT_FOUND", ":", "selection", "=", "0", "# Return code string", "return", "self", ".", "styles", "[", "selection", "]", ...
Returns code representation of value of widget
[ "Returns", "code", "representation", "of", "value", "of", "widget" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L712-L721
train
231,432
manns/pyspread
pyspread/src/gui/_chart_dialog.py
SeriesAttributesPanelBase.update
def update(self, series_data): """Updates self.data from series data Parameters ---------- * series_data: dict \tKey value pairs for self.data, which correspond to chart attributes """ for key in series_data: try: data_list = list(self.data[key]) data_list[2] = str(series_data[key]) self.data[key] = tuple(data_list) except KeyError: pass
python
def update(self, series_data): """Updates self.data from series data Parameters ---------- * series_data: dict \tKey value pairs for self.data, which correspond to chart attributes """ for key in series_data: try: data_list = list(self.data[key]) data_list[2] = str(series_data[key]) self.data[key] = tuple(data_list) except KeyError: pass
[ "def", "update", "(", "self", ",", "series_data", ")", ":", "for", "key", "in", "series_data", ":", "try", ":", "data_list", "=", "list", "(", "self", ".", "data", "[", "key", "]", ")", "data_list", "[", "2", "]", "=", "str", "(", "series_data", "[...
Updates self.data from series data Parameters ---------- * series_data: dict \tKey value pairs for self.data, which correspond to chart attributes
[ "Updates", "self", ".", "data", "from", "series", "data" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L894-L910
train
231,433
manns/pyspread
pyspread/src/gui/_chart_dialog.py
SeriesPanel.get_plot_panel
def get_plot_panel(self): """Returns current plot_panel""" plot_type_no = self.chart_type_book.GetSelection() return self.chart_type_book.GetPage(plot_type_no)
python
def get_plot_panel(self): """Returns current plot_panel""" plot_type_no = self.chart_type_book.GetSelection() return self.chart_type_book.GetPage(plot_type_no)
[ "def", "get_plot_panel", "(", "self", ")", ":", "plot_type_no", "=", "self", ".", "chart_type_book", ".", "GetSelection", "(", ")", "return", "self", ".", "chart_type_book", ".", "GetPage", "(", "plot_type_no", ")" ]
Returns current plot_panel
[ "Returns", "current", "plot_panel" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1423-L1427
train
231,434
manns/pyspread
pyspread/src/gui/_chart_dialog.py
SeriesPanel.set_plot_type
def set_plot_type(self, plot_type): """Sets plot type""" ptypes = [pt["type"] for pt in self.plot_types] self.plot_panel = ptypes.index(plot_type)
python
def set_plot_type(self, plot_type): """Sets plot type""" ptypes = [pt["type"] for pt in self.plot_types] self.plot_panel = ptypes.index(plot_type)
[ "def", "set_plot_type", "(", "self", ",", "plot_type", ")", ":", "ptypes", "=", "[", "pt", "[", "\"type\"", "]", "for", "pt", "in", "self", ".", "plot_types", "]", "self", ".", "plot_panel", "=", "ptypes", ".", "index", "(", "plot_type", ")" ]
Sets plot type
[ "Sets", "plot", "type" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1441-L1445
train
231,435
manns/pyspread
pyspread/src/gui/_chart_dialog.py
AllSeriesPanel.update
def update(self, series_list): """Updates widget content from series_list Parameters ---------- series_list: List of dict \tList of dicts with data from all series """ if not series_list: self.series_notebook.AddPage(wx.Panel(self, -1), _("+")) return self.updating = True # Delete all tabs in the notebook self.series_notebook.DeleteAllPages() # Add as many tabs as there are series in code for page, attrdict in enumerate(series_list): series_panel = SeriesPanel(self.grid, attrdict) name = "Series" self.series_notebook.InsertPage(page, series_panel, name) self.series_notebook.AddPage(wx.Panel(self, -1), _("+")) self.updating = False
python
def update(self, series_list): """Updates widget content from series_list Parameters ---------- series_list: List of dict \tList of dicts with data from all series """ if not series_list: self.series_notebook.AddPage(wx.Panel(self, -1), _("+")) return self.updating = True # Delete all tabs in the notebook self.series_notebook.DeleteAllPages() # Add as many tabs as there are series in code for page, attrdict in enumerate(series_list): series_panel = SeriesPanel(self.grid, attrdict) name = "Series" self.series_notebook.InsertPage(page, series_panel, name) self.series_notebook.AddPage(wx.Panel(self, -1), _("+")) self.updating = False
[ "def", "update", "(", "self", ",", "series_list", ")", ":", "if", "not", "series_list", ":", "self", ".", "series_notebook", ".", "AddPage", "(", "wx", ".", "Panel", "(", "self", ",", "-", "1", ")", ",", "_", "(", "\"+\"", ")", ")", "return", "self...
Updates widget content from series_list Parameters ---------- series_list: List of dict \tList of dicts with data from all series
[ "Updates", "widget", "content", "from", "series_list" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1494-L1523
train
231,436
manns/pyspread
pyspread/src/gui/_chart_dialog.py
AllSeriesPanel.OnSeriesChanged
def OnSeriesChanged(self, event): """FlatNotebook change event handler""" selection = event.GetSelection() if not self.updating and \ selection == self.series_notebook.GetPageCount() - 1: # Add new series new_panel = SeriesPanel(self, {"type": "plot"}) self.series_notebook.InsertPage(selection, new_panel, _("Series")) event.Skip()
python
def OnSeriesChanged(self, event): """FlatNotebook change event handler""" selection = event.GetSelection() if not self.updating and \ selection == self.series_notebook.GetPageCount() - 1: # Add new series new_panel = SeriesPanel(self, {"type": "plot"}) self.series_notebook.InsertPage(selection, new_panel, _("Series")) event.Skip()
[ "def", "OnSeriesChanged", "(", "self", ",", "event", ")", ":", "selection", "=", "event", ".", "GetSelection", "(", ")", "if", "not", "self", ".", "updating", "and", "selection", "==", "self", ".", "series_notebook", ".", "GetPageCount", "(", ")", "-", "...
FlatNotebook change event handler
[ "FlatNotebook", "change", "event", "handler" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1528-L1539
train
231,437
manns/pyspread
pyspread/src/gui/_chart_dialog.py
FigurePanel.update
def update(self, figure): """Updates figure on data change Parameters ---------- * figure: matplotlib.figure.Figure \tMatplotlib figure object that is displayed in self """ if hasattr(self, "figure_canvas"): self.figure_canvas.Destroy() self.figure_canvas = self._get_figure_canvas(figure) self.figure_canvas.SetSize(self.GetSize()) figure.subplots_adjust() self.main_sizer.Add(self.figure_canvas, 1, wx.EXPAND | wx.FIXED_MINSIZE, 0) self.Layout() self.figure_canvas.draw()
python
def update(self, figure): """Updates figure on data change Parameters ---------- * figure: matplotlib.figure.Figure \tMatplotlib figure object that is displayed in self """ if hasattr(self, "figure_canvas"): self.figure_canvas.Destroy() self.figure_canvas = self._get_figure_canvas(figure) self.figure_canvas.SetSize(self.GetSize()) figure.subplots_adjust() self.main_sizer.Add(self.figure_canvas, 1, wx.EXPAND | wx.FIXED_MINSIZE, 0) self.Layout() self.figure_canvas.draw()
[ "def", "update", "(", "self", ",", "figure", ")", ":", "if", "hasattr", "(", "self", ",", "\"figure_canvas\"", ")", ":", "self", ".", "figure_canvas", ".", "Destroy", "(", ")", "self", ".", "figure_canvas", "=", "self", ".", "_get_figure_canvas", "(", "f...
Updates figure on data change Parameters ---------- * figure: matplotlib.figure.Figure \tMatplotlib figure object that is displayed in self
[ "Updates", "figure", "on", "data", "change" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1573-L1595
train
231,438
manns/pyspread
pyspread/src/gui/_chart_dialog.py
ChartDialog.get_figure
def get_figure(self, code): """Returns figure from executing code in grid Returns an empty matplotlib figure if code does not eval to a matplotlib figure instance. Parameters ---------- code: Unicode \tUnicode string which contains Python code that should yield a figure """ # Caching for fast response if there are no changes if code == self.figure_code_old and self.figure_cache: return self.figure_cache self.figure_code_old = code # key is the current cursor cell of the grid key = self.grid.actions.cursor cell_result = self.grid.code_array._eval_cell(key, code) # If cell_result is matplotlib figure if isinstance(cell_result, matplotlib.pyplot.Figure): # Return it self.figure_cache = cell_result return cell_result else: # Otherwise return empty figure self.figure_cache = charts.ChartFigure() return self.figure_cache
python
def get_figure(self, code): """Returns figure from executing code in grid Returns an empty matplotlib figure if code does not eval to a matplotlib figure instance. Parameters ---------- code: Unicode \tUnicode string which contains Python code that should yield a figure """ # Caching for fast response if there are no changes if code == self.figure_code_old and self.figure_cache: return self.figure_cache self.figure_code_old = code # key is the current cursor cell of the grid key = self.grid.actions.cursor cell_result = self.grid.code_array._eval_cell(key, code) # If cell_result is matplotlib figure if isinstance(cell_result, matplotlib.pyplot.Figure): # Return it self.figure_cache = cell_result return cell_result else: # Otherwise return empty figure self.figure_cache = charts.ChartFigure() return self.figure_cache
[ "def", "get_figure", "(", "self", ",", "code", ")", ":", "# Caching for fast response if there are no changes", "if", "code", "==", "self", ".", "figure_code_old", "and", "self", ".", "figure_cache", ":", "return", "self", ".", "figure_cache", "self", ".", "figure...
Returns figure from executing code in grid Returns an empty matplotlib figure if code does not eval to a matplotlib figure instance. Parameters ---------- code: Unicode \tUnicode string which contains Python code that should yield a figure
[ "Returns", "figure", "from", "executing", "code", "in", "grid" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1668-L1701
train
231,439
manns/pyspread
pyspread/src/gui/_chart_dialog.py
ChartDialog.set_code
def set_code(self, code): """Update widgets from code""" # Get attributes from code attributes = [] strip = lambda s: s.strip('u').strip("'").strip('"') for attr_dict in parse_dict_strings(unicode(code).strip()[19:-1]): attrs = list(strip(s) for s in parse_dict_strings(attr_dict[1:-1])) attributes.append(dict(zip(attrs[::2], attrs[1::2]))) if not attributes: return # Set widgets from attributes # --------------------------- # Figure attributes figure_attributes = attributes[0] for key, widget in self.figure_attributes_panel: try: obj = figure_attributes[key] kwargs_key = key + "_kwargs" if kwargs_key in figure_attributes: widget.set_kwargs(figure_attributes[kwargs_key]) except KeyError: obj = "" widget.code = charts.object2code(key, obj) # Series attributes self.all_series_panel.update(attributes[1:])
python
def set_code(self, code): """Update widgets from code""" # Get attributes from code attributes = [] strip = lambda s: s.strip('u').strip("'").strip('"') for attr_dict in parse_dict_strings(unicode(code).strip()[19:-1]): attrs = list(strip(s) for s in parse_dict_strings(attr_dict[1:-1])) attributes.append(dict(zip(attrs[::2], attrs[1::2]))) if not attributes: return # Set widgets from attributes # --------------------------- # Figure attributes figure_attributes = attributes[0] for key, widget in self.figure_attributes_panel: try: obj = figure_attributes[key] kwargs_key = key + "_kwargs" if kwargs_key in figure_attributes: widget.set_kwargs(figure_attributes[kwargs_key]) except KeyError: obj = "" widget.code = charts.object2code(key, obj) # Series attributes self.all_series_panel.update(attributes[1:])
[ "def", "set_code", "(", "self", ",", "code", ")", ":", "# Get attributes from code", "attributes", "=", "[", "]", "strip", "=", "lambda", "s", ":", "s", ".", "strip", "(", "'u'", ")", ".", "strip", "(", "\"'\"", ")", ".", "strip", "(", "'\"'", ")", ...
Update widgets from code
[ "Update", "widgets", "from", "code" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1718-L1751
train
231,440
manns/pyspread
pyspread/src/gui/_chart_dialog.py
ChartDialog.get_code
def get_code(self): """Returns code that generates figure from widgets""" def dict2str(attr_dict): """Returns string with dict content with values as code Code means that string identifiers are removed """ result = u"{" for key in attr_dict: code = attr_dict[key] if key in self.string_keys: code = repr(code) elif code and key in self.tuple_keys and \ not (code[0] in ["[", "("] and code[-1] in ["]", ")"]): code = "(" + code + ")" elif key in ["xscale", "yscale"]: if code: code = '"log"' else: code = '"linear"' elif key in ["legend"]: if code: code = '1' else: code = '0' elif key in ["xtick_params"]: code = '"x"' elif key in ["ytick_params"]: code = '"y"' if not code: if key in self.empty_none_keys: code = "None" else: code = 'u""' result += repr(key) + ": " + code + ", " result = result[:-2] + u"}" return result # cls_name inludes full class name incl. charts cls_name = "charts." + charts.ChartFigure.__name__ attr_dicts = [] # Figure attributes attr_dict = {} # figure_attributes is a dict key2code for key, widget in self.figure_attributes_panel: if key == "type": attr_dict[key] = widget else: attr_dict[key] = widget.code try: attr_dict[key+"_kwargs"] = widget.get_kwargs() except AttributeError: pass attr_dicts.append(attr_dict) # Series_attributes is a list of dicts key2code for series_panel in self.all_series_panel: attr_dict = {} for key, widget in series_panel: if key == "type": attr_dict[key] = widget else: attr_dict[key] = widget.code attr_dicts.append(attr_dict) code = cls_name + "(" for attr_dict in attr_dicts: code += dict2str(attr_dict) + ", " code = code[:-2] + ")" return code
python
def get_code(self): """Returns code that generates figure from widgets""" def dict2str(attr_dict): """Returns string with dict content with values as code Code means that string identifiers are removed """ result = u"{" for key in attr_dict: code = attr_dict[key] if key in self.string_keys: code = repr(code) elif code and key in self.tuple_keys and \ not (code[0] in ["[", "("] and code[-1] in ["]", ")"]): code = "(" + code + ")" elif key in ["xscale", "yscale"]: if code: code = '"log"' else: code = '"linear"' elif key in ["legend"]: if code: code = '1' else: code = '0' elif key in ["xtick_params"]: code = '"x"' elif key in ["ytick_params"]: code = '"y"' if not code: if key in self.empty_none_keys: code = "None" else: code = 'u""' result += repr(key) + ": " + code + ", " result = result[:-2] + u"}" return result # cls_name inludes full class name incl. charts cls_name = "charts." + charts.ChartFigure.__name__ attr_dicts = [] # Figure attributes attr_dict = {} # figure_attributes is a dict key2code for key, widget in self.figure_attributes_panel: if key == "type": attr_dict[key] = widget else: attr_dict[key] = widget.code try: attr_dict[key+"_kwargs"] = widget.get_kwargs() except AttributeError: pass attr_dicts.append(attr_dict) # Series_attributes is a list of dicts key2code for series_panel in self.all_series_panel: attr_dict = {} for key, widget in series_panel: if key == "type": attr_dict[key] = widget else: attr_dict[key] = widget.code attr_dicts.append(attr_dict) code = cls_name + "(" for attr_dict in attr_dicts: code += dict2str(attr_dict) + ", " code = code[:-2] + ")" return code
[ "def", "get_code", "(", "self", ")", ":", "def", "dict2str", "(", "attr_dict", ")", ":", "\"\"\"Returns string with dict content with values as code\n\n Code means that string identifiers are removed\n\n \"\"\"", "result", "=", "u\"{\"", "for", "key", "in", ...
Returns code that generates figure from widgets
[ "Returns", "code", "that", "generates", "figure", "from", "widgets" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1753-L1844
train
231,441
manns/pyspread
pyspread/src/gui/_chart_dialog.py
ChartDialog.OnUpdateFigurePanel
def OnUpdateFigurePanel(self, event): """Redraw event handler for the figure panel""" if self.updating: return self.updating = True self.figure_panel.update(self.get_figure(self.code)) self.updating = False
python
def OnUpdateFigurePanel(self, event): """Redraw event handler for the figure panel""" if self.updating: return self.updating = True self.figure_panel.update(self.get_figure(self.code)) self.updating = False
[ "def", "OnUpdateFigurePanel", "(", "self", ",", "event", ")", ":", "if", "self", ".", "updating", ":", "return", "self", ".", "updating", "=", "True", "self", ".", "figure_panel", ".", "update", "(", "self", ".", "get_figure", "(", "self", ".", "code", ...
Redraw event handler for the figure panel
[ "Redraw", "event", "handler", "for", "the", "figure", "panel" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_chart_dialog.py#L1854-L1862
train
231,442
manns/pyspread
pyspread/src/lib/selection.py
Selection.parameters
def parameters(self): """Returns tuple of selection parameters of self (self.block_tl, self.block_br, self.rows, self.cols, self.cells) """ return self.block_tl, self.block_br, self.rows, self.cols, self.cells
python
def parameters(self): """Returns tuple of selection parameters of self (self.block_tl, self.block_br, self.rows, self.cols, self.cells) """ return self.block_tl, self.block_br, self.rows, self.cols, self.cells
[ "def", "parameters", "(", "self", ")", ":", "return", "self", ".", "block_tl", ",", "self", ".", "block_br", ",", "self", ".", "rows", ",", "self", ".", "cols", ",", "self", ".", "cells" ]
Returns tuple of selection parameters of self (self.block_tl, self.block_br, self.rows, self.cols, self.cells)
[ "Returns", "tuple", "of", "selection", "parameters", "of", "self" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/selection.py#L245-L252
train
231,443
manns/pyspread
pyspread/src/lib/selection.py
Selection.get_access_string
def get_access_string(self, shape, table): """Returns a string, with which the selection can be accessed Parameters ---------- shape: 3-tuple of Integer \tShape of grid, for which the generated keys are valid table: Integer \tThird component of all returned keys. Must be in dimensions """ rows, columns, tables = shape # Negative dimensions cannot be assert all(dim > 0 for dim in shape) # Current table has to be in dimensions assert 0 <= table < tables string_list = [] # Block selections templ = "[(r, c, {}) for r in xrange({}, {}) for c in xrange({}, {})]" for (top, left), (bottom, right) in izip(self.block_tl, self.block_br): string_list += [templ.format(table, top, bottom + 1, left, right + 1)] # Fully selected rows template = "[({}, c, {}) for c in xrange({})]" for row in self.rows: string_list += [template.format(row, table, columns)] # Fully selected columns template = "[(r, {}, {}) for r in xrange({})]" for column in self.cols: string_list += [template.format(column, table, rows)] # Single cells for row, column in self.cells: string_list += [repr([(row, column, table)])] key_string = " + ".join(string_list) if len(string_list) == 0: return "" elif len(self.cells) == 1 and len(string_list) == 1: return "S[{}]".format(string_list[0][1:-1]) else: template = "[S[key] for key in {} if S[key] is not None]" return template.format(key_string)
python
def get_access_string(self, shape, table): """Returns a string, with which the selection can be accessed Parameters ---------- shape: 3-tuple of Integer \tShape of grid, for which the generated keys are valid table: Integer \tThird component of all returned keys. Must be in dimensions """ rows, columns, tables = shape # Negative dimensions cannot be assert all(dim > 0 for dim in shape) # Current table has to be in dimensions assert 0 <= table < tables string_list = [] # Block selections templ = "[(r, c, {}) for r in xrange({}, {}) for c in xrange({}, {})]" for (top, left), (bottom, right) in izip(self.block_tl, self.block_br): string_list += [templ.format(table, top, bottom + 1, left, right + 1)] # Fully selected rows template = "[({}, c, {}) for c in xrange({})]" for row in self.rows: string_list += [template.format(row, table, columns)] # Fully selected columns template = "[(r, {}, {}) for r in xrange({})]" for column in self.cols: string_list += [template.format(column, table, rows)] # Single cells for row, column in self.cells: string_list += [repr([(row, column, table)])] key_string = " + ".join(string_list) if len(string_list) == 0: return "" elif len(self.cells) == 1 and len(string_list) == 1: return "S[{}]".format(string_list[0][1:-1]) else: template = "[S[key] for key in {} if S[key] is not None]" return template.format(key_string)
[ "def", "get_access_string", "(", "self", ",", "shape", ",", "table", ")", ":", "rows", ",", "columns", ",", "tables", "=", "shape", "# Negative dimensions cannot be", "assert", "all", "(", "dim", ">", "0", "for", "dim", "in", "shape", ")", "# Current table h...
Returns a string, with which the selection can be accessed Parameters ---------- shape: 3-tuple of Integer \tShape of grid, for which the generated keys are valid table: Integer \tThird component of all returned keys. Must be in dimensions
[ "Returns", "a", "string", "with", "which", "the", "selection", "can", "be", "accessed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/selection.py#L381-L433
train
231,444
manns/pyspread
pyspread/src/lib/selection.py
Selection.shifted
def shifted(self, rows, cols): """Returns a new selection that is shifted by rows and cols. Negative values for rows and cols may result in a selection that addresses negative cells. Parameters ---------- rows: Integer \tNumber of rows that the new selection is shifted down cols: Integer \tNumber of columns that the new selection is shifted right """ shifted_block_tl = \ [(row + rows, col + cols) for row, col in self.block_tl] shifted_block_br = \ [(row + rows, col + cols) for row, col in self.block_br] shifted_rows = [row + rows for row in self.rows] shifted_cols = [col + cols for col in self.cols] shifted_cells = [(row + rows, col + cols) for row, col in self.cells] return Selection(shifted_block_tl, shifted_block_br, shifted_rows, shifted_cols, shifted_cells)
python
def shifted(self, rows, cols): """Returns a new selection that is shifted by rows and cols. Negative values for rows and cols may result in a selection that addresses negative cells. Parameters ---------- rows: Integer \tNumber of rows that the new selection is shifted down cols: Integer \tNumber of columns that the new selection is shifted right """ shifted_block_tl = \ [(row + rows, col + cols) for row, col in self.block_tl] shifted_block_br = \ [(row + rows, col + cols) for row, col in self.block_br] shifted_rows = [row + rows for row in self.rows] shifted_cols = [col + cols for col in self.cols] shifted_cells = [(row + rows, col + cols) for row, col in self.cells] return Selection(shifted_block_tl, shifted_block_br, shifted_rows, shifted_cols, shifted_cells)
[ "def", "shifted", "(", "self", ",", "rows", ",", "cols", ")", ":", "shifted_block_tl", "=", "[", "(", "row", "+", "rows", ",", "col", "+", "cols", ")", "for", "row", ",", "col", "in", "self", ".", "block_tl", "]", "shifted_block_br", "=", "[", "(",...
Returns a new selection that is shifted by rows and cols. Negative values for rows and cols may result in a selection that addresses negative cells. Parameters ---------- rows: Integer \tNumber of rows that the new selection is shifted down cols: Integer \tNumber of columns that the new selection is shifted right
[ "Returns", "a", "new", "selection", "that", "is", "shifted", "by", "rows", "and", "cols", "." ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/selection.py#L435-L459
train
231,445
manns/pyspread
pyspread/src/lib/selection.py
Selection.grid_select
def grid_select(self, grid, clear_selection=True): """Selects cells of grid with selection content""" if clear_selection: grid.ClearSelection() for (tl, br) in zip(self.block_tl, self.block_br): grid.SelectBlock(tl[0], tl[1], br[0], br[1], addToSelected=True) for row in self.rows: grid.SelectRow(row, addToSelected=True) for col in self.cols: grid.SelectCol(col, addToSelected=True) for cell in self.cells: grid.SelectBlock(cell[0], cell[1], cell[0], cell[1], addToSelected=True)
python
def grid_select(self, grid, clear_selection=True): """Selects cells of grid with selection content""" if clear_selection: grid.ClearSelection() for (tl, br) in zip(self.block_tl, self.block_br): grid.SelectBlock(tl[0], tl[1], br[0], br[1], addToSelected=True) for row in self.rows: grid.SelectRow(row, addToSelected=True) for col in self.cols: grid.SelectCol(col, addToSelected=True) for cell in self.cells: grid.SelectBlock(cell[0], cell[1], cell[0], cell[1], addToSelected=True)
[ "def", "grid_select", "(", "self", ",", "grid", ",", "clear_selection", "=", "True", ")", ":", "if", "clear_selection", ":", "grid", ".", "ClearSelection", "(", ")", "for", "(", "tl", ",", "br", ")", "in", "zip", "(", "self", ".", "block_tl", ",", "s...
Selects cells of grid with selection content
[ "Selects", "cells", "of", "grid", "with", "selection", "content" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/selection.py#L461-L478
train
231,446
manns/pyspread
pyspread/src/lib/charts.py
object2code
def object2code(key, code): """Returns code for widget from dict object""" if key in ["xscale", "yscale"]: if code == "log": code = True else: code = False else: code = unicode(code) return code
python
def object2code(key, code): """Returns code for widget from dict object""" if key in ["xscale", "yscale"]: if code == "log": code = True else: code = False else: code = unicode(code) return code
[ "def", "object2code", "(", "key", ",", "code", ")", ":", "if", "key", "in", "[", "\"xscale\"", ",", "\"yscale\"", "]", ":", "if", "code", "==", "\"log\"", ":", "code", "=", "True", "else", ":", "code", "=", "False", "else", ":", "code", "=", "unico...
Returns code for widget from dict object
[ "Returns", "code", "for", "widget", "from", "dict", "object" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/charts.py#L56-L68
train
231,447
manns/pyspread
pyspread/src/lib/charts.py
fig2bmp
def fig2bmp(figure, width, height, dpi, zoom): """Returns wx.Bitmap from matplotlib chart Parameters ---------- fig: Object \tMatplotlib figure width: Integer \tImage width in pixels height: Integer \tImage height in pixels dpi = Float \tDC resolution """ dpi *= float(zoom) figure.set_figwidth(width / dpi) figure.set_figheight(height / dpi) figure.subplots_adjust() with warnings.catch_warnings(): warnings.simplefilter("ignore") try: # The padding is too small for small sizes. This fixes it. figure.tight_layout(pad=1.0/zoom) except ValueError: pass figure.set_canvas(FigureCanvas(figure)) png_stream = StringIO() figure.savefig(png_stream, format='png', dpi=(dpi)) png_stream.seek(0) img = wx.ImageFromStream(png_stream, type=wx.BITMAP_TYPE_PNG) return wx.BitmapFromImage(img)
python
def fig2bmp(figure, width, height, dpi, zoom): """Returns wx.Bitmap from matplotlib chart Parameters ---------- fig: Object \tMatplotlib figure width: Integer \tImage width in pixels height: Integer \tImage height in pixels dpi = Float \tDC resolution """ dpi *= float(zoom) figure.set_figwidth(width / dpi) figure.set_figheight(height / dpi) figure.subplots_adjust() with warnings.catch_warnings(): warnings.simplefilter("ignore") try: # The padding is too small for small sizes. This fixes it. figure.tight_layout(pad=1.0/zoom) except ValueError: pass figure.set_canvas(FigureCanvas(figure)) png_stream = StringIO() figure.savefig(png_stream, format='png', dpi=(dpi)) png_stream.seek(0) img = wx.ImageFromStream(png_stream, type=wx.BITMAP_TYPE_PNG) return wx.BitmapFromImage(img)
[ "def", "fig2bmp", "(", "figure", ",", "width", ",", "height", ",", "dpi", ",", "zoom", ")", ":", "dpi", "*=", "float", "(", "zoom", ")", "figure", ".", "set_figwidth", "(", "width", "/", "dpi", ")", "figure", ".", "set_figheight", "(", "height", "/",...
Returns wx.Bitmap from matplotlib chart Parameters ---------- fig: Object \tMatplotlib figure width: Integer \tImage width in pixels height: Integer \tImage height in pixels dpi = Float \tDC resolution
[ "Returns", "wx", ".", "Bitmap", "from", "matplotlib", "chart" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/charts.py#L71-L110
train
231,448
manns/pyspread
pyspread/src/lib/charts.py
fig2x
def fig2x(figure, format): """Returns svg from matplotlib chart""" # Save svg to file like object svg_io io = StringIO() figure.savefig(io, format=format) # Rewind the file like object io.seek(0) data = io.getvalue() io.close() return data
python
def fig2x(figure, format): """Returns svg from matplotlib chart""" # Save svg to file like object svg_io io = StringIO() figure.savefig(io, format=format) # Rewind the file like object io.seek(0) data = io.getvalue() io.close() return data
[ "def", "fig2x", "(", "figure", ",", "format", ")", ":", "# Save svg to file like object svg_io", "io", "=", "StringIO", "(", ")", "figure", ".", "savefig", "(", "io", ",", "format", "=", "format", ")", "# Rewind the file like object", "io", ".", "seek", "(", ...
Returns svg from matplotlib chart
[ "Returns", "svg", "from", "matplotlib", "chart" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/charts.py#L113-L126
train
231,449
manns/pyspread
pyspread/src/lib/charts.py
ChartFigure._xdate_setter
def _xdate_setter(self, xdate_format='%Y-%m-%d'): """Makes x axis a date axis with auto format Parameters ---------- xdate_format: String \tSets date formatting """ if xdate_format: # We have to validate xdate_format. If wrong then bail out. try: self.autofmt_xdate() datetime.date(2000, 1, 1).strftime(xdate_format) except ValueError: self.autofmt_xdate() return self.__axes.xaxis_date() formatter = dates.DateFormatter(xdate_format) self.__axes.xaxis.set_major_formatter(formatter)
python
def _xdate_setter(self, xdate_format='%Y-%m-%d'): """Makes x axis a date axis with auto format Parameters ---------- xdate_format: String \tSets date formatting """ if xdate_format: # We have to validate xdate_format. If wrong then bail out. try: self.autofmt_xdate() datetime.date(2000, 1, 1).strftime(xdate_format) except ValueError: self.autofmt_xdate() return self.__axes.xaxis_date() formatter = dates.DateFormatter(xdate_format) self.__axes.xaxis.set_major_formatter(formatter)
[ "def", "_xdate_setter", "(", "self", ",", "xdate_format", "=", "'%Y-%m-%d'", ")", ":", "if", "xdate_format", ":", "# We have to validate xdate_format. If wrong then bail out.", "try", ":", "self", ".", "autofmt_xdate", "(", ")", "datetime", ".", "date", "(", "2000",...
Makes x axis a date axis with auto format Parameters ---------- xdate_format: String \tSets date formatting
[ "Makes", "x", "axis", "a", "date", "axis", "with", "auto", "format" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/charts.py#L180-L203
train
231,450
manns/pyspread
pyspread/src/lib/charts.py
ChartFigure._setup_axes
def _setup_axes(self, axes_data): """Sets up axes for drawing chart""" self.__axes.clear() key_setter = [ ("title", self.__axes.set_title), ("xlabel", self.__axes.set_xlabel), ("ylabel", self.__axes.set_ylabel), ("xscale", self.__axes.set_xscale), ("yscale", self.__axes.set_yscale), ("xticks", self.__axes.set_xticks), ("xtick_labels", self.__axes.set_xticklabels), ("xtick_params", self.__axes.tick_params), ("yticks", self.__axes.set_yticks), ("ytick_labels", self.__axes.set_yticklabels), ("ytick_params", self.__axes.tick_params), ("xlim", self.__axes.set_xlim), ("ylim", self.__axes.set_ylim), ("xgrid", self.__axes.xaxis.grid), ("ygrid", self.__axes.yaxis.grid), ("xdate_format", self._xdate_setter), ] key2setter = OrderedDict(key_setter) for key in key2setter: if key in axes_data and axes_data[key]: try: kwargs_key = key + "_kwargs" kwargs = axes_data[kwargs_key] except KeyError: kwargs = {} if key == "title": # Shift title up kwargs["y"] = 1.08 key2setter[key](axes_data[key], **kwargs)
python
def _setup_axes(self, axes_data): """Sets up axes for drawing chart""" self.__axes.clear() key_setter = [ ("title", self.__axes.set_title), ("xlabel", self.__axes.set_xlabel), ("ylabel", self.__axes.set_ylabel), ("xscale", self.__axes.set_xscale), ("yscale", self.__axes.set_yscale), ("xticks", self.__axes.set_xticks), ("xtick_labels", self.__axes.set_xticklabels), ("xtick_params", self.__axes.tick_params), ("yticks", self.__axes.set_yticks), ("ytick_labels", self.__axes.set_yticklabels), ("ytick_params", self.__axes.tick_params), ("xlim", self.__axes.set_xlim), ("ylim", self.__axes.set_ylim), ("xgrid", self.__axes.xaxis.grid), ("ygrid", self.__axes.yaxis.grid), ("xdate_format", self._xdate_setter), ] key2setter = OrderedDict(key_setter) for key in key2setter: if key in axes_data and axes_data[key]: try: kwargs_key = key + "_kwargs" kwargs = axes_data[kwargs_key] except KeyError: kwargs = {} if key == "title": # Shift title up kwargs["y"] = 1.08 key2setter[key](axes_data[key], **kwargs)
[ "def", "_setup_axes", "(", "self", ",", "axes_data", ")", ":", "self", ".", "__axes", ".", "clear", "(", ")", "key_setter", "=", "[", "(", "\"title\"", ",", "self", ".", "__axes", ".", "set_title", ")", ",", "(", "\"xlabel\"", ",", "self", ".", "__ax...
Sets up axes for drawing chart
[ "Sets", "up", "axes", "for", "drawing", "chart" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/charts.py#L208-L247
train
231,451
manns/pyspread
pyspread/src/lib/charts.py
ChartFigure.draw_chart
def draw_chart(self): """Plots chart from self.attributes""" if not hasattr(self, "attributes"): return # The first element is always axes data self._setup_axes(self.attributes[0]) for attribute in self.attributes[1:]: series = copy(attribute) # Extract chart type chart_type_string = series.pop("type") x_str, y_str = self.plot_type_xy_mapping[chart_type_string] # Check xdata length if x_str in series and \ len(series[x_str]) != len(series[y_str]): # Wrong length --> ignore xdata series[x_str] = range(len(series[y_str])) else: # Solve the problem that the series data may contain utf-8 data series_list = list(series[x_str]) series_unicode_list = [] for ele in series_list: if isinstance(ele, types.StringType): try: series_unicode_list.append(ele.decode('utf-8')) except Exception: series_unicode_list.append(ele) else: series_unicode_list.append(ele) series[x_str] = tuple(series_unicode_list) fixed_attrs = [] if chart_type_string in self.plot_type_fixed_attrs: for attr in self.plot_type_fixed_attrs[chart_type_string]: # Remove attr if it is a fixed (non-kwd) attr # If a fixed attr is missing, insert a dummy try: fixed_attrs.append(tuple(series.pop(attr))) except KeyError: fixed_attrs.append(()) # Remove contour chart label info from series cl_attrs = {} for contour_label_attr in self.contour_label_attrs: if contour_label_attr in series: cl_attrs[self.contour_label_attrs[contour_label_attr]] = \ series.pop(contour_label_attr) # Remove contourf attributes from series cf_attrs = {} for contourf_attr in self.contourf_attrs: if contourf_attr in series: cf_attrs[self.contourf_attrs[contourf_attr]] = \ series.pop(contourf_attr) if not fixed_attrs or all(fixed_attrs): # Draw series to axes # Do we have a Sankey plot --> build it if chart_type_string == "Sankey": Sankey(self.__axes, **series).finish() else: chart_method = getattr(self.__axes, chart_type_string) plot = chart_method(*fixed_attrs, **series) # Do we have a filled contour? try: if cf_attrs.pop("contour_fill"): cf_attrs.update(series) if "linewidths" in cf_attrs: cf_attrs.pop("linewidths") if "linestyles" in cf_attrs: cf_attrs.pop("linestyles") if not cf_attrs["hatches"]: cf_attrs.pop("hatches") self.__axes.contourf(plot, **cf_attrs) except KeyError: pass # Do we have a contour chart label? try: if cl_attrs.pop("contour_labels"): self.__axes.clabel(plot, **cl_attrs) except KeyError: pass # The legend has to be set up after all series are drawn self._setup_legend(self.attributes[0])
python
def draw_chart(self): """Plots chart from self.attributes""" if not hasattr(self, "attributes"): return # The first element is always axes data self._setup_axes(self.attributes[0]) for attribute in self.attributes[1:]: series = copy(attribute) # Extract chart type chart_type_string = series.pop("type") x_str, y_str = self.plot_type_xy_mapping[chart_type_string] # Check xdata length if x_str in series and \ len(series[x_str]) != len(series[y_str]): # Wrong length --> ignore xdata series[x_str] = range(len(series[y_str])) else: # Solve the problem that the series data may contain utf-8 data series_list = list(series[x_str]) series_unicode_list = [] for ele in series_list: if isinstance(ele, types.StringType): try: series_unicode_list.append(ele.decode('utf-8')) except Exception: series_unicode_list.append(ele) else: series_unicode_list.append(ele) series[x_str] = tuple(series_unicode_list) fixed_attrs = [] if chart_type_string in self.plot_type_fixed_attrs: for attr in self.plot_type_fixed_attrs[chart_type_string]: # Remove attr if it is a fixed (non-kwd) attr # If a fixed attr is missing, insert a dummy try: fixed_attrs.append(tuple(series.pop(attr))) except KeyError: fixed_attrs.append(()) # Remove contour chart label info from series cl_attrs = {} for contour_label_attr in self.contour_label_attrs: if contour_label_attr in series: cl_attrs[self.contour_label_attrs[contour_label_attr]] = \ series.pop(contour_label_attr) # Remove contourf attributes from series cf_attrs = {} for contourf_attr in self.contourf_attrs: if contourf_attr in series: cf_attrs[self.contourf_attrs[contourf_attr]] = \ series.pop(contourf_attr) if not fixed_attrs or all(fixed_attrs): # Draw series to axes # Do we have a Sankey plot --> build it if chart_type_string == "Sankey": Sankey(self.__axes, **series).finish() else: chart_method = getattr(self.__axes, chart_type_string) plot = chart_method(*fixed_attrs, **series) # Do we have a filled contour? try: if cf_attrs.pop("contour_fill"): cf_attrs.update(series) if "linewidths" in cf_attrs: cf_attrs.pop("linewidths") if "linestyles" in cf_attrs: cf_attrs.pop("linestyles") if not cf_attrs["hatches"]: cf_attrs.pop("hatches") self.__axes.contourf(plot, **cf_attrs) except KeyError: pass # Do we have a contour chart label? try: if cl_attrs.pop("contour_labels"): self.__axes.clabel(plot, **cl_attrs) except KeyError: pass # The legend has to be set up after all series are drawn self._setup_legend(self.attributes[0])
[ "def", "draw_chart", "(", "self", ")", ":", "if", "not", "hasattr", "(", "self", ",", "\"attributes\"", ")", ":", "return", "# The first element is always axes data", "self", ".", "_setup_axes", "(", "self", ".", "attributes", "[", "0", "]", ")", "for", "att...
Plots chart from self.attributes
[ "Plots", "chart", "from", "self", ".", "attributes" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/charts.py#L255-L347
train
231,452
manns/pyspread
pyspread/src/gui/_grid_table.py
GridTable.GetSource
def GetSource(self, row, col, table=None): """Return the source string of a cell""" if table is None: table = self.grid.current_table value = self.code_array((row, col, table)) if value is None: return u"" else: return value
python
def GetSource(self, row, col, table=None): """Return the source string of a cell""" if table is None: table = self.grid.current_table value = self.code_array((row, col, table)) if value is None: return u"" else: return value
[ "def", "GetSource", "(", "self", ",", "row", ",", "col", ",", "table", "=", "None", ")", ":", "if", "table", "is", "None", ":", "table", "=", "self", ".", "grid", ".", "current_table", "value", "=", "self", ".", "code_array", "(", "(", "row", ",", ...
Return the source string of a cell
[ "Return", "the", "source", "string", "of", "a", "cell" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_table.py#L69-L80
train
231,453
manns/pyspread
pyspread/src/gui/_grid_table.py
GridTable.GetValue
def GetValue(self, row, col, table=None): """Return the result value of a cell, line split if too much data""" if table is None: table = self.grid.current_table try: cell_code = self.code_array((row, col, table)) except IndexError: cell_code = None # Put EOLs into result if it is too long maxlength = int(config["max_textctrl_length"]) if cell_code is not None and len(cell_code) > maxlength: chunk = 80 cell_code = "\n".join(cell_code[i:i + chunk] for i in xrange(0, len(cell_code), chunk)) return cell_code
python
def GetValue(self, row, col, table=None): """Return the result value of a cell, line split if too much data""" if table is None: table = self.grid.current_table try: cell_code = self.code_array((row, col, table)) except IndexError: cell_code = None # Put EOLs into result if it is too long maxlength = int(config["max_textctrl_length"]) if cell_code is not None and len(cell_code) > maxlength: chunk = 80 cell_code = "\n".join(cell_code[i:i + chunk] for i in xrange(0, len(cell_code), chunk)) return cell_code
[ "def", "GetValue", "(", "self", ",", "row", ",", "col", ",", "table", "=", "None", ")", ":", "if", "table", "is", "None", ":", "table", "=", "self", ".", "grid", ".", "current_table", "try", ":", "cell_code", "=", "self", ".", "code_array", "(", "(...
Return the result value of a cell, line split if too much data
[ "Return", "the", "result", "value", "of", "a", "cell", "line", "split", "if", "too", "much", "data" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_table.py#L82-L101
train
231,454
manns/pyspread
pyspread/src/gui/_grid_table.py
GridTable.SetValue
def SetValue(self, row, col, value, refresh=True): """Set the value of a cell, merge line breaks""" # Join code that has been split because of long line issue value = "".join(value.split("\n")) key = row, col, self.grid.current_table old_code = self.grid.code_array(key) if old_code is None: old_code = "" if value != old_code: self.grid.actions.set_code(key, value)
python
def SetValue(self, row, col, value, refresh=True): """Set the value of a cell, merge line breaks""" # Join code that has been split because of long line issue value = "".join(value.split("\n")) key = row, col, self.grid.current_table old_code = self.grid.code_array(key) if old_code is None: old_code = "" if value != old_code: self.grid.actions.set_code(key, value)
[ "def", "SetValue", "(", "self", ",", "row", ",", "col", ",", "value", ",", "refresh", "=", "True", ")", ":", "# Join code that has been split because of long line issue", "value", "=", "\"\"", ".", "join", "(", "value", ".", "split", "(", "\"\\n\"", ")", ")"...
Set the value of a cell, merge line breaks
[ "Set", "the", "value", "of", "a", "cell", "merge", "line", "breaks" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_table.py#L103-L116
train
231,455
manns/pyspread
pyspread/src/gui/_grid_table.py
GridTable.UpdateValues
def UpdateValues(self): """Update all displayed values""" # This sends an event to the grid table # to update all of the values msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) self.grid.ProcessTableMessage(msg)
python
def UpdateValues(self): """Update all displayed values""" # This sends an event to the grid table # to update all of the values msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) self.grid.ProcessTableMessage(msg)
[ "def", "UpdateValues", "(", "self", ")", ":", "# This sends an event to the grid table", "# to update all of the values", "msg", "=", "wx", ".", "grid", ".", "GridTableMessage", "(", "self", ",", "wx", ".", "grid", ".", "GRIDTABLE_REQUEST_VIEW_GET_VALUES", ")", "self"...
Update all displayed values
[ "Update", "all", "displayed", "values" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_table.py#L118-L126
train
231,456
manns/pyspread
pyspread/src/gui/_events.py
post_command_event
def post_command_event(target, msg_cls, **kwargs): """Posts command event to main window Command events propagate. Parameters ---------- * msg_cls: class \tMessage class from new_command_event() * kwargs: dict \tMessage arguments """ msg = msg_cls(id=-1, **kwargs) wx.PostEvent(target, msg)
python
def post_command_event(target, msg_cls, **kwargs): """Posts command event to main window Command events propagate. Parameters ---------- * msg_cls: class \tMessage class from new_command_event() * kwargs: dict \tMessage arguments """ msg = msg_cls(id=-1, **kwargs) wx.PostEvent(target, msg)
[ "def", "post_command_event", "(", "target", ",", "msg_cls", ",", "*", "*", "kwargs", ")", ":", "msg", "=", "msg_cls", "(", "id", "=", "-", "1", ",", "*", "*", "kwargs", ")", "wx", ".", "PostEvent", "(", "target", ",", "msg", ")" ]
Posts command event to main window Command events propagate. Parameters ---------- * msg_cls: class \tMessage class from new_command_event() * kwargs: dict \tMessage arguments
[ "Posts", "command", "event", "to", "main", "window" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_events.py#L40-L55
train
231,457
manns/pyspread
pyspread/src/lib/clipboard.py
Clipboard._convert_clipboard
def _convert_clipboard(self, datastring=None, sep='\t'): """Converts data string to iterable. Parameters: ----------- datastring: string, defaults to None \tThe data string to be converted. \tself.get_clipboard() is called if set to None sep: string \tSeparator for columns in datastring """ if datastring is None: datastring = self.get_clipboard() data_it = ((ele for ele in line.split(sep)) for line in datastring.splitlines()) return data_it
python
def _convert_clipboard(self, datastring=None, sep='\t'): """Converts data string to iterable. Parameters: ----------- datastring: string, defaults to None \tThe data string to be converted. \tself.get_clipboard() is called if set to None sep: string \tSeparator for columns in datastring """ if datastring is None: datastring = self.get_clipboard() data_it = ((ele for ele in line.split(sep)) for line in datastring.splitlines()) return data_it
[ "def", "_convert_clipboard", "(", "self", ",", "datastring", "=", "None", ",", "sep", "=", "'\\t'", ")", ":", "if", "datastring", "is", "None", ":", "datastring", "=", "self", ".", "get_clipboard", "(", ")", "data_it", "=", "(", "(", "ele", "for", "ele...
Converts data string to iterable. Parameters: ----------- datastring: string, defaults to None \tThe data string to be converted. \tself.get_clipboard() is called if set to None sep: string \tSeparator for columns in datastring
[ "Converts", "data", "string", "to", "iterable", "." ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/clipboard.py#L54-L72
train
231,458
manns/pyspread
pyspread/src/lib/clipboard.py
Clipboard.get_clipboard
def get_clipboard(self): """Returns the clipboard content If a bitmap is contained then it is returned. Otherwise, the clipboard text is returned. """ bmpdata = wx.BitmapDataObject() textdata = wx.TextDataObject() if self.clipboard.Open(): is_bmp_present = self.clipboard.GetData(bmpdata) self.clipboard.GetData(textdata) self.clipboard.Close() else: wx.MessageBox(_("Can't open the clipboard"), _("Error")) if is_bmp_present: return bmpdata.GetBitmap() else: return textdata.GetText()
python
def get_clipboard(self): """Returns the clipboard content If a bitmap is contained then it is returned. Otherwise, the clipboard text is returned. """ bmpdata = wx.BitmapDataObject() textdata = wx.TextDataObject() if self.clipboard.Open(): is_bmp_present = self.clipboard.GetData(bmpdata) self.clipboard.GetData(textdata) self.clipboard.Close() else: wx.MessageBox(_("Can't open the clipboard"), _("Error")) if is_bmp_present: return bmpdata.GetBitmap() else: return textdata.GetText()
[ "def", "get_clipboard", "(", "self", ")", ":", "bmpdata", "=", "wx", ".", "BitmapDataObject", "(", ")", "textdata", "=", "wx", ".", "TextDataObject", "(", ")", "if", "self", ".", "clipboard", ".", "Open", "(", ")", ":", "is_bmp_present", "=", "self", "...
Returns the clipboard content If a bitmap is contained then it is returned. Otherwise, the clipboard text is returned.
[ "Returns", "the", "clipboard", "content" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/clipboard.py#L74-L95
train
231,459
manns/pyspread
pyspread/src/lib/clipboard.py
Clipboard.set_clipboard
def set_clipboard(self, data, datatype="text"): """Writes data to the clipboard Parameters ---------- data: Object \tData object for clipboard datatype: String in ["text", "bitmap"] \tIdentifies datatype to be copied to the clipboard """ error_log = [] if datatype == "text": clip_data = wx.TextDataObject(text=data) elif datatype == "bitmap": clip_data = wx.BitmapDataObject(bitmap=data) else: msg = _("Datatype {type} unknown").format(type=datatype) raise ValueError(msg) if self.clipboard.Open(): self.clipboard.SetData(clip_data) self.clipboard.Close() else: wx.MessageBox(_("Can't open the clipboard"), _("Error")) return error_log
python
def set_clipboard(self, data, datatype="text"): """Writes data to the clipboard Parameters ---------- data: Object \tData object for clipboard datatype: String in ["text", "bitmap"] \tIdentifies datatype to be copied to the clipboard """ error_log = [] if datatype == "text": clip_data = wx.TextDataObject(text=data) elif datatype == "bitmap": clip_data = wx.BitmapDataObject(bitmap=data) else: msg = _("Datatype {type} unknown").format(type=datatype) raise ValueError(msg) if self.clipboard.Open(): self.clipboard.SetData(clip_data) self.clipboard.Close() else: wx.MessageBox(_("Can't open the clipboard"), _("Error")) return error_log
[ "def", "set_clipboard", "(", "self", ",", "data", ",", "datatype", "=", "\"text\"", ")", ":", "error_log", "=", "[", "]", "if", "datatype", "==", "\"text\"", ":", "clip_data", "=", "wx", ".", "TextDataObject", "(", "text", "=", "data", ")", "elif", "da...
Writes data to the clipboard Parameters ---------- data: Object \tData object for clipboard datatype: String in ["text", "bitmap"] \tIdentifies datatype to be copied to the clipboard
[ "Writes", "data", "to", "the", "clipboard" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/clipboard.py#L97-L127
train
231,460
manns/pyspread
pyspread/examples/macro_draw.py
draw_rect
def draw_rect(grid, attr, dc, rect): """Draws a rect""" dc.SetBrush(wx.Brush(wx.Colour(15, 255, 127), wx.SOLID)) dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID)) dc.DrawRectangleRect(rect)
python
def draw_rect(grid, attr, dc, rect): """Draws a rect""" dc.SetBrush(wx.Brush(wx.Colour(15, 255, 127), wx.SOLID)) dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID)) dc.DrawRectangleRect(rect)
[ "def", "draw_rect", "(", "grid", ",", "attr", ",", "dc", ",", "rect", ")", ":", "dc", ".", "SetBrush", "(", "wx", ".", "Brush", "(", "wx", ".", "Colour", "(", "15", ",", "255", ",", "127", ")", ",", "wx", ".", "SOLID", ")", ")", "dc", ".", ...
Draws a rect
[ "Draws", "a", "rect" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/examples/macro_draw.py#L2-L6
train
231,461
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._is_aborted
def _is_aborted(self, cycle, statustext, total_elements=None, freq=None): """Displays progress and returns True if abort Parameters ---------- cycle: Integer \tThe current operation cycle statustext: String \tLeft text in statusbar to be displayed total_elements: Integer: \tThe number of elements that have to be processed freq: Integer, defaults to None \tNo. operations between two abort possibilities, 1000 if None """ if total_elements is None: statustext += _("{nele} elements processed. Press <Esc> to abort.") else: statustext += _("{nele} of {totalele} elements processed. " "Press <Esc> to abort.") if freq is None: show_msg = False freq = 1000 else: show_msg = True # Show progress in statusbar each freq (1000) cells if cycle % freq == 0: if show_msg: text = statustext.format(nele=cycle, totalele=total_elements) try: post_command_event(self.main_window, self.StatusBarMsg, text=text) except TypeError: # The main window does not exist any more pass # Now wait for the statusbar update to be written on screen if is_gtk(): try: wx.Yield() except: pass # Abort if we have to if self.need_abort: # We have to abort` return True # Continue return False
python
def _is_aborted(self, cycle, statustext, total_elements=None, freq=None): """Displays progress and returns True if abort Parameters ---------- cycle: Integer \tThe current operation cycle statustext: String \tLeft text in statusbar to be displayed total_elements: Integer: \tThe number of elements that have to be processed freq: Integer, defaults to None \tNo. operations between two abort possibilities, 1000 if None """ if total_elements is None: statustext += _("{nele} elements processed. Press <Esc> to abort.") else: statustext += _("{nele} of {totalele} elements processed. " "Press <Esc> to abort.") if freq is None: show_msg = False freq = 1000 else: show_msg = True # Show progress in statusbar each freq (1000) cells if cycle % freq == 0: if show_msg: text = statustext.format(nele=cycle, totalele=total_elements) try: post_command_event(self.main_window, self.StatusBarMsg, text=text) except TypeError: # The main window does not exist any more pass # Now wait for the statusbar update to be written on screen if is_gtk(): try: wx.Yield() except: pass # Abort if we have to if self.need_abort: # We have to abort` return True # Continue return False
[ "def", "_is_aborted", "(", "self", ",", "cycle", ",", "statustext", ",", "total_elements", "=", "None", ",", "freq", "=", "None", ")", ":", "if", "total_elements", "is", "None", ":", "statustext", "+=", "_", "(", "\"{nele} elements processed. Press <Esc> to abor...
Displays progress and returns True if abort Parameters ---------- cycle: Integer \tThe current operation cycle statustext: String \tLeft text in statusbar to be displayed total_elements: Integer: \tThe number of elements that have to be processed freq: Integer, defaults to None \tNo. operations between two abort possibilities, 1000 if None
[ "Displays", "progress", "and", "returns", "True", "if", "abort" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L127-L180
train
231,462
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.validate_signature
def validate_signature(self, filename): """Returns True if a valid signature is present for filename""" if not GPG_PRESENT: return False sigfilename = filename + '.sig' try: with open(sigfilename): pass except IOError: # Signature file does not exist return False # Check if the sig is valid for the sigfile # TODO: Check for whitespace in filepaths return verify(sigfilename, filename)
python
def validate_signature(self, filename): """Returns True if a valid signature is present for filename""" if not GPG_PRESENT: return False sigfilename = filename + '.sig' try: with open(sigfilename): pass except IOError: # Signature file does not exist return False # Check if the sig is valid for the sigfile # TODO: Check for whitespace in filepaths return verify(sigfilename, filename)
[ "def", "validate_signature", "(", "self", ",", "filename", ")", ":", "if", "not", "GPG_PRESENT", ":", "return", "False", "sigfilename", "=", "filename", "+", "'.sig'", "try", ":", "with", "open", "(", "sigfilename", ")", ":", "pass", "except", "IOError", "...
Returns True if a valid signature is present for filename
[ "Returns", "True", "if", "a", "valid", "signature", "is", "present", "for", "filename" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L182-L200
train
231,463
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.leave_safe_mode
def leave_safe_mode(self): """Leaves safe mode""" self.code_array.safe_mode = False # Clear result cache self.code_array.result_cache.clear() # Execute macros self.main_window.actions.execute_macros() post_command_event(self.main_window, self.SafeModeExitMsg)
python
def leave_safe_mode(self): """Leaves safe mode""" self.code_array.safe_mode = False # Clear result cache self.code_array.result_cache.clear() # Execute macros self.main_window.actions.execute_macros() post_command_event(self.main_window, self.SafeModeExitMsg)
[ "def", "leave_safe_mode", "(", "self", ")", ":", "self", ".", "code_array", ".", "safe_mode", "=", "False", "# Clear result cache", "self", ".", "code_array", ".", "result_cache", ".", "clear", "(", ")", "# Execute macros", "self", ".", "main_window", ".", "ac...
Leaves safe mode
[ "Leaves", "safe", "mode" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L207-L218
train
231,464
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.approve
def approve(self, filepath): """Sets safe mode if signature missing of invalid""" try: signature_valid = self.validate_signature(filepath) except ValueError: # GPG is not installed signature_valid = False if signature_valid: self.leave_safe_mode() post_command_event(self.main_window, self.SafeModeExitMsg) statustext = _("Valid signature found. File is trusted.") post_command_event(self.main_window, self.StatusBarMsg, text=statustext) else: self.enter_safe_mode() post_command_event(self.main_window, self.SafeModeEntryMsg) statustext = \ _("File is not properly signed. Safe mode " "activated. Select File -> Approve to leave safe mode.") post_command_event(self.main_window, self.StatusBarMsg, text=statustext)
python
def approve(self, filepath): """Sets safe mode if signature missing of invalid""" try: signature_valid = self.validate_signature(filepath) except ValueError: # GPG is not installed signature_valid = False if signature_valid: self.leave_safe_mode() post_command_event(self.main_window, self.SafeModeExitMsg) statustext = _("Valid signature found. File is trusted.") post_command_event(self.main_window, self.StatusBarMsg, text=statustext) else: self.enter_safe_mode() post_command_event(self.main_window, self.SafeModeEntryMsg) statustext = \ _("File is not properly signed. Safe mode " "activated. Select File -> Approve to leave safe mode.") post_command_event(self.main_window, self.StatusBarMsg, text=statustext)
[ "def", "approve", "(", "self", ",", "filepath", ")", ":", "try", ":", "signature_valid", "=", "self", ".", "validate_signature", "(", "filepath", ")", "except", "ValueError", ":", "# GPG is not installed", "signature_valid", "=", "False", "if", "signature_valid", ...
Sets safe mode if signature missing of invalid
[ "Sets", "safe", "mode", "if", "signature", "missing", "of", "invalid" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L220-L246
train
231,465
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.clear_globals_reload_modules
def clear_globals_reload_modules(self): """Clears globals and reloads modules""" self.code_array.clear_globals() self.code_array.reload_modules() # Clear result cache self.code_array.result_cache.clear()
python
def clear_globals_reload_modules(self): """Clears globals and reloads modules""" self.code_array.clear_globals() self.code_array.reload_modules() # Clear result cache self.code_array.result_cache.clear()
[ "def", "clear_globals_reload_modules", "(", "self", ")", ":", "self", ".", "code_array", ".", "clear_globals", "(", ")", "self", ".", "code_array", ".", "reload_modules", "(", ")", "# Clear result cache", "self", ".", "code_array", ".", "result_cache", ".", "cle...
Clears globals and reloads modules
[ "Clears", "globals", "and", "reloads", "modules" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L248-L255
train
231,466
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._get_file_version
def _get_file_version(self, infile): """Returns infile version string.""" # Determine file version for line1 in infile: if line1.strip() != "[Pyspread save file version]": raise ValueError(_("File format unsupported.")) break for line2 in infile: return line2.strip()
python
def _get_file_version(self, infile): """Returns infile version string.""" # Determine file version for line1 in infile: if line1.strip() != "[Pyspread save file version]": raise ValueError(_("File format unsupported.")) break for line2 in infile: return line2.strip()
[ "def", "_get_file_version", "(", "self", ",", "infile", ")", ":", "# Determine file version", "for", "line1", "in", "infile", ":", "if", "line1", ".", "strip", "(", ")", "!=", "\"[Pyspread save file version]\"", ":", "raise", "ValueError", "(", "_", "(", "\"Fi...
Returns infile version string.
[ "Returns", "infile", "version", "string", "." ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L257-L267
train
231,467
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.clear
def clear(self, shape=None): """Empties grid and sets shape to shape Clears all attributes, row heights, column withs and frozen states. Empties undo/redo list and caches. Empties globals. Properties ---------- shape: 3-tuple of Integer, defaults to None \tTarget shape of grid after clearing all content. \tShape unchanged if None """ # Without setting this explicitly, the cursor is set too late self.grid.actions.cursor = 0, 0, 0 self.grid.current_table = 0 post_command_event(self.main_window.grid, self.GotoCellMsg, key=(0, 0, 0)) # Clear cells self.code_array.dict_grid.clear() # Clear attributes del self.code_array.dict_grid.cell_attributes[:] if shape is not None: # Set shape self.code_array.shape = shape # Clear row heights and column widths self.code_array.row_heights.clear() self.code_array.col_widths.clear() # Clear macros self.code_array.macros = "" # Clear caches self.code_array.result_cache.clear() # Clear globals self.code_array.clear_globals() self.code_array.reload_modules()
python
def clear(self, shape=None): """Empties grid and sets shape to shape Clears all attributes, row heights, column withs and frozen states. Empties undo/redo list and caches. Empties globals. Properties ---------- shape: 3-tuple of Integer, defaults to None \tTarget shape of grid after clearing all content. \tShape unchanged if None """ # Without setting this explicitly, the cursor is set too late self.grid.actions.cursor = 0, 0, 0 self.grid.current_table = 0 post_command_event(self.main_window.grid, self.GotoCellMsg, key=(0, 0, 0)) # Clear cells self.code_array.dict_grid.clear() # Clear attributes del self.code_array.dict_grid.cell_attributes[:] if shape is not None: # Set shape self.code_array.shape = shape # Clear row heights and column widths self.code_array.row_heights.clear() self.code_array.col_widths.clear() # Clear macros self.code_array.macros = "" # Clear caches self.code_array.result_cache.clear() # Clear globals self.code_array.clear_globals() self.code_array.reload_modules()
[ "def", "clear", "(", "self", ",", "shape", "=", "None", ")", ":", "# Without setting this explicitly, the cursor is set too late", "self", ".", "grid", ".", "actions", ".", "cursor", "=", "0", ",", "0", ",", "0", "self", ".", "grid", ".", "current_table", "=...
Empties grid and sets shape to shape Clears all attributes, row heights, column withs and frozen states. Empties undo/redo list and caches. Empties globals. Properties ---------- shape: 3-tuple of Integer, defaults to None \tTarget shape of grid after clearing all content. \tShape unchanged if None
[ "Empties", "grid", "and", "sets", "shape", "to", "shape" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L269-L313
train
231,468
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.open
def open(self, event): """Opens a file that is specified in event.attr Parameters ---------- event.attr: Dict \tkey filepath contains file path of file to be loaded \tkey filetype contains file type of file to be loaded \tFiletypes can be pys, pysu, xls """ filepath = event.attr["filepath"] try: filetype = event.attr["filetype"] except KeyError: try: file_ext = filepath.strip().split(".")[-1] except: file_ext = None if file_ext in ["pys", "pysu", "xls", "xlsx", "ods"]: filetype = file_ext else: filetype = "pys" type2opener = { "pys": (Bz2AOpen, [filepath, "r"], {"main_window": self.main_window}), "pysu": (AOpen, [filepath, "r"], {"main_window": self.main_window}) } if xlrd is not None: type2opener["xls"] = \ (xlrd.open_workbook, [filepath], {"formatting_info": True}) type2opener["xlsx"] = \ (xlrd.open_workbook, [filepath], {"formatting_info": False}) if odf is not None and Ods is not None: type2opener["ods"] = (open, [filepath, "rb"], {}) # Specify the interface that shall be used opener, op_args, op_kwargs = type2opener[filetype] Interface = self.type2interface[filetype] # Set state for file open self.opening = True try: with opener(*op_args, **op_kwargs) as infile: # Make loading safe self.approve(filepath) if xlrd is None: interface_errors = (ValueError, ) else: interface_errors = (ValueError, xlrd.biffh.XLRDError) try: wx.BeginBusyCursor() self.grid.Disable() self.clear() interface = Interface(self.grid.code_array, infile) interface.to_code_array() self.grid.main_window.macro_panel.codetext_ctrl.SetText( self.grid.code_array.macros) except interface_errors, err: post_command_event(self.main_window, self.StatusBarMsg, text=str(err)) finally: self.grid.GetTable().ResetView() post_command_event(self.main_window, self.ResizeGridMsg, shape=self.grid.code_array.shape) self.grid.Enable() wx.EndBusyCursor() # Execute macros self.main_window.actions.execute_macros() self.grid.GetTable().ResetView() self.grid.ForceRefresh() # File sucessfully opened. Approve again to show status. self.approve(filepath) # Change current directory to file directory filedir = os.path.dirname(filepath) os.chdir(filedir) except IOError, err: txt = _("Error opening file {filepath}:").format(filepath=filepath) txt += " " + str(err) post_command_event(self.main_window, self.StatusBarMsg, text=txt) return False except EOFError: # Normally on empty grids pass finally: # Unset state for file open self.opening = False
python
def open(self, event): """Opens a file that is specified in event.attr Parameters ---------- event.attr: Dict \tkey filepath contains file path of file to be loaded \tkey filetype contains file type of file to be loaded \tFiletypes can be pys, pysu, xls """ filepath = event.attr["filepath"] try: filetype = event.attr["filetype"] except KeyError: try: file_ext = filepath.strip().split(".")[-1] except: file_ext = None if file_ext in ["pys", "pysu", "xls", "xlsx", "ods"]: filetype = file_ext else: filetype = "pys" type2opener = { "pys": (Bz2AOpen, [filepath, "r"], {"main_window": self.main_window}), "pysu": (AOpen, [filepath, "r"], {"main_window": self.main_window}) } if xlrd is not None: type2opener["xls"] = \ (xlrd.open_workbook, [filepath], {"formatting_info": True}) type2opener["xlsx"] = \ (xlrd.open_workbook, [filepath], {"formatting_info": False}) if odf is not None and Ods is not None: type2opener["ods"] = (open, [filepath, "rb"], {}) # Specify the interface that shall be used opener, op_args, op_kwargs = type2opener[filetype] Interface = self.type2interface[filetype] # Set state for file open self.opening = True try: with opener(*op_args, **op_kwargs) as infile: # Make loading safe self.approve(filepath) if xlrd is None: interface_errors = (ValueError, ) else: interface_errors = (ValueError, xlrd.biffh.XLRDError) try: wx.BeginBusyCursor() self.grid.Disable() self.clear() interface = Interface(self.grid.code_array, infile) interface.to_code_array() self.grid.main_window.macro_panel.codetext_ctrl.SetText( self.grid.code_array.macros) except interface_errors, err: post_command_event(self.main_window, self.StatusBarMsg, text=str(err)) finally: self.grid.GetTable().ResetView() post_command_event(self.main_window, self.ResizeGridMsg, shape=self.grid.code_array.shape) self.grid.Enable() wx.EndBusyCursor() # Execute macros self.main_window.actions.execute_macros() self.grid.GetTable().ResetView() self.grid.ForceRefresh() # File sucessfully opened. Approve again to show status. self.approve(filepath) # Change current directory to file directory filedir = os.path.dirname(filepath) os.chdir(filedir) except IOError, err: txt = _("Error opening file {filepath}:").format(filepath=filepath) txt += " " + str(err) post_command_event(self.main_window, self.StatusBarMsg, text=txt) return False except EOFError: # Normally on empty grids pass finally: # Unset state for file open self.opening = False
[ "def", "open", "(", "self", ",", "event", ")", ":", "filepath", "=", "event", ".", "attr", "[", "\"filepath\"", "]", "try", ":", "filetype", "=", "event", ".", "attr", "[", "\"filetype\"", "]", "except", "KeyError", ":", "try", ":", "file_ext", "=", ...
Opens a file that is specified in event.attr Parameters ---------- event.attr: Dict \tkey filepath contains file path of file to be loaded \tkey filetype contains file type of file to be loaded \tFiletypes can be pys, pysu, xls
[ "Opens", "a", "file", "that", "is", "specified", "in", "event", ".", "attr" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L315-L421
train
231,469
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.sign_file
def sign_file(self, filepath): """Signs file if possible""" if not GPG_PRESENT: return signed_data = sign(filepath) signature = signed_data.data if signature is None or not signature: statustext = _('Error signing file. ') + signed_data.stderr try: post_command_event(self.main_window, self.StatusBarMsg, text=statustext) except TypeError: # The main window does not exist any more pass return with open(filepath + '.sig', 'wb') as signfile: signfile.write(signature) # Statustext differs if a save has occurred if self.code_array.safe_mode: statustext = _('File saved and signed') else: statustext = _('File signed') try: post_command_event(self.main_window, self.StatusBarMsg, text=statustext) except TypeError: # The main window does not exist any more pass
python
def sign_file(self, filepath): """Signs file if possible""" if not GPG_PRESENT: return signed_data = sign(filepath) signature = signed_data.data if signature is None or not signature: statustext = _('Error signing file. ') + signed_data.stderr try: post_command_event(self.main_window, self.StatusBarMsg, text=statustext) except TypeError: # The main window does not exist any more pass return with open(filepath + '.sig', 'wb') as signfile: signfile.write(signature) # Statustext differs if a save has occurred if self.code_array.safe_mode: statustext = _('File saved and signed') else: statustext = _('File signed') try: post_command_event(self.main_window, self.StatusBarMsg, text=statustext) except TypeError: # The main window does not exist any more pass
[ "def", "sign_file", "(", "self", ",", "filepath", ")", ":", "if", "not", "GPG_PRESENT", ":", "return", "signed_data", "=", "sign", "(", "filepath", ")", "signature", "=", "signed_data", ".", "data", "if", "signature", "is", "None", "or", "not", "signature"...
Signs file if possible
[ "Signs", "file", "if", "possible" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L423-L458
train
231,470
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._set_save_states
def _set_save_states(self): """Sets application save states""" wx.BeginBusyCursor() self.saving = True self.grid.Disable()
python
def _set_save_states(self): """Sets application save states""" wx.BeginBusyCursor() self.saving = True self.grid.Disable()
[ "def", "_set_save_states", "(", "self", ")", ":", "wx", ".", "BeginBusyCursor", "(", ")", "self", ".", "saving", "=", "True", "self", ".", "grid", ".", "Disable", "(", ")" ]
Sets application save states
[ "Sets", "application", "save", "states" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L460-L465
train
231,471
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._release_save_states
def _release_save_states(self): """Releases application save states""" self.saving = False self.grid.Enable() wx.EndBusyCursor() # Mark content as unchanged try: post_command_event(self.main_window, self.ContentChangedMsg) except TypeError: # The main window does not exist any more pass
python
def _release_save_states(self): """Releases application save states""" self.saving = False self.grid.Enable() wx.EndBusyCursor() # Mark content as unchanged try: post_command_event(self.main_window, self.ContentChangedMsg) except TypeError: # The main window does not exist any more pass
[ "def", "_release_save_states", "(", "self", ")", ":", "self", ".", "saving", "=", "False", "self", ".", "grid", ".", "Enable", "(", ")", "wx", ".", "EndBusyCursor", "(", ")", "# Mark content as unchanged", "try", ":", "post_command_event", "(", "self", ".", ...
Releases application save states
[ "Releases", "application", "save", "states" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L467-L479
train
231,472
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._move_tmp_file
def _move_tmp_file(self, tmpfilepath, filepath): """Moves tmpfile over file after saving is finished Parameters ---------- filepath: String \tTarget file path for xls file tmpfilepath: String \tTemporary file file path for xls file """ try: shutil.move(tmpfilepath, filepath) except OSError, err: # No tmp file present post_command_event(self.main_window, self.StatusBarMsg, text=err)
python
def _move_tmp_file(self, tmpfilepath, filepath): """Moves tmpfile over file after saving is finished Parameters ---------- filepath: String \tTarget file path for xls file tmpfilepath: String \tTemporary file file path for xls file """ try: shutil.move(tmpfilepath, filepath) except OSError, err: # No tmp file present post_command_event(self.main_window, self.StatusBarMsg, text=err)
[ "def", "_move_tmp_file", "(", "self", ",", "tmpfilepath", ",", "filepath", ")", ":", "try", ":", "shutil", ".", "move", "(", "tmpfilepath", ",", "filepath", ")", "except", "OSError", ",", "err", ":", "# No tmp file present", "post_command_event", "(", "self", ...
Moves tmpfile over file after saving is finished Parameters ---------- filepath: String \tTarget file path for xls file tmpfilepath: String \tTemporary file file path for xls file
[ "Moves", "tmpfile", "over", "file", "after", "saving", "is", "finished" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L481-L499
train
231,473
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._save_xls
def _save_xls(self, filepath): """Saves file as xls workbook Parameters ---------- filepath: String \tTarget file path for xls file """ Interface = self.type2interface["xls"] workbook = xlwt.Workbook() interface = Interface(self.grid.code_array, workbook) interface.from_code_array() try: workbook.save(filepath) except IOError, err: try: post_command_event(self.main_window, self.StatusBarMsg, text=err) except TypeError: # The main window does not exist any more pass
python
def _save_xls(self, filepath): """Saves file as xls workbook Parameters ---------- filepath: String \tTarget file path for xls file """ Interface = self.type2interface["xls"] workbook = xlwt.Workbook() interface = Interface(self.grid.code_array, workbook) interface.from_code_array() try: workbook.save(filepath) except IOError, err: try: post_command_event(self.main_window, self.StatusBarMsg, text=err) except TypeError: # The main window does not exist any more pass
[ "def", "_save_xls", "(", "self", ",", "filepath", ")", ":", "Interface", "=", "self", ".", "type2interface", "[", "\"xls\"", "]", "workbook", "=", "xlwt", ".", "Workbook", "(", ")", "interface", "=", "Interface", "(", "self", ".", "grid", ".", "code_arra...
Saves file as xls workbook Parameters ---------- filepath: String \tTarget file path for xls file
[ "Saves", "file", "as", "xls", "workbook" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L501-L527
train
231,474
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._save_pys
def _save_pys(self, filepath): """Saves file as pys file and returns True if save success Parameters ---------- filepath: String \tTarget file path for xls file """ try: with Bz2AOpen(filepath, "wb", main_window=self.main_window) as outfile: interface = Pys(self.grid.code_array, outfile) interface.from_code_array() except (IOError, ValueError), err: try: post_command_event(self.main_window, self.StatusBarMsg, text=err) return except TypeError: # The main window does not exist any more pass return not outfile.aborted
python
def _save_pys(self, filepath): """Saves file as pys file and returns True if save success Parameters ---------- filepath: String \tTarget file path for xls file """ try: with Bz2AOpen(filepath, "wb", main_window=self.main_window) as outfile: interface = Pys(self.grid.code_array, outfile) interface.from_code_array() except (IOError, ValueError), err: try: post_command_event(self.main_window, self.StatusBarMsg, text=err) return except TypeError: # The main window does not exist any more pass return not outfile.aborted
[ "def", "_save_pys", "(", "self", ",", "filepath", ")", ":", "try", ":", "with", "Bz2AOpen", "(", "filepath", ",", "\"wb\"", ",", "main_window", "=", "self", ".", "main_window", ")", "as", "outfile", ":", "interface", "=", "Pys", "(", "self", ".", "grid...
Saves file as pys file and returns True if save success Parameters ---------- filepath: String \tTarget file path for xls file
[ "Saves", "file", "as", "pys", "file", "and", "returns", "True", "if", "save", "success" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L529-L555
train
231,475
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions._save_sign
def _save_sign(self, filepath): """Sign so that the new file may be retrieved without safe mode""" if self.code_array.safe_mode: msg = _("File saved but not signed because it is unapproved.") try: post_command_event(self.main_window, self.StatusBarMsg, text=msg) except TypeError: # The main window does not exist any more pass else: try: self.sign_file(filepath) except ValueError, err: msg = "Signing file failed. " + unicode(err) post_command_event(self.main_window, self.StatusBarMsg, text=msg)
python
def _save_sign(self, filepath): """Sign so that the new file may be retrieved without safe mode""" if self.code_array.safe_mode: msg = _("File saved but not signed because it is unapproved.") try: post_command_event(self.main_window, self.StatusBarMsg, text=msg) except TypeError: # The main window does not exist any more pass else: try: self.sign_file(filepath) except ValueError, err: msg = "Signing file failed. " + unicode(err) post_command_event(self.main_window, self.StatusBarMsg, text=msg)
[ "def", "_save_sign", "(", "self", ",", "filepath", ")", ":", "if", "self", ".", "code_array", ".", "safe_mode", ":", "msg", "=", "_", "(", "\"File saved but not signed because it is unapproved.\"", ")", "try", ":", "post_command_event", "(", "self", ".", "main_w...
Sign so that the new file may be retrieved without safe mode
[ "Sign", "so", "that", "the", "new", "file", "may", "be", "retrieved", "without", "safe", "mode" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L585-L604
train
231,476
manns/pyspread
pyspread/src/actions/_grid_actions.py
FileActions.save
def save(self, event): """Saves a file that is specified in event.attr Parameters ---------- event.attr: Dict \tkey filepath contains file path of file to be saved """ filepath = event.attr["filepath"] try: filetype = event.attr["filetype"] except KeyError: filetype = "pys" # If saving is already in progress abort if self.saving: return # Use tmpfile to make sure that old save file does not get lost # on abort save __, tmpfilepath = tempfile.mkstemp() if filetype == "xls": self._set_save_states() self._save_xls(tmpfilepath) self._move_tmp_file(tmpfilepath, filepath) self._release_save_states() elif filetype == "pys" or filetype == "all": self._set_save_states() if self._save_pys(tmpfilepath): # Writing was successful self._move_tmp_file(tmpfilepath, filepath) self._save_sign(filepath) self._release_save_states() elif filetype == "pysu": self._set_save_states() if self._save_pysu(tmpfilepath): # Writing was successful self._move_tmp_file(tmpfilepath, filepath) self._save_sign(filepath) self._release_save_states() else: os.remove(tmpfilepath) msg = "Filetype {filetype} unknown.".format(filetype=filetype) raise ValueError(msg) try: os.remove(tmpfilepath) except OSError: pass
python
def save(self, event): """Saves a file that is specified in event.attr Parameters ---------- event.attr: Dict \tkey filepath contains file path of file to be saved """ filepath = event.attr["filepath"] try: filetype = event.attr["filetype"] except KeyError: filetype = "pys" # If saving is already in progress abort if self.saving: return # Use tmpfile to make sure that old save file does not get lost # on abort save __, tmpfilepath = tempfile.mkstemp() if filetype == "xls": self._set_save_states() self._save_xls(tmpfilepath) self._move_tmp_file(tmpfilepath, filepath) self._release_save_states() elif filetype == "pys" or filetype == "all": self._set_save_states() if self._save_pys(tmpfilepath): # Writing was successful self._move_tmp_file(tmpfilepath, filepath) self._save_sign(filepath) self._release_save_states() elif filetype == "pysu": self._set_save_states() if self._save_pysu(tmpfilepath): # Writing was successful self._move_tmp_file(tmpfilepath, filepath) self._save_sign(filepath) self._release_save_states() else: os.remove(tmpfilepath) msg = "Filetype {filetype} unknown.".format(filetype=filetype) raise ValueError(msg) try: os.remove(tmpfilepath) except OSError: pass
[ "def", "save", "(", "self", ",", "event", ")", ":", "filepath", "=", "event", ".", "attr", "[", "\"filepath\"", "]", "try", ":", "filetype", "=", "event", ".", "attr", "[", "\"filetype\"", "]", "except", "KeyError", ":", "filetype", "=", "\"pys\"", "# ...
Saves a file that is specified in event.attr Parameters ---------- event.attr: Dict \tkey filepath contains file path of file to be saved
[ "Saves", "a", "file", "that", "is", "specified", "in", "event", ".", "attr" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L606-L662
train
231,477
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableRowActionsMixin.set_row_height
def set_row_height(self, row, height): """Sets row height and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.set_row_height(row, tab, height) self.grid.SetRowSize(row, height)
python
def set_row_height(self, row, height): """Sets row height and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.set_row_height(row, tab, height) self.grid.SetRowSize(row, height)
[ "def", "set_row_height", "(", "self", ",", "row", ",", "height", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "tab", "=", "self", ".", "grid", ".", "current_table", "s...
Sets row height and marks grid as changed
[ "Sets", "row", "height", "and", "marks", "grid", "as", "changed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L668-L677
train
231,478
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableRowActionsMixin.insert_rows
def insert_rows(self, row, no_rows=1): """Adds no_rows rows before row, appends if row > maxrows and marks grid as changed """ # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.insert(row, no_rows, axis=0, tab=tab)
python
def insert_rows(self, row, no_rows=1): """Adds no_rows rows before row, appends if row > maxrows and marks grid as changed """ # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.insert(row, no_rows, axis=0, tab=tab)
[ "def", "insert_rows", "(", "self", ",", "row", ",", "no_rows", "=", "1", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "tab", "=", "self", ".", "grid", ".", "current_...
Adds no_rows rows before row, appends if row > maxrows and marks grid as changed
[ "Adds", "no_rows", "rows", "before", "row", "appends", "if", "row", ">", "maxrows" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L679-L691
train
231,479
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableRowActionsMixin.delete_rows
def delete_rows(self, row, no_rows=1): """Deletes no_rows rows and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table try: self.code_array.delete(row, no_rows, axis=0, tab=tab) except ValueError, err: post_command_event(self.main_window, self.StatusBarMsg, text=err.message)
python
def delete_rows(self, row, no_rows=1): """Deletes no_rows rows and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table try: self.code_array.delete(row, no_rows, axis=0, tab=tab) except ValueError, err: post_command_event(self.main_window, self.StatusBarMsg, text=err.message)
[ "def", "delete_rows", "(", "self", ",", "row", ",", "no_rows", "=", "1", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "tab", "=", "self", ".", "grid", ".", "current_...
Deletes no_rows rows and marks grid as changed
[ "Deletes", "no_rows", "rows", "and", "marks", "grid", "as", "changed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L693-L706
train
231,480
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableColumnActionsMixin.set_col_width
def set_col_width(self, col, width): """Sets column width and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.set_col_width(col, tab, width) self.grid.SetColSize(col, width)
python
def set_col_width(self, col, width): """Sets column width and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.set_col_width(col, tab, width) self.grid.SetColSize(col, width)
[ "def", "set_col_width", "(", "self", ",", "col", ",", "width", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "tab", "=", "self", ".", "grid", ".", "current_table", "sel...
Sets column width and marks grid as changed
[ "Sets", "column", "width", "and", "marks", "grid", "as", "changed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L712-L721
train
231,481
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableColumnActionsMixin.insert_cols
def insert_cols(self, col, no_cols=1): """Adds no_cols columns before col, appends if col > maxcols and marks grid as changed """ # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.insert(col, no_cols, axis=1, tab=tab)
python
def insert_cols(self, col, no_cols=1): """Adds no_cols columns before col, appends if col > maxcols and marks grid as changed """ # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table self.code_array.insert(col, no_cols, axis=1, tab=tab)
[ "def", "insert_cols", "(", "self", ",", "col", ",", "no_cols", "=", "1", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "tab", "=", "self", ".", "grid", ".", "current_...
Adds no_cols columns before col, appends if col > maxcols and marks grid as changed
[ "Adds", "no_cols", "columns", "before", "col", "appends", "if", "col", ">", "maxcols" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L723-L735
train
231,482
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableColumnActionsMixin.delete_cols
def delete_cols(self, col, no_cols=1): """Deletes no_cols column and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table try: self.code_array.delete(col, no_cols, axis=1, tab=tab) except ValueError, err: post_command_event(self.main_window, self.StatusBarMsg, text=err.message)
python
def delete_cols(self, col, no_cols=1): """Deletes no_cols column and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) tab = self.grid.current_table try: self.code_array.delete(col, no_cols, axis=1, tab=tab) except ValueError, err: post_command_event(self.main_window, self.StatusBarMsg, text=err.message)
[ "def", "delete_cols", "(", "self", ",", "col", ",", "no_cols", "=", "1", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "tab", "=", "self", ".", "grid", ".", "current_...
Deletes no_cols column and marks grid as changed
[ "Deletes", "no_cols", "column", "and", "marks", "grid", "as", "changed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L737-L750
train
231,483
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableTabActionsMixin.insert_tabs
def insert_tabs(self, tab, no_tabs=1): """Adds no_tabs tabs before table, appends if tab > maxtabs and marks grid as changed """ # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) self.code_array.insert(tab, no_tabs, axis=2) # Update TableChoiceIntCtrl shape = self.grid.code_array.shape post_command_event(self.main_window, self.ResizeGridMsg, shape=shape)
python
def insert_tabs(self, tab, no_tabs=1): """Adds no_tabs tabs before table, appends if tab > maxtabs and marks grid as changed """ # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) self.code_array.insert(tab, no_tabs, axis=2) # Update TableChoiceIntCtrl shape = self.grid.code_array.shape post_command_event(self.main_window, self.ResizeGridMsg, shape=shape)
[ "def", "insert_tabs", "(", "self", ",", "tab", ",", "no_tabs", "=", "1", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "self", ".", "code_array", ".", "insert", "(", ...
Adds no_tabs tabs before table, appends if tab > maxtabs and marks grid as changed
[ "Adds", "no_tabs", "tabs", "before", "table", "appends", "if", "tab", ">", "maxtabs" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L756-L770
train
231,484
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableTabActionsMixin.delete_tabs
def delete_tabs(self, tab, no_tabs=1): """Deletes no_tabs tabs and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) try: self.code_array.delete(tab, no_tabs, axis=2) # Update TableChoiceIntCtrl shape = self.grid.code_array.shape post_command_event(self.main_window, self.ResizeGridMsg, shape=shape) except ValueError, err: post_command_event(self.main_window, self.StatusBarMsg, text=err.message)
python
def delete_tabs(self, tab, no_tabs=1): """Deletes no_tabs tabs and marks grid as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) try: self.code_array.delete(tab, no_tabs, axis=2) # Update TableChoiceIntCtrl shape = self.grid.code_array.shape post_command_event(self.main_window, self.ResizeGridMsg, shape=shape) except ValueError, err: post_command_event(self.main_window, self.StatusBarMsg, text=err.message)
[ "def", "delete_tabs", "(", "self", ",", "tab", ",", "no_tabs", "=", "1", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "try", ":", "self", ".", "code_array", ".", "de...
Deletes no_tabs tabs and marks grid as changed
[ "Deletes", "no_tabs", "tabs", "and", "marks", "grid", "as", "changed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L772-L788
train
231,485
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions.on_key
def on_key(self, event): """Sets abort if pasting and if escape is pressed""" # If paste is running and Esc is pressed then we need to abort if event.GetKeyCode() == wx.WXK_ESCAPE and \ self.pasting or self.grid.actions.saving: self.need_abort = True event.Skip()
python
def on_key(self, event): """Sets abort if pasting and if escape is pressed""" # If paste is running and Esc is pressed then we need to abort if event.GetKeyCode() == wx.WXK_ESCAPE and \ self.pasting or self.grid.actions.saving: self.need_abort = True event.Skip()
[ "def", "on_key", "(", "self", ",", "event", ")", ":", "# If paste is running and Esc is pressed then we need to abort", "if", "event", ".", "GetKeyCode", "(", ")", "==", "wx", ".", "WXK_ESCAPE", "and", "self", ".", "pasting", "or", "self", ".", "grid", ".", "a...
Sets abort if pasting and if escape is pressed
[ "Sets", "abort", "if", "pasting", "and", "if", "escape", "is", "pressed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L808-L817
train
231,486
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions._get_full_key
def _get_full_key(self, key): """Returns full key even if table is omitted""" length = len(key) if length == 3: return key elif length == 2: row, col = key tab = self.grid.current_table return row, col, tab else: msg = _("Key length {length} not in (2, 3)").format(length=length) raise ValueError(msg)
python
def _get_full_key(self, key): """Returns full key even if table is omitted""" length = len(key) if length == 3: return key elif length == 2: row, col = key tab = self.grid.current_table return row, col, tab else: msg = _("Key length {length} not in (2, 3)").format(length=length) raise ValueError(msg)
[ "def", "_get_full_key", "(", "self", ",", "key", ")", ":", "length", "=", "len", "(", "key", ")", "if", "length", "==", "3", ":", "return", "key", "elif", "length", "==", "2", ":", "row", ",", "col", "=", "key", "tab", "=", "self", ".", "grid", ...
Returns full key even if table is omitted
[ "Returns", "full", "key", "even", "if", "table", "is", "omitted" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L819-L834
train
231,487
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions._show_final_overflow_message
def _show_final_overflow_message(self, row_overflow, col_overflow): """Displays overflow message after import in statusbar""" if row_overflow and col_overflow: overflow_cause = _("rows and columns") elif row_overflow: overflow_cause = _("rows") elif col_overflow: overflow_cause = _("columns") else: raise AssertionError(_("Import cell overflow missing")) statustext = \ _("The imported data did not fit into the grid {cause}. " "It has been truncated. Use a larger grid for full import.").\ format(cause=overflow_cause) post_command_event(self.main_window, self.StatusBarMsg, text=statustext)
python
def _show_final_overflow_message(self, row_overflow, col_overflow): """Displays overflow message after import in statusbar""" if row_overflow and col_overflow: overflow_cause = _("rows and columns") elif row_overflow: overflow_cause = _("rows") elif col_overflow: overflow_cause = _("columns") else: raise AssertionError(_("Import cell overflow missing")) statustext = \ _("The imported data did not fit into the grid {cause}. " "It has been truncated. Use a larger grid for full import.").\ format(cause=overflow_cause) post_command_event(self.main_window, self.StatusBarMsg, text=statustext)
[ "def", "_show_final_overflow_message", "(", "self", ",", "row_overflow", ",", "col_overflow", ")", ":", "if", "row_overflow", "and", "col_overflow", ":", "overflow_cause", "=", "_", "(", "\"rows and columns\"", ")", "elif", "row_overflow", ":", "overflow_cause", "="...
Displays overflow message after import in statusbar
[ "Displays", "overflow", "message", "after", "import", "in", "statusbar" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L846-L863
train
231,488
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions._show_final_paste_message
def _show_final_paste_message(self, tl_key, no_pasted_cells): """Show actually pasted number of cells""" plural = "" if no_pasted_cells == 1 else _("s") statustext = _("{ncells} cell{plural} pasted at cell {topleft}").\ format(ncells=no_pasted_cells, plural=plural, topleft=tl_key) post_command_event(self.main_window, self.StatusBarMsg, text=statustext)
python
def _show_final_paste_message(self, tl_key, no_pasted_cells): """Show actually pasted number of cells""" plural = "" if no_pasted_cells == 1 else _("s") statustext = _("{ncells} cell{plural} pasted at cell {topleft}").\ format(ncells=no_pasted_cells, plural=plural, topleft=tl_key) post_command_event(self.main_window, self.StatusBarMsg, text=statustext)
[ "def", "_show_final_paste_message", "(", "self", ",", "tl_key", ",", "no_pasted_cells", ")", ":", "plural", "=", "\"\"", "if", "no_pasted_cells", "==", "1", "else", "_", "(", "\"s\"", ")", "statustext", "=", "_", "(", "\"{ncells} cell{plural} pasted at cell {tople...
Show actually pasted number of cells
[ "Show", "actually", "pasted", "number", "of", "cells" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L865-L874
train
231,489
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions.paste_to_current_cell
def paste_to_current_cell(self, tl_key, data, freq=None): """Pastes data into grid from top left cell tl_key Parameters ---------- ul_key: Tuple \key of top left cell of paste area data: iterable of iterables where inner iterable returns string \tThe outer iterable represents rows freq: Integer, defaults to None \tStatus message frequency """ self.pasting = True grid_rows, grid_cols, __ = self.grid.code_array.shape self.need_abort = False tl_row, tl_col, tl_tab = self._get_full_key(tl_key) row_overflow = False col_overflow = False no_pasted_cells = 0 for src_row, row_data in enumerate(data): target_row = tl_row + src_row if self.grid.actions._is_aborted(src_row, _("Pasting cells... "), freq=freq): self._abort_paste() return False # Check if rows fit into grid if target_row >= grid_rows: row_overflow = True break for src_col, cell_data in enumerate(row_data): target_col = tl_col + src_col if target_col >= grid_cols: col_overflow = True break if cell_data is not None: # Is only None if pasting into selection key = target_row, target_col, tl_tab try: CellActions.set_code(self, key, cell_data) no_pasted_cells += 1 except KeyError: pass if row_overflow or col_overflow: self._show_final_overflow_message(row_overflow, col_overflow) else: self._show_final_paste_message(tl_key, no_pasted_cells) self.pasting = False
python
def paste_to_current_cell(self, tl_key, data, freq=None): """Pastes data into grid from top left cell tl_key Parameters ---------- ul_key: Tuple \key of top left cell of paste area data: iterable of iterables where inner iterable returns string \tThe outer iterable represents rows freq: Integer, defaults to None \tStatus message frequency """ self.pasting = True grid_rows, grid_cols, __ = self.grid.code_array.shape self.need_abort = False tl_row, tl_col, tl_tab = self._get_full_key(tl_key) row_overflow = False col_overflow = False no_pasted_cells = 0 for src_row, row_data in enumerate(data): target_row = tl_row + src_row if self.grid.actions._is_aborted(src_row, _("Pasting cells... "), freq=freq): self._abort_paste() return False # Check if rows fit into grid if target_row >= grid_rows: row_overflow = True break for src_col, cell_data in enumerate(row_data): target_col = tl_col + src_col if target_col >= grid_cols: col_overflow = True break if cell_data is not None: # Is only None if pasting into selection key = target_row, target_col, tl_tab try: CellActions.set_code(self, key, cell_data) no_pasted_cells += 1 except KeyError: pass if row_overflow or col_overflow: self._show_final_overflow_message(row_overflow, col_overflow) else: self._show_final_paste_message(tl_key, no_pasted_cells) self.pasting = False
[ "def", "paste_to_current_cell", "(", "self", ",", "tl_key", ",", "data", ",", "freq", "=", "None", ")", ":", "self", ".", "pasting", "=", "True", "grid_rows", ",", "grid_cols", ",", "__", "=", "self", ".", "grid", ".", "code_array", ".", "shape", "self...
Pastes data into grid from top left cell tl_key Parameters ---------- ul_key: Tuple \key of top left cell of paste area data: iterable of iterables where inner iterable returns string \tThe outer iterable represents rows freq: Integer, defaults to None \tStatus message frequency
[ "Pastes", "data", "into", "grid", "from", "top", "left", "cell", "tl_key" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L876-L940
train
231,490
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions.selection_paste_data_gen
def selection_paste_data_gen(self, selection, data, freq=None): """Generator that yields data for selection paste""" (bb_top, bb_left), (bb_bottom, bb_right) = \ selection.get_grid_bbox(self.grid.code_array.shape) bbox_height = bb_bottom - bb_top + 1 bbox_width = bb_right - bb_left + 1 for row, row_data in enumerate(itertools.cycle(data)): # Break if row is not in selection bbox if row >= bbox_height: break # Duplicate row data if selection is wider than row data row_data = list(row_data) duplicated_row_data = row_data * (bbox_width // len(row_data) + 1) duplicated_row_data = duplicated_row_data[:bbox_width] for col in xrange(len(duplicated_row_data)): if (bb_top, bb_left + col) not in selection: duplicated_row_data[col] = None yield duplicated_row_data
python
def selection_paste_data_gen(self, selection, data, freq=None): """Generator that yields data for selection paste""" (bb_top, bb_left), (bb_bottom, bb_right) = \ selection.get_grid_bbox(self.grid.code_array.shape) bbox_height = bb_bottom - bb_top + 1 bbox_width = bb_right - bb_left + 1 for row, row_data in enumerate(itertools.cycle(data)): # Break if row is not in selection bbox if row >= bbox_height: break # Duplicate row data if selection is wider than row data row_data = list(row_data) duplicated_row_data = row_data * (bbox_width // len(row_data) + 1) duplicated_row_data = duplicated_row_data[:bbox_width] for col in xrange(len(duplicated_row_data)): if (bb_top, bb_left + col) not in selection: duplicated_row_data[col] = None yield duplicated_row_data
[ "def", "selection_paste_data_gen", "(", "self", ",", "selection", ",", "data", ",", "freq", "=", "None", ")", ":", "(", "bb_top", ",", "bb_left", ")", ",", "(", "bb_bottom", ",", "bb_right", ")", "=", "selection", ".", "get_grid_bbox", "(", "self", ".", ...
Generator that yields data for selection paste
[ "Generator", "that", "yields", "data", "for", "selection", "paste" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L942-L964
train
231,491
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions.paste_to_selection
def paste_to_selection(self, selection, data, freq=None): """Pastes data into grid selection""" (bb_top, bb_left), (bb_bottom, bb_right) = \ selection.get_grid_bbox(self.grid.code_array.shape) adjusted_data = self.selection_paste_data_gen(selection, data) self.paste_to_current_cell((bb_top, bb_left), adjusted_data, freq=freq)
python
def paste_to_selection(self, selection, data, freq=None): """Pastes data into grid selection""" (bb_top, bb_left), (bb_bottom, bb_right) = \ selection.get_grid_bbox(self.grid.code_array.shape) adjusted_data = self.selection_paste_data_gen(selection, data) self.paste_to_current_cell((bb_top, bb_left), adjusted_data, freq=freq)
[ "def", "paste_to_selection", "(", "self", ",", "selection", ",", "data", ",", "freq", "=", "None", ")", ":", "(", "bb_top", ",", "bb_left", ")", ",", "(", "bb_bottom", ",", "bb_right", ")", "=", "selection", ".", "get_grid_bbox", "(", "self", ".", "gri...
Pastes data into grid selection
[ "Pastes", "data", "into", "grid", "selection" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L966-L972
train
231,492
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions.paste
def paste(self, tl_key, data, freq=None): """Pastes data into grid, marks grid changed If no selection is present, data is pasted starting with current cell If a selection is present, data is pasted fully if the selection is smaller. If the selection is larger then data is duplicated. Parameters ---------- ul_key: Tuple \key of top left cell of paste area data: iterable of iterables where inner iterable returns string \tThe outer iterable represents rows freq: Integer, defaults to None \tStatus message frequency """ # Get selection bounding box selection = self.get_selection() # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) if selection: # There is a selection. Paste into it self.paste_to_selection(selection, data, freq=freq) else: # There is no selection. Paste from top left cell. self.paste_to_current_cell(tl_key, data, freq=freq)
python
def paste(self, tl_key, data, freq=None): """Pastes data into grid, marks grid changed If no selection is present, data is pasted starting with current cell If a selection is present, data is pasted fully if the selection is smaller. If the selection is larger then data is duplicated. Parameters ---------- ul_key: Tuple \key of top left cell of paste area data: iterable of iterables where inner iterable returns string \tThe outer iterable represents rows freq: Integer, defaults to None \tStatus message frequency """ # Get selection bounding box selection = self.get_selection() # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) if selection: # There is a selection. Paste into it self.paste_to_selection(selection, data, freq=freq) else: # There is no selection. Paste from top left cell. self.paste_to_current_cell(tl_key, data, freq=freq)
[ "def", "paste", "(", "self", ",", "tl_key", ",", "data", ",", "freq", "=", "None", ")", ":", "# Get selection bounding box", "selection", "=", "self", ".", "get_selection", "(", ")", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_wind...
Pastes data into grid, marks grid changed If no selection is present, data is pasted starting with current cell If a selection is present, data is pasted fully if the selection is smaller. If the selection is larger then data is duplicated. Parameters ---------- ul_key: Tuple \key of top left cell of paste area data: iterable of iterables where inner iterable returns string \tThe outer iterable represents rows freq: Integer, defaults to None \tStatus message frequency
[ "Pastes", "data", "into", "grid", "marks", "grid", "changed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L974-L1005
train
231,493
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions.change_grid_shape
def change_grid_shape(self, shape): """Grid shape change event handler, marks content as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) self.code_array.shape = shape # Update TableChoiceIntCtrl post_command_event(self.main_window, self.ResizeGridMsg, shape=shape) # Change grid table dimensions self.grid.GetTable().ResetView() # Clear caches self.code_array.result_cache.clear()
python
def change_grid_shape(self, shape): """Grid shape change event handler, marks content as changed""" # Mark content as changed post_command_event(self.main_window, self.ContentChangedMsg) self.code_array.shape = shape # Update TableChoiceIntCtrl post_command_event(self.main_window, self.ResizeGridMsg, shape=shape) # Change grid table dimensions self.grid.GetTable().ResetView() # Clear caches self.code_array.result_cache.clear()
[ "def", "change_grid_shape", "(", "self", ",", "shape", ")", ":", "# Mark content as changed", "post_command_event", "(", "self", ".", "main_window", ",", "self", ".", "ContentChangedMsg", ")", "self", ".", "code_array", ".", "shape", "=", "shape", "# Update TableC...
Grid shape change event handler, marks content as changed
[ "Grid", "shape", "change", "event", "handler", "marks", "content", "as", "changed" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L1007-L1022
train
231,494
manns/pyspread
pyspread/src/actions/_grid_actions.py
TableActions.replace_cells
def replace_cells(self, key, sorted_row_idxs): """Replaces cells in current selection so that they are sorted""" row, col, tab = key new_keys = {} del_keys = [] selection = self.grid.actions.get_selection() for __row, __col, __tab in self.grid.code_array: if __tab == tab and \ (not selection or (__row, __col) in selection): new_row = sorted_row_idxs.index(__row) if __row != new_row: new_keys[(new_row, __col, __tab)] = \ self.grid.code_array((__row, __col, __tab)) del_keys.append((__row, __col, __tab)) for key in del_keys: self.grid.code_array.pop(key) for key in new_keys: CellActions.set_code(self, key, new_keys[key])
python
def replace_cells(self, key, sorted_row_idxs): """Replaces cells in current selection so that they are sorted""" row, col, tab = key new_keys = {} del_keys = [] selection = self.grid.actions.get_selection() for __row, __col, __tab in self.grid.code_array: if __tab == tab and \ (not selection or (__row, __col) in selection): new_row = sorted_row_idxs.index(__row) if __row != new_row: new_keys[(new_row, __col, __tab)] = \ self.grid.code_array((__row, __col, __tab)) del_keys.append((__row, __col, __tab)) for key in del_keys: self.grid.code_array.pop(key) for key in new_keys: CellActions.set_code(self, key, new_keys[key])
[ "def", "replace_cells", "(", "self", ",", "key", ",", "sorted_row_idxs", ")", ":", "row", ",", "col", ",", "tab", "=", "key", "new_keys", "=", "{", "}", "del_keys", "=", "[", "]", "selection", "=", "self", ".", "grid", ".", "actions", ".", "get_selec...
Replaces cells in current selection so that they are sorted
[ "Replaces", "cells", "in", "current", "selection", "so", "that", "they", "are", "sorted" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L1024-L1047
train
231,495
manns/pyspread
pyspread/src/actions/_grid_actions.py
GridActions.new
def new(self, event): """Creates a new spreadsheet. Expects code_array in event.""" # Grid table handles interaction to code_array self.grid.actions.clear(event.shape) _grid_table = GridTable(self.grid, self.grid.code_array) self.grid.SetTable(_grid_table, True) # Update toolbars self.grid.update_entry_line() self.grid.update_attribute_toolbar()
python
def new(self, event): """Creates a new spreadsheet. Expects code_array in event.""" # Grid table handles interaction to code_array self.grid.actions.clear(event.shape) _grid_table = GridTable(self.grid, self.grid.code_array) self.grid.SetTable(_grid_table, True) # Update toolbars self.grid.update_entry_line() self.grid.update_attribute_toolbar()
[ "def", "new", "(", "self", ",", "event", ")", ":", "# Grid table handles interaction to code_array", "self", ".", "grid", ".", "actions", ".", "clear", "(", "event", ".", "shape", ")", "_grid_table", "=", "GridTable", "(", "self", ".", "grid", ",", "self", ...
Creates a new spreadsheet. Expects code_array in event.
[ "Creates", "a", "new", "spreadsheet", ".", "Expects", "code_array", "in", "event", "." ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L1098-L1110
train
231,496
manns/pyspread
pyspread/src/actions/_grid_actions.py
GridActions._zoom_rows
def _zoom_rows(self, zoom): """Zooms grid rows""" self.grid.SetDefaultRowSize(self.grid.std_row_size * zoom, resizeExistingRows=True) self.grid.SetRowLabelSize(self.grid.row_label_size * zoom) for row, tab in self.code_array.row_heights: if tab == self.grid.current_table and \ row < self.grid.code_array.shape[0]: base_row_width = self.code_array.row_heights[(row, tab)] if base_row_width is None: base_row_width = self.grid.GetDefaultRowSize() zoomed_row_size = base_row_width * zoom self.grid.SetRowSize(row, zoomed_row_size)
python
def _zoom_rows(self, zoom): """Zooms grid rows""" self.grid.SetDefaultRowSize(self.grid.std_row_size * zoom, resizeExistingRows=True) self.grid.SetRowLabelSize(self.grid.row_label_size * zoom) for row, tab in self.code_array.row_heights: if tab == self.grid.current_table and \ row < self.grid.code_array.shape[0]: base_row_width = self.code_array.row_heights[(row, tab)] if base_row_width is None: base_row_width = self.grid.GetDefaultRowSize() zoomed_row_size = base_row_width * zoom self.grid.SetRowSize(row, zoomed_row_size)
[ "def", "_zoom_rows", "(", "self", ",", "zoom", ")", ":", "self", ".", "grid", ".", "SetDefaultRowSize", "(", "self", ".", "grid", ".", "std_row_size", "*", "zoom", ",", "resizeExistingRows", "=", "True", ")", "self", ".", "grid", ".", "SetRowLabelSize", ...
Zooms grid rows
[ "Zooms", "grid", "rows" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L1114-L1128
train
231,497
manns/pyspread
pyspread/src/actions/_grid_actions.py
GridActions._zoom_cols
def _zoom_cols(self, zoom): """Zooms grid columns""" self.grid.SetDefaultColSize(self.grid.std_col_size * zoom, resizeExistingCols=True) self.grid.SetColLabelSize(self.grid.col_label_size * zoom) for col, tab in self.code_array.col_widths: if tab == self.grid.current_table and \ col < self.grid.code_array.shape[1]: base_col_width = self.code_array.col_widths[(col, tab)] if base_col_width is None: base_col_width = self.grid.GetDefaultColSize() zoomed_col_size = base_col_width * zoom self.grid.SetColSize(col, zoomed_col_size)
python
def _zoom_cols(self, zoom): """Zooms grid columns""" self.grid.SetDefaultColSize(self.grid.std_col_size * zoom, resizeExistingCols=True) self.grid.SetColLabelSize(self.grid.col_label_size * zoom) for col, tab in self.code_array.col_widths: if tab == self.grid.current_table and \ col < self.grid.code_array.shape[1]: base_col_width = self.code_array.col_widths[(col, tab)] if base_col_width is None: base_col_width = self.grid.GetDefaultColSize() zoomed_col_size = base_col_width * zoom self.grid.SetColSize(col, zoomed_col_size)
[ "def", "_zoom_cols", "(", "self", ",", "zoom", ")", ":", "self", ".", "grid", ".", "SetDefaultColSize", "(", "self", ".", "grid", ".", "std_col_size", "*", "zoom", ",", "resizeExistingCols", "=", "True", ")", "self", ".", "grid", ".", "SetColLabelSize", ...
Zooms grid columns
[ "Zooms", "grid", "columns" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L1130-L1144
train
231,498
manns/pyspread
pyspread/src/actions/_grid_actions.py
GridActions._zoom_labels
def _zoom_labels(self, zoom): """Adjust grid label font to zoom factor""" labelfont = self.grid.GetLabelFont() default_fontsize = get_default_font().GetPointSize() labelfont.SetPointSize(max(1, int(round(default_fontsize * zoom)))) self.grid.SetLabelFont(labelfont)
python
def _zoom_labels(self, zoom): """Adjust grid label font to zoom factor""" labelfont = self.grid.GetLabelFont() default_fontsize = get_default_font().GetPointSize() labelfont.SetPointSize(max(1, int(round(default_fontsize * zoom)))) self.grid.SetLabelFont(labelfont)
[ "def", "_zoom_labels", "(", "self", ",", "zoom", ")", ":", "labelfont", "=", "self", ".", "grid", ".", "GetLabelFont", "(", ")", "default_fontsize", "=", "get_default_font", "(", ")", ".", "GetPointSize", "(", ")", "labelfont", ".", "SetPointSize", "(", "m...
Adjust grid label font to zoom factor
[ "Adjust", "grid", "label", "font", "to", "zoom", "factor" ]
0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0
https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/actions/_grid_actions.py#L1146-L1152
train
231,499