|
|
|
@ -22,8 +22,8 @@ import sys
|
|
|
|
|
|
|
|
|
|
from calculate.consolegui import qt
|
|
|
|
|
from calculate.core.client.function import create_obj
|
|
|
|
|
from calculate.lib.utils.files import readLinesFile, listDirectory, readFile
|
|
|
|
|
from PIL import Image
|
|
|
|
|
from calculate.lib.utils.files import readLinesFile, listDirectory, readFile, \
|
|
|
|
|
getProgPath, process, STDOUT
|
|
|
|
|
from calculate.lib.utils.colortext.palette import (
|
|
|
|
|
GuiPalette as WorkPalette)
|
|
|
|
|
from calculate.lib.utils.tools import Locker
|
|
|
|
@ -2650,39 +2650,64 @@ class ImageLabel(qt.QLabel):
|
|
|
|
|
|
|
|
|
|
style = ''
|
|
|
|
|
|
|
|
|
|
def resize_image(source_path, height, output_path):
|
|
|
|
|
convert_cmd = getProgPath('/usr/bin/convert')
|
|
|
|
|
identify_cmd = getProgPath('/usr/bin/identify')
|
|
|
|
|
def convert_image(source, res, target):
|
|
|
|
|
command = [convert_cmd, "-quality", "95",
|
|
|
|
|
source, "-resize", "%s^" % res,
|
|
|
|
|
"-strip", "-gravity", "center",
|
|
|
|
|
"-crop", "%s+0+0" % res, target]
|
|
|
|
|
convert = process(*command, stderr=STDOUT)
|
|
|
|
|
if convert.success():
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
def get_image_resolution(source):
|
|
|
|
|
identify = process(identify_cmd, "-format", "%w %h", source)
|
|
|
|
|
if identify.success():
|
|
|
|
|
swidth, _sep, sheight = identify.read().strip().partition(" ")
|
|
|
|
|
if swidth.isdigit() and sheight.isdigit():
|
|
|
|
|
return int(swidth), int(sheight)
|
|
|
|
|
return None, None
|
|
|
|
|
return None, None
|
|
|
|
|
cx, cy = get_image_resolution(source_path)
|
|
|
|
|
if cx and cy:
|
|
|
|
|
if convert_image(source_path, "{}x{}".format(cx, height),
|
|
|
|
|
output_path):
|
|
|
|
|
return (cx, cy)
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
if len(list_data) == 3:
|
|
|
|
|
fix_image_path = os.path.join(image_path, list_data[2])
|
|
|
|
|
if os.path.isfile(fix_image_path):
|
|
|
|
|
layout = qt.QHBoxLayout(self)
|
|
|
|
|
fix_image = qt.QLabel(self)
|
|
|
|
|
img = Image.open(fix_image_path)
|
|
|
|
|
img.thumbnail((img.size[0],height_image), Image.ANTIALIAS)
|
|
|
|
|
temp_file = os.path.join(save_path, '%s_fix' %filename)
|
|
|
|
|
img.save(temp_file, "JPEG")
|
|
|
|
|
os.chmod(temp_file, 0666)
|
|
|
|
|
fix_image.setFixedWidth(img.size[0])
|
|
|
|
|
fix_image.setStyleSheet("background-image: url(%s); " \
|
|
|
|
|
%temp_file)
|
|
|
|
|
layout.addWidget(fix_image)
|
|
|
|
|
layout.setContentsMargins(0,0,0,0)
|
|
|
|
|
layout.setAlignment(qt.Qt.AlignLeft)
|
|
|
|
|
sizes = resize_image(fix_image_path, height_image, temp_file)
|
|
|
|
|
if sizes:
|
|
|
|
|
os.chmod(temp_file, 0666)
|
|
|
|
|
fix_image.setFixedWidth(sizes[0])
|
|
|
|
|
fix_image.setStyleSheet("background-image: url(%s); " \
|
|
|
|
|
%temp_file)
|
|
|
|
|
layout.addWidget(fix_image)
|
|
|
|
|
layout.setContentsMargins(0,0,0,0)
|
|
|
|
|
layout.setAlignment(qt.Qt.AlignLeft)
|
|
|
|
|
|
|
|
|
|
elif len(list_data) > 3:
|
|
|
|
|
color1, color2 = list_data[-2:]
|
|
|
|
|
style = "background-color: qlineargradient(x1: 0, y1: 0, " + \
|
|
|
|
|
"x2: 0, y2: 1, stop: 0 %s, stop: 1 %s);" %(color1, color2)
|
|
|
|
|
|
|
|
|
|
im = Image.open(image)
|
|
|
|
|
im.thumbnail((im.size[0],height_image), Image.ANTIALIAS)
|
|
|
|
|
temp_file = os.path.join(save_path, '%s_temp' %filename)
|
|
|
|
|
im.save(temp_file, "JPEG")
|
|
|
|
|
os.chmod(temp_file, 0666)
|
|
|
|
|
style += "background-image: url(%s); " %temp_file
|
|
|
|
|
style += "background-attachment: fixed; "
|
|
|
|
|
style += "background-repeat: %s; " %repeat_dict[repeat.lower()]
|
|
|
|
|
style += "border-bottom: 1px solid #B8B3B0;"
|
|
|
|
|
self.setStyleSheet(style)
|
|
|
|
|
self.setFixedHeight(im.size[1])
|
|
|
|
|
sizes = resize_image(image, height_image, temp_file)
|
|
|
|
|
if sizes:
|
|
|
|
|
os.chmod(temp_file, 0666)
|
|
|
|
|
style += "background-image: url(%s); " %temp_file
|
|
|
|
|
style += "background-attachment: fixed; "
|
|
|
|
|
style += "background-repeat: %s; " %repeat_dict[repeat.lower()]
|
|
|
|
|
style += "border-bottom: 1px solid #B8B3B0;"
|
|
|
|
|
self.setStyleSheet(style)
|
|
|
|
|
self.setFixedHeight(height_image)
|
|
|
|
|
|
|
|
|
|
def get_view_params(client, method, step = None, expert = None, brief = None):
|
|
|
|
|
view_params = create_obj(client, method)
|
|
|
|
|