src/eric7/PdfViewer/PdfInfoWidget.py

branch
pdf_viewer
changeset 9705
7629a6f23b2e
parent 9704
6e1650b9b3b5
child 9722
63135ab601e7
--- a/src/eric7/PdfViewer/PdfInfoWidget.py	Wed Jan 18 14:31:55 2023 +0100
+++ b/src/eric7/PdfViewer/PdfInfoWidget.py	Wed Jan 18 16:37:08 2023 +0100
@@ -30,7 +30,7 @@
         """
         super().__init__(parent)
 
-        self.__document = document
+        self.__document = None
 
         self.__layout = QFormLayout(self)
         self.__layout.setRowWrapPolicy(QFormLayout.RowWrapPolicy.WrapLongRows)
@@ -75,9 +75,26 @@
 
         self.setLayout(self.__layout)
 
-        self.__document.statusChanged.connect(self.__populateInfoLabels)
-        self.__document.pageCountChanged.connect(self.__handlePageCountChanged)
-        self.__document.passwordChanged.connect(self.__handlePasswordChanged)
+        self.setDocument(document)
+
+    def setDocument(self, document):
+        """
+        Public method to set the reference to the PDF document.
+
+        @param document reference to the document
+        @type QPdfDocument
+        """
+        if self.__document is not None:
+            self.__document.statusChanged.disconnect(self.__populateInfoLabels)
+            self.__document.pageCountChanged.disconnect(self.__handlePageCountChanged)
+            self.__document.passwordChanged.disconnect(self.__handlePasswordChanged)
+
+        self.__document = document
+
+        if document is not None:
+            self.__document.statusChanged.connect(self.__populateInfoLabels)
+            self.__document.pageCountChanged.connect(self.__handlePageCountChanged)
+            self.__document.passwordChanged.connect(self.__handlePasswordChanged)
 
     @pyqtSlot(QPdfDocument.Status)
     def __populateInfoLabels(self, status):

eric ide

mercurial