本文整理汇总了Python中PyQt5.Qt.QListWidget.setObjectName方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.setObjectName方法的具体用法?Python QListWidget.setObjectName怎么用?Python QListWidget.setObjectName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QListWidget
的用法示例。
在下文中一共展示了QListWidget.setObjectName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpyQWidget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import setObjectName [as 别名]
class SpyQWidget(QWidget):
"""
Class who create QWidget for spied hosts
"""
def __init__(self):
super(SpyQWidget, self).__init__()
self.host_services_lbl = QLabel(_('You are not spying on any hosts for now...'))
self.spy_list_widget = SpyQListWidget()
self.host_list_widget = QListWidget()
self.spy_timer = QTimer()
def initialize(self):
"""
Intialize Spy QWidget
"""
layout = QGridLayout()
self.setLayout(layout)
spy_icon = QLabel()
spy_pixmap = QPixmap(settings.get_image('spy'))
spy_icon.setPixmap(spy_pixmap)
spy_icon.setScaledContents(True)
spy_icon.setFixedSize(20, 20)
layout.addWidget(spy_icon, 0, 0, 1, 1)
layout.setAlignment(spy_icon, Qt.AlignRight)
spy_title = QLabel(_('Spy Hosts'))
spy_title.setObjectName('title')
spy_title.setMinimumHeight(40)
layout.addWidget(spy_title, 0, 1, 1, 1)
hint_lbl = QLabel('Click to refresh, double-click to stop spying')
hint_lbl.setObjectName('subtitle')
layout.addWidget(hint_lbl, 1, 0, 1, 1)
layout.setAlignment(hint_lbl, Qt.AlignCenter)
self.host_services_lbl.setObjectName('subtitle')
layout.addWidget(self.host_services_lbl, 1, 1, 1, 1)
layout.setAlignment(self.host_services_lbl, Qt.AlignCenter)
self.spy_list_widget.setDragDropMode(QAbstractItemView.DragDrop)
self.spy_list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.spy_list_widget.doubleClicked.connect(self.remove_event)
self.spy_list_widget.setAcceptDrops(True)
self.spy_list_widget.setWordWrap(True)
self.spy_list_widget.insertItem(0, self.get_hint_item())
self.spy_list_widget.item_dropped.connect(get_events_widget().remove_event)
self.spy_list_widget.clicked.connect(
lambda: self.manage_host_events(self.spy_list_widget.currentRow())
)
layout.addWidget(self.spy_list_widget, 2, 0, 1, 1)
self.host_list_widget.setObjectName('spy')
# self.host_list_widget.setMinimumWidth(500)
layout.addWidget(self.host_list_widget, 2, 1, 1, 1)
spy_interval = int(settings.get_config('Alignak-app', 'spy_interval')) * 1000
self.spy_timer.setInterval(spy_interval)
self.spy_timer.start()
self.spy_timer.timeout.connect(self.send_spy_events)
@staticmethod
def get_hint_item():
"""
Return an EventItem with a hint text
:return: event item with hint text
:rtype: EventItem
"""
drop_hint_item = EventItem()
drop_hint_item.setText(_('Drop host-related events here to spy on it...'))
drop_hint_item.setIcon(QIcon(settings.get_image('spy')))
drop_hint_item.setFlags(Qt.ItemIsDropEnabled)
return drop_hint_item
def send_spy_events(self):
"""
Send event messages for all hosts who are spied
"""
if self.spy_list_widget.spied_hosts:
for host_id in self.spy_list_widget.spied_hosts:
host = data_manager.get_item('host', host_id)
get_events_widget().add_event(
EventItem.get_event_type(host.data),
_('Host %s, current state: %s') % (
host.get_display_name(), host.data['ls_state']),
host=host.item_id
)
def manage_host_events(self, row):
"""
Manage spy events for a host, defined by current row of "spy_list_widget"
#.........这里部分代码省略.........
示例2: PluginWidget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import setObjectName [as 别名]
class PluginWidget(QWidget):
TITLE = _('CSV/XML options')
HELP = _('Options specific to')+' CSV/XML '+_('output')
sync_enabled = False
formats = {'csv', 'xml'}
handles_scrolling = True
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QVBoxLayout(self)
self.la = la = QLabel(_('Fields to include in output:'))
la.setWordWrap(True)
l.addWidget(la)
self.db_fields = QListWidget(self)
l.addWidget(self.db_fields)
self.la2 = la = QLabel(_('Drag and drop to re-arrange fields'))
l.addWidget(la)
self.db_fields.setDragEnabled(True)
self.db_fields.setDragDropMode(QListWidget.InternalMove)
self.db_fields.setDefaultDropAction(Qt.MoveAction)
self.db_fields.setAlternatingRowColors(True)
self.db_fields.setObjectName("db_fields")
def initialize(self, catalog_name, db):
self.name = catalog_name
from calibre.library.catalogs import FIELDS
db = get_gui().current_db
self.all_fields = {x for x in FIELDS if x != 'all'} | set(db.custom_field_keys())
sort_order, fields = get_saved_field_data(self.name, self.all_fields)
fm = db.field_metadata
def name(x):
if x == 'isbn':
return 'ISBN'
if x == 'library_name':
return _('Library name')
if x.endswith('_index'):
return name(x[:-len('_index')]) + ' ' + _('Number')
return fm[x].get('name') or x
def key(x):
return (sort_order.get(x, 10000), name(x))
self.db_fields.clear()
for x in sorted(self.all_fields, key=key):
QListWidgetItem(name(x) + ' (%s)' % x, self.db_fields).setData(Qt.UserRole, x)
if x.startswith('#') and fm[x]['datatype'] == 'series':
x += '_index'
QListWidgetItem(name(x) + ' (%s)' % x, self.db_fields).setData(Qt.UserRole, x)
# Restore the activated fields from last use
for x in range(self.db_fields.count()):
item = self.db_fields.item(x)
item.setCheckState(Qt.Checked if unicode_type(item.data(Qt.UserRole)) in fields else Qt.Unchecked)
def options(self):
# Save the currently activated fields
fields, all_fields = [], []
for x in range(self.db_fields.count()):
item = self.db_fields.item(x)
all_fields.append(unicode_type(item.data(Qt.UserRole)))
if item.checkState() == Qt.Checked:
fields.append(unicode_type(item.data(Qt.UserRole)))
set_saved_field_data(self.name, fields, {x:i for i, x in enumerate(all_fields)})
# Return a dictionary with current options for this widget
if len(fields):
return {'fields':fields}
else:
return {'fields':['all']}
示例3: PluginWidget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import setObjectName [as 别名]
class PluginWidget(QWidget):
TITLE = _("CSV/XML Options")
HELP = _("Options specific to") + " CSV/XML " + _("output")
sync_enabled = False
formats = set(["csv", "xml"])
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QVBoxLayout(self)
self.la = la = QLabel(_("Fields to include in output:"))
la.setWordWrap(True)
l.addWidget(la)
self.db_fields = QListWidget(self)
l.addWidget(self.db_fields)
self.la2 = la = QLabel(_("Drag and drop to re-arrange fields"))
l.addWidget(la)
self.db_fields.setDragEnabled(True)
self.db_fields.setDragDropMode(QListWidget.InternalMove)
self.db_fields.setDefaultDropAction(Qt.MoveAction)
self.db_fields.setAlternatingRowColors(True)
self.db_fields.setObjectName("db_fields")
def initialize(self, catalog_name, db):
self.name = catalog_name
from calibre.library.catalogs import FIELDS
db = get_gui().current_db
self.all_fields = {x for x in FIELDS if x != "all"} | set(db.custom_field_keys())
sort_order = gprefs.get(self.name + "_db_fields_sort_order", {})
fm = db.field_metadata
def name(x):
if x == "isbn":
return "ISBN"
if x == "library_name":
return _("Library Name")
if x.endswith("_index"):
return name(x[: -len("_index")]) + " " + _("Number")
return fm[x].get("name") or x
def key(x):
return (sort_order.get(x, 10000), name(x))
self.db_fields.clear()
for x in sorted(self.all_fields, key=key):
QListWidgetItem(name(x) + " (%s)" % x, self.db_fields).setData(Qt.UserRole, x)
if x.startswith("#") and fm[x]["datatype"] == "series":
x += "_index"
QListWidgetItem(name(x) + " (%s)" % x, self.db_fields).setData(Qt.UserRole, x)
# Restore the activated fields from last use
fields = frozenset(gprefs.get(self.name + "_db_fields", self.all_fields))
for x in range(self.db_fields.count()):
item = self.db_fields.item(x)
item.setCheckState(Qt.Checked if unicode(item.data(Qt.UserRole)) in fields else Qt.Unchecked)
def options(self):
# Save the currently activated fields
fields, all_fields = [], []
for x in xrange(self.db_fields.count()):
item = self.db_fields.item(x)
all_fields.append(unicode(item.data(Qt.UserRole)))
if item.checkState() == Qt.Checked:
fields.append(unicode(item.data(Qt.UserRole)))
gprefs.set(self.name + "_db_fields", fields)
gprefs.set(self.name + "_db_fields_sort_order", {x: i for i, x in enumerate(all_fields)})
# Return a dictionary with current options for this widget
if len(fields):
return {"fields": fields}
else:
return {"fields": ["all"]}