Exemplo n.º 1
0
    def __init__(self, *args, **kwrgs):

        existing_widgets = Window.mayaWin.findChildren(QDialog,
                                                       Window.objectName)
        if existing_widgets: map(lambda x: x.deleteLater(), existing_widgets)

        super(Window, self).__init__(*args, **kwrgs)

        self.installEventFilter(self)
        self.setObjectName(Window.objectName)
        self.setWindowTitle(Window.title)
        mainLayout = QVBoxLayout(self)

        w_splitter = Widget_splitter(QtCore.Qt.Vertical)
        w_typeAttrList = Widget_TypeAttributeList()
        w_fileTree = Widget_FileTree()
        button_refresh = QPushButton("REFRESH".decode('utf-8'))
        button_refresh.setStyleSheet("font-size:13px")

        w_splitter.addWidget(w_typeAttrList)
        w_splitter.addWidget(w_fileTree)

        mainLayout.addWidget(w_splitter)
        mainLayout.addWidget(button_refresh)
        button_refresh.setFocus()

        self.w_typeAttrList = w_typeAttrList
        self.w_fileTree = w_fileTree

        self.resize(Window.defaultWidth, Window.defaultHeight)
        self.load_shapeInfo(Window.path_uiInfo)

        QtCore.QObject.connect(button_refresh, QtCore.SIGNAL("clicked()"),
                               self.w_fileTree.loadList)
        self.w_fileTree.w_typeAttrList = self.w_typeAttrList
        self.w_fileTree.loadList()

        self.w_typeAttrList.appendCheckEventCommands(self.w_fileTree.loadList)
        w_splitter.loadSplitterPosition()
