Exemplo n.º 1
0
    def __init__(self, parent, current_row, current_key, standard_colheads, standard_colnames):
        QDialog.__init__(self, parent)
        Ui_QCreateCustomColumn.__init__(self)
        self.setupUi(self)
        self.setWindowTitle(_('Create a custom column'))
        self.heading_label.setText(_('Create a custom column'))
        # Remove help icon on title bar
        icon = self.windowIcon()
        self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint))
        self.setWindowIcon(icon)

        self.simple_error = partial(error_dialog, self, show=True,
            show_copy_button=False)
        self.button_box.accepted.connect(self.accept)
        self.button_box.rejected.connect(self.reject)
        self.shortcuts.linkActivated.connect(self.shortcut_activated)
        text = '<p>'+_('Quick create:')
        for col, name in [('isbn', _('ISBN')), ('formats', _('Formats')),
                ('yesno', _('Yes/No')),
                ('tags', _('Tags')), ('series', _('Series')), ('rating',
                    _('Rating')), ('people', _("People's names"))]:
            text += ' <a href="col:%s">%s</a>,'%(col, name)
        text = text[:-1]
        self.shortcuts.setText(text)

        for sort_by in [_('Text'), _('Number'), _('Date'), _('Yes/No')]:
            self.composite_sort_by.addItem(sort_by)

        self.parent = parent
        self.parent.cc_column_key = None
        self.editing_col = current_row is not None
        self.standard_colheads = standard_colheads
        self.standard_colnames = standard_colnames
        self.column_type_box.setMaxVisibleItems(len(self.column_types))
        for t in self.column_types:
            self.column_type_box.addItem(self.column_types[t]['text'])
        self.column_type_box.currentIndexChanged.connect(self.datatype_changed)

        all_colors = [unicode(s) for s in list(QColor.colorNames())]
        self.enum_colors_label.setToolTip('<p>' + ', '.join(all_colors) + '</p>')

        if not self.editing_col:
            self.datatype_changed()
            self.exec_()
            return

        self.setWindowTitle(_('Edit a custom column'))
        self.heading_label.setText(_('Edit a custom column'))
        self.shortcuts.setVisible(False)
        idx = current_row
        if idx < 0:
            self.simple_error(_('No column selected'),
                    _('No column has been selected'))
            return
        col = current_key
        if col not in parent.custcols:
            self.simple_error('', _('Selected column is not a user-defined column'))
            return

        c = parent.custcols[col]
        self.column_name_box.setText(c['label'])
        self.column_heading_box.setText(c['name'])
        ct = c['datatype']
        if c['is_multiple']:
            ct = '*' + ct
        self.orig_column_number = c['colnum']
        self.orig_column_name = col
        column_numbers = dict(map(lambda x:(self.column_types[x]['datatype'], x),
                                  self.column_types))
        self.column_type_box.setCurrentIndex(column_numbers[ct])
        self.column_type_box.setEnabled(False)
        if ct == 'datetime':
            if c['display'].get('date_format', None):
                self.date_format_box.setText(c['display'].get('date_format', ''))
        elif ct in ['composite', '*composite']:
            self.composite_box.setText(c['display'].get('composite_template', ''))
            sb = c['display'].get('composite_sort', 'text')
            vals = ['text', 'number', 'date', 'bool']
            if sb in vals:
                sb = vals.index(sb)
            else:
                sb = 0
            self.composite_sort_by.setCurrentIndex(sb)
            self.composite_make_category.setChecked(
                                c['display'].get('make_category', False))
            self.composite_contains_html.setChecked(
                                c['display'].get('contains_html', False))
        elif ct == 'enumeration':
            self.enum_box.setText(','.join(c['display'].get('enum_values', [])))
            self.enum_colors.setText(','.join(c['display'].get('enum_colors', [])))
        elif ct in ['int', 'float']:
            if c['display'].get('number_format', None):
                self.number_format_box.setText(c['display'].get('number_format', ''))
        self.datatype_changed()
        if ct in ['text', 'composite', 'enumeration']:
            self.use_decorations.setChecked(c['display'].get('use_decorations', False))
        elif ct == '*text':
            self.is_names.setChecked(c['display'].get('is_names', False))
        self.description_box.setText(c['display'].get('description', ''))

        self.composite_contains_html.setToolTip('<p>' +
                _('If checked, this column will be displayed as HTML in '
                  'book details and the content server. This can be used to '
                  'construct links with the template language. For example, '
                  'the template '
                  '<pre>&lt;big&gt;&lt;b&gt;{title}&lt;/b&gt;&lt;/big&gt;'
                  '{series:| [|}{series_index:| [|]]}</pre>'
                  'will create a field displaying the title in bold large '
                  'characters, along with the series, for example <br>"<big><b>'
                  'An Oblique Approach</b></big> [Belisarius [1]]". The template '
                  '<pre>&lt;a href="http://www.beam-ebooks.de/ebook/{identifiers'
                  ':select(beam)}"&gt;Beam book&lt;/a&gt;</pre> '
                  'will generate a link to the book on the Beam ebooks site.') + '</p>')
        self.exec_()
