本文整理汇总了Python中openlp.core.lib.ServiceItem.is_media方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceItem.is_media方法的具体用法?Python ServiceItem.is_media怎么用?Python ServiceItem.is_media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlp.core.lib.ServiceItem
的用法示例。
在下文中一共展示了ServiceItem.is_media方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ListPreviewWidget
# 需要导入模块: from openlp.core.lib import ServiceItem [as 别名]
# 或者: from openlp.core.lib.ServiceItem import is_media [as 别名]
class ListPreviewWidget(QtGui.QTableWidget):
def __init__(self, parent, screen_ratio):
"""
Initializes the widget to default state.
An empty ServiceItem is used per default.
One needs to call replace_service_manager_item() to make this widget display something.
"""
super(QtGui.QTableWidget, self).__init__(parent)
# Set up the widget.
self.setColumnCount(1)
self.horizontalHeader().setVisible(False)
self.setColumnWidth(0, parent.width())
self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setAlternatingRowColors(True)
# Initialize variables.
self.service_item = ServiceItem()
self.screen_ratio = screen_ratio
def resizeEvent(self, QResizeEvent):
"""
Overloaded method from QTableWidget. Will recalculate the layout.
"""
self.__recalculate_layout()
def __recalculate_layout(self):
"""
Recalculates the layout of the table widget. It will set height and width
of the table cells. QTableWidget does not adapt the cells to the widget size on its own.
"""
self.setColumnWidth(0, self.viewport().width())
if self.service_item:
# Sort out songs, bibles, etc.
if self.service_item.is_text():
self.resizeRowsToContents()
else:
# Sort out image heights.
for framenumber in range(len(self.service_item.get_frames())):
height = self.viewport().width() // self.screen_ratio
self.setRowHeight(framenumber, height)
def screen_size_changed(self, screen_ratio):
"""
To be called whenever the live screen size changes.
Because this makes a layout recalculation necessary.
"""
self.screen_ratio = screen_ratio
self.__recalculate_layout()
def replace_service_item(self, service_item, width, slideNumber):
"""
Replaces the current preview items with the ones in service_item.
Displays the given slide.
"""
self.service_item = service_item
self.clear()
self.setRowCount(0)
self.setColumnWidth(0, width)
row = 0
text = []
for framenumber, frame in enumerate(self.service_item.get_frames()):
self.setRowCount(self.slide_count() + 1)
item = QtGui.QTableWidgetItem()
slide_height = 0
if self.service_item.is_text():
if frame['verseTag']:
# These tags are already translated.
verse_def = frame['verseTag']
verse_def = '%s%s' % (verse_def[0], verse_def[1:])
two_line_def = '%s\n%s' % (verse_def[0], verse_def[1:])
row = two_line_def
else:
row += 1
item.setText(frame['text'])
else:
label = QtGui.QLabel()
label.setMargin(4)
if self.service_item.is_media():
label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
else:
label.setScaledContents(True)
if self.service_item.is_command():
label.setPixmap(QtGui.QPixmap(frame['image']))
else:
image = self.image_manager.get_image(frame['path'], ImageSource.ImagePlugin)
label.setPixmap(QtGui.QPixmap.fromImage(image))
self.setCellWidget(framenumber, 0, label)
slide_height = width // self.screen_ratio
row += 1
text.append(str(row))
self.setItem(framenumber, 0, item)
if slide_height:
self.setRowHeight(framenumber, slide_height)
self.setVerticalHeaderLabels(text)
if self.service_item.is_text():
self.resizeRowsToContents()
self.setColumnWidth(0, self.viewport().width())
self.setFocus()
#.........这里部分代码省略.........
示例2: ListPreviewWidget
# 需要导入模块: from openlp.core.lib import ServiceItem [as 别名]
# 或者: from openlp.core.lib.ServiceItem import is_media [as 别名]
#.........这里部分代码省略.........
self.__recalculate_layout()
def replace_service_item(self, service_item, width, slide_number):
"""
Replace the current preview items with the ones in service_item and display the given slide
:param service_item: The service item to insert
:param width: The width of the column
:param slide_number: The slide number to pre-select
"""
self.service_item = service_item
self.setRowCount(0)
self.clear()
self.setColumnWidth(0, width)
row = 0
text = []
for frame_number, frame in enumerate(self.service_item.get_frames()):
self.setRowCount(self.slide_count() + 1)
item = QtWidgets.QTableWidgetItem()
slide_height = 0
if self.service_item.is_text():
if frame['verseTag']:
# These tags are already translated.
verse_def = frame['verseTag']
verse_def = '%s%s' % (verse_def[0], verse_def[1:])
two_line_def = '%s\n%s' % (verse_def[0], verse_def[1:])
row = two_line_def
else:
row += 1
item.setText(frame['text'])
else:
label = QtWidgets.QLabel()
label.setContentsMargins(4, 4, 4, 4)
if self.service_item.is_media():
label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
else:
label.setScaledContents(True)
if self.service_item.is_command():
if self.service_item.is_capable(ItemCapabilities.HasThumbnails):
image = self.image_manager.get_image(frame['image'], ImageSource.CommandPlugins)
pixmap = QtGui.QPixmap.fromImage(image)
else:
pixmap = QtGui.QPixmap(frame['image'])
else:
image = self.image_manager.get_image(frame['path'], ImageSource.ImagePlugin)
pixmap = QtGui.QPixmap.fromImage(image)
pixmap.setDevicePixelRatio(label.devicePixelRatio())
label.setPixmap(pixmap)
slide_height = width // self.screen_ratio
# Setup and validate row height cap if in use.
max_img_row_height = Settings().value('advanced/slide max height')
if isinstance(max_img_row_height, int) and max_img_row_height != 0:
if max_img_row_height > 0 and slide_height > max_img_row_height:
# Manual Setting
slide_height = max_img_row_height
elif max_img_row_height < 0 and slide_height > self.auto_row_height:
# Auto Setting
slide_height = self.auto_row_height
label.setMaximumWidth(slide_height * self.screen_ratio)
label.resize(slide_height * self.screen_ratio, slide_height)
# Build widget with stretch padding
container = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
hbox.addWidget(label, stretch=1)
hbox.addStretch(0)