Helpviewer/PersonalInformationManager/PersonalInformationManager.py

changeset 3002
6ffc581f00f1
parent 2403
e3d7a861547c
child 3057
10516539f238
child 3160
209a07d7e401
equal deleted inserted replaced
3001:3674ff5fa8f8 3002:6ffc581f00f1
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
14 import UI.PixmapCache 15 import UI.PixmapCache
15 16
16 17
17 class PersonalInformationManager(QObject): 18 class PersonalInformationManager(QObject):
18 """ 19 """
19 Class implementing the personal information manager used to complete form fields. 20 Class implementing the personal information manager used to complete form
21 fields.
20 """ 22 """
21 FullName = 0 23 FullName = 0
22 LastName = 1 24 LastName = 1
23 FirstName = 2 25 FirstName = 2
24 Email = 3 26 Email = 3
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
210 215
211 return self.Invalid 216 return self.Invalid
212 217
213 def connectPage(self, page): 218 def connectPage(self, page):
214 """ 219 """
215 Public method to allow the personal information manager to connect to the page. 220 Public method to allow the personal information manager to connect to
221 the page.
216 222
217 @param page reference to the web page (HelpWebPage) 223 @param page reference to the web page (HelpWebPage)
218 """ 224 """
219 page.loadFinished.connect(self.__pageLoadFinished) 225 page.loadFinished.connect(self.__pageLoadFinished)
220 226

eric ide

mercurial