コード例 #1
0
    def setup_ui(self):
        self.l = l = QVBoxLayout(self)
        self.h = h = QHBoxLayout()
        l.addLayout(h)

        self.la1 = la = QLabel(_('F&unction name:'))
        h.addWidget(la)
        self.fb = fb = FunctionBox(self)
        la.setBuddy(fb)
        h.addWidget(fb, stretch=10)

        self.la3 = la = QLabel(_('&Code:'))
        self.source_code = TextEdit(self)
        self.source_code.load_text('', 'python')
        la.setBuddy(self.source_code)
        l.addWidget(la), l.addWidget(self.source_code)

        if self._func_name:
            self.fb.setText(self._func_name)
            func = functions().get(self._func_name)
            if func is not None:
                self.source_code.setPlainText(func.source or ('\n' + EMPTY_FUNC))
        else:
            self.source_code.setPlainText('\n' + EMPTY_FUNC)

        self.la2 = la = QLabel(_(
            'For help with creating functions, see the <a href="%s">User Manual</a>') %
            localize_user_manual_link('https://manual.calibre-ebook.com/function_mode.html'))
        la.setOpenExternalLinks(True)
        l.addWidget(la)

        l.addWidget(self.bb)
コード例 #2
0
ファイル: widget.py プロジェクト: elonchen/calibre
 def __init__(self, syntax, parent=None):
     QMainWindow.__init__(self, parent)
     if parent is None:
         self.setWindowFlags(Qt.Widget)
     self.is_synced_to_container = False
     self.syntax = syntax
     self.editor = TextEdit(self)
     self.editor.setContextMenuPolicy(Qt.CustomContextMenu)
     self.editor.customContextMenuRequested.connect(self.show_context_menu)
     self.setCentralWidget(self.editor)
     self.create_toolbars()
     self.undo_available = False
     self.redo_available = False
     self.copy_available = self.cut_available = False
     self.editor.modificationChanged.connect(
         self._modification_state_changed)
     self.editor.undoAvailable.connect(self._undo_available)
     self.editor.redoAvailable.connect(self._redo_available)
     self.editor.textChanged.connect(self._data_changed)
     self.editor.copyAvailable.connect(self._copy_available)
     self.editor.cursorPositionChanged.connect(
         self._cursor_position_changed)
     self.editor.link_clicked.connect(self.link_clicked)
     self.editor.smart_highlighting_updated.connect(
         self.smart_highlighting_updated)
コード例 #3
0
    def setup_ui(self):
        from calibre.gui2.tweak_book.templates import DEFAULT_TEMPLATES
        from calibre.gui2.tweak_book.editor.text import TextEdit
        self.l = l = QFormLayout(self)
        self.setLayout(l)

        self.syntaxes = s = QComboBox(self)
        s.addItems(sorted(DEFAULT_TEMPLATES.iterkeys()))
        s.setCurrentIndex(s.findText('html'))
        l.addRow(_('Choose the &type of template to edit:'), s)
        s.currentIndexChanged.connect(self.show_template)

        self.helpl = la = QLabel(
            _('The variables {0} and {1} will be replaced with the title and author of the book. {2}'
              ' is where the cursor will be positioned.').format(
                  '{TITLE}', '{AUTHOR}', '%CURSOR%'))
        la.setWordWrap(True)
        l.addRow(la)

        self.save_timer = t = QTimer(self)
        t.setSingleShot(True), t.setInterval(100)
        t.timeout.connect(self._save_syntax)

        self.editor = e = TextEdit(self)
        l.addRow(e)
        e.textChanged.connect(self.save_syntax)

        self.show_template()

        self.bb.clear()
        self.bb.addButton(self.bb.Close)
        self.rd = b = self.bb.addButton(self.bb.RestoreDefaults)
        b.clicked.connect(self.restore_defaults)
        l.addRow(self.bb)
