本文整理汇总了Python中spyderlib.qt.QtGui.QLabel.setText方法的典型用法代码示例。如果您正苦于以下问题:Python QLabel.setText方法的具体用法?Python QLabel.setText怎么用?Python QLabel.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QLabel
的用法示例。
在下文中一共展示了QLabel.setText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EncodingStatus
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class EncodingStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("Encoding:")))
self.encoding = QLabel()
self.encoding.setFont(self.label_font)
layout.addWidget(self.encoding)
layout.addSpacing(20)
def encoding_changed(self, encoding):
self.encoding.setText(str(encoding).upper().ljust(15))
示例2: EOLStatus
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class EOLStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("End-of-lines:")))
self.eol = QLabel()
self.eol.setFont(self.label_font)
layout.addWidget(self.eol)
layout.addSpacing(20)
def eol_changed(self, os_name):
os_name = to_text_string(os_name)
self.eol.setText({"nt": "CRLF", "posix": "LF"}.get(os_name, "CR"))
示例3: ReadWriteStatus
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class ReadWriteStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("Permissions:")))
self.readwrite = QLabel()
self.readwrite.setFont(self.label_font)
layout.addWidget(self.readwrite)
layout.addSpacing(20)
def readonly_changed(self, readonly):
readwrite = "R" if readonly else "RW"
self.readwrite.setText(readwrite.ljust(3))
示例4: FileExplorerTest
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class FileExplorerTest(QWidget):
def __init__(self):
QWidget.__init__(self)
vlayout = QVBoxLayout()
self.setLayout(vlayout)
self.explorer = ExplorerWidget(self, show_cd_only=None)
vlayout.addWidget(self.explorer)
hlayout1 = QHBoxLayout()
vlayout.addLayout(hlayout1)
label = QLabel("<b>Open file:</b>")
label.setAlignment(Qt.AlignRight)
hlayout1.addWidget(label)
self.label1 = QLabel()
hlayout1.addWidget(self.label1)
self.explorer.sig_open_file.connect(self.label1.setText)
hlayout2 = QHBoxLayout()
vlayout.addLayout(hlayout2)
label = QLabel("<b>Open dir:</b>")
label.setAlignment(Qt.AlignRight)
hlayout2.addWidget(label)
self.label2 = QLabel()
hlayout2.addWidget(self.label2)
self.explorer.open_dir.connect(self.label2.setText)
hlayout3 = QHBoxLayout()
vlayout.addLayout(hlayout3)
label = QLabel("<b>Option changed:</b>")
label.setAlignment(Qt.AlignRight)
hlayout3.addWidget(label)
self.label3 = QLabel()
hlayout3.addWidget(self.label3)
self.explorer.sig_option_changed.connect(lambda x, y: self.label3.setText("option_changed: %r, %r" % (x, y)))
self.explorer.open_dir.connect(lambda: self.explorer.treewidget.refresh(".."))
示例5: CursorPositionStatus
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class CursorPositionStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("Line:")))
self.line = QLabel()
self.line.setFont(self.label_font)
layout.addWidget(self.line)
layout.addWidget(QLabel(_("Column:")))
self.column = QLabel()
self.column.setFont(self.label_font)
layout.addWidget(self.column)
self.setLayout(layout)
def cursor_position_changed(self, line, index):
self.line.setText("%-6d" % (line+1))
self.column.setText("%-4d" % (index+1))
示例6: BaseTimerStatus
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class BaseTimerStatus(StatusBarWidget):
TITLE = None
TIP = None
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
self.setToolTip(self.TIP)
layout = self.layout()
layout.addWidget(QLabel(self.TITLE))
self.label = QLabel()
self.label.setFont(self.label_font)
layout.addWidget(self.label)
layout.addSpacing(20)
if self.is_supported():
self.timer = QTimer()
self.timer.timeout.connect(self.update_label)
self.timer.start(2000)
else:
self.timer = None
self.hide()
def set_interval(self, interval):
"""Set timer interval (ms)"""
if self.timer is not None:
self.timer.setInterval(interval)
def import_test(self):
"""Raise ImportError if feature is not supported"""
raise NotImplementedError
def is_supported(self):
"""Return True if feature is supported"""
try:
self.import_test()
return True
except ImportError:
return False
def get_value(self):
"""Return value (e.g. CPU or memory usage)"""
raise NotImplementedError
def update_label(self):
"""Update status label widget, if widget is visible"""
if self.isVisible():
self.label.setText('%d %%' % self.get_value())
示例7: ArrayEditor
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
#.........这里部分代码省略.........
# set the widget to display when launched
self.current_dim_changed(self.last_dim)
else:
ra_combo = QComboBox(self)
ra_combo.currentIndexChanged.connect(self.stack.setCurrentIndex)
ra_combo.addItems(names)
btn_layout.addWidget(ra_combo)
if is_masked_array:
label = QLabel(_("<u>Warning</u>: changes are applied separately"))
label.setToolTip(_("For performance reasons, changes applied "\
"to masked array won't be reflected in "\
"array's data (and vice-versa)."))
btn_layout.addWidget(label)
btn_layout.addStretch()
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
btn_layout.addWidget(bbox)
self.layout.addLayout(btn_layout, 2, 0)
self.setMinimumSize(400, 300)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
return True
def current_widget_changed(self, index):
self.arraywidget = self.stack.widget(index)
def change_active_widget(self, index):
"""
This is implemented for handling negative values in index for
3d arrays, to give the same behavior as slicing
"""
string_index = [':']*3
string_index[self.last_dim] = '<font color=red>%i</font>'
self.slicing_label.setText((r"Slicing: [" + ", ".join(string_index) +
"]") % index)
if index < 0:
data_index = self.data.shape[self.last_dim] + index
else:
data_index = index
slice_index = [slice(None)]*3
slice_index[self.last_dim] = data_index
stack_index = self.dim_indexes[self.last_dim].get(data_index)
if stack_index == None:
stack_index = self.stack.count()
self.stack.addWidget(ArrayEditorWidget(self,
self.data[slice_index]))
self.dim_indexes[self.last_dim][data_index] = stack_index
self.stack.update()
self.stack.setCurrentIndex(stack_index)
def current_dim_changed(self, index):
"""
This change the active axis the array editor is plotting over
in 3D
"""
self.last_dim = index
string_size = ['%i']*3
string_size[index] = '<font color=red>%i</font>'
self.shape_label.setText(('Shape: (' + ', '.join(string_size) +
') ') % self.data.shape)
if self.index_spin.value() != 0:
self.index_spin.setValue(0)
else:
# this is done since if the value is currently 0 it does not emit
# currentIndexChanged(int)
self.change_active_widget(0)
self.index_spin.setRange(-self.data.shape[index],
self.data.shape[index]-1)
@Slot()
def accept(self):
"""Reimplement Qt method"""
for index in range(self.stack.count()):
self.stack.widget(index).accept_changes()
QDialog.accept(self)
def get_value(self):
"""Return modified array -- this is *not* a copy"""
# 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.data
def error(self, message):
"""An error occured, closing the dialog box"""
QMessageBox.critical(self, _("Array editor"), message)
self.setAttribute(Qt.WA_DeleteOnClose)
self.reject()
@Slot()
def reject(self):
"""Reimplement Qt method"""
if self.arraywidget is not None:
for index in range(self.stack.count()):
self.stack.widget(index).reject_changes()
QDialog.reject(self)
示例8: FadingTipBox
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
#.........这里部分代码省略.........
self.setLayout(layout)
self.set_funcs_before_fade_in([self._disable_widgets])
self.set_funcs_after_fade_in([self._enable_widgets])
self.set_funcs_before_fade_out([self._disable_widgets])
self.setContextMenuPolicy(Qt.CustomContextMenu)
# signals and slots
# These are defined every time by the AnimatedTour Class
def _disable_widgets(self):
""" """
for widget in self.widgets:
widget.setDisabled(True)
def _enable_widgets(self):
""" """
self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint |
Qt.WindowStaysOnTopHint)
for widget in self.widgets:
widget.setDisabled(False)
if self.button_disable == 'previous':
self.button_previous.setDisabled(True)
self.button_home.setDisabled(True)
elif self.button_disable == 'next':
self.button_next.setDisabled(True)
self.button_end.setDisabled(True)
def set_data(self, title, content, current, image, run, frames=None,
step=None):
""" """
self.label_title.setText(title)
self.combo_title.clear()
self.combo_title.addItems(frames)
self.combo_title.setCurrentIndex(step)
# min_content_len = max([len(f) for f in frames])
# self.combo_title.setMinimumContentsLength(min_content_len)
# Fix and try to see how it looks with a combo box
self.label_current.setText(current)
self.button_current.setText(current)
self.label_content.setText(content)
self.image = image
if image is None:
self.label_image.setFixedHeight(1)
self.label_image.setFixedWidth(1)
else:
extension = image.split('.')[-1]
self.image = QPixmap(get_image_path(image), extension)
self.label_image.setPixmap(self.image)
self.label_image.setFixedSize(self.image.size())
if run is None:
self.button_run.setVisible(False)
else:
self.button_run.setDisabled(False)
self.button_run.setVisible(True)
# Refresh layout
self.layout().activate()
def set_pos(self, x, y):
""" """
示例9: ShortcutEditor
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class ShortcutEditor(QDialog):
"""A dialog for entering key sequences."""
def __init__(self, parent, context, name, sequence, shortcuts):
super(ShortcutEditor, self).__init__(parent)
self._parent = parent
self.context = context
self.npressed = 0
self.keys = set()
self.key_modifiers = set()
self.key_non_modifiers = list()
self.key_text = list()
self.sequence = sequence
self.new_sequence = None
self.edit_state = True
self.shortcuts = shortcuts
# Widgets
self.label_info = QLabel()
self.label_info.setText(_("Press the new shortcut and select 'Ok': \n"
"(Press 'Tab' once to switch focus between the shortcut entry \n"
"and the buttons below it)"))
self.label_current_sequence = QLabel(_("Current shortcut:"))
self.text_current_sequence = QLabel(sequence)
self.label_new_sequence = QLabel(_("New shortcut:"))
self.text_new_sequence = CustomLineEdit(self)
self.text_new_sequence.setPlaceholderText(sequence)
self.helper_button = HelperToolButton()
self.helper_button.hide()
self.label_warning = QLabel()
self.label_warning.hide()
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.button_ok = bbox.button(QDialogButtonBox.Ok)
self.button_cancel = bbox.button(QDialogButtonBox.Cancel)
# Setup widgets
self.setWindowTitle(_('Shortcut: {0}').format(name))
self.button_ok.setFocusPolicy(Qt.NoFocus)
self.button_ok.setEnabled(False)
self.button_cancel.setFocusPolicy(Qt.NoFocus)
self.helper_button.setToolTip('')
self.helper_button.setFocusPolicy(Qt.NoFocus)
style = """
QToolButton {
margin:1px;
border: 0px solid grey;
padding:0px;
border-radius: 0px;
}"""
self.helper_button.setStyleSheet(style)
self.text_new_sequence.setFocusPolicy(Qt.NoFocus)
self.label_warning.setFocusPolicy(Qt.NoFocus)
# Layout
spacing = 5
layout_sequence = QGridLayout()
layout_sequence.addWidget(self.label_info, 0, 0, 1, 3)
layout_sequence.addItem(QSpacerItem(spacing, spacing), 1, 0, 1, 2)
layout_sequence.addWidget(self.label_current_sequence, 2, 0)
layout_sequence.addWidget(self.text_current_sequence, 2, 2)
layout_sequence.addWidget(self.label_new_sequence, 3, 0)
layout_sequence.addWidget(self.helper_button, 3, 1)
layout_sequence.addWidget(self.text_new_sequence, 3, 2)
layout_sequence.addWidget(self.label_warning, 4, 2, 1, 2)
layout = QVBoxLayout()
layout.addLayout(layout_sequence)
layout.addSpacing(spacing)
layout.addWidget(bbox)
self.setLayout(layout)
# Signals
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
def keyPressEvent(self, e):
"""Qt override."""
key = e.key()
# Check if valid keys
if key not in VALID_KEYS:
self.invalid_key_flag = True
return
self.npressed += 1
self.key_non_modifiers.append(key)
self.key_modifiers.add(key)
self.key_text.append(e.text())
self.invalid_key_flag = False
debug_print('key {0}, npressed: {1}'.format(key, self.npressed))
if key == Qt.Key_unknown:
return
# The user clicked just and only the special keys
# Ctrl, Shift, Alt, Meta.
if (key == Qt.Key_Control or
key == Qt.Key_Shift or
key == Qt.Key_Alt or
#.........这里部分代码省略.........
示例10: ExternalShellBase
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
#.........这里部分代码省略.........
for widget in self.get_toolbar_buttons():
if state:
widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
else:
widget.setToolButtonStyle(Qt.ToolButtonIconOnly)
def get_options_menu(self):
self.show_time_action = create_action(self, _("Show elapsed time"), toggled=self.set_elapsed_time_visible)
self.show_time_action.setChecked(self.show_elapsed_time)
actions = [self.show_time_action]
if self.menu_actions is not None:
actions += [None] + self.menu_actions
return actions
def get_shell_widget(self):
return self.shell
def get_icon(self):
raise NotImplementedError
def show_time(self, end=False):
if self.time_label is None:
return
elapsed_time = time() - self.t0
if elapsed_time > 24 * 3600: # More than a day...!
format = "%d %H:%M:%S"
else:
format = "%H:%M:%S"
if end:
color = "#AAAAAA"
else:
color = "#AA6655"
text = "<span style='color: %s'><b>%s" "</b></span>" % (color, strftime(format, gmtime(elapsed_time)))
self.time_label.setText(text)
def closeEvent(self, event):
if self.process is not None:
self.is_closing = True
self.process.kill()
self.process.waitForFinished(100)
try:
self.timer.timeout.disconnect(self.show_time)
except (RuntimeError, TypeError):
pass
def set_running_state(self, state=True):
self.set_buttons_runnning_state(state)
self.shell.setReadOnly(not state)
if state:
if self.state_label is not None:
self.state_label.setText(_("<span style='color: #44AA44'><b>Running...</b></span>"))
self.t0 = time()
self.timer.timeout.connect(self.show_time)
self.timer.start(1000)
else:
if self.state_label is not None:
self.state_label.setText(_("Terminated."))
try:
self.timer.timeout.disconnect(self.show_time)
except (RuntimeError, TypeError):
pass
def set_buttons_runnning_state(self, state):
self.run_button.setVisible(not state and not self.is_ipykernel)
self.kill_button.setVisible(state)
示例11: ProfilerWidget
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class ProfilerWidget(QWidget):
"""
Profiler widget
"""
DATAPATH = get_conf_path('profiler.results')
VERSION = '0.0.1'
def __init__(self, parent, max_entries=100):
QWidget.__init__(self, parent)
self.setWindowTitle("Profiler")
self.output = None
self.error_output = None
self._last_wdir = None
self._last_args = None
self._last_pythonpath = None
self.filecombo = PythonModulesComboBox(self)
self.start_button = create_toolbutton(self, icon=get_icon('run.png'),
text=_("Profile"),
tip=_("Run profiler"),
triggered=self.start, text_beside_icon=True)
self.stop_button = create_toolbutton(self,
icon=get_icon('terminate.png'),
text=_("Stop"),
tip=_(
"Stop current profiling"),
text_beside_icon=True)
self.connect(self.filecombo, SIGNAL('valid(bool)'),
self.start_button.setEnabled)
#self.connect(self.filecombo, SIGNAL('valid(bool)'), self.show_data)
# FIXME: The combobox emits this signal on almost any event
# triggering show_data() too early, too often.
browse_button = create_toolbutton(self, icon=get_icon('fileopen.png'),
tip=_('Select Python script'),
triggered=self.select_file)
self.datelabel = QLabel()
self.log_button = create_toolbutton(self, icon=get_icon('log.png'),
text=_("Output"),
text_beside_icon=True,
tip=_("Show program's output"),
triggered=self.show_log)
self.datatree = ProfilerDataTree(self)
self.collapse_button = create_toolbutton(self,
icon=get_icon('collapse.png'),
triggered=lambda dD=-1:
self.datatree.change_view(dD),
tip=_('Collapse one level up'))
self.expand_button = create_toolbutton(self,
icon=get_icon('expand.png'),
triggered=lambda dD=1:
self.datatree.change_view(dD),
tip=_('Expand one level down'))
hlayout1 = QHBoxLayout()
hlayout1.addWidget(self.filecombo)
hlayout1.addWidget(browse_button)
hlayout1.addWidget(self.start_button)
hlayout1.addWidget(self.stop_button)
hlayout2 = QHBoxLayout()
hlayout2.addWidget(self.collapse_button)
hlayout2.addWidget(self.expand_button)
hlayout2.addStretch()
hlayout2.addWidget(self.datelabel)
hlayout2.addStretch()
hlayout2.addWidget(self.log_button)
layout = QVBoxLayout()
layout.addLayout(hlayout1)
layout.addLayout(hlayout2)
layout.addWidget(self.datatree)
self.setLayout(layout)
self.process = None
self.set_running_state(False)
self.start_button.setEnabled(False)
if not is_profiler_installed():
# This should happen only on certain GNU/Linux distributions
# or when this a home-made Python build because the Python
# profilers are included in the Python standard library
for widget in (self.datatree, self.filecombo,
self.start_button, self.stop_button):
widget.setDisabled(True)
url = 'http://docs.python.org/library/profile.html'
text = '%s <a href=%s>%s</a>' % (_('Please install'), url,
_("the Python profiler modules"))
self.datelabel.setText(text)
else:
pass # self.show_data()
#.........这里部分代码省略.........
示例12: PylintWidget
# 需要导入模块: from spyderlib.qt.QtGui import QLabel [as 别名]
# 或者: from spyderlib.qt.QtGui.QLabel import setText [as 别名]
class PylintWidget(QWidget):
"""
Pylint widget
"""
DATAPATH = get_conf_path('pylint.results')
VERSION = '1.1.0'
redirect_stdio = Signal(bool)
def __init__(self, parent, max_entries=100):
QWidget.__init__(self, parent)
self.setWindowTitle("Pylint")
self.output = None
self.error_output = None
self.max_entries = max_entries
self.rdata = []
if osp.isfile(self.DATAPATH):
try:
data = pickle.loads(open(self.DATAPATH, 'rb').read())
if data[0] == self.VERSION:
self.rdata = data[1:]
except (EOFError, ImportError):
pass
self.filecombo = PythonModulesComboBox(self)
if self.rdata:
self.remove_obsolete_items()
self.filecombo.addItems(self.get_filenames())
self.start_button = create_toolbutton(self, icon=ima.icon('run'),
text=_("Analyze"),
tip=_("Run analysis"),
triggered=self.start, text_beside_icon=True)
self.stop_button = create_toolbutton(self,
icon=ima.icon('stop'),
text=_("Stop"),
tip=_("Stop current analysis"),
text_beside_icon=True)
self.filecombo.valid.connect(self.start_button.setEnabled)
self.filecombo.valid.connect(self.show_data)
browse_button = create_toolbutton(self, icon=ima.icon('fileopen'),
tip=_('Select Python file'),
triggered=self.select_file)
self.ratelabel = QLabel()
self.datelabel = QLabel()
self.log_button = create_toolbutton(self, icon=ima.icon('log'),
text=_("Output"),
text_beside_icon=True,
tip=_("Complete output"),
triggered=self.show_log)
self.treewidget = ResultsTree(self)
hlayout1 = QHBoxLayout()
hlayout1.addWidget(self.filecombo)
hlayout1.addWidget(browse_button)
hlayout1.addWidget(self.start_button)
hlayout1.addWidget(self.stop_button)
hlayout2 = QHBoxLayout()
hlayout2.addWidget(self.ratelabel)
hlayout2.addStretch()
hlayout2.addWidget(self.datelabel)
hlayout2.addStretch()
hlayout2.addWidget(self.log_button)
layout = QVBoxLayout()
layout.addLayout(hlayout1)
layout.addLayout(hlayout2)
layout.addWidget(self.treewidget)
self.setLayout(layout)
self.process = None
self.set_running_state(False)
if PYLINT_PATH is None:
for widget in (self.treewidget, self.filecombo,
self.start_button, self.stop_button):
widget.setDisabled(True)
if os.name == 'nt' \
and programs.is_module_installed("pylint"):
# Pylint is installed but pylint script is not in PATH
# (AFAIK, could happen only on Windows)
text = _('Pylint script was not found. Please add "%s" to PATH.')
text = to_text_string(text) % osp.join(sys.prefix, "Scripts")
else:
text = _('Please install <b>pylint</b>:')
url = 'http://www.logilab.fr'
text += ' <a href=%s>%s</a>' % (url, url)
self.ratelabel.setText(text)
else:
self.show_data()
def analyze(self, filename):
if PYLINT_PATH is None:
return
filename = to_text_string(filename) # filename is a QString instance
#.........这里部分代码省略.........