From 4ea1bb80b4303aa30c46066a9756b44e91115887 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 27 May 2014 00:18:14 +0200 Subject: [PATCH] Got title from inf file --- DE-env.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/DE-env.py b/DE-env.py index 4a87564..dd3340b 100755 --- a/DE-env.py +++ b/DE-env.py @@ -19,6 +19,8 @@ from gi.repository import Gio from gi.repository import Gdk import logging import pprint +import ConfigParser +import StringIO from wand.image import Image from wand.color import Color @@ -340,6 +342,41 @@ def get_max_monitor_geometry(): return (max_width, max_height) +#------------------------------------------------------------------------- +def get_title_from_ini(ini_file): + + log.debug("Reading %r ...", ini_file) + if not os.path.isfile(ini_file): + return None + + f = None + content = None + try: + f = open(ini_file) + content = f.read() + finally: + f.close() + + if not content: + return None + + content = "[__config__]\n" + content + ini_fp = StringIO.StringIO(content) + config = ConfigParser.RawConfigParser() + try: + config.readfp(ini_fp) + except Exception as e: + log.error("Got a %s on evaluating %r: %s", e.__class__.__name__, + ini_file, e) + return None + + if config.has_section('__config__') and config.has_option('__config__', 'title'): + ini_title = config.get('__config__', 'title').strip() + if ini_title: + return ini_title + + return None + #------------------------------------------------------------------------- bg_dirs = [ #'/home/fbrehm/Bilder/Wallpaper', @@ -406,6 +443,16 @@ if comment: log.debug("New title from comment: %r", title) break +inf_file = re.sub(r'\.[^\.]*$', '.inf', wpaper) +if os .path.exists(inf_file): + inf_title = get_title_from_ini(inf_file) + if inf_title: + inf_title = inf_title.strip() + if inf_title: + inf_title = inf_title.decode('utf-8') + log.debug("Got title %r from %r.", inf_title, inf_file) + title = inf_title + (screen_width, screen_height) = get_max_monitor_geometry() new_height = screen_height new_width = int(float(old_img.width) / float(old_img.height) * float(screen_height)) -- 2.39.5