コード例 #4
0
    def setup_ui(self):
        self.block_show = False
        self.properties = []
        self.l = l = QVBoxLayout(self)
        self.setLayout(l)
        h = QHBoxLayout()
        l.addLayout(h)
        self.la = la = QLabel(_('&Edit theme:'))
        h.addWidget(la)
        self.theme = t = QComboBox(self)
        la.setBuddy(t)
        t.addItems(sorted(custom_theme_names()))
        t.setMinimumWidth(200)
        if t.count() > 0:
            t.setCurrentIndex(0)
        t.currentIndexChanged[int].connect(self.show_theme)
        h.addWidget(t)

        self.add_button = b = QPushButton(QIcon(I('plus.png')),
                                          _('Add &new theme'), self)
        b.clicked.connect(self.create_new_theme)
        h.addWidget(b)

        self.remove_button = b = QPushButton(QIcon(I('minus.png')),
                                             _('&Remove theme'), self)
        b.clicked.connect(self.remove_theme)
        h.addWidget(b)
        h.addStretch(1)

        self.scroll = s = QScrollArea(self)
        self.w = w = QWidget(self)
        s.setWidget(w), s.setWidgetResizable(True)
        self.cl = cl = QVBoxLayout()
        w.setLayout(cl)

        from calibre.gui2.tweak_book.editor.text import TextEdit
        self.preview = p = TextEdit(self, expected_geometry=(73, 50))
        p.load_text(
            HELP_TEXT.format(*[
                '<b>%s</b>' % x
                for x in ('Normal', 'Visual', 'CursorLine', 'LineNr',
                          'MatchParen', 'Function', 'Type', 'Statement',
                          'Constant', 'SpecialCharacter', 'Error',
                          'SpellError', 'Comment')
            ]))
        p.setMaximumWidth(p.size_hint.width() + 5)
        s.setMinimumWidth(600)
        self.splitter = sp = QSplitter(self)
        l.addWidget(sp)
        sp.addWidget(s), sp.addWidget(p)

        self.bb.clear()
        self.bb.addButton(QDialogButtonBox.StandardButton.Close)
        l.addWidget(self.bb)

        if self.theme.count() > 0:
            self.show_theme()
コード例 #5
0
ファイル: custom_recipes.py プロジェクト: wynick27/calibre
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        self.l = l = QVBoxLayout(self)

        self.la = la = QLabel(_(
            'For help with writing advanced news recipes, see the <a href="%s">User Manual</a>'
        ) % localize_user_manual_link('https://manual.calibre-ebook.com/news.html'))
        l.addWidget(la)

        self.editor = TextEdit(self)
        l.addWidget(self.editor)
コード例 #6
0
 def setup_ui(self):
     from calibre.gui2.tweak_book.editor.text import TextEdit
     self.l = l = QVBoxLayout(self)
     self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Close)
     self.la = la = QLabel(self.LABEL)
     l.addWidget(la)
     self.css = t = TextEdit(self)
     t.load_text('', self.SYNTAX)
     la.setBuddy(t)
     c = t.textCursor()
     c.movePosition(QTextCursor.MoveOperation.End)
     t.setTextCursor(c)
     self.h = h = QHBoxLayout()
     l.addLayout(h)
     h.addWidget(t)
     self.test_button = b = QPushButton(_('&Test'), self)
     b.clicked.connect(self.do_test)
     h.addWidget(b)
     self.result = la = TextEdit(self)
     la.setReadOnly(True)
     l.addWidget(la)
     l.addWidget(self.bb)
コード例 #7
0
 def setup_ui(self):
     from calibre.gui2.tweak_book.editor.text import TextEdit
     self.l = l = QVBoxLayout(self)
     self.bb.setStandardButtons(self.bb.Close)
     self.la = la = QLabel(self.LABEL)
     l.addWidget(la)
     self.css = t = TextEdit(self)
     t.load_text('/* %s */\n' % _('Enter CSS rules below and click the "Test" button'), 'css')
     la.setBuddy(t)
     c = t.textCursor()
     c.movePosition(c.End)
     t.setTextCursor(c)
     self.h = h = QHBoxLayout()
     l.addLayout(h)
     h.addWidget(t)
     self.test_button = b = QPushButton(_('&Test'), self)
     b.clicked.connect(self.do_test)
     h.addWidget(b)
     self.result = la = TextEdit(self)
     la.setReadOnly(True)
     l.addWidget(la)
     l.addWidget(self.bb)
