Esempio n. 1
0
 def fix_errors(self, container, errors):
     with BusyCursor():
         self.show_busy(_('Running fixers, please wait...'))
         QApplication.processEvents()
         changed = fix_errors(container, errors)
     self.run_checks(container)
     return changed
Esempio n. 2
0
 def __enter__(self):
     self.stacks.setCurrentIndex(0)
     self.busy.setVisible(True)
     self.busy.pi.startAnimation()
     QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
     QApplication.processEvents(
         QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents
         | QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers)
Esempio n. 3
0
    def run_checks(self, container):
        with BusyCursor():
            self.show_busy()
            QApplication.processEvents()
            errors = run_checks(container)
            self.hide_busy()

        for err in sorted(errors, key=lambda e: (100 - e.level, e.name)):
            i = QListWidgetItem('%s\xa0\xa0\xa0\xa0[%s]' % (err.msg, err.name),
                                self.items)
            i.setData(Qt.ItemDataRole.UserRole, err)
            i.setIcon(icon_for_level(err.level))
        if errors:
            self.items.setCurrentRow(0)
            self.current_item_changed()
            self.items.setFocus(Qt.FocusReason.OtherFocusReason)
        else:
            self.clear_help()
Esempio n. 4
0
 def add_image_diff(self, left_data, right_data):
     def load(data):
         p = QPixmap()
         p.loadFromData(as_bytes(data))
         try:
             dpr = self.devicePixelRatioF()
         except AttributeError:
             dpr = self.devicePixelRatio()
         p.setDevicePixelRatio(dpr)
         if data and p.isNull():
             p = self.failed_img
         return p
     left_img, right_img = load(left_data), load(right_data)
     change = []
     # Let any initial resizing of the window finish in case this is the
     # first diff, to avoid the expensive resize calculation later
     QApplication.processEvents(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents | QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers)
     for v, img, size in ((self.left, left_img, len(left_data)), (self.right, right_img, len(right_data))):
         c = v.textCursor()
         c.movePosition(QTextCursor.MoveOperation.End)
         start = c.block().blockNumber()
         lines, w = self.get_lines_for_image(img, v)
         c.movePosition(QTextCursor.MoveOperation.StartOfBlock)
         if size > 0:
             c.beginEditBlock()
             c.insertText(_('Size: {0} Resolution: {1}x{2}').format(human_readable(size), img.width(), img.height()))
             for i in range(lines + 1):
                 c.insertBlock()
         change.extend((start, c.block().blockNumber()))
         c.insertBlock()
         c.endEditBlock()
         v.images[start] = (img, w, lines)
     change.append('replace' if left_data and right_data else 'delete' if left_data else 'insert')
     self.left.changes.append((change[0], change[1], change[-1]))
     self.right.changes.append((change[2], change[3], change[-1]))
     QApplication.processEvents(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents | QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers)
Esempio n. 5
0
    def add_text_diff(self, left_text, right_text, context, syntax, beautify=False):
        left_text = unicodedata.normalize('NFC', left_text)
        right_text = unicodedata.normalize('NFC', right_text)
        if beautify and syntax in {'xml', 'html', 'css'}:
            left_text, right_text = beautify_text(left_text, syntax), beautify_text(right_text, syntax)
            if len(left_text) == len(right_text) and left_text == right_text:
                for v in (self.left, self.right):
                    c = v.textCursor()
                    c.movePosition(QTextCursor.MoveOperation.End)
                    c.insertText('[%s]\n\n' % _('The files are identical after beautifying'))
                return

        left_lines = self.left_lines = left_text.splitlines()
        right_lines = self.right_lines = right_text.splitlines()

        cruncher = get_sequence_matcher()(None, left_lines, right_lines)

        left_highlight, right_highlight = get_highlighter(self.left, left_text, syntax), get_highlighter(self.right, right_text, syntax)
        cl, cr = self.left_cursor, self.right_cursor = self.left.textCursor(), self.right.textCursor()
        cl.beginEditBlock(), cr.beginEditBlock()
        cl.movePosition(QTextCursor.MoveOperation.End), cr.movePosition(QTextCursor.MoveOperation.End)
        self.left_insert = partial(self.do_insert, cl, left_highlight, self.left.line_number_map)
        self.right_insert = partial(self.do_insert, cr, right_highlight, self.right.line_number_map)

        self.changes = []

        if context is None:
            for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
                getattr(self, tag)(alo, ahi, blo, bhi)
                QApplication.processEvents(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents | QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers)
        else:
            def insert_boundary():
                self.changes.append(Change(
                    ltop=cl.block().blockNumber()-1, lbot=cl.block().blockNumber(),
                    rtop=cr.block().blockNumber()-1, rbot=cr.block().blockNumber(), kind='boundary'))
                self.left.line_number_map[self.changes[-1].ltop] = '-'
                self.right.line_number_map[self.changes[-1].rtop] = '-'

            ahi = bhi = 0
            for i, group in enumerate(cruncher.get_grouped_opcodes(context)):
                for j, (tag, alo, ahi, blo, bhi) in enumerate(group):
                    if j == 0 and (i > 0 or min(alo, blo) > 0):
                        insert_boundary()
                    getattr(self, tag)(alo, ahi, blo, bhi)
                    QApplication.processEvents(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents | QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers)
                cl.insertBlock(), cr.insertBlock()
            if ahi < len(left_lines) - 1 or bhi < len(right_lines) - 1:
                insert_boundary()

        cl.endEditBlock(), cr.endEditBlock()
        del self.left_lines
        del self.right_lines
        del self.left_insert
        del self.right_insert

        self.coalesce_changes()

        for ltop, lbot, rtop, rbot, kind in self.changes:
            if kind != 'equal':
                self.left.changes.append((ltop, lbot, kind))
                self.right.changes.append((rtop, rbot, kind))

        del self.changes