def fileProcessed(self, path, rv): if isinstance(rv, Exception): try: raise rv except IOError as exc: if exc.errno == errno.ENOENT: msg = "ERROR: File doesn't exist" else: msg = "ERROR: %s" % os.strerror(exc.errno) except UnicodeDecodeError: msg = "ERROR: Cannot read file using %s encoding" % self.processor.input_encoding except UnicodeEncodeError: msg = "ERROR: Cannot write file using %s encoding (try setting output encoding to UTF-8)" % self.processor.output_encoding except pysubs2.FormatAutodetectionError: msg = "ERROR: Unknown subtitle format (malformed file?)" except Exception as exc: msg = "ERROR: %r" % exc else: msg = None self.processed_ok += 1 self.processed += 1 self.progressBar.setValue(self.progressBar.value() + 1) if msg: item = QListWidgetItem(msg) item.setForeground(QColor("darkred" if msg.startswith("ERROR") else "darkgreen")) self.logList.addItem(item) scroll_to_bottom(self.logList)
def _create_help_item(self, image, text): Item = QListWidgetItem(QIcon(image), text) font = Item.font() font.setBold(True) Item.setSizeHint(QSize(20, 30)) Item.setBackground(QBrush(Qt.lightGray)) Item.setForeground(QBrush(Qt.black)) Item.setFont(font) return Item
def add_no_found(self): #Load no results found message noFoundItem = QListWidgetItem( QIcon(resources.IMAGES['delete']), 'No results were found!') font = noFoundItem.font() font.setBold(True) noFoundItem.setSizeHint(QSize(20, 30)) noFoundItem.setBackground(QBrush(Qt.lightGray)) noFoundItem.setForeground(QBrush(Qt.black)) noFoundItem.setFont(font) self.listWidget.addItem(noFoundItem)
def provide(self, search): if not search: yield False baloo_dump = subprocess.check_output( ['baloosearch', '--', search]).decode('utf-8') paths = re.findall('\x1b\\[0;32m(.*)\x1b\\[0;0m', baloo_dump) for path in paths: item = QListWidgetItem(path) item.setForeground(Qt.blue) item.setData(ItemTypeRole, 'file') item.setData(ItemDataRole, path) yield item yield False
def create_plugin_view(self, showAll = True): for p_name, p_info in self.p_info.iteritems(): item = QListWidgetItem(p_info["name"], self.ui.pluginView) item.setToolTip(p_name) item.setCheckState(Qt.Checked if p_info["activated"] else Qt.Unchecked) if p_info["forced"]: item.setForeground(Qt.gray) flags = item.flags() flags &= ~Qt.ItemIsUserCheckable item.setFlags(flags) item.setHidden(not showAll and p_info["forced"]) self.ui.pluginView.addItem(item)
def provide(self, search): if not search: yield False try: subprocess.check_call(['which', '--', search.split()[0]]) except subprocess.CalledProcessError: pass else: item = QListWidgetItem(search) item.setForeground(Qt.red) item.setData(ItemTypeRole, 'executable') item.setData(ItemDataRole, search) yield item yield False
def addListItem(self, component, title, valid=True, checked=True): item = QListWidgetItem(title) item.component = component item.setFlags(item.flags() | Qt.ItemIsUserCheckable) if valid: pass else: item.setForeground(QColor('gray')) if checked: item.setCheckState(Qt.Checked) else: item.setCheckState(Qt.Unchecked) self.components_list.addItem(item)
def _insertResult(self, result): for track, res in result: item = QListWidgetItem() item.setText('{0} - {1}'.format(track[0]['name'], res['msg'])) if res['status'] == 'OK': # item.setBackground(Qt.green) pass elif res['status'] == 'ERROR': item.setForeground(Qt.red) self.list.addItem(item)
def populateElements(self, selectedElement=None, edit=False): selected = None self.ui.elementListWidget.clear() slist = [(self.elements[key].name, key) for key in self.elements.keys()] slist.sort() for name, el in slist: item = QListWidgetItem(QString("%s" % name)) item.setData(Qt.UserRole, QVariant(self.elements[el].id)) item.setFlags(item.flags() | Qt.ItemIsEditable) dirty = False if hasattr(self.elements[el], "isDirty") \ and self.elements[el].isDirty(): dirty = True if self.elements[el].instance is not None: if hasattr(self.elements[el].instance, "isDirty") \ and self.elements[el].instance.isDirty(): dirty = True if dirty: item.setForeground(Qt.red) else: item.setForeground(Qt.black) self.ui.elementListWidget.addItem(item) if selectedElement is not None \ and selectedElement == self.elements[el].id: selected = item if self.elements[el].instance is not None \ and self.elements[el].instance.dialog is not None: try: if dirty: self.elements[el].instance.dialog.\ setWindowTitle("%s [%s]*" % (name, self.clName)) else: self.elements[el].instance.dialog.\ setWindowTitle("%s [%s]" % (name, self.clName)) except: self.elements[el].instance.dialog = None if selected is not None: selected.setSelected(True) self.ui.elementListWidget.setCurrentItem(selected) if edit: self.ui.elementListWidget.editItem(selected)
def add_help(self): #Load help fileItem = QListWidgetItem( QIcon(resources.IMAGES['locate-file']), '@\t(Filter only by Files)') font = fileItem.font() font.setBold(True) fileItem.setSizeHint(QSize(20, 30)) fileItem.setBackground(QBrush(Qt.lightGray)) fileItem.setForeground(QBrush(Qt.black)) fileItem.setFont(font) self.listWidget.addItem(fileItem) classItem = QListWidgetItem( QIcon(resources.IMAGES['locate-class']), '<\t(Filter only by Classes)') self.listWidget.addItem(classItem) classItem.setSizeHint(QSize(20, 30)) classItem.setBackground(QBrush(Qt.lightGray)) classItem.setForeground(QBrush(Qt.black)) classItem.setFont(font) methodItem = QListWidgetItem( QIcon(resources.IMAGES['locate-function']), '>\t(Filter only by Methods)') self.listWidget.addItem(methodItem) methodItem.setSizeHint(QSize(20, 30)) methodItem.setBackground(QBrush(Qt.lightGray)) methodItem.setForeground(QBrush(Qt.black)) methodItem.setFont(font) thisFileItem = QListWidgetItem( QIcon(resources.IMAGES['locate-on-this-file']), '.\t(Filter only by Classes and Methods in this File)') font = thisFileItem.font() font.setBold(True) thisFileItem.setSizeHint(QSize(20, 30)) thisFileItem.setBackground(QBrush(Qt.lightGray)) thisFileItem.setForeground(QBrush(Qt.black)) thisFileItem.setFont(font) self.listWidget.addItem(thisFileItem) nonPythonItem = QListWidgetItem( QIcon(resources.IMAGES['locate-nonpython']), '!\t(Filter only by Non Python Files)') self.listWidget.addItem(nonPythonItem) nonPythonItem.setSizeHint(QSize(20, 30)) nonPythonItem.setBackground(QBrush(Qt.lightGray)) nonPythonItem.setForeground(QBrush(Qt.black)) nonPythonItem.setFont(font)
def initExtList(self): extset = set(self.parent().settings.extensions) #for easier performance in checking for ext in self.parent().settings.extensions: item = QListWidgetItem(ext, self.mdExts) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) for ext in self.parent().settings.faulty_exts: item = QListWidgetItem(ext, self.mdExts) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setBackground(QBrush(QColor('red'))) item.setForeground(QBrush(QColor('black'))) item.setCheckState(Qt.Checked) for ext in allMDExtensions(): if ext in extset: continue item = QListWidgetItem(ext, self.mdExts) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked)
def initExtList(self): extset=set(self.parent().settings.extensions) #for easier performance in checking for ext in self.parent().settings.extensions: item = QListWidgetItem(ext, self.mdExts) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) for ext in self.parent().settings.faulty_exts: item = QListWidgetItem(ext, self.mdExts) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setBackground(QBrush(QColor('red'))) item.setForeground(QBrush(QColor('black'))) item.setCheckState(Qt.Checked) for ext in allMDExtensions(): if ext in extset: continue item = QListWidgetItem(ext, self.mdExts) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked)
def populateListGuesses(self): "Populates the list of guesses already made." self.listWidget_guesses.clear() if self._testLexicalForm: theList = self._lexicals else: theList = self._words for i in self._tooHard: t1 = theList[i] t2 = self._definitions[i] item = QListWidgetItem(t1 + " → " + t2) item.setForeground(QColor("blue")) self.listWidget_guesses.addItem(item) for (i, j) in self._alreadyGuessed: t1 = theList[i] t2 = self._definitions[j] self.listWidget_guesses.addItem(t1 + " → " + t2)
def msg_normal(self, message): item = QListWidgetItem(message) item.setForeground(brush_normal) self.addItem(item)
def add_help(self): #Load help fileItem = QListWidgetItem(QIcon(resources.IMAGES['locate-file']), '@\t(Filter only by Files)') font = fileItem.font() font.setBold(True) fileItem.setSizeHint(QSize(20, 30)) fileItem.setBackground(QBrush(Qt.lightGray)) fileItem.setForeground(QBrush(Qt.black)) fileItem.setFont(font) self.listWidget.addItem(fileItem) classItem = QListWidgetItem(QIcon(resources.IMAGES['locate-class']), '<\t(Filter only by Classes)') self.listWidget.addItem(classItem) classItem.setSizeHint(QSize(20, 30)) classItem.setBackground(QBrush(Qt.lightGray)) classItem.setForeground(QBrush(Qt.black)) classItem.setFont(font) methodItem = QListWidgetItem( QIcon(resources.IMAGES['locate-function']), '>\t(Filter only by Methods)') self.listWidget.addItem(methodItem) methodItem.setSizeHint(QSize(20, 30)) methodItem.setBackground(QBrush(Qt.lightGray)) methodItem.setForeground(QBrush(Qt.black)) methodItem.setFont(font) attributeItem = QListWidgetItem( QIcon(resources.IMAGES['locate-attributes']), '-\t(Filter only by Attributes)') self.listWidget.addItem(attributeItem) attributeItem.setSizeHint(QSize(20, 30)) attributeItem.setBackground(QBrush(Qt.lightGray)) attributeItem.setForeground(QBrush(Qt.black)) attributeItem.setFont(font) thisFileItem = QListWidgetItem( QIcon(resources.IMAGES['locate-on-this-file']), '.\t(Filter only by Classes and Methods in this File)') font = thisFileItem.font() font.setBold(True) thisFileItem.setSizeHint(QSize(20, 30)) thisFileItem.setBackground(QBrush(Qt.lightGray)) thisFileItem.setForeground(QBrush(Qt.black)) thisFileItem.setFont(font) self.listWidget.addItem(thisFileItem) nonPythonItem = QListWidgetItem( QIcon(resources.IMAGES['locate-nonpython']), '!\t(Filter only by Non Python Files)') self.listWidget.addItem(nonPythonItem) nonPythonItem.setSizeHint(QSize(20, 30)) nonPythonItem.setBackground(QBrush(Qt.lightGray)) nonPythonItem.setForeground(QBrush(Qt.black)) nonPythonItem.setFont(font)
def validate(self): "The user is happy with his or her guess and wants the solution." p = 0 self.listWidget_translation.setSortingEnabled(False) self.listWidget_original.clear() self.listWidget_translation.clear() if self._testLexicalForm: theList = self._lexicals else: theList = self._words for k in range(len(theList)): if k in [i for (i, j) in self._alreadyGuessed]: (i, j) = [(i, j) for (i, j) in self._alreadyGuessed if i == k][0] if i == j: p += 1 color = "green" else: color = "red" w = QListWidgetItem(theList[i]) w.setForeground(QColor(color)) d = QListWidgetItem(self._definitions[i]) d.setForeground(QColor(color)) self.listWidget_original.addItem(w) self.listWidget_translation.addItem(d) elif k in [j for (i, j) in self._alreadyGuessed]: (i, j) = [(i, j) for (i, j) in self._alreadyGuessed if j == k][0] if i == j: p += 1 color = "green" else: color = "red" w = QListWidgetItem(theList[j]) w.setForeground(QColor(color)) d = QListWidgetItem(self._definitions[j]) d.setForeground(QColor(color)) self.listWidget_original.addItem(w) self.listWidget_translation.addItem(d) else: w = QListWidgetItem(theList[k]) w.setForeground(QColor("blue")) d = QListWidgetItem(self._definitions[k]) d.setForeground(QColor("blue")) self.listWidget_original.addItem(w) self.listWidget_translation.addItem(d) self.setListMaximumWidth(self.listWidget_original) self.setListMaximumWidth(self.listWidget_translation)