|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog base class to preview changes. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import Qt |
|
11 from PyQt4.QtGui import QDialog, QBrush, QColor, QTextCursor |
|
12 |
|
13 from Ui_PreviewDialog import Ui_PreviewDialog |
|
14 |
|
15 import Globals |
|
16 |
|
17 class PreviewDialogBase(QDialog, Ui_PreviewDialog): |
|
18 """ |
|
19 Class implementing a dialog base class to preview changes. |
|
20 """ |
|
21 def __init__(self, parent = None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param parent reference to the parent widget (QWidget) |
|
26 """ |
|
27 QDialog.__init__(self, parent) |
|
28 self.setAttribute(Qt.WA_DeleteOnClose) |
|
29 self.setupUi(self) |
|
30 |
|
31 if Globals.isWindowsPlatform(): |
|
32 self.previewEdit.setFontFamily("Lucida Console") |
|
33 else: |
|
34 self.previewEdit.setFontFamily("Monospace") |
|
35 |
|
36 self.formats = {} |
|
37 self.formats[' '] = self.previewEdit.currentCharFormat() |
|
38 format = self.previewEdit.currentCharFormat() |
|
39 format.setBackground(QBrush(QColor(190, 237, 190))) |
|
40 self.formats['+'] = format |
|
41 format = self.previewEdit.currentCharFormat() |
|
42 format.setBackground(QBrush(QColor(237, 190, 190))) |
|
43 self.formats['-'] = format |
|
44 format = self.previewEdit.currentCharFormat() |
|
45 format.setBackground(QBrush(QColor(190, 190, 237))) |
|
46 self.formats['@'] = format |
|
47 format = self.previewEdit.currentCharFormat() |
|
48 format.setBackground(QBrush(QColor(124, 124, 124))) |
|
49 self.formats['?'] = format |
|
50 format = self.previewEdit.currentCharFormat() |
|
51 format.setBackground(QBrush(QColor(190, 190, 190))) |
|
52 self.formats['='] = format |
|
53 |
|
54 def _appendText(self, txt, format): |
|
55 """ |
|
56 Restricted method to append text to the end of the contents pane. |
|
57 |
|
58 @param txt text to insert (string) |
|
59 @param format text format to be used (QTextCharFormat) |
|
60 """ |
|
61 tc = self.previewEdit.textCursor() |
|
62 tc.movePosition(QTextCursor.End) |
|
63 self.previewEdit.setTextCursor(tc) |
|
64 self.previewEdit.setCurrentCharFormat(format) |
|
65 self.previewEdit.insertPlainText(txt) |