use true division (py3)

This commit is contained in:
Andreas Preikschat 2013-04-24 21:05:34 +02:00
parent 7b7cbc588c
commit 22541e7297
8 changed files with 28 additions and 22 deletions

View File

@ -30,6 +30,7 @@
The :mod:`lib` module contains most of the components and libraries that make
OpenLP work.
"""
from __future__ import division
from distutils.version import LooseVersion
import logging
import os
@ -207,7 +208,7 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None):
ext = os.path.splitext(thumb_path)[1].lower()
reader = QtGui.QImageReader(image_path)
if size is None:
ratio = float(reader.size().width()) / float(reader.size().height())
ratio = reader.size().width() / reader.size().height()
reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88))
else:
reader.setScaledSize(size)
@ -260,8 +261,8 @@ def resize_image(image_path, width, height, background=u'#000000'):
log.debug(u'resize_image - start')
reader = QtGui.QImageReader(image_path)
# The image's ratio.
image_ratio = float(reader.size().width()) / float(reader.size().height())
resize_ratio = float(width) / float(height)
image_ratio = reader.size().width() / reader.size().height()
resize_ratio = width / height
# Figure out the size we want to resize the image to (keep aspect ratio).
if image_ratio == resize_ratio:
size = QtCore.QSize(width, height)
@ -282,7 +283,7 @@ def resize_image(image_path, width, height, background=u'#000000'):
new_image = QtGui.QImage(width, height, QtGui.QImage.Format_ARGB32_Premultiplied)
painter = QtGui.QPainter(new_image)
painter.fillRect(new_image.rect(), QtGui.QColor(background))
painter.drawImage((width - real_width) / 2, (height - real_height) / 2, preview)
painter.drawImage((width - real_width) // 2, (height - real_height) // 2, preview)
return new_image

View File

@ -30,6 +30,7 @@
"""
Provide additional functionality required by OpenLP from the inherited QDockWidget.
"""
from __future__ import division
import logging
from PyQt4 import QtGui
@ -55,7 +56,7 @@ class OpenLPDockWidget(QtGui.QDockWidget):
self.setWindowIcon(build_icon(icon))
# Sort out the minimum width.
screens = ScreenList()
main_window_docbars = screens.current[u'size'].width() / 5
main_window_docbars = screens.current[u'size'].width() // 5
if main_window_docbars > 300:
self.setMinimumWidth(300)
else:

View File

@ -26,7 +26,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from __future__ import division
import logging
from PyQt4 import QtWebKit
@ -276,7 +276,7 @@ def build_background_css(item, width):
``item``
Service Item containing theme and location information
"""
width = int(width) / 2
width = int(width) // 2
theme = item.themedata
background = u'background-color: black'
if theme:

View File

