示例#1
0
    def show_option_dialog(self):
        option_dialog = QtGui.QDialog(self.main_window)
        option_dialog.setWindowTitle(
            self.c.get(const.CONFIG_WINDOW_TITLES, "option_dialog"))

        tab_widget = QtGui.QTabWidget(self)

        general_tab = self.create_general_tab()
        tab_widget.addTab(general_tab, "General")

        markdown_tab = self.create_markdown_tab()
        tab_widget.addTab(markdown_tab, "Markdown")

        button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                            | QtGui.QDialogButtonBox.Cancel)
        button_box.accepted.connect(option_dialog.accept)
        button_box.rejected.connect(option_dialog.reject)

        dialog_vbox = QtGui.QVBoxLayout()
        dialog_vbox.addWidget(tab_widget)
        dialog_vbox.addWidget(button_box)
        option_dialog.setLayout(dialog_vbox)

        if option_dialog.exec_() == QtGui.QDialog.Accepted:
            PrefHelper.save_prefs(preferences.PREFS)
        else:
            if PrefHelper.are_prefs_changed(
                    preferences.PREFS,
                    PrefHelper.load_preferences_from_disk()):
                print "Reverting preferences..."
                preferences.PREFS = PrefHelper.load_preferences_from_disk()
示例#2
0
    def show_option_dialog(self):
        option_dialog = QtGui.QDialog(self.main_window)
        option_dialog.setWindowTitle(self.c.get(const.CONFIG_WINDOW_TITLES,
                                                "option_dialog"))

        tab_widget = QtGui.QTabWidget(self)

        general_tab = self.create_general_tab()
        tab_widget.addTab(general_tab, "General")

        markdown_tab = self.create_markdown_tab()
        tab_widget.addTab(markdown_tab, "Markdown")

        button_box = QtGui.QDialogButtonBox(
                QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
        button_box.accepted.connect(option_dialog.accept)
        button_box.rejected.connect(option_dialog.reject)

        dialog_vbox = QtGui.QVBoxLayout()
        dialog_vbox.addWidget(tab_widget)
        dialog_vbox.addWidget(button_box)
        option_dialog.setLayout(dialog_vbox)

        if option_dialog.exec_() == QtGui.QDialog.Accepted:
            PrefHelper.save_prefs(preferences.PREFS)
        else:
            if PrefHelper.are_prefs_changed(
                    preferences.PREFS,
                    PrefHelper.load_preferences_from_disk()):
                print "Reverting preferences..."
                preferences.PREFS = PrefHelper.load_preferences_from_disk()
    def show_option_dialog(self):
        option_dialog = QtGui.QDialog(self.main_window)
        option_dialog.setWindowTitle(
            self.c.get(const.CONFIG_WINDOW_TITLES, "option_dialog"))

        tab_widget = QtGui.QTabWidget(self)

        general_tab = self.create_general_tab()
        tab_widget.addTab(general_tab, "General")

        markdown_tab = self.create_markdown_tab()
        tab_widget.addTab(markdown_tab, "Markdown")

        button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                            | QtGui.QDialogButtonBox.Cancel)
        button_box.accepted.connect(option_dialog.accept)
        button_box.rejected.connect(option_dialog.reject)

        dialog_vbox = QtGui.QVBoxLayout()
        dialog_vbox.addWidget(tab_widget)
        dialog_vbox.addWidget(button_box)
        option_dialog.setLayout(dialog_vbox)

        if option_dialog.exec_() == QtGui.QDialog.Accepted:
            PrefHelper.save_prefs(self.p)
        else:
            default_prefs = PrefHelper.get_default_preferences()
            if PrefHelper.are_dicts_different(self.p, default_prefs):
                self.p = default_prefs
示例#4
0
 def _on_bg_color_changed(self):
     """
     Event handler for when the hilite color has changed. Request to update the button,
     and save the new preferred color in the preferences.
     """
     self._update_background_button()
     self.p.PREFS["last_bg_color"] = self.bg_color
     PrefHelper.save_prefs(self.p.PREFS)