コード例 #8
0
    def setup_ui(self):
        from calibre.gui2.tweak_book.templates import DEFAULT_TEMPLATES
        from calibre.gui2.tweak_book.editor.text import TextEdit
        # Cannot use QFormLayout as it does not play nice with TextEdit on windows
        self.l = l = QVBoxLayout(self)

        self.syntaxes = s = QComboBox(self)
        s.addItems(sorted(DEFAULT_TEMPLATES))
        s.setCurrentIndex(s.findText('html'))
        h = QHBoxLayout()
        l.addLayout(h)
        la = QLabel(_('Choose the &type of template to edit:'))
        la.setBuddy(s)
        h.addWidget(la), h.addWidget(s), h.addStretch(10)
        s.currentIndexChanged.connect(self.show_template)

        self.helpl = la = QLabel(
            _('The variables {0} and {1} will be replaced with the title and author of the book. {2}'
              ' is where the cursor will be positioned. If you want to include braces in your template,'
              ' for example for CSS rules, you have to escape them, like this: {3}'
              ).format(*[
                  '<code>%s</code>' % x for x in
                  ['{TITLE}', '{AUTHOR}', '%CURSOR%', 'body {{ color: red }}']
              ]))
        la.setWordWrap(True)
        l.addWidget(la)

        self.save_timer = t = QTimer(self)
        t.setSingleShot(True), t.setInterval(100)
        t.timeout.connect(self._save_syntax)

        self.editor = e = TextEdit(self)
        l.addWidget(e)
        e.textChanged.connect(self.save_syntax)

        self.show_template()

        self.bb.clear()
        self.bb.addButton(QDialogButtonBox.StandardButton.Close)
        self.rd = b = self.bb.addButton(
            QDialogButtonBox.StandardButton.RestoreDefaults)
        b.clicked.connect(self.restore_defaults)
        l.addWidget(self.bb)
コード例 #9
0
ファイル: widget.py プロジェクト: kmshi/calibre
 def __init__(self, syntax, parent=None):
     QMainWindow.__init__(self, parent)
     if parent is None:
         self.setWindowFlags(Qt.Widget)
     self.is_synced_to_container = False
     self.syntax = syntax
     self.editor = TextEdit(self)
     self.setCentralWidget(self.editor)
     self.create_toolbars()
     self.undo_available = False
     self.redo_available = False
     self.copy_available = self.cut_available = False
     self.editor.modificationChanged.connect(
         self._modification_state_changed)
     self.editor.undoAvailable.connect(self._undo_available)
     self.editor.redoAvailable.connect(self._redo_available)
     self.editor.textChanged.connect(self._data_changed)
     self.editor.copyAvailable.connect(self._copy_available)
     self.editor.cursorPositionChanged.connect(
         self._cursor_position_changed)
