Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/tautils.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-10-26 15:29:08 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-10-26 15:29:08 (GMT)
commit2ef9a33102d18b10fc7b5bbbc7c0327ce870a605 (patch)
treece7e3eaa422303e2962010099e999fb443676e0a /TurtleArt/tautils.py
parentc83fa3c8f61aaf9a240681ee2c530ca0c8be92d3 (diff)
fix font scaling problem on XO hardware; fix triangle increment of number blocks
Diffstat (limited to 'TurtleArt/tautils.py')
-rw-r--r--TurtleArt/tautils.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py
index c54c65f..daac4fe 100644
--- a/TurtleArt/tautils.py
+++ b/TurtleArt/tautils.py
@@ -25,6 +25,7 @@ import pickle
import subprocess
import os
import string
+from string import find
from gettext import gettext as _
try:
@@ -718,3 +719,39 @@ def _get_dmi(node):
return open(path).readline().strip()
except:
return None
+
+
+def get_screen_dpi():
+ '''Looking for 'dimensions' line in xdpyinfo
+ dimensions: 1280x800 pixels (339x212 millimeters)'''
+ output = check_output('/usr/bin/xdpyinfo', 'xdpyinfo failed')
+ if output is not None:
+ strings = output[find(output, 'dimensions:'):].split()
+ w = int(strings[1].split('x')[0]) # e.g., 1280x800
+ mm = int(strings[3][1:].split('x')[0]) # e.g., (339x212)
+ return int((w * 25.4 / mm) + 0.5)
+ else:
+ return 96
+
+
+def check_output(command, warning):
+ ''' Workaround for old systems without subprocess.check_output'''
+ if hasattr(subprocess, 'check_output'):
+ try:
+ output = subprocess.check_output(command)
+ except subprocess.CalledProcessError:
+ log.warning(warning)
+ return None
+ else:
+ import commands
+
+ cmd = ''
+ for c in command:
+ cmd += c
+ cmd += ' '
+ (status, output) = commands.getstatusoutput(cmd)
+ if status != 0:
+ log.warning(warning)
+ return None
+ return output
+