Example #1
0
class subTitleEdit(QWidget):
    def __init__(self):
        super(subTitleEdit, self).__init__()
        self.rx = QRegExp("(^(?:(:?[0-1][0-9]|[0-2][0-3]):)(?:[0-5][0-9]:){2}(?:[0-2][0-9])$)")
        self.language_choice = 1  # 1 English, 2 Tamil, 3 Hindi
        self.initUI()

    def initUI(self):
        # Master Layout
        mainlayout = QVBoxLayout()
        mainlayout.setContentsMargins(0, 0, 0, 0)
        mainlayout.setMargin(3)
        mainlayout.setSpacing(0)
        mainlayout.setStretch(0, 0)
        # Top Layout (In Out Duration)
        subLayout = QHBoxLayout()
        subLayout.setContentsMargins(0, 0, 0, 0)
        subLayout.setMargin(2)
        subLayout.setSpacing(5)
        # Top Layout Controls
        self.no = QSpinBox()
        self.no.setMinimum(1)
        self.no.setMaximum(9999)  # < Memory Concerns Lower
        self.tcIn = QLineEdit()
        self.tcOut = QLineEdit()
        self.tcDur = QLineEdit()
        index_lbl = QLabel("No:")
        intc_lbl = QLabel("In:")
        outtc_lbl = QLabel("Out:")
        durtc_lbl = QLabel("Duration:")
        # Add to Layout
        subLayout.addWidget(index_lbl)
        subLayout.addWidget(self.no)
        subLayout.addWidget(intc_lbl)
        subLayout.addWidget(self.tcIn)
        subLayout.addWidget(outtc_lbl)
        subLayout.addWidget(self.tcOut)
        subLayout.addWidget(durtc_lbl)
        subLayout.addWidget(self.tcDur)
        # Add to Main
        mainlayout.addLayout(subLayout)
        # Add Next Line Controls
        second_line_layout = QHBoxLayout()
        font = QFont("Helvetica", 13)
        self.font_family = QFontComboBox()
        self.font_family.setMaximumWidth(180)
        self.font_family.setCurrentFont(font)
        second_line_layout.addWidget(self.font_family)
        self.font_family.currentTextChanged.connect(self.set_font)
        self.font_size = QComboBox()
        self.font_size.addItems(["9", "10", "11", "12", "13", "14", "18", "24", "36", "48", "64"])
        self.font_size.setCurrentText("13")
        self.font_size.setMaximumWidth(80)
        self.font_size.currentIndexChanged.connect(self.set_font)
        second_line_layout.addWidget(self.font_size)
        bold = QPushButton("B")
        bold.clicked.connect(self.bold)
        italic = QPushButton("I")
        italic.clicked.connect(self.italic)
        underline = QPushButton("U")
        underline.clicked.connect(self.underline)
        second_line_layout.addWidget(bold)
        second_line_layout.addWidget(italic)
        second_line_layout.addWidget(underline)
        # ------------------------------------------
        language = QComboBox()
        language.addItems(["English", "Tamil", "Hindi"])
        language.currentIndexChanged.connect(self.setup_language)
        language.setDisabled(True)  # Disabled
        spellCheck = QPushButton("Spell Check")
        spellCheck.setDisabled(True)  # Disabled
        autocomplete = QCheckBox("AutoCmp")
        autocomplete.toggled.connect(self.setup_autocomplete)
        second_line_layout.addWidget(language)
        second_line_layout.addWidget(spellCheck)
        second_line_layout.addWidget(autocomplete)
        second_line_layout.addStretch(1)
        mainlayout.addLayout(second_line_layout)
        # txtSubTitle = QTextEdit()
        self.subtitle = CompletionTextEdit()
        # print(self.subtitle.font())
        # completer = DictionaryCompleter()
        # self.subtitle.setCompleter(completer)
        # self.subtitle.setMaximumHeight(100)
        mainlayout.addWidget(self.subtitle)
        # Setup TimeCode LineEdit Controls
        self.setup_linedt_tc(self.tcIn)
        self.setup_linedt_tc(self.tcOut)
        self.setup_linedt_tc(self.tcDur)
        self.tcOut.editingFinished.connect(self.calculate_duration)
        # Layout Operations
        self.setLayout(mainlayout)
        self.setTabOrder(self.tcDur, self.subtitle)
        self.show()
    
    def setup_linedt_tc(self, ctrl):
        ctrl.setDragEnabled(True)
        ctrl.setInputMask("99:99:99:99")
        ctrl.setText("00000000")
        ctrl.setCursorPosition(0)
        ctrl.setValidator(QRegExpValidator(self.rx))
    
    def calculate_duration(self):
        tcIn = TimeCode(self.tcIn.text())
        tcOut = TimeCode(self.tcOut.text())
        if tcOut.frames > tcIn.frames:
            Dur = tcOut - tcIn
            self.tcDur.setText(Dur.timecode)

    @Slot()
    def set_font(self):
        self.subtitle.setCurrentFont(QFont(self.font_family.currentText(), int(self.font_size.currentText())))
    
    @Slot()
    def bold(self):
        if self.subtitle.fontWeight() == QFont.Bold:
            self.subtitle.setFontWeight(QFont.Normal)
        else:
            self.subtitle.setFontWeight(QFont.Bold)
    
    @Slot()
    def italic(self):
        state = self.subtitle.fontItalic()
        self.subtitle.setFontItalic(not state)
    
    @Slot()
    def underline(self):
        state = self.subtitle.fontUnderline()
        self.subtitle.setFontUnderline(not state)
    
    def clearStyles(self):
        bold = self.subtitle.fontWeight() == QFont.Bold
        italic = self.subtitle.fontItalic()
        underline = self.subtitle.fontUnderline()
        if bold:
            self.subtitle.setFontWeight(QFont.Normal)
        if italic:
            self.subtitle.setFontItalic(False)
        if underline:
            self.subtitle.setFontUnderline(False)

    @Slot()
    def setup_language(self, event):
        event += 1
        self.language_choice = event
        if self.language_choice == 1:  # Tamil
            self.subtitle.setText("You have chosen English")
        elif self.language_choice == 2:  # Tamil
            self.subtitle.setText("You have chosen Tamil")
        elif self.language_choice == 3:  # Hindi
            self.subtitle.setText("You have chosen Hindi")

    @Slot()
    def setup_autocomplete(self, event):
        if self.language_choice == 1 and event == True:
            completer = en_autocomplete()
            self.subtitle.setCompleter(completer)
        elif self.language_choice == 1 and event == False:
            self.subtitle.removeCompleter()
