class IngredientsDialogue(QDialog, QWidget): """Class representing second window of program which displays ingredients and allows users to input ingredients and specify a maximum time for recipes displayed. """ def __init__(self) -> None: """Initialize an instance of the ingredients window """ super().__init__() # Set up the screen background self.recipes_dialogue = None self.setStyleSheet("background-color: rgb(240, 225, 204)") self.setWindowIcon(QIcon('visuals/L_C_Icon.PNG')) # Initialized all widgets needed self.lbl_list = QLabel("Your List", self) self.lbl_list.setFont(QFont('Georgia', 12, QFont.Bold)) self.lbl_list.setStyleSheet('color: rgb(211, 104, 80)') self.lbl_list.setFixedSize(200, 25) self.lbl_list.move(80, 100) self.lbl_max_ingredients = QLabel("(10 ingredients max.)", self) self.lbl_max_ingredients.setFont(QFont('Georgia', 9)) self.lbl_max_ingredients.setStyleSheet('color: rgb(35, 87, 77)') self.lbl_max_ingredients.move(57, 125) self.lbl_max_ingredients.resize(200, 20) self.lbl_max_time = QLabel("Maximum cooking time in minutes (optional):", self) self.lbl_max_time.setFont(QFont('Georgia', 12, QFont.Bold)) self.lbl_max_time.setStyleSheet('color: rgb(211, 104, 80)') self.lbl_max_time.setFixedSize(250, 80) self.lbl_max_time.setWordWrap(True) self.lbl_all_ingredients = QLabel("All Ingredients", self) self.lbl_all_ingredients.setFont(QFont('Georgia', 12, QFont.Bold)) self.lbl_all_ingredients.setStyleSheet('color: rgb(211, 104, 80)') self.lbl_all_ingredients.setFixedSize(200, 25) self.lbl_all_ingredients.move(375, 100) self.lbl_select_items = QLabel("Select your ingredients!", self) self.lbl_select_items.setFont(QFont('Georgia', 17, QFont.Bold)) self.lbl_select_items.setStyleSheet('color: rgb(210, 146, 68)') self.lbl_select_items.setFixedSize(400, 40) self.lbl_select_items.move(180, 40) self.time_selected = QSpinBox(self) self.time_selected.setStyleSheet('color: rgb(35, 87, 77)') self.time_selected.setFont(QFont('Georgia', 10)) self.time_selected.setRange(0, 50000) self.all_ingredients = QListWidget() self.all_ingredients.setFont(QFont('Georgia', 10)) self.all_ingredients.setStyleSheet('color: rgb(35, 87, 77)') self.line_edit = None self.user_input = None self.disabled_color2 = QGraphicsColorizeEffect() self.disabled_color2.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color3 = QGraphicsColorizeEffect() self.disabled_color3.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color4 = QGraphicsColorizeEffect() self.disabled_color4.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color5 = QGraphicsColorizeEffect() self.disabled_color5.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color6 = QGraphicsColorizeEffect() self.disabled_color6.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color7 = QGraphicsColorizeEffect() self.disabled_color7.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color8 = QGraphicsColorizeEffect() self.disabled_color8.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color9 = QGraphicsColorizeEffect() self.disabled_color9.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color10 = QGraphicsColorizeEffect() self.disabled_color10.setColor(QColor.fromRgb(240, 225, 204)) # Sets up all the line edits self.ingredient1 = QLineEdit(self) self.ingredient1.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient1.setFont(QFont('Georgia', 10)) self.ingredient2 = QLineEdit(self) self.ingredient2.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient2.setFont(QFont('Georgia', 10)) self.ingredient2.setGraphicsEffect(self.disabled_color2) self.ingredient3 = QLineEdit(self) self.ingredient3.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient3.setFont(QFont('Georgia', 10)) self.ingredient3.setGraphicsEffect(self.disabled_color3) self.ingredient4 = QLineEdit(self) self.ingredient4.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient4.setFont(QFont('Georgia', 10)) self.ingredient4.setGraphicsEffect(self.disabled_color4) self.ingredient5 = QLineEdit(self) self.ingredient5.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient5.setFont(QFont('Georgia', 10)) self.ingredient5.setGraphicsEffect(self.disabled_color5) self.ingredient6 = QLineEdit(self) self.ingredient6.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient6.setFont(QFont('Georgia', 10)) self.ingredient6.setGraphicsEffect(self.disabled_color6) self.ingredient7 = QLineEdit(self) self.ingredient7.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient7.setFont(QFont('Georgia', 10)) self.ingredient7.setGraphicsEffect(self.disabled_color7) self.ingredient8 = QLineEdit(self) self.ingredient8.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient8.setFont(QFont('Georgia', 10)) self.ingredient8.setGraphicsEffect(self.disabled_color8) self.ingredient9 = QLineEdit(self) self.ingredient9.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient9.setFont(QFont('Georgia', 10)) self.ingredient9.setGraphicsEffect(self.disabled_color9) self.ingredient10 = QLineEdit(self) self.ingredient10.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient10.setFont(QFont('Georgia', 10)) self.ingredient10.setGraphicsEffect(self.disabled_color10) # Gets all the ingredients from the data self.ingredient = [self.ingredient1, self.ingredient2, self.ingredient3, self.ingredient4, self.ingredient5, self.ingredient6, self.ingredient7, self.ingredient8, self.ingredient9, self.ingredient10] self.disabled_color = [self.disabled_color2, self.disabled_color3, self.disabled_color4, self.disabled_color5, self.disabled_color6, self.disabled_color7, self.disabled_color8, self.disabled_color9, self.disabled_color10] data = data_reading.read_recipes(data_reading.RECIPES_FILE) data_reading.clean_ingredients(data) self.clean = sorted(list(data_reading.get_ingredients(data))) for i in range(len(self.clean)): self.all_ingredients.insertItem(i, self.clean[i]) # Sets up the screen with all the needed elements self.title = "Look and Cook" self.left = 500 self.top = 200 self.width = 700 self.height = 700 self.init_window() self.center() self.setFixedSize(700, 700) def init_window(self) -> None: """Open the second window on the user's screen with the provided dimensions. """ # Sets up screen self.setGeometry(self.left, self.top, self.width, self.height) self.setWindowTitle(self.title) # Moves the labels to the right position self.lbl_max_time.move(250, self.height - 230) self.time_selected.move(550, self.height - 200) # Creates an autocomplete system to use when typing the ingredients completer = QCompleter(sorted(self.clean)) completer.setFilterMode(Qt.MatchContains) completer.setCaseSensitivity(Qt.CaseInsensitive) # Places all the line edits on the window self.ingredient1.setCompleter(completer) self.ingredient1.move(50, 160) self.ingredient1.setFixedSize(160, 30) height = 200 for x in self.ingredient[1:]: x.setCompleter(completer) x.move(50, height) x.setFixedSize(160, 30) x.setDisabled(True) height += 40 # Places list in the middle on the window vbox = QVBoxLayout() vbox.setContentsMargins(250, 0, 120, 120) self.all_ingredients.setFixedSize(400, 300) vbox.addWidget(self.all_ingredients) self.all_ingredients.itemDoubleClicked.connect(self.add_ingredient) self.setLayout(vbox) # Creates an add_item item button add_item = QPushButton("Add", self) add_item.setGeometry((self.width // 2) - 50, self.height // 2 + 200, 70, 70) add_item.move(50, self.height - 120) add_item.setFont(QFont('Georgia', 8, QFont.Bold)) add_item.setStyleSheet('border-radius: 35; background-color: rgb(211, 104, 80); ' 'color: rgb(240, 225, 204)') add_item.clicked.connect(self.add_item) # Creates an remove_item item button remove_item = QPushButton("Remove", self) remove_item.setGeometry((self.width // 2) - 50, self.height // 2 + 200, 70, 70) remove_item.move(140, self.height - 120) remove_item.setFont(QFont('Georgia', 8, QFont.Bold)) remove_item.setStyleSheet('border-radius: 35; background-color: rgb(211, 104, 80); ' 'color: rgb(240, 225, 204)') remove_item.clicked.connect(self.remove_item) # Creates an clear list item button clear_list = QPushButton("Clear List", self) clear_list.setGeometry((self.width // 2) - 50, self.height // 2 + 200, 190, 70) clear_list.move(250, self.height - 120) clear_list.setFont(QFont('Georgia', 12, weight=QtGui.QFont.Bold)) clear_list.setStyleSheet('border-radius: 35; background-color: rgb(211, 104, 80); ' 'color: rgb(240, 225, 204)') clear_list.clicked.connect(self.clear_list) # Creates a submit button submit = QPushButton("Find Recipes", self) submit.setGeometry((self.width // 2) - 50, self.height // 2 + 200, 190, 70) submit.move(460, self.height - 120) submit.setFont(QFont('Georgia', 12, weight=QtGui.QFont.Bold)) submit.setStyleSheet('border-radius: 35; background-color: rgb(210, 146, 68); ' 'color: rgb(240, 225, 204)') submit.clicked.connect(self.submit) # Displays everything on the window self.show() def center(self) -> None: """Function to center second window on the provided desktop screen. """ qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) # frameGm = self.frameGeometry() # screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos()) # centerPoint = QApplication.desktop().screenGeometry(screen).center() # frameGm.moveCenter(centerPoint) # self.move(frameGm.topLeft()) resolution = QDesktopWidget().screenGeometry() self.move((resolution.width() / 2) - (self.frameSize().width() / 2), (resolution.height() / 2) - (self.frameSize().height() / 2)) def add_item(self) -> None: """Enables search box for user to input a new ingredient.""" for x in range(len(self.ingredient) - 1, 0, -1): if self.ingredient[x - 1].isEnabled(): self.ingredient[x - 1].setCursorPosition(0) self.ingredient[x].setDisabled(False) self.disabled_color[x - 1].setEnabled(False) def remove_item(self) -> None: """Removes the last ingredient of the list.""" for x in range(len(self.ingredient))[::-1][:-1]: if self.ingredient[x].isEnabled(): self.ingredient[x].setDisabled(True) self.ingredient[x].clear() self.disabled_color[x - 1].setEnabled(True) return def clear_list(self) -> None: """Clears all ingredients in user's list.""" for x in self.ingredient: x.clear() if x != self.ingredient1: x.setDisabled(True) self.time_selected.setValue(0) def add_ingredient(self, item: QListWidgetItem) -> None: """Add the double clicked ingredient to the ingredients list.""" for x in self.ingredient: if x.isEnabled() and x.text() == '': x.setText(item.text()) return def submit(self) -> None: """Create button to submit user input and proceed to the third page, which displays the recipes. If there is an ingredient listed twice in the input, raise an error pop up that says "Ingredient [duplicated ingredient] appears more than once" or "Ingredients [duplicated ingredients] appear more than once" if there are multiple duplicated ingredients. If there are remaining unfilled ingredient boxes, raise an error pop up that says "Did not fill all the needed information". If the user has inputted an invalid ingredient that does not appear in the list of ingredients at the center, raise an error pop up that says "The ingredient [invalid ingredient] is invalid" or "The ingredients [invalid ingredients] are invalid" if there are more than 1 invalid ingredients. """ ingredients_set = set() duplicates = '' count = 0 for x in self.ingredient: if x.isEnabled() and x.text() in ingredients_set: duplicates += x.text() count += 1 else: ingredients_set.add(x.text()) if len(duplicates) != 0: # This occurs when the user inputs the same ingredient twice contains_duplicates = QMessageBox() contains_duplicates.setWindowTitle("Error! - Duplicates") contains_duplicates.setWindowIcon(QIcon('visuals/L&C Icon.PNG')) if count == 1: # Only one ingredient appears more than once contains_duplicates.setText( f'Sorry, the ingredient {duplicates} appears more than once.') else: # Muliple ingredients contains_duplicates.setText( f'Sorry, the ingredients {duplicates} appear more than once.') contains_duplicates.setIcon(QMessageBox.Critical) x = contains_duplicates.exec_() elif any([y.isEnabled() and y.text() == '' for y in self.ingredient]): # Checks if there are any empty textboxes warning = QMessageBox() warning.setWindowTitle("Error!") warning.setWindowIcon(QIcon('visuals/L&C Icon.PNG')) warning.setText('Sorry, you did not fill all the necessary information. Please check ' 'that your ingredients list is correct and there are no empty spots.') warning.setIcon(QMessageBox.Critical) x = warning.exec_() elif not all([z.text() in self.clean for z in self.ingredient if z.isEnabled()]): # Checks if there are any items that are not valid invalid_ingredient = '' count = 0 for x in self.ingredient: if x.text() not in self.clean and x.isEnabled(): invalid_ingredient += x.text() + ', ' count += 1 invalid_ingredient = invalid_ingredient.strip(', ') invalid = QMessageBox() invalid.setWindowTitle("Error! - Invalid Ingredient") invalid.setWindowIcon(QIcon('visuals/L&C Icon.PNG')) if count == 1: # One ingredient invalid.setText(f"Sorry, the ingredient '{invalid_ingredient}' is invalid.") else: # More than one invalid.setText(f"Sorry, the ingredients '{invalid_ingredient}' are invalid.") invalid.setIcon(QMessageBox.Critical) x = invalid.exec_() else: # If everything is correct self.hide() user_input = [u.text() for u in self.ingredient if u.isEnabled()] # Goes to the next dialogue self.recipes_dialogue = \ RecipesDialogue(user_input, int(self.time_selected.text()), self) self.recipes_dialogue.show()
def window(): app = QApplication(sys.argv) w = QWidget() w.setGeometry(500,10,300,500) font = QFont() font.setFamily("Calibri") w.setFont(font) b = QLabel(w) b.setText("Basic AF!") colorize = QGraphicsColorizeEffect() colorize.setColor(QColor(0,0,192)) b.setGraphicsEffect(colorize) b.move(120,10) button = QPushButton(w) button.setText("Start cam") button.move(10,30) button.clicked.connect(on_click_main) button_capture = QPushButton(w) button_capture.setText("Save Please") button_capture.move(170,30) button_capture.clicked.connect(on_click_save) button_gray = QPushButton(w) button_gray.setText("50 shades of Grey!") button_gray.move(70,80) button_gray.clicked.connect(on_click_gray) button_mirror = QPushButton(w) button_mirror.setText("Mirror mirror on the wall!") button_mirror.move(70,110) button_mirror.clicked.connect(on_click_mirror) button_random = QPushButton(w) button_random.setText("That's so Random!") button_random.move(70,140) button_random.clicked.connect(on_click_random) button_halfNhalf = QPushButton(w) button_halfNhalf.setText("Invert Half") button_halfNhalf.move(70, 170) button_halfNhalf.clicked.connect(on_click_halfnhalf) button_border = QPushButton(w) button_border.setText("Diamond Border") button_border.move(70,200) button_border.clicked.connect(on_click_border_pattern) button_border = QPushButton(w) button_border.setText("Smile please!") button_border.move(70,230) button_border.clicked.connect(on_click_smile) w.setWindowTitle("My App") w.show() sys.exit(app.exec_())
def __init__(self, playerName, playerCar , keybed, width): self.playerName = playerName self.Car = playerCar self.qpix = QPixmap(('PNG/Car_' + playerCar + '_Main_Positions/Car_' + playerCar + '_01')) self.qpix = self.qpix.scaled(width, width * 1.5) self.keybed = keybed super(Player, self).__init__(self.qpix) self.lives = 3 self.effect = QGraphicsColorizeEffect() self.effect.setColor(QColor(189, 189, 189)) self.effect.setStrength(0.5) self.effect.setEnabled(False) self.setGraphicsEffect(self.effect) self.key_notifier = KeyNotifier() self.key_notifier.key_signal.connect(self.movePlayer) self.safeTimer = QTimer() self.safeTimer.timeout.connect(self.makeKillable) self.killable = True self.safeTimerRemaining = 0 self.touchesplayer = False self.notMoving = QTimer() self.notMoving.timeout.connect(self.enableMoving) self.canMove = True self.notMovingRemaining = 0 self.networkcode = None
class MainWindow(QWidget): def __init__(self): super().__init__() self.resize(500, 500) self.initUi() def initUi(self): self.color = QGraphicsColorizeEffect() self.color.setColor(QColor('black')) self.frame = QFrame(self) self.frame.setGeometry(100, 100, 100, 100) self.frame.setStyleSheet('background-color: black;') self.frame.setGraphicsEffect(self.color) self.button = QPushButton(self) self.button.setGeometry(250, 100, 100, 100) self.button.setText('Анимация') self.button.clicked.connect(self.Animation) def Animation(self): self.anim = QPropertyAnimation(self.color, b"color") self.anim.setDuration(3000) self.anim.setStartValue(QColor('black')) self.anim.setEndValue(QColor('red')) self.anim.start()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setupUi(self) self.textEdit.textChanged.connect(self.paintText) self.textAngle.valueChanged.connect(self.paintText) self.textOpacity.valueChanged.connect(self.paintText) self.fontSize.valueChanged.connect(self.paintText) self.tilingBox.toggled.connect(self.paintText) self.staggeredBox.toggled.connect(self.paintText) self.boldBox.toggled.connect(self.paintText) self.widthSpacing.valueChanged.connect(self.paintText) self.heightSpacing.valueChanged.connect(self.paintText) self.color = QColor(0, 0, 0) effect = QGraphicsColorizeEffect() effect.setColor(self.color) self.colorButton.setGraphicsEffect(effect) self.font = QFont("Serif", 32) self.fontButton.setText(self.font.family()) self.images = [] self.lastPath = Path.cwd() self.zoom = Decimal(1)
def itemChange(self, change, value): if change == QGraphicsItem.ItemEnabledChange: if value: self.setGraphicsEffect(None) else: effect = QGraphicsColorizeEffect(self) effect.setColor(QColor(20, 20, 20)) self.setGraphicsEffect(effect) return super().itemChange(change, value)
def itemChange(self, change, value): if change == QGraphicsObject.ItemSelectedChange: if value: effect = QGraphicsColorizeEffect(self) effect.setColor(QColor(0xcc, 0x00, 0x00)) self.setGraphicsEffect(effect) else: self.setGraphicsEffect(None) return super().itemChange(change, value)
def select_color(self): self.color = QColorDialog.getColor() label = QLabel(self) label.setGeometry(100, 100, 200, 60) label.setWordWrap(True) label.setText(str(self.color)) color_picker = QGraphicsColorizeEffect(self) color_picker.setColor(self.color) label.setGraphicsEffect(color_picker) self.color_selector.setStyleSheet( f'background-color: {self.color.name()};')
def __updateIcon(self): """ Private slot to update the icon. """ if self._testCurrentPageWebAttribute( QWebEngineSettings.JavascriptEnabled): self.setGraphicsEffect(None) else: effect = QGraphicsColorizeEffect(self) effect.setColor(Qt.gray) self.setGraphicsEffect(effect)
def on_colorButton_clicked(self): new = QColorDialog.getColor(self.color, self) if not new.isValid(): return self.color = new effect = QGraphicsColorizeEffect() effect.setColor(self.color) self.colorButton.setGraphicsEffect(effect) self.paintText()
def __init__(self, icon, name, parent): QGraphicsSvgItem.__init__(self) self.setParentItem(parent) self.m_renderer = None self.p_size = QRectF(0, 0, 0, 0) self.m_colorFX = QGraphicsColorizeEffect(self) self.m_colorFX.setColor(canvas.theme.box_text.color()) self.setGraphicsEffect(self.m_colorFX) self.setIcon(icon, name)
def initUi(self): self.color = QGraphicsColorizeEffect() self.color.setColor(QColor('black')) self.frame = QFrame(self) self.frame.setGeometry(100, 100, 100, 100) self.frame.setStyleSheet('background-color: black;') self.frame.setGraphicsEffect(self.color) self.button = QPushButton(self) self.button.setGeometry(250, 100, 100, 100) self.button.setText('Анимация') self.button.clicked.connect(self.Animation)
def colorize_effect(self): print('colorize effect') sel = self.scene().selectedItems() for i in range(len(sel)): self.effect = QGraphicsColorizeEffect(self) self.effect.setColor(QColor(0, 0, 192)) sel[i].setGraphicsEffect(self.effect)
def QPixmapFactory(image): font = image.font if font is None: return None layer = image.layer images = font.images if image.fileName not in images: return None imageColor = image.color data = images[image.fileName] pixmap = QPixmap() pixmap.loadFromData(data) if imageColor is not None: colorEffect = QGraphicsColorizeEffect() colorEffect.setColor(colorToQColor(imageColor)) colorEffect.setStrength(.8) return applyEffectToPixmap(pixmap, colorEffect) return pixmap
def QPixmapFactory(image): font = image.font if font is None: return None layer = image.layer images = font.images if image.fileName not in images: return None imageColor = image.color # TODO: are we really doing this? if imageColor is None: imageColor = layer.color data = images[image.fileName] pixmap = QPixmap() pixmap.loadFromData(data) if imageColor is not None: colorEffect = QGraphicsColorizeEffect() colorEffect.setColor(imageColor) return applyEffectToPixmap(pixmap, colorEffect) return pixmap
def color_animation(widget: QWidget, color=Qt.red): effect = QGraphicsColorizeEffect(widget) widget.setGraphicsEffect(effect) widget.animation = QPropertyAnimation(effect, b'color') widget.animation.setStartValue(QColor(color)) widget.animation.setEndValue(QColor(Qt.black)) widget.animation.setLoopCount(1) widget.animation.setDuration(1500) widget.animation.start()
def keyPressEvent(self, e): if e.key() == Qt.Key_Up: self.rotate(30) elif e.key() == Qt.Key_Down: self.rotate(-30) elif e.key() == Qt.Key_Right: self.currentSlide += 1 if self.currentSlide >= len(self.slides): #Loop to beginning self.currentSlide = 0 self.text.setPlainText(self.slides[self.currentSlide]) self.adjustText() self.centerText() elif e.key() == Qt.Key_Left: self.currentSlide -= 1 if self.currentSlide < 0: #Loop to end self.currentSlide = len(self.slides) - 1 self.text.setPlainText(self.slides[self.currentSlide]) self.adjustText() self.centerText() elif e.key() == Qt.Key_B: shadow = QGraphicsBlurEffect() shadow.setBlurRadius(self.shadowSize) self.text.setGraphicsEffect(shadow) elif e.key() == Qt.Key_S: shadow = QGraphicsDropShadowEffect() shadow.setBlurRadius(self.shadowSize) shadow.setOffset(self.shadowOffset) self.text.setGraphicsEffect(shadow) elif e.key() == Qt.Key_C: self.text.setGraphicsEffect(QGraphicsColorizeEffect()) elif e.key() == Qt.Key_O: self.text.setGraphicsEffect(QGraphicsOpacityEffect()) elif e.key() == Qt.Key_N: self.text.setGraphicsEffect(None)
def __init__(self,*args,**kwargs): super().__init__(*args,**kwargs) kwargs = self._args(*args,**kwargs) redim = kwargs.get("redim",None) posi = kwargs.get("posi",None) size = kwargs.get("size",None) anim = kwargs.get("anim",True) w = 5 if redim == "w": self.resize(size,self.height()) if redim == "h": self.resize(self.width(),size) self.move(posi[0],posi[1]) ef = QGraphicsColorizeEffect(self) self.setGraphicsEffect(ef) self.__animation = QPropertyAnimation(ef,b"color") self.__animation.setDuration(2000) self.__animation.setKeyValueAt(0,QColor(0, 255, 0)) self.__animation.setKeyValueAt(0.5,QColor(255, 0, 0)) self.__animation.setKeyValueAt(1,QColor(0, 255, 0)) self.__animation.setLoopCount(-1) if anim: self.__animation.start() self.show()
def QPixmapFactory(image): font = image.font if font is None: return None _ = image.layer images = font.images if image.fileName not in images: return None imageColor = image.color data = images[image.fileName] pixmap = QPixmap() pixmap.loadFromData(data) if imageColor is not None: colorEffect = QGraphicsColorizeEffect() colorEffect.setColor(colorToQColor(imageColor)) colorEffect.setStrength(0.8) return applyEffectToPixmap(pixmap, colorEffect) return pixmap
class CanvasSvgIcon(QGraphicsSvgItem): def __init__(self, icon_type, name, port_mode, parent): QGraphicsSvgItem.__init__(self) self.setParentItem(parent) self.m_renderer = None self.p_size = QRectF(4, 4, 24, 24) self.m_colorFX = QGraphicsColorizeEffect(self) self.m_colorFX.setColor(canvas.theme.box_text.color()) #self.setGraphicsEffect(self.m_colorFX) self.setIcon(icon_type, name, port_mode) def setIcon(self, icon, name, port_mode): name = name.lower() icon_path = "" if icon == ICON_APPLICATION: self.p_size = QRectF(3, 2, 19, 18) if "audacious" in name: icon_path = ":/scalable/pb_audacious.svg" self.p_size = QRectF(5, 4, 16, 16) elif "clementine" in name: icon_path = ":/scalable/pb_clementine.svg" self.p_size = QRectF(5, 4, 16, 16) elif "distrho" in name: icon_path = ":/scalable/pb_distrho.svg" self.p_size = QRectF(5, 4, 16, 16) elif "jamin" in name: icon_path = ":/scalable/pb_jamin.svg" self.p_size = QRectF(5, 3, 16, 16) elif "mplayer" in name: icon_path = ":/scalable/pb_mplayer.svg" self.p_size = QRectF(5, 4, 16, 16) elif "vlc" in name: icon_path = ":/scalable/pb_vlc.svg" self.p_size = QRectF(5, 3, 16, 16) else: icon_path = ":/scalable/pb_generic.svg" self.p_size = QRectF(4, 4, 24, 24) elif icon == ICON_HARDWARE: if name == "a2j": icon_path = ":/scalable/DIN-5.svg" self.p_size = QRectF(4, 4, 24, 24) else: if port_mode & PORT_MODE_INPUT: icon_path = ":/scalable/audio-headphones.svg" elif port_mode & PORT_MODE_OUTPUT: icon_path = ":/scalable/microphone.svg" else: icon_path = ":/scalable/pb_hardware.svg" self.p_size = QRectF(4, 4, 24, 24) elif icon == ICON_DISTRHO: icon_path = ":/scalable/pb_distrho.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_FILE: icon_path = ":/scalable/pb_file.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_PLUGIN: icon_path = ":/scalable/pb_plugin.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_LADISH_ROOM: # TODO - make a unique ladish-room icon icon_path = ":/scalable/pb_hardware.svg" self.p_size = QRectF(5, 2, 16, 16) elif icon == ICON_INTERNAL: icon_path = ":/scalable/" + name self.p_size = QRectF(4, 4, 24, 24) else: self.p_size = QRectF(0, 0, 0, 0) qCritical("PatchCanvas::CanvasIcon.setIcon(%s, %s) - unsupported icon requested" % ( icon2str(icon), name.encode())) return self.m_renderer = QSvgRenderer(icon_path, canvas.scene) self.setSharedRenderer(self.m_renderer) self.update() def update_zoom(self, scale: float): pass def type(self): return CanvasIconType def is_null(self)->bool: return False def align_at(self, x_pos: int): self.p_size = QRectF(x_pos, 4, 24, 24) def align_right(self, width: int): self.p_size = QRectF(width - 28, 4, 24, 24) def boundingRect(self): return self.p_size def paint(self, painter, option, widget): if not self.m_renderer: QGraphicsSvgItem.paint(self, painter, option, widget) return painter.save() painter.setRenderHint(QPainter.Antialiasing, False) painter.setRenderHint(QPainter.TextAntialiasing, False) self.m_renderer.render(painter, self.p_size) painter.restore()
def set_game_state(self, widget, state): # Grey-out color effect effect = QGraphicsColorizeEffect(widget) effect.setColor(QColor('grey')) widget.setGraphicsEffect(effect) if state == 'disable': effect.setStrength(1.0) elif state == 'enable': effect.setStrength(0.0) elif state == 'select': effect.setColor(QColor('white')) effect.setStrength(0.7) else: pass
class CanvasIcon(QGraphicsSvgItem): def __init__(self, icon, name, parent): QGraphicsSvgItem.__init__(self) self.setParentItem(parent) self.m_renderer = None self.p_size = QRectF(0, 0, 0, 0) self.m_colorFX = QGraphicsColorizeEffect(self) self.m_colorFX.setColor(canvas.theme.box_text.color()) self.setGraphicsEffect(self.m_colorFX) self.setIcon(icon, name) def setIcon(self, icon, name): name = name.lower() icon_path = "" if icon == ICON_APPLICATION: self.p_size = QRectF(3, 2, 19, 18) if "audacious" in name: icon_path = ":/scalable/pb_audacious.svg" self.p_size = QRectF(5, 4, 16, 16) elif "clementine" in name: icon_path = ":/scalable/pb_clementine.svg" self.p_size = QRectF(5, 4, 16, 16) elif "distrho" in name: icon_path = ":/scalable/pb_distrho.svg" self.p_size = QRectF(5, 4, 16, 16) elif "jamin" in name: icon_path = ":/scalable/pb_jamin.svg" self.p_size = QRectF(5, 3, 16, 16) elif "mplayer" in name: icon_path = ":/scalable/pb_mplayer.svg" self.p_size = QRectF(5, 4, 16, 16) elif "vlc" in name: icon_path = ":/scalable/pb_vlc.svg" self.p_size = QRectF(5, 3, 16, 16) else: icon_path = ":/scalable/pb_generic.svg" self.p_size = QRectF(4, 3, 16, 16) elif icon == ICON_HARDWARE: icon_path = ":/scalable/pb_hardware.svg" self.p_size = QRectF(5, 2, 16, 16) elif icon == ICON_DISTRHO: icon_path = ":/scalable/pb_distrho.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_FILE: icon_path = ":/scalable/pb_file.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_PLUGIN: icon_path = ":/scalable/pb_plugin.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_LADISH_ROOM: # TODO - make a unique ladish-room icon icon_path = ":/scalable/pb_hardware.svg" self.p_size = QRectF(5, 2, 16, 16) else: self.p_size = QRectF(0, 0, 0, 0) qCritical("PatchCanvas::CanvasIcon.setIcon(%s, %s) - unsupported icon requested" % ( icon2str(icon), name.encode())) return self.m_renderer = QSvgRenderer(icon_path, canvas.scene) self.setSharedRenderer(self.m_renderer) self.update() def type(self): return CanvasIconType def boundingRect(self): return self.p_size def paint(self, painter, option, widget): if not self.m_renderer: QGraphicsSvgItem.paint(self, painter, option, widget) return painter.save() painter.setRenderHint(QPainter.Antialiasing, False) painter.setRenderHint(QPainter.TextAntialiasing, False) self.m_renderer.render(painter, self.p_size) painter.restore()
def __init__(self) -> None: """Initialize an instance of the ingredients window """ super().__init__() # Set up the screen background self.recipes_dialogue = None self.setStyleSheet("background-color: rgb(240, 225, 204)") self.setWindowIcon(QIcon('visuals/L_C_Icon.PNG')) # Initialized all widgets needed self.lbl_list = QLabel("Your List", self) self.lbl_list.setFont(QFont('Georgia', 12, QFont.Bold)) self.lbl_list.setStyleSheet('color: rgb(211, 104, 80)') self.lbl_list.setFixedSize(200, 25) self.lbl_list.move(80, 100) self.lbl_max_ingredients = QLabel("(10 ingredients max.)", self) self.lbl_max_ingredients.setFont(QFont('Georgia', 9)) self.lbl_max_ingredients.setStyleSheet('color: rgb(35, 87, 77)') self.lbl_max_ingredients.move(57, 125) self.lbl_max_ingredients.resize(200, 20) self.lbl_max_time = QLabel("Maximum cooking time in minutes (optional):", self) self.lbl_max_time.setFont(QFont('Georgia', 12, QFont.Bold)) self.lbl_max_time.setStyleSheet('color: rgb(211, 104, 80)') self.lbl_max_time.setFixedSize(250, 80) self.lbl_max_time.setWordWrap(True) self.lbl_all_ingredients = QLabel("All Ingredients", self) self.lbl_all_ingredients.setFont(QFont('Georgia', 12, QFont.Bold)) self.lbl_all_ingredients.setStyleSheet('color: rgb(211, 104, 80)') self.lbl_all_ingredients.setFixedSize(200, 25) self.lbl_all_ingredients.move(375, 100) self.lbl_select_items = QLabel("Select your ingredients!", self) self.lbl_select_items.setFont(QFont('Georgia', 17, QFont.Bold)) self.lbl_select_items.setStyleSheet('color: rgb(210, 146, 68)') self.lbl_select_items.setFixedSize(400, 40) self.lbl_select_items.move(180, 40) self.time_selected = QSpinBox(self) self.time_selected.setStyleSheet('color: rgb(35, 87, 77)') self.time_selected.setFont(QFont('Georgia', 10)) self.time_selected.setRange(0, 50000) self.all_ingredients = QListWidget() self.all_ingredients.setFont(QFont('Georgia', 10)) self.all_ingredients.setStyleSheet('color: rgb(35, 87, 77)') self.line_edit = None self.user_input = None self.disabled_color2 = QGraphicsColorizeEffect() self.disabled_color2.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color3 = QGraphicsColorizeEffect() self.disabled_color3.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color4 = QGraphicsColorizeEffect() self.disabled_color4.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color5 = QGraphicsColorizeEffect() self.disabled_color5.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color6 = QGraphicsColorizeEffect() self.disabled_color6.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color7 = QGraphicsColorizeEffect() self.disabled_color7.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color8 = QGraphicsColorizeEffect() self.disabled_color8.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color9 = QGraphicsColorizeEffect() self.disabled_color9.setColor(QColor.fromRgb(240, 225, 204)) self.disabled_color10 = QGraphicsColorizeEffect() self.disabled_color10.setColor(QColor.fromRgb(240, 225, 204)) # Sets up all the line edits self.ingredient1 = QLineEdit(self) self.ingredient1.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient1.setFont(QFont('Georgia', 10)) self.ingredient2 = QLineEdit(self) self.ingredient2.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient2.setFont(QFont('Georgia', 10)) self.ingredient2.setGraphicsEffect(self.disabled_color2) self.ingredient3 = QLineEdit(self) self.ingredient3.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient3.setFont(QFont('Georgia', 10)) self.ingredient3.setGraphicsEffect(self.disabled_color3) self.ingredient4 = QLineEdit(self) self.ingredient4.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient4.setFont(QFont('Georgia', 10)) self.ingredient4.setGraphicsEffect(self.disabled_color4) self.ingredient5 = QLineEdit(self) self.ingredient5.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient5.setFont(QFont('Georgia', 10)) self.ingredient5.setGraphicsEffect(self.disabled_color5) self.ingredient6 = QLineEdit(self) self.ingredient6.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient6.setFont(QFont('Georgia', 10)) self.ingredient6.setGraphicsEffect(self.disabled_color6) self.ingredient7 = QLineEdit(self) self.ingredient7.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient7.setFont(QFont('Georgia', 10)) self.ingredient7.setGraphicsEffect(self.disabled_color7) self.ingredient8 = QLineEdit(self) self.ingredient8.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient8.setFont(QFont('Georgia', 10)) self.ingredient8.setGraphicsEffect(self.disabled_color8) self.ingredient9 = QLineEdit(self) self.ingredient9.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient9.setFont(QFont('Georgia', 10)) self.ingredient9.setGraphicsEffect(self.disabled_color9) self.ingredient10 = QLineEdit(self) self.ingredient10.setStyleSheet( 'background-color: rgb(224, 182, 157); color: rgb(35, 87, 77)') self.ingredient10.setFont(QFont('Georgia', 10)) self.ingredient10.setGraphicsEffect(self.disabled_color10) # Gets all the ingredients from the data self.ingredient = [self.ingredient1, self.ingredient2, self.ingredient3, self.ingredient4, self.ingredient5, self.ingredient6, self.ingredient7, self.ingredient8, self.ingredient9, self.ingredient10] self.disabled_color = [self.disabled_color2, self.disabled_color3, self.disabled_color4, self.disabled_color5, self.disabled_color6, self.disabled_color7, self.disabled_color8, self.disabled_color9, self.disabled_color10] data = data_reading.read_recipes(data_reading.RECIPES_FILE) data_reading.clean_ingredients(data) self.clean = sorted(list(data_reading.get_ingredients(data))) for i in range(len(self.clean)): self.all_ingredients.insertItem(i, self.clean[i]) # Sets up the screen with all the needed elements self.title = "Look and Cook" self.left = 500 self.top = 200 self.width = 700 self.height = 700 self.init_window() self.center() self.setFixedSize(700, 700)
class Player(QGraphicsPixmapItem): def __init__(self, playerName, playerCar , keybed, width): self.playerName = playerName self.Car = playerCar self.qpix = QPixmap(('PNG/Car_' + playerCar + '_Main_Positions/Car_' + playerCar + '_01')) self.qpix = self.qpix.scaled(width, width * 1.5) self.keybed = keybed super(Player, self).__init__(self.qpix) self.lives = 3 self.effect = QGraphicsColorizeEffect() self.effect.setColor(QColor(189, 189, 189)) self.effect.setStrength(0.5) self.effect.setEnabled(False) self.setGraphicsEffect(self.effect) self.key_notifier = KeyNotifier() self.key_notifier.key_signal.connect(self.movePlayer) self.safeTimer = QTimer() self.safeTimer.timeout.connect(self.makeKillable) self.killable = True self.safeTimerRemaining = 0 self.touchesplayer = False self.notMoving = QTimer() self.notMoving.timeout.connect(self.enableMoving) self.canMove = True self.notMovingRemaining = 0 self.networkcode = None def die(self): if self.killable == True: self.lives = self.lives - 1 print("Player: {}, Lives: {}".format(self.playerName, self.lives)) if self.lives == 0: self.key_notifier.die() self.hide() self.killable = False # died three times already, no need to count lives anymore else: self.makeUnkillable() # calls timer def getLives(self): return self.lives def keyPressEvent(self, event): self.key_notifier.add_key(event.key()) def keyReleaseEvent(self, event): self.key_notifier.rem_key(event.key()) def setNetworkCode(self, networkCode): self.networkcode = networkCode def movePlayer(self, key): # if it's not killable, means player died and cannot move index = 0 if key == self.keybed[0]: if self.pos().x() + 15 <= 790: self.moveBy(15, 0) self.checkifCollision(key) elif key == self.keybed[1]: if self.pos().y() + 15 <= 530: self.moveBy(0, 15) self.checkifCollision(key) index = 1 elif key == self.keybed[2]: if self.pos().y() - 15 >= 0: self.moveBy(0, -15) self.checkifCollision(key) index = 2 elif key == self.keybed[3]: if self.pos().x() - 15 >= 150: self.moveBy(-15, 0) self.checkifCollision(key) index = 3 # TODO send position to host. if self.networkcode is not None: if isinstance(self.networkcode, NetworkClientCode): self.networkcode.sendplayerPosition(self.playerName, self.x(), self.y(), index) else: self.networkcode.broadcastMovement(self.playerName, self.x(), self.y(), index) def checkifCollision(self, key): touchedplayer = self.doesitTouch() if self.touchesplayer: if key == self.keybed[0]: self.moveBy(-15, 0) if touchedplayer.pos().x() + 30 <= 790: touchedplayer.moveBy(30, 0) elif key == self.keybed[1]: self.moveBy(0, -15) if touchedplayer.pos().y() + 30 <= 530: touchedplayer.moveBy(0, 30) elif key == self.keybed[2]: self.moveBy(0, 15) if touchedplayer.pos().y() - 30 >= 0: touchedplayer.moveBy(0, -30) elif key == self.keybed[3]: self.moveBy(15, 0) if touchedplayer.pos().x() - 30 >= 150: touchedplayer.moveBy(-30, 0) def doesitTouch(self): collidingPlayers = list(filter(lambda x: isinstance(x, Player), self.collidingItems())) if len(collidingPlayers) != 0: self.touchesplayer = True return collidingPlayers[0] else: self.touchesplayer = False def resetLives(self): self.lives = 3 self.effect.setEnabled(False) self.killable = True self.canMove = True self.safeTimerRemaining = 0 self.notMovingRemaining = 0 def activateThreads(self): if self.safeTimerRemaining != 0: self.safeTimer.start(self.safeTimerRemaining) # resuming timers self.safeTimerRemaining = 0 if self.notMovingRemaining != 0: self.notMoving.start(self.notMovingRemaining) self.notMoving = 0 if self.killable and self.canMove: self.key_notifier.start() def stopThread(self): if self.safeTimer.isActive(): self.safeTimerRemaining = self.safeTimer.remainingTime() #pausing timers self.safeTimer.stop() if self.notMoving.isActive(): self.notMovingRemaining = self.notMoving.remainingTime() self.notMoving.stop() self.key_notifier.die() def makeUnkillable(self): self.killable = False self.safeTimer.start(5000) # After 5 seconds, calls makeKillable. self.effect.setColor(QColor(189, 189, 189)) self.effect.setEnabled(True) def makeKillable(self): self.effect.setEnabled(False) self.safeTimer.stop() self.killable = True def addLife(self): if self.lives < 4: # lives limited to 4 self.lives += 1 print("Player: {}, Lives: {}".format(self.playerName, self.lives)) def disableMoving(self): self.key_notifier.die() self.canMove = False self.effect.setColor(QColor(255, 210, 117)) self.effect.setEnabled(True) self.notMoving.start(2000) def enableMoving(self): if self.killable: self.effect.setEnabled(False) self.effect.setColor(QColor(189, 189, 189)) self.notMoving.stop() self.canMove = True self.key_notifier.start() def getNameCar(self): return self.playerName, self.Car