visual .net UPC-E Supplement 5 Rich Text Editing in Java Implement barcode standards 128 in Java Rich Text Editing

How to generate, print barcode using .NET, Java sdk library control with example project source code free download:
Rich Text Editing use none none development togenerate none on noneupc-a generating In this section we none for none will look at rich text editing from two different perspectives. In the rst subsection we will create a plain text editor that uses QSyntaxHighlighter to provide syntax highlighting for Python source code. In the second subsection we will create a single-line rich text editor similar to QLineEdit, that has pop-up menus, and that supports various formatting shortcuts such as Ctrl+B and Ctrl+I to toggle bold and italic on and off.

In both cases, we use QTextEdit as the foundation on which we build.. Microsoft Office Official Website Using QSyntaxHighlighter If we want a Pytho none for none n-savvy text editor with syntax highlighting, we need not create one ourselves. The Tkinter-based IDLE application provides both a sandbox in which we can experiment with Python code, and a perfectly good Python code editor. And for more power, we can use Eric4, itself written in PyQt and using QScintilla for its text editing.

However, no off-the-shelf editor will necessarily work in just the way we want, and since creating our own is instructive and revealing of what is involved, we will create a simple Python Editor to learn how to use QTextEdit and QSyntaxHighlighter. As the screenshot in Figure 13.1 shows, the Python Editor is a simple main-window-style application with two menus and toolbars.

Since we have covered the creation of such applications before, we will focus just on those parts that are relevant to rich text editing, starting with the beginning of the main window s initializer.. class MainWindow(Q MainWindow): def __init__(self, filename=None, parent=None): super(MainWindow, self).__init__(parent) font = QFont("Courier", 11) font.setFixedPitch(True) self.

editor = TextEdit() self.editor.setFont(font) self.

highlighter = PythonHighlighter(self.editor.document()) self.

setCentralWidget(self.editor). Rich Text Editing Figure 13.1 The Python Editor editing itself We begin by creati none none ng a xed-pitch font (a font where every character is the same width). Then we create a TextEdit, a custom QTextEdit class that differs from QTextEdit in that it converts Tab key presses into insertions of four spaces. Next we create a PythonHighlighter, a QSyntaxHighlighter subclass, passing it the text editor s QTextDocument this is the object in which the editor s text and formatting are actually stored.

We make the editor the main window s central widget. The rest of the initializer is concerned with the creation of the actions, menus, and toolbars, things that we are very familiar with and can therefore skip. The only other methods we will look at are two of the three basic le-handling ones, since they involve the text editor.

. def fileNew(self): if not self.okToContinue(): return document = self.editor.

document() document.clear() document.setModified(False) self.

filename = None self.setWindowTitle("Python Editor - Unnamed") self.updateUi().

This method simply none for none retrieves and clears the QTextDocument that actually holds the text, and sets the modi ed ag to False. The result is a blank QTextEdit with no unsaved changes. The updateUi() method is used to enable and disable.

13. Rich Text and Printing actions depending none none on the application s state; see the Enabling and Disabling Actions sidebar on page 385.. def loadFile(self) : fh = None try: fh = QFile(self.filename) if not

ReadOnly): raise IOError, unicode(fh.errorString()) stream = QTextStream(fh) stream.setCodec("UTF-8") self.

editor.setPlainText(stream.readAll()) self.

editor.document().setModified(False) self.

setWindowTitle("Python Editor - %s" % \ QFileInfo(self.filename).fileName()) except (IOError, OSError), e: QMessageBox.

warning(self, "Python Editor -- Load Error", "Failed to load %s: %s" % (self.filename, e)) finally: if fh is not None: fh.close().

If a le is loaded none none for example, by the user invoking the File Open action this method is called. The le-handling code is similar to what we have seen before; the only real difference is that we set the QTextDocument s modi ed ag to False. The code for saving (not shown) is very similar to that for loading.

We get the le handle, create a QTextStream, set the encoding to UTF-8, and output the entire text using QTextEdit.toPlainText(). We also set the QTextDocument s modi ed ag to False.

. class TextEdit(QTe xtEdit): def __init__(self, parent=None): super(TextEdit, self).__init__(parent) def event(self, event): if event.type() == QEvent.

KeyPress and \ event.key() == Qt.Key_Tab: cursor = self.

textCursor() cursor.insertText(" ") return True return QTextEdit.event(self, event).

The preceding code none none shows the complete TextEdit subclass. Every QTextDocument can be manipulated through a QTextCursor object, which is the programmatic equivalent of a user interacting with the document using key presses and mouse actions..

Copyright © . All rights reserved.