Core refactoring 0

This commit is contained in:
Jon Tibble 2009-11-04 01:32:13 +00:00
parent 7029235f45
commit 38615ca5c9
4 changed files with 58 additions and 57 deletions

View File

@ -40,6 +40,7 @@ class Renderer(object):
Initialise the renderer. Initialise the renderer.
""" """
self._rect = None self._rect = None
self._footer_rect = None
self._debug = 0 self._debug = 0
self._right_margin = 64 # the amount of right indent self._right_margin = 64 # the amount of right indent
self._shadow_offset = 5 self._shadow_offset = 5
@ -215,18 +216,29 @@ class Renderer(object):
split_pages.append(page) split_pages.append(page)
return split_pages return split_pages
def set_text_rectangle(self, rect_main, rect_footer): def build_text_rectangle(self, theme):
""" """
Sets the rectangle within which text should be rendered. Builds a text block using the settings in ``theme``.
One is needed per slide
``rect_main`` ``theme``
The main text block. The theme to build a text block for.
``rect_footer``
The footer text block.
""" """
self._rect = rect_main log.debug(u'build_text_rectangle')
self._rect_footer = rect_footer if theme.font_main_override == False:
self._rect = QtCore.QRect(10, 0, self.width - 1,
self.footer_start - 20)
else:
self._rect = QtCore.QRect(int(theme.font_main_x),
int(theme.font_main_y), int(theme.font_main_width)-1,
int(theme.font_main_height) - 1)
if theme.font_footer_override == False:
self._footer_rect = QtCore.QRect(10,self.footer_start, self.width - 1,
self.height-self.footer_start)
else:
self._footer_rect = QtCore.QRect(int(theme.font_footer_x),
int(theme.font_footer_y), int(theme.font_footer_width)-1,
int(theme.font_footer_height) - 1)
def generate_frame_from_lines(self, lines, footer_lines=None): def generate_frame_from_lines(self, lines, footer_lines=None):
""" """

View File

