refactor code to stop duplicate code

This commit is contained in:
Tim Bentley 2011-09-28 18:39:26 +01:00
parent 632e2ce2dd
commit ff32139b2e
3 changed files with 27 additions and 21 deletions

View File

@ -306,19 +306,37 @@ class Renderer(object):
log.debug(u'_build_text_rectangle')
main_rect = None
footer_rect = None
main_rect = self.get_main_rectangle(theme)
footer_rect = self.get_main_rectangle(theme)
self._set_text_rectangle(main_rect, footer_rect)
def get_main_rectangle(self, theme):
"""
Calculates the placement and size of the main rectangle
``theme``
The theme information
"""
if not theme.font_main_override:
main_rect = QtCore.QRect(10, 0, self.width - 20, self.footer_start)
return QtCore.QRect(10, 0, self.width - 20, self.footer_start)
else:
main_rect = QtCore.QRect(theme.font_main_x, theme.font_main_y,
return QtCore.QRect(theme.font_main_x, theme.font_main_y,
theme.font_main_width - 1, theme.font_main_height - 1)
def get_footer_rectangle(self, theme):
"""
Calculates the placement and size of the main rectangle
``theme``
The theme information
"""
if not theme.font_footer_override:
footer_rect = QtCore.QRect(10, self.footer_start, self.width - 20,
return QtCore.QRect(10, self.footer_start, self.width - 20,
self.height - self.footer_start)
else:
footer_rect = QtCore.QRect(theme.font_footer_x,
return QtCore.QRect(theme.font_footer_x,
theme.font_footer_y, theme.font_footer_width - 1,
theme.font_footer_height - 1)
self._set_text_rectangle(main_rect, footer_rect)
def _set_text_rectangle(self, rect_main, rect_footer):
"""

View File

@ -246,23 +246,11 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard):
pixmap.fill(QtCore.Qt.white)
paint = QtGui.QPainter(pixmap)
paint.setPen(QtGui.QPen(QtCore.Qt.blue))
if not self.theme.font_main_override:
main_rect = QtCore.QRect(10, 0, width - 20, footer_start)
else:
main_rect = QtCore.QRect(self.theme.font_main_x, self.theme.font_main_y,
self.theme.font_main_width - 1, self.theme.font_main_height - 1)
paint.drawRect(main_rect)
paint.drawRect(self.thememanager.mainwindow.renderer.get_main_rectangle(self.theme))
paint.setPen(QtGui.QPen(QtCore.Qt.red))
if not self.theme.font_footer_override:
footer_rect = QtCore.QRect(10, footer_start, width - 20,
height - footer_start)
else:
footer_rect = QtCore.QRect(self.theme.font_footer_x,
self.theme.font_footer_y, self.theme.font_footer_width - 1,
self.theme.font_footer_height - 1)
paint.drawRect(footer_rect)
paint.drawRect(self.thememanager.mainwindow.renderer.get_footer_rectangle(self.theme))
paint.end()
pixmap = pixmap.scaledToWidth(100, QtCore.Qt.SmoothTransformation)
pixmap = pixmap.scaledToWidth(200, QtCore.Qt.SmoothTransformation)
self.themeLayoutLabel.setPixmap(pixmap)
self.displayAspectRatio = float(pixmap.width()) / pixmap.height()
self.resizeEvent()

View File

@ -315,7 +315,7 @@ class HttpConnection(object):
"""
log.debug(u'ready to read socket')
if self.socket.canReadLine():
data = unicode(self.socket.readLine())
data = unicode(self.socket.readLine()).encode(u'utf-8')
log.debug(u'received: ' + data)
words = data.split(u' ')
response = None