Helpviewer/UrlBar/UrlBar.py

changeset 945
8cd4d08fa9f6
parent 826
2e3e2055e715
child 981
8217c9d312c3
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
26 26
27 import UI.PixmapCache 27 import UI.PixmapCache
28 import Preferences 28 import Preferences
29 import Utilities 29 import Utilities
30 30
31
31 class UrlBar(E5LineEdit): 32 class UrlBar(E5LineEdit):
32 """ 33 """
33 Class implementing a line edit for entering URLs. 34 Class implementing a line edit for entering URLs.
34 """ 35 """
35 def __init__(self, mainWindow, parent = None): 36 def __init__(self, mainWindow, parent=None):
36 """ 37 """
37 Constructor 38 Constructor
38 39
39 @param mainWindow reference to the main window (HelpWindow) 40 @param mainWindow reference to the main window (HelpWindow)
40 @param parent reference to the parent widget (HelpBrowser) 41 @param parent reference to the parent widget (HelpBrowser)
41 """ 42 """
42 E5LineEdit.__init__(self, parent) 43 E5LineEdit.__init__(self, parent)
43 self.setInactiveText(self.trUtf8("Enter the location here.")) 44 self.setInactiveText(self.trUtf8("Enter the location here."))
44 45
45 self.__mw = mainWindow 46 self.__mw = mainWindow
46 self.__browser = None 47 self.__browser = None
47 self.__privateMode = QWebSettings.globalSettings().testAttribute( 48 self.__privateMode = QWebSettings.globalSettings().testAttribute(
112 """ 113 """
113 Private slot to handle a URL change of the associated browser. 114 Private slot to handle a URL change of the associated browser.
114 115
115 @param url new URL of the browser (QUrl) 116 @param url new URL of the browser (QUrl)
116 """ 117 """
117 self.setText(str(url.toEncoded(), encoding = "utf-8")) 118 self.setText(str(url.toEncoded(), encoding="utf-8"))
118 self.setCursorPosition(0) 119 self.setCursorPosition(0)
119 120
120 def __loadStarted(self): 121 def __loadStarted(self):
121 """ 122 """
122 Private slot to perform actions before the page is loaded. 123 Private slot to perform actions before the page is loaded.
240 r = (highlight.red() + 2 * backgroundColor.red()) // 3 241 r = (highlight.red() + 2 * backgroundColor.red()) // 3
241 g = (highlight.green() + 2 * backgroundColor.green()) // 3 242 g = (highlight.green() + 2 * backgroundColor.green()) // 3
242 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 243 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3
243 244
244 loadingColor = QColor(r, g, b) 245 loadingColor = QColor(r, g, b)
245 if abs(loadingColor.lightness() - backgroundColor.lightness()) < 20: 246 if abs(loadingColor.lightness() - backgroundColor.lightness()) < 20:
246 # special handling for special color schemes (e.g Gaia) 247 # special handling for special color schemes (e.g Gaia)
247 r = (2 * highlight.red() + backgroundColor.red()) // 3 248 r = (2 * highlight.red() + backgroundColor.red()) // 3
248 g = (2 * highlight.green() + backgroundColor.green()) // 3 249 g = (2 * highlight.green() + backgroundColor.green()) // 3
249 b = (2 * highlight.blue() + backgroundColor.blue()) // 3 250 b = (2 * highlight.blue() + backgroundColor.blue()) // 3
250 loadingColor = QColor(r, g, b) 251 loadingColor = QColor(r, g, b)
285 Protected method to handle key presses. 286 Protected method to handle key presses.
286 287
287 @param evt reference to the key press event (QKeyEvent) 288 @param evt reference to the key press event (QKeyEvent)
288 """ 289 """
289 if evt.key() == Qt.Key_Escape and self.__browser is not None: 290 if evt.key() == Qt.Key_Escape and self.__browser is not None:
290 self.setText(str(self.__browser.url().toEncoded(), encoding = "utf-8")) 291 self.setText(str(self.__browser.url().toEncoded(), encoding="utf-8"))
291 self.selectAll() 292 self.selectAll()
292 return 293 return
293 294
294 currentText = self.text().strip() 295 currentText = self.text().strip()
295 if evt.key() in [Qt.Key_Enter, Qt.Key_Return] and \ 296 if evt.key() in [Qt.Key_Enter, Qt.Key_Return] and \
341 342
342 if url.isEmpty() or not url.isValid(): 343 if url.isEmpty() or not url.isValid():
343 E5LineEdit.dropEvent(self, evt) 344 E5LineEdit.dropEvent(self, evt)
344 return 345 return
345 346
346 self.setText(str(url.toEncoded(), encoding = "utf-8")) 347 self.setText(str(url.toEncoded(), encoding="utf-8"))
347 self.selectAll() 348 self.selectAll()
348 349
349 evt.acceptProposedAction() 350 evt.acceptProposedAction()

eric ide

mercurial