Example #2
0
class FontsTab(QWidget):
    def __init__(self, parent_dialog, parent):
        """Initialize the fonts tab
        """

        super(FontsTab, self).__init__(parent_dialog)

        self.prefs = parent_dialog.prefs
        self.parent = parent

        # Base application font code
        app = QApplication.instance()
        self.font_base = app.font()
        font_label_base = QLabel("Base Application Font:")
        self.font_combo_base = QFontComboBox()
        self.font_combo_base.setMaximumWidth(175)
        self.font_combo_base.setCurrentFont(self.font_base.family())
        self.font_combo_base.currentFontChanged.connect(self.update)
        self.font_size_combo_base = QComboBox()
        points_base = self.font_points(self.font_base)
        self.font_size_combo_base.addItems(points_base)
        self.font_size_combo_base.setMaximumWidth(50)
        self.font_size_combo_base.setCurrentIndex(self.font_size_combo_base.findText(str(self.font_base.pointSize())))
        self.font_size_combo_base.currentIndexChanged.connect(self.update)
        base_layout = QHBoxLayout()
        base_layout.addWidget(font_label_base)
        base_layout.addWidget(self.font_combo_base)
        base_layout.addWidget(self.font_size_combo_base)

        # Class Tree font code
        self.font_classTree = self.parent.classTree.font()
        font_label_classTree = QLabel("Class Tree Font:")
        self.font_combo_classTree = QFontComboBox()
        self.font_combo_classTree.setMaximumWidth(175)
        self.font_combo_classTree.setCurrentFont(self.font_classTree.family())
        self.font_combo_classTree.currentFontChanged.connect(self.update)
        self.font_size_combo_classTree = QComboBox()
        points_classTree = self.font_points(self.font_classTree)
        self.font_size_combo_classTree.addItems(points_classTree)
        self.font_size_combo_classTree.setMaximumWidth(50)
        self.font_size_combo_classTree.setCurrentIndex(self.font_size_combo_classTree.findText(str(self.font_classTree.pointSize())))
        self.font_size_combo_classTree.currentIndexChanged.connect(self.update)
        classTree_layout = QHBoxLayout()
        classTree_layout.addWidget(font_label_classTree)
        classTree_layout.addWidget(self.font_combo_classTree)
        classTree_layout.addWidget(self.font_size_combo_classTree)

        # Class Table font code
        self.font_classTable = self.parent.classTable.font()
        font_label_classTable = QLabel("Class Table Font:")
        self.font_combo_classTable = QFontComboBox()
        self.font_combo_classTable.setMaximumWidth(175)
        self.font_combo_classTable.setCurrentFont(self.font_classTable.family())
        self.font_combo_classTable.currentFontChanged.connect(self.update)
        self.font_size_combo_classTable = QComboBox()
        points_classTable = self.font_points(self.font_classTable)
        self.font_size_combo_classTable.addItems(points_classTable)
        self.font_size_combo_classTable.setMaximumWidth(50)
        self.font_size_combo_classTable.setCurrentIndex(self.font_size_combo_classTable.findText(str(self.font_classTable.pointSize())))
        self.font_size_combo_classTable.currentIndexChanged.connect(self.update)
        classTable_layout = QHBoxLayout()
        classTable_layout.addWidget(font_label_classTable)
        classTable_layout.addWidget(self.font_combo_classTable)
        classTable_layout.addWidget(self.font_size_combo_classTable)

        # Comments view font code
        self.font_comments = self.parent.commentView.font()
        font_label_comments = QLabel("Comments Font:")
        self.font_combo_comments = QFontComboBox()
        self.font_combo_comments.setMaximumWidth(175)
        self.font_combo_comments.setCurrentFont(self.font_comments.family())
        self.font_combo_comments.currentFontChanged.connect(self.update)
        self.font_size_combo_comments = QComboBox()
        points_comments = self.font_points(self.font_comments)
        self.font_size_combo_comments.addItems(points_comments)
        self.font_size_combo_comments.setMaximumWidth(50)
        self.font_size_combo_comments.setCurrentIndex(self.font_size_combo_comments.findText(str(self.font_comments.pointSize())))
        self.font_size_combo_comments.currentIndexChanged.connect(self.update)
        comments_layout = QHBoxLayout()
        comments_layout.addWidget(font_label_comments)
        comments_layout.addWidget(self.font_combo_comments)
        comments_layout.addWidget(self.font_size_combo_comments)

        # Main layout code
        mainLayout = QVBoxLayout()
        mainLayout.addLayout(base_layout)
        mainLayout.addSpacing(10)
        mainLayout.addLayout(classTree_layout)
        mainLayout.addSpacing(10)
        mainLayout.addLayout(classTable_layout)
        mainLayout.addSpacing(10)
        mainLayout.addLayout(comments_layout)
        mainLayout.addStretch(1)
        self.setLayout(mainLayout)

    def update(self):
        self.font_base.setFamily(self.font_combo_base.currentFont().family())
        self.font_base.setPointSize(int(self.font_size_combo_base.currentText()))
        self.font_classTree.setFamily(self.font_combo_classTree.currentFont().family())
        self.font_classTree.setPointSize(int(self.font_size_combo_classTree.currentText()))
        self.font_classTable.setFamily(self.font_combo_classTable.currentFont().family())
        self.font_classTable.setPointSize(int(self.font_size_combo_classTable.currentText()))
        self.font_comments.setFamily(self.font_combo_comments.currentFont().family())
        self.font_comments.setPointSize(int(self.font_size_combo_comments.currentText()))
        self.prefs['base_font'] = self.font_base.toString()
        self.prefs['class_tree_font'] = self.font_classTree.toString()
        self.prefs['class_table_font'] = self.font_classTable.toString()
        self.prefs['comments_font'] = self.font_comments.toString()
        # self.prefs['log_font'] = self.font_base.toString()
        # self.prefs['ref_font'] = self.font_base.toString()
        # self.prefs['info_font'] = self.font_base.toString()
        # self.prefs['undo_font'] = self.font_base.toString()

    def font_points(self, font):
        points = [str(p) for p in QFontDatabase().pointSizes(font.family())]
        if not points:
            points = [str(p) for p in QFontDatabase().standardSizes()]
        return points