Exemplo n.º 2
0
class Form(QDialog):
    def __init__(self, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)
        self.setWindowTitle("Copy Character — {}".format(
            QApplication.applicationName()))
        QShortcut(QKeySequence(QKeySequence.FindNext), self, self.findNext)
        self.state = state
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.findSizes(self.fontComboBox.currentFont())
        self.setToFamily(self.state.stdFontFamily)
        self.setToNearestSize(self.state.stdFontSize)
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        self.fontLabel = QLabel("Fon&t:")
        self.fontComboBox = QFontComboBox()
        self.tooltips.append((self.fontComboBox, """\
<p><b>Font</b></p>
<p>The font for displaying the characters.</p>"""))
        self.fontLabel.setBuddy(self.fontComboBox)
        self.sizeLabel = QLabel("&Size:")
        self.sizeComboBox = QComboBox()
        self.tooltips.append((self.sizeComboBox, """\
<p><b>Size</b></p>
<p>The size of font for displaying the characters.</p>"""))
        self.sizeLabel.setBuddy(self.sizeComboBox)
        self.scrollArea = QScrollArea()
        self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.panel = Panel()
        self.scrollArea.setWidget(self.panel)
        self.copyTextLabel = QLabel("Copy T&ext")
        self.copyTextLineEdit = QLineEdit()
        self.tooltips.append((self.copyTextLineEdit, """\
<p><b>Copy Text editor</b></p>
<p>The text for copying to the clipboard when <b>Copy</b> is
pressed.</p>"""))
        self.copyTextLabel.setBuddy(self.copyTextLineEdit)
        self.findTextLabel = QLabel("&Find Text")
        self.findTextLineEdit = QLineEdit()
        self.tooltips.append((self.findTextLineEdit, """\
<p><b>Find Text editor</b></p>
<p>The name or partial name of Unicode characters to be found, e.g.,
“star” will match many characters, including U+22C6 “Star
operator”.</p>"""))
        self.findTextLabel.setBuddy(self.findTextLineEdit)
        self.buttonBox = QDialogButtonBox()
        self.addSelectedButton = QPushButton(QIcon(":/add.svg"),
                                             "&Add Selected")
        self.tooltips.append((self.addSelectedButton, """\
<p><b>Add Selected</b></p>
<p>Append the selected character to the <b>Copy Text</b> editor.</p>"""))
        self.buttonBox.addButton(self.addSelectedButton,
                                 QDialogButtonBox.ActionRole)
        self.findNextButton = QPushButton(QIcon(":/edit-find.svg"),
                                          "Find &Next")
        self.tooltips.append((self.findNextButton, """\
<p><b>Find Next</b></p>
<p>Find the next character whose Unicode name contains or equals the
<b>Find Text</b>.</p>"""))
        self.buttonBox.addButton(self.findNextButton,
                                 QDialogButtonBox.ActionRole)
        self.helpButton = QPushButton(QIcon(":/help.svg"), "Help")
        self.tooltips.append(
            (self.helpButton, "Help on the Copy Character dialog"))
        self.buttonBox.addButton(self.helpButton, QDialogButtonBox.HelpRole)
        self.closeButton = QPushButton(QIcon(":/dialog-close.svg"), "&Close")
        self.tooltips.append((self.closeButton, """<p><b>Cancel</b></p>
<p>Close the dialog.</p>"""))
        self.buttonBox.addButton(self.closeButton, QDialogButtonBox.RejectRole)

    def layoutWidgets(self):
        topLayout = QHBoxLayout()
        topLayout.addWidget(self.fontLabel)
        topLayout.addWidget(self.fontComboBox, 1)
        topLayout.addWidget(self.sizeLabel)
        topLayout.addWidget(self.sizeComboBox)

        bottomLayout = QHBoxLayout()
        bottomLayout.addWidget(self.copyTextLabel)
        bottomLayout.addWidget(self.copyTextLineEdit)
        bottomLayout.addWidget(self.findTextLabel)
        bottomLayout.addWidget(self.findTextLineEdit)

        layout = QVBoxLayout()
        layout.addLayout(topLayout)
        layout.addWidget(self.scrollArea, 1)
        layout.addLayout(bottomLayout)
        layout.addWidget(self.buttonBox)
        self.setLayout(layout)

    def createConnections(self):
        self.fontComboBox.activated[str].connect(self.panel.updateFont)
        self.sizeComboBox.currentIndexChanged[str].connect(
            self.panel.updateSize)
        self.panel.characterSelected.connect(self.copyTextLineEdit.insert)
        self.panel.fontResized.connect(self.updateSize)
        self.addSelectedButton.clicked.connect(self.addSelected)
        self.helpButton.clicked.connect(self.help)
        self.buttonBox.rejected.connect(self.accept)
        self.findNextButton.clicked.connect(self.findNext)
        self.findTextLineEdit.returnPressed.connect(self.findNext)

    def help(self):
        self.state.help("xix_ref_dlg_copychr.html")

    def findSizes(self, font):
        fontDatabase = QFontDatabase()
        currentSize = self.sizeComboBox.currentText()
        with Lib.BlockSignals(self.sizeComboBox):
            self.sizeComboBox.clear()
            if fontDatabase.isSmoothlyScalable(font.family(),
                                               fontDatabase.styleString(font)):
                for size in QFontDatabase.standardSizes():
                    self.sizeComboBox.addItem(str(size))
            else:
                for size in fontDatabase.smoothSizes(
                        font.family(), fontDatabase.styleString(font)):
                    self.sizeComboBox.addItem(str(size))
            self.sizeComboBox.setEditable(False)
        sizeIndex = self.sizeComboBox.findText(currentSize)
        if sizeIndex == -1:
            self.sizeComboBox.setCurrentIndex(
                max(0,
                    self.sizeComboBox.count() / 3))
        else:
            self.sizeComboBox.setCurrentIndex(sizeIndex)

    def accept(self):
        clipboard = QApplication.clipboard()
        text = self.copyTextLineEdit.text() or self.panel.currentChar
        clipboard.setText(text, QClipboard.Clipboard)
        clipboard.setText(text, QClipboard.Selection)
        if text:
            say("Copied “{}” to the clipboard".format(text), SAY_TIMEOUT)
        super().accept()

    def addSelected(self):
        char = self.panel.currentChar
        if char:
            self.copyTextLineEdit.setText(self.copyTextLineEdit.text() + char)
        self.findNextButton.setFocus()

    def setToFamily(self, family):
        family = family.casefold()
        for i in range(self.fontComboBox.count()):
            if self.fontComboBox.itemText(i).casefold() == family:
                self.fontComboBox.setCurrentIndex(i)
                break

    def setToNearestSize(self, size):
        below = 0
        belowIndex = -1
        above = 999
        aboveIndex = -1
        for i in range(self.sizeComboBox.count()):
            sz = int(self.sizeComboBox.itemText(i))
            if sz == size:
                self.sizeComboBox.setCurrentIndex(i)
                break
            if sz < size and sz > below:
                below = sz
                belowIndex = i
            if sz > size and sz < above:
                above = sz
                aboveIndex = i
        else:
            if abs(size - below) < abs(size - above):
                self.sizeComboBox.setCurrentIndex(belowIndex)
            else:
                self.sizeComboBox.setCurrentIndex(aboveIndex)

    def findNext(self):
        text = self.findTextLineEdit.text().strip().casefold()
        if text:
            start = self.panel.currentChar
            start = ord(start) if start else ord(" ")
            for i in range(start + 1, MAX_CHAR):
                try:
                    char = chr(i)
                    name = unicodedata.name(char).casefold()
                    if text in name:
                        self.panel.currentChar = char
                        self.panel.update()
                        y = (self.panel.squareSize * i) // COLUMNS
                        self.scrollArea.ensureVisible(0, y)
                        break
                except ValueError:
                    pass
            else:
                self.panel.currentChar = " "
                self.findNext()

    def keyPressEvent(self, event):
        key = event.key()
        if key in {Qt.Key_Enter, Qt.Key_Return}:
            if self.findTextLineEdit.text().strip():
                self.findNext()
            else:
                self.addSelectedButton.setFocus()

    def updateSize(self, squareSize):
        self.setMinimumWidth((COLUMNS + (1.5 if WIN else 1)) * squareSize)
