本文整理汇总了Python中spyder.py3compat.is_text_string函数的典型用法代码示例。如果您正苦于以下问题:Python is_text_string函数的具体用法?Python is_text_string怎么用?Python is_text_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_text_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
def set(self, section, option, value, verbose=False, save=True):
"""
Set an option
section=None: attribute a default section name
"""
section = self._check_section_option(section, option)
default_value = self.get_default(section, option)
if default_value is NoDefault:
# This let us save correctly string value options with
# no config default that contain non-ascii chars in
# Python 2
if PY2 and is_text_string(value):
value = repr(value)
default_value = value
self.set_default(section, option, default_value)
if isinstance(default_value, bool):
value = bool(value)
elif isinstance(default_value, float):
value = float(value)
elif isinstance(default_value, int):
value = int(value)
elif not is_text_string(default_value):
value = repr(value)
self._set(section, option, value, verbose)
if save:
self._save()
示例2: _check_section_option
def _check_section_option(self, section, option):
"""
Private method to check section and option types
"""
if section is None:
section = self.DEFAULT_SECTION_NAME
elif not is_text_string(section):
raise RuntimeError("Argument 'section' must be a string")
if not is_text_string(option):
raise RuntimeError("Argument 'option' must be a string")
return section
示例3: get
def get(self, section, option, default=NoDefault):
"""
Get an option
section=None: attribute a default section name
default: default value (if not specified, an exception
will be raised if option doesn't exist)
"""
section = self._check_section_option(section, option)
if not self.has_section(section):
if default is NoDefault:
raise cp.NoSectionError(section)
else:
self.add_section(section)
if not self.has_option(section, option):
if default is NoDefault:
raise cp.NoOptionError(option, section)
else:
self.set(section, option, default)
return default
value = cp.ConfigParser.get(self, section, option, raw=self.raw)
# Use type of default_value to parse value correctly
default_value = self.get_default(section, option)
if isinstance(default_value, bool):
value = ast.literal_eval(value)
elif isinstance(default_value, float):
value = float(value)
elif isinstance(default_value, int):
value = int(value)
elif is_text_string(default_value):
if PY2:
try:
value = value.decode('utf-8')
try:
# Some str config values expect to be eval after decoding
new_value = ast.literal_eval(value)
if is_text_string(new_value):
value = new_value
except (SyntaxError, ValueError):
pass
except (UnicodeEncodeError, UnicodeDecodeError):
pass
else:
try:
# lists, tuples, ...
value = ast.literal_eval(value)
except (SyntaxError, ValueError):
pass
return value
示例4: getobjdir
def getobjdir(obj):
"""
For standard objects, will simply return dir(obj)
In special cases (e.g. WrapITK package), will return only string elements
of result returned by dir(obj)
"""
return [item for item in dir(obj) if is_text_string(item)]
示例5: setData
def setData(self, index, value, role=Qt.EditRole, change_type=None):
"""Cell content change"""
column = index.column()
row = index.row()
if change_type is not None:
try:
value = self.data(index, role=Qt.DisplayRole)
val = from_qvariant(value, str)
if change_type is bool:
val = bool_false_check(val)
self.df.iloc[row, column - 1] = change_type(val)
except ValueError:
self.df.iloc[row, column - 1] = change_type('0')
else:
val = from_qvariant(value, str)
current_value = self.get_value(row, column-1)
if isinstance(current_value, bool):
val = bool_false_check(val)
supported_types = (bool,) + REAL_NUMBER_TYPES + COMPLEX_NUMBER_TYPES
if (isinstance(current_value, supported_types) or
is_text_string(current_value)):
try:
self.df.iloc[row, column-1] = current_value.__class__(val)
except ValueError as e:
QMessageBox.critical(self.dialog, "Error",
"Value error: %s" % str(e))
return False
else:
QMessageBox.critical(self.dialog, "Error",
"The type of the cell is not a supported "
"type")
return False
self.max_min_col_update()
return True
示例6: get_bgcolor
def get_bgcolor(self, index):
"""Background color depending on value"""
column = index.column()
if column == 0:
color = QColor(BACKGROUND_NONNUMBER_COLOR)
color.setAlphaF(BACKGROUND_INDEX_ALPHA)
return color
if not self.bgcolor_enabled:
return
value = self.get_value(index.row(), column-1)
if self.max_min_col[column - 1] is None:
color = QColor(BACKGROUND_NONNUMBER_COLOR)
if is_text_string(value):
color.setAlphaF(BACKGROUND_STRING_ALPHA)
else:
color.setAlphaF(BACKGROUND_MISC_ALPHA)
else:
if isinstance(value, COMPLEX_NUMBER_TYPES):
color_func = abs
else:
color_func = float
vmax, vmin = self.return_max(self.max_min_col, column-1)
hue = (BACKGROUND_NUMBER_MINHUE + BACKGROUND_NUMBER_HUERANGE *
(vmax - color_func(value)) / (vmax - vmin))
hue = float(abs(hue))
if hue > 1:
hue = 1
color = QColor.fromHsvF(hue, BACKGROUND_NUMBER_SATURATION,
BACKGROUND_NUMBER_VALUE, BACKGROUND_NUMBER_ALPHA)
return color
示例7: add_pathlist_to_PYTHONPATH
def add_pathlist_to_PYTHONPATH(env, pathlist, drop_env=False,
ipyconsole=False):
# PyQt API 1/2 compatibility-related tests:
assert isinstance(env, list)
assert all([is_text_string(path) for path in env])
pypath = "PYTHONPATH"
pathstr = os.pathsep.join(pathlist)
if os.environ.get(pypath) is not None and not drop_env:
old_pypath = os.environ[pypath]
if not ipyconsole:
for index, var in enumerate(env[:]):
if var.startswith(pypath+'='):
env[index] = var.replace(pypath+'=',
pypath+'='+pathstr+os.pathsep)
env.append('OLD_PYTHONPATH='+old_pypath)
else:
pypath = {'PYTHONPATH': pathstr + os.pathsep + old_pypath,
'OLD_PYTHONPATH': old_pypath}
return pypath
else:
if not ipyconsole:
env.append(pypath+'='+pathstr)
else:
return {'PYTHONPATH': pathstr}
示例8: go_to
def go_to(self, url_or_text):
"""Go to page *address*"""
if is_text_string(url_or_text):
url = QUrl(url_or_text)
else:
url = url_or_text
self.webview.load(url)
示例9: python_executable_changed
def python_executable_changed(self, pyexec):
"""Custom Python executable value has been changed"""
if not self.cus_exec_radio.isChecked():
return
if not is_text_string(pyexec):
pyexec = to_text_string(pyexec.toUtf8(), 'utf-8')
self.warn_python_compatibility(pyexec)
示例10: set_eol_chars
def set_eol_chars(self, text):
"""Set widget end-of-line (EOL) characters from text (analyzes text)"""
if not is_text_string(text): # testing for QString (PyQt API#1)
text = to_text_string(text)
eol_chars = sourcecode.get_eol_chars(text)
if eol_chars is not None and self.eol_chars is not None:
self.document().setModified(True)
self.eol_chars = eol_chars
示例11: create_python_script_action
def create_python_script_action(parent, text, icon, package, module, args=[]):
"""Create action to run a GUI based Python script"""
if is_text_string(icon):
icon = get_icon(icon)
if programs.python_script_exists(package, module):
return create_action(parent, text, icon=icon,
triggered=lambda:
programs.run_python_script(package, module, args))
示例12: translate_gettext
def translate_gettext(x):
if not PY3 and is_unicode(x):
x = x.encode("utf-8")
y = lgettext(x)
if is_text_string(y) and PY3:
return y
else:
return to_text_string(y, "utf-8")
示例13: python_executable_switched
def python_executable_switched(self, custom):
"""Python executable default/custom radio button has been toggled"""
def_pyexec = get_python_executable()
cust_pyexec = self.pyexec_edit.text()
if not is_text_string(cust_pyexec):
cust_pyexec = to_text_string(cust_pyexec.toUtf8(), 'utf-8')
if def_pyexec != cust_pyexec:
if custom:
self.warn_python_compatibility(cust_pyexec)
示例14: load_config
def load_config(self):
"""Load configuration: opened projects & tree widget state"""
expanded_state = self.get_option('expanded_state', None)
# Sometimes the expanded state option may be truncated in .ini file
# (for an unknown reason), in this case it would be converted to a
# string by 'userconfig':
if is_text_string(expanded_state):
expanded_state = None
if expanded_state is not None:
self.explorer.treewidget.set_expanded_state(expanded_state)
示例15: create_program_action
def create_program_action(parent, text, name, icon=None, nt_name=None):
"""Create action to run a program"""
if is_text_string(icon):
icon = get_icon(icon)
if os.name == 'nt' and nt_name is not None:
name = nt_name
path = programs.find_program(name)
if path is not None:
return create_action(parent, text, icon=icon,
triggered=lambda: programs.run_program(name))