PEP8-ified function names in kofoto.common.
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Dec 2005 19:27:10 +0000 (19:27 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Dec 2005 19:27:10 +0000 (19:27 +0000)
New function: kofoto.common.calculate_rescaled_size.

src/packages/kofoto/common.py
src/packages/kofoto/gkofoto/imagepreloader.py
src/packages/kofoto/gkofoto/imageview.py
src/packages/kofoto/imagecache.py
src/packages/kofoto/outputengine.py

index fd5ca00..5679bc2 100644 (file)
@@ -6,8 +6,8 @@
 __all__ = [
     "KofotoError",
     "UnimplementedError",
-    "calculateDownscaledDimensions",
-    "symlinkOrCopyFile",
+    "calculate_downscaled_size",
+    "symlink_or_copy_file",
     ]
 
 ######################################################################
@@ -27,20 +27,30 @@ class UnimplementedError(KofotoError):
 ######################################################################
 ### Functions.
 
-def calculateDownscaledDimensions(width, height, widthlimit, heightlimit):
+def calculate_downscaled_size(width, height, width_limit, height_limit):
     """Scale down width and height to fit within given limits."""
 
     w = width
     h = height
-    if w > widthlimit:
-        h = widthlimit * h // w
-        w = widthlimit
-    if h > heightlimit:
-        w = heightlimit * w // h
-        h = heightlimit
+    if w > width_limit:
+        h = width_limit * h // w
+        w = width_limit
+    if h > height_limit:
+        w = height_limit * w // h
+        h = height_limit
     return w, h
 
-def symlinkOrCopyFile(source, destination):
+def calculate_rescaled_size(width, height, width_limit, height_limit):
+    """Scale up or down width and height to fit within given limits."""
+
+    w = width_limit
+    h = width_limit * height // width
+    if h > height_limit:
+        w = height_limit * w // h
+        h = height_limit
+    return w, h
+
+def symlink_or_copy_file(source, destination):
     """Create a symbolic link, or copy if support links are not supported."""
 
     try:
index 34b5f9f..a5979d3 100644 (file)
@@ -3,7 +3,7 @@
 import gobject
 import gtk
 from kofoto.timer import Timer
-from kofoto.common import calculateDownscaledDimensions
+from kofoto.common import calculate_downscaled_size
 
 class _MyPixbufLoader(gtk.gdk.PixbufLoader):
     def __init__(self, *args, **kwargs):
@@ -178,7 +178,7 @@ class ImagePreloader(object):
                   scaledPixbuf.get_height() <= maxHeight and
                   (scaledPixbuf.get_width() == maxWidth or
                    scaledPixbuf.get_height() == maxHeight)):
-            scaledWidth, scaledHeight = calculateDownscaledDimensions(
+            scaledWidth, scaledHeight = calculate_downscaled_size(
                 fullsizePixbuf.get_width(),
                 fullsizePixbuf.get_height(),
                 maxWidth,
index 2ae3510..9c8c3a9 100644 (file)
@@ -5,7 +5,7 @@ import gtk.gdk
 import math
 import gc
 from kofoto.gkofoto.environment import env
-from kofoto.common import calculateDownscaledDimensions
+from kofoto.common import calculate_downscaled_size
 
 class ImageView(gtk.ScrolledWindow):
     # TODO: Read from configuration file?
@@ -94,7 +94,7 @@ class ImageView(gtk.ScrolledWindow):
         else:
             if self.__fitToWindowMode:
                 maxWidth, maxHeight = tuple(self.get_allocation())[2:4]
-                wantedWidth, wantedHeight = calculateDownscaledDimensions(
+                wantedWidth, wantedHeight = calculate_downscaled_size(
                     self.__pixBuf.get_width(),
                     self.__pixBuf.get_height(),
                     maxWidth,
index a283982..dd2e8e9 100644 (file)
@@ -4,7 +4,7 @@ __all__ = ["ImageCache"]
 
 import os
 import Image as PILImage
-from kofoto.common import calculateDownscaledDimensions
+from kofoto.common import calculate_downscaled_size
 
 class ImageCache:
     """A class representing the Kofoto image cache."""
@@ -95,7 +95,7 @@ class ImageCache:
              heightlimit, orientation):
         """Internal helper method."""
         # Scale image to fit within limits.
-        w, h = calculateDownscaledDimensions(
+        w, h = calculate_downscaled_size(
             width, height, widthlimit, heightlimit)
         if orientation in ["left", "right"]:
             w, h = h, w
index 0e30b2a..d4736aa 100644 (file)
@@ -7,7 +7,7 @@ import os
 import re
 import time
 from sets import Set
-from kofoto.common import symlinkOrCopyFile, UnimplementedError
+from kofoto.common import symlink_or_copy_file, UnimplementedError
 
 class OutputEngine:
     """An abstract base class for output generators of an album tree."""
@@ -118,7 +118,7 @@ class OutputEngine:
                 os.makedirs(os.path.dirname(imgloc))
             except OSError:
                 pass
-            symlinkOrCopyFile(imgabsloc, imgloc)
+            symlink_or_copy_file(imgabsloc, imgloc)
             self.__imgrefMap[key] = (
                 "/".join(htmlimgloc.split(os.sep)),
                 width,
@@ -157,7 +157,7 @@ class OutputEngine:
         source      -- A location in the filesystem.
         destination -- A location in the generated directory.
         """
-        symlinkOrCopyFile(source, os.path.join(self.__dest, destination))
+        symlink_or_copy_file(source, os.path.join(self.__dest, destination))
 
 
     def makeDirectory(self, directory):