def eventFilter(self, object, event): if event.type() == QEvent.HoverEnter: if object.parent().backgroundFlag: object.setStyleSheet("QLabel { color: white; background-color:" + object.params['color'] + "; border: 1px solid white; }") #NB: alternative ~ border: 1px solid black else: object.setStyleSheet("QLabel { color: black; }") object.parent().kanjiLarge.setText(object.text()) object.parent().words.setText(', '.join(object.params['words'])) object.parent().next.setText(object.params['next']) object.parent().leitner.setText(object.params['leitner']) if event.type() == QEvent.HoverLeave: if object.parent().backgroundFlag: object.setStyleSheet("QLabel { color: black; background-color:" + object.params['color'] + "; border: 1px solid white;}") else: object.setStyleSheet("QLabel { color:" + object.params['color'] + "; }") if event.type() == QEvent.MouseButtonPress: object.parent().db.toggleActive(object.params['item']) if object.params['item'].active: object.params['color'] = Leitner.correspondingColor(object.params['item'].leitner_grade) else: object.params['color'] = 'gray' if object.parent().backgroundFlag: object.setStyleSheet("QLabel { color: white; background-color:" + object.params['color'] + "; border: 1px solid white; }") else: object.setStyleSheet("QLabel { color: black; }") return False
def showAll(self): unfillLayout(self.items.infoLayout) unfillLayout(self.items.layout) self.items.infoLayout = QHBoxLayout() self.items.backgroundFlag = self.options.isBackgroundOn() # self.items.scrollArea = QScrollArea(self.items) # self.items.groupItems = QGroupBox() # TODO: implement using group box: QScrollArea <- QGroupBox <- a layout () <- widgets ( created with the group box as parent and added to the layout ) studyItems = self.db.getAllItemsInFull() if len(studyItems) == 0: QMessageBox.information(self, "No items", "Currently no items in db") else: # progress = QProgressDialog('Loading items list...', 'Cancel', 0, len(studyItems), self) progress = QProgressDialog("Loading items list...", None, 0, len(studyItems), self) progress.setWindowModality(Qt.WindowModal) progress.show() count = 0 i = 0 j = 0 max_c = 20 # ; max_r =50 for item in studyItems: element = QLabel(item.item) element.setFont(QFont(self.options.getInfoFont(), 13)) # if item.active: element.setStyleSheet("QLabel { color:" + Leitner.correspondingColor(item.leitner_grade) + "}") # else: element.setStyleSheet("QLabel { color:gray }") if item.active: color = Leitner.correspondingColor(item.leitner_grade) else: color = "gray" if self.options.isBackgroundOn(): element.setStyleSheet( "QLabel { color: black; background-color:" + color + "; border: 1px solid white; }" ) # element.setStyleSheet("QLabel { color: blue; }") else: element.setStyleSheet("QLabel { color:" + color + "}") element.setAttribute(Qt.WA_Hover, True) element.installEventFilter(self.filter) # words = []; examples = {} # for el in item.word: # words.append(el.word) # for el in item.example: # examples[el.sentence] = el.translation element.params = { "color": color, "next": item.next_quiz.strftime("%d %b %H:%M:%S"), "inSession": item.been_in_session, "leitner": Leitner.grades[item.leitner_grade].key, } #'words': words, 'examples': examples, self.items.layout.addWidget(element, i, j) count = count + 1 progress.setValue(count) if progress.wasCanceled(): break if j > max_c: i = i + 1 j = 0 else: j = j + 1 separator_two = QFrame() separator_two.setFrameShape(QFrame.HLine) separator_two.setFrameShadow(QFrame.Sunken) self.items.layout.addWidget(separator_two, i + 1, 0, 1, self.items.layout.columnCount()) self.items.kanjiLarge = QLabel(u"") self.items.kanjiLarge.setFont(QFont(self.options.getSentenceFont(), 56)) self.items.words = QLabel(u"") self.items.words.setWordWrap(True) self.items.words.setFont(QFont(Fonts.MSMyoutyou, 14)) self.items.next = QLabel(u"") self.items.leitner = QLabel(u"") self.items.infoLayout.addWidget(self.items.kanjiLarge) self.items.infoLayout.addWidget(self.items.next) self.items.infoLayout.addWidget(self.items.leitner) self.items.infoLayout.addWidget(self.items.words) # self.items.infoLayout.setAlignment(Qt.AlignCenter) """ #NB: or, may be, add horizontal layout? self.items.layout.addWidget(self.items.kanjiLarge, i + 2, 0, 2, 2) self.items.layout.addWidget(self.items.next, i + 2, 3, 1, 1) self.items.layout.addWidget(self.items.leitner, i + 3, 3, 1, 1) #self.items.layout.addWidget(self.items.kanjiLarge, i + 2, 9, 1, 4) """ if self.options.isBackgroundOn(): self.items.layout.setSpacing(0) else: self.items.layout.setSpacing(6) # self.items.layout.addLayout(self.items.infoLayout, i + 2, 0, 1, self.items.layout.columnCount()) # self.items.layout.addLayout(self.items.infoLayout, i + 2, 0, 1, 8) self.items.layout.addLayout(self.items.infoLayout, i + 2, self.items.layout.columnCount() / 2, 1, 8) # self.items.scrollArea.setLayout(self.items.layout) # self.groupItems.setLayout(self.items.layout) # self.scrollArea.setWidget(self.groupItems) self.items.setLayout(self.items.layout) self.items.show()
def showAll(self): unfillLayout(self.items.infoLayout) unfillLayout(self.items.layout) self.items.infoLayout = QHBoxLayout() self.items.backgroundFlag = self.options.isBackgroundOn() #self.items.scrollArea = QScrollArea(self.items) #self.items.groupItems = QGroupBox() #TODO: implement using group box: QScrollArea <- QGroupBox <- a layout () <- widgets ( created with the group box as parent and added to the layout ) studyItems = self.db.getAllItemsInFull() if len(studyItems) == 0: QMessageBox.information(self, 'No items', 'Currently no items in db') else: #progress = QProgressDialog('Loading items list...', 'Cancel', 0, len(studyItems), self) progress = QProgressDialog('Loading items list...', None, 0, len(studyItems), self) progress.setWindowModality(Qt.WindowModal) progress.show() count = 0 i = 0 j = 0 max_c = 20 #; max_r =50 for item in studyItems: element = QLabel(item.item) element.setFont(QFont(self.options.getInfoFont(), 13)) #if item.active: element.setStyleSheet("QLabel { color:" + Leitner.correspondingColor(item.leitner_grade) + "}") #else: element.setStyleSheet("QLabel { color:gray }") if item.active: color = Leitner.correspondingColor(item.leitner_grade) else: color = 'gray' if self.options.isBackgroundOn(): element.setStyleSheet( "QLabel { color: black; background-color:" + color + "; border: 1px solid white; }") #element.setStyleSheet("QLabel { color: blue; }") else: element.setStyleSheet("QLabel { color:" + color + "}") element.setAttribute(Qt.WA_Hover, True) element.installEventFilter(self.filter) # words = []; examples = {} # for el in item.word: # words.append(el.word) # for el in item.example: # examples[el.sentence] = el.translation element.params = { 'color': color, 'next': item.next_quiz.strftime('%d %b %H:%M:%S'), 'inSession': item.been_in_session, 'leitner': Leitner.grades[item.leitner_grade].key } #'words': words, 'examples': examples, self.items.layout.addWidget(element, i, j) count = count + 1 progress.setValue(count) if progress.wasCanceled(): break if j > max_c: i = i + 1 j = 0 else: j = j + 1 separator_two = QFrame() separator_two.setFrameShape(QFrame.HLine) separator_two.setFrameShadow(QFrame.Sunken) self.items.layout.addWidget(separator_two, i + 1, 0, 1, self.items.layout.columnCount()) self.items.kanjiLarge = QLabel(u'') self.items.kanjiLarge.setFont( QFont(self.options.getSentenceFont(), 56)) self.items.words = QLabel(u'') self.items.words.setWordWrap(True) self.items.words.setFont(QFont(Fonts.MSMyoutyou, 14)) self.items.next = QLabel(u'') self.items.leitner = QLabel(u'') self.items.infoLayout.addWidget(self.items.kanjiLarge) self.items.infoLayout.addWidget(self.items.next) self.items.infoLayout.addWidget(self.items.leitner) self.items.infoLayout.addWidget(self.items.words) #self.items.infoLayout.setAlignment(Qt.AlignCenter) ''' #NB: or, may be, add horizontal layout? self.items.layout.addWidget(self.items.kanjiLarge, i + 2, 0, 2, 2) self.items.layout.addWidget(self.items.next, i + 2, 3, 1, 1) self.items.layout.addWidget(self.items.leitner, i + 3, 3, 1, 1) #self.items.layout.addWidget(self.items.kanjiLarge, i + 2, 9, 1, 4) ''' if self.options.isBackgroundOn(): self.items.layout.setSpacing(0) else: self.items.layout.setSpacing(6) #self.items.layout.addLayout(self.items.infoLayout, i + 2, 0, 1, self.items.layout.columnCount()) #self.items.layout.addLayout(self.items.infoLayout, i + 2, 0, 1, 8) self.items.layout.addLayout(self.items.infoLayout, i + 2, self.items.layout.columnCount() / 2, 1, 8) #self.items.scrollArea.setLayout(self.items.layout) #self.groupItems.setLayout(self.items.layout) #self.scrollArea.setWidget(self.groupItems) self.items.setLayout(self.items.layout) self.items.show()