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/lib/parsers.py | common_start | 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-strings of length 1, 2, ..."""
for i in xrange(1, len(string) + 1):
yield string[:i]
# Empty strings list
if not strings:
return ""
start_string = ""
# Get sucessively start string of 1st string
for start_string in gen_start_strings(max(strings)):
if not all(string.startswith(start_string) for string in strings):
return start_string[:-1]
return start_string | python | 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-strings of length 1, 2, ..."""
for i in xrange(1, len(string) + 1):
yield string[:i]
# Empty strings list
if not strings:
return ""
start_string = ""
# Get sucessively start string of 1st string
for start_string in gen_start_strings(max(strings)):
if not all(string.startswith(start_string) for string in strings):
return start_string[:-1]
return start_string | [
"def",
"common_start",
"(",
"strings",
")",
":",
"def",
"gen_start_strings",
"(",
"string",
")",
":",
"\"\"\"Generator that yield start sub-strings of length 1, 2, ...\"\"\"",
"for",
"i",
"in",
"xrange",
"(",
"1",
",",
"len",
"(",
"string",
")",
"+",
"1",
")",
":",
"yield",
"string",
"[",
":",
"i",
"]",
"# Empty strings list",
"if",
"not",
"strings",
":",
"return",
"\"\"",
"start_string",
"=",
"\"\"",
"# Get sucessively start string of 1st string",
"for",
"start_string",
"in",
"gen_start_strings",
"(",
"max",
"(",
"strings",
")",
")",
":",
"if",
"not",
"all",
"(",
"string",
".",
"startswith",
"(",
"start_string",
")",
"for",
"string",
"in",
"strings",
")",
":",
"return",
"start_string",
"[",
":",
"-",
"1",
"]",
"return",
"start_string"
] | Returns start sub-string that is common for all given strings
Parameters
----------
strings: List of strings
\tThese strings are evaluated for their largest common start string | [
"Returns",
"start",
"sub",
"-",
"string",
"that",
"is",
"common",
"for",
"all",
"given",
"strings"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/parsers.py#L159-L186 | train | 231,600 |
manns/pyspread | pyspread/src/lib/parsers.py | is_svg | 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 refer to its xmlns
# Hopefully, it does so wiyhin the first 1000 characters
if "http://www.w3.org/2000/svg" in code[:1000]:
return True
return False | python | 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 refer to its xmlns
# Hopefully, it does so wiyhin the first 1000 characters
if "http://www.w3.org/2000/svg" in code[:1000]:
return True
return False | [
"def",
"is_svg",
"(",
"code",
")",
":",
"if",
"rsvg",
"is",
"None",
":",
"return",
"try",
":",
"rsvg",
".",
"Handle",
"(",
"data",
"=",
"code",
")",
"except",
"glib",
".",
"GError",
":",
"return",
"False",
"# The SVG file has to refer to its xmlns",
"# Hopefully, it does so wiyhin the first 1000 characters",
"if",
"\"http://www.w3.org/2000/svg\"",
"in",
"code",
"[",
":",
"1000",
"]",
":",
"return",
"True",
"return",
"False"
] | Checks if code is an svg image
Parameters
----------
code: String
\tCode to be parsed in order to check svg complaince | [
"Checks",
"if",
"code",
"is",
"an",
"svg",
"image"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/parsers.py#L189-L214 | train | 231,601 |
manns/pyspread | pyspread/src/gui/_cairo_export_dialog.py | CairoExportDialog._get_dialog_title | 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=title_filetype,
export=title_export) | python | 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=title_filetype,
export=title_export) | [
"def",
"_get_dialog_title",
"(",
"self",
")",
":",
"title_filetype",
"=",
"self",
".",
"filetype",
"[",
"0",
"]",
".",
"upper",
"(",
")",
"+",
"self",
".",
"filetype",
"[",
"1",
":",
"]",
"if",
"self",
".",
"filetype",
"==",
"\"print\"",
":",
"title_export",
"=",
"\"\"",
"else",
":",
"title_export",
"=",
"\" export\"",
"return",
"_",
"(",
"\"{filetype}{export} options\"",
")",
".",
"format",
"(",
"filetype",
"=",
"title_filetype",
",",
"export",
"=",
"title_export",
")"
] | Returns title string | [
"Returns",
"title",
"string"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_cairo_export_dialog.py#L118-L129 | train | 231,602 |
manns/pyspread | pyspread/src/gui/_cairo_export_dialog.py | CairoExportDialog.on_page_layout_choice | 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() | python | 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() | [
"def",
"on_page_layout_choice",
"(",
"self",
",",
"event",
")",
":",
"width",
",",
"height",
"=",
"self",
".",
"paper_sizes_points",
"[",
"event",
".",
"GetString",
"(",
")",
"]",
"self",
".",
"page_width_text_ctrl",
".",
"SetValue",
"(",
"str",
"(",
"width",
"/",
"72.0",
")",
")",
"self",
".",
"page_height_text_ctrl",
".",
"SetValue",
"(",
"str",
"(",
"height",
"/",
"72.0",
")",
")",
"event",
".",
"Skip",
"(",
")"
] | Page layout choice event handler | [
"Page",
"layout",
"choice",
"event",
"handler"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_cairo_export_dialog.py#L248-L255 | train | 231,603 |
manns/pyspread | pyspread/src/gui/_cairo_export_dialog.py | CairoExportDialog.get_info | 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"] = self.bottom_row_text_ctrl.GetValue()
info["left_col"] = self.left_col_text_ctrl.GetValue()
info["right_col"] = self.right_col_text_ctrl.GetValue()
info["first_tab"] = self.first_tab_text_ctrl.GetValue()
info["last_tab"] = self.last_tab_text_ctrl.GetValue()
if self.filetype != "print":
# If printing and not exporting then page info is
# gathered from printer dialog
info["paper_width"] = float(
self.page_width_text_ctrl.GetValue()) * 72.0
info["paper_height"] = float(
self.page_height_text_ctrl.GetValue()) * 72.0
if self.portrait_landscape_radio_box.GetSelection() == 0:
orientation = "portrait"
elif self.portrait_landscape_radio_box.GetSelection() == 1:
orientation = "landscape"
else:
raise ValueError("Orientation not in portrait or landscape")
info["orientation"] = orientation
return info | python | 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"] = self.bottom_row_text_ctrl.GetValue()
info["left_col"] = self.left_col_text_ctrl.GetValue()
info["right_col"] = self.right_col_text_ctrl.GetValue()
info["first_tab"] = self.first_tab_text_ctrl.GetValue()
info["last_tab"] = self.last_tab_text_ctrl.GetValue()
if self.filetype != "print":
# If printing and not exporting then page info is
# gathered from printer dialog
info["paper_width"] = float(
self.page_width_text_ctrl.GetValue()) * 72.0
info["paper_height"] = float(
self.page_height_text_ctrl.GetValue()) * 72.0
if self.portrait_landscape_radio_box.GetSelection() == 0:
orientation = "portrait"
elif self.portrait_landscape_radio_box.GetSelection() == 1:
orientation = "landscape"
else:
raise ValueError("Orientation not in portrait or landscape")
info["orientation"] = orientation
return info | [
"def",
"get_info",
"(",
"self",
")",
":",
"info",
"=",
"{",
"}",
"info",
"[",
"\"top_row\"",
"]",
"=",
"self",
".",
"top_row_text_ctrl",
".",
"GetValue",
"(",
")",
"info",
"[",
"\"bottom_row\"",
"]",
"=",
"self",
".",
"bottom_row_text_ctrl",
".",
"GetValue",
"(",
")",
"info",
"[",
"\"left_col\"",
"]",
"=",
"self",
".",
"left_col_text_ctrl",
".",
"GetValue",
"(",
")",
"info",
"[",
"\"right_col\"",
"]",
"=",
"self",
".",
"right_col_text_ctrl",
".",
"GetValue",
"(",
")",
"info",
"[",
"\"first_tab\"",
"]",
"=",
"self",
".",
"first_tab_text_ctrl",
".",
"GetValue",
"(",
")",
"info",
"[",
"\"last_tab\"",
"]",
"=",
"self",
".",
"last_tab_text_ctrl",
".",
"GetValue",
"(",
")",
"if",
"self",
".",
"filetype",
"!=",
"\"print\"",
":",
"# If printing and not exporting then page info is",
"# gathered from printer dialog",
"info",
"[",
"\"paper_width\"",
"]",
"=",
"float",
"(",
"self",
".",
"page_width_text_ctrl",
".",
"GetValue",
"(",
")",
")",
"*",
"72.0",
"info",
"[",
"\"paper_height\"",
"]",
"=",
"float",
"(",
"self",
".",
"page_height_text_ctrl",
".",
"GetValue",
"(",
")",
")",
"*",
"72.0",
"if",
"self",
".",
"portrait_landscape_radio_box",
".",
"GetSelection",
"(",
")",
"==",
"0",
":",
"orientation",
"=",
"\"portrait\"",
"elif",
"self",
".",
"portrait_landscape_radio_box",
".",
"GetSelection",
"(",
")",
"==",
"1",
":",
"orientation",
"=",
"\"landscape\"",
"else",
":",
"raise",
"ValueError",
"(",
"\"Orientation not in portrait or landscape\"",
")",
"info",
"[",
"\"orientation\"",
"]",
"=",
"orientation",
"return",
"info"
] | Returns a dict with the dialog PDF info
Dict keys are:
top_row, bottom_row, left_col, right_col, first_tab, last_tab,
paper_width, paper_height | [
"Returns",
"a",
"dict",
"with",
"the",
"dialog",
"PDF",
"info"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_cairo_export_dialog.py#L257-L293 | train | 231,604 |
manns/pyspread | pyspread/src/sysvars.py | get_program_path | 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 | python | 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 | [
"def",
"get_program_path",
"(",
")",
":",
"src_folder",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
"program_path",
"=",
"os",
".",
"sep",
".",
"join",
"(",
"src_folder",
".",
"split",
"(",
"os",
".",
"sep",
")",
"[",
":",
"-",
"1",
"]",
")",
"+",
"os",
".",
"sep",
"return",
"program_path"
] | Returns the path in which pyspread is installed | [
"Returns",
"the",
"path",
"in",
"which",
"pyspread",
"is",
"installed"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/sysvars.py#L44-L50 | train | 231,605 |
manns/pyspread | pyspread/src/sysvars.py | get_dpi | 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())) | python | 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())) | [
"def",
"get_dpi",
"(",
")",
":",
"def",
"pxmm_2_dpi",
"(",
"(",
"pixels",
",",
"length_mm",
")",
")",
":",
"return",
"pixels",
"*",
"25.6",
"/",
"length_mm",
"return",
"map",
"(",
"pxmm_2_dpi",
",",
"zip",
"(",
"wx",
".",
"GetDisplaySize",
"(",
")",
",",
"wx",
".",
"GetDisplaySizeMM",
"(",
")",
")",
")"
] | Returns screen dpi resolution | [
"Returns",
"screen",
"dpi",
"resolution"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/sysvars.py#L83-L89 | train | 231,606 |
manns/pyspread | pyspread/src/sysvars.py | get_font_list | 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 | python | 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 | [
"def",
"get_font_list",
"(",
")",
":",
"font_map",
"=",
"pangocairo",
".",
"cairo_font_map_get_default",
"(",
")",
"font_list",
"=",
"[",
"f",
".",
"get_name",
"(",
")",
"for",
"f",
"in",
"font_map",
".",
"list_families",
"(",
")",
"]",
"font_list",
".",
"sort",
"(",
")",
"return",
"font_list"
] | Returns a sorted list of all system font names | [
"Returns",
"a",
"sorted",
"list",
"of",
"all",
"system",
"font",
"names"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/sysvars.py#L112-L119 | train | 231,607 |
manns/pyspread | pyspread/src/sysvars.py | get_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.version
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# wxPython
dep_attrs = {
"name": "wxPython",
"min_version": "2.8.10.1",
"description": "required",
}
try:
import wx
dep_attrs["version"] = wx.version()
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# Matplotlib
dep_attrs = {
"name": "matplotlib",
"min_version": "1.1.1",
"description": "required",
}
try:
import matplotlib
dep_attrs["version"] = matplotlib._version.get_versions()["version"]
except ImportError:
dep_attrs["version"] = None
except AttributeError:
# May happen in old matplotlib versions
dep_attrs["version"] = matplotlib.__version__
dependencies.append(dep_attrs)
# Pycairo
dep_attrs = {
"name": "pycairo",
"min_version": "1.8.8",
"description": "required",
}
try:
import cairo
dep_attrs["version"] = cairo.version
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# Python GnuPG
dep_attrs = {
"name": "python-gnupg",
"min_version": "0.3.0",
"description": "for opening own files without approval",
}
try:
import gnupg
dep_attrs["version"] = gnupg.__version__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# xlrd
dep_attrs = {
"name": "xlrd",
"min_version": "0.9.2",
"description": "for loading Excel files",
}
try:
import xlrd
dep_attrs["version"] = xlrd.__VERSION__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# xlwt
dep_attrs = {
"name": "xlwt",
"min_version": "0.7.2",
"description": "for saving Excel files",
}
try:
import xlwt
dep_attrs["version"] = xlwt.__VERSION__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# Jedi
dep_attrs = {
"name": "jedi",
"min_version": "0.8.0",
"description": "for tab completion and context help in the entry line",
}
try:
import jedi
dep_attrs["version"] = jedi.__version__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# pyrsvg
dep_attrs = {
"name": "pyrsvg",
"min_version": "2.32",
"description": "for displaying SVG files in cells",
}
try:
import rsvg
dep_attrs["version"] = True
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# pyenchant
dep_attrs = {
"name": "pyenchant",
"min_version": "1.6.6",
"description": "for spell checking",
}
try:
import enchant
dep_attrs["version"] = enchant.__version__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
return dependencies | python | 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.version
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# wxPython
dep_attrs = {
"name": "wxPython",
"min_version": "2.8.10.1",
"description": "required",
}
try:
import wx
dep_attrs["version"] = wx.version()
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# Matplotlib
dep_attrs = {
"name": "matplotlib",
"min_version": "1.1.1",
"description": "required",
}
try:
import matplotlib
dep_attrs["version"] = matplotlib._version.get_versions()["version"]
except ImportError:
dep_attrs["version"] = None
except AttributeError:
# May happen in old matplotlib versions
dep_attrs["version"] = matplotlib.__version__
dependencies.append(dep_attrs)
# Pycairo
dep_attrs = {
"name": "pycairo",
"min_version": "1.8.8",
"description": "required",
}
try:
import cairo
dep_attrs["version"] = cairo.version
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# Python GnuPG
dep_attrs = {
"name": "python-gnupg",
"min_version": "0.3.0",
"description": "for opening own files without approval",
}
try:
import gnupg
dep_attrs["version"] = gnupg.__version__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# xlrd
dep_attrs = {
"name": "xlrd",
"min_version": "0.9.2",
"description": "for loading Excel files",
}
try:
import xlrd
dep_attrs["version"] = xlrd.__VERSION__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# xlwt
dep_attrs = {
"name": "xlwt",
"min_version": "0.7.2",
"description": "for saving Excel files",
}
try:
import xlwt
dep_attrs["version"] = xlwt.__VERSION__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# Jedi
dep_attrs = {
"name": "jedi",
"min_version": "0.8.0",
"description": "for tab completion and context help in the entry line",
}
try:
import jedi
dep_attrs["version"] = jedi.__version__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# pyrsvg
dep_attrs = {
"name": "pyrsvg",
"min_version": "2.32",
"description": "for displaying SVG files in cells",
}
try:
import rsvg
dep_attrs["version"] = True
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
# pyenchant
dep_attrs = {
"name": "pyenchant",
"min_version": "1.6.6",
"description": "for spell checking",
}
try:
import enchant
dep_attrs["version"] = enchant.__version__
except ImportError:
dep_attrs["version"] = None
dependencies.append(dep_attrs)
return dependencies | [
"def",
"get_dependencies",
"(",
")",
":",
"dependencies",
"=",
"[",
"]",
"# Numpy",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"numpy\"",
",",
"\"min_version\"",
":",
"\"1.1.0\"",
",",
"\"description\"",
":",
"\"required\"",
",",
"}",
"try",
":",
"import",
"numpy",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"numpy",
".",
"version",
".",
"version",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# wxPython",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"wxPython\"",
",",
"\"min_version\"",
":",
"\"2.8.10.1\"",
",",
"\"description\"",
":",
"\"required\"",
",",
"}",
"try",
":",
"import",
"wx",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"wx",
".",
"version",
"(",
")",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# Matplotlib",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"matplotlib\"",
",",
"\"min_version\"",
":",
"\"1.1.1\"",
",",
"\"description\"",
":",
"\"required\"",
",",
"}",
"try",
":",
"import",
"matplotlib",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"matplotlib",
".",
"_version",
".",
"get_versions",
"(",
")",
"[",
"\"version\"",
"]",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"except",
"AttributeError",
":",
"# May happen in old matplotlib versions",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"matplotlib",
".",
"__version__",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# Pycairo",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"pycairo\"",
",",
"\"min_version\"",
":",
"\"1.8.8\"",
",",
"\"description\"",
":",
"\"required\"",
",",
"}",
"try",
":",
"import",
"cairo",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"cairo",
".",
"version",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# Python GnuPG",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"python-gnupg\"",
",",
"\"min_version\"",
":",
"\"0.3.0\"",
",",
"\"description\"",
":",
"\"for opening own files without approval\"",
",",
"}",
"try",
":",
"import",
"gnupg",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"gnupg",
".",
"__version__",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# xlrd",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"xlrd\"",
",",
"\"min_version\"",
":",
"\"0.9.2\"",
",",
"\"description\"",
":",
"\"for loading Excel files\"",
",",
"}",
"try",
":",
"import",
"xlrd",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"xlrd",
".",
"__VERSION__",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# xlwt",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"xlwt\"",
",",
"\"min_version\"",
":",
"\"0.7.2\"",
",",
"\"description\"",
":",
"\"for saving Excel files\"",
",",
"}",
"try",
":",
"import",
"xlwt",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"xlwt",
".",
"__VERSION__",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# Jedi",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"jedi\"",
",",
"\"min_version\"",
":",
"\"0.8.0\"",
",",
"\"description\"",
":",
"\"for tab completion and context help in the entry line\"",
",",
"}",
"try",
":",
"import",
"jedi",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"jedi",
".",
"__version__",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# pyrsvg",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"pyrsvg\"",
",",
"\"min_version\"",
":",
"\"2.32\"",
",",
"\"description\"",
":",
"\"for displaying SVG files in cells\"",
",",
"}",
"try",
":",
"import",
"rsvg",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"True",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"# pyenchant",
"dep_attrs",
"=",
"{",
"\"name\"",
":",
"\"pyenchant\"",
",",
"\"min_version\"",
":",
"\"1.6.6\"",
",",
"\"description\"",
":",
"\"for spell checking\"",
",",
"}",
"try",
":",
"import",
"enchant",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"enchant",
".",
"__version__",
"except",
"ImportError",
":",
"dep_attrs",
"[",
"\"version\"",
"]",
"=",
"None",
"dependencies",
".",
"append",
"(",
"dep_attrs",
")",
"return",
"dependencies"
] | Returns list of dicts which indicate installed dependencies | [
"Returns",
"list",
"of",
"dicts",
"which",
"indicate",
"installed",
"dependencies"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/sysvars.py#L128-L267 | train | 231,608 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCairoRenderer.get_cell_rect | 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):
__row_height = self.code_array.get_row_height(__row, tab)
pos_y += __row_height
for __col in xrange(left_col, col):
__col_width = self.code_array.get_col_width(__col, tab)
pos_x += __col_width
if merge_area is None:
height = self.code_array.get_row_height(row, tab)
width = self.code_array.get_col_width(col, tab)
else:
# We have a merged cell
top, left, bottom, right = merge_area
# Are we drawing the top left cell?
if top == row and left == col:
# Set rect to merge area
heights = (self.code_array.get_row_height(__row, tab)
for __row in xrange(top, bottom+1))
widths = (self.code_array.get_col_width(__col, tab)
for __col in xrange(left, right+1))
height = sum(heights)
width = sum(widths)
else:
# Do not draw the cell because it is hidden
return
return pos_x, pos_y, width, height | python | 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):
__row_height = self.code_array.get_row_height(__row, tab)
pos_y += __row_height
for __col in xrange(left_col, col):
__col_width = self.code_array.get_col_width(__col, tab)
pos_x += __col_width
if merge_area is None:
height = self.code_array.get_row_height(row, tab)
width = self.code_array.get_col_width(col, tab)
else:
# We have a merged cell
top, left, bottom, right = merge_area
# Are we drawing the top left cell?
if top == row and left == col:
# Set rect to merge area
heights = (self.code_array.get_row_height(__row, tab)
for __row in xrange(top, bottom+1))
widths = (self.code_array.get_col_width(__col, tab)
for __col in xrange(left, right+1))
height = sum(heights)
width = sum(widths)
else:
# Do not draw the cell because it is hidden
return
return pos_x, pos_y, width, height | [
"def",
"get_cell_rect",
"(",
"self",
",",
"row",
",",
"col",
",",
"tab",
")",
":",
"top_row",
"=",
"self",
".",
"row_tb",
"[",
"0",
"]",
"left_col",
"=",
"self",
".",
"col_rl",
"[",
"0",
"]",
"pos_x",
"=",
"self",
".",
"x_offset",
"pos_y",
"=",
"self",
".",
"y_offset",
"merge_area",
"=",
"self",
".",
"_get_merge_area",
"(",
"(",
"row",
",",
"col",
",",
"tab",
")",
")",
"for",
"__row",
"in",
"xrange",
"(",
"top_row",
",",
"row",
")",
":",
"__row_height",
"=",
"self",
".",
"code_array",
".",
"get_row_height",
"(",
"__row",
",",
"tab",
")",
"pos_y",
"+=",
"__row_height",
"for",
"__col",
"in",
"xrange",
"(",
"left_col",
",",
"col",
")",
":",
"__col_width",
"=",
"self",
".",
"code_array",
".",
"get_col_width",
"(",
"__col",
",",
"tab",
")",
"pos_x",
"+=",
"__col_width",
"if",
"merge_area",
"is",
"None",
":",
"height",
"=",
"self",
".",
"code_array",
".",
"get_row_height",
"(",
"row",
",",
"tab",
")",
"width",
"=",
"self",
".",
"code_array",
".",
"get_col_width",
"(",
"col",
",",
"tab",
")",
"else",
":",
"# We have a merged cell",
"top",
",",
"left",
",",
"bottom",
",",
"right",
"=",
"merge_area",
"# Are we drawing the top left cell?",
"if",
"top",
"==",
"row",
"and",
"left",
"==",
"col",
":",
"# Set rect to merge area",
"heights",
"=",
"(",
"self",
".",
"code_array",
".",
"get_row_height",
"(",
"__row",
",",
"tab",
")",
"for",
"__row",
"in",
"xrange",
"(",
"top",
",",
"bottom",
"+",
"1",
")",
")",
"widths",
"=",
"(",
"self",
".",
"code_array",
".",
"get_col_width",
"(",
"__col",
",",
"tab",
")",
"for",
"__col",
"in",
"xrange",
"(",
"left",
",",
"right",
"+",
"1",
")",
")",
"height",
"=",
"sum",
"(",
"heights",
")",
"width",
"=",
"sum",
"(",
"widths",
")",
"else",
":",
"# Do not draw the cell because it is hidden",
"return",
"return",
"pos_x",
",",
"pos_y",
",",
"width",
",",
"height"
] | Returns rectangle of cell on canvas | [
"Returns",
"rectangle",
"of",
"cell",
"on",
"canvas"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L129-L167 | train | 231,609 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCairoRenderer.draw | 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 intact use the maximum
first_key = row_start, col_start, tab
first_rect = self.get_cell_rect(*first_key)
# If we have a merged cell then use the top left cell rect
if first_rect is None:
top, left, __, __ = self._get_merge_area(first_key)
first_rect = self.get_cell_rect(top, left, tab)
last_key = row_stop - 1, col_stop - 1, tab
last_rect = self.get_cell_rect(*last_key)
# If we have a merged cell then use the top left cell rect
if last_rect is None:
top, left, __, __ = self._get_merge_area(last_key)
last_rect = self.get_cell_rect(top, left, tab)
x_extent = last_rect[0] + last_rect[2] - first_rect[0]
y_extent = last_rect[1] + last_rect[3] - first_rect[1]
scale_x = (self.width - 2 * self.x_offset) / float(x_extent)
scale_y = (self.height - 2 * self.y_offset) / float(y_extent)
self.context.save()
# Translate offset to o
self.context.translate(first_rect[0], first_rect[1])
# Scale to fit page, do not change aspect ratio
scale = min(scale_x, scale_y)
self.context.scale(scale, scale)
# Translate offset
self.context.translate(-self.x_offset, -self.y_offset)
# TODO: Center the grid on the page
# Render cells
for row in xrange(row_start, row_stop):
for col in xrange(col_start, col_stop):
key = row, col, tab
rect = self.get_cell_rect(row, col, tab) # Rect
if rect is not None:
cell_renderer = GridCellCairoRenderer(
self.context,
self.code_array,
key, # (row, col, tab)
rect,
self.view_frozen
)
cell_renderer.draw()
# Undo scaling, translation, ...
self.context.restore()
self.context.show_page() | python | 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 intact use the maximum
first_key = row_start, col_start, tab
first_rect = self.get_cell_rect(*first_key)
# If we have a merged cell then use the top left cell rect
if first_rect is None:
top, left, __, __ = self._get_merge_area(first_key)
first_rect = self.get_cell_rect(top, left, tab)
last_key = row_stop - 1, col_stop - 1, tab
last_rect = self.get_cell_rect(*last_key)
# If we have a merged cell then use the top left cell rect
if last_rect is None:
top, left, __, __ = self._get_merge_area(last_key)
last_rect = self.get_cell_rect(top, left, tab)
x_extent = last_rect[0] + last_rect[2] - first_rect[0]
y_extent = last_rect[1] + last_rect[3] - first_rect[1]
scale_x = (self.width - 2 * self.x_offset) / float(x_extent)
scale_y = (self.height - 2 * self.y_offset) / float(y_extent)
self.context.save()
# Translate offset to o
self.context.translate(first_rect[0], first_rect[1])
# Scale to fit page, do not change aspect ratio
scale = min(scale_x, scale_y)
self.context.scale(scale, scale)
# Translate offset
self.context.translate(-self.x_offset, -self.y_offset)
# TODO: Center the grid on the page
# Render cells
for row in xrange(row_start, row_stop):
for col in xrange(col_start, col_stop):
key = row, col, tab
rect = self.get_cell_rect(row, col, tab) # Rect
if rect is not None:
cell_renderer = GridCellCairoRenderer(
self.context,
self.code_array,
key, # (row, col, tab)
rect,
self.view_frozen
)
cell_renderer.draw()
# Undo scaling, translation, ...
self.context.restore()
self.context.show_page() | [
"def",
"draw",
"(",
"self",
")",
":",
"row_start",
",",
"row_stop",
"=",
"self",
".",
"row_tb",
"col_start",
",",
"col_stop",
"=",
"self",
".",
"col_rl",
"tab_start",
",",
"tab_stop",
"=",
"self",
".",
"tab_fl",
"for",
"tab",
"in",
"xrange",
"(",
"tab_start",
",",
"tab_stop",
")",
":",
"# Scale context to page extent",
"# In order to keep the aspect ration intact use the maximum",
"first_key",
"=",
"row_start",
",",
"col_start",
",",
"tab",
"first_rect",
"=",
"self",
".",
"get_cell_rect",
"(",
"*",
"first_key",
")",
"# If we have a merged cell then use the top left cell rect",
"if",
"first_rect",
"is",
"None",
":",
"top",
",",
"left",
",",
"__",
",",
"__",
"=",
"self",
".",
"_get_merge_area",
"(",
"first_key",
")",
"first_rect",
"=",
"self",
".",
"get_cell_rect",
"(",
"top",
",",
"left",
",",
"tab",
")",
"last_key",
"=",
"row_stop",
"-",
"1",
",",
"col_stop",
"-",
"1",
",",
"tab",
"last_rect",
"=",
"self",
".",
"get_cell_rect",
"(",
"*",
"last_key",
")",
"# If we have a merged cell then use the top left cell rect",
"if",
"last_rect",
"is",
"None",
":",
"top",
",",
"left",
",",
"__",
",",
"__",
"=",
"self",
".",
"_get_merge_area",
"(",
"last_key",
")",
"last_rect",
"=",
"self",
".",
"get_cell_rect",
"(",
"top",
",",
"left",
",",
"tab",
")",
"x_extent",
"=",
"last_rect",
"[",
"0",
"]",
"+",
"last_rect",
"[",
"2",
"]",
"-",
"first_rect",
"[",
"0",
"]",
"y_extent",
"=",
"last_rect",
"[",
"1",
"]",
"+",
"last_rect",
"[",
"3",
"]",
"-",
"first_rect",
"[",
"1",
"]",
"scale_x",
"=",
"(",
"self",
".",
"width",
"-",
"2",
"*",
"self",
".",
"x_offset",
")",
"/",
"float",
"(",
"x_extent",
")",
"scale_y",
"=",
"(",
"self",
".",
"height",
"-",
"2",
"*",
"self",
".",
"y_offset",
")",
"/",
"float",
"(",
"y_extent",
")",
"self",
".",
"context",
".",
"save",
"(",
")",
"# Translate offset to o",
"self",
".",
"context",
".",
"translate",
"(",
"first_rect",
"[",
"0",
"]",
",",
"first_rect",
"[",
"1",
"]",
")",
"# Scale to fit page, do not change aspect ratio",
"scale",
"=",
"min",
"(",
"scale_x",
",",
"scale_y",
")",
"self",
".",
"context",
".",
"scale",
"(",
"scale",
",",
"scale",
")",
"# Translate offset",
"self",
".",
"context",
".",
"translate",
"(",
"-",
"self",
".",
"x_offset",
",",
"-",
"self",
".",
"y_offset",
")",
"# TODO: Center the grid on the page",
"# Render cells",
"for",
"row",
"in",
"xrange",
"(",
"row_start",
",",
"row_stop",
")",
":",
"for",
"col",
"in",
"xrange",
"(",
"col_start",
",",
"col_stop",
")",
":",
"key",
"=",
"row",
",",
"col",
",",
"tab",
"rect",
"=",
"self",
".",
"get_cell_rect",
"(",
"row",
",",
"col",
",",
"tab",
")",
"# Rect",
"if",
"rect",
"is",
"not",
"None",
":",
"cell_renderer",
"=",
"GridCellCairoRenderer",
"(",
"self",
".",
"context",
",",
"self",
".",
"code_array",
",",
"key",
",",
"# (row, col, tab)",
"rect",
",",
"self",
".",
"view_frozen",
")",
"cell_renderer",
".",
"draw",
"(",
")",
"# Undo scaling, translation, ...",
"self",
".",
"context",
".",
"restore",
"(",
")",
"self",
".",
"context",
".",
"show_page",
"(",
")"
] | Draws slice to context | [
"Draws",
"slice",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L179-L244 | train | 231,610 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellCairoRenderer.draw | 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(
self.context,
self.code_array,
self.key,
self.rect,
self.spell_check)
cell_border_renderer = GridCellBorderCairoRenderer(
self.context,
self.code_array,
self.key,
self.rect)
cell_background_renderer.draw()
cell_content_renderer.draw()
cell_border_renderer.draw() | python | 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(
self.context,
self.code_array,
self.key,
self.rect,
self.spell_check)
cell_border_renderer = GridCellBorderCairoRenderer(
self.context,
self.code_array,
self.key,
self.rect)
cell_background_renderer.draw()
cell_content_renderer.draw()
cell_border_renderer.draw() | [
"def",
"draw",
"(",
"self",
")",
":",
"cell_background_renderer",
"=",
"GridCellBackgroundCairoRenderer",
"(",
"self",
".",
"context",
",",
"self",
".",
"code_array",
",",
"self",
".",
"key",
",",
"self",
".",
"rect",
",",
"self",
".",
"view_frozen",
")",
"cell_content_renderer",
"=",
"GridCellContentCairoRenderer",
"(",
"self",
".",
"context",
",",
"self",
".",
"code_array",
",",
"self",
".",
"key",
",",
"self",
".",
"rect",
",",
"self",
".",
"spell_check",
")",
"cell_border_renderer",
"=",
"GridCellBorderCairoRenderer",
"(",
"self",
".",
"context",
",",
"self",
".",
"code_array",
",",
"self",
".",
"key",
",",
"self",
".",
"rect",
")",
"cell_background_renderer",
".",
"draw",
"(",
")",
"cell_content_renderer",
".",
"draw",
"(",
")",
"cell_border_renderer",
".",
"draw",
"(",
")"
] | Draws cell to context | [
"Draws",
"cell",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L273-L298 | train | 231,611 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.get_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:
pass | python | 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:
pass | [
"def",
"get_cell_content",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"button_cell\"",
"]",
":",
"return",
"except",
"IndexError",
":",
"return",
"try",
":",
"return",
"self",
".",
"code_array",
"[",
"self",
".",
"key",
"]",
"except",
"IndexError",
":",
"pass"
] | Returns cell content | [
"Returns",
"cell",
"content"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L323-L337 | train | 231,612 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer._get_scalexy | 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(ims_width)
scale_y = self.rect[2] / float(ims_height)
else:
# Normal case
scale_x = self.rect[2] / float(ims_width)
scale_y = self.rect[3] / float(ims_height)
return scale_x, scale_y | python | 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(ims_width)
scale_y = self.rect[2] / float(ims_height)
else:
# Normal case
scale_x = self.rect[2] / float(ims_width)
scale_y = self.rect[3] / float(ims_height)
return scale_x, scale_y | [
"def",
"_get_scalexy",
"(",
"self",
",",
"ims_width",
",",
"ims_height",
")",
":",
"# Get cell attributes",
"cell_attributes",
"=",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"angle",
"=",
"cell_attributes",
"[",
"\"angle\"",
"]",
"if",
"abs",
"(",
"angle",
")",
"==",
"90",
":",
"scale_x",
"=",
"self",
".",
"rect",
"[",
"3",
"]",
"/",
"float",
"(",
"ims_width",
")",
"scale_y",
"=",
"self",
".",
"rect",
"[",
"2",
"]",
"/",
"float",
"(",
"ims_height",
")",
"else",
":",
"# Normal case",
"scale_x",
"=",
"self",
".",
"rect",
"[",
"2",
"]",
"/",
"float",
"(",
"ims_width",
")",
"scale_y",
"=",
"self",
".",
"rect",
"[",
"3",
"]",
"/",
"float",
"(",
"ims_height",
")",
"return",
"scale_x",
",",
"scale_y"
] | Returns scale_x, scale_y for bitmap display | [
"Returns",
"scale_x",
"scale_y",
"for",
"bitmap",
"display"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L339-L355 | train | 231,613 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer._get_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"]
angle = cell_attributes["angle"]
scale_x, scale_y = self._get_scalexy(ims_width, ims_height)
scale = min(scale_x, scale_y)
if angle not in (90, 180, -90):
# Standard direction
x = -2 # Otherwise there is a white border
y = -2 # Otherwise there is a white border
if scale_x > scale_y:
if justification == "center":
x += (self.rect[2] - ims_width * scale) / 2
elif justification == "right":
x += self.rect[2] - ims_width * scale
else:
if vertical_align == "middle":
y += (self.rect[3] - ims_height * scale) / 2
elif vertical_align == "bottom":
y += self.rect[3] - ims_height * scale
if angle == 90:
x = -ims_width * scale + 2
y = -2
if scale_y > scale_x:
if justification == "center":
y += (self.rect[2] - ims_height * scale) / 2
elif justification == "right":
y += self.rect[2] - ims_height * scale
else:
if vertical_align == "middle":
x -= (self.rect[3] - ims_width * scale) / 2
elif vertical_align == "bottom":
x -= self.rect[3] - ims_width * scale
elif angle == 180:
x = -ims_width * scale + 2
y = -ims_height * scale + 2
if scale_x > scale_y:
if justification == "center":
x -= (self.rect[2] - ims_width * scale) / 2
elif justification == "right":
x -= self.rect[2] - ims_width * scale
else:
if vertical_align == "middle":
y -= (self.rect[3] - ims_height * scale) / 2
elif vertical_align == "bottom":
y -= self.rect[3] - ims_height * scale
elif angle == -90:
x = -2
y = -ims_height * scale + 2
if scale_y > scale_x:
if justification == "center":
y -= (self.rect[2] - ims_height * scale) / 2
elif justification == "right":
y -= self.rect[2] - ims_height * scale
else:
if vertical_align == "middle":
x += (self.rect[3] - ims_width * scale) / 2
elif vertical_align == "bottom":
x += self.rect[3] - ims_width * scale
return x, y | python | 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"]
angle = cell_attributes["angle"]
scale_x, scale_y = self._get_scalexy(ims_width, ims_height)
scale = min(scale_x, scale_y)
if angle not in (90, 180, -90):
# Standard direction
x = -2 # Otherwise there is a white border
y = -2 # Otherwise there is a white border
if scale_x > scale_y:
if justification == "center":
x += (self.rect[2] - ims_width * scale) / 2
elif justification == "right":
x += self.rect[2] - ims_width * scale
else:
if vertical_align == "middle":
y += (self.rect[3] - ims_height * scale) / 2
elif vertical_align == "bottom":
y += self.rect[3] - ims_height * scale
if angle == 90:
x = -ims_width * scale + 2
y = -2
if scale_y > scale_x:
if justification == "center":
y += (self.rect[2] - ims_height * scale) / 2
elif justification == "right":
y += self.rect[2] - ims_height * scale
else:
if vertical_align == "middle":
x -= (self.rect[3] - ims_width * scale) / 2
elif vertical_align == "bottom":
x -= self.rect[3] - ims_width * scale
elif angle == 180:
x = -ims_width * scale + 2
y = -ims_height * scale + 2
if scale_x > scale_y:
if justification == "center":
x -= (self.rect[2] - ims_width * scale) / 2
elif justification == "right":
x -= self.rect[2] - ims_width * scale
else:
if vertical_align == "middle":
y -= (self.rect[3] - ims_height * scale) / 2
elif vertical_align == "bottom":
y -= self.rect[3] - ims_height * scale
elif angle == -90:
x = -2
y = -ims_height * scale + 2
if scale_y > scale_x:
if justification == "center":
y -= (self.rect[2] - ims_height * scale) / 2
elif justification == "right":
y -= self.rect[2] - ims_height * scale
else:
if vertical_align == "middle":
x += (self.rect[3] - ims_width * scale) / 2
elif vertical_align == "bottom":
x += self.rect[3] - ims_width * scale
return x, y | [
"def",
"_get_translation",
"(",
"self",
",",
"ims_width",
",",
"ims_height",
")",
":",
"# Get cell attributes",
"cell_attributes",
"=",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"justification",
"=",
"cell_attributes",
"[",
"\"justification\"",
"]",
"vertical_align",
"=",
"cell_attributes",
"[",
"\"vertical_align\"",
"]",
"angle",
"=",
"cell_attributes",
"[",
"\"angle\"",
"]",
"scale_x",
",",
"scale_y",
"=",
"self",
".",
"_get_scalexy",
"(",
"ims_width",
",",
"ims_height",
")",
"scale",
"=",
"min",
"(",
"scale_x",
",",
"scale_y",
")",
"if",
"angle",
"not",
"in",
"(",
"90",
",",
"180",
",",
"-",
"90",
")",
":",
"# Standard direction",
"x",
"=",
"-",
"2",
"# Otherwise there is a white border",
"y",
"=",
"-",
"2",
"# Otherwise there is a white border",
"if",
"scale_x",
">",
"scale_y",
":",
"if",
"justification",
"==",
"\"center\"",
":",
"x",
"+=",
"(",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_width",
"*",
"scale",
")",
"/",
"2",
"elif",
"justification",
"==",
"\"right\"",
":",
"x",
"+=",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_width",
"*",
"scale",
"else",
":",
"if",
"vertical_align",
"==",
"\"middle\"",
":",
"y",
"+=",
"(",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_height",
"*",
"scale",
")",
"/",
"2",
"elif",
"vertical_align",
"==",
"\"bottom\"",
":",
"y",
"+=",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_height",
"*",
"scale",
"if",
"angle",
"==",
"90",
":",
"x",
"=",
"-",
"ims_width",
"*",
"scale",
"+",
"2",
"y",
"=",
"-",
"2",
"if",
"scale_y",
">",
"scale_x",
":",
"if",
"justification",
"==",
"\"center\"",
":",
"y",
"+=",
"(",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_height",
"*",
"scale",
")",
"/",
"2",
"elif",
"justification",
"==",
"\"right\"",
":",
"y",
"+=",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_height",
"*",
"scale",
"else",
":",
"if",
"vertical_align",
"==",
"\"middle\"",
":",
"x",
"-=",
"(",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_width",
"*",
"scale",
")",
"/",
"2",
"elif",
"vertical_align",
"==",
"\"bottom\"",
":",
"x",
"-=",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_width",
"*",
"scale",
"elif",
"angle",
"==",
"180",
":",
"x",
"=",
"-",
"ims_width",
"*",
"scale",
"+",
"2",
"y",
"=",
"-",
"ims_height",
"*",
"scale",
"+",
"2",
"if",
"scale_x",
">",
"scale_y",
":",
"if",
"justification",
"==",
"\"center\"",
":",
"x",
"-=",
"(",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_width",
"*",
"scale",
")",
"/",
"2",
"elif",
"justification",
"==",
"\"right\"",
":",
"x",
"-=",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_width",
"*",
"scale",
"else",
":",
"if",
"vertical_align",
"==",
"\"middle\"",
":",
"y",
"-=",
"(",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_height",
"*",
"scale",
")",
"/",
"2",
"elif",
"vertical_align",
"==",
"\"bottom\"",
":",
"y",
"-=",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_height",
"*",
"scale",
"elif",
"angle",
"==",
"-",
"90",
":",
"x",
"=",
"-",
"2",
"y",
"=",
"-",
"ims_height",
"*",
"scale",
"+",
"2",
"if",
"scale_y",
">",
"scale_x",
":",
"if",
"justification",
"==",
"\"center\"",
":",
"y",
"-=",
"(",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_height",
"*",
"scale",
")",
"/",
"2",
"elif",
"justification",
"==",
"\"right\"",
":",
"y",
"-=",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"ims_height",
"*",
"scale",
"else",
":",
"if",
"vertical_align",
"==",
"\"middle\"",
":",
"x",
"+=",
"(",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_width",
"*",
"scale",
")",
"/",
"2",
"elif",
"vertical_align",
"==",
"\"bottom\"",
":",
"x",
"+=",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"ims_width",
"*",
"scale",
"return",
"x",
",",
"y"
] | Returns x and y for a bitmap translation | [
"Returns",
"x",
"and",
"y",
"for",
"a",
"bitmap",
"translation"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L357-L442 | train | 231,614 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.draw_bitmap | 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.ImageSurfaceFromBitmap(content)
ims_width = ims.get_width()
ims_height = ims.get_height()
transx, transy = self._get_translation(ims_width, ims_height)
scale_x, scale_y = self._get_scalexy(ims_width, ims_height)
scale = min(scale_x, scale_y)
angle = float(self.code_array.cell_attributes[self.key]["angle"])
self.context.save()
self.context.rotate(-angle / 360 * 2 * math.pi)
self.context.translate(transx, transy)
self.context.scale(scale, scale)
self.context.set_source_surface(ims, 0, 0)
self.context.paint()
self.context.restore() | python | 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.ImageSurfaceFromBitmap(content)
ims_width = ims.get_width()
ims_height = ims.get_height()
transx, transy = self._get_translation(ims_width, ims_height)
scale_x, scale_y = self._get_scalexy(ims_width, ims_height)
scale = min(scale_x, scale_y)
angle = float(self.code_array.cell_attributes[self.key]["angle"])
self.context.save()
self.context.rotate(-angle / 360 * 2 * math.pi)
self.context.translate(transx, transy)
self.context.scale(scale, scale)
self.context.set_source_surface(ims, 0, 0)
self.context.paint()
self.context.restore() | [
"def",
"draw_bitmap",
"(",
"self",
",",
"content",
")",
":",
"if",
"content",
".",
"HasAlpha",
"(",
")",
":",
"image",
"=",
"wx",
".",
"ImageFromBitmap",
"(",
"content",
")",
"image",
".",
"ConvertAlphaToMask",
"(",
")",
"image",
".",
"SetMask",
"(",
"False",
")",
"content",
"=",
"wx",
".",
"BitmapFromImage",
"(",
"image",
")",
"ims",
"=",
"wx",
".",
"lib",
".",
"wxcairo",
".",
"ImageSurfaceFromBitmap",
"(",
"content",
")",
"ims_width",
"=",
"ims",
".",
"get_width",
"(",
")",
"ims_height",
"=",
"ims",
".",
"get_height",
"(",
")",
"transx",
",",
"transy",
"=",
"self",
".",
"_get_translation",
"(",
"ims_width",
",",
"ims_height",
")",
"scale_x",
",",
"scale_y",
"=",
"self",
".",
"_get_scalexy",
"(",
"ims_width",
",",
"ims_height",
")",
"scale",
"=",
"min",
"(",
"scale_x",
",",
"scale_y",
")",
"angle",
"=",
"float",
"(",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"angle\"",
"]",
")",
"self",
".",
"context",
".",
"save",
"(",
")",
"self",
".",
"context",
".",
"rotate",
"(",
"-",
"angle",
"/",
"360",
"*",
"2",
"*",
"math",
".",
"pi",
")",
"self",
".",
"context",
".",
"translate",
"(",
"transx",
",",
"transy",
")",
"self",
".",
"context",
".",
"scale",
"(",
"scale",
",",
"scale",
")",
"self",
".",
"context",
".",
"set_source_surface",
"(",
"ims",
",",
"0",
",",
"0",
")",
"self",
".",
"context",
".",
"paint",
"(",
")",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws bitmap cell content to context | [
"Draws",
"bitmap",
"cell",
"content",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L444-L471 | train | 231,615 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.draw_svg | 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 = self._get_translation(svg_width, svg_height)
scale_x, scale_y = self._get_scalexy(svg_width, svg_height)
scale = min(scale_x, scale_y)
angle = float(self.code_array.cell_attributes[self.key]["angle"])
self.context.save()
self.context.rotate(-angle / 360 * 2 * math.pi)
self.context.translate(transx, transy)
self.context.scale(scale, scale)
svg.render_cairo(self.context)
self.context.restore() | python | 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 = self._get_translation(svg_width, svg_height)
scale_x, scale_y = self._get_scalexy(svg_width, svg_height)
scale = min(scale_x, scale_y)
angle = float(self.code_array.cell_attributes[self.key]["angle"])
self.context.save()
self.context.rotate(-angle / 360 * 2 * math.pi)
self.context.translate(transx, transy)
self.context.scale(scale, scale)
svg.render_cairo(self.context)
self.context.restore() | [
"def",
"draw_svg",
"(",
"self",
",",
"svg_str",
")",
":",
"try",
":",
"import",
"rsvg",
"except",
"ImportError",
":",
"self",
".",
"draw_text",
"(",
"svg_str",
")",
"return",
"svg",
"=",
"rsvg",
".",
"Handle",
"(",
"data",
"=",
"svg_str",
")",
"svg_width",
",",
"svg_height",
"=",
"svg",
".",
"get_dimension_data",
"(",
")",
"[",
":",
"2",
"]",
"transx",
",",
"transy",
"=",
"self",
".",
"_get_translation",
"(",
"svg_width",
",",
"svg_height",
")",
"scale_x",
",",
"scale_y",
"=",
"self",
".",
"_get_scalexy",
"(",
"svg_width",
",",
"svg_height",
")",
"scale",
"=",
"min",
"(",
"scale_x",
",",
"scale_y",
")",
"angle",
"=",
"float",
"(",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"angle\"",
"]",
")",
"self",
".",
"context",
".",
"save",
"(",
")",
"self",
".",
"context",
".",
"rotate",
"(",
"-",
"angle",
"/",
"360",
"*",
"2",
"*",
"math",
".",
"pi",
")",
"self",
".",
"context",
".",
"translate",
"(",
"transx",
",",
"transy",
")",
"self",
".",
"context",
".",
"scale",
"(",
"scale",
",",
"scale",
")",
"svg",
".",
"render_cairo",
"(",
"self",
".",
"context",
")",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws svg string to cell | [
"Draws",
"svg",
"string",
"to",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L473-L498 | train | 231,616 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.draw_matplotlib_figure | 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:
BYTE_FORMAT = 1 # ARGB
def draw_path(self, gc, path, transform, rgbFace=None):
ctx = gc.ctx
transform = transform + Affine2D().scale(1.0, -1.0).\
translate(0, self.height)
ctx.new_path()
self.convert_path(ctx, path, transform)
try:
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(),
gc.get_forced_alpha())
except AttributeError:
# Workaround for some Windiws version of Cairo
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha())
def draw_image(self, gc, x, y, im):
# bbox - not currently used
rows, cols, buf = im.color_conv(self.BYTE_FORMAT)
surface = cairo.ImageSurface.create_for_data(
buf, cairo.FORMAT_ARGB32, cols, rows, cols*4)
ctx = gc.ctx
y = self.height - y - rows
ctx.save()
ctx.set_source_surface(surface, x, y)
if gc.get_alpha() != 1.0:
ctx.paint_with_alpha(gc.get_alpha())
else:
ctx.paint()
ctx.restore()
if pyplot is None:
# Matplotlib is not installed
return
FigureCanvasCairo(figure)
dpi = float(figure.dpi)
# Set a border so that the figure is not cut off at the cell border
border_x = 200 / (self.rect[2] / dpi) ** 2
border_y = 200 / (self.rect[3] / dpi) ** 2
width = (self.rect[2] - 2 * border_x) / dpi
height = (self.rect[3] - 2 * border_y) / dpi
figure.set_figwidth(width)
figure.set_figheight(height)
renderer = CustomRendererCairo(dpi)
renderer.set_width_height(width, height)
renderer.gc.ctx = self.context
renderer.text_ctx = self.context
self.context.save()
self.context.translate(border_x, border_y + height * dpi)
figure.draw(renderer)
self.context.restore() | python | 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:
BYTE_FORMAT = 1 # ARGB
def draw_path(self, gc, path, transform, rgbFace=None):
ctx = gc.ctx
transform = transform + Affine2D().scale(1.0, -1.0).\
translate(0, self.height)
ctx.new_path()
self.convert_path(ctx, path, transform)
try:
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(),
gc.get_forced_alpha())
except AttributeError:
# Workaround for some Windiws version of Cairo
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha())
def draw_image(self, gc, x, y, im):
# bbox - not currently used
rows, cols, buf = im.color_conv(self.BYTE_FORMAT)
surface = cairo.ImageSurface.create_for_data(
buf, cairo.FORMAT_ARGB32, cols, rows, cols*4)
ctx = gc.ctx
y = self.height - y - rows
ctx.save()
ctx.set_source_surface(surface, x, y)
if gc.get_alpha() != 1.0:
ctx.paint_with_alpha(gc.get_alpha())
else:
ctx.paint()
ctx.restore()
if pyplot is None:
# Matplotlib is not installed
return
FigureCanvasCairo(figure)
dpi = float(figure.dpi)
# Set a border so that the figure is not cut off at the cell border
border_x = 200 / (self.rect[2] / dpi) ** 2
border_y = 200 / (self.rect[3] / dpi) ** 2
width = (self.rect[2] - 2 * border_x) / dpi
height = (self.rect[3] - 2 * border_y) / dpi
figure.set_figwidth(width)
figure.set_figheight(height)
renderer = CustomRendererCairo(dpi)
renderer.set_width_height(width, height)
renderer.gc.ctx = self.context
renderer.text_ctx = self.context
self.context.save()
self.context.translate(border_x, border_y + height * dpi)
figure.draw(renderer)
self.context.restore() | [
"def",
"draw_matplotlib_figure",
"(",
"self",
",",
"figure",
")",
":",
"class",
"CustomRendererCairo",
"(",
"RendererCairo",
")",
":",
"\"\"\"Workaround for older versins with limited draw path length\"\"\"",
"if",
"sys",
".",
"byteorder",
"==",
"'little'",
":",
"BYTE_FORMAT",
"=",
"0",
"# BGRA",
"else",
":",
"BYTE_FORMAT",
"=",
"1",
"# ARGB",
"def",
"draw_path",
"(",
"self",
",",
"gc",
",",
"path",
",",
"transform",
",",
"rgbFace",
"=",
"None",
")",
":",
"ctx",
"=",
"gc",
".",
"ctx",
"transform",
"=",
"transform",
"+",
"Affine2D",
"(",
")",
".",
"scale",
"(",
"1.0",
",",
"-",
"1.0",
")",
".",
"translate",
"(",
"0",
",",
"self",
".",
"height",
")",
"ctx",
".",
"new_path",
"(",
")",
"self",
".",
"convert_path",
"(",
"ctx",
",",
"path",
",",
"transform",
")",
"try",
":",
"self",
".",
"_fill_and_stroke",
"(",
"ctx",
",",
"rgbFace",
",",
"gc",
".",
"get_alpha",
"(",
")",
",",
"gc",
".",
"get_forced_alpha",
"(",
")",
")",
"except",
"AttributeError",
":",
"# Workaround for some Windiws version of Cairo",
"self",
".",
"_fill_and_stroke",
"(",
"ctx",
",",
"rgbFace",
",",
"gc",
".",
"get_alpha",
"(",
")",
")",
"def",
"draw_image",
"(",
"self",
",",
"gc",
",",
"x",
",",
"y",
",",
"im",
")",
":",
"# bbox - not currently used",
"rows",
",",
"cols",
",",
"buf",
"=",
"im",
".",
"color_conv",
"(",
"self",
".",
"BYTE_FORMAT",
")",
"surface",
"=",
"cairo",
".",
"ImageSurface",
".",
"create_for_data",
"(",
"buf",
",",
"cairo",
".",
"FORMAT_ARGB32",
",",
"cols",
",",
"rows",
",",
"cols",
"*",
"4",
")",
"ctx",
"=",
"gc",
".",
"ctx",
"y",
"=",
"self",
".",
"height",
"-",
"y",
"-",
"rows",
"ctx",
".",
"save",
"(",
")",
"ctx",
".",
"set_source_surface",
"(",
"surface",
",",
"x",
",",
"y",
")",
"if",
"gc",
".",
"get_alpha",
"(",
")",
"!=",
"1.0",
":",
"ctx",
".",
"paint_with_alpha",
"(",
"gc",
".",
"get_alpha",
"(",
")",
")",
"else",
":",
"ctx",
".",
"paint",
"(",
")",
"ctx",
".",
"restore",
"(",
")",
"if",
"pyplot",
"is",
"None",
":",
"# Matplotlib is not installed",
"return",
"FigureCanvasCairo",
"(",
"figure",
")",
"dpi",
"=",
"float",
"(",
"figure",
".",
"dpi",
")",
"# Set a border so that the figure is not cut off at the cell border",
"border_x",
"=",
"200",
"/",
"(",
"self",
".",
"rect",
"[",
"2",
"]",
"/",
"dpi",
")",
"**",
"2",
"border_y",
"=",
"200",
"/",
"(",
"self",
".",
"rect",
"[",
"3",
"]",
"/",
"dpi",
")",
"**",
"2",
"width",
"=",
"(",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"2",
"*",
"border_x",
")",
"/",
"dpi",
"height",
"=",
"(",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"2",
"*",
"border_y",
")",
"/",
"dpi",
"figure",
".",
"set_figwidth",
"(",
"width",
")",
"figure",
".",
"set_figheight",
"(",
"height",
")",
"renderer",
"=",
"CustomRendererCairo",
"(",
"dpi",
")",
"renderer",
".",
"set_width_height",
"(",
"width",
",",
"height",
")",
"renderer",
".",
"gc",
".",
"ctx",
"=",
"self",
".",
"context",
"renderer",
".",
"text_ctx",
"=",
"self",
".",
"context",
"self",
".",
"context",
".",
"save",
"(",
")",
"self",
".",
"context",
".",
"translate",
"(",
"border_x",
",",
"border_y",
"+",
"height",
"*",
"dpi",
")",
"figure",
".",
"draw",
"(",
"renderer",
")",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws matplotlib figure to context | [
"Draws",
"matplotlib",
"figure",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L500-L569 | train | 231,617 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer._get_text_color | 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)) | python | 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)) | [
"def",
"_get_text_color",
"(",
"self",
")",
":",
"color",
"=",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"textcolor\"",
"]",
"return",
"tuple",
"(",
"c",
"/",
"255.0",
"for",
"c",
"in",
"color_pack2rgb",
"(",
"color",
")",
")"
] | Returns text color rgb tuple of right line | [
"Returns",
"text",
"color",
"rgb",
"tuple",
"of",
"right",
"line"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L571-L575 | train | 231,618 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.set_font | 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 = {
wx.FONTSTYLE_NORMAL: None, # Do not set a style by default
wx.FONTSTYLE_SLANT: pango.STYLE_OBLIQUE,
wx.FONTSTYLE_ITALIC: pango.STYLE_ITALIC,
}
cell_attributes = self.code_array.cell_attributes[self.key]
# Text font attributes
textfont = cell_attributes["textfont"]
pointsize = cell_attributes["pointsize"]
fontweight = cell_attributes["fontweight"]
fontstyle = cell_attributes["fontstyle"]
underline = cell_attributes["underline"]
strikethrough = cell_attributes["strikethrough"]
# Now construct the pango font
font_description = pango.FontDescription(
" ".join([textfont, str(pointsize)]))
pango_layout.set_font_description(font_description)
attrs = pango.AttrList()
# Underline
attrs.insert(pango.AttrUnderline(underline, 0, MAX_RESULT_LENGTH))
# Weight
weight = wx2pango_weights[fontweight]
if weight is not None:
attrs.insert(pango.AttrWeight(weight, 0, MAX_RESULT_LENGTH))
# Style
style = wx2pango_styles[fontstyle]
if style is not None:
attrs.insert(pango.AttrStyle(style, 0, MAX_RESULT_LENGTH))
# Strikethrough
attrs.insert(pango.AttrStrikethrough(strikethrough, 0,
MAX_RESULT_LENGTH))
pango_layout.set_attributes(attrs) | python | 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 = {
wx.FONTSTYLE_NORMAL: None, # Do not set a style by default
wx.FONTSTYLE_SLANT: pango.STYLE_OBLIQUE,
wx.FONTSTYLE_ITALIC: pango.STYLE_ITALIC,
}
cell_attributes = self.code_array.cell_attributes[self.key]
# Text font attributes
textfont = cell_attributes["textfont"]
pointsize = cell_attributes["pointsize"]
fontweight = cell_attributes["fontweight"]
fontstyle = cell_attributes["fontstyle"]
underline = cell_attributes["underline"]
strikethrough = cell_attributes["strikethrough"]
# Now construct the pango font
font_description = pango.FontDescription(
" ".join([textfont, str(pointsize)]))
pango_layout.set_font_description(font_description)
attrs = pango.AttrList()
# Underline
attrs.insert(pango.AttrUnderline(underline, 0, MAX_RESULT_LENGTH))
# Weight
weight = wx2pango_weights[fontweight]
if weight is not None:
attrs.insert(pango.AttrWeight(weight, 0, MAX_RESULT_LENGTH))
# Style
style = wx2pango_styles[fontstyle]
if style is not None:
attrs.insert(pango.AttrStyle(style, 0, MAX_RESULT_LENGTH))
# Strikethrough
attrs.insert(pango.AttrStrikethrough(strikethrough, 0,
MAX_RESULT_LENGTH))
pango_layout.set_attributes(attrs) | [
"def",
"set_font",
"(",
"self",
",",
"pango_layout",
")",
":",
"wx2pango_weights",
"=",
"{",
"wx",
".",
"FONTWEIGHT_BOLD",
":",
"pango",
".",
"WEIGHT_BOLD",
",",
"wx",
".",
"FONTWEIGHT_LIGHT",
":",
"pango",
".",
"WEIGHT_LIGHT",
",",
"wx",
".",
"FONTWEIGHT_NORMAL",
":",
"None",
",",
"# Do not set a weight by default",
"}",
"wx2pango_styles",
"=",
"{",
"wx",
".",
"FONTSTYLE_NORMAL",
":",
"None",
",",
"# Do not set a style by default",
"wx",
".",
"FONTSTYLE_SLANT",
":",
"pango",
".",
"STYLE_OBLIQUE",
",",
"wx",
".",
"FONTSTYLE_ITALIC",
":",
"pango",
".",
"STYLE_ITALIC",
",",
"}",
"cell_attributes",
"=",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"# Text font attributes",
"textfont",
"=",
"cell_attributes",
"[",
"\"textfont\"",
"]",
"pointsize",
"=",
"cell_attributes",
"[",
"\"pointsize\"",
"]",
"fontweight",
"=",
"cell_attributes",
"[",
"\"fontweight\"",
"]",
"fontstyle",
"=",
"cell_attributes",
"[",
"\"fontstyle\"",
"]",
"underline",
"=",
"cell_attributes",
"[",
"\"underline\"",
"]",
"strikethrough",
"=",
"cell_attributes",
"[",
"\"strikethrough\"",
"]",
"# Now construct the pango font",
"font_description",
"=",
"pango",
".",
"FontDescription",
"(",
"\" \"",
".",
"join",
"(",
"[",
"textfont",
",",
"str",
"(",
"pointsize",
")",
"]",
")",
")",
"pango_layout",
".",
"set_font_description",
"(",
"font_description",
")",
"attrs",
"=",
"pango",
".",
"AttrList",
"(",
")",
"# Underline",
"attrs",
".",
"insert",
"(",
"pango",
".",
"AttrUnderline",
"(",
"underline",
",",
"0",
",",
"MAX_RESULT_LENGTH",
")",
")",
"# Weight",
"weight",
"=",
"wx2pango_weights",
"[",
"fontweight",
"]",
"if",
"weight",
"is",
"not",
"None",
":",
"attrs",
".",
"insert",
"(",
"pango",
".",
"AttrWeight",
"(",
"weight",
",",
"0",
",",
"MAX_RESULT_LENGTH",
")",
")",
"# Style",
"style",
"=",
"wx2pango_styles",
"[",
"fontstyle",
"]",
"if",
"style",
"is",
"not",
"None",
":",
"attrs",
".",
"insert",
"(",
"pango",
".",
"AttrStyle",
"(",
"style",
",",
"0",
",",
"MAX_RESULT_LENGTH",
")",
")",
"# Strikethrough",
"attrs",
".",
"insert",
"(",
"pango",
".",
"AttrStrikethrough",
"(",
"strikethrough",
",",
"0",
",",
"MAX_RESULT_LENGTH",
")",
")",
"pango_layout",
".",
"set_attributes",
"(",
"attrs",
")"
] | Sets the font for draw_text | [
"Sets",
"the",
"font",
"for",
"draw_text"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L577-L626 | train | 231,619 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer._draw_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()
extents_list = []
for char_no in xrange(start, stop):
char_extents = pit.get_char_extents()
underline_pixel_extents = [
char_extents[0] / pango.SCALE,
(char_extents[1] + char_extents[3]) / pango.SCALE - 2,
char_extents[2] / pango.SCALE,
4,
]
if extents_list:
if extents_list[-1][1] == underline_pixel_extents[1]:
# Same line
extents_list[-1][2] = extents_list[-1][2] + \
underline_pixel_extents[2]
else:
# Line break
extents_list.append(underline_pixel_extents)
else:
extents_list.append(underline_pixel_extents)
pit.next_char()
for extent in extents_list:
pangocairo.show_error_underline(ptx, *extent)
self.context.restore() | python | 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()
extents_list = []
for char_no in xrange(start, stop):
char_extents = pit.get_char_extents()
underline_pixel_extents = [
char_extents[0] / pango.SCALE,
(char_extents[1] + char_extents[3]) / pango.SCALE - 2,
char_extents[2] / pango.SCALE,
4,
]
if extents_list:
if extents_list[-1][1] == underline_pixel_extents[1]:
# Same line
extents_list[-1][2] = extents_list[-1][2] + \
underline_pixel_extents[2]
else:
# Line break
extents_list.append(underline_pixel_extents)
else:
extents_list.append(underline_pixel_extents)
pit.next_char()
for extent in extents_list:
pangocairo.show_error_underline(ptx, *extent)
self.context.restore() | [
"def",
"_draw_error_underline",
"(",
"self",
",",
"ptx",
",",
"pango_layout",
",",
"start",
",",
"stop",
")",
":",
"self",
".",
"context",
".",
"save",
"(",
")",
"self",
".",
"context",
".",
"set_source_rgb",
"(",
"1.0",
",",
"0.0",
",",
"0.0",
")",
"pit",
"=",
"pango_layout",
".",
"get_iter",
"(",
")",
"# Skip characters until start",
"for",
"i",
"in",
"xrange",
"(",
"start",
")",
":",
"pit",
".",
"next_char",
"(",
")",
"extents_list",
"=",
"[",
"]",
"for",
"char_no",
"in",
"xrange",
"(",
"start",
",",
"stop",
")",
":",
"char_extents",
"=",
"pit",
".",
"get_char_extents",
"(",
")",
"underline_pixel_extents",
"=",
"[",
"char_extents",
"[",
"0",
"]",
"/",
"pango",
".",
"SCALE",
",",
"(",
"char_extents",
"[",
"1",
"]",
"+",
"char_extents",
"[",
"3",
"]",
")",
"/",
"pango",
".",
"SCALE",
"-",
"2",
",",
"char_extents",
"[",
"2",
"]",
"/",
"pango",
".",
"SCALE",
",",
"4",
",",
"]",
"if",
"extents_list",
":",
"if",
"extents_list",
"[",
"-",
"1",
"]",
"[",
"1",
"]",
"==",
"underline_pixel_extents",
"[",
"1",
"]",
":",
"# Same line",
"extents_list",
"[",
"-",
"1",
"]",
"[",
"2",
"]",
"=",
"extents_list",
"[",
"-",
"1",
"]",
"[",
"2",
"]",
"+",
"underline_pixel_extents",
"[",
"2",
"]",
"else",
":",
"# Line break",
"extents_list",
".",
"append",
"(",
"underline_pixel_extents",
")",
"else",
":",
"extents_list",
".",
"append",
"(",
"underline_pixel_extents",
")",
"pit",
".",
"next_char",
"(",
")",
"for",
"extent",
"in",
"extents_list",
":",
"pangocairo",
".",
"show_error_underline",
"(",
"ptx",
",",
"*",
"extent",
")",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws an error underline | [
"Draws",
"an",
"error",
"underline"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L655-L693 | train | 231,620 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer._check_spelling | 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
"""
chkr = SpellChecker(lang)
chkr.set_text(text)
word_starts_ends = []
for err in chkr:
start = err.wordpos
stop = err.wordpos + len(err.word) + 1
word_starts_ends.append((start, stop))
return word_starts_ends | python | 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
"""
chkr = SpellChecker(lang)
chkr.set_text(text)
word_starts_ends = []
for err in chkr:
start = err.wordpos
stop = err.wordpos + len(err.word) + 1
word_starts_ends.append((start, stop))
return word_starts_ends | [
"def",
"_check_spelling",
"(",
"self",
",",
"text",
",",
"lang",
"=",
"\"en_US\"",
")",
":",
"chkr",
"=",
"SpellChecker",
"(",
"lang",
")",
"chkr",
".",
"set_text",
"(",
"text",
")",
"word_starts_ends",
"=",
"[",
"]",
"for",
"err",
"in",
"chkr",
":",
"start",
"=",
"err",
".",
"wordpos",
"stop",
"=",
"err",
".",
"wordpos",
"+",
"len",
"(",
"err",
".",
"word",
")",
"+",
"1",
"word_starts_ends",
".",
"append",
"(",
"(",
"start",
",",
"stop",
")",
")",
"return",
"word_starts_ends"
] | Returns a list of start stop tuples that have spelling errors
Parameters
----------
text: Unicode or string
\tThe text that is checked
lang: String, defaults to "en_US"
\tName of spell checking dictionary | [
"Returns",
"a",
"list",
"of",
"start",
"stop",
"tuples",
"that",
"have",
"spelling",
"errors"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L695-L718 | train | 231,621 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.draw_text | 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]
angle = cell_attributes["angle"]
if angle in [-90, 90]:
rect = self.rect[1], self.rect[0], self.rect[3], self.rect[2]
else:
rect = self.rect
# Text color attributes
self.context.set_source_rgb(*self._get_text_color())
ptx = pangocairo.CairoContext(self.context)
pango_layout = ptx.create_layout()
self.set_font(pango_layout)
pango_layout.set_wrap(pango.WRAP_WORD_CHAR)
pango_layout.set_width(int(round((rect[2] - 4.0) * pango.SCALE)))
try:
markup = cell_attributes["markup"]
except KeyError:
# Old file
markup = False
if markup:
with warnings.catch_warnings(record=True) as warning_lines:
warnings.resetwarnings()
warnings.simplefilter("always")
pango_layout.set_markup(unicode(content))
if warning_lines:
w2unicode = lambda m: unicode(m.message)
msg = u"\n".join(map(w2unicode, warning_lines))
pango_layout.set_text(msg)
else:
pango_layout.set_text(unicode(content))
alignment = cell_attributes["justification"]
pango_layout.set_alignment(wx2pango_alignment[alignment])
# Shift text for vertical alignment
extents = pango_layout.get_pixel_extents()
downshift = 0
if cell_attributes["vertical_align"] == "bottom":
downshift = rect[3] - extents[1][3] - 4
elif cell_attributes["vertical_align"] == "middle":
downshift = int((rect[3] - extents[1][3]) / 2) - 2
self.context.save()
self._rotate_cell(angle, rect)
self.context.translate(0, downshift)
# Spell check underline drawing
if SpellChecker is not None and self.spell_check:
text = unicode(pango_layout.get_text())
lang = config["spell_lang"]
for start, stop in self._check_spelling(text, lang=lang):
self._draw_error_underline(ptx, pango_layout, start, stop-1)
ptx.update_layout(pango_layout)
ptx.show_layout(pango_layout)
self.context.restore() | python | 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]
angle = cell_attributes["angle"]
if angle in [-90, 90]:
rect = self.rect[1], self.rect[0], self.rect[3], self.rect[2]
else:
rect = self.rect
# Text color attributes
self.context.set_source_rgb(*self._get_text_color())
ptx = pangocairo.CairoContext(self.context)
pango_layout = ptx.create_layout()
self.set_font(pango_layout)
pango_layout.set_wrap(pango.WRAP_WORD_CHAR)
pango_layout.set_width(int(round((rect[2] - 4.0) * pango.SCALE)))
try:
markup = cell_attributes["markup"]
except KeyError:
# Old file
markup = False
if markup:
with warnings.catch_warnings(record=True) as warning_lines:
warnings.resetwarnings()
warnings.simplefilter("always")
pango_layout.set_markup(unicode(content))
if warning_lines:
w2unicode = lambda m: unicode(m.message)
msg = u"\n".join(map(w2unicode, warning_lines))
pango_layout.set_text(msg)
else:
pango_layout.set_text(unicode(content))
alignment = cell_attributes["justification"]
pango_layout.set_alignment(wx2pango_alignment[alignment])
# Shift text for vertical alignment
extents = pango_layout.get_pixel_extents()
downshift = 0
if cell_attributes["vertical_align"] == "bottom":
downshift = rect[3] - extents[1][3] - 4
elif cell_attributes["vertical_align"] == "middle":
downshift = int((rect[3] - extents[1][3]) / 2) - 2
self.context.save()
self._rotate_cell(angle, rect)
self.context.translate(0, downshift)
# Spell check underline drawing
if SpellChecker is not None and self.spell_check:
text = unicode(pango_layout.get_text())
lang = config["spell_lang"]
for start, stop in self._check_spelling(text, lang=lang):
self._draw_error_underline(ptx, pango_layout, start, stop-1)
ptx.update_layout(pango_layout)
ptx.show_layout(pango_layout)
self.context.restore() | [
"def",
"draw_text",
"(",
"self",
",",
"content",
")",
":",
"wx2pango_alignment",
"=",
"{",
"\"left\"",
":",
"pango",
".",
"ALIGN_LEFT",
",",
"\"center\"",
":",
"pango",
".",
"ALIGN_CENTER",
",",
"\"right\"",
":",
"pango",
".",
"ALIGN_RIGHT",
",",
"}",
"cell_attributes",
"=",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"angle",
"=",
"cell_attributes",
"[",
"\"angle\"",
"]",
"if",
"angle",
"in",
"[",
"-",
"90",
",",
"90",
"]",
":",
"rect",
"=",
"self",
".",
"rect",
"[",
"1",
"]",
",",
"self",
".",
"rect",
"[",
"0",
"]",
",",
"self",
".",
"rect",
"[",
"3",
"]",
",",
"self",
".",
"rect",
"[",
"2",
"]",
"else",
":",
"rect",
"=",
"self",
".",
"rect",
"# Text color attributes",
"self",
".",
"context",
".",
"set_source_rgb",
"(",
"*",
"self",
".",
"_get_text_color",
"(",
")",
")",
"ptx",
"=",
"pangocairo",
".",
"CairoContext",
"(",
"self",
".",
"context",
")",
"pango_layout",
"=",
"ptx",
".",
"create_layout",
"(",
")",
"self",
".",
"set_font",
"(",
"pango_layout",
")",
"pango_layout",
".",
"set_wrap",
"(",
"pango",
".",
"WRAP_WORD_CHAR",
")",
"pango_layout",
".",
"set_width",
"(",
"int",
"(",
"round",
"(",
"(",
"rect",
"[",
"2",
"]",
"-",
"4.0",
")",
"*",
"pango",
".",
"SCALE",
")",
")",
")",
"try",
":",
"markup",
"=",
"cell_attributes",
"[",
"\"markup\"",
"]",
"except",
"KeyError",
":",
"# Old file",
"markup",
"=",
"False",
"if",
"markup",
":",
"with",
"warnings",
".",
"catch_warnings",
"(",
"record",
"=",
"True",
")",
"as",
"warning_lines",
":",
"warnings",
".",
"resetwarnings",
"(",
")",
"warnings",
".",
"simplefilter",
"(",
"\"always\"",
")",
"pango_layout",
".",
"set_markup",
"(",
"unicode",
"(",
"content",
")",
")",
"if",
"warning_lines",
":",
"w2unicode",
"=",
"lambda",
"m",
":",
"unicode",
"(",
"m",
".",
"message",
")",
"msg",
"=",
"u\"\\n\"",
".",
"join",
"(",
"map",
"(",
"w2unicode",
",",
"warning_lines",
")",
")",
"pango_layout",
".",
"set_text",
"(",
"msg",
")",
"else",
":",
"pango_layout",
".",
"set_text",
"(",
"unicode",
"(",
"content",
")",
")",
"alignment",
"=",
"cell_attributes",
"[",
"\"justification\"",
"]",
"pango_layout",
".",
"set_alignment",
"(",
"wx2pango_alignment",
"[",
"alignment",
"]",
")",
"# Shift text for vertical alignment",
"extents",
"=",
"pango_layout",
".",
"get_pixel_extents",
"(",
")",
"downshift",
"=",
"0",
"if",
"cell_attributes",
"[",
"\"vertical_align\"",
"]",
"==",
"\"bottom\"",
":",
"downshift",
"=",
"rect",
"[",
"3",
"]",
"-",
"extents",
"[",
"1",
"]",
"[",
"3",
"]",
"-",
"4",
"elif",
"cell_attributes",
"[",
"\"vertical_align\"",
"]",
"==",
"\"middle\"",
":",
"downshift",
"=",
"int",
"(",
"(",
"rect",
"[",
"3",
"]",
"-",
"extents",
"[",
"1",
"]",
"[",
"3",
"]",
")",
"/",
"2",
")",
"-",
"2",
"self",
".",
"context",
".",
"save",
"(",
")",
"self",
".",
"_rotate_cell",
"(",
"angle",
",",
"rect",
")",
"self",
".",
"context",
".",
"translate",
"(",
"0",
",",
"downshift",
")",
"# Spell check underline drawing",
"if",
"SpellChecker",
"is",
"not",
"None",
"and",
"self",
".",
"spell_check",
":",
"text",
"=",
"unicode",
"(",
"pango_layout",
".",
"get_text",
"(",
")",
")",
"lang",
"=",
"config",
"[",
"\"spell_lang\"",
"]",
"for",
"start",
",",
"stop",
"in",
"self",
".",
"_check_spelling",
"(",
"text",
",",
"lang",
"=",
"lang",
")",
":",
"self",
".",
"_draw_error_underline",
"(",
"ptx",
",",
"pango_layout",
",",
"start",
",",
"stop",
"-",
"1",
")",
"ptx",
".",
"update_layout",
"(",
"pango_layout",
")",
"ptx",
".",
"show_layout",
"(",
"pango_layout",
")",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws text cell content to context | [
"Draws",
"text",
"cell",
"content",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L720-L797 | train | 231,622 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.draw_roundedrect | 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 line to B
context.curve_to(x+w, y, x+w, y, x+w, y+r) # Curve to C
# Control points are both at Q
context.line_to(x+w, y+h-r) # Move to D
context.curve_to(x+w, y+h, x+w, y+h, x+w-r, y+h) # Curve to E
context.line_to(x+r, y+h) # Line to F
context.curve_to(x, y+h, x, y+h, x, y+h-r) # Curve to G
context.line_to(x, y+r) # Line to H
context.curve_to(x, y, x, y, x+r, y) # Curve to A
context.restore | python | 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 line to B
context.curve_to(x+w, y, x+w, y, x+w, y+r) # Curve to C
# Control points are both at Q
context.line_to(x+w, y+h-r) # Move to D
context.curve_to(x+w, y+h, x+w, y+h, x+w-r, y+h) # Curve to E
context.line_to(x+r, y+h) # Line to F
context.curve_to(x, y+h, x, y+h, x, y+h-r) # Curve to G
context.line_to(x, y+r) # Line to H
context.curve_to(x, y, x, y, x+r, y) # Curve to A
context.restore | [
"def",
"draw_roundedrect",
"(",
"self",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"r",
"=",
"10",
")",
":",
"# A****BQ",
"# H C",
"# * *",
"# G D",
"# F****E",
"context",
"=",
"self",
".",
"context",
"context",
".",
"save",
"context",
".",
"move_to",
"(",
"x",
"+",
"r",
",",
"y",
")",
"# Move to A",
"context",
".",
"line_to",
"(",
"x",
"+",
"w",
"-",
"r",
",",
"y",
")",
"# Straight line to B",
"context",
".",
"curve_to",
"(",
"x",
"+",
"w",
",",
"y",
",",
"x",
"+",
"w",
",",
"y",
",",
"x",
"+",
"w",
",",
"y",
"+",
"r",
")",
"# Curve to C",
"# Control points are both at Q",
"context",
".",
"line_to",
"(",
"x",
"+",
"w",
",",
"y",
"+",
"h",
"-",
"r",
")",
"# Move to D",
"context",
".",
"curve_to",
"(",
"x",
"+",
"w",
",",
"y",
"+",
"h",
",",
"x",
"+",
"w",
",",
"y",
"+",
"h",
",",
"x",
"+",
"w",
"-",
"r",
",",
"y",
"+",
"h",
")",
"# Curve to E",
"context",
".",
"line_to",
"(",
"x",
"+",
"r",
",",
"y",
"+",
"h",
")",
"# Line to F",
"context",
".",
"curve_to",
"(",
"x",
",",
"y",
"+",
"h",
",",
"x",
",",
"y",
"+",
"h",
",",
"x",
",",
"y",
"+",
"h",
"-",
"r",
")",
"# Curve to G",
"context",
".",
"line_to",
"(",
"x",
",",
"y",
"+",
"r",
")",
"# Line to H",
"context",
".",
"curve_to",
"(",
"x",
",",
"y",
",",
"x",
",",
"y",
",",
"x",
"+",
"r",
",",
"y",
")",
"# Curve to A",
"context",
".",
"restore"
] | Draws a rounded rectangle | [
"Draws",
"a",
"rounded",
"rectangle"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L799-L822 | train | 231,623 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.draw_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)
gradient.add_color_stop_rgba(1, 0.8, 0.8, 0.8, 0.9)
# # Transform the coordinates so the width and height are both 1
# # We save the current settings and restore them afterward
context.save()
context.scale(w, h)
context.rectangle(0, 0, 1, 1)
context.set_source_rgb(0, 0, 1)
context.set_source(gradient)
context.fill()
context.restore()
# Draw the button text
# Center the text
x_bearing, y_bearing, width, height, x_advance, y_advance = \
context.text_extents(label)
text_x = (w / 2.0)-(width / 2.0 + x_bearing)
text_y = (h / 2.0)-(height / 2.0 + y_bearing) + 1
# Draw the button text
context.move_to(text_x, text_y)
context.set_source_rgba(0, 0, 0, 1)
context.show_text(label)
# Draw the border of the button
context.move_to(x, y)
context.set_source_rgba(0, 0, 0, 1)
self.draw_roundedrect(x, y, w, h)
context.stroke() | python | 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)
gradient.add_color_stop_rgba(1, 0.8, 0.8, 0.8, 0.9)
# # Transform the coordinates so the width and height are both 1
# # We save the current settings and restore them afterward
context.save()
context.scale(w, h)
context.rectangle(0, 0, 1, 1)
context.set_source_rgb(0, 0, 1)
context.set_source(gradient)
context.fill()
context.restore()
# Draw the button text
# Center the text
x_bearing, y_bearing, width, height, x_advance, y_advance = \
context.text_extents(label)
text_x = (w / 2.0)-(width / 2.0 + x_bearing)
text_y = (h / 2.0)-(height / 2.0 + y_bearing) + 1
# Draw the button text
context.move_to(text_x, text_y)
context.set_source_rgba(0, 0, 0, 1)
context.show_text(label)
# Draw the border of the button
context.move_to(x, y)
context.set_source_rgba(0, 0, 0, 1)
self.draw_roundedrect(x, y, w, h)
context.stroke() | [
"def",
"draw_button",
"(",
"self",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"label",
")",
":",
"context",
"=",
"self",
".",
"context",
"self",
".",
"draw_roundedrect",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
"context",
".",
"clip",
"(",
")",
"# Set up the gradients",
"gradient",
"=",
"cairo",
".",
"LinearGradient",
"(",
"0",
",",
"0",
",",
"0",
",",
"1",
")",
"gradient",
".",
"add_color_stop_rgba",
"(",
"0",
",",
"0.5",
",",
"0.5",
",",
"0.5",
",",
"0.1",
")",
"gradient",
".",
"add_color_stop_rgba",
"(",
"1",
",",
"0.8",
",",
"0.8",
",",
"0.8",
",",
"0.9",
")",
"# # Transform the coordinates so the width and height are both 1",
"# # We save the current settings and restore them afterward",
"context",
".",
"save",
"(",
")",
"context",
".",
"scale",
"(",
"w",
",",
"h",
")",
"context",
".",
"rectangle",
"(",
"0",
",",
"0",
",",
"1",
",",
"1",
")",
"context",
".",
"set_source_rgb",
"(",
"0",
",",
"0",
",",
"1",
")",
"context",
".",
"set_source",
"(",
"gradient",
")",
"context",
".",
"fill",
"(",
")",
"context",
".",
"restore",
"(",
")",
"# Draw the button text",
"# Center the text",
"x_bearing",
",",
"y_bearing",
",",
"width",
",",
"height",
",",
"x_advance",
",",
"y_advance",
"=",
"context",
".",
"text_extents",
"(",
"label",
")",
"text_x",
"=",
"(",
"w",
"/",
"2.0",
")",
"-",
"(",
"width",
"/",
"2.0",
"+",
"x_bearing",
")",
"text_y",
"=",
"(",
"h",
"/",
"2.0",
")",
"-",
"(",
"height",
"/",
"2.0",
"+",
"y_bearing",
")",
"+",
"1",
"# Draw the button text",
"context",
".",
"move_to",
"(",
"text_x",
",",
"text_y",
")",
"context",
".",
"set_source_rgba",
"(",
"0",
",",
"0",
",",
"0",
",",
"1",
")",
"context",
".",
"show_text",
"(",
"label",
")",
"# Draw the border of the button",
"context",
".",
"move_to",
"(",
"x",
",",
"y",
")",
"context",
".",
"set_source_rgba",
"(",
"0",
",",
"0",
",",
"0",
",",
"1",
")",
"self",
".",
"draw_roundedrect",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
"context",
".",
"stroke",
"(",
")"
] | Draws a button | [
"Draws",
"a",
"button"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L824-L863 | train | 231,624 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellContentCairoRenderer.draw | 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(pos_x + 2, pos_y + 2)
cell_attributes = self.code_array.cell_attributes
# Do not draw cell content if cell is too small
# This allows blending out small cells by reducing height to 0
if self.rect[2] < cell_attributes[self.key]["borderwidth_right"] or \
self.rect[3] < cell_attributes[self.key]["borderwidth_bottom"]:
self.context.restore()
return
if self.code_array.cell_attributes[self.key]["button_cell"]:
# Render a button instead of the cell
label = self.code_array.cell_attributes[self.key]["button_cell"]
self.draw_button(1, 1, self.rect[2]-5, self.rect[3]-5, label)
elif isinstance(content, wx._gdi.Bitmap):
# A bitmap is returned --> Draw it!
self.draw_bitmap(content)
elif pyplot is not None and isinstance(content, pyplot.Figure):
# A matplotlib figure is returned --> Draw it!
self.draw_matplotlib_figure(content)
elif isinstance(content, basestring) and is_svg(content):
# The content is a vaid SVG xml string
self.draw_svg(content)
elif content is not None:
self.draw_text(content)
self.context.translate(-pos_x - 2, -pos_y - 2)
# Remove clipping to rect
self.context.restore() | python | 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(pos_x + 2, pos_y + 2)
cell_attributes = self.code_array.cell_attributes
# Do not draw cell content if cell is too small
# This allows blending out small cells by reducing height to 0
if self.rect[2] < cell_attributes[self.key]["borderwidth_right"] or \
self.rect[3] < cell_attributes[self.key]["borderwidth_bottom"]:
self.context.restore()
return
if self.code_array.cell_attributes[self.key]["button_cell"]:
# Render a button instead of the cell
label = self.code_array.cell_attributes[self.key]["button_cell"]
self.draw_button(1, 1, self.rect[2]-5, self.rect[3]-5, label)
elif isinstance(content, wx._gdi.Bitmap):
# A bitmap is returned --> Draw it!
self.draw_bitmap(content)
elif pyplot is not None and isinstance(content, pyplot.Figure):
# A matplotlib figure is returned --> Draw it!
self.draw_matplotlib_figure(content)
elif isinstance(content, basestring) and is_svg(content):
# The content is a vaid SVG xml string
self.draw_svg(content)
elif content is not None:
self.draw_text(content)
self.context.translate(-pos_x - 2, -pos_y - 2)
# Remove clipping to rect
self.context.restore() | [
"def",
"draw",
"(",
"self",
")",
":",
"# Content is only rendered within rect",
"self",
".",
"context",
".",
"save",
"(",
")",
"self",
".",
"context",
".",
"rectangle",
"(",
"*",
"self",
".",
"rect",
")",
"self",
".",
"context",
".",
"clip",
"(",
")",
"content",
"=",
"self",
".",
"get_cell_content",
"(",
")",
"pos_x",
",",
"pos_y",
"=",
"self",
".",
"rect",
"[",
":",
"2",
"]",
"self",
".",
"context",
".",
"translate",
"(",
"pos_x",
"+",
"2",
",",
"pos_y",
"+",
"2",
")",
"cell_attributes",
"=",
"self",
".",
"code_array",
".",
"cell_attributes",
"# Do not draw cell content if cell is too small",
"# This allows blending out small cells by reducing height to 0",
"if",
"self",
".",
"rect",
"[",
"2",
"]",
"<",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"borderwidth_right\"",
"]",
"or",
"self",
".",
"rect",
"[",
"3",
"]",
"<",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
":",
"self",
".",
"context",
".",
"restore",
"(",
")",
"return",
"if",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"button_cell\"",
"]",
":",
"# Render a button instead of the cell",
"label",
"=",
"self",
".",
"code_array",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"button_cell\"",
"]",
"self",
".",
"draw_button",
"(",
"1",
",",
"1",
",",
"self",
".",
"rect",
"[",
"2",
"]",
"-",
"5",
",",
"self",
".",
"rect",
"[",
"3",
"]",
"-",
"5",
",",
"label",
")",
"elif",
"isinstance",
"(",
"content",
",",
"wx",
".",
"_gdi",
".",
"Bitmap",
")",
":",
"# A bitmap is returned --> Draw it!",
"self",
".",
"draw_bitmap",
"(",
"content",
")",
"elif",
"pyplot",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"content",
",",
"pyplot",
".",
"Figure",
")",
":",
"# A matplotlib figure is returned --> Draw it!",
"self",
".",
"draw_matplotlib_figure",
"(",
"content",
")",
"elif",
"isinstance",
"(",
"content",
",",
"basestring",
")",
"and",
"is_svg",
"(",
"content",
")",
":",
"# The content is a vaid SVG xml string",
"self",
".",
"draw_svg",
"(",
"content",
")",
"elif",
"content",
"is",
"not",
"None",
":",
"self",
".",
"draw_text",
"(",
"content",
")",
"self",
".",
"context",
".",
"translate",
"(",
"-",
"pos_x",
"-",
"2",
",",
"-",
"pos_y",
"-",
"2",
")",
"# Remove clipping to rect",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws cell content to context | [
"Draws",
"cell",
"content",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L865-L911 | train | 231,625 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellBackgroundCairoRenderer._get_background_color | 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)) | python | 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)) | [
"def",
"_get_background_color",
"(",
"self",
")",
":",
"color",
"=",
"self",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"bgcolor\"",
"]",
"return",
"tuple",
"(",
"c",
"/",
"255.0",
"for",
"c",
"in",
"color_pack2rgb",
"(",
"color",
")",
")"
] | Returns background color rgb tuple of right line | [
"Returns",
"background",
"color",
"rgb",
"tuple",
"of",
"right",
"line"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L938-L942 | train | 231,626 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellBackgroundCairoRenderer._draw_frozen_pattern | 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 __x in numpy.arange(x-h, x+w, 5):
self.context.move_to(__x, y + h)
self.context.line_to(__x + h, y)
self.context.stroke()
self.context.restore() | python | 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 __x in numpy.arange(x-h, x+w, 5):
self.context.move_to(__x, y + h)
self.context.line_to(__x + h, y)
self.context.stroke()
self.context.restore() | [
"def",
"_draw_frozen_pattern",
"(",
"self",
")",
":",
"self",
".",
"context",
".",
"save",
"(",
")",
"x",
",",
"y",
",",
"w",
",",
"h",
"=",
"self",
".",
"rect",
"self",
".",
"context",
".",
"set_source_rgb",
"(",
"0",
",",
"0",
",",
"1",
")",
"self",
".",
"context",
".",
"set_line_width",
"(",
"0.25",
")",
"self",
".",
"context",
".",
"rectangle",
"(",
"*",
"self",
".",
"rect",
")",
"self",
".",
"context",
".",
"clip",
"(",
")",
"for",
"__x",
"in",
"numpy",
".",
"arange",
"(",
"x",
"-",
"h",
",",
"x",
"+",
"w",
",",
"5",
")",
":",
"self",
".",
"context",
".",
"move_to",
"(",
"__x",
",",
"y",
"+",
"h",
")",
"self",
".",
"context",
".",
"line_to",
"(",
"__x",
"+",
"h",
",",
"y",
")",
"self",
".",
"context",
".",
"stroke",
"(",
")",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws frozen pattern, i.e. diagonal lines | [
"Draws",
"frozen",
"pattern",
"i",
".",
"e",
".",
"diagonal",
"lines"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L944-L960 | train | 231,627 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellBackgroundCairoRenderer.draw | 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]["frozen"]:
self._draw_frozen_pattern() | python | 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]["frozen"]:
self._draw_frozen_pattern() | [
"def",
"draw",
"(",
"self",
")",
":",
"self",
".",
"context",
".",
"set_source_rgb",
"(",
"*",
"self",
".",
"_get_background_color",
"(",
")",
")",
"self",
".",
"context",
".",
"rectangle",
"(",
"*",
"self",
".",
"rect",
")",
"self",
".",
"context",
".",
"fill",
"(",
")",
"# If show frozen is active, show frozen pattern",
"if",
"self",
".",
"view_frozen",
"and",
"self",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"frozen\"",
"]",
":",
"self",
".",
"_draw_frozen_pattern",
"(",
")"
] | Draws cell background to context | [
"Draws",
"cell",
"background",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L962-L971 | train | 231,628 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorder.draw | 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() | python | 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() | [
"def",
"draw",
"(",
"self",
",",
"context",
")",
":",
"context",
".",
"set_line_width",
"(",
"self",
".",
"width",
")",
"context",
".",
"set_source_rgb",
"(",
"*",
"self",
".",
"color",
")",
"context",
".",
"move_to",
"(",
"*",
"self",
".",
"start_point",
")",
"context",
".",
"line_to",
"(",
"*",
"self",
".",
"end_point",
")",
"context",
".",
"stroke",
"(",
")"
] | Draws self to Cairo context | [
"Draws",
"self",
"to",
"Cairo",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L996-L1004 | train | 231,629 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_above_key_rect | 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,
self.width, border_width_bottom)
return key_above, rect_above | python | 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,
self.width, border_width_bottom)
return key_above, rect_above | [
"def",
"get_above_key_rect",
"(",
"self",
")",
":",
"key_above",
"=",
"self",
".",
"row",
"-",
"1",
",",
"self",
".",
"col",
",",
"self",
".",
"tab",
"border_width_bottom",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"key_above",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
")",
"/",
"2.0",
"rect_above",
"=",
"(",
"self",
".",
"x",
",",
"self",
".",
"y",
"-",
"border_width_bottom",
",",
"self",
".",
"width",
",",
"border_width_bottom",
")",
"return",
"key_above",
",",
"rect_above"
] | Returns tuple key rect of above cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"above",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1015-L1025 | train | 231,630 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_below_key_rect | 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,
self.width, border_width_bottom)
return key_below, rect_below | python | 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,
self.width, border_width_bottom)
return key_below, rect_below | [
"def",
"get_below_key_rect",
"(",
"self",
")",
":",
"key_below",
"=",
"self",
".",
"row",
"+",
"1",
",",
"self",
".",
"col",
",",
"self",
".",
"tab",
"border_width_bottom",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
")",
"/",
"2.0",
"rect_below",
"=",
"(",
"self",
".",
"x",
",",
"self",
".",
"y",
"+",
"self",
".",
"height",
",",
"self",
".",
"width",
",",
"border_width_bottom",
")",
"return",
"key_below",
",",
"rect_below"
] | Returns tuple key rect of below cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"below",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1027-L1037 | train | 231,631 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_left_key_rect | 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,
border_width_right, self.height)
return key_left, rect_left | python | 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,
border_width_right, self.height)
return key_left, rect_left | [
"def",
"get_left_key_rect",
"(",
"self",
")",
":",
"key_left",
"=",
"self",
".",
"row",
",",
"self",
".",
"col",
"-",
"1",
",",
"self",
".",
"tab",
"border_width_right",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"key_left",
"]",
"[",
"\"borderwidth_right\"",
"]",
")",
"/",
"2.0",
"rect_left",
"=",
"(",
"self",
".",
"x",
"-",
"border_width_right",
",",
"self",
".",
"y",
",",
"border_width_right",
",",
"self",
".",
"height",
")",
"return",
"key_left",
",",
"rect_left"
] | Returns tuple key rect of left cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"left",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1039-L1049 | train | 231,632 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_right_key_rect | 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,
border_width_right, self.height)
return key_right, rect_right | python | 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,
border_width_right, self.height)
return key_right, rect_right | [
"def",
"get_right_key_rect",
"(",
"self",
")",
":",
"key_right",
"=",
"self",
".",
"row",
",",
"self",
".",
"col",
"+",
"1",
",",
"self",
".",
"tab",
"border_width_right",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"borderwidth_right\"",
"]",
")",
"/",
"2.0",
"rect_right",
"=",
"(",
"self",
".",
"x",
"+",
"self",
".",
"width",
",",
"self",
".",
"y",
",",
"border_width_right",
",",
"self",
".",
"height",
")",
"return",
"key_right",
",",
"rect_right"
] | Returns tuple key rect of right cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"right",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1051-L1061 | train | 231,633 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_above_left_key_rect | 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 = \
float(self.cell_attributes[key_above_left]["borderwidth_bottom"]) \
/ 2.0
rect_above_left = (self.x-border_width_right,
self.y-border_width_bottom,
border_width_right, border_width_bottom)
return key_above_left, rect_above_left | python | 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 = \
float(self.cell_attributes[key_above_left]["borderwidth_bottom"]) \
/ 2.0
rect_above_left = (self.x-border_width_right,
self.y-border_width_bottom,
border_width_right, border_width_bottom)
return key_above_left, rect_above_left | [
"def",
"get_above_left_key_rect",
"(",
"self",
")",
":",
"key_above_left",
"=",
"self",
".",
"row",
"-",
"1",
",",
"self",
".",
"col",
"-",
"1",
",",
"self",
".",
"tab",
"border_width_right",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"key_above_left",
"]",
"[",
"\"borderwidth_right\"",
"]",
")",
"/",
"2.0",
"border_width_bottom",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"key_above_left",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
")",
"/",
"2.0",
"rect_above_left",
"=",
"(",
"self",
".",
"x",
"-",
"border_width_right",
",",
"self",
".",
"y",
"-",
"border_width_bottom",
",",
"border_width_right",
",",
"border_width_bottom",
")",
"return",
"key_above_left",
",",
"rect_above_left"
] | Returns tuple key rect of above left cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"above",
"left",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1063-L1078 | train | 231,634 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_above_right_key_rect | 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
border_width_bottom = \
float(self.cell_attributes[key_above_right]["borderwidth_bottom"])\
/ 2.0
rect_above_right = (self.x+self.width, self.y-border_width_bottom,
border_width_right, border_width_bottom)
return key_above_right, rect_above_right | python | 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
border_width_bottom = \
float(self.cell_attributes[key_above_right]["borderwidth_bottom"])\
/ 2.0
rect_above_right = (self.x+self.width, self.y-border_width_bottom,
border_width_right, border_width_bottom)
return key_above_right, rect_above_right | [
"def",
"get_above_right_key_rect",
"(",
"self",
")",
":",
"key_above",
"=",
"self",
".",
"row",
"-",
"1",
",",
"self",
".",
"col",
",",
"self",
".",
"tab",
"key_above_right",
"=",
"self",
".",
"row",
"-",
"1",
",",
"self",
".",
"col",
"+",
"1",
",",
"self",
".",
"tab",
"border_width_right",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"key_above",
"]",
"[",
"\"borderwidth_right\"",
"]",
")",
"/",
"2.0",
"border_width_bottom",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"key_above_right",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
")",
"/",
"2.0",
"rect_above_right",
"=",
"(",
"self",
".",
"x",
"+",
"self",
".",
"width",
",",
"self",
".",
"y",
"-",
"border_width_bottom",
",",
"border_width_right",
",",
"border_width_bottom",
")",
"return",
"key_above_right",
",",
"rect_above_right"
] | Returns tuple key rect of above right cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"above",
"right",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1080-L1094 | train | 231,635 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_below_left_key_rect | 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"]) \
/ 2.0
border_width_bottom = \
float(self.cell_attributes[key_left]["borderwidth_bottom"]) / 2.0
rect_below_left = (self.x-border_width_right, self.y-self.height,
border_width_right, border_width_bottom)
return key_below_left, rect_below_left | python | 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"]) \
/ 2.0
border_width_bottom = \
float(self.cell_attributes[key_left]["borderwidth_bottom"]) / 2.0
rect_below_left = (self.x-border_width_right, self.y-self.height,
border_width_right, border_width_bottom)
return key_below_left, rect_below_left | [
"def",
"get_below_left_key_rect",
"(",
"self",
")",
":",
"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\"",
"]",
")",
"/",
"2.0",
"border_width_bottom",
"=",
"float",
"(",
"self",
".",
"cell_attributes",
"[",
"key_left",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
")",
"/",
"2.0",
"rect_below_left",
"=",
"(",
"self",
".",
"x",
"-",
"border_width_right",
",",
"self",
".",
"y",
"-",
"self",
".",
"height",
",",
"border_width_right",
",",
"border_width_bottom",
")",
"return",
"key_below_left",
",",
"rect_below_left"
] | Returns tuple key rect of below left cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"below",
"left",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1096-L1110 | train | 231,636 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | Cell.get_below_right_key_rect | 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.cell_attributes[self.key]["borderwidth_bottom"]) / 2.0
rect_below_right = (self.x+self.width, self.y-self.height,
border_width_right, border_width_bottom)
return key_below_right, rect_below_right | python | 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.cell_attributes[self.key]["borderwidth_bottom"]) / 2.0
rect_below_right = (self.x+self.width, self.y-self.height,
border_width_right, border_width_bottom)
return key_below_right, rect_below_right | [
"def",
"get_below_right_key_rect",
"(",
"self",
")",
":",
"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",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
")",
"/",
"2.0",
"rect_below_right",
"=",
"(",
"self",
".",
"x",
"+",
"self",
".",
"width",
",",
"self",
".",
"y",
"-",
"self",
".",
"height",
",",
"border_width_right",
",",
"border_width_bottom",
")",
"return",
"key_below_right",
",",
"rect_below_right"
] | Returns tuple key rect of below right cell | [
"Returns",
"tuple",
"key",
"rect",
"of",
"below",
"right",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1112-L1124 | train | 231,637 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders._get_bottom_line_coordinates | 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 | python | 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 | [
"def",
"_get_bottom_line_coordinates",
"(",
"self",
")",
":",
"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 start and stop coordinates of bottom line | [
"Returns",
"start",
"and",
"stop",
"coordinates",
"of",
"bottom",
"line"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1151-L1159 | train | 231,638 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders._get_bottom_line_color | 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)) | python | 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)) | [
"def",
"_get_bottom_line_color",
"(",
"self",
")",
":",
"color",
"=",
"self",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"bordercolor_bottom\"",
"]",
"return",
"tuple",
"(",
"c",
"/",
"255.0",
"for",
"c",
"in",
"color_pack2rgb",
"(",
"color",
")",
")"
] | Returns color rgb tuple of bottom line | [
"Returns",
"color",
"rgb",
"tuple",
"of",
"bottom",
"line"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1171-L1175 | train | 231,639 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders._get_right_line_color | 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)) | python | 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)) | [
"def",
"_get_right_line_color",
"(",
"self",
")",
":",
"color",
"=",
"self",
".",
"cell_attributes",
"[",
"self",
".",
"key",
"]",
"[",
"\"bordercolor_right\"",
"]",
"return",
"tuple",
"(",
"c",
"/",
"255.0",
"for",
"c",
"in",
"color_pack2rgb",
"(",
"color",
")",
")"
] | Returns color rgb tuple of right line | [
"Returns",
"color",
"rgb",
"tuple",
"of",
"right",
"line"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1177-L1181 | train | 231,640 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_b | 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) | python | 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) | [
"def",
"get_b",
"(",
"self",
")",
":",
"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 bottom border of the cell | [
"Returns",
"the",
"bottom",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1193-L1200 | train | 231,641 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_r | 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) | python | 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) | [
"def",
"get_r",
"(",
"self",
")",
":",
"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 right border of the cell | [
"Returns",
"the",
"right",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1202-L1209 | train | 231,642 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_t | 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() | python | 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() | [
"def",
"get_t",
"(",
"self",
")",
":",
"cell_above",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_above_key_rect",
"(",
")",
")",
"return",
"cell_above",
".",
"get_b",
"(",
")"
] | Returns the top border of the cell | [
"Returns",
"the",
"top",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1211-L1216 | train | 231,643 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_l | 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() | python | 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() | [
"def",
"get_l",
"(",
"self",
")",
":",
"cell_left",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_left_key_rect",
"(",
")",
")",
"return",
"cell_left",
".",
"get_r",
"(",
")"
] | Returns the left border of the cell | [
"Returns",
"the",
"left",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1218-L1223 | train | 231,644 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_tl | 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() | python | 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() | [
"def",
"get_tl",
"(",
"self",
")",
":",
"cell_above_left",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_above_left_key_rect",
"(",
")",
")",
"return",
"cell_above_left",
".",
"get_r",
"(",
")"
] | Returns the top left border of the cell | [
"Returns",
"the",
"top",
"left",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1225-L1230 | train | 231,645 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_tr | 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() | python | 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() | [
"def",
"get_tr",
"(",
"self",
")",
":",
"cell_above",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_above_key_rect",
"(",
")",
")",
"return",
"cell_above",
".",
"get_r",
"(",
")"
] | Returns the top right border of the cell | [
"Returns",
"the",
"top",
"right",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1232-L1237 | train | 231,646 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_rt | 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() | python | 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() | [
"def",
"get_rt",
"(",
"self",
")",
":",
"cell_above_right",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_above_right_key_rect",
"(",
")",
")",
"return",
"cell_above_right",
".",
"get_b",
"(",
")"
] | Returns the right top border of the cell | [
"Returns",
"the",
"right",
"top",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1239-L1244 | train | 231,647 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_rb | 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() | python | 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() | [
"def",
"get_rb",
"(",
"self",
")",
":",
"cell_right",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_right_key_rect",
"(",
")",
")",
"return",
"cell_right",
".",
"get_b",
"(",
")"
] | Returns the right bottom border of the cell | [
"Returns",
"the",
"right",
"bottom",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1246-L1251 | train | 231,648 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_br | 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() | python | 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() | [
"def",
"get_br",
"(",
"self",
")",
":",
"cell_below",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_below_key_rect",
"(",
")",
")",
"return",
"cell_below",
".",
"get_r",
"(",
")"
] | Returns the bottom right border of the cell | [
"Returns",
"the",
"bottom",
"right",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1253-L1258 | train | 231,649 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_bl | 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() | python | 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() | [
"def",
"get_bl",
"(",
"self",
")",
":",
"cell_below_left",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_below_left_key_rect",
"(",
")",
")",
"return",
"cell_below_left",
".",
"get_r",
"(",
")"
] | Returns the bottom left border of the cell | [
"Returns",
"the",
"bottom",
"left",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1260-L1265 | train | 231,650 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_lb | 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() | python | 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() | [
"def",
"get_lb",
"(",
"self",
")",
":",
"cell_left",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_left_key_rect",
"(",
")",
")",
"return",
"cell_left",
".",
"get_b",
"(",
")"
] | Returns the left bottom border of the cell | [
"Returns",
"the",
"left",
"bottom",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1267-L1272 | train | 231,651 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.get_lt | 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() | python | 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() | [
"def",
"get_lt",
"(",
"self",
")",
":",
"cell_above_left",
"=",
"CellBorders",
"(",
"self",
".",
"cell_attributes",
",",
"*",
"self",
".",
"cell",
".",
"get_above_left_key_rect",
"(",
")",
")",
"return",
"cell_above_left",
".",
"get_b",
"(",
")"
] | Returns the left top border of the cell | [
"Returns",
"the",
"left",
"top",
"border",
"of",
"the",
"cell"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1274-L1279 | train | 231,652 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | CellBorders.gen_all | 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:
yield borderfunc() | python | 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:
yield borderfunc() | [
"def",
"gen_all",
"(",
"self",
")",
":",
"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",
":",
"yield",
"borderfunc",
"(",
")"
] | Generator of all borders | [
"Generator",
"of",
"all",
"borders"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1281-L1291 | train | 231,653 |
manns/pyspread | pyspread/src/lib/_grid_cairo_renderer.py | GridCellBorderCairoRenderer.draw | 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.cell_attributes, self.key, self.rect)
borders = list(cell_borders.gen_all())
borders.sort(key=attrgetter('width', 'color'))
for border in borders:
border.draw(self.context)
self.context.restore() | python | 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.cell_attributes, self.key, self.rect)
borders = list(cell_borders.gen_all())
borders.sort(key=attrgetter('width', 'color'))
for border in borders:
border.draw(self.context)
self.context.restore() | [
"def",
"draw",
"(",
"self",
")",
":",
"# 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",
".",
"cell_attributes",
",",
"self",
".",
"key",
",",
"self",
".",
"rect",
")",
"borders",
"=",
"list",
"(",
"cell_borders",
".",
"gen_all",
"(",
")",
")",
"borders",
".",
"sort",
"(",
"key",
"=",
"attrgetter",
"(",
"'width'",
",",
"'color'",
")",
")",
"for",
"border",
"in",
"borders",
":",
"border",
".",
"draw",
"(",
"self",
".",
"context",
")",
"self",
".",
"context",
".",
"restore",
"(",
")"
] | Draws cell border to context | [
"Draws",
"cell",
"border",
"to",
"context"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/_grid_cairo_renderer.py#L1316-L1332 | train | 231,654 |
manns/pyspread | pyspread/src/gui/_grid_renderer.py | GridRenderer._draw_cursor | 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 = grid.CellToRect(row, col)
rect = self.get_merged_rect(grid, key, rect)
# Check if cell is invisible
if rect is None:
return
size = self.get_zoomed_size(1.0)
caret_length = int(min([rect.width, rect.height]) / 5.0)
color = get_color(config["text_color"])
if pen is None:
pen = wx.Pen(color)
if brush is None:
brush = wx.Brush(color)
pen.SetWidth(size)
# Inner right and lower borders
border_left = rect.x + size - 1
border_right = rect.x + rect.width - size - 1
border_upper = rect.y + size - 1
border_lower = rect.y + rect.height - size - 1
points_lr = [
(border_right, border_lower - caret_length),
(border_right, border_lower),
(border_right - caret_length, border_lower),
(border_right, border_lower),
]
points_ur = [
(border_right, border_upper + caret_length),
(border_right, border_upper),
(border_right - caret_length, border_upper),
(border_right, border_upper),
]
points_ul = [
(border_left, border_upper + caret_length),
(border_left, border_upper),
(border_left + caret_length, border_upper),
(border_left, border_upper),
]
points_ll = [
(border_left, border_lower - caret_length),
(border_left, border_lower),
(border_left + caret_length, border_lower),
(border_left, border_lower),
]
point_list = [points_lr, points_ur, points_ul, points_ll]
dc.DrawPolygonList(point_list, pens=pen, brushes=brush)
self.old_cursor_row_col = row, col | python | 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 = grid.CellToRect(row, col)
rect = self.get_merged_rect(grid, key, rect)
# Check if cell is invisible
if rect is None:
return
size = self.get_zoomed_size(1.0)
caret_length = int(min([rect.width, rect.height]) / 5.0)
color = get_color(config["text_color"])
if pen is None:
pen = wx.Pen(color)
if brush is None:
brush = wx.Brush(color)
pen.SetWidth(size)
# Inner right and lower borders
border_left = rect.x + size - 1
border_right = rect.x + rect.width - size - 1
border_upper = rect.y + size - 1
border_lower = rect.y + rect.height - size - 1
points_lr = [
(border_right, border_lower - caret_length),
(border_right, border_lower),
(border_right - caret_length, border_lower),
(border_right, border_lower),
]
points_ur = [
(border_right, border_upper + caret_length),
(border_right, border_upper),
(border_right - caret_length, border_upper),
(border_right, border_upper),
]
points_ul = [
(border_left, border_upper + caret_length),
(border_left, border_upper),
(border_left + caret_length, border_upper),
(border_left, border_upper),
]
points_ll = [
(border_left, border_lower - caret_length),
(border_left, border_lower),
(border_left + caret_length, border_lower),
(border_left, border_lower),
]
point_list = [points_lr, points_ur, points_ul, points_ll]
dc.DrawPolygonList(point_list, pens=pen, brushes=brush)
self.old_cursor_row_col = row, col | [
"def",
"_draw_cursor",
"(",
"self",
",",
"dc",
",",
"grid",
",",
"row",
",",
"col",
",",
"pen",
"=",
"None",
",",
"brush",
"=",
"None",
")",
":",
"# If in full screen mode draw no cursor",
"if",
"grid",
".",
"main_window",
".",
"IsFullScreen",
"(",
")",
":",
"return",
"key",
"=",
"row",
",",
"col",
",",
"grid",
".",
"current_table",
"rect",
"=",
"grid",
".",
"CellToRect",
"(",
"row",
",",
"col",
")",
"rect",
"=",
"self",
".",
"get_merged_rect",
"(",
"grid",
",",
"key",
",",
"rect",
")",
"# Check if cell is invisible",
"if",
"rect",
"is",
"None",
":",
"return",
"size",
"=",
"self",
".",
"get_zoomed_size",
"(",
"1.0",
")",
"caret_length",
"=",
"int",
"(",
"min",
"(",
"[",
"rect",
".",
"width",
",",
"rect",
".",
"height",
"]",
")",
"/",
"5.0",
")",
"color",
"=",
"get_color",
"(",
"config",
"[",
"\"text_color\"",
"]",
")",
"if",
"pen",
"is",
"None",
":",
"pen",
"=",
"wx",
".",
"Pen",
"(",
"color",
")",
"if",
"brush",
"is",
"None",
":",
"brush",
"=",
"wx",
".",
"Brush",
"(",
"color",
")",
"pen",
".",
"SetWidth",
"(",
"size",
")",
"# Inner right and lower borders",
"border_left",
"=",
"rect",
".",
"x",
"+",
"size",
"-",
"1",
"border_right",
"=",
"rect",
".",
"x",
"+",
"rect",
".",
"width",
"-",
"size",
"-",
"1",
"border_upper",
"=",
"rect",
".",
"y",
"+",
"size",
"-",
"1",
"border_lower",
"=",
"rect",
".",
"y",
"+",
"rect",
".",
"height",
"-",
"size",
"-",
"1",
"points_lr",
"=",
"[",
"(",
"border_right",
",",
"border_lower",
"-",
"caret_length",
")",
",",
"(",
"border_right",
",",
"border_lower",
")",
",",
"(",
"border_right",
"-",
"caret_length",
",",
"border_lower",
")",
",",
"(",
"border_right",
",",
"border_lower",
")",
",",
"]",
"points_ur",
"=",
"[",
"(",
"border_right",
",",
"border_upper",
"+",
"caret_length",
")",
",",
"(",
"border_right",
",",
"border_upper",
")",
",",
"(",
"border_right",
"-",
"caret_length",
",",
"border_upper",
")",
",",
"(",
"border_right",
",",
"border_upper",
")",
",",
"]",
"points_ul",
"=",
"[",
"(",
"border_left",
",",
"border_upper",
"+",
"caret_length",
")",
",",
"(",
"border_left",
",",
"border_upper",
")",
",",
"(",
"border_left",
"+",
"caret_length",
",",
"border_upper",
")",
",",
"(",
"border_left",
",",
"border_upper",
")",
",",
"]",
"points_ll",
"=",
"[",
"(",
"border_left",
",",
"border_lower",
"-",
"caret_length",
")",
",",
"(",
"border_left",
",",
"border_lower",
")",
",",
"(",
"border_left",
"+",
"caret_length",
",",
"border_lower",
")",
",",
"(",
"border_left",
",",
"border_lower",
")",
",",
"]",
"point_list",
"=",
"[",
"points_lr",
",",
"points_ur",
",",
"points_ul",
",",
"points_ll",
"]",
"dc",
".",
"DrawPolygonList",
"(",
"point_list",
",",
"pens",
"=",
"pen",
",",
"brushes",
"=",
"brush",
")",
"self",
".",
"old_cursor_row_col",
"=",
"row",
",",
"col"
] | Draws cursor as Rectangle in lower right corner | [
"Draws",
"cursor",
"as",
"Rectangle",
"in",
"lower",
"right",
"corner"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_renderer.py#L91-L157 | train | 231,655 |
manns/pyspread | pyspread/src/gui/_grid_renderer.py | GridRenderer.update_cursor | 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), brush=wx.Brush(bgcolor))
self._draw_cursor(dc, grid, row, col) | python | 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), brush=wx.Brush(bgcolor))
self._draw_cursor(dc, grid, row, col) | [
"def",
"update_cursor",
"(",
"self",
",",
"dc",
",",
"grid",
",",
"row",
",",
"col",
")",
":",
"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",
")",
",",
"brush",
"=",
"wx",
".",
"Brush",
"(",
"bgcolor",
")",
")",
"self",
".",
"_draw_cursor",
"(",
"dc",
",",
"grid",
",",
"row",
",",
"col",
")"
] | Whites out the old cursor and draws the new one | [
"Whites",
"out",
"the",
"old",
"cursor",
"and",
"draws",
"the",
"new",
"one"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_renderer.py#L159-L168 | train | 231,656 |
manns/pyspread | pyspread/src/gui/_grid_renderer.py | GridRenderer.get_merged_rect | 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"]
if merge_area is None:
return rect
else:
# We have a merged cell
top, left, bottom, right = merge_area
# Are we drawing the top left cell?
if top == row and left == col:
# Set rect to merge area
ul_rect = grid.CellToRect(row, col)
br_rect = grid.CellToRect(bottom, right)
width = br_rect.x - ul_rect.x + br_rect.width
height = br_rect.y - ul_rect.y + br_rect.height
rect = wx.Rect(ul_rect.x, ul_rect.y, width, height)
return rect | python | 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"]
if merge_area is None:
return rect
else:
# We have a merged cell
top, left, bottom, right = merge_area
# Are we drawing the top left cell?
if top == row and left == col:
# Set rect to merge area
ul_rect = grid.CellToRect(row, col)
br_rect = grid.CellToRect(bottom, right)
width = br_rect.x - ul_rect.x + br_rect.width
height = br_rect.y - ul_rect.y + br_rect.height
rect = wx.Rect(ul_rect.x, ul_rect.y, width, height)
return rect | [
"def",
"get_merged_rect",
"(",
"self",
",",
"grid",
",",
"key",
",",
"rect",
")",
":",
"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\"",
"]",
"if",
"merge_area",
"is",
"None",
":",
"return",
"rect",
"else",
":",
"# We have a merged cell",
"top",
",",
"left",
",",
"bottom",
",",
"right",
"=",
"merge_area",
"# Are we drawing the top left cell?",
"if",
"top",
"==",
"row",
"and",
"left",
"==",
"col",
":",
"# Set rect to merge area",
"ul_rect",
"=",
"grid",
".",
"CellToRect",
"(",
"row",
",",
"col",
")",
"br_rect",
"=",
"grid",
".",
"CellToRect",
"(",
"bottom",
",",
"right",
")",
"width",
"=",
"br_rect",
".",
"x",
"-",
"ul_rect",
".",
"x",
"+",
"br_rect",
".",
"width",
"height",
"=",
"br_rect",
".",
"y",
"-",
"ul_rect",
".",
"y",
"+",
"br_rect",
".",
"height",
"rect",
"=",
"wx",
".",
"Rect",
"(",
"ul_rect",
".",
"x",
",",
"ul_rect",
".",
"y",
",",
"width",
",",
"height",
")",
"return",
"rect"
] | Returns cell rect for normal or merged cells and None for merged | [
"Returns",
"cell",
"rect",
"for",
"normal",
"or",
"merged",
"cells",
"and",
"None",
"for",
"merged"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_renderer.py#L175-L202 | train | 231,657 |
manns/pyspread | pyspread/src/gui/_grid_renderer.py | GridRenderer._get_drawn_rect | 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
if grid.is_merged_cell_drawn(key):
# Merging cell is outside view
row, col, __ = key = self.get_merging_cell(grid, key)
rect = grid.CellToRect(row, col)
rect = self.get_merged_rect(grid, key, rect)
else:
return
return rect | python | 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
if grid.is_merged_cell_drawn(key):
# Merging cell is outside view
row, col, __ = key = self.get_merging_cell(grid, key)
rect = grid.CellToRect(row, col)
rect = self.get_merged_rect(grid, key, rect)
else:
return
return rect | [
"def",
"_get_drawn_rect",
"(",
"self",
",",
"grid",
",",
"key",
",",
"rect",
")",
":",
"rect",
"=",
"self",
".",
"get_merged_rect",
"(",
"grid",
",",
"key",
",",
"rect",
")",
"if",
"rect",
"is",
"None",
":",
"# Merged cell is drawn",
"if",
"grid",
".",
"is_merged_cell_drawn",
"(",
"key",
")",
":",
"# Merging cell is outside view",
"row",
",",
"col",
",",
"__",
"=",
"key",
"=",
"self",
".",
"get_merging_cell",
"(",
"grid",
",",
"key",
")",
"rect",
"=",
"grid",
".",
"CellToRect",
"(",
"row",
",",
"col",
")",
"rect",
"=",
"self",
".",
"get_merged_rect",
"(",
"grid",
",",
"key",
",",
"rect",
")",
"else",
":",
"return",
"return",
"rect"
] | Replaces drawn rect if the one provided by wx is incorrect
This handles merged rects including those that are partly off screen. | [
"Replaces",
"drawn",
"rect",
"if",
"the",
"one",
"provided",
"by",
"wx",
"is",
"incorrect"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_renderer.py#L204-L222 | train | 231,658 |
manns/pyspread | pyspread/src/gui/_grid_renderer.py | GridRenderer._get_draw_cache_key | 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
# Button cells shall not be executed for preview
if grid.code_array.cell_attributes[key]["button_cell"]:
cell_preview = repr(grid.code_array(key))[:100]
__id = id(grid.code_array(key))
else:
cell_preview = repr(grid.code_array[key])[:100]
__id = id(grid.code_array[key])
sorted_keys = sorted(grid.code_array.cell_attributes[key].iteritems())
key_above_left = row - 1, col - 1, tab
key_above = row - 1, col, tab
key_above_right = row - 1, col + 1, tab
key_left = row, col - 1, tab
key_right = row, col + 1, tab
key_below_left = row + 1, col - 1, tab
key_below = row + 1, col, tab
borders = []
for k in [key, key_above_left, key_above, key_above_right,
key_left, key_right, key_below_left, key_below]:
borders.append(cell_attributes[k]["borderwidth_bottom"])
borders.append(cell_attributes[k]["borderwidth_right"])
borders.append(cell_attributes[k]["bordercolor_bottom"])
borders.append(cell_attributes[k]["bordercolor_right"])
return (zoomed_width, zoomed_height, is_selected, cell_preview, __id,
tuple(sorted_keys), tuple(borders)) | python | 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
# Button cells shall not be executed for preview
if grid.code_array.cell_attributes[key]["button_cell"]:
cell_preview = repr(grid.code_array(key))[:100]
__id = id(grid.code_array(key))
else:
cell_preview = repr(grid.code_array[key])[:100]
__id = id(grid.code_array[key])
sorted_keys = sorted(grid.code_array.cell_attributes[key].iteritems())
key_above_left = row - 1, col - 1, tab
key_above = row - 1, col, tab
key_above_right = row - 1, col + 1, tab
key_left = row, col - 1, tab
key_right = row, col + 1, tab
key_below_left = row + 1, col - 1, tab
key_below = row + 1, col, tab
borders = []
for k in [key, key_above_left, key_above, key_above_right,
key_left, key_right, key_below_left, key_below]:
borders.append(cell_attributes[k]["borderwidth_bottom"])
borders.append(cell_attributes[k]["borderwidth_right"])
borders.append(cell_attributes[k]["bordercolor_bottom"])
borders.append(cell_attributes[k]["bordercolor_right"])
return (zoomed_width, zoomed_height, is_selected, cell_preview, __id,
tuple(sorted_keys), tuple(borders)) | [
"def",
"_get_draw_cache_key",
"(",
"self",
",",
"grid",
",",
"key",
",",
"drawn_rect",
",",
"is_selected",
")",
":",
"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",
"# Button cells shall not be executed for preview",
"if",
"grid",
".",
"code_array",
".",
"cell_attributes",
"[",
"key",
"]",
"[",
"\"button_cell\"",
"]",
":",
"cell_preview",
"=",
"repr",
"(",
"grid",
".",
"code_array",
"(",
"key",
")",
")",
"[",
":",
"100",
"]",
"__id",
"=",
"id",
"(",
"grid",
".",
"code_array",
"(",
"key",
")",
")",
"else",
":",
"cell_preview",
"=",
"repr",
"(",
"grid",
".",
"code_array",
"[",
"key",
"]",
")",
"[",
":",
"100",
"]",
"__id",
"=",
"id",
"(",
"grid",
".",
"code_array",
"[",
"key",
"]",
")",
"sorted_keys",
"=",
"sorted",
"(",
"grid",
".",
"code_array",
".",
"cell_attributes",
"[",
"key",
"]",
".",
"iteritems",
"(",
")",
")",
"key_above_left",
"=",
"row",
"-",
"1",
",",
"col",
"-",
"1",
",",
"tab",
"key_above",
"=",
"row",
"-",
"1",
",",
"col",
",",
"tab",
"key_above_right",
"=",
"row",
"-",
"1",
",",
"col",
"+",
"1",
",",
"tab",
"key_left",
"=",
"row",
",",
"col",
"-",
"1",
",",
"tab",
"key_right",
"=",
"row",
",",
"col",
"+",
"1",
",",
"tab",
"key_below_left",
"=",
"row",
"+",
"1",
",",
"col",
"-",
"1",
",",
"tab",
"key_below",
"=",
"row",
"+",
"1",
",",
"col",
",",
"tab",
"borders",
"=",
"[",
"]",
"for",
"k",
"in",
"[",
"key",
",",
"key_above_left",
",",
"key_above",
",",
"key_above_right",
",",
"key_left",
",",
"key_right",
",",
"key_below_left",
",",
"key_below",
"]",
":",
"borders",
".",
"append",
"(",
"cell_attributes",
"[",
"k",
"]",
"[",
"\"borderwidth_bottom\"",
"]",
")",
"borders",
".",
"append",
"(",
"cell_attributes",
"[",
"k",
"]",
"[",
"\"borderwidth_right\"",
"]",
")",
"borders",
".",
"append",
"(",
"cell_attributes",
"[",
"k",
"]",
"[",
"\"bordercolor_bottom\"",
"]",
")",
"borders",
".",
"append",
"(",
"cell_attributes",
"[",
"k",
"]",
"[",
"\"bordercolor_right\"",
"]",
")",
"return",
"(",
"zoomed_width",
",",
"zoomed_height",
",",
"is_selected",
",",
"cell_preview",
",",
"__id",
",",
"tuple",
"(",
"sorted_keys",
")",
",",
"tuple",
"(",
"borders",
")",
")"
] | Returns key for the screen draw cache | [
"Returns",
"key",
"for",
"the",
"screen",
"draw",
"cache"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_renderer.py#L224-L261 | train | 231,659 |
manns/pyspread | pyspread/src/gui/_grid_renderer.py | GridRenderer._get_cairo_bmp | 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()
mdc.SetDeviceOrigin(0, 0)
context = wx.lib.wxcairo.ContextFromDC(mdc)
context.save()
# Zoom context
zoom = self.zoom
context.scale(zoom, zoom)
# Set off cell renderer by 1/2 a pixel to avoid blurry lines
rect_tuple = \
-0.5, -0.5, rect.width / zoom + 0.5, rect.height / zoom + 0.5
spell_check = config["check_spelling"]
cell_renderer = GridCellCairoRenderer(context, self.data_array,
key, rect_tuple, view_frozen,
spell_check=spell_check)
# Draw cell
cell_renderer.draw()
# Draw selection if present
if is_selected:
context.set_source_rgba(*self.selection_color_tuple)
context.rectangle(*rect_tuple)
context.fill()
context.restore()
return bmp | python | 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()
mdc.SetDeviceOrigin(0, 0)
context = wx.lib.wxcairo.ContextFromDC(mdc)
context.save()
# Zoom context
zoom = self.zoom
context.scale(zoom, zoom)
# Set off cell renderer by 1/2 a pixel to avoid blurry lines
rect_tuple = \
-0.5, -0.5, rect.width / zoom + 0.5, rect.height / zoom + 0.5
spell_check = config["check_spelling"]
cell_renderer = GridCellCairoRenderer(context, self.data_array,
key, rect_tuple, view_frozen,
spell_check=spell_check)
# Draw cell
cell_renderer.draw()
# Draw selection if present
if is_selected:
context.set_source_rgba(*self.selection_color_tuple)
context.rectangle(*rect_tuple)
context.fill()
context.restore()
return bmp | [
"def",
"_get_cairo_bmp",
"(",
"self",
",",
"mdc",
",",
"key",
",",
"rect",
",",
"is_selected",
",",
"view_frozen",
")",
":",
"bmp",
"=",
"wx",
".",
"EmptyBitmap",
"(",
"rect",
".",
"width",
",",
"rect",
".",
"height",
")",
"mdc",
".",
"SelectObject",
"(",
"bmp",
")",
"mdc",
".",
"SetBackgroundMode",
"(",
"wx",
".",
"SOLID",
")",
"mdc",
".",
"SetBackground",
"(",
"wx",
".",
"WHITE_BRUSH",
")",
"mdc",
".",
"Clear",
"(",
")",
"mdc",
".",
"SetDeviceOrigin",
"(",
"0",
",",
"0",
")",
"context",
"=",
"wx",
".",
"lib",
".",
"wxcairo",
".",
"ContextFromDC",
"(",
"mdc",
")",
"context",
".",
"save",
"(",
")",
"# Zoom context",
"zoom",
"=",
"self",
".",
"zoom",
"context",
".",
"scale",
"(",
"zoom",
",",
"zoom",
")",
"# Set off cell renderer by 1/2 a pixel to avoid blurry lines",
"rect_tuple",
"=",
"-",
"0.5",
",",
"-",
"0.5",
",",
"rect",
".",
"width",
"/",
"zoom",
"+",
"0.5",
",",
"rect",
".",
"height",
"/",
"zoom",
"+",
"0.5",
"spell_check",
"=",
"config",
"[",
"\"check_spelling\"",
"]",
"cell_renderer",
"=",
"GridCellCairoRenderer",
"(",
"context",
",",
"self",
".",
"data_array",
",",
"key",
",",
"rect_tuple",
",",
"view_frozen",
",",
"spell_check",
"=",
"spell_check",
")",
"# Draw cell",
"cell_renderer",
".",
"draw",
"(",
")",
"# Draw selection if present",
"if",
"is_selected",
":",
"context",
".",
"set_source_rgba",
"(",
"*",
"self",
".",
"selection_color_tuple",
")",
"context",
".",
"rectangle",
"(",
"*",
"rect_tuple",
")",
"context",
".",
"fill",
"(",
")",
"context",
".",
"restore",
"(",
")",
"return",
"bmp"
] | Returns a wx.Bitmap of cell key in size rect | [
"Returns",
"a",
"wx",
".",
"Bitmap",
"of",
"cell",
"key",
"in",
"size",
"rect"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_renderer.py#L263-L299 | train | 231,660 |
manns/pyspread | pyspread/src/gui/_grid_renderer.py | GridRenderer.Draw | 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_merging_cell(grid, key)
drawn_rect = self._get_drawn_rect(grid, key, rect)
if drawn_rect is None:
return
cell_cache_key = self._get_draw_cache_key(grid, key, drawn_rect,
isSelected)
mdc = wx.MemoryDC()
if vlc is not None and key in self.video_cells and \
grid.code_array.cell_attributes[key]["panel_cell"]:
# Update video position of previously created video panel
self.video_cells[key].SetClientRect(drawn_rect)
elif cell_cache_key in self.cell_cache:
mdc.SelectObject(self.cell_cache[cell_cache_key])
else:
code = grid.code_array(key)
if vlc is not None and code is not None and \
grid.code_array.cell_attributes[key]["panel_cell"]:
try:
# A panel is to be displayed
panel_cls = grid.code_array[key]
# Assert that we have a subclass of a wxPanel that we
# can instantiate
assert issubclass(panel_cls, wx.Panel)
video_panel = panel_cls(grid)
video_panel.SetClientRect(drawn_rect)
# Register video cell
self.video_cells[key] = video_panel
return
except Exception, err:
# Someting is wrong with the panel to be displayed
post_command_event(grid.main_window, self.StatusBarMsg,
text=unicode(err))
bmp = self._get_cairo_bmp(mdc, key, drawn_rect, isSelected,
grid._view_frozen)
else:
bmp = self._get_cairo_bmp(mdc, key, drawn_rect, isSelected,
grid._view_frozen)
# Put resulting bmp into cache
self.cell_cache[cell_cache_key] = bmp
dc.Blit(drawn_rect.x, drawn_rect.y,
drawn_rect.width, drawn_rect.height,
mdc, 0, 0, wx.COPY)
# Draw cursor
if grid.actions.cursor[:2] == (row, col):
self.update_cursor(dc, grid, row, col) | python | 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_merging_cell(grid, key)
drawn_rect = self._get_drawn_rect(grid, key, rect)
if drawn_rect is None:
return
cell_cache_key = self._get_draw_cache_key(grid, key, drawn_rect,
isSelected)
mdc = wx.MemoryDC()
if vlc is not None and key in self.video_cells and \
grid.code_array.cell_attributes[key]["panel_cell"]:
# Update video position of previously created video panel
self.video_cells[key].SetClientRect(drawn_rect)
elif cell_cache_key in self.cell_cache:
mdc.SelectObject(self.cell_cache[cell_cache_key])
else:
code = grid.code_array(key)
if vlc is not None and code is not None and \
grid.code_array.cell_attributes[key]["panel_cell"]:
try:
# A panel is to be displayed
panel_cls = grid.code_array[key]
# Assert that we have a subclass of a wxPanel that we
# can instantiate
assert issubclass(panel_cls, wx.Panel)
video_panel = panel_cls(grid)
video_panel.SetClientRect(drawn_rect)
# Register video cell
self.video_cells[key] = video_panel
return
except Exception, err:
# Someting is wrong with the panel to be displayed
post_command_event(grid.main_window, self.StatusBarMsg,
text=unicode(err))
bmp = self._get_cairo_bmp(mdc, key, drawn_rect, isSelected,
grid._view_frozen)
else:
bmp = self._get_cairo_bmp(mdc, key, drawn_rect, isSelected,
grid._view_frozen)
# Put resulting bmp into cache
self.cell_cache[cell_cache_key] = bmp
dc.Blit(drawn_rect.x, drawn_rect.y,
drawn_rect.width, drawn_rect.height,
mdc, 0, 0, wx.COPY)
# Draw cursor
if grid.actions.cursor[:2] == (row, col):
self.update_cursor(dc, grid, row, col) | [
"def",
"Draw",
"(",
"self",
",",
"grid",
",",
"attr",
",",
"dc",
",",
"rect",
",",
"row",
",",
"col",
",",
"isSelected",
")",
":",
"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_merging_cell",
"(",
"grid",
",",
"key",
")",
"drawn_rect",
"=",
"self",
".",
"_get_drawn_rect",
"(",
"grid",
",",
"key",
",",
"rect",
")",
"if",
"drawn_rect",
"is",
"None",
":",
"return",
"cell_cache_key",
"=",
"self",
".",
"_get_draw_cache_key",
"(",
"grid",
",",
"key",
",",
"drawn_rect",
",",
"isSelected",
")",
"mdc",
"=",
"wx",
".",
"MemoryDC",
"(",
")",
"if",
"vlc",
"is",
"not",
"None",
"and",
"key",
"in",
"self",
".",
"video_cells",
"and",
"grid",
".",
"code_array",
".",
"cell_attributes",
"[",
"key",
"]",
"[",
"\"panel_cell\"",
"]",
":",
"# Update video position of previously created video panel",
"self",
".",
"video_cells",
"[",
"key",
"]",
".",
"SetClientRect",
"(",
"drawn_rect",
")",
"elif",
"cell_cache_key",
"in",
"self",
".",
"cell_cache",
":",
"mdc",
".",
"SelectObject",
"(",
"self",
".",
"cell_cache",
"[",
"cell_cache_key",
"]",
")",
"else",
":",
"code",
"=",
"grid",
".",
"code_array",
"(",
"key",
")",
"if",
"vlc",
"is",
"not",
"None",
"and",
"code",
"is",
"not",
"None",
"and",
"grid",
".",
"code_array",
".",
"cell_attributes",
"[",
"key",
"]",
"[",
"\"panel_cell\"",
"]",
":",
"try",
":",
"# A panel is to be displayed",
"panel_cls",
"=",
"grid",
".",
"code_array",
"[",
"key",
"]",
"# Assert that we have a subclass of a wxPanel that we",
"# can instantiate",
"assert",
"issubclass",
"(",
"panel_cls",
",",
"wx",
".",
"Panel",
")",
"video_panel",
"=",
"panel_cls",
"(",
"grid",
")",
"video_panel",
".",
"SetClientRect",
"(",
"drawn_rect",
")",
"# Register video cell",
"self",
".",
"video_cells",
"[",
"key",
"]",
"=",
"video_panel",
"return",
"except",
"Exception",
",",
"err",
":",
"# Someting is wrong with the panel to be displayed",
"post_command_event",
"(",
"grid",
".",
"main_window",
",",
"self",
".",
"StatusBarMsg",
",",
"text",
"=",
"unicode",
"(",
"err",
")",
")",
"bmp",
"=",
"self",
".",
"_get_cairo_bmp",
"(",
"mdc",
",",
"key",
",",
"drawn_rect",
",",
"isSelected",
",",
"grid",
".",
"_view_frozen",
")",
"else",
":",
"bmp",
"=",
"self",
".",
"_get_cairo_bmp",
"(",
"mdc",
",",
"key",
",",
"drawn_rect",
",",
"isSelected",
",",
"grid",
".",
"_view_frozen",
")",
"# Put resulting bmp into cache",
"self",
".",
"cell_cache",
"[",
"cell_cache_key",
"]",
"=",
"bmp",
"dc",
".",
"Blit",
"(",
"drawn_rect",
".",
"x",
",",
"drawn_rect",
".",
"y",
",",
"drawn_rect",
".",
"width",
",",
"drawn_rect",
".",
"height",
",",
"mdc",
",",
"0",
",",
"0",
",",
"wx",
".",
"COPY",
")",
"# Draw cursor",
"if",
"grid",
".",
"actions",
".",
"cursor",
"[",
":",
"2",
"]",
"==",
"(",
"row",
",",
"col",
")",
":",
"self",
".",
"update_cursor",
"(",
"dc",
",",
"grid",
",",
"row",
",",
"col",
")"
] | Draws the cell border and content using pycairo | [
"Draws",
"the",
"cell",
"border",
"and",
"content",
"using",
"pycairo"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_grid_renderer.py#L301-L365 | train | 231,661 |
manns/pyspread | pyspread/src/lib/gpg.py | choose_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"]:
current_key_index = i
for uid_string in key['uids']:
uid_string_fp = '"' + uid_string + ' (' + fingerprint + ')'
uid_strings_fp.append(uid_string_fp)
uid_string_fp2key[uid_string_fp] = key
msg = _('Choose a GPG key for signing pyspread save files.\n'
'The GPG key must not have a passphrase set.')
dlg = wx.SingleChoiceDialog(None, msg, _('Choose key'), uid_strings_fp,
wx.CHOICEDLG_STYLE)
childlist = list(dlg.GetChildren())
childlist[-3].SetLabel(_("Use chosen key"))
childlist[-2].SetLabel(_("Create new key"))
if current_key_index is not None:
# Set choice to current key
dlg.SetSelection(current_key_index)
if dlg.ShowModal() == wx.ID_OK:
uid_string_fp = dlg.GetStringSelection()
key = uid_string_fp2key[uid_string_fp]
else:
key = None
dlg.Destroy()
return key | python | 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"]:
current_key_index = i
for uid_string in key['uids']:
uid_string_fp = '"' + uid_string + ' (' + fingerprint + ')'
uid_strings_fp.append(uid_string_fp)
uid_string_fp2key[uid_string_fp] = key
msg = _('Choose a GPG key for signing pyspread save files.\n'
'The GPG key must not have a passphrase set.')
dlg = wx.SingleChoiceDialog(None, msg, _('Choose key'), uid_strings_fp,
wx.CHOICEDLG_STYLE)
childlist = list(dlg.GetChildren())
childlist[-3].SetLabel(_("Use chosen key"))
childlist[-2].SetLabel(_("Create new key"))
if current_key_index is not None:
# Set choice to current key
dlg.SetSelection(current_key_index)
if dlg.ShowModal() == wx.ID_OK:
uid_string_fp = dlg.GetStringSelection()
key = uid_string_fp2key[uid_string_fp]
else:
key = None
dlg.Destroy()
return key | [
"def",
"choose_key",
"(",
"gpg_private_keys",
")",
":",
"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\"",
"]",
":",
"current_key_index",
"=",
"i",
"for",
"uid_string",
"in",
"key",
"[",
"'uids'",
"]",
":",
"uid_string_fp",
"=",
"'\"'",
"+",
"uid_string",
"+",
"' ('",
"+",
"fingerprint",
"+",
"')'",
"uid_strings_fp",
".",
"append",
"(",
"uid_string_fp",
")",
"uid_string_fp2key",
"[",
"uid_string_fp",
"]",
"=",
"key",
"msg",
"=",
"_",
"(",
"'Choose a GPG key for signing pyspread save files.\\n'",
"'The GPG key must not have a passphrase set.'",
")",
"dlg",
"=",
"wx",
".",
"SingleChoiceDialog",
"(",
"None",
",",
"msg",
",",
"_",
"(",
"'Choose key'",
")",
",",
"uid_strings_fp",
",",
"wx",
".",
"CHOICEDLG_STYLE",
")",
"childlist",
"=",
"list",
"(",
"dlg",
".",
"GetChildren",
"(",
")",
")",
"childlist",
"[",
"-",
"3",
"]",
".",
"SetLabel",
"(",
"_",
"(",
"\"Use chosen key\"",
")",
")",
"childlist",
"[",
"-",
"2",
"]",
".",
"SetLabel",
"(",
"_",
"(",
"\"Create new key\"",
")",
")",
"if",
"current_key_index",
"is",
"not",
"None",
":",
"# Set choice to current key",
"dlg",
".",
"SetSelection",
"(",
"current_key_index",
")",
"if",
"dlg",
".",
"ShowModal",
"(",
")",
"==",
"wx",
".",
"ID_OK",
":",
"uid_string_fp",
"=",
"dlg",
".",
"GetStringSelection",
"(",
")",
"key",
"=",
"uid_string_fp2key",
"[",
"uid_string_fp",
"]",
"else",
":",
"key",
"=",
"None",
"dlg",
".",
"Destroy",
"(",
")",
"return",
"key"
] | Displays gpg key choice and returns key | [
"Displays",
"gpg",
"key",
"choice",
"and",
"returns",
"key"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/gpg.py#L53-L95 | train | 231,662 |
manns/pyspread | pyspread/src/lib/gpg.py | _register_key | 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:
pass | python | 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:
pass | [
"def",
"_register_key",
"(",
"fingerprint",
",",
"gpg",
")",
":",
"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",
":",
"pass"
] | Registers key in config | [
"Registers",
"key",
"in",
"config"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/gpg.py#L98-L107 | train | 231,663 |
manns/pyspread | pyspread/src/lib/gpg.py | has_no_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:
# This may happen on Windows
if hasattr(s, "stderr"):
return "GOOD_PASSPHRASE" in s.stderr | python | 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:
# This may happen on Windows
if hasattr(s, "stderr"):
return "GOOD_PASSPHRASE" in s.stderr | [
"def",
"has_no_password",
"(",
"gpg_secret_keyid",
")",
":",
"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",
":",
"# This may happen on Windows",
"if",
"hasattr",
"(",
"s",
",",
"\"stderr\"",
")",
":",
"return",
"\"GOOD_PASSPHRASE\"",
"in",
"s",
".",
"stderr"
] | Returns True iif gpg_secret_key has a password | [
"Returns",
"True",
"iif",
"gpg_secret_key",
"has",
"a",
"password"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/gpg.py#L110-L124 | train | 231,664 |
manns/pyspread | pyspread/src/lib/gpg.py | genkey | 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', '2048'),
('subkey_type', 'ELG-E'),
('subkey_length', '2048'),
('expire_date', '0'),
]
gpg = gnupg.GPG()
gpg.encoding = 'utf-8'
# Check if standard key is already present
pyspread_key_fingerprint = config["gpg_key_fingerprint"]
gpg_private_keys = [key for key in gpg.list_keys(secret=True)
if has_no_password(key["keyid"])]
gpg_private_fingerprints = \
[key['fingerprint'] for key in gpg.list_keys(secret=True)
if has_no_password(key["keyid"])]
pyspread_key = None
for private_key, fingerprint in zip(gpg_private_keys,
gpg_private_fingerprints):
if str(pyspread_key_fingerprint) == fingerprint:
pyspread_key = private_key
if gpg_private_keys:
# If GPG are available, choose one
pyspread_key = choose_key(gpg_private_keys)
if pyspread_key:
# A key has been chosen
config["gpg_key_fingerprint"] = repr(pyspread_key['fingerprint'])
else:
# No key has been chosen --> Create new one
if key_name is None:
gpg_key_parameters = get_key_params_from_user(gpg_key_param_list)
if gpg_key_parameters is None:
# No name entered
return
else:
gpg_key_param_list.append(
('name_real', '{key_name}'.format(key_name=key_name)))
gpg_key_parameters = dict(gpg_key_param_list)
input_data = gpg.gen_key_input(**gpg_key_parameters)
# Generate key
# ------------
if key_name is None:
# Show information dialog
style = wx.ICON_INFORMATION | wx.DIALOG_NO_PARENT | wx.OK | \
wx.CANCEL
pyspread_key_uid = gpg_key_parameters["name_real"]
short_message = _("New GPG key").format(pyspread_key_uid)
message = _("After confirming this dialog, a new GPG key ") + \
_("'{key}' will be generated.").format(key=pyspread_key_uid) +\
_(" \n \nThis may take some time.\nPlease wait.")
dlg = wx.MessageDialog(None, message, short_message, style)
dlg.Centre()
if dlg.ShowModal() == wx.ID_OK:
dlg.Destroy()
gpg_key = gpg.gen_key(input_data)
_register_key(gpg_key, gpg)
fingerprint = gpg_key.fingerprint
else:
dlg.Destroy()
return
else:
gpg_key = gpg.gen_key(input_data)
_register_key(gpg_key, gpg)
fingerprint = gpg_key.fingerprint
return fingerprint | python | 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', '2048'),
('subkey_type', 'ELG-E'),
('subkey_length', '2048'),
('expire_date', '0'),
]
gpg = gnupg.GPG()
gpg.encoding = 'utf-8'
# Check if standard key is already present
pyspread_key_fingerprint = config["gpg_key_fingerprint"]
gpg_private_keys = [key for key in gpg.list_keys(secret=True)
if has_no_password(key["keyid"])]
gpg_private_fingerprints = \
[key['fingerprint'] for key in gpg.list_keys(secret=True)
if has_no_password(key["keyid"])]
pyspread_key = None
for private_key, fingerprint in zip(gpg_private_keys,
gpg_private_fingerprints):
if str(pyspread_key_fingerprint) == fingerprint:
pyspread_key = private_key
if gpg_private_keys:
# If GPG are available, choose one
pyspread_key = choose_key(gpg_private_keys)
if pyspread_key:
# A key has been chosen
config["gpg_key_fingerprint"] = repr(pyspread_key['fingerprint'])
else:
# No key has been chosen --> Create new one
if key_name is None:
gpg_key_parameters = get_key_params_from_user(gpg_key_param_list)
if gpg_key_parameters is None:
# No name entered
return
else:
gpg_key_param_list.append(
('name_real', '{key_name}'.format(key_name=key_name)))
gpg_key_parameters = dict(gpg_key_param_list)
input_data = gpg.gen_key_input(**gpg_key_parameters)
# Generate key
# ------------
if key_name is None:
# Show information dialog
style = wx.ICON_INFORMATION | wx.DIALOG_NO_PARENT | wx.OK | \
wx.CANCEL
pyspread_key_uid = gpg_key_parameters["name_real"]
short_message = _("New GPG key").format(pyspread_key_uid)
message = _("After confirming this dialog, a new GPG key ") + \
_("'{key}' will be generated.").format(key=pyspread_key_uid) +\
_(" \n \nThis may take some time.\nPlease wait.")
dlg = wx.MessageDialog(None, message, short_message, style)
dlg.Centre()
if dlg.ShowModal() == wx.ID_OK:
dlg.Destroy()
gpg_key = gpg.gen_key(input_data)
_register_key(gpg_key, gpg)
fingerprint = gpg_key.fingerprint
else:
dlg.Destroy()
return
else:
gpg_key = gpg.gen_key(input_data)
_register_key(gpg_key, gpg)
fingerprint = gpg_key.fingerprint
return fingerprint | [
"def",
"genkey",
"(",
"key_name",
"=",
"None",
")",
":",
"if",
"gnupg",
"is",
"None",
":",
"return",
"gpg_key_param_list",
"=",
"[",
"(",
"'key_type'",
",",
"'DSA'",
")",
",",
"(",
"'key_length'",
",",
"'2048'",
")",
",",
"(",
"'subkey_type'",
",",
"'ELG-E'",
")",
",",
"(",
"'subkey_length'",
",",
"'2048'",
")",
",",
"(",
"'expire_date'",
",",
"'0'",
")",
",",
"]",
"gpg",
"=",
"gnupg",
".",
"GPG",
"(",
")",
"gpg",
".",
"encoding",
"=",
"'utf-8'",
"# Check if standard key is already present",
"pyspread_key_fingerprint",
"=",
"config",
"[",
"\"gpg_key_fingerprint\"",
"]",
"gpg_private_keys",
"=",
"[",
"key",
"for",
"key",
"in",
"gpg",
".",
"list_keys",
"(",
"secret",
"=",
"True",
")",
"if",
"has_no_password",
"(",
"key",
"[",
"\"keyid\"",
"]",
")",
"]",
"gpg_private_fingerprints",
"=",
"[",
"key",
"[",
"'fingerprint'",
"]",
"for",
"key",
"in",
"gpg",
".",
"list_keys",
"(",
"secret",
"=",
"True",
")",
"if",
"has_no_password",
"(",
"key",
"[",
"\"keyid\"",
"]",
")",
"]",
"pyspread_key",
"=",
"None",
"for",
"private_key",
",",
"fingerprint",
"in",
"zip",
"(",
"gpg_private_keys",
",",
"gpg_private_fingerprints",
")",
":",
"if",
"str",
"(",
"pyspread_key_fingerprint",
")",
"==",
"fingerprint",
":",
"pyspread_key",
"=",
"private_key",
"if",
"gpg_private_keys",
":",
"# If GPG are available, choose one",
"pyspread_key",
"=",
"choose_key",
"(",
"gpg_private_keys",
")",
"if",
"pyspread_key",
":",
"# A key has been chosen",
"config",
"[",
"\"gpg_key_fingerprint\"",
"]",
"=",
"repr",
"(",
"pyspread_key",
"[",
"'fingerprint'",
"]",
")",
"else",
":",
"# No key has been chosen --> Create new one",
"if",
"key_name",
"is",
"None",
":",
"gpg_key_parameters",
"=",
"get_key_params_from_user",
"(",
"gpg_key_param_list",
")",
"if",
"gpg_key_parameters",
"is",
"None",
":",
"# No name entered",
"return",
"else",
":",
"gpg_key_param_list",
".",
"append",
"(",
"(",
"'name_real'",
",",
"'{key_name}'",
".",
"format",
"(",
"key_name",
"=",
"key_name",
")",
")",
")",
"gpg_key_parameters",
"=",
"dict",
"(",
"gpg_key_param_list",
")",
"input_data",
"=",
"gpg",
".",
"gen_key_input",
"(",
"*",
"*",
"gpg_key_parameters",
")",
"# Generate key",
"# ------------",
"if",
"key_name",
"is",
"None",
":",
"# Show information dialog",
"style",
"=",
"wx",
".",
"ICON_INFORMATION",
"|",
"wx",
".",
"DIALOG_NO_PARENT",
"|",
"wx",
".",
"OK",
"|",
"wx",
".",
"CANCEL",
"pyspread_key_uid",
"=",
"gpg_key_parameters",
"[",
"\"name_real\"",
"]",
"short_message",
"=",
"_",
"(",
"\"New GPG key\"",
")",
".",
"format",
"(",
"pyspread_key_uid",
")",
"message",
"=",
"_",
"(",
"\"After confirming this dialog, a new GPG key \"",
")",
"+",
"_",
"(",
"\"'{key}' will be generated.\"",
")",
".",
"format",
"(",
"key",
"=",
"pyspread_key_uid",
")",
"+",
"_",
"(",
"\" \\n \\nThis may take some time.\\nPlease wait.\"",
")",
"dlg",
"=",
"wx",
".",
"MessageDialog",
"(",
"None",
",",
"message",
",",
"short_message",
",",
"style",
")",
"dlg",
".",
"Centre",
"(",
")",
"if",
"dlg",
".",
"ShowModal",
"(",
")",
"==",
"wx",
".",
"ID_OK",
":",
"dlg",
".",
"Destroy",
"(",
")",
"gpg_key",
"=",
"gpg",
".",
"gen_key",
"(",
"input_data",
")",
"_register_key",
"(",
"gpg_key",
",",
"gpg",
")",
"fingerprint",
"=",
"gpg_key",
".",
"fingerprint",
"else",
":",
"dlg",
".",
"Destroy",
"(",
")",
"return",
"else",
":",
"gpg_key",
"=",
"gpg",
".",
"gen_key",
"(",
"input_data",
")",
"_register_key",
"(",
"gpg_key",
",",
"gpg",
")",
"fingerprint",
"=",
"gpg_key",
".",
"fingerprint",
"return",
"fingerprint"
] | Creates a new standard GPG key
Parameters
----------
ui: Bool
\tIf True, then a new key is created when required without user interaction | [
"Creates",
"a",
"new",
"standard",
"GPG",
"key"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/gpg.py#L127-L221 | train | 231,665 |
manns/pyspread | pyspread/src/lib/gpg.py | fingerprint2keyid | 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"]:
keyid = private_key['keyid']
break
return keyid | python | 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"]:
keyid = private_key['keyid']
break
return keyid | [
"def",
"fingerprint2keyid",
"(",
"fingerprint",
")",
":",
"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\"",
"]",
":",
"keyid",
"=",
"private_key",
"[",
"'keyid'",
"]",
"break",
"return",
"keyid"
] | Returns keyid from fingerprint for private keys | [
"Returns",
"keyid",
"from",
"fingerprint",
"for",
"private",
"keys"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/gpg.py#L224-L239 | train | 231,666 |
manns/pyspread | pyspread/src/lib/gpg.py | sign | 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 '{}'."
raise ValueError(msg.format(config["gpg_key_fingerprint"]))
signed_data = gpg.sign_file(signfile, keyid=keyid, detach=True)
return signed_data | python | 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 '{}'."
raise ValueError(msg.format(config["gpg_key_fingerprint"]))
signed_data = gpg.sign_file(signfile, keyid=keyid, detach=True)
return signed_data | [
"def",
"sign",
"(",
"filename",
")",
":",
"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 '{}'.\"",
"raise",
"ValueError",
"(",
"msg",
".",
"format",
"(",
"config",
"[",
"\"gpg_key_fingerprint\"",
"]",
")",
")",
"signed_data",
"=",
"gpg",
".",
"sign_file",
"(",
"signfile",
",",
"keyid",
"=",
"keyid",
",",
"detach",
"=",
"True",
")",
"return",
"signed_data"
] | Returns detached signature for file | [
"Returns",
"detached",
"signature",
"for",
"file"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/gpg.py#L242-L259 | train | 231,667 |
manns/pyspread | pyspread/src/lib/gpg.py | verify | 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 = fingerprint2keyid(config["gpg_key_fingerprint"])
if verified.valid and verified.key_id == pyspread_keyid:
return True
return False | python | 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 = fingerprint2keyid(config["gpg_key_fingerprint"])
if verified.valid and verified.key_id == pyspread_keyid:
return True
return False | [
"def",
"verify",
"(",
"sigfilename",
",",
"filefilename",
"=",
"None",
")",
":",
"if",
"gnupg",
"is",
"None",
":",
"return",
"False",
"gpg",
"=",
"gnupg",
".",
"GPG",
"(",
")",
"with",
"open",
"(",
"sigfilename",
",",
"\"rb\"",
")",
"as",
"sigfile",
":",
"verified",
"=",
"gpg",
".",
"verify_file",
"(",
"sigfile",
",",
"filefilename",
")",
"pyspread_keyid",
"=",
"fingerprint2keyid",
"(",
"config",
"[",
"\"gpg_key_fingerprint\"",
"]",
")",
"if",
"verified",
".",
"valid",
"and",
"verified",
".",
"key_id",
"==",
"pyspread_keyid",
":",
"return",
"True",
"return",
"False"
] | Verifies a signature, returns True if successful else False. | [
"Verifies",
"a",
"signature",
"returns",
"True",
"if",
"successful",
"else",
"False",
"."
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/lib/gpg.py#L262-L278 | train | 231,668 |
manns/pyspread | pyspread/src/model/model.py | CellAttributes._len_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 | python | 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 | [
"def",
"_len_table_cache",
"(",
"self",
")",
":",
"length",
"=",
"0",
"for",
"table",
"in",
"self",
".",
"_table_cache",
":",
"length",
"+=",
"len",
"(",
"self",
".",
"_table_cache",
"[",
"table",
"]",
")",
"return",
"length"
] | Returns the length of the table cache | [
"Returns",
"the",
"length",
"of",
"the",
"table",
"cache"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L250-L258 | train | 231,669 |
manns/pyspread | pyspread/src/model/model.py | CellAttributes._update_table_cache | 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] = [(sel, val)]
assert len(self) == self._len_table_cache() | python | 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] = [(sel, val)]
assert len(self) == self._len_table_cache() | [
"def",
"_update_table_cache",
"(",
"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",
"]",
"=",
"[",
"(",
"sel",
",",
"val",
")",
"]",
"assert",
"len",
"(",
"self",
")",
"==",
"self",
".",
"_len_table_cache",
"(",
")"
] | Clears and updates the table cache to be in sync with self | [
"Clears",
"and",
"updates",
"the",
"table",
"cache",
"to",
"be",
"in",
"sync",
"with",
"self"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L260-L270 | train | 231,670 |
manns/pyspread | pyspread/src/model/model.py | CellAttributes.get_merging_cell | 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
merge_area = self[key]["merge_area"]
if merge_area:
return merge_area[0], merge_area[1], tab | python | 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
merge_area = self[key]["merge_area"]
if merge_area:
return merge_area[0], merge_area[1], tab | [
"def",
"get_merging_cell",
"(",
"self",
",",
"key",
")",
":",
"row",
",",
"col",
",",
"tab",
"=",
"key",
"# Is cell merged",
"merge_area",
"=",
"self",
"[",
"key",
"]",
"[",
"\"merge_area\"",
"]",
"if",
"merge_area",
":",
"return",
"merge_area",
"[",
"0",
"]",
",",
"merge_area",
"[",
"1",
"]",
",",
"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 | [
"Returns",
"key",
"of",
"cell",
"that",
"merges",
"the",
"cell",
"key"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L272-L290 | train | 231,671 |
manns/pyspread | pyspread/src/model/model.py | DataArray._get_data | 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
\t(row, tab): row_height
col_widths: Dict of 2-tuples to float
\t(col, tab): col_width
macros: String
\tMacros from macro list
"""
data = {}
data["shape"] = self.shape
data["grid"] = {}.update(self.dict_grid)
data["attributes"] = [ca for ca in self.cell_attributes]
data["row_heights"] = self.row_heights
data["col_widths"] = self.col_widths
data["macros"] = self.macros
return data | python | 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
\t(row, tab): row_height
col_widths: Dict of 2-tuples to float
\t(col, tab): col_width
macros: String
\tMacros from macro list
"""
data = {}
data["shape"] = self.shape
data["grid"] = {}.update(self.dict_grid)
data["attributes"] = [ca for ca in self.cell_attributes]
data["row_heights"] = self.row_heights
data["col_widths"] = self.col_widths
data["macros"] = self.macros
return data | [
"def",
"_get_data",
"(",
"self",
")",
":",
"data",
"=",
"{",
"}",
"data",
"[",
"\"shape\"",
"]",
"=",
"self",
".",
"shape",
"data",
"[",
"\"grid\"",
"]",
"=",
"{",
"}",
".",
"update",
"(",
"self",
".",
"dict_grid",
")",
"data",
"[",
"\"attributes\"",
"]",
"=",
"[",
"ca",
"for",
"ca",
"in",
"self",
".",
"cell_attributes",
"]",
"data",
"[",
"\"row_heights\"",
"]",
"=",
"self",
".",
"row_heights",
"data",
"[",
"\"col_widths\"",
"]",
"=",
"self",
".",
"col_widths",
"data",
"[",
"\"macros\"",
"]",
"=",
"self",
".",
"macros",
"return",
"data"
] | 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
col_widths: Dict of 2-tuples to float
\t(col, tab): col_width
macros: String
\tMacros from macro list | [
"Returns",
"dict",
"of",
"data",
"content",
"."
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L388-L418 | train | 231,672 |
manns/pyspread | pyspread/src/model/model.py | DataArray._set_data | 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 content
attributes: List of 3-tuples
\tCell attributes
row_heights: Dict of 2-tuples to float
\t(row, tab): row_height
col_widths: Dict of 2-tuples to float
\t(col, tab): col_width
macros: String
\tMacros from macro list
"""
if "shape" in kwargs:
self.shape = kwargs["shape"]
if "grid" in kwargs:
self.dict_grid.clear()
self.dict_grid.update(kwargs["grid"])
if "attributes" in kwargs:
self.attributes[:] = kwargs["attributes"]
if "row_heights" in kwargs:
self.row_heights = kwargs["row_heights"]
if "col_widths" in kwargs:
self.col_widths = kwargs["col_widths"]
if "macros" in kwargs:
self.macros = kwargs["macros"] | python | 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 content
attributes: List of 3-tuples
\tCell attributes
row_heights: Dict of 2-tuples to float
\t(row, tab): row_height
col_widths: Dict of 2-tuples to float
\t(col, tab): col_width
macros: String
\tMacros from macro list
"""
if "shape" in kwargs:
self.shape = kwargs["shape"]
if "grid" in kwargs:
self.dict_grid.clear()
self.dict_grid.update(kwargs["grid"])
if "attributes" in kwargs:
self.attributes[:] = kwargs["attributes"]
if "row_heights" in kwargs:
self.row_heights = kwargs["row_heights"]
if "col_widths" in kwargs:
self.col_widths = kwargs["col_widths"]
if "macros" in kwargs:
self.macros = kwargs["macros"] | [
"def",
"_set_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"\"shape\"",
"in",
"kwargs",
":",
"self",
".",
"shape",
"=",
"kwargs",
"[",
"\"shape\"",
"]",
"if",
"\"grid\"",
"in",
"kwargs",
":",
"self",
".",
"dict_grid",
".",
"clear",
"(",
")",
"self",
".",
"dict_grid",
".",
"update",
"(",
"kwargs",
"[",
"\"grid\"",
"]",
")",
"if",
"\"attributes\"",
"in",
"kwargs",
":",
"self",
".",
"attributes",
"[",
":",
"]",
"=",
"kwargs",
"[",
"\"attributes\"",
"]",
"if",
"\"row_heights\"",
"in",
"kwargs",
":",
"self",
".",
"row_heights",
"=",
"kwargs",
"[",
"\"row_heights\"",
"]",
"if",
"\"col_widths\"",
"in",
"kwargs",
":",
"self",
".",
"col_widths",
"=",
"kwargs",
"[",
"\"col_widths\"",
"]",
"if",
"\"macros\"",
"in",
"kwargs",
":",
"self",
".",
"macros",
"=",
"kwargs",
"[",
"\"macros\"",
"]"
] | 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
\tCell attributes
row_heights: Dict of 2-tuples to float
\t(row, tab): row_height
col_widths: Dict of 2-tuples to float
\t(col, tab): col_width
macros: String
\tMacros from macro list | [
"Sets",
"data",
"from",
"given",
"parameters"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L420-L461 | train | 231,673 |
manns/pyspread | pyspread/src/model/model.py | DataArray.get_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"] | python | def get_row_height(self, row, tab):
"""Returns row height"""
try:
return self.row_heights[(row, tab)]
except KeyError:
return config["default_row_height"] | [
"def",
"get_row_height",
"(",
"self",
",",
"row",
",",
"tab",
")",
":",
"try",
":",
"return",
"self",
".",
"row_heights",
"[",
"(",
"row",
",",
"tab",
")",
"]",
"except",
"KeyError",
":",
"return",
"config",
"[",
"\"default_row_height\"",
"]"
] | Returns row height | [
"Returns",
"row",
"height"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L465-L472 | train | 231,674 |
manns/pyspread | pyspread/src/model/model.py | DataArray.get_col_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"] | python | def get_col_width(self, col, tab):
"""Returns column width"""
try:
return self.col_widths[(col, tab)]
except KeyError:
return config["default_col_width"] | [
"def",
"get_col_width",
"(",
"self",
",",
"col",
",",
"tab",
")",
":",
"try",
":",
"return",
"self",
".",
"col_widths",
"[",
"(",
"col",
",",
"tab",
")",
"]",
"except",
"KeyError",
":",
"return",
"config",
"[",
"\"default_col_width\"",
"]"
] | Returns column width | [
"Returns",
"column",
"width"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L474-L481 | train | 231,675 |
manns/pyspread | pyspread/src/model/model.py | DataArray._set_shape | 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_cells = {}
if any(new_axis < old_axis
for new_axis, old_axis in zip(shape, old_shape)):
for key in self.dict_grid.keys():
if any(key_ele >= new_axis
for key_ele, new_axis in zip(key, shape)):
deleted_cells[key] = self.pop(key)
# Set dict_grid shape attribute
self.dict_grid.shape = shape
self._adjust_rowcol(0, 0, 0)
self._adjust_cell_attributes(0, 0, 0)
# Undo actions
yield "_set_shape"
self.shape = old_shape
for key in deleted_cells:
self[key] = deleted_cells[key] | python | 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_cells = {}
if any(new_axis < old_axis
for new_axis, old_axis in zip(shape, old_shape)):
for key in self.dict_grid.keys():
if any(key_ele >= new_axis
for key_ele, new_axis in zip(key, shape)):
deleted_cells[key] = self.pop(key)
# Set dict_grid shape attribute
self.dict_grid.shape = shape
self._adjust_rowcol(0, 0, 0)
self._adjust_cell_attributes(0, 0, 0)
# Undo actions
yield "_set_shape"
self.shape = old_shape
for key in deleted_cells:
self[key] = deleted_cells[key] | [
"def",
"_set_shape",
"(",
"self",
",",
"shape",
")",
":",
"# Delete each cell that is beyond new borders",
"old_shape",
"=",
"self",
".",
"shape",
"deleted_cells",
"=",
"{",
"}",
"if",
"any",
"(",
"new_axis",
"<",
"old_axis",
"for",
"new_axis",
",",
"old_axis",
"in",
"zip",
"(",
"shape",
",",
"old_shape",
")",
")",
":",
"for",
"key",
"in",
"self",
".",
"dict_grid",
".",
"keys",
"(",
")",
":",
"if",
"any",
"(",
"key_ele",
">=",
"new_axis",
"for",
"key_ele",
",",
"new_axis",
"in",
"zip",
"(",
"key",
",",
"shape",
")",
")",
":",
"deleted_cells",
"[",
"key",
"]",
"=",
"self",
".",
"pop",
"(",
"key",
")",
"# Set dict_grid shape attribute",
"self",
".",
"dict_grid",
".",
"shape",
"=",
"shape",
"self",
".",
"_adjust_rowcol",
"(",
"0",
",",
"0",
",",
"0",
")",
"self",
".",
"_adjust_cell_attributes",
"(",
"0",
",",
"0",
",",
"0",
")",
"# Undo actions",
"yield",
"\"_set_shape\"",
"self",
".",
"shape",
"=",
"old_shape",
"for",
"key",
"in",
"deleted_cells",
":",
"self",
"[",
"key",
"]",
"=",
"deleted_cells",
"[",
"key",
"]"
] | Deletes all cells beyond new shape and sets dict_grid shape
Parameters
----------
shape: 3-tuple of Integer
\tTarget shape for grid | [
"Deletes",
"all",
"cells",
"beyond",
"new",
"shape",
"and",
"sets",
"dict_grid",
"shape"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L568-L603 | train | 231,676 |
manns/pyspread | pyspread/src/model/model.py | DataArray.get_last_filled_cell | 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.dict_grid:
if table is None or tab == table:
maxrow = max(row, maxrow)
maxcol = max(col, maxcol)
return maxrow, maxcol, table | python | 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.dict_grid:
if table is None or tab == table:
maxrow = max(row, maxrow)
maxcol = max(col, maxcol)
return maxrow, maxcol, table | [
"def",
"get_last_filled_cell",
"(",
"self",
",",
"table",
"=",
"None",
")",
":",
"maxrow",
"=",
"0",
"maxcol",
"=",
"0",
"for",
"row",
",",
"col",
",",
"tab",
"in",
"self",
".",
"dict_grid",
":",
"if",
"table",
"is",
"None",
"or",
"tab",
"==",
"table",
":",
"maxrow",
"=",
"max",
"(",
"row",
",",
"maxrow",
")",
"maxcol",
"=",
"max",
"(",
"col",
",",
"maxcol",
")",
"return",
"maxrow",
",",
"maxcol",
",",
"table"
] | Returns key for the bottommost rightmost cell with content
Parameters
----------
table: Integer, defaults to None
\tLimit search to this table | [
"Returns",
"key",
"for",
"the",
"bottommost",
"rightmost",
"cell",
"with",
"content"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L607-L625 | train | 231,677 |
manns/pyspread | pyspread/src/model/model.py | DataArray.cell_array_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 of key that is a slice
if type(key_ele) is SliceType:
slc_keys = xrange(*key_ele.indices(self.dict_grid.shape[i]))
key_list = list(key)
key_list[i] = None
has_subslice = any(type(ele) is SliceType for ele in key_list)
for slc_key in slc_keys:
key_list[i] = slc_key
if has_subslice:
# If there is a slice left yield generator
yield self.cell_array_generator(key_list)
else:
# No slices? Yield value
yield self[tuple(key_list)]
break | python | 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 of key that is a slice
if type(key_ele) is SliceType:
slc_keys = xrange(*key_ele.indices(self.dict_grid.shape[i]))
key_list = list(key)
key_list[i] = None
has_subslice = any(type(ele) is SliceType for ele in key_list)
for slc_key in slc_keys:
key_list[i] = slc_key
if has_subslice:
# If there is a slice left yield generator
yield self.cell_array_generator(key_list)
else:
# No slices? Yield value
yield self[tuple(key_list)]
break | [
"def",
"cell_array_generator",
"(",
"self",
",",
"key",
")",
":",
"for",
"i",
",",
"key_ele",
"in",
"enumerate",
"(",
"key",
")",
":",
"# Get first element of key that is a slice",
"if",
"type",
"(",
"key_ele",
")",
"is",
"SliceType",
":",
"slc_keys",
"=",
"xrange",
"(",
"*",
"key_ele",
".",
"indices",
"(",
"self",
".",
"dict_grid",
".",
"shape",
"[",
"i",
"]",
")",
")",
"key_list",
"=",
"list",
"(",
"key",
")",
"key_list",
"[",
"i",
"]",
"=",
"None",
"has_subslice",
"=",
"any",
"(",
"type",
"(",
"ele",
")",
"is",
"SliceType",
"for",
"ele",
"in",
"key_list",
")",
"for",
"slc_key",
"in",
"slc_keys",
":",
"key_list",
"[",
"i",
"]",
"=",
"slc_key",
"if",
"has_subslice",
":",
"# If there is a slice left yield generator",
"yield",
"self",
".",
"cell_array_generator",
"(",
"key_list",
")",
"else",
":",
"# No slices? Yield value",
"yield",
"self",
"[",
"tuple",
"(",
"key_list",
")",
"]",
"break"
] | Generator traversing cells specified in key
Parameters
----------
key: Iterable of Integer or slice
\tThe key specifies the cell keys of the generator | [
"Generator",
"traversing",
"cells",
"specified",
"in",
"key"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L720-L752 | train | 231,678 |
manns/pyspread | pyspread/src/model/model.py | DataArray._shift_rowcol | 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:
new_row_heights[(row, tab + no_to_insert)] = \
self.row_heights[(row, tab)]
del_row_heights.append((row, tab))
for row, tab in new_row_heights:
self.set_row_height(row, tab, new_row_heights[(row, tab)])
for row, tab in del_row_heights:
if (row, tab) not in new_row_heights:
self.set_row_height(row, tab, None)
# Shift column widths
new_col_widths = {}
del_col_widths = []
for col, tab in self.col_widths:
if tab > insertion_point:
new_col_widths[(col, tab + no_to_insert)] = \
self.col_widths[(col, tab)]
del_col_widths.append((col, tab))
for col, tab in new_col_widths:
self.set_col_width(col, tab, new_col_widths[(col, tab)])
for col, tab in del_col_widths:
if (col, tab) not in new_col_widths:
self.set_col_width(col, tab, None) | python | 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:
new_row_heights[(row, tab + no_to_insert)] = \
self.row_heights[(row, tab)]
del_row_heights.append((row, tab))
for row, tab in new_row_heights:
self.set_row_height(row, tab, new_row_heights[(row, tab)])
for row, tab in del_row_heights:
if (row, tab) not in new_row_heights:
self.set_row_height(row, tab, None)
# Shift column widths
new_col_widths = {}
del_col_widths = []
for col, tab in self.col_widths:
if tab > insertion_point:
new_col_widths[(col, tab + no_to_insert)] = \
self.col_widths[(col, tab)]
del_col_widths.append((col, tab))
for col, tab in new_col_widths:
self.set_col_width(col, tab, new_col_widths[(col, tab)])
for col, tab in del_col_widths:
if (col, tab) not in new_col_widths:
self.set_col_width(col, tab, None) | [
"def",
"_shift_rowcol",
"(",
"self",
",",
"insertion_point",
",",
"no_to_insert",
")",
":",
"# Shift row heights",
"new_row_heights",
"=",
"{",
"}",
"del_row_heights",
"=",
"[",
"]",
"for",
"row",
",",
"tab",
"in",
"self",
".",
"row_heights",
":",
"if",
"tab",
">",
"insertion_point",
":",
"new_row_heights",
"[",
"(",
"row",
",",
"tab",
"+",
"no_to_insert",
")",
"]",
"=",
"self",
".",
"row_heights",
"[",
"(",
"row",
",",
"tab",
")",
"]",
"del_row_heights",
".",
"append",
"(",
"(",
"row",
",",
"tab",
")",
")",
"for",
"row",
",",
"tab",
"in",
"new_row_heights",
":",
"self",
".",
"set_row_height",
"(",
"row",
",",
"tab",
",",
"new_row_heights",
"[",
"(",
"row",
",",
"tab",
")",
"]",
")",
"for",
"row",
",",
"tab",
"in",
"del_row_heights",
":",
"if",
"(",
"row",
",",
"tab",
")",
"not",
"in",
"new_row_heights",
":",
"self",
".",
"set_row_height",
"(",
"row",
",",
"tab",
",",
"None",
")",
"# Shift column widths",
"new_col_widths",
"=",
"{",
"}",
"del_col_widths",
"=",
"[",
"]",
"for",
"col",
",",
"tab",
"in",
"self",
".",
"col_widths",
":",
"if",
"tab",
">",
"insertion_point",
":",
"new_col_widths",
"[",
"(",
"col",
",",
"tab",
"+",
"no_to_insert",
")",
"]",
"=",
"self",
".",
"col_widths",
"[",
"(",
"col",
",",
"tab",
")",
"]",
"del_col_widths",
".",
"append",
"(",
"(",
"col",
",",
"tab",
")",
")",
"for",
"col",
",",
"tab",
"in",
"new_col_widths",
":",
"self",
".",
"set_col_width",
"(",
"col",
",",
"tab",
",",
"new_col_widths",
"[",
"(",
"col",
",",
"tab",
")",
"]",
")",
"for",
"col",
",",
"tab",
"in",
"del_col_widths",
":",
"if",
"(",
"col",
",",
"tab",
")",
"not",
"in",
"new_col_widths",
":",
"self",
".",
"set_col_width",
"(",
"col",
",",
"tab",
",",
"None",
")"
] | Shifts row and column sizes when a table is inserted or deleted | [
"Shifts",
"row",
"and",
"column",
"sizes",
"when",
"a",
"table",
"is",
"inserted",
"or",
"deleted"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L754-L791 | train | 231,679 |
manns/pyspread | pyspread/src/model/model.py | DataArray._get_adjusted_merge_area | 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 axis, before which insertion takes place
no_to_insert: Integer >= 0
\tNumber of rows/cols/tabs that shall be inserted
axis: Integer in range(2)
\tSpecifies number of dimension, i.e. 0 == row, 1 == col
"""
assert axis in range(2)
if "merge_area" not in attrs or attrs["merge_area"] is None:
return
top, left, bottom, right = attrs["merge_area"]
selection = Selection([(top, left)], [(bottom, right)], [], [], [])
selection.insert(insertion_point, no_to_insert, axis)
__top, __left = selection.block_tl[0]
__bottom, __right = selection.block_br[0]
# Adjust merge area if it is beyond the grid shape
rows, cols, tabs = self.shape
if __top < 0 and __bottom < 0 or __top >= rows and __bottom >= rows or\
__left < 0 and __right < 0 or __left >= cols and __right >= cols:
return
if __top < 0:
__top = 0
if __top >= rows:
__top = rows - 1
if __bottom < 0:
__bottom = 0
if __bottom >= rows:
__bottom = rows - 1
if __left < 0:
__left = 0
if __left >= cols:
__left = cols - 1
if __right < 0:
__right = 0
if __right >= cols:
__right = cols - 1
return __top, __left, __bottom, __right | python | 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 axis, before which insertion takes place
no_to_insert: Integer >= 0
\tNumber of rows/cols/tabs that shall be inserted
axis: Integer in range(2)
\tSpecifies number of dimension, i.e. 0 == row, 1 == col
"""
assert axis in range(2)
if "merge_area" not in attrs or attrs["merge_area"] is None:
return
top, left, bottom, right = attrs["merge_area"]
selection = Selection([(top, left)], [(bottom, right)], [], [], [])
selection.insert(insertion_point, no_to_insert, axis)
__top, __left = selection.block_tl[0]
__bottom, __right = selection.block_br[0]
# Adjust merge area if it is beyond the grid shape
rows, cols, tabs = self.shape
if __top < 0 and __bottom < 0 or __top >= rows and __bottom >= rows or\
__left < 0 and __right < 0 or __left >= cols and __right >= cols:
return
if __top < 0:
__top = 0
if __top >= rows:
__top = rows - 1
if __bottom < 0:
__bottom = 0
if __bottom >= rows:
__bottom = rows - 1
if __left < 0:
__left = 0
if __left >= cols:
__left = cols - 1
if __right < 0:
__right = 0
if __right >= cols:
__right = cols - 1
return __top, __left, __bottom, __right | [
"def",
"_get_adjusted_merge_area",
"(",
"self",
",",
"attrs",
",",
"insertion_point",
",",
"no_to_insert",
",",
"axis",
")",
":",
"assert",
"axis",
"in",
"range",
"(",
"2",
")",
"if",
"\"merge_area\"",
"not",
"in",
"attrs",
"or",
"attrs",
"[",
"\"merge_area\"",
"]",
"is",
"None",
":",
"return",
"top",
",",
"left",
",",
"bottom",
",",
"right",
"=",
"attrs",
"[",
"\"merge_area\"",
"]",
"selection",
"=",
"Selection",
"(",
"[",
"(",
"top",
",",
"left",
")",
"]",
",",
"[",
"(",
"bottom",
",",
"right",
")",
"]",
",",
"[",
"]",
",",
"[",
"]",
",",
"[",
"]",
")",
"selection",
".",
"insert",
"(",
"insertion_point",
",",
"no_to_insert",
",",
"axis",
")",
"__top",
",",
"__left",
"=",
"selection",
".",
"block_tl",
"[",
"0",
"]",
"__bottom",
",",
"__right",
"=",
"selection",
".",
"block_br",
"[",
"0",
"]",
"# Adjust merge area if it is beyond the grid shape",
"rows",
",",
"cols",
",",
"tabs",
"=",
"self",
".",
"shape",
"if",
"__top",
"<",
"0",
"and",
"__bottom",
"<",
"0",
"or",
"__top",
">=",
"rows",
"and",
"__bottom",
">=",
"rows",
"or",
"__left",
"<",
"0",
"and",
"__right",
"<",
"0",
"or",
"__left",
">=",
"cols",
"and",
"__right",
">=",
"cols",
":",
"return",
"if",
"__top",
"<",
"0",
":",
"__top",
"=",
"0",
"if",
"__top",
">=",
"rows",
":",
"__top",
"=",
"rows",
"-",
"1",
"if",
"__bottom",
"<",
"0",
":",
"__bottom",
"=",
"0",
"if",
"__bottom",
">=",
"rows",
":",
"__bottom",
"=",
"rows",
"-",
"1",
"if",
"__left",
"<",
"0",
":",
"__left",
"=",
"0",
"if",
"__left",
">=",
"cols",
":",
"__left",
"=",
"cols",
"-",
"1",
"if",
"__right",
"<",
"0",
":",
"__right",
"=",
"0",
"if",
"__right",
">=",
"cols",
":",
"__right",
"=",
"cols",
"-",
"1",
"return",
"__top",
",",
"__left",
",",
"__bottom",
",",
"__right"
] | 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 inserted
axis: Integer in range(2)
\tSpecifies number of dimension, i.e. 0 == row, 1 == col | [
"Returns",
"updated",
"merge",
"area"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L822-L883 | train | 231,680 |
manns/pyspread | pyspread/src/model/model.py | DataArray.set_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) | python | 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) | [
"def",
"set_row_height",
"(",
"self",
",",
"row",
",",
"tab",
",",
"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 row height | [
"Sets",
"row",
"height"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1078-L1088 | train | 231,681 |
manns/pyspread | pyspread/src/model/model.py | DataArray.set_col_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) | python | 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) | [
"def",
"set_col_width",
"(",
"self",
",",
"col",
",",
"tab",
",",
"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",
")"
] | Sets column width | [
"Sets",
"column",
"width"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1090-L1100 | train | 231,682 |
manns/pyspread | pyspread/src/model/model.py | CodeArray._make_nested_list | 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
res.append(self._make_nested_list(ele))
else:
res.append(ele)
return res | python | 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
res.append(self._make_nested_list(ele))
else:
res.append(ele)
return res | [
"def",
"_make_nested_list",
"(",
"self",
",",
"gen",
")",
":",
"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",
"res",
".",
"append",
"(",
"self",
".",
"_make_nested_list",
"(",
"ele",
")",
")",
"else",
":",
"res",
".",
"append",
"(",
"ele",
")",
"return",
"res"
] | Makes nested list from generator for creating numpy.array | [
"Makes",
"nested",
"list",
"from",
"generator",
"for",
"creating",
"numpy",
".",
"array"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1174-L1190 | train | 231,683 |
manns/pyspread | pyspread/src/model/model.py | CodeArray._get_assignment_target_end | 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) > 1:
raise ValueError("More than one expression or assignment.")
elif len(ast_module.body) > 0 and \
type(ast_module.body[0]) is ast.Assign:
if len(ast_module.body[0].targets) != 1:
raise ValueError("More than one assignment target.")
else:
return len(ast_module.body[0].targets[0].id)
return -1 | python | 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) > 1:
raise ValueError("More than one expression or assignment.")
elif len(ast_module.body) > 0 and \
type(ast_module.body[0]) is ast.Assign:
if len(ast_module.body[0].targets) != 1:
raise ValueError("More than one assignment target.")
else:
return len(ast_module.body[0].targets[0].id)
return -1 | [
"def",
"_get_assignment_target_end",
"(",
"self",
",",
"ast_module",
")",
":",
"if",
"len",
"(",
"ast_module",
".",
"body",
")",
">",
"1",
":",
"raise",
"ValueError",
"(",
"\"More than one expression or assignment.\"",
")",
"elif",
"len",
"(",
"ast_module",
".",
"body",
")",
">",
"0",
"and",
"type",
"(",
"ast_module",
".",
"body",
"[",
"0",
"]",
")",
"is",
"ast",
".",
"Assign",
":",
"if",
"len",
"(",
"ast_module",
".",
"body",
"[",
"0",
"]",
".",
"targets",
")",
"!=",
"1",
":",
"raise",
"ValueError",
"(",
"\"More than one assignment target.\"",
")",
"else",
":",
"return",
"len",
"(",
"ast_module",
".",
"body",
"[",
"0",
"]",
".",
"targets",
"[",
"0",
"]",
".",
"id",
")",
"return",
"-",
"1"
] | 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. | [
"Returns",
"position",
"of",
"1st",
"char",
"after",
"assignment",
"traget",
"."
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1192-L1212 | train | 231,684 |
manns/pyspread | pyspread/src/model/model.py | CodeArray._get_updated_environment | 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 = {'S': self}
env = globals().copy()
env.update(env_dict)
return env | python | 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 = {'S': self}
env = globals().copy()
env.update(env_dict)
return env | [
"def",
"_get_updated_environment",
"(",
"self",
",",
"env_dict",
"=",
"None",
")",
":",
"if",
"env_dict",
"is",
"None",
":",
"env_dict",
"=",
"{",
"'S'",
":",
"self",
"}",
"env",
"=",
"globals",
"(",
")",
".",
"copy",
"(",
")",
"env",
".",
"update",
"(",
"env_dict",
")",
"return",
"env"
] | Returns globals environment with 'magic' variable
Parameters
----------
env_dict: Dict, defaults to {'S': self}
\tDict that maps global variable name to value | [
"Returns",
"globals",
"environment",
"with",
"magic",
"variable"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1214-L1230 | train | 231,685 |
manns/pyspread | pyspread/src/model/model.py | CodeArray._eval_cell | 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:
# Probably no numpy array
return numpy.array(filter(None, val))
# Set up environment for evaluation
env_dict = {'X': key[0], 'Y': key[1], 'Z': key[2], 'bz2': bz2,
'base64': base64, 'charts': charts, 'nn': nn,
'R': key[0], 'C': key[1], 'T': key[2], 'S': self,
'vlcpanel_factory': vlcpanel_factory}
env = self._get_updated_environment(env_dict=env_dict)
#_old_code = self(key)
# Return cell value if in safe mode
if self.safe_mode:
return code
# If cell is not present return None
if code is None:
return
elif is_generator_like(code):
# We have a generator object
return numpy.array(self._make_nested_list(code), dtype="O")
# If only 1 term in front of the "=" --> global
try:
assignment_target_error = None
module = ast.parse(code)
assignment_target_end = self._get_assignment_target_end(module)
except ValueError, err:
assignment_target_error = ValueError(err)
except AttributeError, err:
# Attribute Error includes RunTimeError
assignment_target_error = AttributeError(err)
except Exception, err:
assignment_target_error = Exception(err)
if assignment_target_error is None and assignment_target_end != -1:
glob_var = code[:assignment_target_end]
expression = code.split("=", 1)[1]
expression = expression.strip()
# Delete result cache because assignment changes results
self.result_cache.clear()
else:
glob_var = None
expression = code
if assignment_target_error is not None:
result = assignment_target_error
else:
try:
import signal
signal.signal(signal.SIGALRM, self.handler)
signal.alarm(config["timeout"])
except:
# No POSIX system
pass
try:
result = eval(expression, env, {})
except AttributeError, err:
# Attribute Error includes RunTimeError
result = AttributeError(err)
except RuntimeError, err:
result = RuntimeError(err)
except Exception, err:
result = Exception(err)
finally:
try:
signal.alarm(0)
except:
# No POSIX system
pass
# Change back cell value for evaluation from other cells
#self.dict_grid[key] = _old_code
if glob_var is not None:
globals().update({glob_var: result})
return result | python | 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:
# Probably no numpy array
return numpy.array(filter(None, val))
# Set up environment for evaluation
env_dict = {'X': key[0], 'Y': key[1], 'Z': key[2], 'bz2': bz2,
'base64': base64, 'charts': charts, 'nn': nn,
'R': key[0], 'C': key[1], 'T': key[2], 'S': self,
'vlcpanel_factory': vlcpanel_factory}
env = self._get_updated_environment(env_dict=env_dict)
#_old_code = self(key)
# Return cell value if in safe mode
if self.safe_mode:
return code
# If cell is not present return None
if code is None:
return
elif is_generator_like(code):
# We have a generator object
return numpy.array(self._make_nested_list(code), dtype="O")
# If only 1 term in front of the "=" --> global
try:
assignment_target_error = None
module = ast.parse(code)
assignment_target_end = self._get_assignment_target_end(module)
except ValueError, err:
assignment_target_error = ValueError(err)
except AttributeError, err:
# Attribute Error includes RunTimeError
assignment_target_error = AttributeError(err)
except Exception, err:
assignment_target_error = Exception(err)
if assignment_target_error is None and assignment_target_end != -1:
glob_var = code[:assignment_target_end]
expression = code.split("=", 1)[1]
expression = expression.strip()
# Delete result cache because assignment changes results
self.result_cache.clear()
else:
glob_var = None
expression = code
if assignment_target_error is not None:
result = assignment_target_error
else:
try:
import signal
signal.signal(signal.SIGALRM, self.handler)
signal.alarm(config["timeout"])
except:
# No POSIX system
pass
try:
result = eval(expression, env, {})
except AttributeError, err:
# Attribute Error includes RunTimeError
result = AttributeError(err)
except RuntimeError, err:
result = RuntimeError(err)
except Exception, err:
result = Exception(err)
finally:
try:
signal.alarm(0)
except:
# No POSIX system
pass
# Change back cell value for evaluation from other cells
#self.dict_grid[key] = _old_code
if glob_var is not None:
globals().update({glob_var: result})
return result | [
"def",
"_eval_cell",
"(",
"self",
",",
"key",
",",
"code",
")",
":",
"# Flatten helper function",
"def",
"nn",
"(",
"val",
")",
":",
"\"\"\"Returns flat numpy arraz without None values\"\"\"",
"try",
":",
"return",
"numpy",
".",
"array",
"(",
"filter",
"(",
"None",
",",
"val",
".",
"flat",
")",
")",
"except",
"AttributeError",
":",
"# Probably no numpy array",
"return",
"numpy",
".",
"array",
"(",
"filter",
"(",
"None",
",",
"val",
")",
")",
"# Set up environment for evaluation",
"env_dict",
"=",
"{",
"'X'",
":",
"key",
"[",
"0",
"]",
",",
"'Y'",
":",
"key",
"[",
"1",
"]",
",",
"'Z'",
":",
"key",
"[",
"2",
"]",
",",
"'bz2'",
":",
"bz2",
",",
"'base64'",
":",
"base64",
",",
"'charts'",
":",
"charts",
",",
"'nn'",
":",
"nn",
",",
"'R'",
":",
"key",
"[",
"0",
"]",
",",
"'C'",
":",
"key",
"[",
"1",
"]",
",",
"'T'",
":",
"key",
"[",
"2",
"]",
",",
"'S'",
":",
"self",
",",
"'vlcpanel_factory'",
":",
"vlcpanel_factory",
"}",
"env",
"=",
"self",
".",
"_get_updated_environment",
"(",
"env_dict",
"=",
"env_dict",
")",
"#_old_code = self(key)",
"# Return cell value if in safe mode",
"if",
"self",
".",
"safe_mode",
":",
"return",
"code",
"# If cell is not present return None",
"if",
"code",
"is",
"None",
":",
"return",
"elif",
"is_generator_like",
"(",
"code",
")",
":",
"# We have a generator object",
"return",
"numpy",
".",
"array",
"(",
"self",
".",
"_make_nested_list",
"(",
"code",
")",
",",
"dtype",
"=",
"\"O\"",
")",
"# If only 1 term in front of the \"=\" --> global",
"try",
":",
"assignment_target_error",
"=",
"None",
"module",
"=",
"ast",
".",
"parse",
"(",
"code",
")",
"assignment_target_end",
"=",
"self",
".",
"_get_assignment_target_end",
"(",
"module",
")",
"except",
"ValueError",
",",
"err",
":",
"assignment_target_error",
"=",
"ValueError",
"(",
"err",
")",
"except",
"AttributeError",
",",
"err",
":",
"# Attribute Error includes RunTimeError",
"assignment_target_error",
"=",
"AttributeError",
"(",
"err",
")",
"except",
"Exception",
",",
"err",
":",
"assignment_target_error",
"=",
"Exception",
"(",
"err",
")",
"if",
"assignment_target_error",
"is",
"None",
"and",
"assignment_target_end",
"!=",
"-",
"1",
":",
"glob_var",
"=",
"code",
"[",
":",
"assignment_target_end",
"]",
"expression",
"=",
"code",
".",
"split",
"(",
"\"=\"",
",",
"1",
")",
"[",
"1",
"]",
"expression",
"=",
"expression",
".",
"strip",
"(",
")",
"# Delete result cache because assignment changes results",
"self",
".",
"result_cache",
".",
"clear",
"(",
")",
"else",
":",
"glob_var",
"=",
"None",
"expression",
"=",
"code",
"if",
"assignment_target_error",
"is",
"not",
"None",
":",
"result",
"=",
"assignment_target_error",
"else",
":",
"try",
":",
"import",
"signal",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGALRM",
",",
"self",
".",
"handler",
")",
"signal",
".",
"alarm",
"(",
"config",
"[",
"\"timeout\"",
"]",
")",
"except",
":",
"# No POSIX system",
"pass",
"try",
":",
"result",
"=",
"eval",
"(",
"expression",
",",
"env",
",",
"{",
"}",
")",
"except",
"AttributeError",
",",
"err",
":",
"# Attribute Error includes RunTimeError",
"result",
"=",
"AttributeError",
"(",
"err",
")",
"except",
"RuntimeError",
",",
"err",
":",
"result",
"=",
"RuntimeError",
"(",
"err",
")",
"except",
"Exception",
",",
"err",
":",
"result",
"=",
"Exception",
"(",
"err",
")",
"finally",
":",
"try",
":",
"signal",
".",
"alarm",
"(",
"0",
")",
"except",
":",
"# No POSIX system",
"pass",
"# Change back cell value for evaluation from other cells",
"#self.dict_grid[key] = _old_code",
"if",
"glob_var",
"is",
"not",
"None",
":",
"globals",
"(",
")",
".",
"update",
"(",
"{",
"glob_var",
":",
"result",
"}",
")",
"return",
"result"
] | Evaluates one cell and returns its result | [
"Evaluates",
"one",
"cell",
"and",
"returns",
"its",
"result"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1232-L1340 | train | 231,686 |
manns/pyspread | pyspread/src/model/model.py | CodeArray.pop | 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 DataArray.pop(self, key) | python | 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 DataArray.pop(self, key) | [
"def",
"pop",
"(",
"self",
",",
"key",
")",
":",
"try",
":",
"self",
".",
"result_cache",
".",
"pop",
"(",
"repr",
"(",
"key",
")",
")",
"except",
"KeyError",
":",
"pass",
"return",
"DataArray",
".",
"pop",
"(",
"self",
",",
"key",
")"
] | Pops dict_grid with undo and redo support
Parameters
----------
key: 3-tuple of Integer
\tCell key that shall be popped | [
"Pops",
"dict_grid",
"with",
"undo",
"and",
"redo",
"support"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1342-L1358 | train | 231,687 |
manns/pyspread | pyspread/src/model/model.py | CodeArray.reload_modules | 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) | python | 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) | [
"def",
"reload_modules",
"(",
"self",
")",
":",
"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",
")"
] | Reloads modules that are available in cells | [
"Reloads",
"modules",
"that",
"are",
"available",
"in",
"cells"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1360-L1368 | train | 231,688 |
manns/pyspread | pyspread/src/model/model.py | CodeArray.clear_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',
'CellAttributes', 'product', 'ast', '__builtins__',
'__file__', 'charts', 'sys', 'is_slice_like', '__name__',
'copy', 'imap', 'wx', 'ifilter', 'Selection', 'DictGrid',
'numpy', 'CodeArray', 'DataArray', 'datetime',
'vlcpanel_factory']
for key in globals().keys():
if key not in base_keys:
globals().pop(key) | python | 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',
'CellAttributes', 'product', 'ast', '__builtins__',
'__file__', 'charts', 'sys', 'is_slice_like', '__name__',
'copy', 'imap', 'wx', 'ifilter', 'Selection', 'DictGrid',
'numpy', 'CodeArray', 'DataArray', 'datetime',
'vlcpanel_factory']
for key in globals().keys():
if key not in base_keys:
globals().pop(key) | [
"def",
"clear_globals",
"(",
"self",
")",
":",
"base_keys",
"=",
"[",
"'cStringIO'",
",",
"'IntType'",
",",
"'KeyValueStore'",
",",
"'undoable'",
",",
"'is_generator_like'",
",",
"'is_string_like'",
",",
"'bz2'",
",",
"'base64'",
",",
"'__package__'",
",",
"'re'",
",",
"'config'",
",",
"'__doc__'",
",",
"'SliceType'",
",",
"'CellAttributes'",
",",
"'product'",
",",
"'ast'",
",",
"'__builtins__'",
",",
"'__file__'",
",",
"'charts'",
",",
"'sys'",
",",
"'is_slice_like'",
",",
"'__name__'",
",",
"'copy'",
",",
"'imap'",
",",
"'wx'",
",",
"'ifilter'",
",",
"'Selection'",
",",
"'DictGrid'",
",",
"'numpy'",
",",
"'CodeArray'",
",",
"'DataArray'",
",",
"'datetime'",
",",
"'vlcpanel_factory'",
"]",
"for",
"key",
"in",
"globals",
"(",
")",
".",
"keys",
"(",
")",
":",
"if",
"key",
"not",
"in",
"base_keys",
":",
"globals",
"(",
")",
".",
"pop",
"(",
"key",
")"
] | Clears all newly assigned globals | [
"Clears",
"all",
"newly",
"assigned",
"globals"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1370-L1384 | train | 231,689 |
manns/pyspread | pyspread/src/model/model.py | CodeArray.execute_macros | def execute_macros(self):
"""Executes all macros and returns result string
Executes macros only when not in safe_mode
"""
if self.safe_mode:
return '', "Safe mode activated. Code not executed."
# Windows exec does not like Windows newline
self.macros = self.macros.replace('\r\n', '\n')
# Set up environment for evaluation
globals().update(self._get_updated_environment())
# Create file-like string to capture output
code_out = cStringIO.StringIO()
code_err = cStringIO.StringIO()
err_msg = cStringIO.StringIO()
# Capture output and errors
sys.stdout = code_out
sys.stderr = code_err
try:
import signal
signal.signal(signal.SIGALRM, self.handler)
signal.alarm(config["timeout"])
except:
# No POSIX system
pass
try:
exec(self.macros, globals())
try:
signal.alarm(0)
except:
# No POSIX system
pass
except Exception:
# Print exception
# (Because of how the globals are handled during execution
# we must import modules here)
from traceback import print_exception
from src.lib.exception_handling import get_user_codeframe
exc_info = sys.exc_info()
user_tb = get_user_codeframe(exc_info[2]) or exc_info[2]
print_exception(exc_info[0], exc_info[1], user_tb, None, err_msg)
# Restore stdout and stderr
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
results = code_out.getvalue()
errs = code_err.getvalue() + err_msg.getvalue()
code_out.close()
code_err.close()
# Reset result cache
self.result_cache.clear()
# Reset frozen cache
self.frozen_cache.clear()
return results, errs | python | def execute_macros(self):
"""Executes all macros and returns result string
Executes macros only when not in safe_mode
"""
if self.safe_mode:
return '', "Safe mode activated. Code not executed."
# Windows exec does not like Windows newline
self.macros = self.macros.replace('\r\n', '\n')
# Set up environment for evaluation
globals().update(self._get_updated_environment())
# Create file-like string to capture output
code_out = cStringIO.StringIO()
code_err = cStringIO.StringIO()
err_msg = cStringIO.StringIO()
# Capture output and errors
sys.stdout = code_out
sys.stderr = code_err
try:
import signal
signal.signal(signal.SIGALRM, self.handler)
signal.alarm(config["timeout"])
except:
# No POSIX system
pass
try:
exec(self.macros, globals())
try:
signal.alarm(0)
except:
# No POSIX system
pass
except Exception:
# Print exception
# (Because of how the globals are handled during execution
# we must import modules here)
from traceback import print_exception
from src.lib.exception_handling import get_user_codeframe
exc_info = sys.exc_info()
user_tb = get_user_codeframe(exc_info[2]) or exc_info[2]
print_exception(exc_info[0], exc_info[1], user_tb, None, err_msg)
# Restore stdout and stderr
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
results = code_out.getvalue()
errs = code_err.getvalue() + err_msg.getvalue()
code_out.close()
code_err.close()
# Reset result cache
self.result_cache.clear()
# Reset frozen cache
self.frozen_cache.clear()
return results, errs | [
"def",
"execute_macros",
"(",
"self",
")",
":",
"if",
"self",
".",
"safe_mode",
":",
"return",
"''",
",",
"\"Safe mode activated. Code not executed.\"",
"# Windows exec does not like Windows newline",
"self",
".",
"macros",
"=",
"self",
".",
"macros",
".",
"replace",
"(",
"'\\r\\n'",
",",
"'\\n'",
")",
"# Set up environment for evaluation",
"globals",
"(",
")",
".",
"update",
"(",
"self",
".",
"_get_updated_environment",
"(",
")",
")",
"# Create file-like string to capture output",
"code_out",
"=",
"cStringIO",
".",
"StringIO",
"(",
")",
"code_err",
"=",
"cStringIO",
".",
"StringIO",
"(",
")",
"err_msg",
"=",
"cStringIO",
".",
"StringIO",
"(",
")",
"# Capture output and errors",
"sys",
".",
"stdout",
"=",
"code_out",
"sys",
".",
"stderr",
"=",
"code_err",
"try",
":",
"import",
"signal",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGALRM",
",",
"self",
".",
"handler",
")",
"signal",
".",
"alarm",
"(",
"config",
"[",
"\"timeout\"",
"]",
")",
"except",
":",
"# No POSIX system",
"pass",
"try",
":",
"exec",
"(",
"self",
".",
"macros",
",",
"globals",
"(",
")",
")",
"try",
":",
"signal",
".",
"alarm",
"(",
"0",
")",
"except",
":",
"# No POSIX system",
"pass",
"except",
"Exception",
":",
"# Print exception",
"# (Because of how the globals are handled during execution",
"# we must import modules here)",
"from",
"traceback",
"import",
"print_exception",
"from",
"src",
".",
"lib",
".",
"exception_handling",
"import",
"get_user_codeframe",
"exc_info",
"=",
"sys",
".",
"exc_info",
"(",
")",
"user_tb",
"=",
"get_user_codeframe",
"(",
"exc_info",
"[",
"2",
"]",
")",
"or",
"exc_info",
"[",
"2",
"]",
"print_exception",
"(",
"exc_info",
"[",
"0",
"]",
",",
"exc_info",
"[",
"1",
"]",
",",
"user_tb",
",",
"None",
",",
"err_msg",
")",
"# Restore stdout and stderr",
"sys",
".",
"stdout",
"=",
"sys",
".",
"__stdout__",
"sys",
".",
"stderr",
"=",
"sys",
".",
"__stderr__",
"results",
"=",
"code_out",
".",
"getvalue",
"(",
")",
"errs",
"=",
"code_err",
".",
"getvalue",
"(",
")",
"+",
"err_msg",
".",
"getvalue",
"(",
")",
"code_out",
".",
"close",
"(",
")",
"code_err",
".",
"close",
"(",
")",
"# Reset result cache",
"self",
".",
"result_cache",
".",
"clear",
"(",
")",
"# Reset frozen cache",
"self",
".",
"frozen_cache",
".",
"clear",
"(",
")",
"return",
"results",
",",
"errs"
] | Executes all macros and returns result string
Executes macros only when not in safe_mode | [
"Executes",
"all",
"macros",
"and",
"returns",
"result",
"string"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1391-L1459 | train | 231,690 |
manns/pyspread | pyspread/src/model/model.py | CodeArray._sorted_keys | def _sorted_keys(self, keys, startkey, reverse=False):
"""Generator that yields sorted keys starting with startkey
Parameters
----------
keys: Iterable of tuple/list
\tKey sequence that is sorted
startkey: Tuple/list
\tFirst key to be yielded
reverse: Bool
\tSort direction reversed if True
"""
tuple_key = lambda t: t[::-1]
if reverse:
tuple_cmp = lambda t: t[::-1] > startkey[::-1]
else:
tuple_cmp = lambda t: t[::-1] < startkey[::-1]
searchkeys = sorted(keys, key=tuple_key, reverse=reverse)
searchpos = sum(1 for _ in ifilter(tuple_cmp, searchkeys))
searchkeys = searchkeys[searchpos:] + searchkeys[:searchpos]
for key in searchkeys:
yield key | python | def _sorted_keys(self, keys, startkey, reverse=False):
"""Generator that yields sorted keys starting with startkey
Parameters
----------
keys: Iterable of tuple/list
\tKey sequence that is sorted
startkey: Tuple/list
\tFirst key to be yielded
reverse: Bool
\tSort direction reversed if True
"""
tuple_key = lambda t: t[::-1]
if reverse:
tuple_cmp = lambda t: t[::-1] > startkey[::-1]
else:
tuple_cmp = lambda t: t[::-1] < startkey[::-1]
searchkeys = sorted(keys, key=tuple_key, reverse=reverse)
searchpos = sum(1 for _ in ifilter(tuple_cmp, searchkeys))
searchkeys = searchkeys[searchpos:] + searchkeys[:searchpos]
for key in searchkeys:
yield key | [
"def",
"_sorted_keys",
"(",
"self",
",",
"keys",
",",
"startkey",
",",
"reverse",
"=",
"False",
")",
":",
"tuple_key",
"=",
"lambda",
"t",
":",
"t",
"[",
":",
":",
"-",
"1",
"]",
"if",
"reverse",
":",
"tuple_cmp",
"=",
"lambda",
"t",
":",
"t",
"[",
":",
":",
"-",
"1",
"]",
">",
"startkey",
"[",
":",
":",
"-",
"1",
"]",
"else",
":",
"tuple_cmp",
"=",
"lambda",
"t",
":",
"t",
"[",
":",
":",
"-",
"1",
"]",
"<",
"startkey",
"[",
":",
":",
"-",
"1",
"]",
"searchkeys",
"=",
"sorted",
"(",
"keys",
",",
"key",
"=",
"tuple_key",
",",
"reverse",
"=",
"reverse",
")",
"searchpos",
"=",
"sum",
"(",
"1",
"for",
"_",
"in",
"ifilter",
"(",
"tuple_cmp",
",",
"searchkeys",
")",
")",
"searchkeys",
"=",
"searchkeys",
"[",
"searchpos",
":",
"]",
"+",
"searchkeys",
"[",
":",
"searchpos",
"]",
"for",
"key",
"in",
"searchkeys",
":",
"yield",
"key"
] | Generator that yields sorted keys starting with startkey
Parameters
----------
keys: Iterable of tuple/list
\tKey sequence that is sorted
startkey: Tuple/list
\tFirst key to be yielded
reverse: Bool
\tSort direction reversed if True | [
"Generator",
"that",
"yields",
"sorted",
"keys",
"starting",
"with",
"startkey"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1461-L1488 | train | 231,691 |
manns/pyspread | pyspread/src/model/model.py | CodeArray.findnextmatch | def findnextmatch(self, startkey, find_string, flags, search_result=True):
""" Returns a tuple with the position of the next match of find_string
Returns None if string not found.
Parameters:
-----------
startkey: Start position of search
find_string:String to be searched for
flags: List of strings, out of
["UP" xor "DOWN", "WHOLE_WORD", "MATCH_CASE", "REG_EXP"]
search_result: Bool, defaults to True
\tIf True then the search includes the result string (slower)
"""
assert "UP" in flags or "DOWN" in flags
assert not ("UP" in flags and "DOWN" in flags)
if search_result:
def is_matching(key, find_string, flags):
code = self(key)
if self.string_match(code, find_string, flags) is not None:
return True
else:
res_str = unicode(self[key])
return self.string_match(res_str, find_string, flags) \
is not None
else:
def is_matching(code, find_string, flags):
code = self(key)
return self.string_match(code, find_string, flags) is not None
# List of keys in sgrid in search order
reverse = "UP" in flags
for key in self._sorted_keys(self.keys(), startkey, reverse=reverse):
try:
if is_matching(key, find_string, flags):
return key
except Exception:
# re errors are cryptical: sre_constants,...
pass | python | def findnextmatch(self, startkey, find_string, flags, search_result=True):
""" Returns a tuple with the position of the next match of find_string
Returns None if string not found.
Parameters:
-----------
startkey: Start position of search
find_string:String to be searched for
flags: List of strings, out of
["UP" xor "DOWN", "WHOLE_WORD", "MATCH_CASE", "REG_EXP"]
search_result: Bool, defaults to True
\tIf True then the search includes the result string (slower)
"""
assert "UP" in flags or "DOWN" in flags
assert not ("UP" in flags and "DOWN" in flags)
if search_result:
def is_matching(key, find_string, flags):
code = self(key)
if self.string_match(code, find_string, flags) is not None:
return True
else:
res_str = unicode(self[key])
return self.string_match(res_str, find_string, flags) \
is not None
else:
def is_matching(code, find_string, flags):
code = self(key)
return self.string_match(code, find_string, flags) is not None
# List of keys in sgrid in search order
reverse = "UP" in flags
for key in self._sorted_keys(self.keys(), startkey, reverse=reverse):
try:
if is_matching(key, find_string, flags):
return key
except Exception:
# re errors are cryptical: sre_constants,...
pass | [
"def",
"findnextmatch",
"(",
"self",
",",
"startkey",
",",
"find_string",
",",
"flags",
",",
"search_result",
"=",
"True",
")",
":",
"assert",
"\"UP\"",
"in",
"flags",
"or",
"\"DOWN\"",
"in",
"flags",
"assert",
"not",
"(",
"\"UP\"",
"in",
"flags",
"and",
"\"DOWN\"",
"in",
"flags",
")",
"if",
"search_result",
":",
"def",
"is_matching",
"(",
"key",
",",
"find_string",
",",
"flags",
")",
":",
"code",
"=",
"self",
"(",
"key",
")",
"if",
"self",
".",
"string_match",
"(",
"code",
",",
"find_string",
",",
"flags",
")",
"is",
"not",
"None",
":",
"return",
"True",
"else",
":",
"res_str",
"=",
"unicode",
"(",
"self",
"[",
"key",
"]",
")",
"return",
"self",
".",
"string_match",
"(",
"res_str",
",",
"find_string",
",",
"flags",
")",
"is",
"not",
"None",
"else",
":",
"def",
"is_matching",
"(",
"code",
",",
"find_string",
",",
"flags",
")",
":",
"code",
"=",
"self",
"(",
"key",
")",
"return",
"self",
".",
"string_match",
"(",
"code",
",",
"find_string",
",",
"flags",
")",
"is",
"not",
"None",
"# List of keys in sgrid in search order",
"reverse",
"=",
"\"UP\"",
"in",
"flags",
"for",
"key",
"in",
"self",
".",
"_sorted_keys",
"(",
"self",
".",
"keys",
"(",
")",
",",
"startkey",
",",
"reverse",
"=",
"reverse",
")",
":",
"try",
":",
"if",
"is_matching",
"(",
"key",
",",
"find_string",
",",
"flags",
")",
":",
"return",
"key",
"except",
"Exception",
":",
"# re errors are cryptical: sre_constants,...",
"pass"
] | Returns a tuple with the position of the next match of find_string
Returns None if string not found.
Parameters:
-----------
startkey: Start position of search
find_string:String to be searched for
flags: List of strings, out of
["UP" xor "DOWN", "WHOLE_WORD", "MATCH_CASE", "REG_EXP"]
search_result: Bool, defaults to True
\tIf True then the search includes the result string (slower) | [
"Returns",
"a",
"tuple",
"with",
"the",
"position",
"of",
"the",
"next",
"match",
"of",
"find_string"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/model/model.py#L1532-L1577 | train | 231,692 |
manns/pyspread | pyspread/src/gui/_dialogs.py | IntValidator.Validate | def Validate(self, win):
"""Returns True if Value in digits, False otherwise"""
val = self.GetWindow().GetValue()
for x in val:
if x not in string.digits:
return False
return True | python | def Validate(self, win):
"""Returns True if Value in digits, False otherwise"""
val = self.GetWindow().GetValue()
for x in val:
if x not in string.digits:
return False
return True | [
"def",
"Validate",
"(",
"self",
",",
"win",
")",
":",
"val",
"=",
"self",
".",
"GetWindow",
"(",
")",
".",
"GetValue",
"(",
")",
"for",
"x",
"in",
"val",
":",
"if",
"x",
"not",
"in",
"string",
".",
"digits",
":",
"return",
"False",
"return",
"True"
] | Returns True if Value in digits, False otherwise | [
"Returns",
"True",
"if",
"Value",
"in",
"digits",
"False",
"otherwise"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_dialogs.py#L99-L108 | train | 231,693 |
manns/pyspread | pyspread/src/gui/_dialogs.py | IntValidator.OnChar | def OnChar(self, event):
"""Eats event if key not in digits"""
key = event.GetKeyCode()
if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255 or \
chr(key) in string.digits:
event.Skip() | python | def OnChar(self, event):
"""Eats event if key not in digits"""
key = event.GetKeyCode()
if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255 or \
chr(key) in string.digits:
event.Skip() | [
"def",
"OnChar",
"(",
"self",
",",
"event",
")",
":",
"key",
"=",
"event",
".",
"GetKeyCode",
"(",
")",
"if",
"key",
"<",
"wx",
".",
"WXK_SPACE",
"or",
"key",
"==",
"wx",
".",
"WXK_DELETE",
"or",
"key",
">",
"255",
"or",
"chr",
"(",
"key",
")",
"in",
"string",
".",
"digits",
":",
"event",
".",
"Skip",
"(",
")"
] | Eats event if key not in digits | [
"Eats",
"event",
"if",
"key",
"not",
"in",
"digits"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_dialogs.py#L110-L117 | train | 231,694 |
manns/pyspread | pyspread/src/gui/_dialogs.py | ChoiceRenderer.Draw | def Draw(self, grid, attr, dc, rect, row, col, is_selected):
"""Draws the text and the combobox icon"""
render = wx.RendererNative.Get()
# clear the background
dc.SetBackgroundMode(wx.SOLID)
if is_selected:
dc.SetBrush(wx.Brush(wx.BLUE, wx.SOLID))
dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID))
else:
dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.SOLID))
dc.DrawRectangleRect(rect)
cb_lbl = grid.GetCellValue(row, col)
string_x = rect.x + 2
string_y = rect.y + 2
dc.DrawText(cb_lbl, string_x, string_y)
button_x = rect.x + rect.width - self.iconwidth
button_y = rect.y
button_width = self.iconwidth
button_height = rect.height
button_size = button_x, button_y, button_width, button_height
render.DrawComboBoxDropButton(grid, dc, button_size,
wx.CONTROL_CURRENT) | python | def Draw(self, grid, attr, dc, rect, row, col, is_selected):
"""Draws the text and the combobox icon"""
render = wx.RendererNative.Get()
# clear the background
dc.SetBackgroundMode(wx.SOLID)
if is_selected:
dc.SetBrush(wx.Brush(wx.BLUE, wx.SOLID))
dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID))
else:
dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.SOLID))
dc.DrawRectangleRect(rect)
cb_lbl = grid.GetCellValue(row, col)
string_x = rect.x + 2
string_y = rect.y + 2
dc.DrawText(cb_lbl, string_x, string_y)
button_x = rect.x + rect.width - self.iconwidth
button_y = rect.y
button_width = self.iconwidth
button_height = rect.height
button_size = button_x, button_y, button_width, button_height
render.DrawComboBoxDropButton(grid, dc, button_size,
wx.CONTROL_CURRENT) | [
"def",
"Draw",
"(",
"self",
",",
"grid",
",",
"attr",
",",
"dc",
",",
"rect",
",",
"row",
",",
"col",
",",
"is_selected",
")",
":",
"render",
"=",
"wx",
".",
"RendererNative",
".",
"Get",
"(",
")",
"# clear the background",
"dc",
".",
"SetBackgroundMode",
"(",
"wx",
".",
"SOLID",
")",
"if",
"is_selected",
":",
"dc",
".",
"SetBrush",
"(",
"wx",
".",
"Brush",
"(",
"wx",
".",
"BLUE",
",",
"wx",
".",
"SOLID",
")",
")",
"dc",
".",
"SetPen",
"(",
"wx",
".",
"Pen",
"(",
"wx",
".",
"BLUE",
",",
"1",
",",
"wx",
".",
"SOLID",
")",
")",
"else",
":",
"dc",
".",
"SetBrush",
"(",
"wx",
".",
"Brush",
"(",
"wx",
".",
"WHITE",
",",
"wx",
".",
"SOLID",
")",
")",
"dc",
".",
"SetPen",
"(",
"wx",
".",
"Pen",
"(",
"wx",
".",
"WHITE",
",",
"1",
",",
"wx",
".",
"SOLID",
")",
")",
"dc",
".",
"DrawRectangleRect",
"(",
"rect",
")",
"cb_lbl",
"=",
"grid",
".",
"GetCellValue",
"(",
"row",
",",
"col",
")",
"string_x",
"=",
"rect",
".",
"x",
"+",
"2",
"string_y",
"=",
"rect",
".",
"y",
"+",
"2",
"dc",
".",
"DrawText",
"(",
"cb_lbl",
",",
"string_x",
",",
"string_y",
")",
"button_x",
"=",
"rect",
".",
"x",
"+",
"rect",
".",
"width",
"-",
"self",
".",
"iconwidth",
"button_y",
"=",
"rect",
".",
"y",
"button_width",
"=",
"self",
".",
"iconwidth",
"button_height",
"=",
"rect",
".",
"height",
"button_size",
"=",
"button_x",
",",
"button_y",
",",
"button_width",
",",
"button_height",
"render",
".",
"DrawComboBoxDropButton",
"(",
"grid",
",",
"dc",
",",
"button_size",
",",
"wx",
".",
"CONTROL_CURRENT",
")"
] | Draws the text and the combobox icon | [
"Draws",
"the",
"text",
"and",
"the",
"combobox",
"icon"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_dialogs.py#L140-L167 | train | 231,695 |
manns/pyspread | pyspread/src/gui/_dialogs.py | CsvParameterWidgets._setup_param_widgets | def _setup_param_widgets(self):
"""Creates the parameter entry widgets and binds them to methods"""
for parameter in self.csv_params:
pname, ptype, plabel, phelp = parameter
label = wx.StaticText(self.parent, -1, plabel)
widget = self.type2widget[ptype](self.parent)
# Append choicebox items and bind handler
if pname in self.choices:
widget.AppendItems(self.choices[pname])
widget.SetValue = widget.Select
widget.SetSelection(0)
# Bind event handler to widget
if ptype is types.StringType or ptype is types.UnicodeType:
event_type = wx.EVT_TEXT
elif ptype is types.BooleanType:
event_type = wx.EVT_CHECKBOX
else:
event_type = wx.EVT_CHOICE
handler = getattr(self, self.widget_handlers[pname])
self.parent.Bind(event_type, handler, widget)
# Tool tips
label.SetToolTipString(phelp)
widget.SetToolTipString(phelp)
label.__name__ = wx.StaticText.__name__.lower()
widget.__name__ = self.type2widget[ptype].__name__.lower()
self.param_labels.append(label)
self.param_widgets.append(widget)
self.__setattr__("_".join([label.__name__, pname]), label)
self.__setattr__("_".join([widget.__name__, pname]), widget) | python | def _setup_param_widgets(self):
"""Creates the parameter entry widgets and binds them to methods"""
for parameter in self.csv_params:
pname, ptype, plabel, phelp = parameter
label = wx.StaticText(self.parent, -1, plabel)
widget = self.type2widget[ptype](self.parent)
# Append choicebox items and bind handler
if pname in self.choices:
widget.AppendItems(self.choices[pname])
widget.SetValue = widget.Select
widget.SetSelection(0)
# Bind event handler to widget
if ptype is types.StringType or ptype is types.UnicodeType:
event_type = wx.EVT_TEXT
elif ptype is types.BooleanType:
event_type = wx.EVT_CHECKBOX
else:
event_type = wx.EVT_CHOICE
handler = getattr(self, self.widget_handlers[pname])
self.parent.Bind(event_type, handler, widget)
# Tool tips
label.SetToolTipString(phelp)
widget.SetToolTipString(phelp)
label.__name__ = wx.StaticText.__name__.lower()
widget.__name__ = self.type2widget[ptype].__name__.lower()
self.param_labels.append(label)
self.param_widgets.append(widget)
self.__setattr__("_".join([label.__name__, pname]), label)
self.__setattr__("_".join([widget.__name__, pname]), widget) | [
"def",
"_setup_param_widgets",
"(",
"self",
")",
":",
"for",
"parameter",
"in",
"self",
".",
"csv_params",
":",
"pname",
",",
"ptype",
",",
"plabel",
",",
"phelp",
"=",
"parameter",
"label",
"=",
"wx",
".",
"StaticText",
"(",
"self",
".",
"parent",
",",
"-",
"1",
",",
"plabel",
")",
"widget",
"=",
"self",
".",
"type2widget",
"[",
"ptype",
"]",
"(",
"self",
".",
"parent",
")",
"# Append choicebox items and bind handler",
"if",
"pname",
"in",
"self",
".",
"choices",
":",
"widget",
".",
"AppendItems",
"(",
"self",
".",
"choices",
"[",
"pname",
"]",
")",
"widget",
".",
"SetValue",
"=",
"widget",
".",
"Select",
"widget",
".",
"SetSelection",
"(",
"0",
")",
"# Bind event handler to widget",
"if",
"ptype",
"is",
"types",
".",
"StringType",
"or",
"ptype",
"is",
"types",
".",
"UnicodeType",
":",
"event_type",
"=",
"wx",
".",
"EVT_TEXT",
"elif",
"ptype",
"is",
"types",
".",
"BooleanType",
":",
"event_type",
"=",
"wx",
".",
"EVT_CHECKBOX",
"else",
":",
"event_type",
"=",
"wx",
".",
"EVT_CHOICE",
"handler",
"=",
"getattr",
"(",
"self",
",",
"self",
".",
"widget_handlers",
"[",
"pname",
"]",
")",
"self",
".",
"parent",
".",
"Bind",
"(",
"event_type",
",",
"handler",
",",
"widget",
")",
"# Tool tips",
"label",
".",
"SetToolTipString",
"(",
"phelp",
")",
"widget",
".",
"SetToolTipString",
"(",
"phelp",
")",
"label",
".",
"__name__",
"=",
"wx",
".",
"StaticText",
".",
"__name__",
".",
"lower",
"(",
")",
"widget",
".",
"__name__",
"=",
"self",
".",
"type2widget",
"[",
"ptype",
"]",
".",
"__name__",
".",
"lower",
"(",
")",
"self",
".",
"param_labels",
".",
"append",
"(",
"label",
")",
"self",
".",
"param_widgets",
".",
"append",
"(",
"widget",
")",
"self",
".",
"__setattr__",
"(",
"\"_\"",
".",
"join",
"(",
"[",
"label",
".",
"__name__",
",",
"pname",
"]",
")",
",",
"label",
")",
"self",
".",
"__setattr__",
"(",
"\"_\"",
".",
"join",
"(",
"[",
"widget",
".",
"__name__",
",",
"pname",
"]",
")",
",",
"widget",
")"
] | Creates the parameter entry widgets and binds them to methods | [
"Creates",
"the",
"parameter",
"entry",
"widgets",
"and",
"binds",
"them",
"to",
"methods"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_dialogs.py#L289-L326 | train | 231,696 |
manns/pyspread | pyspread/src/gui/_dialogs.py | CsvParameterWidgets._do_layout | def _do_layout(self):
"""Sizer hell, returns a sizer that contains all widgets"""
sizer_csvoptions = wx.FlexGridSizer(5, 4, 5, 5)
# Adding parameter widgets to sizer_csvoptions
leftpos = wx.LEFT | wx.ADJUST_MINSIZE
rightpos = wx.RIGHT | wx.EXPAND
current_label_margin = 0 # smaller for left column
other_label_margin = 15
for label, widget in zip(self.param_labels, self.param_widgets):
sizer_csvoptions.Add(label, 0, leftpos, current_label_margin)
sizer_csvoptions.Add(widget, 0, rightpos, current_label_margin)
current_label_margin, other_label_margin = \
other_label_margin, current_label_margin
sizer_csvoptions.AddGrowableCol(1)
sizer_csvoptions.AddGrowableCol(3)
self.sizer_csvoptions = sizer_csvoptions | python | def _do_layout(self):
"""Sizer hell, returns a sizer that contains all widgets"""
sizer_csvoptions = wx.FlexGridSizer(5, 4, 5, 5)
# Adding parameter widgets to sizer_csvoptions
leftpos = wx.LEFT | wx.ADJUST_MINSIZE
rightpos = wx.RIGHT | wx.EXPAND
current_label_margin = 0 # smaller for left column
other_label_margin = 15
for label, widget in zip(self.param_labels, self.param_widgets):
sizer_csvoptions.Add(label, 0, leftpos, current_label_margin)
sizer_csvoptions.Add(widget, 0, rightpos, current_label_margin)
current_label_margin, other_label_margin = \
other_label_margin, current_label_margin
sizer_csvoptions.AddGrowableCol(1)
sizer_csvoptions.AddGrowableCol(3)
self.sizer_csvoptions = sizer_csvoptions | [
"def",
"_do_layout",
"(",
"self",
")",
":",
"sizer_csvoptions",
"=",
"wx",
".",
"FlexGridSizer",
"(",
"5",
",",
"4",
",",
"5",
",",
"5",
")",
"# Adding parameter widgets to sizer_csvoptions",
"leftpos",
"=",
"wx",
".",
"LEFT",
"|",
"wx",
".",
"ADJUST_MINSIZE",
"rightpos",
"=",
"wx",
".",
"RIGHT",
"|",
"wx",
".",
"EXPAND",
"current_label_margin",
"=",
"0",
"# smaller for left column",
"other_label_margin",
"=",
"15",
"for",
"label",
",",
"widget",
"in",
"zip",
"(",
"self",
".",
"param_labels",
",",
"self",
".",
"param_widgets",
")",
":",
"sizer_csvoptions",
".",
"Add",
"(",
"label",
",",
"0",
",",
"leftpos",
",",
"current_label_margin",
")",
"sizer_csvoptions",
".",
"Add",
"(",
"widget",
",",
"0",
",",
"rightpos",
",",
"current_label_margin",
")",
"current_label_margin",
",",
"other_label_margin",
"=",
"other_label_margin",
",",
"current_label_margin",
"sizer_csvoptions",
".",
"AddGrowableCol",
"(",
"1",
")",
"sizer_csvoptions",
".",
"AddGrowableCol",
"(",
"3",
")",
"self",
".",
"sizer_csvoptions",
"=",
"sizer_csvoptions"
] | Sizer hell, returns a sizer that contains all widgets | [
"Sizer",
"hell",
"returns",
"a",
"sizer",
"that",
"contains",
"all",
"widgets"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_dialogs.py#L328-L350 | train | 231,697 |
manns/pyspread | pyspread/src/gui/_dialogs.py | CsvParameterWidgets._update_settings | def _update_settings(self, dialect):
"""Sets the widget settings to those of the chosen dialect"""
# the first parameter is the dialect itself --> ignore
for parameter in self.csv_params[2:]:
pname, ptype, plabel, phelp = parameter
widget = self._widget_from_p(pname, ptype)
if ptype is types.TupleType:
ptype = types.ObjectType
digest = Digest(acceptable_types=[ptype])
if pname == 'self.has_header':
if self.has_header is not None:
widget.SetValue(digest(self.has_header))
else:
value = getattr(dialect, pname)
widget.SetValue(digest(value)) | python | def _update_settings(self, dialect):
"""Sets the widget settings to those of the chosen dialect"""
# the first parameter is the dialect itself --> ignore
for parameter in self.csv_params[2:]:
pname, ptype, plabel, phelp = parameter
widget = self._widget_from_p(pname, ptype)
if ptype is types.TupleType:
ptype = types.ObjectType
digest = Digest(acceptable_types=[ptype])
if pname == 'self.has_header':
if self.has_header is not None:
widget.SetValue(digest(self.has_header))
else:
value = getattr(dialect, pname)
widget.SetValue(digest(value)) | [
"def",
"_update_settings",
"(",
"self",
",",
"dialect",
")",
":",
"# the first parameter is the dialect itself --> ignore",
"for",
"parameter",
"in",
"self",
".",
"csv_params",
"[",
"2",
":",
"]",
":",
"pname",
",",
"ptype",
",",
"plabel",
",",
"phelp",
"=",
"parameter",
"widget",
"=",
"self",
".",
"_widget_from_p",
"(",
"pname",
",",
"ptype",
")",
"if",
"ptype",
"is",
"types",
".",
"TupleType",
":",
"ptype",
"=",
"types",
".",
"ObjectType",
"digest",
"=",
"Digest",
"(",
"acceptable_types",
"=",
"[",
"ptype",
"]",
")",
"if",
"pname",
"==",
"'self.has_header'",
":",
"if",
"self",
".",
"has_header",
"is",
"not",
"None",
":",
"widget",
".",
"SetValue",
"(",
"digest",
"(",
"self",
".",
"has_header",
")",
")",
"else",
":",
"value",
"=",
"getattr",
"(",
"dialect",
",",
"pname",
")",
"widget",
".",
"SetValue",
"(",
"digest",
"(",
"value",
")",
")"
] | Sets the widget settings to those of the chosen dialect | [
"Sets",
"the",
"widget",
"settings",
"to",
"those",
"of",
"the",
"chosen",
"dialect"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_dialogs.py#L352-L371 | train | 231,698 |
manns/pyspread | pyspread/src/gui/_dialogs.py | CsvParameterWidgets._widget_from_p | def _widget_from_p(self, pname, ptype):
"""Returns a widget from its ptype and pname"""
widget_name = self.type2widget[ptype].__name__.lower()
widget_name = "_".join([widget_name, pname])
return getattr(self, widget_name) | python | def _widget_from_p(self, pname, ptype):
"""Returns a widget from its ptype and pname"""
widget_name = self.type2widget[ptype].__name__.lower()
widget_name = "_".join([widget_name, pname])
return getattr(self, widget_name) | [
"def",
"_widget_from_p",
"(",
"self",
",",
"pname",
",",
"ptype",
")",
":",
"widget_name",
"=",
"self",
".",
"type2widget",
"[",
"ptype",
"]",
".",
"__name__",
".",
"lower",
"(",
")",
"widget_name",
"=",
"\"_\"",
".",
"join",
"(",
"[",
"widget_name",
",",
"pname",
"]",
")",
"return",
"getattr",
"(",
"self",
",",
"widget_name",
")"
] | Returns a widget from its ptype and pname | [
"Returns",
"a",
"widget",
"from",
"its",
"ptype",
"and",
"pname"
] | 0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0 | https://github.com/manns/pyspread/blob/0e2fd44c2e0f06605efc3058c20a43a8c1f9e7e0/pyspread/src/gui/_dialogs.py#L373-L378 | train | 231,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.