示例#5
0
    def show_doc_dialog(self):
        dialog = QtGui.QDialog(self)
        dialog.setWindowTitle("Supplementary Buttons for Anki Documentation")

        filename = os.path.join(PrefHelper.get_addons_folder(),
                                "extra_buttons", "docs", "doc_start.html")

        if not os.path.exists(filename):
            print "FILENAME {!r} DOES NOT EXIST".format(filename)
            return

        help_buttons = QtGui.QDialogButtonBox(dialog)
        help_buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok)

        help_buttons.accepted.connect(dialog.accept)

        view = QtWebKit.QWebView(dialog)
        view.load(QtCore.QUrl(filename))

        help_vbox = QtGui.QVBoxLayout()
        help_vbox.addWidget(view)
        help_vbox.addWidget(help_buttons)

        dialog.setLayout(help_vbox)

        dialog.exec_()
示例#6
0
    def markdown_syntax_styles_option(self):
        md_style_label = QtGui.QLabel(
            self.c.get(const.CONFIG_LABELS, "md_style_label"), self)
        md_style_combo = QtGui.QComboBox(self)
        md_style_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        md_style_files = os.listdir(
            os.path.join(PrefHelper.get_addons_folder(), const.FOLDER_NAME,
                         "pygments", "styles"))

        # pretty print styles
        for filename in sorted(md_style_files):
            if filename.startswith("_") or filename.endswith(".pyc"):
                continue
            (style, _) = os.path.splitext(filename)
            style = self.prettify_option_name(style)
            md_style_combo.addItem(style)

        all_items_in_combo = \
            [md_style_combo.itemText(i) for i in xrange(md_style_combo.count())]
        current_style = preferences.PREFS.get(const.MARKDOWN_SYNTAX_STYLE)
        current_style = self.prettify_option_name(current_style)
        if current_style and current_style in all_items_in_combo:
            index_current_style = all_items_in_combo.index(current_style)
            md_style_combo.setCurrentIndex(index_current_style)

        md_style_combo.currentIndexChanged[str].connect(
            lambda: self.value_comparison_event_handler(
                const.MARKDOWN_SYNTAX_STYLE,
                self.deprettify_option_name(md_style_combo.currentText())))

        hbox = self.put_elems_in_box((md_style_label, md_style_combo),
                                     const.HBOX, const.WIDGET)
        hbox.insertStretch(1, 1)

        return hbox
    def show_doc_dialog(self):
        dialog = QtGui.QDialog(self)
        dialog.setWindowTitle("Supplementary Buttons for Anki Documentation")

        filename = os.path.join(PrefHelper.get_addons_folder(),
                                "extra_buttons",
                                "docs",
                                "doc_start.html")

        if not os.path.exists(filename):
            print "FILENAME {!r} DOES NOT EXIST".format(filename)
            return

        help_buttons = QtGui.QDialogButtonBox(dialog)
        help_buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok)

        help_buttons.accepted.connect(dialog.accept)

        view = QtWebKit.QWebView(dialog)
        view.load(QtCore.QUrl(filename))

        help_vbox = QtGui.QVBoxLayout()
        help_vbox.addWidget(view)
        help_vbox.addWidget(help_buttons)

        dialog.setLayout(help_vbox)

        dialog.exec_()
示例#8
0
    def show_doc_dialog(self):
        dialog = QtGui.QDialog(self)
        dialog.setWindowTitle(self.c.get(const.CONFIG_WINDOW_TITLES,
                                         "doc_dialog"))

        filename = os.path.join(PrefHelper.get_addons_folder(),
                                const.FOLDER_NAME,
                                "docs",
                                "doc_start.html")

        if not os.path.exists(filename):
            print "FILENAME {!r} DOES NOT EXIST".format(filename)
            return

        help_buttons = QtGui.QDialogButtonBox(dialog)
        help_buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok)

        help_buttons.accepted.connect(dialog.accept)

        view = QtWebKit.QWebView(dialog)
        view.load(QtCore.QUrl(filename))

        help_vbox = QtGui.QVBoxLayout()
        help_vbox.addWidget(view)
        help_vbox.addWidget(help_buttons)

        dialog.setLayout(help_vbox)

        dialog.exec_()