@ -137,49 +137,24 @@ class RenderManager(object):
self.calculate_default( self.calculate_default(
self.screen_list[self.current_display][u'size']) self.screen_list[self.current_display][u'size'])
self.renderer.set_theme(self.themedata) self.renderer.set_theme(self.themedata)
self.build_text_rectangle(self.themedata) self.renderer.build_text_rectangle(self.themedata)
#Replace the backgrount image from renderer with one from image #Replace the backgrount image from renderer with one from image
if self.override_background is not None: if self.override_background is not None:
if self.save_bg_frame is None: if self.save_bg_frame is None:
self.save_bg_frame = self.renderer.bg_frame self.save_bg_frame = self.renderer.bg_frame
if self.override_background_changed: if self.override_background_changed:
self.renderer.bg_frame = self.resize_image(self.override_background) self.renderer.bg_frame = self.resize_image(
self.override_background)
self.override_background_changed = False self.override_background_changed = False
else: else:
if self.override_background_changed: if self.override_background_changed:
self.renderer.bg_frame = self.resize_image(self.override_background) self.renderer.bg_frame = self.resize_image(
self.override_background)
self.override_background_changed = False self.override_background_changed = False
if self.save_bg_frame is not None: if self.save_bg_frame is not None:
self.renderer.bg_frame = self.save_bg_frame self.renderer.bg_frame = self.save_bg_frame
self.save_bg_frame = None self.save_bg_frame = None
def build_text_rectangle(self, theme):
"""
Builds a text block using the settings in ``theme``.
One is needed per slide
``theme``
The theme to build a text block for.
"""
log.debug(u'build_text_rectangle')
main_rect = None
footer_rect = None
if theme.font_main_override == False:
main_rect = QtCore.QRect(10, 0, self.width - 1,
self.footer_start - 20)
else:
main_rect = QtCore.QRect(int(theme.font_main_x),
int(theme.font_main_y), int(theme.font_main_width)-1,
int(theme.font_main_height) - 1)
if theme.font_footer_override == False:
footer_rect = QtCore.QRect(10,self.footer_start, self.width - 1,
self.height-self.footer_start)
else:
footer_rect = QtCore.QRect(int(theme.font_footer_x),
int(theme.font_footer_y), int(theme.font_footer_width)-1,
int(theme.font_footer_height) - 1)
self.renderer.set_text_rectangle(main_rect, footer_rect)
def generate_preview(self, themedata): def generate_preview(self, themedata):
""" """
Generate a preview of a theme. Generate a preview of a theme.
@ -190,7 +165,7 @@ class RenderManager(object):
log.debug(u'generate preview') log.debug(u'generate preview')
self.calculate_default(QtCore.QSize(1024, 768)) self.calculate_default(QtCore.QSize(1024, 768))
self.renderer.set_theme(themedata) self.renderer.set_theme(themedata)
self.build_text_rectangle(themedata) self.renderer.build_text_rectangle(themedata)
self.renderer.set_frame_dest(self.width, self.height, True) self.renderer.set_frame_dest(self.width, self.height, True)
verse = [] verse = []
verse.append(u'Amazing Grace!') verse.append(u'Amazing Grace!')
@ -212,7 +187,7 @@ class RenderManager(object):
The words to go on the slides. The words to go on the slides.
""" """
log.debug(u'format slide') log.debug(u'format slide')
self.build_text_rectangle(self.themedata) self.renderer.build_text_rectangle(self.themedata)
return self.renderer.format_slide(words, False) return self.renderer.format_slide(words, False)
def generate_slide(self, main_text, footer_text): def generate_slide(self, main_text, footer_text):
@ -226,7 +201,7 @@ class RenderManager(object):
The text for the slide footer. The text for the slide footer.
""" """
log.debug(u'generate slide') log.debug(u'generate slide')
self.build_text_rectangle(self.themedata) self.renderer.build_text_rectangle(self.themedata)
self.renderer.set_frame_dest(self.width, self.height) self.renderer.set_frame_dest(self.width, self.height)
return self.renderer.generate_frame_from_lines(main_text, footer_text) return self.renderer.generate_frame_from_lines(main_text, footer_text)
@ -246,7 +221,7 @@ class RenderManager(object):
h = height h = height
preview = preview.scaled(w, h, QtCore.Qt.KeepAspectRatio, preview = preview.scaled(w, h, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation) QtCore.Qt.SmoothTransformation)
realw = preview.width(); realw = preview.width()
realh = preview.height() realh = preview.height()
# and move it to the centre of the preview space # and move it to the centre of the preview space
newImage = QtGui.QImage(w, h, QtGui.QImage.Format_ARGB32_Premultiplied) newImage = QtGui.QImage(w, h, QtGui.QImage.Format_ARGB32_Premultiplied)

View File

@ -448,9 +448,11 @@ class SlideController(QtGui.QWidget):
if self.commandItem is not None and \ if self.commandItem is not None and \
self.commandItem.service_item_type == ServiceItemType.Command: self.commandItem.service_item_type == ServiceItemType.Command:
if blanked: if blanked:
Receiver().send_message(u'%s_blank'% self.commandItem.name.lower()) Receiver().send_message(
u'%s_blank' % self.commandItem.name.lower())
else: else:
Receiver().send_message(u'%s_unblank'% self.commandItem.name.lower()) Receiver().send_message(
u'%s_unblank' % self.commandItem.name.lower())
else: else:
self.parent.mainDisplay.blankDisplay() self.parent.mainDisplay.blankDisplay()
@ -463,7 +465,8 @@ class SlideController(QtGui.QWidget):
self.row = 0 self.row = 0
if row > -1 and row < self.PreviewListWidget.rowCount(): if row > -1 and row < self.PreviewListWidget.rowCount():
if self.commandItem.service_item_type == ServiceItemType.Command: if self.commandItem.service_item_type == ServiceItemType.Command:
Receiver().send_message(u'%s_slide'% self.commandItem.name.lower(), [row]) Receiver().send_message(
u'%s_slide'% self.commandItem.name.lower(), [row])
if self.isLive: if self.isLive:
QtCore.QTimer.singleShot(0.5, self.grabMainDisplay) QtCore.QTimer.singleShot(0.5, self.grabMainDisplay)
else: else:
@ -489,10 +492,12 @@ class SlideController(QtGui.QWidget):
if not rm.screen_list[rm.current_display][u'primary']: if not rm.screen_list[rm.current_display][u'primary']:
winid = QtGui.QApplication.desktop().winId() winid = QtGui.QApplication.desktop().winId()
rect = rm.screen_list[rm.current_display][u'size'] rect = rm.screen_list[rm.current_display][u'size']
winimg = QtGui.QPixmap.grabWindow(winid, rect.x(), rect.y(), rect.width(), rect.height()) winimg = QtGui.QPixmap.grabWindow(
winid, rect.x(), rect.y(), rect.width(), rect.height())
self.SlidePreview.setPixmap(winimg) self.SlidePreview.setPixmap(winimg)
else: else:
label = self.PreviewListWidget.cellWidget(self.PreviewListWidget.currentRow(), 0) label = self.PreviewListWidget.cellWidget(
self.PreviewListWidget.currentRow(), 0)
self.SlidePreview.setPixmap(label.pixmap()) self.SlidePreview.setPixmap(label.pixmap())
def onSlideSelectedNext(self): def onSlideSelectedNext(self):

