本文整理汇总了Python中spyderlib.qt.QtGui.QTextEdit类的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit类的具体用法?Python QTextEdit怎么用?Python QTextEdit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextEdit类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent=None):
QTextEdit.__init__(self, parent)
BaseEditMixin.__init__(self)
TracebackLinksMixin.__init__(self)
InspectObjectMixin.__init__(self)
self.found_results = []
self.calltip_widget = CallTipWidget(self, hide_timer_on=True)
# To not use Spyder calltips obtained through the monitor
self.calltips = False
示例2: keyPressEvent
def keyPressEvent(self, event):
"""Reimplement Qt Method - Basic keypress event handler"""
event, text, key, ctrl, shift = restore_keyevent(event)
if key == Qt.Key_Question and not self.has_selected_text():
self._key_question(text)
elif key == Qt.Key_ParenLeft and not self.has_selected_text():
self._key_question(text)
else:
# Let the parent widget handle the key press event
QTextEdit.keyPressEvent(self, event)
示例3: TextEditor
class TextEditor(QDialog):
"""Array Editor Dialog"""
def __init__(self, text, title='', font=None, parent=None,
readonly=False, size=(400, 300)):
QDialog.__init__(self, parent)
# Destroying the C++ object right after closing the dialog box,
# otherwise it may be garbage-collected in another QThread
# (e.g. the editor's analysis thread in Spyder), thus leading to
# a segmentation fault on UNIX or an application crash on Windows
self.setAttribute(Qt.WA_DeleteOnClose)
self.text = None
self._conv = str if isinstance(text, str) else to_text_string
self.layout = QVBoxLayout()
self.setLayout(self.layout)
# Text edit
self.edit = QTextEdit(parent)
self.connect(self.edit, SIGNAL('textChanged()'), self.text_changed)
self.edit.setReadOnly(readonly)
self.edit.setPlainText(text)
if font is None:
font = get_font('texteditor')
self.edit.setFont(font)
self.layout.addWidget(self.edit)
# Buttons configuration
buttons = QDialogButtonBox.Ok
if not readonly:
buttons = buttons | QDialogButtonBox.Cancel
bbox = QDialogButtonBox(buttons)
self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
self.layout.addWidget(bbox)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
self.setWindowIcon(get_icon('edit.png'))
self.setWindowTitle(_("Text editor") + \
"%s" % (" - "+str(title) if str(title) else ""))
self.resize(size[0], size[1])
def text_changed(self):
"""Text has changed"""
self.text = self._conv(self.edit.toPlainText())
def get_value(self):
"""Return modified text"""
# It is import to avoid accessing Qt C++ object as it has probably
# already been destroyed, due to the Qt.WA_DeleteOnClose attribute
return self.text
示例4: __init__
def __init__(self, text, title='', font=None, parent=None,
readonly=False, size=(400, 300)):
QDialog.__init__(self, parent)
# Destroying the C++ object right after closing the dialog box,
# otherwise it may be garbage-collected in another QThread
# (e.g. the editor's analysis thread in Spyder), thus leading to
# a segmentation fault on UNIX or an application crash on Windows
self.setAttribute(Qt.WA_DeleteOnClose)
self.text = None
# Display text as unicode if it comes as bytes, so users see
# its right representation
if is_binary_string(text):
self.is_binary = True
text = to_text_string(text, 'utf8')
else:
self.is_binary = False
self.layout = QVBoxLayout()
self.setLayout(self.layout)
# Text edit
self.edit = QTextEdit(parent)
self.edit.textChanged.connect(self.text_changed)
self.edit.setReadOnly(readonly)
self.edit.setPlainText(text)
if font is None:
font = get_font()
self.edit.setFont(font)
self.layout.addWidget(self.edit)
# Buttons configuration
buttons = QDialogButtonBox.Ok
if not readonly:
buttons = buttons | QDialogButtonBox.Cancel
bbox = QDialogButtonBox(buttons)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
self.layout.addWidget(bbox)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
self.setWindowIcon(ima.icon('edit'))
self.setWindowTitle(_("Text editor") + \
"%s" % (" - "+str(title) if str(title) else ""))
self.resize(size[0], size[1])
示例5: __init__
def __init__(self, parent=None):
QTextEdit.__init__(self, parent)
BaseEditMixin.__init__(self)
self.found_results = []
示例6: __init__
def __init__(self, parent, text):
QWidget.__init__(self, parent)
self.text_editor = QTextEdit(self)
self.text_editor.setText(text)
self.text_editor.setReadOnly(True)
# Type frame
type_layout = QHBoxLayout()
type_label = QLabel(_("Import as"))
type_layout.addWidget(type_label)
data_btn = QRadioButton(_("data"))
data_btn.setChecked(True)
self._as_data = True
type_layout.addWidget(data_btn)
code_btn = QRadioButton(_("code"))
self._as_code = False
type_layout.addWidget(code_btn)
txt_btn = QRadioButton(_("text"))
type_layout.addWidget(txt_btn)
h_spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
type_layout.addItem(h_spacer)
type_frame = QFrame()
type_frame.setLayout(type_layout)
# Opts frame
grid_layout = QGridLayout()
grid_layout.setSpacing(0)
col_label = QLabel(_("Column separator:"))
grid_layout.addWidget(col_label, 0, 0)
col_w = QWidget()
col_btn_layout = QHBoxLayout()
self.tab_btn = QRadioButton(_("Tab"))
self.tab_btn.setChecked(False)
col_btn_layout.addWidget(self.tab_btn)
other_btn_col = QRadioButton(_("other"))
other_btn_col.setChecked(True)
col_btn_layout.addWidget(other_btn_col)
col_w.setLayout(col_btn_layout)
grid_layout.addWidget(col_w, 0, 1)
self.line_edt = QLineEdit(",")
self.line_edt.setMaximumWidth(30)
self.line_edt.setEnabled(True)
other_btn_col.toggled.connect(self.line_edt.setEnabled)
grid_layout.addWidget(self.line_edt, 0, 2)
row_label = QLabel(_("Row separator:"))
grid_layout.addWidget(row_label, 1, 0)
row_w = QWidget()
row_btn_layout = QHBoxLayout()
self.eol_btn = QRadioButton(_("EOL"))
self.eol_btn.setChecked(True)
row_btn_layout.addWidget(self.eol_btn)
other_btn_row = QRadioButton(_("other"))
row_btn_layout.addWidget(other_btn_row)
row_w.setLayout(row_btn_layout)
grid_layout.addWidget(row_w, 1, 1)
self.line_edt_row = QLineEdit(";")
self.line_edt_row.setMaximumWidth(30)
self.line_edt_row.setEnabled(False)
other_btn_row.toggled.connect(self.line_edt_row.setEnabled)
grid_layout.addWidget(self.line_edt_row, 1, 2)
grid_layout.setRowMinimumHeight(2, 15)
other_group = QGroupBox(_("Additional options"))
other_layout = QGridLayout()
other_group.setLayout(other_layout)
skiprows_label = QLabel(_("Skip rows:"))
other_layout.addWidget(skiprows_label, 0, 0)
self.skiprows_edt = QLineEdit("0")
self.skiprows_edt.setMaximumWidth(30)
intvalid = QIntValidator(0, len(to_text_string(text).splitlines()), self.skiprows_edt)
self.skiprows_edt.setValidator(intvalid)
other_layout.addWidget(self.skiprows_edt, 0, 1)
other_layout.setColumnMinimumWidth(2, 5)
comments_label = QLabel(_("Comments:"))
other_layout.addWidget(comments_label, 0, 3)
self.comments_edt = QLineEdit("#")
self.comments_edt.setMaximumWidth(30)
other_layout.addWidget(self.comments_edt, 0, 4)
self.trnsp_box = QCheckBox(_("Transpose"))
# self.trnsp_box.setEnabled(False)
other_layout.addWidget(self.trnsp_box, 1, 0, 2, 0)
grid_layout.addWidget(other_group, 3, 0, 2, 0)
opts_frame = QFrame()
opts_frame.setLayout(grid_layout)
data_btn.toggled.connect(opts_frame.setEnabled)
data_btn.toggled.connect(self.set_as_data)
code_btn.toggled.connect(self.set_as_code)
# self.connect(txt_btn, SIGNAL("toggled(bool)"),
#.........这里部分代码省略.........
示例7: ContentsWidget
class ContentsWidget(QWidget):
"""Import wizard contents widget"""
asDataChanged = Signal(bool)
def __init__(self, parent, text):
QWidget.__init__(self, parent)
self.text_editor = QTextEdit(self)
self.text_editor.setText(text)
self.text_editor.setReadOnly(True)
# Type frame
type_layout = QHBoxLayout()
type_label = QLabel(_("Import as"))
type_layout.addWidget(type_label)
data_btn = QRadioButton(_("data"))
data_btn.setChecked(True)
self._as_data = True
type_layout.addWidget(data_btn)
code_btn = QRadioButton(_("code"))
self._as_code = False
type_layout.addWidget(code_btn)
txt_btn = QRadioButton(_("text"))
type_layout.addWidget(txt_btn)
h_spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
type_layout.addItem(h_spacer)
type_frame = QFrame()
type_frame.setLayout(type_layout)
# Opts frame
grid_layout = QGridLayout()
grid_layout.setSpacing(0)
col_label = QLabel(_("Column separator:"))
grid_layout.addWidget(col_label, 0, 0)
col_w = QWidget()
col_btn_layout = QHBoxLayout()
self.tab_btn = QRadioButton(_("Tab"))
self.tab_btn.setChecked(False)
col_btn_layout.addWidget(self.tab_btn)
other_btn_col = QRadioButton(_("other"))
other_btn_col.setChecked(True)
col_btn_layout.addWidget(other_btn_col)
col_w.setLayout(col_btn_layout)
grid_layout.addWidget(col_w, 0, 1)
self.line_edt = QLineEdit(",")
self.line_edt.setMaximumWidth(30)
self.line_edt.setEnabled(True)
other_btn_col.toggled.connect(self.line_edt.setEnabled)
grid_layout.addWidget(self.line_edt, 0, 2)
row_label = QLabel(_("Row separator:"))
grid_layout.addWidget(row_label, 1, 0)
row_w = QWidget()
row_btn_layout = QHBoxLayout()
self.eol_btn = QRadioButton(_("EOL"))
self.eol_btn.setChecked(True)
row_btn_layout.addWidget(self.eol_btn)
other_btn_row = QRadioButton(_("other"))
row_btn_layout.addWidget(other_btn_row)
row_w.setLayout(row_btn_layout)
grid_layout.addWidget(row_w, 1, 1)
self.line_edt_row = QLineEdit(";")
self.line_edt_row.setMaximumWidth(30)
self.line_edt_row.setEnabled(False)
other_btn_row.toggled.connect(self.line_edt_row.setEnabled)
grid_layout.addWidget(self.line_edt_row, 1, 2)
grid_layout.setRowMinimumHeight(2, 15)
other_group = QGroupBox(_("Additional options"))
other_layout = QGridLayout()
other_group.setLayout(other_layout)
skiprows_label = QLabel(_("Skip rows:"))
other_layout.addWidget(skiprows_label, 0, 0)
self.skiprows_edt = QLineEdit("0")
self.skiprows_edt.setMaximumWidth(30)
intvalid = QIntValidator(0, len(to_text_string(text).splitlines()), self.skiprows_edt)
self.skiprows_edt.setValidator(intvalid)
other_layout.addWidget(self.skiprows_edt, 0, 1)
other_layout.setColumnMinimumWidth(2, 5)
comments_label = QLabel(_("Comments:"))
other_layout.addWidget(comments_label, 0, 3)
self.comments_edt = QLineEdit("#")
self.comments_edt.setMaximumWidth(30)
other_layout.addWidget(self.comments_edt, 0, 4)
self.trnsp_box = QCheckBox(_("Transpose"))
# self.trnsp_box.setEnabled(False)
other_layout.addWidget(self.trnsp_box, 1, 0, 2, 0)
grid_layout.addWidget(other_group, 3, 0, 2, 0)
opts_frame = QFrame()
opts_frame.setLayout(grid_layout)
#.........这里部分代码省略.........
示例8: setup
def setup(self):
for label, value in self.data:
if DEBUG_FORMLAYOUT:
print("value:", value)
if label is None and value is None:
# Separator: (None, None)
self.formlayout.addRow(QLabel(" "), QLabel(" "))
self.widgets.append(None)
continue
elif label is None:
# Comment
self.formlayout.addRow(QLabel(value))
self.widgets.append(None)
continue
elif is_text_string(value):
if '\n' in value:
for linesep in (os.linesep, '\n'):
if linesep in value:
value = value.replace(linesep, u("\u2029"))
field = QTextEdit(value, self)
else:
field = QLineEdit(value, self)
elif isinstance(value, (list, tuple)):
value = list(value) # in case this is a tuple
selindex = value.pop(0)
field = QComboBox(self)
if isinstance(value[0], (list, tuple)):
keys = [key for key, _val in value]
value = [val for _key, val in value]
else:
keys = value
field.addItems(value)
if selindex in value:
selindex = value.index(selindex)
elif selindex in keys:
selindex = keys.index(selindex)
elif not isinstance(selindex, int):
print("Warning: '%s' index is invalid (label: " \
"%s, value: %s)" % (selindex, label, value),
file=STDERR)
selindex = 0
field.setCurrentIndex(selindex)
elif isinstance(value, bool):
field = QCheckBox(self)
field.setCheckState(Qt.Checked if value else Qt.Unchecked)
elif isinstance(value, QLabel):
field = QCheckBox(self)
field.setCheckState(Qt.Checked if value.text() else Qt.Unchecked)
elif isinstance(value, float):
field = QLineEdit(repr(value), self)
field.setValidator(QDoubleValidator(field))
dialog = self.get_dialog()
dialog.register_float_field(field)
self.connect(field, SIGNAL('textChanged(QString)'),
lambda text: dialog.update_buttons())
elif isinstance(value, int):
field = QSpinBox(self)
field.setRange(-1e9, 1e9)
field.setValue(value)
elif isinstance(value, datetime.datetime):
field = QDateTimeEdit(self)
field.setDateTime(value)
elif isinstance(value, datetime.date):
field = QDateEdit(self)
field.setDate(value)
else:
field = QLineEdit(repr(value), self)
self.formlayout.addRow(label, field)
self.widgets.append(field)