コード例 #10
0
ファイル: themes.py プロジェクト: dusual/calibre
    def setup_ui(self):
        self.block_show = False
        self.properties = []
        self.l = l = QVBoxLayout(self)
        self.setLayout(l)
        h = QHBoxLayout()
        l.addLayout(h)
        self.la = la = QLabel(_('&Edit theme:'))
        h.addWidget(la)
        self.theme = t = QComboBox(self)
        la.setBuddy(t)
        t.addItems(sorted(custom_theme_names()))
        t.setMinimumWidth(200)
        if t.count() > 0:
            t.setCurrentIndex(0)
        t.currentIndexChanged[int].connect(self.show_theme)
        h.addWidget(t)

        self.add_button = b = QPushButton(QIcon(I('plus.png')),
                                          _('Add &new theme'), self)
        b.clicked.connect(self.create_new_theme)
        h.addWidget(b)

        self.remove_button = b = QPushButton(QIcon(I('minus.png')),
                                             _('&Remove theme'), self)
        b.clicked.connect(self.remove_theme)
        h.addWidget(b)
        h.addStretch(1)

        self.scroll = s = QScrollArea(self)
        self.w = w = QWidget(self)
        s.setWidget(w), s.setWidgetResizable(True)
        self.cl = cl = QVBoxLayout()
        w.setLayout(cl)

        from calibre.gui2.tweak_book.editor.text import TextEdit
        self.preview = p = TextEdit(self, expected_geometry=(73, 50))
        p.load_text(
            textwrap.dedent(
                _('''\
            <h2>Creating a custom theme</h2>

            <p id="attribute" lang="und">You can create a custom syntax highlighting
            theme, with your own colors and font styles. The most important
            types of highlighting rules are described below. Note that not
            every rule supports every kind of customization, for example,
            changing font or underline styles for the <code>Cursor</code> rule
            does not have any effect as that rule is used only for the color of
            the blinking cursor.</p>

            <p>As you make changes to your them on the left, the changes will
            be reflected live in this panel.</p>

            <p xml:lang="und">
            {0}
                The most important rule. Sets the
                foreground and background colors for the editor as well as the
                style of "normal" text, that is, text that does not match any
                special syntax.

            {1}
                Defines the colors for text selected by the mouse.

            {2}
                Defines the color for the line containing the cursor.

            {3}
                Defines the colors for the line numbers on the left.

            {4}
                Defines the colors for matching tags in HTML and matching
                braces in CSS.

            {5}
                Used for highlighting tags in HTML

            {6}
                Used for highlighting attributes in HTML

            {7}
                Tag names in HTML

            {8}
                Namespace prefixes in XML and constants in CSS

            {9}
                Non-breaking spaces/hyphens in HTML

            {10}
                Syntax errors such as <this <>

            {11}
                Misspelled words such as <span lang="en">thisword</span>

            {12}
                Comments like <!-- this one -->
            </p>

            <style type="text/css">
            /* Some CSS so you can see how the highlighting rules affect it */

            p.someclass {{
                font-family: serif;
                font-size: 12px;
                line-height: 1.2;
            }}
            </style>
            ''')).format(*[
                    '<b>%s</b>' % x
                    for x in ('Normal', 'Visual', 'CursorLine', 'LineNr',
                              'MatchParen', 'Function', 'Type', 'Statement',
                              'Constant', 'SpecialCharacter', 'Error',
                              'SpellError', 'Comment')
                ]))
        p.setMaximumWidth(p.size_hint.width() + 5)
        s.setMinimumWidth(600)
        self.splitter = sp = QSplitter(self)
        l.addWidget(sp)
        sp.addWidget(s), sp.addWidget(p)

        self.bb.clear()
        self.bb.addButton(self.bb.Close)
        l.addWidget(self.bb)

        if self.theme.count() > 0:
            self.show_theme()