Exemplo n.º 3
0
class Mixin:
    def createWidgets(self):
        settings = QSettings()

        self.searchLabel = QLabel("Search For")
        self.searchLineEdit = QLineEdit()
        self.tooltips.append((self.searchLineEdit, """\
<p><b>Search For editor</b></p>
<p>The text or regular expression to search for.</p>"""))
        self.searchLabel.setBuddy(self.searchLineEdit)
        self.replaceLabel = QLabel("Replace With")
        self.replaceLineEdit = QLineEdit()
        self.tooltips.append((self.replaceLineEdit, """\
<p><b>Replace With editor</b></p>
<p>The replacement text (which may include backreferences, \\1, \\2,
etc., if a regular expression search is being made).</p>"""))
        self.replaceLabel.setBuddy(self.replaceLineEdit)

        self.allEntriesRadioButton = QRadioButton("All Entries")
        self.allEntriesRadioButton.setChecked(
            bool(int(settings.value("RP/All", 1))))
        self.tooltips.append((self.allEntriesRadioButton, """\
<p><b>All Entries</b></p>
<p>If checked, the search will consider every entry in the index.</p>"""))
        self.filteredEntriesRadioButton = QRadioButton("Filtered Entries")
        self.filteredEntriesRadioButton.setChecked(
            bool(int(settings.value("RP/Filtered", 0))))
        self.tooltips.append((self.filteredEntriesRadioButton, """\
<p><b>Filtered Entries</b></p>
<p>If checked, the search will consider only those entries that are in
the current filtered view.</p>"""))
        self.considerLabel = QLabel("Consider")
        self.scopeGroup = QButtonGroup()
        self.scopeGroup.addButton(self.allEntriesRadioButton)
        self.scopeGroup.addButton(self.filteredEntriesRadioButton)

        self.literalRadioButton = QRadioButton("Literal")
        self.literalRadioButton.setChecked(
            bool(int(settings.value("RP/Literal", 1))))
        self.tooltips.append((self.literalRadioButton, """<p><b>Literal</b></p>
<p>If checked, the <b>Search For</b> text will be searched for
literally.</p>"""))
        self.regexRadioButton = QRadioButton("Regex")
        self.regexRadioButton.setChecked(
            bool(int(settings.value("RP/Regex", 0))))
        self.tooltips.append((self.regexRadioButton, """<p><b>Regex</b></p>
<p>If checked, the <b>Search For</b> text will be searched for
as a regular expression pattern.</p>"""))
        self.matchAsGroup = QButtonGroup()
        self.matchAsGroup.addButton(self.literalRadioButton)
        self.matchAsGroup.addButton(self.regexRadioButton)
        self.ignoreCaseCheckBox = QCheckBox("Ignore Case")
        self.ignoreCaseCheckBox.setChecked(
            bool(int(settings.value("RP/ICase", 0))))
        self.tooltips.append((self.ignoreCaseCheckBox, """\
<p><b>Ignore Case</b></p>
<p>If checked, the <b>Search For</b> text will be searched for
case-insensitively.</p>"""))
        self.wholeWordsCheckBox = QCheckBox("Whole Words")
        self.wholeWordsCheckBox.setChecked(
            bool(int(settings.value("RP/WW", 0))))
        self.tooltips.append((self.wholeWordsCheckBox, """\
<p><b>Whole Words</b></p>
<p>If checked&mdash;and when <b>Literal</b> is checked&mdash;the
<b>Search For</b> text will be matched as whole words.</p>
<p>For example, “habit” will not match “habitat” when whole words is
checked.</p>
<p>(For regular expressions use \\b before and after each word to get
whole word matches.)</p>"""))

        self.replaceInLabel = QLabel("Look In")
        self.replaceInTermsCheckBox = QCheckBox("Terms")
        self.replaceInTermsCheckBox.setChecked(
            bool(int(settings.value("RP/Terms", 1))))
        self.tooltips.append((self.replaceInTermsCheckBox, """\
<p><b>Terms</b></p>
<p>If checked, the search will look in term texts.</p>"""))
        self.replaceInPagesCheckBox = QCheckBox("Pages")
        self.replaceInPagesCheckBox.setChecked(
            bool(int(settings.value("RP/Pages", 0))))
        self.tooltips.append((self.replaceInPagesCheckBox, """\
<p><b>Pages</b></p>
<p>If checked, the search will look in pages texts.</p>"""))
        self.replaceInNotesCheckBox = QCheckBox("Notes")
        self.replaceInNotesCheckBox.setChecked(
            bool(int(settings.value("RP/Notes", 0))))
        self.tooltips.append((self.replaceInNotesCheckBox, """\
<p><b>Notes</b></p>
<p>If checked, the search will look in notes texts.</p>"""))
        self.startButton = QPushButton(QIcon(":/edit-find.svg"),
                                       "Start Search")
        self.tooltips.append((self.startButton, """<p><b>Start Search</b></p>
<p>Start the search from the first entry in the index or the first entry
in the filtered view's entries.</p>"""))
        self.replaceButton = QPushButton(QIcon(":/edit-find-replace.svg"),
                                         "Replace")
        self.tooltips.append((self.replaceButton, """<p><b>Replace</b></p>
<p>Replace the highlighted text with the <b>Replace With</b> text (using
backreferences if they are in the replacement text and a <b>Regex</b>
search is underway), and then try to find the next matching text.</p>"""))
        self.skipButton = QPushButton(QIcon(":/skip.svg"), "S&kip")
        self.tooltips.append((self.skipButton, """<p><b>Skip</b></p>
<p>Skip the highlighted text and try to find the next matching
text.</p>"""))
        self.stopButton = QPushButton(QIcon(":/process-stop.svg"),
                                      "Stop Search")
        self.tooltips.append((self.stopButton, """<p><b>Stop Search</b></p>
<p>Stop the current search. This allows the search options to be
changed.</p>"""))
        self.closeButton = QToolButton()
        self.closeButton.setIcon(QIcon(":/hide.svg"))
        self.closeButton.setFocusPolicy(Qt.NoFocus)
        self.tooltips.append((self.closeButton, """<p><b>Hide</b></p>
<p>Hide the Search and Replace panel.</p>
<p>Press <b>Ctrl+H</b> or click <img src=":/edit-find-replace.svg"
width={0} height={0}> or click <b>Edit→Search and Replace</b> to show it
again.</p>""".format(TOOLTIP_IMAGE_SIZE)))
        self.helpButton = QToolButton()
        self.helpButton.setIcon(QIcon(":/help.svg"))
        self.helpButton.setFocusPolicy(Qt.NoFocus)
        self.tooltips.append(
            (self.helpButton, "Help on the Search and Replace panel."))

    def layoutWidgets(self):
        form = QFormLayout()
        hbox = QHBoxLayout()
        hbox.addWidget(self.searchLineEdit)
        hbox.addWidget(self.closeButton)
        form.addRow(self.searchLabel, hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.replaceLineEdit)
        hbox.addWidget(self.helpButton)
        form.addRow(self.replaceLabel, hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.allEntriesRadioButton)
        hbox.addWidget(self.filteredEntriesRadioButton)
        hbox.addStretch()
        form.addRow(self.considerLabel, hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.literalRadioButton)
        hbox.addWidget(self.regexRadioButton)
        hbox.addStretch(1)
        hbox.addWidget(self.ignoreCaseCheckBox)
        hbox.addWidget(self.wholeWordsCheckBox)
        hbox.addStretch(5)
        form.addRow(QLabel("Match"), hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.replaceInTermsCheckBox)
        hbox.addWidget(self.replaceInPagesCheckBox)
        hbox.addWidget(self.replaceInNotesCheckBox)
        hbox.addStretch()
        form.addRow(self.replaceInLabel, hbox)
        hbox = QHBoxLayout()
        hbox.addWidget(self.startButton)
        hbox.addWidget(self.replaceButton)
        hbox.addWidget(self.skipButton)
        hbox.addWidget(self.stopButton)
        hbox.addStretch()
        form.addRow(hbox)
        self.setLayout(form)

    def createConnections(self):
        self.helpButton.clicked.connect(self.help)
        self.stopButton.clicked.connect(self.stop)
        self.startButton.clicked.connect(self.start)
        self.replaceButton.clicked.connect(self.replace)
        self.skipButton.clicked.connect(self.skip)
        self.searchLineEdit.textChanged.connect(self.updateUi)
        self.searchLineEdit.returnPressed.connect(self.doAction)
        self.replaceLineEdit.textChanged.connect(self.updateUi)
        self.replaceLineEdit.returnPressed.connect(self.doAction)
        for button in (self.literalRadioButton, self.regexRadioButton,
                       self.ignoreCaseCheckBox, self.wholeWordsCheckBox,
                       self.replaceInTermsCheckBox,
                       self.replaceInPagesCheckBox,
                       self.replaceInNotesCheckBox):
            button.clicked.connect(self.updateUi)

    def doAction(self):
        button = None
        if self.skipButton.isEnabled():
            button = self.skipButton
        elif self.startButton.isEnabled():
            button = self.startButton
        if button is not None:
            button.setFocus()
            button.click()
        if self.skipButton.isEnabled():
            self.skipButton.setFocus()

    def help(self):
        self.state.help("xix_ref_panel_replace.html")
