def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(700, 250)

        vlayout = aqt.qt.QVBoxLayout(self)

        vlayout.addWidget(gui_utils.get_header_label('Yomichan Integration'))

        voice_name = self.japanese_voice['voice_description']

        label_text1 = f'You can use Language Tools voices from within Yomichan. Currently using voice: <b>{voice_name}</b>. You can change this in the <b>Voice Selection</b> dialog.'
        label_text2 = """
        <ol>
            <li>Please go to <b>Yomichan settings</b></li>
            <li>Look for <b>Audio</b></li>
            <li>Configure audio playback sources...</li>
            <li>In <b>Custom audio source</b>, choose <b>Type: Audio</b>, and enter the URL below (it should already be copied to your clipboard)</li>
            <li>In the <b>Audio sources</b> dropdown, choose <b>Custom</b></li>
            <li>Try playing some audio using Yomichan, you should hear it played back in the voice you've chosen.</li>
        </ol>
        """

        label = aqt.qt.QLabel(label_text1)
        label.setWordWrap(True)
        vlayout.addWidget(label)

        label = aqt.qt.QLabel(label_text2)
        vlayout.addWidget(label)

        # compute URL

        api_key = self.languagetools.config['api_key']
        voice_key_str = urllib.parse.quote_plus(
            json.dumps(self.japanese_voice['voice_key']))
        service = self.japanese_voice['service']
        url_params = f"api_key={api_key}&service={service}&voice_key={voice_key_str}&text={'{'}expression{'}'}"
        url_end = f'yomichan_audio?{url_params}'
        full_url = self.languagetools.cloud_language_tools.base_url + '/' + url_end

        aqt.qt.QApplication.clipboard().setText(full_url)

        line_edit = aqt.qt.QLineEdit(full_url)
        vlayout.addWidget(line_edit)

        vlayout.addStretch()

        # add buttons
        buttonBox = aqt.qt.QDialogButtonBox()
        self.okButton = buttonBox.addButton("OK",
                                            aqt.qt.QDialogButtonBox.AcceptRole)
        vlayout.addWidget(buttonBox)

        # wire events
        # ===========
        buttonBox.accepted.connect(self.accept)
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(700, 500)

        vlayout = aqt.qt.QVBoxLayout(self)

        vlayout.addWidget(gui_utils.get_header_label(self.get_header_text()))

        vlayout.addWidget(
            aqt.qt.QLabel(
                'You can visualize and remove Audio / Translation / Transliteration rules from here.'
            ))

        self.layout_rules(vlayout)

        vlayout.addWidget(
            gui_utils.get_medium_label(f'Apply Changes While Typing'))
        self.checkbox = aqt.qt.QCheckBox(
            "Language Tools will automatically apply field translations / transliterations / audio when typing into the From field"
        )
        self.checkbox.setChecked(
            self.languagetools.get_apply_updates_automatically())
        self.checkbox.setContentsMargins(10, 0, 10, 0)
        vlayout.addWidget(self.checkbox)

        vlayout.addStretch()

        # buttom buttons
        buttonBox = aqt.qt.QDialogButtonBox()
        self.applyButton = buttonBox.addButton(
            "Save Settings", aqt.qt.QDialogButtonBox.AcceptRole)
        self.applyButton.setEnabled(False)
        self.cancelButton = buttonBox.addButton(
            "Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancelButton.setStyleSheet(
            self.languagetools.anki_utils.get_red_stylesheet())
        vlayout.addWidget(buttonBox)

        # wire events
        self.checkbox.stateChanged.connect(self.apply_updates_state_changed)
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(700, 300)

        vlayout = aqt.qt.QVBoxLayout(self)

        vlayout.addWidget(gui_utils.get_header_label(self.get_header_text()))

        vlayout.addWidget(
            aqt.qt.QLabel(
                'Select the rules you want to run, then click Apply Rules.'))

        self.layout_rules(vlayout)

        # progress bar
        hlayout = aqt.qt.QHBoxLayout()
        hlayout.setContentsMargins(0, 20, 0, 0)
        self.progress_bar = aqt.qt.QProgressBar()
        hlayout.addWidget(self.progress_bar)
        vlayout.addLayout(hlayout)

        # buttom buttons
        buttonBox = aqt.qt.QDialogButtonBox()
        self.applyButton = buttonBox.addButton(
            "Apply Rules", aqt.qt.QDialogButtonBox.AcceptRole)
        self.applyButton.setStyleSheet(
            self.languagetools.anki_utils.get_green_stylesheet())
        self.cancelButton = buttonBox.addButton(
            "Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancelButton.setStyleSheet(
            self.languagetools.anki_utils.get_red_stylesheet())
        vlayout.addWidget(buttonBox)

        vlayout.addStretch()

        # wire events
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(700, 200)

        vlayout = aqt.qt.QVBoxLayout(self)

        vlayout.addWidget(gui_utils.get_header_label('Add Audio'))

        description_label = aqt.qt.QLabel(
            f'After adding audio to notes, the setting will be memorized.')
        vlayout.addWidget(description_label)

        # from/ to field
        gridlayout = aqt.qt.QGridLayout()

        # from
        gridlayout.addWidget(gui_utils.get_medium_label('From Field:'), 0, 0,
                             1, 1)
        self.from_field_combobox = aqt.qt.QComboBox()
        self.from_field_combobox.addItems(self.from_field_name_list)
        gridlayout.addWidget(self.from_field_combobox, 0, 1, 1, 1)
        # to
        gridlayout.addWidget(gui_utils.get_medium_label('To Field:'), 0, 3, 1,
                             1)
        self.to_field_combobox = aqt.qt.QComboBox()
        self.to_field_combobox.addItems(self.to_field_name_list)
        gridlayout.addWidget(self.to_field_combobox, 0, 4, 1, 1)

        # voice
        gridlayout.addWidget(gui_utils.get_medium_label('Voice:'), 1, 0, 1, 2)
        self.voice_label = aqt.qt.QLabel()
        self.voice_label.setText('undefined')
        self.voice = aqt.qt.QComboBox()
        gridlayout.addWidget(self.voice_label, 1, 1, 1, 4)

        vlayout.addLayout(gridlayout)

        self.progress_bar = aqt.qt.QProgressBar()
        vlayout.addWidget(self.progress_bar)

        vlayout.addStretch()

        buttonBox = aqt.qt.QDialogButtonBox()
        self.applyButton = buttonBox.addButton(
            "Apply To Notes", aqt.qt.QDialogButtonBox.AcceptRole)
        self.applyButton.setEnabled(False)
        self.cancelButton = buttonBox.addButton(
            "Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancelButton.setStyleSheet(
            self.languagetools.anki_utils.get_red_stylesheet())

        vlayout.addWidget(buttonBox)

        # wire events
        self.pick_default_fields()
        self.from_field_combobox.currentIndexChanged.connect(
            self.from_field_index_changed)
        self.to_field_combobox.currentIndexChanged.connect(
            self.to_field_index_changed)

        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
