本文整理汇总了Python中spyder.py3compat.is_text_string函数的典型用法代码示例。如果您正苦于以下问题:Python is_text_string函数的具体用法?Python is_text_string怎么用?Python is_text_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_text_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:26,代码来源:user.py
示例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
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:11,代码来源:user.py
示例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
开发者ID:rlaverde,项目名称:spyder,代码行数:51,代码来源:user.py
示例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)]
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:7,代码来源:dochelpers.py
示例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
开发者ID:rlaverde,项目名称:spyder,代码行数:35,代码来源:dataframeeditor.py
示例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
开发者ID:rlaverde,项目名称:spyder,代码行数:30,代码来源:dataframeeditor.py
示例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}
开发者ID:burrbull,项目名称:spyder,代码行数:25,代码来源:misc.py
示例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)
开发者ID:silentquasar,项目名称:spyder,代码行数:7,代码来源:browser.py
示例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)
开发者ID:jitseniesen,项目名称:spyder,代码行数:7,代码来源:maininterpreter.py
示例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
开发者ID:jitseniesen,项目名称:spyder,代码行数:8,代码来源:mixins.py
示例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))
开发者ID:silentquasar,项目名称:spyder,代码行数:8,代码来源:qthelpers.py
示例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")
开发者ID:0xBADCA7,项目名称:spyder,代码行数:8,代码来源:base.py
示例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)
开发者ID:rlaverde,项目名称:spyder,代码行数:9,代码来源:maininterpreter.py
示例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)
开发者ID:burrbull,项目名称:spyder,代码行数:10,代码来源:plugin.py
示例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))
开发者ID:silentquasar,项目名称:spyder,代码行数:10,代码来源:qthelpers.py
示例16: _set
def _set(self, section, option, value, verbose):
"""
Private set method
"""
if not self.has_section(section):
self.add_section( section )
if not is_text_string(value):
value = repr( value )
if verbose:
print('%s[ %s ] = %s' % (section, option, value))
cp.ConfigParser.set(self, section, option, value)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:11,代码来源:user.py
示例17: eval
def eval(self, text):
"""
Evaluate text and return (obj, valid)
where *obj* is the object represented by *text*
and *valid* is True if object evaluation did not raise any exception
"""
assert is_text_string(text)
try:
return eval(text, self.locals), True
except:
return None, False
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:11,代码来源:interpreter.py
示例18: _eval
def _eval(self, text):
"""
Evaluate text and return (obj, valid)
where *obj* is the object represented by *text*
and *valid* is True if object evaluation did not raise any exception
"""
assert is_text_string(text)
ns = self.get_current_namespace(with_magics=True)
try:
return eval(text, ns), True
except:
return None, False
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:12,代码来源:monitor.py
示例19: append_to_history
def append_to_history(self, filename, command):
"""
Append an entry to history filename
Slot for append_to_history signal emitted by shell instance
"""
if not is_text_string(filename): # filename is a QString
filename = to_text_string(filename.toUtf8(), "utf-8")
command = to_text_string(command)
index = self.filenames.index(filename)
self.editors[index].append(command)
if self.get_option("go_to_eof"):
self.editors[index].set_cursor_position("eof")
self.tabwidget.setCurrentIndex(index)
开发者ID:silentquasar,项目名称:spyder,代码行数:13,代码来源:history.py
示例20: create_dialog
def create_dialog(obj, obj_name):
"""Creates the editor dialog and returns a tuple (dialog, func) where func
is the function to be called with the dialog instance as argument, after
quitting the dialog box
The role of this intermediate function is to allow easy monkey-patching.
(uschmitt suggested this indirection here so that he can monkey patch
oedit to show eMZed related data)
"""
# Local import
from spyder.widgets.variableexplorer.texteditor import TextEditor
from spyder.widgets.variableexplorer.utils import (ndarray, FakeObject,
Image, is_known_type, DataFrame,
Series)
from spyder.widgets.variableexplorer.collectionseditor import CollectionsEditor
from spyder.widgets.variableexplorer.arrayeditor import ArrayEditor
if DataFrame is not FakeObject:
from spyder.widgets.variableexplorer.dataframeeditor import DataFrameEditor
conv_func = lambda data: data
readonly = not is_known_type(obj)
if isinstance(obj, ndarray) and ndarray is not FakeObject:
dialog = ArrayEditor()
if not dialog.setup_and_check(obj, title=obj_name,
readonly=readonly):
return
elif isinstance(obj, Image) and Image is not FakeObject \
and ndarray is not FakeObject:
dialog = ArrayEditor()
import numpy as np
data = np.array(obj)
if not dialog.setup_and_check(data, title=obj_name,
readonly=readonly):
return
from spyder.pil_patch import Image
conv_func = lambda data: Image.fromarray(data, mode=obj.mode)
elif isinstance(obj, (DataFrame, Series)) and DataFrame is not FakeObject:
dialog = DataFrameEditor()
if not dialog.setup_and_check(obj):
return
elif is_text_string(obj):
dialog = TextEditor(obj, title=obj_name, readonly=readonly)
else:
dialog = CollectionsEditor()
dialog.setup(obj, title=obj_name, readonly=readonly)
def end_func(dialog):
return conv_func(dialog.get_value())
return dialog, end_func
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:50,代码来源:objecteditor.py
注:本文中的spyder.py3compat.is_text_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论