本文整理汇总了Python中spyderlib.qt.compat.from_qvariant函数的典型用法代码示例。如果您正苦于以下问题:Python from_qvariant函数的具体用法?Python from_qvariant怎么用?Python from_qvariant使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了from_qvariant函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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)
if isinstance(current_value, ((bool,) + _sup_nr + _sup_com)) 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:gyenney,项目名称:Tools,代码行数:34,代码来源:dataframeeditor.py
示例2: setData
def setData(self, index, value, role=Qt.EditRole):
"""Cell content change"""
if not index.isValid() or self.readonly:
return False
i = index.row()
j = index.column()
value = from_qvariant(value, str)
if self._data.dtype.name == "bool":
try:
val = bool(float(value))
except ValueError:
val = value.lower() == "true"
elif self._data.dtype.name.startswith("string"):
val = str(value)
elif self._data.dtype.name.startswith("unicode"):
val = unicode(value)
else:
if value.lower().startswith('e') or value.lower().endswith('e'):
return False
try:
val = complex(value)
if not val.imag:
val = val.real
except ValueError, e:
QMessageBox.critical(self.dialog, "Error",
"Value error: %s" % str(e))
return False
开发者ID:jromang,项目名称:retina-old,代码行数:27,代码来源:arrayeditor.py
示例3: setEditorData
def setEditorData(self, editor, index):
text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
if index.column() in (MOD1, MOD2, MOD3, KEY):
i = editor.findText(text)
if i == -1:
i = 0
editor.setCurrentIndex(i)
else:
QItemDelegate.setEditorData(self, editor, index)
开发者ID:jromang,项目名称:spyderlib,代码行数:9,代码来源:shortcuts.py
示例4: setData
def setData(self, index, value, role=Qt.EditRole):
"""Qt Override."""
if index.isValid() and 0 <= index.row() < len(self.shortcuts):
shortcut = self.shortcuts[index.row()]
column = index.column()
text = from_qvariant(value, str)
if column == SEQUENCE:
shortcut.key = text
self.dataChanged.emit(index, index)
return True
return False
开发者ID:AminJamalzadeh,项目名称:spyder,代码行数:11,代码来源:shortcuts.py
示例5: _save_lang
def _save_lang(self):
"""
Get selected language setting and save to language configuration file.
"""
for combobox, (option, _default) in list(self.comboboxes.items()):
if option == 'interface_language':
data = combobox.itemData(combobox.currentIndex())
value = from_qvariant(data, to_text_string)
break
save_lang_conf(value)
self.set_option('interface_language', value)
开发者ID:gyenney,项目名称:Tools,代码行数:11,代码来源:configdialog.py
示例6: setData
def setData(self, index, value, role):
"""Override Qt method"""
row = index.row()
name, state = self.row(row)
if role == Qt.CheckStateRole:
self.set_row(row, [name, not state])
self._parent.setCurrentIndex(index)
self._parent.setFocus()
self.dataChanged.emit(index, index)
return True
elif role == Qt.EditRole:
self.set_row(row, [from_qvariant(value, to_text_string), state])
self.dataChanged.emit(index, index)
return True
return True
开发者ID:ming-hai,项目名称:spyder,代码行数:16,代码来源:layoutdialog.py
示例7: setData
def setData(self, index, value, role=Qt.EditRole):
if index.isValid() and 0 <= index.row() < len(self.shortcuts):
shortcut = self.shortcuts[index.row()]
key = shortcut.key
column = index.column()
text = from_qvariant(value, str)
if column == MOD1:
key.modifiers[0] = Key.modifier_from_name(text)
elif column == MOD2:
key.modifiers[1] = Key.modifier_from_name(text)
elif column == MOD3:
key.modifiers[2] = Key.modifier_from_name(text)
elif column == KEY:
key.key = Key.key_from_str(text)
self.dataChanged.emit(index, index)
return True
return False
开发者ID:Micseb,项目名称:spyder,代码行数:17,代码来源:shortcuts.py
示例8: setData
def setData(self, index, value, role=Qt.EditRole):
"""Cell content change"""
if not index.isValid() or self.readonly:
return False
i = index.row()
j = index.column()
value = from_qvariant(value, str)
dtype = self._data.dtype.name
if dtype == "bool":
try:
val = bool(float(value))
except ValueError:
val = value.lower() == "true"
elif dtype.startswith("string") or dtype.startswith("bytes"):
val = to_binary_string(value, 'utf8')
elif dtype.startswith("unicode") or dtype.startswith("str"):
val = to_text_string(value)
else:
if value.lower().startswith('e') or value.lower().endswith('e'):
return False
try:
val = complex(value)
if not val.imag:
val = val.real
except ValueError as e:
QMessageBox.critical(self.dialog, "Error",
"Value error: %s" % str(e))
return False
try:
self.test_array[0] = val # will raise an Exception eventually
except OverflowError as e:
print(type(e.message))
QMessageBox.critical(self.dialog, "Error",
"Overflow error: %s" % e.message)
return False
# Add change to self.changes
self.changes[(i, j)] = val
self.dataChanged.emit(index, index)
if not is_string(val):
if val > self.vmax:
self.vmax = val
if val < self.vmin:
self.vmin = val
return True
开发者ID:wellsoftware,项目名称:spyder,代码行数:45,代码来源:arrayeditor.py
示例9: display_to_value
def display_to_value(value, default_value, ignore_errors=True):
"""Convert back to value"""
from spyderlib.qt.compat import from_qvariant
value = from_qvariant(value, to_text_string)
try:
np_dtype = get_numpy_dtype(default_value)
if isinstance(default_value, bool):
# We must test for boolean before NumPy data types
# because `bool` class derives from `int` class
try:
value = bool(float(value))
except ValueError:
value = value.lower() == "true"
elif np_dtype is not None:
if 'complex' in str(type(default_value)):
value = np_dtype(complex(value))
else:
value = np_dtype(value)
elif is_binary_string(default_value):
value = to_binary_string(value, 'utf8')
elif is_text_string(default_value):
value = to_text_string(value)
elif isinstance(default_value, complex):
value = complex(value)
elif isinstance(default_value, float):
value = float(value)
elif isinstance(default_value, int):
try:
value = int(value)
except ValueError:
value = float(value)
elif isinstance(default_value, datetime.datetime):
value = datestr_to_datetime(value)
elif isinstance(default_value, datetime.date):
value = datestr_to_datetime(value).date()
elif ignore_errors:
value = try_to_eval(value)
else:
value = eval(value)
except (ValueError, SyntaxError):
if ignore_errors:
value = try_to_eval(value)
else:
return default_value
return value
开发者ID:MarvinLiu0810,项目名称:spyder,代码行数:45,代码来源:utils.py
示例10: __init__
def __init__(self, name, line, parent, preceding):
if preceding is None:
QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
else:
if preceding is not parent:
# Preceding must be either the same as item's parent
# or have the same parent as item
while preceding.parent() is not parent:
preceding = preceding.parent()
if preceding is None:
break
if preceding is None:
QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
else:
QTreeWidgetItem.__init__(self, parent, preceding, QTreeWidgetItem.Type)
self.setText(0, name)
parent_text = from_qvariant(parent.data(0, Qt.UserRole), to_text_string)
set_item_user_text(self, parent_text + "/" + name)
self.line = line
开发者ID:MarvinLiu0810,项目名称:spyder,代码行数:19,代码来源:editortools.py
示例11: save_to_conf
def save_to_conf(self):
"""Save settings to configuration file"""
for checkbox, (option, _default) in list(self.checkboxes.items()):
self.set_option(option, checkbox.isChecked())
for radiobutton, (option, _default) in list(self.radiobuttons.items()):
self.set_option(option, radiobutton.isChecked())
for lineedit, (option, _default) in list(self.lineedits.items()):
self.set_option(option, to_text_string(lineedit.text()))
for spinbox, (option, _default) in list(self.spinboxes.items()):
self.set_option(option, spinbox.value())
for combobox, (option, _default) in list(self.comboboxes.items()):
data = combobox.itemData(combobox.currentIndex())
self.set_option(option, from_qvariant(data, to_text_string))
for (fontbox, sizebox), option in list(self.fontboxes.items()):
font = fontbox.currentFont()
font.setPointSize(sizebox.value())
self.set_font(font, option)
for clayout, (option, _default) in list(self.coloredits.items()):
self.set_option(option, to_text_string(clayout.lineedit.text()))
for (clayout, cb_bold, cb_italic), (option, _default) in list(self.scedits.items()):
color = to_text_string(clayout.lineedit.text())
bold = cb_bold.isChecked()
italic = cb_italic.isChecked()
self.set_option(option, (color, bold, italic))
开发者ID:gyenney,项目名称:Tools,代码行数:24,代码来源:configdialog.py
示例12: delete_layout
def delete_layout(self):
""" """
names, order, active = self.names, self.order, self.order
name = from_qvariant(self.table.selectionModel().currentIndex().data(),
to_text_string)
if name in names:
index = names.index(name)
# In case nothing has focus in the table
if index != -1:
order.remove(name)
names[index] = None
if name in active:
active.remove(name)
self.names, self.order, self.active = names, order, active
self.table.model().set_data(order, active)
index = self.table.model().index(0, 0)
self.table.setCurrentIndex(index)
self.table.setFocus()
self.selection_changed(None, None)
if len(order) == 0:
self.button_move_up.setDisabled(True)
self.button_move_down.setDisabled(True)
self.button_delete.setDisabled(True)
开发者ID:ming-hai,项目名称:spyder,代码行数:24,代码来源:layoutdialog.py
示例13: setEditorData
def setEditorData(self, editor, index):
"""Set editor widget's data"""
text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
editor.setText(text)
开发者ID:da-woods,项目名称:spyder,代码行数:4,代码来源:arrayeditor.py
示例14: get_item_user_text
def get_item_user_text(item):
"""Get QTreeWidgetItem user role string"""
return from_qvariant(item.data(0, Qt.UserRole), to_text_string)
开发者ID:jromang,项目名称:spyderlib,代码行数:3,代码来源:qthelpers.py
示例15: keybinding
def keybinding(attr):
"""Return keybinding"""
ks = getattr(QKeySequence, attr)
return from_qvariant(QKeySequence.keyBindings(ks)[0], str)
开发者ID:jromang,项目名称:spyderlib,代码行数:4,代码来源:qthelpers.py
示例16: load_from_conf
def load_from_conf(self):
"""Load settings from configuration file"""
for checkbox, (option, default) in list(self.checkboxes.items()):
checkbox.setChecked(self.get_option(option, default))
# Checkboxes work differently for PySide and PyQt
if API == 'pyqt':
checkbox.clicked.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
else:
checkbox.clicked.connect(lambda opt=option:
self.has_been_modified(opt))
for radiobutton, (option, default) in list(self.radiobuttons.items()):
radiobutton.setChecked(self.get_option(option, default))
radiobutton.toggled.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
for lineedit, (option, default) in list(self.lineedits.items()):
lineedit.setText(self.get_option(option, default))
lineedit.textChanged.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
for spinbox, (option, default) in list(self.spinboxes.items()):
spinbox.setValue(self.get_option(option, default))
spinbox.valueChanged.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
for combobox, (option, default) in list(self.comboboxes.items()):
value = self.get_option(option, default)
for index in range(combobox.count()):
data = from_qvariant(combobox.itemData(index), to_text_string)
# For PyQt API v2, it is necessary to convert `data` to
# unicode in case the original type was not a string, like an
# integer for example (see spyderlib.qt.compat.from_qvariant):
if to_text_string(data) == to_text_string(value):
break
combobox.setCurrentIndex(index)
combobox.currentIndexChanged.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
if combobox.restart_required:
self.restart_options[option] = combobox.label_text
for (fontbox, sizebox), option in list(self.fontboxes.items()):
font = self.get_font(option)
fontbox.setCurrentFont(font)
sizebox.setValue(font.pointSize())
if option is None:
property = 'plugin_font'
else:
property = option
fontbox.currentIndexChanged.connect(lambda _foo, opt=property:
self.has_been_modified(opt))
sizebox.valueChanged.connect(lambda _foo, opt=property:
self.has_been_modified(opt))
for clayout, (option, default) in list(self.coloredits.items()):
property = to_qvariant(option)
edit = clayout.lineedit
btn = clayout.colorbtn
edit.setText(self.get_option(option, default))
btn.clicked.connect(lambda opt=option: self.has_been_modified(opt))
edit.textChanged.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
for (clayout, cb_bold, cb_italic
), (option, default) in list(self.scedits.items()):
edit = clayout.lineedit
btn = clayout.colorbtn
color, bold, italic = self.get_option(option, default)
edit.setText(color)
cb_bold.setChecked(bold)
cb_italic.setChecked(italic)
btn.clicked.connect(lambda opt=option: self.has_been_modified(opt))
edit.textChanged.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
if API == 'pyqt':
cb_bold.clicked.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
else:
cb_bold.clicked.connect(lambda opt=option:
self.has_been_modified(opt))
if API == 'pyqt':
cb_italic.clicked.connect(lambda _foo, opt=option:
self.has_been_modified(opt))
else:
cb_italic.clicked.connect(lambda opt=option:
self.has_been_modified(opt))
开发者ID:gyenney,项目名称:Tools,代码行数:81,代码来源:configdialog.py
示例17: load_from_conf
def load_from_conf(self):
"""Load settings from configuration file"""
for checkbox, (option, default) in list(self.checkboxes.items()):
checkbox.setChecked(self.get_option(option, default))
self.connect(checkbox, SIGNAL("clicked(bool)"),
lambda _foo, opt=option: self.has_been_modified(opt))
for radiobutton, (option, default) in list(self.radiobuttons.items()):
radiobutton.setChecked(self.get_option(option, default))
self.connect(radiobutton, SIGNAL("toggled(bool)"),
lambda _foo, opt=option: self.has_been_modified(opt))
for lineedit, (option, default) in list(self.lineedits.items()):
lineedit.setText(self.get_option(option, default))
self.connect(lineedit, SIGNAL("textChanged(QString)"),
lambda _foo, opt=option: self.has_been_modified(opt))
for spinbox, (option, default) in list(self.spinboxes.items()):
spinbox.setValue(self.get_option(option, default))
self.connect(spinbox, SIGNAL('valueChanged(int)'),
lambda _foo, opt=option: self.has_been_modified(opt))
for combobox, (option, default) in list(self.comboboxes.items()):
value = self.get_option(option, default)
for index in range(combobox.count()):
data = from_qvariant(combobox.itemData(index), to_text_string)
# For PyQt API v2, it is necessary to convert `data` to
# unicode in case the original type was not a string, like an
# integer for example (see spyderlib.qt.compat.from_qvariant):
if to_text_string(data) == to_text_string(value):
break
combobox.setCurrentIndex(index)
self.connect(combobox, SIGNAL('currentIndexChanged(int)'),
lambda _foo, opt=option: self.has_been_modified(opt))
for (fontbox, sizebox), option in list(self.fontboxes.items()):
font = self.get_font(option)
fontbox.setCurrentFont(font)
sizebox.setValue(font.pointSize())
if option is None:
property = 'plugin_font'
else:
property = option
self.connect(fontbox, SIGNAL('currentIndexChanged(int)'),
lambda _foo, opt=property: self.has_been_modified(opt))
self.connect(sizebox, SIGNAL('valueChanged(int)'),
lambda _foo, opt=property: self.has_been_modified(opt))
for clayout, (option, default) in list(self.coloredits.items()):
property = to_qvariant(option)
edit = clayout.lineedit
btn = clayout.colorbtn
edit.setText(self.get_option(option, default))
self.connect(btn, SIGNAL('clicked()'),
lambda opt=option: self.has_been_modified(opt))
self.connect(edit, SIGNAL("textChanged(QString)"),
lambda _foo, opt=option: self.has_been_modified(opt))
for (clayout, cb_bold, cb_italic
), (option, default) in list(self.scedits.items()):
edit = clayout.lineedit
btn = clayout.colorbtn
color, bold, italic = self.get_option(option, default)
edit.setText(color)
cb_bold.setChecked(bold)
cb_italic.setChecked(italic)
self.connect(btn, SIGNAL('clicked()'),
lambda opt=option: self.has_been_modified(opt))
self.connect(edit, SIGNAL("textChanged(QString)"),
lambda _foo, opt=option: self.has_been_modified(opt))
self.connect(cb_bold, SIGNAL("clicked(bool)"),
lambda _foo, opt=option: self.has_been_modified(opt))
self.connect(cb_italic, SIGNAL("clicked(bool)"),
lambda _foo, opt=option: self.has_been_modified(opt))
开发者ID:jromang,项目名称:spyderlib,代码行数:67,代码来源:configdialog.py
注:本文中的spyderlib.qt.compat.from_qvariant函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论