Esempio n. 1
0
    def __init__(self, my_book):
        super().__init__(parent=my_book)
        # Initialize slot for cached copy of document text, see full_text()
        self._text = None
        self.contentsChanged.connect(self._text_modified)

        # TODO do I want to customize the layout?
        self.setDocumentLayout(QPlainTextDocumentLayout(self))
        # Set my default font to the current mono font.
        self.setDefaultFont(fonts.get_fixed(my_book.get_font_size()))
Esempio n. 2
0
    def add_defaults(self):
        """Add default table entries."""
        if not self.get_race_property(self.NAME):
            self.set_race_property(self.NAME, defaults.RACE_NAME)

        if not self.get_race_property(self.DATE):
            self.set_date(QDateTime.currentDateTime().date())

        if not self.get_race_property(self.NOTES):
            document = QTextDocument()
            document.setDocumentLayout(QPlainTextDocumentLayout(document))
            self.set_notes(document)
Esempio n. 3
0
    def __init__(self, encoding=None, name=None, text='', parent=None,
                 textLayout=True):
        super().__init__(text, parent)

        if textLayout is True:
            self.setDocumentLayout(QPlainTextDocumentLayout(self))

        self._filename = name
        self._changed = False
        self._encoding = encoding if encoding else 'utf-8'
        self._previewDocument = None
        self.setDefaultStyleSheet(defaultStyleSheet)
        self.setModified(False)
        self.modificationChanged.connect(self.onModifChange)
Esempio n. 4
0
    def __init__(self, url=None, encoding=None):
        """Create a new Document with url and encoding.

        Does not load the contents, you should use load() for that, or
        use the new_from_url() constructor to instantiate a new Document
        with the contents loaded.

        """
        if url is None:
            url = QUrl()
        super(AbstractDocument, self).__init__()
        self.setDocumentLayout(QPlainTextDocumentLayout(self))
        self._encoding = encoding
        self._url = url  # avoid urlChanged on init
        self.setUrl(url)
Esempio n. 5
0
 def __init__(self, my_book, parent=None):
     super().__init__(parent)
     self.book = my_book
     # Where we store the last-sought-for find string
     self.find_text = None
     # Register to read and write metadata
     my_book.get_meta_manager().register(C.MD_NO, self._read_meta,
                                         self._save_meta)
     # Set our only font (we don't care about the general font, only mono)
     # n.b. this gets the Book's default size as it hasn't loaded a document
     # yet.
     self.setFont(fonts.get_fixed(my_book.get_font_size()))
     # hook up to be notified of a change in font choice
     fonts.notify_me(self.font_change)
     # Set up our document not using the default one
     a_document = QTextDocument()
     a_document.setDocumentLayout(QPlainTextDocumentLayout(a_document))
     self.setDocument(a_document)
     # Turn off linewrap mode
     self.setLineWrapMode(QPlainTextEdit.NoWrap)
     # The following kludge allows us to get the correct highlight
     # color on focus-in. For unknown reasons Qt makes us use the
     # "Inactive" color group even after focus-in. See focusInEvent()
     # and focusOutEvent() below.
     self.palette_active = QPalette(self.palette())
     self.palette_inactive = QPalette(self.palette())
     b = self.palette().brush(QPalette.Active, QPalette.Highlight)
     self.palette_active.setBrush(QPalette.Inactive, QPalette.Highlight, b)
     # Set the cursor shape to IBeam -- no idea why this supposed default
     # inherited from QTextEdit, doesn't happen. But it doesn't.
     self.viewport().setCursor(Qt.IBeamCursor)
     # Hook up a slot to notice that the document has changed its
     # modification state.
     self.document().modificationChanged.connect(self.yikes)
     # Create the list of actions for our edit menu and save it
     # for use on focus-in.
     self.ed_action_list = [
         (C.ED_MENU_UNDO, self.undo, QKeySequence.Undo),
         (C.ED_MENU_REDO, self.redo, QKeySequence.Redo), (None, None, None),
         (C.ED_MENU_CUT, self.cut, QKeySequence.Cut),
         (C.ED_MENU_COPY, self.copy, QKeySequence.Copy),
         (C.ED_MENU_PASTE, self.paste, QKeySequence.Paste),
         (None, None, None),
         (C.ED_MENU_FIND, self.find_action, QKeySequence.Find),
         (C.ED_MENU_NEXT, self.find_next_action, QKeySequence.FindNext)
     ]
     self.setFocusPolicy(Qt.StrongFocus)
Esempio n. 6
0
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)
        self._document = None
        self.messageLabel().setWordWrap(True)
        self.document = d = QTextDocument()
        d.setDocumentLayout(QPlainTextDocumentLayout(d))
        self.highlighter = highlighter.highlighter(d)
        self.view = View(d)
        self.matcher = Matcher(self.view)
        self.completer = Completer(self.view)
        self.setMainWidget(self.view)
        userguide.addButton(self.buttonBox(), "musicview_editinplace")
        # action for completion popup
        self._showPopupAction = QAction(None,
                                        triggered=self.slotCompletionPopup)
        self.addAction(self._showPopupAction)
        # make Ctrl+Return accept the dialog
        self.button("ok").setShortcut(QKeySequence("Ctrl+Return"))
        qutil.saveDialogSize(self, "editinplace/dialog/size")

        self.accepted.connect(self.save)
        app.translateUI(self)
        app.settingsChanged.connect(self.readSettings)
        self.readSettings()
Esempio n. 7
0
 def get_notes(self):
     """Get the notes, as a QTextDocument."""
     document = QTextDocument(self.get_race_property(self.NOTES))
     document.setDocumentLayout(QPlainTextDocumentLayout(document))
     return document