class QRefilaLineEdit (object): def __init__(self, collectionSelector, lineEdit): self.filter_line_edit = lineEdit self.collectionSelector = collectionSelector lineEdit.editingFinished.connect(self.reparseRefilaInput) self.completer = QCompleter(["Apple", "Terminal"]) self.completer.setCaseSensitivity(Qt.CaseInsensitive) lineEdit.setCompleter(self.completer) def reparseRefilaInput (self): text = str(self.filter_line_edit.text()) if text == "": self.collectionSelector.updateFilter(None) return filter = Refila.parser.parse(text, debug=True) if filter == None: print ("Parsing failed!") self.collectionSelector.updateFilter(filter)
def __init__(self, parent=None): super(SynthesisQWidget, self).__init__(parent) # Fields self.host_widget = HostQWidget() self.services_widget = ServicesQWidget() self.line_search = QLineEdit() self.completer = QCompleter() self.hint_widget = QWidget()
def __init__(self, collectionSelector, lineEdit): self.filter_line_edit = lineEdit self.collectionSelector = collectionSelector lineEdit.editingFinished.connect(self.reparseRefilaInput) self.completer = QCompleter(["Apple", "Terminal"]) self.completer.setCaseSensitivity(Qt.CaseInsensitive) lineEdit.setCompleter(self.completer)
def __init__(self, gui, icon, do_user_config): QDialog.__init__(self, gui) self.gui = gui self.do_user_config = do_user_config # The current database shown in the GUI > class LibraryDatabase2 self.db = gui.current_db self.l = QVBoxLayout() self.setLayout(self.l) # Label self.labelText = QLabel('Use "and" and "or" for the search.') self.l.addWidget(self.labelText) # Title self.setWindowTitle('SpotlightLibre Full Text Search') self.setWindowIcon(icon) # Search window self.searchTextWindow = QComboBox() self.searchTextWindow.setEditable(True) self.l.addWidget(self.searchTextWindow) self.searchTextWindow.setFocus() self.searchTextWindow.setInsertPolicy(QComboBox.NoInsert) self.searchTextWindow.setDuplicatesEnabled(False) #Completer for the seach window self.completer = QCompleter() self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion ) self.searchTextWindow.setCompleter(self.completer) # output window self.outputWindow = QLabel() self.l.addWidget(self.outputWindow) # search button 1 self.doSearchButton = QPushButton('Search and replace the filter', self) self.doSearchButton.clicked.connect(self.spotlightSearchNew) self.l.addWidget(self.doSearchButton) self.doSearchButton.setDefault(True) # search button 2 self.doSearchButton = QPushButton('Search and add to filter', self) self.doSearchButton.clicked.connect(self.spotlightSearchAdd) self.l.addWidget(self.doSearchButton) # about button self.aboutButton = QPushButton('About', self) self.aboutButton.clicked.connect(self.about) self.l.addWidget(self.aboutButton) self.resize(self.sizeHint())
def create_line_search(self): """ Add all hosts to QLineEdit and set QCompleter """ # Create list for QStringModel hosts_list = [] params = {'where': json.dumps({'_is_template': False})} all_hosts = self.app_backend.get('host', params, ['name']) if all_hosts: for host in all_hosts['_items']: hosts_list.append(host['name']) model = QStringListModel() model.setStringList(hosts_list) # Create completer from model completer = QCompleter() completer.setFilterMode(Qt.MatchContains) completer.setCaseSensitivity(Qt.CaseInsensitive) completer.setModel(model) # Add completer to "line edit" self.line_search.setCompleter(completer) self.line_search.setPlaceholderText( 'Type a host name to display its data') self.line_search.setToolTip('Type a host name to display its data')
def setupUi(self): self.setWindowTitle('Dictionary') layout = QGridLayout(self) self.setLayout(layout) self.edit = QLineEdit(self) self.edit.textChanged.connect(self.onTextChanged) self.edit.returnPressed.connect(self.onReturnPressed) searchButton = QPushButton('&Search', self) searchButton.clicked.connect(self.onSearchButtonClicked) addButton = QPushButton('Add', self) addButton.clicked.connect(self.onAddButtonClicked) header = ('Short', 'Long', "Translate") self.table = QTableWidget(self) self.table.setColumnCount(3) self.table.setHorizontalHeaderLabels(header) self.table.setColumnWidth(0, 50) self.table.setColumnWidth(1, 200) self.edit.setCompleter( QCompleter(self.updateTable(self.dictionary.words))) layout.addWidget(self.edit, 0, 0) layout.addWidget(searchButton, 0, 1) layout.addWidget(addButton, 0, 2) layout.addWidget(self.table, 1, 0, 1, 3)
def _add_completer(items_list, combobox): if items_list is None: items_list = [] completer = QCompleter(items_list) completer.setFilterMode(Qt.MatchContains) completer.setCompletionMode(QCompleter.PopupCompletion) combobox.setCompleter(completer)
def set_model(self, prefix): """ Update the completion model when the prefix is known. Has to be done through an instance variable because of a bug (will not complete the line edit otherwise) CFG02 """ # storage in __model is required because, apparently, the value # returned from DatabaseLogLite.model() is deleted somehow (not stored # anywhere) if used directly to set the QCompleter, disabling # completion silently self.__model = database().model(prefix) self.__completer = QCompleter(self.__model, self) self.setCompleter(self.__completer)
def __init__(self, parent=None): QComboBox.__init__(self, parent) self.line_edit = SearchLineEdit(self) self.setLineEdit(self.line_edit) self.line_edit.key_pressed.connect(self.key_pressed, type=Qt.DirectConnection) self.activated[native_string_type].connect(self.saved_search_selected) # Turn off auto-completion so that it doesn't interfere with typing # names of new searches. completer = QCompleter(self) self.setCompleter(completer) self.setEditable(True) self.setInsertPolicy(self.NoInsert) self.setSizeAdjustPolicy(self.AdjustToMinimumContentsLengthWithIcon) self.setMinimumContentsLength(10) self.tool_tip_text = self.toolTip()
def __init__(self, gui, icon, do_user_config): QDialog.__init__(self, gui) self.gui = gui self.do_user_config = do_user_config # The current database shown in the GUI # db is an instance of the class LibraryDatabase2 from database.py # This class has many, many methods that allow you to do a lot of # things. self.db = gui.current_db self.l = QVBoxLayout() self.setLayout(self.l) # Label self.labelText = QLabel('Use "and" and "or" for the search.') self.l.addWidget(self.labelText) # Title self.setWindowTitle('Recoll Full Text Search') self.setWindowIcon(icon) # Search window self.searchTextWindow = QComboBox() self.searchTextWindow.setEditable(True) self.l.addWidget(self.searchTextWindow) self.searchTextWindow.setFocus() self.searchTextWindow.setInsertPolicy(QComboBox.NoInsert) self.searchTextWindow.setDuplicatesEnabled(False) #Completer for the seach window self.completer = QCompleter() self.completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion) self.searchTextWindow.setCompleter(self.completer) # output window self.outputWindow = QLabel() self.l.addWidget(self.outputWindow) # search button 1 self.doSearchButton = QPushButton('Search and replace the filter', self) self.doSearchButton.clicked.connect(self.recollSearchNew) self.l.addWidget(self.doSearchButton) self.doSearchButton.setDefault(True) # search button 2 self.doSearchButton = QPushButton('Search and add to filter', self) self.doSearchButton.clicked.connect(self.recollSearchAdd) self.l.addWidget(self.doSearchButton) # update database button 1 self.updateDatabaseButton = QPushButton('Update recoll database', self) self.updateDatabaseButton.clicked.connect(self.updateDatabase) self.l.addWidget(self.updateDatabaseButton) # update database button 2 self.newDatabaseButton = QPushButton('Make new recoll database', self) self.newDatabaseButton.clicked.connect(self.newDatabase) self.l.addWidget(self.newDatabaseButton) # config button self.configButton = QPushButton('Configure this plugin', self) self.configButton.clicked.connect(self.config) self.l.addWidget(self.configButton) # about button self.aboutButton = QPushButton('About', self) self.aboutButton.clicked.connect(self.about) self.l.addWidget(self.aboutButton) self.resize(self.sizeHint())
class RecollFulltextSearchDialog(QDialog): def __init__(self, gui, icon, do_user_config): QDialog.__init__(self, gui) self.gui = gui self.do_user_config = do_user_config # The current database shown in the GUI # db is an instance of the class LibraryDatabase2 from database.py # This class has many, many methods that allow you to do a lot of # things. self.db = gui.current_db self.l = QVBoxLayout() self.setLayout(self.l) # Label self.labelText = QLabel('Use "and" and "or" for the search.') self.l.addWidget(self.labelText) # Title self.setWindowTitle('Recoll Full Text Search') self.setWindowIcon(icon) # Search window self.searchTextWindow = QComboBox() self.searchTextWindow.setEditable(True) self.l.addWidget(self.searchTextWindow) self.searchTextWindow.setFocus() self.searchTextWindow.setInsertPolicy(QComboBox.NoInsert) self.searchTextWindow.setDuplicatesEnabled(False) #Completer for the seach window self.completer = QCompleter() self.completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion) self.searchTextWindow.setCompleter(self.completer) # output window self.outputWindow = QLabel() self.l.addWidget(self.outputWindow) # search button 1 self.doSearchButton = QPushButton('Search and replace the filter', self) self.doSearchButton.clicked.connect(self.recollSearchNew) self.l.addWidget(self.doSearchButton) self.doSearchButton.setDefault(True) # search button 2 self.doSearchButton = QPushButton('Search and add to filter', self) self.doSearchButton.clicked.connect(self.recollSearchAdd) self.l.addWidget(self.doSearchButton) # update database button 1 self.updateDatabaseButton = QPushButton('Update recoll database', self) self.updateDatabaseButton.clicked.connect(self.updateDatabase) self.l.addWidget(self.updateDatabaseButton) # update database button 2 self.newDatabaseButton = QPushButton('Make new recoll database', self) self.newDatabaseButton.clicked.connect(self.newDatabase) self.l.addWidget(self.newDatabaseButton) # config button self.configButton = QPushButton('Configure this plugin', self) self.configButton.clicked.connect(self.config) self.l.addWidget(self.configButton) # about button self.aboutButton = QPushButton('About', self) self.aboutButton.clicked.connect(self.about) self.l.addWidget(self.aboutButton) self.resize(self.sizeHint()) #self.resize(500, self.height()) def about(self): # Get the about text from a file inside the plugin zip file # The get_resources function is a builtin function defined for all your # plugin code. It loads files from the plugin zip file. It returns # the bytes from the specified file. text = get_resources('about.txt') #box = QMessageBox() #box.about(self, 'About the Recoll Full Text Search \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t',text.decode('utf-8')) #self.resize(600, self.height()) self.box = AboutWindow() self.box.setWindowTitle("About the Recoll Full Text Search Plugin") self.box.textWindow.setText(text) self.box.textWindow.setReadOnly(True) self.box.resize(600, 500) self.box.show() def updateDatabase(self): self.replaceDatabase = False self.makeDatabase() def newDatabase(self): self.replaceDatabase = True self.makeDatabase() def recollSearchNew(self): self.searchAdd = False self.recollSearch() def recollSearchAdd(self): self.searchAdd = True self.recollSearch() def makeDatabase(self): '''Runs recollindex outside calibre like in a terminal. Look for recollindex for more information about the flags and options''' self.cmd = [ prefs['pathToRecoll'] + '/recollindex', '-c', prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin' ] #TODO: Fix for Linux #self.cmd = 'LD_LIBRARY_PATH="" ' + prefs['pathToRecoll'] + '/recollindex -c ' + prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin' if self.replaceDatabase == True: self.cmd += [' -z'] self.p = Popen(self.cmd, shell=False) # TODO: Was close_fds nessesary? check it on linux #self.p = Popen(self.cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) box = QMessageBox() box.about( self, 'Please read! \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t', 'Depending on you library size this operation can take a lot of time.\nThe process runs outside calibre so you can use or close it, but do not use this plugin.\nFor now there is no information about when recoll finishs,\nso look up, whether a recoll of recollindex process is running on you system.' ) def recollSearch(self): '''Runs recoll outside calibre like in a terminal. Look for recollindex for more information about the flags and options''' self.searchText = str(self.searchTextWindow.currentText() ) # search text from the plugin gui self.searchTextWindow.insertItem(0, self.searchText) #TODO: Fix Linux #self.cmd = 'LD_LIBRARY_PATH="" ' + prefs['pathToRecoll'] + '/recoll -c ' + prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin -b -t ' self.cmd = [ prefs['pathToRecoll'] + '/recoll', '-c', prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin', '-b', '-t' ] self.cmdString = self.cmd + [self.searchText] # TODO: Was close_fds nessesary? check it on linux #self.p = Popen(self.cmdString, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) self.p = Popen(self.cmdString, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) self.output = self.p.stdout.read() # output from the recoll search self.found = list(set(re.findall( r" \((\d+)\)\/[^/]*", self.output))) # regex to find the calibre ids in the folder names self.wholeString = '' if len(self.found) == 0: self.outputWindow.setText('no books found' + ' for ' + self.searchText) else: for elem in self.found[:400]: self.wholeString += 'id:=' + elem + ' or ' self.wholeString = self.wholeString[:-4] if len(self.found) > 400: self.outputWindow.setText( str(len(self.found)) + ' books found' + ' for ' + self.searchText + '. Only the first 400 books are shown') else: self.outputWindow.setText( str(len(self.found)) + ' books found' + ' for ' + self.searchText) if self.searchAdd == True: self.oldFilter = self.gui.search.text() self.wholeString = self.oldFilter + ' and (' + self.wholeString + ')' self.searchTextWindow.clearEditText() self.gui.search.setEditText( self.wholeString ) # set calibre search to the string found by recoll self.gui.search.do_search() def config(self): self.do_user_config(parent=self)
class SynthesisQWidget(QWidget): """ Class who manage Synthesis view with Host and Services QWidgets """ def __init__(self, parent=None): super(SynthesisQWidget, self).__init__(parent) # Fields self.host_widget = HostQWidget() self.services_widget = ServicesQWidget() self.line_search = QLineEdit() self.completer = QCompleter() self.hint_widget = QWidget() def initialize_synthesis(self): """ Initialize Synthesis QWidget """ synthesis_layout = QVBoxLayout() synthesis_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(synthesis_layout) # Search widget search_widget = self.get_search_widget() synthesis_layout.addWidget(search_widget) # Host widget self.host_widget.initialize() self.host_widget.setMaximumHeight(self.width() * 0.5) synthesis_layout.addWidget(self.host_widget) # Hint Widget hint_text = _( '<h4>Dahsboard</h4>' '<ul><li>At the top of App, ' 'you have a dashboard that summarizes the number of items per state.</li></ul>' '<h4>Tabs</h4>' '<ul><li><h4>Host Synthesis</h4></li>' 'Tap in the search bar to view a host and its services.' '<li><h4>Problems</h4></li>' 'The "Problems" tab will show you all problems detected in your backend.' '<li><h4>Spy Hosts</h4></li>' 'A "Spy Host" will keep you regularly informed of his condition. ' 'You will also see problems detected for this host, in the "Spy Hosts" panel.</ul>' '<h4>Alignak</h4>' '<ul><li>You can see your backend status and daemons if available, ' 'as well as your profile.</li></ul>' '<h4>Livestate</h4>' '<ul><li>In the livestate, you can see global state of your monitored items.</li></ul>' '<h4>Events</h4>' '<ul><li>Events will show you informative messages your actions inside App.</li></ul>' ) hint_layout = QVBoxLayout(self.hint_widget) hint_label = QLabel(hint_text) hint_label.setObjectName('subtitle') hint_layout.addWidget(hint_label) synthesis_layout.addWidget(self.hint_widget) # Services widget self.services_widget.initialize() synthesis_layout.addWidget(self.services_widget) # Align all widgets to Top synthesis_layout.setAlignment(Qt.AlignTop) def get_search_widget(self): """ Create and return the search QWidget :return: search QWidget :rtype: QWidget """ widget = QWidget() layout = QHBoxLayout() layout.setSpacing(0) widget.setLayout(layout) # Search label search_lbl = QLabel(_('Search Host')) search_lbl.setObjectName('bordertitle') search_lbl.setFixedHeight(25) search_lbl.setToolTip(_('Search Host')) layout.addWidget(search_lbl) # QLineEdit self.line_search.setFixedHeight(search_lbl.height()) layout.addWidget(self.line_search) self.create_line_search([]) return widget def create_line_search(self, hostnames_list): """ Add all hosts to QLineEdit and set QCompleter :param hostnames_list: list of host names :type hostnames_list: list """ # Get QStringListModel model = self.completer.model() if not model: model = QStringListModel() model.setStringList(hostnames_list) # Configure QCompleter from model self.completer.setFilterMode(Qt.MatchContains) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.completer.setModel(model) self.completer.popup().setObjectName('popup') # Add completer to QLineEdit self.line_search.setCompleter(self.completer) self.line_search.setPlaceholderText(_('Type a host name to display its data')) self.line_search.setToolTip(_('Type a host name to display its data')) def update_synthesis(self, host, services, not_spied): """ Update Synthesis QWidget with given host and services :param host: host item :type host: alignak_app.items.host.Host :param services: list of services attached to host :type services: list :param not_spied: define if host is spied or not :type not_spied: bool """ self.host_widget.spy_btn.setEnabled(not_spied) if host: logger.info('Display %s in synthesis view', host.name) # Update Qwidgets self.host_widget.update_host(host) self.services_widget.update_widget(services) self.hint_widget.hide() self.host_widget.show() self.services_widget.show() # If the service element does not have the same ID as the host, reset to None if self.services_widget.service_data_widget.service_item: if self.services_widget.service_data_widget.service_item.data['host'] != \ self.host_widget.host_item.item_id: self.services_widget.service_data_widget.service_item = None else: self.host_widget.hide() self.services_widget.hide() self.hint_widget.show()
def __init__(self, parent=None): super().__init__(parent) self._completer = None # LocationCompleter self._domainCompleterModel = None # QStringListModel self._bookmarkIcon = None # BookmarksIcon self._goIcon = None # GoIcon self._siteIcon = None # SiteIcon self._autofillIcon = None # AutoFillIcon self._window = None # BrowserWindow self._webView = None # TabbedWebView self._holdingAlt = False self._oldTextLength = 0 self._currentTextLength = 0 self._loadProgress = 0 self._progressVisible = True self._progressStyle = 0 # ProgressStyle self._progressColor = QColor() self._progressTimer = None # QTimer self.setObjectName('locationbar') self.setDragEnabled(True) # Disable KDE QLineEdit transitions, it breaks with setText() && home() self._bookmarkIcon = BookmarksIcon(self) self._goIcon = GoIcon(self) self._siteIcon = SiteIcon(self) self._autofillIcon = AutoFillIcon(self) down = DownIcon(self) self.addWidget(self._siteIcon, LineEdit.LeftSide) self.addWidget(self._autofillIcon, LineEdit.RightSide) self.addWidget(self._bookmarkIcon, LineEdit.RightSide) self.addWidget(self._goIcon, LineEdit.RightSide) self.addWidget(down, LineEdit.RightSide) self._completer = LocationCompleter(self) self._completer.setLocationBar(self) self._completer.showCompletion.connect(self._showCompletion) self._completer.showDomainCompletion.connect( self._showDomainCompletion) self._completer.clearCompletion.connect(self._clearCompletion) self._completer.loadRequested.connect(self.loadRequest) self._completer.popupClosed.connect(self._updateSiteIcon) self._domainCompleterModel = QStringListModel(self) domainCompleter = QCompleter(self) domainCompleter.setCompletionMode(QCompleter.InlineCompletion) domainCompleter.setModel(self._domainCompleterModel) self.setCompleter(domainCompleter) self._progressTimer = QTimer(self) self._progressTimer.setInterval(700) self._progressTimer.setSingleShot(True) self._progressTimer.timeout.connect(self._hideProgress) self.editAction(self.PasteAndGo).setText(_('Paste And &Go')) self.editAction(self.PasteAndGo).setIcon(QIcon.fromTheme('edit-paste')) self.editAction(self.PasteAndGo).triggered.connect(self._pasteAndGo) self.textEdited.connect(self._textEdited) self._goIcon.clicked.connect(self._requestLoadUrl) down.clicked.connect(self._completer.showMostVisited) # TODO: #gVar.app.searchEnginesManager().activeEngineChanged.connect(self._updatePlaceHolderText) #gVar.app.searchEnginesManager().defaultEngineChanged.connect(self._updatePlaceHolderText) self._loadSettings() self._updateSiteIcon() # Hide icons by default self._goIcon.setVisible(gVar.appSettings.alwaysShowGoIcon) self._autofillIcon.hide() QTimer.singleShot(0, self._updatePlaceHolderText)
class SynthesisQWidget(QWidget): """ Class who manage Synthesis view with Host and Services QWidgets """ def __init__(self, parent=None): super(SynthesisQWidget, self).__init__(parent) # Fields self.host_widget = HostQWidget() self.services_widget = ServicesQWidget() self.line_search = QLineEdit() self.completer = QCompleter() self.hint_widget = QWidget() def initialize_synthesis(self): """ Initialize Synthesis QWidget """ synthesis_layout = QVBoxLayout() synthesis_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(synthesis_layout) # Search widget search_widget = self.get_search_widget() synthesis_layout.addWidget(search_widget) # Host widget self.host_widget.initialize() self.host_widget.setMaximumHeight(self.width() * 0.5) synthesis_layout.addWidget(self.host_widget) # Hint Widget hint_text = _( '<h4>Dahsboard</h4>' '<ul><li>At the top of App, ' 'you have a dashboard that summarizes the number of items per state.</li></ul>' '<h4>Tabs</h4>' '<ul><li><h4>Host Synthesis</h4></li>' 'Tap in the search bar to view a host and its services.' '<li><h4>Problems</h4></li>' 'The "Problems" tab will show you all problems detected in your backend.' '<li><h4>Spy Hosts</h4></li>' 'A "Spy Host" will keep you regularly informed of his condition. ' 'You will also see problems detected for this host, in the "Spy Hosts" panel.</ul>' '<h4>Alignak</h4>' '<ul><li>You can see your backend status and daemons if available, ' 'as well as your profile.</li></ul>' '<h4>Livestate</h4>' '<ul><li>In the livestate, you can see global state of your monitored items.</li></ul>' '<h4>Events</h4>' '<ul><li>Events will show you informative messages your actions inside App.</li></ul>' ) hint_layout = QVBoxLayout(self.hint_widget) hint_label = QLabel(hint_text) hint_label.setObjectName('subtitle') hint_layout.addWidget(hint_label) synthesis_layout.addWidget(self.hint_widget) # Services widget self.services_widget.initialize() synthesis_layout.addWidget(self.services_widget) # Align all widgets to Top synthesis_layout.setAlignment(Qt.AlignTop) def get_search_widget(self): """ Create and return the search QWidget :return: search QWidget :rtype: QWidget """ widget = QWidget() layout = QHBoxLayout() layout.setSpacing(0) widget.setLayout(layout) # Search label search_lbl = QLabel(_('Search Host')) search_lbl.setObjectName('bordertitle') search_lbl.setFixedHeight(25) search_lbl.setToolTip(_('Search Host')) layout.addWidget(search_lbl) # QLineEdit self.line_search.setFixedHeight(search_lbl.height()) layout.addWidget(self.line_search) self.create_line_search([]) return widget def create_line_search(self, hostnames_list): """ Add all hosts to QLineEdit and set QCompleter :param hostnames_list: list of host names :type hostnames_list: list """ # Get QStringListModel model = self.completer.model() if not model: model = QStringListModel() model.setStringList(hostnames_list) # Configure QCompleter from model self.completer.setFilterMode(Qt.MatchContains) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.completer.setModel(model) self.completer.popup().setObjectName('popup') # Add completer to QLineEdit self.line_search.setCompleter(self.completer) self.line_search.setPlaceholderText( _('Type a host name to display its data')) self.line_search.setToolTip(_('Type a host name to display its data')) def update_synthesis(self, host, services, not_spied): """ Update Synthesis QWidget with given host and services :param host: host item :type host: alignak_app.items.host.Host :param services: list of services attached to host :type services: list :param not_spied: define if host is spied or not :type not_spied: bool """ self.host_widget.spy_btn.setEnabled(not_spied) if host: logger.info('Display %s in synthesis view', host.name) # Update Qwidgets self.host_widget.update_host(host) self.services_widget.update_widget(services) self.hint_widget.hide() self.host_widget.show() self.services_widget.show() # If the service element does not have the same ID as the host, reset to None if self.services_widget.service_data_widget.service_item: if self.services_widget.service_data_widget.service_item.data['host'] != \ self.host_widget.host_item.item_id: self.services_widget.service_data_widget.service_item = None else: self.host_widget.hide() self.services_widget.hide() self.hint_widget.show()
def __init__(self, parent, all_items): QCompleter.__init__(self, all_items, parent) self.all_items = set(all_items)
class SpotlightLibreDialog(QDialog): def __init__(self, gui, icon, do_user_config): QDialog.__init__(self, gui) self.gui = gui self.do_user_config = do_user_config # The current database shown in the GUI > class LibraryDatabase2 self.db = gui.current_db self.l = QVBoxLayout() self.setLayout(self.l) # Label self.labelText = QLabel('Use "and" and "or" for the search.') self.l.addWidget(self.labelText) # Title self.setWindowTitle('SpotlightLibre Full Text Search') self.setWindowIcon(icon) # Search window self.searchTextWindow = QComboBox() self.searchTextWindow.setEditable(True) self.l.addWidget(self.searchTextWindow) self.searchTextWindow.setFocus() self.searchTextWindow.setInsertPolicy(QComboBox.NoInsert) self.searchTextWindow.setDuplicatesEnabled(False) #Completer for the seach window self.completer = QCompleter() self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion ) self.searchTextWindow.setCompleter(self.completer) # output window self.outputWindow = QLabel() self.l.addWidget(self.outputWindow) # search button 1 self.doSearchButton = QPushButton('Search and replace the filter', self) self.doSearchButton.clicked.connect(self.spotlightSearchNew) self.l.addWidget(self.doSearchButton) self.doSearchButton.setDefault(True) # search button 2 self.doSearchButton = QPushButton('Search and add to filter', self) self.doSearchButton.clicked.connect(self.spotlightSearchAdd) self.l.addWidget(self.doSearchButton) # about button self.aboutButton = QPushButton('About', self) self.aboutButton.clicked.connect(self.about) self.l.addWidget(self.aboutButton) self.resize(self.sizeHint()) #self.resize(500, self.height()) def about(self): # Get the about text from a file inside the plugin zip file # The get_resources function is a builtin function defined for all your # plugin code. It loads files from the plugin zip file. It returns # the bytes from the specified file. text = get_resources('about.txt') #box = QMessageBox() #box.about(self, 'About the SpotlightLibre Full Text Search \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t',text.decode('utf-8')) #self.resize(600, self.height()) self.box = AboutWindow() self.box.setWindowTitle("About the SpotlightLibre Full Text Search Plugin") self.box.textWindow.setText(text) self.box.textWindow.setReadOnly(True) self.box.resize(600, 500) self.box.show() def spotlightSearchNew(self): self.searchAdd = False self.spotlightSearch() def spotlightSearchAdd(self): self.searchAdd = True self.spotlightSearch() def spotlightSearch(self): self.searchText = str(self.searchTextWindow.currentText())# search text from the plugin gui self.searchTextWindow.insertItem(0, self.searchText) # self.cmd = 'mdfind -onlyin '+ prefs['pathToLibrary']+' ' # saved to allow for checkbox option later? print(self.db.library_path) self.cmd = 'mdfind -onlyin "'+self.db.library_path+'" ' self.cmdString = self.cmd + '"'+self.searchText+'"' print(self.cmdString) self.p = Popen(self.cmdString, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) self.output = self.p.stdout.read()# output from the spotlight search print(self.output) self.found = '' self.found = re.findall(r" \((\d+)\)\/", self.output)# regex to find the calibre ids in the folder names self.wholeString = '' if len(self.found) == 0 : self.outputWindow.setText('no books found' + ' for ' + self.searchText) else : self.wholeString = '#cid:' for elem in self.found: self.wholeString += '=' + elem + ' or ' self.wholeString = self.wholeString[:-4] self.outputWindow.setText(str(len(self.found)) + ' books found' + ' for ' + self.searchText) if self.searchAdd == True : self.oldFilter = self.gui.search.text() self.wholeString = self.oldFilter + ' and (' + self.wholeString + ')' self.searchTextWindow.clearEditText() self.gui.search.setEditText(self.wholeString) # set calibre search to the string found by spotlight self.gui.search.do_search() def config(self): self.do_user_config(parent=self)
class RecollFulltextSearchDialog(QDialog): def __init__(self, gui, icon, do_user_config): QDialog.__init__(self, gui) self.gui = gui self.do_user_config = do_user_config # The current database shown in the GUI # db is an instance of the class LibraryDatabase2 from database.py # This class has many, many methods that allow you to do a lot of # things. self.db = gui.current_db self.l = QVBoxLayout() self.setLayout(self.l) # Label self.labelText = QLabel('Use "and" and "or" for the search.') self.l.addWidget(self.labelText) # Title self.setWindowTitle('Recoll Full Text Search') self.setWindowIcon(icon) # Search window self.searchTextWindow = QComboBox() self.searchTextWindow.setEditable(True) self.l.addWidget(self.searchTextWindow) self.searchTextWindow.setFocus() self.searchTextWindow.setInsertPolicy(QComboBox.NoInsert) self.searchTextWindow.setDuplicatesEnabled(False) #Completer for the seach window self.completer = QCompleter() self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion ) self.searchTextWindow.setCompleter(self.completer) # output window self.outputWindow = QLabel() self.l.addWidget(self.outputWindow) # search button 1 self.doSearchButton = QPushButton('Search and replace the filter', self) self.doSearchButton.clicked.connect(self.recollSearchNew) self.l.addWidget(self.doSearchButton) self.doSearchButton.setDefault(True) # search button 2 self.doSearchButton = QPushButton('Search and add to filter', self) self.doSearchButton.clicked.connect(self.recollSearchAdd) self.l.addWidget(self.doSearchButton) # update database button 1 self.updateDatabaseButton = QPushButton('Update recoll database', self) self.updateDatabaseButton.clicked.connect(self.updateDatabase) self.l.addWidget(self.updateDatabaseButton) # update database button 2 self.newDatabaseButton = QPushButton('Make new recoll database', self) self.newDatabaseButton.clicked.connect(self.newDatabase) self.l.addWidget(self.newDatabaseButton) # config button self.configButton = QPushButton('Configure this plugin', self) self.configButton.clicked.connect(self.config) self.l.addWidget(self.configButton) # about button self.aboutButton = QPushButton('About', self) self.aboutButton.clicked.connect(self.about) self.l.addWidget(self.aboutButton) self.resize(self.sizeHint()) #self.resize(500, self.height()) def about(self): # Get the about text from a file inside the plugin zip file # The get_resources function is a builtin function defined for all your # plugin code. It loads files from the plugin zip file. It returns # the bytes from the specified file. text = get_resources('about.txt') #box = QMessageBox() #box.about(self, 'About the Recoll Full Text Search \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t',text.decode('utf-8')) #self.resize(600, self.height()) self.box = AboutWindow() self.box.setWindowTitle("About the Recoll Full Text Search Plugin") self.box.textWindow.setText(text) self.box.textWindow.setReadOnly(True) self.box.resize(600, 500) self.box.show() def updateDatabase(self): self.replaceDatabase =False self.makeDatabase() def newDatabase(self): self.replaceDatabase = True self.makeDatabase() def recollSearchNew(self): self.searchAdd = False self.recollSearch() def recollSearchAdd(self): self.searchAdd = True self.recollSearch() def makeDatabase(self): '''Runs recollindex outside calibre like in a terminal. Look for recollindex for more information about the flags and options''' self.cmd = [prefs['pathToRecoll'] + '/recollindex', '-c', prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin'] #TODO: Fix for Linux #self.cmd = 'LD_LIBRARY_PATH="" ' + prefs['pathToRecoll'] + '/recollindex -c ' + prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin' if self.replaceDatabase == True : self.cmd += [' -z'] self.p = Popen(self.cmd, shell=False) # TODO: Was close_fds nessesary? check it on linux #self.p = Popen(self.cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) box = QMessageBox() box.about(self, 'Please read! \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t','Depending on you library size this operation can take a lot of time.\nThe process runs outside calibre so you can use or close it, but do not use this plugin.\nFor now there is no information about when recoll finishs,\nso look up, whether a recoll of recollindex process is running on you system.') def recollSearch(self): '''Runs recoll outside calibre like in a terminal. Look for recollindex for more information about the flags and options''' self.searchText = str(self.searchTextWindow.currentText())# search text from the plugin gui self.searchTextWindow.insertItem(0, self.searchText) #TODO: Fix Linux #self.cmd = 'LD_LIBRARY_PATH="" ' + prefs['pathToRecoll'] + '/recoll -c ' + prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin -b -t ' self.cmd = [prefs['pathToRecoll'] + '/recoll', '-c', prefs['pathToCofig'] + '/plugins/recollFullTextSearchPlugin', '-b', '-t'] self.cmdString = self.cmd + [self.searchText] # TODO: Was close_fds nessesary? check it on linux #self.p = Popen(self.cmdString, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) self.p = Popen(self.cmdString, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) self.output = self.p.stdout.read()# output from the recoll search self.found = list(set(re.findall(r" \((\d+)\)\/[^/]*", self.output)))# regex to find the calibre ids in the folder names self.wholeString = '' if len(self.found) == 0 : self.outputWindow.setText('no books found' + ' for ' + self.searchText) else : for elem in self.found[:400]: self.wholeString += 'id:=' + elem + ' or ' self.wholeString = self.wholeString[:-4] if len(self.found) > 400 : self.outputWindow.setText(str(len(self.found)) + ' books found' + ' for ' + self.searchText+ '. Only the first 400 books are shown') else : self.outputWindow.setText(str(len(self.found)) + ' books found' + ' for ' + self.searchText) if self.searchAdd == True : self.oldFilter = self.gui.search.text() self.wholeString = self.oldFilter + ' and (' + self.wholeString + ')' self.searchTextWindow.clearEditText() self.gui.search.setEditText(self.wholeString) # set calibre search to the string found by recoll self.gui.search.do_search() def config(self): self.do_user_config(parent=self)
def __init__(self, gui, icon, do_user_config): QDialog.__init__(self, gui) self.gui = gui self.do_user_config = do_user_config # The current database shown in the GUI # db is an instance of the class LibraryDatabase2 from database.py # This class has many, many methods that allow you to do a lot of # things. self.db = gui.current_db self.l = QVBoxLayout() self.setLayout(self.l) # Label self.labelText = QLabel('Use "and" and "or" for the search.') self.l.addWidget(self.labelText) # Title self.setWindowTitle('Recoll Full Text Search') self.setWindowIcon(icon) # Search window self.searchTextWindow = QComboBox() self.searchTextWindow.setEditable(True) self.l.addWidget(self.searchTextWindow) self.searchTextWindow.setFocus() self.searchTextWindow.setInsertPolicy(QComboBox.NoInsert) self.searchTextWindow.setDuplicatesEnabled(False) #Completer for the seach window self.completer = QCompleter() self.completer.setCompletionMode( QCompleter.UnfilteredPopupCompletion ) self.searchTextWindow.setCompleter(self.completer) # output window self.outputWindow = QLabel() self.l.addWidget(self.outputWindow) # search button 1 self.doSearchButton = QPushButton('Search and replace the filter', self) self.doSearchButton.clicked.connect(self.recollSearchNew) self.l.addWidget(self.doSearchButton) self.doSearchButton.setDefault(True) # search button 2 self.doSearchButton = QPushButton('Search and add to filter', self) self.doSearchButton.clicked.connect(self.recollSearchAdd) self.l.addWidget(self.doSearchButton) # update database button 1 self.updateDatabaseButton = QPushButton('Update recoll database', self) self.updateDatabaseButton.clicked.connect(self.updateDatabase) self.l.addWidget(self.updateDatabaseButton) # update database button 2 self.newDatabaseButton = QPushButton('Make new recoll database', self) self.newDatabaseButton.clicked.connect(self.newDatabase) self.l.addWidget(self.newDatabaseButton) # config button self.configButton = QPushButton('Configure this plugin', self) self.configButton.clicked.connect(self.config) self.l.addWidget(self.configButton) # about button self.aboutButton = QPushButton('About', self) self.aboutButton.clicked.connect(self.about) self.l.addWidget(self.aboutButton) self.resize(self.sizeHint())