def __init__(self):
        super().__init__()

        self._label_info = QLabel()

        self._button_append = QPushButton('Add')
        self._button_append.clicked.connect(self._on_append_clicked)

        self._spin_box_numbers = QSpinBox()
        self._spin_box_numbers.setRange(1, 1_000_000)
        self._spin_box_numbers.setValue(1_000_000)

        h_layout = QHBoxLayout()
        h_layout.addWidget(self._button_append)
        h_layout.addWidget(self._spin_box_numbers)
        h_layout.addWidget(QLabel('objects'))

        main_layout = QVBoxLayout()
        main_layout.addWidget(self._label_info)
        main_layout.addLayout(h_layout)
        self.setLayout(main_layout)

        self._items = []

        pid = current_process().pid
        self._process = psutil.Process(pid)

        self._timer = QTimer()
        self._timer.timeout.connect(self.update_memory_info)
        self._timer.start(500)

        self.update_memory_info()
Ejemplo n.º 2
0
        def __init__(self, p=None):
            QDialog.__init__(self, p)
            self.setWindowTitle("Generate page layout...")
            self.layout = QFormLayout()

            self.numberOfLabelsSpinBox = QSpinBox()
            self.numberOfLabelsSpinBox.setRange(1, 200)
            self.numberOfLabelsSpinBox.setValue(
                generate_settings['defaultNumberOfLabels'])
            self.layout.addRow("Number of labels", self.numberOfLabelsSpinBox)

            self.firstLabelArticleNumberSB = QSpinBox()
            self.firstLabelArticleNumberSB.setRange(0, 9999)
            self.firstLabelArticleNumberSB.setValue(
                generate_settings['firstLabelArticleNumber'])
            self.layout.addRow("First label article number",
                               self.firstLabelArticleNumberSB)

            self.weekNrYearLE = QLineEdit()
            self.weekNrYearLE.setText(generate_settings['weekNrYear'])
            self.layout.addRow("Week nr/ year", self.weekNrYearLE)

            self.lotNameLE = QLineEdit()
            self.lotNameLE.setText(generate_settings['lotName'])
            self.layout.addRow("Lot", self.lotNameLE)

            self.generatePB = QPushButton("Generate")
            self.generatePB.clicked.connect(self.onGenerate)
            self.layout.addRow("", self.generatePB)
            self.cancelPB = QPushButton("Cancel")
            self.cancelPB.clicked.connect(self.close)
            self.layout.addRow("", self.cancelPB)
            self.setLayout(self.layout)
Ejemplo n.º 3
0
 def createEditor(self, parent, option, index):
     sb = QSpinBox(parent)
     sb.setMinimum(0)
     sb.setMaximum(5)
     sb.setSuffix(' ' + _('stars'))
     sb.setSpecialValueText(_('Not rated'))
     return sb
Ejemplo n.º 4
0
 def setup_ui(self, parent):
     self.make_widgets(parent, EditWithComplete)
     values = self.all_values = list(self.db.all_custom(num=self.col_id))
     values.sort(key=sort_key)
     self.main_widget.setSizeAdjustPolicy(
         self.main_widget.AdjustToMinimumContentsLengthWithIcon)
     self.main_widget.setMinimumContentsLength(25)
     self.widgets.append(QLabel('', parent))
     w = QWidget(parent)
     layout = QHBoxLayout(w)
     layout.setContentsMargins(0, 0, 0, 0)
     self.remove_series = QCheckBox(parent)
     self.remove_series.setText(_('Remove series'))
     layout.addWidget(self.remove_series)
     self.idx_widget = QCheckBox(parent)
     self.idx_widget.setText(_('Automatically number books'))
     layout.addWidget(self.idx_widget)
     self.force_number = QCheckBox(parent)
     self.force_number.setText(_('Force numbers to start with '))
     layout.addWidget(self.force_number)
     self.series_start_number = QSpinBox(parent)
     self.series_start_number.setMinimum(1)
     self.series_start_number.setMaximum(9999999)
     self.series_start_number.setProperty("value", 1)
     layout.addWidget(self.series_start_number)
     layout.addItem(
         QSpacerItem(20, 10, QSizePolicy.Expanding, QSizePolicy.Minimum))
     self.widgets.append(w)
     self.idx_widget.stateChanged.connect(self.check_changed_checkbox)
     self.force_number.stateChanged.connect(self.check_changed_checkbox)
     self.series_start_number.valueChanged.connect(
         self.check_changed_checkbox)
     self.remove_series.stateChanged.connect(self.check_changed_checkbox)
     self.ignore_change_signals = False
Ejemplo n.º 5
0
    def __init__(self, width, height, parent=None):
        QDialog.__init__(self, parent)
        self.l = l = QFormLayout(self)
        self.setLayout(l)
        self.aspect_ratio = width / float(height)
        l.addRow(QLabel(_('Choose the new width and height')))

        self._width = w = QSpinBox(self)
        w.setMinimum(1)
        w.setMaximum(10 * width)
        w.setValue(width)
        w.setSuffix(' px')
        l.addRow(_('&Width:'), w)

        self._height = h = QSpinBox(self)
        h.setMinimum(1)
        h.setMaximum(10 * height)
        h.setValue(height)
        h.setSuffix(' px')
        l.addRow(_('&Height:'), h)
        connect_lambda(w.valueChanged, self,
                       lambda self: self.keep_ar('width'))
        connect_lambda(h.valueChanged, self,
                       lambda self: self.keep_ar('height'))

        self.ar = ar = QCheckBox(_('Keep &aspect ratio'))
        ar.setChecked(True)
        l.addRow(ar)
        self.resize(self.sizeHint())

        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok
                                        | QDialogButtonBox.Cancel)
        bb.accepted.connect(self.accept)
        bb.rejected.connect(self.reject)
        l.addRow(bb)
Ejemplo n.º 6
0
 def ulkoinen_voima_valikko(self):
     '''Luo voiman suuruus -tekstin'''
     self.ulkoinen_voima = QGraphicsSimpleTextItem("Voiman suuruus")
     self.ulkoinen_voima.setPos(600, 5)
     self.ulkoinen_voima.font = QtGui.QFont()
     self.ulkoinen_voima.font.setPointSize(12)
     self.ulkoinen_voima.setFont(self.ulkoinen_voima.font)
     self.lisaa_ulkoinen_voima.setEnabled(False)
     self.scene.addItem(self.ulkoinen_voima)
     self.ulkoinen_voima.hide()
     '''Luo voiman arvon QSpinBoxin'''
     self.sp_voima = QSpinBox()
     self.sp_voima.move(750, 5)
     self.sp_voima.setRange(0, 10000)
     self.sp_voima.setSingleStep(1)
     self.sp_voima.setMinimumHeight(30)
     self.sp_voima.setValue(int(Ominaisuudet.palauta_voima(self)))
     self.sp_voima.valueChanged.connect(self.paivita_voima)
     self.scene.addWidget(self.sp_voima)
     self.sp_voima.hide()
     '''Luo yksikönvalinta QComboBOxin'''
     self.yksikko_voima = QComboBox()
     self.yksikko_voima.addItem("kN", 0)
     self.yksikko_voima.addItem("N", 1)
     self.yksikko_voima.move(820, 5)
     self.yksikko_voima.setMinimumHeight(30)
     self.yksikko_voima.setCurrentIndex(
         int(Ominaisuudet.palauta_voiman_yksikko(self)))
     self.yksikko_voima.setEditable(True)
     self.yksikko_voima.lineEdit().setAlignment(QtCore.Qt.AlignCenter)
     self.scene.addWidget(self.yksikko_voima)
     self.yksikko_voima.currentIndexChanged.connect(
         self.paivita_yksikko_voima)
     self.yksikko_voima.hide()
Ejemplo n.º 7
0
    def __init__(self, mainWindow, quantity):

        # appel du constructeur de la classe de base :
        QWidget.__init__(self, mainWindow)

        self.mw = mainWindow  # la fenêtre de l'application principale

        # Attributs (objets persistants)
        self.__quantity = quantity  # "position" or "velocity"
        self.__data1 = None  # data for the first plot
        self.__data2 = None  # data for tthe second
        self.__figure = None  # figure tracé
        self.__axes1 = None  # système d'axes tracé 1
        self.__axes2 = None  # système d'axes tracé 2
        self.__canvas = None  # pour le tracé matplot.lib
        self.__toolbar = None  # barre d'outils tracé
        self.__time = None  # abcissa values for plot
        self.__xlim = None  # xmin, xmay tracé
        self.__xlabel = None  # étiquette axe X (n° image ou temps [s])
        self.__ylim1 = None  # ymin, ymax tracé x(t)
        self.__ylim2 = None  # ymin, ymax tracé y(t)

        self.btn_imageSize = QRadioButton("ImageSize", self)
        self.btn_autoSize = QRadioButton("AutoSize", self)

        self.btn_smooth_Vx = QCheckBox("Lissage Vx", self)
        self.btn_smooth_Vy = QCheckBox("Lissage Vy", self)
        self.x_mav_nb_pts = QSpinBox(parent=self)  # X velocity moving average
        self.y_mav_nb_pts = QSpinBox(parent=self)  # Y velocity moving average

        self.__initUI()  # Initialisation de l'interface utilisateur
Ejemplo n.º 8
0
 def createEditor(self, parent, option, index):
     sb = QSpinBox(parent)
     sb.setMinimum(0)
     sb.setMaximum(5)
     sb.setSuffix(' ' + _('stars'))
     sb.setSpecialValueText(_('Not rated'))
     return sb
Ejemplo n.º 9
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent=parent)
        self.l = l = QFormLayout(self)
        self.setLayout(l)
        self.setWindowTitle(_('Import OPML file'))
        self.setWindowIcon(QIcon(I('opml.png')))

        self.h = h = QHBoxLayout()
        self.path = p = QLineEdit(self)
        p.setMinimumWidth(300)
        p.setPlaceholderText(_('Path to OPML file'))
        h.addWidget(p)
        self.cfb = b = QToolButton(self)
        b.setIcon(QIcon(I('document_open.png')))
        b.setToolTip(_('Browse for OPML file'))
        b.clicked.connect(self.choose_file)
        h.addWidget(b)
        l.addRow(_('&OPML file:'), h)
        l.labelForField(h).setBuddy(p)
        b.setFocus(Qt.OtherFocusReason)

        self._articles_per_feed = a = QSpinBox(self)
        a.setMinimum(1), a.setMaximum(1000), a.setValue(100)
        a.setToolTip(_('Maximum number of articles to download per RSS feed'))
        l.addRow(_('&Maximum articles per feed:'), a)

        self._oldest_article = o = QSpinBox(self)
        o.setMinimum(1), o.setMaximum(3650), o.setValue(7)
        o.setSuffix(_(' days'))
        o.setToolTip(
            _('Articles in the RSS feeds older than this will be ignored'))
        l.addRow(_('&Oldest article:'), o)

        self.preserve_groups = g = QCheckBox(
            _('Preserve groups in the OPML file'))
        g.setToolTip('<p>' + _(
            'If enabled, every group of feeds in the OPML file will be converted into a single recipe. Otherwise every feed becomes its own recipe'
        ))
        g.setChecked(True)
        l.addRow(g)

        self._replace_existing = r = QCheckBox(_('Replace existing recipes'))
        r.setToolTip('<p>' + _(
            'If enabled, any existing recipes with the same titles as entries in the OPML file will be replaced.'
            ' Otherwise, new entries with modified titles will be created'))
        r.setChecked(True)
        l.addRow(r)

        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok
                                        | QDialogButtonBox.Cancel)
        bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
        l.addRow(bb)

        self.recipes = ()
Ejemplo n.º 10
0
    def __init__(self):
        QWidget.__init__(self)
        self.l = QHBoxLayout()
        self.setLayout(self.l)

        self.label = QLabel("Max number of last issues to download:")
        self.l.addWidget(self.label)

        self.max_number = QSpinBox(self)
        self.max_number.setValue(prefs["max_numbers"])
        self.max_number.setMinimum(0)
        self.l.addWidget(self.max_number)
        self.label.setBuddy(self.max_number)