Example #5
0
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(350, 400)

        vlayout = aqt.qt.QVBoxLayout(self)

        vlayout.addWidget(gui_utils.get_header_label('Enter API Key'))

        description_label = aqt.qt.QLabel(
            """<b>Why is Language Tools a paid addon and not free ?</b> """
            """ this addon makes use of cloud services such as Google Cloud and Microsoft Azure to generate premium text to speech, translations and transliterations. """
            """These service cost money and hence this addon cannot be provided for free. """
            """You can sign up for a free trial at the link below""")
        description_label.setWordWrap(True)
        vlayout.addWidget(description_label)

        urlLink = "<a href=\"https://languagetools.anki.study/language-tools-signup?utm_campaign=langtools_apikey&utm_source=languagetools&utm_medium=addon\">Don't have an API Key? Sign up here</a>"
        signup_label = aqt.qt.QLabel()
        signup_label.setText(urlLink)
        signup_label.setOpenExternalLinks(True)
        vlayout.addWidget(signup_label)

        self.api_text_input = aqt.qt.QLineEdit()
        self.api_text_input.setText(self.languagetools.get_config_api_key())
        vlayout.addWidget(self.api_text_input)

        self.status_label = aqt.qt.QLabel('Enter API Key')
        vlayout.addWidget(self.status_label)

        self.account_info_label = aqt.qt.QLabel()
        vlayout.addWidget(self.account_info_label)

        # plan update / cancel buttons
        self.account_update_button = aqt.qt.QPushButton()
        self.account_update_button.setText(
            'Upgrade / Downgrade / Payment options')
        self.account_update_button.setStyleSheet(
            self.languagetools.anki_utils.get_green_stylesheet())
        self.account_cancel_button = aqt.qt.QPushButton()
        self.account_cancel_button.setText('Cancel Plan')
        self.account_cancel_button.setStyleSheet(
            self.languagetools.anki_utils.get_red_stylesheet())
        vlayout.addWidget(self.account_update_button)
        vlayout.addWidget(self.account_cancel_button)
        self.account_update_button.setVisible(False)
        self.account_cancel_button.setVisible(False)

        self.buttonBox = aqt.qt.QDialogButtonBox()
        self.applyButton = self.buttonBox.addButton(
            "OK", aqt.qt.QDialogButtonBox.AcceptRole)
        self.applyButton.setObjectName('apply')
        self.applyButton.setEnabled(False)
        self.cancelButton = self.buttonBox.addButton(
            "Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancelButton.setObjectName('cancel')
        self.cancelButton.setStyleSheet(
            self.languagetools.anki_utils.get_red_stylesheet())
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)

        vlayout.addStretch()
        vlayout.addWidget(self.buttonBox)

        # wire events
        self.typing_timer = self.languagetools.anki_utils.wire_typing_timer(
            self.api_text_input, self.api_key_changed)

        # run api_key_changed logic once
        self.api_key_changed()
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(700, 500)

        vlayout = aqt.qt.QVBoxLayout(self)

        vlayout.addWidget(gui_utils.get_header_label('Audio Voice Selection'))

        # setup grid
        # ==========

        gridlayout = aqt.qt.QGridLayout()

        label_font_size = 13
        font1 = aqt.qt.QFont()
        font1.setBold(True)
        font1.setPointSize(label_font_size)

        # language

        language_label = aqt.qt.QLabel()
        language_label.setText('Language:')
        language_label.setFont(font1)
        gridlayout.addWidget(language_label, 0, 0, 1, 1)

        language_combobox = aqt.qt.QComboBox()
        language_combobox.addItems(self.language_name_list)
        language_combobox.setObjectName('languages_combobox')
        gridlayout.addWidget(language_combobox, 0, 1, 1, 1)

        # voices

        voice_label = aqt.qt.QLabel()
        voice_label.setText('Voice:')
        voice_label.setFont(font1)
        gridlayout.addWidget(voice_label, 1, 0, 1, 1)

        self.voice_combobox = aqt.qt.QComboBox()
        self.voice_combobox.setMaxVisibleItems(15)
        self.voice_combobox.setStyleSheet("combobox-popup: 0;")        
        self.voice_combobox.setObjectName('voices_combobox')
        gridlayout.addWidget(self.voice_combobox, 1, 1, 1, 1)

        # button to refresh samples
        samples_label = aqt.qt.QLabel()
        samples_label.setText('Random Samples:')
        samples_label.setFont(font1)
        gridlayout.addWidget(samples_label, 2, 0, 1, 1)

        samples_reload_button = aqt.qt.QPushButton()
        samples_reload_button.setText('Reload Random Samples')
        gridlayout.addWidget(samples_reload_button, 2, 1, 1, 1)

        gridlayout.setContentsMargins(10, 20, 10, 0)
        vlayout.addLayout(gridlayout)

        # samples, 
        self.samples_gridlayout = aqt.qt.QGridLayout()
        self.sample_labels = []
        self.sample_play_buttons = []
        for i in range(self.sample_size):
            sample_label = aqt.qt.QLabel()
            sample_label.setText('sample')
            self.sample_labels.append(sample_label)
            sample_button = aqt.qt.QPushButton()
            sample_button.setText('Play Audio')
            sample_button.setObjectName(f'play_sample_{i}')
            def get_play_lambda(i):
                def play():
                    self.play_sample(i)
                return play
            sample_button.pressed.connect(get_play_lambda(i))
            self.sample_play_buttons.append(sample_button)
            self.samples_gridlayout.addWidget(sample_label, i, 0, 1, 1)
            self.samples_gridlayout.addWidget(sample_button, i, 1, 1, 1)
        self.samples_gridlayout.setColumnStretch(0, 70)
        self.samples_gridlayout.setColumnStretch(1, 30)
        self.samples_gridlayout.setContentsMargins(20, 20, 20, 20)
        vlayout.addLayout(self.samples_gridlayout)

        vlayout.addStretch()

        # buttom buttons
        buttonBox = aqt.qt.QDialogButtonBox()
        self.applyButton = buttonBox.addButton("Save Voice Selection", aqt.qt.QDialogButtonBox.AcceptRole)
        self.applyButton.setObjectName('apply')
        self.applyButton.setEnabled(False)
        self.cancelButton = buttonBox.addButton("Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancelButton.setObjectName('cancel')
        self.cancelButton.setStyleSheet(self.languagetools.anki_utils.get_red_stylesheet())
        vlayout.addWidget(buttonBox)

        # wire events
        # ===========

        language_combobox.currentIndexChanged.connect(self.language_index_changed)
        # run once
        self.language_index_changed(0)
        self.voice_combobox.currentIndexChanged.connect(self.voice_index_changed)

        samples_reload_button.pressed.connect(self.load_field_samples)
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
Example #7
0
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(700, 500)

        vlayout = aqt.qt.QVBoxLayout(self)

        vlayout.addWidget(
            gui_utils.get_header_label('Text Processing Settings'))

        # setup test input box
        # ====================

        vlayout.addWidget(gui_utils.get_medium_label('Preview Settings'))

        # first line
        hlayout = aqt.qt.QHBoxLayout()
        hlayout.addWidget(aqt.qt.QLabel('Transformation Type:'))
        self.sample_transformation_type_combo_box = aqt.qt.QComboBox()
        transformation_type_names = [
            x.name for x in constants.TransformationType
        ]
        self.sample_transformation_type_combo_box.addItems(
            transformation_type_names)
        hlayout.addWidget(self.sample_transformation_type_combo_box)

        label = aqt.qt.QLabel('Enter sample text:')
        hlayout.addWidget(label)
        self.sample_text_input = aqt.qt.QLineEdit()
        hlayout.addWidget(self.sample_text_input)
        hlayout.addStretch()
        vlayout.addLayout(hlayout)

        # second line
        hlayout = aqt.qt.QHBoxLayout()
        hlayout.addWidget(aqt.qt.QLabel('Transformed Text:'))
        self.sample_text_transformed_label = aqt.qt.QLabel(BLANK_TEXT)
        hlayout.addWidget(self.sample_text_transformed_label)
        hlayout.addStretch()
        vlayout.addLayout(hlayout)

        vlayout.addWidget(gui_utils.get_medium_label('Text Replacement'))

        # setup preview table
        # ===================

        self.table_view = aqt.qt.QTableView()
        self.table_view.setModel(self.textReplacementTableModel)
        self.table_view.setSelectionMode(
            aqt.qt.QTableView.SelectionMode.SingleSelection)
        # self.table_view.setSelectionBehavior(aqt.qt.QTableView.SelectionBehavior.SelectRows)
        header = self.table_view.horizontalHeader()
        header.setSectionResizeMode(0, aqt.qt.QHeaderView.Stretch)
        header.setSectionResizeMode(1, aqt.qt.QHeaderView.Stretch)
        vlayout.addWidget(self.table_view)

        # setup buttons below table
        hlayout = aqt.qt.QHBoxLayout()
        self.add_replace_simple_button = aqt.qt.QPushButton(
            'Add Simple Text Replacement Rule')
        hlayout.addWidget(self.add_replace_simple_button)
        self.add_replace_regex_button = aqt.qt.QPushButton(
            'Add Regex Text Replacement Rule')
        hlayout.addWidget(self.add_replace_regex_button)
        self.remove_replace_button = aqt.qt.QPushButton('Remove Selected Rule')
        hlayout.addWidget(self.remove_replace_button)
        vlayout.addLayout(hlayout)

        # setup bottom buttons
        # ====================

        buttonBox = aqt.qt.QDialogButtonBox()
        self.applyButton = buttonBox.addButton(
            "OK", aqt.qt.QDialogButtonBox.AcceptRole)
        self.applyButton.setStyleSheet(
            self.languagetools.anki_utils.get_green_stylesheet())
        self.cancelButton = buttonBox.addButton(
            "Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancelButton.setStyleSheet(
            self.languagetools.anki_utils.get_red_stylesheet())

        vlayout.addWidget(buttonBox)

        # wire events
        # ===========
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
        self.add_replace_simple_button.pressed.connect(
            lambda: self.textReplacementTableModel.add_replacement(
                constants.ReplaceType.simple))
        self.add_replace_regex_button.pressed.connect(
            lambda: self.textReplacementTableModel.add_replacement(
                constants.ReplaceType.regex))
        self.remove_replace_button.pressed.connect(
            self.delete_text_replacement)
        self.typing_timer = self.languagetools.anki_utils.wire_typing_timer(
            self.sample_text_input, self.sample_text_changed)
        self.sample_transformation_type_combo_box.currentIndexChanged.connect(
            self.sample_transformation_type_changed)
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(700, 500)

        vlayout = aqt.qt.QVBoxLayout(self)

        header_label_text_map = {
            constants.TransformationType.Translation: 'Add Translation',
            constants.TransformationType.Transliteration: 'Add Transliteration'
        }

        vlayout.addWidget(gui_utils.get_header_label(header_label_text_map[self.transformation_type]))

        description_label = aqt.qt.QLabel(f'After adding {self.transformation_type.name.lower()} to notes, the setting will be memorized.')
        vlayout.addWidget(description_label)

        # setup to/from fields
        # ====================

        gridlayout = aqt.qt.QGridLayout()

        # "from" side
        # -----------

        label_font_size = 13
        font1 = aqt.qt.QFont()
        font1.setBold(True)
        font1.setPointSize(label_font_size)

        from_label = aqt.qt.QLabel()
        from_label.setText('From Field:')
        from_label.setFont(font1)
        gridlayout.addWidget(from_label, 0, 0, 1, 1)

        self.from_combobox = aqt.qt.QComboBox()
        self.from_combobox.addItems(self.field_name_list)
        gridlayout.addWidget(self.from_combobox, 0, 1, 1, 1)

        gridlayout.addWidget(aqt.qt.QLabel('Language:'), 1, 0, 1, 1)

        self.from_language_label = aqt.qt.QLabel()
        gridlayout.addWidget(self.from_language_label, 1, 1, 1, 1)


        # "to" side
        # ---------

        to_label = aqt.qt.QLabel()
        to_label.setText('To Field:')
        to_label.setFont(font1)
        gridlayout.addWidget(to_label, 0, 3, 1, 1)

        self.to_combobox = aqt.qt.QComboBox()
        self.to_combobox.addItems(self.field_name_list)
        gridlayout.addWidget(self.to_combobox, 0, 4, 1, 1)

        gridlayout.addWidget(aqt.qt.QLabel('Language:'), 1, 3, 1, 1)
        self.to_language_label = aqt.qt.QLabel()
        gridlayout.addWidget(self.to_language_label, 1, 4, 1, 1)

        gridlayout.setColumnStretch(0, 50)
        gridlayout.setColumnStretch(1, 50)
        gridlayout.setColumnStretch(2, 30)
        gridlayout.setColumnStretch(3, 50)
        gridlayout.setColumnStretch(4, 50)

        gridlayout.setContentsMargins(20, 30, 20, 30)

        vlayout.addLayout(gridlayout)

        # setup translation service
        # =========================

        gridlayout = aqt.qt.QGridLayout()
        service_label = aqt.qt.QLabel()
        service_label.setFont(font1)
        service_label.setText('Service:')
        gridlayout.addWidget(service_label, 0, 0, 1, 1)

        self.service_combobox = aqt.qt.QComboBox()
        gridlayout.addWidget(self.service_combobox, 0, 1, 1, 1)


        self.load_translations_button = aqt.qt.QPushButton()
        self.load_button_text_map = {
            constants.TransformationType.Translation: 'Load Translations',
            constants.TransformationType.Transliteration: 'Load Transliterations'
        }        
        self.load_translations_button.setText(self.load_button_text_map[self.transformation_type])
        self.load_translations_button.setStyleSheet(self.languagetools.anki_utils.get_green_stylesheet())
        gridlayout.addWidget(self.load_translations_button, 0, 3, 1, 2)

        if self.transformation_type == constants.TransformationType.Translation:
            gridlayout.setColumnStretch(0, 50)
            gridlayout.setColumnStretch(1, 50)
            gridlayout.setColumnStretch(2, 30)
            gridlayout.setColumnStretch(3, 50)
            gridlayout.setColumnStretch(4, 50)
        elif self.transformation_type == constants.TransformationType.Transliteration:
            # need to provide more space for the services combobox
            gridlayout.setColumnStretch(0, 20)
            gridlayout.setColumnStretch(1, 120)
            gridlayout.setColumnStretch(2, 0)
            gridlayout.setColumnStretch(3, 20)
            gridlayout.setColumnStretch(4, 20)            

        gridlayout.setContentsMargins(20, 0, 20, 10)

        vlayout.addLayout(gridlayout)

        # setup progress bar
        # ==================

        self.progress_bar = aqt.qt.QProgressBar()
        vlayout.addWidget(self.progress_bar)

        # setup preview table
        # ===================

        self.table_view = aqt.qt.QTableView()
        self.table_view.setModel(self.noteTableModel)
        header = self.table_view.horizontalHeader()       
        header.setSectionResizeMode(0, aqt.qt.QHeaderView.Stretch)
        header.setSectionResizeMode(1, aqt.qt.QHeaderView.Stretch)
        vlayout.addWidget(self.table_view)

        # setup bottom buttons
        # ====================

        buttonBox = aqt.qt.QDialogButtonBox()
        self.applyButton = buttonBox.addButton("Apply To Notes", aqt.qt.QDialogButtonBox.AcceptRole)
        self.applyButton.setEnabled(False)
        self.cancelButton = buttonBox.addButton("Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancelButton.setStyleSheet(self.languagetools.anki_utils.get_red_stylesheet())

        
        vlayout.addWidget(buttonBox)

        self.pickDefaultFromToFields()
        self.updateTranslationOptions()

        # wire events
        # ===========
        self.from_combobox.currentIndexChanged.connect(self.fromFieldIndexChanged)
        self.to_combobox.currentIndexChanged.connect(self.toFieldIndexChanged)
        self.load_translations_button.pressed.connect(self.loadTranslations)
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
Example #9
0
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(500, 350)

        vlayout = aqt.qt.QVBoxLayout(self)
        vlayout.addWidget(gui_utils.get_header_label('Breakdown'))
        vlayout.addWidget(
            gui_utils.get_medium_label(
                f'{self.text} ({self.languagetools.get_language_name(self.from_language)})'
            ))

        gridlayout = aqt.qt.QGridLayout()

        # show tokenization options
        # show translation options, with checkbox
        # show transliteration options, with checkbox

        # create all widgets
        # ==================

        font1 = aqt.qt.QFont()
        font1.setBold(True)

        self.target_language_dropdown = aqt.qt.QComboBox()

        self.tokenization_dropdown = aqt.qt.QComboBox()
        self.translation_checkbox = aqt.qt.QCheckBox()
        self.translation_checkbox.setText('Enable')
        self.translation_dropdown = aqt.qt.QComboBox()
        self.transliteration_checkbox = aqt.qt.QCheckBox()
        self.transliteration_checkbox.setText('Enable')
        self.transliteration_dropdown = aqt.qt.QComboBox()
        self.target_field_dropdown = aqt.qt.QComboBox()
        self.target_field_dropdown.setDisabled(True)

        self.breakdown_result = aqt.qt.QLabel()
        self.breakdown_result.setTextInteractionFlags(
            aqt.qt.Qt.TextSelectableByMouse)
        self.breakdown_result.setText(
            '<i>Press Load Breakdown to see result</i>')

        target_language_label = aqt.qt.QLabel()
        target_language_label.setText('Target Language:')
        target_language_label.setFont(font1)

        segmentation_label = aqt.qt.QLabel()
        segmentation_label.setText('Segmentation:')
        segmentation_label.setFont(font1)

        translation_label = aqt.qt.QLabel()
        translation_label.setText('Translation:')
        translation_label.setFont(font1)

        transliteration_label = aqt.qt.QLabel()
        transliteration_label.setText('Transliteration:')
        transliteration_label.setFont(font1)

        self.load_button = aqt.qt.QPushButton()
        self.load_button.setText('Load Breakdown')
        self.load_button.setDisabled(False)
        self.load_button.setStyleSheet(
            self.languagetools.anki_utils.get_green_stylesheet())
        self.load_button.setFont(gui_utils.get_large_button_font())

        self.copy_to_field_button = aqt.qt.QPushButton()
        self.copy_to_field_button.setText('Copy to Field')
        self.copy_to_field_button.setDisabled(True)

        vlayout.addWidget(gui_utils.get_medium_label('Options'))

        # place widgets on grid
        # =====================

        regular_width = 2
        row = 0
        gridlayout.addWidget(segmentation_label, row, 0, 1, 1)
        gridlayout.addWidget(self.tokenization_dropdown, row, 1, 1,
                             regular_width)
        row = 1
        gridlayout.addWidget(target_language_label, row, 0, 1, 1)
        gridlayout.addWidget(self.target_language_dropdown, row, 1, 1,
                             regular_width)
        row = 2
        gridlayout.addWidget(translation_label, row, 0, 1, 1)
        gridlayout.addWidget(self.translation_checkbox, row, 1, 1, 1)
        gridlayout.addWidget(self.translation_dropdown, row, 2, 1, 1)
        row = 3
        gridlayout.addWidget(transliteration_label, row, 0, 1, 1)
        gridlayout.addWidget(self.transliteration_checkbox, row, 1, 1, 1)
        gridlayout.addWidget(self.transliteration_dropdown, row, 2, 1, 1)

        gridlayout.setContentsMargins(10, 10, 10, 10)
        vlayout.addLayout(gridlayout)

        # add result label
        # ================
        vlayout.addWidget(gui_utils.get_medium_label('Breakdown Result'))
        self.breakdown_result.setContentsMargins(10, 10, 10, 10)
        vlayout.addWidget(self.breakdown_result)

        # load button
        # ===========
        vlayout.addWidget(self.load_button)

        hlayout = aqt.qt.QHBoxLayout(self)
        hlayout.addWidget(self.copy_to_field_button)
        hlayout.addWidget(self.target_field_dropdown)
        vlayout.addLayout(hlayout)

        self.populate_target_languages()
        self.populate_controls()

        self.load_button.pressed.connect(self.load_breakdown)
        self.copy_to_field_button.pressed.connect(self.copy_to_field)
    def setupUi(self):
        self.setWindowTitle(constants.ADDON_NAME)
        self.resize(500, 350)

        vlayout = aqt.qt.QVBoxLayout(self)
        vlayout.addWidget(gui_utils.get_header_label('Choose Translation'))

        # add the source text / languages
        translation_info_gridlayout = aqt.qt.QGridLayout()
        vlayout.addLayout(translation_info_gridlayout)

        translation_info_gridlayout.addWidget(
            gui_utils.get_medium_label('Source Text'), 0, 0, 1, 1)

        self.original_text_label = aqt.qt.QLabel(self.original_text)
        translation_info_gridlayout.addWidget(self.original_text_label, 1, 0,
                                              1, 1)

        self.from_language_label = aqt.qt.QLabel(
            self.languagetools.get_language_name(self.from_language))
        translation_info_gridlayout.addWidget(
            gui_utils.get_medium_label('From'), 0, 1, 1, 1)
        translation_info_gridlayout.addWidget(self.from_language_label, 1, 1,
                                              1, 1)

        self.to_language_label = aqt.qt.QLabel(
            self.languagetools.get_language_name(self.to_language))
        translation_info_gridlayout.addWidget(gui_utils.get_medium_label('To'),
                                              0, 2, 1, 1)
        translation_info_gridlayout.addWidget(self.to_language_label, 1, 2, 1,
                                              1)

        translation_info_gridlayout.setColumnStretch(0, 60)
        translation_info_gridlayout.setColumnStretch(1, 20)
        translation_info_gridlayout.setColumnStretch(2, 20)

        vlayout.addLayout(translation_info_gridlayout)

        # add grid with translations
        vlayout.addWidget(gui_utils.get_medium_label('Translations Available'))
        translation_gridlayout = aqt.qt.QGridLayout()

        i = 0
        for key, value in self.all_translations.items():
            service_radio_button = aqt.qt.QRadioButton()
            service_radio_button.setObjectName(f'radio_button_{i}')
            service_radio_button.service = key
            service_radio_button.toggled.connect(self.on_translation_selected)
            service_label = aqt.qt.QLabel()
            service_label.setText(f'<b>{key}</b>')
            service_label.setObjectName(f'service_label_{i}')
            translation_label = aqt.qt.QLabel()
            translation_label.setText(f'{value}')
            translation_label.setObjectName(f'translation_label_{i}')
            translation_gridlayout.addWidget(service_radio_button, i, 0, 1, 1)
            translation_gridlayout.addWidget(service_label, i, 1, 1, 1)
            translation_gridlayout.addWidget(translation_label, i, 2, 1, 1)
            i += 1
        translation_gridlayout.setColumnStretch(0, 5)
        translation_gridlayout.setColumnStretch(1, 15)
        translation_gridlayout.setColumnStretch(2, 80)
        vlayout.addLayout(translation_gridlayout)

        vlayout.addStretch()

        # buttom buttons
        buttonBox = aqt.qt.QDialogButtonBox()
        self.apply_button = buttonBox.addButton(
            "OK", aqt.qt.QDialogButtonBox.AcceptRole)
        self.apply_button.setObjectName('apply')
        self.apply_button.setEnabled(False)
        self.cancel_button = buttonBox.addButton(
            "Cancel", aqt.qt.QDialogButtonBox.RejectRole)
        self.cancel_button.setObjectName('cancel')
        self.cancel_button.setStyleSheet(
            self.languagetools.anki_utils.get_red_stylesheet())
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
        vlayout.addWidget(buttonBox)