@ -26,7 +26,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from __future__ import division
import logging
from PyQt4 import QtGui, QtCore, QtWebKit
@ -327,7 +327,7 @@ class Renderer(object):
screen_size = self.screens.current[u'size']
self.width = screen_size.width()
self.height = screen_size.height()
self.screen_ratio = float(self.height) / float(self.width)
self.screen_ratio = self.height / self.width
log.debug(u'_calculate default %s, %f' % (screen_size, self.screen_ratio))
# 90% is start of footer
self.footer_start = int(self.height * 0.90)
@ -546,15 +546,15 @@ class Renderer(object):
"""
smallest_index = 0
highest_index = len(html_list) - 1
index = int(highest_index / 2)
index = highest_index // 2
while True:
if not self._text_fits_on_slide(previous_html + separator.join(html_list[:index + 1]).strip()):
# We know that it does not fit, so change/calculate the new index and highest_index accordingly.
highest_index = index
index = int(index - (index - smallest_index) / 2)
index = index - (index - smallest_index) // 2
else:
smallest_index = index
index = int(index + (highest_index - index) / 2)
index = index + (highest_index - index) // 2
# We found the number of words which will fit.
if smallest_index == index or highest_index == index:
index = smallest_index
@ -582,7 +582,7 @@ class Renderer(object):
html_list[0] = html_tags + html_list[0]
smallest_index = 0
highest_index = len(html_list) - 1
index = int(highest_index / 2)
index = highest_index // 2
return previous_html, previous_raw
def _text_fits_on_slide(self, text):

View File

@ -30,6 +30,7 @@
The :mod:`screen` module provides management functionality for a machines'
displays.
"""
from __future__ import division
import logging
import copy
@ -232,8 +233,8 @@ class ScreenList(object):
``window``
A QWidget we are finding the location of.
"""
x = window.x() + (window.width() / 2)
y = window.y() + (window.height() / 2)
x = window.x() + (window.width() // 2)
y = window.y() + (window.height() // 2)
for screen in self.screen_list:
size = screen[u'size']
if x >= size.x() and x <= (size.x() + size.width()) and y >= size.y() and y <= (size.y() + size.height()):

View File

@ -26,7 +26,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from __future__ import division
import logging
from PyQt4 import QtCore, QtGui
@ -85,10 +85,10 @@ class SearchEdit(QtGui.QLineEdit):
size = self.clear_button.size()
frame_width = self.style().pixelMetric(QtGui.QStyle.PM_DefaultFrameWidth)
self.clear_button.move(self.rect().right() - frame_width - size.width(),
(self.rect().bottom() + 1 - size.height()) / 2)
(self.rect().bottom() + 1 - size.height()) // 2)
if hasattr(self, u'menu_button'):
size = self.menu_button.size()
self.menu_button.move(self.rect().left() + frame_width + 2, (self.rect().bottom() + 1 - size.height()) / 2)
self.menu_button.move(self.rect().left() + frame_width + 2, (self.rect().bottom() + 1 - size.height()) // 2)
def current_search_type(self):
"""

View File

@ -35,6 +35,7 @@ Some of the code for this form is based on the examples at:
* `http://html5demos.com/two-videos`_
"""
from __future__ import division
import cgi
import logging
import sys
@ -207,8 +208,8 @@ class MainDisplay(Display):
painter_image.begin(self.initial_fame)
painter_image.fillRect(self.initial_fame.rect(), background_color)
painter_image.drawImage(
(self.screen[u'size'].width() - splash_image.width()) / 2,
(self.screen[u'size'].height() - splash_image.height()) / 2,
(self.screen[u'size'].width() - splash_image.width()) // 2,
(self.screen[u'size'].height() - splash_image.height()) // 2,
splash_image)
service_item = ServiceItem()
service_item.bg_image_bytes = image_to_byte(self.initial_fame)
@ -268,7 +269,7 @@ class MainDisplay(Display):
self.resize(self.width(), alert_height)
self.setVisible(True)
if location == AlertLocation.Middle:
self.move(self.screen[u'size'].left(), (self.screen[u'size'].height() - alert_height) / 2)
self.move(self.screen[u'size'].left(), (self.screen[u'size'].height() - alert_height) // 2)
elif location == AlertLocation.Bottom:
self.move(self.screen[u'size'].left(), self.screen[u'size'].height() - alert_height)
else:

View File

@ -29,6 +29,8 @@
"""
The Themes configuration tab
"""
from __future__ import division
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Registry, Settings, SettingsTab, UiStrings, translate
@ -90,7 +92,7 @@ class ThemesTab(SettingsTab):
self.global_level_label.setObjectName(u'global_level_label')
self.level_layout.addRow(self.global_level_radio_button, self.global_level_label)
label_top_margin = (self.song_level_radio_button.sizeHint().height() -
self.song_level_label.sizeHint().height()) / 2
self.song_level_label.sizeHint().height()) // 2
for label in [self.song_level_label, self.service_level_label, self.global_level_label]:
rect = label.rect()
rect.setTop(rect.top() + label_top_margin)