eric7/UI/Previewer.py

branch
eric7
changeset 8414
8c3b52d1b4b6
parent 8318
962bce857696
child 8881
54e42bc2437a
equal deleted inserted replaced
8413:65ed18753c40 8414:8c3b52d1b4b6
18 class Previewer(QStackedWidget): 18 class Previewer(QStackedWidget):
19 """ 19 """
20 Class implementing a previewer widget containing a stack of 20 Class implementing a previewer widget containing a stack of
21 specialized previewers. 21 specialized previewers.
22 """ 22 """
23 def __init__(self, viewmanager, splitter, parent=None): 23 def __init__(self, viewmanager, parent=None):
24 """ 24 """
25 Constructor 25 Constructor
26 26
27 @param viewmanager reference to the viewmanager object (ViewManager) 27 @param viewmanager reference to the viewmanager object
28 @param splitter reference to the embedding splitter (QSplitter) 28 @type ViewManager
29 @param parent reference to the parent widget (QWidget) 29 @param parent reference to the parent widget
30 @type QWidget
30 """ 31 """
31 super().__init__(parent) 32 super().__init__(parent)
32 33
33 self.__vm = viewmanager 34 self.__vm = viewmanager
34 self.__splitter = splitter
35 35
36 self.__firstShow = True 36 self.__firstShow = True
37 37
38 self.__htmlPreviewer = None 38 self.__htmlPreviewer = None
39 self.__qssPreviewer = None 39 self.__qssPreviewer = None
48 self.__vm.editorLanguageChanged.connect(self.__editorLanguageChanged) 48 self.__vm.editorLanguageChanged.connect(self.__editorLanguageChanged)
49 self.__vm.editorTextChanged.connect(self.__editorTextChanged) 49 self.__vm.editorTextChanged.connect(self.__editorTextChanged)
50 50
51 self.__vm.previewStateChanged.connect(self.__previewStateChanged) 51 self.__vm.previewStateChanged.connect(self.__previewStateChanged)
52 52
53 self.hide()
54
55 def setSplitter(self, splitter):
56 """
57 Public method to set the splitter.
58
59 @param splitter reference to the embedding splitter
60 @type QSplitter
61 """
62 self.__splitter = splitter
53 self.__splitter.splitterMoved.connect(self.__splitterMoved) 63 self.__splitter.splitterMoved.connect(self.__splitterMoved)
54
55 self.hide()
56 64
57 @pyqtSlot() 65 @pyqtSlot()
58 def preferencesChanged(self): 66 def preferencesChanged(self):
59 """ 67 """
60 Public slot handling a change of preferences. 68 Public slot handling a change of preferences.
96 104
97 def __editorChanged(self, editor): 105 def __editorChanged(self, editor):
98 """ 106 """
99 Private slot to handle a change of the current editor. 107 Private slot to handle a change of the current editor.
100 108
101 @param editor reference to the editor (Editor) 109 @param editor reference to the editor
110 @type Editor
102 """ 111 """
103 if editor is None: 112 if editor is None:
104 self.hide() 113 self.hide()
105 return 114 return
106 115
115 124
116 def __editorLanguageChanged(self, editor): 125 def __editorLanguageChanged(self, editor):
117 """ 126 """
118 Private slot to handle a change of the current editor's language. 127 Private slot to handle a change of the current editor's language.
119 128
120 @param editor reference to the editor (Editor) 129 @param editor reference to the editor
130 @type Editor
121 """ 131 """
122 self.__editorChanged(editor) 132 self.__editorChanged(editor)
123 133
124 def __editorTextChanged(self, editor): 134 def __editorTextChanged(self, editor):
125 """ 135 """
126 Private slot to handle changes of an editor's text. 136 Private slot to handle changes of an editor's text.
127 137
128 @param editor reference to the editor (Editor) 138 @param editor reference to the editor
139 @type Editor
129 """ 140 """
130 if self.isVisible(): 141 if self.isVisible():
131 self.__typingTimer.stop() 142 self.__typingTimer.stop()
132 self.__typingTimer.start() 143 self.__typingTimer.start()
133 144
134 def __previewStateChanged(self, on): 145 def __previewStateChanged(self, on):
135 """ 146 """
136 Private slot to toggle the display of the preview. 147 Private slot to toggle the display of the preview.
137 148
138 @param on flag indicating to show a preview (boolean) 149 @param on flag indicating to show a preview
150 @type bool
139 """ 151 """
140 editor = self.__vm.activeWindow() 152 editor = self.__vm.activeWindow()
141 if on and editor and self.__isPreviewable(editor): 153 if on and editor and self.__isPreviewable(editor):
142 self.show() 154 self.show()
143 else: 155 else:
146 def __isPreviewable(self, editor): 158 def __isPreviewable(self, editor):
147 """ 159 """
148 Private method to check, if a preview can be shown for the given 160 Private method to check, if a preview can be shown for the given
149 editor. 161 editor.
150 162
151 @param editor reference to an editor (Editor) 163 @param editor reference to an editor
152 @return flag indicating if a preview can be shown (boolean) 164 @type Editor
165 @return flag indicating if a preview can be shown
166 @rtype bool
153 """ 167 """
154 if editor: 168 if editor:
155 if bool(editor.getFileName()): 169 if bool(editor.getFileName()):
156 extension = os.path.normcase( 170 extension = os.path.normcase(
157 os.path.splitext(editor.getFileName())[1][1:]) 171 os.path.splitext(editor.getFileName())[1][1:])

eric ide

mercurial