PipxInterface/PipxExecDialog.py

Sun, 29 Dec 2024 14:56:04 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Dec 2024 14:56:04 +0100
changeset 121
8deb7d8d9b86
parent 104
45c88e73e3dd
permissions
-rw-r--r--

Prepared a new release.

4
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
104
45c88e73e3dd Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
3 # Copyright (c) 2024 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
4
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog showing the output of a pip command.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt6.QtCore import QCoreApplication, QProcess, Qt, QTimer, pyqtSlot
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt6.QtWidgets import QAbstractButton, QDialog, QDialogButtonBox
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from eric7 import Preferences
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from eric7.EricWidgets import EricMessageBox
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
9
2ab7d3ac8283 Implemented the 'pipx install' and 'pipx install-all' functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
16 from .Ui_PipxExecDialog import Ui_PipxExecDialog
4
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
9
2ab7d3ac8283 Implemented the 'pipx install' and 'pipx install-all' functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
19 class PipxExecDialog(QDialog, Ui_PipxExecDialog):
4
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class implementing a dialog showing the output of a 'python -m pip'
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 command.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def __init__(self, text, parent=None):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param text text to be shown by the label
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @type str
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param parent reference to the parent widget
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @type QWidget
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 super().__init__(parent)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.setupUi(self)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.proc = None
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.__processQueue = []
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.outputGroup.setTitle(text)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.show()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 QCoreApplication.processEvents()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 def closeEvent(self, e):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 Protected slot implementing a close event handler.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @param e close event
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @type QCloseEvent
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__cancel()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 e.accept()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 def __finish(self):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Private slot called when the process finished or the user pressed
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 the button.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 if (
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.proc is not None
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 and self.proc.state() != QProcess.ProcessState.NotRunning
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 ):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.proc.terminate()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 QTimer.singleShot(2000, self.proc.kill)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.proc.waitForFinished(3000)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.proc = None
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 if self.__processQueue:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 command, args = self.__processQueue.pop(0)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__addOutput("\n\n")
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.startProcess(command, args)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 else:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 True
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 )
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 False
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 )
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 True
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 )
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus(
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 Qt.FocusReason.OtherFocusReason
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 )
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 def __cancel(self):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 Private slot to cancel the current action.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.__processQueue = []
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.__finish()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @pyqtSlot(QAbstractButton)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 def on_buttonBox_clicked(self, button):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 Private slot called by a button of the button box clicked.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 @param button button that was clicked
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @type QAbstractButton
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.close()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.__cancel()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 @pyqtSlot(int, QProcess.ExitStatus)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 def __procFinished(self, _exitCode, _exitStatus):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 Private slot connected to the finished signal.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @param _exitCode exit code of the process (unused)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @type int
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @param _exitStatus exit status of the process (unused)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @type QProcess.ExitStatus
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.__finish()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 def startProcess(self, pipx, args, showArgs=True):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 Public slot used to start the process.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 @param pipx path to the 'pipx' executable to be used
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @type str
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 @param args list of arguments for the process
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 @type list of str
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 @param showArgs flag indicating to show the arguments
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 @type bool
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @return flag indicating a successful start of the process
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 @rtype bool
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 if len(self.errors.toPlainText()) == 0:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 self.errorGroup.hide()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 if showArgs:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.resultbox.append(pipx + " " + " ".join(args))
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.resultbox.append("")
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 self.proc = QProcess()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 self.proc.finished.connect(self.__procFinished)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 self.proc.readyReadStandardOutput.connect(self.__readStdout)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 self.proc.readyReadStandardError.connect(self.__readStderr)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 self.proc.start(pipx, args)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 procStarted = self.proc.waitForStarted(5000)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if not procStarted:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.buttonBox.setFocus()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 EricMessageBox.critical(
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 self,
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.tr("Process Generation Error"),
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 self.tr("The process {0} could not be started.").format(pipx),
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 )
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 return procStarted
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 def startProcesses(self, processParams):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 Public method to issue a list of commands to be executed.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @param processParams list of tuples containing the command
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 and arguments
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 @type list of tuples of (str, list of str)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @return flag indicating a successful start of the first process
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @rtype bool
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 if len(processParams) > 1:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 for command, args in processParams[1:]:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 self.__processQueue.append((command, args[:]))
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 command, args = processParams[0]
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 return self.startProcess(command, args)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 def __readStdout(self):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 Private slot to handle the readyReadStandardOutput signal.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 It reads the output of the process, formats it and inserts it into
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 the contents pane.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 if self.proc is not None:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 txt = str(
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.proc.readAllStandardOutput(),
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 Preferences.getSystem("IOEncoding"),
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 "replace",
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 )
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 self.__addOutput(txt)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 def __addOutput(self, txt):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 Private method to add some text to the output pane.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 @param txt text to be added
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 @type str
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 self.resultbox.insertPlainText(txt)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.resultbox.ensureCursorVisible()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 QCoreApplication.processEvents()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 def __readStderr(self):
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 Private slot to handle the readyReadStandardError signal.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 It reads the error output of the process and inserts it into the
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 error pane.
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 """
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 if self.proc is not None:
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 s = str(
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 self.proc.readAllStandardError(),
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 Preferences.getSystem("IOEncoding"),
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 "replace",
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 )
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 self.errorGroup.show()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.errors.insertPlainText(s)
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.errors.ensureCursorVisible()
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216
097a06104774 Implemented two foundational dialogs for executing pipx commands and running applications from the list.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 QCoreApplication.processEvents()

eric ide

mercurial