View File

@ -78,17 +78,25 @@ class ThemeManager(QtGui.QWidget):
self.ThemeListWidget.addAction( self.ThemeListWidget.addAction(
contextMenuAction(self.ThemeListWidget, u':/themes/theme_edit.png', contextMenuAction(self.ThemeListWidget, u':/themes/theme_edit.png',
self.trUtf8(u'Edit a theme'), self.onEditTheme)) self.trUtf8(u'Edit a theme'), self.onEditTheme))
self.ThemeListWidget.addAction(contextMenuSeparator(self.ThemeListWidget))
self.ThemeListWidget.addAction( self.ThemeListWidget.addAction(
contextMenuAction(self.ThemeListWidget, u':/themes/theme_delete.png', contextMenuSeparator(self.ThemeListWidget))
self.trUtf8(u'Delete theme'), self.onDeleteTheme))
self.ThemeListWidget.addAction( self.ThemeListWidget.addAction(
contextMenuAction(self.ThemeListWidget, u':/themes/theme_export.png', contextMenuAction(self.ThemeListWidget,
self.trUtf8(u'Make Global'), self.changeGlobalFromScreen)) u':/themes/theme_delete.png',
self.trUtf8(u'Delete theme'),
self.onDeleteTheme))
self.ThemeListWidget.addAction( self.ThemeListWidget.addAction(
contextMenuAction(self.ThemeListWidget, u':/themes/theme_export.png', contextMenuAction(self.ThemeListWidget,
self.trUtf8(u'Export theme'), self.onExportTheme)) u':/themes/theme_export.png',
self.ThemeListWidget.addAction(contextMenuSeparator(self.ThemeListWidget)) self.trUtf8(u'Make Global'),
self.changeGlobalFromScreen))
self.ThemeListWidget.addAction(
contextMenuAction(self.ThemeListWidget,
u':/themes/theme_export.png',
self.trUtf8(u'Export theme'),
self.onExportTheme))
self.ThemeListWidget.addAction(
contextMenuSeparator(self.ThemeListWidget))
#Signals #Signals
QtCore.QObject.connect(self.ThemeListWidget, QtCore.QObject.connect(self.ThemeListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
@ -151,7 +159,8 @@ class ThemeManager(QtGui.QWidget):
if item is not None: if item is not None:
self.amendThemeForm.loadTheme( self.amendThemeForm.loadTheme(
unicode(item.data(QtCore.Qt.UserRole).toString())) unicode(item.data(QtCore.Qt.UserRole).toString()))
self.saveThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) self.saveThemeName = unicode(
item.data(QtCore.Qt.UserRole).toString())
self.amendThemeForm.exec_() self.amendThemeForm.exec_()
def onDeleteTheme(self): def onDeleteTheme(self):