示例#9
0
    def show_doc_dialog(self):
        dialog = QtGui.QDialog(self)
        dialog.setWindowTitle(
            self.c.get(const.CONFIG_WINDOW_TITLES, "doc_dialog"))

        filename = os.path.join(PrefHelper.get_addons_folder(),
                                const.FOLDER_NAME, "docs", "doc_start.html")

        if not os.path.exists(filename):
            print "FILENAME {!r} DOES NOT EXIST".format(filename)
            return

        help_buttons = QtGui.QDialogButtonBox(dialog)
        help_buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok)

        help_buttons.accepted.connect(dialog.accept)

        view = QtWebKit.QWebView(dialog)
        view.load(QtCore.QUrl(filename))

        help_vbox = QtGui.QVBoxLayout()
        help_vbox.addWidget(view)
        help_vbox.addWidget(help_buttons)

        dialog.setLayout(help_vbox)

        dialog.exec_()
def get_config_parser(path=None):
    """
    Return a RawConfigParser for the specified path.
    """
    if path is None:
        path = os.path.join(PrefHelper.get_addons_folder(), const.FOLDER_NAME,
                            const.CONFIG_FILENAME)
    config = ConfigParser.ConfigParser()
    ret = config.read(path)
    if not ret:
        raise Exception("Could not read config file {!r}".format(path))
    return config
示例#11
0
    def __init__(self, other, parent_window, fixed=False):
        super(OrderedList, self).__init__(parent_window)
        self.editor_instance = other
        config_path = os.path.join(PrefHelper.get_addons_folder(),
                                   const.FOLDER_NAME,
                                   const.CONFIG_FILENAME)
        self.c = utility.get_config_parser(config_path)

        if not fixed:
            self.show_dialog_window()
        else:
            self.insert_ordered_list(
                    preferences.PREFS["fixed_ol_type"][0], 1)
示例#12
0
def get_config_parser(path=None):
    """
    Return a RawConfigParser for the specified path.
    """
    if path is None:
        path = os.path.join(PrefHelper.get_addons_folder(),
                            const.FOLDER_NAME,
                            const.CONFIG_FILENAME)
    config = ConfigParser.ConfigParser()
    ret = config.read(path)
    if not ret:
        raise Exception("Could not read config file {!r}".format(path))
    return config
示例#13
0
    def markdown_syntax_styles_option(self):
        md_style_label = QtGui.QLabel(
                    self.c.get(const.CONFIG_LABELS, "md_style_label"), self)
        md_style_combo = QtGui.QComboBox(self)
        md_style_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        md_style_files = os.listdir(os.path.join(PrefHelper.get_addons_folder(),
                                                 const.FOLDER_NAME,
                                                 "pygments",
                                                 "styles"))

        # pretty print styles
        for filename in sorted(md_style_files):
            if filename.startswith("_") or filename.endswith(".pyc"):
                continue
            (style, _) = os.path.splitext(filename)
            style = self.prettify_option_name(style)
            md_style_combo.addItem(style)

        all_items_in_combo = \
            [md_style_combo.itemText(i) for i in xrange(md_style_combo.count())]
        current_style = preferences.PREFS.get(const.MARKDOWN_SYNTAX_STYLE)
        current_style = self.prettify_option_name(current_style)
        if current_style and current_style in all_items_in_combo:
            index_current_style = all_items_in_combo.index(current_style)
            md_style_combo.setCurrentIndex(index_current_style)

        md_style_combo.currentIndexChanged[str].connect(
                lambda: self.value_comparison_event_handler(
                    const.MARKDOWN_SYNTAX_STYLE,
                    self.deprettify_option_name(md_style_combo.currentText())))

        hbox = self.put_elems_in_box((md_style_label, md_style_combo),
                                     const.HBOX,
                                     const.WIDGET)
        hbox.insertStretch(1, 1)

        return hbox
