E5Network/E5NetworkMonitor.py

Sun, 29 Jun 2014 20:13:56 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Jun 2014 20:13:56 +0200
changeset 3656
441956d8fce5
parent 3484
645c12de6b0c
child 4021
195a471c327b
permissions
-rw-r--r--

Started porting eric5 to PyQt5.

52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
3 # Copyright (c) 2009 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a network monitor dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3057
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
11
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtCore import Qt, QAbstractTableModel, QModelIndex, QUrl, \
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 QSortFilterProxyModel
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
14 from PyQt5.QtGui import QStandardItemModel
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
15 from PyQt5.QtWidgets import QDialog
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
16 from PyQt5.QtNetwork import QNetworkRequest, QNetworkAccessManager
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from .Ui_E5NetworkMonitor import Ui_E5NetworkMonitor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
20
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class E5NetworkRequest(object):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class for storing all data related to a specific request.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def __init__(self):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.op = -1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.request = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.reply = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.response = ""
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.length = 0
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.contentType = ""
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.info = ""
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.replyHeaders = [] # list of tuple of two items
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
39
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 class E5NetworkMonitor(QDialog, Ui_E5NetworkMonitor):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Class implementing a network monitor dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 _monitor = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @classmethod
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 def instance(cls, networkAccessManager):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 Class method to get a reference to our singleton.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @param networkAccessManager reference to the network access manager
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 (QNetworkAccessManager)
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
53 @return reference to the network monitor singleton (E5NetworkMonitor)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 if cls._monitor is None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 cls._monitor = E5NetworkMonitor(networkAccessManager)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 return cls._monitor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @classmethod
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 def closeMonitor(cls):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Class method to close the monitor dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 if cls._monitor is not None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 cls._monitor.close()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
68 def __init__(self, networkAccessManager, parent=None):
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Constructor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @param networkAccessManager reference to the network access manager
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 (QNetworkAccessManager)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 @param parent reference to the parent widget (QWidget)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
76 super(E5NetworkMonitor, self).__init__(parent)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.setupUi(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__requestHeaders = QStandardItemModel(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.__requestHeaders.setHorizontalHeaderLabels(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
81 [self.tr("Name"), self.tr("Value")])
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.requestHeadersList.setModel(self.__requestHeaders)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.requestHeadersList.horizontalHeader().setStretchLastSection(True)
463
8d0309c4b7f6 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 410
diff changeset
84 self.requestHeadersList.doubleClicked.connect(self.__showHeaderDetails)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__replyHeaders = QStandardItemModel(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__replyHeaders.setHorizontalHeaderLabels(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
88 [self.tr("Name"), self.tr("Value")])
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.responseHeadersList.setModel(self.__replyHeaders)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.responseHeadersList.horizontalHeader().setStretchLastSection(True)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
91 self.responseHeadersList.doubleClicked.connect(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
92 self.__showHeaderDetails)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.requestsList.horizontalHeader().setStretchLastSection(True)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.requestsList.verticalHeader().setMinimumSectionSize(-1)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.__proxyModel = QSortFilterProxyModel(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__proxyModel.setFilterKeyColumn(-1)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
99 self.searchEdit.textChanged.connect(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
100 self.__proxyModel.setFilterFixedString)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3201
diff changeset
102 self.removeButton.clicked.connect(self.requestsList.removeSelected)
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3201
diff changeset
103 self.removeAllButton.clicked.connect(self.requestsList.removeAll)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.__model = E5RequestModel(networkAccessManager, self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self.__proxyModel.setSourceModel(self.__model)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.requestsList.setModel(self.__proxyModel)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
108 self.__proxyModel.rowsInserted.connect(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
109 self.requestsList.scrollToBottom)
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
110 self.requestsList.selectionModel()\
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
111 .currentChanged[QModelIndex, QModelIndex]\
482
4650a72c307a Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 464
diff changeset
112 .connect(self.__currentChanged)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 fm = self.fontMetrics()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 em = fm.width("m")
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
116 self.requestsList.horizontalHeader().resizeSection(0, em * 5)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.requestsList.horizontalHeader().resizeSection(1, em * 20)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
118 self.requestsList.horizontalHeader().resizeSection(3, em * 5)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.requestsList.horizontalHeader().resizeSection(4, em * 15)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.__headersDlg = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 def closeEvent(self, evt):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 Protected method called upon closing the dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 @param evt reference to the close event object (QCloseEvent)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.__class__._monitor = None
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
130 super(E5NetworkMonitor, self).closeEvent(evt)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 def reject(self):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 Public slot to close the dialog with a Reject status.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.__class__._monitor = None
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
137 super(E5NetworkMonitor, self).reject()
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 def __currentChanged(self, current, previous):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 Private slot to handle a change of the current index.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 @param current new current index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 @param previous old current index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 self.__requestHeaders.setRowCount(0)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 self.__replyHeaders.setRowCount(0)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if not current.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 row = self.__proxyModel.mapToSource(current).row()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 req = self.__model.requests[row].request
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 for header in req.rawHeaderList():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self.__requestHeaders.insertRows(0, 1, QModelIndex())
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.__requestHeaders.setData(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
159 self.__requestHeaders.index(0, 0),
556
05b73ee2ae42 Fixed a few issues in E5NetworkMonitor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 482
diff changeset
160 str(header, "utf-8"))
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.__requestHeaders.setData(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
162 self.__requestHeaders.index(0, 1),
556
05b73ee2ae42 Fixed a few issues in E5NetworkMonitor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 482
diff changeset
163 str(req.rawHeader(header), "utf-8"))
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.__requestHeaders.item(0, 0).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__requestHeaders.item(0, 1).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 for header in self.__model.requests[row].replyHeaders:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 self.__replyHeaders.insertRows(0, 1, QModelIndex())
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 self.__replyHeaders.setData(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
172 self.__replyHeaders.index(0, 0),
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 header[0])
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self.__replyHeaders.setData(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
175 self.__replyHeaders.index(0, 1),
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 header[1])
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self.__replyHeaders.item(0, 0).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 self.__replyHeaders.item(0, 1).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 def __showHeaderDetails(self, index):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 Private slot to show a dialog with the header details.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @param index index of the entry to show (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 if not index.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 headerList = self.sender()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 if headerList is None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 row = index.row()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 name = headerList.model().data(headerList.model().index(row, 0))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 value = headerList.model().data(headerList.model().index(row, 1))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 if self.__headersDlg is None:
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
199 from .E5NetworkHeaderDetailsDialog import \
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
200 E5NetworkHeaderDetailsDialog
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 self.__headersDlg = E5NetworkHeaderDetailsDialog(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 self.__headersDlg.setData(name, value)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 self.__headersDlg.show()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
205
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 class E5RequestModel(QAbstractTableModel):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 Class implementing a model storing request objects.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
210 def __init__(self, networkAccessManager, parent=None):
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 Constructor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 @param networkAccessManager reference to the network access manager
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 (QNetworkAccessManager)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 @param parent reference to the parent object (QObject)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
218 super(E5RequestModel, self).__init__(parent)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 self.__headerData = [
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
221 self.tr("Method"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
222 self.tr("Address"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
223 self.tr("Response"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
224 self.tr("Length"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
225 self.tr("Content Type"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
226 self.tr("Info"),
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 ]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 self.__operations = {
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
230 QNetworkAccessManager.HeadOperation: "HEAD",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
231 QNetworkAccessManager.GetOperation: "GET",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
232 QNetworkAccessManager.PutOperation: "PUT",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
233 QNetworkAccessManager.PostOperation: "POST",
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 }
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.requests = []
974
124032ef6b6d Fixed a bug in E5NetworkMonitor connecting a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
237 networkAccessManager.requestCreated.connect(self.__requestCreated)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 def __requestCreated(self, operation, request, reply):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 Private slot handling the creation of a network request.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 @param operation network operation (QNetworkAccessManager.Operation)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @param request reference to the request object (QNetworkRequest)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 @param reply reference to the reply object(QNetworkReply)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 req = E5NetworkRequest()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 req.op = operation
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 req.request = QNetworkRequest(request)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 req.reply = reply
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 self.__addRequest(req)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 def __addRequest(self, req):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 Private method to add a request object to the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 @param req reference to the request object (E5NetworkRequest)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 """
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
259 self.beginInsertRows(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
260 QModelIndex(), len(self.requests), len(self.requests))
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 self.requests.append(req)
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3201
diff changeset
262 req.reply.finished.connect(self.__addReply)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 self.endInsertRows()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 def __addReply(self):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 Private slot to add the reply data to the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 reply = self.sender()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 if reply is None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 offset = len(self.requests) - 1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 while offset >= 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 if self.requests[offset].reply is reply:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 break
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 offset -= 1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 if offset < 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 # save the reply header data
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 for header in reply.rawHeaderList():
556
05b73ee2ae42 Fixed a few issues in E5NetworkMonitor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 482
diff changeset
283 self.requests[offset].replyHeaders.append((
05b73ee2ae42 Fixed a few issues in E5NetworkMonitor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 482
diff changeset
284 str(header, "utf-8"), str(reply.rawHeader(header), "utf-8")))
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 # save reply info to be displayed
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 status = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) or 0
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
288 reason = \
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
289 reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute) or ""
410
e5d1addeb90c Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 365
diff changeset
290 self.requests[offset].response = "{0:d} {1}".format(status, reason)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
291 self.requests[offset].length = \
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
292 reply.header(QNetworkRequest.ContentLengthHeader)
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
293 self.requests[offset].contentType = \
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
294 reply.header(QNetworkRequest.ContentTypeHeader)
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 if status == 302:
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
297 target = reply.attribute(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
298 QNetworkRequest.RedirectionTargetAttribute) or QUrl()
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 self.requests[offset].info = \
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
300 self.tr("Redirect: {0}").format(target.toString())
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
302 def headerData(self, section, orientation, role=Qt.DisplayRole):
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 Public method to get header data from the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 @param section section number (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 @param orientation orientation (Qt.Orientation)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 @param role role of the data to retrieve (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 @return requested data
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 return self.__headerData[section]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 return QAbstractTableModel.headerData(self, section, orientation, role)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
316 def data(self, index, role=Qt.DisplayRole):
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 Public method to get data from the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 @param index index to get data for (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 @param role role of the data to retrieve (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 @return requested data
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 if index.row() < 0 or index.row() >= len(self.requests):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 return None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 if role == Qt.DisplayRole or role == Qt.EditRole:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 col = index.column()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 if col == 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 try:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 return self.__operations[self.requests[index.row()].op]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 except KeyError:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
333 return self.tr("Unknown")
52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 elif col == 1:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 return self.requests[index.row()].request.url().toEncoded()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 elif col == 2:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 return self.requests[index.row()].response
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 elif col == 3:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 return self.requests[index.row()].length
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 elif col == 4:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 return self.requests[index.row()].contentType
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 elif col == 5:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 return self.requests[index.row()].info
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 return None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 def columnCount(self, parent):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 Public method to get the number of columns of the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 @param parent parent index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 @return number of columns (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 if parent.column() > 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 return 0
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 else:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 return len(self.__headerData)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 def rowCount(self, parent):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 Public method to get the number of rows of the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 @param parent parent index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 @return number of columns (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 if parent.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 return 0
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 else:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 return len(self.requests)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 def removeRows(self, row, count, parent):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 Public method to remove entries from the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 @param row start row (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 @param count number of rows to remove (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 @param parent parent index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 @return flag indicating success (boolean)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 if parent.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 return False
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 lastRow = row + count - 1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 self.beginRemoveRows(parent, row, lastRow)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 del self.requests[row:lastRow + 1]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 self.endRemoveRows()
482
4650a72c307a Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 464
diff changeset
387 return True

eric ide

mercurial