Ejemplo n.º 11
0
    def __init__(self):
        QWidget.__init__(self)
        self.layout = QGridLayout()
        self.layout.setSpacing(10)
        self.setLayout(self.layout)

        self.index = 0

        self.api_key = QLineEdit(self)
        self.api_key.setText(PREFS['api_key'])
        self.add_labeled_widget('&API key:', self.api_key)

        # Worker threads is the maximum number of worker threads to spawn.
        # Restricted to 1+
        self.worker_threads = QSpinBox(self)
        self.worker_threads.setMinimum(1)
        self.worker_threads.setValue(PREFS['worker_threads'])
        self.add_labeled_widget('&Worker threads:', self.worker_threads)

        # Request interval represents wait time between batches of requests.
        self.request_interval = QSpinBox(self)
        self.request_interval.setMinimum(0)
        self.request_interval.setValue(PREFS['request_interval'])
        self.add_labeled_widget('&Request interval (seconds):',
                                self.request_interval)

        # Request batch is the maximum number of requests to run at a time.
        # Restricted to 1+
        self.request_batch_size = QSpinBox(self)
        self.request_batch_size.setMinimum(1)
        self.request_batch_size.setValue(PREFS['request_batch_size'])
        self.add_labeled_widget('&Request batch size:',
                                self.request_batch_size)

        # Retries is the number of times to retry if we get any error
        # from comicvine besides a rate limit error.
        self.retries = QSpinBox(self)
        self.retries.setMinimum(0)
        self.retries.setValue(PREFS['retries'])
        self.add_labeled_widget('&Retries:', self.retries)

        # Search volume limit is the max number of volumes to return from
        # a volume search.
        self.search_volume_limit = QSpinBox(self)
        self.search_volume_limit.setMinimum(10)
        self.search_volume_limit.setMaximum(10000)
        self.search_volume_limit.setSingleStep(10)
        self.search_volume_limit.setValue(PREFS['search_volume_limit'])
        self.add_labeled_widget('&search_volume_limit:',
                                self.search_volume_limit)
Ejemplo n.º 12
0
    def initUI(self):
        self.setFixedSize(800, 600)

        layout = QVBoxLayout()

        layout1 = QHBoxLayout()

        layout1.addWidget(QLabel('地图类型'))
        tmp = QComboBox(self)
        tmp.addItems(self.types)
        tmp.currentTextChanged.connect(self.swap_menu)
        self.typeCom = tmp
        layout1.addWidget(tmp)
        layout1.addStretch(1)

        layout1.addWidget(QLabel('编辑器宽高:'))
        tmp = QSpinBox(self)
        tmp.setMaximum(1960)
        tmp.setMinimum(400)
        tmp.setValue(600)
        tmp.setSingleStep(100)
        layout1.addWidget(tmp)
        tmp = QSpinBox(self)
        tmp.setMaximum(1080)
        tmp.setSingleStep(100)
        tmp.setMinimum(400)
        layout1.addWidget(tmp)

        layout.addLayout(layout1)

        layout1 = QHBoxLayout()
        self.layer1 = []
        tmp = QLabel(self)
        self.layer1.append(tmp)
        self.image = tmp
        self.image.filepath = None
        layout1.addWidget(tmp)
        tmp = QPushButton('选择文件', self)
        tmp.clicked.connect(self.open_file)
        self.layer1.append(tmp)
        layout1.addWidget(tmp)

        layout.addLayout(layout1)

        tmp = QPushButton('开始编辑', self)
        tmp.clicked.connect(self.edit)
        layout.addWidget(tmp)

        self.setLayout(layout)
Ejemplo n.º 13
0
    def __init__(self):
        QWidget.__init__(self)
        self.layout = QGridLayout()
        self.layout.setSpacing(10)
        self.setLayout(self.layout)

        self.index = 0

        self.api_key = QLineEdit(self)
        self.api_key.setText(PREFS['api_key'])
        self.add_labeled_widget('&API key:', self.api_key)

        # Worker threads is the maximum number of worker threads to spawn.
        # Restricted to 1+
        self.worker_threads = QSpinBox(self)
        self.worker_threads.setMinimum(1)
        self.worker_threads.setValue(PREFS['worker_threads'])
        self.add_labeled_widget('&Worker threads:', self.worker_threads)

        # Request interval represents wait time between batches of requests.
        self.request_interval = QSpinBox(self)
        self.request_interval.setMinimum(0)
        self.request_interval.setValue(PREFS['request_interval'])
        self.add_labeled_widget('&Request interval (seconds):',
                                self.request_interval)

        # Request batch is the maximum number of requests to run at a time.
        # Restricted to 1+
        self.request_batch_size = QSpinBox(self)
        self.request_batch_size.setMinimum(1)
        self.request_batch_size.setValue(PREFS['request_batch_size'])
        self.add_labeled_widget('&Request batch size:', self.request_batch_size)

        # Retries is the number of times to retry if we get any error
        # from comicvine besides a rate limit error.
        self.retries = QSpinBox(self)
        self.retries.setMinimum(0)
        self.retries.setValue(PREFS['retries'])
        self.add_labeled_widget('&Retries:', self.retries)

        # Search volume limit is the max number of volumes to return from
        # a volume search.
        self.search_volume_limit = QSpinBox(self)
        self.search_volume_limit.setMinimum(10)
        self.search_volume_limit.setMaximum(10000)
        self.search_volume_limit.setSingleStep(10)
        self.search_volume_limit.setValue(PREFS['search_volume_limit'])
        self.add_labeled_widget('&search_volume_limit:',
                                self.search_volume_limit)
Ejemplo n.º 14
0
 def setup_ui(self, parent):
     self.make_widgets(parent, EditWithComplete)
     values = self.all_values = list(self.db.all_custom(num=self.col_id))
     values.sort(key=sort_key)
     self.main_widget.setSizeAdjustPolicy(self.main_widget.AdjustToMinimumContentsLengthWithIcon)
     self.main_widget.setMinimumContentsLength(25)
     self.widgets.append(QLabel('', parent))
     w = QWidget(parent)
     layout = QHBoxLayout(w)
     layout.setContentsMargins(0, 0, 0, 0)
     self.remove_series = QCheckBox(parent)
     self.remove_series.setText(_('Remove series'))
     layout.addWidget(self.remove_series)
     self.idx_widget = QCheckBox(parent)
     self.idx_widget.setText(_('Automatically number books'))
     layout.addWidget(self.idx_widget)
     self.force_number = QCheckBox(parent)
     self.force_number.setText(_('Force numbers to start with '))
     layout.addWidget(self.force_number)
     self.series_start_number = QSpinBox(parent)
     self.series_start_number.setMinimum(1)
     self.series_start_number.setMaximum(9999999)
     self.series_start_number.setProperty("value", 1)
     layout.addWidget(self.series_start_number)
     layout.addItem(QSpacerItem(20, 10, QSizePolicy.Expanding, QSizePolicy.Minimum))
     self.widgets.append(w)
     self.idx_widget.stateChanged.connect(self.check_changed_checkbox)
     self.force_number.stateChanged.connect(self.check_changed_checkbox)
     self.series_start_number.valueChanged.connect(self.check_changed_checkbox)
     self.remove_series.stateChanged.connect(self.check_changed_checkbox)
     self.ignore_change_signals = False
Ejemplo n.º 15
0
    def setup_ui(self):
        self.splitter = QSplitter(self)
        self.l = l = QVBoxLayout(self)
        l.addWidget(self.splitter)
        l.addWidget(self.bb)
        self.w = w = QGroupBox(_('Theme Metadata'), self)
        self.splitter.addWidget(w)
        l = w.l = QFormLayout(w)
        self.missing_icons_group = mg = QGroupBox(self)
        self.mising_icons = mi = QListWidget(mg)
        mi.setSelectionMode(mi.NoSelection)
        mg.l = QVBoxLayout(mg)
        mg.l.addWidget(mi)
        self.splitter.addWidget(mg)
        self.title = QLineEdit(self)
        l.addRow(_('&Title:'), self.title)
        self.author = QLineEdit(self)
        l.addRow(_('&Author:'), self.author)
        self.version = v = QSpinBox(self)
        v.setMinimum(1), v.setMaximum(1000000)
        l.addRow(_('&Version:'), v)
        self.description = QTextEdit(self)
        l.addRow(self.description)
        self.refresh_button = rb = self.bb.addButton(_('&Refresh'), self.bb.ActionRole)
        rb.setIcon(QIcon(I('view-refresh.png')))
        rb.clicked.connect(self.refresh)

        self.apply_report()
Ejemplo n.º 16
0
    def init_ui(self):

        layout = QGridLayout()
        for i, lbl in enumerate((
                self.tr("Rows"), self.tr("Columns"),
                self.tr("The distance between the outer borders"),
                self.tr("Distance between border and content"))):
            # noinspection PyArgumentList
            layout.addWidget(QLabel(lbl, self), i, 0)
            self.controls.append(QSpinBox(self))
            # noinspection PyArgumentList
            layout.addWidget(self.controls[-1], i, 1)
        self.controls[2].setValue(
            self._cfg.get('TextEditor/PaddingInTable', 3))
        self.controls[3].setValue(self._cfg.get('TextEditor/SpaceInTable', 0))

        insert_button = QPushButton(self.tr("Insert"), self)
        insert_button.clicked.connect(self.insert)
        # noinspection PyArgumentList
        layout.addWidget(insert_button, 4, 0, 1, 2)
        self.controls.append(insert_button)

        self.setWindowTitle(self.tr("Insert table"))
        # self.setGeometry(300, 300, 200, 100)
        self.setLayout(layout)
Ejemplo n.º 17
0
def get_bulk_rename_settings(parent, number, msg=None, sanitize=sanitize_file_name_unicode, leading_zeros=True, prefix=None, category='text'):  # {{{
    d = QDialog(parent)
    d.setWindowTitle(_('Bulk rename items'))
    d.l = l = QFormLayout(d)
    d.setLayout(l)
    d.prefix = p = QLineEdit(d)
    prefix = prefix or {k:v for k, __, v in CATEGORIES}.get(category, _('Chapter-'))
    p.setText(prefix)
    p.selectAll()
    d.la = la = QLabel(msg or _(
        'All selected files will be renamed to the form prefix-number'))
    l.addRow(la)
    l.addRow(_('&Prefix:'), p)
    d.num = num = QSpinBox(d)
    num.setMinimum(0), num.setValue(1), num.setMaximum(1000)
    l.addRow(_('Starting &number:'), num)
    d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
    bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)
    l.addRow(bb)

    if d.exec_() == d.Accepted:
        prefix = sanitize(unicode(d.prefix.text()))
        num = d.num.value()
        fmt = '%d'
        if leading_zeros:
            largest = num + number - 1
            fmt = '%0{0}d'.format(len(str(largest)))
        return prefix + fmt, num
    return None, None
Ejemplo n.º 18
0
def bindSpinboxAndSlider(editor: QSpinBox, slider: QSlider, slot):
    # 联动
    editor.valueChanged.connect(lambda value: slider.setValue(value))
    slider.valueChanged.connect(lambda value: editor.setValue(value))

    # 绑定槽函数
    slider.valueChanged.connect(slot)
Ejemplo n.º 19
0
 def __mkSpinBox(self, value, min, max, options={}):
     spBox = QSpinBox()
     spBox.setValue(value)
     spBox.setMinimum(min)
     spBox.setMaximum(max)
     valueChangedSlot = options.get("valueChangedSlot", None)
     if valueChangedSlot is not None:
         spBox.valueChanged.connect(valueChangedSlot)
     return spBox
Ejemplo n.º 20
0
    def __init__(self, parent, db, author, series=None):
        QDialog.__init__(self, parent)
        self.db = db

        self.setWindowTitle(_('How many empty books?'))

        self._layout = QGridLayout(self)
        self.setLayout(self._layout)

        self.qty_label = QLabel(_('How many empty books should be added?'))
        self._layout.addWidget(self.qty_label, 0, 0, 1, 2)

        self.qty_spinbox = QSpinBox(self)
        self.qty_spinbox.setRange(1, 10000)
        self.qty_spinbox.setValue(1)
        self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2)

        self.author_label = QLabel(_('Set the author of the new books to:'))
        self._layout.addWidget(self.author_label, 2, 0, 1, 2)

        self.authors_combo = EditWithComplete(self)
        self.authors_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.authors_combo.setEditable(True)
        self._layout.addWidget(self.authors_combo, 3, 0, 1, 1)
        self.initialize_authors(db, author)

        self.clear_button = QToolButton(self)
        self.clear_button.setIcon(QIcon(I('trash.png')))
        self.clear_button.setToolTip(_('Reset author to Unknown'))
        self.clear_button.clicked.connect(self.reset_author)
        self._layout.addWidget(self.clear_button, 3, 1, 1, 1)

        self.series_label = QLabel(_('Set the series of the new books to:'))
        self._layout.addWidget(self.series_label, 4, 0, 1, 2)

        self.series_combo = EditWithComplete(self)
        self.authors_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.series_combo.setEditable(True)
        self._layout.addWidget(self.series_combo, 5, 0, 1, 1)
        self.initialize_series(db, series)

        self.sclear_button = QToolButton(self)
        self.sclear_button.setIcon(QIcon(I('trash.png')))
        self.sclear_button.setToolTip(_('Reset series'))
        self.sclear_button.clicked.connect(self.reset_series)
        self._layout.addWidget(self.sclear_button, 5, 1, 1, 1)

        self.create_epub = c = QCheckBox(_('Create an empty EPUB file as well'))
        c.setChecked(gprefs.get('create_empty_epub_file', False))
        c.setToolTip(_('Also create an empty EPUB file that you can subsequently edit'))
        self._layout.addWidget(c, 6, 0, 1, -1)

        button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self._layout.addWidget(button_box, 7, 0, 1, -1)
        self.resize(self.sizeHint())
