From 823637cf0ea883954d463d085652dedab105f83d Mon Sep 17 00:00:00 2001 From: asamoukin Date: Sat, 1 Nov 2008 12:19:49 +0000 Subject: [PATCH] git-svn-id: http://svn.calculate.ru/calculate2/calculate-client/trunk@342 c91db197-33c1-4113-bf15-f8a5c547ca64 --- pym/cl_fill_client.py | 56 +++++++++++++++++++++++++++++++++++++++++-- pym/cl_vars_client.py | 4 ++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/pym/cl_fill_client.py b/pym/cl_fill_client.py index f87b469..468d13e 100644 --- a/pym/cl_fill_client.py +++ b/pym/cl_fill_client.py @@ -37,7 +37,7 @@ class fillVars(object, cl_base.glob_attr): def getX11Resolution(self): """возвращает текущее разрешение экрана (ширина, высота), X запущен""" - lines=self._runos("%s xdpyinfo -display :0.0"%self.path_env) + lines=self._runos("%s xdpyinfo"%self.path_env) reRes = re.compile("dimensions:\s+(\d+)x(\d+)\s+pixels") searchRes=False for line in lines: @@ -61,4 +61,56 @@ class fillVars(object, cl_base.glob_attr): resolution = self.getX11Resolution() if resolution: self.Set('hr_x11_height',resolution[1]) - return resolution[0] \ No newline at end of file + 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) \ No newline at end of file diff --git a/pym/cl_vars_client.py b/pym/cl_vars_client.py index 8530dbf..301f6da 100644 --- a/pym/cl_vars_client.py +++ b/pym/cl_vars_client.py @@ -59,8 +59,12 @@ class Data: #Разрешение X по вертикали hr_x11_height = {'mode':"w"} + #Разрешение X по горизонтали hr_x11_width = {'mode':"w"} + + #ближайший стандартный размер изображения к текущему разрешению + hr_x11_standart = {} # Calculate плюс версия калкулэйта для записи в заголовок файла # объединяемого с профилем #setup_name