def update_search_letters(self, text): """Update search letters with text input in search box.""" self.letters = text contexts = [shortcut.context for shortcut in self.shortcuts] names = [shortcut.name for shortcut in self.shortcuts] context_results = get_search_scores( text, contexts, template='<b>{0}</b>') results = get_search_scores(text, names, template='<b>{0}</b>') __, self.context_rich_text, context_scores = ( zip(*context_results)) self.normal_text, self.rich_text, self.scores = zip(*results) self.scores = [x + y for x, y in zip(self.scores, context_scores)] self.reset()
def update_search_letters(self, text): """Update search letters with text input in search box.""" self.letters = text names = [shortcut.name for shortcut in self.shortcuts] results = get_search_scores(text, names, template='<b>{0}</b>') self.normal_text, self.rich_text, self.scores = zip(*results) self.reset()
def setup(self): """Set-up list widget content based on the filtering.""" # Check exited mode mode = self._mode_on if mode: search_text = self.search_text()[len(mode):] else: search_text = self.search_text() # Check exited mode if mode and self.search_text() == '': self._mode_on = '' self.sig_mode_selected.emit(self._mode_on) return # Check entered mode for key in self._modes: if self.search_text().startswith(key) and not mode: self._mode_on = key self.sig_mode_selected.emit(key) return # Filter by text titles = [] for row in range(self.model.rowCount()): item = self.model.item(row) if isinstance(item, SwitcherItem): title = item.get_title() else: title = '' titles.append(title) search_text = clean_string(search_text) scores = get_search_scores(to_text_string(search_text), titles, template=u"<b>{0}</b>") self._visible_rows = self.model.rowCount() for idx, score in enumerate(scores): title, rich_title, score_value = score item = self.model.item(idx) if not self._is_separator(item): item.set_rich_title(rich_title) item.set_score(score_value) proxy_index = self.proxy.mapFromSource(self.model.index(idx, 0)) if not item.is_action_item(): self.list.setRowHidden(proxy_index.row(), score_value == -1) if score_value == -1: self._visible_rows -= 1 if self._visible_rows: self.set_current_row(0) else: self.set_current_row(-1) self.setup_sections()
def setup_symbol_list(self, filter_text, current_path): """Setup list widget content for symbol list display.""" # Get optional symbol name filter_text, symbol_text = filter_text.split('@') # Fetch the Outline explorer data, get the icons and values oedata = self.get_symbol_list() icons = get_python_symbol_icons(oedata) # The list of shorten paths here is needed in order to have the same # point of measurement for the list widget width as in the file list # See issue 4648 short_paths = shorten_paths(self.paths, self.save_status) symbol_list = process_python_symbol_data(oedata) line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list] choices = [item[1] for item in symbol_list] scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>") # Build the text that will appear on the list widget results = [] lines = [] self.filtered_symbol_lines = [] for index, score in enumerate(scores): text, rich_text, score_value = score line, fold_level, token = line_fold_token[index] lines.append(text) if score_value != -1: results.append((score_value, line, text, rich_text, fold_level, icons[index], token)) template = '{0}{1}' for (score, line, text, rich_text, fold_level, icon, token) in sorted(results): fold_space = ' ' * (fold_level) line_number = line + 1 self.filtered_symbol_lines.append(line_number) textline = template.format(fold_space, rich_text) item = QListWidgetItem(icon, textline) item.setSizeHint(QSize(0, 16)) self.list.addItem(item) # To adjust the delegate layout for KDE themes self.list.files_list = False # Move selected item in list accordingly # NOTE: Doing this is causing two problems: # 1. It makes the cursor to auto-jump to the last selected # symbol after opening or closing a different file # 2. It moves the cursor to the first symbol by default, # which is very distracting. # That's why this line is commented! # self.set_current_row(0) # Update list size self.fix_size(short_paths, extra=100)
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') else: line_number = None # Get all available filenames and get the scores for "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Build the text that will appear on the list widget for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = '<big>' + rich_text.replace('&', '') + '</big>' if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) text_item += u"<br><i>{0:}</i>".format(short_paths[index]) results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] for result in sorted(results): index = result[1] text = result[-1] path = paths[index] item = QListWidgetItem(ima.icon('FileIcon'), text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) self.fix_size(short_paths, extra=200) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') else: line_number = None # Get all available filenames and get the scores for "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Build the text that will appear on the list widget for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = '<big>' + rich_text.replace('&', '') + '</big>' if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) text_item += "<br><i>{0:}</i>".format(short_paths[index]) results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] for result in sorted(results): index = result[1] text = result[-1] path = paths[index] item = QListWidgetItem(ima.icon('FileIcon'), text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) self.fix_size(short_paths, extra=200) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
def setup(self): """Set-up list widget content based on the filtering.""" # Check exited mode mode = self._mode_on if mode: search_text = self.search_text()[len(mode):] else: search_text = self.search_text() # Check exited mode if self.search_text() == '': self._mode_on = '' self.clear() self.proxy.set_filter_by_score(False) self.sig_mode_selected.emit(self._mode_on) return # Check entered mode for key in self._modes: if self.search_text().startswith(key) and not mode: self._mode_on = key self.sig_mode_selected.emit(key) return # Filter by text titles = [] for row in range(self.model.rowCount()): item = self.model.item(row) if isinstance(item, SwitcherItem): title = item.get_title() else: title = '' titles.append(title) search_text = clean_string(search_text) scores = get_search_scores(to_text_string(search_text), titles, template=u"<b>{0}</b>") for idx, (title, rich_title, score_value) in enumerate(scores): item = self.model.item(idx) if not self._is_separator(item) and not item.is_action_item(): rich_title = rich_title.replace(" ", " ") item.set_rich_title(rich_title) item.set_score(score_value) self.proxy.set_filter_by_score(True) self.setup_sections() if self.count(): self.set_current_row(0) else: self.set_current_row(-1) self.set_height()
def setup_symbol_list(self, filter_text, current_path): """Setup list widget content for symbol list display.""" # Get optional symbol name filter_text, symbol_text = filter_text.split('@') # Fetch the Outline explorer data, get the icons and values oedata = self.get_symbol_list() icons = get_python_symbol_icons(oedata) # The list of paths here is needed in order to have the same # point of measurement for the list widget size as in the file list # See issue 4648 paths = self.paths # Update list size self.fix_size(paths) symbol_list = process_python_symbol_data(oedata) line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list] choices = [item[1] for item in symbol_list] scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>") # Build the text that will appear on the list widget results = [] lines = [] self.filtered_symbol_lines = [] for index, score in enumerate(scores): text, rich_text, score_value = score line, fold_level, token = line_fold_token[index] lines.append(text) if score_value != -1: results.append((score_value, line, text, rich_text, fold_level, icons[index], token)) template = '{{0}}<span style="color:{0}">{{1}}</span>'.format( ima.MAIN_FG_COLOR) for (score, line, text, rich_text, fold_level, icon, token) in sorted(results): fold_space = ' ' * (fold_level) line_number = line + 1 self.filtered_symbol_lines.append(line_number) textline = template.format(fold_space, rich_text) item = QListWidgetItem(icon, textline) item.setSizeHint(QSize(0, 16)) self.list.addItem(item) # To adjust the delegate layout for KDE themes self.list.files_list = False # Select edit line when using symbol search initially. # See issue 5661 self.edit.setFocus()
def setup_symbol_list(self, filter_text, current_path): """Setup list widget content for symbol list display.""" # Get optional symbol name filter_text, symbol_text = filter_text.split('@') # Fetch the Outline explorer data, get the icons and values oedata = self.get_symbol_list() icons = get_python_symbol_icons(oedata) symbol_list = process_python_symbol_data(oedata) line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list] choices = [item[1] for item in symbol_list] scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>") # Build the text that will appear on the list widget results = [] lines = [] self.filtered_symbol_lines = [] for index, score in enumerate(scores): text, rich_text, score_value = score line, fold_level, token = line_fold_token[index] lines.append(text) if score_value != -1: results.append((score_value, line, text, rich_text, fold_level, icons[index], token)) template = '{0}{1}' for (score, line, text, rich_text, fold_level, icon, token) in sorted(results): fold_space = ' '*(fold_level) line_number = line + 1 self.filtered_symbol_lines.append(line_number) textline = template.format(fold_space, rich_text) item = QListWidgetItem(icon, textline) item.setSizeHint(QSize(0, 16)) self.list.addItem(item) # To adjust the delegate layout for KDE themes self.list.files_list = False # Move selected item in list accordingly # NOTE: Doing this is causing two problems: # 1. It makes the cursor to auto-jump to the last selected # symbol after opening or closing a different file # 2. It moves the cursor to the first symbol by default, # which is very distracting. # That's why this line is commented! # self.set_current_row(0) # Update list size self.fix_size(lines, extra=125)
def setup_symbol_list(self, filter_text, current_path): """Setup list widget content for symbol list display.""" # Get optional symbol name filter_text, symbol_text = filter_text.split('@') # Fetch the Outline explorer data, get the icons and values oedata = self.get_symbol_list() icons = get_python_symbol_icons(oedata) # The list of paths here is needed in order to have the same # point of measurement for the list widget size as in the file list # See issue 4648 paths = self.paths # Update list size self.fix_size(paths) symbol_list = process_python_symbol_data(oedata) line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list] choices = [item[1] for item in symbol_list] scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>") # Build the text that will appear on the list widget results = [] lines = [] self.filtered_symbol_lines = [] for index, score in enumerate(scores): text, rich_text, score_value = score line, fold_level, token = line_fold_token[index] lines.append(text) if score_value != -1: results.append((score_value, line, text, rich_text, fold_level, icons[index], token)) template = '{{0}}<span style="color:{0}">{{1}}</span>'.format( ima.MAIN_FG_COLOR) for (score, line, text, rich_text, fold_level, icon, token) in sorted(results): fold_space = ' '*(fold_level) line_number = line + 1 self.filtered_symbol_lines.append(line_number) textline = template.format(fold_space, rich_text) item = QListWidgetItem(icon, textline) item.setSizeHint(QSize(0, 16)) self.list.addItem(item) # To adjust the delegate layout for KDE themes self.list.files_list = False # Select edit line when using symbol search initially. # See issue 5661 self.edit.setFocus()
def test_stringmatching_order_filter(): """Test stringmatching ordered and filtered.""" template = '<b>{0}</b>' names = ['close pane', 'debug continue', 'debug exit', 'debug step into', 'debug step over', 'debug step return', 'fullscreen mode', 'layout preferences', 'lock unlock panes', 'maximize pane', 'preferences', 'quit', 'restart', 'save current layout', 'switch to breakpoints', 'switch to console', 'switch to editor', 'switch to explorer', 'switch to find_in_files', 'switch to historylog', 'switch to help', 'switch to ipython_console', 'switch to onlinehelp', 'switch to outline_explorer', 'switch to project_explorer', 'switch to variable_explorer', 'use next layout', 'use previous layout', 'clear line', 'clear shell', 'inspect current object', 'blockcomment', 'breakpoint', 'close all', 'code completion', 'conditional breakpoint', 'configure', 'copy', 'copy line', 'cut', 'debug', 'debug with winpdb', 'delete', 'delete line', 'duplicate line', 'end of document', 'end of line', 'file list management', 'find next', 'find previous', 'find text', 'go to definition', 'go to line', 'go to next file', 'go to previous file', 'inspect current object', 'kill next word', 'kill previous word', 'kill to line end', 'kill to line start', 'last edit location', 'move line down', 'move line up', 'new file', 'next char', 'next cursor position', 'next line', 'next word', 'open file', 'paste', 'previous char', 'previous cursor position', 'previous line', 'previous word', 'print', 're-run last script', 'redo', 'replace text', 'rotate kill ring', 'run', 'run selection', 'save all', 'save as', 'save file', 'select all', 'show/hide outline', 'show/hide project explorer', 'start of document', 'start of line', 'toggle comment', 'unblockcomment', 'undo', 'yank', 'run profiler', 'run analysis'] order_filter_results = get_search_scores('lay', names, template=template, valid_only=True, sort=True) assert order_filter_results == [('layout preferences', '<b>lay</b>out preferences', 400100), ('use next layout', 'use next <b>lay</b>out', 400109), ('save current layout', 'save current <b>lay</b>out', 400113), ('use previous layout', 'use previous <b>lay</b>out', 400113)]
def test_stringmatching_order_filter(): """Test stringmatching ordered and filtered.""" template = '<b>{0}</b>' names = [ 'close pane', 'debug continue', 'debug exit', 'debug step into', 'debug step over', 'debug step return', 'fullscreen mode', 'layout preferences', 'lock unlock panes', 'maximize pane', 'preferences', 'quit', 'restart', 'save current layout', 'switch to breakpoints', 'switch to console', 'switch to editor', 'switch to explorer', 'switch to find_in_files', 'switch to historylog', 'switch to help', 'switch to ipython_console', 'switch to onlinehelp', 'switch to outline_explorer', 'switch to project_explorer', 'switch to variable_explorer', 'use next layout', 'use previous layout', 'clear line', 'clear shell', 'inspect current object', 'blockcomment', 'breakpoint', 'close all', 'code completion', 'conditional breakpoint', 'configure', 'copy', 'copy line', 'cut', 'debug', 'debug with winpdb', 'delete', 'delete line', 'duplicate line', 'end of document', 'end of line', 'file list management', 'find next', 'find previous', 'find text', 'go to definition', 'go to line', 'go to next file', 'go to previous file', 'inspect current object', 'kill next word', 'kill previous word', 'kill to line end', 'kill to line start', 'last edit location', 'move line down', 'move line up', 'new file', 'next char', 'next cursor position', 'next line', 'next word', 'open file', 'paste', 'previous char', 'previous cursor position', 'previous line', 'previous word', 'print', 're-run last script', 'redo', 'replace text', 'rotate kill ring', 'run', 'run selection', 'save all', 'save as', 'save file', 'select all', 'show/hide outline', 'show/hide project explorer', 'start of document', 'start of line', 'toggle comment', 'unblockcomment', 'undo', 'yank', 'run profiler', 'run analysis' ] order_filter_results = get_search_scores('lay', names, template=template, valid_only=True, sort=True) assert order_filter_results == [ ('layout preferences', '<b>lay</b>out preferences', 400100), ('use next layout', 'use next <b>lay</b>out', 400109), ('save current layout', 'save current <b>lay</b>out', 400113), ('use previous layout', 'use previous <b>lay</b>out', 400113) ]
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths icons = self.icons results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') if line_number == '': line_number = None # Get all the available filenames scores = get_search_scores('', self.filenames, template="<b>{0}</b>") else: line_number = None # Get all available filenames and get the scores for # "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Get max width to determine if shortpaths should be used max_width = self.get_item_size(paths)[0] self.fix_size(paths) # Build the text that will appear on the list widget for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = '<big>' + rich_text.replace('&', '') + '</big>' if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) if max_width > self.list.width(): text_item += u"<br><i>{0:}</i>".format(short_paths[index]) else: text_item += u"<br><i>{0:}</i>".format(paths[index]) if (trying_for_line_number and self.line_count[index] != 0 or not trying_for_line_number): results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] plugin = None for result in sorted(results): index = result[1] path = paths[index] icon = icons[index] text = '' try: title = self.widgets[index][1].get_plugin_title().split(' - ') if plugin != title[0]: plugin = title[0] text += '<br><big><b>' + plugin + '</b></big><br>' item = QListWidgetItem(text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) item.setFlags(Qt.ItemIsEditable) self.list.addItem(item) self.filtered_path.append(path) except: # The widget using the fileswitcher is not a plugin pass text = '' text += result[-1] item = QListWidgetItem(icon, text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths icons = self.icons results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') if line_number == '': line_number = None # Get all the available filenames scores = get_search_scores('', self.filenames, template="<b>{0}</b>") else: line_number = None # Get all available filenames and get the scores for # "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Get max width to determine if shortpaths should be used max_width = self.get_item_size(paths)[0] self.fix_size(paths) # Build the text that will appear on the list widget rich_font = CONF.get('appearance', 'rich_font/size', 10) if sys.platform == 'darwin': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 2 elif os.name == 'nt': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 elif is_ubuntu(): path_text_font_size = rich_font - 2 filename_text_font_size = path_text_font_size + 1 else: path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 for index, score in enumerate(scores): text, rich_text, score_value = score linecount = "" if score_value != -1: fileName = rich_text.replace('&', '') if trying_for_line_number: linecount = "[{0:} {1:}]".format(self.line_count[index], _("lines")) if max_width > self.list.width(): path = short_paths[index] else: path = paths[index] title = self.widgets[index][1].get_plugin_title().split( ' - ')[0] text_item = self._TEMPLATE.format(width=self._MIN_WIDTH, height=self._HEIGHT, title=fileName, section=title, description=path, padding=self._PADDING, shortcut=linecount, **self._STYLES) if ((trying_for_line_number and self.line_count[index] != 0) or not trying_for_line_number): results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] plugin = None separator = self._TEMPLATE_SEP.format(width=self.list.width() - 20, height=self._HEIGHT_SEP, **self._STYLES_SEP) for result in sorted(results): index = result[1] path = paths[index] if sys.platform == 'darwin': scale_factor = 0.9 elif os.name == 'nt': scale_factor = 0.8 elif is_ubuntu(): scale_factor = 0.7 else: scale_factor = 0.9 icon = ima.get_icon_by_extension(path, scale_factor) text = '' try: title = self.widgets[index][1].get_plugin_title().split(' - ') if plugin != title[0]: plugin = title[0] text = separator item = QListWidgetItem(text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) item.setFlags(Qt.ItemIsEditable) self.list.addItem(item) self.filtered_path.append(path) except: # The widget using the fileswitcher is not a plugin pass text = '' text += result[-1] item = QListWidgetItem(icon, text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths icons = self.icons results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') # Get all the available filenames scores = get_search_scores('', self.filenames, template="<b>{0}</b>") else: line_number = None # Get all available filenames and get the scores for # "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Get max width to determine if shortpaths should be used max_width = self.get_item_size(paths)[0] self.fix_size(paths) # Build the text that will appear on the list widget for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = '<big>' + rich_text.replace('&', '') + '</big>' if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) if max_width > self.list.width(): text_item += u"<br><i>{0:}</i>".format(short_paths[index]) else: text_item += u"<br><i>{0:}</i>".format(paths[index]) if (trying_for_line_number and self.line_count[index] != 0 or not trying_for_line_number): results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] plugin = None for result in sorted(results): index = result[1] path = paths[index] icon = icons[index] text = '' try: title = self.widgets[index][1].get_plugin_title().split(' - ') if plugin != title[0]: plugin = title[0] text += '<br><big><b>' + plugin + '</b></big><br>' item = QListWidgetItem(text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) item.setFlags(Qt.ItemIsEditable) self.list.addItem(item) self.filtered_path.append(path) except: # The widget using the fileswitcher is not a plugin pass text = '' text += result[-1] item = QListWidgetItem(icon, text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths icons = self.icons results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') if line_number == '': line_number = None # Get all the available filenames scores = get_search_scores('', self.filenames, template="<b>{0}</b>") else: line_number = None # Get all available filenames and get the scores for # "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Get max width to determine if shortpaths should be used max_width = self.get_item_size(paths)[0] self.fix_size(paths) # Build the text that will appear on the list widget rich_font = CONF.get('appearance', 'rich_font/size', 10) if sys.platform == 'darwin': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 2 elif os.name == 'nt': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 elif is_ubuntu(): path_text_font_size = rich_font - 2 filename_text_font_size = path_text_font_size + 1 else: path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = ("<span style='color:{0:}; font-size:{1:}pt'>{2:}" "</span>").format(ima.MAIN_FG_COLOR, filename_text_font_size, rich_text.replace('&', '')) if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) if max_width > self.list.width(): text_item += (u" <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, short_paths[index]) else: text_item += (u" <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, paths[index]) if (trying_for_line_number and self.line_count[index] != 0 or not trying_for_line_number): results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] plugin = None for result in sorted(results): index = result[1] path = paths[index] if sys.platform == 'darwin': scale_factor = 0.9 elif os.name == 'nt': scale_factor = 0.8 elif is_ubuntu(): scale_factor = 0.6 else: scale_factor = 0.9 icon = ima.get_icon_by_extension(path, scale_factor) text = '' try: title = self.widgets[index][1].get_plugin_title().split(' - ') if plugin != title[0]: plugin = title[0] text += ("<br><big style='color:{0:}'>" "<b>{1:}</b></big><br>").format(ima.MAIN_FG_COLOR, plugin) item = QListWidgetItem(text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) item.setFlags(Qt.ItemIsEditable) self.list.addItem(item) self.filtered_path.append(path) except: # The widget using the fileswitcher is not a plugin pass text = '' text += result[-1] item = QListWidgetItem(icon, text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)
def setup_file_list(self, filter_text, current_path): """Setup list widget content for file list display.""" short_paths = shorten_paths(self.paths, self.save_status) paths = self.paths icons = self.icons results = [] trying_for_line_number = ':' in filter_text # Get optional line number if trying_for_line_number: filter_text, line_number = filter_text.split(':') if line_number == '': line_number = None # Get all the available filenames scores = get_search_scores('', self.filenames, template="<b>{0}</b>") else: line_number = None # Get all available filenames and get the scores for # "fuzzy" matching scores = get_search_scores(filter_text, self.filenames, template="<b>{0}</b>") # Get max width to determine if shortpaths should be used max_width = self.get_item_size(paths)[0] self.fix_size(paths) # Build the text that will appear on the list widget rich_font = CONF.get('appearance', 'rich_font/size', 11) if sys.platform == 'darwin': path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 2 elif os.name == 'nt': path_text_font_size = rich_font - 1 filename_text_font_size = path_text_font_size + 1 elif is_ubuntu(): path_text_font_size = rich_font - 2 filename_text_font_size = path_text_font_size + 1 else: path_text_font_size = rich_font filename_text_font_size = path_text_font_size + 1 for index, score in enumerate(scores): text, rich_text, score_value = score if score_value != -1: text_item = ("<span style='color:{0:}; font-size:{1:}pt'>{2:}" "</span>").format(ima.MAIN_FG_COLOR, filename_text_font_size, rich_text.replace('&', '')) if trying_for_line_number: text_item += " [{0:} {1:}]".format(self.line_count[index], _("lines")) if max_width > self.list.width(): text_item += (u" <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, short_paths[index]) else: text_item += (u" <span style='color:{0:};" "font-size:{1:}pt'>{2:}" "</span>").format(self.PATH_FG_COLOR, path_text_font_size, paths[index]) if (trying_for_line_number and self.line_count[index] != 0 or not trying_for_line_number): results.append((score_value, index, text_item)) # Sort the obtained scores and populate the list widget self.filtered_path = [] plugin = None for result in sorted(results): index = result[1] path = paths[index] if sys.platform == 'darwin': scale_factor = 0.9 elif os.name == 'nt': scale_factor = 0.8 elif is_ubuntu(): scale_factor = 0.6 else: scale_factor = 0.9 icon = ima.get_icon_by_extension(path, scale_factor) text = '' try: title = self.widgets[index][1].get_plugin_title().split(' - ') if plugin != title[0]: plugin = title[0] text += ("<br><big style='color:{0:}'>" "<b>{1:}</b></big><br>").format( ima.MAIN_FG_COLOR, plugin) item = QListWidgetItem(text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) item.setFlags(Qt.ItemIsEditable) self.list.addItem(item) self.filtered_path.append(path) except: # The widget using the fileswitcher is not a plugin pass text = '' text += result[-1] item = QListWidgetItem(icon, text) item.setToolTip(path) item.setSizeHint(QSize(0, 25)) self.list.addItem(item) self.filtered_path.append(path) # To adjust the delegate layout for KDE themes self.list.files_list = True # Move selected item in list accordingly and update list size if current_path in self.filtered_path: self.set_current_row(self.filtered_path.index(current_path)) elif self.filtered_path: self.set_current_row(0) # If a line number is searched look for it self.line_number = line_number self.goto_line(line_number)