Ejemplo n.º 21
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     layout = QHBoxLayout()
     self.sbx = QSpinBox()
     self.sby = QSpinBox()
     self.sbx.setRange(0, 1000)
     self.sby.setRange(0, 1000)
     lb = QLabel('x')
     lb.setSizePolicy(Qt.QSizePolicy.Minimum, Qt.QSizePolicy.Minimum)
     layout.addWidget(lb)
     self.sbx.setSizePolicy(Qt.QSizePolicy.Maximum, Qt.QSizePolicy.Maximum)
     layout.addWidget(self.sbx)
     lby = QLabel('y')
     lby.setSizePolicy(Qt.QSizePolicy.Minimum, Qt.QSizePolicy.Minimum)
     layout.addWidget(lby)
     layout.setAlignment(Qt.Qt.AlignLeft)
     layout.addWidget(self.sby)
     self.setLayout(layout)
Ejemplo n.º 22
0
class ConfigWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.l = QHBoxLayout()
        self.setLayout(self.l)

        self.label = QLabel("Max number of last issues to download:")
        self.l.addWidget(self.label)

        self.max_number = QSpinBox(self)
        self.max_number.setValue(prefs["max_numbers"])
        self.max_number.setMinimum(0)
        self.l.addWidget(self.max_number)
        self.label.setBuddy(self.max_number)

    def save_settings(self):
        prefs["max_numbers"] = self.max_number.value()
        prefs.commit()
Ejemplo n.º 23
0
 def setup_ui(self, parent):
     self.widgets = [
         QLabel('&' + self.col_metadata['name'] + ':', parent),
         QSpinBox(parent)
     ]
     w = self.widgets[1]
     w.setRange(-1000000, 100000000)
     w.setSpecialValueText(_('Undefined'))
     w.setSingleStep(1)
Ejemplo n.º 24
0
def get_bulk_rename_settings(parent,
                             number,
                             msg=None,
                             sanitize=sanitize_file_name_unicode,
                             leading_zeros=True,
                             prefix=None,
                             category='text',
                             allow_spine_order=False):  # {{{
    d = QDialog(parent)
    d.setWindowTitle(_('Bulk rename items'))
    d.l = l = QFormLayout(d)
    d.setLayout(l)
    d.prefix = p = QLineEdit(d)
    default_prefix = {k: v
                      for k, __, v in CATEGORIES}.get(category, _('Chapter-'))
    previous = tprefs.get('file-list-bulk-rename-prefix', {})
    prefix = prefix or previous.get(category, default_prefix)
    p.setText(prefix)
    p.selectAll()
    d.la = la = QLabel(
        msg
        or _('All selected files will be renamed to the form prefix-number'))
    l.addRow(la)
    l.addRow(_('&Prefix:'), p)
    d.num = num = QSpinBox(d)
    num.setMinimum(0), num.setValue(1), num.setMaximum(1000)
    l.addRow(_('Starting &number:'), num)
    if allow_spine_order:
        d.spine_order = QCheckBox(
            _('Rename files according to their book order'))
        d.spine_order.setToolTip(
            textwrap.fill(
                _('Rename the selected files according to the order they appear in the book, instead of the order they were selected in.'
                  )))
        l.addRow(d.spine_order)
    d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
    bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)
    l.addRow(bb)
    ans = {'prefix': None, 'start': None}

    if d.exec_() == d.Accepted:
        prefix = sanitize(unicode(d.prefix.text()))
        previous[category] = prefix
        tprefs.set('file-list-bulk-rename-prefix', previous)
        num = d.num.value()
        fmt = '%d'
        if leading_zeros:
            largest = num + number - 1
            fmt = '%0{0}d'.format(len(str(largest)))
        ans['prefix'] = prefix + fmt
        ans['start'] = num
        if allow_spine_order:
            ans['spine_order'] = d.spine_order.isChecked()
    return ans
Ejemplo n.º 25
0
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        self.resize(800, 600)

        self.bar = ProgressBar(self)
        self.bar.setMinimumSize(400, 400)
        self.bar.setMaximumSize(400, 400)

        layout = QFormLayout(self)

        layout.addWidget(
            QRadioButton('矩形',
                         self,
                         checked=True,
                         clicked=lambda: self.bar.setStyleType(1)))
        layout.addWidget(
            QRadioButton('圆形', clicked=lambda: self.bar.setStyleType(0)))
        layout.addWidget(
            QPushButton('设置背景颜色', self, clicked=self.chooseBackgroundColor))
        layout.addWidget(
            QPushButton('设置文字颜色', self, clicked=self.chooseTextColor))
        layout.addWidget(
            QPushButton('设置波浪1颜色', self, clicked=self.chooseWaterColor1))
        layout.addWidget(
            QPushButton('设置波浪2颜色', self, clicked=self.chooseWaterColor2))
        layout.addWidget(
            QPushButton('设置随机0-100固定值', self, clicked=self.setRandomValue))

        layout.addRow(
            '振幅(浪高)',
            QSpinBox(self, value=1, valueChanged=self.bar.setWaterHeight))

        layout.addRow(
            '周期(密度)',
            QSpinBox(self, value=1, valueChanged=self.bar.setWaterDensity))

        layout.addWidget(self.bar)

        # 动态设置进度条的值
        self._valueTimer = QTimer(self, timeout=self.updateValue)
        self._valueTimer.start(100)
Ejemplo n.º 26
0
    def __init__(self, console):
        super().__init__()
        self.console = console
        self.cpustress = CPUStress()

        self.stress = False

        self.layout = QVBoxLayout(self)

        self.title = QLabel(
            "<h1>CPU Stress</h1>\nAnzahl der Kerne (0 Cores = Anzahl der Systemkerne"
        )
        self.layout.addWidget(self.title)
        self.cpuCoresSpin = QSpinBox()
        self.layout.addWidget(self.cpuCoresSpin)

        self.startButton = QPushButton("Start")
        self.startButton.clicked.connect(self.start)
        self.layout.addWidget(self.startButton)

        self.layout.addStretch(1)
Ejemplo n.º 27
0
    def palkin_pituus_valikko(self):
        '''Luo palkin pituus tekstin sekä spinbox-valitsimen pituuden asettamista varten
        Päivittää palkin pituuden Ominaisuudet luokan avulla'''
        self.palkin_pituus = QGraphicsSimpleTextItem("Palkin pituus")
        self.palkin_pituus.setPos(300, 5)
        self.palkin_pituus.font = QtGui.QFont()
        self.palkin_pituus.font.setPointSize(12)
        self.palkin_pituus.setFont(self.palkin_pituus.font)
        self.scene.addItem(self.palkin_pituus)
        self.palkin_pituus.hide()

        self.sp = QSpinBox()
        self.scene.addWidget(self.sp)
        self.sp.hide()
        self.sp.move(450, 5)
        self.sp.setRange(0, 100)
        self.sp.setSingleStep(1)
        self.sp.setMinimumHeight(30)
        self.sp.setValue(int(Ominaisuudet.palauta_palkin_pituus(self)))
        self.paivita_pituus()
        self.sp.valueChanged.connect(self.paivita_pituus)
Ejemplo n.º 28
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.l = l = QVBoxLayout(self)
     self.la = la = QLabel(
         _('calibre contains an internet server that allows you to'
           ' access your book collection using a browser from anywhere'
           ' in the world. Any changes to the settings will only take'
           ' effect after a server restart.'))
     la.setWordWrap(True)
     l.addWidget(la)
     l.addSpacing(10)
     self.fl = fl = QFormLayout()
     l.addLayout(fl)
     self.opt_port = sb = QSpinBox(self)
     if options['port'].longdoc:
         sb.setToolTip(options['port'].longdoc)
     sb.setRange(1, 65535)
     sb.valueChanged.connect(self.changed_signal.emit)
     fl.addRow(options['port'].shortdoc + ':', sb)
     l.addSpacing(25)
     self.opt_auth = cb = QCheckBox(
         _('Require &username and password to access the content server'))
     l.addWidget(cb)
     self.auth_desc = la = QLabel(self)
     la.setStyleSheet('QLabel { font-size: small; font-style: italic }')
     la.setWordWrap(True)
     l.addWidget(la)
     l.addSpacing(25)
     self.opt_autolaunch_server = al = QCheckBox(
         _('Run server &automatically when calibre starts'))
     l.addWidget(al)
     l.addSpacing(25)
     self.h = h = QHBoxLayout()
     l.addLayout(h)
     for text, name in [(_('&Start server'), 'start_server'),
                        (_('St&op server'), 'stop_server'),
                        (_('&Test server'), 'test_server'),
                        (_('Show server &logs'), 'show_logs')]:
         b = QPushButton(text)
         b.clicked.connect(getattr(self, name).emit)
         setattr(self, name + '_button', b)
         if name == 'show_logs':
             h.addStretch(10)
         h.addWidget(b)
     self.ip_info = QLabel(self)
     self.update_ip_info()
     from calibre.gui2.ui import get_gui
     get_gui().iactions[
         'Connect Share'].share_conn_menu.server_state_changed_signal.connect(
             self.update_ip_info)
     l.addSpacing(10)
     l.addWidget(self.ip_info)
     l.addStretch(10)
Ejemplo n.º 29
0
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        self.default_template = default_custom_list_template()
        self.l = l = QFormLayout(self)
        l.setFieldGrowthPolicy(l.AllNonFixedFieldsGrow)
        self.la = la = QLabel('<p>' + _(
            'Here you can create a template to control what data is shown when'
            ' using the <i>Custom list</i> mode for the book list'))
        la.setWordWrap(True)
        l.addRow(la)
        self.thumbnail = t = QCheckBox(_('Show a cover &thumbnail'))
        self.thumbnail_height = th = QSpinBox(self)
        th.setSuffix(' px'), th.setRange(60, 600)
        self.entry_height = eh = QLineEdit(self)
        l.addRow(t), l.addRow(_('Thumbnail &height:'), th)
        l.addRow(_('Entry &height:'), eh)
        t.stateChanged.connect(self.changed_signal)
        th.valueChanged.connect(self.changed_signal)
        eh.textChanged.connect(self.changed_signal)
        eh.setToolTip(
            textwrap.fill(
                _('The height for each entry. The special value "auto" causes a height to be calculated'
                  ' based on the number of lines in the template. Otherwise, use a CSS length, such as'
                  ' 100px or 15ex')))
        t.stateChanged.connect(self.thumbnail_state_changed)
        th.setVisible(False)

        self.comments_fields = cf = QLineEdit(self)
        l.addRow(_('&Long text fields:'), cf)
        cf.setToolTip(
            textwrap.fill(
                _('A comma separated list of fields that will be added at the bottom of every entry.'
                  ' These fields are interpreted as containing HTML, not plain text.'
                  )))
        cf.textChanged.connect(self.changed_signal)

        self.la1 = la = QLabel('<p>' + _(
            'The template below will be interpreted as HTML and all {{fields}} will be replaced'
            ' by the actual metadata, if available. For custom columns use the column lookup'
            ' name, for example: #mytags. You can use {0} as a separator'
            ' to split a line into multiple columns.').format('|||'))
        la.setWordWrap(True)
        l.addRow(la)
        self.template = t = QPlainTextEdit(self)
        l.addRow(t)
        t.textChanged.connect(self.changed_signal)
        self.imex = bb = QDialogButtonBox(self)
        b = bb.addButton(_('&Import template'), bb.ActionRole)
        b.clicked.connect(self.import_template)
        b = bb.addButton(_('E&xport template'), bb.ActionRole)
        b.clicked.connect(self.export_template)
        l.addRow(bb)
Ejemplo n.º 30
0
    def __init__(self, logger, opts, parent=None):
        MainWindow.__init__(self, opts, parent)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
        self.setWindowTitle(__appname__ + _(' - LRF viewer'))

        self.logger = logger
        self.opts = opts
        self.create_document()
        self.spin_box_action = self.spin_box = QSpinBox()
        self.tool_bar.addWidget(self.spin_box)
        self.tool_bar.addSeparator()
        self.slider_action = self.slider = QSlider(Qt.Orientation.Horizontal)
        self.tool_bar.addWidget(self.slider)
        self.tool_bar.addSeparator()
        self.search = SearchBox2(self)
        self.search.initialize('lrf_viewer_search_history')
        self.search_action = self.tool_bar.addWidget(self.search)
        self.search.search.connect(self.find)

        self.action_next_page.setShortcuts([
            QKeySequence.StandardKey.MoveToNextPage,
            QKeySequence(Qt.Key.Key_Space)
        ])
        self.action_previous_page.setShortcuts([
            QKeySequence.StandardKey.MoveToPreviousPage,
            QKeySequence(Qt.Key.Key_Backspace)
        ])
        self.action_next_match.setShortcuts(QKeySequence.StandardKey.FindNext)
        self.addAction(self.action_next_match)
        self.action_next_page.triggered[(bool)].connect(self.next)
        self.action_previous_page.triggered[(bool)].connect(self.previous)
        self.action_back.triggered[(bool)].connect(self.back)
        self.action_forward.triggered[(bool)].connect(self.forward)
        self.action_next_match.triggered[(bool)].connect(self.next_match)
        self.action_open_ebook.triggered[(bool)].connect(self.open_ebook)
        self.action_configure.triggered[(bool)].connect(self.configure)
        self.spin_box.valueChanged[(int)].connect(self.go_to_page)
        self.slider.valueChanged[(int)].connect(self.go_to_page)

        self.graphics_view.setRenderHint(QPainter.RenderHint.Antialiasing,
                                         True)
        self.graphics_view.setRenderHint(QPainter.RenderHint.TextAntialiasing,
                                         True)
        self.graphics_view.setRenderHint(
            QPainter.RenderHint.SmoothPixmapTransform, True)

        self.closed = False