Exemplo n.º 2
0
    def __init__(self, parent, editing, standard_colheads, standard_colnames):
        QDialog.__init__(self, parent)
        Ui_QCreateCustomColumn.__init__(self)
        self.setupUi(self)
        self.setWindowTitle(_("Create a custom column"))
        self.heading_label.setText(_("Create a custom column"))
        # Remove help icon on title bar
        icon = self.windowIcon()
        self.setWindowFlags(self.windowFlags() & (~Qt.WindowContextHelpButtonHint))
        self.setWindowIcon(icon)

        self.simple_error = partial(error_dialog, self, show=True, show_copy_button=False)
        self.button_box.accepted.connect(self.accept)
        self.button_box.rejected.connect(self.reject)
        self.shortcuts.linkActivated.connect(self.shortcut_activated)
        text = "<p>" + _("Quick create:")
        for col, name in [
            ("isbn", _("ISBN")),
            ("formats", _("Formats")),
            ("yesno", _("Yes/No")),
            ("tags", _("Tags")),
            ("series", _("Series")),
            ("rating", _("Rating")),
            ("people", _("People's names")),
        ]:
            text += ' <a href="col:%s">%s</a>,' % (col, name)
        text = text[:-1]
        self.shortcuts.setText(text)

        for sort_by in [_("Text"), _("Number"), _("Date"), _("Yes/No")]:
            self.composite_sort_by.addItem(sort_by)

        self.parent = parent
        self.editing_col = editing
        self.standard_colheads = standard_colheads
        self.standard_colnames = standard_colnames
        self.column_type_box.setMaxVisibleItems(len(self.column_types))
        for t in self.column_types:
            self.column_type_box.addItem(self.column_types[t]["text"])
        self.column_type_box.currentIndexChanged.connect(self.datatype_changed)
        if not self.editing_col:
            self.datatype_changed()
            self.exec_()
            return
        self.setWindowTitle(_("Edit a custom column"))
        self.heading_label.setText(_("Edit a custom column"))
        self.shortcuts.setVisible(False)
        idx = parent.opt_columns.currentRow()
        if idx < 0:
            self.simple_error(_("No column selected"), _("No column has been selected"))
            return
        col = unicode(parent.opt_columns.item(idx).data(Qt.UserRole).toString())
        if col not in parent.custcols:
            self.simple_error("", _("Selected column is not a user-defined column"))
            return

        c = parent.custcols[col]
        self.column_name_box.setText(c["label"])
        self.column_heading_box.setText(c["name"])
        ct = c["datatype"]
        if c["is_multiple"]:
            ct = "*" + ct
        self.orig_column_number = c["colnum"]
        self.orig_column_name = col
        column_numbers = dict(map(lambda x: (self.column_types[x]["datatype"], x), self.column_types))
        self.column_type_box.setCurrentIndex(column_numbers[ct])
        self.column_type_box.setEnabled(False)
        if ct == "datetime":
            if c["display"].get("date_format", None):
                self.date_format_box.setText(c["display"].get("date_format", ""))
        elif ct in ["composite", "*composite"]:
            self.composite_box.setText(c["display"].get("composite_template", ""))
            sb = c["display"].get("composite_sort", "text")
            vals = ["text", "number", "date", "bool"]
            if sb in vals:
                sb = vals.index(sb)
            else:
                sb = 0
            self.composite_sort_by.setCurrentIndex(sb)
            self.composite_make_category.setChecked(c["display"].get("make_category", False))
            self.composite_contains_html.setChecked(c["display"].get("contains_html", False))
        elif ct == "enumeration":
            self.enum_box.setText(",".join(c["display"].get("enum_values", [])))
            self.enum_colors.setText(",".join(c["display"].get("enum_colors", [])))
        elif ct in ["int", "float"]:
            if c["display"].get("number_format", None):
                self.number_format_box.setText(c["display"].get("number_format", ""))
        self.datatype_changed()
        if ct in ["text", "composite", "enumeration"]:
            self.use_decorations.setChecked(c["display"].get("use_decorations", False))
        elif ct == "*text":
            self.is_names.setChecked(c["display"].get("is_names", False))

        all_colors = [unicode(s) for s in list(QColor.colorNames())]
        self.enum_colors_label.setToolTip("<p>" + ", ".join(all_colors) + "</p>")

        self.composite_contains_html.setToolTip(
            "<p>"
            + _(
                "If checked, this column will be displayed as HTML in "
                "book details and the content server. This can be used to "
                "construct links with the template language. For example, "
                "the template "
                "<pre>&lt;big&gt;&lt;b&gt;{title}&lt;/b&gt;&lt;/big&gt;"
                "{series:| [|}{series_index:| [|]]}</pre>"
                "will create a field displaying the title in bold large "
                'characters, along with the series, for example <br>"<big><b>'
                'An Oblique Approach</b></big> [Belisarius [1]]". The template '
                '<pre>&lt;a href="http://www.beam-ebooks.de/ebook/{identifiers'
                ':select(beam)}"&gt;Beam book&lt;/a&gt;</pre> '
                "will generate a link to the book on the Beam ebooks site."
            )
            + "</p>"
        )
        self.exec_()