示例#14
0
 def init():
     global PREFS
     global KEYS
     PREFS = PrefHelper.load_preferences_from_disk()
     KEYS = PrefHelper.get_current_keybindings()
 def init():
     global PREFS
     global KEYS
     PREFS = PrefHelper.get_current_preferences()
     KEYS = PrefHelper.get_current_keybindings()
示例#16
0
def on_bg_color_changed(self):
    self._update_background_button()
    preferences.PREFS["last_bg_color"] = self.bg_color
    PrefHelper.save_prefs(preferences.PREFS)
示例#17
0
def on_bg_color_changed(self):
    self._update_background_button()
    preferences.PREFS["last_bg_color"] = self.bg_color
    PrefHelper.save_prefs(preferences.PREFS)
示例#18
0
 def init():
     global PREFS
     global KEYS
     PREFS = PrefHelper.load_preferences_from_disk()
     KEYS = PrefHelper.get_current_keybindings()
    def show_option_dialog(self):
        option_dialog = QtGui.QDialog(self.main_window)
        option_dialog.setWindowTitle("Options for Supplementary Buttons")

        grid = QtGui.QGridLayout()
        l = [k for k in preferences.PREFS.keys() if k not in (
                                                const.CODE_CLASS,
                                                const.LAST_BG_COLOR,
                                                const.FIXED_OL_TYPE,
                                                const.MARKDOWN_SYNTAX_STYLE,
                                                const.MARKDOWN_LINE_NUMS,
                                                const.MARKDOWN_ALWAYS_REVERT,
                                                const.MARKDOWN_CODE_DIRECTION,
                                                const.BUTTON_PLACEMENT
                                            )]
        num_items = len(l) / 2.0
        num_items = num_items + 0.5 if (num_items % 1.0 > 0.0) else num_items

        # go through the keys in the prefs and make QCheckBoxes for them
        for index, option in enumerate(sorted(l)):
            checkbox = self.create_checkbox(option)
            if index >= num_items:
                col = 1
                row = index - num_items
                grid.addWidget(checkbox, row, col)
            else:
                col = 0
                row = index
                grid.addWidget(checkbox, row, col)

        cssClassLabel = QtGui.QLabel(
                "CSS class for <code> and <pre> code blocks", self)
        cssClassLabel.setToolTip("""\
This class will be automatically added when you use the code and pre buttons.
You can add the CSS you want in your stylesheet and refer to this class. E.g.
.myCodeClass { color: red; } will color the text of your code and pre elements
red.\
        """)
        cssClassText = QtGui.QLineEdit(
                preferences.PREFS.get(const.CODE_CLASS), self)
        cssClassHBox = QtGui.QHBoxLayout()
        cssClassHBox.addWidget(cssClassLabel)
        cssClassHBox.addWidget(cssClassText)

        checkBox = QtGui.QCheckBox("Fix ordered list type", self)
        checkBox.setToolTip("Do not show the choice dialog each time, "
                            "but always use the selected list type.")
        if preferences.PREFS.get(const.FIXED_OL_TYPE):
            checkBox.setChecked(True)
        else:
            checkBox.setChecked(False)

        checkBox.stateChanged.connect(
                lambda: self.enable_radio_buttons(checkBox))

        # make sure self.list_of_radio_buttons is empty
        # before adding new buttons
        self.list_of_radio_buttons = list()
        for type_ol in ("1.", "A.", "a.", "I.", "i."):
            rb = self.create_radiobutton(type_ol)
            self.list_of_radio_buttons.append(rb)

        ol_type = preferences.PREFS.get(const.FIXED_OL_TYPE)
        if not ol_type:
            self.list_of_radio_buttons[0].toggle()
        else:
            for rb in self.list_of_radio_buttons:
                if ol_type == rb.text():
                    rb.toggle()
                    break

        buttonGroup = QtGui.QButtonGroup(self)

        numRadioButton = 0
        for rb in self.list_of_radio_buttons:
            buttonGroup.addButton(rb, numRadioButton)
            numRadioButton += 1

        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(checkBox)
        for rb in self.list_of_radio_buttons:
            if not checkBox.isChecked():
                rb.setEnabled(False)
            hbox.addWidget(rb)

        # Markdown syntax highlighting

        md_style_label = QtGui.QLabel(
                "Markdown syntax highlighting style", self)
        md_style_combo = QtGui.QComboBox(self)
        md_style_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        md_style_files = os.listdir(os.path.join(PrefHelper.get_addons_folder(),
                                                 const.FOLDER_NAME,
                                                 "pygments",
                                                 "styles"))

        # pretty print styles
        for filename in sorted(md_style_files):
            if filename.startswith("_") or filename.endswith(".pyc"):
                continue
            (style, _) = os.path.splitext(filename)
            style = style.replace("_", " ").capitalize()
            md_style_combo.addItem(style)

        all_items_in_combo = \
            [md_style_combo.itemText(i) for i in xrange(md_style_combo.count())]
        current_style = preferences.PREFS.get(const.MARKDOWN_SYNTAX_STYLE)
        current_style = current_style.replace("_", " ").capitalize()
        if current_style and current_style in all_items_in_combo:
            index_current_style = all_items_in_combo.index(current_style)
            md_style_combo.setCurrentIndex(index_current_style)

        md_style_hbox = QtGui.QHBoxLayout()
        md_style_hbox.addWidget(md_style_label)
        md_style_hbox.addStretch(1)
        md_style_hbox.addWidget(md_style_combo)

        # line numbers Markdown code highlighting
        linenums_cb = QtGui.QCheckBox(
                "Toggle line numbers in code blocks", self)
        if preferences.PREFS.get(const.MARKDOWN_LINE_NUMS):
            linenums_cb.setChecked(True)

        linenums_hbox = QtGui.QHBoxLayout()
        linenums_hbox.addWidget(linenums_cb)

        # align Markdown code block
        code_align_label = QtGui.QLabel(u"Alignment for Markdown code blocks")
        code_align_combo = QtGui.QComboBox(self)
        code_align_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        alignments = ("left", "center", "right")
        for alignment in alignments:
            code_align_combo.addItem(alignment)
        current_alignment = preferences.PREFS.get(
                const.MARKDOWN_CODE_DIRECTION)
        code_align_combo.setCurrentIndex(alignments.index(current_alignment))
        code_align_hbox = QtGui.QHBoxLayout()
        code_align_hbox.addWidget(code_align_label)
        code_align_hbox.addStretch(1)
        code_align_hbox.addWidget(code_align_combo)

        # always revert automatically back to old Markdown
        # and skip the warning dialog
        automatic_revert_cb = QtGui.QCheckBox(
                "Always revert back automatically to old Markdown", self)
        automatic_revert_cb.setToolTip("""\
Do not show the warning dialog each time a conflict occurs, but revert back to
the old Markdown, discarding any changes made.\
""")
        if preferences.PREFS.get(const.MARKDOWN_ALWAYS_REVERT):
            automatic_revert_cb.setChecked(True)

        automatic_revert_hbox = QtGui.QHBoxLayout()
        automatic_revert_hbox.addWidget(automatic_revert_cb)

        # button placement
        button_placement_label = QtGui.QLabel(u"Buttons placement")
        button_placement_combo = QtGui.QComboBox(self)
        button_placement_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        for placement in const.PLACEMENT_POSITIONS:
            button_placement_combo.addItem(placement)
        current_placement = preferences.PREFS.get(
                const.BUTTON_PLACEMENT)
        button_placement_combo.setCurrentIndex(
                const.PLACEMENT_POSITIONS.index(current_placement))
        button_placement_hbox = QtGui.QHBoxLayout()
        button_placement_hbox.addWidget(button_placement_label)
        button_placement_hbox.addStretch(1)
        button_placement_hbox.addWidget(button_placement_combo)

        button_box = QtGui.QDialogButtonBox(
                QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
        button_box.accepted.connect(option_dialog.accept)
        button_box.rejected.connect(option_dialog.reject)

        vbox = QtGui.QVBoxLayout()
        vbox.addLayout(grid)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(button_placement_hbox)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(cssClassHBox)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(hbox)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(md_style_hbox)
        vbox.addLayout(code_align_hbox)
        vbox.addLayout(linenums_hbox)
        vbox.addLayout(automatic_revert_hbox)
        vbox.addWidget(button_box)

        option_dialog.setLayout(vbox)

        if option_dialog.exec_() == QtGui.QDialog.Accepted:
            # fixed ordered list type
            if checkBox.isChecked():
                selected_radio_button = \
                        buttonGroup.id(buttonGroup.checkedButton())
                preferences.PREFS[const.FIXED_OL_TYPE] = \
                    self.list_of_radio_buttons[selected_radio_button].text()
            else:
                preferences.PREFS[const.FIXED_OL_TYPE] = ""

            # line numbers for Markdown code highlighting
            if linenums_cb.isChecked():
                preferences.PREFS[const.MARKDOWN_LINE_NUMS] = True
            else:
                preferences.PREFS[const.MARKDOWN_LINE_NUMS] = False

            # always revert automatically back to old Markdown
            if automatic_revert_cb.isChecked():
                preferences.PREFS[const.MARKDOWN_ALWAYS_REVERT] = True
            else:
                preferences.PREFS[const.MARKDOWN_ALWAYS_REVERT] = False

            # style for code highlighting
            chosen_style = str(md_style_combo.currentText())
            chosen_style = chosen_style.lower().replace(" ", "_")
            preferences.PREFS[const.MARKDOWN_SYNTAX_STYLE] = chosen_style

            # alignment for Markdown code blocks
            chosen_alignment = str(code_align_combo.currentText())
            preferences.PREFS[const.MARKDOWN_CODE_DIRECTION] = \
                chosen_alignment

            # button placement
            chosen_placement = str(button_placement_combo.currentText())
            preferences.PREFS[const.BUTTON_PLACEMENT] = chosen_placement

            preferences.PREFS[const.CODE_CLASS] = cssClassText.text()

            PrefHelper.save_prefs(preferences.PREFS)
示例#20
0
    def show_option_dialog(self):
        option_dialog = QtGui.QDialog(self.main_window)
        option_dialog.setWindowTitle("Options for Supplementary Buttons")

        grid = QtGui.QGridLayout()
        l = [
            k for k in preferences.PREFS.keys()
            if k not in (const.CODE_CLASS, const.LAST_BG_COLOR,
                         const.FIXED_OL_TYPE, const.MARKDOWN_SYNTAX_STYLE,
                         const.MARKDOWN_LINE_NUMS,
                         const.MARKDOWN_ALWAYS_REVERT,
                         const.MARKDOWN_CODE_DIRECTION, const.BUTTON_PLACEMENT)
        ]
        num_items = len(l) / 2.0
        num_items = num_items + 0.5 if (num_items % 1.0 > 0.0) else num_items

        # go through the keys in the prefs and make QCheckBoxes for them
        for index, option in enumerate(sorted(l)):
            checkbox = self.create_checkbox(option)
            if index >= num_items:
                col = 1
                row = index - num_items
                grid.addWidget(checkbox, row, col)
            else:
                col = 0
                row = index
                grid.addWidget(checkbox, row, col)

        cssClassLabel = QtGui.QLabel(
            "CSS class for <code> and <pre> code blocks", self)
        cssClassLabel.setToolTip("""\
This class will be automatically added when you use the code and pre buttons.
You can add the CSS you want in your stylesheet and refer to this class. E.g.
.myCodeClass { color: red; } will color the text of your code and pre elements
red.\
        """)
        cssClassText = QtGui.QLineEdit(preferences.PREFS.get(const.CODE_CLASS),
                                       self)
        cssClassHBox = QtGui.QHBoxLayout()
        cssClassHBox.addWidget(cssClassLabel)
        cssClassHBox.addWidget(cssClassText)

        checkBox = QtGui.QCheckBox("Fix ordered list type", self)
        checkBox.setToolTip("Do not show the choice dialog each time, "
                            "but always use the selected list type.")
        if preferences.PREFS.get(const.FIXED_OL_TYPE):
            checkBox.setChecked(True)
        else:
            checkBox.setChecked(False)

        checkBox.stateChanged.connect(
            lambda: self.enable_radio_buttons(checkBox))

        # make sure self.list_of_radio_buttons is empty
        # before adding new buttons
        self.list_of_radio_buttons = list()
        for type_ol in ("1.", "A.", "a.", "I.", "i."):
            rb = self.create_radiobutton(type_ol)
            self.list_of_radio_buttons.append(rb)

        ol_type = preferences.PREFS.get(const.FIXED_OL_TYPE)
        if not ol_type:
            self.list_of_radio_buttons[0].toggle()
        else:
            for rb in self.list_of_radio_buttons:
                if ol_type == rb.text():
                    rb.toggle()
                    break

        buttonGroup = QtGui.QButtonGroup(self)

        numRadioButton = 0
        for rb in self.list_of_radio_buttons:
            buttonGroup.addButton(rb, numRadioButton)
            numRadioButton += 1

        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(checkBox)
        for rb in self.list_of_radio_buttons:
            if not checkBox.isChecked():
                rb.setEnabled(False)
            hbox.addWidget(rb)

        # Markdown syntax highlighting

        md_style_label = QtGui.QLabel("Markdown syntax highlighting style",
                                      self)
        md_style_combo = QtGui.QComboBox(self)
        md_style_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        md_style_files = os.listdir(
            os.path.join(PrefHelper.get_addons_folder(), const.FOLDER_NAME,
                         "pygments", "styles"))

        # pretty print styles
        for filename in sorted(md_style_files):
            if filename.startswith("_") or filename.endswith(".pyc"):
                continue
            (style, _) = os.path.splitext(filename)
            style = style.replace("_", " ").capitalize()
            md_style_combo.addItem(style)

        all_items_in_combo = \
            [md_style_combo.itemText(i) for i in xrange(md_style_combo.count())]
        current_style = preferences.PREFS.get(const.MARKDOWN_SYNTAX_STYLE)
        current_style = current_style.replace("_", " ").capitalize()
        if current_style and current_style in all_items_in_combo:
            index_current_style = all_items_in_combo.index(current_style)
            md_style_combo.setCurrentIndex(index_current_style)

        md_style_hbox = QtGui.QHBoxLayout()
        md_style_hbox.addWidget(md_style_label)
        md_style_hbox.addStretch(1)
        md_style_hbox.addWidget(md_style_combo)

        # line numbers Markdown code highlighting
        linenums_cb = QtGui.QCheckBox("Toggle line numbers in code blocks",
                                      self)
        if preferences.PREFS.get(const.MARKDOWN_LINE_NUMS):
            linenums_cb.setChecked(True)

        linenums_hbox = QtGui.QHBoxLayout()
        linenums_hbox.addWidget(linenums_cb)

        # align Markdown code block
        code_align_label = QtGui.QLabel(u"Alignment for Markdown code blocks")
        code_align_combo = QtGui.QComboBox(self)
        code_align_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        alignments = ("left", "center", "right")
        for alignment in alignments:
            code_align_combo.addItem(alignment)
        current_alignment = preferences.PREFS.get(
            const.MARKDOWN_CODE_DIRECTION)
        code_align_combo.setCurrentIndex(alignments.index(current_alignment))
        code_align_hbox = QtGui.QHBoxLayout()
        code_align_hbox.addWidget(code_align_label)
        code_align_hbox.addStretch(1)
        code_align_hbox.addWidget(code_align_combo)

        # always revert automatically back to old Markdown
        # and skip the warning dialog
        automatic_revert_cb = QtGui.QCheckBox(
            "Always revert back automatically to old Markdown", self)
        automatic_revert_cb.setToolTip("""\
Do not show the warning dialog each time a conflict occurs, but revert back to
the old Markdown, discarding any changes made.\
""")
        if preferences.PREFS.get(const.MARKDOWN_ALWAYS_REVERT):
            automatic_revert_cb.setChecked(True)

        automatic_revert_hbox = QtGui.QHBoxLayout()
        automatic_revert_hbox.addWidget(automatic_revert_cb)

        # button placement
        button_placement_label = QtGui.QLabel(u"Buttons placement")
        button_placement_combo = QtGui.QComboBox(self)
        button_placement_combo.setMinimumWidth(const.MIN_COMBOBOX_WIDTH)
        for placement in const.PLACEMENT_POSITIONS:
            button_placement_combo.addItem(placement)
        current_placement = preferences.PREFS.get(const.BUTTON_PLACEMENT)
        button_placement_combo.setCurrentIndex(
            const.PLACEMENT_POSITIONS.index(current_placement))
        button_placement_hbox = QtGui.QHBoxLayout()
        button_placement_hbox.addWidget(button_placement_label)
        button_placement_hbox.addStretch(1)
        button_placement_hbox.addWidget(button_placement_combo)

        button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                            | QtGui.QDialogButtonBox.Cancel)
        button_box.accepted.connect(option_dialog.accept)
        button_box.rejected.connect(option_dialog.reject)

        vbox = QtGui.QVBoxLayout()
        vbox.addLayout(grid)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(button_placement_hbox)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(cssClassHBox)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(hbox)
        vbox.addWidget(utility.create_horizontal_rule())
        vbox.addLayout(md_style_hbox)
        vbox.addLayout(code_align_hbox)
        vbox.addLayout(linenums_hbox)
        vbox.addLayout(automatic_revert_hbox)
        vbox.addWidget(button_box)

        option_dialog.setLayout(vbox)

        if option_dialog.exec_() == QtGui.QDialog.Accepted:
            # fixed ordered list type
            if checkBox.isChecked():
                selected_radio_button = \
                        buttonGroup.id(buttonGroup.checkedButton())
                preferences.PREFS[const.FIXED_OL_TYPE] = \
                    self.list_of_radio_buttons[selected_radio_button].text()
            else:
                preferences.PREFS[const.FIXED_OL_TYPE] = ""

            # line numbers for Markdown code highlighting
            if linenums_cb.isChecked():
                preferences.PREFS[const.MARKDOWN_LINE_NUMS] = True
            else:
                preferences.PREFS[const.MARKDOWN_LINE_NUMS] = False

            # always revert automatically back to old Markdown
            if automatic_revert_cb.isChecked():
                preferences.PREFS[const.MARKDOWN_ALWAYS_REVERT] = True
            else:
                preferences.PREFS[const.MARKDOWN_ALWAYS_REVERT] = False

            # style for code highlighting
            chosen_style = str(md_style_combo.currentText())
            chosen_style = chosen_style.lower().replace(" ", "_")
            preferences.PREFS[const.MARKDOWN_SYNTAX_STYLE] = chosen_style

            # alignment for Markdown code blocks
            chosen_alignment = str(code_align_combo.currentText())
            preferences.PREFS[const.MARKDOWN_CODE_DIRECTION] = \
                chosen_alignment

            # button placement
            chosen_placement = str(button_placement_combo.currentText())
            preferences.PREFS[const.BUTTON_PLACEMENT] = chosen_placement

            preferences.PREFS[const.CODE_CLASS] = cssClassText.text()

            PrefHelper.save_prefs(preferences.PREFS)