Ejemplo n.º 31
0
    def setup_ui(self):
        from calibre.ebooks.oeb.polish.images import get_compressible_images
        self.setWindowIcon(QIcon(I('compress-image.png')))
        self.h = h = QHBoxLayout(self)
        self.images = i = QListWidget(self)
        h.addWidget(i)
        self.l = l = QVBoxLayout()
        h.addLayout(l)
        c = current_container()
        for name in sorted(get_compressible_images(c), key=numeric_sort_key):
            x = QListWidgetItem(name, i)
            x.setData(Qt.ItemDataRole.UserRole, c.filesize(name))
        i.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
        i.setMinimumHeight(350), i.setMinimumWidth(350)
        i.selectAll(), i.setSpacing(5)
        self.delegate = ImageItemDelegate(self)
        i.setItemDelegate(self.delegate)
        self.la = la = QLabel(
            _('You can compress the images in this book losslessly, reducing the file size of the book,'
              ' without affecting image quality. Typically image size is reduced by 5 - 15%.'
              ))
        la.setWordWrap(True)
        la.setMinimumWidth(250)
        l.addWidget(la), l.addSpacing(30)

        self.enable_lossy = el = QCheckBox(
            _('Enable &lossy compression of JPEG images'))
        el.setToolTip(
            _('This allows you to change the quality factor used for JPEG images.\nBy lowering'
              ' the quality you can greatly reduce file size, at the expense of the image looking blurred.'
              ))
        l.addWidget(el)
        self.h2 = h = QHBoxLayout()
        l.addLayout(h)
        self.jq = jq = QSpinBox(self)
        jq.setMinimum(0), jq.setMaximum(100), jq.setValue(
            tprefs.get('jpeg_compression_quality_for_lossless_compression',
                       80)), jq.setEnabled(False)
        jq.setToolTip(
            _('The compression quality, 1 is high compression, 100 is low compression.\nImage'
              ' quality is inversely correlated with compression quality.'))
        jq.valueChanged.connect(self.save_compression_quality)
        el.toggled.connect(jq.setEnabled)
        self.jql = la = QLabel(_('Compression &quality:'))
        la.setBuddy(jq)
        h.addWidget(la), h.addWidget(jq)
        l.addStretch(10)
        l.addWidget(self.bb)
class MainWidget(QWidget):
    def __init__(self):
        super().__init__()

        self._label_info = QLabel()

        self._button_append = QPushButton('Add')
        self._button_append.clicked.connect(self._on_append_clicked)

        self._spin_box_numbers = QSpinBox()
        self._spin_box_numbers.setRange(1, 1_000_000)
        self._spin_box_numbers.setValue(1_000_000)

        h_layout = QHBoxLayout()
        h_layout.addWidget(self._button_append)
        h_layout.addWidget(self._spin_box_numbers)
        h_layout.addWidget(QLabel('objects'))

        main_layout = QVBoxLayout()
        main_layout.addWidget(self._label_info)
        main_layout.addLayout(h_layout)
        self.setLayout(main_layout)

        self._items = []

        pid = current_process().pid
        self._process = psutil.Process(pid)

        self._timer = QTimer()
        self._timer.timeout.connect(self.update_memory_info)
        self._timer.start(500)

        self.update_memory_info()

    def _on_append_clicked(self):
        row = [0 for _ in range(self._spin_box_numbers.value())]
        self._items.append(row)

    def update_memory_info(self):
        memory_bytes = self._process.memory_info().rss

        self._label_info.setText(
            f'Current memory: {memory_bytes} bytes\n'
            f'Current memory: {memory_bytes // 1024} KB\n'
            f'Current memory: {memory_bytes // 1024 // 1024} MB')
Ejemplo n.º 33
0
    def setLines(self):
        _, intClass, compMini, _, _ = self.getAmostSexo()
        if intClass is not None and compMini is not None:
            mini = float(compMini)
            intClass = float(intClass)

            self.TWComprimentos.setRowCount(self.rowCount)
            for row in range(self.rowCount):
                spinBox = QSpinBox()  #Criando objecto Spin e double box
                doubleSpin = QDoubleSpinBox()
                if row == 0:
                    idx = mini
                else:
                    idx = mini + (row * intClass
                                  )  #formula para determinar o valor inicial
                doubleSpin.setMinimum(idx)
                doubleSpin.setReadOnly(True)
                self.TWComprimentos.setCellWidget(
                    row, 0, doubleSpin)  #Configurando os valores nas possicoes
                self.TWComprimentos.setCellWidget(row, 1, spinBox)
            self.toEdit()
Ejemplo n.º 34
0
    def setup_ui(self):
        self.splitter = QSplitter(self)
        self.l = l = QVBoxLayout(self)
        l.addWidget(self.splitter)
        l.addWidget(self.bb)
        self.w = w = QGroupBox(_('Theme Metadata'), self)
        self.splitter.addWidget(w)
        l = w.l = QFormLayout(w)
        l.setFieldGrowthPolicy(
            QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
        self.missing_icons_group = mg = QGroupBox(self)
        self.mising_icons = mi = QListWidget(mg)
        mi.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection)
        mg.l = QVBoxLayout(mg)
        mg.l.addWidget(mi)
        self.splitter.addWidget(mg)
        self.title = QLineEdit(self)
        l.addRow(_('&Title:'), self.title)
        self.author = QLineEdit(self)
        l.addRow(_('&Author:'), self.author)
        self.version = v = QSpinBox(self)
        v.setMinimum(1), v.setMaximum(1000000)
        l.addRow(_('&Version:'), v)
        self.license = lc = QLineEdit(self)
        l.addRow(_('&License:'), lc)
        self.url = QLineEdit(self)
        l.addRow(_('&URL:'), self.url)
        lc.setText(
            _('The license for the icons in this theme. Common choices are'
              ' Creative Commons or Public Domain.'))
        self.description = QTextEdit(self)
        l.addRow(self.description)
        self.refresh_button = rb = self.bb.addButton(
            _('&Refresh'), QDialogButtonBox.ButtonRole.ActionRole)
        rb.setIcon(QIcon(I('view-refresh.png')))
        rb.clicked.connect(self.refresh)

        self.apply_report()
Ejemplo n.º 35
0
    def __init__(self, plugin_action):
        QWidget.__init__(self)
        self.plugin_action = plugin_action
        layout = QVBoxLayout(self)
        self.setLayout(layout)
        self.help_anchor = "configuration"
        
        title_layout = ImageTitleLayout(self, 'images/icon.png', 'Sony Utilities Options')
        layout.addLayout(title_layout)

#        c = plugin_prefs[STORE_NAME]
        library_config = get_library_config(self.plugin_action.gui.current_db)

        custom_column_group = QGroupBox(_('Custom Columns'), self)
        layout.addWidget(custom_column_group )
        options_layout = QGridLayout()
        custom_column_group.setLayout(options_layout)

        avail_text_columns   = self.get_text_custom_columns()
        avail_number_columns = self.get_number_custom_columns()
        avail_rating_columns = self.get_rating_custom_columns()
        avail_date_columns   = self.get_date_custom_columns()
#        debug_print("avail_rating_columns=", avail_rating_columns)
#        debug_print("default columns=", self.plugin_action.gui.library_view.model().orig_headers)
        current_Location_column  = library_config.get(KEY_CURRENT_LOCATION_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_CURRENT_LOCATION_CUSTOM_COLUMN])
        precent_read_column      = library_config.get(KEY_PERCENT_READ_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_PERCENT_READ_CUSTOM_COLUMN])
        rating_column            = library_config.get(KEY_RATING_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_RATING_CUSTOM_COLUMN])
        last_read_column         = library_config.get(KEY_LAST_READ_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_LAST_READ_CUSTOM_COLUMN])

        store_on_connect         = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_STORE_ON_CONNECT)
        prompt_to_store          = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_PROMPT_TO_STORE)
        store_if_more_recent     = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_STORE_IF_MORE_RECENT)
        do_not_store_if_reopened = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_DO_NOT_STORE_IF_REOPENED)

#         do_check_for_firmware_updates = get_plugin_pref(UPDATE_OPTIONS_STORE_NAME, KEY_DO_UPDATE_CHECK)
#         do_early_firmware_updates     = get_plugin_pref(UPDATE_OPTIONS_STORE_NAME, KEY_DO_EARLY_FIRMWARE_CHECK)
#         self.update_check_last_time   = get_plugin_pref(UPDATE_OPTIONS_STORE_NAME, KEY_LAST_FIRMWARE_CHECK_TIME)

        do_daily_backup          = get_plugin_pref(BACKUP_OPTIONS_STORE_NAME, KEY_DO_DAILY_BACKUP)
        dest_directory           = get_plugin_pref(BACKUP_OPTIONS_STORE_NAME, KEY_BACKUP_DEST_DIRECTORY)
        copies_to_keep           = get_plugin_pref(BACKUP_OPTIONS_STORE_NAME, KEY_BACKUP_COPIES_TO_KEEP)
#        debug_print("current_Location_column=%s, precent_read_column=%s, rating_column=%s" % (current_Location_column, precent_read_column, rating_column))

        current_Location_label = QLabel(_('Current Reading Location Column:'), self)
        current_Location_label.setToolTip(_("Select a custom column to store the current reading location. The column type must be 'text'. Leave this blank if you do not want to store or restore the current reading location."))
        self.current_Location_combo = CustomColumnComboBox(self, avail_text_columns, current_Location_column)
        current_Location_label.setBuddy(self.current_Location_combo)
        options_layout.addWidget(current_Location_label, 0, 0, 1, 1)
        options_layout.addWidget(self.current_Location_combo, 0, 1, 1, 1)
        
        percent_read_label = QLabel(_('Percent Read Column:'), self)
        percent_read_label.setToolTip(_("Column used to store the current percent read. The column type must be a 'integer'. Leave this blank if you do not want to store or restore the percentage read."))
        self.percent_read_combo = CustomColumnComboBox(self, avail_number_columns, precent_read_column)
        percent_read_label.setBuddy(self.percent_read_combo)
        options_layout.addWidget(percent_read_label, 2, 0, 1, 1)
        options_layout.addWidget(self.percent_read_combo, 2, 1, 1, 1)

        rating_label = QLabel(_('Rating Column:'), self)
        rating_label.setToolTip(_("Column used to store the rating. The column type must be a 'integer'. Leave this blank if you do not want to store or restore the rating."))
        self.rating_combo = CustomColumnComboBox(self, avail_rating_columns, rating_column)
        rating_label.setBuddy(self.rating_combo)
        options_layout.addWidget(rating_label, 3, 0, 1, 1)
        options_layout.addWidget(self.rating_combo, 3, 1, 1, 1)

        last_read_label = QLabel(_('Last Read Column:'), self)
        last_read_label.setToolTip(_("Column used to store when the book was last read. The column type must be a 'Date'. Leave this blank if you do not want to store the last read timestamp."))
        self.last_read_combo = CustomColumnComboBox(self, avail_date_columns, last_read_column)
        last_read_label.setBuddy(self.last_read_combo)
        options_layout.addWidget(last_read_label, 4, 0, 1, 1)
        options_layout.addWidget(self.last_read_combo, 4, 1, 1, 1)

        auto_store_group = QGroupBox(_('Store on connect'), self)
        layout.addWidget(auto_store_group )
        options_layout = QGridLayout()
        auto_store_group.setLayout(options_layout)

        self.store_on_connect_checkbox = QCheckBox(_("Store current bookmarks on connect"), self)
        self.store_on_connect_checkbox.setToolTip(_("When this is checked, the library will be updated with the current bookmark for all books on the device."))
        self.store_on_connect_checkbox.setCheckState(Qt.Checked if store_on_connect else Qt.Unchecked)
        self.store_on_connect_checkbox.clicked.connect(self.store_on_connect_checkbox_clicked)
        options_layout.addWidget(self.store_on_connect_checkbox, 0, 0, 1, 3)

        self.prompt_to_store_checkbox = QCheckBox(_("Prompt to store any changes"), self)
        self.prompt_to_store_checkbox.setToolTip(_("Enable this to be prompted to save the changed bookmarks after an automatic store is done."))
        self.prompt_to_store_checkbox.setCheckState(Qt.Checked if prompt_to_store else Qt.Unchecked)
        self.prompt_to_store_checkbox.setEnabled(store_on_connect)
        options_layout.addWidget(self.prompt_to_store_checkbox, 1, 0, 1, 1)

        self.store_if_more_recent_checkbox = QCheckBox(_("Only if more recent"), self)
        self.store_if_more_recent_checkbox.setToolTip(_("Only store the reading position if the last read timestamp on the device is more recent than in the library."))
        self.store_if_more_recent_checkbox.setCheckState(Qt.Checked if store_if_more_recent else Qt.Unchecked)
        self.store_if_more_recent_checkbox.setEnabled(store_on_connect)
        options_layout.addWidget(self.store_if_more_recent_checkbox, 1, 1, 1, 1)

        self.do_not_store_if_reopened_checkbox = QCheckBox(_("Not if finished in library"), self)
        self.do_not_store_if_reopened_checkbox.setToolTip(_("Do not store the reading position if the library has the book as finished. This is if the percent read is 100%."))
        self.do_not_store_if_reopened_checkbox.setCheckState(Qt.Checked if do_not_store_if_reopened else Qt.Unchecked)
        self.do_not_store_if_reopened_checkbox.setEnabled(store_on_connect)
        options_layout.addWidget(self.do_not_store_if_reopened_checkbox, 1, 2, 1, 1)

