replace print outputs with outputs to qt

This commit is contained in:
Yannik Schmidt
2021-02-26 12:54:52 +01:00
parent 5113561a8c
commit eb6a9dedac
3 changed files with 24 additions and 12 deletions

View File

@@ -2,10 +2,12 @@
from config_parse import CFG
from PIL import Image
import math
def check_and_rotate(path):
import localization.de as localization
def check_and_rotate(path, qtTextBrowser):
img = Image.open(path)
div=abs(float(img.size[1])/float(img.size[0])-a4_aspect())/a4_aspect()*100
print("Seitenverhältnisabweichung zu A4: %.2f"%div+r'%')
qtTextBrowser.append(localization.info_divergence.format(div))
img.rotate(CFG("image_rotation"),expand=True).save(path.strip(".png")+"_rotated.png")
def a4_aspect():

View File

@@ -29,3 +29,11 @@ special_err_1 = "Zeitstempelanzahl stimmt nicht mit Datensatzzahl überein
warn_no_data = "Warnung, keine Daten für {}"
pg_request = "Downloading: {}"
info_ig_lines = "INFO: Ignoriere {} Zeilen ohne Daten am Anfang der Datei"
# plot.py
warn_empty_series = "WARN: Leere Datenserie (vielleicht falsches Start-/Enddatum?)"
err_empty_series = "ERR: Alle gewählten Datenserie sind leer."
info_output_path = "INFO: Output wird gespeichert nach: {}"
# imageutils.py
info_divergence = "INFO: Seitenverhältnisabweichung zu A4: {:.2f}%"

View File

@@ -17,13 +17,15 @@ import plot_graphutils
import imageutils
import timeutils
import localization.de as localization
def plot(datapoints, path=None, date1=None, date2=None, forcePath=False):
def plot(datapoints, path=None, date1=None, date2=None, forcePath=False, qtTextBrowser=None):
plotname = "" if CFG("name_of_plot") == "None" else CFG("name_of_plot")
tup = [None,None,timeutils.between_dates,plotname]
return __plot(tup, datapoints, path, date1, date2, forcePath)
return __plot(tup, datapoints, path, date1, date2, forcePath, qtTextBrowser)
def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False, qtTextBrowser=None):
NO_SERIES = True
x,y,ymin,ymax,unix_x,major_xticks = ( [] , [], -1 , -1 , [], [] )
lw = CFG("plot_line_width")
@@ -47,7 +49,7 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
# plot #
for x, y, g in tupelsToIterate:
if not x or not y or len(x) <= 0 or len(y) <= 0:
print("Warning: Empty series of data '%s' (wrong start/end time?)"%g.name)
qtTextBrowser.append(localization.warn_empty_series)
continue
else:
NO_SERIES = False
@@ -61,8 +63,8 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
lagacy_y_save = y
if NO_SERIES:
print("Error: no data, nothing to plot. cannot continue. exit.")
sys.exit(1)
qtTextBrowser.append(localization.err_empty_series)
raise ValueError(localization.err_empty_series)
## GRID ##
plot_graphutils.general_background_setup(tup, ymin, ymax, legacy_x_save)
@@ -72,7 +74,7 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
path = open_file()
if not forcePath:
pic_path = output_path(path, date1, date2)
pic_path = output_path(path, date1, date2, qtTextBrowser)
else:
pic_path = path
@@ -87,11 +89,11 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
tup[FIGURE].savefig(pic_path,dpi=DPI,pad_inches=0.1,bbox_inches='tight',transparent=CFG("transparent_background"))
### do operations on the finished png ###
imageutils.check_and_rotate(pic_path)
imageutils.check_and_rotate(pic_path, qtTextBrowser)
return pic_path
def output_path(path,date1,date2):
def output_path(path, date1, date2, qtTextBrowser):
if date1 != None and date2 == None:
pic_path = path + "-nach-%s"%date1.strftime("%d.%m.%y") + ".png"
elif date1 == None and date2 != None:
@@ -100,5 +102,5 @@ def output_path(path,date1,date2):
pic_path = path + "-alles" + ".png"
else:
pic_path = path + "-%s_to_%s"%(date1.strftime("%d.%m.%y"),date2.strftime("%d.%m.%y")) + ".png"
print("Output wird gespeichert nach: %s"%str(pic_path))
qtTextBrowser.append(localization.info_output_path.format(pic_path))
return pic_path