-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecipe_dialog.py
116 lines (88 loc) · 3.44 KB
/
recipe_dialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import PyQt5
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5.QtCore import QFile
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtWidgets import QComboBox
from PyQt5.QtWidgets import QListWidget
from PyQt5.QtWidgets import QListWidgetItem
from ui import recipe_ui
import io
import os
from os import path
import sys
import glob
import zips
import recipe
import settings
import main_dialog
import zipfile
from zipfile import ZipFile
import subprocess
from subprocess import check_call
from PIL import Image
from PIL import ImageQt
settings.loadConfiguration()
class RecipeDialog(QtWidgets.QDialog, recipe_ui.Ui_Dialog):
def __init__(self, app, selectedRecipe):
super(RecipeDialog, self).__init__()
recipe_ui.Ui_Dialog.setupUi(self, self)
self.zipPackages = []
self.loadedRecipe = selectedRecipe
self.label_1.setScaledContents(True)
self.zipPackages = [os.path.basename(x)
for x in glob.glob(settings.localPath
+ settings.zipsFolder + '*.zip')]
self.combo_box_1.addItems(self.zipPackages)
self.combo_box_1.currentIndexChanged[str].connect(self.changeRecipe)
self.button_box_1.accepted.connect(self.accept)
self.button_box_1.rejected.connect(self.reject)
self.setFont(QFont(settings.sets['user']['font-name'],
int(settings.sets['user']['font-size'])))
self.showPreviewOfRecipe()
def accept(self):
self.loadedRecipe = str(settings.localPath + settings.zipsFolder
+ str(self.combo_box_1.currentText()))
print("Current loaded recipe: " + self.loadedRecipe) # for debugging
super(RecipeDialog, self).accept()
def reject(self):
super(RecipeDialog, self).reject()
def getRecipe(self):
return self.loadedRecipe
def setRecipe(self):
self.ui.combo_box_1.setCurrentText(str(self.loadedRecipe))
def showPreviewOfRecipe(self):
self.path = os.path.dirname(__file__)
print(self.path + settings.zipsFolder
+ str(self.combo_box_1.currentText()))
zippedImgs = ZipFile(self.path + settings.zipsFolder
+ str(self.combo_box_1.currentText()))
self.label_2.setText("Brak podglądu")
self.label_2.setScaledContents(True)
for file_in_zip in zippedImgs.namelist():
if ("preview" in file_in_zip):
print("Found image: ", file_in_zip, " -- ")
# for debugging
data = zippedImgs.read(file_in_zip)
# read bits to variable
dataEnc = io.BytesIO(data)
# save bytes like io
dataImgEnc = Image.open(dataEnc)
# convert bytes on Image file
qimage = ImageQt.ImageQt(dataImgEnc)
# create QtImage from Image
pixmap = QtGui.QPixmap.fromImage(qimage)
# convert QtImage to QPixmap
print(pixmap) # for debugging
self.label_2.setPixmap(pixmap)
def changeRecipe(self):
print(self.combo_box_1.currentText())
loadedRecipe = self.combo_box_1.currentText()
self.showPreviewOfRecipe()