#         update_options_group = QGroupBox(_('Firmware Update Options'), self)
#         layout.addWidget(update_options_group)
#         options_layout = QGridLayout()
#         update_options_group.setLayout(options_layout)
# 
#         self.do_update_check = QCheckBox(_('Check for Sony firmware updates daily?'), self)
#         self.do_update_check.setToolTip(_('If this is selected the plugin will check for Sony firmware updates when your Sony device is plugged in, once per 24-hour period.'))
#         self.do_update_check.setCheckState(Qt.Checked if do_check_for_firmware_updates else Qt.Unchecked)
#         options_layout.addWidget(self.do_update_check, 0, 0, 1, 1)
# 
#         self.do_early_firmware_check = QCheckBox(_('Use early firmware adopter affiliate?'), self)
#         self.do_early_firmware_check.setToolTip(_('WARNING: THIS OPTION RISKS DOWNLOADING THE WRONG FIRMWARE FOR YOUR DEVICE! YOUR DEVICE MAY NOT FUNCTION PROPERLY IF THIS HAPPENS! Choose this option to attempt to download Sony firmware updates before they are officially available for your device.'))
#         self.do_early_firmware_check.setCheckState(Qt.Checked if do_early_firmware_updates else Qt.Unchecked)
#         options_layout.addWidget(self.do_early_firmware_check, 0, 1, 1, 1)

        backup_options_group = QGroupBox(_('Device Database Backup'), self)
        layout.addWidget(backup_options_group)
        options_layout = QGridLayout()
        backup_options_group.setLayout(options_layout)

        self.do_daily_backp_checkbox = QCheckBox(_('Backup the device database daily'), self)
        self.do_daily_backp_checkbox.setToolTip(_('If this is selected the plugin will backup the device database the first time it is connected each day.'))
        self.do_daily_backp_checkbox.setCheckState(Qt.Checked if do_daily_backup else Qt.Unchecked)
        self.do_daily_backp_checkbox.clicked.connect(self.do_daily_backp_checkbox_clicked)
        options_layout.addWidget(self.do_daily_backp_checkbox, 0, 0, 1, 3)

        self.dest_directory_label = QLabel(_("Destination:"), self)
        self.dest_directory_label.setToolTip(_("Select the destination the annotations files are to be backed up in."))
        self.dest_directory_edit = QLineEdit(self)
        self.dest_directory_edit.setMinimumSize(150, 0)
        self.dest_directory_edit.setText(dest_directory)
        self.dest_directory_label.setBuddy(self.dest_directory_edit)
        self.dest_pick_button = QPushButton(_("..."), self)
        self.dest_pick_button.setMaximumSize(24, 20)
        self.dest_pick_button.clicked.connect(self._get_dest_directory_name)
        options_layout.addWidget(self.dest_directory_label, 1, 0, 1, 1)
        options_layout.addWidget(self.dest_directory_edit, 1, 1, 1, 1)
        options_layout.addWidget(self.dest_pick_button, 1, 2, 1, 1)

        self.copies_to_keep_checkbox = QCheckBox(_('Copies to keep'), self)
        self.copies_to_keep_checkbox.setToolTip(_("Select this to limit the number of backup kept. If not set, the backup files must be manually deleted."))
        self.copies_to_keep_spin = QSpinBox(self)
        self.copies_to_keep_spin.setMinimum(2)
        self.copies_to_keep_spin.setToolTip(_("The number of backup copies of the database to keep. The minimum is 2."))
        options_layout.addWidget(self.copies_to_keep_checkbox, 1, 3, 1, 1)
        options_layout.addWidget(self.copies_to_keep_spin, 1, 4, 1, 1)
        self.copies_to_keep_checkbox.clicked.connect(self.copies_to_keep_checkbox_clicked)
        if copies_to_keep == -1:
            self.copies_to_keep_checkbox.setCheckState(not Qt.Checked)
        else:
            self.copies_to_keep_checkbox.setCheckState(Qt.Checked)
            self.copies_to_keep_spin.setProperty('value', copies_to_keep)

        self.do_daily_backp_checkbox_clicked(do_daily_backup)

        other_options_group = QGroupBox(_('Other Options'), self)
        layout.addWidget(other_options_group )
        options_layout = QGridLayout()
        other_options_group.setLayout(options_layout)

        library_default_label = QLabel(_('&Library Button default:'), self)
        library_default_label.setToolTip(_('If plugin is placed as a toolbar button, choose a default action when clicked on'))
        self.library_default_combo = KeyComboBox(self, self.plugin_action.library_actions_map, unicode(get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_BUTTON_ACTION_LIBRARY)))
        library_default_label.setBuddy(self.library_default_combo)
        options_layout.addWidget(library_default_label, 0, 0, 1, 1)
        options_layout.addWidget(self.library_default_combo, 0, 1, 1, 2)

        device_default_label = QLabel(_('&Device Button default:'), self)
        device_default_label.setToolTip(_('If plugin is placed as a toolbar button, choose a default action when clicked on'))
        self.device_default_combo = KeyComboBox(self, self.plugin_action.device_actions_map, unicode(get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_BUTTON_ACTION_DEVICE)))
        device_default_label.setBuddy(self.device_default_combo)
        options_layout.addWidget(device_default_label, 1, 0, 1, 1)
        options_layout.addWidget(self.device_default_combo, 1, 1, 1, 2)

        keyboard_shortcuts_button = QPushButton(_('Keyboard shortcuts...'), self)
        keyboard_shortcuts_button.setToolTip(_('Edit the keyboard shortcuts associated with this plugin'))
        keyboard_shortcuts_button.clicked.connect(self.edit_shortcuts)
        layout.addWidget(keyboard_shortcuts_button)
        layout.addStretch(1)
Ejemplo n.º 36
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Space:
         self.setValue(-1000000)
     else:
         return QSpinBox.keyPressEvent(self, ev)
Ejemplo n.º 37
0
 def createEditor(self, parent, option, index):
     sb = QSpinBox(parent)
     sb.setMinimum(0)
     sb.setMaximum(5)
     sb.setSuffix(' ' + _('stars'))
     return sb
Ejemplo n.º 38
0
class BulkSeries(BulkBase):

    def setup_ui(self, parent):
        self.make_widgets(parent, EditWithComplete)
        values = self.all_values = list(self.db.all_custom(num=self.col_id))
        values.sort(key=sort_key)
        self.main_widget.setSizeAdjustPolicy(self.main_widget.AdjustToMinimumContentsLengthWithIcon)
        self.main_widget.setMinimumContentsLength(25)
        self.widgets.append(QLabel('', parent))
        w = QWidget(parent)
        layout = QHBoxLayout(w)
        layout.setContentsMargins(0, 0, 0, 0)
        self.remove_series = QCheckBox(parent)
        self.remove_series.setText(_('Remove series'))
        layout.addWidget(self.remove_series)
        self.idx_widget = QCheckBox(parent)
        self.idx_widget.setText(_('Automatically number books'))
        layout.addWidget(self.idx_widget)
        self.force_number = QCheckBox(parent)
        self.force_number.setText(_('Force numbers to start with '))
        layout.addWidget(self.force_number)
        self.series_start_number = QSpinBox(parent)
        self.series_start_number.setMinimum(1)
        self.series_start_number.setMaximum(9999999)
        self.series_start_number.setProperty("value", 1)
        layout.addWidget(self.series_start_number)
        layout.addItem(QSpacerItem(20, 10, QSizePolicy.Expanding, QSizePolicy.Minimum))
        self.widgets.append(w)
        self.idx_widget.stateChanged.connect(self.check_changed_checkbox)
        self.force_number.stateChanged.connect(self.check_changed_checkbox)
        self.series_start_number.valueChanged.connect(self.check_changed_checkbox)
        self.remove_series.stateChanged.connect(self.check_changed_checkbox)
        self.ignore_change_signals = False

    def check_changed_checkbox(self):
        self.a_c_checkbox.setChecked(True)

    def initialize(self, book_id):
        self.idx_widget.setChecked(False)
        self.main_widget.set_separator(None)
        self.main_widget.update_items_cache(self.all_values)
        self.main_widget.setEditText('')
        self.a_c_checkbox.setChecked(False)

    def getter(self):
        n = unicode(self.main_widget.currentText()).strip()
        i = self.idx_widget.checkState()
        f = self.force_number.checkState()
        s = self.series_start_number.value()
        r = self.remove_series.checkState()
        return n, i, f, s, r

    def commit(self, book_ids, notify=False):
        if not self.a_c_checkbox.isChecked():
            return
        val, update_indices, force_start, at_value, clear = self.gui_val
        val = None if clear else self.normalize_ui_val(val)
        if clear or val != '':
            extras = []
            for book_id in book_ids:
                if clear:
                    extras.append(None)
                    continue
                if update_indices:
                    if force_start:
                        s_index = at_value
                        at_value += 1
                    elif tweaks['series_index_auto_increment'] != 'const':
                        s_index = self.db.get_next_cc_series_num_for(val, num=self.col_id)
                    else:
                        s_index = 1.0
                else:
                    s_index = self.db.get_custom_extra(book_id, num=self.col_id,
                                                       index_is_id=True)
                extras.append(s_index)
            self.db.set_custom_bulk(book_ids, val, extras=extras,
                                   num=self.col_id, notify=notify)
Ejemplo n.º 39
0
class ConfigWidget(QWidget):
    """Configuration widget for managing calibre-comicvine config."""

    def __init__(self):
        QWidget.__init__(self)
        self.layout = QGridLayout()
        self.layout.setSpacing(10)
        self.setLayout(self.layout)

        self.index = 0

        self.api_key = QLineEdit(self)
        self.api_key.setText(PREFS['api_key'])
        self.add_labeled_widget('&API key:', self.api_key)

        # Worker threads is the maximum number of worker threads to spawn.
        # Restricted to 1+
        self.worker_threads = QSpinBox(self)
        self.worker_threads.setMinimum(1)
        self.worker_threads.setValue(PREFS['worker_threads'])
        self.add_labeled_widget('&Worker threads:', self.worker_threads)

        # Request interval represents wait time between batches of requests.
        self.request_interval = QSpinBox(self)
        self.request_interval.setMinimum(0)
        self.request_interval.setValue(PREFS['request_interval'])
        self.add_labeled_widget('&Request interval (seconds):',
                                self.request_interval)

        # Request batch is the maximum number of requests to run at a time.
        # Restricted to 1+
        self.request_batch_size = QSpinBox(self)
        self.request_batch_size.setMinimum(1)
        self.request_batch_size.setValue(PREFS['request_batch_size'])
        self.add_labeled_widget('&Request batch size:', self.request_batch_size)

        # Retries is the number of times to retry if we get any error
        # from comicvine besides a rate limit error.
        self.retries = QSpinBox(self)
        self.retries.setMinimum(0)
        self.retries.setValue(PREFS['retries'])
        self.add_labeled_widget('&Retries:', self.retries)

        # Search volume limit is the max number of volumes to return from
        # a volume search.
        self.search_volume_limit = QSpinBox(self)
        self.search_volume_limit.setMinimum(10)
        self.search_volume_limit.setMaximum(10000)
        self.search_volume_limit.setSingleStep(10)
        self.search_volume_limit.setValue(PREFS['search_volume_limit'])
        self.add_labeled_widget('&search_volume_limit:',
                                self.search_volume_limit)

    def add_labeled_widget(self, label_text, widget):
        """
        Add a configuration widget, incrementing the index for the next widget.
        """
        self.index += 1
        label = QLabel(label_text)
        label.setBuddy(widget)
        self.layout.addWidget(label, self.index, 0)
        self.layout.addWidget(widget, self.index, 1)

    def save_settings(self):
        """Apply new settings value."""
        PREFS['api_key'] = unicode(self.api_key.text())
        PREFS['worker_threads'] = self.worker_threads.value()
        PREFS['request_interval'] = self.request_interval.value()
        PREFS['request_batch_size'] = self.request_batch_size.value()
        PREFS['retries'] = self.retries.value()
        PREFS['search_volume_limit'] = self.search_volume_limit.value()
