]> Frank Brehm's Git Trees - my-stuff/python.git/commitdiff
Added image resizing
authorFrank Brehm <frank@brehm-online.com>
Sat, 24 May 2014 06:35:47 +0000 (08:35 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sat, 24 May 2014 06:35:47 +0000 (08:35 +0200)
DE-env.py

index 4162a11ca49bd4834548825682993f741e4e7576..ec62371b29bd6f32f7c85ec73e769f8bbd42a000 100755 (executable)
--- a/DE-env.py
+++ b/DE-env.py
@@ -16,6 +16,7 @@ import re
 #import gconf
 import random
 from gi.repository import Gio
+from gi.repository import Gdk
 import logging
 
 from wand.image import Image
@@ -33,6 +34,7 @@ font = '/usr/share/fonts/corefonts/verdanab.ttf'
 if not os.path.exists(font):
     font = '/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf'
 
+#-------------------------------------------------------------------------
 def init_logging():
     """
     Initialize the logger object.
@@ -74,6 +76,7 @@ def init_logging():
 
 init_logging()
 
+#-------------------------------------------------------------------------
 def get_desktop_environment():
     #From http://stackoverflow.com/questions/2035657/what-is-my-current-desktop-environment
     # and http://ubuntuforums.org/showthread.php?t=652320
@@ -129,6 +132,7 @@ def get_desktop_environment():
             return "kde"
     return "unknown"
 
+#-------------------------------------------------------------------------
 def is_running(process):
     #From http://www.bloggerpolis.com/2011/05/how-to-check-if-a-process-is-running-using-python/
     # and http://richarddingwall.name/2009/06/18/windows-equivalents-of-ps-and-kill-commands/
@@ -268,6 +272,7 @@ def set_wallpaper(file_loc, first_run):
         sys.stderr.write("ERROR: Failed to set wallpaper. There might be a bug.\n")
         return False
 
+#-------------------------------------------------------------------------
 def get_config_dir(app_name=APP_NAME):
     if "XDG_CONFIG_HOME" in os.environ:
         confighome = os.environ['XDG_CONFIG_HOME'] 
@@ -292,6 +297,27 @@ def get_home_dir():
     else:
         raise KeyError("Neither USERPROFILE or HOME environment variables set.")
 
+#-------------------------------------------------------------------------
+def get_max_monitor_height():
+
+    max_height = 768
+    screen = Gdk.Screen.get_default()
+    if screen is None:
+        return max_height
+
+    monitors = []
+    nmons = screen.get_n_monitors()
+    log.debug("There are %d monitors.", nmons)
+
+    for m in range(nmons):
+        mg = screen.get_monitor_geometry(m)
+        log.debug("Monitor geometry %d: %d x %d", m, mg.width, mg.height)
+        if mg.height > max_height:
+            max_height = mg.height
+
+    return max_height
+
+#-------------------------------------------------------------------------
 bg_dirs = [
     #'/home/fbrehm/Bilder/Wallpaper',
     '/home/frank/Bilder',
@@ -338,6 +364,12 @@ new_img_fname = '/tmp/wallpaper.jpg'
 old_img = Image(filename = wpaper)
 new_img = old_img.clone()
 
+screen_height = get_max_monitor_height()
+new_width = int(float(old_img.width) / float(old_img.height) * float(screen_height))
+
+log.debug("Resizing image to %d x %d.", new_width, screen_height)
+new_img.resize(new_width, screen_height)
+
 black = Color('srgba(0,0,0,0.5)')
 white = Color('srgba(255,255,255,0.5)')