def __init__(self, component_manager, parent, card_type): QtGui.QWidget.__init__(self, parent) GenericCardTypeWidget.__init__(self, component_manager) self.card_type = card_type self.hboxlayout = QtGui.QHBoxLayout(self) self.hboxlayout.setMargin(0) self.vboxlayout = QtGui.QVBoxLayout() self.edit_boxes = {} self.top_edit_box = None for fact_key, fact_key_name in self.card_type.fields: self.vboxlayout.addWidget(QtGui.QLabel(fact_key_name + ":", self)) t = QTextEdit2(self) t.setTabChangesFocus(True) t.setUndoRedoEnabled(True) t.setReadOnly(False) try: colour = self.config()["font_colour"][card_type.id][fact_key] t.setTextColor(QtGui.QColor(colour)) except: pass try: colour = self.config()["background_colour"][card_type.id] p = QtGui.QPalette() p.setColor(QtGui.QPalette.Active, QtGui.QPalette.Base, QtGui.QColor(colour)) t.setPalette(p) except: pass try: font_string = self.config()["font"][card_type.id][fact_key] font = QtGui.QFont() font.fromString(font_string) t.setCurrentFont(font) except: pass if len(self.card_type.fields) > 2: t.setMinimumSize(QtCore.QSize(0, 60)) else: t.setMinimumSize(QtCore.QSize(0, 106)) self.vboxlayout.addWidget(t) self.edit_boxes[t] = fact_key if not self.top_edit_box: self.top_edit_box = t self.connect(t, QtCore.SIGNAL("textChanged()"), self.text_changed) self.hboxlayout.addLayout(self.vboxlayout) self.resize(QtCore.QSize(QtCore.QRect(0, 0, 325, 264).size()).expandedTo(self.minimumSizeHint()))
def __init__(self, component_manager, parent, card_type): QtGui.QWidget.__init__(self, parent) GenericCardTypeWidget.__init__(self, component_manager) self.card_type = card_type self.hboxlayout = QtGui.QHBoxLayout(self) self.hboxlayout.setMargin(0) self.vboxlayout = QtGui.QVBoxLayout() self.fact_key_for_edit_box = {} self.top_edit_box = None self.edit_boxes = [] self.fact_data_before_edit = {} # Does this card type need to deal with the hiding of pronunciation # keys? if "p_1" not in self.card_type.fact_keys(): pronunciation_hiding = None else: pronunciation_hiding = self.config().card_type_property(\ "hide_pronunciation_field", self.card_type, default=False) # Construct the rest of the dialog. parent.setTabOrder(parent.card_types_widget, parent.tags) for fact_key, fact_key_name in self.card_type.fact_keys_and_names: l = QtGui.QLabel(_(fact_key_name) + ":", self) self.vboxlayout.addWidget(l) if fact_key == "p_1": self.pronunciation_label = l self.pronunciation_label.setVisible(not pronunciation_hiding) t = QTextEdit2(self, pronunciation_hiding) self.edit_boxes.append(t) t.setTabChangesFocus(True) t.setUndoRedoEnabled(True) t.setReadOnly(False) if len(self.card_type.fact_keys_and_names) > 2: t.setMinimumSize(QtCore.QSize(0, 60)) else: t.setMinimumSize(QtCore.QSize(0, 106)) self.vboxlayout.addWidget(t) self.fact_key_for_edit_box[t] = fact_key if self.top_edit_box is None: self.top_edit_box = t parent.setTabOrder(parent.tags, t) else: parent.setTabOrder(previous_box, t) previous_box = t if fact_key == "p_1": self.pronunciation_box = t self.pronunciation_box.setVisible(not pronunciation_hiding) self.update_formatting(t) t.textChanged.connect(self.text_changed) t.currentCharFormatChanged.connect(self.reset_formatting) self.hboxlayout.addLayout(self.vboxlayout) self.resize(QtCore.QSize(QtCore.QRect(0,0,325,264).size()).\ expandedTo(self.minimumSizeHint())) if parent.component_type == "add_cards_dialog": parent.setTabOrder(t, parent.yet_to_learn_button) parent.setTabOrder(parent.yet_to_learn_button, parent.grade_2_button) parent.setTabOrder(parent.grade_2_button, parent.grade_3_button) parent.setTabOrder(parent.grade_3_button, parent.grade_4_button) parent.setTabOrder(parent.grade_4_button, parent.grade_5_button) parent.setTabOrder(parent.grade_5_button, parent.preview_button) parent.setTabOrder(parent.preview_button, parent.exit_button) else: parent.setTabOrder(t, parent.OK_button) parent.setTabOrder(parent.OK_button, parent.preview_button) parent.setTabOrder(parent.preview_button, parent.exit_button) self.top_edit_box.setFocus()