Ejemplo n.º 40
0
class ConfigWidget(QWidget):

    def __init__(self, plugin_action):
        QWidget.__init__(self)
        self.plugin_action = plugin_action
        layout = QVBoxLayout(self)
        self.setLayout(layout)
        self.help_anchor = "configuration"
        
        title_layout = ImageTitleLayout(self, 'images/icon.png', 'Sony Utilities Options')
        layout.addLayout(title_layout)

#        c = plugin_prefs[STORE_NAME]
        library_config = get_library_config(self.plugin_action.gui.current_db)

        custom_column_group = QGroupBox(_('Custom Columns'), self)
        layout.addWidget(custom_column_group )
        options_layout = QGridLayout()
        custom_column_group.setLayout(options_layout)

        avail_text_columns   = self.get_text_custom_columns()
        avail_number_columns = self.get_number_custom_columns()
        avail_rating_columns = self.get_rating_custom_columns()
        avail_date_columns   = self.get_date_custom_columns()
#        debug_print("avail_rating_columns=", avail_rating_columns)
#        debug_print("default columns=", self.plugin_action.gui.library_view.model().orig_headers)
        current_Location_column  = library_config.get(KEY_CURRENT_LOCATION_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_CURRENT_LOCATION_CUSTOM_COLUMN])
        precent_read_column      = library_config.get(KEY_PERCENT_READ_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_PERCENT_READ_CUSTOM_COLUMN])
        rating_column            = library_config.get(KEY_RATING_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_RATING_CUSTOM_COLUMN])
        last_read_column         = library_config.get(KEY_LAST_READ_CUSTOM_COLUMN, DEFAULT_LIBRARY_VALUES[KEY_LAST_READ_CUSTOM_COLUMN])

        store_on_connect         = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_STORE_ON_CONNECT)
        prompt_to_store          = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_PROMPT_TO_STORE)
        store_if_more_recent     = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_STORE_IF_MORE_RECENT)
        do_not_store_if_reopened = get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_DO_NOT_STORE_IF_REOPENED)

#         do_check_for_firmware_updates = get_plugin_pref(UPDATE_OPTIONS_STORE_NAME, KEY_DO_UPDATE_CHECK)
#         do_early_firmware_updates     = get_plugin_pref(UPDATE_OPTIONS_STORE_NAME, KEY_DO_EARLY_FIRMWARE_CHECK)
#         self.update_check_last_time   = get_plugin_pref(UPDATE_OPTIONS_STORE_NAME, KEY_LAST_FIRMWARE_CHECK_TIME)

        do_daily_backup          = get_plugin_pref(BACKUP_OPTIONS_STORE_NAME, KEY_DO_DAILY_BACKUP)
        dest_directory           = get_plugin_pref(BACKUP_OPTIONS_STORE_NAME, KEY_BACKUP_DEST_DIRECTORY)
        copies_to_keep           = get_plugin_pref(BACKUP_OPTIONS_STORE_NAME, KEY_BACKUP_COPIES_TO_KEEP)
#        debug_print("current_Location_column=%s, precent_read_column=%s, rating_column=%s" % (current_Location_column, precent_read_column, rating_column))

        current_Location_label = QLabel(_('Current Reading Location Column:'), self)
        current_Location_label.setToolTip(_("Select a custom column to store the current reading location. The column type must be 'text'. Leave this blank if you do not want to store or restore the current reading location."))
        self.current_Location_combo = CustomColumnComboBox(self, avail_text_columns, current_Location_column)
        current_Location_label.setBuddy(self.current_Location_combo)
        options_layout.addWidget(current_Location_label, 0, 0, 1, 1)
        options_layout.addWidget(self.current_Location_combo, 0, 1, 1, 1)
        
        percent_read_label = QLabel(_('Percent Read Column:'), self)
        percent_read_label.setToolTip(_("Column used to store the current percent read. The column type must be a 'integer'. Leave this blank if you do not want to store or restore the percentage read."))
        self.percent_read_combo = CustomColumnComboBox(self, avail_number_columns, precent_read_column)
        percent_read_label.setBuddy(self.percent_read_combo)
        options_layout.addWidget(percent_read_label, 2, 0, 1, 1)
        options_layout.addWidget(self.percent_read_combo, 2, 1, 1, 1)

        rating_label = QLabel(_('Rating Column:'), self)
        rating_label.setToolTip(_("Column used to store the rating. The column type must be a 'integer'. Leave this blank if you do not want to store or restore the rating."))
        self.rating_combo = CustomColumnComboBox(self, avail_rating_columns, rating_column)
        rating_label.setBuddy(self.rating_combo)
        options_layout.addWidget(rating_label, 3, 0, 1, 1)
        options_layout.addWidget(self.rating_combo, 3, 1, 1, 1)

        last_read_label = QLabel(_('Last Read Column:'), self)
        last_read_label.setToolTip(_("Column used to store when the book was last read. The column type must be a 'Date'. Leave this blank if you do not want to store the last read timestamp."))
        self.last_read_combo = CustomColumnComboBox(self, avail_date_columns, last_read_column)
        last_read_label.setBuddy(self.last_read_combo)
        options_layout.addWidget(last_read_label, 4, 0, 1, 1)
        options_layout.addWidget(self.last_read_combo, 4, 1, 1, 1)

        auto_store_group = QGroupBox(_('Store on connect'), self)
        layout.addWidget(auto_store_group )
        options_layout = QGridLayout()
        auto_store_group.setLayout(options_layout)

        self.store_on_connect_checkbox = QCheckBox(_("Store current bookmarks on connect"), self)
        self.store_on_connect_checkbox.setToolTip(_("When this is checked, the library will be updated with the current bookmark for all books on the device."))
        self.store_on_connect_checkbox.setCheckState(Qt.Checked if store_on_connect else Qt.Unchecked)
        self.store_on_connect_checkbox.clicked.connect(self.store_on_connect_checkbox_clicked)
        options_layout.addWidget(self.store_on_connect_checkbox, 0, 0, 1, 3)

        self.prompt_to_store_checkbox = QCheckBox(_("Prompt to store any changes"), self)
        self.prompt_to_store_checkbox.setToolTip(_("Enable this to be prompted to save the changed bookmarks after an automatic store is done."))
        self.prompt_to_store_checkbox.setCheckState(Qt.Checked if prompt_to_store else Qt.Unchecked)
        self.prompt_to_store_checkbox.setEnabled(store_on_connect)
        options_layout.addWidget(self.prompt_to_store_checkbox, 1, 0, 1, 1)

        self.store_if_more_recent_checkbox = QCheckBox(_("Only if more recent"), self)
        self.store_if_more_recent_checkbox.setToolTip(_("Only store the reading position if the last read timestamp on the device is more recent than in the library."))
        self.store_if_more_recent_checkbox.setCheckState(Qt.Checked if store_if_more_recent else Qt.Unchecked)
        self.store_if_more_recent_checkbox.setEnabled(store_on_connect)
        options_layout.addWidget(self.store_if_more_recent_checkbox, 1, 1, 1, 1)

        self.do_not_store_if_reopened_checkbox = QCheckBox(_("Not if finished in library"), self)
        self.do_not_store_if_reopened_checkbox.setToolTip(_("Do not store the reading position if the library has the book as finished. This is if the percent read is 100%."))
        self.do_not_store_if_reopened_checkbox.setCheckState(Qt.Checked if do_not_store_if_reopened else Qt.Unchecked)
        self.do_not_store_if_reopened_checkbox.setEnabled(store_on_connect)
        options_layout.addWidget(self.do_not_store_if_reopened_checkbox, 1, 2, 1, 1)

#         update_options_group = QGroupBox(_('Firmware Update Options'), self)
#         layout.addWidget(update_options_group)
#         options_layout = QGridLayout()
#         update_options_group.setLayout(options_layout)
# 
#         self.do_update_check = QCheckBox(_('Check for Sony firmware updates daily?'), self)
#         self.do_update_check.setToolTip(_('If this is selected the plugin will check for Sony firmware updates when your Sony device is plugged in, once per 24-hour period.'))
#         self.do_update_check.setCheckState(Qt.Checked if do_check_for_firmware_updates else Qt.Unchecked)
#         options_layout.addWidget(self.do_update_check, 0, 0, 1, 1)
# 
#         self.do_early_firmware_check = QCheckBox(_('Use early firmware adopter affiliate?'), self)
#         self.do_early_firmware_check.setToolTip(_('WARNING: THIS OPTION RISKS DOWNLOADING THE WRONG FIRMWARE FOR YOUR DEVICE! YOUR DEVICE MAY NOT FUNCTION PROPERLY IF THIS HAPPENS! Choose this option to attempt to download Sony firmware updates before they are officially available for your device.'))
#         self.do_early_firmware_check.setCheckState(Qt.Checked if do_early_firmware_updates else Qt.Unchecked)
#         options_layout.addWidget(self.do_early_firmware_check, 0, 1, 1, 1)

        backup_options_group = QGroupBox(_('Device Database Backup'), self)
        layout.addWidget(backup_options_group)
        options_layout = QGridLayout()
        backup_options_group.setLayout(options_layout)

        self.do_daily_backp_checkbox = QCheckBox(_('Backup the device database daily'), self)
        self.do_daily_backp_checkbox.setToolTip(_('If this is selected the plugin will backup the device database the first time it is connected each day.'))
        self.do_daily_backp_checkbox.setCheckState(Qt.Checked if do_daily_backup else Qt.Unchecked)
        self.do_daily_backp_checkbox.clicked.connect(self.do_daily_backp_checkbox_clicked)
        options_layout.addWidget(self.do_daily_backp_checkbox, 0, 0, 1, 3)

        self.dest_directory_label = QLabel(_("Destination:"), self)
        self.dest_directory_label.setToolTip(_("Select the destination the annotations files are to be backed up in."))
        self.dest_directory_edit = QLineEdit(self)
        self.dest_directory_edit.setMinimumSize(150, 0)
        self.dest_directory_edit.setText(dest_directory)
        self.dest_directory_label.setBuddy(self.dest_directory_edit)
        self.dest_pick_button = QPushButton(_("..."), self)
        self.dest_pick_button.setMaximumSize(24, 20)
        self.dest_pick_button.clicked.connect(self._get_dest_directory_name)
        options_layout.addWidget(self.dest_directory_label, 1, 0, 1, 1)
        options_layout.addWidget(self.dest_directory_edit, 1, 1, 1, 1)
        options_layout.addWidget(self.dest_pick_button, 1, 2, 1, 1)

        self.copies_to_keep_checkbox = QCheckBox(_('Copies to keep'), self)
        self.copies_to_keep_checkbox.setToolTip(_("Select this to limit the number of backup kept. If not set, the backup files must be manually deleted."))
        self.copies_to_keep_spin = QSpinBox(self)
        self.copies_to_keep_spin.setMinimum(2)
        self.copies_to_keep_spin.setToolTip(_("The number of backup copies of the database to keep. The minimum is 2."))
        options_layout.addWidget(self.copies_to_keep_checkbox, 1, 3, 1, 1)
        options_layout.addWidget(self.copies_to_keep_spin, 1, 4, 1, 1)
        self.copies_to_keep_checkbox.clicked.connect(self.copies_to_keep_checkbox_clicked)
        if copies_to_keep == -1:
            self.copies_to_keep_checkbox.setCheckState(not Qt.Checked)
        else:
            self.copies_to_keep_checkbox.setCheckState(Qt.Checked)
            self.copies_to_keep_spin.setProperty('value', copies_to_keep)

        self.do_daily_backp_checkbox_clicked(do_daily_backup)

        other_options_group = QGroupBox(_('Other Options'), self)
        layout.addWidget(other_options_group )
        options_layout = QGridLayout()
        other_options_group.setLayout(options_layout)

        library_default_label = QLabel(_('&Library Button default:'), self)
        library_default_label.setToolTip(_('If plugin is placed as a toolbar button, choose a default action when clicked on'))
        self.library_default_combo = KeyComboBox(self, self.plugin_action.library_actions_map, unicode(get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_BUTTON_ACTION_LIBRARY)))
        library_default_label.setBuddy(self.library_default_combo)
        options_layout.addWidget(library_default_label, 0, 0, 1, 1)
        options_layout.addWidget(self.library_default_combo, 0, 1, 1, 2)

        device_default_label = QLabel(_('&Device Button default:'), self)
        device_default_label.setToolTip(_('If plugin is placed as a toolbar button, choose a default action when clicked on'))
        self.device_default_combo = KeyComboBox(self, self.plugin_action.device_actions_map, unicode(get_plugin_pref(COMMON_OPTIONS_STORE_NAME, KEY_BUTTON_ACTION_DEVICE)))
        device_default_label.setBuddy(self.device_default_combo)
        options_layout.addWidget(device_default_label, 1, 0, 1, 1)
        options_layout.addWidget(self.device_default_combo, 1, 1, 1, 2)

        keyboard_shortcuts_button = QPushButton(_('Keyboard shortcuts...'), self)
        keyboard_shortcuts_button.setToolTip(_('Edit the keyboard shortcuts associated with this plugin'))
        keyboard_shortcuts_button.clicked.connect(self.edit_shortcuts)
        layout.addWidget(keyboard_shortcuts_button)
        layout.addStretch(1)

    def store_on_connect_checkbox_clicked(self, checked):
        self.prompt_to_store_checkbox.setEnabled(checked)
        self.store_if_more_recent_checkbox.setEnabled(checked)
        self.do_not_store_if_reopened_checkbox.setEnabled(checked)

    def do_daily_backp_checkbox_clicked(self, checked):
        self.dest_directory_edit.setEnabled(checked)
        self.dest_pick_button.setEnabled(checked)
        self.dest_directory_label.setEnabled(checked)
        self.copies_to_keep_checkbox.setEnabled(checked)
        self.copies_to_keep_checkbox_clicked(checked and self.copies_to_keep_checkbox.checkState() == Qt.Checked)

    def copies_to_keep_checkbox_clicked(self, checked):
        self.copies_to_keep_spin.setEnabled(checked)

    # Called by Calibre before save_settings 
    def validate(self):