Exemplo n.º 4
0
class MainWindow(QWidget):
    # noinspection PyUnresolvedReferences
    def __init__(self, clipboard):
        super().__init__()
        self.clipboard = clipboard
        self.setWindowIcon(QIcon('Logo_rendered_edited.png'))
        self.layout = QBoxLayout(QBoxLayout.TopToBottom, self)
        self.generator = CtSesam()
        self.iterations = 4096
        # Master password
        self.master_password_label = QLabel("&Master-Passwort:")
        self.maser_password_edit = QLineEdit()
        self.maser_password_edit.setEchoMode(QLineEdit.EchoMode.Password)
        self.maser_password_edit.textChanged.connect(self.reset_iterations)
        self.maser_password_edit.returnPressed.connect(self.move_focus)
        self.maser_password_edit.setMaximumHeight(28)
        self.master_password_label.setBuddy(self.maser_password_edit)
        self.layout.addWidget(self.master_password_label)
        self.layout.addWidget(self.maser_password_edit)
        # Domain
        self.domain_label = QLabel("&Domain:")
        self.domain_edit = QLineEdit()
        self.domain_edit.textChanged.connect(self.reset_iterations)
        self.domain_edit.returnPressed.connect(self.move_focus)
        self.domain_edit.setMaximumHeight(28)
        self.domain_label.setBuddy(self.domain_edit)
        self.layout.addWidget(self.domain_label)
        self.layout.addWidget(self.domain_edit)
        # Username
        self.username_label = QLabel("&Username:"******"Sonderzeichen")
        self.special_characters_checkbox.setChecked(True)
        self.special_characters_checkbox.stateChanged.connect(self.reset_iterations)
        self.layout.addWidget(self.special_characters_checkbox)
        self.letters_checkbox = QCheckBox("Buchstaben")
        self.letters_checkbox.setChecked(True)
        self.letters_checkbox.stateChanged.connect(self.reset_iterations)
        self.layout.addWidget(self.letters_checkbox)
        self.digits_checkbox = QCheckBox("Zahlen")
        self.digits_checkbox.setChecked(True)
        self.digits_checkbox.stateChanged.connect(self.reset_iterations)
        self.layout.addWidget(self.digits_checkbox)
        # Length slider
        self.length_label = QLabel("&Länge:")
        self.length_display = QLabel()
        self.length_label_layout = QBoxLayout(QBoxLayout.LeftToRight)
        self.length_label_layout.addWidget(self.length_label)
        self.length_label_layout.addWidget(self.length_display)
        self.length_label_layout.addStretch()
        self.length_slider = QSlider(Qt.Horizontal)
        self.length_slider.setMinimum(4)
        self.length_slider.setMaximum(20)
        self.length_slider.setPageStep(1)
        self.length_slider.setValue(10)
        self.length_display.setText(str(self.length_slider.sliderPosition()))
        self.length_slider.valueChanged.connect(self.length_slider_changed)
        self.length_label.setBuddy(self.length_slider)
        self.layout.addLayout(self.length_label_layout)
        self.layout.addWidget(self.length_slider)
        # Button
        self.generate_button = QPushButton("Erzeugen")
        self.generate_button.clicked.connect(self.generate_password)
        self.generate_button.setAutoDefault(True)
        self.layout.addWidget(self.generate_button)
        # Password
        self.password_label = QLabel("&Passwort:")
        self.password = QLabel()
        self.password.setTextFormat(Qt.PlainText)
        self.password.setAlignment(Qt.AlignCenter)
        self.password.setFont(QFont("Helvetica", 18, QFont.Bold))
        self.password_label.setBuddy(self.password)
        self.layout.addWidget(self.password_label)
        self.layout.addWidget(self.password)
        # Iteration display
        self.message_label = QLabel()
        self.message_label.setTextFormat(Qt.RichText)
        self.message_label.setVisible(False)
        self.layout.addWidget(self.message_label)
        # Window layout
        self.layout.addStretch()
        self.setGeometry(0, 30, 300, 400)
        self.setWindowTitle("c't SESAM")
        self.maser_password_edit.setFocus()
        self.show()

    def length_slider_changed(self):
        self.length_display.setText(str(self.length_slider.sliderPosition()))
        self.reset_iterations()

    def reset_iterations(self):
        self.iterations = 4096
        self.message_label.setVisible(False)
        self.password.setText('')
        self.clipboard.setText('')

    def move_focus(self):
        line_edits = [self.maser_password_edit, self.domain_edit, self.username_edit]
        for i, edit in enumerate(line_edits):
            if edit.hasFocus() and i + 1 < len(line_edits):
                line_edits[i + 1].setFocus()
                return True
        self.generate_button.setFocus()

    def generate_password(self):
        if len(self.domain_edit.text()) <= 0:
            self.reset_iterations()
            self.message_label.setText(
                '<span style="font-size: 10px; color: #aa0000;">Bitte geben Sie eine Domain an.</span>')
            self.message_label.setVisible(True)
            return False
        if self.letters_checkbox.isChecked() or \
           self.digits_checkbox.isChecked() or \
           self.special_characters_checkbox.isChecked():
            self.generator.set_password_characters(
                use_letters=self.letters_checkbox.isChecked(),
                use_digits=self.digits_checkbox.isChecked(),
                use_special_characters=self.special_characters_checkbox.isChecked())
        else:
            self.reset_iterations()
            self.message_label.setText(
                '<span style="font-size: 10px; color: #aa0000;">Bei den aktuellen Einstellungen ' +
                'kann kein Passwort berechnet werden.</span>')
            self.message_label.setVisible(True)
            return False
        password = self.generator.generate(
            master_password=self.maser_password_edit.text(),
            domain=self.domain_edit.text(),
            username=self.username_edit.text(),
            length=self.length_slider.sliderPosition(),
            iterations=self.iterations
        )
        self.password.setText(password)
        self.password.setTextInteractionFlags(Qt.TextSelectableByMouse | Qt.TextSelectableByKeyboard)
        self.clipboard.setText(password)
        self.message_label.setText(
            '<span style="font-size: 10px; color: #888888;">Das Passwort wurde ' + str(self.iterations) +
            ' mal gehasht <br />und in die Zwischenablage kopiert.</span>')
        self.message_label.setVisible(True)
        self.iterations += 1
