You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-2.1-client/pym/cl_fill_client.py

116 lines
4.3 KiB

#-*- coding: utf-8 -*-
#Copyright 2008 Calculate Pack, http://www.calculate-linux.ru
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import cl_base
class fillVars(object, cl_base.glob_attr):
def get_cl_profile_path(self):
"""список накладываемых профилей при установке, наложении профилей"""
profpath = []
profPaths = ['/usr/lib/calculate/calculate-client/profile',
'/var/calculate/remote/client-profile',
'/var/calculate/client-profile'
]
for profPath in profPaths:
if os.path.exists(profPath):
paths = os.listdir(profPath)
for path in paths:
ph = os.path.join(profPath,path)
if os.path.exists(ph) and os.listdir(ph):
profpath.append(ph)
return profpath
def getX11Resolution(self):
"""возвращает текущее разрешение экрана (ширина, высота), X запущен"""
lines=self._runos("%s xdpyinfo"%self.path_env)
reRes = re.compile("dimensions:\s+(\d+)x(\d+)\s+pixels")
searchRes=False
for line in lines:
searchRes = reRes.search(line)
if searchRes:
break
if searchRes:
return (searchRes.group(1), searchRes.group(2))
else:
return False
def get_hr_x11_height(self):
"""Получить высоту экрана в пикселах"""
resolution = self.getX11Resolution()
if resolution:
self.Set('hr_x11_width',resolution[0])
return resolution[1]
def get_hr_x11_width(self):
"""Получить ширину экрана в пикселах"""
resolution = self.getX11Resolution()
if resolution:
self.Set('hr_x11_height',resolution[1])
return resolution[0]
def get_hr_x11_standart(self):
"""Получить ближайший стандартный размер изображения к текущему разрешению"""
#Стандартные разрешения
width = int(self.Get('hr_x11_width'))
height = int(self.Get('hr_x11_height'))
res = [(1024,768),
(1280,1024),
(1280,800),
(1440,900),
(1600,1200),
(1680,1050),
(1920,1200)]
resolution = []
formats = []
for w, h in res:
formats.append(float(w)/float(h))
listFr = list(set(formats))
listFormats = {}
for fr in listFr:
listFormats[fr] = []
for w, h in res:
for fr in listFormats.keys():
if fr == float(w)/float(h):
listFormats[fr].append((w,h))
break
format = float(width)/float(height)
deltaFr = {}
for fr in listFormats.keys():
deltaFr[abs(format - fr)] = fr
resolution = listFormats[deltaFr[min(deltaFr.keys())]]
flagFound = False
stResol = []
stHeights = []
stWidths = []
stWidth = False
stHeight = False
for w, h in resolution:
if w >= width and h >= height:
stResol.append((w,h))
stHeights.append(h)
if stHeights:
stHeight = min(stHeights)
for w, h in stResol:
if stHeight == h:
stWidths.append(w)
if stWidths:
stWidth = min(stWidths)
if (not stWidth) or (not stHeight):
return "%sx%s"%(resolution[-1][0],resolution[-1][1])
else:
return "%sx%s"%(stWidth,stHeight)