def data(self, index, role): """ Public method to get data from the model. @param index index to get data for (QModelIndex) @param role role of the data to retrieve (integer) @return requested data """ if index.row() >= self.__manager.enginesCount() or index.row() < 0: return None engine = self.__manager.engine( self.__manager.allEnginesNames()[index.row()]) if engine is None: return None if index.column() == 0: if role == Qt.DisplayRole: return engine.name() elif role == Qt.DecorationRole: image = engine.image() if image.isNull(): from Helpviewer.HelpWindow import HelpWindow icon = HelpWindow.icon(QUrl(engine.imageUrl())) else: icon = QIcon(QPixmap.fromImage(image)) return icon elif role == Qt.ToolTipRole: description = self.tr("<strong>Description:</strong> {0}")\ .format(engine.description()) if engine.providesSuggestions(): description += "<br/>" description += self.tr( "<strong>Provides contextual suggestions</strong>") return description elif index.column() == 1: if role in [Qt.EditRole, Qt.DisplayRole]: return ",".join(self.__manager.keywordsForEngine(engine)) elif role == Qt.ToolTipRole: return self.tr( "Comma-separated list of keywords that may" " be entered in the location bar followed by search terms" " to search with this engine") return None
def __addEngineByUrl(self, url): """ Private method to add a new search engine given its URL. @param url URL of the engine definition file (QUrl) @return flag indicating success (boolean) """ if not url.isValid(): return from Helpviewer.HelpWindow import HelpWindow reply = HelpWindow.networkAccessManager().get(QNetworkRequest(url)) reply.finished.connect(self.__engineFromUrlAvailable) reply.setParent(self) self.__replies.append(reply) return True
def createMainWidget(argv): """ Function to create the main widget. @param argv list of commandline parameters (list of strings) @return reference to the main widget (QWidget) """ from Helpviewer.HelpWindow import HelpWindow searchWord = None for arg in reversed(argv): if arg.startswith("--search="): searchWord = argv[1].split("=", 1)[1] argv.remove(arg) elif arg.startswith("--"): argv.remove(arg) try: home = argv[1] except IndexError: home = "" help = HelpWindow(home, '.', None, 'help viewer', searchWord=searchWord) return help