コード例 #11
0
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(955, 672)
        self.gridLayout = QtWidgets.QGridLayout(Form)
        self.gridLayout.setObjectName("gridLayout")
        self.label_4 = QtWidgets.QLabel(Form)
        self.label_4.setObjectName("label_4")
        self.gridLayout.addWidget(self.label_4, 1, 0, 1, 1)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.execute_button = QtWidgets.QPushButton(Form)
        self.execute_button.setObjectName("execute_button")
        self.horizontalLayout_3.addWidget(self.execute_button)
        self.gridLayout.addLayout(self.horizontalLayout_3, 6, 0, 1, 1)
        self.line = QtWidgets.QFrame(Form)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.gridLayout.addWidget(self.line, 9, 0, 1, 2)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.gridLayout_3 = QtWidgets.QGridLayout()
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.documentation = QtWidgets.QTextEdit(Form)
        self.documentation.setObjectName("documentation")
        self.gridLayout_3.addWidget(self.documentation, 5, 1, 1, 1)
        self.function_name = QtWidgets.QComboBox(Form)
        self.function_name.setEditable(True)
        self.function_name.setObjectName("function_name")
        self.gridLayout_3.addWidget(self.function_name, 0, 1, 1, 1)
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.gridLayout_3.addWidget(self.label_2, 0, 0, 1, 1)
        self.label_3 = QtWidgets.QLabel(Form)
        self.label_3.setToolTip("")
        self.label_3.setObjectName("label_3")
        self.gridLayout_3.addWidget(self.label_3, 2, 0, 1, 1)
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.fromfile_checkbox = QtWidgets.QCheckBox(Form)
        self.fromfile_checkbox.setObjectName("fromfile_checkbox")
        self.horizontalLayout_5.addWidget(self.fromfile_checkbox)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_5.addItem(spacerItem1)
        self.save_file_button = QtWidgets.QPushButton(Form)
        self.save_file_button.setObjectName("save_file_button")
        self.horizontalLayout_5.addWidget(self.save_file_button)
        self.load_file_button = QtWidgets.QPushButton(Form)
        self.load_file_button.setObjectName("load_file_button")
        self.horizontalLayout_5.addWidget(self.load_file_button)
        self.gridLayout_3.addLayout(self.horizontalLayout_5, 4, 1, 1, 1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.delete_button = QtWidgets.QPushButton(Form)
        self.delete_button.setObjectName("delete_button")
        self.horizontalLayout_2.addWidget(self.delete_button)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem2)
        self.save_button = QtWidgets.QPushButton(Form)
        self.save_button.setObjectName("save_button")
        self.horizontalLayout_2.addWidget(self.save_button)
        self.gridLayout_3.addLayout(self.horizontalLayout_2, 6, 1, 1, 1)
        self.label_41 = QtWidgets.QLabel(Form)
        self.label_41.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
        self.label_41.setObjectName("label_41")
        self.gridLayout_3.addWidget(self.label_41, 5, 0, 1, 1)
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.macrofile = QtWidgets.QLineEdit(Form)
        self.macrofile.setObjectName("macrofile")
        self.horizontalLayout_6.addWidget(self.macrofile)
        self.filebrowse_button = QtWidgets.QToolButton(Form)
        self.filebrowse_button.setObjectName("filebrowse_button")
        self.horizontalLayout_6.addWidget(self.filebrowse_button)
        self.gridLayout_3.addLayout(self.horizontalLayout_6, 2, 1, 1, 1)
        self.horizontalLayout.addLayout(self.gridLayout_3)
        self.horizontalLayout1 = QtWidgets.QVBoxLayout()
        self.horizontalLayout1.setObjectName("horizontalLayout1")
        self.textBrowser = QtWidgets.QTextBrowser(Form)
        self.textBrowser.setObjectName("textBrowser")
        self.horizontalLayout1.addWidget(self.textBrowser)
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem3)
        self.import_button = QtWidgets.QPushButton(Form)
        self.import_button.setObjectName("import_button")
        self.horizontalLayout_4.addWidget(self.import_button)
        self.export_button = QtWidgets.QPushButton(Form)
        self.export_button.setObjectName("export_button")
        self.horizontalLayout_4.addWidget(self.export_button)
        self.horizontalLayout1.addLayout(self.horizontalLayout_4)
        self.horizontalLayout.addLayout(self.horizontalLayout1)
        self.gridLayout.addLayout(self.horizontalLayout, 10, 0, 1, 1)
        from calibre.gui2.tweak_book.editor.text import TextEdit
        self.program = TextEdit(Form)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(1)
        sizePolicy.setHeightForWidth(self.program.sizePolicy().hasHeightForWidth())
        self.program.setSizePolicy(sizePolicy)
        self.program.setMinimumSize(QtCore.QSize(400, 0))
        self.program.setDocumentTitle("")
        self.program.setTabStopWidth(30)
        self.program.setObjectName("program")
        self.gridLayout.addWidget(self.program, 2, 0, 1, 1)
        self.label_4.setBuddy(self.program)
        self.label_2.setBuddy(self.function_name)
        self.label_3.setBuddy(self.macrofile)
        self.label_41.setBuddy(self.documentation)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)