mirror of
https://github.com/kbumsik/VirtScreen.git
synced 2025-03-09 15:40:18 +00:00
UI: More graceful program termination
This commit is contained in:
parent
3baace0064
commit
6e93c9783d
1 changed files with 38 additions and 2 deletions
|
@ -110,6 +110,11 @@ class XRandR:
|
||||||
self._update_virtual_screen()
|
self._update_virtual_screen()
|
||||||
|
|
||||||
def delete_virtual_screen(self) -> None:
|
def delete_virtual_screen(self) -> None:
|
||||||
|
try:
|
||||||
|
self.virt.name
|
||||||
|
self.mode_name
|
||||||
|
except AttributeError:
|
||||||
|
return
|
||||||
self._call(f"xrandr --output {self.virt.name} --off")
|
self._call(f"xrandr --output {self.virt.name} --off")
|
||||||
self._call(f"xrandr --delmode {self.virt.name} {self.mode_name}")
|
self._call(f"xrandr --delmode {self.virt.name} {self.mode_name}")
|
||||||
|
|
||||||
|
@ -187,18 +192,21 @@ class Window(QDialog):
|
||||||
# Create objects
|
# Create objects
|
||||||
self.createDisplayGroupBox()
|
self.createDisplayGroupBox()
|
||||||
self.createVNCGroupBox()
|
self.createVNCGroupBox()
|
||||||
|
self.createBottomLayout()
|
||||||
self.createActions()
|
self.createActions()
|
||||||
self.createTrayIcon()
|
self.createTrayIcon()
|
||||||
self.xrandr = XRandR()
|
self.xrandr = XRandR()
|
||||||
# Additional attributes
|
# Additional attributes
|
||||||
self.isDisplayCreated = False
|
self.isDisplayCreated = False
|
||||||
self.isVNCRunning = False
|
self.isVNCRunning = False
|
||||||
|
self.isQuitProgramPending = False
|
||||||
# Update UI
|
# Update UI
|
||||||
self.update_ip_address()
|
self.update_ip_address()
|
||||||
# Put togather
|
# Put togather
|
||||||
mainLayout = QVBoxLayout()
|
mainLayout = QVBoxLayout()
|
||||||
mainLayout.addWidget(self.displayGroupBox)
|
mainLayout.addWidget(self.displayGroupBox)
|
||||||
mainLayout.addWidget(self.VNCGroupBox)
|
mainLayout.addWidget(self.VNCGroupBox)
|
||||||
|
mainLayout.addLayout(self.bottomLayout)
|
||||||
self.setLayout(mainLayout)
|
self.setLayout(mainLayout)
|
||||||
# Events
|
# Events
|
||||||
self.trayIcon.activated.connect(self.iconActivated)
|
self.trayIcon.activated.connect(self.iconActivated)
|
||||||
|
@ -206,6 +214,7 @@ class Window(QDialog):
|
||||||
self.startVNCButton.pressed.connect(self.startVNCPressed)
|
self.startVNCButton.pressed.connect(self.startVNCPressed)
|
||||||
self.VNCMessageListWidget.model().rowsInserted.connect(
|
self.VNCMessageListWidget.model().rowsInserted.connect(
|
||||||
self.VNCMessageListWidget.scrollToBottom)
|
self.VNCMessageListWidget.scrollToBottom)
|
||||||
|
self.bottomQuitButton.pressed.connect(self.quitProgram)
|
||||||
# Show
|
# Show
|
||||||
icon = QIcon("icon.png")
|
icon = QIcon("icon.png")
|
||||||
self.trayIcon.setIcon(icon)
|
self.trayIcon.setIcon(icon)
|
||||||
|
@ -292,6 +301,16 @@ class Window(QDialog):
|
||||||
icon,
|
icon,
|
||||||
7 * 1000)
|
7 * 1000)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def quitProgram(self):
|
||||||
|
self.isQuitProgramPending = True
|
||||||
|
try:
|
||||||
|
# Rest of quit sequence will be handled in the callback.
|
||||||
|
self.VNCServer.kill()
|
||||||
|
except AttributeError:
|
||||||
|
self.xrandr.delete_virtual_screen()
|
||||||
|
QApplication.instance().quit()
|
||||||
|
|
||||||
def createDisplayGroupBox(self):
|
def createDisplayGroupBox(self):
|
||||||
self.displayGroupBox = QGroupBox("Virtual Display Settings")
|
self.displayGroupBox = QGroupBox("Virtual Display Settings")
|
||||||
|
|
||||||
|
@ -381,14 +400,28 @@ class Window(QDialog):
|
||||||
portLayout.addWidget(self.VNCPortSpinBox)
|
portLayout.addWidget(self.VNCPortSpinBox)
|
||||||
portLayout.addStretch()
|
portLayout.addStretch()
|
||||||
layout.addLayout(portLayout)
|
layout.addLayout(portLayout)
|
||||||
|
layout.addWidget(self.startVNCButton)
|
||||||
layout.addWidget(IPLabel)
|
layout.addWidget(IPLabel)
|
||||||
layout.addWidget(self.VNCIPListWidget)
|
layout.addWidget(self.VNCIPListWidget)
|
||||||
layout.addWidget(self.startVNCButton)
|
|
||||||
layout.addSpacing(15)
|
layout.addSpacing(15)
|
||||||
layout.addWidget(messageLabel)
|
layout.addWidget(messageLabel)
|
||||||
layout.addWidget(self.VNCMessageListWidget)
|
layout.addWidget(self.VNCMessageListWidget)
|
||||||
self.VNCGroupBox.setLayout(layout)
|
self.VNCGroupBox.setLayout(layout)
|
||||||
|
|
||||||
|
def createBottomLayout(self):
|
||||||
|
self.bottomLayout = QVBoxLayout()
|
||||||
|
|
||||||
|
# Create button
|
||||||
|
self.bottomQuitButton = QPushButton("Quit")
|
||||||
|
self.bottomQuitButton.setDefault(False)
|
||||||
|
self.bottomQuitButton.setEnabled(True)
|
||||||
|
|
||||||
|
# Set Overall layout
|
||||||
|
hLayout = QHBoxLayout()
|
||||||
|
hLayout.addStretch()
|
||||||
|
hLayout.addWidget(self.bottomQuitButton)
|
||||||
|
self.bottomLayout.addLayout(hLayout)
|
||||||
|
|
||||||
def createActions(self):
|
def createActions(self):
|
||||||
self.createDisplayAction = QAction("Create display", self)
|
self.createDisplayAction = QAction("Create display", self)
|
||||||
self.createDisplayAction.triggered.connect(self.createDisplayPressed)
|
self.createDisplayAction.triggered.connect(self.createDisplayPressed)
|
||||||
|
@ -410,7 +443,7 @@ class Window(QDialog):
|
||||||
self.openAction.triggered.connect(self.showNormal)
|
self.openAction.triggered.connect(self.showNormal)
|
||||||
|
|
||||||
self.quitAction = QAction("&Quit", self)
|
self.quitAction = QAction("&Quit", self)
|
||||||
self.quitAction.triggered.connect(QApplication.instance().quit)
|
self.quitAction.triggered.connect(self.quitProgram)
|
||||||
|
|
||||||
def createTrayIcon(self):
|
def createTrayIcon(self):
|
||||||
self.trayIconMenu = QMenu(self)
|
self.trayIconMenu = QMenu(self)
|
||||||
|
@ -447,6 +480,9 @@ class Window(QDialog):
|
||||||
def _onEnded(exitCode):
|
def _onEnded(exitCode):
|
||||||
self.startVNCButton.setEnabled(False)
|
self.startVNCButton.setEnabled(False)
|
||||||
self.isVNCRunning = False
|
self.isVNCRunning = False
|
||||||
|
if self.isQuitProgramPending:
|
||||||
|
self.xrandr.delete_virtual_screen()
|
||||||
|
QApplication.instance().quit()
|
||||||
self.VNCMessageListWidget.setEnabled(False)
|
self.VNCMessageListWidget.setEnabled(False)
|
||||||
self.startVNCButton.setText("Start VNC Server")
|
self.startVNCButton.setText("Start VNC Server")
|
||||||
self.startVNCButton.setEnabled(True)
|
self.startVNCButton.setEnabled(True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue