mirror of
https://github.com/kbumsik/VirtScreen.git
synced 2025-03-09 15:40:18 +00:00
Backend: capture errors of xrandr and display settings program
This commit is contained in:
parent
7e8eeaf0a7
commit
bc0de4f368
2 changed files with 48 additions and 23 deletions
|
@ -230,12 +230,16 @@ ApplicationWindow {
|
||||||
x: (parent.width - width) / 2
|
x: (parent.width - width) / 2
|
||||||
y: (parent.width - height) / 2 //(window.height) / 2
|
y: (parent.width - height) / 2 //(window.height) / 2
|
||||||
width: popupWidth
|
width: popupWidth
|
||||||
|
height: 310
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
Text {
|
ScrollView {
|
||||||
horizontalAlignment: Text.AlignHCenter
|
anchors.fill: parent
|
||||||
|
TextArea {
|
||||||
|
// readOnly: true
|
||||||
|
selectByMouse: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
wrapMode: Text.WordWrap
|
// wrapMode: Text.WordWrap
|
||||||
text: errorText.text
|
text: errorText.text
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
if (text) {
|
if (text) {
|
||||||
|
@ -244,6 +248,21 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ScrollBar.vertical: ScrollBar {
|
||||||
|
// parent: ipListView.parent
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.left: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
policy: ScrollBar.AlwaysOn
|
||||||
|
}
|
||||||
|
ScrollBar.horizontal: ScrollBar {
|
||||||
|
// parent: ipListView.parent
|
||||||
|
anchors.top: parent.bottom
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
policy: ScrollBar.AlwaysOn
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,24 +39,17 @@ ICON_TABLET_ON_PATH = PROGRAM_PATH + "/icon/icon_tablet_on.png"
|
||||||
# Subprocess wrapper
|
# Subprocess wrapper
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
class SubprocessWrapper:
|
class SubprocessWrapper:
|
||||||
def __init__(self, stdout:str=os.devnull, stderr:str=os.devnull):
|
def __init__(self):
|
||||||
self.stdout: str = stdout
|
pass
|
||||||
self.stderr: str = stderr
|
|
||||||
|
|
||||||
def call(self, arg) -> None:
|
|
||||||
with open(os.devnull, "w") as f:
|
|
||||||
subprocess.call(arg.split(), stdout=f, stderr=f)
|
|
||||||
|
|
||||||
def check_call(self, arg) -> None:
|
def check_call(self, arg) -> None:
|
||||||
with open(os.devnull, "w") as f:
|
return subprocess.check_output(arg.split(), stderr=subprocess.STDOUT).decode('utf-8')
|
||||||
subprocess.check_call(arg.split(), stdout=f, stderr=f)
|
|
||||||
|
|
||||||
def run(self, arg: str, input: str = None) -> str:
|
def run(self, arg: str, input: str = None) -> str:
|
||||||
if input:
|
if input:
|
||||||
input = input.encode('utf-8')
|
input = input.encode('utf-8')
|
||||||
with open(os.devnull, "w") as f:
|
|
||||||
return subprocess.run(arg.split(), input=input, stdout=subprocess.PIPE,
|
return subprocess.run(arg.split(), input=input, stdout=subprocess.PIPE,
|
||||||
stderr=f).stdout.decode('utf-8')
|
stderr=subprocess.STDOUT).stdout.decode('utf-8')
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Twisted class
|
# Twisted class
|
||||||
|
@ -340,8 +333,8 @@ class XRandR(SubprocessWrapper):
|
||||||
self.mode_name
|
self.mode_name
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return
|
return
|
||||||
self.call(f"xrandr --output {self.virt.name} --off")
|
self.run(f"xrandr --output {self.virt.name} --off")
|
||||||
self.call(f"xrandr --delmode {self.virt.name} {self.mode_name}")
|
self.run(f"xrandr --delmode {self.virt.name} {self.mode_name}")
|
||||||
atexit.unregister(self.delete_virtual_screen)
|
atexit.unregister(self.delete_virtual_screen)
|
||||||
self._update_screens()
|
self._update_screens()
|
||||||
|
|
||||||
|
@ -469,7 +462,11 @@ class Backend(QObject):
|
||||||
@pyqtSlot(int, int, bool, bool)
|
@pyqtSlot(int, int, bool, bool)
|
||||||
def createVirtScreen(self, width, height, portrait, hidpi):
|
def createVirtScreen(self, width, height, portrait, hidpi):
|
||||||
print("Creating a Virtual Screen...")
|
print("Creating a Virtual Screen...")
|
||||||
|
try:
|
||||||
self.xrandr.create_virtual_screen(width, height, portrait, hidpi)
|
self.xrandr.create_virtual_screen(width, height, portrait, hidpi)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
self.onError.emit(str(e.cmd) + '\n' + e.stdout.decode('utf-8'))
|
||||||
|
return
|
||||||
self.virtScreenCreated = True
|
self.virtScreenCreated = True
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
|
@ -556,14 +553,23 @@ class Backend(QObject):
|
||||||
def _onEnded(exitCode):
|
def _onEnded(exitCode):
|
||||||
print("External Display Setting closed.")
|
print("External Display Setting closed.")
|
||||||
self.onDisplaySettingClosed.emit()
|
self.onDisplaySettingClosed.emit()
|
||||||
|
if exitCode is not 0:
|
||||||
|
self.onError.emit(f'Error opening "{running_program}".')
|
||||||
program_list = ["gnome-control-center display", "arandr"]
|
program_list = ["gnome-control-center display", "arandr"]
|
||||||
program = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, None)
|
program = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, None)
|
||||||
|
running_program = ''
|
||||||
for arg in program_list:
|
for arg in program_list:
|
||||||
if not shutil.which(arg.split()[0]):
|
if not shutil.which(arg.split()[0]):
|
||||||
continue
|
continue
|
||||||
|
running_program = arg
|
||||||
program.run(arg)
|
program.run(arg)
|
||||||
return
|
return
|
||||||
self.onError.emit('Failed to find a display settings program. Please install ARandR package.')
|
self.onError.emit('Failed to find a display settings program.\n'
|
||||||
|
'Please install ARandR package.\n'
|
||||||
|
'(e.g. sudo apt-get install arandr)\n'
|
||||||
|
'Please issue a feature request\n'
|
||||||
|
'if you wish to add a display settings\n'
|
||||||
|
'program for your Desktop Environment.')
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def stopVNC(self, force=False):
|
def stopVNC(self, force=False):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue