Пример #1
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
Пример #2
0
    def __init__(self, names, txt, parent=None):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout(self)
        self.setLayout(l)

        self.la = la = QLabel(_('Create a Virtual Library based on %s') % txt)
        l.addWidget(la)

        self._names = QListWidget(self)
        self._names.addItems(sorted(names, key=sort_key))
        self._names.setSelectionMode(self._names.ExtendedSelection)
        l.addWidget(self._names)

        self._or = QRadioButton(_('Match any of the selected %s names')%txt)
        self._and = QRadioButton(_('Match all of the selected %s names')%txt)
        self._or.setChecked(True)
        l.addWidget(self._or)
        l.addWidget(self._and)

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

        self.resize(self.sizeHint())
Пример #3
0
class ConfigWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        self.vl = QVBoxLayout()
        self.setLayout(self.vl)

        self.xray_button = QRadioButton('X-Ray', self)
        self.xray_button.setChecked(prefs['x-ray'])
        self.vl.addWidget(self.xray_button)

        self.donate_button = QPushButton('Donate', self)
        self.donate_button.clicked.connect(self.donate)
        self.vl.addWidget(self.donate_button)

        self.github_button = QPushButton('Source code', self)
        self.github_button.clicked.connect(self.github)
        self.vl.addWidget(self.github_button)

    def donate(self):
        webbrowser.open('https://liberapay.com/xxyzz/donate')

    def github(self):
        webbrowser.open('https://github.com/xxyzz/WordDumb')

    def save_settings(self):
        prefs['x-ray'] = self.xray_button.isChecked()
    def __init__(self, names, txt, parent=None):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout(self)
        self.setLayout(l)

        self.la = la = QLabel(_('Create a Virtual library based on %s') % txt)
        l.addWidget(la)

        self._names = QListWidget(self)
        self._names.addItems(sorted(names, key=sort_key))
        self._names.setSelectionMode(self._names.ExtendedSelection)
        l.addWidget(self._names)

        self._or = QRadioButton(_('Match any of the selected %s names') % txt)
        self._and = QRadioButton(_('Match all of the selected %s names') % txt)
        self._or.setChecked(True)
        l.addWidget(self._or)
        l.addWidget(self._and)

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

        self.resize(self.sizeHint())
Пример #5
0
    def __init__(self, mainWindow):

        # call the base class constructor:
        QWidget.__init__(self, mainWindow)

        self.mw = mainWindow  # remember he application main windwos

        # Attributes (persistant data)
        self.__figure = Figure()  # the plot figure
        self.__axes = None  # axis system
        self.__canvas = None  # area for matplotlib plot
        self.__toolbar = None  # plot tool bar
        self.__xlim = None  # xmin, xmay of the plo
        self.__ylim = None  # ymin, ymax of the plot
        self.__axes_aspect = 'equal'  # 'equal' or 'auto'

        self.btn_imageSize = QRadioButton("ImageSize", self)
        self.btn_autoSize = QRadioButton("AutoSize", self)
        self.btn_axesEqual = QRadioButton("Equal", self)
        self.btn_axesAuto = QRadioButton("Auto", self)

        group = QButtonGroup(self)  # pour les 2 boutons imageSize, autoSize
        group.addButton(self.btn_imageSize)
        group.addButton(self.btn_autoSize)

        group = QButtonGroup(self)
        group.addButton(self.btn_axesEqual)
        group.addButton(self.btn_axesAuto)

        self.__initUI()  # Initialisation de l'interface utilisateur
Пример #6
0
    def __init__(self, names, parent=None):
        QDialog.__init__(self, parent)
        self.names = names
        self.setWindowTitle(_('Choose master file'))
        self.l = l = QVBoxLayout()
        self.setLayout(l)
        self.la = la = QLabel(
            _('Choose the master file. All selected files will be merged into the master file:'
              ))
        la.setWordWrap(True)
        l.addWidget(la)
        self.sa = sa = QScrollArea(self)
        l.addWidget(sa)
        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok
                                        | QDialogButtonBox.Cancel)
        l.addWidget(bb)
        bb.accepted.connect(self.accept)
        bb.rejected.connect(self.reject)
        self.w = w = QWidget(self)
        w.l = QVBoxLayout()
        w.setLayout(w.l)

        buttons = self.buttons = [QRadioButton(n) for n in names]
        buttons[0].setChecked(True)
        map(w.l.addWidget, buttons)
        sa.setWidget(w)

        self.resize(self.sizeHint() + QSize(150, 20))
Пример #7
0
    def __init__(self):
        QWidget.__init__(self)

        self.vl = QVBoxLayout()
        self.setLayout(self.vl)

        self.xray_button = QRadioButton('X-Ray', self)
        self.xray_button.setChecked(prefs['x-ray'])
        self.vl.addWidget(self.xray_button)

        self.donate_button = QPushButton('Donate', self)
        self.donate_button.clicked.connect(self.donate)
        self.vl.addWidget(self.donate_button)

        self.github_button = QPushButton('Source code', self)
        self.github_button.clicked.connect(self.github)
        self.vl.addWidget(self.github_button)
Пример #8
0
    def __init__(self, parent=None):
        QFrame.__init__(self, parent)
        self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
        self.setAutoFillBackground(True)
        self.capture = 0

        self.setFrameShape(self.StyledPanel)
        self.setFrameShadow(self.Raised)
        self._layout = l = QGridLayout(self)
        self.setLayout(l)

        self.header = QLabel('')
        l.addWidget(self.header, 0, 0, 1, 2)

        self.use_default = QRadioButton('')
        self.use_custom = QRadioButton(_('&Custom'))
        l.addWidget(self.use_default, 1, 0, 1, 3)
        l.addWidget(self.use_custom, 2, 0, 1, 3)
        self.use_custom.toggled.connect(self.custom_toggled)

        off = 2
        for which in (1, 2):
            text = _('&Shortcut:') if which == 1 else _('&Alternate shortcut:')
            la = QLabel(text)
            la.setStyleSheet('QLabel { margin-left: 1.5em }')
            l.addWidget(la, off + which, 0, 1, 3)
            setattr(self, 'label%d' % which, la)
            button = QPushButton(_('None'), self)
            button.clicked.connect(partial(self.capture_clicked, which=which))
            button.installEventFilter(self)
            setattr(self, 'button%d' % which, button)
            clear = QToolButton(self)
            clear.setIcon(QIcon(I('clear_left.png')))
            clear.clicked.connect(partial(self.clear_clicked, which=which))
            setattr(self, 'clear%d' % which, clear)
            l.addWidget(button, off + which, 1, 1, 1)
            l.addWidget(clear, off + which, 2, 1, 1)
            la.setBuddy(button)

        self.done_button = doneb = QPushButton(_('Done'), self)
        l.addWidget(doneb, 0, 2, 1, 1)
        doneb.clicked.connect(lambda: self.editing_done.emit(self))
        l.setColumnStretch(0, 100)

        self.custom_toggled(False)
Пример #9
0
    def __init__(self, parent=None):
        QFrame.__init__(self, parent)
        self.setFocusPolicy(Qt.StrongFocus)
        self.setAutoFillBackground(True)
        self.capture = 0

        self.setFrameShape(self.StyledPanel)
        self.setFrameShadow(self.Raised)
        self._layout = l = QGridLayout(self)
        self.setLayout(l)

        self.header = QLabel('')
        l.addWidget(self.header, 0, 0, 1, 2)

        self.use_default = QRadioButton('')
        self.use_custom = QRadioButton(_('Custom'))
        l.addWidget(self.use_default, 1, 0, 1, 3)
        l.addWidget(self.use_custom, 2, 0, 1, 3)
        self.use_custom.toggled.connect(self.custom_toggled)

        off = 2
        for which in (1, 2):
            text = _('&Shortcut:') if which == 1 else _('&Alternate shortcut:')
            la = QLabel(text)
            la.setStyleSheet('QLabel { margin-left: 1.5em }')
            l.addWidget(la, off+which, 0, 1, 3)
            setattr(self, 'label%d'%which, la)
            button = QPushButton(_('None'), self)
            button.clicked.connect(partial(self.capture_clicked, which=which))
            button.keyPressEvent = partial(self.key_press_event, which=which)
            setattr(self, 'button%d'%which, button)
            clear = QToolButton(self)
            clear.setIcon(QIcon(I('clear_left.png')))
            clear.clicked.connect(partial(self.clear_clicked, which=which))
            setattr(self, 'clear%d'%which, clear)
            l.addWidget(button, off+which, 1, 1, 1)
            l.addWidget(clear, off+which, 2, 1, 1)
            la.setBuddy(button)

        self.done_button = doneb = QPushButton(_('Done'), self)
        l.addWidget(doneb, 0, 2, 1, 1)
        doneb.clicked.connect(lambda : self.editing_done.emit(self))
        l.setColumnStretch(0, 100)

        self.custom_toggled(False)
Пример #10
0
 def __init__(self, index, dup_check, parent=None):
     QFrame.__init__(self, parent)
     self.setFrameShape(self.StyledPanel)
     self.setFrameShadow(self.Raised)
     self.setFocusPolicy(Qt.StrongFocus)
     self.setAutoFillBackground(True)
     self.l = l = QVBoxLayout(self)
     self.header = la = QLabel(self)
     la.setWordWrap(True)
     l.addWidget(la)
     self.default_shortcuts = QRadioButton(_("&Default"), self)
     self.custom = QRadioButton(_("&Custom"), self)
     self.custom.toggled.connect(self.custom_toggled)
     l.addWidget(self.default_shortcuts)
     l.addWidget(self.custom)
     for which in 1, 2:
         la = QLabel(
             _("&Shortcut:") if which == 1 else _("&Alternate shortcut:"))
         setattr(self, 'label%d' % which, la)
         h = QHBoxLayout()
         l.addLayout(h)
         h.setContentsMargins(25, -1, -1, -1)
         h.addWidget(la)
         b = QPushButton(_("Click to change"), self)
         la.setBuddy(b)
         b.clicked.connect(partial(self.capture_clicked, which=which))
         b.installEventFilter(self)
         setattr(self, 'button%d' % which, b)
         h.addWidget(b)
         c = QToolButton(self)
         c.setIcon(QIcon(I('clear_left.png')))
         c.setToolTip(_('Clear'))
         h.addWidget(c)
         c.clicked.connect(partial(self.clear_clicked, which=which))
         setattr(self, 'clear%d' % which, c)
     self.data_model = index.model()
     self.capture = 0
     self.key = None
     self.shorcut1 = self.shortcut2 = None
     self.dup_check = dup_check
     self.custom_toggled(False)
Пример #11
0
    def init_ui(self):

        layout = QGridLayout()
        self.controls.append(QRadioButton(self.tr("english")))
        # noinspection PyArgumentList
        layout.addWidget(self.controls[-1], 0, 0)
        self.controls.append(QRadioButton(self.tr("russian")))
        # noinspection PyArgumentList
        layout.addWidget(self.controls[-1], 1, 0)
        self.controls.append(QCheckBox(self.tr("auto switch language")))
        # noinspection PyArgumentList
        layout.addWidget(self.controls[-1], 2, 0)
        self.controls.append(QPushButton(self.tr("Apply")))
        # noinspection PyArgumentList
        layout.addWidget(self.controls[-1], 4, 0)

        self.controls[-1].clicked.connect(self.apply)

        self.setWindowTitle(self.tr("Auto switch params"))
        # self.setGeometry(300, 300, 200, 100)
        self.setLayout(layout)
Пример #12
0
    def _initialize_file_type_settings(self, layout):
        '''Initialize file creation/sending type settings'''
        separator_b = QFrame()
        separator_b.setFrameStyle(QFrame.HLine)
        separator_b.setFrameShadow(QFrame.Sunken)
        layout.addWidget(separator_b)

        book_types_to_create = QGroupBox()
        book_types_to_create.setTitle('Book types to create files for:')
        book_types_to_create.setLayout(QHBoxLayout(book_types_to_create))

        self._settings['mobi'] = QCheckBox('MOBI')
        self._settings['mobi'].setChecked('mobi' in __prefs__['formats'])
        book_types_to_create.layout().addWidget(self._settings['mobi'])

        self._settings['azw3'] = QCheckBox('AZW3')
        self._settings['azw3'].setChecked('azw3' in __prefs__['formats'])
        book_types_to_create.layout().addWidget(self._settings['azw3'])
        layout.addWidget(book_types_to_create)

        file_preference_layout = QGroupBox()
        file_preference_layout.setTitle(
            'If device has both (mobi and azw3) formats, prefer:')
        file_preference_layout.setLayout(QHBoxLayout(file_preference_layout))

        file_preference_group = QButtonGroup()
        self._settings['file_preference_mobi'] = QRadioButton('MOBI')
        self._settings['file_preference_mobi'].setChecked(
            __prefs__['file_preference'] == 'mobi')
        file_preference_group.addButton(self._settings['file_preference_mobi'])
        file_preference_layout.layout().addWidget(
            self._settings['file_preference_mobi'])

        self._settings['file_preference_azw3'] = QRadioButton('AZW3')
        self._settings['file_preference_azw3'].setChecked(
            __prefs__['file_preference'] == 'azw3')
        file_preference_group.addButton(self._settings['file_preference_azw3'])
        file_preference_layout.layout().addWidget(
            self._settings['file_preference_azw3'])
        layout.addWidget(file_preference_layout)
Пример #13
0
 def b(name, text, tt):
     ans = QRadioButton(text, w)
     l.addWidget(ans)
     ans.setToolTip(tt)
     setattr(w, name, ans)
     ans.setObjectName(name)
     return ans
Пример #14
0
    def __init__(self, dicTitle, dicList):
        super(LLT_MC, self).__init__()
        self.w = QWidget()
        self.setCentralWidget(self.w)

        self.title = dicTitle
        self.wordList = dicList

        self.setWindowTitle("Multiple Choice")
        self.setGeometry(0, 0, 300, 400)

        self.currentWordS = random.sample(self.wordList, 3)
        self.currentQWord = self.currentWordS[0][0]
        self.currentAWord = self.currentWordS[0][1]

        self.topLabel = QLabel("Multiple Choice: " + str(dicTitle))
        self.wordLabel = QLabel()
        self.wordLabel.setFont(QFont('Times New Roman', 16))
        self.wordLabel.setAlignment(Qt.AlignCenter)
        self.resultLabel = QLabel()
        self.resultLabel.setAlignment(Qt.AlignCenter)

        self.aRad = QRadioButton()
        self.bRad = QRadioButton()
        self.cRad = QRadioButton()
        self.group = QButtonGroup()
        self.group.addButton(self.aRad)
        self.group.addButton(self.bRad)
        self.group.addButton(self.cRad)

        self.checkBut = QPushButton("Check")
        self.checkBut.setMinimumWidth(100)
        self.checkBut.setMinimumHeight(70)
        self.checkBut.clicked.connect(self.check)
        self.nextBut = QPushButton("Next Word")
        self.nextBut.setMinimumWidth(100)
        self.nextBut.setMinimumHeight(70)
        self.nextBut.clicked.connect(self.next)
        self.exitBut = QPushButton("Exit")
        self.exitBut.setMinimumWidth(130)
        self.exitBut.setMinimumHeight(70)
        self.exitBut.clicked.connect(self.exit)

        self.hbox = QHBoxLayout()
        self.hbox.addWidget(self.checkBut)
        self.hbox.addWidget(self.nextBut)
        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.topLabel)
        self.vbox.addWidget(self.wordLabel)
        self.vbox.addWidget(self.aRad)
        self.vbox.addWidget(self.bRad)
        self.vbox.addWidget(self.cRad)
        self.vbox.addWidget(self.resultLabel)
        self.vbox.addLayout(self.hbox)
        self.vbox.addWidget(self.exitBut)

        self.w.setLayout(self.vbox)
        self.setWord()
Пример #15
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QVBoxLayout(self)
        self.h = h = QHBoxLayout()

        self.filter_edit = e = QLineEdit(self)
        l.addWidget(e)
        e.setPlaceholderText(_('Filter'))
        self.model = m = self.MODEL(self)
        self.proxy = p = self.PROXY(self)
        p.setSourceModel(m)
        self.view = f = QTreeView(self)
        f.setAlternatingRowColors(True)
        f.setHeaderHidden(True), f.setExpandsOnDoubleClick(False)
        f.setModel(p)
        l.addWidget(f)
        f.doubleClicked.connect(self.double_clicked)
        e.textChanged.connect(p.filter_text)

        l.addLayout(h)
        h.addWidget(QLabel(_('Sort by:')))
        self.counts_button = b = QRadioButton(_('&Counts'), self)
        b.setChecked(self.read_state('sort-on-counts', True))
        h.addWidget(b)
        self.name_button = b = QRadioButton(_('&Name'), self)
        b.setChecked(not self.read_state('sort-on-counts', True))
        h.addWidget(b)
        b.toggled.connect(self.resort)
        h.addStrut(20)
        self._sort_order = o = QComboBox(self)
        o.addItems([_('Ascending'), _('Descending')])
        o.setCurrentIndex(0 if self.read_state('sort-ascending', True) else 1)
        o.setEditable(False)
        o.currentIndexChanged[int].connect(self.resort)
        h.addWidget(o)
        h.addStretch(10)
        self.summary = la = QLabel('\xa0')
        h.addWidget(la)
Пример #16
0
class SelectNames(QDialog):  # {{{
    def __init__(self, names, txt, parent=None):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout(self)
        self.setLayout(l)

        self.la = la = QLabel(_('Create a Virtual library based on %s') % txt)
        l.addWidget(la)

        self._names = QListWidget(self)
        self._names.addItems(sorted(names, key=sort_key))
        self._names.setSelectionMode(
            QAbstractItemView.SelectionMode.MultiSelection)
        l.addWidget(self._names)

        self._or = QRadioButton(_('Match any of the selected %s') % txt)
        self._and = QRadioButton(_('Match all of the selected %s') % txt)
        self._or.setChecked(True)
        l.addWidget(self._or)
        l.addWidget(self._and)

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

        self.resize(self.sizeHint())

    @property
    def names(self):
        for item in self._names.selectedItems():
            yield unicode_type(item.data(Qt.ItemDataRole.DisplayRole) or '')

    @property
    def match_type(self):
        return ' and ' if self._and.isChecked() else ' or '
Пример #17
0
class SelectNames(QDialog):  # {{{

    def __init__(self, names, txt, parent=None):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout(self)
        self.setLayout(l)

        self.la = la = QLabel(_('Create a Virtual Library based on %s') % txt)
        l.addWidget(la)

        self._names = QListWidget(self)
        self._names.addItems(sorted(names, key=sort_key))
        self._names.setSelectionMode(self._names.ExtendedSelection)
        l.addWidget(self._names)

        self._or = QRadioButton(_('Match any of the selected %s names')%txt)
        self._and = QRadioButton(_('Match all of the selected %s names')%txt)
        self._or.setChecked(True)
        l.addWidget(self._or)
        l.addWidget(self._and)

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

        self.resize(self.sizeHint())

    @property
    def names(self):
        for item in self._names.selectedItems():
            yield unicode(item.data(Qt.DisplayRole) or '')

    @property
    def match_type(self):
        return ' and ' if self._and.isChecked() else ' or '
Пример #18
0
    def __init__(self, gui, formats, parent=None):
        QDialog.__init__(self, parent=parent)

        self.gui = gui
        self.formats = formats
        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok)

        msg = '\nThis book has multiple formats which could be scrambled.\n' \
            'Please select one of the following:\n'
        label = QLabel(msg)

        self.dradio = {}
        for k in self.formats:
            self.dradio[k] = QRadioButton(k)

        gpbox1 = QGroupBox('Formats available:')
        lay1 = QHBoxLayout()
        gpbox1.setLayout(lay1)

        for fmt in self.formats:
            lay1.addWidget(self.dradio[fmt])

        if 'EPUB' in self.formats:
            self.dradio['EPUB'].setChecked(True)
        else:
            self.dradio[self.formats[0]].setChecked(True)

        lay = QVBoxLayout()
        lay.addWidget(label)
        lay.addWidget(gpbox1)
        lay.addStretch()
        lay.addWidget(buttonBox)
        self.setLayout(lay)

        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)

        self.setWindowTitle('ScrambleEbook: Select a single format')
        self.setWindowIcon(get_icons('images/plugin_icon.png'))
Пример #19
0
    def npkModeBox(self):
        label_ = QLabel(self)
        label_.resize(self.width() // 3, 25)
        label_.setText("NPK提取模式:")
        label_.setAlignment(Qt.AlignCenter)
        label_.setStyleSheet("font-size: 15px")
        # 选项AB
        npkYes = QRadioButton(self)
        npkYes.resize(self.width() // 3, 25)
        npkYes.move(self.width() // 3, 0)
        npkYes.setText("提取")
        npkNo = QRadioButton(self)
        npkNo.resize(self.width() // 3, 25)
        npkNo.move(self.width() // 3 * 2, 0)
        npkNo.setText("不提取")
        npkNo.setChecked(True)

        def npkYesFunc():
            if not self.mainWin.npkDict:
                QMessageBox.warning(self, "未设置NPK词典", "未设置NPK词典将不能设置NPK提取",
                                    QMessageBox.Yes, QMessageBox.Yes)
                npkNo.setChecked(True)
                return False
            if not self.mainWin.img2Dir:
                QMessageBox.warning(self, "未设置img2目录", "未设置img2目录将不能设置NPK提取",
                                    QMessageBox.Yes, QMessageBox.Yes)
                npkNo.setChecked(True)
                return False

        npkYes.clicked.connect(npkYesFunc)

        def yes():
            self.mainWin.npkMode = True

        npkYes.toggled.connect(yes)

        def no():
            self.mainWin.npkMode = False

        npkNo.toggled.connect(no)
        self.npkModeGroup.setObjectName("npkExtractMode")
        self.npkModeGroup.addButton(npkYes)
        self.npkModeGroup.addButton(npkNo)
Пример #20
0
    def __init__(self, recipe_model, parent=None):
        QDialog.__init__(self, parent)
        self.commit_on_change = True
        self.previous_urn = None

        self.setWindowIcon(QIcon(I('scheduler.png')))
        self.setWindowTitle(_("Schedule news download"))
        self.l = l = QGridLayout(self)

        # Left panel
        self.h = h = QHBoxLayout()
        l.addLayout(h, 0, 0, 1, 1)
        self.search = s = SearchBox2(self)
        self.search.initialize('scheduler_search_history')
        self.search.setMinimumContentsLength(15)
        self.go_button = b = QToolButton(self)
        b.setText(_("Go"))
        b.clicked.connect(self.search.do_search)
        self.clear_search_button = cb = QToolButton(self)
        self.clear_search_button.clicked.connect(self.search.clear_clicked)
        cb.setIcon(QIcon(I('clear_left.png')))
        h.addWidget(s), h.addWidget(b), h.addWidget(cb)
        self.recipes = RecipesView(self)
        l.addWidget(self.recipes, 1, 0, 1, 1)
        self.recipe_model = recipe_model
        self.recipe_model.do_refresh()
        self.recipes.setModel(self.recipe_model)
        self.recipes.setFocus(Qt.OtherFocusReason)
        self.count_label = la = QLabel(_('%s news sources') % self.recipe_model.showing_count)
        la.setAlignment(Qt.AlignCenter)
        l.addWidget(la, 2, 0, 1, 1)
        self.search.search.connect(self.recipe_model.search)
        self.recipe_model.searched.connect(self.search.search_done, type=Qt.QueuedConnection)
        self.recipe_model.searched.connect(self.search_done)

        # Right Panel
        self.scroll_area = sa = QScrollArea(self)
        self.l.addWidget(sa, 0, 1, 2, 1)
        sa.setFrameShape(QFrame.NoFrame)
        sa.setWidgetResizable(True)
        self.scroll_area_contents = sac = QWidget(self)
        sa.setWidget(sac)
        sac.v = v = QVBoxLayout(sac)
        v.setContentsMargins(0, 0, 0, 0)
        self.detail_box = QTabWidget(self)
        self.detail_box.setVisible(False)
        self.detail_box.setCurrentIndex(0)
        v.addWidget(self.detail_box)
        v.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))

        # First Tab (scheduling)
        self.tab = QWidget()
        self.detail_box.addTab(self.tab, _("&Schedule"))
        self.tab.v = vt = QVBoxLayout(self.tab)
        vt.setContentsMargins(0, 0, 0, 0)
        self.blurb = la = QLabel('blurb')
        la.setWordWrap(True), la.setOpenExternalLinks(True)
        vt.addWidget(la)
        vt.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
        self.frame = f = QFrame(self.tab)
        vt.addWidget(f)
        f.setFrameShape(f.StyledPanel)
        f.setFrameShadow(f.Raised)
        f.v = vf = QVBoxLayout(f)
        self.schedule = s = QCheckBox(_("&Schedule for download:"), f)
        self.schedule.stateChanged[int].connect(self.toggle_schedule_info)
        vf.addWidget(s)
        f.h = h = QHBoxLayout()
        vf.addLayout(h)
        self.days_of_week = QRadioButton(_("&Days of  week"), f)
        self.days_of_month = QRadioButton(_("Da&ys of month"), f)
        self.every_x_days = QRadioButton(_("Every &x days"), f)
        self.days_of_week.setChecked(True)
        h.addWidget(self.days_of_week), h.addWidget(self.days_of_month), h.addWidget(self.every_x_days)
        self.schedule_stack = ss = QStackedWidget(f)
        self.schedule_widgets = []
        for key in reversed(self.SCHEDULE_TYPES):
            self.schedule_widgets.insert(0, self.SCHEDULE_TYPES[key](self))
            self.schedule_stack.insertWidget(0, self.schedule_widgets[0])
        vf.addWidget(ss)
        self.last_downloaded = la = QLabel(f)
        la.setWordWrap(True)
        vf.addWidget(la)
        vt.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
        self.account = acc = QGroupBox(self.tab)
        acc.setTitle(_("&Account"))
        vt.addWidget(acc)
        acc.g = g = QGridLayout(acc)
        acc.unla = la = QLabel(_("&Username:"******"&Password:"******"&Show password"), self.account)
        spw.stateChanged[int].connect(self.set_pw_echo_mode)
        g.addWidget(spw, 2, 0, 1, 2)
        self.rla = la = QLabel(_("For the scheduling to work, you must leave calibre running."))
        vt.addWidget(la)
        for b, c in self.SCHEDULE_TYPES.iteritems():
            b = getattr(self, b)
            b.toggled.connect(self.schedule_type_selected)
            b.setToolTip(textwrap.dedent(c.HELP))

        # Second tab (advanced settings)
        self.tab2 = t2 = QWidget()
        self.detail_box.addTab(self.tab2, _("&Advanced"))
        self.tab2.g = g = QGridLayout(t2)
        g.setContentsMargins(0, 0, 0, 0)
        self.add_title_tag = tt = QCheckBox(_("Add &title as tag"), t2)
        g.addWidget(tt, 0, 0, 1, 2)
        t2.la = la = QLabel(_("&Extra tags:"))
        self.custom_tags = ct = QLineEdit(self)
        la.setBuddy(ct)
        g.addWidget(la), g.addWidget(ct, 1, 1)
        t2.la2 = la = QLabel(_("&Keep at most:"))
        la.setToolTip(_("Maximum number of copies (issues) of this recipe to keep.  Set to 0 to keep all (disable)."))
        self.keep_issues = ki = QSpinBox(t2)
        tt.toggled['bool'].connect(self.keep_issues.setEnabled)
        ki.setMaximum(100000), la.setBuddy(ki)
        ki.setToolTip(_(
            "<p>When set, this option will cause calibre to keep, at most, the specified number of issues"
            " of this periodical. Every time a new issue is downloaded, the oldest one is deleted, if the"
            " total is larger than this number.\n<p>Note that this feature only works if you have the"
            " option to add the title as tag checked, above.\n<p>Also, the setting for deleting periodicals"
            " older than a number of days, below, takes priority over this setting."))
        ki.setSpecialValueText(_("all issues")), ki.setSuffix(_(" issues"))
        g.addWidget(la), g.addWidget(ki, 2, 1)
        si = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
        g.addItem(si, 3, 1, 1, 1)

        # Bottom area
        self.hb = h = QHBoxLayout()
        self.l.addLayout(h, 2, 1, 1, 1)
        self.labt = la = QLabel(_("Delete downloaded &news older than:"))
        self.old_news = on = QSpinBox(self)
        on.setToolTip(_(
            "<p>Delete downloaded news older than the specified number of days. Set to zero to disable.\n"
            "<p>You can also control the maximum number of issues of a specific periodical that are kept"
            " by clicking the Advanced tab for that periodical above."))
        on.setSpecialValueText(_("never delete")), on.setSuffix(_(" days"))
        on.setMaximum(1000), la.setBuddy(on)
        on.setValue(gconf['oldest_news'])
        h.addWidget(la), h.addWidget(on)
        self.download_all_button = b = QPushButton(QIcon(I('news.png')), _("Download &all scheduled"), self)
        b.setToolTip(_("Download all scheduled news sources at once"))
        b.clicked.connect(self.download_all_clicked)
        self.l.addWidget(b, 3, 0, 1, 1)
        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Save, self)
        bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
        self.download_button = b = bb.addButton(_('&Download now'), bb.ActionRole)
        b.setIcon(QIcon(I('arrow-down.png'))), b.setVisible(False)
        b.clicked.connect(self.download_clicked)
        self.l.addWidget(bb, 3, 1, 1, 1)

        geom = gprefs.get('scheduler_dialog_geometry')
        if geom is not None:
            self.restoreGeometry(geom)
Пример #21
0
    def setup_ui(self):
        self.setWindowIcon(QIcon(I('diff.png')))
        self.stacks = st = QStackedLayout(self)
        self.busy = BusyWidget(self)
        self.w = QWidget(self)
        st.addWidget(self.busy), st.addWidget(self.w)

        self.setLayout(st)
        self.l = l = QGridLayout()
        self.w.setLayout(l)

        self.view = v = DiffView(self,
                                 show_open_in_editor=self.show_open_in_editor)
        l.addWidget(v, l.rowCount(), 0, 1, -1)

        r = l.rowCount()
        self.bp = b = QToolButton(self)
        b.setIcon(QIcon(I('back.png')))
        b.clicked.connect(partial(self.view.next_change, -1))
        b.setToolTip(_('Go to previous change') + ' [p]')
        b.setText(_('&Previous change')), b.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        l.addWidget(b, r, 0)

        self.bn = b = QToolButton(self)
        b.setIcon(QIcon(I('forward.png')))
        b.clicked.connect(partial(self.view.next_change, 1))
        b.setToolTip(_('Go to next change') + ' [n]')
        b.setText(_('&Next change')), b.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        l.addWidget(b, r, 1)

        self.search = s = HistoryLineEdit2(self)
        s.initialize('diff_search_history')
        l.addWidget(s, r, 2)
        s.setPlaceholderText(_('Search for text'))
        s.returnPressed.connect(partial(self.do_search, False))
        self.sbn = b = QToolButton(self)
        b.setIcon(QIcon(I('arrow-down.png')))
        b.clicked.connect(partial(self.do_search, False))
        b.setToolTip(_('Find next match'))
        b.setText(_('Next &match')), b.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        l.addWidget(b, r, 3)
        self.sbp = b = QToolButton(self)
        b.setIcon(QIcon(I('arrow-up.png')))
        b.clicked.connect(partial(self.do_search, True))
        b.setToolTip(_('Find previous match'))
        b.setText(_('P&revious match')), b.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        l.addWidget(b, r, 4)
        self.lb = b = QRadioButton(_('Left panel'), self)
        b.setToolTip(_('Perform search in the left panel'))
        l.addWidget(b, r, 5)
        self.rb = b = QRadioButton(_('Right panel'), self)
        b.setToolTip(_('Perform search in the right panel'))
        l.addWidget(b, r, 6)
        b.setChecked(True)
        self.pb = b = QToolButton(self)
        b.setIcon(QIcon(I('config.png')))
        b.setText(_('&Options')), b.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)
        b.setToolTip(_('Change how the differences are displayed'))
        b.setPopupMode(b.InstantPopup)
        m = QMenu(b)
        b.setMenu(m)
        cm = self.cm = QMenu(_('Lines of context around each change'))
        for i in (3, 5, 10, 50):
            cm.addAction(
                _('Show %d lines of context') % i,
                partial(self.change_context, i))
        cm.addAction(_('Show all text'), partial(self.change_context, None))
        self.beautify_action = m.addAction('', self.toggle_beautify)
        self.set_beautify_action_text()
        m.addMenu(cm)
        l.addWidget(b, r, 7)

        self.hl = QHBoxLayout()
        l.addLayout(self.hl, l.rowCount(), 0, 1, -1)
        self.names = QLabel('')
        self.hl.addWidget(self.names, r)

        self.bb.setStandardButtons(self.bb.Close)
        if self.revert_button_msg is not None:
            self.rvb = b = self.bb.addButton(self.revert_button_msg,
                                             self.bb.ActionRole)
            b.setIcon(QIcon(I('edit-undo.png'))), b.setAutoDefault(False)
            b.clicked.connect(self.revert_requested)
            b.clicked.connect(self.reject)
        self.bb.button(self.bb.Close).setDefault(True)
        self.hl.addWidget(self.bb, r)

        self.view.setFocus(Qt.OtherFocusReason)
Пример #22
0
class LLT_MC(QMainWindow):
    def __init__(self, dicTitle, dicList):
        super(LLT_MC, self).__init__()
        self.w = QWidget()
        self.setCentralWidget(self.w)

        self.title = dicTitle
        self.wordList = dicList

        self.setWindowTitle("Multiple Choice")
        self.setGeometry(0, 0, 300, 400)

        self.currentWordS = random.sample(self.wordList, 3)
        self.currentQWord = self.currentWordS[0][0]
        self.currentAWord = self.currentWordS[0][1]

        self.topLabel = QLabel("Multiple Choice: " + str(dicTitle))
        self.wordLabel = QLabel()
        self.wordLabel.setFont(QFont('Times New Roman', 16))
        self.wordLabel.setAlignment(Qt.AlignCenter)
        self.resultLabel = QLabel()
        self.resultLabel.setAlignment(Qt.AlignCenter)

        self.aRad = QRadioButton()
        self.bRad = QRadioButton()
        self.cRad = QRadioButton()
        self.group = QButtonGroup()
        self.group.addButton(self.aRad)
        self.group.addButton(self.bRad)
        self.group.addButton(self.cRad)

        self.checkBut = QPushButton("Check")
        self.checkBut.setMinimumWidth(100)
        self.checkBut.setMinimumHeight(70)
        self.checkBut.clicked.connect(self.check)
        self.nextBut = QPushButton("Next Word")
        self.nextBut.setMinimumWidth(100)
        self.nextBut.setMinimumHeight(70)
        self.nextBut.clicked.connect(self.next)
        self.exitBut = QPushButton("Exit")
        self.exitBut.setMinimumWidth(130)
        self.exitBut.setMinimumHeight(70)
        self.exitBut.clicked.connect(self.exit)

        self.hbox = QHBoxLayout()
        self.hbox.addWidget(self.checkBut)
        self.hbox.addWidget(self.nextBut)
        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.topLabel)
        self.vbox.addWidget(self.wordLabel)
        self.vbox.addWidget(self.aRad)
        self.vbox.addWidget(self.bRad)
        self.vbox.addWidget(self.cRad)
        self.vbox.addWidget(self.resultLabel)
        self.vbox.addLayout(self.hbox)
        self.vbox.addWidget(self.exitBut)

        self.w.setLayout(self.vbox)
        self.setWord()

    #define methods

    def setWord(self):
        newText = []
        for item in self.currentWordS:
            newText.append(item[1])

        random.shuffle(newText)

        self.group.setExclusive(False)
        self.aRad.setText(newText[0])
        self.bRad.setText(newText[1])
        self.cRad.setText(newText[2])
        self.wordLabel.setText(self.currentQWord)
        self.group.setExclusive(True)

    def check(self):
        if self.aRad.isChecked() and self.aRad.text() == self.currentAWord:
            self.resultLabel.setText("CORRECT")
        elif self.aRad.isChecked() and self.aRad.text() != self.currentAWord:
            self.resultLabel.setText("Try again")
        if self.bRad.isChecked() and self.bRad.text() == self.currentAWord:
            self.resultLabel.setText("CORRECT")
        elif self.bRad.isChecked() and self.bRad.text() != self.currentAWord:
            self.resultLabel.setText("Try again")
        if self.cRad.isChecked() and self.cRad.text() == self.currentAWord:
            self.resultLabel.setText("CORRECT")
        elif self.cRad.isChecked() and self.cRad.text() != self.currentAWord:
            self.resultLabel.setText("Try again")

    def next(self):
        self.currentWordS = random.sample(self.wordList, 3)
        self.currentQWord = self.currentWordS[0][0]
        self.currentAWord = self.currentWordS[0][1]

        self.wordLabel.setText(self.currentQWord)
        self.resultLabel.setText('')

        self.group.setExclusive(False)
        self.aRad.setChecked(False)
        self.bRad.setChecked(False)
        self.cRad.setChecked(False)
        self.group.setExclusive(True)

        newText = []
        for item in self.currentWordS:
            newText.append(item[1])
        random.shuffle(newText)
        self.aRad.setText(newText[0])
        self.bRad.setText(newText[1])
        self.cRad.setText(newText[2])

    def exit(self):
        confirm = QMessageBox.question(self.w, 'Quit',
                                       'Are you sure you want to exit?',
                                       QMessageBox.Yes | QMessageBox.No)
        if confirm == QMessageBox.Yes:
            self.close()
        else:
            pass
Пример #23
0
class Editor(QFrame):  # {{{

    editing_done = pyqtSignal(object)

    def __init__(self, parent=None):
        QFrame.__init__(self, parent)
        self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
        self.setAutoFillBackground(True)
        self.capture = 0

        self.setFrameShape(self.StyledPanel)
        self.setFrameShadow(self.Raised)
        self._layout = l = QGridLayout(self)
        self.setLayout(l)

        self.header = QLabel('')
        l.addWidget(self.header, 0, 0, 1, 2)

        self.use_default = QRadioButton('')
        self.use_custom = QRadioButton(_('&Custom'))
        l.addWidget(self.use_default, 1, 0, 1, 3)
        l.addWidget(self.use_custom, 2, 0, 1, 3)
        self.use_custom.toggled.connect(self.custom_toggled)

        off = 2
        for which in (1, 2):
            text = _('&Shortcut:') if which == 1 else _('&Alternate shortcut:')
            la = QLabel(text)
            la.setStyleSheet('QLabel { margin-left: 1.5em }')
            l.addWidget(la, off + which, 0, 1, 3)
            setattr(self, 'label%d' % which, la)
            button = QPushButton(_('None'), self)
            button.clicked.connect(partial(self.capture_clicked, which=which))
            button.installEventFilter(self)
            setattr(self, 'button%d' % which, button)
            clear = QToolButton(self)
            clear.setIcon(QIcon(I('clear_left.png')))
            clear.clicked.connect(partial(self.clear_clicked, which=which))
            setattr(self, 'clear%d' % which, clear)
            l.addWidget(button, off + which, 1, 1, 1)
            l.addWidget(clear, off + which, 2, 1, 1)
            la.setBuddy(button)

        self.done_button = doneb = QPushButton(_('Done'), self)
        l.addWidget(doneb, 0, 2, 1, 1)
        doneb.clicked.connect(lambda: self.editing_done.emit(self))
        l.setColumnStretch(0, 100)

        self.custom_toggled(False)

    def initialize(self, shortcut, all_shortcuts):
        self.header.setText('<b>%s: %s</b>' %
                            (_('Customize'), shortcut['name']))
        self.all_shortcuts = all_shortcuts
        self.shortcut = shortcut

        self.default_keys = [
            QKeySequence(k, QKeySequence.SequenceFormat.PortableText)
            for k in shortcut['default_keys']
        ]
        self.current_keys = list(shortcut['keys'])
        default = ', '.join([
            unicode_type(k.toString(k.NativeText)) for k in self.default_keys
        ])
        if not default:
            default = _('None')
        current = ', '.join([
            unicode_type(k.toString(k.NativeText)) for k in self.current_keys
        ])
        if not current:
            current = _('None')

        self.use_default.setText(
            _('&Default: %(deflt)s [Currently not conflicting: %(curr)s]') %
            dict(deflt=default, curr=current))

        if shortcut['set_to_default']:
            self.use_default.setChecked(True)
        else:
            self.use_custom.setChecked(True)
            for key, which in zip(self.current_keys, [1, 2]):
                button = getattr(self, 'button%d' % which)
                button.setText(key.toString(key.NativeText))

    def custom_toggled(self, checked):
        for w in ('1', '2'):
            for o in ('label', 'button', 'clear'):
                getattr(self, o + w).setEnabled(checked)

    def capture_clicked(self, which=1):
        self.capture = which
        button = getattr(self, 'button%d' % which)
        button.setText(_('Press a key...'))
        button.setFocus(Qt.FocusReason.OtherFocusReason)
        button.setStyleSheet('QPushButton { font-weight: bold}')

    def clear_clicked(self, which=0):
        button = getattr(self, 'button%d' % which)
        button.setText(_('None'))

    def eventFilter(self, obj, event):
        if self.capture and obj in (self.button1, self.button2):
            t = event.type()
            if t == QEvent.Type.ShortcutOverride:
                event.accept()
                return True
            if t == QEvent.Type.KeyPress:
                self.key_press_event(event, 1 if obj is self.button1 else 2)
                return True
        return QFrame.eventFilter(self, obj, event)

    def key_press_event(self, ev, which=0):
        if self.capture == 0:
            return QWidget.keyPressEvent(self, ev)
        sequence = keysequence_from_event(ev)
        if sequence is None:
            return QWidget.keyPressEvent(self, ev)
        ev.accept()

        button = getattr(self, 'button%d' % which)
        button.setStyleSheet('QPushButton { font-weight: normal}')
        button.setText(
            sequence.toString(QKeySequence.SequenceFormat.NativeText))
        self.capture = 0
        dup_desc = self.dup_check(sequence)
        if dup_desc is not None:
            error_dialog(self,
                         _('Already assigned'),
                         unicode_type(
                             sequence.toString(
                                 QKeySequence.SequenceFormat.NativeText)) +
                         ' ' + _('already assigned to') + ' ' + dup_desc,
                         show=True)
            self.clear_clicked(which=which)

    def dup_check(self, sequence):
        for sc in self.all_shortcuts:
            if sc is self.shortcut:
                continue
            for k in sc['keys']:
                if k == sequence:
                    return sc['name']

    @property
    def custom_keys(self):
        if self.use_default.isChecked():
            return None
        ans = []
        for which in (1, 2):
            button = getattr(self, 'button%d' % which)
            t = unicode_type(button.text())
            if t == _('None'):
                continue
            ks = QKeySequence(t, QKeySequence.SequenceFormat.NativeText)
            if not ks.isEmpty():
                ans.append(ks)
        return tuple(ans)
Пример #24
0
class SchedulerDialog(QDialog):

    SCHEDULE_TYPES = OrderedDict([
            ('days_of_week', DaysOfWeek),
            ('days_of_month', DaysOfMonth),
            ('every_x_days', EveryXDays),
    ])

    download = pyqtSignal(object)

    def __init__(self, recipe_model, parent=None):
        QDialog.__init__(self, parent)
        self.commit_on_change = True
        self.previous_urn = None

        self.setWindowIcon(QIcon(I('scheduler.png')))
        self.setWindowTitle(_("Schedule news download"))
        self.l = l = QGridLayout(self)

        # Left panel
        self.h = h = QHBoxLayout()
        l.addLayout(h, 0, 0, 1, 1)
        self.search = s = SearchBox2(self)
        self.search.initialize('scheduler_search_history')
        self.search.setMinimumContentsLength(15)
        self.go_button = b = QToolButton(self)
        b.setText(_("Go"))
        b.clicked.connect(self.search.do_search)
        self.clear_search_button = cb = QToolButton(self)
        self.clear_search_button.clicked.connect(self.search.clear_clicked)
        cb.setIcon(QIcon(I('clear_left.png')))
        h.addWidget(s), h.addWidget(b), h.addWidget(cb)
        self.recipes = RecipesView(self)
        l.addWidget(self.recipes, 1, 0, 1, 1)
        self.recipe_model = recipe_model
        self.recipe_model.do_refresh()
        self.recipes.setModel(self.recipe_model)
        self.recipes.setFocus(Qt.OtherFocusReason)
        self.count_label = la = QLabel(_('%s news sources') % self.recipe_model.showing_count)
        la.setAlignment(Qt.AlignCenter)
        l.addWidget(la, 2, 0, 1, 1)
        self.search.search.connect(self.recipe_model.search)
        self.recipe_model.searched.connect(self.search.search_done, type=Qt.QueuedConnection)
        self.recipe_model.searched.connect(self.search_done)

        # Right Panel
        self.scroll_area = sa = QScrollArea(self)
        self.l.addWidget(sa, 0, 1, 2, 1)
        sa.setFrameShape(QFrame.NoFrame)
        sa.setWidgetResizable(True)
        self.scroll_area_contents = sac = QWidget(self)
        sa.setWidget(sac)
        sac.v = v = QVBoxLayout(sac)
        v.setContentsMargins(0, 0, 0, 0)
        self.detail_box = QTabWidget(self)
        self.detail_box.setVisible(False)
        self.detail_box.setCurrentIndex(0)
        v.addWidget(self.detail_box)
        v.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))

        # First Tab (scheduling)
        self.tab = QWidget()
        self.detail_box.addTab(self.tab, _("&Schedule"))
        self.tab.v = vt = QVBoxLayout(self.tab)
        vt.setContentsMargins(0, 0, 0, 0)
        self.blurb = la = QLabel('blurb')
        la.setWordWrap(True), la.setOpenExternalLinks(True)
        vt.addWidget(la)
        vt.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
        self.frame = f = QFrame(self.tab)
        vt.addWidget(f)
        f.setFrameShape(f.StyledPanel)
        f.setFrameShadow(f.Raised)
        f.v = vf = QVBoxLayout(f)
        self.schedule = s = QCheckBox(_("&Schedule for download:"), f)
        self.schedule.stateChanged[int].connect(self.toggle_schedule_info)
        vf.addWidget(s)
        f.h = h = QHBoxLayout()
        vf.addLayout(h)
        self.days_of_week = QRadioButton(_("&Days of  week"), f)
        self.days_of_month = QRadioButton(_("Da&ys of month"), f)
        self.every_x_days = QRadioButton(_("Every &x days"), f)
        self.days_of_week.setChecked(True)
        h.addWidget(self.days_of_week), h.addWidget(self.days_of_month), h.addWidget(self.every_x_days)
        self.schedule_stack = ss = QStackedWidget(f)
        self.schedule_widgets = []
        for key in reversed(self.SCHEDULE_TYPES):
            self.schedule_widgets.insert(0, self.SCHEDULE_TYPES[key](self))
            self.schedule_stack.insertWidget(0, self.schedule_widgets[0])
        vf.addWidget(ss)
        self.last_downloaded = la = QLabel(f)
        la.setWordWrap(True)
        vf.addWidget(la)
        vt.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))
        self.account = acc = QGroupBox(self.tab)
        acc.setTitle(_("&Account"))
        vt.addWidget(acc)
        acc.g = g = QGridLayout(acc)
        acc.unla = la = QLabel(_("&Username:"******"&Password:"******"&Show password"), self.account)
        spw.stateChanged[int].connect(self.set_pw_echo_mode)
        g.addWidget(spw, 2, 0, 1, 2)
        self.rla = la = QLabel(_("For the scheduling to work, you must leave calibre running."))
        vt.addWidget(la)
        for b, c in self.SCHEDULE_TYPES.iteritems():
            b = getattr(self, b)
            b.toggled.connect(self.schedule_type_selected)
            b.setToolTip(textwrap.dedent(c.HELP))

        # Second tab (advanced settings)
        self.tab2 = t2 = QWidget()
        self.detail_box.addTab(self.tab2, _("&Advanced"))
        self.tab2.g = g = QGridLayout(t2)
        g.setContentsMargins(0, 0, 0, 0)
        self.add_title_tag = tt = QCheckBox(_("Add &title as tag"), t2)
        g.addWidget(tt, 0, 0, 1, 2)
        t2.la = la = QLabel(_("&Extra tags:"))
        self.custom_tags = ct = QLineEdit(self)
        la.setBuddy(ct)
        g.addWidget(la), g.addWidget(ct, 1, 1)
        t2.la2 = la = QLabel(_("&Keep at most:"))
        la.setToolTip(_("Maximum number of copies (issues) of this recipe to keep.  Set to 0 to keep all (disable)."))
        self.keep_issues = ki = QSpinBox(t2)
        tt.toggled['bool'].connect(self.keep_issues.setEnabled)
        ki.setMaximum(100000), la.setBuddy(ki)
        ki.setToolTip(_(
            "<p>When set, this option will cause calibre to keep, at most, the specified number of issues"
            " of this periodical. Every time a new issue is downloaded, the oldest one is deleted, if the"
            " total is larger than this number.\n<p>Note that this feature only works if you have the"
            " option to add the title as tag checked, above.\n<p>Also, the setting for deleting periodicals"
            " older than a number of days, below, takes priority over this setting."))
        ki.setSpecialValueText(_("all issues")), ki.setSuffix(_(" issues"))
        g.addWidget(la), g.addWidget(ki, 2, 1)
        si = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
        g.addItem(si, 3, 1, 1, 1)

        # Bottom area
        self.hb = h = QHBoxLayout()
        self.l.addLayout(h, 2, 1, 1, 1)
        self.labt = la = QLabel(_("Delete downloaded &news older than:"))
        self.old_news = on = QSpinBox(self)
        on.setToolTip(_(
            "<p>Delete downloaded news older than the specified number of days. Set to zero to disable.\n"
            "<p>You can also control the maximum number of issues of a specific periodical that are kept"
            " by clicking the Advanced tab for that periodical above."))
        on.setSpecialValueText(_("never delete")), on.setSuffix(_(" days"))
        on.setMaximum(1000), la.setBuddy(on)
        on.setValue(gconf['oldest_news'])
        h.addWidget(la), h.addWidget(on)
        self.download_all_button = b = QPushButton(QIcon(I('news.png')), _("Download &all scheduled"), self)
        b.setToolTip(_("Download all scheduled news sources at once"))
        b.clicked.connect(self.download_all_clicked)
        self.l.addWidget(b, 3, 0, 1, 1)
        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Save, self)
        bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
        self.download_button = b = bb.addButton(_('&Download now'), bb.ActionRole)
        b.setIcon(QIcon(I('arrow-down.png'))), b.setVisible(False)
        b.clicked.connect(self.download_clicked)
        self.l.addWidget(bb, 3, 1, 1, 1)

        geom = gprefs.get('scheduler_dialog_geometry')
        if geom is not None:
            self.restoreGeometry(geom)

    def sizeHint(self):
        return QSize(800, 600)

    def set_pw_echo_mode(self, state):
        self.password.setEchoMode(self.password.Normal
                if state == Qt.Checked else self.password.Password)

    def schedule_type_selected(self, *args):
        for i, st in enumerate(self.SCHEDULE_TYPES):
            if getattr(self, st).isChecked():
                self.schedule_stack.setCurrentIndex(i)
                break

    def keyPressEvent(self, ev):
        if ev.key() not in (Qt.Key_Enter, Qt.Key_Return):
            return QDialog.keyPressEvent(self, ev)

    def break_cycles(self):
        try:
            self.recipe_model.searched.disconnect(self.search_done)
            self.recipe_model.searched.disconnect(self.search.search_done)
            self.search.search.disconnect()
            self.download.disconnect()
        except:
            pass
        self.recipe_model = None

    def search_done(self, *args):
        if self.recipe_model.showing_count < 10:
            self.recipes.expandAll()

    def toggle_schedule_info(self, *args):
        enabled = self.schedule.isChecked()
        for x in self.SCHEDULE_TYPES:
            getattr(self, x).setEnabled(enabled)
        self.schedule_stack.setEnabled(enabled)
        self.last_downloaded.setVisible(enabled)

    def current_changed(self, current, previous):
        if self.previous_urn is not None:
            self.commit(urn=self.previous_urn)
            self.previous_urn = None

        urn = self.current_urn
        if urn is not None:
            self.initialize_detail_box(urn)
        self.recipes.scrollTo(current)

    def accept(self):
        if not self.commit():
            return False
        self.save_geometry()
        return QDialog.accept(self)

    def reject(self):
        self.save_geometry()
        return QDialog.reject(self)

    def save_geometry(self):
        gprefs.set('scheduler_dialog_geometry', bytearray(self.saveGeometry()))

    def download_clicked(self, *args):
        self.commit()
        if self.commit() and self.current_urn:
            self.download.emit(self.current_urn)

    def download_all_clicked(self, *args):
        if self.commit() and self.commit():
            self.download.emit(None)

    @property
    def current_urn(self):
        current = self.recipes.currentIndex()
        if current.isValid():
            return getattr(current.internalPointer(), 'urn', None)

    def commit(self, urn=None):
        urn = self.current_urn if urn is None else urn
        if not self.detail_box.isVisible() or urn is None:
            return True

        if self.account.isVisible():
            un, pw = map(unicode, (self.username.text(), self.password.text()))
            un, pw = un.strip(), pw.strip()
            if not un and not pw and self.schedule.isChecked():
                if not getattr(self, 'subscription_optional', False):
                    error_dialog(self, _('Need username and password'),
                            _('You must provide a username and/or password to '
                                'use this news source.'), show=True)
                    return False
            if un or pw:
                self.recipe_model.set_account_info(urn, un, pw)
            else:
                self.recipe_model.clear_account_info(urn)

        if self.schedule.isChecked():
            schedule_type, schedule = \
                    self.schedule_stack.currentWidget().schedule
            self.recipe_model.schedule_recipe(urn, schedule_type, schedule)
        else:
            self.recipe_model.un_schedule_recipe(urn)

        add_title_tag = self.add_title_tag.isChecked()
        keep_issues = u'0'
        if self.keep_issues.isEnabled():
            keep_issues = unicode(self.keep_issues.value())
        custom_tags = unicode(self.custom_tags.text()).strip()
        custom_tags = [x.strip() for x in custom_tags.split(',')]
        self.recipe_model.customize_recipe(urn, add_title_tag, custom_tags, keep_issues)
        return True

    def initialize_detail_box(self, urn):
        self.previous_urn = urn
        self.detail_box.setVisible(True)
        self.download_button.setVisible(True)
        self.detail_box.setCurrentIndex(0)
        recipe = self.recipe_model.recipe_from_urn(urn)
        try:
            schedule_info = self.recipe_model.schedule_info_from_urn(urn)
        except:
            # Happens if user does something stupid like unchecking all the
            # days of the week
            schedule_info = None
        account_info = self.recipe_model.account_info_from_urn(urn)
        customize_info = self.recipe_model.get_customize_info(urn)

        ns = recipe.get('needs_subscription', '')
        self.account.setVisible(ns in ('yes', 'optional'))
        self.subscription_optional = ns == 'optional'
        act = _('Account')
        act2 = _('(optional)') if self.subscription_optional else \
                _('(required)')
        self.account.setTitle(act+' '+act2)
        un = pw = ''
        if account_info is not None:
            un, pw = account_info[:2]
            if not un:
                un = ''
            if not pw:
                pw = ''
        self.username.setText(un)
        self.password.setText(pw)
        self.show_password.setChecked(False)

        self.blurb.setText('''
        <p>
        <b>%(title)s</b><br>
        %(cb)s %(author)s<br/>
        %(description)s
        </p>
        '''%dict(title=recipe.get('title'), cb=_('Created by: '),
            author=recipe.get('author', _('Unknown')),
            description=recipe.get('description', '')))
        self.download_button.setToolTip(
                _('Download %s now')%recipe.get('title'))
        scheduled = schedule_info is not None
        self.schedule.setChecked(scheduled)
        self.toggle_schedule_info()
        self.last_downloaded.setText(_('Last downloaded: never'))
        ld_text = _('never')
        if scheduled:
            typ, sch, last_downloaded = schedule_info
            d = utcnow() - last_downloaded
            def hm(x):
                return (x-x%3600)//3600, (x%3600 - (x%3600)%60)//60
            hours, minutes = hm(d.seconds)
            tm = _('%(days)d days, %(hours)d hours'
                    ' and %(mins)d minutes ago')%dict(
                            days=d.days, hours=hours, mins=minutes)
            if d < timedelta(days=366):
                ld_text = tm
        else:
            typ, sch = 'day/time', (-1, 6, 0)
        sch_widget = {'day/time': 0, 'days_of_week': 0, 'days_of_month':1,
                'interval':2}[typ]
        rb = getattr(self, list(self.SCHEDULE_TYPES)[sch_widget])
        rb.setChecked(True)
        self.schedule_stack.setCurrentIndex(sch_widget)
        self.schedule_stack.currentWidget().initialize(typ, sch)
        add_title_tag, custom_tags, keep_issues = customize_info
        self.add_title_tag.setChecked(add_title_tag)
        self.custom_tags.setText(u', '.join(custom_tags))
        self.last_downloaded.setText(_('Last downloaded:') + ' ' + ld_text)
        try:
            keep_issues = int(keep_issues)
        except:
            keep_issues = 0
        self.keep_issues.setValue(keep_issues)
        self.keep_issues.setEnabled(self.add_title_tag.isChecked())
Пример #25
0
    def _set_middle_frame_ui(self):
        middle_frame = QFrame()
        self.middle_layout = QHBoxLayout(middle_frame)
        middle_left_frame = QFrame()
        # middle_left_frame.setMinimumWidth(self.main_ui.window.geometry().width() / 2 - 20)
        middle_right_frame = QFrame()
        # middle_right_frame.setMinimumWidth(self.main_ui.window.geometry().width() / 2 - 20)
        self.middle_left_layout = QGridLayout(middle_left_frame)
        self.middle_right_layout = QGridLayout(middle_right_frame)

        self.middle_layout.addWidget(middle_left_frame)
        self.middle_layout.addWidget(middle_right_frame)
        self.layout.addWidget(middle_frame)

        row = 0
        self.checkbox_outline = QRadioButton('OutLine')
        self.checkbox_gray = QRadioButton('Gray')
        self.checkbox_gray.hide()
        self.btn_load_img = QPushButton('LoadImage')
        self.checkbox_outline.toggle()
        self.isOutlineMode = True
        self.checkbox_outline.setDisabled(True)
        self.middle_left_layout.addWidget(self.checkbox_outline, row, 0)
        self.middle_left_layout.addWidget(self.checkbox_gray, row, 1)
        self.middle_left_layout.addWidget(self.btn_load_img, row, 2)

        row += 1
        label_x_home = QLabel('x_home:')
        self.slider_x_home = QSlider(QtCore.Qt.Horizontal)
        self.slider_x_home.setMinimum(0)
        self.slider_x_home.setMaximum(2000)
        self.slider_x_home.setValue(1500)
        self.spinbox_x_home = QDoubleSpinBox()
        self.spinbox_x_home.setDecimals(1)
        self.spinbox_x_home.setSingleStep(0.1)
        self.spinbox_x_home.setMinimum(0.0)
        self.spinbox_x_home.setMaximum(200.0)
        self.spinbox_x_home.setValue(150.0)
        self.slider_x_home.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_x_home.mouseReleaseEvent)
        self.spinbox_x_home.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_x_home.focusOutEvent)
        self.middle_left_layout.addWidget(label_x_home, row, 0)
        self.middle_left_layout.addWidget(self.slider_x_home, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_x_home, row, 2)

        row += 1
        label_y_home = QLabel('y_home:')
        self.slider_y_home = QSlider(QtCore.Qt.Horizontal)
        self.slider_y_home.setMinimum(-1500)
        self.slider_y_home.setMaximum(1500)
        self.slider_y_home.setValue(0)
        self.spinbox_y_home = QDoubleSpinBox()
        self.spinbox_y_home.setDecimals(1)
        self.spinbox_y_home.setSingleStep(0.1)
        self.spinbox_y_home.setMinimum(-150.0)
        self.spinbox_y_home.setMaximum(150.0)
        self.spinbox_y_home.setValue(0.0)
        self.slider_y_home.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_y_home.mouseReleaseEvent)
        self.spinbox_y_home.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_y_home.focusOutEvent)
        self.middle_left_layout.addWidget(label_y_home, row, 0)
        self.middle_left_layout.addWidget(self.slider_y_home, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_y_home, row, 2)

        row += 1
        label_z_home = QLabel('z_home:')
        self.slider_z_home = QSlider(QtCore.Qt.Horizontal)
        self.slider_z_home.setMinimum(0)
        self.slider_z_home.setMaximum(1500)
        self.slider_z_home.setValue(900)
        self.spinbox_z_home = QDoubleSpinBox()
        self.spinbox_z_home.setDecimals(1)
        self.spinbox_z_home.setSingleStep(0.1)
        self.spinbox_z_home.setMinimum(0.0)
        self.spinbox_z_home.setMaximum(150.0)
        self.spinbox_z_home.setValue(90.0)
        self.slider_z_home.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_z_home.mouseReleaseEvent)
        self.spinbox_z_home.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_z_home.focusOutEvent)
        self.middle_left_layout.addWidget(label_z_home, row, 0)
        self.middle_left_layout.addWidget(self.slider_z_home, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_z_home, row, 2)

        row += 1
        label_x_offset = QLabel('x_offset:')
        self.slider_x_offset = QSlider(QtCore.Qt.Horizontal)
        self.slider_x_offset.setMinimum(-5000)
        self.slider_x_offset.setMaximum(5000)
        self.slider_x_offset.setValue(0)
        self.spinbox_x_offset = QDoubleSpinBox()
        self.spinbox_x_offset.setSingleStep(0.1)
        self.spinbox_x_offset.setDecimals(1)
        self.spinbox_x_offset.setMinimum(-500.0)
        self.spinbox_x_offset.setMaximum(500.0)
        self.spinbox_x_offset.setValue(0.0)
        self.slider_x_offset.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_x_offset.mouseReleaseEvent)
        self.spinbox_x_offset.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_x_offset.focusOutEvent)
        self.middle_left_layout.addWidget(label_x_offset, row, 0)
        self.middle_left_layout.addWidget(self.slider_x_offset, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_x_offset, row, 2)

        row += 1
        label_y_offset = QLabel('y_offset:')
        self.slider_y_offset = QSlider(QtCore.Qt.Horizontal)
        self.slider_y_offset.setMinimum(-5000)
        self.slider_y_offset.setMaximum(5000)
        self.slider_y_offset.setValue(0)
        self.spinbox_y_offset = QDoubleSpinBox()
        self.spinbox_y_offset.setDecimals(1)
        self.spinbox_y_offset.setSingleStep(0.1)
        self.spinbox_y_offset.setMinimum(-500.0)
        self.spinbox_y_offset.setMaximum(500.0)
        self.spinbox_y_offset.setValue(0.0)
        self.slider_y_offset.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_y_offset.mouseReleaseEvent)
        self.spinbox_y_offset.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_y_offset.focusOutEvent)
        self.middle_left_layout.addWidget(label_y_offset, row, 0)
        self.middle_left_layout.addWidget(self.slider_y_offset, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_y_offset, row, 2)

        row += 1
        label_z_offset = QLabel('z_offset:')
        self.slider_z_offset = QSlider(QtCore.Qt.Horizontal)
        self.slider_z_offset.setMinimum(-1000)
        self.slider_z_offset.setMaximum(1500)
        self.slider_z_offset.setValue(900)
        self.spinbox_z_offset = QDoubleSpinBox()
        self.spinbox_z_offset.setDecimals(1)
        self.spinbox_z_offset.setSingleStep(0.1)
        self.spinbox_z_offset.setMinimum(-100.0)
        self.spinbox_z_offset.setMaximum(150.0)
        self.spinbox_z_offset.setValue(90.0)
        self.slider_z_offset.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_z_offset.mouseReleaseEvent)
        self.spinbox_z_offset.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_z_offset.focusOutEvent)
        self.middle_left_layout.addWidget(label_z_offset, row, 0)
        self.middle_left_layout.addWidget(self.slider_z_offset, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_z_offset, row, 2)

        row += 1
        label_pen_up = QLabel('pen_up:')
        self.slider_pen_up = QSlider(QtCore.Qt.Horizontal)
        self.slider_pen_up.setMinimum(0)
        self.slider_pen_up.setMaximum(500)
        self.slider_pen_up.setValue(200)
        self.spinbox_pen_up = QDoubleSpinBox()
        self.spinbox_pen_up.setDecimals(1)
        self.spinbox_pen_up.setSingleStep(0.1)
        self.spinbox_pen_up.setMinimum(0.0)
        self.spinbox_pen_up.setMaximum(50.0)
        self.spinbox_pen_up.setValue(20.0)
        self.slider_pen_up.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_pen_up.mouseReleaseEvent)
        self.spinbox_pen_up.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_pen_up.focusOutEvent)
        self.slider_pen_up.setDisabled(True)
        self.spinbox_pen_up.setDisabled(True)
        self.middle_left_layout.addWidget(label_pen_up, row, 0)
        self.middle_left_layout.addWidget(self.slider_pen_up, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_pen_up, row, 2)

        row = 0
        self.checkbox_laser = QRadioButton('Laser')
        self.checkbox_pen = QRadioButton('Pen')
        self.checkbox_laser.toggle()
        self.isLaserMode = True
        self.middle_right_layout.addWidget(self.checkbox_laser, row, 0)
        self.middle_right_layout.addWidget(self.checkbox_pen, row, 1)

        row += 1
        label_drawing_feedrate = QLabel('drawing_feedrate:')
        self.slider_drawing_feedrate = QSlider(QtCore.Qt.Horizontal)
        self.slider_drawing_feedrate.setMinimum(5)
        self.slider_drawing_feedrate.setMaximum(1000)
        self.slider_drawing_feedrate.setValue(100)
        self.spinbox_drawing_feedrate = QSpinBox()
        self.spinbox_drawing_feedrate.setMinimum(5)
        self.spinbox_drawing_feedrate.setMaximum(1000)
        self.spinbox_drawing_feedrate.setValue(100)
        self.slider_drawing_feedrate.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_drawing_feedrate.mouseReleaseEvent)
        self.spinbox_drawing_feedrate.focusOutEvent = functools.partial(
            self.focusOutEvent,
            source=self.spinbox_drawing_feedrate.focusOutEvent)
        self.middle_right_layout.addWidget(label_drawing_feedrate, row, 0)
        self.middle_right_layout.addWidget(self.slider_drawing_feedrate, row,
                                           1)
        self.middle_right_layout.addWidget(self.spinbox_drawing_feedrate, row,
                                           2)

        row += 1
        label_moving_feedrate = QLabel('moving_feedrate:')
        self.slider_moving_feedrate = QSlider(QtCore.Qt.Horizontal)
        self.slider_moving_feedrate.setMinimum(5)
        self.slider_moving_feedrate.setMaximum(20000)
        self.slider_moving_feedrate.setValue(100)
        self.spinbox_moving_feedrate = QSpinBox()
        self.spinbox_moving_feedrate.setMinimum(5)
        self.spinbox_moving_feedrate.setMaximum(20000)
        self.spinbox_moving_feedrate.setValue(100)
        self.slider_moving_feedrate.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_moving_feedrate.mouseReleaseEvent)
        self.spinbox_moving_feedrate.focusOutEvent = functools.partial(
            self.focusOutEvent,
            source=self.spinbox_moving_feedrate.focusOutEvent)
        self.middle_right_layout.addWidget(label_moving_feedrate, row, 0)
        self.middle_right_layout.addWidget(self.slider_moving_feedrate, row, 1)
        self.middle_right_layout.addWidget(self.spinbox_moving_feedrate, row,
                                           2)

        row += 1
        label_scale = QLabel('scale:')
        self.slider_scale = QSlider(QtCore.Qt.Horizontal)
        self.slider_scale.setMinimum(1)
        self.slider_scale.setMaximum(100)
        self.slider_scale.setValue(10)
        self.spinbox_scale = QDoubleSpinBox()
        self.spinbox_scale.setDecimals(1)
        self.spinbox_scale.setSingleStep(0.1)
        self.spinbox_scale.setMinimum(0.1)
        self.spinbox_scale.setMaximum(10.0)
        self.spinbox_scale.setValue(1.0)
        # self.slider_scale.setDisabled(True)
        # self.spinbox_scale.setDisabled(True)
        self.slider_scale.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent, source=self.slider_scale.mouseReleaseEvent)
        self.spinbox_scale.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_scale.focusOutEvent)

        self.middle_right_layout.addWidget(label_scale, row, 0)
        self.middle_right_layout.addWidget(self.slider_scale, row, 1)
        self.middle_right_layout.addWidget(self.spinbox_scale, row, 2)

        row += 1
        label_resolution = QLabel('resolution:')
        self.slider_resolution = QSlider(QtCore.Qt.Horizontal)
        self.slider_resolution.setMinimum(1)
        self.slider_resolution.setMaximum(100)
        self.slider_resolution.setValue(10)
        self.spinbox_resolution = QDoubleSpinBox()
        self.spinbox_resolution.setMinimum(0.1)
        self.spinbox_resolution.setMaximum(10.0)
        self.spinbox_resolution.setSingleStep(0.1)
        self.spinbox_resolution.setDecimals(1)
        self.spinbox_resolution.setValue(1.0)
        self.slider_resolution.setDisabled(True)
        self.spinbox_resolution.setDisabled(True)
        self.middle_right_layout.addWidget(label_resolution, row, 0)
        self.middle_right_layout.addWidget(self.slider_resolution, row, 1)
        self.middle_right_layout.addWidget(self.spinbox_resolution, row, 2)

        row += 1
        self.btn_generate_gcode = QPushButton('Generate_Gcode')
        self.middle_right_layout.addWidget(self.btn_generate_gcode, row, 0)

        row += 1
        self.label_x_min = QLabel('')
        self.label_x_max = QLabel('')
        self.middle_right_layout.addWidget(self.label_x_min, row, 0)
        self.middle_right_layout.addWidget(self.label_x_max, row, 1)

        row += 1
        self.label_y_min = QLabel('')
        self.label_y_max = QLabel('')
        self.middle_right_layout.addWidget(self.label_y_min, row, 0)
        self.middle_right_layout.addWidget(self.label_y_max, row, 1)
Пример #26
0
class ConversionDialog(Dialog):
    def __init__(self, parent, force_entire_book=False):
        self.prefs = self.prefsPrep()
        self.parent = parent
        self.force_entire_book = force_entire_book
        self.criteria = None
        Dialog.__init__(self, _('Chinese Conversion'), 'chinese_conversion_dialog', parent)

    def setup_ui(self):

        # Create layout for entire dialog
        layout = QVBoxLayout(self)
        self.setLayout(layout)

        #Create a scroll area for the top part of the dialog
        self.scrollArea = QScrollArea(self)
        self.scrollArea.setWidgetResizable(True)

        # Create widget for all the contents of the dialog except the OK and Cancel buttons
        self.scrollContentWidget = QWidget(self.scrollArea)
        self.scrollArea.setWidget(self.scrollContentWidget)
        widgetLayout = QVBoxLayout(self.scrollContentWidget)

        # Add scrollArea to dialog
        layout.addWidget(self.scrollArea)

        self.other_group_box = QGroupBox(_('Other Changes'))
        widgetLayout.addWidget(self.other_group_box)
        other_group_box_layout = QVBoxLayout()
        self.other_group_box.setLayout(other_group_box_layout)

        text_dir_layout = QHBoxLayout()
        other_group_box_layout.addLayout(text_dir_layout)
        direction_label = QLabel(_('Text Direction:'))
        text_dir_layout.addWidget(direction_label)
        self.text_dir_combo = QComboBox()
        text_dir_layout.addWidget(self.text_dir_combo)
        self.text_dir_combo.addItems([_('No Conversion'), _('Horizontal'), _('Vertical')])
        self.text_dir_combo.setToolTip(_('Select the desired text orientation'))
        self.text_dir_combo.currentIndexChanged.connect(self.update_gui)


        self.optimization_group_box = QGroupBox(_('Reader Device Optimization'))
        other_group_box_layout.addWidget(self.optimization_group_box)
        optimization_group_box_layout = QVBoxLayout()
        self.optimization_group_box.setLayout(optimization_group_box_layout)
        
        punc_group=QButtonGroup(self)
        self.text_dir_punc_none_button = QRadioButton("""No presentation optimization""")
        optimization_group_box_layout.addWidget(self.text_dir_punc_none_button)
        self.text_dir_punc_button = QRadioButton("""Optimize presentation for Readium reader""")
        self.text_dir_punc_button.setToolTip(_('Use vert/horiz punctuation presentation forms for Chrome Readium Epub3 reader'))
        optimization_group_box_layout.addWidget(self.text_dir_punc_button)
        self.text_dir_punc_kindle_button = QRadioButton("""Optimize presentation for Kindle reader""")
        self.text_dir_punc_kindle_button.setToolTip(_('Use vert/horiz puncuation presentation forms for Kindle reader'))
        optimization_group_box_layout.addWidget(self.text_dir_punc_kindle_button)
        self.text_dir_punc_none_button.toggled.connect(self.update_gui)
        self.text_dir_punc_button.toggled.connect(self.update_gui)
        self.text_dir_punc_kindle_button.toggled.connect(self.update_gui)

        source_group=QButtonGroup(self)
        self.file_source_button = QRadioButton(_('Selected File Only'))
        self.book_source_button = QRadioButton(_('Entire eBook'))
        source_group.addButton(self.file_source_button)
        source_group.addButton(self.book_source_button)
        self.source_group_box = QGroupBox(_('Source'))
        if not self.force_entire_book:
            widgetLayout.addWidget(self.source_group_box)
            source_group_box_layout = QVBoxLayout()
            self.source_group_box.setLayout(source_group_box_layout)
            source_group_box_layout.addWidget(self.file_source_button)
            source_group_box_layout.addWidget(self.book_source_button)

        layout.addSpacing(10)
        self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)

        self.button_box.accepted.connect(self._ok_clicked)
        self.button_box.rejected.connect(self.reject)
        layout.addWidget(self.button_box)

        if not self.force_entire_book:
            self.file_source_button.setChecked(self.prefs['use_html_file'])
            self.book_source_button.setChecked(self.prefs['use_entire_book'])
        else:
            self.file_source_button.setChecked(False)
            self.book_source_button.setChecked(True)

        self.text_dir_combo.setCurrentIndex(self.prefs['orientation'])
        self.text_dir_punc_none_button.setChecked(self.prefs['no_optimization'])
        self.text_dir_punc_button.setChecked(self.prefs['readium_optimization'])
        self.text_dir_punc_kindle_button.setChecked(self.prefs['kindle_optimization'])
        self.update_gui()

    def update_gui(self):

        if self.text_dir_combo.currentIndex() == 0:
            self.optimization_group_box.setEnabled(False)
            self.text_dir_punc_none_button.setEnabled(False)
            self.text_dir_punc_button.setEnabled(False)
            self.text_dir_punc_kindle_button.setEnabled(False)
        else:
            self.optimization_group_box.setEnabled(True)
            self.text_dir_punc_none_button.setEnabled(True)
            self.text_dir_punc_button.setEnabled(True)
            self.text_dir_punc_kindle_button.setEnabled(True)
            
    def _ok_clicked(self):

        optimization_mode = 0
        if self.text_dir_punc_button.isChecked():
            optimization_mode = 1    #Readium
        if self.text_dir_punc_kindle_button.isChecked():
            optimization_mode = 2    #Kindle
 
        self.criteria = (self.text_dir_combo.currentIndex(), optimization_mode)
        self.savePrefs()
        self.accept()

    def getCriteria(self):
        return self.criteria

    def prefsPrep(self):
        from calibre.utils.config import JSONConfig
        plugin_prefs = JSONConfig('plugins/{0}_ChineseConversion_settings'.format(PLUGIN_SAFE_NAME))
        plugin_prefs.defaults['use_html_file'] = True
        plugin_prefs.defaults['use_entire_book'] = True
        plugin_prefs.defaults['orientation'] = 0
        plugin_prefs.defaults['no_optimization'] = True
        plugin_prefs.defaults['readium_optimization'] = False
        plugin_prefs.defaults['kindle_optimization'] = False
        return plugin_prefs

    def savePrefs(self):
        self.prefs['use_html_file'] = self.file_source_button.isChecked()
        self.prefs['use_entire_book'] = self.book_source_button.isChecked()
        self.prefs['orientation'] = self.text_dir_combo.currentIndex()
        self.prefs['no_optimization'] = self.text_dir_punc_none_button.isChecked()
        self.prefs['readium_optimization'] = self.text_dir_punc_button.isChecked()
        self.prefs['kindle_optimization'] = self.text_dir_punc_kindle_button.isChecked()
Пример #27
0
    def __init__(self, gui, do_user_config, selected_book_ids,
                 is_sync_selected):
        QWidget.__init__(self, gui)

        api.build_request('/limits')

        self.logger = Logger(
            path.join(gui.current_db.library_path, 'bookfusion_sync.log'))
        self.logger.info(
            'Open sync dialog: selected_book_ids={}; is_sync_selected={}'.
            format(selected_book_ids, is_sync_selected))

        if len(selected_book_ids) == 0:
            is_sync_selected = False

        self.worker_thread = None

        self.do_user_config = do_user_config
        self.db = gui.current_db.new_api

        self.selected_book_ids = selected_book_ids

        self.l = QVBoxLayout()
        self.l.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.l)

        self.radio_layout = QVBoxLayout()
        self.l.addLayout(self.radio_layout)

        self.sync_all_radio = QRadioButton('Sync all books')
        self.sync_all_radio.setChecked(not is_sync_selected)
        self.radio_layout.addWidget(self.sync_all_radio)

        sync_selected_radio_label = 'Sync selected books'
        if len(selected_book_ids) > 0:
            sync_selected_radio_label = 'Sync {} selected {}'.format(
                len(selected_book_ids),
                'book' if len(selected_book_ids) == 1 else 'books')
        self.sync_selected_radio = QRadioButton(sync_selected_radio_label)
        self.sync_selected_radio.toggled.connect(self.toggle_sync_selected)
        self.sync_selected_radio.setChecked(is_sync_selected)
        self.sync_selected_radio.setEnabled(len(selected_book_ids) > 0)
        self.radio_layout.addWidget(self.sync_selected_radio)

        self.reupload_possible = len(selected_book_ids) > 0 and len(
            selected_book_ids) <= 100
        if self.reupload_possible:
            for book_id in selected_book_ids:
                identifiers = self.db.get_proxy_metadata(book_id).identifiers
                if not identifiers.get('bookfusion'):
                    self.reupload_possible = False

        self.reupload_checkbox = QCheckBox('Re-upload book files', self)
        self.reupload_checkbox.setVisible(is_sync_selected
                                          and self.reupload_possible)
        self.radio_layout.addWidget(self.reupload_checkbox)

        self.btn_layout = QHBoxLayout()
        self.l.addLayout(self.btn_layout)

        self.config_btn = QPushButton('Configure')
        self.config_btn.clicked.connect(self.config)
        self.btn_layout.addWidget(self.config_btn)

        self.btn_layout.addStretch()

        self.start_btn = QPushButton('Start')
        self.start_btn.clicked.connect(self.start)
        self.btn_layout.addWidget(self.start_btn)

        self.cancel_btn = QPushButton('Cancel')
        self.cancel_btn.clicked.connect(self.cancel)
        self.cancel_btn.hide()
        self.btn_layout.addWidget(self.cancel_btn)

        self.info = QHBoxLayout()
        self.info.setContentsMargins(0, 0, 0, 0)
        self.l.addLayout(self.info)
        self.msg = QLabel()
        self.info.addWidget(self.msg)
        self.info.addStretch()
        self.log_btn = QLabel('<a href="#">Log</a>')
        self.log_btn.linkActivated.connect(self.toggle_log)
        self.log_btn.hide()
        self.info.addWidget(self.log_btn)

        self.log = QTableWidget(0, 2)
        self.log.setHorizontalHeaderLabels(['Book', 'Message'])
        self.log.horizontalHeader().setStretchLastSection(True)
        self.log.hide()
        self.l.addWidget(self.log)

        self.apply_config()
Пример #28
0
    def setup_ui(self):

        # Create layout for entire dialog
        layout = QVBoxLayout(self)
        self.setLayout(layout)

        #Create a scroll area for the top part of the dialog
        self.scrollArea = QScrollArea(self)
        self.scrollArea.setWidgetResizable(True)

        # Create widget for all the contents of the dialog except the OK and Cancel buttons
        self.scrollContentWidget = QWidget(self.scrollArea)
        self.scrollArea.setWidget(self.scrollContentWidget)
        widgetLayout = QVBoxLayout(self.scrollContentWidget)

        # Add scrollArea to dialog
        layout.addWidget(self.scrollArea)

        self.other_group_box = QGroupBox(_('Other Changes'))
        widgetLayout.addWidget(self.other_group_box)
        other_group_box_layout = QVBoxLayout()
        self.other_group_box.setLayout(other_group_box_layout)

        text_dir_layout = QHBoxLayout()
        other_group_box_layout.addLayout(text_dir_layout)
        direction_label = QLabel(_('Text Direction:'))
        text_dir_layout.addWidget(direction_label)
        self.text_dir_combo = QComboBox()
        text_dir_layout.addWidget(self.text_dir_combo)
        self.text_dir_combo.addItems([_('No Conversion'), _('Horizontal'), _('Vertical')])
        self.text_dir_combo.setToolTip(_('Select the desired text orientation'))
        self.text_dir_combo.currentIndexChanged.connect(self.update_gui)


        self.optimization_group_box = QGroupBox(_('Reader Device Optimization'))
        other_group_box_layout.addWidget(self.optimization_group_box)
        optimization_group_box_layout = QVBoxLayout()
        self.optimization_group_box.setLayout(optimization_group_box_layout)
        
        punc_group=QButtonGroup(self)
        self.text_dir_punc_none_button = QRadioButton("""No presentation optimization""")
        optimization_group_box_layout.addWidget(self.text_dir_punc_none_button)
        self.text_dir_punc_button = QRadioButton("""Optimize presentation for Readium reader""")
        self.text_dir_punc_button.setToolTip(_('Use vert/horiz punctuation presentation forms for Chrome Readium Epub3 reader'))
        optimization_group_box_layout.addWidget(self.text_dir_punc_button)
        self.text_dir_punc_kindle_button = QRadioButton("""Optimize presentation for Kindle reader""")
        self.text_dir_punc_kindle_button.setToolTip(_('Use vert/horiz puncuation presentation forms for Kindle reader'))
        optimization_group_box_layout.addWidget(self.text_dir_punc_kindle_button)
        self.text_dir_punc_none_button.toggled.connect(self.update_gui)
        self.text_dir_punc_button.toggled.connect(self.update_gui)
        self.text_dir_punc_kindle_button.toggled.connect(self.update_gui)

        source_group=QButtonGroup(self)
        self.file_source_button = QRadioButton(_('Selected File Only'))
        self.book_source_button = QRadioButton(_('Entire eBook'))
        source_group.addButton(self.file_source_button)
        source_group.addButton(self.book_source_button)
        self.source_group_box = QGroupBox(_('Source'))
        if not self.force_entire_book:
            widgetLayout.addWidget(self.source_group_box)
            source_group_box_layout = QVBoxLayout()
            self.source_group_box.setLayout(source_group_box_layout)
            source_group_box_layout.addWidget(self.file_source_button)
            source_group_box_layout.addWidget(self.book_source_button)

        layout.addSpacing(10)
        self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)

        self.button_box.accepted.connect(self._ok_clicked)
        self.button_box.rejected.connect(self.reject)
        layout.addWidget(self.button_box)

        if not self.force_entire_book:
            self.file_source_button.setChecked(self.prefs['use_html_file'])
            self.book_source_button.setChecked(self.prefs['use_entire_book'])
        else:
            self.file_source_button.setChecked(False)
            self.book_source_button.setChecked(True)

        self.text_dir_combo.setCurrentIndex(self.prefs['orientation'])
        self.text_dir_punc_none_button.setChecked(self.prefs['no_optimization'])
        self.text_dir_punc_button.setChecked(self.prefs['readium_optimization'])
        self.text_dir_punc_kindle_button.setChecked(self.prefs['kindle_optimization'])
        self.update_gui()
Пример #29
0
    def request_octo_init_settings(self, wizard, method):
        vbox = QVBoxLayout()
        next_enabled = True
        label = QLabel(_("Enter a label to name your device:"))
        name = QLineEdit()
        hl = QHBoxLayout()
        hl.addWidget(label)
        hl.addWidget(name)
        hl.addStretch(1)
        vbox.addLayout(hl)

        def clean_text(widget):
            text = widget.toPlainText().strip()
            return ' '.join(text.split())

        if method in [TIM_NEW, TIM_RECOVER]:
            gb = QGroupBox()
            hbox1 = QHBoxLayout()
            gb.setLayout(hbox1)
            vbox.addWidget(gb)
            gb.setTitle(_("Select your seed length:"))
            bg_numwords = QButtonGroup()
            for i, count in enumerate([12, 18, 24]):
                rb = QRadioButton(gb)
                rb.setText(_("%d words") % count)
                bg_numwords.addButton(rb)
                bg_numwords.setId(rb, i)
                hbox1.addWidget(rb)
                rb.setChecked(True)
            cb_pin = QCheckBox(_('Enable PIN protection'))
            cb_pin.setChecked(True)
        else:
            text = QTextEdit()
            text.setMaximumHeight(60)
            if method == TIM_MNEMONIC:
                msg = _("Enter your BIP39 mnemonic:")
            else:
                msg = _("Enter the master private key beginning with xprv:")

                def set_enabled():
                    from electrum.keystore import is_xprv
                    wizard.next_button.setEnabled(is_xprv(clean_text(text)))

                text.textChanged.connect(set_enabled)
                next_enabled = False

            vbox.addWidget(QLabel(msg))
            vbox.addWidget(text)
            pin = QLineEdit()
            pin.setValidator(QRegExpValidator(QRegExp('[1-9]{0,9}')))
            pin.setMaximumWidth(100)
            hbox_pin = QHBoxLayout()
            hbox_pin.addWidget(QLabel(_("Enter your PIN (digits 1-9):")))
            hbox_pin.addWidget(pin)
            hbox_pin.addStretch(1)

        if method in [TIM_NEW, TIM_RECOVER]:
            vbox.addWidget(WWLabel(RECOMMEND_PIN))
            vbox.addWidget(cb_pin)
        else:
            vbox.addLayout(hbox_pin)

        passphrase_msg = WWLabel(PASSPHRASE_HELP_SHORT)
        passphrase_warning = WWLabel(PASSPHRASE_NOT_PIN)
        passphrase_warning.setStyleSheet("color: red")
        cb_phrase = QCheckBox(_('Enable passphrases'))
        cb_phrase.setChecked(False)
        vbox.addWidget(passphrase_msg)
        vbox.addWidget(passphrase_warning)
        vbox.addWidget(cb_phrase)

        # ask for recovery type (random word order OR matrix)
        if method == TIM_RECOVER:
            gb_rectype = QGroupBox()
            hbox_rectype = QHBoxLayout()
            gb_rectype.setLayout(hbox_rectype)
            vbox.addWidget(gb_rectype)
            gb_rectype.setTitle(_("Select recovery type:"))
            bg_rectype = QButtonGroup()

            rb1 = QRadioButton(gb_rectype)
            rb1.setText(_('Scrambled words'))
            bg_rectype.addButton(rb1)
            bg_rectype.setId(rb1, RECOVERY_TYPE_SCRAMBLED_WORDS)
            hbox_rectype.addWidget(rb1)
            rb1.setChecked(True)

            rb2 = QRadioButton(gb_rectype)
            rb2.setText(_('Matrix'))
            bg_rectype.addButton(rb2)
            bg_rectype.setId(rb2, RECOVERY_TYPE_MATRIX)
            hbox_rectype.addWidget(rb2)
        else:
            bg_rectype = None

        wizard.exec_layout(vbox, next_enabled=next_enabled)

        if method in [TIM_NEW, TIM_RECOVER]:
            item = bg_numwords.checkedId()
            pin = cb_pin.isChecked()
            recovery_type = bg_rectype.checkedId() if bg_rectype else None
        else:
            item = ' '.join(str(clean_text(text)).split())
            pin = str(pin.text())
            recovery_type = None

        return (item, name.text(), pin, cb_phrase.isChecked(), recovery_type)
Пример #30
0
    def __init__(self, recipe_model, parent=None):
        QDialog.__init__(self, parent)
        self.commit_on_change = True
        self.previous_urn = None

        self.setWindowIcon(QIcon(I('scheduler.png')))
        self.setWindowTitle(_("Schedule news download"))
        self.l = l = QGridLayout(self)

        # Left panel
        self.h = h = QHBoxLayout()
        l.addLayout(h, 0, 0, 1, 1)
        self.search = s = SearchBox2(self)
        self.search.initialize('scheduler_search_history')
        self.search.setMinimumContentsLength(15)
        self.go_button = b = QToolButton(self)
        b.setText(_("Go"))
        b.clicked.connect(self.search.do_search)
        h.addWidget(s), h.addWidget(b)
        self.recipes = RecipesView(self)
        l.addWidget(self.recipes, 1, 0, 1, 1)
        self.recipe_model = recipe_model
        self.recipe_model.do_refresh()
        self.recipes.setModel(self.recipe_model)
        self.recipes.setFocus(Qt.OtherFocusReason)
        self.count_label = la = QLabel(_('%s news sources') % self.recipe_model.showing_count)
        la.setAlignment(Qt.AlignCenter)
        l.addWidget(la, 2, 0, 1, 1)
        self.search.search.connect(self.recipe_model.search)
        self.recipe_model.searched.connect(self.search.search_done, type=Qt.QueuedConnection)
        self.recipe_model.searched.connect(self.search_done)

        # Right Panel
        self.scroll_area_contents = sac = QWidget(self)
        self.l.addWidget(sac, 0, 1, 2, 1)
        sac.v = v = QVBoxLayout(sac)
        v.setContentsMargins(0, 0, 0, 0)
        self.detail_box = QTabWidget(self)
        self.detail_box.setVisible(False)
        self.detail_box.setCurrentIndex(0)
        v.addWidget(self.detail_box)
        v.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))

        # First Tab (scheduling)
        self.tab = QWidget()
        self.detail_box.addTab(self.tab, _("&Schedule"))
        self.tab.v = vt = QVBoxLayout(self.tab)
        vt.setContentsMargins(0, 0, 0, 0)
        self.blurb = la = QLabel('blurb')
        la.setWordWrap(True), la.setOpenExternalLinks(True)
        vt.addWidget(la)
        self.frame = f = QFrame(self.tab)
        vt.addWidget(f)
        f.setFrameShape(f.StyledPanel)
        f.setFrameShadow(f.Raised)
        f.v = vf = QVBoxLayout(f)
        self.schedule = s = QCheckBox(_("&Schedule for download:"), f)
        self.schedule.stateChanged[int].connect(self.toggle_schedule_info)
        vf.addWidget(s)
        f.h = h = QHBoxLayout()
        vf.addLayout(h)
        self.days_of_week = QRadioButton(_("&Days of  week"), f)
        self.days_of_month = QRadioButton(_("Da&ys of month"), f)
        self.every_x_days = QRadioButton(_("Every &x days"), f)
        self.days_of_week.setChecked(True)
        h.addWidget(self.days_of_week), h.addWidget(self.days_of_month), h.addWidget(self.every_x_days)
        self.schedule_stack = ss = QStackedWidget(f)
        self.schedule_widgets = []
        for key in reversed(self.SCHEDULE_TYPES):
            self.schedule_widgets.insert(0, self.SCHEDULE_TYPES[key](self))
            self.schedule_stack.insertWidget(0, self.schedule_widgets[0])
        vf.addWidget(ss)
        self.last_downloaded = la = QLabel(f)
        la.setWordWrap(True)
        vf.addWidget(la)
        self.account = acc = QGroupBox(self.tab)
        acc.setTitle(_("&Account"))
        vt.addWidget(acc)
        acc.g = g = QGridLayout(acc)
        acc.unla = la = QLabel(_("&Username:"******"&Password:"******"&Show password"), self.account)
        spw.stateChanged[int].connect(self.set_pw_echo_mode)
        g.addWidget(spw, 2, 0, 1, 2)
        self.rla = la = QLabel(_("For the scheduling to work, you must leave calibre running."))
        vt.addWidget(la)
        for b, c in iteritems(self.SCHEDULE_TYPES):
            b = getattr(self, b)
            b.toggled.connect(self.schedule_type_selected)
            b.setToolTip(textwrap.dedent(c.HELP))

        # Second tab (advanced settings)
        self.tab2 = t2 = QWidget()
        self.detail_box.addTab(self.tab2, _("&Advanced"))
        self.tab2.g = g = QGridLayout(t2)
        g.setContentsMargins(0, 0, 0, 0)
        self.add_title_tag = tt = QCheckBox(_("Add &title as tag"), t2)
        g.addWidget(tt, 0, 0, 1, 2)
        t2.la = la = QLabel(_("&Extra tags:"))
        self.custom_tags = ct = QLineEdit(self)
        la.setBuddy(ct)
        g.addWidget(la), g.addWidget(ct, 1, 1)
        t2.la2 = la = QLabel(_("&Keep at most:"))
        la.setToolTip(_("Maximum number of copies (issues) of this recipe to keep.  Set to 0 to keep all (disable)."))
        self.keep_issues = ki = QSpinBox(t2)
        tt.toggled['bool'].connect(self.keep_issues.setEnabled)
        ki.setMaximum(100000), la.setBuddy(ki)
        ki.setToolTip(_(
            "<p>When set, this option will cause calibre to keep, at most, the specified number of issues"
            " of this periodical. Every time a new issue is downloaded, the oldest one is deleted, if the"
            " total is larger than this number.\n<p>Note that this feature only works if you have the"
            " option to add the title as tag checked, above.\n<p>Also, the setting for deleting periodicals"
            " older than a number of days, below, takes priority over this setting."))
        ki.setSpecialValueText(_("all issues")), ki.setSuffix(_(" issues"))
        g.addWidget(la), g.addWidget(ki, 2, 1)
        si = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
        g.addItem(si, 3, 1, 1, 1)

        # Bottom area
        self.hb = h = QHBoxLayout()
        self.l.addLayout(h, 2, 1, 1, 1)
        self.labt = la = QLabel(_("Delete downloaded &news older than:"))
        self.old_news = on = QSpinBox(self)
        on.setToolTip(_(
            "<p>Delete downloaded news older than the specified number of days. Set to zero to disable.\n"
            "<p>You can also control the maximum number of issues of a specific periodical that are kept"
            " by clicking the Advanced tab for that periodical above."))
        on.setSpecialValueText(_("never delete")), on.setSuffix(_(" days"))
        on.setMaximum(1000), la.setBuddy(on)
        on.setValue(gconf['oldest_news'])
        h.addWidget(la), h.addWidget(on)
        self.download_all_button = b = QPushButton(QIcon(I('news.png')), _("Download &all scheduled"), self)
        b.setToolTip(_("Download all scheduled news sources at once"))
        b.clicked.connect(self.download_all_clicked)
        self.l.addWidget(b, 3, 0, 1, 1)
        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
        bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
        self.download_button = b = bb.addButton(_('&Download now'), bb.ActionRole)
        b.setIcon(QIcon(I('arrow-down.png'))), b.setVisible(False)
        b.clicked.connect(self.download_clicked)
        self.l.addWidget(bb, 3, 1, 1, 1)

        geom = gprefs.get('scheduler_dialog_geometry')
        if geom is not None:
            QApplication.instance().safe_restore_geometry(self, geom)
Пример #31
0
    def allExtractBox(self):
        label_ = QLabel(self)
        label_.resize(self.width() // 3, 25)
        label_.move(0, 25)
        label_.setText("全部提取模式:")
        label_.setAlignment(Qt.AlignCenter)
        label_.setStyleSheet("font-size: 15px")
        # 选项AB
        allYes = QRadioButton(self)
        allYes.resize(self.width() // 3, 25)
        allYes.move(self.width() // 3, 25)
        allYes.setText("全部提取")
        allNo = QRadioButton(self)
        allNo.resize(self.width() // 3, 25)
        allNo.move(self.width() // 3 * 2, 25)
        allNo.setText("单个提取")
        allNo.setChecked(True)

        self.allModeGroup.setObjectName("allExtractMode")
        self.allModeGroup.addButton(allYes)
        self.allModeGroup.addButton(allNo)
Пример #32
0
class GcodeUI(object):
    def __init__(self, ui, layout):
        self.main_ui = ui
        self.layout = layout
        super(GcodeUI, self).__init__()
        self.isOutlineMode = True
        self.isLaserMode = True
        self.handler = GcodeHandler(self)
        self.set_ui()
        self.connect_slot()
        self.gcode = ''

    def set_ui(self):
        self._set_up_frame_ui()
        self._set_middle_frame_ui()
        self._set_down_frame_ui()

    def _set_up_frame_ui(self):
        self.up_frame = QFrame()
        self.up_frame.setMinimumHeight(300)
        self.up_frame.setMaximumHeight(500)
        self.up_layout = QHBoxLayout(self.up_frame)
        up_left_frame = QFrame()
        # up_left_frame.setMinimumWidth(self.main_ui.window.geometry().width() / 2)
        # up_left_frame.setMaximumWidth(self.geometry().width() / 2)
        up_right_frame = QFrame()
        # up_right_frame.setMinimumWidth(self.main_ui.window.geometry().width() / 2)
        # up_right_frame.setMaximumWidth(self.geometry().width() / 2)
        self.up_left_layout = QHBoxLayout(up_left_frame)
        self.up_right_layout = QHBoxLayout(up_right_frame)
        self.up_layout.addWidget(up_left_frame)
        # self.up_layout.addWidget(up_right_frame)
        self.layout.addWidget(self.up_frame)

        self.label_img = QLabel()
        # self.label_img.setMaximumHeight(320)
        # self.label_img.setMaximumWidth(480)
        # self.label_img.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        # self.label_img.setScaledContents(True)

        img = QImage()
        if img.load(os.path.join(icon_path, 'tmp.svg')):
            self.label_img.setPixmap(QPixmap.fromImage(img))
            with open(os.path.join(icon_path, 'tmp.svg'), 'rb') as f:
                self.handler.source = f.read()

        self.up_left_layout.addWidget(self.label_img)

        self.label_img_preview = QLabel()
        # self.label_img_preview.setMaximumHeight(320)
        # self.label_img_preview.setMaximumWidth(480)
        self.label_img_preview.setDisabled(True)
        # # self.label_img_preview.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        # # self.label_img_preview.setScaledContents(True)
        # data = np.zeros(320 * 240)
        # img = QImage(data, 320, 240, QImage.Format_RGB888)
        # pixmap = QPixmap.fromImage(img)
        # self.label_img_preview.setPixmap(pixmap)
        self.up_right_layout.addWidget(self.label_img_preview)
        # self.up_frame.hide()

    def _set_middle_frame_ui(self):
        middle_frame = QFrame()
        self.middle_layout = QHBoxLayout(middle_frame)
        middle_left_frame = QFrame()
        # middle_left_frame.setMinimumWidth(self.main_ui.window.geometry().width() / 2 - 20)
        middle_right_frame = QFrame()
        # middle_right_frame.setMinimumWidth(self.main_ui.window.geometry().width() / 2 - 20)
        self.middle_left_layout = QGridLayout(middle_left_frame)
        self.middle_right_layout = QGridLayout(middle_right_frame)

        self.middle_layout.addWidget(middle_left_frame)
        self.middle_layout.addWidget(middle_right_frame)
        self.layout.addWidget(middle_frame)

        row = 0
        self.checkbox_outline = QRadioButton('OutLine')
        self.checkbox_gray = QRadioButton('Gray')
        self.checkbox_gray.hide()
        self.btn_load_img = QPushButton('LoadImage')
        self.checkbox_outline.toggle()
        self.isOutlineMode = True
        self.checkbox_outline.setDisabled(True)
        self.middle_left_layout.addWidget(self.checkbox_outline, row, 0)
        self.middle_left_layout.addWidget(self.checkbox_gray, row, 1)
        self.middle_left_layout.addWidget(self.btn_load_img, row, 2)

        row += 1
        label_x_home = QLabel('x_home:')
        self.slider_x_home = QSlider(QtCore.Qt.Horizontal)
        self.slider_x_home.setMinimum(0)
        self.slider_x_home.setMaximum(2000)
        self.slider_x_home.setValue(1500)
        self.spinbox_x_home = QDoubleSpinBox()
        self.spinbox_x_home.setDecimals(1)
        self.spinbox_x_home.setSingleStep(0.1)
        self.spinbox_x_home.setMinimum(0.0)
        self.spinbox_x_home.setMaximum(200.0)
        self.spinbox_x_home.setValue(150.0)
        self.slider_x_home.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_x_home.mouseReleaseEvent)
        self.spinbox_x_home.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_x_home.focusOutEvent)
        self.middle_left_layout.addWidget(label_x_home, row, 0)
        self.middle_left_layout.addWidget(self.slider_x_home, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_x_home, row, 2)

        row += 1
        label_y_home = QLabel('y_home:')
        self.slider_y_home = QSlider(QtCore.Qt.Horizontal)
        self.slider_y_home.setMinimum(-1500)
        self.slider_y_home.setMaximum(1500)
        self.slider_y_home.setValue(0)
        self.spinbox_y_home = QDoubleSpinBox()
        self.spinbox_y_home.setDecimals(1)
        self.spinbox_y_home.setSingleStep(0.1)
        self.spinbox_y_home.setMinimum(-150.0)
        self.spinbox_y_home.setMaximum(150.0)
        self.spinbox_y_home.setValue(0.0)
        self.slider_y_home.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_y_home.mouseReleaseEvent)
        self.spinbox_y_home.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_y_home.focusOutEvent)
        self.middle_left_layout.addWidget(label_y_home, row, 0)
        self.middle_left_layout.addWidget(self.slider_y_home, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_y_home, row, 2)

        row += 1
        label_z_home = QLabel('z_home:')
        self.slider_z_home = QSlider(QtCore.Qt.Horizontal)
        self.slider_z_home.setMinimum(0)
        self.slider_z_home.setMaximum(1500)
        self.slider_z_home.setValue(900)
        self.spinbox_z_home = QDoubleSpinBox()
        self.spinbox_z_home.setDecimals(1)
        self.spinbox_z_home.setSingleStep(0.1)
        self.spinbox_z_home.setMinimum(0.0)
        self.spinbox_z_home.setMaximum(150.0)
        self.spinbox_z_home.setValue(90.0)
        self.slider_z_home.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_z_home.mouseReleaseEvent)
        self.spinbox_z_home.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_z_home.focusOutEvent)
        self.middle_left_layout.addWidget(label_z_home, row, 0)
        self.middle_left_layout.addWidget(self.slider_z_home, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_z_home, row, 2)

        row += 1
        label_x_offset = QLabel('x_offset:')
        self.slider_x_offset = QSlider(QtCore.Qt.Horizontal)
        self.slider_x_offset.setMinimum(-5000)
        self.slider_x_offset.setMaximum(5000)
        self.slider_x_offset.setValue(0)
        self.spinbox_x_offset = QDoubleSpinBox()
        self.spinbox_x_offset.setSingleStep(0.1)
        self.spinbox_x_offset.setDecimals(1)
        self.spinbox_x_offset.setMinimum(-500.0)
        self.spinbox_x_offset.setMaximum(500.0)
        self.spinbox_x_offset.setValue(0.0)
        self.slider_x_offset.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_x_offset.mouseReleaseEvent)
        self.spinbox_x_offset.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_x_offset.focusOutEvent)
        self.middle_left_layout.addWidget(label_x_offset, row, 0)
        self.middle_left_layout.addWidget(self.slider_x_offset, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_x_offset, row, 2)

        row += 1
        label_y_offset = QLabel('y_offset:')
        self.slider_y_offset = QSlider(QtCore.Qt.Horizontal)
        self.slider_y_offset.setMinimum(-5000)
        self.slider_y_offset.setMaximum(5000)
        self.slider_y_offset.setValue(0)
        self.spinbox_y_offset = QDoubleSpinBox()
        self.spinbox_y_offset.setDecimals(1)
        self.spinbox_y_offset.setSingleStep(0.1)
        self.spinbox_y_offset.setMinimum(-500.0)
        self.spinbox_y_offset.setMaximum(500.0)
        self.spinbox_y_offset.setValue(0.0)
        self.slider_y_offset.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_y_offset.mouseReleaseEvent)
        self.spinbox_y_offset.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_y_offset.focusOutEvent)
        self.middle_left_layout.addWidget(label_y_offset, row, 0)
        self.middle_left_layout.addWidget(self.slider_y_offset, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_y_offset, row, 2)

        row += 1
        label_z_offset = QLabel('z_offset:')
        self.slider_z_offset = QSlider(QtCore.Qt.Horizontal)
        self.slider_z_offset.setMinimum(-1000)
        self.slider_z_offset.setMaximum(1500)
        self.slider_z_offset.setValue(900)
        self.spinbox_z_offset = QDoubleSpinBox()
        self.spinbox_z_offset.setDecimals(1)
        self.spinbox_z_offset.setSingleStep(0.1)
        self.spinbox_z_offset.setMinimum(-100.0)
        self.spinbox_z_offset.setMaximum(150.0)
        self.spinbox_z_offset.setValue(90.0)
        self.slider_z_offset.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_z_offset.mouseReleaseEvent)
        self.spinbox_z_offset.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_z_offset.focusOutEvent)
        self.middle_left_layout.addWidget(label_z_offset, row, 0)
        self.middle_left_layout.addWidget(self.slider_z_offset, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_z_offset, row, 2)

        row += 1
        label_pen_up = QLabel('pen_up:')
        self.slider_pen_up = QSlider(QtCore.Qt.Horizontal)
        self.slider_pen_up.setMinimum(0)
        self.slider_pen_up.setMaximum(500)
        self.slider_pen_up.setValue(200)
        self.spinbox_pen_up = QDoubleSpinBox()
        self.spinbox_pen_up.setDecimals(1)
        self.spinbox_pen_up.setSingleStep(0.1)
        self.spinbox_pen_up.setMinimum(0.0)
        self.spinbox_pen_up.setMaximum(50.0)
        self.spinbox_pen_up.setValue(20.0)
        self.slider_pen_up.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_pen_up.mouseReleaseEvent)
        self.spinbox_pen_up.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_pen_up.focusOutEvent)
        self.slider_pen_up.setDisabled(True)
        self.spinbox_pen_up.setDisabled(True)
        self.middle_left_layout.addWidget(label_pen_up, row, 0)
        self.middle_left_layout.addWidget(self.slider_pen_up, row, 1)
        self.middle_left_layout.addWidget(self.spinbox_pen_up, row, 2)

        row = 0
        self.checkbox_laser = QRadioButton('Laser')
        self.checkbox_pen = QRadioButton('Pen')
        self.checkbox_laser.toggle()
        self.isLaserMode = True
        self.middle_right_layout.addWidget(self.checkbox_laser, row, 0)
        self.middle_right_layout.addWidget(self.checkbox_pen, row, 1)

        row += 1
        label_drawing_feedrate = QLabel('drawing_feedrate:')
        self.slider_drawing_feedrate = QSlider(QtCore.Qt.Horizontal)
        self.slider_drawing_feedrate.setMinimum(5)
        self.slider_drawing_feedrate.setMaximum(1000)
        self.slider_drawing_feedrate.setValue(100)
        self.spinbox_drawing_feedrate = QSpinBox()
        self.spinbox_drawing_feedrate.setMinimum(5)
        self.spinbox_drawing_feedrate.setMaximum(1000)
        self.spinbox_drawing_feedrate.setValue(100)
        self.slider_drawing_feedrate.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_drawing_feedrate.mouseReleaseEvent)
        self.spinbox_drawing_feedrate.focusOutEvent = functools.partial(
            self.focusOutEvent,
            source=self.spinbox_drawing_feedrate.focusOutEvent)
        self.middle_right_layout.addWidget(label_drawing_feedrate, row, 0)
        self.middle_right_layout.addWidget(self.slider_drawing_feedrate, row,
                                           1)
        self.middle_right_layout.addWidget(self.spinbox_drawing_feedrate, row,
                                           2)

        row += 1
        label_moving_feedrate = QLabel('moving_feedrate:')
        self.slider_moving_feedrate = QSlider(QtCore.Qt.Horizontal)
        self.slider_moving_feedrate.setMinimum(5)
        self.slider_moving_feedrate.setMaximum(20000)
        self.slider_moving_feedrate.setValue(100)
        self.spinbox_moving_feedrate = QSpinBox()
        self.spinbox_moving_feedrate.setMinimum(5)
        self.spinbox_moving_feedrate.setMaximum(20000)
        self.spinbox_moving_feedrate.setValue(100)
        self.slider_moving_feedrate.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent,
            source=self.slider_moving_feedrate.mouseReleaseEvent)
        self.spinbox_moving_feedrate.focusOutEvent = functools.partial(
            self.focusOutEvent,
            source=self.spinbox_moving_feedrate.focusOutEvent)
        self.middle_right_layout.addWidget(label_moving_feedrate, row, 0)
        self.middle_right_layout.addWidget(self.slider_moving_feedrate, row, 1)
        self.middle_right_layout.addWidget(self.spinbox_moving_feedrate, row,
                                           2)

        row += 1
        label_scale = QLabel('scale:')
        self.slider_scale = QSlider(QtCore.Qt.Horizontal)
        self.slider_scale.setMinimum(1)
        self.slider_scale.setMaximum(100)
        self.slider_scale.setValue(10)
        self.spinbox_scale = QDoubleSpinBox()
        self.spinbox_scale.setDecimals(1)
        self.spinbox_scale.setSingleStep(0.1)
        self.spinbox_scale.setMinimum(0.1)
        self.spinbox_scale.setMaximum(10.0)
        self.spinbox_scale.setValue(1.0)
        # self.slider_scale.setDisabled(True)
        # self.spinbox_scale.setDisabled(True)
        self.slider_scale.mouseReleaseEvent = functools.partial(
            self.mouseReleaseEvent, source=self.slider_scale.mouseReleaseEvent)
        self.spinbox_scale.focusOutEvent = functools.partial(
            self.focusOutEvent, source=self.spinbox_scale.focusOutEvent)

        self.middle_right_layout.addWidget(label_scale, row, 0)
        self.middle_right_layout.addWidget(self.slider_scale, row, 1)
        self.middle_right_layout.addWidget(self.spinbox_scale, row, 2)

        row += 1
        label_resolution = QLabel('resolution:')
        self.slider_resolution = QSlider(QtCore.Qt.Horizontal)
        self.slider_resolution.setMinimum(1)
        self.slider_resolution.setMaximum(100)
        self.slider_resolution.setValue(10)
        self.spinbox_resolution = QDoubleSpinBox()
        self.spinbox_resolution.setMinimum(0.1)
        self.spinbox_resolution.setMaximum(10.0)
        self.spinbox_resolution.setSingleStep(0.1)
        self.spinbox_resolution.setDecimals(1)
        self.spinbox_resolution.setValue(1.0)
        self.slider_resolution.setDisabled(True)
        self.spinbox_resolution.setDisabled(True)
        self.middle_right_layout.addWidget(label_resolution, row, 0)
        self.middle_right_layout.addWidget(self.slider_resolution, row, 1)
        self.middle_right_layout.addWidget(self.spinbox_resolution, row, 2)

        row += 1
        self.btn_generate_gcode = QPushButton('Generate_Gcode')
        self.middle_right_layout.addWidget(self.btn_generate_gcode, row, 0)

        row += 1
        self.label_x_min = QLabel('')
        self.label_x_max = QLabel('')
        self.middle_right_layout.addWidget(self.label_x_min, row, 0)
        self.middle_right_layout.addWidget(self.label_x_max, row, 1)

        row += 1
        self.label_y_min = QLabel('')
        self.label_y_max = QLabel('')
        self.middle_right_layout.addWidget(self.label_y_min, row, 0)
        self.middle_right_layout.addWidget(self.label_y_max, row, 1)

    def _set_down_frame_ui(self):
        self.down_frame = QFrame()
        self.down_layout = QHBoxLayout(self.down_frame)
        self.layout.addWidget(self.down_frame)

        self.textEdit = QTextEdit()
        self.down_layout.addWidget(self.textEdit)
        # self.down_frame.hide()

    def select_engrave_mode(self, event):
        self.isOutlineMode = event
        # print('outline: {}, laser: {}'.format(self.isOutlineMode, self.isLaserMode))

    def select_end_type(self, event):
        self.isLaserMode = event
        self.slider_pen_up.setDisabled(self.isLaserMode)
        self.spinbox_pen_up.setDisabled(self.isLaserMode)
        self.generate_gcode()
        # print('outline: {}, laser: {}'.format(self.isOutlineMode, self.isLaserMode))

    def connect_slot(self):
        self.checkbox_outline.toggled.connect(self.select_engrave_mode)
        self.checkbox_laser.toggled.connect(self.select_end_type)
        self.btn_load_img.clicked.connect(self.load_image)

        self.slider_x_home.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_x_home,
                              scale=.1))
        self.spinbox_x_home.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_x_home,
                              scale=10))

        self.slider_y_home.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_y_home,
                              scale=.1))
        self.spinbox_y_home.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_y_home,
                              scale=10))

        self.slider_z_home.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_z_home,
                              scale=.1))
        self.spinbox_z_home.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_z_home,
                              scale=10))

        self.slider_x_offset.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_x_offset,
                              scale=.1))
        self.spinbox_x_offset.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_x_offset,
                              scale=10))

        self.slider_y_offset.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_y_offset,
                              scale=.1))
        self.spinbox_y_offset.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_y_offset,
                              scale=10))

        self.slider_z_offset.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_z_offset,
                              scale=.1))
        self.spinbox_z_offset.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_z_offset,
                              scale=10))

        self.slider_pen_up.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_pen_up,
                              scale=.1))
        self.spinbox_pen_up.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_pen_up,
                              scale=10))

        self.slider_scale.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_scale,
                              scale=.1))
        self.spinbox_scale.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_scale,
                              scale=10))

        self.slider_resolution.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_resolution,
                              scale=.1))
        self.spinbox_resolution.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_resolution,
                              scale=10))

        self.slider_drawing_feedrate.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_drawing_feedrate,
                              scale=1))
        self.spinbox_drawing_feedrate.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_drawing_feedrate,
                              scale=1))

        self.slider_moving_feedrate.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.spinbox_moving_feedrate,
                              scale=1))
        self.spinbox_moving_feedrate.valueChanged.connect(
            functools.partial(self.slider_spinbox_related,
                              slave=self.slider_moving_feedrate,
                              scale=1))

        self.btn_generate_gcode.clicked.connect(
            functools.partial(self.generate_gcode, flag=True))

    def slider_spinbox_related(self, value, master=None, slave=None, scale=1):
        try:
            slave.setValue(value * scale)
        except Exception as e:
            print(e)

    def mouseReleaseEvent(self, event, source=None):
        try:
            self.generate_gcode()
        except Exception as e:
            print(e)
        source(event)

    def focusOutEvent(self, event, source=None):
        try:
            self.generate_gcode()
        except Exception as e:
            print(e)
        source(event)

    def generate_gcode(self, flag=False):
        if self.handler.template is None and flag:
            self.handler.svg_to_gcode()
        if self.handler.template:
            pen_up = self.spinbox_pen_up.value() if not self.isLaserMode else 0
            config = {
                'x_home': self.spinbox_x_home.value(),
                'y_home': self.spinbox_y_home.value(),
                'z_home': self.spinbox_z_home.value(),
                'z_offset': self.spinbox_z_offset.value(),
                'pen_up': pen_up,
                'z_offset_pen_up': self.spinbox_z_offset.value() + pen_up,
                'moving_feedrate': self.spinbox_moving_feedrate.value(),
                'drawing_feedrate': self.spinbox_drawing_feedrate.value(),
            }
            self.gcode = self.handler.template.format(**config)
            self.change_gcode()
            # self.textEdit.setText(self.gcode)

    def change_gcode(self):
        if self.gcode:
            x_offset = self.spinbox_x_offset.value()
            y_offset = self.spinbox_y_offset.value()
            z_offset = self.spinbox_z_offset.value()
            moving_feedrate = self.spinbox_moving_feedrate.value()
            drawing_feedrate = self.spinbox_drawing_feedrate.value()
            scale = self.spinbox_scale.value()

            lines = self.gcode.split('\n')
            for i, line in enumerate(lines):
                List = line.strip().split(' ')
                line = ''
                for l in List:
                    if l.startswith('F'):
                        if line.startswith(('G01', 'G1')):
                            l = 'F{}'.format(drawing_feedrate)
                        elif line.startswith(('G00', 'G0')):
                            l = 'F{}'.format(moving_feedrate)
                    elif l.startswith('X'):
                        x = float(l[1:]) * scale + x_offset
                        l = 'X{0:.2f}'.format(x)
                    elif l.startswith('Y'):
                        y = float(l[1:]) * scale + y_offset
                        l = 'Y{0:.2f}'.format(y)
                    # elif l.startswith('Z'):
                    #     z = float(l[1:]) + z_offset
                    #     l = 'Z{0:.2f}'.format(z)
                    line += l + ' '
                line = line.strip()
                lines[i] = line
            self.calc_gcode(lines)
            gcode = '\n'.join(lines)
            self.textEdit.setText(gcode)

    def calc_gcode(self, lines):
        x_list = []
        y_list = []
        for i, line in enumerate(lines):
            if line.startswith(tuple(['G0', 'G1', 'G00', 'G01'])):
                List = line.strip().split(' ')
                for l in List:
                    if l.startswith('X'):
                        x = float(l[1:])
                        x_list.append(x)
                    elif l.startswith('Y'):
                        y = float(l[1:])
                        y_list.append(y)
        if len(x_list) > 0:
            x_min = np.min(x_list)
            x_max = np.max(x_list)
            self.label_x_min.setText('X(min): ' + str(x_min))
            self.label_x_max.setText('X(max): ' + str(x_max))
            # print('x_min: {}, x_max: {}, x_distance: {}'.format(x_min, x_max, x_max - x_min))
        if len(y_list) > 0:
            y_min = np.min(y_list)
            y_max = np.max(y_list)
            self.label_y_min.setText('Y(min): ' + str(y_min))
            self.label_y_max.setText('Y(max): ' + str(y_max))
            # print('y_min: {}, y_max: {}, y_distance: {}'.format(y_min, y_max, y_max - y_min))

    def load_image(self):
        fname = QFileDialog.getOpenFileName(self.main_ui.window, 'Open file',
                                            '', '*.svg')
        if fname and fname[0]:
            img = QImage()
            if img.load(fname[0]):
                self.label_img.setPixmap(QPixmap.fromImage(img))
                with open(fname[0], 'rb') as f:
                    self.handler.source = f.read()
                    self.handler.template = None
                    self.gcode = None
                    self.up_frame.show()
Пример #33
0
class SyncWidget(QWidget):
    def __init__(self, gui, do_user_config, selected_book_ids,
                 is_sync_selected):
        QWidget.__init__(self, gui)

        api.build_request('/limits')

        self.logger = Logger(
            path.join(gui.current_db.library_path, 'bookfusion_sync.log'))
        self.logger.info(
            'Open sync dialog: selected_book_ids={}; is_sync_selected={}'.
            format(selected_book_ids, is_sync_selected))

        if len(selected_book_ids) == 0:
            is_sync_selected = False

        self.worker_thread = None

        self.do_user_config = do_user_config
        self.db = gui.current_db.new_api

        self.selected_book_ids = selected_book_ids

        self.l = QVBoxLayout()
        self.l.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.l)

        self.radio_layout = QVBoxLayout()
        self.l.addLayout(self.radio_layout)

        self.sync_all_radio = QRadioButton('Sync all books')
        self.sync_all_radio.setChecked(not is_sync_selected)
        self.radio_layout.addWidget(self.sync_all_radio)

        sync_selected_radio_label = 'Sync selected books'
        if len(selected_book_ids) > 0:
            sync_selected_radio_label = 'Sync {} selected {}'.format(
                len(selected_book_ids),
                'book' if len(selected_book_ids) == 1 else 'books')
        self.sync_selected_radio = QRadioButton(sync_selected_radio_label)
        self.sync_selected_radio.toggled.connect(self.toggle_sync_selected)
        self.sync_selected_radio.setChecked(is_sync_selected)
        self.sync_selected_radio.setEnabled(len(selected_book_ids) > 0)
        self.radio_layout.addWidget(self.sync_selected_radio)

        self.reupload_possible = len(selected_book_ids) > 0 and len(
            selected_book_ids) <= 100
        if self.reupload_possible:
            for book_id in selected_book_ids:
                identifiers = self.db.get_proxy_metadata(book_id).identifiers
                if not identifiers.get('bookfusion'):
                    self.reupload_possible = False

        self.reupload_checkbox = QCheckBox('Re-upload book files', self)
        self.reupload_checkbox.setVisible(is_sync_selected
                                          and self.reupload_possible)
        self.radio_layout.addWidget(self.reupload_checkbox)

        self.btn_layout = QHBoxLayout()
        self.l.addLayout(self.btn_layout)

        self.config_btn = QPushButton('Configure')
        self.config_btn.clicked.connect(self.config)
        self.btn_layout.addWidget(self.config_btn)

        self.btn_layout.addStretch()

        self.start_btn = QPushButton('Start')
        self.start_btn.clicked.connect(self.start)
        self.btn_layout.addWidget(self.start_btn)

        self.cancel_btn = QPushButton('Cancel')
        self.cancel_btn.clicked.connect(self.cancel)
        self.cancel_btn.hide()
        self.btn_layout.addWidget(self.cancel_btn)

        self.info = QHBoxLayout()
        self.info.setContentsMargins(0, 0, 0, 0)
        self.l.addLayout(self.info)
        self.msg = QLabel()
        self.info.addWidget(self.msg)
        self.info.addStretch()
        self.log_btn = QLabel('<a href="#">Log</a>')
        self.log_btn.linkActivated.connect(self.toggle_log)
        self.log_btn.hide()
        self.info.addWidget(self.log_btn)

        self.log = QTableWidget(0, 2)
        self.log.setHorizontalHeaderLabels(['Book', 'Message'])
        self.log.horizontalHeader().setStretchLastSection(True)
        self.log.hide()
        self.l.addWidget(self.log)

        self.apply_config()

    def __del__(self):
        if self.worker_thread:
            self.worker_thread.quit()
            self.worker_thread.terminate()

    def config(self):
        self.do_user_config(parent=self)
        self.apply_config()

    def apply_config(self):
        configured = bool(prefs['api_key'])
        self.start_btn.setEnabled(configured)

    def toggle_sync_selected(self, is_sync_selected):
        if hasattr(self, 'reupload_checkbox'):
            self.reupload_checkbox.setVisible(is_sync_selected
                                              and self.reupload_possible)

    def start(self):
        if self.sync_selected_radio.isChecked(
        ) and self.reupload_checkbox.isChecked():
            reply = QMessageBox.question(
                self, 'BookFusion Sync',
                'Re-uploading book files can potentially result in previous highlights or bookmarks no longer working.\n\nPreviously uploaded files will be overwritten. Are you sure you want to re-upload?',
                QMessageBox.No | QMessageBox.Yes, QMessageBox.Yes)
            if reply != QMessageBox.Yes:
                return

        self.worker = None
        self.valid_book_ids = None
        self.book_log_map = {}
        self.book_progress_map = {}

        if self.sync_selected_radio.isChecked():
            book_ids = list(self.selected_book_ids)
        else:
            book_ids = list(self.db.all_book_ids())

        self.logger.info('Start sync: sync_selected={}; book_ids={}'.format(
            self.sync_selected_radio.isChecked(), book_ids))

        self.in_progress = True
        self.total = len(book_ids)
        self.update_progress(None)
        self.start_btn.hide()
        self.cancel_btn.show()
        self.config_btn.setEnabled(False)
        self.sync_all_radio.setEnabled(False)
        self.sync_selected_radio.setEnabled(False)

        self.worker_thread = QThread(self)

        self.worker = CheckWorker(self.db, self.logger, book_ids)
        self.worker.finished.connect(self.finish_check)
        self.worker.finished.connect(self.worker_thread.quit)
        self.worker.progress.connect(self.update_progress)
        self.worker.limitsAvailable.connect(self.apply_limits)
        self.worker.resultsAvailable.connect(self.apply_results)
        self.worker.aborted.connect(self.abort)
        self.worker.moveToThread(self.worker_thread)

        self.worker_thread.started.connect(self.worker.start)
        self.worker_thread.start()

    def apply_limits(self, limits):
        self.logger.info('Limits: {}'.format(limits))
        self.limits = limits

    def apply_results(self, books_count, valid_ids):
        self.logger.info('Check results: books_count={}; valid_ids={}'.format(
            books_count, valid_ids))
        self.valid_book_ids = valid_ids
        self.books_count = books_count

    def finish_check(self):
        if self.valid_book_ids:
            is_filesize_exceeded = len(self.valid_book_ids) < self.books_count
            is_total_books_exceeded = self.limits[
                'total_books'] and self.books_count > self.limits['total_books']

            if is_filesize_exceeded or is_total_books_exceeded:
                if self.limits['message']:
                    msg_box = QMessageBox(self)
                    msg_box.setWindowTitle('BookFusion Sync')
                    msg_box.addButton(QMessageBox.No)
                    msg_box.addButton(QMessageBox.Yes)
                    msg_box.setText(self.limits['message'])
                    msg_box.setDefaultButton(QMessageBox.Yes)
                    reply = msg_box.exec_()
                    if reply == QMessageBox.Yes:
                        self.start_sync()
                    else:
                        self.in_progress = False
                        self.msg.setText('Canceled.')
                        self.finish_sync()
                else:
                    self.start_sync()
            else:
                self.start_sync()
        else:
            if self.in_progress:
                self.in_progress = False
                self.msg.setText('No supported books selected.')
            self.finish_sync()

    def start_sync(self):
        self.log_btn.show()
        self.log.setRowCount(0)
        self.log.show()

        self.worker_thread = QThread(self)

        book_ids = self.valid_book_ids
        if self.limits['total_books']:
            book_ids = book_ids[:self.limits['total_books']]

        self.total = len(book_ids)

        self.worker = UploadManager(
            self.db, self.logger, book_ids,
            self.sync_selected_radio.isChecked()
            and self.reupload_checkbox.isChecked())
        self.worker.finished.connect(self.finish_sync)
        self.worker.finished.connect(self.worker_thread.quit)
        self.worker.progress.connect(self.update_progress)
        self.worker.uploadProgress.connect(self.update_upload_progress)
        self.worker.started.connect(self.log_start)
        self.worker.skipped.connect(self.log_skip)
        self.worker.failed.connect(self.log_fail)
        self.worker.uploaded.connect(self.log_upload)
        self.worker.updated.connect(self.log_update)
        self.worker.aborted.connect(self.abort)
        self.worker.moveToThread(self.worker_thread)

        self.worker_thread.started.connect(self.worker.start)
        self.worker_thread.start()

    def finish_sync(self):
        if self.in_progress:
            self.msg.setText('Done.')
        self.cancel_btn.hide()
        self.cancel_btn.setEnabled(True)
        self.start_btn.show()
        self.config_btn.setEnabled(True)
        self.sync_all_radio.setEnabled(True)
        self.sync_selected_radio.setEnabled(len(self.selected_book_ids) > 0)

    def abort(self, error):
        self.in_progress = False
        self.msg.setText(error)

    def cancel(self):
        self.in_progress = False
        self.msg.setText('Canceled.')
        self.cancel_btn.setEnabled(False)
        self.worker.cancel()

    def update_progress(self, progress):
        if self.in_progress:
            if isinstance(self.worker, UploadManager):
                msg = 'Synchronizing...'
            else:
                msg = 'Preparing...'
            if progress:
                msg += ' {} of {}'.format(progress + 1, self.total)
            self.msg.setText(msg)

    def update_upload_progress(self, book_id, sent, total):
        if not book_id in self.book_progress_map:
            return

        progress = self.book_progress_map[book_id]

        if sent < total:
            progress.setValue(sent)
            progress.setMaximum(total)
        else:
            progress.setMaximum(0)

    def log_start(self, book_id):
        self.update_log(book_id, None)

    def log_fail(self, book_id, msg):
        self.update_log(book_id, msg)

    def log_skip(self, book_id):
        self.update_log(book_id, 'skipped')

    def log_upload(self, book_id):
        self.update_log(book_id, 'uploaded')

    def log_update(self, book_id):
        self.update_log(book_id, 'updated')

    def toggle_log(self, _):
        self.log.setVisible(not self.log.isVisible())

    def update_log(self, book_id, msg):
        if book_id in self.book_log_map:
            index = self.book_log_map[book_id]
        else:
            index = self.log.rowCount()
            self.book_log_map[book_id] = index

            self.log.insertRow(index)

            title = self.db.get_proxy_metadata(book_id).title
            title_item = QTableWidgetItem(title)
            title_item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled
                                | Qt.ItemNeverHasChildren)
            self.log.setItem(index, 0, title_item)

            progress = QProgressBar()
            progress.setMaximum(0)
            self.log.setCellWidget(index, 1, progress)
            self.book_progress_map[book_id] = progress

        if not msg is None:
            del (self.book_progress_map[book_id])
            self.log.setCellWidget(index, 1, None)

            msg_item = QTableWidgetItem(msg)
            msg_item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled
                              | Qt.ItemNeverHasChildren)
            self.log.setItem(index, 1, msg_item)

    def maybe_cancel(self):
        if self.worker_thread and self.worker_thread.isRunning():
            reply = QMessageBox.question(
                self, 'BookFusion Sync',
                'Are you sure you want to cancel the currently running process?',
                QMessageBox.No | QMessageBox.Yes, QMessageBox.Yes)
            if reply == QMessageBox.Yes:
                self.cancel()
            else:
                return False
        return True
Пример #34
0
    def setup_ui(self):  # {{{
        self._g = g = QHBoxLayout(self)
        self.setLayout(g)
        self._l = l = QVBoxLayout()
        g.addLayout(l)

        fmts = sorted(x.upper() for x in self.fmts)
        self.fmt_choice_box = QGroupBox(_('Choose the format to unpack:'),
                                        self)
        self._fl = fl = QHBoxLayout()
        self.fmt_choice_box.setLayout(self._fl)
        self.fmt_choice_buttons = [QRadioButton(y, self) for y in fmts]
        for x in self.fmt_choice_buttons:
            fl.addWidget(x,
                         stretch=10 if x is self.fmt_choice_buttons[-1] else 0)
        l.addWidget(self.fmt_choice_box)
        self.fmt_choice_box.setVisible(len(fmts) > 1)

        self.help_label = QLabel(
            _('''\
            <h2>About Unpack book</h2>
            <p>Unpack book allows you to fine tune the appearance of an e-book by
            making small changes to its internals. In order to use Unpack book,
            you need to know a little bit about HTML and CSS, technologies that
            are used in e-books. Follow the steps:</p>
            <br>
            <ol>
            <li>Click "Explode book": This will "explode" the book into its
            individual internal components.<br></li>
            <li>Right click on any individual file and select "Open with..." to
            edit it in your favorite text editor.<br></li>
            <li>When you are done: <b>close the file browser window
            and the editor windows you used to make your tweaks</b>. Then click
            the "Rebuild book" button, to update the book in your calibre
            library.</li>
            </ol>'''))
        self.help_label.setWordWrap(True)
        self._fr = QFrame()
        self._fr.setFrameShape(QFrame.VLine)
        g.addWidget(self._fr)
        g.addWidget(self.help_label)

        self._b = b = QGridLayout()
        left, top, right, bottom = b.getContentsMargins()
        top += top
        b.setContentsMargins(left, top, right, bottom)
        l.addLayout(b, stretch=10)

        self.explode_button = QPushButton(QIcon(I('wizard.png')),
                                          _('&Explode book'))
        self.preview_button = QPushButton(QIcon(I('view.png')),
                                          _('&Preview book'))
        self.cancel_button = QPushButton(QIcon(I('window-close.png')),
                                         _('&Cancel'))
        self.rebuild_button = QPushButton(QIcon(I('exec.png')),
                                          _('&Rebuild book'))

        self.explode_button.setToolTip(
            _('Explode the book to edit its components'))
        self.preview_button.setToolTip(_('Preview the result of your changes'))
        self.cancel_button.setToolTip(_('Abort without saving any changes'))
        self.rebuild_button.setToolTip(
            _('Save your changes and update the book in the calibre library'))

        a = b.addWidget
        a(self.explode_button, 0, 0, 1, 1)
        a(self.preview_button, 0, 1, 1, 1)
        a(self.cancel_button, 1, 0, 1, 1)
        a(self.rebuild_button, 1, 1, 1, 1)

        for x in ('explode', 'preview', 'cancel', 'rebuild'):
            getattr(self, x + '_button').clicked.connect(getattr(self, x))

        self.msg = QLabel('dummy', self)
        self.msg.setVisible(False)
        self.msg.setStyleSheet('''
        QLabel {
            text-align: center;
            background-color: white;
            color: black;
            border-width: 1px;
            border-style: solid;
            border-radius: 20px;
            font-size: x-large;
            font-weight: bold;
        }
        ''')

        self.resize(self.sizeHint() + QSize(40, 10))
Пример #35
0
class SchedulerDialog(QDialog):

    SCHEDULE_TYPES = OrderedDict([
            ('days_of_week', DaysOfWeek),
            ('days_of_month', DaysOfMonth),
            ('every_x_days', EveryXDays),
    ])

    download = pyqtSignal(object)

    def __init__(self, recipe_model, parent=None):
        QDialog.__init__(self, parent)
        self.commit_on_change = True
        self.previous_urn = None

        self.setWindowIcon(QIcon(I('scheduler.png')))
        self.setWindowTitle(_("Schedule news download"))
        self.l = l = QGridLayout(self)

        # Left panel
        self.h = h = QHBoxLayout()
        l.addLayout(h, 0, 0, 1, 1)
        self.search = s = SearchBox2(self)
        self.search.initialize('scheduler_search_history')
        self.search.setMinimumContentsLength(15)
        self.go_button = b = QToolButton(self)
        b.setText(_("Go"))
        b.clicked.connect(self.search.do_search)
        h.addWidget(s), h.addWidget(b)
        self.recipes = RecipesView(self)
        l.addWidget(self.recipes, 1, 0, 1, 1)
        self.recipe_model = recipe_model
        self.recipe_model.do_refresh()
        self.recipes.setModel(self.recipe_model)
        self.recipes.setFocus(Qt.OtherFocusReason)
        self.count_label = la = QLabel(_('%s news sources') % self.recipe_model.showing_count)
        la.setAlignment(Qt.AlignCenter)
        l.addWidget(la, 2, 0, 1, 1)
        self.search.search.connect(self.recipe_model.search)
        self.recipe_model.searched.connect(self.search.search_done, type=Qt.QueuedConnection)
        self.recipe_model.searched.connect(self.search_done)

        # Right Panel
        self.scroll_area_contents = sac = QWidget(self)
        self.l.addWidget(sac, 0, 1, 2, 1)
        sac.v = v = QVBoxLayout(sac)
        v.setContentsMargins(0, 0, 0, 0)
        self.detail_box = QTabWidget(self)
        self.detail_box.setVisible(False)
        self.detail_box.setCurrentIndex(0)
        v.addWidget(self.detail_box)
        v.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding))

        # First Tab (scheduling)
        self.tab = QWidget()
        self.detail_box.addTab(self.tab, _("&Schedule"))
        self.tab.v = vt = QVBoxLayout(self.tab)
        vt.setContentsMargins(0, 0, 0, 0)
        self.blurb = la = QLabel('blurb')
        la.setWordWrap(True), la.setOpenExternalLinks(True)
        vt.addWidget(la)
        self.frame = f = QFrame(self.tab)
        vt.addWidget(f)
        f.setFrameShape(f.StyledPanel)
        f.setFrameShadow(f.Raised)
        f.v = vf = QVBoxLayout(f)
        self.schedule = s = QCheckBox(_("&Schedule for download:"), f)
        self.schedule.stateChanged[int].connect(self.toggle_schedule_info)
        vf.addWidget(s)
        f.h = h = QHBoxLayout()
        vf.addLayout(h)
        self.days_of_week = QRadioButton(_("&Days of  week"), f)
        self.days_of_month = QRadioButton(_("Da&ys of month"), f)
        self.every_x_days = QRadioButton(_("Every &x days"), f)
        self.days_of_week.setChecked(True)
        h.addWidget(self.days_of_week), h.addWidget(self.days_of_month), h.addWidget(self.every_x_days)
        self.schedule_stack = ss = QStackedWidget(f)
        self.schedule_widgets = []
        for key in reversed(self.SCHEDULE_TYPES):
            self.schedule_widgets.insert(0, self.SCHEDULE_TYPES[key](self))
            self.schedule_stack.insertWidget(0, self.schedule_widgets[0])
        vf.addWidget(ss)
        self.last_downloaded = la = QLabel(f)
        la.setWordWrap(True)
        vf.addWidget(la)
        self.account = acc = QGroupBox(self.tab)
        acc.setTitle(_("&Account"))
        vt.addWidget(acc)
        acc.g = g = QGridLayout(acc)
        acc.unla = la = QLabel(_("&Username:"******"&Password:"******"&Show password"), self.account)
        spw.stateChanged[int].connect(self.set_pw_echo_mode)
        g.addWidget(spw, 2, 0, 1, 2)
        self.rla = la = QLabel(_("For the scheduling to work, you must leave calibre running."))
        vt.addWidget(la)
        for b, c in iteritems(self.SCHEDULE_TYPES):
            b = getattr(self, b)
            b.toggled.connect(self.schedule_type_selected)
            b.setToolTip(textwrap.dedent(c.HELP))

        # Second tab (advanced settings)
        self.tab2 = t2 = QWidget()
        self.detail_box.addTab(self.tab2, _("&Advanced"))
        self.tab2.g = g = QGridLayout(t2)
        g.setContentsMargins(0, 0, 0, 0)
        self.add_title_tag = tt = QCheckBox(_("Add &title as tag"), t2)
        g.addWidget(tt, 0, 0, 1, 2)
        t2.la = la = QLabel(_("&Extra tags:"))
        self.custom_tags = ct = QLineEdit(self)
        la.setBuddy(ct)
        g.addWidget(la), g.addWidget(ct, 1, 1)
        t2.la2 = la = QLabel(_("&Keep at most:"))
        la.setToolTip(_("Maximum number of copies (issues) of this recipe to keep.  Set to 0 to keep all (disable)."))
        self.keep_issues = ki = QSpinBox(t2)
        tt.toggled['bool'].connect(self.keep_issues.setEnabled)
        ki.setMaximum(100000), la.setBuddy(ki)
        ki.setToolTip(_(
            "<p>When set, this option will cause calibre to keep, at most, the specified number of issues"
            " of this periodical. Every time a new issue is downloaded, the oldest one is deleted, if the"
            " total is larger than this number.\n<p>Note that this feature only works if you have the"
            " option to add the title as tag checked, above.\n<p>Also, the setting for deleting periodicals"
            " older than a number of days, below, takes priority over this setting."))
        ki.setSpecialValueText(_("all issues")), ki.setSuffix(_(" issues"))
        g.addWidget(la), g.addWidget(ki, 2, 1)
        si = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
        g.addItem(si, 3, 1, 1, 1)

        # Bottom area
        self.hb = h = QHBoxLayout()
        self.l.addLayout(h, 2, 1, 1, 1)
        self.labt = la = QLabel(_("Delete downloaded &news older than:"))
        self.old_news = on = QSpinBox(self)
        on.setToolTip(_(
            "<p>Delete downloaded news older than the specified number of days. Set to zero to disable.\n"
            "<p>You can also control the maximum number of issues of a specific periodical that are kept"
            " by clicking the Advanced tab for that periodical above."))
        on.setSpecialValueText(_("never delete")), on.setSuffix(_(" days"))
        on.setMaximum(1000), la.setBuddy(on)
        on.setValue(gconf['oldest_news'])
        h.addWidget(la), h.addWidget(on)
        self.download_all_button = b = QPushButton(QIcon(I('news.png')), _("Download &all scheduled"), self)
        b.setToolTip(_("Download all scheduled news sources at once"))
        b.clicked.connect(self.download_all_clicked)
        self.l.addWidget(b, 3, 0, 1, 1)
        self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
        bb.accepted.connect(self.accept), bb.rejected.connect(self.reject)
        self.download_button = b = bb.addButton(_('&Download now'), bb.ActionRole)
        b.setIcon(QIcon(I('arrow-down.png'))), b.setVisible(False)
        b.clicked.connect(self.download_clicked)
        self.l.addWidget(bb, 3, 1, 1, 1)

        geom = gprefs.get('scheduler_dialog_geometry')
        if geom is not None:
            QApplication.instance().safe_restore_geometry(self, geom)

    def sizeHint(self):
        return QSize(800, 600)

    def set_pw_echo_mode(self, state):
        self.password.setEchoMode(self.password.Normal
                if state == Qt.Checked else self.password.Password)

    def schedule_type_selected(self, *args):
        for i, st in enumerate(self.SCHEDULE_TYPES):
            if getattr(self, st).isChecked():
                self.schedule_stack.setCurrentIndex(i)
                break

    def keyPressEvent(self, ev):
        if ev.key() not in (Qt.Key_Enter, Qt.Key_Return):
            return QDialog.keyPressEvent(self, ev)

    def break_cycles(self):
        try:
            self.recipe_model.searched.disconnect(self.search_done)
            self.recipe_model.searched.disconnect(self.search.search_done)
            self.search.search.disconnect()
            self.download.disconnect()
        except:
            pass
        self.recipe_model = None

    def search_done(self, *args):
        if self.recipe_model.showing_count < 10:
            self.recipes.expandAll()

    def toggle_schedule_info(self, *args):
        enabled = self.schedule.isChecked()
        for x in self.SCHEDULE_TYPES:
            getattr(self, x).setEnabled(enabled)
        self.schedule_stack.setEnabled(enabled)
        self.last_downloaded.setVisible(enabled)

    def current_changed(self, current, previous):
        if self.previous_urn is not None:
            self.commit(urn=self.previous_urn)
            self.previous_urn = None

        urn = self.current_urn
        if urn is not None:
            self.initialize_detail_box(urn)
        self.recipes.scrollTo(current)

    def accept(self):
        if not self.commit():
            return False
        self.save_geometry()
        return QDialog.accept(self)

    def reject(self):
        self.save_geometry()
        return QDialog.reject(self)

    def save_geometry(self):
        gprefs.set('scheduler_dialog_geometry', bytearray(self.saveGeometry()))

    def download_clicked(self, *args):
        self.commit()
        if self.commit() and self.current_urn:
            self.download.emit(self.current_urn)

    def download_all_clicked(self, *args):
        if self.commit() and self.commit():
            self.download.emit(None)

    @property
    def current_urn(self):
        current = self.recipes.currentIndex()
        if current.isValid():
            return getattr(current.internalPointer(), 'urn', None)

    def commit(self, urn=None):
        urn = self.current_urn if urn is None else urn
        if not self.detail_box.isVisible() or urn is None:
            return True

        if self.account.isVisible():
            un, pw = map(unicode_type, (self.username.text(), self.password.text()))
            un, pw = un.strip(), pw.strip()
            if not un and not pw and self.schedule.isChecked():
                if not getattr(self, 'subscription_optional', False):
                    error_dialog(self, _('Need username and password'),
                            _('You must provide a username and/or password to '
                                'use this news source.'), show=True)
                    return False
            if un or pw:
                self.recipe_model.set_account_info(urn, un, pw)
            else:
                self.recipe_model.clear_account_info(urn)

        if self.schedule.isChecked():
            schedule_type, schedule = \
                    self.schedule_stack.currentWidget().schedule
            self.recipe_model.schedule_recipe(urn, schedule_type, schedule)
        else:
            self.recipe_model.un_schedule_recipe(urn)

        add_title_tag = self.add_title_tag.isChecked()
        keep_issues = '0'
        if self.keep_issues.isEnabled():
            keep_issues = unicode_type(self.keep_issues.value())
        custom_tags = unicode_type(self.custom_tags.text()).strip()
        custom_tags = [x.strip() for x in custom_tags.split(',')]
        self.recipe_model.customize_recipe(urn, add_title_tag, custom_tags, keep_issues)
        return True

    def initialize_detail_box(self, urn):
        self.previous_urn = urn
        self.detail_box.setVisible(True)
        self.download_button.setVisible(True)
        self.detail_box.setCurrentIndex(0)
        recipe = self.recipe_model.recipe_from_urn(urn)
        try:
            schedule_info = self.recipe_model.schedule_info_from_urn(urn)
        except:
            # Happens if user does something stupid like unchecking all the
            # days of the week
            schedule_info = None
        account_info = self.recipe_model.account_info_from_urn(urn)
        customize_info = self.recipe_model.get_customize_info(urn)

        ns = recipe.get('needs_subscription', '')
        self.account.setVisible(ns in ('yes', 'optional'))
        self.subscription_optional = ns == 'optional'
        act = _('Account')
        act2 = _('(optional)') if self.subscription_optional else \
                _('(required)')
        self.account.setTitle(act+' '+act2)
        un = pw = ''
        if account_info is not None:
            un, pw = account_info[:2]
            if not un:
                un = ''
            if not pw:
                pw = ''
        self.username.setText(un)
        self.password.setText(pw)
        self.show_password.setChecked(False)

        self.blurb.setText('''
        <p>
        <b>%(title)s</b><br>
        %(cb)s %(author)s<br/>
        %(description)s
        </p>
        '''%dict(title=recipe.get('title'), cb=_('Created by: '),
            author=recipe.get('author', _('Unknown')),
            description=recipe.get('description', '')))
        self.download_button.setToolTip(
                _('Download %s now')%recipe.get('title'))
        scheduled = schedule_info is not None
        self.schedule.setChecked(scheduled)
        self.toggle_schedule_info()
        self.last_downloaded.setText(_('Last downloaded: never'))
        ld_text = _('never')
        if scheduled:
            typ, sch, last_downloaded = schedule_info
            d = utcnow() - last_downloaded

            def hm(x):
                return (x-x%3600)//3600, (x%3600 - (x%3600)%60)//60
            hours, minutes = hm(d.seconds)
            tm = _('%(days)d days, %(hours)d hours'
                    ' and %(mins)d minutes ago')%dict(
                            days=d.days, hours=hours, mins=minutes)
            if d < timedelta(days=366):
                ld_text = tm
        else:
            typ, sch = 'day/time', (-1, 6, 0)
        sch_widget = {'day/time': 0, 'days_of_week': 0, 'days_of_month':1,
                'interval':2}[typ]
        rb = getattr(self, list(self.SCHEDULE_TYPES)[sch_widget])
        rb.setChecked(True)
        self.schedule_stack.setCurrentIndex(sch_widget)
        self.schedule_stack.currentWidget().initialize(typ, sch)
        add_title_tag, custom_tags, keep_issues = customize_info
        self.add_title_tag.setChecked(add_title_tag)
        self.custom_tags.setText(', '.join(custom_tags))
        self.last_downloaded.setText(_('Last downloaded:') + ' ' + ld_text)
        try:
            keep_issues = int(keep_issues)
        except:
            keep_issues = 0
        self.keep_issues.setValue(keep_issues)
        self.keep_issues.setEnabled(self.add_title_tag.isChecked())
Пример #36
0
class Editor(QFrame):  # {{{

    editing_done = pyqtSignal(object)

    def __init__(self, parent=None):
        QFrame.__init__(self, parent)
        self.setFocusPolicy(Qt.StrongFocus)
        self.setAutoFillBackground(True)
        self.capture = 0

        self.setFrameShape(self.StyledPanel)
        self.setFrameShadow(self.Raised)
        self._layout = l = QGridLayout(self)
        self.setLayout(l)

        self.header = QLabel('')
        l.addWidget(self.header, 0, 0, 1, 2)

        self.use_default = QRadioButton('')
        self.use_custom = QRadioButton(_('Custom'))
        l.addWidget(self.use_default, 1, 0, 1, 3)
        l.addWidget(self.use_custom, 2, 0, 1, 3)
        self.use_custom.toggled.connect(self.custom_toggled)

        off = 2
        for which in (1, 2):
            text = _('&Shortcut:') if which == 1 else _('&Alternate shortcut:')
            la = QLabel(text)
            la.setStyleSheet('QLabel { margin-left: 1.5em }')
            l.addWidget(la, off+which, 0, 1, 3)
            setattr(self, 'label%d'%which, la)
            button = QPushButton(_('None'), self)
            button.clicked.connect(partial(self.capture_clicked, which=which))
            button.keyPressEvent = partial(self.key_press_event, which=which)
            setattr(self, 'button%d'%which, button)
            clear = QToolButton(self)
            clear.setIcon(QIcon(I('clear_left.png')))
            clear.clicked.connect(partial(self.clear_clicked, which=which))
            setattr(self, 'clear%d'%which, clear)
            l.addWidget(button, off+which, 1, 1, 1)
            l.addWidget(clear, off+which, 2, 1, 1)
            la.setBuddy(button)

        self.done_button = doneb = QPushButton(_('Done'), self)
        l.addWidget(doneb, 0, 2, 1, 1)
        doneb.clicked.connect(lambda : self.editing_done.emit(self))
        l.setColumnStretch(0, 100)

        self.custom_toggled(False)

    def initialize(self, shortcut, all_shortcuts):
        self.header.setText('<b>%s: %s</b>'%(_('Customize'), shortcut['name']))
        self.all_shortcuts = all_shortcuts
        self.shortcut = shortcut

        self.default_keys = [QKeySequence(k, QKeySequence.PortableText) for k
                in shortcut['default_keys']]
        self.current_keys = list(shortcut['keys'])
        default = ', '.join([unicode(k.toString(k.NativeText)) for k in
                    self.default_keys])
        if not default:
            default = _('None')
        current = ', '.join([unicode(k.toString(k.NativeText)) for k in
                    self.current_keys])
        if not current:
            current = _('None')

        self.use_default.setText(_('Default: %(deflt)s [Currently not conflicting: %(curr)s]')%
                dict(deflt=default, curr=current))

        if shortcut['set_to_default']:
            self.use_default.setChecked(True)
        else:
            self.use_custom.setChecked(True)
            for key, which in zip(self.current_keys, [1,2]):
                button = getattr(self, 'button%d'%which)
                button.setText(key.toString(key.NativeText))

    def custom_toggled(self, checked):
        for w in ('1', '2'):
            for o in ('label', 'button', 'clear'):
                getattr(self, o+w).setEnabled(checked)

    def capture_clicked(self, which=1):
        self.capture = which
        button = getattr(self, 'button%d'%which)
        button.setText(_('Press a key...'))
        button.setFocus(Qt.OtherFocusReason)
        button.setStyleSheet('QPushButton { font-weight: bold}')

    def clear_clicked(self, which=0):
        button = getattr(self, 'button%d'%which)
        button.setText(_('None'))

    def key_press_event(self, ev, which=0):
        if self.capture == 0:
            return QWidget.keyPressEvent(self, ev)
        sequence = keysequence_from_event(ev)
        if sequence is None:
            return QWidget.keyPressEvent(self, ev)
        ev.accept()

        button = getattr(self, 'button%d'%which)
        button.setStyleSheet('QPushButton { font-weight: normal}')
        button.setText(sequence.toString(QKeySequence.NativeText))
        self.capture = 0
        dup_desc = self.dup_check(sequence)
        if dup_desc is not None:
            error_dialog(self, _('Already assigned'),
                    unicode(sequence.toString(QKeySequence.NativeText)) + ' ' +
                    _('already assigned to') + ' ' + dup_desc, show=True)
            self.clear_clicked(which=which)

    def dup_check(self, sequence):
        for sc in self.all_shortcuts:
            if sc is self.shortcut:
                continue
            for k in sc['keys']:
                if k == sequence:
                    return sc['name']

    @property
    def custom_keys(self):
        if self.use_default.isChecked():
            return None
        ans = []
        for which in (1, 2):
            button = getattr(self, 'button%d'%which)
            t = unicode(button.text())
            if t == _('None'):
                continue
            ks = QKeySequence(t, QKeySequence.NativeText)
            if not ks.isEmpty():
                ans.append(ks)
        return tuple(ans)