#        import traceback
#        traceback.print_stack()
        
        debug_print('BEGIN Validate')
        valid = True
        # Only save if we were able to get data to avoid corrupting stored data
#        if self.do_daily_backp_checkbox.checkState() == Qt.Checked and not len(self.dest_directory_edit.text()):
#            error_dialog(self, 'No destination directory',
#                            'If the automatic device backup is set, there must be a destination directory.',
#                            show=True, show_copy_button=False)
#            valid = False

        debug_print('END Validate, status = %s' % valid)
        return valid

    def save_settings(self):

        new_prefs = {}
        new_prefs[KEY_BUTTON_ACTION_DEVICE]     = unicode(self.device_default_combo.currentText())
        new_prefs[KEY_BUTTON_ACTION_LIBRARY]    = unicode(self.library_default_combo.currentText())
        new_prefs[KEY_STORE_ON_CONNECT]         = self.store_on_connect_checkbox.checkState() == Qt.Checked
        new_prefs[KEY_PROMPT_TO_STORE]          = self.prompt_to_store_checkbox.checkState() == Qt.Checked
        new_prefs[KEY_STORE_IF_MORE_RECENT]     = self.store_if_more_recent_checkbox.checkState() == Qt.Checked
        new_prefs[KEY_DO_NOT_STORE_IF_REOPENED] = self.do_not_store_if_reopened_checkbox.checkState() == Qt.Checked
        plugin_prefs[COMMON_OPTIONS_STORE_NAME] = new_prefs

        new_update_prefs = {}
#         new_update_prefs[KEY_DO_UPDATE_CHECK]          = self.do_update_check.checkState() == Qt.Checked
#         new_update_prefs[KEY_DO_EARLY_FIRMWARE_CHECK]  = self.do_early_firmware_check.checkState() == Qt.Checked
#         new_update_prefs[KEY_LAST_FIRMWARE_CHECK_TIME] = self.update_check_last_time
        plugin_prefs[UPDATE_OPTIONS_STORE_NAME]        = new_update_prefs

        backup_prefs = {}
        backup_prefs[KEY_DO_DAILY_BACKUP]       = self.do_daily_backp_checkbox.checkState() == Qt.Checked
        backup_prefs[KEY_BACKUP_DEST_DIRECTORY] = unicode(self.dest_directory_edit.text())
        backup_prefs[KEY_BACKUP_COPIES_TO_KEEP] = int(unicode(self.copies_to_keep_spin.value())) if self.copies_to_keep_checkbox.checkState() == Qt.Checked else -1 
        plugin_prefs[BACKUP_OPTIONS_STORE_NAME] = backup_prefs

        db = self.plugin_action.gui.current_db
        library_config = get_library_config(db)
        library_config[KEY_CURRENT_LOCATION_CUSTOM_COLUMN] = self.current_Location_combo.get_selected_column()
        library_config[KEY_PERCENT_READ_CUSTOM_COLUMN]     = self.percent_read_combo.get_selected_column()
        library_config[KEY_RATING_CUSTOM_COLUMN]           = self.rating_combo.get_selected_column()
        library_config[KEY_LAST_READ_CUSTOM_COLUMN]        = self.last_read_combo.get_selected_column()
        set_library_config(db, library_config)

    def get_number_custom_columns(self):
        column_types = ['float','int']
        return self.get_custom_columns(column_types)

    def get_rating_custom_columns(self):
        column_types = ['rating','int']
        custom_columns = self.get_custom_columns(column_types)
        ratings_column_name = self.plugin_action.gui.library_view.model().orig_headers['rating']
        custom_columns['rating'] = {'name': ratings_column_name}
        return custom_columns

    def get_text_custom_columns(self):
        column_types = ['text']
        return self.get_custom_columns(column_types)

    def get_date_custom_columns(self):
        column_types = ['datetime']
        return self.get_custom_columns(column_types)

    def get_custom_columns(self, column_types):
        custom_columns = self.plugin_action.gui.library_view.model().custom_columns
        available_columns = {}
        for key, column in custom_columns.iteritems():
            typ = column['datatype']
            if typ in column_types and not column['is_multiple']:
                available_columns[key] = column
        return available_columns

    def help_link_activated(self, url):
        self.plugin_action.show_help(anchor="configuration")

    def edit_shortcuts(self):
        d = KeyboardConfigDialog(self.plugin_action.gui, self.plugin_action.action_spec[0])
        if d.exec_() == d.Accepted:
            self.plugin_action.gui.keyboard.finalize()

    def _get_dest_directory_name(self):
        path = choose_dir(self, 'backup annotations destination dialog','Choose destination directory')
        if path:
            self.dest_directory_edit.setText(path)
Ejemplo n.º 41
0
    def __init__(self,
                 mi=None,
                 prefs=None,
                 parent=None,
                 for_global_prefs=False):
        QWidget.__init__(self, parent)
        self.ignore_changed = False
        self.for_global_prefs = for_global_prefs

        self.l = l = QHBoxLayout(self)
        l.setContentsMargins(0, 0, 0, 0)
        self.setLayout(l)
        self.settings_tabs = st = QTabWidget(self)
        l.addWidget(st)
        self.preview_label = la = Preview(self)
        l.addWidget(la)

        if prefs is None:
            prefs = cprefs
        self.original_prefs = prefs
        self.mi = mi or self.default_mi()

        self.colors_page = cp = QWidget(st)
        st.addTab(cp, _('&Colors'))
        cp.l = l = QGridLayout()
        cp.setLayout(l)
        if for_global_prefs:
            msg = _(
                'When generating covers, a color scheme for the cover is chosen at random from the'
                ' color schemes below. You can prevent an individual scheme from being selected by'
                ' unchecking it. The preview on the right shows the currently selected color scheme.'
            )
        else:
            msg = _(
                'Choose a color scheme to be used for this generated cover.'
            ) + '<p>' + _(
                'In normal cover generation, the color scheme is chosen at random from the list of color schemes below. You'
                ' can prevent an individual color scheme from being chosen by unchecking it here.'
            )
        cp.la = la = QLabel('<p>' + msg)
        la.setWordWrap(True)
        l.addWidget(la, 0, 0, 1, -1)
        self.colors_list = cl = QListWidget(cp)
        l.addWidget(cl, 1, 0, 1, -1)
        self.colors_map = OrderedDict()
        self.ncs = ncs = QPushButton(
            QIcon(I('plus.png')), _('&New color scheme'), cp)
        ncs.clicked.connect(self.create_color_scheme)
        l.addWidget(ncs)
        self.ecs = ecs = QPushButton(
            QIcon(I('format-fill-color.png')), _('&Edit color scheme'), cp)
        ecs.clicked.connect(self.edit_color_scheme)
        l.addWidget(ecs, l.rowCount() - 1, 1)
        self.rcs = rcs = QPushButton(
            QIcon(I('minus.png')), _('&Remove color scheme'), cp)
        rcs.clicked.connect(self.remove_color_scheme)
        l.addWidget(rcs, l.rowCount() - 1, 2)

        self.styles_page = sp = QWidget(st)
        st.addTab(sp, _('&Styles'))
        sp.l = l = QVBoxLayout()
        sp.setLayout(l)
        if for_global_prefs:
            msg = _(
                'When generating covers, a style for the cover is chosen at random from the'
                ' styles below. You can prevent an individual style from being selected by'
                ' unchecking it. The preview on the right shows the currently selected style.'
            )
        else:
            msg = _(
                'Choose a style to be used for this generated cover.'
            ) + '<p>' + _(
                'In normal cover generation, the style is chosen at random from the list of styles below. You'
                ' can prevent an individual style from being chosen by unchecking it here.'
            )
        sp.la = la = QLabel('<p>' + msg)
        la.setWordWrap(True)
        l.addWidget(la)
        self.styles_list = sl = QListWidget(sp)
        l.addWidget(sl)
        self.style_map = OrderedDict()

        self.font_page = fp = QWidget(st)
        st.addTab(fp, _('&Fonts and Sizes'))
        fp.l = l = QFormLayout()
        fp.setLayout(l)
        fp.f = []

        def add_hline():
            f = QFrame()
            fp.f.append(f)
            f.setFrameShape(f.HLine)
            l.addRow(f)

        for x, label, size_label in (
            ('title', _('&Title font family:'), _('&Title font size:')),
            ('subtitle', _('&Subtitle font family'),
             _('&Subtitle font size:')),
            ('footer', _('&Footer font family'), _('&Footer font size')),
        ):
            attr = '%s_font_family' % x
            ff = FontFamilyChooser(fp)
            setattr(self, attr, ff)
            l.addRow(label, ff)
            ff.family_changed.connect(self.emit_changed)
            attr = '%s_font_size' % x
            fs = QSpinBox(fp)
            setattr(self, attr, fs)
            fs.setMinimum(8), fs.setMaximum(200), fs.setSuffix(' px')
            fs.setValue(prefs[attr])
            fs.valueChanged.connect(self.emit_changed)
            l.addRow(size_label, fs)
            add_hline()
        self.changed_timer = t = QTimer(self)
        t.setSingleShot(True), t.setInterval(500), t.timeout.connect(
            self.emit_changed)

        def create_sz(label):
            ans = QSpinBox(self)
            ans.setSuffix(' px'), ans.setMinimum(100), ans.setMaximum(10000)
            l.addRow(label, ans)
            ans.valueChanged.connect(self.changed_timer.start)
            return ans

        self.cover_width = create_sz(_('Cover &width:'))
        self.cover_height = create_sz(_('Cover &height:'))
        fp.cla = la = QLabel(
            _('Note that the preview to the side is of fixed aspect ratio, so changing the cover'
              ' width above will not have any effect. If you change the height, you should also change the width nevertheless'
              ' as it will be used in actual cover generation.'))
        la.setWordWrap(True)
        l.addRow(la)

        self.templates_page = tp = QWidget(st)
        st.addTab(tp, _('&Text'))
        tp.l = l = QVBoxLayout()
        tp.setLayout(l)
        tp.la = la = QLabel(
            _('The text on the generated cover is taken from the metadata of the book.'
              ' This is controlled via templates. You can use the <b>, <i> and <br> tags'
              ' in the templates for bold, italic and line breaks, respectively. The'
              ' default templates use the title, series and authors. You can change them to use'
              ' whatever metadata you like.'))
        la.setWordWrap(True), la.setTextFormat(Qt.PlainText)
        l.addWidget(la)

        def create_template_widget(title, which, button):
            attr = which + '_template'
            heading = QLabel('<h2>' + title)
            setattr(tp, attr + '_heading', heading)
            l.addWidget(heading)
            la = QLabel()
            setattr(self, attr, la)
            l.addWidget(la), la.setTextFormat(Qt.PlainText), la.setStyleSheet(
                'QLabel {font-family: monospace}')
            la.setWordWrap(True)
            b = QPushButton(button)
            b.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            b.clicked.connect(partial(self.change_template, which))
            setattr(self, attr + '_button', b)
            l.addWidget(b)
            if which != 'footer':
                f = QFrame(tp)
                setattr(tp, attr + '_sep', f), f.setFrameShape(QFrame.HLine)
                l.addWidget(f)
            l.addSpacing(10)

        create_template_widget(
            _('The title template'), 'title', _('Change the &title template'))
        create_template_widget(
            _('The sub-title template'), 'subtitle',
            _('Change the &sub-title template'))
        create_template_widget(
            _('The footer template'), 'footer',
            _('Change the &footer template'))
        l.addStretch(2)

        self.apply_prefs(prefs)
        self.changed.connect(self.update_preview)
        self.styles_list.itemSelectionChanged.connect(self.update_preview)
        self.colors_list.itemSelectionChanged.connect(self.update_preview)
        self.update_preview()