Exemplo n.º 5
0
class DirectoryDetectWindow(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.setWindowTitle('Directory Detective Tool')
        main_layout = QVBoxLayout()

        path_layout = self._init_path_layout()
        guide_layout = self._init_guide_layout()
        detail_layout = self._init_detail_layout()

        main_layout.addLayout(path_layout)
        main_layout.addLayout(guide_layout)
        main_layout.addLayout(detail_layout)
        self.setLayout(main_layout)
        self.setGeometry(300, 300, 400, 350)
        self._connect()

        self._walk_folder = None
        self._last_path = None
        self.directory_info = None
        self._button_list = list()
        self._last_info = None

    def _init_path_layout(self):
        path_layout = QHBoxLayout()
        self.input_path = QLineEdit(self)
        self.input_path.setFixedHeight(35)
        self.input_path.setPlaceholderText('Type search path here')
        self.button_path = QPushButton('Scan', self)
        self.button_path.setFixedHeight(35)
        self.button_path.setFocus()

        path_layout.addWidget(QLabel('Path:', self))
        path_layout.addWidget(self.input_path, stretch=True)
        path_layout.addWidget(self.button_path)
        return path_layout

    def _init_guide_layout(self):
        self.guide_layout = QHBoxLayout()
        self.guide_layout.setAlignment(Qt.AlignLeft)
        return self.guide_layout

    def refresh_trees(self, store_list, ignore_list):
        self._refresh_key_tree(store_list, ignore_list=ignore_list)
        self._refresh_value_tree(store_list)

    def add_button(self, name, store_list, ignore_list=None):
        button = QPushButton(name)
        button.setFixedSize(60, 35)
        item = (name, button, store_list, ignore_list)
        self._button_list.append(item)
        self.guide_layout.addWidget(button)
        self.refresh_trees(store_list=store_list, ignore_list=ignore_list)
        button.clicked.connect(lambda: self._set_button(item=item))

    def _set_button(self, item):
        index_item = self._button_list.index(item)

        if len(self._button_list) > index_item + 1:
            for name, button, store_list, ignore_list in self._button_list[index_item + 1:]:
                button.setParent(None)

        name, button, store_list, ignore_list = item
        self.refresh_trees(store_list=store_list, ignore_list=ignore_list)

    def _init_detail_layout(self):
        detail_layout = QGridLayout()
        self.key_tree = QTreeWidget()
        self.key_tree.setColumnCount(2)
        self.key_tree.setColumnWidth(0, 200)
        self.key_tree.setHeaderLabels(['Key', 'Size'])

        self.value_tree = QTreeWidget()
        self.value_tree.setColumnCount(2)
        self.value_tree.setColumnWidth(0, 200)
        self.value_tree.setHeaderLabels(['Path', 'Size'])

        detail_layout.setColumnStretch(0, 1)
        detail_layout.setColumnStretch(1, 1)
        detail_layout.addWidget(self.value_tree)
        detail_layout.addWidget(self.key_tree)
        return detail_layout

    def _connect(self):
        self.button_path.clicked.connect(self.button_path_clicked)
        self.key_tree.doubleClicked.connect(self.key_tree_double_clicked)

    def button_path_clicked(self):
        del self._button_list[:]
        for _ in range(self.guide_layout.count()):
            current_item = self.guide_layout.takeAt(0)
            current_item.widget().setParent(None)

        path = unicode.encode(self.input_path.text())
        if self._last_path != path:
            self._walk_folder = walk_folder.run(path=path)

        max_level = 4
        self.directory_info = list(self._walk_folder.get_children_by_level(level=max_level))
        self.add_button('/', self.directory_info)

    def key_tree_double_clicked(self, selected_index=QModelIndex()):
        select_data = selected_index.data()
        ignore_list = [select_data]
        for item in self._button_list[1:]:
            ignore_list.append(item[0])

        store_dict = dict(self._last_info.get_children_by_key(key=select_data, ignore_list=ignore_list).sort_dictionary)
        store_list = list()

        for item in store_dict.values():
            store_list.extend(item['children'])

        store_list = list(set(store_list))
        self.add_button(select_data, store_list or list(), ignore_list=ignore_list)

    def _get_size(self, size):
        return '{} <> {}%'.format(human_size(size), round(size * 100 / self._walk_folder.total_size, 2))

    def _refresh_key_tree(self, directory_info, ignore_list=None):
        info = LabelInfo(make_dictionary_by_classification(directory_info, ignore_list))

        # Clear
        for _ in range(self.key_tree.topLevelItemCount()):
            self.key_tree.takeTopLevelItem(0)

        # Add
        for k, v in info.sort_dictionary:
            tree_widget = QTreeWidgetItem()
            tree_widget.setText(0, k)
            total_size = 0
            for child in v['children']:
                total_size += child.total_size
            tree_widget.setText(1, self._get_size(v[constant.sort_size_name]))
            self.key_tree.addTopLevelItem(tree_widget)
        self._last_info = info

    def _refresh_value_tree(self, directory_info):
        info = sorted(directory_info, key=lambda x: x.total_size, reverse=True)

        # Clear
        for _ in range(self.value_tree.topLevelItemCount()):
            self.value_tree.takeTopLevelItem(0)

        # Add
        for item in info:
            tree_widget = QTreeWidgetItem()
            tree_widget.setText(0, item.part_path)
            tree_widget.setText(1, self._get_size(item.total_size))
            self.value_tree.addTopLevelItem(tree_widget)
Exemplo n.º 6
0
class Form(QDialog):
    def __init__(self, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.state = state
        self.setWindowTitle("Combine Overlapping Pages — {}".format(
            QApplication.applicationName()))
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.entry = None
        QApplication.setOverrideCursor(Qt.WaitCursor)
        try:
            self.eids = list(
                self.state.model.filteredEntries(
                    filter=FilterKind.HAS_OVERLAPPING_PAGES,
                    match=None,
                    offset=0,
                    limit=UNLIMITED,
                    entryData=EntryDataKind.EID))
        finally:
            QApplication.restoreOverrideCursor()
        self.eidIndex = -1 if self.eids else None
        if self.eids:
            self.skip()
            self.combineButton.setFocus()
            say(
                "Found {:,} entries with overlapping pages".format(
                    len(self.eids)), SAY_TIMEOUT)
        else:
            say("No overlapping pages found", SAY_TIMEOUT)
        self.updateUi()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        self.termLabelLabel = QLabel("Term")
        self.termLabel = Widgets.Label.HtmlLabel()
        self.originalPagesLabel = Widgets.Label.HtmlLabel()
        self.originalPagesLabel.setStyleSheet(_BG_SAME)
        self.combinedPagesLabel = Widgets.Label.HtmlLabel()
        self.combinedPagesLabel.setStyleSheet(_BG_SAME)

        self.buttonBox = QDialogButtonBox()
        self.combineButton = QPushButton(QIcon(":/combinepages.svg"),
                                         "Co&mbine")
        self.tooltips.append((self.combineButton, """\
<p><b>Combine</b></p>
<p>Combine overlapping pages as shown, and move to the next term with
overlapping pages.</p>"""))
        self.buttonBox.addButton(self.combineButton,
                                 QDialogButtonBox.ActionRole)
        self.skipButton = QPushButton(QIcon(":/skip.svg"), "S&kip")
        self.tooltips.append((self.skipButton, """\
<p><b>Skip</b></p>
<p>Skip this term's overlapping pages, and move to the next term with
overlapping pages.</p>"""))
        self.buttonBox.addButton(self.skipButton, QDialogButtonBox.ActionRole)
        self.closeButton = QPushButton(QIcon(":/dialog-close.svg"), "&Close")
        self.tooltips.append((self.closeButton, """<p><b>Close</b></p>
<p>Close the dialog.</p>"""))
        self.buttonBox.addButton(self.closeButton, QDialogButtonBox.RejectRole)
        self.helpButton = QPushButton(QIcon(":/help.svg"), "Help")
        self.tooltips.append(
            (self.helpButton, "Help on the Combine Overlapping Pages dialog"))
        self.buttonBox.addButton(self.helpButton, QDialogButtonBox.HelpRole)

    def layoutWidgets(self):
        layout = QFormLayout()
        layout.addRow(self.termLabelLabel, self.termLabel)
        layout.addRow("Pages", self.originalPagesLabel)
        layout.addRow("Pages if Combined", self.combinedPagesLabel)
        layout.addRow(self.buttonBox)
        self.setLayout(layout)

    def createConnections(self):
        self.buttonBox.rejected.connect(self.reject)
        self.combineButton.clicked.connect(self.combine)
        self.skipButton.clicked.connect(self.skip)
        self.helpButton.clicked.connect(self.help)

    def help(self):
        self.state.help("xix_ref_dlg_combpages.html")

    def updateUi(self):
        if bool(self.eids) and self.eidIndex < len(self.eids):
            enableReplace = (self.combinedPagesLabel.text() !=
                             self.originalPagesLabel.text())
            self.combineButton.setEnabled(enableReplace)
            self.skipButton.setEnabled(True)
            if enableReplace:
                self.combineButton.setFocus()
            else:
                self.skipButton.setFocus()
        else:
            self.combineButton.setEnabled(False)
            self.skipButton.setEnabled(False)

    def combine(self):
        pages = self.combinedPagesLabel.text()
        if pages != self.originalPagesLabel.text():
            with Lib.BlockSignals(self.state.model):
                self.state.model.editEntry(self.entry, self.entry.saf,
                                           self.entry.sortas, self.entry.term,
                                           pages)
        self.skip()

    def skip(self):
        self.eidIndex += 1
        while 0 <= self.eidIndex < len(self.eids):
            self.entry = self.state.model.entry(self.eids[self.eidIndex])
            self.termLabelLabel.setText("Term ({:,} of {:,})".format(
                self.eidIndex + 1, len(self.eids)))
            self.termLabel.setText(
                Lib.elidePatchHtml(self.entry.term, self.state))
            self.originalPagesLabel.setText(self.entry.pages)
            pages = Pages.combinedOverlappingPages(self.entry.pages)
            self.combinedPagesLabel.setText(pages)
            self.combinedPagesLabel.setStyleSheet(
                _BG_DIFFERENT if pages != self.entry.pages else _BG_SAME)
            if pages != self.entry.pages:
                break
            self.eidIndex += 1
        self.updateUi()

    def reject(self):
        message = "Combine overlapping pages"
        if self.state.model.canUndo:
            self.state.model.can_undo.emit(True, message)
        if self.state.model.canRedo:
            self.state.model.can_redo.emit(True, message)
        self.state.updateUi()
        super().accept()  # Because this is Close not Cancel