2 |
2 |
3 # Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing a personal information manager used to complete form fields. |
7 Module implementing a personal information manager used to complete form |
|
8 fields. |
8 """ |
9 """ |
9 |
10 |
10 from PyQt4.QtCore import Qt, QObject |
11 from PyQt4.QtCore import Qt, QObject |
11 from PyQt4.QtGui import QDialog, QMenu |
12 from PyQt4.QtGui import QDialog, QMenu |
12 |
13 |
120 """ |
122 """ |
121 Public method to create the personal information sub-menu. |
123 Public method to create the personal information sub-menu. |
122 |
124 |
123 @param menu reference to the main menu (QMenu) |
125 @param menu reference to the main menu (QMenu) |
124 @param view reference to the view (HelpBrowser) |
126 @param view reference to the view (HelpBrowser) |
125 @param hitTestResult reference to the hit test result (QWebHitTestResult) |
127 @param hitTestResult reference to the hit test result |
|
128 (QWebHitTestResult) |
126 """ |
129 """ |
127 self.__view = view |
130 self.__view = view |
128 self.__element = hitTestResult.element() |
131 self.__element = hitTestResult.element() |
129 |
132 |
130 if not hitTestResult.isContentEditable(): |
133 if not hitTestResult.isContentEditable(): |
136 submenu = QMenu(self.trUtf8("Insert Personal Information"), menu) |
139 submenu = QMenu(self.trUtf8("Insert Personal Information"), menu) |
137 submenu.setIcon(UI.PixmapCache.getIcon("pim.png")) |
140 submenu.setIcon(UI.PixmapCache.getIcon("pim.png")) |
138 |
141 |
139 for key, info in sorted(self.__allInfo.items()): |
142 for key, info in sorted(self.__allInfo.items()): |
140 if info: |
143 if info: |
141 act = submenu.addAction(self.__translations[key], self.__insertData) |
144 act = submenu.addAction( |
|
145 self.__translations[key], self.__insertData) |
142 act.setData(info) |
146 act.setData(info) |
143 |
147 |
144 submenu.addSeparator() |
148 submenu.addSeparator() |
145 submenu.addAction(self.trUtf8("Edit Personal Information"), |
149 submenu.addAction(self.trUtf8("Edit Personal Information"), |
146 self.showConfigurationDialog) |
150 self.showConfigurationDialog) |
157 return |
161 return |
158 |
162 |
159 info = act.data() |
163 info = act.data() |
160 info = info.replace('"', '\\"') |
164 info = info.replace('"', '\\"') |
161 self.__element.evaluateJavaScript( |
165 self.__element.evaluateJavaScript( |
162 'var newVal = this.value.substring(0, this.selectionStart) + "{0}" +' |
166 'var newVal = this.value.substring(0, this.selectionStart) +' |
163 ' this.value.substring(this.selectionEnd); this.value = newVal;'.format(info)) |
167 ' "{0}" + this.value.substring(this.selectionEnd); this.value =' |
|
168 ' newVal;'.format(info)) |
164 |
169 |
165 def viewKeyPressEvent(self, view, evt): |
170 def viewKeyPressEvent(self, view, evt): |
166 """ |
171 """ |
167 Public method to handle key press events we are interested in. |
172 Public method to handle key press events we are interested in. |
168 |
173 |