INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Returns wx.Pen from pendata attribute list
def get_pen_from_data(pendata): """Returns wx.Pen from pendata attribute list""" pen_color = wx.Colour() pen_color.SetRGB(pendata[0]) pen = wx.Pen(pen_color, *pendata[1:]) pen.SetJoin(wx.JOIN_MITER) return pen
Returns wx.Colour from a string of a 3-tuple of floats in [0.0, 1.0]
def code2color(color_string): """Returns wx.Colour from a string of a 3-tuple of floats in [0.0, 1.0]""" color_tuple = ast.literal_eval(color_string) color_tuple_int = map(lambda x: int(x * 255.0), color_tuple) return wx.Colour(*color_tuple_int)
Returns r, g, b tuple from packed wx.ColourGetRGB value
def color_pack2rgb(packed): """Returns r, g, b tuple from packed wx.ColourGetRGB value""" r = packed & 255 g = (packed & (255 << 8)) >> 8 b = (packed & (255 << 16)) >> 16 return r, g, b
Returns a string from code that contains a repr of the string
def unquote_string(code): """Returns a string from code that contains a repr of the string""" scode = code.strip() assert scode[-1] in ["'", '"'] assert scode[0] in ["'", '"'] or scode[1] in ["'", '"'] return ast.literal_eval(scode)
Generator of elements of a dict that is given in the code string Parsing is shallow, i.e. all content is yielded as strings Parameters ---------- code: String \tString that contains a dict
def parse_dict_strings(code): """Generator of elements of a dict that is given in the code string Parsing is shallow, i.e. all content is yielded as strings Parameters ---------- code: String \tString that contains a dict """ i = 0 level = 0 chunk_start = 0 curr_paren = N...
Returns start sub-string that is common for all given strings Parameters ---------- strings: List of strings \tThese strings are evaluated for their largest common start string
def common_start(strings): """Returns start sub-string that is common for all given strings Parameters ---------- strings: List of strings \tThese strings are evaluated for their largest common start string """ def gen_start_strings(string): """Generator that yield start sub-strin...
Checks if code is an svg image Parameters ---------- code: String \tCode to be parsed in order to check svg complaince
def is_svg(code): """Checks if code is an svg image Parameters ---------- code: String \tCode to be parsed in order to check svg complaince """ if rsvg is None: return try: rsvg.Handle(data=code) except glib.GError: return False # The SVG file has to...
Returns title string
def _get_dialog_title(self): """Returns title string""" title_filetype = self.filetype[0].upper() + self.filetype[1:] if self.filetype == "print": title_export = "" else: title_export = " export" return _("{filetype}{export} options").format(filetype=ti...
Page layout choice event handler
def on_page_layout_choice(self, event): """Page layout choice event handler""" width, height = self.paper_sizes_points[event.GetString()] self.page_width_text_ctrl.SetValue(str(width / 72.0)) self.page_height_text_ctrl.SetValue(str(height / 72.0)) event.Skip()
Returns a dict with the dialog PDF info Dict keys are: top_row, bottom_row, left_col, right_col, first_tab, last_tab, paper_width, paper_height
def get_info(self): """Returns a dict with the dialog PDF info Dict keys are: top_row, bottom_row, left_col, right_col, first_tab, last_tab, paper_width, paper_height """ info = {} info["top_row"] = self.top_row_text_ctrl.GetValue() info["bottom_row"] ...
Returns the path in which pyspread is installed
def get_program_path(): """Returns the path in which pyspread is installed""" src_folder = os.path.dirname(__file__) program_path = os.sep.join(src_folder.split(os.sep)[:-1]) + os.sep return program_path
Returns screen dpi resolution
def get_dpi(): """Returns screen dpi resolution""" def pxmm_2_dpi((pixels, length_mm)): return pixels * 25.6 / length_mm return map(pxmm_2_dpi, zip(wx.GetDisplaySize(), wx.GetDisplaySizeMM()))
Returns a sorted list of all system font names
def get_font_list(): """Returns a sorted list of all system font names""" font_map = pangocairo.cairo_font_map_get_default() font_list = [f.get_name() for f in font_map.list_families()] font_list.sort() return font_list
Returns list of dicts which indicate installed dependencies
def get_dependencies(): """Returns list of dicts which indicate installed dependencies""" dependencies = [] # Numpy dep_attrs = { "name": "numpy", "min_version": "1.1.0", "description": "required", } try: import numpy dep_attrs["version"] = numpy.version...
Returns rectangle of cell on canvas
def get_cell_rect(self, row, col, tab): """Returns rectangle of cell on canvas""" top_row = self.row_tb[0] left_col = self.col_rl[0] pos_x = self.x_offset pos_y = self.y_offset merge_area = self._get_merge_area((row, col, tab)) for __row in xrange(top_row, row...
Draws slice to context
def draw(self): """Draws slice to context""" row_start, row_stop = self.row_tb col_start, col_stop = self.col_rl tab_start, tab_stop = self.tab_fl for tab in xrange(tab_start, tab_stop): # Scale context to page extent # In order to keep the aspect ration...
Draws cell to context
def draw(self): """Draws cell to context""" cell_background_renderer = GridCellBackgroundCairoRenderer( self.context, self.code_array, self.key, self.rect, self.view_frozen) cell_content_renderer = GridCellContentCairoRenderer( ...
Returns cell content
def get_cell_content(self): """Returns cell content""" try: if self.code_array.cell_attributes[self.key]["button_cell"]: return except IndexError: return try: return self.code_array[self.key] except IndexError: p...
Returns scale_x, scale_y for bitmap display
def _get_scalexy(self, ims_width, ims_height): """Returns scale_x, scale_y for bitmap display""" # Get cell attributes cell_attributes = self.code_array.cell_attributes[self.key] angle = cell_attributes["angle"] if abs(angle) == 90: scale_x = self.rect[3] / float(im...
Returns x and y for a bitmap translation
def _get_translation(self, ims_width, ims_height): """Returns x and y for a bitmap translation""" # Get cell attributes cell_attributes = self.code_array.cell_attributes[self.key] justification = cell_attributes["justification"] vertical_align = cell_attributes["vertical_align"]...
Draws bitmap cell content to context
def draw_bitmap(self, content): """Draws bitmap cell content to context""" if content.HasAlpha(): image = wx.ImageFromBitmap(content) image.ConvertAlphaToMask() image.SetMask(False) content = wx.BitmapFromImage(image) ims = wx.lib.wxcairo.ImageSu...
Draws svg string to cell
def draw_svg(self, svg_str): """Draws svg string to cell""" try: import rsvg except ImportError: self.draw_text(svg_str) return svg = rsvg.Handle(data=svg_str) svg_width, svg_height = svg.get_dimension_data()[:2] transx, transy = se...
Draws matplotlib figure to context
def draw_matplotlib_figure(self, figure): """Draws matplotlib figure to context""" class CustomRendererCairo(RendererCairo): """Workaround for older versins with limited draw path length""" if sys.byteorder == 'little': BYTE_FORMAT = 0 # BGRA else: ...
Returns text color rgb tuple of right line
def _get_text_color(self): """Returns text color rgb tuple of right line""" color = self.code_array.cell_attributes[self.key]["textcolor"] return tuple(c / 255.0 for c in color_pack2rgb(color))
Sets the font for draw_text
def set_font(self, pango_layout): """Sets the font for draw_text""" wx2pango_weights = { wx.FONTWEIGHT_BOLD: pango.WEIGHT_BOLD, wx.FONTWEIGHT_LIGHT: pango.WEIGHT_LIGHT, wx.FONTWEIGHT_NORMAL: None, # Do not set a weight by default } wx2pango_styles =...
Rotates and translates cell if angle in [90, -90, 180]
def _rotate_cell(self, angle, rect, back=False): """Rotates and translates cell if angle in [90, -90, 180]""" if angle == 90 and not back: self.context.rotate(-math.pi / 2.0) self.context.translate(-rect[2] + 4, 0) elif angle == 90 and back: self.context.tra...
Draws an error underline
def _draw_error_underline(self, ptx, pango_layout, start, stop): """Draws an error underline""" self.context.save() self.context.set_source_rgb(1.0, 0.0, 0.0) pit = pango_layout.get_iter() # Skip characters until start for i in xrange(start): pit.next_char(...
Returns a list of start stop tuples that have spelling errors Parameters ---------- text: Unicode or string \tThe text that is checked lang: String, defaults to "en_US" \tName of spell checking dictionary
def _check_spelling(self, text, lang="en_US"): """Returns a list of start stop tuples that have spelling errors Parameters ---------- text: Unicode or string \tThe text that is checked lang: String, defaults to "en_US" \tName of spell checking dictionary ...
Draws text cell content to context
def draw_text(self, content): """Draws text cell content to context""" wx2pango_alignment = { "left": pango.ALIGN_LEFT, "center": pango.ALIGN_CENTER, "right": pango.ALIGN_RIGHT, } cell_attributes = self.code_array.cell_attributes[self.key] a...
Draws a rounded rectangle
def draw_roundedrect(self, x, y, w, h, r=10): """Draws a rounded rectangle""" # A****BQ # H C # * * # G D # F****E context = self.context context.save context.move_to(x+r, y) # Move to A context.line_to(x+w-r, y) # Straight...
Draws a button
def draw_button(self, x, y, w, h, label): """Draws a button""" context = self.context self.draw_roundedrect(x, y, w, h) context.clip() # Set up the gradients gradient = cairo.LinearGradient(0, 0, 0, 1) gradient.add_color_stop_rgba(0, 0.5, 0.5, 0.5, 0.1) ...
Draws cell content to context
def draw(self): """Draws cell content to context""" # Content is only rendered within rect self.context.save() self.context.rectangle(*self.rect) self.context.clip() content = self.get_cell_content() pos_x, pos_y = self.rect[:2] self.context.translate(p...
Returns background color rgb tuple of right line
def _get_background_color(self): """Returns background color rgb tuple of right line""" color = self.cell_attributes[self.key]["bgcolor"] return tuple(c / 255.0 for c in color_pack2rgb(color))
Draws frozen pattern, i.e. diagonal lines
def _draw_frozen_pattern(self): """Draws frozen pattern, i.e. diagonal lines""" self.context.save() x, y, w, h = self.rect self.context.set_source_rgb(0, 0, 1) self.context.set_line_width(0.25) self.context.rectangle(*self.rect) self.context.clip() for ...
Draws self to Cairo context
def draw(self, context): """Draws self to Cairo context""" context.set_line_width(self.width) context.set_source_rgb(*self.color) context.move_to(*self.start_point) context.line_to(*self.end_point) context.stroke()
Draws cell background to context
def draw(self): """Draws cell background to context""" self.context.set_source_rgb(*self._get_background_color()) self.context.rectangle(*self.rect) self.context.fill() # If show frozen is active, show frozen pattern if self.view_frozen and self.cell_attributes[self.key...
Returns tuple key rect of above cell
def get_above_key_rect(self): """Returns tuple key rect of above cell""" key_above = self.row - 1, self.col, self.tab border_width_bottom = \ float(self.cell_attributes[key_above]["borderwidth_bottom"]) / 2.0 rect_above = (self.x, self.y-border_width_bottom, ...
Returns tuple key rect of below cell
def get_below_key_rect(self): """Returns tuple key rect of below cell""" key_below = self.row + 1, self.col, self.tab border_width_bottom = \ float(self.cell_attributes[self.key]["borderwidth_bottom"]) / 2.0 rect_below = (self.x, self.y+self.height, s...
Returns tuple key rect of left cell
def get_left_key_rect(self): """Returns tuple key rect of left cell""" key_left = self.row, self.col - 1, self.tab border_width_right = \ float(self.cell_attributes[key_left]["borderwidth_right"]) / 2.0 rect_left = (self.x-border_width_right, self.y, b...
Returns tuple key rect of right cell
def get_right_key_rect(self): """Returns tuple key rect of right cell""" key_right = self.row, self.col + 1, self.tab border_width_right = \ float(self.cell_attributes[self.key]["borderwidth_right"]) / 2.0 rect_right = (self.x+self.width, self.y, bord...
Returns tuple key rect of above left cell
def get_above_left_key_rect(self): """Returns tuple key rect of above left cell""" key_above_left = self.row - 1, self.col - 1, self.tab border_width_right = \ float(self.cell_attributes[key_above_left]["borderwidth_right"]) \ / 2.0 border_width_bottom = \ ...
Returns tuple key rect of above right cell
def get_above_right_key_rect(self): """Returns tuple key rect of above right cell""" key_above = self.row - 1, self.col, self.tab key_above_right = self.row - 1, self.col + 1, self.tab border_width_right = \ float(self.cell_attributes[key_above]["borderwidth_right"]) / 2.0 ...
Returns tuple key rect of below left cell
def get_below_left_key_rect(self): """Returns tuple key rect of below left cell""" key_left = self.row, self.col - 1, self.tab key_below_left = self.row + 1, self.col - 1, self.tab border_width_right = \ float(self.cell_attributes[key_below_left]["borderwidth_right"]) \ ...
Returns tuple key rect of below right cell
def get_below_right_key_rect(self): """Returns tuple key rect of below right cell""" key_below_right = self.row + 1, self.col + 1, self.tab border_width_right = \ float(self.cell_attributes[self.key]["borderwidth_right"]) / 2.0 border_width_bottom = \ float(self...
Returns start and stop coordinates of bottom line
def _get_bottom_line_coordinates(self): """Returns start and stop coordinates of bottom line""" rect_x, rect_y, rect_width, rect_height = self.rect start_point = rect_x, rect_y + rect_height end_point = rect_x + rect_width, rect_y + rect_height return start_point, end_point
Returns color rgb tuple of bottom line
def _get_bottom_line_color(self): """Returns color rgb tuple of bottom line""" color = self.cell_attributes[self.key]["bordercolor_bottom"] return tuple(c / 255.0 for c in color_pack2rgb(color))
Returns color rgb tuple of right line
def _get_right_line_color(self): """Returns color rgb tuple of right line""" color = self.cell_attributes[self.key]["bordercolor_right"] return tuple(c / 255.0 for c in color_pack2rgb(color))
Returns the bottom border of the cell
def get_b(self): """Returns the bottom border of the cell""" start_point, end_point = self._get_bottom_line_coordinates() width = self._get_bottom_line_width() color = self._get_bottom_line_color() return CellBorder(start_point, end_point, width, color)
Returns the right border of the cell
def get_r(self): """Returns the right border of the cell""" start_point, end_point = self._get_right_line_coordinates() width = self._get_right_line_width() color = self._get_right_line_color() return CellBorder(start_point, end_point, width, color)
Returns the top border of the cell
def get_t(self): """Returns the top border of the cell""" cell_above = CellBorders(self.cell_attributes, *self.cell.get_above_key_rect()) return cell_above.get_b()
Returns the left border of the cell
def get_l(self): """Returns the left border of the cell""" cell_left = CellBorders(self.cell_attributes, *self.cell.get_left_key_rect()) return cell_left.get_r()
Returns the top left border of the cell
def get_tl(self): """Returns the top left border of the cell""" cell_above_left = CellBorders(self.cell_attributes, *self.cell.get_above_left_key_rect()) return cell_above_left.get_r()
Returns the top right border of the cell
def get_tr(self): """Returns the top right border of the cell""" cell_above = CellBorders(self.cell_attributes, *self.cell.get_above_key_rect()) return cell_above.get_r()
Returns the right top border of the cell
def get_rt(self): """Returns the right top border of the cell""" cell_above_right = CellBorders(self.cell_attributes, *self.cell.get_above_right_key_rect()) return cell_above_right.get_b()
Returns the right bottom border of the cell
def get_rb(self): """Returns the right bottom border of the cell""" cell_right = CellBorders(self.cell_attributes, *self.cell.get_right_key_rect()) return cell_right.get_b()
Returns the bottom right border of the cell
def get_br(self): """Returns the bottom right border of the cell""" cell_below = CellBorders(self.cell_attributes, *self.cell.get_below_key_rect()) return cell_below.get_r()
Returns the bottom left border of the cell
def get_bl(self): """Returns the bottom left border of the cell""" cell_below_left = CellBorders(self.cell_attributes, *self.cell.get_below_left_key_rect()) return cell_below_left.get_r()
Returns the left bottom border of the cell
def get_lb(self): """Returns the left bottom border of the cell""" cell_left = CellBorders(self.cell_attributes, *self.cell.get_left_key_rect()) return cell_left.get_b()
Returns the left top border of the cell
def get_lt(self): """Returns the left top border of the cell""" cell_above_left = CellBorders(self.cell_attributes, *self.cell.get_above_left_key_rect()) return cell_above_left.get_b()
Generator of all borders
def gen_all(self): """Generator of all borders""" borderfuncs = [ self.get_b, self.get_r, self.get_t, self.get_l, self.get_tl, self.get_tr, self.get_rt, self.get_rb, self.get_br, self.get_bl, self.get_lb, self.get_lt, ] for borderfunc in borderfuncs:...
Draws cell border to context
def draw(self): """Draws cell border to context""" # Lines should have a square cap to avoid ugly edges self.context.set_line_cap(cairo.LINE_CAP_SQUARE) self.context.save() self.context.rectangle(*self.rect) self.context.clip() cell_borders = CellBorders(self.c...
Draws cursor as Rectangle in lower right corner
def _draw_cursor(self, dc, grid, row, col, pen=None, brush=None): """Draws cursor as Rectangle in lower right corner""" # If in full screen mode draw no cursor if grid.main_window.IsFullScreen(): return key = row, col, grid.current_table rect = ...
Whites out the old cursor and draws the new one
def update_cursor(self, dc, grid, row, col): """Whites out the old cursor and draws the new one""" old_row, old_col = self.old_cursor_row_col bgcolor = get_color(config["background_color"]) self._draw_cursor(dc, grid, old_row, old_col, pen=wx.Pen(bgcolor), br...
Returns cell rect for normal or merged cells and None for merged
def get_merged_rect(self, grid, key, rect): """Returns cell rect for normal or merged cells and None for merged""" row, col, tab = key # Check if cell is merged: cell_attributes = grid.code_array.cell_attributes merge_area = cell_attributes[(row, col, tab)]["merge_area"] ...
Replaces drawn rect if the one provided by wx is incorrect This handles merged rects including those that are partly off screen.
def _get_drawn_rect(self, grid, key, rect): """Replaces drawn rect if the one provided by wx is incorrect This handles merged rects including those that are partly off screen. """ rect = self.get_merged_rect(grid, key, rect) if rect is None: # Merged cell is drawn ...
Returns key for the screen draw cache
def _get_draw_cache_key(self, grid, key, drawn_rect, is_selected): """Returns key for the screen draw cache""" row, col, tab = key cell_attributes = grid.code_array.cell_attributes zoomed_width = drawn_rect.width / self.zoom zoomed_height = drawn_rect.height / self.zoom ...
Returns a wx.Bitmap of cell key in size rect
def _get_cairo_bmp(self, mdc, key, rect, is_selected, view_frozen): """Returns a wx.Bitmap of cell key in size rect""" bmp = wx.EmptyBitmap(rect.width, rect.height) mdc.SelectObject(bmp) mdc.SetBackgroundMode(wx.SOLID) mdc.SetBackground(wx.WHITE_BRUSH) mdc.Clear() ...
Draws the cell border and content using pycairo
def Draw(self, grid, attr, dc, rect, row, col, isSelected): """Draws the cell border and content using pycairo""" key = row, col, grid.current_table # If cell is merge draw the merging cell if invisibile if grid.code_array.cell_attributes[key]["merge_area"]: key = self.get_...
Displays gpg key choice and returns key
def choose_key(gpg_private_keys): """Displays gpg key choice and returns key""" uid_strings_fp = [] uid_string_fp2key = {} current_key_index = None for i, key in enumerate(gpg_private_keys): fingerprint = key['fingerprint'] if fingerprint == config["gpg_key_fingerprint"]: ...
Registers key in config
def _register_key(fingerprint, gpg): """Registers key in config""" for private_key in gpg.list_keys(True): try: if str(fingerprint) == private_key['fingerprint']: config["gpg_key_fingerprint"] = \ repr(private_key['fingerprint']) except KeyError: ...
Returns True iif gpg_secret_key has a password
def has_no_password(gpg_secret_keyid): """Returns True iif gpg_secret_key has a password""" if gnupg is None: return False gpg = gnupg.GPG() s = gpg.sign("", keyid=gpg_secret_keyid, passphrase="") try: return s.status == "signature created" except AttributeError: # Thi...
Creates a new standard GPG key Parameters ---------- ui: Bool \tIf True, then a new key is created when required without user interaction
def genkey(key_name=None): """Creates a new standard GPG key Parameters ---------- ui: Bool \tIf True, then a new key is created when required without user interaction """ if gnupg is None: return gpg_key_param_list = [ ('key_type', 'DSA'), ('key_length', '20...
Returns keyid from fingerprint for private keys
def fingerprint2keyid(fingerprint): """Returns keyid from fingerprint for private keys""" if gnupg is None: return gpg = gnupg.GPG() private_keys = gpg.list_keys(True) keyid = None for private_key in private_keys: if private_key['fingerprint'] == config["gpg_key_fingerprint"]:...
Returns detached signature for file
def sign(filename): """Returns detached signature for file""" if gnupg is None: return gpg = gnupg.GPG() with open(filename, "rb") as signfile: keyid = fingerprint2keyid(config["gpg_key_fingerprint"]) if keyid is None: msg = "No private key for GPG fingerprint '{}...
Verifies a signature, returns True if successful else False.
def verify(sigfilename, filefilename=None): """Verifies a signature, returns True if successful else False.""" if gnupg is None: return False gpg = gnupg.GPG() with open(sigfilename, "rb") as sigfile: verified = gpg.verify_file(sigfile, filefilename) pyspread_keyid = fingerpr...
Returns the length of the table cache
def _len_table_cache(self): """Returns the length of the table cache""" length = 0 for table in self._table_cache: length += len(self._table_cache[table]) return length
Clears and updates the table cache to be in sync with self
def _update_table_cache(self): """Clears and updates the table cache to be in sync with self""" self._table_cache.clear() for sel, tab, val in self: try: self._table_cache[tab].append((sel, val)) except KeyError: self._table_cache[tab] = [...
Returns key of cell that merges the cell key or None if cell key not merged Parameters ---------- key: 3-tuple of Integer \tThe key of the cell that is merged
def get_merging_cell(self, key): """Returns key of cell that merges the cell key or None if cell key not merged Parameters ---------- key: 3-tuple of Integer \tThe key of the cell that is merged """ row, col, tab = key # Is cell merged ...
Returns dict of data content. Keys ---- shape: 3-tuple of Integer \tGrid shape grid: Dict of 3-tuples to strings \tCell content attributes: List of 3-tuples \tCell attributes row_heights: Dict of 2-tuples to float \t(row, tab): row_height...
def _get_data(self): """Returns dict of data content. Keys ---- shape: 3-tuple of Integer \tGrid shape grid: Dict of 3-tuples to strings \tCell content attributes: List of 3-tuples \tCell attributes row_heights: Dict of 2-tuples to float ...
Sets data from given parameters Old values are deleted. If a paremeter is not given, nothing is changed. Parameters ---------- shape: 3-tuple of Integer \tGrid shape grid: Dict of 3-tuples to strings \tCell content attributes: List of 3-tuples ...
def _set_data(self, **kwargs): """Sets data from given parameters Old values are deleted. If a paremeter is not given, nothing is changed. Parameters ---------- shape: 3-tuple of Integer \tGrid shape grid: Dict of 3-tuples to strings \tCell cont...
Returns row height
def get_row_height(self, row, tab): """Returns row height""" try: return self.row_heights[(row, tab)] except KeyError: return config["default_row_height"]
Returns column width
def get_col_width(self, col, tab): """Returns column width""" try: return self.col_widths[(col, tab)] except KeyError: return config["default_col_width"]
Deletes all cells beyond new shape and sets dict_grid shape Parameters ---------- shape: 3-tuple of Integer \tTarget shape for grid
def _set_shape(self, shape): """Deletes all cells beyond new shape and sets dict_grid shape Parameters ---------- shape: 3-tuple of Integer \tTarget shape for grid """ # Delete each cell that is beyond new borders old_shape = self.shape deleted...
Returns key for the bottommost rightmost cell with content Parameters ---------- table: Integer, defaults to None \tLimit search to this table
def get_last_filled_cell(self, table=None): """Returns key for the bottommost rightmost cell with content Parameters ---------- table: Integer, defaults to None \tLimit search to this table """ maxrow = 0 maxcol = 0 for row, col, tab in self.di...
Generator traversing cells specified in key Parameters ---------- key: Iterable of Integer or slice \tThe key specifies the cell keys of the generator
def cell_array_generator(self, key): """Generator traversing cells specified in key Parameters ---------- key: Iterable of Integer or slice \tThe key specifies the cell keys of the generator """ for i, key_ele in enumerate(key): # Get first element...
Shifts row and column sizes when a table is inserted or deleted
def _shift_rowcol(self, insertion_point, no_to_insert): """Shifts row and column sizes when a table is inserted or deleted""" # Shift row heights new_row_heights = {} del_row_heights = [] for row, tab in self.row_heights: if tab > insertion_point: n...
Adjusts row and column sizes on insertion/deletion
def _adjust_rowcol(self, insertion_point, no_to_insert, axis, tab=None): """Adjusts row and column sizes on insertion/deletion""" if axis == 2: self._shift_rowcol(insertion_point, no_to_insert) return assert axis in (0, 1) cell_sizes = self.col_widths if axis e...
Returns updated merge area Parameters ---------- attrs: Dict \tCell attribute dictionary that shall be adjusted insertion_point: Integer \tPont on axis, before which insertion takes place no_to_insert: Integer >= 0 \tNumber of rows/cols/tabs that shall be...
def _get_adjusted_merge_area(self, attrs, insertion_point, no_to_insert, axis): """Returns updated merge area Parameters ---------- attrs: Dict \tCell attribute dictionary that shall be adjusted insertion_point: Integer \tPont on ...
Adjusts cell attributes on insertion/deletion Parameters ---------- insertion_point: Integer \tPont on axis, before which insertion takes place no_to_insert: Integer >= 0 \tNumber of rows/cols/tabs that shall be inserted axis: Integer in range(3) \tSpecif...
def _adjust_cell_attributes(self, insertion_point, no_to_insert, axis, tab=None, cell_attrs=None): """Adjusts cell attributes on insertion/deletion Parameters ---------- insertion_point: Integer \tPont on axis, before which insertion takes place ...
Inserts no_to_insert rows/cols/tabs/... before insertion_point Parameters ---------- insertion_point: Integer \tPont on axis, before which insertion takes place no_to_insert: Integer >= 0 \tNumber of rows/cols/tabs that shall be inserted axis: Integer \t...
def insert(self, insertion_point, no_to_insert, axis, tab=None): """Inserts no_to_insert rows/cols/tabs/... before insertion_point Parameters ---------- insertion_point: Integer \tPont on axis, before which insertion takes place no_to_insert: Integer >= 0 \tNumb...
Deletes no_to_delete rows/cols/... starting with deletion_point Axis specifies number of dimension, i.e. 0 == row, 1 == col, 2 == tab
def delete(self, deletion_point, no_to_delete, axis, tab=None): """Deletes no_to_delete rows/cols/... starting with deletion_point Axis specifies number of dimension, i.e. 0 == row, 1 == col, 2 == tab """ if not 0 <= axis < len(self.shape): raise ValueError("Axis not in gr...
Sets row height
def set_row_height(self, row, tab, height): """Sets row height""" try: old_height = self.row_heights.pop((row, tab)) except KeyError: old_height = None if height is not None: self.row_heights[(row, tab)] = float(height)
Sets column width
def set_col_width(self, col, tab, width): """Sets column width""" try: old_width = self.col_widths.pop((col, tab)) except KeyError: old_width = None if width is not None: self.col_widths[(col, tab)] = float(width)
Returns position of 1st char after assignment traget. If there is no assignment, -1 is returned If there are more than one of any ( expressions or assigments) then a ValueError is raised.
def _get_assignment_target_end(self, ast_module): """Returns position of 1st char after assignment traget. If there is no assignment, -1 is returned If there are more than one of any ( expressions or assigments) then a ValueError is raised. """ if len(ast_module.body)...
Makes nested list from generator for creating numpy.array
def _make_nested_list(self, gen): """Makes nested list from generator for creating numpy.array""" res = [] for ele in gen: if ele is None: res.append(None) elif not is_string_like(ele) and is_generator_like(ele): # Nested generator ...
Returns globals environment with 'magic' variable Parameters ---------- env_dict: Dict, defaults to {'S': self} \tDict that maps global variable name to value
def _get_updated_environment(self, env_dict=None): """Returns globals environment with 'magic' variable Parameters ---------- env_dict: Dict, defaults to {'S': self} \tDict that maps global variable name to value """ if env_dict is None: env_dict = ...
Evaluates one cell and returns its result
def _eval_cell(self, key, code): """Evaluates one cell and returns its result""" # Flatten helper function def nn(val): """Returns flat numpy arraz without None values""" try: return numpy.array(filter(None, val.flat)) except AttributeError: ...
Pops dict_grid with undo and redo support Parameters ---------- key: 3-tuple of Integer \tCell key that shall be popped
def pop(self, key): """Pops dict_grid with undo and redo support Parameters ---------- key: 3-tuple of Integer \tCell key that shall be popped """ try: self.result_cache.pop(repr(key)) except KeyError: pass return DataA...
Reloads modules that are available in cells
def reload_modules(self): """Reloads modules that are available in cells""" import src.lib.charts as charts from src.gui.grid_panels import vlcpanel_factory modules = [charts, bz2, base64, re, ast, sys, wx, numpy, datetime] for module in modules: reload(module)
Clears all newly assigned globals
def clear_globals(self): """Clears all newly assigned globals""" base_keys = ['cStringIO', 'IntType', 'KeyValueStore', 'undoable', 'is_generator_like', 'is_string_like', 'bz2', 'base64', '__package__', 're', 'config', '__doc__', 'SliceType', ...