diff options
| author | Igor Pashev <pashev.igor@gmail.com> | 2026-07-02 18:40:06 +0200 |
|---|---|---|
| committer | Igor Pashev <pashev.igor@gmail.com> | 2026-07-02 18:40:06 +0200 |
| commit | e8b09c20345e927396cf75aa2ede4eacda0869e8 (patch) | |
| tree | 8862948d164a2e73787c5e3a619c7b90c4ffe18c | |
| parent | 157370c4afbeb49836e10bff0a3400e12fd34f94 (diff) | |
| download | newslack-master.tar.gz | |
| -rw-r--r-- | README | 13 | ||||
| -rw-r--r-- | cpp/main.cpp | 23 | ||||
| -rw-r--r-- | cpp/mainwindow.cpp | 327 | ||||
| -rw-r--r-- | cpp/mainwindow.h | 44 | ||||
| -rw-r--r-- | cpp/mainwindow.ui | 3 | ||||
| -rw-r--r-- | cpp/newslack.pro | 29 | ||||
| -rw-r--r--[-rwxr-xr-x] | newslack | 232 |
7 files changed, 320 insertions, 351 deletions
@@ -10,8 +10,8 @@ upgradepkg /mnt/slack-13.0/slackware/a/pciutils-3.1.3-i486-1.txz # pciutils-2.2. upgradepkg /mnt/slack-13.0/slackware/a/pcmciautils-015-i486-2.txz # pcmciautils-015-i486-1 installpkg /mnt/slack-13.0/slackware/ap/cupsddk-1.2.3-i486-1.txz installpkg /mnt/slack-13.0/slackware/ap/dc3dd-6.12.3-i486-1.txz -# /mnt/slack-13.0/slackware/ap/diffstat-1.43-i486-1.txz # same -# /mnt/slack-13.0/slackware/ap/diffutils-2.8.1-i486-3.txz # same +# /mnt/slack-13.0/slackware/ap/diffstat-1.43-i486-1.txz # same +# /mnt/slack-13.0/slackware/ap/diffutils-2.8.1-i486-3.txz # same upgradepkg /mnt/slack-13.0/slackware/ap/dmapi-2.2.10-i486-1.txz # dmapi-2.2.8_1-i486-1 @@ -22,17 +22,16 @@ Python program to help upgrading Slackware Usage: ./newslack [directory] -Searches for *.new files in directory (default /etc) +Searches for *.new files in the directory (default /etc) and show the differences with older files. For example: /etc/rc.d/rc.inet1 and /etc/rc.d/rc.inet1.new -Can apply partial patch. +Can apply partial patches. Requires: -Qt 4.5, -python 3.1, -pyQt4, +python 3.13, +pyQt6, pygments, find, gvim, diff --git a/cpp/main.cpp b/cpp/main.cpp index db7ef9d..1ffb56b 100644 --- a/cpp/main.cpp +++ b/cpp/main.cpp @@ -1,18 +1,17 @@ -#include <QtGui/QApplication> #include "mainwindow.h" +#include <QtWidgets/QApplication> -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + MainWindow w; - if (argc > 1) - for (int i = 1; i < argc; i++) - w.findFiles(argv[i]); - else - w.findFiles("/home/pashev/tmp"); + if (argc > 1) + for (int i = 1; i < argc; i++) + w.findFiles(argv[i]); + else + w.findFiles("/etc"); - w.show(); + w.show(); - return a.exec(); + return a.exec(); } diff --git a/cpp/mainwindow.cpp b/cpp/mainwindow.cpp index 4ad16f0..ce5b2bc 100644 --- a/cpp/mainwindow.cpp +++ b/cpp/mainwindow.cpp @@ -1,220 +1,183 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include <QDir> #include <QDebug> +#include <QDir> #include <QProcess> -#include <QRegExp> #include <QTextBlock> +#include <QtCore/QRegularExpression> -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); -} - -MainWindow::~MainWindow() -{ - delete ui; +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), ui(new Ui::MainWindow) { + ui->setupUi(this); } -void MainWindow::changeEvent(QEvent *e) -{ - QMainWindow::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } +MainWindow::~MainWindow() { delete ui; } + +void MainWindow::changeEvent(QEvent *e) { + QMainWindow::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } } -void MainWindow::on_quit_clicked() -{ - qApp->quit(); +void MainWindow::on_quit_clicked() { qApp->quit(); } + +void MainWindow::findFiles(QString path) { + QDir currentDir = QDir(path); + QStringList files = currentDir.entryList(QStringList("*.new"), + QDir::Files | QDir::NoSymLinks); + Q_FOREACH (QString f, files) { + ui->files->addItem(path + "/" + f); + } + + files = + currentDir.entryList(QStringList("*"), QDir::Dirs | QDir::NoSymLinks | + QDir::NoDot | QDir::NoDotDot); + Q_FOREACH (QString dir, files) { + findFiles(path + "/" + dir); + } } -void MainWindow::findFiles(QString path) -{ - QDir currentDir = QDir(path); - QStringList files = - currentDir.entryList(QStringList("*.new"), - QDir::Files | QDir::NoSymLinks); - Q_FOREACH (QString f, files) - { - ui->files->addItem(path + "/" + f); - } - - files = - currentDir.entryList(QStringList("*"), - QDir::Dirs | QDir::NoSymLinks - | QDir::NoDot | QDir::NoDotDot); - Q_FOREACH (QString dir, files) - { - findFiles(path + "/" + dir); - } +void MainWindow::enableButtons() { + bool enable = 0 != ui->files->count(); + ui->accept->setEnabled(enable); + ui->reject->setEnabled(enable); + ui->edit->setEnabled(enable); } -void MainWindow::enableButtons() -{ - bool enable = 0 != ui->files->count(); - ui->accept->setEnabled(enable); - ui->reject->setEnabled(enable); - ui->edit->setEnabled(enable); +void MainWindow::on_files_currentItemChanged(QListWidgetItem *current, + QListWidgetItem * /*previous*/) { + if (!current) { + ui->diff->clear(); + return; + } + update_diff(); } -void MainWindow::on_files_currentItemChanged - (QListWidgetItem* current, QListWidgetItem* /*previous*/) -{ - if (!current) - { - ui->diff->clear(); - return; - } - update_diff(); +void MainWindow::update_diff() { + QString fold, fnew; + fold = fnew = ui->files->currentItem()->text(); + fold.replace(QRegularExpression("\\.new$"), ""); + QStringList difflines = diff(fold, fnew).split("\n"); + difflines.replaceInStrings( + QRegularExpression("(@@[^@]+@@)"), + "<span style=\"color:blue;font-weight:bold;\">\\1</span>"); + difflines.replaceInStrings(QRegularExpression("^((---|\\+\\+\\+)\\s.*)$"), + "<span style=\"font-weight:bold;\">\\1</span>"); + difflines.replaceInStrings( + QRegularExpression("^(-.*)$"), + "<span style=\"color:red;font-weight:bold;\">\\1</span>"); + difflines.replaceInStrings( + QRegularExpression("^(\\+.*)$"), + "<span style=\"color:green;font-weight:bold;\">\\1</span>"); + + if (difflines.count() < 2) + on_reject_clicked(); + else { + ui->diff->setHtml("<pre>" + difflines.join("\n") + "</pre>"); + enableButtons(); + } } -void MainWindow::update_diff() -{ - QString fold, fnew; - fold = fnew = ui->files->currentItem()->text(); - fold.replace(QRegExp("\\.new$"), ""); - QStringList difflines = diff(fold, fnew).split("\n"); - difflines.replaceInStrings(QRegExp("(@@[^@]+@@)"), - "<span style=\"color:blue;font-weight:bold;\">\\1</span>"); - difflines.replaceInStrings(QRegExp("^((---|\\+\\+\\+)\\s.*)$"), - "<span style=\"font-weight:bold;\">\\1</span>"); - difflines.replaceInStrings(QRegExp("^(-.*)$"), - "<span style=\"color:red;font-weight:bold;\">\\1</span>"); - difflines.replaceInStrings(QRegExp("^(\\+.*)$"), - "<span style=\"color:green;font-weight:bold;\">\\1</span>"); - - if (difflines.count() < 2) - on_reject_clicked(); - else - { - ui->diff->setHtml("<pre>" + difflines.join("\n") + "</pre>"); - enableButtons(); - } +QString MainWindow::diff(QString fold, QString fnew) { + QProcess pipe; + QStringList args; + args << "-udb" << fold << fnew; + pipe.start("diff", args, QIODevice::ReadOnly); + pipe.waitForFinished(); + QString res = QString::fromUtf8(pipe.readAllStandardOutput().constData()); + return res; } -QString MainWindow::diff(QString fold, QString fnew) -{ - QProcess pipe; - QStringList args; - args << "-udb" << fold << fnew; - pipe.start("diff", args, QIODevice::ReadOnly); - pipe.waitForFinished(); - QString res = QString::fromUtf8( - pipe.readAllStandardOutput().constData()); - return res; +void MainWindow::on_accept_clicked() { + QString fold, fnew; + fold = fnew = ui->files->currentItem()->text(); + fold.replace(QRegularExpression("\\.new$"), ""); + if (QFile::remove(fold) && QFile::rename(fnew, fold)) { + ui->files->takeItem(ui->files->row(ui->files->currentItem())); + } else { + qWarning() << "Unable to move" << fnew << "to" << fold; + } + enableButtons(); } -void MainWindow::on_accept_clicked() -{ - QString fold, fnew; - fold = fnew = ui->files->currentItem()->text(); - fold.replace(QRegExp("\\.new$"), ""); - if (QFile::remove(fold) && QFile::rename(fnew, fold)) - { - ui->files->takeItem( - ui->files->row( - ui->files->currentItem())); - } - else - { - qWarning() << "Unable to move" - << fnew << "to" << fold; - } - enableButtons(); +void MainWindow::on_reject_clicked() { + QString fnew; + fnew = ui->files->currentItem()->text(); + if (QFile::remove(fnew)) { + ui->files->takeItem(ui->files->row(ui->files->currentItem())); + } else { + qWarning() << "Unable to delete" << fnew; + } + enableButtons(); } -void MainWindow::on_reject_clicked() -{ - QString fnew; - fnew = ui->files->currentItem()->text(); - if (QFile::remove(fnew)) - { - ui->files->takeItem(ui->files->row(ui->files->currentItem())); - } - else - { - qWarning() << "Unable to delete" << fnew; - } - enableButtons(); +void MainWindow::on_diff_selectionChanged() { + ui->apply->setEnabled(ui->diff->textCursor().selectionStart() != + ui->diff->textCursor().selectionEnd()); } -void MainWindow::on_diff_selectionChanged() -{ - ui->apply->setEnabled( - ui->diff->textCursor().selectionStart() != - ui->diff->textCursor().selectionEnd()); +void MainWindow::on_edit_clicked() { + QString fold, fnew; + fold = fnew = ui->files->currentItem()->text(); + fold.replace(QRegularExpression("\\.new$"), ""); + + QProcess editor; + QStringList args; + args << "-f"; + args << fold; + editor.start("gvim", args); + editor.waitForFinished(); + update_diff(); } -void MainWindow::on_edit_clicked() -{ - QString fold, fnew; - fold = fnew = ui->files->currentItem()->text(); - fold.replace(QRegExp("\\.new$"), ""); - - QProcess editor; - QStringList args; - args << "-f"; - args << fold; - editor.start("gvim", args); - editor.waitForFinished(); - update_diff(); -} +void MainWindow::on_apply_clicked() { + int start = ui->diff->textCursor().selectionStart(); + int end = ui->diff->textCursor().selectionEnd(); -void MainWindow::on_apply_clicked() -{ - int start = ui->diff->textCursor().selectionStart(); - int end = ui->diff->textCursor().selectionEnd(); + int first = ui->diff->document()->findBlock(start).firstLineNumber(); + int last = ui->diff->document()->findBlock(end).firstLineNumber(); - int first = ui->diff->document()->findBlock(start).firstLineNumber(); - int last = ui->diff->document()->findBlock(end).firstLineNumber(); + if (last <= first) + last = first + 1; - if (last <= first) - last = first + 1; + QStringList lines = ui->diff->toPlainText().split("\n"); - QStringList lines = ui->diff->toPlainText().split("\n"); + QStringList part_diff; + part_diff << lines[0] << lines[1]; - QStringList part_diff; - part_diff << lines[0] << lines[1]; + // Looking for the beginning + if (first < 2) + first = 2; + else + while (lines[first].left(2) != "@@") + first--; - // Looking for the begining - if (first < 2) first = 2; + // Looking for the end + int nlines = lines.count(); + while (last < nlines) { + if (lines[last].left(2) == "@@") + break; else - while (lines[first].left(2) != "@@") - first--; - - // Looking for the end - int nlines = lines.count(); - while (last < nlines) - { - if (lines[last].left(2) == "@@") - break; - else last++; - } - part_diff << lines.mid(first, last-first) << "\n"; - patch(part_diff.join("\n")); - update_diff(); + last++; + } + part_diff << lines.mid(first, last - first) << "\n"; + patch(part_diff.join("\n")); + update_diff(); } -void MainWindow::patch(QString diff) -{ - QProcess pipe; - QStringList args; - // args << "--dry-run"; // TODO: remove me - args << "-p0" << "-l"; - pipe.start("patch", args); - pipe.waitForStarted(); - pipe.write(diff.toUtf8()); - pipe.closeWriteChannel(); - pipe.waitForFinished(); - qDebug() << pipe.readAllStandardOutput(); +void MainWindow::patch(QString diff) { + QProcess pipe; + QStringList args; + args << "-p0" << "-l"; + pipe.start("patch", args); + pipe.waitForStarted(); + pipe.write(diff.toUtf8()); + pipe.closeWriteChannel(); + pipe.waitForFinished(); + qDebug() << pipe.readAllStandardOutput(); } - - - diff --git a/cpp/mainwindow.h b/cpp/mainwindow.h index f18ee95..a8719a4 100644 --- a/cpp/mainwindow.h +++ b/cpp/mainwindow.h @@ -1,40 +1,40 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include <QtGui/QMainWindow> -#include <QListWidgetItem> +#include <QtWidgets/QListWidgetItem> +#include <QtWidgets/QMainWindow> namespace Ui { - class MainWindow; +class MainWindow; } -class MainWindow : public QMainWindow -{ - Q_OBJECT +class MainWindow : public QMainWindow { + Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); - void findFiles(QString); - ~MainWindow(); + explicit MainWindow(QWidget *parent = 0); + void findFiles(QString); + ~MainWindow(); protected: - void changeEvent(QEvent *e); - void patch(QString); - QString diff(QString, QString); - void enableButtons(); - void update_diff(); + void changeEvent(QEvent *e); + void patch(QString); + QString diff(QString, QString); + void enableButtons(); + void update_diff(); private: - Ui::MainWindow *ui; + Ui::MainWindow *ui; private slots: - void on_apply_clicked(); - void on_edit_clicked(); - void on_diff_selectionChanged(); - void on_reject_clicked(); - void on_accept_clicked(); - void on_files_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous); - void on_quit_clicked(); + void on_apply_clicked(); + void on_edit_clicked(); + void on_diff_selectionChanged(); + void on_reject_clicked(); + void on_accept_clicked(); + void on_files_currentItemChanged(QListWidgetItem *current, + QListWidgetItem *previous); + void on_quit_clicked(); }; #endif // MAINWINDOW_H diff --git a/cpp/mainwindow.ui b/cpp/mainwindow.ui index 93f7ac2..4450fa1 100644 --- a/cpp/mainwindow.ui +++ b/cpp/mainwindow.ui @@ -33,9 +33,6 @@ <property name="readOnly"> <bool>true</bool> </property> - <property name="tabStopWidth"> - <number>40</number> - </property> </widget> </item> <item> diff --git a/cpp/newslack.pro b/cpp/newslack.pro index df4fb8b..2081eb0 100644 --- a/cpp/newslack.pro +++ b/cpp/newslack.pro @@ -1,18 +1,21 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2010-11-06T17:12:39 -# -#------------------------------------------------- +###################################################################### +# Automatically generated by qmake (3.1) Thu Jul 2 18:24:27 2026 +###################################################################### -QT += core gui - -TARGET = newslack TEMPLATE = app +TARGET = newslack +INCLUDEPATH += . +QT += widgets -SOURCES += main.cpp\ - mainwindow.cpp - -HEADERS += mainwindow.h +# You can make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# Please consult the documentation of the deprecated API in order to know +# how to port your code away from it. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_UP_TO=0x060000 # disables all APIs deprecated in Qt 6.0.0 and earlier -FORMS += mainwindow.ui +# Input +HEADERS += mainwindow.h +FORMS += mainwindow.ui +SOURCES += main.cpp mainwindow.cpp @@ -3,92 +3,91 @@ import sys import os -import stat -import glob import difflib -import string import subprocess -from PyQt4 import QtGui, QtCore +from PyQt6 import QtWidgets, QtCore from pygments import highlight -from pygments.lexers import DiffLexer -from pygments.formatters import HtmlFormatter +from pygments.lexers.diff import DiffLexer +from pygments.formatters.html import HtmlFormatter + +EDITOR = "gvim -f" +FIND = "find {} -type f -name '*.new' -o -name '*.dpkg-dist'" +PATCH = "patch -p0" +DIR = "/etc" -EDITOR = 'gvim -f' -FIND = "find {} -type f -name '*.new'" -PATCH = 'patch -p0' -DIR = '/etc' def usage(): - print ('Usage: {} [directory]'.format(sys.argv[0])) + print(f"Usage: {sys.argv[0]} [directory]") -class MainWindow(QtGui.QWidget): - newlist = None # QListWidget - diff = None # QTextEdit - edit = None # QPushButton - accept = None # QPushButton - reject = None # QPushButton - patch = None # QPushButton +class MainWindow(QtWidgets.QWidget): + newlist = None # QListWidget + diff = None # QTextEdit + edit = None # QPushButton + accept = None # QPushButton + reject = None # QPushButton + patch = None # QPushButton - newfile = None # /etc/file.new - oldfile = None # /etc/file + newfile = None # /etc/file.new + oldfile = None # /etc/file @QtCore.pyqtSlot() def on_partial_diff(self): cursor = self.diff.textCursor() - start = cursor.selectionStart() - end = cursor.selectionEnd() + start = cursor.selectionStart() + end = cursor.selectionEnd() # starting and ending line numbers for the selection start_line = self.diff.document().findBlock(start).firstLineNumber() - end_line = self.diff.document().findBlock(end).firstLineNumber() + end_line = self.diff.document().findBlock(end).firstLineNumber() - fulldiff = self.diff.toPlainText().splitlines(); + fulldiff = self.diff.toPlainText().splitlines() max_lines = len(fulldiff) - 1 -# For references: -#--- etc/ftpusers -#+++ etc/ftpusers.new -#@@ -16,7 +16,7 @@ -# # To enable anonymous FTP, remove the "ftp" user: -# ftp -# root -#-uucp -#+pashev -# news + # For references: + # --- etc/ftpusers + # +++ etc/ftpusers.new + # @@ -16,7 +16,7 @@ + # # To enable anonymous FTP, remove the "ftp" user: + # ftp + # root + # -uucp + # +pashev + # news # two first lines - partdiff = fulldiff[0] + '\n' + fulldiff[1] + '\n' - + partdiff = fulldiff[0] + "\n" + fulldiff[1] + "\n" + # looking for start of diff block (@@ -16,7 +16,7 @@) if start_line < 2: start_line = 2 else: - while fulldiff[start_line][0:2] != '@@': + while fulldiff[start_line][0:2] != "@@": start_line = start_line - 1 # looking for end of diff block (next @@ ... @@ or EOF) if end_line <= start_line: end_line = start_line + 1 - + while end_line < max_lines: - if fulldiff[end_line][0:2] == '@@': + if fulldiff[end_line][0:2] == "@@": break end_line = end_line + 1 - + for l in range(start_line, end_line): - partdiff = partdiff + fulldiff[l] + '\n' - + partdiff = partdiff + fulldiff[l] + "\n" + # apply partial patch - pipe = subprocess.Popen(PATCH, shell=True, - universal_newlines=True, stdin=subprocess.PIPE) - pipe.stdin.write(partdiff) - pipe.stdin.flush() - pipe.stdin.close() - pipe.wait() - + with subprocess.Popen( + PATCH, shell=True, universal_newlines=True, stdin=subprocess.PIPE + ) as pipe: + pipe.stdin.write(partdiff) + pipe.stdin.flush() + pipe.stdin.close() + pipe.wait() + self.reloaddiff(self.newfile) def enable_buttons(self): @@ -97,13 +96,12 @@ class MainWindow(QtGui.QWidget): self.accept.setEnabled(n > 0) self.reject.setEnabled(n > 0) - @QtCore.pyqtSlot() def on_selection_changed(self): self.patch.setEnabled( - self.diff.textCursor().selectionStart() != self.diff.textCursor().selectionEnd() - ) - + self.diff.textCursor().selectionStart() + != self.diff.textCursor().selectionEnd() + ) @QtCore.pyqtSlot() def on_accept(self): @@ -122,8 +120,8 @@ class MainWindow(QtGui.QWidget): self.accept.setEnabled(False) self.newlist.setEnabled(False) - p = subprocess.Popen(EDITOR + ' ' + self.oldfile, shell=True) - sts = os.waitpid(p.pid, 0) + with subprocess.Popen(EDITOR + " " + self.oldfile, shell=True) as p: + os.waitpid(p.pid, 0) self.reloaddiff(self.newfile) self.newlist.setEnabled(True) @@ -133,99 +131,109 @@ class MainWindow(QtGui.QWidget): def reloaddiff(self, newfile): self.diff.clear() self.newfile = str(newfile) - self.oldfile = self.newfile[0:self.newfile.find('.new')] + self.oldfile = self.newfile.removesuffix(".new").removesuffix(".dpkg-dist") if self.newfile: - tolines = open(self.newfile, 'U').readlines() - fromlines = open(self.oldfile, 'U').readlines() - difflines = difflib.unified_diff(fromlines, tolines, self.oldfile, self.newfile) - difftext = ''.join(difflines) - - self.edit.setToolTip(EDITOR + ' ' + self.oldfile) - self.reject.setToolTip('Remove ' + self.newfile) - self.accept.setToolTip(self.newfile + ' -> ' + self.oldfile) + with open(self.newfile, encoding="utf-8") as f: + tolines = f.readlines() + with open(self.oldfile, encoding="utf-8") as f: + fromlines = f.readlines() + + difflines = difflib.unified_diff( + fromlines, tolines, self.oldfile, self.newfile + ) + difftext = "".join(difflines) + + self.edit.setToolTip(EDITOR + " " + self.oldfile) + self.reject.setToolTip("Remove " + self.newfile) + self.accept.setToolTip(self.newfile + " -> " + self.oldfile) self.accept.setEnabled(bool(difftext)) - colored_rtf = highlight(difftext, DiffLexer(), HtmlFormatter(full=True)) + colored_rtf = highlight( + difftext, DiffLexer(), HtmlFormatter(noclasses=True) + ) self.diff.setText(colored_rtf) def __init__(self, parent=None): - QtGui.QWidget.__init__(self, parent) + QtWidgets.QWidget.__init__(self, parent) + + mvbox = QtWidgets.QVBoxLayout() # main layout + split = QtWidgets.QSplitter( + QtCore.Qt.Orientation.Horizontal, self + ) # left-right splitter - mvbox = QtGui.QVBoxLayout() # main layout - split = QtGui.QSplitter(QtCore.Qt.Horizontal, self) # left-right splitter - - rpart = QtGui.QWidget(split) # right side - lpart = QtGui.QWidget(split) # left side + rpart = QtWidgets.QWidget(split) # right side + lpart = QtWidgets.QWidget(split) # left side - rvbox = QtGui.QVBoxLayout() # right side layout - lvbox = QtGui.QVBoxLayout() # left side layout + rvbox = QtWidgets.QVBoxLayout() # right side layout + lvbox = QtWidgets.QVBoxLayout() # left side layout rpart.setLayout(rvbox) lpart.setLayout(lvbox) - self.diff = QtGui.QTextEdit() # to show diff + self.diff = QtWidgets.QTextEdit() # to show diff self.diff.setReadOnly(True) - - self.newlist = QtGui.QListWidget() # to show all *.new files - - # Load all *.new files - pipe = subprocess.Popen(FIND.format(DIR), shell=True, - universal_newlines=True, stdout=subprocess.PIPE) - news = pipe.stdout.read().splitlines() + + self.newlist = QtWidgets.QListWidget() # to show all *.new files + + # Load all *.new files + with subprocess.Popen( + FIND.format(DIR), + shell=True, + universal_newlines=True, + stdout=subprocess.PIPE, + ) as pipe: + news = pipe.stdout.read().splitlines() + for new in news: if new: self.newlist.addItem(new) - - quit = QtGui.QPushButton('&Quit', self) - self.accept = QtGui.QPushButton('&Accept', self) - self.reject = QtGui.QPushButton('&Reject', self) - self.edit = QtGui.QPushButton('&Edit old...', self) - self.patch = QtGui.QPushButton('A&pply selection', self) + + bye = QtWidgets.QPushButton("&Quit", self) + self.accept = QtWidgets.QPushButton("&Accept", self) + self.reject = QtWidgets.QPushButton("&Reject", self) + self.edit = QtWidgets.QPushButton("&Edit old...", self) + self.patch = QtWidgets.QPushButton("A&pply selection", self) self.patch.setEnabled(False) - self.patch.setToolTip('Patch using block with selected text') + self.patch.setToolTip("Patch using block with selected text") - lvbox.addWidget(self.diff) # diff is on the left side - lvbox.addWidget(self.patch) # "apply patch" button (can be invisible) - buttons = QtGui.QHBoxLayout() # buttons are below it - lvbox.addLayout(buttons) # buttons layout + lvbox.addWidget(self.diff) # diff is on the left side + lvbox.addWidget(self.patch) # "apply patch" button (can be invisible) + buttons = QtWidgets.QHBoxLayout() # buttons are below it + lvbox.addLayout(buttons) # buttons layout buttons.addWidget(self.accept) buttons.addWidget(self.reject) buttons.addWidget(self.edit) - rvbox.addWidget(self.newlist) # file list is on the right side - rvbox.addWidget(quit) # quit button is below it + rvbox.addWidget(self.newlist) # file list is on the right side + rvbox.addWidget(bye) # quit button is below it - mvbox.addWidget(split) # split is the main widget of main window - split.addWidget(lpart) # add the left side on the split - split.addWidget(rpart) # add the right side on the split + mvbox.addWidget(split) # split is the main widget of main window + split.addWidget(lpart) # add the left side on the split + split.addWidget(rpart) # add the right side on the split self.resize(640, 480) - self.setWindowTitle("What\'s new in %s ?" % DIR) + self.setWindowTitle(f"What's new in {DIR} ?") self.setLayout(mvbox) - self.connect(quit, QtCore.SIGNAL('clicked()'), QtGui.qApp, QtCore.SLOT('quit()')) - self.connect(self.edit, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('on_edit()')) - self.connect(self.accept, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('on_accept()')) - self.connect(self.reject, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('on_reject()')) - self.connect(self.patch, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('on_partial_diff()')) - self.connect(self.diff, QtCore.SIGNAL('selectionChanged()'), self, QtCore.SLOT('on_selection_changed()')) - self.connect(self.newlist, QtCore.SIGNAL('currentTextChanged(QString)'), - self, QtCore.SLOT('reloaddiff(QString)')) - + bye.clicked.connect(QtWidgets.QApplication.quit) + self.edit.clicked.connect(self.on_edit) + self.accept.clicked.connect(self.on_accept) + self.reject.clicked.connect(self.on_reject) + self.patch.clicked.connect(self.on_partial_diff) + self.diff.selectionChanged.connect(self.on_selection_changed) + self.newlist.currentTextChanged.connect(self.reloaddiff) + self.newlist.setCurrentRow(0) self.enable_buttons() - if len(sys.argv) > 2: usage() sys.exit(1) elif len(sys.argv) == 2: DIR = sys.argv[1] - -app = QtGui.QApplication(sys.argv) +app = QtWidgets.QApplication(sys.argv) win = MainWindow() win.show() -sys.exit(app.exec_()) - +sys.exit(app.exec()) |
