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 __future__ import unicode_literals # __IGNORE_WARNING__ |
11 from __future__ import unicode_literals # __IGNORE_WARNING__ |
11 |
12 |
12 from PyQt4.QtCore import Qt, QObject |
13 from PyQt4.QtCore import Qt, QObject |
122 """ |
124 """ |
123 Public method to create the personal information sub-menu. |
125 Public method to create the personal information sub-menu. |
124 |
126 |
125 @param menu reference to the main menu (QMenu) |
127 @param menu reference to the main menu (QMenu) |
126 @param view reference to the view (HelpBrowser) |
128 @param view reference to the view (HelpBrowser) |
127 @param hitTestResult reference to the hit test result (QWebHitTestResult) |
129 @param hitTestResult reference to the hit test result |
|
130 (QWebHitTestResult) |
128 """ |
131 """ |
129 self.__view = view |
132 self.__view = view |
130 self.__element = hitTestResult.element() |
133 self.__element = hitTestResult.element() |
131 |
134 |
132 if not hitTestResult.isContentEditable(): |
135 if not hitTestResult.isContentEditable(): |
138 submenu = QMenu(self.trUtf8("Insert Personal Information"), menu) |
141 submenu = QMenu(self.trUtf8("Insert Personal Information"), menu) |
139 submenu.setIcon(UI.PixmapCache.getIcon("pim.png")) |
142 submenu.setIcon(UI.PixmapCache.getIcon("pim.png")) |
140 |
143 |
141 for key, info in sorted(self.__allInfo.items()): |
144 for key, info in sorted(self.__allInfo.items()): |
142 if info: |
145 if info: |
143 act = submenu.addAction(self.__translations[key], self.__insertData) |
146 act = submenu.addAction( |
|
147 self.__translations[key], self.__insertData) |
144 act.setData(info) |
148 act.setData(info) |
145 |
149 |
146 submenu.addSeparator() |
150 submenu.addSeparator() |
147 submenu.addAction(self.trUtf8("Edit Personal Information"), |
151 submenu.addAction(self.trUtf8("Edit Personal Information"), |
148 self.showConfigurationDialog) |
152 self.showConfigurationDialog) |
159 return |
163 return |
160 |
164 |
161 info = act.data() |
165 info = act.data() |
162 info = info.replace('"', '\\"') |
166 info = info.replace('"', '\\"') |
163 self.__element.evaluateJavaScript( |
167 self.__element.evaluateJavaScript( |
164 'var newVal = this.value.substring(0, this.selectionStart) + "{0}" +' |
168 'var newVal = this.value.substring(0, this.selectionStart) +' |
165 ' this.value.substring(this.selectionEnd); this.value = newVal;'.format(info)) |
169 ' "{0}" + this.value.substring(this.selectionEnd); this.value =' |
|
170 ' newVal;'.format(info)) |
166 |
171 |
167 def viewKeyPressEvent(self, view, evt): |
172 def viewKeyPressEvent(self, view, evt): |
168 """ |
173 """ |
169 Public method to handle key press events we are interested in. |
174 Public method to handle key press events we are interested in. |
170 |
175 |