def scan_config_devices_update_list_view(self): """ Scans for saved devices :return: """ self.devices_view.clear() paired_devices = self.config['device'] for i in paired_devices: if paired_devices[i].get('wifi'): icon = ':/icons/icons/portrait_mobile_disconnect.svg' devices_view_list_item = QListWidgetItem( QIcon(icon), "{device}\n{mode}\n{status}".format( device=paired_devices[i].get('model'), mode=i, status='Disconnected')) __sha_shift = self.config.get('sha_shift', 5) __sha = hashlib.sha256( str(i).encode()).hexdigest()[__sha_shift:__sha_shift + 6] devices_view_list_item.setToolTip( "<span style='color: #{color}'>Device</snap>: <b>{d}</b>\n" "Status: {s}".format( d=i, s="Disconnected. Right click 'ping' to attempt " "reconnect", color=__sha)) devices_view_list_item.setFont(QFont('Noto Sans', 8)) self.devices_view.addItem(devices_view_list_item) return paired_devices
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__list__(self): """ Load working days and sets tooltips for list items. :return: """ for k in self.time_capture_service.working_dates: sum = 0 for booking in self.time_capture_service.load_bookings(str(k)): sum += booking[bk.HOURS] qlwi = QListWidgetItem(str(k)) qlwi.setToolTip("Day: {} | Sum: {} hrs".format(days[k.weekday()], sum)) self.ui.list_days.addItem(qlwi)
def __draw_atlas(self, i: int, g: Graph) -> bool: """Draw atlas and return True if done.""" item = QListWidgetItem(f"No. {i + 1}") item.setIcon( graph2icon(g, self.structure_list.iconSize().width(), self.graph_engine.currentText(), self.graph_link_as_node.isChecked(), self.graph_show_label.isChecked(), self.prefer.monochrome_option)) item.setToolTip( f"Edge Set: {list(g.edges)}\n" f"Link assortment: {link_assortment(g)}\n" f"Contracted Link assortment: {contracted_link_assortment(g)}") self.structure_list.addItem(item) return True
def __reload_atlas(self) -> None: """Reload atlas with the engine.""" current_pos = self.collection_list.currentRow() self.collections_layouts.clear() self.collection_list.clear() self.__clear_selection() if not self.collections: return dlg = QProgressDialog( "Drawing atlas...", "Cancel", 0, len(self.collections), self ) dlg.setWindowTitle("Type synthesis") dlg.resize(400, dlg.height()) dlg.setModal(True) dlg.show() engine_str = self.graph_engine.currentText() for i, g in enumerate(self.collections): QCoreApplication.processEvents() if dlg.wasCanceled(): dlg.deleteLater() return item = QListWidgetItem(f"No. {i + 1}") engine = engine_picker(g, engine_str, self.graph_link_as_node.isChecked()) item.setIcon(graph2icon( g, self.collection_list.iconSize().width(), engine, self.graph_link_as_node.isChecked(), self.graph_show_label.isChecked(), self.prefer.monochrome_option )) self.collections_layouts.append(engine) item.setToolTip(f"{g.edges}") self.collection_list.addItem(item) dlg.setValue(i + 1) dlg.deleteLater() if current_pos > -1: self.collection_list.setCurrentRow(current_pos) self.__set_selection(self.collection_list.currentItem())
class AddInput(QUndoCommand): """Add a variable to list widget.""" def __init__(self, name: str, widget: QListWidget, parent: Optional[QWidget] = None): super(AddInput, self).__init__(parent) self.setText(f"Add variable of {name}") self.item = QListWidgetItem(name) self.item.setToolTip(name) self.widget = widget def redo(self) -> None: """Add to widget.""" self.widget.addItem(self.item) def undo(self) -> None: """Take out the item.""" self.widget.takeItem(self.widget.row(self.item))
def __add_result(self, result: Dict[str, Any]) -> None: """Add result items, except add to the list.""" item = QListWidgetItem(result['algorithm']) interrupt = result['interrupted'] if interrupt == 'False': interrupt_icon = "task_completed.png" elif interrupt == 'N/A': interrupt_icon = "question.png" else: interrupt_icon = "interrupted.png" item.setIcon(QIcon(QPixmap(f":/icons/{interrupt_icon}"))) if interrupt == 'False': interrupt_text = "No interrupt." else: interrupt_text = f"Interrupt at: {interrupt}" text = f"{result['algorithm']} ({interrupt_text})" if interrupt == 'N/A': text += "\n※Completeness is unknown." item.setToolTip(text) self.result_list.addItem(item)
def setup(self, applications=None): """Load installed applications.""" QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) self.list.clear() if applications is None: apps = get_installed_applications() else: apps = applications for app in sorted(apps, key=lambda x: x.lower()): fpath = apps[app] icon = get_application_icon(fpath) item = QListWidgetItem(icon, app) item.setToolTip(fpath) item.fpath = fpath self.list.addItem(item) # FIXME: Use metrics self.list.setMinimumWidth(self.list.sizeHintForColumn(0) + 24) QApplication.restoreOverrideCursor() self._refresh()
def _add_application(self, app_name, fpath): """Add application helper.""" app_not_found_text = _(' (Application not found!)') for row in range(self.list_applications.count()): item = self.list_applications.item(row) # Ensure the actual name is checked without the `app not found` # additional text, in case app was not found item_text = item.text().replace(app_not_found_text, '').strip() if item and item_text == app_name: break else: icon = get_application_icon(fpath) if not (os.path.isfile(fpath) or os.path.isdir(fpath)): app_name += app_not_found_text item = QListWidgetItem(icon, app_name) self.list_applications.addItem(item) self.list_applications.setCurrentItem(item) if not (os.path.isfile(fpath) or os.path.isdir(fpath)): item.setToolTip(_('Application not found!'))
def __init__( self, parent: QWidget, title: str, main_expr: str, storage_data: Mapping[str, str], input_data: Sequence[Tuple[int, int]], path_data: Mapping[str, _Paths], collection_data: Sequence[_Pairs], config_data: Mapping[str, Mapping[str, Any]], algorithm_data: Sequence[Mapping[str, Any]], background_path: str ): """Data come from commit.""" super(OverviewDialog, self).__init__(parent) self.setupUi(self) self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) self.setWindowTitle(f"Project: {title}") # Expression of storage data self.main_expr.setText(main_expr) for name, expr in storage_data.items(): item = QListWidgetItem(f"[{name}]: {expr}") item.setToolTip(expr) self.storage_list.addItem(item) size = len(storage_data) if main_expr != "M[]": size += 1 self.__set_item_text(0, size) # Expression of inputs variable data and Path data for a, b in input_data: self.variables_list.addItem(f"Point{a}->Point{b}") for name, paths in path_data.items(): item = QListWidgetItem(name) item.setToolTip(", ".join( f'[{i}]' for i, path in enumerate(paths) if path )) self.records_list.addItem(item) self.__set_item_text(1, len(input_data), len(path_data)) # Structure collections and Triangle collections for edges in collection_data: self.structures_list.addItem(str(edges)) for name, data in config_data.items(): item = QListWidgetItem(name) item.setToolTip(data['expression']) self.triangular_iteration_list.addItem(item) self.__set_item_text(2, len(collection_data), len(config_data)) # Dimensional synthesis for data in algorithm_data: self.results_list.addItem(data['algorithm']) self.__set_item_text(3, len(algorithm_data)) # Background image self.image_path.setText(background_path) self.__set_item_text(4, 1 if background_path else 0) self.background_preview.setPixmap(QPixmap(background_path))
def __init__(self, parent: QWidget, title: str, storage_data: Dict[str, str], input_data: Sequence[Tuple[int, int]], path_data: Dict[str, Sequence[Tuple[float, float]]], collection_data: List[Tuple[Tuple[int, int], ...]], config_data: Dict[str, Dict[str, Any]], algorithm_data: List[Dict[str, Any]]): """Data come from commit.""" super(OverviewDialog, self).__init__(parent) self.setupUi(self) flags = self.windowFlags() self.setWindowFlags(flags & ~Qt.WindowContextHelpButtonHint) self.setWindowTitle(f"Project: {title}") # Expression of storage data. for name, expr in storage_data.items(): item = QListWidgetItem(f"[Storage] - {name}") item.setToolTip(expr) self.storage_list.addItem(item) self.__set_item_text(0, len(storage_data)) # Expression of inputs variable data and Path data. for a, b in input_data: self.variables_list.addItem(f"Point{a}->Point{b}") for name, paths in path_data.items(): item = QListWidgetItem(name) item.setToolTip(", ".join(f'[{i}]' for i, path in enumerate(paths) if path)) self.records_list.addItem(item) self.__set_item_text(1, len(input_data), len(path_data)) # Structure collections and Triangle collections. for edges in collection_data: self.structures_list.addItem(str(edges)) for name, data in config_data.items(): item = QListWidgetItem(name) item.setToolTip(data['Expression']) self.triangular_iteration_list.addItem(item) self.__set_item_text(2, len(collection_data), len(config_data)) # Dimensional synthesis. for data in algorithm_data: self.results_list.addItem(data['Algorithm']) self.__set_item_text(3, len(algorithm_data))
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', 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)
def scan_devices_update_list_view(self): """ Scan for new devices; and update the list view :return: """ # self.devices_view.clear() device_exists_in_view = False paired_devices = [] for index in range(self.devices_view.count()): paired_devices.append(self.devices_view.item(index)) __devices = self.adb.devices_detailed() log(__devices) for i in __devices: device_is_wifi = \ i['identifier'].count('.') >= 3 and (':' in i['identifier']) if i['identifier'] not in self.config['device'].keys(): device_paired_and_exists = False self.config['device'][i['identifier']] = {'rotation': 0} else: device_paired_and_exists = True if device_is_wifi: _icon_suffix = '_wifi' else: _icon_suffix = '_usb' icon = ':/icons/icons/portrait_mobile_white{}.svg'.format( _icon_suffix) if i['status'] == 'offline': icon = ':/icons/icons/portrait_mobile_error.svg' elif i['status'] == 'unauthorized': icon = ':/icons/icons/portrait_mobile_warning.svg' if i['status'] == 'no_permission': log("pairfilter: 5") # https://stackoverflow.com/questions/ # 53887322/adb-devices-no-permissions-user-in- # plugdev-group-are-your-udev-rules-wrong udev_error = "Error connecting to device. Your udev rules are"\ " incorrect. See https://stackoverflow.com/questions"\ "/53887322/adb-devices-no-permissions-user-in-plugdev-"\ "group-are-your-udev-rules-wrong" self.display_public_message(udev_error) print(udev_error) return [] # Check if device is unauthorized elif i['status'] == "unauthorized": log("unauthorized device detected: Click Allow on your device") log("pairfilter: 4") # The device is connected; and might/might't paired in the past # And is connected to the same IP address # It is possibly a bug with the connection; # Temporarily create a new QListItem to display the # device with the error paired = False device_paired_and_exists = False self.display_public_message( f"{i['identifier']} is unauthorized. Please click allow " f"on your device.") # Remove other devices with the same id and offline and # unauthorized self.remove_device_device_view( i['identifier'], statuses=['offline', 'unauthorized']) # Unauthorized device cannot be considered as a paired device devices_view_list_item = QListWidgetItem() else: # check if device is paired # if yes, just update the list item if not device_paired_and_exists: paired = False devices_view_list_item = QListWidgetItem() else: for paired_device in paired_devices: if paired_device.text().split()[0] == i['model']: log("pairfilter: 1") paired = True devices_view_list_item = paired_device # as we have found a paired device # we know by assumption; there cannot be two # devices with the same local IP address; # lets scan the devices_view once more in a loop # to check for any device with the same # identifier and remove them; based on this same # assumption self.remove_device_device_view( i['identifier'], statuses=['offline', 'unauthorized']) break elif paired_device.text().split()[1] ==\ i['identifier']: log("pairfilter: 2") self.remove_device_device_view( i['identifier'], statuses=['offline', 'unauthorized']) devices_view_list_item = QListWidgetItem() paired = False break else: log("pairfilter: 3") paired = False devices_view_list_item = QListWidgetItem() devices_view_list_item.setIcon(QIcon(icon)) devices_view_list_item.setText("{device}\n{mode}\n{status}".format( device=i['model'], mode=i['identifier'], status=i['status'])) __sha_shift = self.config.get('sha_shift', 5) __sha = hashlib.sha256(str(i['identifier']).encode()).hexdigest( )[__sha_shift:__sha_shift + 6] devices_view_list_item.setToolTip( "Device: " "<span style='color: #{inv_color};background-color: #{color}'>" "<b>{d}</b></span>\n" "<br>" "Model: {m}\n<br>" "Alias: {a}\n<br>" "Status: {s}\n<br>" "Transport ID: {t}\n<br>" "Paired: {p}".format(d=i['identifier'], m=i['model'], a=i['product'], s=i['status'], t=i['transport_id'], p=paired, color=__sha, inv_color=str( hex(0xFFFFFF - int(__sha, 16))[2:]))) devices_view_list_item.setFont(QFont('Noto Sans', 8)) log(f"Pairing status: {device_paired_and_exists}") if device_paired_and_exists and device_is_wifi: # we need to only neglect wifi devices # paired usb device need to still show in the display continue elif device_exists_in_view: # devices exists in the list with the same status and # we should not add the new detected list item continue # If and only if the device doesn't exist; add it self.devices_view.addItem(devices_view_list_item) return __devices
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)