INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Return kwargs dict for text | def get_kwargs(self):
"""Return kwargs dict for text"""
kwargs = {}
if self.font_face:
kwargs["fontname"] = repr(self.font_face)
if self.font_size:
kwargs["fontsize"] = repr(self.font_size)
if self.font_style in self.style_wx2mpl:
kwargs["fon... |
Sets widget from kwargs string
Parameters
----------
code: String
\tCode representation of kwargs value | def set_kwargs(self, code):
"""Sets widget from kwargs string
Parameters
----------
code: String
\tCode representation of kwargs value
"""
kwargs = {}
kwarglist = list(parse_dict_strings(code[1:-1]))
for kwarg, val in zip(kwarglist[::2], kwarg... |
Check event handler | 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 ... |
Binds events to handlers | def __bindings(self):
"""Binds events to handlers"""
self.direction_choicectrl.Bind(wx.EVT_CHOICE, self.OnDirectionChoice)
self.sec_checkboxctrl.Bind(wx.EVT_CHECKBOX, self.OnSecondaryCheckbox)
self.pad_intctrl.Bind(EVT_INT, self.OnPadIntCtrl)
self.labelsize_intctrl.Bind(EVT_INT,... |
Return kwargs dict for text | def get_kwargs(self):
"""Return kwargs dict for text"""
kwargs = {}
for attr in self.attrs:
val = self.attrs[attr]
if val is not None:
kwargs[attr] = repr(val)
code = ", ".join(repr(key) + ": " + kwargs[key] for key in kwargs)
code = "{... |
Direction choice event handler | 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) |
Top Checkbox event handler | def OnSecondaryCheckbox(self, event):
"""Top Checkbox event handler"""
self.attrs["top"] = event.IsChecked()
self.attrs["right"] = event.IsChecked()
post_command_event(self, self.DrawChartMsg) |
Pad IntCtrl event handler | def OnPadIntCtrl(self, event):
"""Pad IntCtrl event handler"""
self.attrs["pad"] = event.GetValue()
post_command_event(self, self.DrawChartMsg) |
Label size IntCtrl event handler | def OnLabelSizeIntCtrl(self, event):
"""Label size IntCtrl event handler"""
self.attrs["labelsize"] = event.GetValue()
post_command_event(self, self.DrawChartMsg) |
Returns code representation of value of widget | 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] |
Sets widget from code string
Parameters
----------
code: String
\tCode representation of widget value | def set_code(self, code):
"""Sets widget from code string
Parameters
----------
code: String
\tCode representation of widget value
"""
for i, (_, style_code) in enumerate(self.styles):
if code == style_code:
self.SetSelection(i) |
Updates self.data from series data
Parameters
----------
* series_data: dict
\tKey value pairs for self.data, which correspond to chart attributes | 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(s... |
Returns current 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) |
Sets 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) |
Binds events to handlers | def __bindings(self):
"""Binds events to handlers"""
self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnSeriesChanged)
self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.OnSeriesDeleted) |
Updates widget content from series_list
Parameters
----------
series_list: List of dict
\tList of dicts with data from all series | 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), _("+"))
... |
FlatNotebook change event handler | 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"})
... |
Updates figure on data change
Parameters
----------
* figure: matplotlib.figure.Figure
\tMatplotlib figure object that is displayed in self | 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()
sel... |
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 | 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 ... |
Update widgets from 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_stri... |
Returns code that generates figure from widgets | 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_dic... |
Redraw event handler for the figure panel | 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 |
Returns tuple of selection parameters of self
(self.block_tl, self.block_br, self.rows, self.cols, self.cells) | 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 |
Inserts number of rows/cols/tabs into selection at point on axis
Parameters
----------
point: Integer
\tAt this point the rows/cols are inserted or deleted
number: Integer
\tNumber of rows/cols to be inserted, negative number deletes
axis: Integer in 0, 1
... | def insert(self, point, number, axis):
"""Inserts number of rows/cols/tabs into selection at point on axis
Parameters
----------
point: Integer
\tAt this point the rows/cols are inserted or deleted
number: Integer
\tNumber of rows/cols to be inserted, negative nu... |
Returns ((top, left), (bottom, right)) of bounding box
A bounding box is the smallest rectangle that contains all selections.
Non-specified boundaries are None. | def get_bbox(self):
"""Returns ((top, left), (bottom, right)) of bounding box
A bounding box is the smallest rectangle that contains all selections.
Non-specified boundaries are None.
"""
bb_top, bb_left, bb_bottom, bb_right = [None] * 4
# Block selections
fo... |
Returns ((top, left), (bottom, right)) of bounding box
A bounding box is the smallest rectangle that contains all selections.
Non-specified boundaries are filled i from size.
Parameters
----------
shape: 3-Tuple of Integer
\tGrid shape | def get_grid_bbox(self, shape):
"""Returns ((top, left), (bottom, right)) of bounding box
A bounding box is the smallest rectangle that contains all selections.
Non-specified boundaries are filled i from size.
Parameters
----------
shape: 3-Tuple of Integer
\tG... |
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 | 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.... |
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
... | 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 ... |
Selects cells of grid with selection content | 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)
f... |
Modify traceback to only include the user code's execution frame
Always call in this fashion:
e = sys.exc_info()
user_tb = get_user_codeframe(e[2]) or e[2]
so that you can get the original frame back if you need to
(this is necessary because copying traceback objects is tricky and
this i... | def get_user_codeframe(tb):
"""Modify traceback to only include the user code's execution frame
Always call in this fashion:
e = sys.exc_info()
user_tb = get_user_codeframe(e[2]) or e[2]
so that you can get the original frame back if you need to
(this is necessary because copying traceba... |
Returns code for widget from dict object | 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 |
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 | 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 *= fl... |
Returns svg from matplotlib chart | 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 |
Sets up axes for drawing chart | 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)... |
Makes x axis a date axis with auto format
Parameters
----------
xdate_format: String
\tSets date formatting | 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.
... |
Plots chart from self.attributes | 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)
... |
Return the source string of a cell | 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 |
Return the result value of a cell, line split if too much data | 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
... |
Set the value of a cell, merge line breaks | 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)
... |
Update all displayed values | 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) |
(Grid) -> Reset the grid view. Call this to
update the grid if rows and columns have been added or deleted | def ResetView(self):
"""
(Grid) -> Reset the grid view. Call this to
update the grid if rows and columns have been added or deleted
"""
grid = self.grid
current_rows = self.grid.GetNumberRows()
current_cols = self.grid.GetNumberCols()
grid.BeginBatch... |
Posts command event to main window
Command events propagate.
Parameters
----------
* msg_cls: class
\tMessage class from new_command_event()
* kwargs: dict
\tMessage arguments | 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.Po... |
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 | 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
\tSep... |
Returns the clipboard content
If a bitmap is contained then it is returned.
Otherwise, the clipboard text is returned. | 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_p... |
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 | 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_l... |
Draws a 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) |
Draws bitmap | def draw_bmp(bmp_filepath):
"""Draws bitmap"""
def draw(grid, attr, dc, rect):
bmp = wx.EmptyBitmap(100, 100)
try:
dummy = open(bmp_filepath)
dummy.close()
bmp.LoadFile(bmp_filepath, wx.BITMAP_TYPE_ANY)
dc.DrawBitmap(bmp, 0, 0)
except:
return
return draw |
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
... | 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_... |
Returns True if a valid signature is present for filename | 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:
# Sig... |
Leaves 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) |
Sets safe mode if signature missing of invalid | 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_s... |
Clears globals and reloads 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() |
Returns infile version string. | 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:... |
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 cont... | 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
\tTarg... |
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 | 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
... |
Signs file if possible | 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
... |
Sets application save states | def _set_save_states(self):
"""Sets application save states"""
wx.BeginBusyCursor()
self.saving = True
self.grid.Disable() |
Releases application 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:
... |
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 | 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:
... |
Saves file as xls workbook
Parameters
----------
filepath: String
\tTarget file path for xls file | 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_arra... |
Saves file as pys file and returns True if save success
Parameters
----------
filepath: String
\tTarget file path for xls file | 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_... |
Sign so that the new file may be retrieved without safe mode | 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,
... |
Saves a file that is specified in event.attr
Parameters
----------
event.attr: Dict
\tkey filepath contains file path of file to be saved | 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"]... |
Sets row height and marks grid as changed | 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.SetRow... |
Adds no_rows rows before row, appends if row > maxrows
and marks grid as changed | 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... |
Deletes no_rows rows and marks grid as changed | 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=ta... |
Sets column width and marks grid as changed | 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.SetColSi... |
Adds no_cols columns before col, appends if col > maxcols
and marks grid as changed | 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_ar... |
Deletes no_cols column and marks grid as changed | 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=... |
Adds no_tabs tabs before table, appends if tab > maxtabs
and marks grid as changed | 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)
... |
Deletes no_tabs tabs and marks grid as changed | 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
... |
Sets abort if pasting and if escape is pressed | 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(... |
Returns full key even if table is omitted | 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... |
Aborts import | def _abort_paste(self):
"""Aborts import"""
statustext = _("Paste aborted.")
post_command_event(self.main_window, self.StatusBarMsg,
text=statustext)
self.pasting = False
self.need_abort = False |
Displays overflow message after import in statusbar | 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:... |
Show actually pasted number of cells | 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)
... |
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
\... | 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 itera... |
Generator that yields data for selection paste | 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 - ... |
Pastes data into grid 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_curre... |
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... | 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.
... |
Grid shape change event handler, marks content as changed | 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.... |
Replaces cells in current selection so that they are sorted | 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:
... |
Sorts selection (or grid if none) corresponding to column of key | def sort_ascending(self, key):
"""Sorts selection (or grid if none) corresponding to column of key"""
row, col, tab = key
scells = self.grid.code_array[:, col, tab]
def sorter(i):
sorted_ele = scells[i]
return sorted_ele is None, sorted_ele
sorted_row_... |
Sorts inversely selection (or grid if none)
corresponding to column of key | def sort_descending(self, key):
"""Sorts inversely selection (or grid if none)
corresponding to column of key
"""
row, col, tab = key
scells = self.grid.code_array[:, col, tab]
sorted_row_idxs = sorted(xrange(len(scells)), key=scells.__getitem__)
sorted_row_id... |
Creates a new spreadsheet. Expects code_array in event. | 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)
# Upd... |
Zooms grid 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:
... |
Zooms grid columns | 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:
... |
Adjust grid label font to zoom factor | 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) |
Zooms to zoom factor | def zoom(self, zoom=None):
"""Zooms to zoom factor"""
status = True
if zoom is None:
zoom = self.grid.grid_renderer.zoom
status = False
# Zoom factor for grid content
self.grid.grid_renderer.zoom = zoom
# Zoom grid labels
self._zoom_lab... |
Zooms in by zoom factor | def zoom_in(self):
"""Zooms in by zoom factor"""
zoom = self.grid.grid_renderer.zoom
target_zoom = zoom * (1 + config["zoom_factor"])
if target_zoom < config["maximum_zoom"]:
self.zoom(target_zoom) |
Zooms out by zoom factor | def zoom_out(self):
"""Zooms out by zoom factor"""
zoom = self.grid.grid_renderer.zoom
target_zoom = zoom * (1 - config["zoom_factor"])
if target_zoom > config["minimum_zoom"]:
self.zoom(target_zoom) |
Returns the total height of all grid rows | def _get_rows_height(self):
"""Returns the total height of all grid rows"""
tab = self.grid.current_table
no_rows = self.grid.code_array.shape[0]
default_row_height = self.grid.code_array.cell_attributes.\
default_cell_attributes["row-height"]
non_standard_row_heigh... |
Returns the total width of all grid cols | def _get_cols_width(self):
"""Returns the total width of all grid cols"""
tab = self.grid.current_table
no_cols = self.grid.code_array.shape[1]
default_col_width = self.grid.code_array.cell_attributes.\
default_cell_attributes["column-width"]
non_standard_col_widths... |
Displays cell code of cell key in status bar | def on_mouse_over(self, key):
"""Displays cell code of cell key in status bar"""
def split_lines(string, line_length=80):
"""Returns string that is split into lines of length line_length"""
result = u""
line = 0
while len(string) > line_length * line:
... |
Zooms the rid to fit the window.
Only has an effect if the resulting zoom level is between
minimum and maximum zoom level. | def zoom_fit(self):
"""Zooms the rid to fit the window.
Only has an effect if the resulting zoom level is between
minimum and maximum zoom level.
"""
zoom = self.grid.grid_renderer.zoom
grid_width, grid_height = self.grid.GetSize()
rows_height = self._get_row... |
Returns visible area
Format is a tuple of the top left tuple and the lower right tuple | def get_visible_area(self):
"""Returns visible area
Format is a tuple of the top left tuple and the lower right tuple
"""
grid = self.grid
top = grid.YToRow(grid.GetViewStart()[1] * grid.ScrollLineX)
left = grid.XToCol(grid.GetViewStart()[0] * grid.ScrollLineY)
... |
Switches grid to table
Parameters
----------
event.newtable: Integer
\tTable that the grid is switched to | def switch_to_table(self, event):
"""Switches grid to table
Parameters
----------
event.newtable: Integer
\tTable that the grid is switched to
"""
newtable = event.newtable
no_tabs = self.grid.code_array.shape[2] - 1
if 0 <= newtable <= no_ta... |
Returns current grid cursor cell (row, col, tab) | def get_cursor(self):
"""Returns current grid cursor cell (row, col, tab)"""
return self.grid.GetGridCursorRow(), self.grid.GetGridCursorCol(), \
self.grid.current_table |
Changes the grid cursor cell.
Parameters
----------
value: 2-tuple or 3-tuple of String
\trow, col, tab or row, col for target cursor position | def set_cursor(self, value):
"""Changes the grid cursor cell.
Parameters
----------
value: 2-tuple or 3-tuple of String
\trow, col, tab or row, col for target cursor position
"""
shape = self.grid.code_array.shape
if len(value) == 3:
self.... |
Returns selected cells in grid as Selection object | def get_selection(self):
"""Returns selected cells in grid as Selection object"""
# GetSelectedCells: individual cells selected by ctrl-clicking
# GetSelectedRows: rows selected by clicking on the labels
# GetSelectedCols: cols selected by clicking on the labels
# GetSelectionBl... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.