Ejemplo n.º 42
0
 def create_sz(label):
     ans = QSpinBox(self)
     ans.setSuffix(' px'), ans.setMinimum(100), ans.setMaximum(10000)
     l.addRow(label, ans)
     ans.valueChanged.connect(self.changed_timer.start)
     return ans
Ejemplo n.º 43
0
class AddEmptyBookDialog(QDialog):

    def __init__(self, parent, db, author, series=None, title=None):
        QDialog.__init__(self, parent)
        self.db = db

        self.setWindowTitle(_('How many empty books?'))

        self._layout = QGridLayout(self)
        self.setLayout(self._layout)

        self.qty_label = QLabel(_('How many empty books should be added?'))
        self._layout.addWidget(self.qty_label, 0, 0, 1, 2)

        self.qty_spinbox = QSpinBox(self)
        self.qty_spinbox.setRange(1, 10000)
        self.qty_spinbox.setValue(1)
        self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2)

        self.author_label = QLabel(_('Set the author of the new books to:'))
        self._layout.addWidget(self.author_label, 2, 0, 1, 2)

        self.authors_combo = EditWithComplete(self)
        self.authors_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.authors_combo.setEditable(True)
        self._layout.addWidget(self.authors_combo, 3, 0, 1, 1)
        self.initialize_authors(db, author)

        self.clear_button = QToolButton(self)
        self.clear_button.setIcon(QIcon(I('trash.png')))
        self.clear_button.setToolTip(_('Reset author to Unknown'))
        self.clear_button.clicked.connect(self.reset_author)
        self._layout.addWidget(self.clear_button, 3, 1, 1, 1)

        self.series_label = QLabel(_('Set the series of the new books to:'))
        self._layout.addWidget(self.series_label, 4, 0, 1, 2)

        self.series_combo = EditWithComplete(self)
        self.series_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.series_combo.setEditable(True)
        self._layout.addWidget(self.series_combo, 5, 0, 1, 1)
        self.initialize_series(db, series)

        self.sclear_button = QToolButton(self)
        self.sclear_button.setIcon(QIcon(I('trash.png')))
        self.sclear_button.setToolTip(_('Reset series'))
        self.sclear_button.clicked.connect(self.reset_series)
        self._layout.addWidget(self.sclear_button, 5, 1, 1, 1)

        self.title_label = QLabel(_('Set the title of the new books to:'))
        self._layout.addWidget(self.title_label, 6, 0, 1, 2)

        self.title_edit = QLineEdit(self)
        self.title_edit.setText(title or '')
        self._layout.addWidget(self.title_edit, 7, 0, 1, 1)

        self.tclear_button = QToolButton(self)
        self.tclear_button.setIcon(QIcon(I('trash.png')))
        self.tclear_button.setToolTip(_('Reset title'))
        self.tclear_button.clicked.connect(self.title_edit.clear)
        self._layout.addWidget(self.tclear_button, 7, 1, 1, 1)

        self.format_label = QLabel(_('Also create an empty ebook in format:'))
        self._layout.addWidget(self.format_label, 8, 0, 1, 2)
        c = self.format_value = QComboBox(self)
        from calibre.ebooks.oeb.polish.create import valid_empty_formats
        possible_formats = [''] + sorted(x.upper() for x in valid_empty_formats)
        c.addItems(possible_formats)
        c.setToolTip(_('Also create an empty book format file that you can subsequently edit'))
        if gprefs.get('create_empty_epub_file', False):
            # Migration of the check box
            gprefs.set('create_empty_format_file', 'epub')
            del gprefs['create_empty_epub_file']
        use_format = gprefs.get('create_empty_format_file', '').upper()
        try:
            c.setCurrentIndex(possible_formats.index(use_format))
        except Exception:
            pass
        self._layout.addWidget(c, 9, 0, 1, 1)

        button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self._layout.addWidget(button_box, 10, 0, 1, -1)
        self.resize(self.sizeHint())

    def accept(self):
        gprefs['create_empty_format_file'] = self.format_value.currentText().lower()
        return QDialog.accept(self)

    def reset_author(self, *args):
        self.authors_combo.setEditText(_('Unknown'))

    def reset_series(self):
        self.series_combo.setEditText('')

    def initialize_authors(self, db, author):
        au = author
        if not au:
            au = _('Unknown')
        self.authors_combo.show_initial_value(au.replace('|', ','))

        self.authors_combo.set_separator('&')
        self.authors_combo.set_space_before_sep(True)
        self.authors_combo.set_add_separator(tweaks['authors_completer_append_separator'])
        self.authors_combo.update_items_cache(db.all_author_names())

    def initialize_series(self, db, series):
        self.series_combo.show_initial_value(series or '')
        self.series_combo.update_items_cache(db.all_series_names())
        self.series_combo.set_separator(None)

    @property
    def qty_to_add(self):
        return self.qty_spinbox.value()

    @property
    def selected_authors(self):
        return string_to_authors(unicode(self.authors_combo.text()))

    @property
    def selected_series(self):
        return unicode(self.series_combo.text())

    @property
    def selected_title(self):
        return self.title_edit.text().strip()
Ejemplo n.º 44
0
    def __init__(self, parent, db, author, series=None, title=None):
        QDialog.__init__(self, parent)
        self.db = db

        self.setWindowTitle(_('How many empty books?'))

        self._layout = QGridLayout(self)
        self.setLayout(self._layout)

        self.qty_label = QLabel(_('How many empty books should be added?'))
        self._layout.addWidget(self.qty_label, 0, 0, 1, 2)

        self.qty_spinbox = QSpinBox(self)
        self.qty_spinbox.setRange(1, 10000)
        self.qty_spinbox.setValue(1)
        self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2)

        self.author_label = QLabel(_('Set the author of the new books to:'))
        self._layout.addWidget(self.author_label, 2, 0, 1, 2)

        self.authors_combo = EditWithComplete(self)
        self.authors_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.authors_combo.setEditable(True)
        self._layout.addWidget(self.authors_combo, 3, 0, 1, 1)
        self.initialize_authors(db, author)

        self.clear_button = QToolButton(self)
        self.clear_button.setIcon(QIcon(I('trash.png')))
        self.clear_button.setToolTip(_('Reset author to Unknown'))
        self.clear_button.clicked.connect(self.reset_author)
        self._layout.addWidget(self.clear_button, 3, 1, 1, 1)

        self.series_label = QLabel(_('Set the series of the new books to:'))
        self._layout.addWidget(self.series_label, 4, 0, 1, 2)

        self.series_combo = EditWithComplete(self)
        self.series_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.series_combo.setEditable(True)
        self._layout.addWidget(self.series_combo, 5, 0, 1, 1)
        self.initialize_series(db, series)

        self.sclear_button = QToolButton(self)
        self.sclear_button.setIcon(QIcon(I('trash.png')))
        self.sclear_button.setToolTip(_('Reset series'))
        self.sclear_button.clicked.connect(self.reset_series)
        self._layout.addWidget(self.sclear_button, 5, 1, 1, 1)

        self.title_label = QLabel(_('Set the title of the new books to:'))
        self._layout.addWidget(self.title_label, 6, 0, 1, 2)

        self.title_edit = QLineEdit(self)
        self.title_edit.setText(title or '')
        self._layout.addWidget(self.title_edit, 7, 0, 1, 1)

        self.tclear_button = QToolButton(self)
        self.tclear_button.setIcon(QIcon(I('trash.png')))
        self.tclear_button.setToolTip(_('Reset title'))
        self.tclear_button.clicked.connect(self.title_edit.clear)
        self._layout.addWidget(self.tclear_button, 7, 1, 1, 1)

        self.format_label = QLabel(_('Also create an empty ebook in format:'))
        self._layout.addWidget(self.format_label, 8, 0, 1, 2)
        c = self.format_value = QComboBox(self)
        from calibre.ebooks.oeb.polish.create import valid_empty_formats
        possible_formats = [''] + sorted(x.upper() for x in valid_empty_formats)
        c.addItems(possible_formats)
        c.setToolTip(_('Also create an empty book format file that you can subsequently edit'))
        if gprefs.get('create_empty_epub_file', False):
            # Migration of the check box
            gprefs.set('create_empty_format_file', 'epub')
            del gprefs['create_empty_epub_file']
        use_format = gprefs.get('create_empty_format_file', '').upper()
        try:
            c.setCurrentIndex(possible_formats.index(use_format))
        except Exception:
            pass
        self._layout.addWidget(c, 9, 0, 1, 1)

        button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self._layout.addWidget(button_box, 10, 0, 1, -1)
        self.resize(self.sizeHint())
Ejemplo n.º 45
0
class AddEmptyBookDialog(QDialog):

    def __init__(self, parent, db, author, series=None):
        QDialog.__init__(self, parent)
        self.db = db

        self.setWindowTitle(_('How many empty books?'))

        self._layout = QGridLayout(self)
        self.setLayout(self._layout)

        self.qty_label = QLabel(_('How many empty books should be added?'))
        self._layout.addWidget(self.qty_label, 0, 0, 1, 2)

        self.qty_spinbox = QSpinBox(self)
        self.qty_spinbox.setRange(1, 10000)
        self.qty_spinbox.setValue(1)
        self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2)

        self.author_label = QLabel(_('Set the author of the new books to:'))
        self._layout.addWidget(self.author_label, 2, 0, 1, 2)

        self.authors_combo = EditWithComplete(self)
        self.authors_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.authors_combo.setEditable(True)
        self._layout.addWidget(self.authors_combo, 3, 0, 1, 1)
        self.initialize_authors(db, author)

        self.clear_button = QToolButton(self)
        self.clear_button.setIcon(QIcon(I('trash.png')))
        self.clear_button.setToolTip(_('Reset author to Unknown'))
        self.clear_button.clicked.connect(self.reset_author)
        self._layout.addWidget(self.clear_button, 3, 1, 1, 1)

        self.series_label = QLabel(_('Set the series of the new books to:'))
        self._layout.addWidget(self.series_label, 4, 0, 1, 2)

        self.series_combo = EditWithComplete(self)
        self.authors_combo.setSizeAdjustPolicy(
                self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
        self.series_combo.setEditable(True)
        self._layout.addWidget(self.series_combo, 5, 0, 1, 1)
        self.initialize_series(db, series)

        self.sclear_button = QToolButton(self)
        self.sclear_button.setIcon(QIcon(I('trash.png')))
        self.sclear_button.setToolTip(_('Reset series'))
        self.sclear_button.clicked.connect(self.reset_series)
        self._layout.addWidget(self.sclear_button, 5, 1, 1, 1)

        self.create_epub = c = QCheckBox(_('Create an empty EPUB file as well'))
        c.setChecked(gprefs.get('create_empty_epub_file', False))
        c.setToolTip(_('Also create an empty EPUB file that you can subsequently edit'))
        self._layout.addWidget(c, 6, 0, 1, -1)

        button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self._layout.addWidget(button_box, 7, 0, 1, -1)
        self.resize(self.sizeHint())

    def accept(self):
        oval = gprefs.get('create_empty_epub_file', False)
        if self.create_epub.isChecked() != oval:
            gprefs['create_empty_epub_file'] = self.create_epub.isChecked()
        return QDialog.accept(self)

    def reset_author(self, *args):
        self.authors_combo.setEditText(_('Unknown'))

    def reset_series(self):
        self.series_combo.setEditText('')

    def initialize_authors(self, db, author):
        au = author
        if not au:
            au = _('Unknown')
        self.authors_combo.show_initial_value(au.replace('|', ','))

        self.authors_combo.set_separator('&')
        self.authors_combo.set_space_before_sep(True)
        self.authors_combo.set_add_separator(tweaks['authors_completer_append_separator'])
        self.authors_combo.update_items_cache(db.all_author_names())

    def initialize_series(self, db, series):
        self.series_combo.show_initial_value(series or '')
        self.series_combo.update_items_cache(db.all_series_names())
        self.series_combo.set_separator(None)

    @property
    def qty_to_add(self):
        return self.qty_spinbox.value()

    @property
    def selected_authors(self):
        return string_to_authors(unicode(self.authors_combo.text()))

    @property
    def selected_series(self):
        return unicode(self.series_combo.text())
Ejemplo n.º 46
0
 def __init__(self, name, layout):
     QSpinBox.__init__(self)
     self.setRange(0, 10000)
     opt = options[name]
     self.valueChanged.connect(self.changed_signal.emit)
     init_opt(self, opt, layout)